4 * Generates an RSS feed from a page's associated SVN log
6 class XHTMLCompiler_DOMFilter_RSSFromSVN
extends XHTMLCompiler_DOMFilter
9 protected $name = 'RSSFromSVN';
12 * Number of log entries to display
14 protected $limit = 10;
17 * Description of changelog to place in RSS feed title
19 protected $description = 'Subversion changelog for %s';
22 * Compact title to place in <link> and other places
24 protected $title = 'Changelog for %s';
26 protected $xcAttr = array('rss-from-svn');
28 public function process(DOMDocument
$dom, $page, $manager) {
30 $xc = XHTMLCompiler
::getInstance();
31 $viewvc_url = $xc->getConf('viewvc_url');
33 // see if we need to make the link ourself
34 $trigger = $this->confiscateAttr($dom->documentElement
, $this->ns
, 'rss-from-svn');
35 if ($trigger == 'yes') {
36 // alright, set it up ourselves
37 $link = $dom->createElement('link');
38 $link->setAttribute('rel', 'alternate');
39 $link->setAttribute('type', 'application/rss+xml');
40 $link->setAttribute('title', str_replace('%s', $page->getCachePath(), $this->title
));
41 $link->setAttribute('href', $page->getPathStem() . '.rss');
42 $head = $this->query('//html:head')->item(0);
43 $head->appendChild($link);
45 // grab the document's links to RSS feeds
46 // link must be marked with xc:rss-from-svn
48 $link = $this->query('//html:link[@xc:rss-from-svn]')->item(0);
49 if (!$link) return; // nothing to do
51 $trigger = $this->confiscateAttr($link, $this->ns
, 'rss-from-svn');
52 if ($trigger != 'yes') return;
55 $path = $page->getWebPath();
57 $rss = new XHTMLCompiler_RSSFeed(
58 $link->getAttribute('title'),
60 str_replace('%s', $page->getCachePath(), $this->description
),
61 $dom->documentElement
->getAttribute('xml:lang')
64 // must be accessible by this script, but not necessarily the
66 $url = $page->getSVNHeadURLMunged();
69 // file is not versioned, fail silently: it might work later
73 // Extension not enabled, fail silently
74 if (!function_exists('svn_log')) return;
75 $logs = svn_log_limit($url, $this->limit
, $page);
77 $page_link = $page->getWebPath();
79 date_default_timezone_set('UTC');
80 foreach ($logs as $log) {
81 // link to ViewVC snapshot if possible
83 $item_link = $viewvc_url . '/' . $page->getSourcePath() .
84 '?r1=' . ($log['rev'] - 1) . '&r2=' . $log['rev'];
86 $item_link = $page_link . '#svn_r' . $log['rev'];
88 // generate short message (first line) for title
89 $lines = explode("\n", wordwrap($log['msg'], 40));
90 $short_msg = $lines[0];
94 'Revision ' . $log['rev'] . ': ' . htmlspecialchars($short_msg),
95 $d = gmdate('r', strtotime($log['date'])),
96 htmlspecialchars($log['msg'])
101 $page->normalizePath(
102 $link->getAttribute('href')