diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-05-16 13:22:43 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-05-16 13:22:43 +0200 |
commit | 1715619fda2aebd7ebae960e5fcbdf4b24ce4dca (patch) | |
tree | e4fc7fa0e0c6c34fc1c009ca2bb6340a59b9ae4c | |
parent | 204cdb21640aead9f7560034bb8e686c17707476 (diff) | |
download | forums-1715619fda2aebd7ebae960e5fcbdf4b24ce4dca.tar forums-1715619fda2aebd7ebae960e5fcbdf4b24ce4dca.tar.gz forums-1715619fda2aebd7ebae960e5fcbdf4b24ce4dca.tar.bz2 forums-1715619fda2aebd7ebae960e5fcbdf4b24ce4dca.tar.xz forums-1715619fda2aebd7ebae960e5fcbdf4b24ce4dca.zip |
[ticket/11538] Add function phpbb_validate_colour for validating colours
It will be possible to use this function via the validate_data() function
interface that has already been used previously. Thus, this new function
will extend the capabilities of validate_data() to checking hex color
values.
PHPBB3-11538
-rw-r--r-- | phpBB/includes/acp/acp_groups.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_user.php | 24 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_groups.php | 2 |
3 files changed, 25 insertions, 3 deletions
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index ffbce33667..9a9a723605 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -423,7 +423,7 @@ class acp_groups } // Validate submitted colour value - if ($colour_error = validate_data($submit_ary, array('colour' => array('match', true, '/^([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/')))) + if ($colour_error = validate_data($submit_ary, array('colour' => array('colour')))) { // Replace "error" string with its real, localised form $error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error)); diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 5a6a0b4a05..b7fdb7a6ad 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,27 @@ function validate_jabber($jid) } /** +* Validate hex colour value +* +* @param string $colour The hex colour value +* @return bool/string Error message if colour value is incorrect, false if it fits the hex colour code +*/ +function phpbb_validate_colour($colour) +{ + if (empty($colour)) + { + return false; + } + + 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 58c8d1ae4a..9d2cf2728d 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -596,7 +596,7 @@ class ucp_groups } // Validate submitted colour value - if ($colour_error = validate_data($submit_ary, array('colour' => array('match', true, '/^([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/')))) + if ($colour_error = validate_data($submit_ary, array('colour' => array('colour')))) { // Replace "error" string with its real, localised form $error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error)); |