|
1 | 1 | <?php |
| 2 | +use dokuwiki\Form\Form; |
| 3 | +use dokuwiki\plugin\sync\ProfileManager; |
| 4 | + |
2 | 5 | // must be run within Dokuwiki |
3 | 6 | if(!defined('DOKU_INC')) die(); |
4 | | -if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); |
5 | | -require_once(DOKU_PLUGIN . 'admin.php'); |
6 | | - |
7 | | -require_once(DOKU_INC . 'inc/IXR_Library.php'); |
8 | 7 |
|
9 | 8 | /** |
10 | 9 | * All DokuWiki plugins to extend the admin function |
11 | 10 | * need to inherit from this class |
12 | 11 | */ |
13 | 12 | class admin_plugin_sync extends DokuWiki_Admin_Plugin { |
14 | 13 |
|
15 | | - protected $profiles = array(); |
16 | | - protected $profno = ''; |
17 | 14 | /** @var IXR_Client */ |
18 | 15 | protected $client = null; |
19 | 16 | protected $apiversion = 0; |
20 | 17 | protected $defaultTimeout = 15; |
21 | 18 |
|
| 19 | + protected $profileManager; |
| 20 | + protected $profno; |
| 21 | + |
22 | 22 | /** |
23 | 23 | * Constructor. |
24 | 24 | */ |
25 | 25 | function __construct() { |
26 | | - $this->_profileLoad(); |
27 | | - $this->profno = preg_replace('/[^0-9]+/', '', $_REQUEST['no']); |
| 26 | + global $INPUT; |
| 27 | + |
| 28 | + $this->profileManager = new ProfileManager(); |
| 29 | + $this->profno = $INPUT->int('no', false); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * return sort order for position in admin menu |
| 34 | + */ |
| 35 | + function getMenuSort() { |
| 36 | + return 1020; |
28 | 37 | } |
29 | 38 |
|
30 | 39 | function _connect() { |
@@ -72,19 +81,12 @@ function _connect() { |
72 | 81 | return true; |
73 | 82 | } |
74 | 83 |
|
75 | | - /** |
76 | | - * return sort order for position in admin menu |
77 | | - */ |
78 | | - function getMenuSort() { |
79 | | - return 1020; |
80 | | - } |
81 | | - |
82 | 84 | /** |
83 | 85 | * handle profile saving/deleting |
84 | 86 | */ |
85 | 87 | function handle() { |
86 | 88 | if(isset($_REQUEST['prf']) && is_array($_REQUEST['prf'])) { |
87 | | - if(isset($_REQUEST['sync__delete']) && $this->profno !== '') { |
| 89 | + if(isset($_REQUEST['sync__delete']) && $this->profno !== false) { |
88 | 90 | // delete profile |
89 | 91 | unset($this->profiles[$this->profno]); |
90 | 92 | $this->profiles = array_values($this->profiles); //reindex |
@@ -182,18 +184,98 @@ function html() { |
182 | 184 | echo $this->locale_xhtml('intro'); |
183 | 185 |
|
184 | 186 | echo '<div class="sync_left">'; |
185 | | - $this->_profilelist($this->profno); |
186 | | - if($this->profno !== '') { |
| 187 | + $this->profileDropdown(); |
| 188 | + if($this->profno !== false) { |
187 | 189 | echo '<br />'; |
188 | 190 | $this->_profileView(); |
189 | 191 | } |
190 | 192 | echo '</div>'; |
191 | 193 | echo '<div class="sync_right">'; |
192 | | - $this->_profileform($this->profno); |
| 194 | + $this->profileForm(); |
193 | 195 | echo '</div>'; |
194 | 196 | } |
195 | 197 | } |
196 | 198 |
|
| 199 | + /** |
| 200 | + * Dropdown list of available sync profiles |
| 201 | + */ |
| 202 | + protected function profileDropdown() { |
| 203 | + $form = new Form( |
| 204 | + [ |
| 205 | + 'action' => wl('', ['do' => 'admin', 'page' => 'sync'], false, '&'), |
| 206 | + 'method' => 'POST', |
| 207 | + ] |
| 208 | + ); |
| 209 | + |
| 210 | + $profiles = $this->profileManager->getProfileLabels(); |
| 211 | + $profiles[''] = $this->getLang('newprofile'); |
| 212 | + |
| 213 | + $form->addFieldsetOpen($this->getLang('profile')); |
| 214 | + $form->addDropdown('no', $profiles); |
| 215 | + $form->addButton('', $this->getLang('select')); |
| 216 | + $form->addFieldsetClose(); |
| 217 | + |
| 218 | + echo $form->toHTML(); |
| 219 | + } |
| 220 | + |
| 221 | + /** |
| 222 | + * Form to edit or create a sync profile |
| 223 | + */ |
| 224 | + protected function profileForm() { |
| 225 | + $form = new Form( |
| 226 | + [ |
| 227 | + 'action' => wl('', ['do' => 'admin', 'page' => 'sync'], false, '&'), |
| 228 | + 'method' => 'POST', |
| 229 | + ] |
| 230 | + ); |
| 231 | + |
| 232 | + if($this->profno === false) { |
| 233 | + $legend = $this->getLang('create'); |
| 234 | + $profile = $this->profileManager->getEmptyConfig(); |
| 235 | + } else { |
| 236 | + $legend = $this->getLang('edit'); |
| 237 | + $profile = $this->profileManager->getProfileConfig($this->profno); |
| 238 | + } |
| 239 | + |
| 240 | + $depths = [ |
| 241 | + 0 => $this->getLang('level0'), |
| 242 | + 1 => $this->getLang('level1'), |
| 243 | + 2 => $this->getLang('level2'), |
| 244 | + 3 => $this->getLang('level3'), |
| 245 | + ]; |
| 246 | + $types = [ |
| 247 | + 0 => $this->getLang('type0'), |
| 248 | + 1 => $this->getLang('type1'), |
| 249 | + 2 => $this->getLang('type2'), |
| 250 | + ]; |
| 251 | + |
| 252 | + $form->addFieldsetOpen($legend); |
| 253 | + $form->setHiddenField('no', $this->profno); |
| 254 | + $form->addTextInput('prf[server]', $this->getLang('server'))->val($profile['server']); |
| 255 | + $form->addHTML('<samp>http://example.com/dokuwiki/lib/exe/xmlrpc.php</samp>'); |
| 256 | + $form->addTextInput('prf[ns]', $this->getLang('ns'))->val($profile['ns']); |
| 257 | + $form->addDropdown('prf[depth]', $depths, $this->getLang('depth'))->val($profile['depth']); |
| 258 | + $form->addTextInput('prf[user]', $this->getLang('user'))->val($profile['user']); |
| 259 | + $form->addPasswordInput('prf[pass]', $this->getLang('pass'))->val($profile['pass']); |
| 260 | + $form->addTextInput('prf[timeout]', $this->getLang('timeout'))->val($profile['timeout']); |
| 261 | + $form->addDropdown('prf[type]', $types, $this->getLang('type'))->val($profile['type']); |
| 262 | + $form->addButton('', $this->getLang('save'))->attr('type', 'submit'); |
| 263 | + |
| 264 | +// if($no !== '' && $this->profiles[$no]['ltime']) { |
| 265 | +// echo '<small>' . $this->getLang('changewarn') . '</small>'; |
| 266 | +// } |
| 267 | + |
| 268 | + $form->addFieldsetClose(); |
| 269 | + |
| 270 | + if($this->profno !== false) { |
| 271 | + $form->addFieldsetOpen($this->getLang('delete')); |
| 272 | + $form->addButton('sync__delete', $this->getLang('delete')); |
| 273 | + $form->addFieldsetClose(); |
| 274 | + } |
| 275 | + |
| 276 | + echo $form->toHTML(); |
| 277 | + } |
| 278 | + |
197 | 279 | /** |
198 | 280 | * Load profiles from serialized storage |
199 | 281 | */ |
@@ -245,97 +327,6 @@ function _profileView() { |
245 | 327 | echo '</form>'; |
246 | 328 | } |
247 | 329 |
|
248 | | - /** |
249 | | - * Dropdown list of available sync profiles |
250 | | - */ |
251 | | - function _profilelist($no = '') { |
252 | | - echo '<form action="" method="post">'; |
253 | | - echo '<fieldset><legend>' . $this->getLang('profile') . '</legend>'; |
254 | | - echo '<select name="no" class="edit">'; |
255 | | - echo ' <option value="">' . $this->getLang('newprofile') . '</option>'; |
256 | | - foreach($this->profiles as $pno => $opts) { |
257 | | - $srv = parse_url($opts['server']); |
258 | | - |
259 | | - echo '<option value="' . hsc($pno) . '" ' . (($no !== '' && $pno == $no) ? 'selected="selected"' : '') . '>'; |
260 | | - echo ($pno + 1) . '. '; |
261 | | - if($opts['user']) echo hsc($opts['user']) . '@'; |
262 | | - echo hsc($srv['host']); |
263 | | - if($opts['ns']) echo ':' . hsc($opts['ns']); |
264 | | - echo '</option>'; |
265 | | - } |
266 | | - echo '</select>'; |
267 | | - echo '<input type="submit" value="' . $this->getLang('select') . '" class="button" />'; |
268 | | - echo '</fieldset>'; |
269 | | - echo '</form>'; |
270 | | - } |
271 | | - |
272 | | - /** |
273 | | - * Form to edit or create a sync profile |
274 | | - */ |
275 | | - function _profileform($no = '') { |
276 | | - echo '<form action="" method="post" class="sync_profile">'; |
277 | | - echo '<fieldset><legend>'; |
278 | | - if($no !== '') { |
279 | | - echo $this->getLang('edit'); |
280 | | - } else { |
281 | | - echo $this->getLang('create'); |
282 | | - } |
283 | | - echo '</legend>'; |
284 | | - |
285 | | - echo '<input type="hidden" name="no" value="' . hsc($no) . '" />'; |
286 | | - |
287 | | - echo '<label for="sync__server">' . $this->getLang('server') . '</label> '; |
288 | | - echo '<input type="text" name="prf[server]" id="sync__server" class="edit" value="' . hsc($this->profiles[$no]['server']) . '" />'; |
289 | | - echo '<samp>http://example.com/dokuwiki/lib/exe/xmlrpc.php</samp>'; |
290 | | - |
291 | | - echo '<label for="sync__ns">' . $this->getLang('ns') . '</label> '; |
292 | | - echo '<input type="text" name="prf[ns]" id="sync__ns" class="edit" value="' . hsc($this->profiles[$no]['ns']) . '" />'; |
293 | | - |
294 | | - echo '<label for="sync__depth">' . $this->getLang('depth') . '</label> '; |
295 | | - echo '<select name="prf[depth]" id="sync__depth" class="edit">'; |
296 | | - echo '<option value="0" ' . (($this->profiles[$no]['depth'] == 0) ? 'selected="selected"' : '') . '>' . $this->getLang('level0') . '</option>'; |
297 | | - echo '<option value="1" ' . (($this->profiles[$no]['depth'] == 1) ? 'selected="selected"' : '') . '>' . $this->getLang('level1') . '</option>'; |
298 | | - echo '<option value="2" ' . (($this->profiles[$no]['depth'] == 2) ? 'selected="selected"' : '') . '>' . $this->getLang('level2') . '</option>'; |
299 | | - echo '<option value="3" ' . (($this->profiles[$no]['depth'] == 3) ? 'selected="selected"' : '') . '>' . $this->getLang('level3') . '</option>'; |
300 | | - echo '</select>'; |
301 | | - |
302 | | - echo '<label for="sync__user">' . $this->getLang('user') . '</label> '; |
303 | | - echo '<input type="text" name="prf[user]" id="sync__user" class="edit" value="' . hsc($this->profiles[$no]['user']) . '" />'; |
304 | | - |
305 | | - echo '<label for="sync__pass">' . $this->getLang('pass') . '</label> '; |
306 | | - echo '<input type="password" name="prf[pass]" id="sync__pass" class="edit" value="' . hsc($this->profiles[$no]['pass']) . '" />'; |
307 | | - |
308 | | - echo '<label for="sync__timeout">' . $this->getLang('timeout') . '</label>'; |
309 | | - echo '<input type="number" name="prf[timeout]" id="sync__timeout" class="edit" value="' . hsc($this->profiles[$no]['timeout']) . '" />'; |
310 | | - |
311 | | - echo '<span>' . $this->getLang('type') . '</span>'; |
312 | | - |
313 | | - echo '<div class="type">'; |
314 | | - echo '<input type="radio" name="prf[type]" id="sync__type0" value="0" ' . (($this->profiles[$no]['type'] == 0) ? 'checked="checked"' : '') . '/>'; |
315 | | - echo '<label for="sync__type0">' . $this->getLang('type0') . '</label> '; |
316 | | - |
317 | | - echo '<input type="radio" name="prf[type]" id="sync__type1" value="1" ' . (($this->profiles[$no]['type'] == 1) ? 'checked="checked"' : '') . '/>'; |
318 | | - echo '<label for="sync__type1">' . $this->getLang('type1') . '</label> '; |
319 | | - |
320 | | - echo '<input type="radio" name="prf[type]" id="sync__type2" value="2" ' . (($this->profiles[$no]['type'] == 2) ? 'checked="checked"' : '') . '/>'; |
321 | | - echo '<label for="sync__type2">' . $this->getLang('type2') . '</label> '; |
322 | | - echo '</div>'; |
323 | | - |
324 | | - echo '<div class="submit">'; |
325 | | - echo '<input type="submit" value="' . $this->getLang('save') . '" class="button" />'; |
326 | | - if($no !== '' && $this->profiles[$no]['ltime']) { |
327 | | - echo '<small>' . $this->getLang('changewarn') . '</small>'; |
328 | | - } |
329 | | - echo '</div>'; |
330 | | - |
331 | | - echo '<div class="submit">'; |
332 | | - echo '<input name="sync__delete" type="submit" value="' . $this->getLang('delete') . '" class="button" />'; |
333 | | - echo '</div>'; |
334 | | - |
335 | | - echo '</fieldset>'; |
336 | | - echo '</form>'; |
337 | | - } |
338 | | - |
339 | 330 | /** |
340 | 331 | * Lock files that will be modified on either side. |
341 | 332 | * |
|
0 commit comments