diff options
author | Christopher Smith <chris@jalakai.co.uk> | 2013-02-18 15:51:06 +0000 |
---|---|---|
committer | Christopher Smith <chris@jalakai.co.uk> | 2013-02-18 15:51:06 +0000 |
commit | d110fb0d68e5a037b6db151d7bfd4881c48ccdec (patch) | |
tree | 0228f52d4996e964c907b0a4c8cb3dd13fd9826c /lib/plugins/config/settings | |
parent | 8bb7fe5546a24e8bcba3b258406f02205a8825f8 (diff) | |
download | rpg-d110fb0d68e5a037b6db151d7bfd4881c48ccdec.tar.gz rpg-d110fb0d68e5a037b6db151d7bfd4881c48ccdec.tar.bz2 |
FS#2722 add settings_regex class, use it for hidepages
Diffstat (limited to 'lib/plugins/config/settings')
-rw-r--r-- | lib/plugins/config/settings/config.class.php | 37 | ||||
-rw-r--r-- | lib/plugins/config/settings/config.metadata.php | 8 |
2 files changed, 44 insertions, 1 deletions
diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index ec5f73fa5..bbb25b695 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -1081,3 +1081,40 @@ if (!class_exists('setting_multicheckbox')) { } } } + +if (!class_exists('setting_regex')){ + 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 + + /**
+ * 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) { + + // let parent do basic checks, value, not changed, etc. + $local = $this->_local; + if (!parent::update($input)) return false; + $this->_local = $local; + + // see if the regex compiles and runs (we don't check for effectiveness) + $regex = $this->_delimiter . $input . $this->_delimiter . $this->_pregflags; + $lastError = error_get_last(); + $ok = @preg_match($regex,'testdata'); + if (preg_last_error() != PREG_NO_ERROR || error_get_last() != $lastError) { + $this->_input = $input; + $this->_error = true; + return false; + } +
+ $this->_local = $input;
+ return true;
+ } + } +}
\ No newline at end of file diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php index 4731ffc16..5aedaa6f1 100644 --- a/lib/plugins/config/settings/config.metadata.php +++ b/lib/plugins/config/settings/config.metadata.php @@ -33,6 +33,9 @@ * 'array' - a simple (one dimensional) array of string values, shown as comma separated list in the * config manager but saved as PHP array(). Values may not contain commas themselves. * _pattern matching on the array values supported. + * 'regex' - regular expression string, normally without delimiters; as for string, in addition tested + * to see if will compile & run as a regex. in addition to _pattern, also accepts _delimiter + * (default '/') and _pregflags (default 'ui') * * Single Setting (source: settings/extra.class.php) * ------------------------------------------------- @@ -60,6 +63,9 @@ * '_code' - encoding method to use, accepted values: 'base64','uuencode','plain'. defaults to plain. * '_min' - minimum numeric value, optional for 'numeric' and 'numericopt', ignored by others * '_max' - maximum numeric value, optional for 'numeric' and 'numericopt', ignored by others + * '_delimiter' - string, default '/', a single character used as a delimiter for testing regex input values + * '_pregflags' - string, default 'ui', valid preg pattern modifiers used when testing regex input values, for more + * information see http://uk1.php.net/manual/en/reference.pcre.pattern.modifiers.php * * @author Chris Smith <chris@jalakai.co.uk> */ @@ -115,7 +121,7 @@ $meta['camelcase'] = array('onoff'); $meta['deaccent'] = array('multichoice','_choices' => array(0,1,2)); $meta['useheading'] = array('multichoice','_choices' => array(0,'navigation','content',1)); $meta['sneaky_index'] = array('onoff'); -$meta['hidepages'] = array('string'); +$meta['hidepages'] = array('regex'); $meta['_authentication'] = array('fieldset'); $meta['useacl'] = array('onoff'); |