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 if (!function_exists('svn_log')) {
52 throw new Exception('RSSFromSVN requires the svn extension');
55 $trigger = $this->confiscateAttr($link, $this->ns
, 'rss-from-svn');
56 if ($trigger != 'yes') return;
59 $path = $page->getWebPath();
61 $rss = new XHTMLCompiler_RSSFeed(
62 $link->getAttribute('title'),
64 str_replace('%s', $page->getCachePath(), $this->description
),
65 $dom->documentElement
->getAttribute('xml:lang')
68 // must be accessible by this script, but not necessarily the
70 $url = $page->getSVNHeadURLMunged();
73 // file is not versioned, fail silently: it might work later
77 $logs = svn_log_limit($url, $this->limit
, $page);
79 $page_link = $page->getWebPath();
81 date_default_timezone_set('UTC');
82 foreach ($logs as $log) {
83 // link to ViewVC snapshot if possible
85 $item_link = $viewvc_url . '/' . $page->getSourcePath() .
86 '?r1=' . ($log['rev'] - 1) . '&r2=' . $log['rev'];
88 $item_link = $page_link . '#svn_r' . $log['rev'];
90 // generate short message (first line) for title
91 $lines = explode("\n", wordwrap($log['msg'], 40));
92 $short_msg = $lines[0];
96 'Revision ' . $log['rev'] . ': ' . htmlspecialchars($short_msg),
97 $d = gmdate('r', strtotime($log['date'])),
98 htmlspecialchars($log['msg'])
103 $page->normalizePath(
104 $link->getAttribute('href')