4 * GEnerates an RSS feed from a page's associated Git log.
6 class XHTMLCompiler_DOMFilter_RSSFromGit
extends XHTMLCompiler_DOMFilter
8 protected $name = 'RSSFromGit';
9 /** Number of log entries to display */
10 protected $limit = 10;
11 /** Description of changelog to place in feed title */
12 protected $description = 'Git changelog for %s';
13 /** Compact title to place in <link> and other places */
14 protected $title = 'Log for %s';
15 protected $xcAttr = array('rss-from-git');
17 public function process(DOMDocument
$dom, $page, $manager) {
18 $xc = XHTMLCompiler
::getInstance();
19 // implement gitweb/repo.or.cz support
21 $logs = $page->getLog();
23 // see if we need to make the link ourself
24 $trigger = $this->confiscateAttr($dom->documentElement
, $this->ns
, 'rss-from-git');
25 if ($trigger == 'yes') {
26 // this shows up twice because we have to perform all
27 // confiscations before aborting
29 $link = $dom->createElement('link');
30 $link->setAttribute('rel', 'alternate');
31 $link->setAttribute('type', 'application/rss+xml');
32 $link->setAttribute('title', str_replace('%s', $page->getCachePath(), $this->title
));
33 $link->setAttribute('href', $page->getPathStem() . '.rss');
34 $head = $this->query('//html:head')->item(0);
35 $head->appendChild($link);
37 // grab the document's links to RSS feeds
38 // link must be marked with xc:rss-from-svn
40 $link = $this->query('//html:link[@xc:rss-from-svn]')->item(0);
41 if (!$link) return; // nothing to do
43 $trigger = $this->confiscateAttr($link, $this->ns
, 'rss-from-svn');
44 if ($trigger != 'yes') return;
48 $path = $page->getWebPath();
50 $rss = new XHTMLCompiler_RSSFeed(
51 $link->getAttribute('title'),
53 str_replace('%s', $page->getCachePath(), $this->description
),
54 $dom->documentElement
->getAttribute('xml:lang')
57 for ($i = 0; $i < $this->limit
&& isset($logs[$i]); $i++
) {
60 // :TODO: link to gitweb commitdiff
61 $item_link = $path . '#git_' . $commit->id
;
63 // generate short message (first line) for title\
67 htmlspecialchars($commit->message
),
68 $d = $commit->committedDate
->format('r'),
69 // :TODO: Extend phpgit so that we can retrieve full message
70 htmlspecialchars($commit->message
)
76 $link->getAttribute('href')