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 } 43 44 return $data; 45 } 46 47 function render($mode, &$renderer, $data) { 48 if ($mode !== 'xhtml') { 49 return false; 50 } 51 52 $hlp = plugin_load('helper', 'tagging'); 53 54 switch($data['cmd']) { 55 case 'user': 56 $renderer->info['cache'] = false; 57 if (!isset($data['user'])) { 58 $data['user'] = $_SERVER['REMOTE_USER']; 59 } 60 $tags = $hlp->getTags(array('tagger' => $data['user']), 'tag'); 61 $renderer->doc .= $hlp->html_cloud($tags, 'tag', array($hlp, 'linkToSearch'), true, true); 62 63 break; 64 } 65 66 return true; 67 } 68} 69 70// vim:ts=4:sw=4:et:enc=utf-8: 71