function drupal_lookup_path in Drupal 5
Same name and namespace in other branches
- 4 includes/path.inc \drupal_lookup_path()
- 6 includes/path.inc \drupal_lookup_path()
- 7 includes/path.inc \drupal_lookup_path()
Given an alias, return its Drupal system URL if one exists. Given a Drupal system URL return one of its aliases if such a one exists. Otherwise, return FALSE.
Parameters
$action: One of the following values:
- wipe: delete the alias cache.
- alias: return an alias for a given Drupal system path (if one exists).
- source: return the Drupal system URL for a path alias (if one exists).
$path: The path to investigate for corresponding aliases or system URLs.
Return value
Either a Drupal system path, an aliased path, or FALSE if no path was found.
3 calls to drupal_lookup_path()
- drupal_clear_path_cache in includes/
common.inc - Reset the static variable which holds the aliases mapped for this request.
- drupal_get_normal_path in includes/
path.inc - Given a path alias, return the internal path it represents.
- drupal_get_path_alias in includes/
path.inc - Given an internal Drupal path, return the alias set by the administrator.
File
- includes/
path.inc, line 41 - Functions to handle paths in Drupal, including path aliasing.
Code
function drupal_lookup_path($action, $path = '') {
// $map keys are Drupal paths and the values are the corresponding aliases
static $map = array(), $no_src = array();
static $count;
// Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
if (!isset($count)) {
$count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}'));
}
if ($action == 'wipe') {
$map = array();
$no_src = array();
}
elseif ($count > 0 && $path != '') {
if ($action == 'alias') {
if (isset($map[$path])) {
return $map[$path];
}
$alias = db_result(db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path));
$map[$path] = $alias;
return $alias;
}
elseif ($action == 'source' && !isset($no_src[$path])) {
// Look for the value $path within the cached $map
if (!($src = array_search($path, $map))) {
if ($src = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
$map[$src] = $path;
}
else {
// We can't record anything into $map because we do not have a valid
// index and there is no need because we have not learned anything
// about any Drupal path. Thus cache to $no_src.
$no_src[$path] = TRUE;
}
}
return $src;
}
}
return FALSE;
}