public static function SmartIp::checkAllowedPage in Smart IP 8.3
Same name and namespace in other branches
- 8.4 src/SmartIp.php \Drupal\smart_ip\SmartIp::checkAllowedPage()
- 8.2 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 390 - Contains \Drupal\smart_ip\SmartIp.
Class
- SmartIp
- Smart IP static basic methods wrapper.
Namespace
Drupal\smart_ipCode
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\Core\Path\AliasManagerInterface $aliasManager */
$aliasManager = \Drupal::service('path.alias_manager');
$pathAlias = $aliasManager
->getAliasByPath($url);
// Convert the Drupal path to lowercase.
$path = Unicode::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;
}
}