paging_xmlsitemap.module in Paging 5
Adds node paging links to the site map.
File
contrib/paging_xmlsitemap/paging_xmlsitemap.moduleView source
<?php
/**
* @file
* Adds node paging links to the site map.
*/
/**
* Implementation of hook_xmlsitemap_links().
*/
function paging_xmlsitemap_xmlsitemap_links($type = NULL, $excludes = array()) {
if ($type == 'node') {
$excludes = array_merge($excludes, _paging_xmlsitemap_excludes());
if (module_exists('comment')) {
$query = "\n SELECT n.nid, px.pages, n.type, n.promote, s.comment_count, n.changed, xn.previously_changed, s.last_comment_timestamp, xn.previous_comment, xn.priority_override, COALESCE(ua.dst) AS alias\n FROM {node} n\n INNER JOIN {paging_xmlsitemap} px ON n.nid = px.nid\n LEFT JOIN {node_comment_statistics} s ON n.nid = s.nid";
}
else {
$query = "\n SELECT n.nid, px.pages, n.type, n.promote, n.changed, xn.previously_changed, xn.priority_override, COALESCE(ua.dst) AS alias\n FROM {node} n";
}
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$query .= "\n LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', CAST(n.nid AS CHAR))";
break;
case 'pgsql':
$query .= "\n LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', CAST(n.nid AS VARCHAR))";
break;
}
$query .= "\n LEFT JOIN {xmlsitemap_node} xn ON n.nid = xn.nid\n WHERE n.status > 0\n AND (n.type NOT IN ('" . implode("', '", $excludes) . "') AND xn.priority_override IS NULL OR xn.priority_override >= 0)\n GROUP BY n.nid";
$result = db_query(db_rewrite_sql($query));
while ($node = db_fetch_object($result)) {
for ($count = 1; $count < $node->pages; ++$count) {
if (function_exists('_xmlsitemap_links')) {
$links[] = array(
'nid' => $node->nid,
'#loc' => xmlsitemap_url('node/' . $node->nid, $node->alias, "page=0,{$count}", NULL, TRUE),
'#lastmod' => variable_get('xmlsitemap_node_count_comments', TRUE) ? max($node->changed, $node->last_comment_timestamp) : $node->changed,
'#changefreq' => xmlsitemap_node_frequency($node),
'#priority' => xmlsitemap_node_priority($node),
);
}
else {
$link = array(
'loc' => xmlsitemap_url('node/' . $node->nid, $node->alias, "page=0,{$count}", NULL, TRUE),
'lastmod' => variable_get('xmlsitemap_node_count_comments', TRUE) ? max($node->changed, $node->last_comment_timestamp) : $node->changed,
'changefreq' => xmlsitemap_node_frequency($node),
'priority' => xmlsitemap_node_priority($node),
);
db_query("INSERT INTO {xmlsitemap} (loc, lastmod, changefreq, priority) VALUES ('%s', %d, %d, %f)", $link);
}
}
}
if (function_exists('_xmlsitemap_links')) {
return $links;
}
}
}
/**
* Get node types for which paging is disabled.
* @return An array of node types.
*/
function _paging_xmlsitemap_excludes() {
static $excludes = NULL;
if (!isset($excludes)) {
foreach (node_get_types() as $type => $name) {
$types[] = $type;
}
$excludes = array_diff($types, variable_get('paging_node_types_enabled', array()));
}
return $excludes;
}
/**
* Implementation of hook_nodeapi().
*/
function paging_xmlsitemap_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'insert':
case 'update':
if (in_array($node->type, variable_get('paging_node_types_enabled', array()), TRUE)) {
if (isset($node->field_body[0]['view'])) {
// support for CCK
$body = $node->field_body[0]['view'];
}
elseif (isset($node->field_body[0]['value'])) {
// support for CCK
$body = $node->field_body[0]['value'];
}
else {
$body = $node->body;
}
$page_count = 1 + substr_count($body, variable_get('paging_separator', '<!--pagebreak-->'));
if ($page_count > 1) {
if ($op == 'insert') {
db_query("INSERT INTO {paging_xmlsitemap} (nid, pages) VALUES (%d, %d)", $node->nid, $node->page_count);
}
else {
db_query("UPDATE {paging_xmlsitemap} SET pages = %d WHERE nid = %d", $node->page_count, $node->nid);
}
}
}
break;
case 'delete':
db_query("DELETE FROM {paging_xmlsitemap} WHERE nid = %d", $node->nid);
break;
}
}
Functions
Name![]() |
Description |
---|---|
paging_xmlsitemap_nodeapi | Implementation of hook_nodeapi(). |
paging_xmlsitemap_xmlsitemap_links | Implementation of hook_xmlsitemap_links(). |
_paging_xmlsitemap_excludes | Get node types for which paging is disabled. |