diff options
author | Henry Sudhof <kellanved@phpbb.com> | 2008-02-27 15:09:04 +0000 |
---|---|---|
committer | Henry Sudhof <kellanved@phpbb.com> | 2008-02-27 15:09:04 +0000 |
commit | 30f32e8bb7e3f1c36d4931c3a9fc263f00aa1f4d (patch) | |
tree | d758e1d47e14db5dadd7ef6d04df4be5809a1558 /phpBB | |
parent | eaf97f2a672af99f9704171ecedc5676cf3dad7b (diff) | |
download | forums-30f32e8bb7e3f1c36d4931c3a9fc263f00aa1f4d.tar forums-30f32e8bb7e3f1c36d4931c3a9fc263f00aa1f4d.tar.gz forums-30f32e8bb7e3f1c36d4931c3a9fc263f00aa1f4d.tar.bz2 forums-30f32e8bb7e3f1c36d4931c3a9fc263f00aa1f4d.tar.xz forums-30f32e8bb7e3f1c36d4931c3a9fc263f00aa1f4d.zip |
Adding new validation options for ACP values
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8406 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/adm/index.php | 100 | ||||
-rw-r--r-- | phpBB/language/en/acp/common.php | 5 |
2 files changed, 99 insertions, 6 deletions
diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index 0932e01aa1..c577cefacd 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -367,33 +367,61 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) } /** -* Going through a config array and validate values, writing errors to $error. +* Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int. +* The first parameter defines the type to be used, the second the lower bound and the third the upper bound. Only the type is required. */ function validate_config_vars($config_vars, &$cfg_array, &$error) { global $phpbb_root_path, $user; - + $type = 0; + $min = 1; + $max = 2; + foreach ($config_vars as $config_name => $config_definition) { if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) { continue; } - + if (!isset($config_definition['validate'])) { continue; } - - // Validate a bit. ;) String is already checked through request_var(), therefore we do not check this again - switch ($config_definition['validate']) + + $validator = explode(':', $config_definition['validate']); + // Validate a bit. ;) (0 = type, 1 = min, 2= max) + switch ($validator[$type]) { + case 'string': + $length = strlen($cfg_array[$config_name]); + // the column is a VARCHAR + $validator[$max] = (isset($validator[$max])) ? min(255, $validator[$max]) : 255; + if (isset($validator[$min]) && $length < $validator[$min]) + { + $error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]); + } + else if (isset($validator[$max]) && $length > $validator[2]) + { + $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]); + } + break; + case 'bool': $cfg_array[$config_name] = ($cfg_array[$config_name]) ? 1 : 0; break; case 'int': $cfg_array[$config_name] = (int) $cfg_array[$config_name]; + + if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min]) + { + $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]); + } + else if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max]) + { + $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]); + } break; // Absolute path @@ -508,4 +536,64 @@ function validate_config_vars($config_vars, &$cfg_array, &$error) return; } +/** +* Checks whatever or not a variable is OK for use in the Database +* param mixed $value_ary An array of the form array(array('lang' => ..., 'value' => ..., 'column_type' =>))' +* param mixed $error The error array +*/ +function validate_range($value_ary, &$error) +{ + global $user; + + $column_types = array( + 'BOOL' => array('php_type' => 'int', 'min' => 0, 'max' => 1), + 'USINT' => array('php_type' => 'int', 'min' => 0, 'max' => 65535), + 'UINT' => array('php_type' => 'int', 'min' => 0, 'max' => (int) 0x7fffffff), + 'INT' => array('php_type' => 'int', 'min' => (int) 0x80000000, 'max' => (int) 0x7fffffff), + 'TINT' => array('php_type' => 'int', 'min' => -128, 'max' => 127), + + 'VCHAR' => array('php_type' => 'string', 'min' => 0, 'max' => 255), + ); + foreach ($value_ary as $value) + { + $column = explode(':', $value['column_type']); + $max = $min = 0; + $type = 0; + if (!isset($column_types[$column[0]])) + { + continue; + } + else + { + $type = $column_types[$column[0]]; + } + + switch ($type['php_type']) + { + case 'string' : + $max = (isset($column[1])) ? min($column[1],$type['max']) : $type['max']; + if (strlen($value['value']) > $max) + { + $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$value['lang']], $max); + } + + break; + + case 'int': + $min = (isset($column[1])) ? max($column[1],$type['min']) : $type['min']; + $max = (isset($column[2])) ? min($column[2],$type['max']) : $type['max']; + if ($value['value'] < $min) + { + $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$value['lang']], $min); + } + else if ($value['value'] > $max) + { + $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$value['lang']], $max); + } + break; + } + } + +} + ?>
\ No newline at end of file diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 0c6014bc24..c3f884bc8e 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -262,6 +262,11 @@ $lang = array_merge($lang, array( 'SELECT_ANONYMOUS' => 'Select anonymous user', 'SELECT_OPTION' => 'Select option', + 'SETTING_TOO_LOW' => 'The entered value for the setting %s is too low. The minimal allowed value is %d.', + 'SETTING_TOO_BIG' => 'The entered value for the setting %s is too big. The maximal allowed value is %d.', + 'SETTING_TOO_LONG' => 'The entered value for the setting %s is too long. The maximal allowed length is %d.', + 'SETTING_TOO_SHORT' => 'The entered value for the setting %s is not long enough. The minimal allowed length is %d.', + 'UCP' => 'User Control Panel', 'USERNAMES_EXPLAIN' => 'Place each username on a separate line.', 'USER_CONTROL_PANEL' => 'User Control Panel', |