Completed
Push — sidebaracl ( 7a112d...7c3e4a )
by Andreas
04:38
created

setting_no_default

Complexity

Total Complexity 0

Size/Duplication

Total Lines 4
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 0
lcom 0
cbo 1
dl 0
loc 4
1
<?php
2
/**
3
 * Configuration Class and generic setting classes
4
 *
5
 * @author  Chris Smith <[email protected]>
6
 * @author  Ben Coburn <[email protected]>
7
 */
8
9
10
if(!defined('CM_KEYMARKER')) define('CM_KEYMARKER','____');
11
12
if (!class_exists('configuration')) {
13
    /**
14
     * Class configuration
15
     */
16
    class configuration {
17
18
        var $_name = 'conf';           // name of the config variable found in the files (overridden by $config['varname'])
19
        var $_format = 'php';          // format of the config file, supported formats - php (overridden by $config['format'])
20
        var $_heading = '';            // heading string written at top of config file - don't include comment indicators
21
        var $_loaded = false;          // set to true after configuration files are loaded
22
        var $_metadata = array();      // holds metadata describing the settings
23
        /** @var setting[]  */
24
        var $setting = array();        // array of setting objects
25
        var $locked = false;           // configuration is considered locked if it can't be updated
26
        var $show_disabled_plugins = false;
27
28
        // configuration filenames
29
        var $_default_files  = array();
30
        var $_local_files = array();      // updated configuration is written to the first file
31
        var $_protected_files = array();
32
33
        var $_plugin_list = null;
34
35
        /**
36
         * constructor
37
         *
38
         * @param string $datafile path to config metadata file
39
         */
40
        public function __construct($datafile) {
41
            global $conf, $config_cascade;
42
43
            if (!file_exists($datafile)) {
44
                msg('No configuration metadata found at - '.htmlspecialchars($datafile),-1);
45
                return;
46
            }
47
            $meta = array();
48
            include($datafile);
49
50
            if (isset($config['varname'])) $this->_name = $config['varname'];
0 ignored issues
show
Bug introduced by
The variable $config does not exist. Did you mean $config_cascade?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
51
            if (isset($config['format'])) $this->_format = $config['format'];
52
            if (isset($config['heading'])) $this->_heading = $config['heading'];
53
54
            $this->_default_files = $config_cascade['main']['default'];
55
            $this->_local_files = $config_cascade['main']['local'];
56
            $this->_protected_files = $config_cascade['main']['protected'];
57
58
            $this->locked = $this->_is_locked();
59
            $this->_metadata = array_merge($meta, $this->get_plugintpl_metadata($conf['template']));
60
            $this->retrieve_settings();
61
        }
62
63
        /**
64
         * Retrieve and stores settings in setting[] attribute
65
         */
66
        public function retrieve_settings() {
67
            global $conf;
68
            $no_default_check = array('setting_fieldset', 'setting_undefined', 'setting_no_class');
69
70
            if (!$this->_loaded) {
71
                $default = array_merge($this->get_plugintpl_default($conf['template']), $this->_read_config_group($this->_default_files));
72
                $local = $this->_read_config_group($this->_local_files);
73
                $protected = $this->_read_config_group($this->_protected_files);
74
75
                $keys = array_merge(array_keys($this->_metadata),array_keys($default), array_keys($local), array_keys($protected));
76
                $keys = array_unique($keys);
77
78
                $param = null;
79
                foreach ($keys as $key) {
80
                    if (isset($this->_metadata[$key])) {
81
                        $class = $this->_metadata[$key][0];
82
83
                        if($class && class_exists('setting_'.$class)){
84
                            $class = 'setting_'.$class;
85
                        } else {
86
                            if($class != '') {
87
                                $this->setting[] = new setting_no_class($key,$param);
88
                            }
89
                            $class = 'setting';
90
                        }
91
92
                        $param = $this->_metadata[$key];
93
                        array_shift($param);
94
                    } else {
95
                        $class = 'setting_undefined';
96
                        $param = null;
97
                    }
98
99
                    if (!in_array($class, $no_default_check) && !isset($default[$key])) {
100
                        $this->setting[] = new setting_no_default($key,$param);
101
                    }
102
103
                    $this->setting[$key] = new $class($key,$param);
104
                    $this->setting[$key]->initialize($default[$key],$local[$key],$protected[$key]);
105
                }
106
107
                $this->_loaded = true;
108
            }
109
        }
110
111
        /**
112
         * Stores setting[] array to file
113
         *
114
         * @param string $id     Name of plugin, which saves the settings
115
         * @param string $header Text at the top of the rewritten settings file
116
         * @param bool $backup   backup current file? (remove any existing backup)
117
         * @return bool succesful?
118
         */
119
        public function save_settings($id, $header='', $backup=true) {
120
            global $conf;
121
122
            if ($this->locked) return false;
123
124
            // write back to the last file in the local config cascade
125
            $file = end($this->_local_files);
126
127
            // backup current file (remove any existing backup)
128
            if (file_exists($file) && $backup) {
129
                if (file_exists($file.'.bak')) @unlink($file.'.bak');
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
130
                if (!io_rename($file, $file.'.bak')) return false;
131
            }
132
133
            if (!$fh = @fopen($file, 'wb')) {
134
                io_rename($file.'.bak', $file);     // problem opening, restore the backup
135
                return false;
136
            }
137
138
            if (empty($header)) $header = $this->_heading;
139
140
            $out = $this->_out_header($id,$header);
141
142
            foreach ($this->setting as $setting) {
143
                $out .= $setting->out($this->_name, $this->_format);
144
            }
145
146
            $out .= $this->_out_footer();
147
148
            @fwrite($fh, $out);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
149
            fclose($fh);
150
            if($conf['fperm']) chmod($file, $conf['fperm']);
151
            return true;
152
        }
153
154
        /**
155
         * Update last modified time stamp of the config file
156
         *
157
         * @return bool
158
         */
159
        public function touch_settings(){
160
            if ($this->locked) return false;
161
            $file = end($this->_local_files);
162
            return @touch($file);
163
        }
164
165
        /**
166
         * Read and merge given config files
167
         *
168
         * @param array $files file paths
169
         * @return array config settings
170
         */
171
        protected function _read_config_group($files) {
172
            $config = array();
173
            foreach ($files as $file) {
174
                $config = array_merge($config, $this->_read_config($file));
175
            }
176
177
            return $config;
178
        }
179
180
        /**
181
         * Return an array of config settings
182
         *
183
         * @param string $file file path
184
         * @return array config settings
185
         */
186
        function _read_config($file) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
187
188
            if (!$file) return array();
189
190
            $config = array();
191
192
            if ($this->_format == 'php') {
193
194
                if(file_exists($file)){
195
                    $contents = @php_strip_whitespace($file);
196
                }else{
197
                    $contents = '';
198
                }
199
                $pattern = '/\$'.$this->_name.'\[[\'"]([^=]+)[\'"]\] ?= ?(.*?);(?=[^;]*(?:\$'.$this->_name.'|$))/s';
200
                $matches=array();
201
                preg_match_all($pattern,$contents,$matches,PREG_SET_ORDER);
202
203
                for ($i=0; $i<count($matches); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
204
                    $value = $matches[$i][2];
205
206
                    // correct issues with the incoming data
207
                    // FIXME ... for now merge multi-dimensional array indices using ____
208
                    $key = preg_replace('/.\]\[./',CM_KEYMARKER,$matches[$i][1]);
209
210
                    // handle arrays
211
                    if(preg_match('/^array ?\((.*)\)/', $value, $match)){
212
                        $arr = explode(',', $match[1]);
213
214
                        // remove quotes from quoted strings & unescape escaped data
215
                        $len = count($arr);
216
                        for($j=0; $j<$len; $j++){
217
                            $arr[$j] = trim($arr[$j]);
218
                            $arr[$j] = preg_replace('/^(\'|")(.*)(?<!\\\\)\1$/s','$2',$arr[$j]);
219
                            $arr[$j] = strtr($arr[$j], array('\\\\'=>'\\','\\\''=>'\'','\\"'=>'"'));
220
                        }
221
222
                        $value = $arr;
223
                    }else{
224
                        // remove quotes from quoted strings & unescape escaped data
225
                        $value = preg_replace('/^(\'|")(.*)(?<!\\\\)\1$/s','$2',$value);
226
                        $value = strtr($value, array('\\\\'=>'\\','\\\''=>'\'','\\"'=>'"'));
227
                    }
228
229
                    $config[$key] = $value;
230
                }
231
            }
232
233
            return $config;
234
        }
235
236
        /**
237
         * Returns header of rewritten settings file
238
         *
239
         * @param string $id plugin name of which generated this output
240
         * @param string $header additional text for at top of the file
241
         * @return string text of header
242
         */
243
        protected function _out_header($id, $header) {
244
            $out = '';
245
            if ($this->_format == 'php') {
246
                $out .= '<'.'?php'."\n".
247
                      "/*\n".
248
                      " * ".$header."\n".
249
                      " * Auto-generated by ".$id." plugin\n".
250
                      " * Run for user: ".$_SERVER['REMOTE_USER']."\n".
251
                      " * Date: ".date('r')."\n".
252
                      " */\n\n";
253
            }
254
255
            return $out;
256
        }
257
258
        /**
259
         * Returns footer of rewritten settings file
260
         *
261
         * @return string text of footer
262
         */
263
        protected function _out_footer() {
264
            $out = '';
265
            if ($this->_format == 'php') {
266
                $out .= "\n// end auto-generated content\n";
267
            }
268
269
            return $out;
270
        }
271
272
        /**
273
         * Configuration is considered locked if there is no local settings filename
274
         * or the directory its in is not writable or the file exists and is not writable
275
         *
276
         * @return bool true: locked, false: writable
277
         */
278
        protected function _is_locked() {
279
            if (!$this->_local_files) return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_local_files of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
280
281
            $local = $this->_local_files[0];
282
283
            if (!is_writable(dirname($local))) return true;
284
            if (file_exists($local) && !is_writable($local)) return true;
285
286
            return false;
287
        }
288
289
        /**
290
         * not used ... conf's contents are an array!
291
         * reduce any multidimensional settings to one dimension using CM_KEYMARKER
292
         *
293
         * @param $conf
294
         * @param string $prefix
295
         * @return array
296
         */
297
        protected function _flatten($conf,$prefix='') {
298
299
            $out = array();
300
301
            foreach($conf as $key => $value) {
302
                if (!is_array($value)) {
303
                    $out[$prefix.$key] = $value;
304
                    continue;
305
                }
306
307
                $tmp = $this->_flatten($value,$prefix.$key.CM_KEYMARKER);
308
                $out = array_merge($out,$tmp);
309
            }
310
311
            return $out;
312
        }
313
314
        /**
315
         * Returns array of plugin names
316
         *
317
         * @return array plugin names
318
         * @triggers PLUGIN_CONFIG_PLUGINLIST event
319
         */
320
        function get_plugin_list() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
321
            if (is_null($this->_plugin_list)) {
322
                $list = plugin_list('',$this->show_disabled_plugins);
323
324
                // remove this plugin from the list
325
                $idx = array_search('config',$list);
326
                unset($list[$idx]);
327
328
                trigger_event('PLUGIN_CONFIG_PLUGINLIST',$list);
329
                $this->_plugin_list = $list;
330
            }
331
332
            return $this->_plugin_list;
333
        }
334
335
        /**
336
         * load metadata for plugin and template settings
337
         *
338
         * @param string $tpl name of active template
339
         * @return array metadata of settings
340
         */
341
        function get_plugintpl_metadata($tpl){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
342
            $file     = '/conf/metadata.php';
343
            $class    = '/conf/settings.class.php';
344
            $metadata = array();
345
346
            foreach ($this->get_plugin_list() as $plugin) {
347
                $plugin_dir = plugin_directory($plugin);
348
                if (file_exists(DOKU_PLUGIN.$plugin_dir.$file)){
349
                    $meta = array();
350
                    @include(DOKU_PLUGIN.$plugin_dir.$file);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
351
                    @include(DOKU_PLUGIN.$plugin_dir.$class);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
352
                    if (!empty($meta)) {
353
                        $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.'plugin_settings_name'] = array('fieldset');
354
                    }
355
                    foreach ($meta as $key => $value){
356
                        if ($value[0]=='fieldset') { continue; } //plugins only get one fieldset
357
                        $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value;
358
                    }
359
                }
360
            }
361
362
            // the same for the active template
363
            if (file_exists(tpl_incdir().$file)){
364
                $meta = array();
365
                @include(tpl_incdir().$file);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
366
                @include(tpl_incdir().$class);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
367
                if (!empty($meta)) {
368
                    $metadata['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.'template_settings_name'] = array('fieldset');
369
                }
370
                foreach ($meta as $key => $value){
371
                    if ($value[0]=='fieldset') { continue; } //template only gets one fieldset
372
                    $metadata['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.$key] = $value;
373
                }
374
            }
375
376
            return $metadata;
377
        }
378
379
        /**
380
         * Load default settings for plugins and templates
381
         *
382
         * @param string $tpl name of active template
383
         * @return array default settings
384
         */
385
        function get_plugintpl_default($tpl){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
386
            $file    = '/conf/default.php';
387
            $default = array();
388
389
            foreach ($this->get_plugin_list() as $plugin) {
390
                $plugin_dir = plugin_directory($plugin);
391
                if (file_exists(DOKU_PLUGIN.$plugin_dir.$file)){
392
                    $conf = $this->_read_config(DOKU_PLUGIN.$plugin_dir.$file);
393
                    foreach ($conf as $key => $value){
394
                        $default['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value;
395
                    }
396
                }
397
            }
398
399
            // the same for the active template
400
            if (file_exists(tpl_incdir().$file)){
401
                $conf = $this->_read_config(tpl_incdir().$file);
402
                foreach ($conf as $key => $value){
403
                    $default['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.$key] = $value;
404
                }
405
            }
406
407
            return $default;
408
        }
409
410
    }
411
}
412
413
if (!class_exists('setting')) {
414
    /**
415
     * Class setting
416
     */
417
    class setting {
418
419
        var $_key = '';
420
        var $_default = null;
421
        var $_local = null;
422
        var $_protected = null;
423
424
        var $_pattern = '';
425
        var $_error = false;            // only used by those classes which error check
426
        var $_input = null;             // only used by those classes which error check
427
        var $_caution = null;           // used by any setting to provide an alert along with the setting
428
                                        // valid alerts, 'warning', 'danger', 'security'
429
                                        // images matching the alerts are in the plugin's images directory
430
431
        static protected $_validCautions = array('warning','danger','security');
432
433
        /**
434
         * @param string $key
435
         * @param array|null $params array with metadata of setting
436
         */
437
        public function __construct($key, $params=null) {
438
            $this->_key = $key;
439
440
            if (is_array($params)) {
441
                foreach($params as $property => $value) {
442
                    $this->$property = $value;
443
                }
444
            }
445
        }
446
447
        /**
448
         * Receives current values for the setting $key
449
         *
450
         * @param mixed $default   default setting value
451
         * @param mixed $local     local setting value
452
         * @param mixed $protected protected setting value
453
         */
454
        public function initialize($default, $local, $protected) {
455
            if (isset($default)) $this->_default = $default;
456
            if (isset($local)) $this->_local = $local;
457
            if (isset($protected)) $this->_protected = $protected;
458
        }
459
460
        /**
461
         * update changed setting with user provided value $input
462
         * - if changed value fails error check, save it to $this->_input (to allow echoing later)
463
         * - if changed value passes error check, set $this->_local to the new value
464
         *
465
         * @param  mixed   $input   the new value
466
         * @return boolean          true if changed, false otherwise (also on error)
467
         */
468
        public function update($input) {
469
            if (is_null($input)) return false;
470
            if ($this->is_protected()) return false;
471
472
            $value = is_null($this->_local) ? $this->_default : $this->_local;
473
            if ($value == $input) return false;
474
475
            if ($this->_pattern && !preg_match($this->_pattern,$input)) {
476
                $this->_error = true;
477
                $this->_input = $input;
478
                return false;
479
            }
480
481
            $this->_local = $input;
482
            return true;
483
        }
484
485
        /**
486
         * Build html for label and input of setting
487
         *
488
         * @param DokuWiki_Plugin $plugin object of config plugin
489
         * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
490
         * @return string[] with content array(string $label_html, string $input_html)
491
         */
492
        public function html(&$plugin, $echo=false) {
493
            $disable = '';
494
495
            if ($this->is_protected()) {
496
                $value = $this->_protected;
497
                $disable = 'disabled="disabled"';
498
            } else {
499
                if ($echo && $this->_error) {
500
                    $value = $this->_input;
501
                } else {
502
                    $value = is_null($this->_local) ? $this->_default : $this->_local;
503
                }
504
            }
505
506
            $key = htmlspecialchars($this->_key);
507
            $value = formText($value);
508
509
            $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
510
            $input = '<textarea rows="3" cols="40" id="config___'.$key.'" name="config['.$key.']" class="edit" '.$disable.'>'.$value.'</textarea>';
511
            return array($label,$input);
512
        }
513
514
        /**
515
         * Generate string to save setting value to file according to $fmt
516
         *
517
         * @param string $var name of variable
518
         * @param string $fmt save format
519
         * @return string
520
         */
521
        public function out($var, $fmt='php') {
522
523
            if ($this->is_protected()) return '';
524
            if (is_null($this->_local) || ($this->_default == $this->_local)) return '';
525
526
            $out = '';
527
528
            if ($fmt=='php') {
529
                $tr = array("\\" => '\\\\', "'" => '\\\'');
530
531
                $out =  '$'.$var."['".$this->_out_key()."'] = '".strtr( cleanText($this->_local), $tr)."';\n";
532
            }
533
534
            return $out;
535
        }
536
537
        /**
538
         * Returns the localized prompt
539
         *
540
         * @param DokuWiki_Plugin $plugin object of config plugin
541
         * @return string text
542
         */
543
        public function prompt(&$plugin) {
544
            $prompt = $plugin->getLang($this->_key);
545
            if (!$prompt) $prompt = htmlspecialchars(str_replace(array('____','_'),' ',$this->_key));
546
            return $prompt;
547
        }
548
549
        /**
550
         * Is setting protected
551
         *
552
         * @return bool
553
         */
554
        public function is_protected() { return !is_null($this->_protected); }
555
556
        /**
557
         * Is setting the default?
558
         *
559
         * @return bool
560
         */
561
        public function is_default() { return !$this->is_protected() && is_null($this->_local); }
562
563
        /**
564
         * Has an error?
565
         *
566
         * @return bool
567
         */
568
        public function error() { return $this->_error; }
569
570
        /**
571
         * Returns caution
572
         *
573
         * @return false|string caution string, otherwise false for invalid caution
574
         */
575
        public function caution() {
576
            if (!empty($this->_caution)) {
577
                if (!in_array($this->_caution, setting::$_validCautions)) {
578
                    trigger_error('Invalid caution string ('.$this->_caution.') in metadata for setting "'.$this->_key.'"', E_USER_WARNING);
579
                    return false;
580
                }
581
                return $this->_caution;
582
            }
583
            // compatibility with previous cautionList
584
            // TODO: check if any plugins use; remove
585
            if (!empty($this->_cautionList[$this->_key])) {
0 ignored issues
show
Bug introduced by
The property _cautionList does not seem to exist. Did you mean _caution?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
586
                $this->_caution = $this->_cautionList[$this->_key];
0 ignored issues
show
Bug introduced by
The property _cautionList does not seem to exist. Did you mean _caution?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
587
                unset($this->_cautionList);
588
589
                return $this->caution();
590
            }
591
            return false;
592
        }
593
594
        /**
595
         * Returns setting key, eventually with referer to config: namespace at dokuwiki.org
596
         *
597
         * @param bool $pretty create nice key
598
         * @param bool $url    provide url to config: namespace
599
         * @return string key
600
         */
601
        public function _out_key($pretty=false,$url=false) {
602
            if($pretty){
603
                $out = str_replace(CM_KEYMARKER,"»",$this->_key);
604
                if ($url && !strstr($out,'»')) {//provide no urls for plugins, etc.
605
                    if ($out == 'start') //one exception
606
                        return '<a href="http://www.dokuwiki.org/config:startpage">'.$out.'</a>';
607
                    else
608
                        return '<a href="http://www.dokuwiki.org/config:'.$out.'">'.$out.'</a>';
609
                }
610
                return $out;
611
            }else{
612
                return str_replace(CM_KEYMARKER,"']['",$this->_key);
613
            }
614
        }
615
    }
616
}
617
618
619
if (!class_exists('setting_array')) {
620
    /**
621
     * Class setting_array
622
     */
623
    class setting_array extends setting {
624
625
        /**
626
         * Create an array from a string
627
         *
628
         * @param string $string
629
         * @return array
630
         */
631
        protected function _from_string($string){
632
            $array = explode(',', $string);
633
            $array = array_map('trim', $array);
634
            $array = array_filter($array);
635
            $array = array_unique($array);
636
            return $array;
637
        }
638
639
        /**
640
         * Create a string from an array
641
         *
642
         * @param array $array
643
         * @return string
644
         */
645
        protected function _from_array($array){
646
            return join(', ', (array) $array);
647
        }
648
649
        /**
650
         * update setting with user provided value $input
651
         * if value fails error check, save it
652
         *
653
         * @param string $input
654
         * @return bool true if changed, false otherwise (incl. on error)
655
         */
656
        function update($input) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
657
            if (is_null($input)) return false;
658
            if ($this->is_protected()) return false;
659
660
            $input = $this->_from_string($input);
661
662
            $value = is_null($this->_local) ? $this->_default : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
663
            if ($value == $input) return false;
664
665
            foreach($input as $item){
666
                if ($this->_pattern && !preg_match($this->_pattern,$item)) {
0 ignored issues
show
Bug introduced by
The property _pattern cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
667
                    $this->_error = true;
0 ignored issues
show
Bug introduced by
The property _error cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
668
                    $this->_input = $input;
0 ignored issues
show
Bug introduced by
The property _input cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
669
                    return false;
670
                }
671
            }
672
673
            $this->_local = $input;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
674
            return true;
675
        }
676
677
        /**
678
         * Escaping
679
         *
680
         * @param string $string
681
         * @return string
682
         */
683
        protected function _escape($string) {
684
            $tr = array("\\" => '\\\\', "'" => '\\\'');
685
            return "'".strtr( cleanText($string), $tr)."'";
686
        }
687
688
        /**
689
         * Generate string to save setting value to file according to $fmt
690
         *
691
         * @param string $var name of variable
692
         * @param string $fmt save format
693
         * @return string
694
         */
695
        function out($var, $fmt='php') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
696
697
            if ($this->is_protected()) return '';
698
            if (is_null($this->_local) || ($this->_default == $this->_local)) return '';
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
699
700
            $out = '';
701
702
            if ($fmt=='php') {
703
                $vals = array_map(array($this, '_escape'), $this->_local);
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
704
                $out =  '$'.$var."['".$this->_out_key()."'] = array(".join(', ',$vals).");\n";
705
            }
706
707
            return $out;
708
        }
709
710
        /**
711
         * Build html for label and input of setting
712
         *
713
         * @param DokuWiki_Plugin $plugin object of config plugin
714
         * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
715
         * @return string[] with content array(string $label_html, string $input_html)
716
         */
717
        function html(&$plugin, $echo=false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
718
            $disable = '';
719
720
            if ($this->is_protected()) {
721
                $value = $this->_protected;
0 ignored issues
show
Bug introduced by
The property _protected cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
722
                $disable = 'disabled="disabled"';
723
            } else {
724
                if ($echo && $this->_error) {
0 ignored issues
show
Bug introduced by
The property _error cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
725
                    $value = $this->_input;
0 ignored issues
show
Bug introduced by
The property _input cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
726
                } else {
727
                    $value = is_null($this->_local) ? $this->_default : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
728
                }
729
            }
730
731
            $key = htmlspecialchars($this->_key);
0 ignored issues
show
Bug introduced by
The property _key cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
732
            $value = htmlspecialchars($this->_from_array($value));
733
734
            $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
735
            $input = '<input id="config___'.$key.'" name="config['.$key.']" type="text" class="edit" value="'.$value.'" '.$disable.'/>';
736
            return array($label,$input);
737
        }
738
    }
739
}
740
741
if (!class_exists('setting_string')) {
742
    /**
743
     * Class setting_string
744
     */
745
    class setting_string extends setting {
746
        /**
747
         * Build html for label and input of setting
748
         *
749
         * @param DokuWiki_Plugin $plugin object of config plugin
750
         * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
751
         * @return string[] with content array(string $label_html, string $input_html)
752
         */
753
        function html(&$plugin, $echo=false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
754
            $disable = '';
755
756
            if ($this->is_protected()) {
757
                $value = $this->_protected;
0 ignored issues
show
Bug introduced by
The property _protected cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
758
                $disable = 'disabled="disabled"';
759
            } else {
760
                if ($echo && $this->_error) {
0 ignored issues
show
Bug introduced by
The property _error cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
761
                    $value = $this->_input;
0 ignored issues
show
Bug introduced by
The property _input cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
762
                } else {
763
                    $value = is_null($this->_local) ? $this->_default : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
764
                }
765
            }
766
767
            $key = htmlspecialchars($this->_key);
0 ignored issues
show
Bug introduced by
The property _key cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
768
            $value = htmlspecialchars($value);
769
770
            $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
771
            $input = '<input id="config___'.$key.'" name="config['.$key.']" type="text" class="edit" value="'.$value.'" '.$disable.'/>';
772
            return array($label,$input);
773
        }
774
    }
775
}
776
777
if (!class_exists('setting_password')) {
778
    /**
779
     * Class setting_password
780
     */
781
    class setting_password extends setting_string {
782
783
        var $_code = 'plain';  // mechanism to be used to obscure passwords
784
785
        /**
786
         * update changed setting with user provided value $input
787
         * - if changed value fails error check, save it to $this->_input (to allow echoing later)
788
         * - if changed value passes error check, set $this->_local to the new value
789
         *
790
         * @param  mixed   $input   the new value
791
         * @return boolean          true if changed, false otherwise (also on error)
792
         */
793
        function update($input) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
794
            if ($this->is_protected()) return false;
795
            if (!$input) return false;
796
797
            if ($this->_pattern && !preg_match($this->_pattern,$input)) {
0 ignored issues
show
Bug introduced by
The property _pattern cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
798
                $this->_error = true;
0 ignored issues
show
Bug introduced by
The property _error cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
799
                $this->_input = $input;
0 ignored issues
show
Bug introduced by
The property _input cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
800
                return false;
801
            }
802
803
            $this->_local = conf_encodeString($input,$this->_code);
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
804
            return true;
805
        }
806
807
        /**
808
         * Build html for label and input of setting
809
         *
810
         * @param DokuWiki_Plugin $plugin object of config plugin
811
         * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
812
         * @return string[] with content array(string $label_html, string $input_html)
813
         */
814
        function html(&$plugin, $echo=false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
815
816
            $disable = $this->is_protected() ? 'disabled="disabled"' : '';
817
818
            $key = htmlspecialchars($this->_key);
0 ignored issues
show
Bug introduced by
The property _key cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
819
820
            $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
821
            $input = '<input id="config___'.$key.'" name="config['.$key.']" autocomplete="off" type="password" class="edit" value="" '.$disable.' />';
822
            return array($label,$input);
823
        }
824
    }
825
}
826
827
if (!class_exists('setting_email')) {
828
    /**
829
     * Class setting_email
830
     */
831
    class setting_email extends setting_string {
832
        var $_multiple = false;
833
        var $_placeholders = false;
834
835
        /**
836
         * update setting with user provided value $input
837
         * if value fails error check, save it
838
         *
839
         * @param mixed $input
840
         * @return boolean true if changed, false otherwise (incl. on error)
841
         */
842
        function update($input) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
843
            if (is_null($input)) return false;
844
            if ($this->is_protected()) return false;
845
846
            $value = is_null($this->_local) ? $this->_default : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
847
            if ($value == $input) return false;
848
            if($input === ''){
849
                $this->_local = $input;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
850
                return true;
851
            }
852
            $mail = $input;
853
854
            if($this->_placeholders){
855
                // replace variables with pseudo values
856
                $mail = str_replace('@USER@','joe',$mail);
857
                $mail = str_replace('@NAME@','Joe Schmoe',$mail);
858
                $mail = str_replace('@MAIL@','[email protected]',$mail);
859
            }
860
861
            // multiple mail addresses?
862
            if ($this->_multiple) {
863
                $mails = array_filter(array_map('trim', explode(',', $mail)));
864
            } else {
865
                $mails = array($mail);
866
            }
867
868
            // check them all
869
            foreach ($mails as $mail) {
870
                // only check the address part
871
                if(preg_match('#(.*?)<(.*?)>#', $mail, $matches)){
872
                    $addr = $matches[2];
873
                }else{
874
                    $addr = $mail;
875
                }
876
877
                if (!mail_isvalid($addr)) {
878
                    $this->_error = true;
0 ignored issues
show
Bug introduced by
The property _error cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
879
                    $this->_input = $input;
0 ignored issues
show
Bug introduced by
The property _input cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
880
                    return false;
881
                }
882
            }
883
884
            $this->_local = $input;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
885
            return true;
886
        }
887
    }
888
}
889
890
if (!class_exists('setting_numeric')) {
891
    /**
892
     * Class setting_numeric
893
     */
894
    class setting_numeric extends setting_string {
895
        // This allows for many PHP syntax errors...
896
        // var $_pattern = '/^[-+\/*0-9 ]*$/';
897
        // much more restrictive, but should eliminate syntax errors.
898
        var $_pattern = '/^[-+]? *[0-9]+ *(?:[-+*] *[0-9]+ *)*$/';
899
        var $_min = null;
900
        var $_max = null;
901
902
        /**
903
         * update changed setting with user provided value $input
904
         * - if changed value fails error check, save it to $this->_input (to allow echoing later)
905
         * - if changed value passes error check, set $this->_local to the new value
906
         *
907
         * @param  mixed   $input   the new value
908
         * @return boolean          true if changed, false otherwise (also on error)
909
         */
910
        function update($input) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
911
            $local = $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
912
            $valid = parent::update($input);
913
            if ($valid && !(is_null($this->_min) && is_null($this->_max))) {
914
                $numeric_local = (int) eval('return '.$this->_local.';');
915
                if ((!is_null($this->_min) && $numeric_local < $this->_min) ||
916
                    (!is_null($this->_max) && $numeric_local > $this->_max)) {
917
                    $this->_error = true;
0 ignored issues
show
Bug introduced by
The property _error cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
918
                    $this->_input = $input;
0 ignored issues
show
Bug introduced by
The property _input cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
919
                    $this->_local = $local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
920
                    $valid = false;
921
                }
922
            }
923
            return $valid;
924
        }
925
926
        /**
927
         * Generate string to save setting value to file according to $fmt
928
         *
929
         * @param string $var name of variable
930
         * @param string $fmt save format
931
         * @return string
932
         */
933
        function out($var, $fmt='php') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
934
935
            if ($this->is_protected()) return '';
936
            if (is_null($this->_local) || ($this->_default == $this->_local)) return '';
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
937
938
            $out = '';
939
940
            if ($fmt=='php') {
941
                $local = $this->_local === '' ? "''" : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
942
                $out .=  '$'.$var."['".$this->_out_key()."'] = ".$local.";\n";
943
            }
944
945
            return $out;
946
        }
947
    }
948
}
949
950
if (!class_exists('setting_numericopt')) {
951
    /**
952
     * Class setting_numericopt
953
     */
954
    class setting_numericopt extends setting_numeric {
955
        // just allow an empty config
956
        var $_pattern = '/^(|[-]?[0-9]+(?:[-+*][0-9]+)*)$/';
957
    }
958
}
959
960
if (!class_exists('setting_onoff')) {
961
    /**
962
     * Class setting_onoff
963
     */
964
    class setting_onoff extends setting_numeric {
965
        /**
966
         * Build html for label and input of setting
967
         *
968
         * @param DokuWiki_Plugin $plugin object of config plugin
969
         * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
970
         * @return string[] with content array(string $label_html, string $input_html)
971
         */
972
        function html(&$plugin, $echo = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
973
            $disable = '';
974
975
            if ($this->is_protected()) {
976
                $value = $this->_protected;
0 ignored issues
show
Bug introduced by
The property _protected cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
977
                $disable = ' disabled="disabled"';
978
            } else {
979
                $value = is_null($this->_local) ? $this->_default : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
980
            }
981
982
            $key = htmlspecialchars($this->_key);
0 ignored issues
show
Bug introduced by
The property _key cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
983
            $checked = ($value) ? ' checked="checked"' : '';
984
985
            $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
986
            $input = '<div class="input"><input id="config___'.$key.'" name="config['.$key.']" type="checkbox" class="checkbox" value="1"'.$checked.$disable.'/></div>';
987
            return array($label,$input);
988
        }
989
990
        /**
991
         * update changed setting with user provided value $input
992
         * - if changed value fails error check, save it to $this->_input (to allow echoing later)
993
         * - if changed value passes error check, set $this->_local to the new value
994
         *
995
         * @param  mixed   $input   the new value
996
         * @return boolean          true if changed, false otherwise (also on error)
997
         */
998
        function update($input) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
999
            if ($this->is_protected()) return false;
1000
1001
            $input = ($input) ? 1 : 0;
1002
            $value = is_null($this->_local) ? $this->_default : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1003
            if ($value == $input) return false;
1004
1005
            $this->_local = $input;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1006
            return true;
1007
        }
1008
    }
1009
}
1010
1011
if (!class_exists('setting_multichoice')) {
1012
    /**
1013
     * Class setting_multichoice
1014
     */
1015
    class setting_multichoice extends setting_string {
1016
        var $_choices = array();
1017
        var $lang; //some custom language strings are stored in setting
1018
1019
        /**
1020
         * Build html for label and input of setting
1021
         *
1022
         * @param DokuWiki_Plugin $plugin object of config plugin
1023
         * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
1024
         * @return string[] with content array(string $label_html, string $input_html)
1025
         */
1026
        function html(&$plugin, $echo = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1027
            $disable = '';
1028
            $nochoice = '';
1029
1030
            if ($this->is_protected()) {
1031
                $value = $this->_protected;
0 ignored issues
show
Bug introduced by
The property _protected cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1032
                $disable = ' disabled="disabled"';
1033
            } else {
1034
                $value = is_null($this->_local) ? $this->_default : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1035
            }
1036
1037
            // ensure current value is included
1038
            if (!in_array($value, $this->_choices)) {
1039
                $this->_choices[] = $value;
1040
            }
1041
            // disable if no other choices
1042
            if (!$this->is_protected() && count($this->_choices) <= 1) {
1043
                $disable = ' disabled="disabled"';
1044
                $nochoice = $plugin->getLang('nochoice');
1045
            }
1046
1047
            $key = htmlspecialchars($this->_key);
0 ignored issues
show
Bug introduced by
The property _key cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1048
1049
            $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
1050
1051
            $input = "<div class=\"input\">\n";
1052
            $input .= '<select class="edit" id="config___'.$key.'" name="config['.$key.']"'.$disable.'>'."\n";
1053
            foreach ($this->_choices as $choice) {
1054
                $selected = ($value == $choice) ? ' selected="selected"' : '';
1055
                $option = $plugin->getLang($this->_key.'_o_'.$choice);
0 ignored issues
show
Bug introduced by
The property _key cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1056
                if (!$option && isset($this->lang[$this->_key.'_o_'.$choice])) $option = $this->lang[$this->_key.'_o_'.$choice];
0 ignored issues
show
Bug introduced by
The property _key cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1057
                if (!$option) $option = $choice;
1058
1059
                $choice = htmlspecialchars($choice);
1060
                $option = htmlspecialchars($option);
1061
                $input .= '  <option value="'.$choice.'"'.$selected.' >'.$option.'</option>'."\n";
1062
            }
1063
            $input .= "</select> $nochoice \n";
1064
            $input .= "</div>\n";
1065
1066
            return array($label,$input);
1067
        }
1068
1069
        /**
1070
         * update changed setting with user provided value $input
1071
         * - if changed value fails error check, save it to $this->_input (to allow echoing later)
1072
         * - if changed value passes error check, set $this->_local to the new value
1073
         *
1074
         * @param  mixed   $input   the new value
1075
         * @return boolean          true if changed, false otherwise (also on error)
1076
         */
1077
        function update($input) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1078
            if (is_null($input)) return false;
1079
            if ($this->is_protected()) return false;
1080
1081
            $value = is_null($this->_local) ? $this->_default : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1082
            if ($value == $input) return false;
1083
1084
            if (!in_array($input, $this->_choices)) return false;
1085
1086
            $this->_local = $input;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1087
            return true;
1088
        }
1089
    }
1090
}
1091
1092
1093
if (!class_exists('setting_dirchoice')) {
1094
    /**
1095
     * Class setting_dirchoice
1096
     */
1097
    class setting_dirchoice extends setting_multichoice {
1098
1099
        var $_dir = '';
1100
1101
        /**
1102
         * Receives current values for the setting $key
1103
         *
1104
         * @param mixed $default   default setting value
1105
         * @param mixed $local     local setting value
1106
         * @param mixed $protected protected setting value
1107
         */
1108
        function initialize($default,$local,$protected) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1109
1110
            // populate $this->_choices with a list of directories
1111
            $list = array();
1112
1113
            if ($dh = @opendir($this->_dir)) {
1114
                while (false !== ($entry = readdir($dh))) {
1115
                    if ($entry == '.' || $entry == '..') continue;
1116
                    if ($this->_pattern && !preg_match($this->_pattern,$entry)) continue;
0 ignored issues
show
Bug introduced by
The property _pattern cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1117
1118
                    $file = (is_link($this->_dir.$entry)) ? readlink($this->_dir.$entry) : $this->_dir.$entry;
1119
                    if (is_dir($file)) $list[] = $entry;
1120
                }
1121
                closedir($dh);
1122
            }
1123
            sort($list);
1124
            $this->_choices = $list;
0 ignored issues
show
Bug introduced by
The property _choices cannot be accessed from this context as it is declared private in class setting_multichoice.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1125
1126
            parent::initialize($default,$local,$protected);
1127
        }
1128
    }
1129
}
1130
1131
1132
if (!class_exists('setting_hidden')) {
1133
    /**
1134
     * Class setting_hidden
1135
     */
1136
    class setting_hidden extends setting {
1137
        // Used to explicitly ignore a setting in the configuration manager.
1138
    }
1139
}
1140
1141
if (!class_exists('setting_fieldset')) {
1142
    /**
1143
     * Class setting_fieldset
1144
     */
1145
    class setting_fieldset extends setting {
1146
        // A do-nothing class used to detect the 'fieldset' type.
1147
        // Used to start a new settings "display-group".
1148
    }
1149
}
1150
1151
if (!class_exists('setting_undefined')) {
1152
    /**
1153
     * Class setting_undefined
1154
     */
1155
    class setting_undefined extends setting_hidden {
1156
        // A do-nothing class used to detect settings with no metadata entry.
1157
        // Used internaly to hide undefined settings, and generate the undefined settings list.
1158
    }
1159
}
1160
1161
if (!class_exists('setting_no_class')) {
1162
    /**
1163
     * Class setting_no_class
1164
     */
1165
    class setting_no_class extends setting_undefined {
1166
        // A do-nothing class used to detect settings with a missing setting class.
1167
        // Used internaly to hide undefined settings, and generate the undefined settings list.
1168
    }
1169
}
1170
1171
if (!class_exists('setting_no_default')) {
1172
    /**
1173
     * Class setting_no_default
1174
     */
1175
    class setting_no_default extends setting_undefined {
1176
        // A do-nothing class used to detect settings with no default value.
1177
        // Used internaly to hide undefined settings, and generate the undefined settings list.
1178
    }
1179
}
1180
1181
if (!class_exists('setting_multicheckbox')) {
1182
    /**
1183
     * Class setting_multicheckbox
1184
     */
1185
    class setting_multicheckbox extends setting_string {
1186
1187
        var $_choices = array();
1188
        var $_combine = array();
1189
1190
        /**
1191
         * update changed setting with user provided value $input
1192
         * - if changed value fails error check, save it to $this->_input (to allow echoing later)
1193
         * - if changed value passes error check, set $this->_local to the new value
1194
         *
1195
         * @param  mixed   $input   the new value
1196
         * @return boolean          true if changed, false otherwise (also on error)
1197
         */
1198
        function update($input) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1199
            if ($this->is_protected()) return false;
1200
1201
            // split any combined values + convert from array to comma separated string
1202
            $input = ($input) ? $input : array();
1203
            $input = $this->_array2str($input);
1204
1205
            $value = is_null($this->_local) ? $this->_default : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1206
            if ($value == $input) return false;
1207
1208
            if ($this->_pattern && !preg_match($this->_pattern,$input)) {
0 ignored issues
show
Bug introduced by
The property _pattern cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1209
                $this->_error = true;
0 ignored issues
show
Bug introduced by
The property _error cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1210
                $this->_input = $input;
0 ignored issues
show
Bug introduced by
The property _input cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1211
                return false;
1212
            }
1213
1214
            $this->_local = $input;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1215
            return true;
1216
        }
1217
1218
        /**
1219
         * Build html for label and input of setting
1220
         *
1221
         * @param DokuWiki_Plugin $plugin object of config plugin
1222
         * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
1223
         * @return string[] with content array(string $label_html, string $input_html)
1224
         */
1225
        function html(&$plugin, $echo=false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1226
1227
            $disable = '';
1228
1229
            if ($this->is_protected()) {
1230
                $value = $this->_protected;
0 ignored issues
show
Bug introduced by
The property _protected cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1231
                $disable = 'disabled="disabled"';
1232
            } else {
1233
                if ($echo && $this->_error) {
0 ignored issues
show
Bug introduced by
The property _error cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1234
                    $value = $this->_input;
0 ignored issues
show
Bug introduced by
The property _input cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1235
                } else {
1236
                    $value = is_null($this->_local) ? $this->_default : $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1237
                }
1238
            }
1239
1240
            $key = htmlspecialchars($this->_key);
0 ignored issues
show
Bug introduced by
The property _key cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1241
1242
            // convert from comma separated list into array + combine complimentary actions
1243
            $value = $this->_str2array($value);
1244
            $default = $this->_str2array($this->_default);
0 ignored issues
show
Bug introduced by
The property _default cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1245
1246
            $input = '';
1247
            foreach ($this->_choices as $choice) {
1248
                $idx = array_search($choice, $value);
1249
                $idx_default = array_search($choice,$default);
1250
1251
                $checked = ($idx !== false) ? 'checked="checked"' : '';
1252
1253
                // ideally this would be handled using a second class of "default", however IE6 does not
1254
                // correctly support CSS selectors referencing multiple class names on the same element
1255
                // (e.g. .default.selection).
1256
                $class = (($idx !== false) == (false !== $idx_default)) ? " selectiondefault" : "";
1257
1258
                $prompt = ($plugin->getLang($this->_key.'_'.$choice) ?
0 ignored issues
show
Bug introduced by
The property _key cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1259
                                $plugin->getLang($this->_key.'_'.$choice) : htmlspecialchars($choice));
0 ignored issues
show
Bug introduced by
The property _key cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1260
1261
                $input .= '<div class="selection'.$class.'">'."\n";
1262
                $input .= '<label for="config___'.$key.'_'.$choice.'">'.$prompt."</label>\n";
1263
                $input .= '<input id="config___'.$key.'_'.$choice.'" name="config['.$key.'][]" type="checkbox" class="checkbox" value="'.$choice.'" '.$disable.' '.$checked."/>\n";
1264
                $input .= "</div>\n";
1265
1266
                // remove this action from the disabledactions array
1267
                if ($idx !== false) unset($value[$idx]);
1268
                if ($idx_default !== false) unset($default[$idx_default]);
1269
            }
1270
1271
            // handle any remaining values
1272
            $other = join(',',$value);
1273
1274
            $class = ((count($default) == count($value)) && (count($value) == count(array_intersect($value,$default)))) ?
1275
                            " selectiondefault" : "";
1276
1277
            $input .= '<div class="other'.$class.'">'."\n";
1278
            $input .= '<label for="config___'.$key.'_other">'.$plugin->getLang($key.'_other')."</label>\n";
1279
            $input .= '<input id="config___'.$key.'_other" name="config['.$key.'][other]" type="text" class="edit" value="'.htmlspecialchars($other).'" '.$disable." />\n";
1280
            $input .= "</div>\n";
1281
1282
            $label = '<label>'.$this->prompt($plugin).'</label>';
1283
            return array($label,$input);
1284
        }
1285
1286
        /**
1287
         * convert comma separated list to an array and combine any complimentary values
1288
         *
1289
         * @param string $str
1290
         * @return array
1291
         */
1292
        function _str2array($str) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1293
            $array = explode(',',$str);
1294
1295
            if (!empty($this->_combine)) {
1296
                foreach ($this->_combine as $key => $combinators) {
1297
                    $idx = array();
1298
                    foreach ($combinators as $val) {
1299
                        if  (($idx[] = array_search($val, $array)) === false) break;
1300
                    }
1301
1302
                    if (count($idx) && $idx[count($idx)-1] !== false) {
1303
                        foreach ($idx as $i) unset($array[$i]);
1304
                        $array[] = $key;
1305
                    }
1306
                }
1307
            }
1308
1309
            return $array;
1310
        }
1311
1312
        /**
1313
         * convert array of values + other back to a comma separated list, incl. splitting any combined values
1314
         *
1315
         * @param array $input
1316
         * @return string
1317
         */
1318
        function _array2str($input) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1319
1320
            // handle other
1321
            $other = trim($input['other']);
1322
            $other = !empty($other) ? explode(',',str_replace(' ','',$input['other'])) : array();
1323
            unset($input['other']);
1324
1325
            $array = array_unique(array_merge($input, $other));
1326
1327
            // deconstruct any combinations
1328
            if (!empty($this->_combine)) {
1329
                foreach ($this->_combine as $key => $combinators) {
1330
1331
                    $idx = array_search($key,$array);
1332
                    if ($idx !== false) {
1333
                        unset($array[$idx]);
1334
                        $array = array_merge($array, $combinators);
1335
                    }
1336
                }
1337
            }
1338
1339
            return join(',',array_unique($array));
1340
        }
1341
    }
1342
}
1343
1344
if (!class_exists('setting_regex')){
1345
    /**
1346
     * Class setting_regex
1347
     */
1348
    class setting_regex extends setting_string {
1349
1350
        var $_delimiter = '/';    // regex delimiter to be used in testing input
1351
        var $_pregflags = 'ui';   // regex pattern modifiers to be used in testing input
1352
1353
        /**
1354
         * update changed setting with user provided value $input
1355
         * - if changed value fails error check, save it to $this->_input (to allow echoing later)
1356
         * - if changed value passes error check, set $this->_local to the new value
1357
         *
1358
         * @param  mixed   $input   the new value
1359
         * @return boolean          true if changed, false otherwise (incl. on error)
1360
         */
1361
        function update($input) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1362
1363
            // let parent do basic checks, value, not changed, etc.
1364
            $local = $this->_local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1365
            if (!parent::update($input)) return false;
1366
            $this->_local = $local;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1367
1368
            // see if the regex compiles and runs (we don't check for effectiveness)
1369
            $regex = $this->_delimiter . $input . $this->_delimiter . $this->_pregflags;
1370
            $lastError = error_get_last();
1371
            @preg_match($regex,'testdata');
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1372
            if (preg_last_error() != PREG_NO_ERROR || error_get_last() != $lastError) {
1373
                $this->_input = $input;
0 ignored issues
show
Bug introduced by
The property _input cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1374
                $this->_error = true;
0 ignored issues
show
Bug introduced by
The property _error cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1375
                return false;
1376
            }
1377
1378
            $this->_local = $input;
0 ignored issues
show
Bug introduced by
The property _local cannot be accessed from this context as it is declared private in class setting.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1379
            return true;
1380
        }
1381
    }
1382
}
1383