You are here

function domain_301_redirect_may_redirect in Domain 301 Redirect 7

Determines if a page is configured to redirect.

Uses logic copied from block.module to handle either all pages except those listed or all pages listed.

1 call to domain_301_redirect_may_redirect()
domain_301_redirect_init in ./domain_301_redirect.module
Implements hook_init().

File

./domain_301_redirect.module, line 87
This module allows you to 301 redirect all domains to one specific domain.

Code

function domain_301_redirect_may_redirect() {
  $applicability = (int) variable_get('domain_301_redirect_applicability');
  if ($pages = trim((string) variable_get('domain_301_redirect_pages'))) {

    // Convert path to lowercase. This allows comparison of the same path
    // with different case. Ex: /Page, /page, /PAGE.
    $pages = drupal_strtolower($pages);

    // Convert the Drupal path to lowercase and get the aliased version of it.
    $current_path = drupal_strtolower(current_path());
    $aliased_path = drupal_strtolower(drupal_get_path_alias($current_path));

    // Compare the lowercase internal and lowercase path alias (if any).
    $page_match = drupal_match_path($aliased_path, $pages);
    if ($aliased_path != $current_path) {
      $page_match = $page_match || drupal_match_path($current_path, $pages);
    }

    // When $applicability has a value of 0 (BLOCK_VISIBILITY_NOTLISTED),
    // the redirect is applied on all pages except those listed in $pages.
    // When set to 1 (BLOCK_VISIBILITY_LISTED), it is applied only on those
    // pages listed in $pages.
    $page_match = !($applicability xor $page_match);
  }
  elseif ($applicability == BLOCK_VISIBILITY_LISTED) {
    $page_match = FALSE;
  }
  else {
    $page_match = TRUE;
  }
  return $page_match;
}