forked from cosmocode/tagging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
207 lines (175 loc) · 6.47 KB
/
admin.php
File metadata and controls
207 lines (175 loc) · 6.47 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
// must be run within Dokuwiki
if (!defined('DOKU_INC')) {
die();
}
class admin_plugin_tagging extends DokuWiki_Admin_Plugin {
/** @var helper_plugin_tagging */
private $hlp;
public function __construct() {
$this->hlp = plugin_load('helper', 'tagging');
}
/**
* We allow use by managers
*
* @return bool always false
*/
function forAdminOnly() {
return false;
}
/**
* Handle tag actions
*/
function handle() {
global $ID, $INPUT;
//by default use current page namespace
if (!$INPUT->has('filter')) {
$INPUT->set('filter', getNS($ID));
}
//by default sort by tag name
if (!$INPUT->has('sort')) {
$INPUT->set('sort', 'tid');
}
//now starts functions handle
if (!$INPUT->has('fn')) {
return false;
}
if (!checkSecurityToken()) {
return false;
}
// extract the command and any specific parameters
// submit button name is of the form - fn[cmd][param(s)]
$fn = $INPUT->param('fn');
if (is_array($fn)) {
$cmd = key($fn);
$param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null;
} else {
$cmd = $fn;
$param = null;
}
switch ($cmd) {
case 'rename':
$this->hlp->renameTag($INPUT->str('old'), $INPUT->str('new'));
break;
case 'delete':
$this->hlp->deleteTags(array_keys($INPUT->arr('tags')), $INPUT->str('filter'));
break;
case 'sort':
$INPUT->set('sort', $param);
break;
}
}
/**
* Draw the interface
*/
function html() {
echo $this->locale_xhtml('intro');
$this->html_form();
echo '<br />';
$this->html_table();
}
/**
* Show form for renaming tags
*/
protected function html_form() {
global $ID, $INPUT;
$form = new dokuwiki\Form\Form();
$form->addClass('plugin_tagging');
$form->setHiddenField('do', 'admin');
$form->setHiddenField('page', 'tagging');
$form->setHiddenField('id', $ID);
$form->setHiddenField('filter', $INPUT->str('filter'));
$form->setHiddenField('sort', $INPUT->str('sort'));
$form->addFieldsetOpen($this->getLang('admin rename tag'));
$form->addTextInput('old', $this->getLang('admin find tag'))->addClass('block');
$form->addTagClose('br');
$form->addTextInput('new', $this->getLang('admin new name'))->addClass('block');
$form->addTagClose('br');
$form->addButton('fn[rename]', $this->getLang('admin save'));
$form->addFieldsetClose();
echo $form->toHTML();
}
/**
* Display ALL the tags!
*/
protected function html_table() {
global $ID, $INPUT;
$headers = array(
array('value' => ' ', 'sort_by' => false),
array('value' => $this->getLang('admin tag'), 'sort_by' => 'tid'),
array('value' => $this->getLang('admin occurrence'), 'sort_by' => 'count'),
array('value' => $this->getLang('admin writtenas'), 'sort_by' => 'orig'),
array('value' => $this->getLang('admin taggers'), 'sort_by' => 'taggers'),
);
$sort = explode(',', $INPUT->str('sort'));
$order_by = $sort[0];
$desc = false;
if (isset($sort[1]) && $sort[1] === 'desc') {
$desc = true;
}
$tags = $this->hlp->getAllTags($INPUT->str('filter'), $order_by, $desc);
$form = new dokuwiki\Form\Form();
$form->setHiddenField('do', 'admin');
$form->setHiddenField('page', 'tagging');
$form->setHiddenField('id', $ID);
$form->setHiddenField('sort', $INPUT->str('sort'));
$form->addTagOpen('table')->addClass('inline plugin_tagging');
$form->addTagOpen('tr');
$form->addTagOpen('th')->attr('colspan', count($headers));
/**
* Show form for filtering the tags by namespaces
*/
$form->addTextInput('filter', $this->getLang('admin filter') . ': ');
$form->addButton('fn[filter]', $this->getLang('admin filter button'));
$form->addTagClose('th');
$form->addTagClose('tr');
/**
* Table headers
*/
$form->addTagOpen('tr');
foreach ($headers as $header) {
$form->addTagOpen('th');
if ($header['sort_by'] !== false) {
$param = $header['sort_by'];
$icon = 'arrow-both';
$title = $this->getLang('admin sort ascending');
if ($header['sort_by'] === $order_by) {
if ($desc === false) {
$icon = 'arrow-up';
$title = $this->getLang('admin sort descending');
$param .= ',desc';
} else {
$icon = 'arrow-down';
}
}
$form->addButtonHTML("fn[sort][$param]", $header['value'] . ' ' . inlineSVG(dirname(__FILE__) . "/images/$icon.svg"))
->addClass('plugin_tagging sort_button')
->attr('title', $title);
}
$form->addTagClose('th');
}
$form->addTagClose('tr');
foreach ($tags as $taginfo) {
$tagname = $taginfo['tid'];
$taggers = $taginfo['taggers'];
$written = $taginfo['orig'];
$form->addTagOpen('tr');
$form->addTagOpen('td')->addClass('centeralign');
$form->addCheckbox('tags[' . hsc($tagname) . ']');
$form->addTagClose('td');
$form->addHTML('<td><a class="tagslist" href="' .
$this->hlp->getTagSearchURL($tagname) . '">' . hsc($tagname) . '</a></td>');
$form->addHTML('<td>' . $taginfo['count'] . '</td>');
$form->addHTML('<td>' . hsc($written) . '</td>');
$form->addHTML('<td>' . hsc($taggers) . '</td>');
$form->addTagClose('tr');
}
$form->addTagOpen('tr');
$form->addHTML('<td colspan="5" class="centeralign"><span class="medialeft">');
$form->addButton('fn[delete]', $this->getLang('admin delete_selected'))->id('tagging__del');
$form->addHTML('</span></td>');
$form->addTagClose('tr');
$form->addTagClose('table');
echo $form->toHTML();
}
}