You are here

function theme_xmlsitemap_node_view_sitemap in XML sitemap 5.2

Same name and namespace in other branches
  1. 5 xmlsitemap_node/xmlsitemap_node.module \theme_xmlsitemap_node_view_sitemap()

Display the nodes of a view as an XML sitemap.

File

xmlsitemap_node/xmlsitemap_node.module, line 351
Adds nodes to the sitemap.

Code

function theme_xmlsitemap_node_view_sitemap($view, $nodes, $type) {
  drupal_set_header('Content-Type: text/xml; charset=utf-8');
  print '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  print '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' . "\n";
  print '  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n";
  print '  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9' . "\n";
  print '  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n";
  $count_comments = variable_get('xmlsitemap_node_count_comments', TRUE) && module_exists('comment');
  foreach ($nodes as $node) {
    if ($count_comments) {
      $lastmod = max($node->changed, $node->last_comment_timestamp);
    }
    else {
      $lastmod = $node->changed;
    }
    print '  <url>' . "\n";
    print '    <loc>' . xmlsitemap_url('node/' . $node->nid, $node->alias, NULL, NULL, TRUE) . '</loc>' . "\n";
    print '    <lastmod>' . gmdate('Y-m-d\\TH:i:s+00:00', $lastmod) . '</lastmod>' . "\n";
    print '    <changefreq>' . xmlsitemap_sitemap_frequency(xmlsitemap_node_frequency($node)) . '</changefreq>' . "\n";
    print '    <priority>' . number_format(xmlsitemap_node_priority($node), 1) . '</priority>' . "\n";
    print '  </url>' . "\n";
  }
  print '</urlset>';
  drupal_page_footer();
  exit;
}