first commit. dokuwiki.
[h2N7SspZmY.git] / lib / plugins / tag / syntax / topic.php
blob23ea2a969d0996bbe7bb37d000be2ab25da42972
1 <?php
2 /**
3 * Tag Plugin, topic component: displays links to all wiki pages with a certain tag
4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Esther Brunner <wikidesign@gmail.com>
7 */
9 // must be run within Dokuwiki
10 if (!defined('DOKU_INC')) die();
12 if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14 require_once(DOKU_PLUGIN.'syntax.php');
16 class syntax_plugin_tag_topic extends DokuWiki_Syntax_Plugin {
18 function getInfo() {
19 return array(
20 'author' => 'Gina Häußge, Michael Klier, Esther Brunner',
21 'email' => 'dokuwiki@chimeric.de',
22 'date' => @file_get_contents(DOKU_PLUGIN.'tag/VERSION'),
23 'name' => 'Tag Plugin (topic component)',
24 'desc' => 'Displays a list of wiki pages with a given category tag',
25 'url' => 'http://www.dokuwiki.org/plugin:tag',
29 function getType() { return 'substition'; }
30 function getPType() { return 'block'; }
31 function getSort() { return 306; }
33 function connectTo($mode) {
34 $this->Lexer->addSpecialPattern('\{\{topic>.+?\}\}',$mode,'plugin_tag_topic');
37 function handle($match, $state, $pos, &$handler) {
38 global $ID;
40 $match = substr($match, 8, -2); // strip {{topic> from start and }} from end
41 list($match, $flags) = explode('&', $match, 2);
42 $flags = explode('&', $flags);
43 list($ns, $tag) = explode('?', $match);
45 if (!$tag) {
46 $tag = $ns;
47 $ns = '';
50 if (($ns == '*') || ($ns == ':')) $ns = '';
51 elseif ($ns == '.') $ns = getNS($ID);
52 else $ns = cleanID($ns);
54 return array($ns, trim($tag), $flags);
57 function render($mode, &$renderer, $data) {
58 list($ns, $tag, $flags) = $data;
60 if ($my =& plugin_load('helper', 'tag')) $pages = $my->getTopic($ns, '', $tag);
61 if (!$pages) return true; // nothing to display
63 if ($mode == 'xhtml') {
65 // prevent caching to ensure content is always fresh
66 $renderer->info['cache'] = false;
68 // let Pagelist Plugin do the work for us
69 if (plugin_isdisabled('pagelist')
70 || (!$pagelist = plugin_load('helper', 'pagelist'))) {
71 msg($this->getLang('missing_pagelistplugin'), -1);
72 return false;
74 $pagelist->setFlags($flags);
75 $pagelist->startList();
76 foreach ($pages as $page) {
77 $pagelist->addPage($page);
79 $renderer->doc .= $pagelist->finishList();
80 return true;
82 // for metadata renderer
83 } elseif ($mode == 'metadata') {
84 foreach ($pages as $page) {
85 $renderer->meta['relation']['references'][$page['id']] = true;
88 return true;
90 return false;
93 // vim:ts=4:sw=4:et:enc=utf-8: