forked from phpbb/phpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype_text.php
More file actions
201 lines (176 loc) · 5.51 KB
/
Copy pathtype_text.php
File metadata and controls
201 lines (176 loc) · 5.51 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
*
* @package phpBB
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\profilefields\type;
class type_text extends type_string_common
{
/**
* Request object
* @var \phpbb\request\request
*/
protected $request;
/**
* Template object
* @var \phpbb\template\template
*/
protected $template;
/**
* User object
* @var \phpbb\user
*/
protected $user;
/**
* Construct
*
* @param \phpbb\request\request $request Request object
* @param \phpbb\template\template $template Template object
* @param \phpbb\user $user User object
* @param string $language_table Table where the language strings are stored
*/
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
{
$this->request = $request;
$this->template = $template;
$this->user = $user;
}
/**
* {@inheritDoc}
*/
public function get_name_short()
{
return 'text';
}
/**
* {@inheritDoc}
*/
public function get_options($default_lang_id, $field_data)
{
$options = array(
0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="number" min="0" max="99999" name="rows" size="5" value="' . $field_data['rows'] . '" /> ' . $this->user->lang['ROWS'] . '</dd><dd><input type="number" min="0" max="99999" name="columns" size="5" value="' . $field_data['columns'] . '" /> ' . $this->user->lang['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $field_data['field_length'] . '" />'),
1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="9999999999" name="field_minlen" size="10" value="' . $field_data['field_minlen'] . '" />'),
2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="9999999999" name="field_maxlen" size="10" value="' . $field_data['field_maxlen'] . '" />'),
3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options($field_data) . '</select>'),
);
return $options;
}
/**
* {@inheritDoc}
*/
public function get_default_option_values()
{
return array(
'field_length' => '5|80',
'field_minlen' => 0,
'field_maxlen' => 1000,
'field_validation' => '.*',
'field_novalue' => '',
'field_default_value' => '',
);
}
/**
* {@inheritDoc}
*/
public function get_profile_field($profile_row)
{
$var_name = 'pf_' . $profile_row['field_ident'];
return $this->request->variable($var_name, (string) $profile_row['field_default_value'], true);
}
/**
* {@inheritDoc}
*/
public function validate_profile_field(&$field_value, $field_data)
{
return $this->validate_string_profile_field('text', $field_value, $field_data);
}
/**
* {@inheritDoc}
*/
public function generate_field($profile_row, $preview_options = false)
{
$field_length = explode('|', $profile_row['field_length']);
$profile_row['field_rows'] = $field_length[0];
$profile_row['field_cols'] = $field_length[1];
$profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$field_ident = $profile_row['field_ident'];
$default_value = $profile_row['lang_default_value'];
$profile_row['field_value'] = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value, true) : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]);
$this->template->assign_block_vars('text', array_change_key_case($profile_row, CASE_UPPER));
}
/**
* {@inheritDoc}
*/
public function get_database_column_type()
{
return 'MTEXT';
}
/**
* {@inheritDoc}
*/
public function get_language_options($field_data)
{
$options = array(
'lang_name' => 'string',
);
if ($field_data['lang_explain'])
{
$options['lang_explain'] = 'text';
}
if (strlen($field_data['lang_default_value']))
{
$options['lang_default_value'] = 'text';
}
return $options;
}
/**
* {@inheritDoc}
*/
public function get_excluded_options($key, $action, $current_value, &$field_data, $step)
{
if ($step == 2 && $key == 'field_length')
{
if ($this->request->is_set('rows'))
{
$field_data['rows'] = $this->request->variable('rows', 0);
$field_data['columns'] = $this->request->variable('columns', 0);
$current_value = $field_data['rows'] . '|' . $field_data['columns'];
}
else
{
$row_col = explode('|', $current_value);
$field_data['rows'] = $row_col[0];
$field_data['columns'] = $row_col[1];
}
return $current_value;
}
return parent::get_excluded_options($key, $action, $current_value, $field_data, $step);
}
/**
* {@inheritDoc}
*/
public function prepare_hidden_fields($step, $key, $action, &$field_data)
{
if ($key == 'field_length' && $this->request->is_set('rows'))
{
$field_data['rows'] = $this->request->variable('rows', 0);
$field_data['columns'] = $this->request->variable('columns', 0);
return $field_data['rows'] . '|' . $field_data['columns'];
}
return parent::prepare_hidden_fields($step, $key, $action, $field_data);
}
/**
* {@inheritDoc}
*/
public function display_options(&$template_vars, &$field_data)
{
$template_vars = array_merge($template_vars, array(
'S_TEXT' => true,
'L_DEFAULT_VALUE_EXPLAIN' => $this->user->lang['TEXT_DEFAULT_VALUE_EXPLAIN'],
'LANG_DEFAULT_VALUE' => $field_data['lang_default_value'],
));
}
}