| 1 |
<?php
|
| 2 |
// $Id: revisions_rss.module,v 1.3 2009/01/21 02:49:43 alexj Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Revisions RSS feed generator.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Menu callback; publish an RSS feed
|
| 11 |
*/
|
| 12 |
function revisions_rss_handler(&$node) {
|
| 13 |
if ($output = revisions_rss_node_feed($node->nid)) {
|
| 14 |
print $output;
|
| 15 |
|
| 16 |
return;
|
| 17 |
}
|
| 18 |
|
| 19 |
drupal_not_found();
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Publish a feed for all revisions of a specific node
|
| 24 |
*
|
| 25 |
* @return bool True if successful in generating a feed, false otherwise.
|
| 26 |
*/
|
| 27 |
function revisions_rss_node_feed($nid) {
|
| 28 |
global $base_url;
|
| 29 |
|
| 30 |
$node = node_load($nid);
|
| 31 |
|
| 32 |
if (revision_rss_check_type($node)) {
|
| 33 |
$items = revisions_rss_get_revisions($node->nid);
|
| 34 |
|
| 35 |
$namespaces = array();
|
| 36 |
|
| 37 |
$channel = array(
|
| 38 |
'title' => t('@site - Updates for "@title"', array(
|
| 39 |
'@site' => variable_get('site_name', 'Drupal'),
|
| 40 |
'@title' => $node->title)),
|
| 41 |
'description' => t('Updates for "@title"', array('@title' => $node->title)),
|
| 42 |
'link' => url('node/{$node->nid}', array('absolute' => TRUE)),
|
| 43 |
);
|
| 44 |
|
| 45 |
return revisions_rss_format_feed($items, $channel, $namespaces);
|
| 46 |
}
|
| 47 |
else {
|
| 48 |
return FALSE;
|
| 49 |
}
|
| 50 |
}
|
| 51 |
|
| 52 |
/**
|
| 53 |
* Format and print a revision feed.
|
| 54 |
*
|
| 55 |
* @param $items string The individual RSS items.
|
| 56 |
* @param $channel array The channels present in the RSS.
|
| 57 |
* @param $namespaces array The namespaces present in the RSS.
|
| 58 |
*/
|
| 59 |
function revisions_rss_format_feed($items, $channel = array(), $namespaces = array()) {
|
| 60 |
global $base_url, $locale;
|
| 61 |
|
| 62 |
$channel_defaults = array(
|
| 63 |
'version' => '2.0',
|
| 64 |
'title' => t('@site_name - Updates', array('@site_name' => variable_get('site_name', 'Drupal'))),
|
| 65 |
'link' => $base_url,
|
| 66 |
'description' => t('Updates'),
|
| 67 |
'language' => $locale);
|
| 68 |
$channel = array_merge($channel_defaults, $channel);
|
| 69 |
$namespaces = array_merge(array('xmlns:dc="http://purl.org/dc/elements/1.1/"'), $namespaces);
|
| 70 |
|
| 71 |
$output = '<?xml version="1.0" encoding="utf-8"?>'."\n";
|
| 72 |
$output .= '<rss version="'. $channel['version'] .'" xml:base="'. $base_url .'" '. implode(' ', $namespaces) .">\n";
|
| 73 |
$output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']);
|
| 74 |
$output .= "</rss>\n";
|
| 75 |
|
| 76 |
drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
|
| 77 |
|
| 78 |
return $output;
|
| 79 |
}
|
| 80 |
|
| 81 |
/**
|
| 82 |
* Takes a node ID and generates the rss for that nodes revisions.
|
| 83 |
*
|
| 84 |
* @param $nid int The node ID of the note to generate RSS for.
|
| 85 |
* @return The generated RSS.
|
| 86 |
*/
|
| 87 |
function revisions_rss_get_revisions($nid) {
|
| 88 |
global $base_url;
|
| 89 |
|
| 90 |
$items = '';
|
| 91 |
|
| 92 |
$sql = "SELECT nr.nid
|
| 93 |
, n.title
|
| 94 |
, nr.uid
|
| 95 |
, nr.vid
|
| 96 |
, n.vid AS latest
|
| 97 |
, nr.log
|
| 98 |
, nr.timestamp
|
| 99 |
FROM {node_revisions} nr
|
| 100 |
INNER JOIN {node} n
|
| 101 |
ON nr.nid = n.nid
|
| 102 |
WHERE nr.nid = '$nid'
|
| 103 |
ORDER BY nr.timestamp DESC";
|
| 104 |
|
| 105 |
$nodes = db_query_range(db_rewrite_sql($sql), 0, variable_get('feed_default_items', 10));
|
| 106 |
|
| 107 |
while ($node = db_fetch_object($nodes)) {
|
| 108 |
$user = user_load(array('uid' => $node->uid));
|
| 109 |
$node->name = $user->name;
|
| 110 |
|
| 111 |
if (!empty( $node->log)) {
|
| 112 |
$node->description = "Log: {$node->log}\n\n";
|
| 113 |
}
|
| 114 |
|
| 115 |
$node->description .= "Updated by: {$user->name}\n\n";
|
| 116 |
|
| 117 |
$extra = array(
|
| 118 |
array(
|
| 119 |
'key' => 'pubDate',
|
| 120 |
'value' => date('r', $node->timestamp)),
|
| 121 |
array(
|
| 122 |
'key' => 'dc:creator',
|
| 123 |
'value' => $node->name),
|
| 124 |
array(
|
| 125 |
'key' => 'guid',
|
| 126 |
'value' => t("Update !vid at !base/node/!nid", array('!vid' => $node->vid,
|
| 127 |
'!base' => $base_url,
|
| 128 |
'!nid' => $node->nid)),
|
| 129 |
'attributes' => array('isPermaLink' => 'false'))
|
| 130 |
);
|
| 131 |
|
| 132 |
if (module_exists('diff') && $node->vid != $node->latest) {
|
| 133 |
$node->description .= l("Diff vs Newest", "node/{$node->nid}/revisions/view/{$node->vid}/{$node->latest}");
|
| 134 |
}
|
| 135 |
|
| 136 |
$link = url("node/{$node->nid}", array('absolute' => TRUE));
|
| 137 |
|
| 138 |
$items .= format_rss_item($node->title, $link, check_markup($node->description, $node->format, FALSE), $extra);
|
| 139 |
}
|
| 140 |
|
| 141 |
return $items;
|
| 142 |
}
|