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