_key = $key; $this->_level = $level; $this->_protect = @$set['protect']; $this->_value = @$set['value']; $this->_initSetting($meta); } function setProtect($val){ if (!$val) unset($this->_protect); else $this->_protect = (bool)$val; return true; } function tryUpdate($val){ $this->_old_val = $this->_setting->_local; $changed = $this->_setting->update($val); if ($this->_setting->_error){ return false; } $this->_updated = true; if ($this->_setting->_local !== null && $this->_setting->_local === $this->_setting->_default){ $this->_setting->_local = null; } $this->_value = $this->_setting->_local; return true; } protected function _initSetting($meta){ $class_meta = array_shift($meta); if($class_meta && class_exists('setting_'.$class_meta)){ $class = 'setting_'.$class_meta; }elseif($class_meta == ''){ $class = 'setting'; // the '' option is the textarea... }else{ die('TODO: extend this function!'); } $this->_setting = new $class($this->_key,$meta); $this->_setting->initialize( $this->_level->getDefault($this->_key), $this->_level->getLocal($this->_key), // protection applies from parent not the current level. If you protect a level's value, you can still change it on this level, but it's protected for children. $this->_level->getParentProtected($this->_key) ); } function currentValue(){ if ($this->_changed) return $this->_old_val; return $this->_setting->_local === null ? $this->_setting->_default : $this->_setting->_local; } function markChanged(){ $this->_changed = true; } protected function _showHierarchyButton(){ return ""; } protected function _showProtectedCell(){ return " _protect ? 'checked="checked"' : '')." ".($this->_level->getParentProtected($this->_key) !== null ? "disabled='disabled'":"")."/> "; } protected function _showInputUpdateResults(){ if ($this->_setting->_error){ return "
".settingshierarchy::$helper->getLang('invalid_value').($this->_setting->_input !== null ? ": {$this->format($this->_setting->_input)}": "!")."
"; }elseif ($this->_updated && !$this->changed){ return "
".settingshierarchy::$helper->getLang('updated_value_from').": {$this->format($this->_old_val,$default)}". ($default ? " (".settingshierarchy::$helper->getLang('default_value').") ":"")."
"; } } function showHtml(){ $lang = $this->_level->getHierarchy(); list($label,$input) = $this->_setting->html($lang); // html only uses the $plugin as parameter to have a getLang method, we emulate that on hierarchy. $cssclass = $this->_setting->is_default() ? ' class="default"' : ($this->_setting->is_protected() ? ' class="protected"' : ''); $errorclass = ($this->_setting->error() ? ' value error' : ' value'). ($this->_changed ? " changed" : ""); $has_icon = $this->_setting->caution() ? ''.$this->_setting->caution().'' : ''; $ret = ""; $ret .= "{$this->_setting->_out_key(true,true)}{$has_icon}{$label}"; // DECIDE: push to plugin debug? /* $ret .= "debug: _local = ".var_export($this->_setting->_local ,1).", _default = ".var_export($this->_setting->_default ,1).", _protected = ".var_export($this->_setting->_protected ,1).", _updated: '{$this->_updated}', _old_val: ".var_export($this->_old_val ,1)."
";*/ $ret .= $this->_showHierarchyButton(); $ret .= ""; $ret .= "".$this->_showProtectedCell(); $ret .= ""; $ret .= $this->_showInputUpdateResults(); $ret .= "{$input}"; return $ret; } function format($value,&$default = null){ $default = false; if ($value === null){ $default = true; $value = $this->_level->getDefault($this->_key); } return $this->_level->getHierarchy()->format($this->_key,$value); } } class settingswrapper_export extends settingswrapper{ protected function _showHierarchyButton(){ return ""; } protected function _showProtectedCell(){ return ""; } function showHtml(){ $lang = $this->_level->getHierarchy(); list($label,$input) = $this->_setting->html($lang); // html only uses the $plugin as parameter to have a getLang method, we emulate that on hierarchy. $input = strtr($input,array('id="config_'=>'id="export_')); // we need to replace the id/for for the inputs/labels, as they can be present on pages where config options are available and then they can violate the id-uniqueness constraint of html. $label = strtr($label,array('for="config_'=>'for="export_')); $cssclass = $this->_setting->is_default() ? ' class="default"' : ($this->_setting->is_protected() ? ' class="protected"' : ''); $errorclass = ($this->_setting->error() ? ' value error' : ' value'). ($this->_changed ? " changed" : ""); $has_icon = $this->_setting->caution() ? ''.$this->_setting->caution().'' : ''; $ret = ""; $ret .= "{$this->_setting->_out_key(true,true)}{$has_icon}{$label}"; $ret .= ""; $ret .= ""; $ret .= $this->_showInputUpdateResults(); $ret .= "{$input}"; return $ret; } } } // class_exists