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 $content = $dom->getElementById('content');
39 $body = $content->parentNode
;
40 $nav = $dom->createElement('div');
41 $nav->setAttribute('id', 'news-navigation');
44 $prevPage = new XHTMLCompiler_Page($prev);
45 if (!$page->isCacheExistent()) {
46 // Force a new cache run
49 $prevDiv = $dom->createElement('div');
50 $prevDiv->setAttribute('class', 'prev');
51 $a = $dom->createElement('a', 'Previous');
52 $a->setAttribute('href', $prevPage->getAbsolutePath());
53 $prevDiv->appendChild($a);
54 $nav->appendchild($prevDiv);
57 $indexDiv = $dom->createElement('div');
58 $indexDiv->setAttribute('class', 'index');
59 $a = $dom->createElement('a', 'Index');
60 $indexDiv->appendChild($a);
61 //$nav->appendChild($indexDiv);
64 $nextPage = new XHTMLCompiler_Page($next);
65 $nextDiv = $dom->createElement('div');
66 $nextDiv->setAttribute('class', 'next');
67 $a = $dom->createElement('a', 'Next');
68 $a->setAttribute('href', $nextPage->getAbsolutePath());
69 $nextDiv->appendChild($a);
70 $nav->appendChild($nextDiv);
73 $body->appendChild($nav);