blob: 69a74aa9fed98db1315c6009ac4c240472107280 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<?php
namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_onoff
*/
class SettingOnoff extends SettingNumeric
{
/**
* We treat the strings 'false' and 'off' as false
* @inheritdoc
*/
protected function cleanValue($value)
{
if ($value === null) return null;
if (is_string($value)) {
if (strtolower($value) === 'false') return 0;
if (strtolower($value) === 'off') return 0;
if (trim($value) === '') return 0;
}
return (int) (bool) $value;
}
/** @inheritdoc */
public function html(\admin_plugin_config $plugin, $echo = false)
{
$disable = '';
if ($this->isProtected()) {
$value = $this->protected;
$disable = ' disabled="disabled"';
} else {
$value = is_null($this->local) ? $this->default : $this->local;
}
$key = htmlspecialchars($this->key);
$checked = ($value) ? ' checked="checked"' : '';
$label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>';
$input = '<div class="input"><input id="config___' . $key . '" name="config[' . $key .
']" type="checkbox" class="checkbox" value="1"' . $checked . $disable . '/></div>';
return [$label, $input];
}
/** @inheritdoc */
public function update($input)
{
if ($this->isProtected()) return false;
$input = ($input) ? 1 : 0;
$value = is_null($this->local) ? $this->default : $this->local;
if ($value == $input) return false;
$this->local = $input;
return true;
}
}
|