You are here

function securepages_match in Secure Pages 6

Same name and namespace in other branches
  1. 5 securepages.module \securepages_match()
  2. 6.2 securepages.module \securepages_match()
  3. 7 securepages.module \securepages_match()

securepages_match()

check the page past and see if it should be secure or insecure.

Parameters

$path: the page of the page to check.

Return value

0 - page should be insecure. 1 - page should be secure. NULL - do not change page.

4 calls to securepages_match()
SecurePagesTestCase::_testMatch in ./securepages.test
Tests the securepages_match() function.
securepages_form_alter in ./securepages.module
Implementation of hook_form_alter().
securepages_link_alter in ./securepages.module
Implementation of hook_link_alter().
securepages_redirect in ./securepages.module
Check the current page and see if we need to redirect to the secure or insecure version of the page.

File

./securepages.module, line 212
Provide method of creating allowing certain pages to only viewable from https pages

Code

function securepages_match($path) {

  /**
   * Check to see if the page matches the current settings
   */
  $secure = variable_get('securepages_secure', 1);
  $pages = variable_get('securepages_pages', "node/add*\nnode/*/edit\nuser/*\nadmin*");
  $ignore = variable_get('securepages_ignore', '');
  $path = securepages_strtolower(trim($path, '/'));
  if ($ignore) {
    $regexp = '/^(' . preg_replace(array(
      '/(\\r\\n?|\\n)/',
      '/\\\\\\*/',
      '/(^|\\|)\\\\<front\\\\>($|\\|)/',
    ), array(
      '|',
      '.*',
      '\\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\\2',
    ), preg_quote($ignore, '/')) . ')$/';
    if (preg_match($regexp, $path)) {
      return securepages_is_secure() ? 1 : 0;
    }
  }
  if ($pages) {
    $regexp = '/^(' . preg_replace(array(
      '/(\\r\\n?|\\n)/',
      '/\\\\\\*/',
      '/(^|\\|)\\\\<front\\\\>($|\\|)/',
    ), array(
      '|',
      '.*',
      '\\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\\2',
    ), preg_quote($pages, '/')) . ')$/';
    $result = preg_match($regexp, $path);
    if (function_exists('drupal_get_path_alias')) {
      $path_alias = drupal_get_path_alias($path);
      $result |= preg_match($regexp, $path_alias);
    }
    return !($secure xor $result) ? 1 : 0;
  }
  else {
    return;
  }
}