-
Notifications
You must be signed in to change notification settings - Fork 12
/
admin.php
188 lines (172 loc) · 6.16 KB
/
admin.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
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
<?php
/**
* DokuWiki Plugin custombuttons (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Constantinos Xanthopoulos <[email protected]>
*/
class admin_plugin_custombuttons extends DokuWiki_Admin_Plugin {
/**
* Return true for access only by admins (config:superuser) or false if managers are allowed as well
*
* @return bool
*/
public function forAdminOnly() {
return true;
}
/**
* return prompt for admin menu
*/
public function getMenuText($language) {
return $this->getLang('name');
}
/**
* Read config
*
* @return bool|mixed
*/
protected function loadCBData() {
$file = @file_get_contents(DOKU_PLUGIN.'custombuttons/config.json');
if (!$file) return false;
return json_decode($file, true);
}
/**
* Store config
*
* @param $conf
*/
protected function saveCBData($conf) {
$configfile = DOKU_PLUGIN.'custombuttons/config.json';
if (is_writable($configfile) || (!file_exists($configfile) && is_writable(DOKU_PLUGIN.'custombuttons'))) {
file_put_contents($configfile, json_encode($conf));
} else {
msg($this->getLang('txt_error'), -1);
}
}
protected function reloadBar() {
touch(DOKU_CONF.'local.php');
}
/**
* Execute the requested action
*/
public function handle() {
global $INPUT;
if ($INPUT->has('add')) {
if (!checkSecurityToken()) return;
$conf = $this->loadCBData();
if (!$conf) {
$conf = array();
}
$type = 0;
if ($INPUT->str('pretag') != '' && $INPUT->str('posttag') != '') {
$type = 1;
}
array_push($conf, array(
'label' => $INPUT->str('label'),
'code' => $INPUT->str('code'),
'type' => $type,
'pretag' => $INPUT->str('pretag'),
'posttag' => $INPUT->str('posttag'),
'icon' => $INPUT->str('icon'),
));
$this->saveCBData($conf);
$this->reloadBar();
} elseif ($INPUT->has('delete')) {
if (!checkSecurityToken()) return;
$conf = $this->loadCBData();
unset($conf[$INPUT->int('delete')]);
$this->saveCBData($conf);
$this->reloadBar();
}
}
/**
* Render HTML output
*/
public function html() {
global $ID;
$conf = $this->loadCBData();
echo '<div id="custombuttons">';
echo '<h1>'.$this->getLang('name').'</h1>';
// list of custom buttons
echo '<h3>'.$this->getLang('btnslist').'</h3>';
echo '<form id="cb_button_list" action="'.wl($ID).'" method="post">'
.'<input type="hidden" name="do" value="admin" />'
.'<input type="hidden" name="page" value="'.$this->getPluginName().'" />';
formSecurityToken();
echo '<table class = "inline">';
echo '<tr>'
.'<th>'.$this->getLang('btnslist_label').'</th>'
.'<th>'.$this->getLang('btnslist_code').'</th>'
.'<th>'.$this->getLang('btnslist_delete').'</th>'
.'</tr>';
if ($conf) {
foreach ($conf as $key => $button) {
echo '<tr>';
if (!$button['type']) {
echo '<td>'.hsc($button['label']).'</td>'
.'<td>'.hsc($button['code']).'</td>';
} else {
$icon = '';
if ($button['icon']) {
$icon = '<img src="'. DOKU_BASE.'lib/plugins/custombuttons/ico/'.$button['icon'].'" /> ';
}
echo '<td>'.$icon.hsc($button['label']).'</td>'
.'<td>'.hsc($button['pretag']).hsc($button['code']).hsc($button['posttag']).'</td>';
};
echo '<td><input type="checkbox" name="delete" value="'.$key.'"/></td>';
echo '</tr>';
}
}
echo '</table>';
echo '<input type="submit" class="button" value="'.$this->getLang('btn_delete').'"/>';
echo '</form>';
echo '</br></br>';
// add custom button form
echo '<h3>'.$this->getLang('addbtn').'</h3>';
echo '<form id="cb_add_button" action="'.wl($ID).'" method="post">'
.'<input type="hidden" name="do" value="admin" />'
.'<input type="hidden" name="add" value="1" />'
.'<input type="hidden" name="page" value="'.$this->getPluginName().'" />';
formSecurityToken();
echo '<table>';
echo '<tr>';
echo '<th>'.$this->getLang('addbtn_icon').'</th>';
echo '<td>'
.'<select name="icon">'
.'<option value="">'.$this->getLang('addbtn_textonly').'</option>';
$files = glob(dirname(__FILE__).'/ico/*.png');
foreach ($files as $file) {
$file = hsc(basename($file));
echo '<option value="'.$file.'">'.$file.'</option>';
};
echo '</select>';
echo '</td>';
echo '<td></td>';
echo '</tr>';
echo '<tr>'
.'<th>'.$this->getLang('addbtn_label').'</th>'
.'<td><input type="text" name="label" /></td>'
.'<td></td>'
.'</tr>';
echo '<tr>'
.'<th>'.$this->getLang('addbtn_pretag').'</th>'
.'<td><input type="text" name="pretag" /></td>'
.'<td>*</td>'
.'</tr>';
echo '<tr>'
.'<th>'.$this->getLang('addbtn_posttag').'</th>'
.'<td><input type="text" name="posttag" /></td>'
.'<td>*</td>'
.'</tr>';
echo '<tr>'
.'<th>'.$this->getLang('addbtn_code').'</th>'
.'<td><input type="text" name="code" /></td>'
.'<td></td>'
.'</tr>';
echo '</table>';
echo '<input type="submit" class="button" value="'.$this->getLang('btn_add').'" />';
echo '</form>';
echo '<div id="cb_comment">'.$this->getLang('txt_comment').'</div>';
echo '</div>';
}
}