*/ /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_blog_archive extends DokuWiki_Syntax_Plugin { function getType() { return 'substition'; } function getPType() { return 'block'; } function getSort() { return 309; } function connectTo($mode) { $this->Lexer->addSpecialPattern('\{\{archive>.*?\}\}', $mode, 'plugin_blog_archive'); } function handle($match, $state, $pos, Doku_Handler $handler) { global $ID; $match = substr($match, 10, -2); // strip {{archive> from start and }} from end list($match, $flags) = explode('&', $match, 2); $flags = explode('&', $flags); list($match, $refine) = explode(' ', $match, 2); list($ns, $rest) = explode('?', $match, 2); $author = NULL; foreach($flags as $i=>$flag) { if(preg_match('/(\w+)\s*=(.+)/', $flag, $temp) == 1) { if ($temp[1] == 'author') { $author = trim($temp[2]); unset($flags[$i]); } } } if (!$rest) { $rest = $ns; $ns = ''; } if ($ns == '') $ns = cleanID($this->getConf('namespace')); elseif (($ns == '*') || ($ns == ':')) $ns = ''; elseif ($ns == '.') $ns = getNS($ID); else $ns = cleanID($ns); // daily archive if (preg_match("/\d{4}-\d{2}-\d{2}/", $rest)) { list($year, $month, $day) = explode('-', $rest, 3); $start = mktime(0, 0, 0, $month, $day, $year); $end = $start + 24*60*60; // monthly archive } elseif (preg_match("/\d{4}-\d{2}/", $rest)) { list($year, $month) = explode('-', $rest, 2); // calculate start and end times $nextmonth = $month + 1; $year2 = $year; if ($nextmonth > 12) { $nextmonth = 1; $year2 = $year + 1; } $start = mktime(0, 0, 0, $month, 1, $year); $end = mktime(0, 0, 0, $nextmonth, 1, $year2); // a whole year } elseif (preg_match("/\d{4}/", $rest)) { $start = mktime(0, 0, 0, 1, 1, $rest); $end = mktime(0, 0, 0, 1, 1, $rest + 1); // all entries from that namespace up to now } elseif ($rest == '*') { $start = 0; $end = PHP_INT_MAX; // unknown format } else { return false; } return array($ns, $start, $end, $flags, $refine, $author); } function render($mode, Doku_Renderer $renderer, $data) { list($ns, $start, $end, $flags, $refine, $author) = $data; // get the blog entries for our namespace /** @var helper_plugin_blog $my */ if ($my = plugin_load('helper', 'blog')) $entries = $my->getBlog($ns, NULL, $author); else return false; // use tag refinements? if ($refine) { /** @var helper_plugin_tag $tag */ if (plugin_isdisabled('tag') || (!$tag = plugin_load('helper', 'tag'))) { msg($this->getLang('missing_tagplugin'), -1); } else { $entries = $tag->tagRefine($entries, $refine); } } if (!$entries) return true; // nothing to display if ($mode == 'xhtml') { if ($this->getConf('showhistogram')) { $alt_list = $this->_build_alternative_list($start, $end, $entries); // Add histogram and posts list $renderer->doc .= '
'; $max_months = $this->getConf('max_months'); $histogram_height = $this->getConf('histogram_height'); $histogram_count = array_reverse($histogram_count); $month_count = 0; foreach ($histogram_count as $key => $month_reference) { // Check the max_months parameter if ($month_count >= $max_months) { break; } if ($month_reference > 0) { // Height in "px" $current_height = $histogram_height / $histogram_higher * $month_reference; } else { // Height in "px" $current_height = 1; } // Generate the alt attribute $alt = $key.': '.$month_reference.' '; if ($month_reference > 1) { $alt .= $this->getLang('entries'); } else { $alt .= $this->getLang('entry'); } $histogram .= ''; $histogram .= '' . DOKU_LF; $month_count += 1; } $histogram .= '
'; return $histogram; } } // vim:ts=4:sw=4:et:enc=utf-8: