You are here

function _ng_lightbox_check_path in NG Lightbox 7

Checks whether a give path matches the ng-lightbox path rules. This function checks both internal paths and aliased paths.

Parameters

string $path: The path to check.

Return value

bool TRUE if it matches the given rules.

1 call to _ng_lightbox_check_path()
ng_lightbox_link in ./ng_lightbox.module
Implements theme_link().

File

./ng_lightbox.module, line 57
The NG Lightbox module.

Code

function _ng_lightbox_check_path($path) {

  // We filter out empty paths because some modules (such as Media) use
  // theme_link() to generate links with empty paths.
  if (empty($path)) {
    return FALSE;
  }

  // If we want to skip admin paths and this path is admin, return theme link.
  if (variable_get('ng_lightbox_skip_admin_paths', TRUE) && path_is_admin(current_path())) {
    return FALSE;
  }

  // Normalise the path because Drupal does the same in the router.
  $path = drupal_strtolower($path);
  $matches =& drupal_static(__FUNCTION__);
  if (isset($matches[$path])) {
    return $matches[$path];
  }

  // Normalise the patterns as well so they match the normalised paths.
  $patterns = drupal_strtolower(variable_get('ng_lightbox_patterns', ''));

  // Check for internal paths first which is much quicker than the alias lookup.
  if (drupal_match_path($path, $patterns)) {
    $matches[$path] = TRUE;
  }
  else {

    // Now check for aliases paths.
    $aliased_path = drupal_strtolower(drupal_get_path_alias($path));
    if ($path != $aliased_path && drupal_match_path($aliased_path, $patterns)) {
      $matches[$path] = TRUE;
    }
    else {

      // No match.
      $matches[$path] = FALSE;
    }
  }
  return $matches[$path];
}