| 1 |
<?php
|
| 2 |
// $Id: xmlsitemap.php,v 1.2 2007/05/06 22:06:54 darrenoh Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @addtogroup hooks
|
| 6 |
* @{
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Define additional links to add to the site map.
|
| 11 |
*
|
| 12 |
* This hook allows modules to add additional links to the site map. Links
|
| 13 |
* may be associated with nodes, terms, or users, as shown in the example.
|
| 14 |
*
|
| 15 |
* @param $type:
|
| 16 |
* If set, a string specifying the type of additional links to return.
|
| 17 |
* - nid:
|
| 18 |
* Links associated with nodes
|
| 19 |
* - tid:
|
| 20 |
* Links associated with terms
|
| 21 |
* - uid:
|
| 22 |
* Links associated with users
|
| 23 |
* - xml:
|
| 24 |
* An XML site map (for including site maps from other modules)
|
| 25 |
* @param $excludes:
|
| 26 |
* If set, an array of criteria for excluding links.
|
| 27 |
* @return
|
| 28 |
* If $type is xml, return an XML site map. Otherwise, return an array of
|
| 29 |
* links or an empty array. Each link should be an array with the
|
| 30 |
* following keys:
|
| 31 |
* - nid, tid, or uid:
|
| 32 |
* ID to associate with this link (if $type is set)
|
| 33 |
* - #loc:
|
| 34 |
* The URL of the page
|
| 35 |
* - #lastmod:
|
| 36 |
* Timestamp of last modification
|
| 37 |
* - #changefreq:
|
| 38 |
* Number of seconds between changes
|
| 39 |
* - #priority:
|
| 40 |
* A number between 1.0 and 0.0 indicating the link's priority
|
| 41 |
*/
|
| 42 |
function hook_xmlsitemap($type = NULL, $excludes = array()) {
|
| 43 |
$additional = array();
|
| 44 |
switch ($type) {
|
| 45 |
case 'node':
|
| 46 |
// Add pages created by the node paging module.
|
| 47 |
foreach (node_get_types() as $type => $name) {
|
| 48 |
$node_types[$type] = db_escape_string($type);
|
| 49 |
}
|
| 50 |
$excludes = array_merge($excludes, array_diff($node_types, variable_get('paging_node_types_enabled', array())));
|
| 51 |
if (module_exists('comment')) {
|
| 52 |
$result = db_query("
|
| 53 |
SELECT p.pages, n.nid, n.type, n.promote, s.comment_count, n.changed, x.previously_changed, s.last_comment_timestamp, x.previous_comment, x.priority_override, u.dst AS alias
|
| 54 |
FROM {node} n
|
| 55 |
INNER JOIN {paging} p
|
| 56 |
ON n.nid = p.nid
|
| 57 |
LEFT JOIN {node_comment_statistics} s
|
| 58 |
ON n.nid = s.nid
|
| 59 |
LEFT JOIN {xmlsitemap} x
|
| 60 |
ON n.nid = x.nid
|
| 61 |
LEFT JOIN {url_alias} u
|
| 62 |
ON x.pid = u.pid
|
| 63 |
WHERE n.status > 0
|
| 64 |
AND (x.priority_override >= 0 OR x.priority_override IS NULL)
|
| 65 |
AND n.type NOT IN ('". implode("', '", $excludes) ."')
|
| 66 |
");
|
| 67 |
$maxcomments = db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'));
|
| 68 |
}
|
| 69 |
else {
|
| 70 |
$result = db_query("
|
| 71 |
SELECT p.pages, n.nid, n.type, n.promote, n.changed, x.previously_changed, x.priority_override, u.dst AS alias
|
| 72 |
FROM {node} n
|
| 73 |
INNER JOIN {paging} p
|
| 74 |
ON n.nid = p.nid
|
| 75 |
LEFT JOIN {xmlsitemap} x
|
| 76 |
ON n.nid = x.nid
|
| 77 |
LEFT JOIN {url_alias} u
|
| 78 |
ON x.pid = u.pid
|
| 79 |
WHERE n.status > 0
|
| 80 |
AND (x.priority_override >= 0 OR x.priority_override IS NULL)
|
| 81 |
AND n.type NOT IN ('". implode("', '", $excludes) ."')
|
| 82 |
");
|
| 83 |
$maxcomments = 0;
|
| 84 |
}
|
| 85 |
while ($node = db_fetch_object($result)) {
|
| 86 |
$pri = xmlsitemap_node_priority($node, $maxcomments);
|
| 87 |
if ($pri < 0) {
|
| 88 |
continue;
|
| 89 |
}
|
| 90 |
$age = time() - $node->changed;
|
| 91 |
if (!empty($node->previously_changed)) {
|
| 92 |
$interval = $node->changed - $node->previously_changed;
|
| 93 |
}
|
| 94 |
else {
|
| 95 |
$interval = 0;
|
| 96 |
}
|
| 97 |
for ($count = 1; $count < $node->pages; ++ $count) {
|
| 98 |
$entry = array(
|
| 99 |
'nid' => $node->nid,
|
| 100 |
'#loc' => xmlsitemap_url('node/'. $node->nid, $node->alias, array('query' => "page=0,$count", 'absolute' => TRUE)),
|
| 101 |
'#lastmod' => $node->changed,
|
| 102 |
'#changefreq' => max($age, $interval),
|
| 103 |
'#priority' => $pri,
|
| 104 |
);
|
| 105 |
$additional[] = $entry;
|
| 106 |
}
|
| 107 |
}
|
| 108 |
break;
|
| 109 |
case 'term':
|
| 110 |
case 'user':
|
| 111 |
break;
|
| 112 |
case 'xml':
|
| 113 |
$additional = example_sitemap();
|
| 114 |
break;
|
| 115 |
default:
|
| 116 |
// Add arbitrary additional links.
|
| 117 |
$result = db_query('SELECT x.*, u.dst AS alias FROM {xmlsitemap_additional} x LEFT JOIN {url_alias} u ON x.pid = u.pid');
|
| 118 |
while ($link = db_fetch_object($result)) {
|
| 119 |
$age = time() - $link->last_changed;
|
| 120 |
if (!empty($link->previously_changed)) {
|
| 121 |
$interval = $link->last_changed - $link->previously_changed;
|
| 122 |
}
|
| 123 |
else {
|
| 124 |
$interval = 0;
|
| 125 |
}
|
| 126 |
$entry = array(
|
| 127 |
'#loc' => xmlsitemap_url($link->path, $link->alias, NULL, NULL, TRUE),
|
| 128 |
'#lastmod' => $link->last_changed,
|
| 129 |
'#changefreq' => max($age, $interval),
|
| 130 |
'#priority' => $link->priority,
|
| 131 |
);
|
| 132 |
$additional[] = $entry;
|
| 133 |
}
|
| 134 |
}
|
| 135 |
return $additional;
|
| 136 |
}
|
| 137 |
|
| 138 |
/**
|
| 139 |
* @} End of "addtogroup hooks".
|
| 140 |
*/
|
| 141 |
|