You are here

function restrict_ip_access_denied_page in Restrict IP 7.2

Callback for path restrict_ip/access_denied.

Redirects user to the front page if they have been whitelisted. Otherwise shows an access denied error.

1 string reference to 'restrict_ip_access_denied_page'
restrict_ip_menu in ./restrict_ip.module
Implements hook_menu().

File

includes/restrict_ip.pages.inc, line 269
Holds page callbacks for the Restrict IP module.

Code

function restrict_ip_access_denied_page() {
  if (!isset($_SESSION['restrict_ip']) || !$_SESSION['restrict_ip']) {
    drupal_goto('<front>');
  }
  $page['access_denied'] = array(
    '#markup' => t('The page you are trying to access cannot be accessed from your IP address.'),
    '#prefix' => '<p>',
    '#suffix' => '</p>',
  );
  $contact_mail = trim(variable_get('restrict_ip_mail_address', ''));
  if (strlen($contact_mail)) {
    $contact_mail = str_replace('@', '[at]', $contact_mail);
    $page['contact_us'] = array(
      '#markup' => t('If you feel this is in error, please contact an administrator at !email.', array(
        '!email' => '<span id="restrict_ip_contact_mail">' . $contact_mail . '</span>',
      )),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    );
  }
  if (variable_get('restrict_ip_allow_role_bypass', FALSE)) {
    if (user_is_logged_in()) {
      $page['logout_link'] = array(
        '#markup' => l(t('Logout'), 'user/logout'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
    }
    elseif (variable_get('restrict_ip_bypass_action', 'provide_link_login_page') === 'provide_link_login_page') {
      $page['login_link'] = array(
        '#markup' => l(t('Sign in'), 'user/login'),
        '#prefix' => '<p>',
        '#suffix' => '</p>',
      );
    }
  }
  $page['#attached']['js'][] = array(
    'type' => 'file',
    'data' => drupal_get_path('module', 'restrict_ip') . '/js/restrict_ip.js',
  );
  drupal_alter('restrict_ip_access_denied_page', $page);
  return $page;
}