You are here

function hansel_switch_url_argument_compare in Hansel breadcrumbs 8

Same name and namespace in other branches
  1. 7 hansel.switches.inc \hansel_switch_url_argument_compare()

Callback for "url argument" switch to compare a given value.

Parameters

array $arguments:

string $value:

Return value

boolean

2 string references to 'hansel_switch_url_argument_compare'
hansel_hansel_switch_types in ./hansel.module
Implements hook_hansel_switch_types().
hook_hansel_switch_types in ./hansel.hooks.inc
Define switch types.

File

./hansel.switches.inc, line 20
Hansel switches

Code

function hansel_switch_url_argument_compare($arguments, $value) {
  if (empty($arguments['argument'])) {
    $arg = hansel_arg(0);
  }
  else {
    $arg = hansel_arg((int) $arguments['argument'] - 1);
  }

  // Check for <empty>
  if ($arg == '' && $value == '<empty>') {
    return TRUE;
  }

  // Check for <front>
  global $_hansel_test_path;
  $path = empty($_hansel_test_path) ? $_GET['q'] : $_hansel_test_path;
  if ($value == '<front>' && $path == variable_get('site_frontpage', 'node')) {
    return TRUE;
  }
  if (empty($arguments['regex'])) {
    if (empty($arguments['cs'])) {

      // Use case insensitive matching.
      return drupal_strtolower($arg) == drupal_strtolower($value);
    }
    else {
      return $arg == $value;
    }
  }
  else {

    // Backslash forward slashes
    $pattern = str_replace('/', '\\/', $value);
    $pattern = "/{$pattern}/s";
    if (empty($arguments['cs'])) {

      // Use case insensitive matching.
      $pattern .= 'i';
    }
    return (bool) @preg_match($pattern, $arg);
  }
}