You are here

function xmlsitemap_get_path_alias in XML sitemap 6.2

Same name and namespace in other branches
  1. 7.2 xmlsitemap.generate.inc \xmlsitemap_get_path_alias()

Given an internal Drupal path, return the alias for the path.

This is similar to drupal_get_path_alias(), but designed to fetch all alises at once so that only one database query is executed instead of several or possibly thousands during sitemap generation.

Parameters

$path: An internal Drupal path.

$language: A language code to use when looking up the paths.

1 call to xmlsitemap_get_path_alias()
xmlsitemap_generate_chunk in ./xmlsitemap.generate.inc

File

./xmlsitemap.generate.inc, line 22
Sitemap generation and rebuilding functions for the xmlsitemap module.

Code

function xmlsitemap_get_path_alias($path, $language) {
  static $aliases;
  static $last_language;
  if (!isset($aliases)) {
    $aliases['all'] = array();
    $query = db_query("SELECT src, dst FROM {url_alias} WHERE language = '' ORDER BY pid");
    while ($alias = db_fetch_array($query)) {
      $aliases['all'][$alias['src']] = $alias['dst'];
    }
  }
  if ($language && $last_language != $language) {
    unset($aliases[$last_language]);
    $aliases[$language] = array();
    $query = db_query("SELECT src, dst FROM {url_alias} WHERE language = '%s' ORDER BY pid", $language);
    while ($alias = db_fetch_array($query)) {
      $aliases[$language][$alias['src']] = $alias['dst'];
    }
    $last_language = $language;
  }
  if ($language && isset($aliases[$language][$path])) {
    return $aliases[$language][$path];
  }
  elseif (isset($aliases['all'][$path])) {
    return $aliases['all'][$path];
  }
  else {
    return $path;
  }
}