summaryrefslogtreecommitdiff
path: root/lib/plugins/config/settings/config.class.php
diff options
context:
space:
mode:
authorChristopher Smith <chris@jalakai.co.uk>2013-02-18 15:51:06 +0000
committerChristopher Smith <chris@jalakai.co.uk>2013-02-18 15:51:06 +0000
commitd110fb0d68e5a037b6db151d7bfd4881c48ccdec (patch)
tree0228f52d4996e964c907b0a4c8cb3dd13fd9826c /lib/plugins/config/settings/config.class.php
parent8bb7fe5546a24e8bcba3b258406f02205a8825f8 (diff)
downloadrpg-d110fb0d68e5a037b6db151d7bfd4881c48ccdec.tar.gz
rpg-d110fb0d68e5a037b6db151d7bfd4881c48ccdec.tar.bz2
FS#2722 add settings_regex class, use it for hidepages
Diffstat (limited to 'lib/plugins/config/settings/config.class.php')
-rw-r--r--lib/plugins/config/settings/config.class.php37
1 files changed, 37 insertions, 0 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