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')) die(); 11 12class syntax_plugin_tagging extends DokuWiki_Syntax_Plugin { 13 14 function getType() { 15 return 'substition'; 16 } 17 18 function getPType() { 19 return 'block'; 20 } 21 22 function getSort() { 23 return 13; 24 } 25 26 function connectTo($mode) { 27 $this->Lexer->addSpecialPattern('{{tagging::\w+(?:>[^}]+)?}}',$mode,'plugin_tagging'); 28 } 29 30 function handle($match, $state, $pos, &$handler){ 31 $data = array(); 32 $matches = array(); 33 preg_match('/{{tagging::(\w+)(?:>([^}]+))?}}/', $match, $matches); 34 $data['cmd'] = $matches[1]; 35 36 switch($data['cmd']) { 37 case 'user': 38 if (count($matches) > 2) { 39 $data['user'] = trim($matches[2]); 40 } 41 break; 42 case 'ns': 43 if (count($matches) > 2) { 44 $data['ns'] = trim($matches[2]); 45 } 46 break; 47 } 48 49 return $data; 50 } 51 52 function render($mode, &$renderer, $data) { 53 if ($mode !== 'xhtml') { 54 return false; 55 } 56 57 $hlp = plugin_load('helper', 'tagging'); 58 59 switch($data['cmd']) { 60 case 'user': 61 $renderer->info['cache'] = false; 62 if (!isset($data['user'])) { 63 $data['user'] = $_SERVER['REMOTE_USER']; 64 } 65 $tags = $hlp->getTags(array('tagger' => $data['user']), 'tag'); 66 $renderer->doc .= $hlp->html_cloud($tags, 'tag', array($hlp, 'linkToSearch'), true, true); 67 68 break; 69 case 'ns': 70 $renderer->info['cache'] = false; 71 if (!isset($data['ns'])) { 72 global $INFO; 73 $data['ns'] = $INFO['namespace']; 74 } 75 global $ID; 76 $data['ns'] = resolve_id(getNS($ID), $data['ns'] . ':'); 77 if ($data['ns'] !== '') { 78 // Do not match nsbla, only ns:bla 79 $data['ns'] .= ':'; 80 } 81 $data['ns'] .= '%'; 82 $tags = $hlp->getTags(array('pid' => $data['ns']), 'tag'); 83 $renderer->doc .= $hlp->html_cloud($tags, 'tag', array($hlp, 'linkToSearch'), true, true); 84 85 break; 86 } 87 88 return true; 89 } 90} 91 92// vim:ts=4:sw=4:et:enc=utf-8: 93