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