FS#2722 add settings_regex class, use it for hidepages
This commit is contained in:
parent
8bb7fe5546
commit
d110fb0d68
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue