forked from chimeric/dokuwiki-plugin-loadskin
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathadmin.php
123 lines (108 loc) · 4.12 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
<?php
/**
* DokuWiki Plugin Loadskin
*
* @author Michael Klier <[email protected]>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'admin.php');
/**
* All DokuWiki plugins to extend the admin function
* need to inherit from this class
*/
class admin_plugin_loadskin extends DokuWiki_Admin_Plugin {
/**
* Constructor
*/
public function __construct() {
$this->setupLocale();
$this->config = DOKU_CONF.'loadskin.conf';
}
/**
* return sort order for position in admin menu
*/
public function getMenuSort() {
return 300;
}
/**
* handle user request
*/
public function handle() {
global $INPUT;
$data = array();
if($INPUT->str('pattern')) {
if (!checkSecurityToken()) return;
$id = cleanID($INPUT->str('pattern'));
if($INPUT->str('act') == 'add') {
if(@file_exists($this->config)) {
$data = unserialize(io_readFile($this->config, false));
$data[$id] = $INPUT->str('tpl');
io_saveFile($this->config, serialize($data));
} else {
$data[$id] = $INPUT->str('tpl');
io_saveFile($this->config, serialize($data));
}
}
if($INPUT->str('act') == 'del') {
$data = unserialize(io_readFile($this->config, false));
unset($data[$id]);
io_saveFile($this->config, serialize($data));
}
}
}
/**
* output appropriate html
*/
public function html() {
global $lang;
$helper = $this->loadHelper('loadskin', true);
print '<div id="plugin__loadskin">';
print $this->locale_xhtml('intro');
$form = new Doku_Form(array());
$form->startFieldSet('Add rule');
$form->addHidden('id',$ID);
$form->addHidden('do','admin');
$form->addHidden('page','loadskin');
$form->addHidden('act','add');
$form->addElement(form_makeOpenTag('p'));
$form->addElement(form_makeTextField('pattern','',$this->getLang('pattern')));
$form->addElement(form_makeCloseTag('p'));
$form->addElement(form_makeOpenTag('p'));
$form->addElement(form_makeListboxField('tpl',$helper->getTemplates(),'',$this->getLang('template')));
$form->addElement(form_makeCloseTag('p'));
$form->addElement(form_makeButton('submit','',$lang['btn_save']));
$form->endFieldSet();
$form->printForm();
if(@file_exists($this->config)) {
$data = unserialize(io_readFile($this->config, false));
if(!empty($data)) {
echo '<table class="inline">' . DOKU_LF;
echo ' <tr>' . DOKU_LF;
echo ' <th>' . $this->getLang('pattern') . '</th>' . DOKU_LF;
echo ' <th>' . $this->getLang('template') . '</th>' . DOKU_LF;
echo ' <th>' . $this->getLang('action') . '</th>' . DOKU_LF;
echo ' </tr>' . DOKU_LF;
foreach($data as $key => $value) {
echo ' <tr>' . DOKU_LF;
echo ' <td>' . $key . '</td>' . DOKU_LF;
echo ' <td>' . $value . '</td>' . DOKU_LF;
echo ' <td>' . DOKU_LF;
$form = new Doku_Form(array());
$form->addHidden('do','admin');
$form->addHidden('page','loadskin');
$form->addHidden('act','del');
$form->addHidden('id',$ID);
$form->addHidden('pattern',$key);
$form->addElement(form_makeButton('submit','',$lang['btn_delete']));
$form->printForm();
echo ' </td>' . DOKU_LF;
echo ' </tr>' . DOKU_LF;
}
echo '</table>' . DOKU_LF;
}
}
print '</div>';
}
}
//vim:ts=4:sw=4:et:enc=utf-8: