You are here

function pages_restriction_page_alter in Pages Restriction Access 7

Implements hook_page_alter().

File

./pages_restriction.module, line 38
Contains the administrative features for the Pages Restriction.

Code

function pages_restriction_page_alter(&$page) {
  global $language;
  $lang_name = $language->language;
  module_load_include('inc', 'pages_restriction', 'includes/pages_restriction.helpers');
  module_load_include('inc', 'pages_restriction', 'includes/pages_restriction.cache');
  $path = current_path();
  $path_alias = drupal_lookup_path('alias', $path);
  if ($path_alias == FALSE) {
    $path_alias = $path;
  }
  $translated_path = _pages_restriction_get_translated_path($path_alias);
  if ($translated_path != $path_alias) {
    $path_alias = $translated_path;
  }
  if (strpos($path_alias, $lang_name . "/") !== FALSE) {
    $path_alias = str_replace($lang_name . "/", "", $path_alias);
  }
  $rules = _pages_restriction_get_rules_by_path($path_alias);
  if (_pages_restriction_restrict_access($path_alias)) {
    foreach ($rules as $rule) {
      if (!preg_match('@^' . str_replace('%', '\\w*', trim($rule[1])) . '$@', $path_alias)) {
        drupal_goto($path_alias);
      }
    }
  }
  foreach ($rules as $rule) {
    if (preg_match('@^' . str_replace('%', '\\w*', trim($rule[1])) . '$@', $path_alias)) {
      $data = _pages_restriction_get_cached_data();
      _pages_restriction_unset_sections_with_path($path_alias);
      if (empty($data)) {
        drupal_goto($rule[0]);
      }
    }
  }
}