4 * This filter, closely related with the News filter, generates links
5 * between news entries.
7 class XHTMLCompiler_DOMFilter_NewsLinker
extends XHTMLCompiler_DOMFilter
9 protected $name = 'NewsLinker';
10 public function process(DOMDocument
$dom, $page, $manager) {
11 if (!isset($page->attr
['news'])) return;
13 // calculate forward and backward links
15 // we assume that one directory up is the years directory. An alternate
16 // algorithm may be needed if we decide to allow further nesting.
17 // This code needs to be factored out
18 $result = $fs->globr(dirname($page->getDirname()), '*.xhtml');
19 // This doesn't work if there is more than one entry in a day
23 foreach ($result as $i => $entry) {
24 $base = basename($entry);
25 if (strlen($base) < 4 ||
!ctype_digit(substr($base, 0, 4))) {
28 if ($page->getSourcePath() == $entry) {
38 $body = $dom->getElementsByTagName('body')->item(0);
39 $nav = $dom->createElement('div');
40 $nav->setAttribute('id', 'news-navigation');
43 $prevPage = new XHTMLCompiler_Page($prev);
44 if (!$page->isCacheExistent()) {
45 // Force a new cache run
48 $prevDiv = $dom->createElement('div');
49 $prevDiv->setAttribute('class', 'prev');
50 $a = $dom->createElement('a', 'Previous');
51 $a->setAttribute('href', $prevPage->getAbsolutePath());
52 $prevDiv->appendChild($a);
53 $nav->appendchild($prevDiv);
56 $indexDiv = $dom->createElement('div');
57 $indexDiv->setAttribute('class', 'index');
58 $a = $dom->createElement('a', 'Index');
59 $indexDiv->appendChild($a);
60 //$nav->appendChild($indexDiv);
63 $nextPage = new XHTMLCompiler_Page($next);
64 $nextDiv = $dom->createElement('div');
65 $nextDiv->setAttribute('class', 'next');
66 $a = $dom->createElement('a', 'Next');
67 $a->setAttribute('href', $nextPage->getAbsolutePath());
68 $nextDiv->appendChild($a);
69 $nav->appendChild($nextDiv);
72 $body->appendChild($nav);