You are here

function protected_pages_init in Protected Pages 7.2

Same name and namespace in other branches
  1. 7 protected_pages.module \protected_pages_init()

Implements hook_init().

File

./protected_pages.module, line 118
This module allows you to protect any page of your website by secure password. You can enter urls of pages to protect and set password per page. Admin (uid = 1) or user with bypass protection permission can view page.

Code

function protected_pages_init() {
  if (user_access('bypass pages password protection')) {
    return;
  }
  $current_path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
  $normal_path = drupal_get_normal_path($current_path);
  $pid = protected_pages_is_page_locked($current_path, $normal_path);
  if ($pid) {
    $query = drupal_get_destination();
    if (!empty($_SERVER['HTTP_REFERER'])) {
      $query['back'] = urlencode($current_path);
    }
    $query['protected_page'] = $pid;
    drupal_goto('protected-page', array(
      'query' => $query,
    ));
  }
  else {
    $page_node = menu_get_object();
    if (isset($page_node->nid) && is_numeric($page_node->nid)) {
      $path_to_node = 'node/' . $page_node->nid;
      $current_path = drupal_strtolower(drupal_get_path_alias($path_to_node));
      $normal_path = drupal_get_normal_path($current_path);
      $pid = protected_pages_is_page_locked($current_path, $normal_path);
      if ($pid) {
        $query = drupal_get_destination();
        if (!empty($_SERVER['HTTP_REFERER'])) {
          $query['back'] = urlencode($current_path);
        }
        $query['protected_page'] = $pid;
        drupal_goto('protected-page', array(
          'query' => $query,
        ));
      }
    }
  }
}