From f4ae26c8ce0f56c658426d17e81c37fe138915d0 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 27 Jul 2008 11:45:38 -0600 Subject: [PATCH] Add support for custom limits and headers in News. Signed-off-by: Edward Z. Yang --- XHTMLCompiler/DOMFilter/News.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/XHTMLCompiler/DOMFilter/News.php b/XHTMLCompiler/DOMFilter/News.php index 2997151..311c1e9 100644 --- a/XHTMLCompiler/DOMFilter/News.php +++ b/XHTMLCompiler/DOMFilter/News.php @@ -4,7 +4,8 @@ * Mini blog-style filter for globbing contents of another directory * and inserting summaries into a main page. * @note This filter should be run before other "cosmetic" filters, as - * it makes major changes to page content. + * it makes major changes to page content and may pull data from + * sources that have not been processed yet. */ class XHTMLCompiler_DOMFilter_News extends XHTMLCompiler_DOMFilter { @@ -13,27 +14,37 @@ class XHTMLCompiler_DOMFilter_News extends XHTMLCompiler_DOMFilter public function process(DOMDocument $dom, $page, $manager) { $container = $this->query("//html:div[@news:source]")->item(0); if (!$container) return; + + // Grab variables $source = $this->confiscateAttr($container, $this->ns, 'source'); $source = $page->normalizePath($source); + $limit = $this->confiscateAttr($container, $this->ns, 'limit'); + if (!$limit) $limit = 5; + $header = $this->confiscateAttr($container, $this->ns, 'header'); + if (!$header) $header = 'h2'; + + // Recursively glob for source files // :TODO: add DI for this $fs = new FSTools(); - $xc = XHTMLCompiler::getInstance(); $result = $fs->globr($source, '*.xhtml'); rsort($result); + + // Setup manager + $xc = XHTMLCompiler::getInstance(); $manager = $xc->getFilterManager(); - // :TODO: Make this limit configurable - for ($i = $d = 0, $c = count($result); $i < $c && $d < 5; $i++) { - // Test if it matches DDDD-, otherwise ignore (it's a big/legacy entry). - + + for ($i = $d = 0, $c = count($result); $i < $c && $d < $limit; $i++) { $entry = $result[$i]; - // :TODO: Add support for nested directories + // :TODO: Add support for nested directories. Also need to modify + // generateId when that happens. $base = basename($entry); if (strlen($base) < 4 || !ctype_digit(substr($base, 0, 4))) { continue; } $entryFile = new XHTMLCompiler_Page($entry); + // This DOM has IDs setup, but no other processing setup. $subdom = $manager->parse($entryFile->getSource(), $entryFile); $entryNode = $dom->createElement('div'); @@ -46,10 +57,10 @@ class XHTMLCompiler_DOMFilter_News extends XHTMLCompiler_DOMFilter // Grab the title $node = $subdom->getElementsByTagName('h1')->item(0); $h1 = $dom->importNode($node, true); - $h2 = $dom->createElement('h2'); - $h2->setAttribute('class', 'title'); - foreach ($h1->childNodes as $h1node) $h2->appendChild($h1node); - $entryNode->appendChild($h2); + $hx = $dom->createElement($header); + $hx->setAttribute('class', 'title'); + foreach ($h1->childNodes as $h1node) $hx->appendChild($h1node); + $entryNode->appendChild($hx); // Possible place for factoring out. Also, we can also add // a timezone to be more like ours. -- 2.11.4.GIT