1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-06 15:45:34 +02:00

[ticket/13055] Add string profile fields validation options to support unicode

PHPBB3-13055
This commit is contained in:
rxu 2014-09-13 12:35:44 +08:00
parent c1d0528d80
commit dc65058c20
4 changed files with 108 additions and 2 deletions

View File

@ -119,6 +119,12 @@ $lang = array_merge($lang, array(
'LANG_SPECIFIC_OPTIONS' => 'Language specific options [<strong>%s</strong>]',
'LETTER_NUM_DOTS' => 'Any letters, numbers and dots (periods)',
'LETTER_NUM_ONLY' => 'Any letters and numbers',
'LETTER_NUM_PUNCTUATION' => 'Any letters, numbers, comma, dots, underscores and dashes beginning with any letter',
'LETTER_NUM_SPACERS' => 'Any letters, numbers and spacers',
'LETTER_NUM_UNDERSCORE' => 'Any letters, numbers and underscores',
'MAX_FIELD_CHARS' => 'Maximum number of characters',
'MAX_FIELD_NUMBER' => 'Highest allowed number',
'MIN_FIELD_CHARS' => 'Minimum number of characters',

View File

@ -214,6 +214,11 @@ $lang = array_merge($lang, array(
'FIELD_INVALID_CHARS_ALPHA_PUNCTUATION' => 'The field “%s” has invalid characters, only alphanumeric or _,-. characters are allowed and the first character must be alphabetic.',
'FIELD_INVALID_CHARS_ALPHA_SPACERS' => 'The field “%s” has invalid characters, only alphanumeric, space or -+_[] characters are allowed.',
'FIELD_INVALID_CHARS_ALPHA_UNDERSCORE' => 'The field “%s” has invalid characters, only alphanumeric or _ characters are allowed.',
'FIELD_INVALID_CHARS_LETTER_NUM_DOTS' => 'The field “%s” has invalid characters, only letter, number or . characters are allowed.',
'FIELD_INVALID_CHARS_LETTER_NUM_ONLY' => 'The field “%s” has invalid characters, only letter and number characters are allowed.',
'FIELD_INVALID_CHARS_LETTER_NUM_PUNCTUATION' => 'The field “%s” has invalid characters, only letter, number or _,-. characters are allowed and the first character must be alphabetic.',
'FIELD_INVALID_CHARS_LETTER_NUM_SPACERS' => 'The field “%s” has invalid characters, only letter, number, space or -+_[] characters are allowed.',
'FIELD_INVALID_CHARS_LETTER_NUM_UNDERSCORE' => 'The field “%s” has invalid characters, only letter, number or _ characters are allowed.',
'FIELD_INVALID_DATE' => 'The field “%s” has an invalid date.',
'FIELD_INVALID_URL' => 'The field “%s” has an invalid url.',
'FIELD_INVALID_VALUE' => 'The field “%s” has an invalid value.',

View File

@ -0,0 +1,90 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\db\migration\data\v310;
class profilefield_field_validation_length extends \phpbb\db\migration\migration
{
protected $validation_options_old = array(
'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+',
);
protected $validation_options_new = array(
'ALPHA_SPACERS' => '[\w\x20_+\-\[\]]+',
);
static public function depends_on()
{
return array(
'\phpbb\db\migration\data\v310\rc3',
);
}
public function update_schema()
{
return array(
'change_columns' => array(
$this->table_prefix . 'profile_fields' => array(
'field_validation' => array('VCHAR_UNI:64', ''),
),
),
);
}
public function revert_schema()
{
return array(
'change_columns' => array(
$this->table_prefix . 'profile_fields' => array(
'field_validation' => array('VCHAR_UNI:20', ''),
),
),
);
}
public function update_data()
{
return array(
array('custom', array(array($this, 'update_profile_fields_validation'))),
);
}
public function revert_data()
{
return array(
array('custom', array(array($this, 'revert_profile_fields_validation'))),
);
}
public function update_profile_fields_validation()
{
foreach ($this->validation_options_new as $validation_type => $regex)
{
$sql = 'UPDATE ' . $this->table_prefix . "profile_fields
SET field_validation = '" . $this->db->sql_escape($this->validation_options_new[$validation_type]) . "'
WHERE field_validation = '" . $this->db->sql_escape($this->validation_options_old[$validation_type]) . "'";
$this->sql_query($sql);
}
}
public function revert_profile_fields_validation()
{
foreach ($this->validation_options_new as $validation_type => $regex)
{
$sql = 'UPDATE ' . $this->table_prefix . "profile_fields
SET field_validation = '" . $this->db->sql_escape($this->validation_options_old[$validation_type]) . "'
WHERE field_validation = '" . $this->db->sql_escape($this->validation_options_new[$validation_type]) . "'";
$this->sql_query($sql);
}
}
}

View File

@ -21,8 +21,13 @@ abstract class type_string_common extends type_base
'ALPHA_ONLY' => '[\w]+',
'ALPHA_UNDERSCORE' => '[\w_]+',
'ALPHA_DOTS' => '[\w.]+',
'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+',
'ALPHA_SPACERS' => '[\w\x20_+\-\[\]]+',
'ALPHA_PUNCTUATION' => '[a-zA-Z][\w\.,\-_]+',
'LETTER_NUM_ONLY' => '[\p{Lu}\p{Ll}0-9]+',
'LETTER_NUM_UNDERSCORE' => '[\p{Lu}\p{Ll}0-9_]+',
'LETTER_NUM_DOTS' => '[\p{Lu}\p{Ll}0-9.]+',
'LETTER_NUM_SPACERS' => '[\p{Lu}\p{Ll}0-9\x20_+\-\[\]]+',
'LETTER_NUM_PUNCTUATION' => '[\p{Lu}\p{Ll}][\p{Lu}\p{Ll}0-9.,\-_]+',
);
/**
@ -79,7 +84,7 @@ abstract class type_string_common extends type_base
if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
{
$field_validate = ($field_type != 'text') ? $field_value : bbcode_nl2br($field_value);
if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate))
if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#iu', $field_validate))
{
$validation = array_search($field_data['field_validation'], $this->validation_options);
if ($validation)