10a5b05ebSAndreas Gohr<?php 20a5b05ebSAndreas Gohr 30a5b05ebSAndreas Gohrnamespace dokuwiki\plugin\config\core\Setting; 40a5b05ebSAndreas Gohr 50a5b05ebSAndreas Gohr/** 60a5b05ebSAndreas Gohr * Class setting_onoff 70a5b05ebSAndreas Gohr */ 88c7c53b0SAndreas Gohrclass SettingOnoff extends SettingNumeric 98c7c53b0SAndreas Gohr{ 1028cc4f40SAndreas Gohr /** 1128cc4f40SAndreas Gohr * We treat the strings 'false' and 'off' as false 1228cc4f40SAndreas Gohr * @inheritdoc 1328cc4f40SAndreas Gohr */ 14*d868eb89SAndreas Gohr protected function cleanValue($value) 15*d868eb89SAndreas Gohr { 1628cc4f40SAndreas Gohr if ($value === null) return null; 1728cc4f40SAndreas Gohr 1828cc4f40SAndreas Gohr if (is_string($value)) { 1928cc4f40SAndreas Gohr if (strtolower($value) === 'false') return 0; 2028cc4f40SAndreas Gohr if (strtolower($value) === 'off') return 0; 2128cc4f40SAndreas Gohr if (trim($value) === '') return 0; 2228cc4f40SAndreas Gohr } 2328cc4f40SAndreas Gohr 2428cc4f40SAndreas Gohr return (int) (bool) $value; 2528cc4f40SAndreas Gohr } 2628cc4f40SAndreas Gohr 270a5b05ebSAndreas Gohr /** @inheritdoc */ 28*d868eb89SAndreas Gohr public function html(\admin_plugin_config $plugin, $echo = false) 29*d868eb89SAndreas Gohr { 300a5b05ebSAndreas Gohr $disable = ''; 310a5b05ebSAndreas Gohr 320a5b05ebSAndreas Gohr if ($this->isProtected()) { 330a5b05ebSAndreas Gohr $value = $this->protected; 340a5b05ebSAndreas Gohr $disable = ' disabled="disabled"'; 350a5b05ebSAndreas Gohr } else { 360a5b05ebSAndreas Gohr $value = is_null($this->local) ? $this->default : $this->local; 370a5b05ebSAndreas Gohr } 380a5b05ebSAndreas Gohr 390a5b05ebSAndreas Gohr $key = htmlspecialchars($this->key); 400a5b05ebSAndreas Gohr $checked = ($value) ? ' checked="checked"' : ''; 410a5b05ebSAndreas Gohr 420a5b05ebSAndreas Gohr $label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>'; 430a5b05ebSAndreas Gohr $input = '<div class="input"><input id="config___' . $key . '" name="config[' . $key . 440a5b05ebSAndreas Gohr ']" type="checkbox" class="checkbox" value="1"' . $checked . $disable . '/></div>'; 45467c1427SAndreas Gohr return [$label, $input]; 460a5b05ebSAndreas Gohr } 470a5b05ebSAndreas Gohr 480a5b05ebSAndreas Gohr /** @inheritdoc */ 49*d868eb89SAndreas Gohr public function update($input) 50*d868eb89SAndreas Gohr { 510a5b05ebSAndreas Gohr if ($this->isProtected()) return false; 520a5b05ebSAndreas Gohr 530a5b05ebSAndreas Gohr $input = ($input) ? 1 : 0; 540a5b05ebSAndreas Gohr $value = is_null($this->local) ? $this->default : $this->local; 550a5b05ebSAndreas Gohr if ($value == $input) return false; 560a5b05ebSAndreas Gohr 570a5b05ebSAndreas Gohr $this->local = $input; 580a5b05ebSAndreas Gohr return true; 590a5b05ebSAndreas Gohr } 600a5b05ebSAndreas Gohr} 61