summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/tag/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'platform/www/lib/plugins/tag/syntax')
-rw-r--r--platform/www/lib/plugins/tag/syntax/count.php124
-rw-r--r--platform/www/lib/plugins/tag/syntax/searchtags.php281
-rw-r--r--platform/www/lib/plugins/tag/syntax/tag.php112
-rw-r--r--platform/www/lib/plugins/tag/syntax/tagpage.php90
-rw-r--r--platform/www/lib/plugins/tag/syntax/topic.php129
5 files changed, 736 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/tag/syntax/count.php b/platform/www/lib/plugins/tag/syntax/count.php
new file mode 100644
index 0000000..f19d342
--- /dev/null
+++ b/platform/www/lib/plugins/tag/syntax/count.php
@@ -0,0 +1,124 @@
+<?php
+/**
+ * Tag Plugin: displays list of keywords with links to categories this page
+ * belongs to. The links are marked as tags for Technorati and other services
+ * using tagging.
+ *
+ * Usage: {{tag>category tags space separated}}
+ *
+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author Matthias Schulte <dokuwiki@lupo49.de>
+ */
+
+/** Count syntax, allows to list tag counts */
+class syntax_plugin_tag_count extends DokuWiki_Syntax_Plugin {
+
+ /**
+ * @return string Syntax type
+ */
+ function getType() { return 'substition'; }
+ /**
+ * @return int Sort order
+ */
+ function getSort() { return 305; }
+ /**
+ * @return string Paragraph type
+ */
+ function getPType() { return 'block';}
+
+ /**
+ * @param string $mode Parser mode
+ */
+ function connectTo($mode) {
+ $this->Lexer->addSpecialPattern('\{\{count>.*?\}\}', $mode, 'plugin_tag_count');
+ }
+
+ /**
+ * Handle matches of the count syntax
+ *
+ * @param string $match The match of the syntax
+ * @param int $state The state of the handler
+ * @param int $pos The position in the document
+ * @param Doku_Handler $handler The handler
+ * @return array Data for the renderer
+ */
+ function handle($match, $state, $pos, Doku_Handler $handler) {
+
+ $dump = trim(substr($match, 8, -2)); // get given tags
+ $dump = explode('&', $dump); // split to tags and allowed namespaces
+ $tags = $dump[0];
+ $allowedNamespaces = explode(' ', $dump[1]); // split given namespaces into an array
+
+ if($allowedNamespaces && $allowedNamespaces[0] == '') {
+ unset($allowedNamespaces[0]); // When exists, remove leading space after the delimiter
+ $allowedNamespaces = array_values($allowedNamespaces);
+ }
+
+ if (empty($allowedNamespaces)) $allowedNamespaces = null;
+
+ if (!$tags) $tags = '+';
+
+ /** @var helper_plugin_tag $my */
+ if(!($my = $this->loadHelper('tag'))) return false;
+
+ return array($my->_parseTagList($tags), $allowedNamespaces);
+ }
+
+ /**
+ * Render xhtml output or metadata
+ *
+ * @param string $mode Renderer mode (supported modes: xhtml and metadata)
+ * @param Doku_Renderer $renderer The renderer
+ * @param array $data The data from the handler function
+ * @return bool If rendering was successful.
+ */
+ function render($mode, Doku_Renderer $renderer, $data) {
+ if ($data == false) return false;
+
+ list($tags, $allowedNamespaces) = $data;
+
+ // deactivate (renderer) cache as long as there is no proper cache handling
+ // implemented for the count syntax
+ $renderer->nocache();
+
+ if($mode == "xhtml") {
+ /** @var helper_plugin_tag $my */
+ if(!($my = $this->loadHelper('tag'))) return false;
+
+ // get tags and their occurrences
+ if($tags[0] == '+') {
+ // no tags given, list all tags for allowed namespaces
+ $occurrences = $my->tagOccurrences($tags, $allowedNamespaces, true);
+ } else {
+ $occurrences = $my->tagOccurrences($tags, $allowedNamespaces);
+ }
+
+ $class = "inline"; // valid: inline, ul, pagelist
+ $col = "page";
+
+ $renderer->doc .= '<table class="'.$class.'">'.DOKU_LF;
+ $renderer->doc .= DOKU_TAB.'<tr>'.DOKU_LF.DOKU_TAB.DOKU_TAB;
+ $renderer->doc .= '<th class="'.$col.'">'.$this->getLang('tag').'</th>';
+ $renderer->doc .= '<th class="'.$col.'">'.$this->getLang('count').'</th>';
+ $renderer->doc .= DOKU_LF.DOKU_TAB.'</tr>'.DOKU_LF;
+
+ if(empty($occurrences)) {
+ // Skip output
+ $renderer->doc .= DOKU_TAB.'<tr>'.DOKU_LF.DOKU_TAB.DOKU_TAB;
+ $renderer->doc .= DOKU_TAB.DOKU_TAB.'<td class="'.$class.'" colspan="2">'.$this->getLang('empty_output').'</td>'.DOKU_LF;
+ $renderer->doc .= DOKU_LF.DOKU_TAB.'</tr>'.DOKU_LF;
+ } else {
+ foreach($occurrences as $tagname => $count) {
+ if($count <= 0) continue; // don't display tags with zero occurrences
+ $renderer->doc .= DOKU_TAB.'<tr>'.DOKU_LF.DOKU_TAB.DOKU_TAB;
+ $renderer->doc .= DOKU_TAB.DOKU_TAB.'<td class="'.$class.'">'.$my->tagLink($tagname).'</td>'.DOKU_LF;
+ $renderer->doc .= DOKU_TAB.DOKU_TAB.'<td class="'.$class.'">'.$count.'</td>'.DOKU_LF;
+ $renderer->doc .= DOKU_LF.DOKU_TAB.'</tr>'.DOKU_LF;
+ }
+ }
+ $renderer->doc .= '</table>'.DOKU_LF;
+ }
+ return true;
+ }
+}
+// vim:ts=4:sw=4:et:
diff --git a/platform/www/lib/plugins/tag/syntax/searchtags.php b/platform/www/lib/plugins/tag/syntax/searchtags.php
new file mode 100644
index 0000000..67d62b3
--- /dev/null
+++ b/platform/www/lib/plugins/tag/syntax/searchtags.php
@@ -0,0 +1,281 @@
+<?php
+/**
+ * Syntax plugin part for displaying a tag search form with results.
+ *
+ * Usage: {{tagsearch[&flags]}}
+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author Michael Hamann <michael@content-space.de>
+ */
+
+/**
+ * Tagsearch syntax, displays a tag search form with results similar to the topic syntax
+ */
+class syntax_plugin_tag_searchtags extends DokuWiki_Syntax_Plugin {
+ /**
+ * @return string Syntax type
+ */
+ function getType() { return 'substition'; }
+
+ /**
+ * @return string Paragraph type
+ */
+ function getPType() { return 'block'; }
+
+ /**
+ * @return int Sort order
+ */
+ function getSort() { return 295; }
+
+ /**
+ * @param string $mode Parser mode
+ */
+ function connectTo($mode) {
+ $this->Lexer->addSpecialPattern('\{\{searchtags\}\}',$mode,'plugin_tag_searchtags');
+ // make sure that flags really start with & and media files starting with "searchtags" still work
+ $this->Lexer->addSpecialPattern('\{\{searchtags&.*?\}\}',$mode,'plugin_tag_searchtags');
+ }
+
+ /**
+ * Handle matches of the searchtags syntax
+ *
+ * @param string $match The match of the syntax
+ * @param int $state The state of the handler
+ * @param int $pos The position in the document
+ * @param Doku_Handler $handler The handler
+ * @return array Data for the renderer
+ */
+ function handle($match, $state, $pos, Doku_Handler $handler) {
+ $flags = substr($match, 10, -2); // strip {{searchtags from start and }} from end
+ // remove empty flags by using array_filter (removes elements == false)
+ $flags = array_filter(explode('&', $flags));
+
+ return $flags;
+ }
+
+ /**
+ * Render xhtml output or metadata
+ *
+ * @param string $mode Renderer mode (supported modes: xhtml and metadata)
+ * @param Doku_Renderer $renderer The renderer
+ * @param array $data The data from the handler function
+ * @return bool If rendering was successful.
+ */
+ function render($mode, Doku_Renderer $renderer, $data) {
+ global $lang;
+ $flags = $data;
+
+ if ($mode == 'xhtml') {
+ /* @var Doku_Renderer_xhtml $renderer */
+
+ // prevent caching to ensure content is always fresh
+ $renderer->nocache();
+
+ /* @var helper_plugin_pagelist $pagelist */
+ // let Pagelist Plugin do the work for us
+ if ((!$pagelist = $this->loadHelper('pagelist'))) {
+ return false;
+ }
+
+ // Prepare the flags for the pagelist plugin
+ $configflags = explode(',', str_replace(" ", "", $this->getConf('pagelist_flags')));
+ $flags = array_merge($configflags, $flags);
+ foreach($flags as $key => $flag) {
+ if($flag == "") unset($flags[$key]);
+ }
+
+ // print the search form
+ $nonsform = in_array('nonsform', $flags);
+ $renderer->doc .= $this->getForm($nonsform);
+
+ // get the tag input data
+ $tags = $this->getTagSearchString();
+
+ if ($tags != NULL) {
+ /* @var helper_plugin_tag $my */
+ if ($my = $this->loadHelper('tag')) $pages = $my->getTopic($this->getNS(), '', $tags);
+
+ // Display a message when no pages were found
+ if (!isset($pages) || !$pages) {
+ $renderer->p_open();
+ $renderer->cdata($lang['nothingfound']);
+ $renderer->p_close();
+ } else {
+
+ // display the actual search results
+ $pagelist->setFlags($flags);
+ $pagelist->startList();
+ foreach ($pages as $page) {
+ $pagelist->addPage($page);
+ }
+ $renderer->doc .= $pagelist->finishList();
+ }
+ }
+
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return the search form for the namespace and the tag selection
+ *
+ * @return string the HTML code of the search form
+ */
+ private function getForm($nonsform=false) {
+ global $conf, $lang;
+
+ if (!$nonsform) {
+ // Get the list of all namespaces for the dropdown
+ $namespaces = array();
+ search($namespaces,$conf['datadir'],'search_namespaces',array());
+
+ // build the list in the form value => label from the namespace search result
+ $ns_select = array('' => '');
+ foreach ($namespaces as $ns) {
+ // only display namespaces the user can access when sneaky index is on
+ if ($ns['perm'] > 0 || $conf['sneaky_index'] == 0) {
+ $ns_select[$ns['id']] = $ns['id'];
+ }
+ }
+ }
+
+ $form = new Doku_Form(array('action' => '', 'method' => 'post', 'class' => 'plugin__tag_search'));
+
+ // add a paragraph around the inputs in order to get some margin around the form elements
+ $form->addElement(form_makeOpenTag('p'));
+ // namespace select
+ if (!$nonsform) {
+ $form->addElement(form_makeMenuField('plugin__tag_search_namespace', $ns_select, $this->getNS(), $lang['namespaces']));
+ }
+
+ // checkbox for AND
+ $attr = array();
+ if ($this->useAnd()) $attr['checked'] = 'checked';
+ $form->addElement(form_makeCheckboxField('plugin__tag_search_and', 1, $this->getLang('use_and'), '', '', $attr));
+ $form->addElement(form_makeCloseTag('p'));
+
+ // load the tag list - only tags that actually have pages assigned that the current user can access are listed
+ /* @var helper_plugin_tag $my */
+ if ($my = $this->loadHelper('tag')) $tags = $my->tagOccurrences(array(), NULL, true);
+ // sort tags by name ($tags is in the form $tag => $count)
+ ksort($tags);
+
+ // display error message when no tags were found
+ if (!isset($tags) || $tags == NULL) {
+ $form->addElement(form_makeOpenTag('p'));
+ $form->addElement($this->getLang('no_tags'));
+ $form->addElement(form_makeCloseTag('p'));
+ } else {
+ // the tags table
+ $form->addElement(form_makeOpenTag('div', array('class' => 'table')));
+ $form->addElement(form_makeOpenTag('table', array('class' => 'inline')));
+ // print table header
+ $form->addElement(form_makeOpenTag('tr'));
+ $form->addElement(form_makeOpenTag('th'));
+ $form->addElement($this->getLang('include'));
+ $form->addElement(form_makeCloseTag('th'));
+ $form->addElement(form_makeOpenTag('th'));
+ $form->addElement($this->getLang('exclude'));
+ $form->addElement(form_makeCloseTag('th'));
+ $form->addElement(form_makeOpenTag('th'));
+ $form->addElement($this->getLang('tags'));
+ $form->addElement(form_makeCloseTag('th'));
+ $form->addElement(form_makeCloseTag('tr'));
+
+ // print tag checkboxes
+ foreach ($tags as $tag => $count) {
+ $form->addElement(form_makeOpenTag('tr'));
+ $form->addElement(form_makeOpenTag('td'));
+ $attr = array();
+ if ($this->isSelected($tag)) $attr['checked'] = 'checked';
+ $form->addElement(form_makeCheckboxField('plugin__tag_search_tags[]', $tag, '+', '', 'plus', $attr));
+ $form->addElement(form_makeCloseTag('td'));
+ $form->addElement(form_makeOpenTag('td'));
+ $attr = array();
+ if ($this->isSelected('-'.$tag)) $attr['checked'] = 'checked';
+ $form->addElement(form_makeCheckboxField('plugin__tag_search_tags[]', '-'.$tag, '-', '', 'minus', $attr));
+ $form->addElement(form_makeCloseTag('td'));
+ $form->addElement(form_makeOpenTag('td'));
+ $form->addElement(hsc($tag).' ['.$count.']');
+ $form->addElement(form_makeCloseTag('td'));
+ $form->addElement(form_makeCloseTag('tr'));
+ }
+
+ $form->addElement(form_makeCloseTag('table'));
+ $form->addElement(form_makeCloseTag('div'));
+
+ // submit button (doesn't use the button form element because it always submits an action which is not
+ // recognized for $preact in inc/actions.php and thus always causes a redirect)
+ $form->addElement(form_makeOpenTag('p'));
+ $form->addElement(form_makeTag('input', array('type' => 'submit', 'value' => $lang['btn_search'])));
+ $form->addElement(form_makeCloseTag('p'));
+ }
+
+ return $form->getForm();
+ }
+
+ /**
+ * Returns the currently selected namespace
+ * @return string the cleaned namespace id
+ */
+ private function getNS() {
+ if (isset($_POST['plugin__tag_search_namespace'])) {
+ return cleanID($_POST['plugin__tag_search_namespace']);
+ } else {
+ return '';
+ }
+ }
+
+ /**
+ * Returns the tag search string from the selected tags
+ * @return string|NULL the tag search or NULL when no tags were selected
+ */
+ private function getTagSearchString() {
+ if (isset($_POST['plugin__tag_search_tags']) && is_array($_POST['plugin__tag_search_tags'])) {
+ $tags = $_POST['plugin__tag_search_tags'];
+ // wWhen and is set, prepend "+" to each tag
+ $plus = (isset($_POST['plugin__tag_search_and']) ? '+' : '');
+ $positive_tags = '';
+ $negative_tags = '';
+ foreach ($tags as $tag) {
+ $tag = (string)$tag;
+ if ($tag[0] == '-') {
+ $negative_tags .= $tag.' ';
+ } else {
+ if ($positive_tags === '') {
+ $positive_tags = $tag.' ';
+ } else {
+ $positive_tags .= $plus.$tag.' ';
+ }
+ }
+ }
+ return $positive_tags.$negative_tags;
+ } else {
+ return NULL; // return NULL when no tags were selected so no results will be displayed
+ }
+ }
+
+ /**
+ * Check if a tag was selected for search
+ *
+ * @param string $tag The tag to check
+ * @return bool if the tag was checked
+ */
+ private function isSelected($tag) {
+ if (isset($_POST['plugin__tag_search_tags']) && is_array($_POST['plugin__tag_search_tags'])) {
+ return in_array($tag, $_POST['plugin__tag_search_tags'], true);
+ } else {
+ return false; // no tags in the post data - no tag selected
+ }
+ }
+
+ /**
+ * Check if the tag query should use AND (instead of OR)
+ *
+ * @return bool if the query should use AND
+ */
+ private function useAnd() {
+ return isset($_POST['plugin__tag_search_and']);
+ }
+}
+// vim:ts=4:sw=4:et:
diff --git a/platform/www/lib/plugins/tag/syntax/tag.php b/platform/www/lib/plugins/tag/syntax/tag.php
new file mode 100644
index 0000000..dc8bce5
--- /dev/null
+++ b/platform/www/lib/plugins/tag/syntax/tag.php
@@ -0,0 +1,112 @@
+<?php
+/**
+ * Tag Plugin: displays list of keywords with links to categories this page
+ * belongs to. The links are marked as tags for Technorati and other services
+ * using tagging.
+ *
+ * Usage: {{tag>category tags space separated}}
+ *
+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author Esther Brunner <wikidesign@gmail.com>
+ */
+
+/**
+ * Tag syntax plugin, allows to specify tags in a page
+ */
+class syntax_plugin_tag_tag extends DokuWiki_Syntax_Plugin {
+
+ /**
+ * @return string Syntax type
+ */
+ function getType() { return 'substition'; }
+ /**
+ * @return int Sort order
+ */
+ function getSort() { return 305; }
+ /**
+ * @return string Paragraph type
+ */
+ function getPType() { return 'block';}
+
+ /**
+ * @param string $mode Parser mode
+ */
+ function connectTo($mode) {
+ $this->Lexer->addSpecialPattern('\{\{tag>.*?\}\}', $mode, 'plugin_tag_tag');
+ }
+
+ /**
+ * Handle matches of the tag syntax
+ *
+ * @param string $match The match of the syntax
+ * @param int $state The state of the handler
+ * @param int $pos The position in the document
+ * @param Doku_Handler $handler The handler
+ * @return array Data for the renderer
+ */
+ function handle($match, $state, $pos, Doku_Handler $handler) {
+ $tags = trim(substr($match, 6, -2)); // strip markup & whitespace
+ $tags = preg_replace(array('/[[:blank:]]+/', '/\s+/'), " ", $tags); // replace linebreaks and multiple spaces with one space character
+
+ if (!$tags) return false;
+
+ // load the helper_plugin_tag
+ /** @var helper_plugin_tag $my */
+ if (!$my = $this->loadHelper('tag')) return false;
+
+ // split tags and returns for renderer
+ return $my->_parseTagList($tags);
+ }
+
+ /**
+ * Render xhtml output or metadata
+ *
+ * @param string $mode Renderer mode (supported modes: xhtml and metadata)
+ * @param Doku_Renderer $renderer The renderer
+ * @param array $data The data from the handler function
+ * @return bool If rendering was successful.
+ */
+ function render($mode, Doku_Renderer $renderer, $data) {
+ if ($data === false) return false;
+ /** @var helper_plugin_tag $my */
+ if (!$my = $this->loadHelper('tag')) return false;
+
+ // XHTML output
+ if ($mode == 'xhtml') {
+ $tags = $my->tagLinks($data);
+ if (!$tags) return true;
+ $renderer->doc .= '<div class="'.$this->getConf('tags_list_css').'"><span>'.DOKU_LF.
+ DOKU_TAB.$tags.DOKU_LF.
+ '</span></div>'.DOKU_LF;
+ return true;
+
+ // for metadata renderer
+ } elseif ($mode == 'metadata') {
+ /** @var Doku_Renderer_metadata $renderer */
+ // erase tags on persistent metadata no more used
+ if (isset($renderer->persistent['subject'])) {
+ unset($renderer->persistent['subject']);
+ $renderer->meta['subject'] = array();
+ }
+
+ if (!isset($renderer->meta['subject'])) $renderer->meta['subject'] = array();
+
+ // each registered tags in metadata and index should be valid IDs
+ $data = array_map('cleanID', $data);
+ // merge with previous tags and make the values unique
+ $renderer->meta['subject'] = array_unique(array_merge($renderer->meta['subject'], $data));
+
+ if ($renderer->capture) $renderer->doc .= DOKU_LF.implode(' ', $data).DOKU_LF;
+
+ // add references if tag page exists
+ foreach ($data as $tag) {
+ resolve_pageid($my->namespace, $tag, $exists); // resolve shortcuts
+ $renderer->meta['relation']['references'][$tag] = $exists;
+ }
+
+ return true;
+ }
+ return false;
+ }
+}
+// vim:ts=4:sw=4:et:
diff --git a/platform/www/lib/plugins/tag/syntax/tagpage.php b/platform/www/lib/plugins/tag/syntax/tagpage.php
new file mode 100644
index 0000000..bec2e70
--- /dev/null
+++ b/platform/www/lib/plugins/tag/syntax/tagpage.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * Tag Plugin: Display a link to the listing of all pages with a certain tag.
+ *
+ * Usage: {{tagpage>mytag[&dynamic][|title]}}
+ *
+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author Matthias Schulte <dokuwiki@lupo49.de>
+ */
+
+/** Tagpage syntax, allows to link to a given tag */
+class syntax_plugin_tag_tagpage extends DokuWiki_Syntax_Plugin {
+
+ /**
+ * @return string Syntax type
+ */
+ function getType() {
+ return 'substition';
+ }
+
+ /**
+ * @return int Sort order
+ */
+ function getSort() {
+ return 305;
+ }
+
+ /**
+ * @return string Paragraph type
+ */
+ function getPType() {
+ return 'normal';
+ }
+
+ /**
+ * @param string $mode Parser mode
+ */
+ function connectTo($mode) {
+ $this->Lexer->addSpecialPattern('\{\{tagpage>.*?\}\}', $mode, 'plugin_tag_tagpage');
+ }
+
+ /**
+ * Handle matches of the count syntax
+ *
+ * @param string $match The match of the syntax
+ * @param int $state The state of the handler
+ * @param int $pos The position in the document
+ * @param Doku_Handler $handler The handler
+ * @return array Data for the renderer
+ */
+ function handle($match, $state, $pos, Doku_Handler $handler) {
+ $params = array();
+ $dump = trim(substr($match, 10, -2)); // get given tag
+ $dump = explode('|', $dump, 2); // split to tags, link name and options
+ $params['title'] = $dump[1];
+ $dump = explode('&', $dump[0]);
+ $params['dynamic'] = ($dump[1] == 'dynamic');
+ $params['tag'] = trim($dump[0]);
+
+ return $params;
+ }
+
+ /**
+ * Render xhtml output
+ *
+ * @param string $mode Renderer mode (supported modes: xhtml)
+ * @param Doku_Renderer $renderer The renderer
+ * @param array $data The data from the handler function
+ * @return bool If rendering was successful.
+ */
+ function render($mode, Doku_Renderer $renderer, $data) {
+ if($data == false) return false;
+
+ if($mode == "xhtml") {
+ if($data['dynamic']) {
+ // deactivate (renderer) cache as long as there is no proper cache handling
+ // implemented for the count syntax
+ $renderer->nocache();
+ }
+
+ /** @var helper_plugin_tag $my */
+ if(!($my = $this->loadHelper('tag'))) return false;
+
+ $renderer->doc .= $my->tagLink($data['tag'], $data['title'], $data['dynamic']);
+ return true;
+ }
+ return false;
+ }
+}
+// vim:ts=4:sw=4:et:
diff --git a/platform/www/lib/plugins/tag/syntax/topic.php b/platform/www/lib/plugins/tag/syntax/topic.php
new file mode 100644
index 0000000..a065a94
--- /dev/null
+++ b/platform/www/lib/plugins/tag/syntax/topic.php
@@ -0,0 +1,129 @@
+<?php
+/**
+ * Tag Plugin, topic component: displays links to all wiki pages with a certain tag
+ *
+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author Esther Brunner <wikidesign@gmail.com>
+ */
+
+/**
+ * Topic syntax, displays links to all wiki pages with a certain tag
+ */
+class syntax_plugin_tag_topic extends DokuWiki_Syntax_Plugin {
+
+ /**
+ * @return string Syntax type
+ */
+ function getType() { return 'substition'; }
+
+ /**
+ * @return string Paragraph type
+ */
+ function getPType() { return 'block'; }
+
+ /**
+ * @return int Sort order
+ */
+ function getSort() { return 295; }
+
+ /**
+ * @param string $mode Parser mode
+ */
+ function connectTo($mode) {
+ $this->Lexer->addSpecialPattern('\{\{topic>.+?\}\}',$mode,'plugin_tag_topic');
+ }
+
+ /**
+ * Handle matches of the topic syntax
+ *
+ * @param string $match The match of the syntax
+ * @param int $state The state of the handler
+ * @param int $pos The position in the document
+ * @param Doku_Handler $handler The handler
+ * @return array Data for the renderer
+ */
+ function handle($match, $state, $pos, Doku_Handler $handler) {
+ global $ID;
+
+ $match = substr($match, 8, -2); // strip {{topic> from start and }} from end
+ list($match, $flags) = explode('&', $match, 2);
+ $flags = explode('&', $flags);
+ list($ns, $tag) = explode('?', $match);
+
+ if (!$tag) {
+ $tag = $ns;
+ $ns = '';
+ }
+
+ if (($ns == '*') || ($ns == ':')) $ns = '';
+ elseif ($ns == '.') $ns = getNS($ID);
+ else $ns = cleanID($ns);
+
+ return array($ns, trim($tag), $flags);
+ }
+
+ /**
+ * Render xhtml output or metadata
+ *
+ * @param string $mode Renderer mode (supported modes: xhtml and metadata)
+ * @param Doku_Renderer $renderer The renderer
+ * @param array $data The data from the handler function
+ * @return bool If rendering was successful.
+ */
+ function render($mode, Doku_Renderer $renderer, $data) {
+ list($ns, $tag, $flags) = $data;
+
+ /* @var helper_plugin_tag $my */
+ if ($my = $this->loadHelper('tag')) $pages = $my->getTopic($ns, '', $tag);
+ if (!isset($pages) || !$pages) return true; // nothing to display
+
+ if ($mode == 'xhtml') {
+ /* @var Doku_Renderer_xhtml $renderer */
+
+ // prevent caching to ensure content is always fresh
+ $renderer->nocache();
+
+ /* @var helper_plugin_pagelist $pagelist */
+ // let Pagelist Plugin do the work for us
+ if ((!$pagelist = $this->loadHelper('pagelist'))) {
+ return false;
+ }
+ $pagelist->sort = false;
+ $pagelist->rsort = false;
+
+ $configflags = explode(',', str_replace(" ", "", $this->getConf('pagelist_flags')));
+ $flags = array_merge($configflags, $flags);
+ foreach($flags as $key => $flag) {
+ if($flag == "") unset($flags[$key]);
+ }
+
+ $pagelist->setFlags($flags);
+ $pagelist->startList();
+
+ // Sort pages by pagename if required by flags
+ if($pagelist->sort || $pagelist->rsort) {
+ $keys = array();
+ $fnc = create_function('$a, $b', 'return strcmp(noNS($a["id"]), noNS($b["id"])); ');
+ usort($pages, $fnc);
+ // rsort is true - revserse sort the pages
+ if($pagelist->rsort) krsort($pages);
+ }
+
+ foreach ($pages as $page) {
+ $pagelist->addPage($page);
+ }
+ $renderer->doc .= $pagelist->finishList();
+ return true;
+
+ // for metadata renderer
+/* } elseif ($mode == 'metadata') {
+ foreach ($pages as $page) {
+ $renderer->meta['relation']['references'][$page['id']] = true;
+ }
+
+ return true;*/ // causes issues with backlinks
+ }
+ return false;
+ }
+}
+// vim:ts=4:sw=4:et: