1 | <?php |
||
19 | class admin_plugin_config extends DokuWiki_Admin_Plugin { |
||
20 | |||
21 | const IMGDIR = DOKU_BASE . 'lib/plugins/config/images/'; |
||
22 | |||
23 | /** @var Configuration */ |
||
24 | protected $configuration; |
||
25 | |||
26 | /** @var bool were there any errors in the submitted data? */ |
||
27 | protected $hasErrors = false; |
||
28 | |||
29 | /** @var bool have the settings translations been loaded? */ |
||
30 | protected $promptsLocalized = false; |
||
31 | |||
32 | /** |
||
33 | * admin_plugin_config constructor. |
||
34 | */ |
||
35 | public function __construct() { |
||
38 | |||
39 | /** |
||
40 | * handle user request |
||
41 | */ |
||
42 | public function handle() { |
||
70 | |||
71 | /** |
||
72 | * output appropriate html |
||
73 | */ |
||
74 | public function html() { |
||
75 | $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here. |
||
76 | global $lang; |
||
77 | global $ID; |
||
78 | |||
79 | $this->setupLocale(true); |
||
80 | |||
81 | echo $this->locale_xhtml('intro'); |
||
82 | |||
83 | echo '<div id="config__manager">'; |
||
84 | |||
85 | if($this->configuration->isLocked()) { |
||
86 | echo '<div class="info">' . $this->getLang('locked') . '</div>'; |
||
87 | } |
||
88 | |||
89 | // POST to script() instead of wl($ID) so config manager still works if |
||
90 | // rewrite config is broken. Add $ID as hidden field to remember |
||
91 | // current ID in most cases. |
||
92 | echo '<form action="' . script() . '" method="post">'; |
||
93 | echo '<div class="no"><input type="hidden" name="id" value="' . $ID . '" /></div>'; |
||
94 | formSecurityToken(); |
||
95 | $this->printH1('dokuwiki_settings', $this->getLang('_header_dokuwiki')); |
||
96 | |||
97 | $in_fieldset = false; |
||
98 | $first_plugin_fieldset = true; |
||
99 | $first_template_fieldset = true; |
||
100 | foreach($this->configuration->getSettings() as $setting) { |
||
101 | if(is_a($setting, SettingHidden::class)) { |
||
102 | continue; |
||
103 | } else if(is_a($setting, settingFieldset::class)) { |
||
104 | // config setting group |
||
105 | if($in_fieldset) { |
||
106 | echo '</table>'; |
||
107 | echo '</div>'; |
||
108 | echo '</fieldset>'; |
||
109 | } else { |
||
110 | $in_fieldset = true; |
||
111 | } |
||
112 | if($first_plugin_fieldset && $setting->getType() == 'plugin') { |
||
113 | $this->printH1('plugin_settings', $this->getLang('_header_plugin')); |
||
114 | $first_plugin_fieldset = false; |
||
115 | } else if($first_template_fieldset && $setting->getType() == 'template') { |
||
116 | $this->printH1('template_settings', $this->getLang('_header_template')); |
||
117 | $first_template_fieldset = false; |
||
118 | } |
||
119 | echo '<fieldset id="' . $setting->getKey() . '">'; |
||
120 | echo '<legend>' . $setting->prompt($this) . '</legend>'; |
||
121 | echo '<div class="table">'; |
||
122 | echo '<table class="inline">'; |
||
123 | } else { |
||
124 | // config settings |
||
125 | list($label, $input) = $setting->html($this, $this->hasErrors); |
||
126 | |||
127 | $class = $setting->isDefault() |
||
128 | ? ' class="default"' |
||
129 | : ($setting->isProtected() ? ' class="protected"' : ''); |
||
130 | $error = $setting->hasError() |
||
131 | ? ' class="value error"' |
||
132 | : ' class="value"'; |
||
133 | $icon = $setting->caution() |
||
134 | ? '<img src="' . self::IMGDIR . $setting->caution() . '.png" ' . |
||
135 | 'alt="' . $setting->caution() . '" title="' . $this->getLang($setting->caution()) . '" />' |
||
136 | : ''; |
||
137 | |||
138 | echo '<tr' . $class . '>'; |
||
139 | echo '<td class="label">'; |
||
140 | echo '<span class="outkey">' . $setting->getPrettyKey() . '</span>'; |
||
141 | echo $icon . $label; |
||
142 | echo '</td>'; |
||
143 | echo '<td' . $error . '>' . $input . '</td>'; |
||
144 | echo '</tr>'; |
||
145 | } |
||
146 | } |
||
147 | |||
148 | echo '</table>'; |
||
149 | echo '</div>'; |
||
150 | if($in_fieldset) { |
||
151 | echo '</fieldset>'; |
||
152 | } |
||
153 | |||
154 | // show undefined settings list |
||
155 | $undefined_settings = $this->configuration->getUndefined(); |
||
156 | if($allow_debug && !empty($undefined_settings)) { |
||
157 | /** |
||
158 | * Callback for sorting settings |
||
159 | * |
||
160 | * @param Setting $a |
||
161 | * @param Setting $b |
||
162 | * @return int if $a is lower/equal/higher than $b |
||
163 | */ |
||
164 | function settingNaturalComparison($a, $b) { |
||
201 | |||
202 | /** |
||
203 | * @param bool $prompts |
||
204 | */ |
||
205 | public function setupLocale($prompts = false) { |
||
211 | |||
212 | /** |
||
213 | * Generates a two-level table of contents for the config plugin. |
||
214 | * |
||
215 | * @author Ben Coburn <[email protected]> |
||
216 | * |
||
217 | * @return array |
||
218 | */ |
||
219 | public function getTOC() { |
||
264 | |||
265 | /** |
||
266 | * @param string $id |
||
267 | * @param string $text |
||
268 | */ |
||
269 | protected function printH1($id, $text) { |
||
272 | |||
273 | /** |
||
274 | * Adds a translation to this plugin's language array |
||
275 | * |
||
276 | * Used by some settings to set up dynamic translations |
||
277 | * |
||
278 | * @param string $key |
||
279 | * @param string $value |
||
280 | */ |
||
281 | public function addLang($key, $value) { |
||
285 | } |
||
286 |