You are here

function xmlsitemap_node_xmlsitemap_links in XML sitemap 5.2

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

Implementation of hook_xmlsitemap_links().

File

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

Code

function xmlsitemap_node_xmlsitemap_links() {
  $excludes = xmlsitemap_node_excludes();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $coalesce = 'COALESCE';
      break;
    case 'pgsql':
      $coalesce = 'FIRST';
      break;
  }
  if (module_exists('comment')) {
    $columns = 'n.nid, n.type, n.promote, n.changed, xn.previously_changed, xn.priority_override, s.comment_count, s.last_comment_timestamp, xn.previous_comment';
    $left_join = "LEFT JOIN {node_comment_statistics} s ON n.nid = s.nid";
  }
  else {
    $columns = 'n.nid, n.type, n.promote, n.changed, xn.previously_changed, xn.priority_override';
    $left_join = '';
  }
  $query = "SELECT {$columns}, {$coalesce}(ua.dst) AS alias FROM {node} n\n    LEFT JOIN {xmlsitemap_node} xn ON n.nid = xn.nid\n    {$left_join}\n    LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', n.nid)\n    WHERE n.status > 0\n      AND n.type NOT IN (" . xmlsitemap_placeholders($excludes, 'varchar') . ")\n      AND (xn.priority_override IS NULL OR xn.priority_override = -2 OR xn.priority_override >= 0)\n      AND n.nid <> %d\n    GROUP BY {$columns}";
  $nid = 0;
  $frontpage = explode('/', drupal_get_normal_path(variable_get('site_frontpage', 'node')));
  if (count($frontpage) == 2 && $frontpage[0] == 'node' && is_numeric($frontpage[1])) {
    $nid = $frontpage[1];
  }
  $query_args = array_merge($excludes, array(
    $nid,
  ));
  $result = db_query(db_rewrite_sql($query), $query_args);
  $count_comments = variable_get('xmlsitemap_node_count_comments', TRUE) && module_exists('comment');
  while ($node = db_fetch_object($result)) {
    db_query("INSERT INTO {xmlsitemap} (loc, lastmod, changefreq, priority) VALUES ('%s', %d, %d, %f)", xmlsitemap_url('node/' . $node->nid, $node->alias, NULL, NULL, TRUE), $count_comments ? max($node->changed, $node->last_comment_timestamp) : $node->changed, xmlsitemap_node_frequency($node), xmlsitemap_node_priority($node));
  }
}