diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-01-15 11:40:03 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-01-15 12:15:41 +0100 |
commit | 5df7f76e6b810f08076b905f189bc7e4c3f8b8b1 (patch) | |
tree | 18a7ebc38aeb82b2be79c2f944307bd82c233167 /phpBB/phpbb | |
parent | cd6bdc7b2719bea5c89e96efa5b175ed54a6b496 (diff) | |
download | forums-5df7f76e6b810f08076b905f189bc7e4c3f8b8b1.tar forums-5df7f76e6b810f08076b905f189bc7e4c3f8b8b1.tar.gz forums-5df7f76e6b810f08076b905f189bc7e4c3f8b8b1.tar.bz2 forums-5df7f76e6b810f08076b905f189bc7e4c3f8b8b1.tar.xz forums-5df7f76e6b810f08076b905f189bc7e4c3f8b8b1.zip |
[ticket/11201] Split language options into a new class
Otherwise we run into a circular dependency
PHPBB3-11201
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/profilefields/lang_helper.php | 114 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/profilefields.php | 37 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_bool.php | 28 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_date.php | 10 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_dropdown.php | 33 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_int.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_interface.php | 6 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_string.php | 6 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_text.php | 6 |
9 files changed, 165 insertions, 83 deletions
diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php new file mode 100644 index 0000000000..ddf77f5e42 --- /dev/null +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -0,0 +1,114 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2014 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\profilefields; + +/** +* Custom Profile Fields +* @package phpBB3 +*/ +class lang_helper +{ + /** + * Array with the language option, grouped by field and language + * @var array + */ + protected $options_lang = array(); + + /** + * Database object + * @var \phpbb\db\driver\driver + */ + protected $db; + + /** + * Construct + * + * @param \phpbb\db\driver\driver $db Database object + */ + public function __construct($db) + { + $this->db = $db; + } + + /** + * Get language entries for options and store them here for later use + */ + public function get_option_lang($field_id, $lang_id, $field_type, $preview_options) + { + if ($preview_options !== false) + { + $lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options; + + foreach ($lang_options as $num => $var) + { + $this->options_lang[$field_id][$lang_id][($num + 1)] = $var; + } + } + else + { + $sql = 'SELECT option_id, lang_value + FROM ' . PROFILE_FIELDS_LANG_TABLE . " + WHERE field_id = $field_id + AND lang_id = $lang_id + AND field_type = $field_type + ORDER BY option_id"; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['lang_value']; + } + $this->db->sql_freeresult($result); + } + } + + /** + * Are language options set for this field? + * + * @param int $field_id Database ID of the field + * @param int $lang_id ID of the language + * @param int $field_value Selected value of the field + * @return boolean + */ + public function is_set($field_id, $lang_id = null, $field_value = null) + { + $is_set = isset($this->lang_helper->options_lang[$field_id]); + + if ($is_set && (!is_null($lang_id) || !is_null($field_value))) + { + $is_set = isset($this->lang_helper->options_lang[$field_id][$lang_id]); + } + + if ($is_set && !is_null($field_value)) + { + $is_set = isset($this->lang_helper->options_lang[$field_id][$lang_id][$field_value]); + } + + return $is_set; + } + + /** + * Get the selected language string + * + * @param int $field_id Database ID of the field + * @param int $lang_id ID of the language + * @param int $field_value Selected value of the field + * @return string + */ + public function get($field_id, $lang_id, $field_value = null) + { + if (!is_null($field_value)) + { + return $this->lang_helper->options_lang[$field_id][$lang_id]; + } + + return $this->lang_helper->options_lang[$field_id][$lang_id][$field_value]; + } +} diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index e01611460b..0ed63223f5 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -17,7 +17,6 @@ class profilefields { var $profile_types = array(FIELD_INT => 'int', FIELD_STRING => 'string', FIELD_TEXT => 'text', FIELD_BOOL => 'bool', FIELD_DROPDOWN => 'dropdown', FIELD_DATE => 'date'); var $profile_cache = array(); - var $options_lang = array(); /** * @@ -111,38 +110,6 @@ class profilefields } /** - * Get language entries for options and store them here for later use - */ - public function get_option_lang($field_id, $lang_id, $field_type, $preview) - { - if ($preview) - { - $lang_options = (!is_array($this->vars['lang_options'])) ? explode("\n", $this->vars['lang_options']) : $this->vars['lang_options']; - - foreach ($lang_options as $num => $var) - { - $this->options_lang[$field_id][$lang_id][($num + 1)] = $var; - } - } - else - { - $sql = 'SELECT option_id, lang_value - FROM ' . PROFILE_FIELDS_LANG_TABLE . " - WHERE field_id = $field_id - AND lang_id = $lang_id - AND field_type = $field_type - ORDER BY option_id"; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['lang_value']; - } - $this->db->sql_freeresult($result); - } - } - - /** * Submit profile field for validation */ public function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error) @@ -360,7 +327,7 @@ class profilefields */ protected function process_field_row($mode, $profile_row) { - $preview = ($mode == 'preview') ? true : false; + $preview_options = ($mode == 'preview') ? $this->vars['lang_options'] : false; // set template filename $this->template->set_filenames(array( @@ -375,7 +342,7 @@ class profilefields // Assign template variables $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$profile_row['field_type']]); - $profile_field->generate_field($profile_row, $preview); + $profile_field->generate_field($profile_row, $preview_options); // Return templated data return $this->template->assign_display('cp_body'); diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index f4b056d3fc..f32f4a7513 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -14,9 +14,9 @@ class type_bool implements type_interface /** * */ - public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) + public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { - $this->profilefields = $profilefields; + $this->lang_helper = $lang_helper; $this->request = $request; $this->template = $template; $this->user = $user; @@ -42,7 +42,7 @@ class type_bool implements type_interface $options = array( 0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => '<label><input type="radio" class="radio" name="field_length" value="1"' . (($field_data['field_length'] == 1) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['RADIO_BUTTONS'] . '</label><label><input type="radio" class="radio" name="field_length" value="2"' . (($field_data['field_length'] == 2) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $this->user->lang['CHECKBOX'] . '</label>'), - 1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row)) + 1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row)), ); return $options; @@ -112,9 +112,9 @@ class type_bool implements type_interface $field_id = $field_data['field_id']; $lang_id = $field_data['lang_id']; - if (!isset($this->profilefields->options_lang[$field_id][$lang_id])) + if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->profilefields->get_option_lang($field_id, $lang_id, FIELD_BOOL, false); + $this->lang_helper->get_option_lang($field_id, $lang_id, FIELD_BOOL, false); } if (!$field_value && $field_data['field_show_novalue']) @@ -124,7 +124,7 @@ class type_bool implements type_interface if ($field_data['field_length'] == 1) { - return (isset($this->profilefields->options_lang[$field_id][$lang_id][(int) $field_value])) ? $this->options_lang[$field_id][$lang_id][(int) $field_value] : null; + return ($this->lang_helper->is_set($field_id, $lang_id, (int) $field_value)) ? $this->lang_helper->get($field_id, $lang_id, (int) $field_value) : null; } else if (!$field_value) { @@ -132,28 +132,27 @@ class type_bool implements type_interface } else { - return $this->profilefields->options_lang[$field_id][$lang_id][(int) ($field_value) + 1]; + return $this->lang_helper->is_set($field_id, $lang_id, $field_value + 1); } } /** * {@inheritDoc} */ - public function generate_field($profile_row, $preview = false) + 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']; - $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); // checkbox - set the value to "true" if it has been set to 1 if ($profile_row['field_length'] == 2) { - $value = ($this->request->is_set($field_ident) && $this->request->variable($field_ident, $default_value) == 1) ? true : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]); + $value = ($this->request->is_set($field_ident) && $this->request->variable($field_ident, $default_value) == 1) ? true : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]); } else { - $value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]); + $value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]); } $profile_row['field_value'] = (int) $value; @@ -161,12 +160,13 @@ class type_bool implements type_interface if ($profile_row['field_length'] == 1) { - if (!isset($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']])) + if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->profilefields->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview_options); } - foreach ($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) + $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); + foreach ($options as $option_id => $option_value) { $this->template->assign_block_vars('bool.options', array( 'OPTION_ID' => $option_id, diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 21b55874e5..fda09c05e2 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -35,7 +35,7 @@ class type_date implements type_interface 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', 'field_type' => FIELD_DATE, - 'field_length' => $field_data['field_length'] + 'field_length' => $field_data['field_length'], ); $always_now = request_var('always_now', -1); @@ -174,7 +174,7 @@ class type_date implements type_interface /** * {@inheritDoc} */ - public function generate_field($profile_row, $preview = false) + 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']; @@ -186,14 +186,14 @@ class type_date implements type_interface { $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); } - list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident])); + list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident])); } else { - if ($preview && $profile_row['field_default_value'] == 'now') + if ($preview_options !== false && $profile_row['field_default_value'] == 'now') { $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); - list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident])); + list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$user_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident])); } else { diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 9b434fd085..a3217f004c 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -14,9 +14,9 @@ class type_dropdown implements type_interface /** * */ - public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) + public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { - $this->profilefields = $profilefields; + $this->lang_helper = $lang_helper; $this->request = $request; $this->template = $template; $this->user = $user; @@ -36,7 +36,7 @@ class type_dropdown implements type_interface 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', 'field_type' => FIELD_DROPDOWN, - 'lang_options' => $field_data['lang_options'] + 'lang_options' => $field_data['lang_options'], ); $profile_row[1] = $profile_row[0]; @@ -46,7 +46,7 @@ class type_dropdown implements type_interface $options = array( 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row[0])), - 1 => array('TITLE' => $this->user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $this->user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row[1])) + 1 => array('TITLE' => $this->user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $this->user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row[1])), ); return $options; @@ -92,12 +92,12 @@ class type_dropdown implements type_interface $field_value = (int) $field_value; // retrieve option lang data if necessary - if (!isset($this->profilefields->options_lang[$field_data['field_id']]) || !isset($this->profilefields->options_lang[$field_data['field_id']][$field_data['lang_id']]) || !sizeof($this->profilefields->options_lang[$file_data['field_id']][$field_data['lang_id']])) + if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1)) { - $this->profilefields->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false); + $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false); } - if (!isset($this->profilefields->options_lang[$field_data['field_id']][$field_data['lang_id']][$field_value])) + if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value)) { return $this->user->lang('FIELD_INVALID_VALUE', $field_data['lang_name']); } @@ -117,9 +117,9 @@ class type_dropdown implements type_interface { $field_id = $field_data['field_id']; $lang_id = $field_data['lang_id']; - if (!isset($this->profilefields->options_lang[$field_id][$lang_id])) + if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->profilefields->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); + $this->lang_helper->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); } if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) @@ -130,7 +130,7 @@ class type_dropdown implements type_interface $field_value = (int) $field_value; // User not having a value assigned - if (!isset($this->profilefields->options_lang[$field_id][$lang_id][$field_value])) + if (!$this->lang_helper->is_set($field_id, $lang_id, $field_value)) { if ($field_data['field_show_novalue']) { @@ -142,29 +142,30 @@ class type_dropdown implements type_interface } } - return $this->profilefields->options_lang[$field_id][$lang_id][$field_value]; + return $this->lang_helper->get($field_id, $lang_id, $field_value); } /** * {@inheritDoc} */ - public function generate_field($profile_row, $preview = false) + 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']; - $value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview) ? $default_value : $this->user->profile_fields[$field_ident]); + $value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]); - if (!isset($this->profilefields->options_lang[$profile_row['field_id']]) || !isset($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']])) + if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->profilefields->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview_options); } $profile_row['field_value'] = (int) $value; $this->template->assign_block_vars('dropdown', array_change_key_case($profile_row, CASE_UPPER)); - foreach ($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) + $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); + foreach ($options as $option_id => $option_value) { $this->template->assign_block_vars('dropdown.options', array( 'OPTION_ID' => $option_id, diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 7ac99f5b80..13e39039c3 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -30,7 +30,7 @@ class type_int implements type_interface 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_length" size="5" value="' . $field_data['field_length'] . '" />'), 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_minlen" size="5" value="' . $field_data['field_minlen'] . '" />'), 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_maxlen" size="5" value="' . $field_data['field_maxlen'] . '" />'), - 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $field_data['field_default_value'] . '" />') + 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $field_data['field_default_value'] . '" />'), ); return $options; @@ -120,7 +120,7 @@ class type_int implements type_interface /** * {@inheritDoc} */ - public function generate_field($profile_row, $preview = false) + 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']; @@ -132,11 +132,11 @@ class type_int implements type_interface } else { - if (!$preview && array_key_exists($field_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$field_ident])) + if ($preview_options === false && array_key_exists($field_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$field_ident])) { $value = null; } - else if (!isset($this->user->profile_fields[$field_ident]) || $preview) + else if (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) { $value = $default_value; } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 9c78e1956d..5b662205b3 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -74,11 +74,11 @@ interface type_interface /** * Generate the input field for display * - * @param array $profile_row Array with data for this field - * @param bool $preview Do we preview the form + * @param array $profile_row Array with data for this field + * @param mixed $preview_options When previewing we use different data * @return null */ - public function generate_field($profile_row, $preview = false); + public function generate_field($profile_row, $preview_options = false); /** * Get the ident of the field diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 090b5a2a54..57edd14d62 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -30,7 +30,7 @@ class type_string extends type_string_common implements type_interface 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" 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>') + 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options($field_data) . '</select>'), ); return $options; @@ -71,12 +71,12 @@ class type_string extends type_string_common implements type_interface /** * {@inheritDoc} */ - public function generate_field($profile_row, $preview = false) + 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) ? $default_value : $this->user->profile_fields[$field_ident]); + $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('string', array_change_key_case($profile_row, CASE_UPPER)); diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index e73ffc5375..da1bb32859 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -30,7 +30,7 @@ class type_text extends type_string_common implements type_interface 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>') + 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options($field_data) . '</select>'), ); return $options; @@ -71,7 +71,7 @@ class type_text extends type_string_common implements type_interface /** * {@inheritDoc} */ - public function generate_field($profile_row, $preview = false) + public function generate_field($profile_row, $preview_options = false) { $field_length = explode('|', $profile_row['field_length']); $profile_row['field_rows'] = $field_length[0]; @@ -80,7 +80,7 @@ class type_text extends type_string_common implements type_interface $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) ? $default_value : $this->user->profile_fields[$field_ident]); + $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)); } |