You are here

function _login_destination_match_rule in Login Destination 7

A helper function to determine whether redirection should happen.

Return value

bool TRUE - apply redirect, FALSE - not to apply redirect.

1 call to _login_destination_match_rule()
login_destination_get_destination in ./login_destination.module
Process all destination rules and return destination path.

File

./login_destination.module, line 479
Control where users are directed to, once they login

Code

function _login_destination_match_rule($rule, $trigger = '', $current = NULL) {
  global $user;

  // Check rule is enabled or not.
  if ($rule->enabled == 0) {
    return FALSE;
  }
  $type = $rule->pages_type;
  $pages = $rule->pages;
  $triggers = unserialize($rule->triggers);
  if (empty($triggers)) {
    $triggers = array();
  }
  $roles = unserialize($rule->roles);
  if (empty($roles)) {
    $roles = array();
  }

  // Remove non-existent roles.
  $roles = array_intersect_key(_login_destination_role_options(), $roles);

  // Examine trigger match.
  if (!(empty($triggers) || array_key_exists($trigger, $triggers))) {
    return FALSE;
  }

  // Examine role matches.
  $roles_intersect = array_intersect_key($roles, $user->roles);
  if (!empty($roles) && empty($roles_intersect)) {
    return FALSE;
  }
  if ($type < LOGIN_DESTINATION_REDIRECT_PHP) {
    $pages = drupal_strtolower($pages);
    $alias = drupal_strtolower(drupal_get_path_alias($current));
    $page_match = drupal_match_path($alias, $pages);
    if ($alias != $current) {
      $page_match = $page_match || drupal_match_path($current, $pages);
    }
    $page_match = !($type xor $page_match);
  }
  elseif (module_exists('php')) {

    // Do not execute php if the PHP Filter is off.
    $page_match = _login_destination_eval($pages);
  }
  else {
    $page_match = FALSE;
  }
  return $page_match;
}