You are here

function xmlsitemap_url in XML sitemap 5

Same name and namespace in other branches
  1. 5.2 xmlsitemap/xmlsitemap.module \xmlsitemap_url()

Modified version of url(). We don't want to do a separate database query for each url, so we pass the alias as an extra parameter.

Parameters

$alias: The URL alias. Default is NULL.:

Return value

The fully formatted URL

Related topics

16 calls to xmlsitemap_url()
hook_xmlsitemap_engines in docs/xmlsitemap.php
Define actions for search engines.
hook_xmlsitemap_links in docs/xmlsitemap.php
Define additional links to add to the site map.
theme_xmlsitemap_node_view_news in xmlsitemap_node/xmlsitemap_node.module
Display the nodes of a view as a Google News site map.
theme_xmlsitemap_node_view_sitemap in xmlsitemap_node/xmlsitemap_node.module
Display the nodes of a view as an XML site map.
xmlsitemap_help in ./xmlsitemap.module
Implementation of hook_help().

... See full list

File

./xmlsitemap.module, line 709
Creates a site map compatible with the sitemaps.org schema.

Code

function xmlsitemap_url($path = NULL, $alias = NULL, $query = NULL, $fragment = NULL, $absolute = FALSE) {
  if (isset($fragment)) {
    $fragment = "#{$fragment}";
  }
  $colonpos = strpos($path, ':');
  if ($colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && filter_xss_bad_protocol($path, FALSE) == check_plain($path)) {
    if (strpos($path, '#') !== FALSE) {
      list($path, $old_fragment) = explode('#', $path, 2);
      if (isset($old_fragment) && !isset($fragment)) {
        $fragment = "#{$old_fragment}";
      }
    }
    if (isset($query)) {
      $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . $query;
    }
    return $path . $fragment;
  }
  global $base_url;
  static $script;
  static $clean_url;
  $script = isset($script) ? $script : strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === FALSE ? 'index.php' : '';
  $clean_url = isset($clean_url) ? $clean_url : variable_get('clean_url', FALSE);
  $base = $absolute ? $base_url . '/' : base_path();
  if (!empty($path) && $path != '<front>') {
    $path = _xmlsitemap_get_path_alias($path, $alias);
    $path = drupal_urlencode($path);
    if (!$clean_url) {
      if (isset($query)) {
        return $base . $script . '?q=' . $path . '&' . $query . $fragment;
      }
      else {
        return $base . $script . '?q=' . $path . $fragment;
      }
    }
    else {
      if (isset($query)) {
        return $base . $path . '?' . $query . $fragment;
      }
      else {
        return $base . $path . $fragment;
      }
    }
  }
  else {
    if (isset($query)) {
      return $base . $script . '?' . $query . $fragment;
    }
    else {
      return $base . $fragment;
    }
  }
}