diff options
author | Andreas Fischer <bantu@phpbb.com> | 2013-05-26 18:24:29 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2013-05-26 18:24:29 +0200 |
commit | 2b356e766f8d0f3e9dfc2d1fdd6bc857fdb63497 (patch) | |
tree | b8b1bb07ef8cd5e070099445ef497ab92d321747 /phpBB | |
parent | 4a935608708c28f2996c732517d877bb0cd80738 (diff) | |
parent | cd1da92d8540d6b4aa0fa1ccf2bcafe68007288a (diff) | |
download | forums-2b356e766f8d0f3e9dfc2d1fdd6bc857fdb63497.tar forums-2b356e766f8d0f3e9dfc2d1fdd6bc857fdb63497.tar.gz forums-2b356e766f8d0f3e9dfc2d1fdd6bc857fdb63497.tar.bz2 forums-2b356e766f8d0f3e9dfc2d1fdd6bc857fdb63497.tar.xz forums-2b356e766f8d0f3e9dfc2d1fdd6bc857fdb63497.zip |
Merge remote-tracking branch 'marc1706/ticket/11538' into develop-olympus
* marc1706/ticket/11538:
[ticket/11538] Add optional switch as argument to hex colour validation
[ticket/11538] Modify test colour values
[ticket/11538] Limit comment in acp_groups to 80 characters per line
[ticket/11538] Move group ID into abstract test class and add more test cases
[ticket/11538] Merge calls to validate_data() in acp_groups
[ticket/11538] Rename phpbb_validate_colour to phpbb_validate_hex_colour
[ticket/11538] Use abstract class for functional test cases for group colour
[ticket/11538] Add function phpbb_validate_colour for validating colours
[ticket/11538] Make sure regex doesn't allow multiple color values
[ticket/11538] Add tests for acp group manage page
[ticket/11538] Simplify colour value check and remove support for '#'
[ticket/11538] Fix incorrect regex and test for duplicate # in color string
[ticket/11538] Use regex for testing color value and improve tests
[ticket/11538] Make sure group color can't exceed maximum of 6 characters
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/acp/acp_groups.php | 18 | ||||
-rw-r--r-- | phpBB/includes/functions_user.php | 27 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_groups.php | 7 | ||||
-rw-r--r-- | phpBB/language/en/common.php | 1 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/ucp_groups_manage.html | 2 |
5 files changed, 48 insertions, 7 deletions
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index beb7aefee5..83c355540e 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -413,13 +413,21 @@ class acp_groups } } - // Validate the length of "Maximum number of allowed recipients per private message" setting. - // We use 16777215 as a maximum because it matches MySQL unsigned mediumint maximum value - // which is the lowest amongst DBMSes supported by phpBB3 - if ($max_recipients_error = validate_data($submit_ary, array('max_recipients' => array('num', false, 0, 16777215)))) + /* + * Validate the length of "Maximum number of allowed recipients per + * private message" setting. We use 16777215 as a maximum because it matches + * MySQL unsigned mediumint maximum value which is the lowest amongst DBMSes + * supported by phpBB3. Also validate the submitted colour value. + */ + $validation_checks = array( + 'max_recipients' => array('num', false, 0, 16777215), + 'colour' => array('hex_colour', true), + ); + + if ($validation_error = validate_data($submit_ary, $validation_checks)) { // Replace "error" string with its real, localised form - $error = array_merge($error, array_map(array(&$user, 'lang'), $max_recipients_error)); + $error = array_merge($error, array_map(array(&$user, 'lang'), $validation_error)); } if (!sizeof($error)) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 5a6a0b4a05..61972c3876 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1247,8 +1247,9 @@ function validate_data($data, $val_ary) { $function = array_shift($validate); array_unshift($validate, $data[$var]); + $function_prefix = (function_exists('phpbb_validate_' . $function)) ? 'phpbb_validate_' : 'validate'; - if ($result = call_user_func_array('validate_' . $function, $validate)) + if ($result = call_user_func_array($function_prefix . $function, $validate)) { // Since errors are checked later for their language file existence, we need to make sure custom errors are not adjusted. $error[] = (empty($user->lang[$result . '_' . strtoupper($var)])) ? $result : $result . '_' . strtoupper($var); @@ -1899,6 +1900,30 @@ function validate_jabber($jid) } /** +* Validate hex colour value +* +* @param string $colour The hex colour value +* @param bool $optional Whether the colour value is optional. True if an empty +* string will be accepted as correct input, false if not. +* @return bool|string Error message if colour value is incorrect, false if it +* fits the hex colour code +*/ +function phpbb_validate_hex_colour($colour, $optional = false) +{ + if (empty($colour)) + { + return (($optional) ? false : 'WRONG_DATA'); + } + + if (!preg_match('/^([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/', $colour)) + { + return 'WRONG_DATA'; + } + + return false; +} + +/** * Verifies whether a style ID corresponds to an active style. * * @param int $style_id The style_id of a style which should be checked if activated or not. diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index d62dbb1866..9365913541 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -595,6 +595,13 @@ class ucp_groups $error[] = $user->lang['FORM_INVALID']; } + // Validate submitted colour value + if ($colour_error = validate_data($submit_ary, array('colour' => array('hex_colour', true)))) + { + // Replace "error" string with its real, localised form + $error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error)); + } + if (!sizeof($error)) { // Only set the rank, colour, etc. if it's changed or if we're adding a new diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index baf398b146..c986e8213d 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -722,6 +722,7 @@ $lang = array_merge($lang, array( 'WHO_IS_ONLINE' => 'Who is online', 'WRONG_PASSWORD' => 'You entered an incorrect password.', + 'WRONG_DATA_COLOUR' => 'The colour value you entered is invalid.', 'WRONG_DATA_ICQ' => 'The number you entered is not a valid ICQ number.', 'WRONG_DATA_JABBER' => 'The name you entered is not a valid Jabber account name.', 'WRONG_DATA_LANG' => 'The language you specified is not valid.', diff --git a/phpBB/styles/prosilver/template/ucp_groups_manage.html b/phpBB/styles/prosilver/template/ucp_groups_manage.html index a58829f99f..c90461312e 100644 --- a/phpBB/styles/prosilver/template/ucp_groups_manage.html +++ b/phpBB/styles/prosilver/template/ucp_groups_manage.html @@ -54,7 +54,7 @@ <fieldset> <dl> <dt><label for="group_colour">{L_GROUP_COLOR}:</label><br /><span>{L_GROUP_COLOR_EXPLAIN}</span></dt> - <dd><input name="group_colour" type="text" id="group_colour" value="{GROUP_COLOUR}" size="7" maxlength="7" class="inputbox narrow" /> <span style="background-color: {GROUP_COLOUR};"> </span> [ <a href="{U_SWATCH}" onclick="popup(this.href, 636, 150, '_swatch'); return false;">{L_COLOUR_SWATCH}</a> ]</dd> + <dd><input name="group_colour" type="text" id="group_colour" value="{GROUP_COLOUR}" size="6" maxlength="6" class="inputbox narrow" /> <span style="background-color: {GROUP_COLOUR};"> </span> [ <a href="{U_SWATCH}" onclick="popup(this.href, 636, 150, '_swatch'); return false;">{L_COLOUR_SWATCH}</a> ]</dd> </dl> <dl> <dt><label for="group_rank">{L_GROUP_RANK}:</label></dt> |