diff options
Diffstat (limited to 'platform/www/lib/plugins/blog/syntax')
-rw-r--r-- | platform/www/lib/plugins/blog/syntax/archive.php | 245 | ||||
-rw-r--r-- | platform/www/lib/plugins/blog/syntax/autoarchive.php | 157 | ||||
-rw-r--r-- | platform/www/lib/plugins/blog/syntax/blog.php | 213 | ||||
-rw-r--r-- | platform/www/lib/plugins/blog/syntax/draft.php | 33 |
4 files changed, 648 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/blog/syntax/archive.php b/platform/www/lib/plugins/blog/syntax/archive.php new file mode 100644 index 0000000..751a4a6 --- /dev/null +++ b/platform/www/lib/plugins/blog/syntax/archive.php @@ -0,0 +1,245 @@ +<?php +/** + * Archive Plugin: displays links to all wiki pages from a given month + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Esther Brunner <wikidesign@gmail.com> + */ + +/** + * 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 .= '<div class="level1">'; + $renderer->doc .= '<h1>' . $this->getLang('archive_title') . '</h1>'; + $renderer->doc .= $alt_list; + $renderer->doc .= '</div>' . DOKU_LF; + } else { + // let Pagelist Plugin do the work for us + if (plugin_isdisabled('pagelist') + || (!$pagelist = plugin_load('helper', 'pagelist'))) { + msg($this->getLang('missing_pagelistplugin'), -1); + return false; + } + /** @var helper_plugin_pagelist $pagelist */ + $pagelist->setFlags($flags); + $pagelist->startList(); + foreach ($entries as $entry) { + + // entry in the right date range? + if (($start > $entry['date']) || ($entry['date'] >= $end)) continue; + + $pagelist->addPage($entry); + } + $renderer->doc .= $pagelist->finishList(); + } + return true; + + // for metadata renderer + } elseif ($mode == 'metadata') { + /** @var Doku_Renderer_metadata $renderer */ + // use the blog plugin cache handler in order to ensure that the cache is expired whenever a page, comment + // or linkback is added + if (time() < $end) $renderer->meta['plugin_blog']['purgefile_cache'] = true; + + foreach ($entries as $entry) { + + // entry in the right date range? + if (($start > $entry['date']) || ($entry['date'] >= $end)) continue; + + $renderer->meta['relation']['references'][$entry['id']] = true; + $renderer->meta['plugin_blog']['archive_pages'][] = $entry['id']; + } + + return true; + } + return false; + } + + // Generate alternative posts list + function _build_alternative_list($start, $end, $entries) { + $current_year =''; + $current_month =''; + $ul_open = false; + + $histogram_count = array(); + $histogram_higher = 0; + + $list = ''; + foreach ($entries as $entry) { + // entry in the right date range? + if (($start > $entry['date']) || ($entry['date'] >= $end)) continue; + + if ($current_year != date('o',$entry['date'])) { + if ($ul_open) { + $list .= '</ul>' . DOKU_LF; + $ul_open = false; + } + $current_year = date('o',$entry['date']); + $list .= '<h2>' . $current_year . '</h2>' . DOKU_LF; + $current_month = ''; + } + if ($current_month != date('m',$entry['date'])) { + if ($ul_open) { + $list .= '</ul>' . DOKU_LF; + } + $current_month = date('m',$entry['date']); + $list .= '<h3 id="m' . date('o-m',$entry['date']) . '">' . $this->getLang('month_' . $current_month) . '</h3><ul>' . DOKU_LF; + $ul_open = true; + } + $histogram_count[date('o-m',$entry['date'])] += 1; + if ($histogram_higher < $histogram_count[date('o-m',$entry['date'])]) { + $histogram_higher = $histogram_count[date('o-m',$entry['date'])]; + } + $list .= '<li>' . date('d',$entry['date']) . ' - <a href="' . wl($entry['id']) . '" title="' . $entry['id'] . '">' . $entry['title'] . '</a></li>' . DOKU_LF; + } + $list .= '</ul>' . DOKU_LF; + + $histogram = $this->_build_histogram($histogram_count, $histogram_higher); + + return $histogram . $list; + } + + // Generate histogram + function _build_histogram($histogram_count, $histogram_higher) { + if (empty($histogram_count)) return ''; + + $histogram = '<p>'; + $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 .= '<a href="#m' . $key . '" title="' . $alt . '">'; + $histogram .= '<img class="blog_archive_bar" alt="' . $alt . '" style="height: ' . $current_height . 'px;" src="'.DOKU_BASE.'lib/images/blank.gif"/></a>' . DOKU_LF; + $month_count += 1; + } + $histogram .= '</p>'; + + return $histogram; + } + +} +// vim:ts=4:sw=4:et:enc=utf-8: diff --git a/platform/www/lib/plugins/blog/syntax/autoarchive.php b/platform/www/lib/plugins/blog/syntax/autoarchive.php new file mode 100644 index 0000000..34cb240 --- /dev/null +++ b/platform/www/lib/plugins/blog/syntax/autoarchive.php @@ -0,0 +1,157 @@ +<?php +/** + * Dynamic Archive Plugin: dynamically displays + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Esther Brunner <wikidesign@gmail.com> + */ + +/** + * All DokuWiki plugins to extend the parser/rendering mechanism + * need to inherit from this class + */ +class syntax_plugin_blog_autoarchive extends DokuWiki_Syntax_Plugin { + + function getType() { return 'substition'; } + function getPType() { return 'block'; } + function getSort() { return 309; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern('\{\{autoarchive>.*?\}\}', $mode, 'plugin_blog_autoarchive'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + global $ID; + + $match = substr($match, 14, -2); // strip {{autoarchive> from start and }} from end + list($match, $flags) = explode('?', $match, 2); + $flags = explode('&', $flags); + list($ns, $refine) = explode(' ', $match, 2); + + if ($ns == '') $ns = cleanID($this->getConf('namespace')); + elseif (($ns == '*') || ($ns == ':')) $ns = ''; + elseif ($ns == '.') $ns = getNS($ID); + else $ns = cleanID($ns); + + return array($ns, $flags, $refine, $pos); + } + + function render($mode, Doku_Renderer $renderer, $data) { + list($ns, $flags, $refine, $pos) = $data; + if ($mode != 'xhtml') return false; + + // no caching for dynamic content + $renderer->nocache(); + + // get the blog entries for our namespace + if ($my = plugin_load('helper', 'blog')) $entries = $my->getBlog($ns); + + // use tag refinements? + if ($refine) { + 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 + + // what to display + if(preg_match('/^\d\d\d\d-\d\d$/',$_REQUEST['blogarchive'])){ + $now = $_REQUEST['blogarchive']; + }else{ + $now = strftime('%Y-%m'); // current month + } + list($y,$m) = explode('-',$now); + + // display the archive overview + $cnt = $this->_buildTimeChooser($renderer, $entries, $now); + + $renderer->header($this->_posts($cnt,$m,$y),2,$pos); + $renderer->section_open(2); + + // let Pagelist Plugin do the work for us + if (plugin_isdisabled('pagelist') + || (!$pagelist = plugin_load('helper', 'pagelist'))) { + msg($this->getLang('missing_pagelistplugin'), -1); + return false; + } + $pagelist->setFlags($flags); + $pagelist->startList(); + foreach ($entries as $entry) { + $date = strftime('%Y-%m',$entry['date']); + // entry in the right date range? + if($date < $now || $date > $now) continue; + $pagelist->addPage($entry); + } + $renderer->doc .= $pagelist->finishList(); + + $renderer->section_close(); + return true; + + } + + /** + * Creates a list of monthly archive links + * + * @param object reference $R - the XHTML renderer + * @param array reference $entries - all entries metadata + * @param string $now - currently selected month ('YYYY-MM') + * @return int - number of posts for selected month + */ + function _buildTimeChooser(&$R, &$entries, $now){ + global $ID; + + // get the months where posts exist + $months = array(); + foreach($entries as $entry){ + $y = date('Y',$entry['date']); + $m = date('m',$entry['date']); + if(isset($months[$y][$m])) { + $months[$y][$m]++; + }else{ + $months[$y][$m] = 1; + } + } + + $ret = 0; + // output + $R->doc .= '<div class="autoarchive_selector">'; + foreach($months as $y => $mdata){ + $R->listu_open(); + $R->listitem_open(1); + $R->listcontent_open(); + $R->doc .= $y.'<span>:</span>'; + $R->listcontent_close(); + ksort($mdata); + foreach($mdata as $m => $cnt){ + $R->listu_open(); + $R->listitem_open(2); + $R->listcontent_open(); + if("$y-$m" == $now) $R->doc .= '<span class="cur">'; + $R->doc .= '<a href="'.wl($ID,array('blogarchive'=>"$y-$m")).'" class="wikilink1" title="'.$this->_posts($cnt,$m,$y).'">'; + $R->doc .= $this->getLang('month_'.$m); + $R->doc .= '</a>'; + if("$y-$m" == $now){ + $R->doc .= '</span>'; + $ret = $cnt; + } + $R->listcontent_close(); + $R->listitem_close(); + $R->listu_close(); + } + $R->listitem_close(); + $R->listu_close(); + } + $R->doc .='</div>'; + return $ret; + } + + function _posts($num,$month,$year){ + return sprintf($this->getLang('autoarchive'), + $num, $this->getLang("month_$month"), + $year); + } +} +// vim:ts=4:sw=4:et:enc=utf-8: diff --git a/platform/www/lib/plugins/blog/syntax/blog.php b/platform/www/lib/plugins/blog/syntax/blog.php new file mode 100644 index 0000000..2ca56d8 --- /dev/null +++ b/platform/www/lib/plugins/blog/syntax/blog.php @@ -0,0 +1,213 @@ +<?php +/** + * Blog Plugin: displays a number of recent entries from the blog subnamespace + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Esther Brunner <wikidesign@gmail.com> + * @author Robert Rackl <wiki@doogie.de> + */ + +class syntax_plugin_blog_blog extends DokuWiki_Syntax_Plugin { + private $included_pages = array(); + + function getType() { return 'substition'; } + function getPType() { return 'block'; } + function getSort() { return 307; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern('\{\{blog>.*?\}\}',$mode,'plugin_blog_blog'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + global $ID; + + $match = substr($match, 7, -2); // strip {{blog> from start and }} from end + list($match, $flags) = explode('&', $match, 2); + $flags = explode('&', $flags); + array_unshift($flags, 'link'); // always make the first header of a blog entry a permalink (unless nolink is set) + list($match, $refine) = explode(' ', $match, 2); + list($ns, $num) = explode('?', $match, 2); + + if (!is_numeric($num)) { + if (is_numeric($ns)) { + $num = $ns; + $ns = ''; + } else { + $num = 5; + } + } + + if ($ns == '') $ns = cleanID($this->getConf('namespace')); + elseif (($ns == '*') || ($ns == ':')) $ns = ''; + elseif ($ns == '.') $ns = getNS($ID); + else $ns = cleanID($ns); + + return array($ns, $num, $flags, $refine); + } + + function render($mode, Doku_Renderer $renderer, $data) { + list($ns, $num, $flags, $refine) = $data; + + $first = $_REQUEST['first']; + if (!is_numeric($first)) $first = 0; + + // get the blog entries for our namespace + /** @var helper_plugin_blog $my */ + if ($my = plugin_load('helper', 'blog')) $entries = $my->getBlog($ns); + 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); + } + } + + // Normalise flags + $blog_flags = $my->getFlags($flags); + $formpos = $blog_flags['formpos']; + $newentrytitle = $blog_flags['newentrytitle']; + $pagingcontrols = $blog_flags['pagingcontrols']; + + if ($mode == 'xhtml') { + // prevent caching to ensure the included pages are always fresh + $renderer->nocache(); + } + + if (!$entries) { + if ((auth_quickaclcheck($ns.':*') >= AUTH_CREATE) && ($mode == 'xhtml')) { + if($formpos != 'none') $renderer->doc .= $this->_newEntryForm($ns, $newentrytitle); + } + return true; // nothing to display + } + + // slice the needed chunk of pages + $isMore = count($entries) > ($first + $num); + $entries = array_slice($entries, $first, $num); + + // load the include helper plugin + /** @var helper_plugin_include $include */ + if (plugin_isdisabled('include') || (!$include = plugin_load('helper', 'include'))) { + msg($this->getLang('missing_includeplugin'), -1); + return false; + } + + // current section level + $clevel = 0; + + $perm_create = (auth_quickaclcheck($ns.':*') >= AUTH_CREATE); + $include_flags = $include->get_flags($flags); + + if ($mode == 'xhtml') { + // show new entry form + if ($perm_create && $formpos == 'top') { + $renderer->doc .= $this->_newEntryForm($ns, $newentrytitle); + } + + // get current section level + preg_match_all('|<div class="level(\d)">|i', $renderer->doc, $matches, PREG_SET_ORDER); + $n = count($matches)-1; + if ($n > -1) $clevel = $matches[$n][1]; + + // close current section + if ($clevel && !$include_flags['inline']) $renderer->doc .= '</div>'.DOKU_LF; + $renderer->doc .= '<div class="hfeed">'.DOKU_LF; + } + + + // now include the blog entries + foreach ($entries as $entry) { + if ($mode == 'xhtml' || $mode == 'code') { + if(auth_quickaclcheck($entry['id']) >= AUTH_READ) { + // prevent blog include loops + if(!$this->included_pages[$entry['id']]) { + $this->included_pages[$entry['id']] = true; + $renderer->nest($include->_get_instructions($entry['id'], '', 'page', $clevel, $include_flags)); + $this->included_pages[$entry['id']] = false; + } + } + } elseif ($mode == 'metadata') { + /** @var Doku_Renderer_metadata $renderer */ + $renderer->meta['relation']['haspart'][$entry['id']] = true; + } + } + + if ($mode == 'xhtml') { + // resume the section + $renderer->doc .= '</div>'.DOKU_LF; + if ($clevel && !$include_flags['inline']) $renderer->doc .= '<div class="level'.$clevel.'">'.DOKU_LF; + + // show older / newer entries links + if ($pagingcontrols) $renderer->doc .= $this->_browseEntriesLinks($isMore, $first, $num); + + // show new entry form + if ($perm_create && $formpos == 'bottom') { + $renderer->doc .= $this->_newEntryForm($ns, $newentrytitle); + } + } + + return in_array($mode, array('xhtml', 'metadata', 'code')); + } + + /* ---------- (X)HTML Output Functions ---------- */ + + /** + * Displays links to older newer entries of the blog namespace + * + * @param $more + * @param $first + * @param $num + * @return string + */ + function _browseEntriesLinks($more, $first, $num) { + global $ID; + + $ret = ''; + $last = $first+$num; + if ($first > 0) { + $first -= $num; + if ($first < 0) $first = 0; + $ret .= '<p class="centeralign">'.DOKU_LF.'<a href="'.wl($ID, 'first='.$first).'"'. + ' class="wikilink1"><< '.$this->getLang('newer').'</a>'; + if ($more) $ret .= ' | '; + else $ret .= '</p>'; + } else if ($more) { + $ret .= '<p class="centeralign">'.DOKU_LF; + } + if ($more) { + $ret .= '<a href="'.wl($ID, 'first='.$last).'" class="wikilink1">'. + $this->getLang('older').' >></a>'.DOKU_LF.'</p>'.DOKU_LF; + } + return $ret; + } + + /** + * Displays a form to enter the title of a new entry in the blog namespace + * and then open that page in the edit mode + * + * @param $ns + * @param $newentrytitle + * @return string + */ + function _newEntryForm($ns, $newentrytitle) { + global $lang; + global $ID; + + return '<div class="newentry_form">'.DOKU_LF. + '<form id="blog__newentry_form" method="post" action="'.script().'" accept-charset="'.$lang['encoding'].'">'.DOKU_LF. + DOKU_TAB.'<fieldset>'.DOKU_LF. + DOKU_TAB.DOKU_TAB.'<legend>'.hsc($newentrytitle).'</legend>'.DOKU_LF. + DOKU_TAB.DOKU_TAB.'<input type="hidden" name="id" value="'.$ID.'" />'.DOKU_LF. + DOKU_TAB.DOKU_TAB.'<input type="hidden" name="do" value="newentry" />'.DOKU_LF. + DOKU_TAB.DOKU_TAB.'<input type="hidden" name="ns" value="'.$ns.'" />'.DOKU_LF. + DOKU_TAB.DOKU_TAB.'<input class="edit" type="text" name="title" id="blog__newentry_title" size="40" tabindex="1" />'.DOKU_LF. + DOKU_TAB.DOKU_TAB.'<input class="button" type="submit" value="'.$lang['btn_create'].'" tabindex="2" />'.DOKU_LF. + DOKU_TAB.'</fieldset>'.DOKU_LF. + '</form>'.DOKU_LF. + '</div>'.DOKU_LF; + } +} +// vim:ts=4:sw=4:et:enc=utf-8: diff --git a/platform/www/lib/plugins/blog/syntax/draft.php b/platform/www/lib/plugins/blog/syntax/draft.php new file mode 100644 index 0000000..239f0c2 --- /dev/null +++ b/platform/www/lib/plugins/blog/syntax/draft.php @@ -0,0 +1,33 @@ +<?php +/** + * Blog Plugin, draft component: marks the current page as draft + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Esther Brunner <wikidesign@gmail.com> + */ + +class syntax_plugin_blog_draft extends DokuWiki_Syntax_Plugin { + + function getType() { return 'substition'; } + function getSort() { return 99; } + + function connectTo($mode) { + $this->Lexer->addSpecialPattern('~~DRAFT~~', $mode, 'plugin_blog_draft'); + } + + function handle($match, $state, $pos, Doku_Handler $handler) { + return true; + } + + /** + * The only thing this plugin component does is to set the metadata 'type' to 'draft' + */ + function render($mode, Doku_Renderer $renderer, $data) { + if ($mode == 'xthml') { + return true; // don't output anything + } elseif ($mode == 'metadata') { + $renderer->meta['type'] = 'draft'; + } + } +} +// vim:ts=4:sw=4:et:enc=utf-8: |