summaryrefslogtreecommitdiff
path: root/lib/plugins/config/settings/extra.class.php
blob: 232a8177f477072a7a7852da2354b828a6958a6d (plain)
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?php
/**
 * additional setting classes specific to these settings
 *
 * @author    Chris Smith <chris@jalakai.co.uk>
 */

if (!class_exists('setting_sepchar')) {
    /**
     * Class setting_sepchar
     */
    class setting_sepchar extends setting_multichoice {

        /**
         * @param string $key
         * @param array|null $param array with metadata of setting
         */
        function setting_sepchar($key,$param=null) {
            $str = '_-.';
            for ($i=0;$i<strlen($str);$i++) $this->_choices[] = $str{$i};

            // call foundation class constructor
            $this->setting($key,$param);
        }
    }
}

if (!class_exists('setting_savedir')) {
    /**
     * Class setting_savedir
     */
    class setting_savedir extends setting_string {

        /**
         * update changed setting with user provided value $input
         * - if changed value fails error check, save it to $this->_input (to allow echoing later)
         * - if changed value passes error check, set $this->_local to the new value
         *
         * @param  mixed   $input   the new value
         * @return boolean          true if changed, false otherwise (also on error)
         */
        function update($input) {
            if ($this->is_protected()) return false;

            $value = is_null($this->_local) ? $this->_default : $this->_local;
            if ($value == $input) return false;

            if (!init_path($input)) {
                $this->_error = true;
                $this->_input = $input;
                return false;
            }

            $this->_local = $input;
            return true;
        }
    }
}

if (!class_exists('setting_authtype')) {
    /**
     * Class setting_authtype
     */
    class setting_authtype extends setting_multichoice {

        /**
         * Receives current values for the setting $key
         *
         * @param mixed $default   default setting value
         * @param mixed $local     local setting value
         * @param mixed $protected protected setting value
         */
        function initialize($default,$local,$protected) {
            /** @var $plugin_controller Doku_Plugin_Controller */
            global $plugin_controller;

            // retrieve auth types provided by plugins
            foreach ($plugin_controller->getList('auth') as $plugin) {
                $this->_choices[] = $plugin;
            }

            parent::initialize($default,$local,$protected);
        }

        /**
         * update changed setting with user provided value $input
         * - if changed value fails error check, save it to $this->_input (to allow echoing later)
         * - if changed value passes error check, set $this->_local to the new value
         *
         * @param  mixed   $input   the new value
         * @return boolean          true if changed, false otherwise (also on error)
         */
        function update($input) {
            /** @var $plugin_controller Doku_Plugin_Controller */
            global $plugin_controller;

            // is an update possible/requested?
            $local = $this->_local;                       // save this, parent::update() may change it
            if (!parent::update($input)) return false;    // nothing changed or an error caught by parent
            $this->_local = $local;                       // restore original, more error checking to come

            // attempt to load the plugin
            $auth_plugin = $plugin_controller->load('auth', $input);

            // @TODO: throw an error in plugin controller instead of returning null
            if (is_null($auth_plugin)) {
                $this->_error = true;
                msg('Cannot load Auth Plugin "' . $input . '"', -1);
                return false;
            }

            // verify proper instantiation (is this really a plugin?) @TODO use instanceof? implement interface?
            if (is_object($auth_plugin) && !method_exists($auth_plugin, 'getPluginName')) {
                $this->_error = true;
                msg('Cannot create Auth Plugin "' . $input . '"', -1);
                return false;
            }

            // did we change the auth type? logout
            global $conf;
            if($conf['authtype'] != $input) {
                msg('Authentication system changed. Please re-login.');
                auth_logoff();
            }

            $this->_local = $input;
            return true;
        }
    }
}

if (!class_exists('setting_im_convert')) {
    /**
     * Class setting_im_convert
     */
    class setting_im_convert extends setting_string {

        /**
         * update changed setting with user provided value $input
         * - if changed value fails error check, save it to $this->_input (to allow echoing later)
         * - if changed value passes error check, set $this->_local to the new value
         *
         * @param  mixed   $input   the new value
         * @return boolean          true if changed, false otherwise (also on error)
         */
        function update($input) {
            if ($this->is_protected()) return false;

            $input = trim($input);

            $value = is_null($this->_local) ? $this->_default : $this->_local;
            if ($value == $input) return false;

            if ($input && !@file_exists($input)) {
                $this->_error = true;
                $this->_input = $input;
                return false;
            }

            $this->_local = $input;
            return true;
        }
    }
}

if (!class_exists('setting_disableactions')) {
    /**
     * Class setting_disableactions
     */
    class setting_disableactions extends setting_multicheckbox {

        /**
         * Build html for label and input of setting
         *
         * @param DokuWiki_Plugin $plugin object of config plugin
         * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
         * @return array with content array(string $label_html, string $input_html)
         */
        function html(&$plugin, $echo=false) {
            global $lang;

            // make some language adjustments (there must be a better way)
            // transfer some DokuWiki language strings to the plugin
            if (!$plugin->localised) $plugin->setupLocale();
            $plugin->lang[$this->_key.'_revisions'] = $lang['btn_revs'];

            foreach ($this->_choices as $choice)
              if (isset($lang['btn_'.$choice])) $plugin->lang[$this->_key.'_'.$choice] = $lang['btn_'.$choice];

            return parent::html($plugin, $echo);
        }
    }
}

if (!class_exists('setting_compression')) {
    /**
     * Class setting_compression
     */
    class setting_compression extends setting_multichoice {

        var $_choices = array('0');      // 0 = no compression, always supported

        /**
         * Receives current values for the setting $key
         *
         * @param mixed $default   default setting value
         * @param mixed $local     local setting value
         * @param mixed $protected protected setting value
         */
        function initialize($default,$local,$protected) {

            // populate _choices with the compression methods supported by this php installation
            if (function_exists('gzopen')) $this->_choices[] = 'gz';
            if (function_exists('bzopen')) $this->_choices[] = 'bz2';

            parent::initialize($default,$local,$protected);
        }
    }
}

if (!class_exists('setting_license')) {
    /**
     * Class setting_license
     */
    class setting_license extends setting_multichoice {

        var $_choices = array('');      // none choosen

        /**
         * Receives current values for the setting $key
         *
         * @param mixed $default   default setting value
         * @param mixed $local     local setting value
         * @param mixed $protected protected setting value
         */
        function initialize($default,$local,$protected) {
            global $license;

            foreach($license as $key => $data){
                $this->_choices[] = $key;
                $this->lang[$this->_key.'_o_'.$key] = $data['name']; // stored in setting
            }

            parent::initialize($default,$local,$protected);
        }
    }
}


if (!class_exists('setting_renderer')) {
    /**
     * Class setting_renderer
     */
    class setting_renderer extends setting_multichoice {
        var $_prompts = array();
        var $_format = null;

        /**
         * Receives current values for the setting $key
         *
         * @param mixed $default   default setting value
         * @param mixed $local     local setting value
         * @param mixed $protected protected setting value
         */
        function initialize($default,$local,$protected) {
            $format = $this->_format;

            foreach (plugin_list('renderer') as $plugin) {
                $renderer = plugin_load('renderer',$plugin);
                if (method_exists($renderer,'canRender') && $renderer->canRender($format)) {
                    $this->_choices[] = $plugin;

                    $info = $renderer->getInfo();
                    $this->_prompts[$plugin] = $info['name'];
                }
            }

            parent::initialize($default,$local,$protected);
        }

        /**
         * Build html for label and input of setting
         *
         * @param DokuWiki_Plugin $plugin object of config plugin
         * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
         * @return array with content array(string $label_html, string $input_html)
         */
        function html(&$plugin, $echo=false) {

            // make some language adjustments (there must be a better way)
            // transfer some plugin names to the config plugin
            if (!$plugin->localised) $plugin->setupLocale();

            foreach ($this->_choices as $choice) {
                if (!isset($plugin->lang[$this->_key.'_o_'.$choice])) {
                    if (!isset($this->_prompts[$choice])) {
                        $plugin->lang[$this->_key.'_o_'.$choice] = sprintf($plugin->lang['renderer__core'],$choice);
                    } else {
                        $plugin->lang[$this->_key.'_o_'.$choice] = sprintf($plugin->lang['renderer__plugin'],$this->_prompts[$choice]);
                    }
                }
            }
            return parent::html($plugin, $echo);
        }
    }
}