Mark Subversion related classes as deprecated.
[xhtml-compiler.git] / XHTMLCompiler / DOMFilter / RSSFromSVN.php
blob18620173ae4ce37e0b3fb7d3427f7a5b5a282b33
1 <?php
3 /**
4 * Generates an RSS feed from a page's associated SVN log
5 * @deprecated
6 */
7 class XHTMLCompiler_DOMFilter_RSSFromSVN extends XHTMLCompiler_DOMFilter
10 protected $name = 'RSSFromSVN';
12 /**
13 * Number of log entries to display
15 protected $limit = 10;
17 /**
18 * Description of changelog to place in RSS feed title
20 protected $description = 'Subversion changelog for %s';
22 /**
23 * Compact title to place in <link> and other places
25 protected $title = 'Changelog for %s';
27 protected $xcAttr = array('rss-from-svn');
29 public function process(DOMDocument $dom, $page, $manager) {
31 $xc = XHTMLCompiler::getInstance();
32 $viewvc_url = $xc->getConf('viewvc_url');
34 // see if we need to make the link ourself
35 $trigger = $this->confiscateAttr($dom->documentElement, $this->ns, 'rss-from-svn');
36 if ($trigger == 'yes') {
37 // alright, set it up ourselves
38 $link = $dom->createElement('link');
39 $link->setAttribute('rel', 'alternate');
40 $link->setAttribute('type', 'application/rss+xml');
41 $link->setAttribute('title', str_replace('%s', $page->getCachePath(), $this->title));
42 $link->setAttribute('href', $page->getPathStem() . '.rss');
43 $head = $this->query('//html:head')->item(0);
44 $head->appendChild($link);
45 } else {
46 // grab the document's links to RSS feeds
47 // link must be marked with xc:rss-from-svn
48 // only one allowed
49 $link = $this->query('//html:link[@xc:rss-from-svn]')->item(0);
50 if (!$link) return; // nothing to do
52 $trigger = $this->confiscateAttr($link, $this->ns, 'rss-from-svn');
53 if ($trigger != 'yes') return;
56 $path = $page->getWebPath();
58 $rss = new XHTMLCompiler_RSSFeed(
59 $link->getAttribute('title'),
60 $path,
61 str_replace('%s', $page->getCachePath(), $this->description),
62 $dom->documentElement->getAttribute('xml:lang')
65 // must be accessible by this script, but not necessarily the
66 // general public
67 $url = $page->getSVNHeadURLMunged();
69 if (!$url) {
70 // file is not versioned, fail silently: it might work later
71 return;
74 // Extension not enabled, fail silently
75 if (!function_exists('svn_log')) return;
76 $logs = svn_log_limit($url, $this->limit, $page);
78 $page_link = $page->getWebPath();
80 date_default_timezone_set('UTC');
81 foreach ($logs as $log) {
82 // link to ViewVC snapshot if possible
83 if ($viewvc_url) {
84 $item_link = $viewvc_url . '/' . $page->getSourcePath() .
85 '?r1=' . ($log['rev'] - 1) . '&r2=' . $log['rev'];
86 } else {
87 $item_link = $page_link . '#svn_r' . $log['rev'];
89 // generate short message (first line) for title
90 $lines = explode("\n", wordwrap($log['msg'], 40));
91 $short_msg = $lines[0];
93 $rss->addItem(
94 $item_link,
95 'Revision ' . $log['rev'] . ': ' . htmlspecialchars($short_msg),
96 $d = gmdate('r', strtotime($log['date'])),
97 htmlspecialchars($log['msg'])
101 $rss->save(
102 $page->normalizePath(
103 $link->getAttribute('href')