function xmlsitemap_node_xmlsitemap_links in XML sitemap 6
Same name and namespace in other branches
- 5.2 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_xmlsitemap_links()
- 5 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_xmlsitemap_links()
Implementation of hook_xmlsitemap_links().
File
- xmlsitemap_node/
xmlsitemap_node.module, line 294 - Adds nodes to the sitemap.
Code
function xmlsitemap_node_xmlsitemap_links() {
$anon_account = drupal_anonymous_user();
$query = "SELECT n.nid, n.vid, n.type, n.language, n.uid, n.created, n.promote, xn.changed, xn.previously_changed, xn.priority_override, xn.comment_ratio\n FROM {node} n\n INNER JOIN {xmlsitemap_node} xn ON n.nid = xn.nid\n WHERE n.status > 0";
$result = db_query($query);
$row = new stdClass();
$row->module = 'xmlsitemap_node';
$row->type = 'node';
while ($node = db_fetch_object($result)) {
$row->loc = 'node/' . $node->nid;
$row->id = $node->nid;
$row->sid = $node->vid;
$row->language = $node->language;
$row->changed = $node->changed;
$row->changefreq = max(REQUEST_TIME - $node->changed, empty($node->previously_changed) ? $node->changed - $node->created : $node->changed - $node->previously_changed);
$priority = xmlsitemap_node_get_priority($node);
$row->priority = $priority == -1.0 ? $priority : min(max(round($priority, 1), 0.0), 1.0);
$old_row = db_fetch_object(db_query("SELECT lid, type, language, priority FROM {xmlsitemap} WHERE loc = '%s'", $row->loc));
$node_access = node_access('view', node_load(array(
'nid' => $node->nid,
), NULL, TRUE), $anon_account);
$row->priority = $node_access ? $row->priority : -1;
if ($old_row === FALSE) {
drupal_write_record('xmlsitemap', $row);
}
elseif ($old_row->type == 'node' && ($old_row->priority != $row->priority || $old_row->language != $row->language || $old_row->changed != $row->changed || $old_row->changefreq != $row->changefreq)) {
$row->lid = $old_row->lid;
drupal_write_record('xmlsitemap', $row, 'lid');
}
}
}