Switch from snapshot to diff. This nukes the description, but is far more useful...
[htmlpurifier-web.git] / xhtml-compiler / XHTMLCompiler / DOMFilter / RSSFromSVN.php
blob0841053b2d36bcc756c5925bc1c5b09cfe360996
1 <?php
3 class XHTMLCompiler_DOMFilter_RSSFromSVN extends XHTMLCompiler_DOMFilter
6 protected $name = 'RSSFromSVN';
7 protected $limit = 10;
9 protected $description = 'Subversion changelog for %s';
11 // xc:rss-from-svn="yes" on meta element to activate this feature
13 public function process(DOMDocument $dom, $page, $manager) {
15 $xc = XHTMLCompiler::getInstance();
16 $viewvc_url = $xc->getConf('viewvc_url');
18 // grab the document's links to RSS feeds
19 // link must be marked with xc:rss-from-svn
20 // only one allowed
21 $link = $this->query('//html:link[@xc:rss-from-svn]')->item(0);
23 if (!$link) return; // nothing to do
25 if (!function_exists('svn_log')) {
26 throw new Exception('RSSFromSVN requires the svn extension');
29 $trigger = $this->confiscateAttr($link, $this->ns, 'rss-from-svn');
30 if ($trigger != 'yes') return;
32 $path = $page->getWebPath();
34 $rss = new XHTMLCompiler_RSSFeed(
35 $link->getAttribute('title'),
36 $path,
37 str_replace('%s', $page->getCachePath(), $this->description),
38 $dom->documentElement->getAttribute('xml:lang')
41 $url = $page->getSVNHeadURL();
42 if (!$url) {
43 // file is not versioned, fail silently: it might work later
44 return;
47 $logs = svn_log_limit($url, $this->limit, $page);
49 $page_link = $page->getWebPath();
51 date_default_timezone_set('UTC');
52 foreach ($logs as $log) {
53 // link to ViewVC snapshot if possible
54 if ($viewvc_url) {
55 $item_link = $viewvc_url . '/' . $page->getSourcePath() .
56 '?r1=' . ($log['rev'] - 1) . '&r2=' . $log['rev'];
57 } else {
58 $item_link = $page_link . '#svn_r' . $log['rev'];
60 // generate short message (first line) for title
61 $lines = explode("\n", wordwrap($log['msg'], 40));
62 $short_msg = $lines[0];
64 $rss->addItem(
65 $item_link,
66 'Revision ' . $log['rev'] . ': ' . htmlspecialchars($short_msg),
67 $d = gmdate('r', strtotime($log['date'])),
68 htmlspecialchars($log['msg'])
72 $rss->save(
73 $page->normalizePath(
74 $link->getAttribute('href')