forked from phpbb/phpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype_string.php
More file actions
156 lines (137 loc) · 3.96 KB
/
Copy pathtype_string.php
File metadata and controls
156 lines (137 loc) · 3.96 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
<?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_string 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 'string';
}
/**
* {@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" name="field_length" size="5" value="' . $field_data['field_length'] . '" />'),
1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" name="field_minlen" size="5" value="' . $field_data['field_minlen'] . '" />'),
2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" name="field_maxlen" size="5" 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' => 10,
'field_minlen' => 0,
'field_maxlen' => 20,
'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('string', $field_value, $field_data);
}
/**
* {@inheritDoc}
*/
public function generate_field($profile_row, $preview_options = false)
{
$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($this->get_name_short(), array_change_key_case($profile_row, CASE_UPPER));
}
/**
* {@inheritDoc}
*/
public function get_database_column_type()
{
return 'VCHAR';
}
/**
* {@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'] = 'string';
}
return $options;
}
/**
* {@inheritDoc}
*/
public function display_options(&$template_vars, &$field_data)
{
$template_vars = array_merge($template_vars, array(
'S_STRING' => true,
'L_DEFAULT_VALUE_EXPLAIN' => $this->user->lang['STRING_DEFAULT_VALUE_EXPLAIN'],
'LANG_DEFAULT_VALUE' => $field_data['lang_default_value'],
));
}
}