forked from phpbb/phpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype_string_common.php
More file actions
143 lines (127 loc) · 4.17 KB
/
type_string_common.php
File metadata and controls
143 lines (127 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?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\profilefields\type;
abstract class type_string_common extends type_base
{
protected $validation_options = array(
'CHARS_ANY' => '.*',
'NUMBERS_ONLY' => '[0-9]+',
'ALPHA_ONLY' => '[a-zA-Z0-9]+',
'ALPHA_UNDERSCORE' => '[\w]+',
'ALPHA_DOTS' => '[a-zA-Z0-9.]+',
'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.,\-_]+',
);
/**
* Return possible validation options
*/
public function validate_options($field_data)
{
$validate_options = '';
foreach ($this->validation_options as $lang => $value)
{
$selected = ($field_data['field_validation'] == $value) ? ' selected="selected"' : '';
$validate_options .= '<option value="' . $value . '"' . $selected . '>' . $this->user->lang[$lang] . '</option>';
}
return $validate_options;
}
/**
* {@inheritDoc}
*/
public function get_default_field_value($field_data)
{
return $field_data['lang_default_value'];
}
/**
* Validate entered profile field data
*
* @param string $field_type Field type (string or text)
* @param mixed $field_value Field value to validate
* @param array $field_data Array with requirements of the field
* @return mixed String with key of the error language string, false otherwise
*/
public function validate_string_profile_field($field_type, &$field_value, $field_data)
{
if (trim($field_value ?? '') === '')
{
return $field_data['field_required'] ? $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name'])) : false;
}
if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen'])
{
return $this->user->lang('FIELD_TOO_SHORT', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name']));
}
else if ($field_data['field_maxlen'] && utf8_strlen(html_entity_decode($field_value)) > $field_data['field_maxlen'])
{
return $this->user->lang('FIELD_TOO_LONG', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name']));
}
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']) . '$#iu', $field_validate))
{
$validation = array_search($field_data['field_validation'], $this->validation_options);
if ($validation)
{
return $this->user->lang('FIELD_INVALID_CHARS_' . $validation, $this->get_field_name($field_data['lang_name']));
}
return $this->user->lang('FIELD_INVALID_CHARS_INVALID', $this->get_field_name($field_data['lang_name']));
}
}
return false;
}
/**
* {@inheritDoc}
*/
public function get_profile_value($field_value, $field_data)
{
if (($field_value === null || $field_value === '') && !$field_data['field_show_novalue'])
{
return null;
}
$field_value = make_clickable($field_value);
$field_value = censor_text($field_value);
$field_value = bbcode_nl2br($field_value);
return $field_value;
}
/**
* {@inheritDoc}
*/
public function get_profile_value_raw($field_value, $field_data)
{
if (($field_value === null || $field_value === '') && !$field_data['field_show_novalue'])
{
return null;
}
return $field_value;
}
/**
* {@inheritDoc}
*/
public function get_profile_contact_value($field_value, $field_data)
{
return $this->get_profile_value_raw($field_value, $field_data);
}
/**
* {@inheritDoc}
*/
public function prepare_options_form(&$exclude_options, &$visibility_options)
{
$exclude_options[1][] = 'lang_default_value';
return $this->request->variable('lang_options', '', true);
}
}