1<?php 2/** 3 * DokuWiki Plugin tagging (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Adrian Lang <lang@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) { 11 die(); 12} 13 14class syntax_plugin_tagging extends DokuWiki_Syntax_Plugin { 15 16 function getType() { 17 return 'substition'; 18 } 19 20 function getPType() { 21 return 'block'; 22 } 23 24 function getSort() { 25 return 13; 26 } 27 28 function connectTo($mode) { 29 $this->Lexer->addSpecialPattern('{{tagging::\w+(?:>[^}\?]+)?(?:\?[0-9]+)?}}', $mode, 'plugin_tagging'); 30 } 31 32 function handle($match, $state, $pos, Doku_Handler $handler) { 33 $data = array(); 34 $matches = array(); 35 preg_match('/{{tagging::(\w+)(?:>([^}\?]+))?(\?[0-9]+)?}}/', $match, $matches); 36 $data['cmd'] = $matches[1]; 37 $data['limit'] = (int)ltrim($matches[3], '?'); 38 if (!$data['limit']) { 39 $data['limit'] = $this->getConf('cloudlimit'); 40 } 41 42 switch ($data['cmd']) { 43 case 'user': 44 if (count($matches) > 2) { 45 $data['user'] = trim($matches[2]); 46 } 47 break; 48 case 'tag': 49 if (count($matches) > 2) { 50 $data['tag'] = trim($matches[2]); 51 } 52 break; 53 case 'ns': 54 if (count($matches) > 2) { 55 $data['ns'] = trim($matches[2]); 56 } 57 break; 58 } 59 60 return $data; 61 } 62 63 function render($mode, Doku_Renderer $renderer, $data) { 64 if ($mode !== 'xhtml') { 65 return false; 66 } 67 68 /** @var helper_plugin_tagging $hlp */ 69 $hlp = plugin_load('helper', 'tagging'); 70 71 switch ($data['cmd']) { 72 case 'user': 73 $renderer->info['cache'] = false; 74 if (!isset($data['user'])) { 75 $data['user'] = $_SERVER['REMOTE_USER']; 76 } 77 $tags = $hlp->findItems(array('tagger' => $data['user']), 'tag', $data['limit']); 78 79 $renderer->doc .= $hlp->html_cloud($tags, 'tag', array($hlp, 'linkToSearch'), true, true); 80 81 break; 82 case 'tag': 83 $renderer->info['cache'] = false; 84 85 $pids = $hlp->findItems(array('tag' => $data['tag']), 'pid', $data['limit']); 86 87 $renderer->doc .= $hlp->html_page_list($pids); 88 89 break; 90 case 'ns': 91 $renderer->info['cache'] = false; 92 if (!isset($data['ns'])) { 93 global $INFO; 94 $data['ns'] = $INFO['namespace']; 95 } 96 global $ID; 97 $data['ns'] = resolve_id(getNS($ID), $data['ns'] . ':'); 98 if ($data['ns'] !== '') { 99 // Do not match nsbla, only ns:bla 100 $data['ns'] .= ':'; 101 } 102 $tags = $hlp->findItems(array('pid' => $data['ns'] . '%'), 'tag', $data['limit']); 103 $renderer->doc .= $hlp->html_cloud($tags, 'tag', array($hlp, 'linkToSearch'), true, true, $data['ns']); 104 105 break; 106 case 'input': 107 $renderer->nocache(); 108 $renderer->doc .= $hlp->tpl_tags(false); 109 break; 110 } 111 112 return true; 113 } 114} 115 116// vim:ts=4:sw=4:et:enc=utf-8: 117