summaryrefslogtreecommitdiff
path: root/lib/plugins/config/settings
diff options
context:
space:
mode:
authorMatt Perry <matt@mattperry.com>2013-08-22 01:01:41 -0700
committerMatt Perry <matt@mattperry.com>2013-08-22 01:01:41 -0700
commit7ef8e99fe605c5da36ab6b5d317b22fcd17f665b (patch)
tree2245231ac0dcbeea7084a751f89699e3307133f2 /lib/plugins/config/settings
parent104262381eb89124eb900397f5054fde8e3d5658 (diff)
downloadrpg-7ef8e99fe605c5da36ab6b5d317b22fcd17f665b.tar.gz
rpg-7ef8e99fe605c5da36ab6b5d317b22fcd17f665b.tar.bz2
Fix CodeSniffer violations
Change indentation to ensure code confirms to CodeSniffer rules.
Diffstat (limited to 'lib/plugins/config/settings')
-rw-r--r--lib/plugins/config/settings/config.class.php1478
-rw-r--r--lib/plugins/config/settings/extra.class.php270
2 files changed, 874 insertions, 874 deletions
diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php
index 6de560128..0b9fa8103 100644
--- a/lib/plugins/config/settings/config.class.php
+++ b/lib/plugins/config/settings/config.class.php
@@ -11,500 +11,500 @@ if(!defined('CM_KEYMARKER')) define('CM_KEYMARKER','____');
if (!class_exists('configuration')) {
- class configuration {
-
- var $_name = 'conf'; // name of the config variable found in the files (overridden by $config['varname'])
- var $_format = 'php'; // format of the config file, supported formats - php (overridden by $config['format'])
- var $_heading = ''; // heading string written at top of config file - don't include comment indicators
- var $_loaded = false; // set to true after configuration files are loaded
- var $_metadata = array(); // holds metadata describing the settings
- var $setting = array(); // array of setting objects
- var $locked = false; // configuration is considered locked if it can't be updated
- var $show_disabled_plugins = false;
-
- // configuration filenames
- var $_default_files = array();
- var $_local_files = array(); // updated configuration is written to the first file
- var $_protected_files = array();
-
- var $_plugin_list = null;
-
- /**
- * constructor
- */
- function configuration($datafile) {
- global $conf, $config_cascade;
-
- if (!@file_exists($datafile)) {
- msg('No configuration metadata found at - '.htmlspecialchars($datafile),-1);
- return;
- }
- $meta = array();
- include($datafile);
+ class configuration {
- if (isset($config['varname'])) $this->_name = $config['varname'];
- if (isset($config['format'])) $this->_format = $config['format'];
- if (isset($config['heading'])) $this->_heading = $config['heading'];
+ var $_name = 'conf'; // name of the config variable found in the files (overridden by $config['varname'])
+ var $_format = 'php'; // format of the config file, supported formats - php (overridden by $config['format'])
+ var $_heading = ''; // heading string written at top of config file - don't include comment indicators
+ var $_loaded = false; // set to true after configuration files are loaded
+ var $_metadata = array(); // holds metadata describing the settings
+ var $setting = array(); // array of setting objects
+ var $locked = false; // configuration is considered locked if it can't be updated
+ var $show_disabled_plugins = false;
- $this->_default_files = $config_cascade['main']['default'];
- $this->_local_files = $config_cascade['main']['local'];
- $this->_protected_files = $config_cascade['main']['protected'];
+ // configuration filenames
+ var $_default_files = array();
+ var $_local_files = array(); // updated configuration is written to the first file
+ var $_protected_files = array();
- $this->locked = $this->_is_locked();
- $this->_metadata = array_merge($meta, $this->get_plugintpl_metadata($conf['template']));
- $this->retrieve_settings();
- }
+ var $_plugin_list = null;
- function retrieve_settings() {
- global $conf;
- $no_default_check = array('setting_fieldset', 'setting_undefined', 'setting_no_class');
+ /**
+ * constructor
+ */
+ function configuration($datafile) {
+ global $conf, $config_cascade;
- if (!$this->_loaded) {
- $default = array_merge($this->get_plugintpl_default($conf['template']), $this->_read_config_group($this->_default_files));
- $local = $this->_read_config_group($this->_local_files);
- $protected = $this->_read_config_group($this->_protected_files);
+ if (!@file_exists($datafile)) {
+ msg('No configuration metadata found at - '.htmlspecialchars($datafile),-1);
+ return;
+ }
+ $meta = array();
+ include($datafile);
- $keys = array_merge(array_keys($this->_metadata),array_keys($default), array_keys($local), array_keys($protected));
- $keys = array_unique($keys);
+ if (isset($config['varname'])) $this->_name = $config['varname'];
+ if (isset($config['format'])) $this->_format = $config['format'];
+ if (isset($config['heading'])) $this->_heading = $config['heading'];
- $param = null;
- foreach ($keys as $key) {
- if (isset($this->_metadata[$key])) {
- $class = $this->_metadata[$key][0];
+ $this->_default_files = $config_cascade['main']['default'];
+ $this->_local_files = $config_cascade['main']['local'];
+ $this->_protected_files = $config_cascade['main']['protected'];
- if($class && class_exists('setting_'.$class)){
- $class = 'setting_'.$class;
- } else {
- if($class != '') {
- $this->setting[] = new setting_no_class($key,$param);
+ $this->locked = $this->_is_locked();
+ $this->_metadata = array_merge($meta, $this->get_plugintpl_metadata($conf['template']));
+ $this->retrieve_settings();
+ }
+
+ function retrieve_settings() {
+ global $conf;
+ $no_default_check = array('setting_fieldset', 'setting_undefined', 'setting_no_class');
+
+ if (!$this->_loaded) {
+ $default = array_merge($this->get_plugintpl_default($conf['template']), $this->_read_config_group($this->_default_files));
+ $local = $this->_read_config_group($this->_local_files);
+ $protected = $this->_read_config_group($this->_protected_files);
+
+ $keys = array_merge(array_keys($this->_metadata),array_keys($default), array_keys($local), array_keys($protected));
+ $keys = array_unique($keys);
+
+ $param = null;
+ foreach ($keys as $key) {
+ if (isset($this->_metadata[$key])) {
+ $class = $this->_metadata[$key][0];
+
+ if($class && class_exists('setting_'.$class)){
+ $class = 'setting_'.$class;
+ } else {
+ if($class != '') {
+ $this->setting[] = new setting_no_class($key,$param);
+ }
+ $class = 'setting';
+ }
+
+ $param = $this->_metadata[$key];
+ array_shift($param);
+ } else {
+ $class = 'setting_undefined';
+ $param = null;
+ }
+
+ if (!in_array($class, $no_default_check) && !isset($default[$key])) {
+ $this->setting[] = new setting_no_default($key,$param);
+ }
+
+ $this->setting[$key] = new $class($key,$param);
+ $this->setting[$key]->initialize($default[$key],$local[$key],$protected[$key]);
}
- $class = 'setting';
- }
- $param = $this->_metadata[$key];
- array_shift($param);
- } else {
- $class = 'setting_undefined';
- $param = null;
+ $this->_loaded = true;
}
+ }
- if (!in_array($class, $no_default_check) && !isset($default[$key])) {
- $this->setting[] = new setting_no_default($key,$param);
- }
+ function save_settings($id, $header='', $backup=true) {
+ global $conf;
- $this->setting[$key] = new $class($key,$param);
- $this->setting[$key]->initialize($default[$key],$local[$key],$protected[$key]);
- }
+ if ($this->locked) return false;
- $this->_loaded = true;
- }
- }
-
- function save_settings($id, $header='', $backup=true) {
- global $conf;
+ // write back to the last file in the local config cascade
+ $file = end($this->_local_files);
- if ($this->locked) return false;
+ // backup current file (remove any existing backup)
+ if (@file_exists($file) && $backup) {
+ if (@file_exists($file.'.bak')) @unlink($file.'.bak');
+ if (!io_rename($file, $file.'.bak')) return false;
+ }
- // write back to the last file in the local config cascade
- $file = end($this->_local_files);
+ if (!$fh = @fopen($file, 'wb')) {
+ io_rename($file.'.bak', $file); // problem opening, restore the backup
+ return false;
+ }
- // backup current file (remove any existing backup)
- if (@file_exists($file) && $backup) {
- if (@file_exists($file.'.bak')) @unlink($file.'.bak');
- if (!io_rename($file, $file.'.bak')) return false;
- }
+ if (empty($header)) $header = $this->_heading;
- if (!$fh = @fopen($file, 'wb')) {
- io_rename($file.'.bak', $file); // problem opening, restore the backup
- return false;
- }
+ $out = $this->_out_header($id,$header);
- if (empty($header)) $header = $this->_heading;
+ foreach ($this->setting as $setting) {
+ $out .= $setting->out($this->_name, $this->_format);
+ }
- $out = $this->_out_header($id,$header);
+ $out .= $this->_out_footer();
- foreach ($this->setting as $setting) {
- $out .= $setting->out($this->_name, $this->_format);
- }
+ @fwrite($fh, $out);
+ fclose($fh);
+ if($conf['fperm']) chmod($file, $conf['fperm']);
+ return true;
+ }
- $out .= $this->_out_footer();
+ /**
+ * Update last modified time stamp of the config file
+ */
+ function touch_settings(){
+ if ($this->locked) return false;
+ $file = end($this->_local_files);
+ return @touch($file);
+ }
- @fwrite($fh, $out);
- fclose($fh);
- if($conf['fperm']) chmod($file, $conf['fperm']);
- return true;
- }
+ function _read_config_group($files) {
+ $config = array();
+ foreach ($files as $file) {
+ $config = array_merge($config, $this->_read_config($file));
+ }
- /**
- * Update last modified time stamp of the config file
- */
- function touch_settings(){
- if ($this->locked) return false;
- $file = end($this->_local_files);
- return @touch($file);
- }
+ return $config;
+ }
- function _read_config_group($files) {
- $config = array();
- foreach ($files as $file) {
- $config = array_merge($config, $this->_read_config($file));
- }
+ /**
+ * return an array of config settings
+ */
+ function _read_config($file) {
- return $config;
- }
+ if (!$file) return array();
- /**
- * return an array of config settings
- */
- function _read_config($file) {
+ $config = array();
- if (!$file) return array();
+ if ($this->_format == 'php') {
- $config = array();
+ if(@file_exists($file)){
+ $contents = @php_strip_whitespace($file);
+ }else{
+ $contents = '';
+ }
+ $pattern = '/\$'.$this->_name.'\[[\'"]([^=]+)[\'"]\] ?= ?(.*?);(?=[^;]*(?:\$'.$this->_name.'|$))/s';
+ $matches=array();
+ preg_match_all($pattern,$contents,$matches,PREG_SET_ORDER);
- if ($this->_format == 'php') {
+ for ($i=0; $i<count($matches); $i++) {
+ $value = $matches[$i][2];
- if(@file_exists($file)){
- $contents = @php_strip_whitespace($file);
- }else{
- $contents = '';
- }
- $pattern = '/\$'.$this->_name.'\[[\'"]([^=]+)[\'"]\] ?= ?(.*?);(?=[^;]*(?:\$'.$this->_name.'|$))/s';
- $matches=array();
- preg_match_all($pattern,$contents,$matches,PREG_SET_ORDER);
- for ($i=0; $i<count($matches); $i++) {
- $value = $matches[$i][2];
+ // correct issues with the incoming data
+ // FIXME ... for now merge multi-dimensional array indices using ____
+ $key = preg_replace('/.\]\[./',CM_KEYMARKER,$matches[$i][1]);
- // correct issues with the incoming data
- // FIXME ... for now merge multi-dimensional array indices using ____
- $key = preg_replace('/.\]\[./',CM_KEYMARKER,$matches[$i][1]);
+ // handle arrays
+ if(preg_match('/^array ?\((.*)\)/', $value, $match)){
+ $arr = explode(',', $match[1]);
+ // remove quotes from quoted strings & unescape escaped data
+ $len = count($arr);
+ for($j=0; $j<$len; $j++){
+ $arr[$j] = trim($arr[$j]);
+ $arr[$j] = preg_replace('/^(\'|")(.*)(?<!\\\\)\1$/s','$2',$arr[$j]);
+ $arr[$j] = strtr($arr[$j], array('\\\\'=>'\\','\\\''=>'\'','\\"'=>'"'));
+ }
- // handle arrays
- if(preg_match('/^array ?\((.*)\)/', $value, $match)){
- $arr = explode(',', $match[1]);
+ $value = $arr;
+ }else{
+ // remove quotes from quoted strings & unescape escaped data
+ $value = preg_replace('/^(\'|")(.*)(?<!\\\\)\1$/s','$2',$value);
+ $value = strtr($value, array('\\\\'=>'\\','\\\''=>'\'','\\"'=>'"'));
+ }
- // remove quotes from quoted strings & unescape escaped data
- $len = count($arr);
- for($j=0; $j<$len; $j++){
- $arr[$j] = trim($arr[$j]);
- $arr[$j] = preg_replace('/^(\'|")(.*)(?<!\\\\)\1$/s','$2',$arr[$j]);
- $arr[$j] = strtr($arr[$j], array('\\\\'=>'\\','\\\''=>'\'','\\"'=>'"'));
+ $config[$key] = $value;
+ }
}
- $value = $arr;
- }else{
- // remove quotes from quoted strings & unescape escaped data
- $value = preg_replace('/^(\'|")(.*)(?<!\\\\)\1$/s','$2',$value);
- $value = strtr($value, array('\\\\'=>'\\','\\\''=>'\'','\\"'=>'"'));
- }
-
- $config[$key] = $value;
+ return $config;
}
- }
- return $config;
- }
+ function _out_header($id, $header) {
+ $out = '';
+ if ($this->_format == 'php') {
+ $out .= '<'.'?php'."\n".
+ "/*\n".
+ " * ".$header."\n".
+ " * Auto-generated by ".$id." plugin\n".
+ " * Run for user: ".$_SERVER['REMOTE_USER']."\n".
+ " * Date: ".date('r')."\n".
+ " */\n\n";
+ }
- function _out_header($id, $header) {
- $out = '';
- if ($this->_format == 'php') {
- $out .= '<'.'?php'."\n".
- "/*\n".
- " * ".$header."\n".
- " * Auto-generated by ".$id." plugin\n".
- " * Run for user: ".$_SERVER['REMOTE_USER']."\n".
- " * Date: ".date('r')."\n".
- " */\n\n";
- }
-
- return $out;
- }
+ return $out;
+ }
- function _out_footer() {
- $out = '';
- if ($this->_format == 'php') {
- $out .= "\n// end auto-generated content\n";
- }
+ function _out_footer() {
+ $out = '';
+ if ($this->_format == 'php') {
+ $out .= "\n// end auto-generated content\n";
+ }
- return $out;
- }
+ return $out;
+ }
- // configuration is considered locked if there is no local settings filename
- // or the directory its in is not writable or the file exists and is not writable
- function _is_locked() {
- if (!$this->_local_files) return true;
+ // configuration is considered locked if there is no local settings filename
+ // or the directory its in is not writable or the file exists and is not writable
+ function _is_locked() {
+ if (!$this->_local_files) return true;
- $local = $this->_local_files[0];
+ $local = $this->_local_files[0];
- if (!is_writable(dirname($local))) return true;
- if (@file_exists($local) && !is_writable($local)) return true;
+ if (!is_writable(dirname($local))) return true;
+ if (@file_exists($local) && !is_writable($local)) return true;
- return false;
- }
+ return false;
+ }
- /**
- * not used ... conf's contents are an array!
- * reduce any multidimensional settings to one dimension using CM_KEYMARKER
- */
- function _flatten($conf,$prefix='') {
+ /**
+ * not used ... conf's contents are an array!
+ * reduce any multidimensional settings to one dimension using CM_KEYMARKER
+ */
+ function _flatten($conf,$prefix='') {
- $out = array();
+ $out = array();
- foreach($conf as $key => $value) {
- if (!is_array($value)) {
- $out[$prefix.$key] = $value;
- continue;
- }
+ foreach($conf as $key => $value) {
+ if (!is_array($value)) {
+ $out[$prefix.$key] = $value;
+ continue;
+ }
+
+ $tmp = $this->_flatten($value,$prefix.$key.CM_KEYMARKER);
+ $out = array_merge($out,$tmp);
+ }
- $tmp = $this->_flatten($value,$prefix.$key.CM_KEYMARKER);
- $out = array_merge($out,$tmp);
+ return $out;
}
- return $out;
- }
+ function get_plugin_list() {
+ if (is_null($this->_plugin_list)) {
+ $list = plugin_list('',$this->show_disabled_plugins);
- function get_plugin_list() {
- if (is_null($this->_plugin_list)) {
- $list = plugin_list('',$this->show_disabled_plugins);
+ // remove this plugin from the list
+ $idx = array_search('config',$list);
+ unset($list[$idx]);
- // remove this plugin from the list
- $idx = array_search('config',$list);
- unset($list[$idx]);
+ trigger_event('PLUGIN_CONFIG_PLUGINLIST',$list);
+ $this->_plugin_list = $list;
+ }
- trigger_event('PLUGIN_CONFIG_PLUGINLIST',$list);
- $this->_plugin_list = $list;
- }
+ return $this->_plugin_list;
+ }
- return $this->_plugin_list;
- }
+ /**
+ * load metadata for plugin and template settings
+ */
+ function get_plugintpl_metadata($tpl){
+ $file = '/conf/metadata.php';
+ $class = '/conf/settings.class.php';
+ $metadata = array();
+
+ foreach ($this->get_plugin_list() as $plugin) {
+ $plugin_dir = plugin_directory($plugin);
+ if (@file_exists(DOKU_PLUGIN.$plugin_dir.$file)){
+ $meta = array();
+ @include(DOKU_PLUGIN.$plugin_dir.$file);
+ @include(DOKU_PLUGIN.$plugin_dir.$class);
+ if (!empty($meta)) {
+ $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.'plugin_settings_name'] = array('fieldset');
+ }
+ foreach ($meta as $key => $value){
+ if ($value[0]=='fieldset') { continue; } //plugins only get one fieldset
+ $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value;
+ }
+ }
+ }
- /**
- * load metadata for plugin and template settings
- */
- function get_plugintpl_metadata($tpl){
- $file = '/conf/metadata.php';
- $class = '/conf/settings.class.php';
- $metadata = array();
-
- foreach ($this->get_plugin_list() as $plugin) {
- $plugin_dir = plugin_directory($plugin);
- if (@file_exists(DOKU_PLUGIN.$plugin_dir.$file)){
- $meta = array();
- @include(DOKU_PLUGIN.$plugin_dir.$file);
- @include(DOKU_PLUGIN.$plugin_dir.$class);
- if (!empty($meta)) {
- $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.'plugin_settings_name'] = array('fieldset');
- }
- foreach ($meta as $key => $value){
- if ($value[0]=='fieldset') { continue; } //plugins only get one fieldset
- $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value;
- }
- }
- }
-
- // the same for the active template
- if (@file_exists(tpl_incdir().$file)){
- $meta = array();
- @include(tpl_incdir().$file);
- @include(tpl_incdir().$class);
- if (!empty($meta)) {
- $metadata['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.'template_settings_name'] = array('fieldset');
- }
- foreach ($meta as $key => $value){
- if ($value[0]=='fieldset') { continue; } //template only gets one fieldset
- $metadata['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.$key] = $value;
+ // the same for the active template
+ if (@file_exists(tpl_incdir().$file)){
+ $meta = array();
+ @include(tpl_incdir().$file);
+ @include(tpl_incdir().$class);
+ if (!empty($meta)) {
+ $metadata['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.'template_settings_name'] = array('fieldset');
+ }
+ foreach ($meta as $key => $value){
+ if ($value[0]=='fieldset') { continue; } //template only gets one fieldset
+ $metadata['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.$key] = $value;
+ }
+ }
+
+ return $metadata;
}
- }
- return $metadata;
- }
+ /**
+ * load default settings for plugins and templates
+ */
+ function get_plugintpl_default($tpl){
+ $file = '/conf/default.php';
+ $default = array();
+
+ foreach ($this->get_plugin_list() as $plugin) {
+ $plugin_dir = plugin_directory($plugin);
+ if (@file_exists(DOKU_PLUGIN.$plugin_dir.$file)){
+ $conf = array();
+ @include(DOKU_PLUGIN.$plugin_dir.$file);
+ foreach ($conf as $key => $value){
+ $default['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value;
+ }
+ }
+ }
- /**
- * load default settings for plugins and templates
- */
- function get_plugintpl_default($tpl){
- $file = '/conf/default.php';
- $default = array();
-
- foreach ($this->get_plugin_list() as $plugin) {
- $plugin_dir = plugin_directory($plugin);
- if (@file_exists(DOKU_PLUGIN.$plugin_dir.$file)){
- $conf = array();
- @include(DOKU_PLUGIN.$plugin_dir.$file);
- foreach ($conf as $key => $value){
- $default['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value;
- }
- }
- }
-
- // the same for the active template
- if (@file_exists(tpl_incdir().$file)){
- $conf = array();
- @include(tpl_incdir().$file);
- foreach ($conf as $key => $value){
- $default['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.$key] = $value;
+ // the same for the active template
+ if (@file_exists(tpl_incdir().$file)){
+ $conf = array();
+ @include(tpl_incdir().$file);
+ foreach ($conf as $key => $value){
+ $default['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.$key] = $value;
+ }
+ }
+
+ return $default;
}
- }
- return $default;
}
-
- }
}
if (!class_exists('setting')) {
- class setting {
+ class setting {
- var $_key = '';
- var $_default = null;
- var $_local = null;
- var $_protected = null;
+ var $_key = '';
+ var $_default = null;
+ var $_local = null;
+ var $_protected = null;
- var $_pattern = '';
- var $_error = false; // only used by those classes which error check
- var $_input = null; // only used by those classes which error check
- var $_caution = null; // used by any setting to provide an alert along with the setting
- // valid alerts, 'warning', 'danger', 'security'
- // images matching the alerts are in the plugin's images directory
+ var $_pattern = '';
+ var $_error = false; // only used by those classes which error check
+ var $_input = null; // only used by those classes which error check
+ var $_caution = null; // used by any setting to provide an alert along with the setting
+ // valid alerts, 'warning', 'danger', 'security'
+ // images matching the alerts are in the plugin's images directory
- static protected $_validCautions = array('warning','danger','security');
+ static protected $_validCautions = array('warning','danger','security');
- function setting($key, $params=null) {
- $this->_key = $key;
+ function setting($key, $params=null) {
+ $this->_key = $key;
- if (is_array($params)) {
- foreach($params as $property => $value) {
- $this->$property = $value;
- }
+ if (is_array($params)) {
+ foreach($params as $property => $value) {
+ $this->$property = $value;
+ }
+ }
}
- }
-
- /**
- * receives current values for the setting $key
- */
- function initialize($default, $local, $protected) {
- if (isset($default)) $this->_default = $default;
- if (isset($local)) $this->_local = $local;
- if (isset($protected)) $this->_protected = $protected;
- }
- /**
- * update changed setting with user provided value $input
- * - if changed value fails error check, save it to $this->_input (to allow echoing later)
- * - if changed value passes error check, set $this->_local to the new value
- *
- * @param mixed $input the new value
- * @return boolean true if changed, false otherwise (incl. on error)
- */
- function update($input) {
- if (is_null($input)) return false;
- if ($this->is_protected()) return false;
-
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- if ($value == $input) return false;
-
- if ($this->_pattern && !preg_match($this->_pattern,$input)) {
- $this->_error = true;
- $this->_input = $input;
- return false;
+ /**
+ * receives current values for the setting $key
+ */
+ function initialize($default, $local, $protected) {
+ if (isset($default)) $this->_default = $default;
+ if (isset($local)) $this->_local = $local;
+ if (isset($protected)) $this->_protected = $protected;
}
- $this->_local = $input;
- return true;
- }
+ /**
+ * update changed setting with user provided value $input
+ * - if changed value fails error check, save it to $this->_input (to allow echoing later)
+ * - if changed value passes error check, set $this->_local to the new value
+ *
+ * @param mixed $input the new value
+ * @return boolean true if changed, false otherwise (incl. on error)
+ */
+ function update($input) {
+ if (is_null($input)) return false;
+ if ($this->is_protected()) return false;
- /**
- * @return array(string $label_html, string $input_html)
- */
- function html(&$plugin, $echo=false) {
- $value = '';
- $disable = '';
-
- if ($this->is_protected()) {
- $value = $this->_protected;
- $disable = 'disabled="disabled"';
- } else {
- if ($echo && $this->_error) {
- $value = $this->_input;
- } else {
$value = is_null($this->_local) ? $this->_default : $this->_local;
- }
- }
+ if ($value == $input) return false;
- $key = htmlspecialchars($this->_key);
- $value = formText($value);
+ if ($this->_pattern && !preg_match($this->_pattern,$input)) {
+ $this->_error = true;
+ $this->_input = $input;
+ return false;
+ }
- $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
- $input = '<textarea rows="3" cols="40" id="config___'.$key.'" name="config['.$key.']" class="edit" '.$disable.'>'.$value.'</textarea>';
- return array($label,$input);
- }
+ $this->_local = $input;
+ return true;
+ }
- /**
- * generate string to save setting value to file according to $fmt
- */
- function out($var, $fmt='php') {
+ /**
+ * @return array(string $label_html, string $input_html)
+ */
+ function html(&$plugin, $echo=false) {
+ $value = '';
+ $disable = '';
- if ($this->is_protected()) return '';
- if (is_null($this->_local) || ($this->_default == $this->_local)) return '';
+ if ($this->is_protected()) {
+ $value = $this->_protected;
+ $disable = 'disabled="disabled"';
+ } else {
+ if ($echo && $this->_error) {
+ $value = $this->_input;
+ } else {
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ }
+ }
- $out = '';
+ $key = htmlspecialchars($this->_key);
+ $value = formText($value);
- if ($fmt=='php') {
- $tr = array("\\" => '\\\\', "'" => '\\\'');
+ $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
+ $input = '<textarea rows="3" cols="40" id="config___'.$key.'" name="config['.$key.']" class="edit" '.$disable.'>'.$value.'</textarea>';
+ return array($label,$input);
+ }
- $out = '$'.$var."['".$this->_out_key()."'] = '".strtr( cleanText($this->_local), $tr)."';\n";
- }
+ /**
+ * generate string to save setting value to file according to $fmt
+ */
+ function out($var, $fmt='php') {
- return $out;
- }
+ if ($this->is_protected()) return '';
+ if (is_null($this->_local) || ($this->_default == $this->_local)) return '';
- function prompt(&$plugin) {
- $prompt = $plugin->getLang($this->_key);
- if (!$prompt) $prompt = htmlspecialchars(str_replace(array('____','_'),' ',$this->_key));
- return $prompt;
- }
+ $out = '';
- function is_protected() { return !is_null($this->_protected); }
- function is_default() { return !$this->is_protected() && is_null($this->_local); }
- function error() { return $this->_error; }
+ if ($fmt=='php') {
+ $tr = array("\\" => '\\\\', "'" => '\\\'');
- function caution() {
- if (!empty($this->_caution)) {
- if (!in_array($this->_caution, setting::$_validCautions)) {
- trigger_error('Invalid caution string ('.$this->_caution.') in metadata for setting "'.$this->_key.'"', E_USER_WARNING);
- return false;
+ $out = '$'.$var."['".$this->_out_key()."'] = '".strtr( cleanText($this->_local), $tr)."';\n";
}
- return $this->_caution;
+
+ return $out;
}
- // compatibility with previous cautionList
- // TODO: check if any plugins use; remove
- if (!empty($this->_cautionList[$this->_key])) {
- $this->_caution = $this->_cautionList[$this->_key];
- unset($this->_cautionList);
- return $this->caution();
+ function prompt(&$plugin) {
+ $prompt = $plugin->getLang($this->_key);
+ if (!$prompt) $prompt = htmlspecialchars(str_replace(array('____','_'),' ',$this->_key));
+ return $prompt;
}
- return false;
- }
- function _out_key($pretty=false,$url=false) {
- if($pretty){
- $out = str_replace(CM_KEYMARKER,"»",$this->_key);
- if ($url && !strstr($out,'»')) {//provide no urls for plugins, etc.
- if ($out == 'start') //one exception
- return '<a href="http://www.dokuwiki.org/config:startpage">'.$out.'</a>';
- else
- return '<a href="http://www.dokuwiki.org/config:'.$out.'">'.$out.'</a>';
+ function is_protected() { return !is_null($this->_protected); }
+ function is_default() { return !$this->is_protected() && is_null($this->_local); }
+ function error() { return $this->_error; }
+
+ function caution() {
+ if (!empty($this->_caution)) {
+ if (!in_array($this->_caution, setting::$_validCautions)) {
+ trigger_error('Invalid caution string ('.$this->_caution.') in metadata for setting "'.$this->_key.'"', E_USER_WARNING);
+ return false;
+ }
+ return $this->_caution;
+ }
+ // compatibility with previous cautionList
+ // TODO: check if any plugins use; remove
+ if (!empty($this->_cautionList[$this->_key])) {
+ $this->_caution = $this->_cautionList[$this->_key];
+ unset($this->_cautionList);
+
+ return $this->caution();
+ }
+ return false;
+ }
+
+ function _out_key($pretty=false,$url=false) {
+ if($pretty){
+ $out = str_replace(CM_KEYMARKER,"»",$this->_key);
+ if ($url && !strstr($out,'»')) {//provide no urls for plugins, etc.
+ if ($out == 'start') //one exception
+ return '<a href="http://www.dokuwiki.org/config:startpage">'.$out.'</a>';
+ else
+ return '<a href="http://www.dokuwiki.org/config:'.$out.'">'.$out.'</a>';
+ }
+ return $out;
+ }else{
+ return str_replace(CM_KEYMARKER,"']['",$this->_key);
}
- return $out;
- }else{
- return str_replace(CM_KEYMARKER,"']['",$this->_key);
}
}
- }
}
@@ -612,178 +612,178 @@ if (!class_exists('setting_array')) {
}
if (!class_exists('setting_string')) {
- class setting_string extends setting {
- function html(&$plugin, $echo=false) {
- $value = '';
- $disable = '';
-
- if ($this->is_protected()) {
- $value = $this->_protected;
- $disable = 'disabled="disabled"';
- } else {
- if ($echo && $this->_error) {
- $value = $this->_input;
- } else {
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- }
- }
+ class setting_string extends setting {
+ function html(&$plugin, $echo=false) {
+ $value = '';
+ $disable = '';
+
+ if ($this->is_protected()) {
+ $value = $this->_protected;
+ $disable = 'disabled="disabled"';
+ } else {
+ if ($echo && $this->_error) {
+ $value = $this->_input;
+ } else {
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ }
+ }
- $key = htmlspecialchars($this->_key);
- $value = htmlspecialchars($value);
+ $key = htmlspecialchars($this->_key);
+ $value = htmlspecialchars($value);
- $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
- $input = '<input id="config___'.$key.'" name="config['.$key.']" type="text" class="edit" value="'.$value.'" '.$disable.'/>';
- return array($label,$input);
+ $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
+ $input = '<input id="config___'.$key.'" name="config['.$key.']" type="text" class="edit" value="'.$value.'" '.$disable.'/>';
+ return array($label,$input);
+ }
}
- }
}
if (!class_exists('setting_password')) {
- class setting_password extends setting_string {
+ class setting_password extends setting_string {
- var $_code = 'plain'; // mechanism to be used to obscure passwords
+ var $_code = 'plain'; // mechanism to be used to obscure passwords
- function update($input) {
- if ($this->is_protected()) return false;
- if (!$input) return false;
+ function update($input) {
+ if ($this->is_protected()) return false;
+ if (!$input) return false;
- if ($this->_pattern && !preg_match($this->_pattern,$input)) {
- $this->_error = true;
- $this->_input = $input;
- return false;
- }
+ if ($this->_pattern && !preg_match($this->_pattern,$input)) {
+ $this->_error = true;
+ $this->_input = $input;
+ return false;
+ }
- $this->_local = conf_encodeString($input,$this->_code);
- return true;
- }
+ $this->_local = conf_encodeString($input,$this->_code);
+ return true;
+ }
- function html(&$plugin, $echo=false) {
+ function html(&$plugin, $echo=false) {
- $value = '';
- $disable = $this->is_protected() ? 'disabled="disabled"' : '';
+ $value = '';
+ $disable = $this->is_protected() ? 'disabled="disabled"' : '';
- $key = htmlspecialchars($this->_key);
+ $key = htmlspecialchars($this->_key);
- $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
- $input = '<input id="config___'.$key.'" name="config['.$key.']" autocomplete="off" type="password" class="edit" value="" '.$disable.' />';
- return array($label,$input);
+ $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
+ $input = '<input id="config___'.$key.'" name="config['.$key.']" autocomplete="off" type="password" class="edit" value="" '.$disable.' />';
+ return array($label,$input);
+ }
}
- }
}
if (!class_exists('setting_email')) {
- class setting_email extends setting_string {
- var $_multiple = false;
- var $_placeholders = false;
-
- /**
- * update setting with user provided value $input
- * if value fails error check, save it
- *
- * @return boolean true if changed, false otherwise (incl. on error)
- */
- function update($input) {
- if (is_null($input)) return false;
- if ($this->is_protected()) return false;
-
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- if ($value == $input) return false;
- if($input === ''){
- $this->_local = $input;
- return true;
- }
- $mail = $input;
+ class setting_email extends setting_string {
+ var $_multiple = false;
+ var $_placeholders = false;
- if($this->_placeholders){
- // replace variables with pseudo values
- $mail = str_replace('@USER@','joe',$mail);
- $mail = str_replace('@NAME@','Joe Schmoe',$mail);
- $mail = str_replace('@MAIL@','joe@example.com',$mail);
- }
+ /**
+ * update setting with user provided value $input
+ * if value fails error check, save it
+ *
+ * @return boolean true if changed, false otherwise (incl. on error)
+ */
+ function update($input) {
+ if (is_null($input)) return false;
+ if ($this->is_protected()) return false;
- // multiple mail addresses?
- if ($this->_multiple) {
- $mails = array_filter(array_map('trim', explode(',', $mail)));
- } else {
- $mails = array($mail);
- }
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ if ($value == $input) return false;
+ if($input === ''){
+ $this->_local = $input;
+ return true;
+ }
+ $mail = $input;
- // check them all
- foreach ($mails as $mail) {
- // only check the address part
- if(preg_match('#(.*?)<(.*?)>#', $mail, $matches)){
- $addr = $matches[2];
- }else{
- $addr = $mail;
+ if($this->_placeholders){
+ // replace variables with pseudo values
+ $mail = str_replace('@USER@','joe',$mail);
+ $mail = str_replace('@NAME@','Joe Schmoe',$mail);
+ $mail = str_replace('@MAIL@','joe@example.com',$mail);
}
- if (!mail_isvalid($addr)) {
- $this->_error = true;
- $this->_input = $input;
- return false;
+ // multiple mail addresses?
+ if ($this->_multiple) {
+ $mails = array_filter(array_map('trim', explode(',', $mail)));
+ } else {
+ $mails = array($mail);
}
- }
- $this->_local = $input;
- return true;
+ // check them all
+ foreach ($mails as $mail) {
+ // only check the address part
+ if(preg_match('#(.*?)<(.*?)>#', $mail, $matches)){
+ $addr = $matches[2];
+ }else{
+ $addr = $mail;
+ }
+
+ if (!mail_isvalid($addr)) {
+ $this->_error = true;
+ $this->_input = $input;
+ return false;
+ }
+ }
+
+ $this->_local = $input;
+ return true;
+ }
}
- }
}
/**
* @deprecated 2013-02-16
*/
if (!class_exists('setting_richemail')) {
- class setting_richemail extends setting_email {
- function update($input) {
- $this->_placeholders = true;
- return parent::update($input);
- }
- }
+ class setting_richemail extends setting_email {
+ function update($input) {
+ $this->_placeholders = true;
+ return parent::update($input);
+ }
+ }
}
if (!class_exists('setting_numeric')) {
- class setting_numeric extends setting_string {
- // This allows for many PHP syntax errors...
- // var $_pattern = '/^[-+\/*0-9 ]*$/';
- // much more restrictive, but should eliminate syntax errors.
- var $_pattern = '/^[-+]? *[0-9]+ *(?:[-+*] *[0-9]+ *)*$/';
- var $_min = null;
- var $_max = null;
-
- function update($input) {
- $local = $this->_local;
- $valid = parent::update($input);
- if ($valid && !(is_null($this->_min) && is_null($this->_max))) {
- $numeric_local = (int) eval('return '.$this->_local.';');
- if ((!is_null($this->_min) && $numeric_local < $this->_min) ||
- (!is_null($this->_max) && $numeric_local > $this->_max)) {
- $this->_error = true;
- $this->_input = $input;
- $this->_local = $local;
- $valid = false;
+ class setting_numeric extends setting_string {
+ // This allows for many PHP syntax errors...
+ // var $_pattern = '/^[-+\/*0-9 ]*$/';
+ // much more restrictive, but should eliminate syntax errors.
+ var $_pattern = '/^[-+]? *[0-9]+ *(?:[-+*] *[0-9]+ *)*$/';
+ var $_min = null;
+ var $_max = null;
+
+ function update($input) {
+ $local = $this->_local;
+ $valid = parent::update($input);
+ if ($valid && !(is_null($this->_min) && is_null($this->_max))) {
+ $numeric_local = (int) eval('return '.$this->_local.';');
+ if ((!is_null($this->_min) && $numeric_local < $this->_min) ||
+ (!is_null($this->_max) && $numeric_local > $this->_max)) {
+ $this->_error = true;
+ $this->_input = $input;
+ $this->_local = $local;
+ $valid = false;
+ }
}
+ return $valid;
}
- return $valid;
- }
- function out($var, $fmt='php') {
+ function out($var, $fmt='php') {
- if ($this->is_protected()) return '';
- if (is_null($this->_local) || ($this->_default == $this->_local)) return '';
+ if ($this->is_protected()) return '';
+ if (is_null($this->_local) || ($this->_default == $this->_local)) return '';
- $out = '';
+ $out = '';
- if ($fmt=='php') {
- $local = $this->_local === '' ? "''" : $this->_local;
- $out .= '$'.$var."['".$this->_out_key()."'] = ".$local.";\n";
- }
+ if ($fmt=='php') {
+ $local = $this->_local === '' ? "''" : $this->_local;
+ $out .= '$'.$var."['".$this->_out_key()."'] = ".$local.";\n";
+ }
- return $out;
+ return $out;
+ }
}
- }
}
if (!class_exists('setting_numericopt')) {
@@ -794,309 +794,309 @@ if (!class_exists('setting_numericopt')) {
}
if (!class_exists('setting_onoff')) {
- class setting_onoff extends setting_numeric {
+ class setting_onoff extends setting_numeric {
- function html(&$plugin) {
- $value = '';
- $disable = '';
+ function html(&$plugin) {
+ $value = '';
+ $disable = '';
- if ($this->is_protected()) {
- $value = $this->_protected;
- $disable = ' disabled="disabled"';
- } else {
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- }
+ if ($this->is_protected()) {
+ $value = $this->_protected;
+ $disable = ' disabled="disabled"';
+ } else {
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ }
- $key = htmlspecialchars($this->_key);
- $checked = ($value) ? ' checked="checked"' : '';
+ $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 array($label,$input);
- }
+ $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 array($label,$input);
+ }
- function update($input) {
- if ($this->is_protected()) return false;
+ function update($input) {
+ if ($this->is_protected()) return false;
- $input = ($input) ? 1 : 0;
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- if ($value == $input) 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;
+ $this->_local = $input;
+ return true;
+ }
}
- }
}
if (!class_exists('setting_multichoice')) {
- class setting_multichoice extends setting_string {
- var $_choices = array();
-
- function html(&$plugin) {
- $value = '';
- $disable = '';
- $nochoice = '';
-
- if ($this->is_protected()) {
- $value = $this->_protected;
- $disable = ' disabled="disabled"';
- } else {
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- }
+ class setting_multichoice extends setting_string {
+ var $_choices = array();
- // ensure current value is included
- if (!in_array($value, $this->_choices)) {
- $this->_choices[] = $value;
- }
- // disable if no other choices
- if (!$this->is_protected() && count($this->_choices) <= 1) {
- $disable = ' disabled="disabled"';
- $nochoice = $plugin->getLang('nochoice');
- }
+ function html(&$plugin) {
+ $value = '';
+ $disable = '';
+ $nochoice = '';
- $key = htmlspecialchars($this->_key);
+ if ($this->is_protected()) {
+ $value = $this->_protected;
+ $disable = ' disabled="disabled"';
+ } else {
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ }
- $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
+ // ensure current value is included
+ if (!in_array($value, $this->_choices)) {
+ $this->_choices[] = $value;
+ }
+ // disable if no other choices
+ if (!$this->is_protected() && count($this->_choices) <= 1) {
+ $disable = ' disabled="disabled"';
+ $nochoice = $plugin->getLang('nochoice');
+ }
- $input = "<div class=\"input\">\n";
- $input .= '<select class="edit" id="config___'.$key.'" name="config['.$key.']"'.$disable.'>'."\n";
- foreach ($this->_choices as $choice) {
- $selected = ($value == $choice) ? ' selected="selected"' : '';
- $option = $plugin->getLang($this->_key.'_o_'.$choice);
- if (!$option && isset($this->lang[$this->_key.'_o_'.$choice])) $option = $this->lang[$this->_key.'_o_'.$choice];
- if (!$option) $option = $choice;
+ $key = htmlspecialchars($this->_key);
- $choice = htmlspecialchars($choice);
- $option = htmlspecialchars($option);
- $input .= ' <option value="'.$choice.'"'.$selected.' >'.$option.'</option>'."\n";
- }
- $input .= "</select> $nochoice \n";
- $input .= "</div>\n";
+ $label = '<label for="config___'.$key.'">'.$this->prompt($plugin).'</label>';
- return array($label,$input);
- }
+ $input = "<div class=\"input\">\n";
+ $input .= '<select class="edit" id="config___'.$key.'" name="config['.$key.']"'.$disable.'>'."\n";
+ foreach ($this->_choices as $choice) {
+ $selected = ($value == $choice) ? ' selected="selected"' : '';
+ $option = $plugin->getLang($this->_key.'_o_'.$choice);
+ if (!$option && isset($this->lang[$this->_key.'_o_'.$choice])) $option = $this->lang[$this->_key.'_o_'.$choice];
+ if (!$option) $option = $choice;
+
+ $choice = htmlspecialchars($choice);
+ $option = htmlspecialchars($option);
+ $input .= ' <option value="'.$choice.'"'.$selected.' >'.$option.'</option>'."\n";
+ }
+ $input .= "</select> $nochoice \n";
+ $input .= "</div>\n";
+
+ return array($label,$input);
+ }
- function update($input) {
- if (is_null($input)) return false;
- if ($this->is_protected()) return false;
+ function update($input) {
+ if (is_null($input)) return false;
+ if ($this->is_protected()) return false;
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- if ($value == $input) return false;
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ if ($value == $input) return false;
- if (!in_array($input, $this->_choices)) return false;
+ if (!in_array($input, $this->_choices)) return false;
- $this->_local = $input;
- return true;
+ $this->_local = $input;
+ return true;
+ }
}
- }
}
if (!class_exists('setting_dirchoice')) {
- class setting_dirchoice extends setting_multichoice {
+ class setting_dirchoice extends setting_multichoice {
- var $_dir = '';
+ var $_dir = '';
- function initialize($default,$local,$protected) {
+ function initialize($default,$local,$protected) {
- // populate $this->_choices with a list of directories
- $list = array();
+ // populate $this->_choices with a list of directories
+ $list = array();
- if ($dh = @opendir($this->_dir)) {
- while (false !== ($entry = readdir($dh))) {
- if ($entry == '.' || $entry == '..') continue;
- if ($this->_pattern && !preg_match($this->_pattern,$entry)) continue;
+ if ($dh = @opendir($this->_dir)) {
+ while (false !== ($entry = readdir($dh))) {
+ if ($entry == '.' || $entry == '..') continue;
+ if ($this->_pattern && !preg_match($this->_pattern,$entry)) continue;
- $file = (is_link($this->_dir.$entry)) ? readlink($this->_dir.$entry) : $this->_dir.$entry;
- if (is_dir($file)) $list[] = $entry;
- }
- closedir($dh);
- }
- sort($list);
- $this->_choices = $list;
+ $file = (is_link($this->_dir.$entry)) ? readlink($this->_dir.$entry) : $this->_dir.$entry;
+ if (is_dir($file)) $list[] = $entry;
+ }
+ closedir($dh);
+ }
+ sort($list);
+ $this->_choices = $list;
- parent::initialize($default,$local,$protected);
+ parent::initialize($default,$local,$protected);
+ }
}
- }
}
if (!class_exists('setting_hidden')) {
- class setting_hidden extends setting {
- // Used to explicitly ignore a setting in the configuration manager.
- }
+ class setting_hidden extends setting {
+ // Used to explicitly ignore a setting in the configuration manager.
+ }
}
if (!class_exists('setting_fieldset')) {
- class setting_fieldset extends setting {
- // A do-nothing class used to detect the 'fieldset' type.
- // Used to start a new settings "display-group".
- }
+ class setting_fieldset extends setting {
+ // A do-nothing class used to detect the 'fieldset' type.
+ // Used to start a new settings "display-group".
+ }
}
if (!class_exists('setting_undefined')) {
- class setting_undefined extends setting_hidden {
- // A do-nothing class used to detect settings with no metadata entry.
- // Used internaly to hide undefined settings, and generate the undefined settings list.
- }
+ class setting_undefined extends setting_hidden {
+ // A do-nothing class used to detect settings with no metadata entry.
+ // Used internaly to hide undefined settings, and generate the undefined settings list.
+ }
}
if (!class_exists('setting_no_class')) {
- class setting_no_class extends setting_undefined {
- // A do-nothing class used to detect settings with a missing setting class.
- // Used internaly to hide undefined settings, and generate the undefined settings list.
- }
+ class setting_no_class extends setting_undefined {
+ // A do-nothing class used to detect settings with a missing setting class.
+ // Used internaly to hide undefined settings, and generate the undefined settings list.
+ }
}
if (!class_exists('setting_no_default')) {
- class setting_no_default extends setting_undefined {
- // A do-nothing class used to detect settings with no default value.
- // Used internaly to hide undefined settings, and generate the undefined settings list.
- }
+ class setting_no_default extends setting_undefined {
+ // A do-nothing class used to detect settings with no default value.
+ // Used internaly to hide undefined settings, and generate the undefined settings list.
+ }
}
if (!class_exists('setting_multicheckbox')) {
- class setting_multicheckbox extends setting_string {
+ class setting_multicheckbox extends setting_string {
- var $_choices = array();
- var $_combine = array();
+ var $_choices = array();
+ var $_combine = array();
- function update($input) {
- if ($this->is_protected()) return false;
+ function update($input) {
+ if ($this->is_protected()) return false;
- // split any combined values + convert from array to comma separated string
- $input = ($input) ? $input : array();
- $input = $this->_array2str($input);
+ // split any combined values + convert from array to comma separated string
+ $input = ($input) ? $input : array();
+ $input = $this->_array2str($input);
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- if ($value == $input) return false;
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ if ($value == $input) return false;
+
+ if ($this->_pattern && !preg_match($this->_pattern,$input)) {
+ $this->_error = true;
+ $this->_input = $input;
+ return false;
+ }
- if ($this->_pattern && !preg_match($this->_pattern,$input)) {
- $this->_error = true;
- $this->_input = $input;
- return false;
+ $this->_local = $input;
+ return true;
}
- $this->_local = $input;
- return true;
- }
+ function html(&$plugin, $echo=false) {
- function html(&$plugin, $echo=false) {
+ $value = '';
+ $disable = '';
- $value = '';
- $disable = '';
+ if ($this->is_protected()) {
+ $value = $this->_protected;
+ $disable = 'disabled="disabled"';
+ } else {
+ if ($echo && $this->_error) {
+ $value = $this->_input;
+ } else {
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ }
+ }
- if ($this->is_protected()) {
- $value = $this->_protected;
- $disable = 'disabled="disabled"';
- } else {
- if ($echo && $this->_error) {
- $value = $this->_input;
- } else {
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- }
- }
+ $key = htmlspecialchars($this->_key);
- $key = htmlspecialchars($this->_key);
+ // convert from comma separated list into array + combine complimentary actions
+ $value = $this->_str2array($value);
+ $default = $this->_str2array($this->_default);
- // convert from comma separated list into array + combine complimentary actions
- $value = $this->_str2array($value);
- $default = $this->_str2array($this->_default);
+ $input = '';
+ foreach ($this->_choices as $choice) {
+ $idx = array_search($choice, $value);
+ $idx_default = array_search($choice,$default);
- $input = '';
- foreach ($this->_choices as $choice) {
- $idx = array_search($choice, $value);
- $idx_default = array_search($choice,$default);
+ $checked = ($idx !== false) ? 'checked="checked"' : '';
- $checked = ($idx !== false) ? 'checked="checked"' : '';
+ // ideally this would be handled using a second class of "default", however IE6 does not
+ // correctly support CSS selectors referencing multiple class names on the same element
+ // (e.g. .default.selection).
+ $class = (($idx !== false) == (false !== $idx_default)) ? " selectiondefault" : "";
- // ideally this would be handled using a second class of "default", however IE6 does not
- // correctly support CSS selectors referencing multiple class names on the same element
- // (e.g. .default.selection).
- $class = (($idx !== false) == (false !== $idx_default)) ? " selectiondefault" : "";
+ $prompt = ($plugin->getLang($this->_key.'_'.$choice) ?
+ $plugin->getLang($this->_key.'_'.$choice) : htmlspecialchars($choice));
- $prompt = ($plugin->getLang($this->_key.'_'.$choice) ?
- $plugin->getLang($this->_key.'_'.$choice) : htmlspecialchars($choice));
+ $input .= '<div class="selection'.$class.'">'."\n";
+ $input .= '<label for="config___'.$key.'_'.$choice.'">'.$prompt."</label>\n";
+ $input .= '<input id="config___'.$key.'_'.$choice.'" name="config['.$key.'][]" type="checkbox" class="checkbox" value="'.$choice.'" '.$disable.' '.$checked."/>\n";
+ $input .= "</div>\n";
- $input .= '<div class="selection'.$class.'">'."\n";
- $input .= '<label for="config___'.$key.'_'.$choice.'">'.$prompt."</label>\n";
- $input .= '<input id="config___'.$key.'_'.$choice.'" name="config['.$key.'][]" type="checkbox" class="checkbox" value="'.$choice.'" '.$disable.' '.$checked."/>\n";
- $input .= "</div>\n";
+ // remove this action from the disabledactions array
+ if ($idx !== false) unset($value[$idx]);
+ if ($idx_default !== false) unset($default[$idx_default]);
+ }
- // remove this action from the disabledactions array
- if ($idx !== false) unset($value[$idx]);
- if ($idx_default !== false) unset($default[$idx_default]);
- }
+ // handle any remaining values
+ $other = join(',',$value);
- // handle any remaining values
- $other = join(',',$value);
+ $class = (count($default == count($value)) && (count($value) == count(array_intersect($value,$default)))) ?
+ " selectiondefault" : "";
- $class = (count($default == count($value)) && (count($value) == count(array_intersect($value,$default)))) ?
- " selectiondefault" : "";
+ $input .= '<div class="other'.$class.'">'."\n";
+ $input .= '<label for="config___'.$key.'_other">'.$plugin->getLang($key.'_other')."</label>\n";
+ $input .= '<input id="config___'.$key.'_other" name="config['.$key.'][other]" type="text" class="edit" value="'.htmlspecialchars($other).'" '.$disable." />\n";
+ $input .= "</div>\n";
- $input .= '<div class="other'.$class.'">'."\n";
- $input .= '<label for="config___'.$key.'_other">'.$plugin->getLang($key.'_other')."</label>\n";
- $input .= '<input id="config___'.$key.'_other" name="config['.$key.'][other]" type="text" class="edit" value="'.htmlspecialchars($other).'" '.$disable." />\n";
- $input .= "</div>\n";
+ $label = '<label>'.$this->prompt($plugin).'</label>';
+ return array($label,$input);
+ }
- $label = '<label>'.$this->prompt($plugin).'</label>';
- return array($label,$input);
- }
+ /**
+ * convert comma separated list to an array and combine any complimentary values
+ */
+ function _str2array($str) {
+ $array = explode(',',$str);
+
+ if (!empty($this->_combine)) {
+ foreach ($this->_combine as $key => $combinators) {
+ $idx = array();
+ foreach ($combinators as $val) {
+ if (($idx[] = array_search($val, $array)) === false) break;
+ }
+
+ if (count($idx) && $idx[count($idx)-1] !== false) {
+ foreach ($idx as $i) unset($array[$i]);
+ $array[] = $key;
+ }
+ }
+ }
- /**
- * convert comma separated list to an array and combine any complimentary values
- */
- function _str2array($str) {
- $array = explode(',',$str);
-
- if (!empty($this->_combine)) {
- foreach ($this->_combine as $key => $combinators) {
- $idx = array();
- foreach ($combinators as $val) {
- if (($idx[] = array_search($val, $array)) === false) break;
- }
-
- if (count($idx) && $idx[count($idx)-1] !== false) {
- foreach ($idx as $i) unset($array[$i]);
- $array[] = $key;
- }
+ return $array;
}
- }
- return $array;
- }
+ /**
+ * convert array of values + other back to a comma separated list, incl. splitting any combined values
+ */
+ function _array2str($input) {
- /**
- * convert array of values + other back to a comma separated list, incl. splitting any combined values
- */
- function _array2str($input) {
+ // handle other
+ $other = trim($input['other']);
+ $other = !empty($other) ? explode(',',str_replace(' ','',$input['other'])) : array();
+ unset($input['other']);
- // handle other
- $other = trim($input['other']);
- $other = !empty($other) ? explode(',',str_replace(' ','',$input['other'])) : array();
- unset($input['other']);
+ $array = array_unique(array_merge($input, $other));
- $array = array_unique(array_merge($input, $other));
+ // deconstruct any combinations
+ if (!empty($this->_combine)) {
+ foreach ($this->_combine as $key => $combinators) {
- // deconstruct any combinations
- if (!empty($this->_combine)) {
- foreach ($this->_combine as $key => $combinators) {
+ $idx = array_search($key,$array);
+ if ($idx !== false) {
+ unset($array[$idx]);
+ $array = array_merge($array, $combinators);
+ }
+ }
+ }
- $idx = array_search($key,$array);
- if ($idx !== false) {
- unset($array[$idx]);
- $array = array_merge($array, $combinators);
- }
+ return join(',',array_unique($array));
}
- }
-
- return join(',',array_unique($array));
}
- }
}
if (!class_exists('setting_regex')){
- class setting_regex extends setting_string {
+ class setting_regex extends setting_string {
var $_delimiter = '/'; // regex delimiter to be used in testing input
var $_pregflags = 'ui'; // regex pattern modifiers to be used in testing input
diff --git a/lib/plugins/config/settings/extra.class.php b/lib/plugins/config/settings/extra.class.php
index e4b97eb01..954178bc1 100644
--- a/lib/plugins/config/settings/extra.class.php
+++ b/lib/plugins/config/settings/extra.class.php
@@ -6,204 +6,204 @@
*/
if (!class_exists('setting_sepchar')) {
- class setting_sepchar extends setting_multichoice {
+ class setting_sepchar extends setting_multichoice {
- function setting_sepchar($key,$param=NULL) {
- $str = '_-.';
- for ($i=0;$i<strlen($str);$i++) $this->_choices[] = $str{$i};
+ function setting_sepchar($key,$param=NULL) {
+ $str = '_-.';
+ for ($i=0;$i<strlen($str);$i++) $this->_choices[] = $str{$i};
- // call foundation class constructor
- $this->setting($key,$param);
+ // call foundation class constructor
+ $this->setting($key,$param);
+ }
}
- }
}
if (!class_exists('setting_savedir')) {
- class setting_savedir extends setting_string {
+ class setting_savedir extends setting_string {
- function update($input) {
- if ($this->is_protected()) return false;
+ function update($input) {
+ if ($this->is_protected()) return false;
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- if ($value == $input) return false;
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ if ($value == $input) return false;
- if (!init_path($input)) {
- $this->_error = true;
- $this->_input = $input;
- return false;
- }
+ if (!init_path($input)) {
+ $this->_error = true;
+ $this->_input = $input;
+ return false;
+ }
- $this->_local = $input;
- return true;
+ $this->_local = $input;
+ return true;
+ }
}
- }
}
if (!class_exists('setting_authtype')) {
- class setting_authtype extends setting_multichoice {
+ class setting_authtype extends setting_multichoice {
- function initialize($default,$local,$protected) {
- global $plugin_controller;
+ function initialize($default,$local,$protected) {
+ global $plugin_controller;
- // retrieve auth types provided by plugins
- foreach ($plugin_controller->getList('auth') as $plugin) {
- $this->_choices[] = $plugin;
- }
-
- parent::initialize($default,$local,$protected);
- }
-
- function update($input) {
- global $plugin_controller;
-
- // is an update possible/requested?
- $local = $this->_local; // save this, parent::update() may change it
- if (!parent::update($input)) return false; // nothing changed or an error caught by parent
- $this->_local = $local; // restore original, more error checking to come
-
- // attempt to load the plugin
- $auth_plugin = $plugin_controller->load('auth', $input);
-
- // @TODO: throw an error in plugin controller instead of returning null
- if (is_null($auth_plugin)) {
- $this->_error = true;
- msg('Cannot load Auth Plugin "' . $input . '"', -1);
- return false;
- }
+ // retrieve auth types provided by plugins
+ foreach ($plugin_controller->getList('auth') as $plugin) {
+ $this->_choices[] = $plugin;
+ }
- // verify proper instantiation (is this really a plugin?) @TODO use instanceof? implement interface?
- if (is_object($auth_plugin) && !method_exists($auth_plugin, 'getPluginName')) {
- $this->_error = true;
- msg('Cannot create Auth Plugin "' . $input . '"', -1);
- return false;
+ parent::initialize($default,$local,$protected);
}
- // did we change the auth type? logout
- global $conf;
- if($conf['authtype'] != $input) {
- msg('Authentication system changed. Please re-login.');
- auth_logoff();
+ function update($input) {
+ global $plugin_controller;
+
+ // is an update possible/requested?
+ $local = $this->_local; // save this, parent::update() may change it
+ if (!parent::update($input)) return false; // nothing changed or an error caught by parent
+ $this->_local = $local; // restore original, more error checking to come
+
+ // attempt to load the plugin
+ $auth_plugin = $plugin_controller->load('auth', $input);
+
+ // @TODO: throw an error in plugin controller instead of returning null
+ if (is_null($auth_plugin)) {
+ $this->_error = true;
+ msg('Cannot load Auth Plugin "' . $input . '"', -1);
+ return false;
+ }
+
+ // verify proper instantiation (is this really a plugin?) @TODO use instanceof? implement interface?
+ if (is_object($auth_plugin) && !method_exists($auth_plugin, 'getPluginName')) {
+ $this->_error = true;
+ msg('Cannot create Auth Plugin "' . $input . '"', -1);
+ return false;
+ }
+
+ // did we change the auth type? logout
+ global $conf;
+ if($conf['authtype'] != $input) {
+ msg('Authentication system changed. Please re-login.');
+ auth_logoff();
+ }
+
+ $this->_local = $input;
+ return true;
}
-
- $this->_local = $input;
- return true;
}
- }
}
if (!class_exists('setting_im_convert')) {
- class setting_im_convert extends setting_string {
+ class setting_im_convert extends setting_string {
- function update($input) {
- if ($this->is_protected()) return false;
+ function update($input) {
+ if ($this->is_protected()) return false;
- $input = trim($input);
+ $input = trim($input);
- $value = is_null($this->_local) ? $this->_default : $this->_local;
- if ($value == $input) return false;
+ $value = is_null($this->_local) ? $this->_default : $this->_local;
+ if ($value == $input) return false;
- if ($input && !@file_exists($input)) {
- $this->_error = true;
- $this->_input = $input;
- return false;
- }
+ if ($input && !@file_exists($input)) {
+ $this->_error = true;
+ $this->_input = $input;
+ return false;
+ }
- $this->_local = $input;
- return true;
+ $this->_local = $input;
+ return true;
+ }
}
- }
}
if (!class_exists('setting_disableactions')) {
- class setting_disableactions extends setting_multicheckbox {
+ class setting_disableactions extends setting_multicheckbox {
- function html(&$plugin, $echo=false) {
- global $lang;
+ function html(&$plugin, $echo=false) {
+ global $lang;
- // make some language adjustments (there must be a better way)
- // transfer some DokuWiki language strings to the plugin
- if (!$plugin->localised) $this->setupLocale();
- $plugin->lang[$this->_key.'_revisions'] = $lang['btn_revs'];
+ // make some language adjustments (there must be a better way)
+ // transfer some DokuWiki language strings to the plugin
+ if (!$plugin->localised) $this->setupLocale();
+ $plugin->lang[$this->_key.'_revisions'] = $lang['btn_revs'];
- foreach ($this->_choices as $choice)
- if (isset($lang['btn_'.$choice])) $plugin->lang[$this->_key.'_'.$choice] = $lang['btn_'.$choice];
+ foreach ($this->_choices as $choice)
+ if (isset($lang['btn_'.$choice])) $plugin->lang[$this->_key.'_'.$choice] = $lang['btn_'.$choice];
- return parent::html($plugin, $echo);
+ return parent::html($plugin, $echo);
+ }
}
- }
}
if (!class_exists('setting_compression')) {
- class setting_compression extends setting_multichoice {
+ class setting_compression extends setting_multichoice {
- var $_choices = array('0'); // 0 = no compression, always supported
+ var $_choices = array('0'); // 0 = no compression, always supported
- function initialize($default,$local,$protected) {
+ function initialize($default,$local,$protected) {
- // populate _choices with the compression methods supported by this php installation
- if (function_exists('gzopen')) $this->_choices[] = 'gz';
- if (function_exists('bzopen')) $this->_choices[] = 'bz2';
+ // populate _choices with the compression methods supported by this php installation
+ if (function_exists('gzopen')) $this->_choices[] = 'gz';
+ if (function_exists('bzopen')) $this->_choices[] = 'bz2';
- parent::initialize($default,$local,$protected);
+ parent::initialize($default,$local,$protected);
+ }
}
- }
}
if (!class_exists('setting_license')) {
- class setting_license extends setting_multichoice {
+ class setting_license extends setting_multichoice {
- var $_choices = array(''); // none choosen
+ var $_choices = array(''); // none choosen
- function initialize($default,$local,$protected) {
- global $license;
+ function initialize($default,$local,$protected) {
+ global $license;
- foreach($license as $key => $data){
- $this->_choices[] = $key;
- $this->lang[$this->_key.'_o_'.$key] = $data['name'];
- }
+ foreach($license as $key => $data){
+ $this->_choices[] = $key;
+ $this->lang[$this->_key.'_o_'.$key] = $data['name'];
+ }
- parent::initialize($default,$local,$protected);
+ parent::initialize($default,$local,$protected);
+ }
}
- }
}
if (!class_exists('setting_renderer')) {
- class setting_renderer extends setting_multichoice {
- var $_prompts = array();
+ class setting_renderer extends setting_multichoice {
+ var $_prompts = array();
- function initialize($default,$local,$protected) {
- $format = $this->_format;
+ function initialize($default,$local,$protected) {
+ $format = $this->_format;
- foreach (plugin_list('renderer') as $plugin) {
- $renderer =& plugin_load('renderer',$plugin);
- if (method_exists($renderer,'canRender') && $renderer->canRender($format)) {
- $this->_choices[] = $plugin;
+ foreach (plugin_list('renderer') as $plugin) {
+ $renderer =& plugin_load('renderer',$plugin);
+ if (method_exists($renderer,'canRender') && $renderer->canRender($format)) {
+ $this->_choices[] = $plugin;
- $info = $renderer->getInfo();
- $this->_prompts[$plugin] = $info['name'];
- }
- }
-
- parent::initialize($default,$local,$protected);
- }
+ $info = $renderer->getInfo();
+ $this->_prompts[$plugin] = $info['name'];
+ }
+ }
- function html(&$plugin, $echo=false) {
-
- // make some language adjustments (there must be a better way)
- // transfer some plugin names to the config plugin
- if (!$plugin->localised) $this->setupLocale();
+ parent::initialize($default,$local,$protected);
+ }
- foreach ($this->_choices as $choice) {
- if (!isset($plugin->lang[$this->_key.'_o_'.$choice])) {
- if (!isset($this->_prompts[$choice])) {
- $plugin->lang[$this->_key.'_o_'.$choice] = sprintf($plugin->lang['renderer__core'],$choice);
- } else {
- $plugin->lang[$this->_key.'_o_'.$choice] = sprintf($plugin->lang['renderer__plugin'],$this->_prompts[$choice]);
- }
+ function html(&$plugin, $echo=false) {
+
+ // make some language adjustments (there must be a better way)
+ // transfer some plugin names to the config plugin
+ if (!$plugin->localised) $this->setupLocale();
+
+ foreach ($this->_choices as $choice) {
+ if (!isset($plugin->lang[$this->_key.'_o_'.$choice])) {
+ if (!isset($this->_prompts[$choice])) {
+ $plugin->lang[$this->_key.'_o_'.$choice] = sprintf($plugin->lang['renderer__core'],$choice);
+ } else {
+ $plugin->lang[$this->_key.'_o_'.$choice] = sprintf($plugin->lang['renderer__plugin'],$this->_prompts[$choice]);
+ }
+ }
+ }
+ return parent::html($plugin, $echo);
}
- }
- return parent::html($plugin, $echo);
}
- }
}