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+(?:>[^}\?]+)?(?:\?[0-9]+)?}}', $mode, 'plugin_tagging'); 28 } 29 30 function handle($match, $state, $pos, &$handler) { 31 $data = array(); 32 $matches = array(); 33 preg_match('/{{tagging::(\w+)(?:>([^}\?]+))?(\?[0-9]+)?}}/', $match, $matches); 34 $data['cmd'] = $matches[1]; 35 $data['limit'] = (int) ltrim($matches[3], '?'); 36 if(!$data['limit']) $data['limit'] = $this->getConf('cloudlimit'); 37 38 switch($data['cmd']) { 39 case 'user': 40 if(count($matches) > 2) { 41 $data['user'] = trim($matches[2]); 42 } 43 break; 44 case 'ns': 45 if(count($matches) > 2) { 46 $data['ns'] = trim($matches[2]); 47 } 48 break; 49 } 50 51 return $data; 52 } 53 54 function render($mode, &$renderer, $data) { 55 if($mode !== 'xhtml') { 56 return false; 57 } 58 59 /** @var helper_plugin_tagging $hlp */ 60 $hlp = plugin_load('helper', 'tagging'); 61 62 switch($data['cmd']) { 63 case 'user': 64 $renderer->info['cache'] = false; 65 if(!isset($data['user'])) { 66 $data['user'] = $_SERVER['REMOTE_USER']; 67 } 68 $tags = $hlp->findItems(array('tagger' => $data['user']), 'tag', $data['limit']); 69 $renderer->doc .= $hlp->html_cloud($tags, 'tag', array($hlp, 'linkToSearch'), true, true); 70 71 break; 72 case 'ns': 73 $renderer->info['cache'] = false; 74 if(!isset($data['ns'])) { 75 global $INFO; 76 $data['ns'] = $INFO['namespace']; 77 } 78 global $ID; 79 $data['ns'] = resolve_id(getNS($ID), $data['ns'] . ':'); 80 if($data['ns'] !== '') { 81 // Do not match nsbla, only ns:bla 82 $data['ns'] .= ':'; 83 } 84 $tags = $hlp->findItems(array('pid' => $data['ns'] . '%'), 'tag', $data['limit']); 85 $renderer->doc .= $hlp->html_cloud($tags, 'tag', array($hlp, 'linkToSearch'), true, true, $data['ns']); 86 87 break; 88 case 'input': 89 $hlp->tpl_tags(); 90 91 break; 92 } 93 94 return true; 95 } 96} 97 98// vim:ts=4:sw=4:et:enc=utf-8: 99