mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[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
This commit is contained in:
parent
204cdb2164
commit
1715619fda
3 changed files with 25 additions and 3 deletions
|
@ -423,7 +423,7 @@ class acp_groups
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate submitted colour value
|
// 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
|
// Replace "error" string with its real, localised form
|
||||||
$error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error));
|
$error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error));
|
||||||
|
|
|
@ -1247,8 +1247,9 @@ function validate_data($data, $val_ary)
|
||||||
{
|
{
|
||||||
$function = array_shift($validate);
|
$function = array_shift($validate);
|
||||||
array_unshift($validate, $data[$var]);
|
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.
|
// 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);
|
$error[] = (empty($user->lang[$result . '_' . strtoupper($var)])) ? $result : $result . '_' . strtoupper($var);
|
||||||
|
@ -1898,6 +1899,27 @@ function validate_jabber($jid)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Verifies whether a style ID corresponds to an active style.
|
||||||
*
|
*
|
||||||
|
|
|
@ -596,7 +596,7 @@ class ucp_groups
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate submitted colour value
|
// 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
|
// Replace "error" string with its real, localised form
|
||||||
$error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error));
|
$error = array_merge($error, array_map(array(&$user, 'lang'), $colour_error));
|
||||||
|
|
Loading…
Add table
Reference in a new issue