You are here

public static function SmartIp::checkAllowedPage in Smart IP 8.4

Same name and namespace in other branches
  1. 8.2 src/SmartIp.php \Drupal\smart_ip\SmartIp::checkAllowedPage()
  2. 8.3 src/SmartIp.php \Drupal\smart_ip\SmartIp::checkAllowedPage()

Check the page URL in allowed geolocate list.

Return value

bool

4 calls to SmartIp::checkAllowedPage()
DeviceGeolocationController::check in modules/device_geolocation/src/Controller/DeviceGeolocationController.php
Check for Geolocation attempt.
device_geolocation_page_attachments in modules/device_geolocation/device_geolocation.module
Implements hook_page_attachments().
GeolocateUserSubscriber::geolocateUser in src/EventSubscriber/GeolocateUserSubscriber.php
Initiate user geolocation.
smart_ip_page_attachments in ./smart_ip.module
Implements hook_page_attachments().

File

src/SmartIp.php, line 389
Contains \Drupal\smart_ip\SmartIp.

Class

SmartIp
Smart IP static basic methods wrapper.

Namespace

Drupal\smart_ip

Code

public static function checkAllowedPage() {
  $pages = \Drupal::config('smart_ip.settings')
    ->get('allowed_pages');
  if (empty($pages)) {

    // No pages specified then all pages are allowed.
    return TRUE;
  }
  else {
    if (isset($_GET['geolocate_uri'])) {

      // Handle "geolocate_uri" from ajax request.
      $url = $_GET['geolocate_uri'];
    }
    else {
      $url = \Drupal::service('path.current')
        ->getPath();
    }

    /** @var \Drupal\path_alias\AliasManagerInterface $aliasManager */
    $aliasManager = \Drupal::service('path_alias.manager');
    $pathAlias = $aliasManager
      ->getAliasByPath($url);

    // Convert the Drupal path to lowercase.
    $path = mb_strtolower($pathAlias);

    /** @var \Drupal\Core\Path\PathMatcherInterface $pathMatcher */
    $pathMatcher = \Drupal::service('path.matcher');

    // Compare the lowercase internal and lowercase path alias (if any).
    $pageMatch = $pathMatcher
      ->matchPath($path, $pages);
    if ($path != $url) {
      $pageMatch = $pageMatch || $pathMatcher
        ->matchPath($url, $pages);
    }
    elseif ($path == $url) {
      $url = $aliasManager
        ->getPathByAlias($url);
      $pageMatch = $pageMatch || $pathMatcher
        ->matchPath($url, $pages);
    }
    return $pageMatch;
  }
}