diff options
-rw-r--r-- | lib/plugins/config/settings/config.class.php | 18 | ||||
-rw-r--r-- | lib/plugins/config/settings/config.metadata.php | 3 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index 4f2129c70..252bc79a9 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -618,6 +618,24 @@ if (!class_exists('setting_numeric')) { // much more restrictive, but should eliminate syntax errors. var $_pattern = '/^[-]?[0-9]+(?:[-+*][0-9]+)*$/'; //FIXME - make the numeric error checking better. + 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; + } function out($var, $fmt='php') { diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php index edba65262..127017624 100644 --- a/lib/plugins/config/settings/config.metadata.php +++ b/lib/plugins/config/settings/config.metadata.php @@ -16,6 +16,7 @@ * '' - default class ('setting'), textarea, minimal input validation, setting output in quotes * 'string' - single line text input, minimal input validation, setting output in quotes * 'numeric' - text input, accepts numbers and arithmetic operators, setting output without quotes + * if given the '_min' and '_max' parameters are used for validation * 'numericopt' - like above, but accepts empty values * 'onoff' - checkbox input, setting output 0|1 * 'multichoice' - select input (single choice), setting output with quotes, required _choices parameter @@ -54,6 +55,8 @@ * '_combine' - complimentary output setting values which can be combined into a single display checkbox * optional for 'multicheckbox', ignored by other classes * '_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 * * @author Chris Smith <chris@jalakai.co.uk> */ |