You are here

function restrict_ip_page_alter in Restrict IP 7.2

Implements hook_page_alter().

Redirects non-whitelisted users to the access denied page, and unsets all regions of the page, except for the content regions, which shows the blacklisted error to users.

File

./restrict_ip.module, line 322
Holds hooks for the restrict_ip module.

Code

function restrict_ip_page_alter(&$page) {
  global $theme;
  if (ip_restricted()) {
    if (strtolower(current_path()) != 'restrict_ip/access_denied') {
      if (module_exists('dblog') && variable_get('restrict_ip_watchdog', FALSE)) {
        $current_path = drupal_get_path_alias(filter_xss(check_plain(strtolower(current_path()))));
        watchdog('Restrict IP', 'Access to the path %path was blocked for the IP address %ip_address', array(
          '%path' => $current_path,
          '%ip_address' => ip_address(),
        ));
      }
      if (variable_get('restrict_ip_allow_role_bypass', FALSE) && variable_get('restrict_ip_bypass_action', 'provide_link_login_page') === 'redirect_login_page') {
        drupal_goto('user/login');
      }
      if (in_array(variable_get('restrict_ip_white_black_list', 0), array(
        0,
        1,
      ))) {
        drupal_goto('restrict_ip/access_denied');
      }
      else {
        drupal_set_message(t('The page you are trying to access cannot be accessed from your IP address.'));
        drupal_goto('<front>');
      }
    }
    $regions = system_region_list($theme, REGIONS_ALL);
    unset($regions['content']);
    $whitelisted_regions = array();
    foreach (module_implements('restrict_ip_whitelisted_regions') as $module_name) {
      $function = $module_name . '_restrict_ip_whitelisted_regions';
      $whitelisted_regions = array_merge($whitelisted_regions, $function());
    }
    foreach ($whitelisted_regions as $wr) {
      unset($regions[$wr]);
    }
    foreach (array_keys($regions) as $region) {
      if (isset($page[$region])) {
        $page[$region] = FALSE;
      }
    }
  }
}