From 2471b19d73c38359ed70a7c9e3a82a297946c5b8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 17 Sep 2013 15:17:54 +0200 Subject: [ticket/11201] Make profile field classes autoloadable PHPBB3-11201 --- phpBB/phpbb/profilefields/admin.php | 191 ++++++ phpBB/phpbb/profilefields/profilefields.php | 974 ++++++++++++++++++++++++++++ 2 files changed, 1165 insertions(+) create mode 100644 phpBB/phpbb/profilefields/admin.php create mode 100644 phpBB/phpbb/profilefields/profilefields.php (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/admin.php b/phpBB/phpbb/profilefields/admin.php new file mode 100644 index 0000000000..b784b91c55 --- /dev/null +++ b/phpBB/phpbb/profilefields/admin.php @@ -0,0 +1,191 @@ + '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+'); + + $validate_options = ''; + foreach ($validate_ary as $lang => $value) + { + $selected = ($this->vars['field_validation'] == $value) ? ' selected="selected"' : ''; + $validate_options .= ''; + } + + return $validate_options; + } + + /** + * Get string options for second step in ACP + */ + function get_string_options() + { + global $user; + + $options = array( + 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '') + ); + + return $options; + } + + /** + * Get text options for second step in ACP + */ + function get_text_options() + { + global $user; + + $options = array( + 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => ' ' . $user->lang['ROWS'] . '
' . $user->lang['COLUMNS'] . ' '), + 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '') + ); + + return $options; + } + + /** + * Get int options for second step in ACP + */ + function get_int_options() + { + global $user; + + $options = array( + 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), + 2 => array('TITLE' => $user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), + 3 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => '') + ); + + return $options; + } + + /** + * Get bool options for second step in ACP + */ + function get_bool_options() + { + global $user, $config, $lang_defs; + + $default_lang_id = $lang_defs['iso'][$config['default_lang']]; + + $profile_row = array( + 'var_name' => 'field_default_value', + 'field_id' => 1, + 'lang_name' => $this->vars['lang_name'], + 'lang_explain' => $this->vars['lang_explain'], + 'lang_id' => $default_lang_id, + 'field_default_value' => $this->vars['field_default_value'], + 'field_ident' => 'field_default_value', + 'field_type' => FIELD_BOOL, + 'field_length' => $this->vars['field_length'], + 'lang_options' => $this->vars['lang_options'] + ); + + $options = array( + 0 => array('TITLE' => $user->lang['FIELD_TYPE'], 'EXPLAIN' => $user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => ''), + 1 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)) + ); + + return $options; + } + + /** + * Get dropdown options for second step in ACP + */ + function get_dropdown_options() + { + global $user, $config, $lang_defs; + + $default_lang_id = $lang_defs['iso'][$config['default_lang']]; + + $profile_row[0] = array( + 'var_name' => 'field_default_value', + 'field_id' => 1, + 'lang_name' => $this->vars['lang_name'], + 'lang_explain' => $this->vars['lang_explain'], + 'lang_id' => $default_lang_id, + 'field_default_value' => $this->vars['field_default_value'], + 'field_ident' => 'field_default_value', + 'field_type' => FIELD_DROPDOWN, + 'lang_options' => $this->vars['lang_options'] + ); + + $profile_row[1] = $profile_row[0]; + $profile_row[1]['var_name'] = 'field_novalue'; + $profile_row[1]['field_ident'] = 'field_novalue'; + $profile_row[1]['field_default_value'] = $this->vars['field_novalue']; + + $options = array( + 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])), + 1 => array('TITLE' => $user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1])) + ); + + return $options; + } + + /** + * Get date options for second step in ACP + */ + function get_date_options() + { + global $user, $config, $lang_defs; + + $default_lang_id = $lang_defs['iso'][$config['default_lang']]; + + $profile_row = array( + 'var_name' => 'field_default_value', + 'lang_name' => $this->vars['lang_name'], + 'lang_explain' => $this->vars['lang_explain'], + 'lang_id' => $default_lang_id, + 'field_default_value' => $this->vars['field_default_value'], + 'field_ident' => 'field_default_value', + 'field_type' => FIELD_DATE, + 'field_length' => $this->vars['field_length'] + ); + + $always_now = request_var('always_now', -1); + if ($always_now == -1) + { + $s_checked = ($this->vars['field_default_value'] == 'now') ? true : false; + } + else + { + $s_checked = ($always_now) ? true : false; + } + + $options = array( + 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)), + 1 => array('TITLE' => $user->lang['ALWAYS_TODAY'], 'FIELD' => ''), + ); + + return $options; + } +} diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php new file mode 100644 index 0000000000..3d9339d1d7 --- /dev/null +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -0,0 +1,974 @@ + 'int', FIELD_STRING => 'string', FIELD_TEXT => 'text', FIELD_BOOL => 'bool', FIELD_DROPDOWN => 'dropdown', FIELD_DATE => 'date'); + var $profile_cache = array(); + var $options_lang = array(); + + /** + * + */ + public function __construct($auth, $db, $request, $template, $user) + { + $this->auth = $auth; + $this->db = $db; + $this->request = $request; + $this->template = $template; + $this->user = $user; + } + + /** + * Assign editable fields to template, mode can be profile (for profile change) or register (for registration) + * Called by ucp_profile and ucp_register + * @access public + */ + function generate_profile_fields($mode, $lang_id) + { + $sql_where = ''; + switch ($mode) + { + case 'register': + // If the field is required we show it on the registration page + $sql_where .= ' AND f.field_show_on_reg = 1'; + break; + + case 'profile': + // Show hidden fields to moderators/admins + if (!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) + { + $sql_where .= ' AND f.field_show_profile = 1'; + } + break; + + default: + trigger_error('Wrong profile mode specified', E_USER_ERROR); + break; + } + + $sql = 'SELECT l.*, f.* + FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f + WHERE f.field_active = 1 + $sql_where + AND l.lang_id = $lang_id + AND l.field_id = f.field_id + ORDER BY f.field_order"; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + // Return templated field + $tpl_snippet = $this->process_field_row('change', $row); + + // Some types are multivalue, we can't give them a field_id as we would not know which to pick + $type = (int) $row['field_type']; + + $this->template->assign_block_vars('profile_fields', array( + 'LANG_NAME' => $row['lang_name'], + 'LANG_EXPLAIN' => $row['lang_explain'], + 'FIELD' => $tpl_snippet, + 'FIELD_ID' => ($type == FIELD_DATE || ($type == FIELD_BOOL && $row['field_length'] == '1')) ? '' : 'pf_' . $row['field_ident'], + 'S_REQUIRED' => ($row['field_required']) ? true : false) + ); + } + $this->db->sql_freeresult($result); + } + + /** + * Validate entered profile field data + * @access public + */ + function validate_profile_field($field_type, &$field_value, $field_data) + { + switch ($field_type) + { + case FIELD_DATE: + $field_validate = explode('-', $field_value); + + $day = (isset($field_validate[0])) ? (int) $field_validate[0] : 0; + $month = (isset($field_validate[1])) ? (int) $field_validate[1] : 0; + $year = (isset($field_validate[2])) ? (int) $field_validate[2] : 0; + + if ((!$day || !$month || !$year) && !$field_data['field_required']) + { + return false; + } + + if ((!$day || !$month || !$year) && $field_data['field_required']) + { + return 'FIELD_REQUIRED'; + } + + if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50) + { + return 'FIELD_INVALID_DATE'; + } + + if (checkdate($month, $day, $year) === false) + { + return 'FIELD_INVALID_DATE'; + } + break; + + case FIELD_BOOL: + $field_value = (bool) $field_value; + + if (!$field_value && $field_data['field_required']) + { + return 'FIELD_REQUIRED'; + } + break; + + case FIELD_INT: + if (trim($field_value) === '' && !$field_data['field_required']) + { + return false; + } + + $field_value = (int) $field_value; + + if ($field_value < $field_data['field_minlen']) + { + return 'FIELD_TOO_SMALL'; + } + else if ($field_value > $field_data['field_maxlen']) + { + return 'FIELD_TOO_LARGE'; + } + break; + + case FIELD_DROPDOWN: + $field_value = (int) $field_value; + + // retrieve option lang data if necessary + if (!isset($this->options_lang[$field_data['field_id']]) || !isset($this->options_lang[$field_data['field_id']][$field_data['lang_id']]) || !sizeof($this->options_lang[$file_data['field_id']][$field_data['lang_id']])) + { + $this->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false); + } + + if (!isset($this->options_lang[$field_data['field_id']][$field_data['lang_id']][$field_value])) + { + return 'FIELD_INVALID_VALUE'; + } + + if ($field_value == $field_data['field_novalue'] && $field_data['field_required']) + { + return 'FIELD_REQUIRED'; + } + break; + + case FIELD_STRING: + case FIELD_TEXT: + if (trim($field_value) === '' && !$field_data['field_required']) + { + return false; + } + else if (trim($field_value) === '' && $field_data['field_required']) + { + return 'FIELD_REQUIRED'; + } + + if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen']) + { + return 'FIELD_TOO_SHORT'; + } + else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen']) + { + return 'FIELD_TOO_LONG'; + } + + if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*') + { + $field_validate = ($field_type == FIELD_STRING) ? $field_value : bbcode_nl2br($field_value); + if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate)) + { + return 'FIELD_INVALID_CHARS'; + } + } + break; + } + + return false; + } + + /** + * Build profile cache, used for display + * @access private + */ + function build_cache() + { + $this->profile_cache = array(); + + // Display hidden/no_view fields for admin/moderator + $sql = 'SELECT l.*, f.* + FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f + WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . ' + AND f.field_active = 1 ' . + ((!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) ? ' AND f.field_hide = 0 ' : '') . ' + AND f.field_no_view = 0 + AND l.field_id = f.field_id + ORDER BY f.field_order'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->profile_cache[$row['field_ident']] = $row; + } + $this->db->sql_freeresult($result); + } + + /** + * Get language entries for options and store them here for later use + */ + 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 + * @access public + */ + function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error) + { + $sql_where = ''; + switch ($mode) + { + case 'register': + // If the field is required we show it on the registration page + $sql_where .= ' AND f.field_show_on_reg = 1'; + break; + + case 'profile': + // Show hidden fields to moderators/admins + if (!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) + { + $sql_where .= ' AND f.field_show_profile = 1'; + } + break; + + default: + trigger_error('Wrong profile mode specified', E_USER_ERROR); + break; + } + + $sql = 'SELECT l.*, f.* + FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f + WHERE l.lang_id = $lang_id + AND f.field_active = 1 + $sql_where + AND l.field_id = f.field_id + ORDER BY f.field_order"; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $cp_data['pf_' . $row['field_ident']] = $this->get_profile_field($row); + $check_value = $cp_data['pf_' . $row['field_ident']]; + + if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false) + { + // If not and only showing common error messages, use this one + $error = ''; + switch ($cp_result) + { + case 'FIELD_INVALID_DATE': + case 'FIELD_INVALID_VALUE': + case 'FIELD_REQUIRED': + $error = $this->user->lang($cp_result, $row['lang_name']); + break; + + case 'FIELD_TOO_SHORT': + case 'FIELD_TOO_SMALL': + $error = $this->user->lang($cp_result, (int) $row['field_minlen'], $row['lang_name']); + break; + + case 'FIELD_TOO_LONG': + case 'FIELD_TOO_LARGE': + $error = $this->user->lang($cp_result, (int) $row['field_maxlen'], $row['lang_name']); + break; + + case 'FIELD_INVALID_CHARS': + switch ($row['field_validation']) + { + case '[0-9]+': + $error = $this->user->lang($cp_result . '_NUMBERS_ONLY', $row['lang_name']); + break; + + case '[\w]+': + $error = $this->user->lang($cp_result . '_ALPHA_ONLY', $row['lang_name']); + break; + + case '[\w_\+\. \-\[\]]+': + $error = $this->user->lang($cp_result . '_SPACERS_ONLY', $row['lang_name']); + break; + } + break; + } + + if ($error != '') + { + $cp_error[] = $error; + } + } + } + $this->db->sql_freeresult($result); + } + + /** + * Update profile field data directly + */ + function update_profile_field_data($user_id, &$cp_data) + { + if (!sizeof($cp_data)) + { + return; + } + + switch ($db->sql_layer) + { + case 'oracle': + case 'firebird': + case 'postgres': + $right_delim = $left_delim = '"'; + break; + + case 'sqlite': + case 'mssql': + case 'mssql_odbc': + case 'mssqlnative': + $right_delim = ']'; + $left_delim = '['; + break; + + case 'mysql': + case 'mysql4': + case 'mysqli': + $right_delim = $left_delim = '`'; + break; + } + + // use new array for the UPDATE; changes in the key do not affect the original array + $cp_data_sql = array(); + foreach ($cp_data as $key => $value) + { + // Firebird is case sensitive with delimiter + $cp_data_sql[$left_delim . (($this->db->sql_layer == 'firebird' || $this->db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value; + } + + $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $cp_data_sql) . " + WHERE user_id = $user_id"; + $this->db->sql_query($sql); + + if (!$this->db->sql_affectedrows()) + { + $cp_data_sql['user_id'] = (int) $user_id; + + $this->db->sql_return_on_error(true); + + $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $this->db->sql_build_array('INSERT', $cp_data_sql); + $this->db->sql_query($sql); + + $this->db->sql_return_on_error(false); + } + } + + /** + * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) + * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template + * @access public + */ + function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false) + { + if ($mode == 'grab') + { + if (!is_array($user_id)) + { + $user_id = array($user_id); + } + + if (!sizeof($this->profile_cache)) + { + $this->build_cache(); + } + + if (!sizeof($user_id)) + { + return array(); + } + + $sql = 'SELECT * + FROM ' . PROFILE_FIELDS_DATA_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_id)); + $result = $this->db->sql_query($sql); + + $field_data = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $field_data[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + + $user_fields = array(); + + $user_ids = $user_id; + + // Go through the fields in correct order + foreach (array_keys($this->profile_cache) as $used_ident) + { + foreach ($field_data as $user_id => $row) + { + $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident]; + $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident]; + } + + foreach ($user_ids as $user_id) + { + if (!isset($user_fields[$user_id][$used_ident]) && $this->profile_cache[$used_ident]['field_show_novalue']) + { + $user_fields[$user_id][$used_ident]['value'] = ''; + $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident]; + } + } + } + + return $user_fields; + } + else if ($mode == 'show') + { + // $profile_row == $user_fields[$row['user_id']]; + $tpl_fields = array(); + $tpl_fields['row'] = $tpl_fields['blockrow'] = array(); + + foreach ($profile_row as $ident => $ident_ary) + { + $value = $this->get_profile_value($ident_ary); + + if ($value === NULL) + { + continue; + } + + $tpl_fields['row'] += array( + 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, + 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_' . strtoupper($ident) . '_NAME' => $ident_ary['data']['lang_name'], + 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $ident_ary['data']['lang_explain'], + + 'S_PROFILE_' . strtoupper($ident) => true + ); + + $tpl_fields['blockrow'][] = array( + 'PROFILE_FIELD_VALUE' => $value, + 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_FIELD_NAME' => $ident_ary['data']['lang_name'], + 'PROFILE_FIELD_EXPLAIN' => $ident_ary['data']['lang_explain'], + + 'S_PROFILE_' . strtoupper($ident) => true + ); + } + + return $tpl_fields; + } + else + { + trigger_error('Wrong mode for custom profile', E_USER_ERROR); + } + } + + /** + * Get Profile Value for display + */ + function get_profile_value($ident_ary) + { + $value = $ident_ary['value']; + $field_type = $ident_ary['data']['field_type']; + + switch ($this->profile_types[$field_type]) + { + case 'int': + if ($value === '' && !$ident_ary['data']['field_show_novalue']) + { + return NULL; + } + return (int) $value; + break; + + case 'string': + case 'text': + if (!$value && !$ident_ary['data']['field_show_novalue']) + { + return NULL; + } + + $value = make_clickable($value); + $value = censor_text($value); + $value = bbcode_nl2br($value); + return $value; + break; + + // case 'datetime': + case 'date': + $date = explode('-', $value); + $day = (isset($date[0])) ? (int) $date[0] : 0; + $month = (isset($date[1])) ? (int) $date[1] : 0; + $year = (isset($date[2])) ? (int) $date[2] : 0; + + if (!$day && !$month && !$year && !$ident_ary['data']['field_show_novalue']) + { + return NULL; + } + else if ($day && $month && $year) + { + // Date should display as the same date for every user regardless of timezone + return $this->user->create_datetime() + ->setDate($year, $month, $day) + ->setTime(0, 0, 0) + ->format($user->lang['DATE_FORMAT'], true); + } + + return $value; + break; + + case 'dropdown': + $field_id = $ident_ary['data']['field_id']; + $lang_id = $ident_ary['data']['lang_id']; + if (!isset($this->options_lang[$field_id][$lang_id])) + { + $this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); + } + + if ($value == $ident_ary['data']['field_novalue'] && !$ident_ary['data']['field_show_novalue']) + { + return NULL; + } + + $value = (int) $value; + + // User not having a value assigned + if (!isset($this->options_lang[$field_id][$lang_id][$value])) + { + if ($ident_ary['data']['field_show_novalue']) + { + $value = $ident_ary['data']['field_novalue']; + } + else + { + return NULL; + } + } + + return $this->options_lang[$field_id][$lang_id][$value]; + break; + + case 'bool': + $field_id = $ident_ary['data']['field_id']; + $lang_id = $ident_ary['data']['lang_id']; + if (!isset($this->options_lang[$field_id][$lang_id])) + { + $this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false); + } + + if (!$value && $ident_ary['data']['field_show_novalue']) + { + $value = $ident_ary['data']['field_default_value']; + } + + if ($ident_ary['data']['field_length'] == 1) + { + return (isset($this->options_lang[$field_id][$lang_id][(int) $value])) ? $this->options_lang[$field_id][$lang_id][(int) $value] : NULL; + } + else if (!$value) + { + return NULL; + } + else + { + return $this->options_lang[$field_id][$lang_id][(int) ($value) + 1]; + } + break; + + default: + trigger_error('Unknown profile type', E_USER_ERROR); + break; + } + } + + /** + * Get field value for registration/profile + * @access private + */ + function get_var($field_validation, &$profile_row, $default_value, $preview) + { + $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; + $user_ident = $profile_row['field_ident']; + // checkbox - set the value to "true" if it has been set to 1 + if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2) + { + $value = (isset($_REQUEST[$profile_row['field_ident']]) && request_var($profile_row['field_ident'], $default_value) == 1) ? true : ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $default_value : $this->user->profile_fields[$user_ident]); + } + else if ($profile_row['field_type'] == FIELD_INT) + { + if (isset($_REQUEST[$profile_row['field_ident']])) + { + $value = ($this->request->variable($profile_row['field_ident'], '') === '') ? NULL : $this->request->variable($profile_row['field_ident'], $default_value); + } + else + { + if (!$preview && array_key_exists($user_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$user_ident])) + { + $value = NULL; + } + else if (!isset($this->user->profile_fields[$user_ident]) || $preview) + { + $value = $default_value; + } + else + { + $value = $this->user->profile_fields[$user_ident]; + } + } + + return (is_null($value) || $value === '') ? '' : (int) $value; + } + else + { + $value = (isset($_REQUEST[$profile_row['field_ident']])) ? request_var($profile_row['field_ident'], $default_value, true) : ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $default_value : $this->user->profile_fields[$user_ident]); + + if (gettype($value) == 'string') + { + $value = utf8_normalize_nfc($value); + } + } + + switch ($field_validation) + { + case 'int': + return (int) $value; + break; + } + + return $value; + } + + /** + * Process int-type + * @access private + */ + function generate_int($profile_row, $preview = false) + { + $profile_row['field_value'] = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); + $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); + } + + /** + * Process date-type + * @access private + */ + function generate_date($profile_row, $preview = false) + { + $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; + $user_ident = $profile_row['field_ident']; + + $now = getdate(); + + if (!isset($_REQUEST[$profile_row['field_ident'] . '_day'])) + { + if ($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])); + } + else + { + if ($preview && $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])); + } + else + { + $day = request_var($profile_row['field_ident'] . '_day', 0); + $month = request_var($profile_row['field_ident'] . '_month', 0); + $year = request_var($profile_row['field_ident'] . '_year', 0); + } + } + + $profile_row['s_day_options'] = ''; + for ($i = 1; $i < 32; $i++) + { + $profile_row['s_day_options'] .= '"; + } + + $profile_row['s_month_options'] = ''; + for ($i = 1; $i < 13; $i++) + { + $profile_row['s_month_options'] .= '"; + } + + $profile_row['s_year_options'] = ''; + for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++) + { + $profile_row['s_year_options'] .= '"; + } + unset($now); + + $profile_row['field_value'] = 0; + $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); + } + + /** + * Process bool-type + * @access private + */ + function generate_bool($profile_row, $preview = false) + { + $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); + + $profile_row['field_value'] = $value; + $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); + + if ($profile_row['field_length'] == 1) + { + if (!isset($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']])) + { + $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview); + } + + foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) + { + $this->template->assign_block_vars('bool.options', array( + 'OPTION_ID' => $option_id, + 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '', + 'VALUE' => $option_value) + ); + } + } + } + + /** + * Process string-type + * @access private + */ + function generate_string($profile_row, $preview = false) + { + $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview); + $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); + } + + /** + * Process text-type + * @access private + */ + function generate_text($profile_row, $preview = 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_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview); + $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); + } + + /** + * Process dropdown-type + * @access private + */ + function generate_dropdown($profile_row, $preview = false) + { + $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); + + if (!isset($this->options_lang[$profile_row['field_id']]) || !isset($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']])) + { + $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview); + } + + $profile_row['field_value'] = $value; + $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); + + foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) + { + $this->template->assign_block_vars('dropdown.options', array( + 'OPTION_ID' => $option_id, + 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '', + 'VALUE' => $option_value) + ); + } + } + + /** + * Return Templated value/field. Possible values for $mode are: + * change == user is able to set/enter profile values; preview == just show the value + * @access private + */ + function process_field_row($mode, $profile_row) + { + $preview = ($mode == 'preview') ? true : false; + + // set template filename + $this->template->set_filenames(array( + 'cp_body' => 'custom_profile_fields.html', + )); + + // empty previously filled blockvars + foreach ($this->profile_types as $field_case => $field_type) + { + $this->template->destroy_block_vars($field_type); + } + + // Assign template variables + $type_func = 'generate_' . $this->profile_types[$profile_row['field_type']]; + $this->$type_func($profile_row, $preview); + + // Return templated data + return $this->template->assign_display('cp_body'); + } + + /** + * Build Array for user insertion into custom profile fields table + */ + function build_insert_sql_array($cp_data) + { + $sql_not_in = array(); + foreach ($cp_data as $key => $null) + { + $sql_not_in[] = (strncmp($key, 'pf_', 3) === 0) ? substr($key, 3) : $key; + } + + $sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value + FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f + WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . ' + ' . ((sizeof($sql_not_in)) ? ' AND ' . $this->db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . ' + AND l.field_id = f.field_id'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if ($row['field_default_value'] == 'now' && $row['field_type'] == FIELD_DATE) + { + $now = getdate(); + $row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); + } + else if ($row['field_default_value'] === '' && $row['field_type'] == FIELD_INT) + { + // We cannot insert an empty string into an integer column. + $row['field_default_value'] = NULL; + } + + $cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT, FIELD_STRING))) ? $row['lang_default_value'] : $row['field_default_value']; + } + $this->db->sql_freeresult($result); + + return $cp_data; + } + + /** + * Get profile field value on submit + * @access private + */ + function get_profile_field($profile_row) + { + $var_name = 'pf_' . $profile_row['field_ident']; + + switch ($profile_row['field_type']) + { + case FIELD_DATE: + + if (!isset($_REQUEST[$var_name . '_day'])) + { + if ($profile_row['field_default_value'] == 'now') + { + $now = getdate(); + $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); + } + list($day, $month, $year) = explode('-', $profile_row['field_default_value']); + } + else + { + $day = request_var($var_name . '_day', 0); + $month = request_var($var_name . '_month', 0); + $year = request_var($var_name . '_year', 0); + } + + $var = sprintf('%2d-%2d-%4d', $day, $month, $year); + break; + + case FIELD_BOOL: + // Checkbox + if ($profile_row['field_length'] == 2) + { + $var = (isset($_REQUEST[$var_name])) ? 1 : 0; + } + else + { + $var = request_var($var_name, (int) $profile_row['field_default_value']); + } + break; + + case FIELD_STRING: + case FIELD_TEXT: + $var = utf8_normalize_nfc(request_var($var_name, (string) $profile_row['field_default_value'], true)); + break; + + case FIELD_INT: + if (isset($_REQUEST[$var_name]) && $this->request->variable($var_name, '') === '') + { + $var = NULL; + } + else + { + $var = request_var($var_name, (int) $profile_row['field_default_value']); + } + break; + + case FIELD_DROPDOWN: + $var = request_var($var_name, (int) $profile_row['field_default_value']); + break; + + default: + $var = request_var($var_name, $profile_row['field_default_value']); + break; + } + + return $var; + } +} -- cgit v1.2.1 From c6658396362f56e1f6605b032bbb7d12275e4749 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 10 Jan 2014 23:00:37 +0100 Subject: [ticket/11201] Remove global use from admin class PHPBB3-11201 --- phpBB/phpbb/profilefields/admin.php | 83 ++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 42 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/admin.php b/phpBB/phpbb/profilefields/admin.php index b784b91c55..1cca496265 100644 --- a/phpBB/phpbb/profilefields/admin.php +++ b/phpBB/phpbb/profilefields/admin.php @@ -17,20 +17,31 @@ class admin extends profilefields { var $vars = array(); + /** + * + */ + public function __construct($auth, $config, $db, $request, $template, $user) + { + $this->auth = $auth; + $this->config = $config; + $this->db = $db; + $this->request = $request; + $this->template = $template; + $this->user = $user; + } + /** * Return possible validation options */ function validate_options() { - global $user; - $validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+'); $validate_options = ''; foreach ($validate_ary as $lang => $value) { $selected = ($this->vars['field_validation'] == $value) ? ' selected="selected"' : ''; - $validate_options .= ''; + $validate_options .= ''; } return $validate_options; @@ -39,15 +50,13 @@ class admin extends profilefields /** * Get string options for second step in ACP */ - function get_string_options() + function get_string_options($lang_defs) { - global $user; - $options = array( - 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => ''), - 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), - 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '') + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') ); return $options; @@ -56,15 +65,13 @@ class admin extends profilefields /** * Get text options for second step in ACP */ - function get_text_options() + function get_text_options($lang_defs) { - global $user; - $options = array( - 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => ' ' . $user->lang['ROWS'] . '
' . $user->lang['COLUMNS'] . ' '), - 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), - 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '') + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ' ' . $user->lang['ROWS'] . '
' . $user->lang['COLUMNS'] . ' '), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') ); return $options; @@ -73,15 +80,13 @@ class admin extends profilefields /** * Get int options for second step in ACP */ - function get_int_options() + function get_int_options($lang_defs) { - global $user; - $options = array( - 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => ''), - 1 => array('TITLE' => $user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), - 2 => array('TITLE' => $user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), - 3 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => '') + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), + 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '') ); return $options; @@ -90,11 +95,9 @@ class admin extends profilefields /** * Get bool options for second step in ACP */ - function get_bool_options() + function get_bool_options($lang_defs) { - global $user, $config, $lang_defs; - - $default_lang_id = $lang_defs['iso'][$config['default_lang']]; + $default_lang_id = $lang_defs['iso'][$this->config['default_lang']]; $profile_row = array( 'var_name' => 'field_default_value', @@ -110,8 +113,8 @@ class admin extends profilefields ); $options = array( - 0 => array('TITLE' => $user->lang['FIELD_TYPE'], 'EXPLAIN' => $user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => ''), - 1 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)) + 0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)) ); return $options; @@ -120,11 +123,9 @@ class admin extends profilefields /** * Get dropdown options for second step in ACP */ - function get_dropdown_options() + function get_dropdown_options($lang_defs) { - global $user, $config, $lang_defs; - - $default_lang_id = $lang_defs['iso'][$config['default_lang']]; + $default_lang_id = $lang_defs['iso'][$this->config['default_lang']]; $profile_row[0] = array( 'var_name' => 'field_default_value', @@ -144,8 +145,8 @@ class admin extends profilefields $profile_row[1]['field_default_value'] = $this->vars['field_novalue']; $options = array( - 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])), - 1 => array('TITLE' => $user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1])) + 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->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->process_field_row('preview', $profile_row[1])) ); return $options; @@ -154,11 +155,9 @@ class admin extends profilefields /** * Get date options for second step in ACP */ - function get_date_options() + function get_date_options($lang_defs) { - global $user, $config, $lang_defs; - - $default_lang_id = $lang_defs['iso'][$config['default_lang']]; + $default_lang_id = $lang_defs['iso'][$this->config['default_lang']]; $profile_row = array( 'var_name' => 'field_default_value', @@ -182,8 +181,8 @@ class admin extends profilefields } $options = array( - 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)), - 1 => array('TITLE' => $user->lang['ALWAYS_TODAY'], 'FIELD' => ''), + 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)), + 1 => array('TITLE' => $this->user->lang['ALWAYS_TODAY'], 'FIELD' => ''), ); return $options; -- cgit v1.2.1 From a7e3538e5b0cb12610b5c051a5d30292970249d1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 11 Jan 2014 01:44:48 +0100 Subject: [ticket/11201] Move get_options to type classes PHPBB3-11201 --- phpBB/phpbb/profilefields/admin.php | 190 --------------------- phpBB/phpbb/profilefields/type/type_bool.php | 63 +++++++ phpBB/phpbb/profilefields/type/type_date.php | 71 ++++++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 67 ++++++++ phpBB/phpbb/profilefields/type/type_int.php | 51 ++++++ phpBB/phpbb/profilefields/type/type_interface.php | 39 +++++ phpBB/phpbb/profilefields/type/type_string.php | 51 ++++++ .../profilefields/type/type_string_common.php | 30 ++++ phpBB/phpbb/profilefields/type/type_text.php | 51 ++++++ 9 files changed, 423 insertions(+), 190 deletions(-) delete mode 100644 phpBB/phpbb/profilefields/admin.php create mode 100644 phpBB/phpbb/profilefields/type/type_bool.php create mode 100644 phpBB/phpbb/profilefields/type/type_date.php create mode 100644 phpBB/phpbb/profilefields/type/type_dropdown.php create mode 100644 phpBB/phpbb/profilefields/type/type_int.php create mode 100644 phpBB/phpbb/profilefields/type/type_interface.php create mode 100644 phpBB/phpbb/profilefields/type/type_string.php create mode 100644 phpBB/phpbb/profilefields/type/type_string_common.php create mode 100644 phpBB/phpbb/profilefields/type/type_text.php (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/admin.php b/phpBB/phpbb/profilefields/admin.php deleted file mode 100644 index 1cca496265..0000000000 --- a/phpBB/phpbb/profilefields/admin.php +++ /dev/null @@ -1,190 +0,0 @@ -auth = $auth; - $this->config = $config; - $this->db = $db; - $this->request = $request; - $this->template = $template; - $this->user = $user; - } - - /** - * Return possible validation options - */ - function validate_options() - { - $validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+'); - - $validate_options = ''; - foreach ($validate_ary as $lang => $value) - { - $selected = ($this->vars['field_validation'] == $value) ? ' selected="selected"' : ''; - $validate_options .= ''; - } - - return $validate_options; - } - - /** - * Get string options for second step in ACP - */ - function get_string_options($lang_defs) - { - $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), - 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), - 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') - ); - - return $options; - } - - /** - * Get text options for second step in ACP - */ - function get_text_options($lang_defs) - { - $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ' ' . $user->lang['ROWS'] . '
' . $user->lang['COLUMNS'] . ' '), - 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), - 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') - ); - - return $options; - } - - /** - * Get int options for second step in ACP - */ - function get_int_options($lang_defs) - { - $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), - 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), - 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '') - ); - - return $options; - } - - /** - * Get bool options for second step in ACP - */ - function get_bool_options($lang_defs) - { - $default_lang_id = $lang_defs['iso'][$this->config['default_lang']]; - - $profile_row = array( - 'var_name' => 'field_default_value', - 'field_id' => 1, - 'lang_name' => $this->vars['lang_name'], - 'lang_explain' => $this->vars['lang_explain'], - 'lang_id' => $default_lang_id, - 'field_default_value' => $this->vars['field_default_value'], - 'field_ident' => 'field_default_value', - 'field_type' => FIELD_BOOL, - 'field_length' => $this->vars['field_length'], - 'lang_options' => $this->vars['lang_options'] - ); - - $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => ''), - 1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)) - ); - - return $options; - } - - /** - * Get dropdown options for second step in ACP - */ - function get_dropdown_options($lang_defs) - { - $default_lang_id = $lang_defs['iso'][$this->config['default_lang']]; - - $profile_row[0] = array( - 'var_name' => 'field_default_value', - 'field_id' => 1, - 'lang_name' => $this->vars['lang_name'], - 'lang_explain' => $this->vars['lang_explain'], - 'lang_id' => $default_lang_id, - 'field_default_value' => $this->vars['field_default_value'], - 'field_ident' => 'field_default_value', - 'field_type' => FIELD_DROPDOWN, - 'lang_options' => $this->vars['lang_options'] - ); - - $profile_row[1] = $profile_row[0]; - $profile_row[1]['var_name'] = 'field_novalue'; - $profile_row[1]['field_ident'] = 'field_novalue'; - $profile_row[1]['field_default_value'] = $this->vars['field_novalue']; - - $options = array( - 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->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->process_field_row('preview', $profile_row[1])) - ); - - return $options; - } - - /** - * Get date options for second step in ACP - */ - function get_date_options($lang_defs) - { - $default_lang_id = $lang_defs['iso'][$this->config['default_lang']]; - - $profile_row = array( - 'var_name' => 'field_default_value', - 'lang_name' => $this->vars['lang_name'], - 'lang_explain' => $this->vars['lang_explain'], - 'lang_id' => $default_lang_id, - 'field_default_value' => $this->vars['field_default_value'], - 'field_ident' => 'field_default_value', - 'field_type' => FIELD_DATE, - 'field_length' => $this->vars['field_length'] - ); - - $always_now = request_var('always_now', -1); - if ($always_now == -1) - { - $s_checked = ($this->vars['field_default_value'] == 'now') ? true : false; - } - else - { - $s_checked = ($always_now) ? true : false; - } - - $options = array( - 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)), - 1 => array('TITLE' => $this->user->lang['ALWAYS_TODAY'], 'FIELD' => ''), - ); - - return $options; - } -} diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php new file mode 100644 index 0000000000..b3dafa30d4 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -0,0 +1,63 @@ +profilefields = $profilefields; + $this->user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $profile_row = array( + 'var_name' => 'field_default_value', + 'field_id' => 1, + 'lang_name' => $field_data['lang_name'], + 'lang_explain' => $field_data['lang_explain'], + 'lang_id' => $default_lang_id, + 'field_default_value' => $field_data['field_default_value'], + 'field_ident' => 'field_default_value', + 'field_type' => FIELD_BOOL, + 'field_length' => $field_data['field_length'], + 'lang_options' => $field_data['lang_options'] + ); + + $options = array( + 0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row)) + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => 1, + 'field_minlen' => 0, + 'field_maxlen' => 0, + 'field_validation' => '', + 'field_novalue' => 0, + 'field_default_value' => 0, + ); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php new file mode 100644 index 0000000000..9639b45770 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -0,0 +1,71 @@ +profilefields = $profilefields; + $this->user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $profile_row = array( + 'var_name' => 'field_default_value', + 'lang_name' => $field_data['lang_name'], + 'lang_explain' => $field_data['lang_explain'], + 'lang_id' => $default_lang_id, + 'field_default_value' => $field_data['field_default_value'], + 'field_ident' => 'field_default_value', + 'field_type' => FIELD_DATE, + 'field_length' => $field_data['field_length'] + ); + + $always_now = request_var('always_now', -1); + if ($always_now == -1) + { + $s_checked = ($field_data['field_default_value'] == 'now') ? true : false; + } + else + { + $s_checked = ($always_now) ? true : false; + } + + $options = array( + 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row)), + 1 => array('TITLE' => $this->user->lang['ALWAYS_TODAY'], 'FIELD' => ''), + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => 10, + 'field_minlen' => 10, + 'field_maxlen' => 10, + 'field_validation' => '', + 'field_novalue' => ' 0- 0- 0', + 'field_default_value' => ' 0- 0- 0', + ); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php new file mode 100644 index 0000000000..8a101f1fc1 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -0,0 +1,67 @@ +profilefields = $profilefields; + $this->user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $profile_row[0] = array( + 'var_name' => 'field_default_value', + 'field_id' => 1, + 'lang_name' => $field_data['lang_name'], + 'lang_explain' => $field_data['lang_explain'], + 'lang_id' => $default_lang_id, + 'field_default_value' => $field_data['field_default_value'], + 'field_ident' => 'field_default_value', + 'field_type' => FIELD_DROPDOWN, + 'lang_options' => $field_data['lang_options'] + ); + + $profile_row[1] = $profile_row[0]; + $profile_row[1]['var_name'] = 'field_novalue'; + $profile_row[1]['field_ident'] = 'field_novalue'; + $profile_row[1]['field_default_value'] = $field_data['field_novalue']; + + $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])) + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => 0, + 'field_minlen' => 0, + 'field_maxlen' => 5, + 'field_validation' => '', + 'field_novalue' => 0, + 'field_default_value' => 0, + ); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php new file mode 100644 index 0000000000..7cc74b6e44 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -0,0 +1,51 @@ +user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $options = array( + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), + 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '') + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => 5, + 'field_minlen' => 0, + 'field_maxlen' => 100, + 'field_validation' => '', + 'field_novalue' => 0, + 'field_default_value' => 0, + ); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php new file mode 100644 index 0000000000..8b011aa48e --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -0,0 +1,39 @@ +user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $options = array( + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => 10, + 'field_minlen' => 0, + 'field_maxlen' => 20, + 'field_validation' => '.*', + 'field_novalue' => '', + 'field_default_value' => '', + ); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php new file mode 100644 index 0000000000..dc2cd2f157 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -0,0 +1,30 @@ + '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+'); + + $validate_options = ''; + foreach ($validate_ary as $lang => $value) + { + $selected = ($field_data['field_validation'] == $value) ? ' selected="selected"' : ''; + $validate_options .= ''; + } + + return $validate_options; + } +} diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php new file mode 100644 index 0000000000..4b58ef0486 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -0,0 +1,51 @@ +user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_options($default_lang_id, $field_data) + { + $options = array( + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ' ' . $this->user->lang['ROWS'] . '
' . $this->user->lang['COLUMNS'] . ' '), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_values() + { + return array( + 'field_length' => '5|80', + 'field_minlen' => 0, + 'field_maxlen' => 1000, + 'field_validation' => '.*', + 'field_novalue' => '', + 'field_default_value' => '', + ); + } +} -- cgit v1.2.1 From b3803d563a857e12f540a315c51cf97a6c0be438 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 13 Jan 2014 21:05:19 +0100 Subject: [ticket/11201] Move get_profile_field() to type classes PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 79 ++--------------------- phpBB/phpbb/profilefields/type/type_bool.php | 21 +++++- phpBB/phpbb/profilefields/type/type_date.php | 29 ++++++++- phpBB/phpbb/profilefields/type/type_dropdown.php | 12 +++- phpBB/phpbb/profilefields/type/type_int.php | 19 +++++- phpBB/phpbb/profilefields/type/type_interface.php | 8 +++ phpBB/phpbb/profilefields/type/type_string.php | 12 +++- phpBB/phpbb/profilefields/type/type_text.php | 12 +++- 8 files changed, 112 insertions(+), 80 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index 3d9339d1d7..b34a85f9fa 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -22,10 +22,11 @@ class profilefields /** * */ - public function __construct($auth, $db, $request, $template, $user) + public function __construct($auth, $db, /** @todo: */ $phpbb_container, $request, $template, $user) { $this->auth = $auth; $this->db = $db; + $this->container = $phpbb_container; $this->request = $request; $this->template = $template; $this->user = $user; @@ -300,7 +301,8 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - $cp_data['pf_' . $row['field_ident']] = $this->get_profile_field($row); + $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]); + $cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row); $check_value = $cp_data['pf_' . $row['field_ident']]; if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false) @@ -362,7 +364,7 @@ class profilefields return; } - switch ($db->sql_layer) + switch ($this->db->sql_layer) { case 'oracle': case 'firebird': @@ -900,75 +902,4 @@ class profilefields return $cp_data; } - - /** - * Get profile field value on submit - * @access private - */ - function get_profile_field($profile_row) - { - $var_name = 'pf_' . $profile_row['field_ident']; - - switch ($profile_row['field_type']) - { - case FIELD_DATE: - - if (!isset($_REQUEST[$var_name . '_day'])) - { - if ($profile_row['field_default_value'] == 'now') - { - $now = getdate(); - $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); - } - list($day, $month, $year) = explode('-', $profile_row['field_default_value']); - } - else - { - $day = request_var($var_name . '_day', 0); - $month = request_var($var_name . '_month', 0); - $year = request_var($var_name . '_year', 0); - } - - $var = sprintf('%2d-%2d-%4d', $day, $month, $year); - break; - - case FIELD_BOOL: - // Checkbox - if ($profile_row['field_length'] == 2) - { - $var = (isset($_REQUEST[$var_name])) ? 1 : 0; - } - else - { - $var = request_var($var_name, (int) $profile_row['field_default_value']); - } - break; - - case FIELD_STRING: - case FIELD_TEXT: - $var = utf8_normalize_nfc(request_var($var_name, (string) $profile_row['field_default_value'], true)); - break; - - case FIELD_INT: - if (isset($_REQUEST[$var_name]) && $this->request->variable($var_name, '') === '') - { - $var = NULL; - } - else - { - $var = request_var($var_name, (int) $profile_row['field_default_value']); - } - break; - - case FIELD_DROPDOWN: - $var = request_var($var_name, (int) $profile_row['field_default_value']); - break; - - default: - $var = request_var($var_name, $profile_row['field_default_value']); - break; - } - - return $var; - } } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index b3dafa30d4..31d1c7d780 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -14,9 +14,10 @@ class type_bool implements type_interface /** * */ - public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user) + public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user) { $this->profilefields = $profilefields; + $this->request = $request; $this->user = $user; } @@ -60,4 +61,22 @@ class type_bool implements type_interface 'field_default_value' => 0, ); } + + /** + * {@inheritDoc} + */ + public function get_profile_field($profile_row) + { + $var_name = 'pf_' . $profile_row['field_ident']; + + // Checkbox + if ($profile_row['field_length'] == 2) + { + return ($this->request->is_set($var_name)) ? 1 : 0; + } + else + { + return $this->request->variable($var_name, (int) $profile_row['field_default_value']); + } + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 9639b45770..f5b5182222 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -14,9 +14,10 @@ class type_date implements type_interface /** * */ - public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user) + public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user) { $this->profilefields = $profilefields; + $this->request = $request; $this->user = $user; } @@ -68,4 +69,30 @@ class type_date implements type_interface 'field_default_value' => ' 0- 0- 0', ); } + + /** + * {@inheritDoc} + */ + public function get_profile_field($profile_row) + { + $var_name = 'pf_' . $profile_row['field_ident']; + + if (!$this->request->is_set($var_name . '_day')) + { + if ($profile_row['field_default_value'] == 'now') + { + $now = getdate(); + $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); + } + list($day, $month, $year) = explode('-', $profile_row['field_default_value']); + } + else + { + $day = $this->request->variable($var_name . '_day', 0); + $month = $this->request->variable($var_name . '_month', 0); + $year = $this->request->variable($var_name . '_year', 0); + } + + return sprintf('%2d-%2d-%4d', $day, $month, $year); + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 8a101f1fc1..7324ef3ee7 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -14,9 +14,10 @@ class type_dropdown implements type_interface /** * */ - public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user) + public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user) { $this->profilefields = $profilefields; + $this->request = $request; $this->user = $user; } @@ -64,4 +65,13 @@ class type_dropdown implements type_interface 'field_default_value' => 0, ); } + + /** + * {@inheritDoc} + */ + public function get_profile_field($profile_row) + { + $var_name = 'pf_' . $profile_row['field_ident']; + return $this->request->variable($var_name, (int) $profile_row['field_default_value']); + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 7cc74b6e44..c40d137a2b 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -14,8 +14,9 @@ class type_int implements type_interface /** * */ - public function __construct($user) + public function __construct(\phpbb\request\request $request, \phpbb\user $user) { + $this->request = $request; $this->user = $user; } @@ -48,4 +49,20 @@ class type_int implements type_interface 'field_default_value' => 0, ); } + + /** + * {@inheritDoc} + */ + public function get_profile_field($profile_row) + { + $var_name = 'pf_' . $profile_row['field_ident']; + if ($this->request->is_set($var_name) && $this->request->variable($var_name, '') === '') + { + return null; + } + else + { + return $this->request->variable($var_name, (int) $profile_row['field_default_value']); + } + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 8b011aa48e..f3ca903e30 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -36,4 +36,12 @@ interface type_interface * @return array with values like default field size and more */ public function get_default_values(); + + /** + * Get profile field value on submit + * + * @param array $profile_row Array with data for this field + * @return mixed Submitted value of the profile field + */ + public function get_profile_field($profile_row); } diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index c7f9d188ae..64b0660e6e 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -14,8 +14,9 @@ class type_string extends type_string_common implements type_interface /** * */ - public function __construct($user) + public function __construct(\phpbb\request\request $request, \phpbb\user $user) { + $this->request = $request; $this->user = $user; } @@ -48,4 +49,13 @@ class type_string extends type_string_common implements type_interface '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); + } } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 4b58ef0486..8fff2c917a 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -14,8 +14,9 @@ class type_text extends type_string_common implements type_interface /** * */ - public function __construct($user) + public function __construct(\phpbb\request\request $request, \phpbb\user $user) { + $this->request = $request; $this->user = $user; } @@ -48,4 +49,13 @@ class type_text extends type_string_common implements type_interface '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); + } } -- cgit v1.2.1 From ee78aed2f1c428b4b45474098f7279402e1f1270 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 Jan 2014 10:13:47 +0100 Subject: [ticket/11201] Move validate_profile_field() to type class PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 119 +-------------------- phpBB/phpbb/profilefields/type/type_bool.php | 15 +++ phpBB/phpbb/profilefields/type/type_date.php | 34 ++++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 26 +++++ phpBB/phpbb/profilefields/type/type_int.php | 24 +++++ phpBB/phpbb/profilefields/type/type_interface.php | 9 ++ phpBB/phpbb/profilefields/type/type_string.php | 8 ++ .../profilefields/type/type_string_common.php | 40 +++++++ phpBB/phpbb/profilefields/type/type_text.php | 8 ++ 9 files changed, 165 insertions(+), 118 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index b34a85f9fa..d8ba04a862 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -88,123 +88,6 @@ class profilefields $this->db->sql_freeresult($result); } - /** - * Validate entered profile field data - * @access public - */ - function validate_profile_field($field_type, &$field_value, $field_data) - { - switch ($field_type) - { - case FIELD_DATE: - $field_validate = explode('-', $field_value); - - $day = (isset($field_validate[0])) ? (int) $field_validate[0] : 0; - $month = (isset($field_validate[1])) ? (int) $field_validate[1] : 0; - $year = (isset($field_validate[2])) ? (int) $field_validate[2] : 0; - - if ((!$day || !$month || !$year) && !$field_data['field_required']) - { - return false; - } - - if ((!$day || !$month || !$year) && $field_data['field_required']) - { - return 'FIELD_REQUIRED'; - } - - if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50) - { - return 'FIELD_INVALID_DATE'; - } - - if (checkdate($month, $day, $year) === false) - { - return 'FIELD_INVALID_DATE'; - } - break; - - case FIELD_BOOL: - $field_value = (bool) $field_value; - - if (!$field_value && $field_data['field_required']) - { - return 'FIELD_REQUIRED'; - } - break; - - case FIELD_INT: - if (trim($field_value) === '' && !$field_data['field_required']) - { - return false; - } - - $field_value = (int) $field_value; - - if ($field_value < $field_data['field_minlen']) - { - return 'FIELD_TOO_SMALL'; - } - else if ($field_value > $field_data['field_maxlen']) - { - return 'FIELD_TOO_LARGE'; - } - break; - - case FIELD_DROPDOWN: - $field_value = (int) $field_value; - - // retrieve option lang data if necessary - if (!isset($this->options_lang[$field_data['field_id']]) || !isset($this->options_lang[$field_data['field_id']][$field_data['lang_id']]) || !sizeof($this->options_lang[$file_data['field_id']][$field_data['lang_id']])) - { - $this->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false); - } - - if (!isset($this->options_lang[$field_data['field_id']][$field_data['lang_id']][$field_value])) - { - return 'FIELD_INVALID_VALUE'; - } - - if ($field_value == $field_data['field_novalue'] && $field_data['field_required']) - { - return 'FIELD_REQUIRED'; - } - break; - - case FIELD_STRING: - case FIELD_TEXT: - if (trim($field_value) === '' && !$field_data['field_required']) - { - return false; - } - else if (trim($field_value) === '' && $field_data['field_required']) - { - return 'FIELD_REQUIRED'; - } - - if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen']) - { - return 'FIELD_TOO_SHORT'; - } - else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen']) - { - return 'FIELD_TOO_LONG'; - } - - if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*') - { - $field_validate = ($field_type == FIELD_STRING) ? $field_value : bbcode_nl2br($field_value); - if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate)) - { - return 'FIELD_INVALID_CHARS'; - } - } - break; - } - - return false; - } - /** * Build profile cache, used for display * @access private @@ -305,7 +188,7 @@ class profilefields $cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row); $check_value = $cp_data['pf_' . $row['field_ident']]; - if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false) + if (($cp_result = $profile_field->validate_profile_field($check_value, $row)) !== false) { // If not and only showing common error messages, use this one $error = ''; diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 31d1c7d780..c26e9aa160 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -79,4 +79,19 @@ class type_bool implements type_interface return $this->request->variable($var_name, (int) $profile_row['field_default_value']); } } + + /** + * {@inheritDoc} + */ + public function validate_profile_field(&$field_value, $field_data) + { + $field_value = (bool) $field_value; + + if (!$field_value && $field_data['field_required']) + { + return 'FIELD_REQUIRED'; + } + + return false; + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index f5b5182222..a9b4bc731b 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -95,4 +95,38 @@ class type_date implements type_interface return sprintf('%2d-%2d-%4d', $day, $month, $year); } + + /** + * {@inheritDoc} + */ + public function validate_profile_field(&$field_value, $field_data) + { + $field_validate = explode('-', $field_value); + + $day = (isset($field_validate[0])) ? (int) $field_validate[0] : 0; + $month = (isset($field_validate[1])) ? (int) $field_validate[1] : 0; + $year = (isset($field_validate[2])) ? (int) $field_validate[2] : 0; + + if ((!$day || !$month || !$year) && !$field_data['field_required']) + { + return false; + } + + if ((!$day || !$month || !$year) && $field_data['field_required']) + { + return 'FIELD_REQUIRED'; + } + + if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50) + { + return 'FIELD_INVALID_DATE'; + } + + if (checkdate($month, $day, $year) === false) + { + return 'FIELD_INVALID_DATE'; + } + + return false; + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 7324ef3ee7..8f2fe01d75 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -74,4 +74,30 @@ class type_dropdown implements type_interface $var_name = 'pf_' . $profile_row['field_ident']; return $this->request->variable($var_name, (int) $profile_row['field_default_value']); } + + /** + * {@inheritDoc} + */ + public function validate_profile_field(&$field_value, $field_data) + { + $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']])) + { + $this->profilefields->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])) + { + return 'FIELD_INVALID_VALUE'; + } + + if ($field_value == $field_data['field_novalue'] && $field_data['field_required']) + { + return 'FIELD_REQUIRED'; + } + + return false; + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index c40d137a2b..d27adf5696 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -65,4 +65,28 @@ class type_int implements type_interface return $this->request->variable($var_name, (int) $profile_row['field_default_value']); } } + + /** + * {@inheritDoc} + */ + public function validate_profile_field(&$field_value, $field_data) + { + if (trim($field_value) === '' && !$field_data['field_required']) + { + return false; + } + + $field_value = (int) $field_value; + + if ($field_value < $field_data['field_minlen']) + { + return 'FIELD_TOO_SMALL'; + } + else if ($field_value > $field_data['field_maxlen']) + { + return 'FIELD_TOO_LARGE'; + } + + return false; + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index f3ca903e30..3c0c479a09 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -44,4 +44,13 @@ interface type_interface * @return mixed Submitted value of the profile field */ public function get_profile_field($profile_row); + + /** + * Validate entered profile field data + * + * @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_profile_field(&$field_value, $field_data); } diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 64b0660e6e..84469749f1 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -58,4 +58,12 @@ class type_string extends type_string_common implements type_interface $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); + } } diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index dc2cd2f157..afb75f3026 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -27,4 +27,44 @@ abstract class type_string_common return $validate_options; } + + /** + * 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) === '' && !$field_data['field_required']) + { + return false; + } + else if (trim($field_value) === '' && $field_data['field_required']) + { + return 'FIELD_REQUIRED'; + } + + if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen']) + { + return 'FIELD_TOO_SHORT'; + } + else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen']) + { + return 'FIELD_TOO_LONG'; + } + + 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)) + { + return 'FIELD_INVALID_CHARS'; + } + } + + return false; + } } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 8fff2c917a..2f8fcb12f5 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -58,4 +58,12 @@ class type_text extends type_string_common implements type_interface $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); + } } -- cgit v1.2.1 From 0d79ccaaddb8c34bdf34780de104beeaf559308f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 Jan 2014 10:36:44 +0100 Subject: [ticket/11201] Move get_profile_value() to type class PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 121 +-------------------- phpBB/phpbb/profilefields/type/type_bool.php | 32 ++++++ phpBB/phpbb/profilefields/type/type_date.php | 26 +++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 35 ++++++ phpBB/phpbb/profilefields/type/type_int.php | 12 ++ phpBB/phpbb/profilefields/type/type_interface.php | 9 ++ .../profilefields/type/type_string_common.php | 16 +++ 7 files changed, 132 insertions(+), 119 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index d8ba04a862..362859d57a 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -365,7 +365,8 @@ class profilefields foreach ($profile_row as $ident => $ident_ary) { - $value = $this->get_profile_value($ident_ary); + $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]); + $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); if ($value === NULL) { @@ -399,124 +400,6 @@ class profilefields } } - /** - * Get Profile Value for display - */ - function get_profile_value($ident_ary) - { - $value = $ident_ary['value']; - $field_type = $ident_ary['data']['field_type']; - - switch ($this->profile_types[$field_type]) - { - case 'int': - if ($value === '' && !$ident_ary['data']['field_show_novalue']) - { - return NULL; - } - return (int) $value; - break; - - case 'string': - case 'text': - if (!$value && !$ident_ary['data']['field_show_novalue']) - { - return NULL; - } - - $value = make_clickable($value); - $value = censor_text($value); - $value = bbcode_nl2br($value); - return $value; - break; - - // case 'datetime': - case 'date': - $date = explode('-', $value); - $day = (isset($date[0])) ? (int) $date[0] : 0; - $month = (isset($date[1])) ? (int) $date[1] : 0; - $year = (isset($date[2])) ? (int) $date[2] : 0; - - if (!$day && !$month && !$year && !$ident_ary['data']['field_show_novalue']) - { - return NULL; - } - else if ($day && $month && $year) - { - // Date should display as the same date for every user regardless of timezone - return $this->user->create_datetime() - ->setDate($year, $month, $day) - ->setTime(0, 0, 0) - ->format($user->lang['DATE_FORMAT'], true); - } - - return $value; - break; - - case 'dropdown': - $field_id = $ident_ary['data']['field_id']; - $lang_id = $ident_ary['data']['lang_id']; - if (!isset($this->options_lang[$field_id][$lang_id])) - { - $this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); - } - - if ($value == $ident_ary['data']['field_novalue'] && !$ident_ary['data']['field_show_novalue']) - { - return NULL; - } - - $value = (int) $value; - - // User not having a value assigned - if (!isset($this->options_lang[$field_id][$lang_id][$value])) - { - if ($ident_ary['data']['field_show_novalue']) - { - $value = $ident_ary['data']['field_novalue']; - } - else - { - return NULL; - } - } - - return $this->options_lang[$field_id][$lang_id][$value]; - break; - - case 'bool': - $field_id = $ident_ary['data']['field_id']; - $lang_id = $ident_ary['data']['lang_id']; - if (!isset($this->options_lang[$field_id][$lang_id])) - { - $this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false); - } - - if (!$value && $ident_ary['data']['field_show_novalue']) - { - $value = $ident_ary['data']['field_default_value']; - } - - if ($ident_ary['data']['field_length'] == 1) - { - return (isset($this->options_lang[$field_id][$lang_id][(int) $value])) ? $this->options_lang[$field_id][$lang_id][(int) $value] : NULL; - } - else if (!$value) - { - return NULL; - } - else - { - return $this->options_lang[$field_id][$lang_id][(int) ($value) + 1]; - } - break; - - default: - trigger_error('Unknown profile type', E_USER_ERROR); - break; - } - } - /** * Get field value for registration/profile * @access private diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index c26e9aa160..7edb2ff2c6 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -94,4 +94,36 @@ class type_bool implements type_interface return false; } + + /** + * {@inheritDoc} + */ + public function get_profile_value($field_value, $field_data) + { + $field_id = $field_data['field_id']; + $lang_id = $field_data['lang_id']; + + if (!isset($this->profilefields->options_lang[$field_id][$lang_id])) + { + $this->profilefields->get_option_lang($field_id, $lang_id, FIELD_BOOL, false); + } + + if (!$field_value && $field_data['field_show_novalue']) + { + $field_value = $field_data['field_default_value']; + } + + 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; + } + else if (!$field_value) + { + return null; + } + else + { + return $this->profilefields->options_lang[$field_id][$lang_id][(int) ($field_value) + 1]; + } + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index a9b4bc731b..e7f1e9543e 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -129,4 +129,30 @@ class type_date implements type_interface return false; } + + /** + * {@inheritDoc} + */ + public function get_profile_value($field_value, $field_data) + { + $date = explode('-', $field_value); + $day = (isset($date[0])) ? (int) $date[0] : 0; + $month = (isset($date[1])) ? (int) $date[1] : 0; + $year = (isset($date[2])) ? (int) $date[2] : 0; + + if (!$day && !$month && !$year && !$field_data['field_show_novalue']) + { + return null; + } + else if ($day && $month && $year) + { + // Date should display as the same date for every user regardless of timezone + return $this->user->create_datetime() + ->setDate($year, $month, $day) + ->setTime(0, 0, 0) + ->format($user->lang['DATE_FORMAT'], true); + } + + return $field_value; + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 8f2fe01d75..cfc8b289da 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -100,4 +100,39 @@ class type_dropdown implements type_interface return false; } + + /** + * {@inheritDoc} + */ + public function get_profile_value($field_value, $field_data) + { + $field_id = $field_data['field_id']; + $lang_id = $field_data['lang_id']; + if (!isset($this->profilefields->options_lang[$field_id][$lang_id])) + { + $this->profilefields->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); + } + + if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) + { + return null; + } + + $field_value = (int) $field_value; + + // User not having a value assigned + if (!isset($this->profilefields->options_lang[$field_id][$lang_id][$field_value])) + { + if ($field_data['field_show_novalue']) + { + $field_value = $field_data['field_novalue']; + } + else + { + return null; + } + } + + return $this->profilefields->options_lang[$field_id][$lang_id][$field_value]; + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index d27adf5696..5aaa0036f7 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -89,4 +89,16 @@ class type_int implements type_interface return false; } + + /** + * {@inheritDoc} + */ + public function get_profile_value($field_value, $field_data) + { + if ($field_value === '' && !$field_data['field_show_novalue']) + { + return null; + } + return (int) $field_value; + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 3c0c479a09..57f495ec9a 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -53,4 +53,13 @@ interface type_interface * @return mixed String with key of the error language string, false otherwise */ public function validate_profile_field(&$field_value, $field_data); + + /** + * Get Profile Value for display + * + * @param mixed $field_value Field value as stored in the database + * @param array $field_data Array with requirements of the field + * @return mixed Field value to display + */ + public function get_profile_value($field_value, $field_data); } diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index afb75f3026..c026d93948 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -67,4 +67,20 @@ abstract class type_string_common return false; } + + /** + * {@inheritDoc} + */ + public function get_profile_value($field_value, $field_data) + { + if (!$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; + } } -- cgit v1.2.1 From 190c2e989a27bcd1ec9592f0d22faf32b496ed52 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 Jan 2014 10:50:12 +0100 Subject: [ticket/11201] Remove call by refernce PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_string.php | 2 +- phpBB/phpbb/profilefields/type/type_text.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 84469749f1..e477ff4ea7 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -64,6 +64,6 @@ class type_string extends type_string_common implements type_interface */ public function validate_profile_field(&$field_value, $field_data) { - return $this->validate_string_profile_field('string', &$field_value, $field_data); + return $this->validate_string_profile_field('string', $field_value, $field_data); } } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 2f8fcb12f5..f8377015aa 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -64,6 +64,6 @@ class type_text extends type_string_common implements type_interface */ public function validate_profile_field(&$field_value, $field_data) { - return $this->validate_string_profile_field('text', &$field_value, $field_data); + return $this->validate_string_profile_field('text', $field_value, $field_data); } } -- cgit v1.2.1 From d57c43d39769c7f29df85684428f6e120d65c103 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 Jan 2014 12:04:02 +0100 Subject: [ticket/11201] Move error message generation to type class PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 44 +--------------------- phpBB/phpbb/profilefields/type/type_bool.php | 2 +- phpBB/phpbb/profilefields/type/type_date.php | 6 +-- phpBB/phpbb/profilefields/type/type_dropdown.php | 4 +- phpBB/phpbb/profilefields/type/type_int.php | 4 +- phpBB/phpbb/profilefields/type/type_interface.php | 2 +- .../profilefields/type/type_string_common.php | 18 +++++++-- 7 files changed, 25 insertions(+), 55 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index 362859d57a..9edefdcca5 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -190,48 +190,8 @@ class profilefields if (($cp_result = $profile_field->validate_profile_field($check_value, $row)) !== false) { - // If not and only showing common error messages, use this one - $error = ''; - switch ($cp_result) - { - case 'FIELD_INVALID_DATE': - case 'FIELD_INVALID_VALUE': - case 'FIELD_REQUIRED': - $error = $this->user->lang($cp_result, $row['lang_name']); - break; - - case 'FIELD_TOO_SHORT': - case 'FIELD_TOO_SMALL': - $error = $this->user->lang($cp_result, (int) $row['field_minlen'], $row['lang_name']); - break; - - case 'FIELD_TOO_LONG': - case 'FIELD_TOO_LARGE': - $error = $this->user->lang($cp_result, (int) $row['field_maxlen'], $row['lang_name']); - break; - - case 'FIELD_INVALID_CHARS': - switch ($row['field_validation']) - { - case '[0-9]+': - $error = $this->user->lang($cp_result . '_NUMBERS_ONLY', $row['lang_name']); - break; - - case '[\w]+': - $error = $this->user->lang($cp_result . '_ALPHA_ONLY', $row['lang_name']); - break; - - case '[\w_\+\. \-\[\]]+': - $error = $this->user->lang($cp_result . '_SPACERS_ONLY', $row['lang_name']); - break; - } - break; - } - - if ($error != '') - { - $cp_error[] = $error; - } + // If the result is not false, it's an error message + $cp_error[] = $cp_result; } } $this->db->sql_freeresult($result); diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 7edb2ff2c6..c492e2bb81 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -89,7 +89,7 @@ class type_bool implements type_interface if (!$field_value && $field_data['field_required']) { - return 'FIELD_REQUIRED'; + return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']); } return false; diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index e7f1e9543e..48fe651d17 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -114,17 +114,17 @@ class type_date implements type_interface if ((!$day || !$month || !$year) && $field_data['field_required']) { - return 'FIELD_REQUIRED'; + return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']); } if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50) { - return 'FIELD_INVALID_DATE'; + return $this->user->lang('FIELD_INVALID_DATE', $field_data['lang_name']); } if (checkdate($month, $day, $year) === false) { - return 'FIELD_INVALID_DATE'; + return $this->user->lang('FIELD_INVALID_DATE', $field_data['lang_name']); } return false; diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index cfc8b289da..0b7ee88217 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -90,12 +90,12 @@ class type_dropdown implements type_interface if (!isset($this->profilefields->options_lang[$field_data['field_id']][$field_data['lang_id']][$field_value])) { - return 'FIELD_INVALID_VALUE'; + return $this->user->lang('FIELD_INVALID_VALUE', $field_data['lang_name']); } if ($field_value == $field_data['field_novalue'] && $field_data['field_required']) { - return 'FIELD_REQUIRED'; + return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']); } return false; diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 5aaa0036f7..0bb9d2049b 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -80,11 +80,11 @@ class type_int implements type_interface if ($field_value < $field_data['field_minlen']) { - return 'FIELD_TOO_SMALL'; + return $this->user->lang('FIELD_TOO_SMALL', (int) $row['field_minlen'], $row['lang_name']); } else if ($field_value > $field_data['field_maxlen']) { - return 'FIELD_TOO_LARGE'; + return $this->user->lang('FIELD_TOO_LARGE', (int) $row['field_maxlen'], $row['lang_name']); } return false; diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 57f495ec9a..36dfb5686f 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -50,7 +50,7 @@ interface type_interface * * @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 + * @return mixed String with the error message */ public function validate_profile_field(&$field_value, $field_data); diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index c026d93948..46e44fa85a 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -44,16 +44,16 @@ abstract class type_string_common } else if (trim($field_value) === '' && $field_data['field_required']) { - return 'FIELD_REQUIRED'; + return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']); } if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen']) { - return 'FIELD_TOO_SHORT'; + return $this->user->lang('FIELD_TOO_SHORT', (int) $row['field_minlen'], $row['lang_name']); } else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen']) { - return 'FIELD_TOO_LONG'; + return $this->user->lang('FIELD_TOO_LONG', (int) $row['field_maxlen'], $row['lang_name']); } if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*') @@ -61,7 +61,17 @@ abstract class type_string_common $field_validate = ($field_type != 'text') ? $field_value : bbcode_nl2br($field_value); if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate)) { - return 'FIELD_INVALID_CHARS'; + switch ($row['field_validation']) + { + case '[0-9]+': + return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $row['lang_name']); + + case '[\w]+': + return $this->user->lang('FIELD_INVALID_CHARS_ALPHA_ONLY', $row['lang_name']); + + case '[\w_\+\. \-\[\]]+': + return $this->user->lang('FIELD_INVALID_CHARS_SPACERS_ONLY', $row['lang_name']); + } } } -- cgit v1.2.1 From daf21fcb30c5c76c1d3f0b2a2bce8d8c1d8aed14 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 Jan 2014 12:51:32 +0100 Subject: [ticket/11201] Move generate_field() method to type class PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 207 +--------------------- phpBB/phpbb/profilefields/type/type_bool.php | 44 ++++- phpBB/phpbb/profilefields/type/type_date.php | 57 +++++- phpBB/phpbb/profilefields/type/type_dropdown.php | 32 +++- phpBB/phpbb/profilefields/type/type_int.php | 37 +++- phpBB/phpbb/profilefields/type/type_interface.php | 9 + phpBB/phpbb/profilefields/type/type_string.php | 17 +- phpBB/phpbb/profilefields/type/type_text.php | 20 ++- 8 files changed, 212 insertions(+), 211 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index 9edefdcca5..ba0baa53f0 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -360,209 +360,6 @@ class profilefields } } - /** - * Get field value for registration/profile - * @access private - */ - function get_var($field_validation, &$profile_row, $default_value, $preview) - { - $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; - $user_ident = $profile_row['field_ident']; - // checkbox - set the value to "true" if it has been set to 1 - if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2) - { - $value = (isset($_REQUEST[$profile_row['field_ident']]) && request_var($profile_row['field_ident'], $default_value) == 1) ? true : ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $default_value : $this->user->profile_fields[$user_ident]); - } - else if ($profile_row['field_type'] == FIELD_INT) - { - if (isset($_REQUEST[$profile_row['field_ident']])) - { - $value = ($this->request->variable($profile_row['field_ident'], '') === '') ? NULL : $this->request->variable($profile_row['field_ident'], $default_value); - } - else - { - if (!$preview && array_key_exists($user_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$user_ident])) - { - $value = NULL; - } - else if (!isset($this->user->profile_fields[$user_ident]) || $preview) - { - $value = $default_value; - } - else - { - $value = $this->user->profile_fields[$user_ident]; - } - } - - return (is_null($value) || $value === '') ? '' : (int) $value; - } - else - { - $value = (isset($_REQUEST[$profile_row['field_ident']])) ? request_var($profile_row['field_ident'], $default_value, true) : ((!isset($this->user->profile_fields[$user_ident]) || $preview) ? $default_value : $this->user->profile_fields[$user_ident]); - - if (gettype($value) == 'string') - { - $value = utf8_normalize_nfc($value); - } - } - - switch ($field_validation) - { - case 'int': - return (int) $value; - break; - } - - return $value; - } - - /** - * Process int-type - * @access private - */ - function generate_int($profile_row, $preview = false) - { - $profile_row['field_value'] = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); - $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); - } - - /** - * Process date-type - * @access private - */ - function generate_date($profile_row, $preview = false) - { - $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; - $user_ident = $profile_row['field_ident']; - - $now = getdate(); - - if (!isset($_REQUEST[$profile_row['field_ident'] . '_day'])) - { - if ($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])); - } - else - { - if ($preview && $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])); - } - else - { - $day = request_var($profile_row['field_ident'] . '_day', 0); - $month = request_var($profile_row['field_ident'] . '_month', 0); - $year = request_var($profile_row['field_ident'] . '_year', 0); - } - } - - $profile_row['s_day_options'] = ''; - for ($i = 1; $i < 32; $i++) - { - $profile_row['s_day_options'] .= '"; - } - - $profile_row['s_month_options'] = ''; - for ($i = 1; $i < 13; $i++) - { - $profile_row['s_month_options'] .= '"; - } - - $profile_row['s_year_options'] = ''; - for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++) - { - $profile_row['s_year_options'] .= '"; - } - unset($now); - - $profile_row['field_value'] = 0; - $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); - } - - /** - * Process bool-type - * @access private - */ - function generate_bool($profile_row, $preview = false) - { - $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); - - $profile_row['field_value'] = $value; - $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); - - if ($profile_row['field_length'] == 1) - { - if (!isset($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']])) - { - $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview); - } - - foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) - { - $this->template->assign_block_vars('bool.options', array( - 'OPTION_ID' => $option_id, - 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '', - 'VALUE' => $option_value) - ); - } - } - } - - /** - * Process string-type - * @access private - */ - function generate_string($profile_row, $preview = false) - { - $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview); - $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); - } - - /** - * Process text-type - * @access private - */ - function generate_text($profile_row, $preview = 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_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview); - $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); - } - - /** - * Process dropdown-type - * @access private - */ - function generate_dropdown($profile_row, $preview = false) - { - $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); - - if (!isset($this->options_lang[$profile_row['field_id']]) || !isset($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']])) - { - $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview); - } - - $profile_row['field_value'] = $value; - $this->template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); - - foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) - { - $this->template->assign_block_vars('dropdown.options', array( - 'OPTION_ID' => $option_id, - 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '', - 'VALUE' => $option_value) - ); - } - } - /** * Return Templated value/field. Possible values for $mode are: * change == user is able to set/enter profile values; preview == just show the value @@ -584,8 +381,8 @@ class profilefields } // Assign template variables - $type_func = 'generate_' . $this->profile_types[$profile_row['field_type']]; - $this->$type_func($profile_row, $preview); + $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$profile_row['field_type']]); + $profile_field->generate_field($profile_row, $preview); // 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 c492e2bb81..ee75578a16 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -14,10 +14,11 @@ class type_bool implements type_interface /** * */ - public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user) + public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { $this->profilefields = $profilefields; $this->request = $request; + $this->template = $template; $this->user = $user; } @@ -126,4 +127,45 @@ class type_bool implements type_interface return $this->profilefields->options_lang[$field_id][$lang_id][(int) ($field_value) + 1]; } } + + /** + * {@inheritDoc} + */ + public function generate_field($profile_row, $preview = 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]); + } + 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]); + } + + $profile_row['field_value'] = (int) $value; + $this->template->assign_block_vars('bool', array_change_key_case($profile_row, CASE_UPPER)); + + 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']])) + { + $this->profilefields->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview); + } + + foreach ($this->profilefields->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) + { + $this->template->assign_block_vars('bool.options', array( + 'OPTION_ID' => $option_id, + 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '', + 'VALUE' => $option_value) + ); + } + } + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 48fe651d17..36e82dabce 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -14,10 +14,11 @@ class type_date implements type_interface /** * */ - public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user) + public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { $this->profilefields = $profilefields; $this->request = $request; + $this->template = $template; $this->user = $user; } @@ -155,4 +156,58 @@ class type_date implements type_interface return $field_value; } + + /** + * {@inheritDoc} + */ + public function generate_field($profile_row, $preview = false) + { + $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; + + $now = getdate(); + + if (!$this->request->is_set($profile_row['field_ident'] . '_day')) + { + if ($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])); + } + else + { + if ($preview && $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])); + } + else + { + $day = $this->request->variable($profile_row['field_ident'] . '_day', 0); + $month = $this->request->variable($profile_row['field_ident'] . '_month', 0); + $year = $this->request->variable($profile_row['field_ident'] . '_year', 0); + } + } + + $profile_row['s_day_options'] = ''; + for ($i = 1; $i < 32; $i++) + { + $profile_row['s_day_options'] .= '"; + } + + $profile_row['s_month_options'] = ''; + for ($i = 1; $i < 13; $i++) + { + $profile_row['s_month_options'] .= '"; + } + + $profile_row['s_year_options'] = ''; + for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++) + { + $profile_row['s_year_options'] .= '"; + } + + $profile_row['field_value'] = 0; + $this->template->assign_block_vars('date', array_change_key_case($profile_row, CASE_UPPER)); + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 0b7ee88217..61fa8d7585 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -14,10 +14,11 @@ class type_dropdown implements type_interface /** * */ - public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user) + public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { $this->profilefields = $profilefields; $this->request = $request; + $this->template = $template; $this->user = $user; } @@ -135,4 +136,33 @@ class type_dropdown implements type_interface return $this->profilefields->options_lang[$field_id][$lang_id][$field_value]; } + + /** + * {@inheritDoc} + */ + public function generate_field($profile_row, $preview = 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]); + + 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']])) + { + $this->profilefields->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview); + } + + $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) + { + $this->template->assign_block_vars('dropdown.options', array( + 'OPTION_ID' => $option_id, + 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '', + 'VALUE' => $option_value) + ); + } + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 0bb9d2049b..7285b0f4ba 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -14,9 +14,10 @@ class type_int implements type_interface /** * */ - public function __construct(\phpbb\request\request $request, \phpbb\user $user) + public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { $this->request = $request; + $this->template = $template; $this->user = $user; } @@ -101,4 +102,38 @@ class type_int implements type_interface } return (int) $field_value; } + + /** + * {@inheritDoc} + */ + public function generate_field($profile_row, $preview = 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']; + + if ($this->request->is_set($field_ident)) + { + $value = ($this->request->variable($field_ident, '') === '') ? null : $this->request->variable($field_ident, $default_value); + } + else + { + if (!$preview && 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) + { + $value = $default_value; + } + else + { + $value = $this->user->profile_fields[$field_ident]; + } + } + + $profile_row['field_value'] = (is_null($value) || $value === '') ? '' : (int) $value; + + $this->template->assign_block_vars('int', array_change_key_case($profile_row, CASE_UPPER)); + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 36dfb5686f..92925c3023 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -62,4 +62,13 @@ interface type_interface * @return mixed Field value to display */ public function get_profile_value($field_value, $field_data); + + /** + * Generate the input field for display + * + * @param array $profile_row Array with data for this field + * @param bool $preview Do we preview the form + * @return null + */ + public function generate_field($profile_row, $preview = false); } diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index e477ff4ea7..c9929b1110 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -14,9 +14,10 @@ class type_string extends type_string_common implements type_interface /** * */ - public function __construct(\phpbb\request\request $request, \phpbb\user $user) + public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { $this->request = $request; + $this->template = $template; $this->user = $user; } @@ -66,4 +67,18 @@ class type_string extends type_string_common implements type_interface { return $this->validate_string_profile_field('string', $field_value, $field_data); } + + /** + * {@inheritDoc} + */ + public function generate_field($profile_row, $preview = 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]); + + + $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 f8377015aa..476e1d204f 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -14,9 +14,10 @@ class type_text extends type_string_common implements type_interface /** * */ - public function __construct(\phpbb\request\request $request, \phpbb\user $user) + public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { $this->request = $request; + $this->template = $template; $this->user = $user; } @@ -66,4 +67,21 @@ class type_text extends type_string_common implements type_interface { return $this->validate_string_profile_field('text', $field_value, $field_data); } + + /** + * {@inheritDoc} + */ + public function generate_field($profile_row, $preview = 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) ? $default_value : $this->user->profile_fields[$field_ident]); + + $this->template->assign_block_vars('text', array_change_key_case($profile_row, CASE_UPPER)); + } } -- cgit v1.2.1 From d601aaad263e19b47865bca56da527f4fdf504e1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 Jan 2014 13:38:24 +0100 Subject: [ticket/11201] Remove type related code from build_insert_sql_array() PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 14 ++------------ phpBB/phpbb/profilefields/type/type_bool.php | 10 +++++++++- phpBB/phpbb/profilefields/type/type_date.php | 16 +++++++++++++++- phpBB/phpbb/profilefields/type/type_dropdown.php | 10 +++++++++- phpBB/phpbb/profilefields/type/type_int.php | 16 +++++++++++++++- phpBB/phpbb/profilefields/type/type_interface.php | 12 ++++++++++-- phpBB/phpbb/profilefields/type/type_string.php | 2 +- phpBB/phpbb/profilefields/type/type_string_common.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_text.php | 2 +- 9 files changed, 70 insertions(+), 20 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index ba0baa53f0..e3201712df 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -408,18 +408,8 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - if ($row['field_default_value'] == 'now' && $row['field_type'] == FIELD_DATE) - { - $now = getdate(); - $row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); - } - else if ($row['field_default_value'] === '' && $row['field_type'] == FIELD_INT) - { - // We cannot insert an empty string into an integer column. - $row['field_default_value'] = NULL; - } - - $cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT, FIELD_STRING))) ? $row['lang_default_value'] : $row['field_default_value']; + $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]); + $cp_data['pf_' . $row['field_ident']] = $profile_field->get_default_field_value($row); } $this->db->sql_freeresult($result); diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index ee75578a16..e60806becd 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -51,7 +51,7 @@ class type_bool implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => 1, @@ -63,6 +63,14 @@ class type_bool implements type_interface ); } + /** + * {@inheritDoc} + */ + public function get_default_field_value($field_data) + { + return $field_data['field_default_value']; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 36e82dabce..7aabafcb14 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -59,7 +59,7 @@ class type_date implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => 10, @@ -71,6 +71,20 @@ class type_date implements type_interface ); } + /** + * {@inheritDoc} + */ + public function get_default_field_value($field_data) + { + if ($field_data['field_default_value'] == 'now') + { + $now = getdate(); + $field_data['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); + } + + return $field_data['field_default_value']; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 61fa8d7585..c461815426 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -55,7 +55,7 @@ class type_dropdown implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => 0, @@ -67,6 +67,14 @@ class type_dropdown implements type_interface ); } + /** + * {@inheritDoc} + */ + public function get_default_field_value($field_data) + { + return $field_data['field_default_value']; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 7285b0f4ba..f650436d21 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -39,7 +39,7 @@ class type_int implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => 5, @@ -51,6 +51,20 @@ class type_int implements type_interface ); } + /** + * {@inheritDoc} + */ + public function get_default_field_value($field_data) + { + if ($field_data['field_default_value'] === '') + { + // We cannot insert an empty string into an integer column. + return null; + } + + return $field_data['field_default_value']; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 92925c3023..d53c038d2d 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -31,11 +31,19 @@ interface type_interface public function get_options($default_lang_id, $field_data); /** - * Get default values for this type + * Get default values for the options of this type * * @return array with values like default field size and more */ - public function get_default_values(); + public function get_default_option_values(); + + /** + * Get default value for this type + * + * @param array $field_data Array with data for this field + * @return mixed default value for new users when no value is given + */ + public function get_default_field_value($field_data); /** * Get profile field value on submit diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index c9929b1110..090b5a2a54 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -39,7 +39,7 @@ class type_string extends type_string_common implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => 10, diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 46e44fa85a..02b640bb44 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -28,6 +28,14 @@ abstract class type_string_common return $validate_options; } + /** + * {@inheritDoc} + */ + public function get_default_field_value($field_data) + { + return $field_data['lang_default_value']; + } + /** * Validate entered profile field data * diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 476e1d204f..e73ffc5375 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -39,7 +39,7 @@ class type_text extends type_string_common implements type_interface /** * {@inheritDoc} */ - public function get_default_values() + public function get_default_option_values() { return array( 'field_length' => '5|80', -- cgit v1.2.1 From 9dec023632ae09dd457982db4a5e68fa3bb49887 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 Jan 2014 13:42:18 +0100 Subject: [ticket/11201] Add visibility to methods PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index e3201712df..78b408ba56 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -35,9 +35,8 @@ class profilefields /** * Assign editable fields to template, mode can be profile (for profile change) or register (for registration) * Called by ucp_profile and ucp_register - * @access public */ - function generate_profile_fields($mode, $lang_id) + public function generate_profile_fields($mode, $lang_id) { $sql_where = ''; switch ($mode) @@ -90,9 +89,8 @@ class profilefields /** * Build profile cache, used for display - * @access private */ - function build_cache() + protected function build_cache() { $this->profile_cache = array(); @@ -117,7 +115,7 @@ class profilefields /** * Get language entries for options and store them here for later use */ - function get_option_lang($field_id, $lang_id, $field_type, $preview) + public function get_option_lang($field_id, $lang_id, $field_type, $preview) { if ($preview) { @@ -148,9 +146,8 @@ class profilefields /** * Submit profile field for validation - * @access public */ - function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error) + public function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error) { $sql_where = ''; switch ($mode) @@ -200,7 +197,7 @@ class profilefields /** * Update profile field data directly */ - function update_profile_field_data($user_id, &$cp_data) + public function update_profile_field_data($user_id, &$cp_data) { if (!sizeof($cp_data)) { @@ -259,9 +256,8 @@ class profilefields /** * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template - * @access public */ - function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false) + public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false) { if ($mode == 'grab') { @@ -363,9 +359,8 @@ class profilefields /** * Return Templated value/field. Possible values for $mode are: * change == user is able to set/enter profile values; preview == just show the value - * @access private */ - function process_field_row($mode, $profile_row) + protected function process_field_row($mode, $profile_row) { $preview = ($mode == 'preview') ? true : false; @@ -391,7 +386,7 @@ class profilefields /** * Build Array for user insertion into custom profile fields table */ - function build_insert_sql_array($cp_data) + public function build_insert_sql_array($cp_data) { $sql_not_in = array(); foreach ($cp_data as $key => $null) -- cgit v1.2.1 From cd6bdc7b2719bea5c89e96efa5b175ed54a6b496 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 Jan 2014 15:08:33 +0100 Subject: [ticket/11201] Remove remaining type depending code to type class PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 10 ++++------ phpBB/phpbb/profilefields/type/type_bool.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_date.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_int.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_interface.php | 11 +++++++++++ phpBB/phpbb/profilefields/type/type_string_common.php | 8 ++++++++ 7 files changed, 55 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index 78b408ba56..e01611460b 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -72,17 +72,15 @@ class profilefields { // Return templated field $tpl_snippet = $this->process_field_row('change', $row); - - // Some types are multivalue, we can't give them a field_id as we would not know which to pick - $type = (int) $row['field_type']; + $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]); $this->template->assign_block_vars('profile_fields', array( 'LANG_NAME' => $row['lang_name'], 'LANG_EXPLAIN' => $row['lang_explain'], 'FIELD' => $tpl_snippet, - 'FIELD_ID' => ($type == FIELD_DATE || ($type == FIELD_BOOL && $row['field_length'] == '1')) ? '' : 'pf_' . $row['field_ident'], - 'S_REQUIRED' => ($row['field_required']) ? true : false) - ); + 'FIELD_ID' => $profile_field->get_field_ident($row), + 'S_REQUIRED' => ($row['field_required']) ? true : false, + )); } $this->db->sql_freeresult($result); } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index e60806becd..f4b056d3fc 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -176,4 +176,12 @@ class type_bool implements type_interface } } } + + /** + * {@inheritDoc} + */ + public function get_field_ident($field_data) + { + return ($field_data['field_length'] == '1') ? '' : 'pf_' . $field_data['field_ident']; + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 7aabafcb14..21b55874e5 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -224,4 +224,12 @@ class type_date implements type_interface $profile_row['field_value'] = 0; $this->template->assign_block_vars('date', array_change_key_case($profile_row, CASE_UPPER)); } + + /** + * {@inheritDoc} + */ + public function get_field_ident($field_data) + { + return ''; + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index c461815426..9b434fd085 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -173,4 +173,12 @@ class type_dropdown implements type_interface ); } } + + /** + * {@inheritDoc} + */ + public function get_field_ident($field_data) + { + return 'pf_' . $field_data['field_ident']; + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index f650436d21..7ac99f5b80 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -150,4 +150,12 @@ class type_int implements type_interface $this->template->assign_block_vars('int', array_change_key_case($profile_row, CASE_UPPER)); } + + /** + * {@inheritDoc} + */ + public function get_field_ident($field_data) + { + return 'pf_' . $field_data['field_ident']; + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index d53c038d2d..9c78e1956d 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -79,4 +79,15 @@ interface type_interface * @return null */ public function generate_field($profile_row, $preview = false); + + /** + * Get the ident of the field + * + * Some types are multivalue, we can't give them a field_id + * as we would not know which to pick. + * + * @param array $field_data Array with data for this field + * @return string ident of the field + */ + public function get_field_ident($field_data); } diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 02b640bb44..686c50d4db 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -101,4 +101,12 @@ abstract class type_string_common $field_value = bbcode_nl2br($field_value); return $field_value; } + + /** + * {@inheritDoc} + */ + public function get_field_ident($field_data) + { + return 'pf_' . $field_data['field_ident']; + } } -- cgit v1.2.1 From 5df7f76e6b810f08076b905f189bc7e4c3f8b8b1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 15 Jan 2014 11:40:03 +0100 Subject: [ticket/11201] Split language options into a new class Otherwise we run into a circular dependency PHPBB3-11201 --- phpBB/phpbb/profilefields/lang_helper.php | 114 ++++++++++++++++++++++ phpBB/phpbb/profilefields/profilefields.php | 37 +------ phpBB/phpbb/profilefields/type/type_bool.php | 28 +++--- phpBB/phpbb/profilefields/type/type_date.php | 10 +- phpBB/phpbb/profilefields/type/type_dropdown.php | 33 ++++--- phpBB/phpbb/profilefields/type/type_int.php | 8 +- phpBB/phpbb/profilefields/type/type_interface.php | 6 +- phpBB/phpbb/profilefields/type/type_string.php | 6 +- phpBB/phpbb/profilefields/type/type_text.php | 6 +- 9 files changed, 165 insertions(+), 83 deletions(-) create mode 100644 phpBB/phpbb/profilefields/lang_helper.php (limited to 'phpBB/phpbb/profilefields') 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 @@ +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(); /** * @@ -110,38 +109,6 @@ class profilefields $this->db->sql_freeresult($result); } - /** - * 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 */ @@ -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' => ''), - 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' => ''), 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), - 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '') + 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => ''), ); 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' => ''), 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), - 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') + 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => ''), ); 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' => ' ' . $this->user->lang['ROWS'] . '
' . $this->user->lang['COLUMNS'] . ' '), 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), - 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '') + 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => ''), ); 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)); } -- cgit v1.2.1 From 7fd5f16fa2aeeaddfe21062ffe3c4052ec5ec6c1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 15 Jan 2014 12:16:04 +0100 Subject: [ticket/11201] Use a service collection for the types instead of the container PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index 0ed63223f5..38b8600b7b 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -21,16 +21,29 @@ class profilefields /** * */ - public function __construct($auth, $db, /** @todo: */ $phpbb_container, $request, $template, $user) + public function __construct($auth, $db, $request, $template, $user) { $this->auth = $auth; $this->db = $db; - $this->container = $phpbb_container; $this->request = $request; $this->template = $template; $this->user = $user; } + /** + * Setter for the type collection + * + * We need to set the type collection later, + * in order to avoid a circular dependency + * + * @param \phpbb\di\service_collection $type_collection + * @return null + */ + public function set_type_collection(\phpbb\di\service_collection $type_collection) + { + $this->type_collection = $type_collection; + } + /** * Assign editable fields to template, mode can be profile (for profile change) or register (for registration) * Called by ucp_profile and ucp_register @@ -69,9 +82,10 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { + // Return templated field $tpl_snippet = $this->process_field_row('change', $row); - $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]); + $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; $this->template->assign_block_vars('profile_fields', array( 'LANG_NAME' => $row['lang_name'], @@ -146,7 +160,7 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]); + $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; $cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row); $check_value = $cp_data['pf_' . $row['field_ident']]; @@ -286,7 +300,7 @@ class profilefields foreach ($profile_row as $ident => $ident_ary) { - $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]); + $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); if ($value === NULL) @@ -341,7 +355,7 @@ class profilefields } // Assign template variables - $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$profile_row['field_type']]); + $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$profile_row['field_type']]]; $profile_field->generate_field($profile_row, $preview_options); // Return templated data @@ -368,7 +382,7 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]); + $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; $cp_data['pf_' . $row['field_ident']] = $profile_field->get_default_field_value($row); } $this->db->sql_freeresult($result); -- cgit v1.2.1 From 1dbc2d621861249a40633012fe33af02c097e69b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 15 Jan 2014 12:36:54 +0100 Subject: [ticket/11201] Fix dropdown tests The error message is now already the language string including the fieldname and not the language key anymore. PHPBB3-11201 --- phpBB/phpbb/profilefields/lang_helper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index ddf77f5e42..627c76e76e 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -79,16 +79,16 @@ class lang_helper */ public function is_set($field_id, $lang_id = null, $field_value = null) { - $is_set = isset($this->lang_helper->options_lang[$field_id]); + $is_set = isset($this->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]); + $is_set = isset($this->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]); + $is_set = isset($this->options_lang[$field_id][$lang_id][$field_value]); } return $is_set; @@ -106,9 +106,9 @@ class lang_helper { if (!is_null($field_value)) { - return $this->lang_helper->options_lang[$field_id][$lang_id]; + return $this->options_lang[$field_id][$lang_id]; } - return $this->lang_helper->options_lang[$field_id][$lang_id][$field_value]; + return $this->options_lang[$field_id][$lang_id][$field_value]; } } -- cgit v1.2.1 From 8e86e56120279a0522b2b05e627edde1b8a11d80 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 15 Jan 2014 15:34:17 +0100 Subject: [ticket/11201] Add database column type to type class PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 2 +- phpBB/phpbb/profilefields/type/type_bool.php | 11 ++++++++++- phpBB/phpbb/profilefields/type/type_date.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 11 ++++++++++- phpBB/phpbb/profilefields/type/type_int.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_interface.php | 7 +++++++ phpBB/phpbb/profilefields/type/type_string.php | 9 ++++++++- phpBB/phpbb/profilefields/type/type_text.php | 8 ++++++++ 8 files changed, 60 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index 38b8600b7b..a580ca2937 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -339,7 +339,7 @@ class profilefields * Return Templated value/field. Possible values for $mode are: * change == user is able to set/enter profile values; preview == just show the value */ - protected function process_field_row($mode, $profile_row) + public function process_field_row($mode, $profile_row) { $preview_options = ($mode == 'preview') ? $this->vars['lang_options'] : false; diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index f32f4a7513..6abac8c7bf 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -14,9 +14,10 @@ class type_bool implements type_interface /** * */ - public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) + public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { $this->lang_helper = $lang_helper; + $this->profilefields = $profilefields; $this->request = $request; $this->template = $template; $this->user = $user; @@ -184,4 +185,12 @@ class type_bool implements type_interface { return ($field_data['field_length'] == '1') ? '' : 'pf_' . $field_data['field_ident']; } + + /** + * {@inheritDoc} + */ + public function get_database_column_type() + { + return 'TINT:2'; + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index fda09c05e2..1fcbf2ea3e 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -232,4 +232,12 @@ class type_date implements type_interface { return ''; } + + /** + * {@inheritDoc} + */ + public function get_database_column_type() + { + return 'VCHAR:10'; + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index a3217f004c..e2b0dc646c 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -14,9 +14,10 @@ class type_dropdown implements type_interface /** * */ - public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) + public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { $this->lang_helper = $lang_helper; + $this->profilefields = $profilefields; $this->request = $request; $this->template = $template; $this->user = $user; @@ -182,4 +183,12 @@ class type_dropdown implements type_interface { return 'pf_' . $field_data['field_ident']; } + + /** + * {@inheritDoc} + */ + public function get_database_column_type() + { + return 'UINT'; + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 13e39039c3..202005008f 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -158,4 +158,12 @@ class type_int implements type_interface { return 'pf_' . $field_data['field_ident']; } + + /** + * {@inheritDoc} + */ + public function get_database_column_type() + { + return 'BINT'; + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 5b662205b3..917b95f653 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -90,4 +90,11 @@ interface type_interface * @return string ident of the field */ public function get_field_ident($field_data); + + /** + * Get the column type for the database + * + * @return string Returns the database column type + */ + public function get_database_column_type(); } diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 57edd14d62..a9d9fddfb0 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -78,7 +78,14 @@ class type_string extends type_string_common implements type_interface $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('string', array_change_key_case($profile_row, CASE_UPPER)); } + + /** + * {@inheritDoc} + */ + public function get_database_column_type() + { + return 'VCHAR'; + } } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index da1bb32859..58cc2d2741 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -84,4 +84,12 @@ class type_text extends type_string_common implements type_interface $this->template->assign_block_vars('text', array_change_key_case($profile_row, CASE_UPPER)); } + + /** + * {@inheritDoc} + */ + public function get_database_column_type() + { + return 'MTEXT'; + } } -- cgit v1.2.1 From 78603bb96d0afa0695b296013dec17485d74ea45 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 15 Jan 2014 18:25:28 +0100 Subject: [ticket/11201] Move language option determination into type class PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_bool.php | 18 ++++++++++++++++++ phpBB/phpbb/profilefields/type/type_date.php | 17 +++++++++++++++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 18 ++++++++++++++++++ phpBB/phpbb/profilefields/type/type_int.php | 17 +++++++++++++++++ phpBB/phpbb/profilefields/type/type_interface.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_string.php | 22 ++++++++++++++++++++++ phpBB/phpbb/profilefields/type/type_text.php | 22 ++++++++++++++++++++++ 7 files changed, 122 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 6abac8c7bf..f4e0ac0f86 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -193,4 +193,22 @@ class type_bool implements type_interface { return 'TINT:2'; } + + /** + * {@inheritDoc} + */ + public function get_language_options($field_data) + { + $options = array( + 'lang_name' => 'string', + 'lang_options' => 'two_options', + ); + + if ($field_data['lang_explain']) + { + $options['lang_explain'] = 'text'; + } + + return $options; + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 1fcbf2ea3e..d2a10cdd15 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -240,4 +240,21 @@ class type_date implements type_interface { return 'VCHAR:10'; } + + /** + * {@inheritDoc} + */ + public function get_language_options($field_data) + { + $options = array( + 'lang_name' => 'string', + ); + + if ($field_data['lang_explain']) + { + $options['lang_explain'] = 'text'; + } + + return $options; + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index e2b0dc646c..82c128861a 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -191,4 +191,22 @@ class type_dropdown implements type_interface { return 'UINT'; } + + /** + * {@inheritDoc} + */ + public function get_language_options($field_data) + { + $options = array( + 'lang_name' => 'string', + 'lang_options' => 'optionfield', + ); + + if ($field_data['lang_explain']) + { + $options['lang_explain'] = 'text'; + } + + return $options; + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 202005008f..a2e6f8e663 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -166,4 +166,21 @@ class type_int implements type_interface { return 'BINT'; } + + /** + * {@inheritDoc} + */ + public function get_language_options($field_data) + { + $options = array( + 'lang_name' => 'string', + ); + + if ($field_data['lang_explain']) + { + $options['lang_explain'] = 'text'; + } + + return $options; + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 917b95f653..f6f6355698 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -97,4 +97,12 @@ interface type_interface * @return string Returns the database column type */ public function get_database_column_type(); + + /** + * Get the options we need to display for the language input fields in the ACP + * + * @param array $field_data Array with data for this field + * @return array Returns the language options we need to generate + */ + public function get_language_options($field_data); } diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index a9d9fddfb0..ee2eb8b760 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -88,4 +88,26 @@ class type_string extends type_string_common implements type_interface { 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; + } } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 58cc2d2741..7aea982f6f 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -92,4 +92,26 @@ class type_text extends type_string_common implements type_interface { 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; + } } -- cgit v1.2.1 From 0bdec35cd4127cd4f1e96b9a77340580c6045423 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 Jan 2014 16:00:52 +0100 Subject: [ticket/11201] Move grabbing the input of the language options to type class PHPBB3-11201 --- phpBB/phpbb/profilefields/lang_helper.php | 10 +++++++++- phpBB/phpbb/profilefields/type/type_bool.php | 20 +++++++++++++++++++- phpBB/phpbb/profilefields/type/type_date.php | 18 ++++++++++++++++-- phpBB/phpbb/profilefields/type/type_dropdown.php | 15 ++++++++++++++- phpBB/phpbb/profilefields/type/type_int.php | 15 ++++++++++++++- phpBB/phpbb/profilefields/type/type_interface.php | 10 +++++++++- .../phpbb/profilefields/type/type_string_common.php | 13 +++++++++++++ 7 files changed, 94 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 627c76e76e..569eaaca40 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -48,6 +48,14 @@ class lang_helper foreach ($lang_options as $num => $var) { + if (!isset($this->options_lang[$field_id])) + { + $this->options_lang[$field_id] = array(); + } + if (!isset($this->options_lang[$field_id][$lang_id])) + { + $this->options_lang[$field_id][$lang_id] = array(); + } $this->options_lang[$field_id][$lang_id][($num + 1)] = $var; } } @@ -104,7 +112,7 @@ class lang_helper */ public function get($field_id, $lang_id, $field_value = null) { - if (!is_null($field_value)) + if (is_null($field_value)) { return $this->options_lang[$field_id][$lang_id]; } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index f4e0ac0f86..a3291d5ce1 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -144,7 +144,7 @@ class type_bool implements type_interface { $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']; + $default_value = $profile_row['field_default_value']; // checkbox - set the value to "true" if it has been set to 1 if ($profile_row['field_length'] == 2) @@ -211,4 +211,22 @@ class type_bool implements type_interface return $options; } + + /** + * {@inheritDoc} + */ + public function get_language_options_input($field_data) + { + $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); + $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); + $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); + + /** + * @todo check if this line is correct... + $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => array('')), true); + */ + $field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => array('')), true); + + return $field_data; + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index d2a10cdd15..c76c7e1d49 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -177,6 +177,7 @@ class type_date implements type_interface 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']; $now = getdate(); @@ -186,14 +187,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_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident])); + list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$field_ident])); } else { 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_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$user_ident])); + list($day, $month, $year) = explode('-', ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $profile_row['field_default_value'] : $this->user->profile_fields[$field_ident])); } else { @@ -257,4 +258,17 @@ class type_date implements type_interface return $options; } + + /** + * {@inheritDoc} + */ + public function get_language_options_input($field_data) + { + $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); + $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); + $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); + $field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true); + + return $field_data; + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 82c128861a..4313f0e64c 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -153,7 +153,7 @@ class type_dropdown implements type_interface { $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']; + $default_value = $profile_row['field_default_value']; $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]); @@ -209,4 +209,17 @@ class type_dropdown implements type_interface return $options; } + + /** + * {@inheritDoc} + */ + public function get_language_options_input($field_data) + { + $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); + $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); + $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); + $field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true); + + return $field_data; + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index a2e6f8e663..9901f61795 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -124,7 +124,7 @@ class type_int implements type_interface { $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']; + $default_value = $profile_row['field_default_value']; if ($this->request->is_set($field_ident)) { @@ -183,4 +183,17 @@ class type_int implements type_interface return $options; } + + /** + * {@inheritDoc} + */ + public function get_language_options_input($field_data) + { + $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); + $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); + $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); + $field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true); + + return $field_data; + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index f6f6355698..9390c4171b 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -102,7 +102,15 @@ interface type_interface * Get the options we need to display for the language input fields in the ACP * * @param array $field_data Array with data for this field - * @return array Returns the language options we need to generate + * @return array Returns the language options we need to generate */ public function get_language_options($field_data); + + /** + * Get the input for the supplied language options + * + * @param array $field_data Array with data for this field + * @return array Returns the language options we need to generate + */ + public function get_language_options_input($field_data); } diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 686c50d4db..88ca905aee 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -109,4 +109,17 @@ abstract class type_string_common { return 'pf_' . $field_data['field_ident']; } + + /** + * {@inheritDoc} + */ + public function get_language_options_input($field_data) + { + $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); + $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); + $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); + $field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true); + + return $field_data; + } } -- cgit v1.2.1 From 9653764fb15de3e3126466c98525c121a8a3ac0b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 Jan 2014 09:55:52 +0100 Subject: [ticket/11201] Move field type depending preparation of the options to class PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_bool.php | 10 ++++++++++ phpBB/phpbb/profilefields/type/type_date.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 10 ++++++++++ phpBB/phpbb/profilefields/type/type_int.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_interface.php | 9 +++++++++ phpBB/phpbb/profilefields/type/type_string_common.php | 10 ++++++++++ 6 files changed, 55 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index a3291d5ce1..f27c5af1ee 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -229,4 +229,14 @@ class type_bool implements type_interface return $field_data; } + + /** + * {@inheritDoc} + */ + public function prepare_options_form(&$exclude_options, &$visibility_options) + { + $exclude_options[1][] = 'lang_options'; + + return $this->request->variable('lang_options', array(''), true); + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index c76c7e1d49..37b8db2779 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -271,4 +271,12 @@ class type_date implements type_interface return $field_data; } + + /** + * {@inheritDoc} + */ + public function prepare_options_form(&$exclude_options, &$visibility_options) + { + return $this->request->variable('lang_options', '', true); + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 4313f0e64c..25671c88fa 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -222,4 +222,14 @@ class type_dropdown implements type_interface return $field_data; } + + /** + * {@inheritDoc} + */ + public function prepare_options_form(&$exclude_options, &$visibility_options) + { + $exclude_options[1][] = 'lang_options'; + + return $this->request->variable('lang_options', '', true); + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 9901f61795..35f021f0fa 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -196,4 +196,12 @@ class type_int implements type_interface return $field_data; } + + /** + * {@inheritDoc} + */ + public function prepare_options_form(&$exclude_options, &$visibility_options) + { + return $this->request->variable('lang_options', '', true); + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 9390c4171b..f8d5c46239 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -113,4 +113,13 @@ interface type_interface * @return array Returns the language options we need to generate */ public function get_language_options_input($field_data); + + /** + * Allows exclusion of options in single steps of the creation process + * + * @param array $exclude_options Array with options that should be excluded in the steps + * @param array $visibility_options Array with options responsible for the fields visibility + * @return mixed Returns the provided language options + */ + public function prepare_options_form(&$exclude_options, &$visibility_options); } diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 88ca905aee..a6145e910b 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -122,4 +122,14 @@ abstract class type_string_common return $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); + } } -- cgit v1.2.1 From 5e2ffe0d5cc4b7280b0bf51202cdbde4fca1e03b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 Jan 2014 10:12:30 +0100 Subject: [ticket/11201] Add abstract base class with shared methods PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_base.php | 52 ++++++++++++++++++++++ phpBB/phpbb/profilefields/type/type_bool.php | 2 +- phpBB/phpbb/profilefields/type/type_date.php | 23 +--------- phpBB/phpbb/profilefields/type/type_dropdown.php | 23 +--------- phpBB/phpbb/profilefields/type/type_int.php | 23 +--------- phpBB/phpbb/profilefields/type/type_string.php | 2 +- .../profilefields/type/type_string_common.php | 23 +--------- phpBB/phpbb/profilefields/type/type_text.php | 2 +- 8 files changed, 59 insertions(+), 91 deletions(-) create mode 100644 phpBB/phpbb/profilefields/type/type_base.php (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php new file mode 100644 index 0000000000..00e8d74327 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -0,0 +1,52 @@ +request = $request; + $this->template = $template; + $this->user = $user; + } + + /** + * {@inheritDoc} + */ + public function get_field_ident($field_data) + { + return 'pf_' . $field_data['field_ident']; + } + + /** + * {@inheritDoc} + */ + public function get_language_options_input($field_data) + { + $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); + $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); + $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); + $field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true); + + return $field_data; + } + + /** + * {@inheritDoc} + */ + public function prepare_options_form(&$exclude_options, &$visibility_options) + { + return $this->request->variable('lang_options', '', true); + } +} diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index f27c5af1ee..4cfd147ea2 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -9,7 +9,7 @@ namespace phpbb\profilefields\type; -class type_bool implements type_interface +class type_bool extends type_base { /** * diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 37b8db2779..a2c9111351 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -9,7 +9,7 @@ namespace phpbb\profilefields\type; -class type_date implements type_interface +class type_date extends type_base { /** * @@ -258,25 +258,4 @@ class type_date implements type_interface return $options; } - - /** - * {@inheritDoc} - */ - public function get_language_options_input($field_data) - { - $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); - $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); - $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); - $field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true); - - return $field_data; - } - - /** - * {@inheritDoc} - */ - public function prepare_options_form(&$exclude_options, &$visibility_options) - { - return $this->request->variable('lang_options', '', true); - } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 25671c88fa..2119443a7a 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -9,7 +9,7 @@ namespace phpbb\profilefields\type; -class type_dropdown implements type_interface +class type_dropdown extends type_base { /** * @@ -176,14 +176,6 @@ class type_dropdown implements type_interface } } - /** - * {@inheritDoc} - */ - public function get_field_ident($field_data) - { - return 'pf_' . $field_data['field_ident']; - } - /** * {@inheritDoc} */ @@ -210,19 +202,6 @@ class type_dropdown implements type_interface return $options; } - /** - * {@inheritDoc} - */ - public function get_language_options_input($field_data) - { - $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); - $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); - $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); - $field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true); - - return $field_data; - } - /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 35f021f0fa..2cd9d3b2c4 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -9,7 +9,7 @@ namespace phpbb\profilefields\type; -class type_int implements type_interface +class type_int extends type_base { /** * @@ -183,25 +183,4 @@ class type_int implements type_interface return $options; } - - /** - * {@inheritDoc} - */ - public function get_language_options_input($field_data) - { - $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); - $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); - $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); - $field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true); - - return $field_data; - } - - /** - * {@inheritDoc} - */ - public function prepare_options_form(&$exclude_options, &$visibility_options) - { - return $this->request->variable('lang_options', '', true); - } } diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index ee2eb8b760..66157ddc20 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -9,7 +9,7 @@ namespace phpbb\profilefields\type; -class type_string extends type_string_common implements type_interface +class type_string extends type_string_common { /** * diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index a6145e910b..d322099c34 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -9,7 +9,7 @@ namespace phpbb\profilefields\type; -abstract class type_string_common +abstract class type_string_common extends type_base { /** * Return possible validation options @@ -102,27 +102,6 @@ abstract class type_string_common return $field_value; } - /** - * {@inheritDoc} - */ - public function get_field_ident($field_data) - { - return 'pf_' . $field_data['field_ident']; - } - - /** - * {@inheritDoc} - */ - public function get_language_options_input($field_data) - { - $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); - $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); - $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); - $field_data['l_lang_options'] = $this->request->variable('l_lang_options', array(0 => ''), true); - - return $field_data; - } - /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 7aea982f6f..309ed88818 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -9,7 +9,7 @@ namespace phpbb\profilefields\type; -class type_text extends type_string_common implements type_interface +class type_text extends type_string_common { /** * -- cgit v1.2.1 From ae38cfaa701458aaebbc0991512d8788db07f9cb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 Jan 2014 10:20:00 +0100 Subject: [ticket/11201] Move type specific error messages to type class PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_base.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_bool.php | 13 +++++++++++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 13 +++++++++++++ phpBB/phpbb/profilefields/type/type_interface.php | 9 +++++++++ 4 files changed, 43 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 00e8d74327..976411baee 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -49,4 +49,12 @@ abstract class type_base implements type_interface { return $this->request->variable('lang_options', '', true); } + + /** + * {@inheritDoc} + */ + public function validate_options_on_submit($error, $field_data) + { + return $error; + } } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 4cfd147ea2..24319c2bfe 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -239,4 +239,17 @@ class type_bool extends type_base return $this->request->variable('lang_options', array(''), true); } + + /** + * {@inheritDoc} + */ + public function validate_options_on_submit($error, $field_data) + { + if (empty($field_data['lang_options'][0]) || empty($field_data['lang_options'][1])) + { + $error[] = $this->user->lang['NO_FIELD_ENTRIES']; + } + + return $error; + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 2119443a7a..a113b1d5ef 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -211,4 +211,17 @@ class type_dropdown extends type_base return $this->request->variable('lang_options', '', true); } + + /** + * {@inheritDoc} + */ + public function validate_options_on_submit($error, $field_data) + { + if (!sizeof($field_data['lang_options'])) + { + $error[] = $this->user->lang['NO_FIELD_ENTRIES']; + } + + return $error; + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index f8d5c46239..ad67536543 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -122,4 +122,13 @@ interface type_interface * @return mixed Returns the provided language options */ public function prepare_options_form(&$exclude_options, &$visibility_options); + + /** + * Allows exclusion of options in single steps of the creation process + * + * @param array $error Array with error messages + * @param array $field_data Array with data for this field + * @return array Array with error messages + */ + public function validate_options_on_submit($error, $field_data); } -- cgit v1.2.1 From 67f477fc8f184e5b2585bda914e2fbbabf4afcd8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 Jan 2014 13:35:38 +0100 Subject: [ticket/11201] Allow manipulating the intended variables with the type class PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_base.php | 18 ++++++++++ phpBB/phpbb/profilefields/type/type_bool.php | 44 +++++++++++++++++++++++ phpBB/phpbb/profilefields/type/type_date.php | 42 ++++++++++++++++++++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 15 ++++++++ phpBB/phpbb/profilefields/type/type_int.php | 17 +++++++++ phpBB/phpbb/profilefields/type/type_interface.php | 12 +++++++ phpBB/phpbb/profilefields/type/type_text.php | 26 ++++++++++++++ 7 files changed, 174 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 976411baee..cd03af57f7 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -57,4 +57,22 @@ abstract class type_base implements type_interface { return $error; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 3 && ($field_data[$key] || $action != 'edit') && $key == 'l_lang_options' && is_array($field_data[$key])) + { + foreach ($field_data[$key] as $lang_id => $options) + { + $field_data[$key][$lang_id] = explode("\n", $options); + } + + return $current_value; + } + + return $current_value; + } } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 24319c2bfe..acf20e93e0 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -252,4 +252,48 @@ class type_bool extends type_base return $error; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 2 && $key == 'field_default_value') + { + // 'field_length' == 1 defines radio buttons. Possible values are 1 or 2 only. + // 'field_length' == 2 defines checkbox. Possible values are 0 or 1 only. + // If we switch the type on step 2, we have to adjust field value. + // 1 is a common value for the checkbox and radio buttons. + + // Adjust unchecked checkbox value. + // If we return or save settings from 2nd/3rd page + // and the checkbox is unchecked, set the value to 0. + if ($this->request->is_set('step') && !$this->request->is_set($key)) + { + return 0; + } + + // If we switch to the checkbox type but former radio buttons value was 2, + // which is not the case for the checkbox, set it to 0 (unchecked). + if ($field_data['field_length'] == 2 && $current_value == 2) + { + return 0; + } + // If we switch to the radio buttons but the former checkbox value was 0, + // which is not the case for the radio buttons, set it to 0. + else if ($field_data['field_length'] == 1 && $current_value == 0) + { + return 2; + } + } + + if ($step == 3 && ($field_data[$key] || $action != 'edit') && $key == 'l_lang_options') + { + $field_data[$key] = $this->request->variable($key, array(0 => array('')), true); + + return $current_value; + } + + return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index a2c9111351..099d1dbb50 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -258,4 +258,46 @@ class type_date extends type_base return $options; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 2 && $key == 'field_default_value') + { + $always_now = $this->request->variable('always_now', -1); + + if ($always_now == 1 || ($always_now === -1 && $current_value == 'now')) + { + $now = getdate(); + + $field_data['field_default_value_day'] = $now['mday']; + $field_data['field_default_value_month'] = $now['mon']; + $field_data['field_default_value_year'] = $now['year']; + $current_value = 'now'; + $this->request->overwrite('field_default_value', $current_value, \phpbb\request\request_interface::POST); + } + else + { + if ($this->request->is_set('field_default_value_day')) + { + $field_data['field_default_value_day'] = $this->request->variable('field_default_value_day', 0); + $field_data['field_default_value_month'] = $this->request->variable('field_default_value_month', 0); + $field_data['field_default_value_year'] = $this->request->variable('field_default_value_year', 0); + $current_value = sprintf('%2d-%2d-%4d', $field_data['field_default_value_day'], $field_data['field_default_value_month'], $field_data['field_default_value_year']); + $this->request->overwrite('field_default_value', $current_value, \phpbb\request\request_interface::POST); + } + else + { + list($field_data['field_default_value_day'], $field_data['field_default_value_month'], $field_data['field_default_value_year']) = explode('-', $current_value); + } + } + + return $current_value; + } + + + return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); + } } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index a113b1d5ef..0bf36fcbfd 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -224,4 +224,19 @@ class type_dropdown extends type_base return $error; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 2 && $key == 'field_maxlen') + { + // Get the number of options if this key is 'field_maxlen' + return sizeof(explode("\n", $this->request->variable('lang_options', '', true))); + } + + + return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); + } } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 2cd9d3b2c4..e22b45e7a4 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -183,4 +183,21 @@ class type_int extends type_base return $options; } + + /** + * {@inheritDoc} + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step) + { + if ($step == 2 && $key == 'field_default_value') + { + // Permit an empty string + if ($action == 'create' && $this->request->variable('field_default_value', '') === '') + { + return ''; + } + } + + return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index ad67536543..7cbdd30ddf 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -131,4 +131,16 @@ interface type_interface * @return array Array with error messages */ public function validate_options_on_submit($error, $field_data); + + /** + * Allows manipulating the intended variables if needed + * + * @param string $key Name of the option + * @param string $action Currently performed action (create|edit) + * @param mixed $current_value Currently value of the option + * @param array $field_data Array with data for this field + * @param int $step Step on which the option is excluded + * @return mixed Final value of the option + */ + public function get_excluded_options($key, $action, $current_value, &$field_data, $step); } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 309ed88818..4437334d2b 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -114,4 +114,30 @@ class type_text extends type_string_common 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); + } } -- cgit v1.2.1 From af5c747f6f01e9e5c10f5b32e7336ba9fb85aeeb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 Jan 2014 14:41:01 +0100 Subject: [ticket/11201] Move preparation of hidden fields to type class PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_base.php | 20 +++++++++++++++ phpBB/phpbb/profilefields/type/type_bool.php | 30 +++++++++++++++++++++++ phpBB/phpbb/profilefields/type/type_date.php | 25 +++++++++++++++++++ phpBB/phpbb/profilefields/type/type_interface.php | 11 +++++++++ phpBB/phpbb/profilefields/type/type_text.php | 15 ++++++++++++ 5 files changed, 101 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index cd03af57f7..cb262d54a8 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -75,4 +75,24 @@ abstract class type_base implements type_interface return $current_value; } + + /** + * {@inheritDoc} + */ + public function prepare_hidden_fields($step, $key, $action, &$field_data) + { + if (!$this->request->is_set($key)) + { + // Do not set this variable, we will use the default value + return null; + } + else if ($key == 'field_ident' && isset($field_data[$key])) + { + return $field_data[$key]; + } + else + { + return $this->request->variable($key, '', true); + } + } } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index acf20e93e0..f303e40213 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -296,4 +296,34 @@ class type_bool extends type_base 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 == 'l_lang_options' && $this->request->is_set('l_lang_options')) + { + return $this->request->variable($key, array(array('')), true); + } + else if ($key == 'field_default_value') + { + return $this->request->variable($key, $field_data[$key]); + } + else + { + if (!$this->request->is_set($key)) + { + return false; + } + else if ($key == 'field_ident' && isset($field_data[$key])) + { + return $field_data[$key]; + } + else + { + return ($key == 'lang_options') ? $this->request->variable($key, array(''), true) : $this->request->variable($key, '', true); + } + } + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 099d1dbb50..9c706af7a3 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -300,4 +300,29 @@ class type_date extends type_base 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_default_value') + { + $always_now = $this->request->variable('always_now', 0); + + if ($always_now) + { + return 'now'; + } + else if ($this->request->is_set'field_default_value_day')) + { + $field_data['field_default_value_day'] = $this->request->variable('field_default_value_day', 0); + $field_data['field_default_value_month'] = $this->request->variable('field_default_value_month', 0); + $field_data['field_default_value_year'] = $this->request->variable('field_default_value_year', 0); + return sprintf('%2d-%2d-%4d', $field_data['field_default_value_day'], $field_data['field_default_value_month'], $field_data['field_default_value_year']); + } + } + + return parent::prepare_hidden_fields($step, $key, $action, $field_data); + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 7cbdd30ddf..9ce975f676 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -143,4 +143,15 @@ interface type_interface * @return mixed Final value of the option */ public function get_excluded_options($key, $action, $current_value, &$field_data, $step); + + /** + * Allows manipulating the intended variables if needed + * + * @param string $key Name of the option + * @param int $step Step on which the option is hidden + * @param string $action Currently performed action (create|edit) + * @param array $field_data Array with data for this field + * @return mixed Final value of the option + */ + public function prepare_hidden_fields($step, $key, $action, &$field_data); } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 4437334d2b..60abb2e421 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -140,4 +140,19 @@ class type_text extends type_string_common 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); + } } -- cgit v1.2.1 From 74d36591e1664702b6aae58802c8d89d7bc450b4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 Jan 2014 14:56:13 +0100 Subject: [ticket/11201] Move custom template variable assignment to type class PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_base.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_bool.php | 21 +++++++++++++++++++++ phpBB/phpbb/profilefields/type/type_date.php | 2 +- phpBB/phpbb/profilefields/type/type_dropdown.php | 19 +++++++++++++++++++ phpBB/phpbb/profilefields/type/type_interface.php | 19 +++++++++---------- phpBB/phpbb/profilefields/type/type_string.php | 12 ++++++++++++ phpBB/phpbb/profilefields/type/type_text.php | 12 ++++++++++++ 7 files changed, 82 insertions(+), 11 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index cb262d54a8..2fd4c50f6b 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -95,4 +95,12 @@ abstract class type_base implements type_interface return $this->request->variable($key, '', true); } } + + /** + * {@inheritDoc} + */ + public function display_options(&$template_vars, &$field_data) + { + return; + } } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index f303e40213..016ceb6000 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -326,4 +326,25 @@ class type_bool extends type_base } } } + + /** + * {@inheritDoc} + */ + public function display_options(&$template_vars, &$field_data) + { + // Initialize these array elements if we are creating a new field + if (!sizeof($field_data['lang_options'])) + { + // No options have been defined for a boolean field. + $field_data['lang_options'][0] = ''; + $field_data['lang_options'][1] = ''; + } + + $template_vars = array_merge($template_vars, array( + 'S_BOOL' => true, + 'L_LANG_OPTIONS_EXPLAIN' => $this->user->lang['BOOL_ENTRIES_EXPLAIN'], + 'FIRST_LANG_OPTION' => $field_data['lang_options'][0], + 'SECOND_LANG_OPTION' => $field_data['lang_options'][1], + )); + } } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 9c706af7a3..301e05c9ae 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -314,7 +314,7 @@ class type_date extends type_base { return 'now'; } - else if ($this->request->is_set'field_default_value_day')) + else if ($this->request->is_set('field_default_value_day')) { $field_data['field_default_value_day'] = $this->request->variable('field_default_value_day', 0); $field_data['field_default_value_month'] = $this->request->variable('field_default_value_month', 0); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 0bf36fcbfd..95f250f444 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -239,4 +239,23 @@ class type_dropdown extends type_base return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); } + + /** + * {@inheritDoc} + */ + public function display_options(&$template_vars, &$field_data) + { + // Initialize these array elements if we are creating a new field + if (!sizeof($field_data['lang_options'])) + { + // No options have been defined for the dropdown menu + $field_data['lang_options'] = array(); + } + + $template_vars = array_merge($template_vars, array( + 'S_DROPDOWN' => true, + 'L_LANG_OPTIONS_EXPLAIN' => $this->user->lang['DROPDOWN_ENTRIES_EXPLAIN'], + 'LANG_OPTIONS' => implode("\n", $field_data['lang_options']), + )); + } } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 9ce975f676..e0c2ba824d 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -11,16 +11,6 @@ namespace phpbb\profilefields\type; interface type_interface { - /* - public function validate(&$value, $validation); - - public function prepare_for_storage($value); - - public function prepare_for_display($value); - - public function prepare_for_edit($value); - */ - /** * Get dropdown options for second step in ACP * @@ -154,4 +144,13 @@ interface type_interface * @return mixed Final value of the option */ public function prepare_hidden_fields($step, $key, $action, &$field_data); + + /** + * Allows assigning of additional template variables + * + * @param array $template_vars Template variables we are going to assign + * @param array $field_data Array with data for this field + * @return null + */ + public function display_options(&$template_vars, &$field_data); } diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 66157ddc20..9542a6256a 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -110,4 +110,16 @@ class type_string extends type_string_common 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'], + )); + } } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 60abb2e421..0ead505262 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -155,4 +155,16 @@ class type_text extends type_string_common 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'], + )); + } } -- cgit v1.2.1 From aa2f0a652ff19490def8137bc73255dff282f305 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 Jan 2014 19:33:29 +0100 Subject: [ticket/11201] Change type from integer to service name PHPBB3-11201 --- phpBB/phpbb/profilefields/lang_helper.php | 2 +- phpBB/phpbb/profilefields/profilefields.php | 15 +++++++-------- phpBB/phpbb/profilefields/type/type_base.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_bool.php | 12 ++++++++++-- phpBB/phpbb/profilefields/type/type_date.php | 10 +++++++++- phpBB/phpbb/profilefields/type/type_dropdown.php | 16 ++++++++++++---- phpBB/phpbb/profilefields/type/type_int.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_interface.php | 14 ++++++++++++++ phpBB/phpbb/profilefields/type/type_string.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_text.php | 8 ++++++++ 10 files changed, 85 insertions(+), 16 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 569eaaca40..432c0aa40b 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -65,7 +65,7 @@ class lang_helper FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id AND lang_id = $lang_id - AND field_type = $field_type + AND field_type = '" . $this->db->sql_escape($field_type) . "' ORDER BY option_id"; $result = $this->db->sql_query($sql); diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index a580ca2937..bd9765d04c 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -82,10 +82,9 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - // Return templated field $tpl_snippet = $this->process_field_row('change', $row); - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$row['field_type']]; $this->template->assign_block_vars('profile_fields', array( 'LANG_NAME' => $row['lang_name'], @@ -160,7 +159,7 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$row['field_type']]; $cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row); $check_value = $cp_data['pf_' . $row['field_ident']]; @@ -300,7 +299,7 @@ class profilefields foreach ($profile_row as $ident => $ident_ary) { - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); if ($value === NULL) @@ -349,13 +348,13 @@ class profilefields )); // empty previously filled blockvars - foreach ($this->profile_types as $field_case => $field_type) + foreach ($this->type_collection as $field_key => $field_type) { - $this->template->destroy_block_vars($field_type); + $this->template->destroy_block_vars($field_type->get_name()); } // Assign template variables - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$profile_row['field_type']]]; + $profile_field = $this->type_collection[$profile_row['field_type']]; $profile_field->generate_field($profile_row, $preview_options); // Return templated data @@ -382,7 +381,7 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$row['field_type']]; $cp_data['pf_' . $row['field_ident']] = $profile_field->get_default_field_value($row); } $this->db->sql_freeresult($result); diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 2fd4c50f6b..7aee74d9ff 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -21,6 +21,14 @@ abstract class type_base implements type_interface $this->user = $user; } + /** + * {@inheritDoc} + */ + public function get_service_name() + { + return 'profilefields.type.' . $this->get_name(); + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 016ceb6000..f466b60099 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -23,6 +23,14 @@ class type_bool extends type_base $this->user = $user; } + /** + * {@inheritDoc} + */ + public function get_name() + { + return 'bool'; + } + /** * {@inheritDoc} */ @@ -36,7 +44,7 @@ class type_bool extends type_base 'lang_id' => $default_lang_id, 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', - 'field_type' => FIELD_BOOL, + 'field_type' => $this->get_service_name(), 'field_length' => $field_data['field_length'], 'lang_options' => $field_data['lang_options'] ); @@ -163,7 +171,7 @@ class type_bool extends type_base { if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview_options); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $this->get_service_name(), $preview_options); } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 301e05c9ae..e59c959f5d 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -22,6 +22,14 @@ class type_date extends type_base $this->user = $user; } + /** + * {@inheritDoc} + */ + public function get_name() + { + return 'date'; + } + /** * {@inheritDoc} */ @@ -34,7 +42,7 @@ class type_date extends type_base 'lang_id' => $default_lang_id, 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', - 'field_type' => FIELD_DATE, + 'field_type' => $this->get_service_name(), 'field_length' => $field_data['field_length'], ); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 95f250f444..c9d0936816 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -23,6 +23,14 @@ class type_dropdown extends type_base $this->user = $user; } + /** + * {@inheritDoc} + */ + public function get_name() + { + return 'dropdown'; + } + /** * {@inheritDoc} */ @@ -36,7 +44,7 @@ class type_dropdown extends type_base 'lang_id' => $default_lang_id, 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', - 'field_type' => FIELD_DROPDOWN, + 'field_type' => $this->get_service_name(), 'lang_options' => $field_data['lang_options'], ); @@ -95,7 +103,7 @@ class type_dropdown extends type_base // retrieve option lang data if necessary if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1)) { - $this->lang_helper->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'], $this->get_service_name(), false); } if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value)) @@ -120,7 +128,7 @@ class type_dropdown extends type_base $lang_id = $field_data['lang_id']; if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); + $this->lang_helper->get_option_lang($field_id, $lang_id, $this->get_service_name(), false); } if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) @@ -159,7 +167,7 @@ class type_dropdown extends type_base if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview_options); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $this->get_service_name(), $preview_options); } $profile_row['field_value'] = (int) $value; diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index e22b45e7a4..5b5f84d41b 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -21,6 +21,14 @@ class type_int extends type_base $this->user = $user; } + /** + * {@inheritDoc} + */ + public function get_name() + { + return 'int'; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index e0c2ba824d..5a88200bad 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -11,6 +11,20 @@ namespace phpbb\profilefields\type; interface type_interface { + /** + * Get the name of the type, used for error messages and template loops + * + * @return string lowercase version of the fields type + */ + public function get_name(); + + /** + * Get the name of service representing the type + * + * @return string lowercase version of the fields type + */ + public function get_service_name(); + /** * Get dropdown options for second step in ACP * diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 9542a6256a..73563bc579 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -21,6 +21,14 @@ class type_string extends type_string_common $this->user = $user; } + /** + * {@inheritDoc} + */ + public function get_name() + { + return 'string'; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 0ead505262..1638bffcff 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -21,6 +21,14 @@ class type_text extends type_string_common $this->user = $user; } + /** + * {@inheritDoc} + */ + public function get_name() + { + return 'text'; + } + /** * {@inheritDoc} */ -- cgit v1.2.1 From 431fa7b59321376fa7ceb44ac62de30c6edb29a8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Jan 2014 12:36:18 +0100 Subject: [ticket/11201] Inject table names rather then using constants PHPBB3-11201 --- phpBB/phpbb/profilefields/lang_helper.php | 12 ++++++++++-- phpBB/phpbb/profilefields/profilefields.php | 20 ++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 432c0aa40b..cf4a248d1b 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -27,14 +27,22 @@ class lang_helper */ protected $db; + /** + * Table where the language strings are stored + * @var string + */ + protected $language_table; + /** * Construct * * @param \phpbb\db\driver\driver $db Database object + * @param string $language_table Table where the language strings are stored */ - public function __construct($db) + public function __construct($db, $language_table) { $this->db = $db; + $this->language_table = $language_table; } /** @@ -62,7 +70,7 @@ class lang_helper else { $sql = 'SELECT option_id, lang_value - FROM ' . PROFILE_FIELDS_LANG_TABLE . " + FROM ' . $this->language_table . " WHERE field_id = $field_id AND lang_id = $lang_id AND field_type = '" . $this->db->sql_escape($field_type) . "' diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index bd9765d04c..af0b733f32 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -21,13 +21,17 @@ class profilefields /** * */ - public function __construct($auth, $db, $request, $template, $user) + public function __construct($auth, $db, $request, $template, $user, $fields_table, $fields_language_table, $fields_data_table) { $this->auth = $auth; $this->db = $db; $this->request = $request; $this->template = $template; $this->user = $user; + + $this->fields_table = $fields_table; + $this->fields_language_table = $fields_language_table; + $this->fields_data_table = $fields_data_table; } /** @@ -72,7 +76,7 @@ class profilefields } $sql = 'SELECT l.*, f.* - FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f + FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . " f WHERE f.field_active = 1 $sql_where AND l.lang_id = $lang_id @@ -106,7 +110,7 @@ class profilefields // Display hidden/no_view fields for admin/moderator $sql = 'SELECT l.*, f.* - FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f + FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . ' AND f.field_active = 1 ' . ((!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) ? ' AND f.field_hide = 0 ' : '') . ' @@ -149,7 +153,7 @@ class profilefields } $sql = 'SELECT l.*, f.* - FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f + FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . " f WHERE l.lang_id = $lang_id AND f.field_active = 1 $sql_where @@ -213,7 +217,7 @@ class profilefields $cp_data_sql[$left_delim . (($this->db->sql_layer == 'firebird' || $this->db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value; } - $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . ' + $sql = 'UPDATE ' . $this->fields_data_table . ' SET ' . $this->db->sql_build_array('UPDATE', $cp_data_sql) . " WHERE user_id = $user_id"; $this->db->sql_query($sql); @@ -224,7 +228,7 @@ class profilefields $this->db->sql_return_on_error(true); - $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $this->db->sql_build_array('INSERT', $cp_data_sql); + $sql = 'INSERT INTO ' . $this->fields_data_table . ' ' . $this->db->sql_build_array('INSERT', $cp_data_sql); $this->db->sql_query($sql); $this->db->sql_return_on_error(false); @@ -255,7 +259,7 @@ class profilefields } $sql = 'SELECT * - FROM ' . PROFILE_FIELDS_DATA_TABLE . ' + FROM ' . $this->fields_data_table . ' WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_id)); $result = $this->db->sql_query($sql); @@ -373,7 +377,7 @@ class profilefields } $sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value - FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f + FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . ' ' . ((sizeof($sql_not_in)) ? ' AND ' . $this->db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . ' AND l.field_id = f.field_id'; -- cgit v1.2.1 From 876e5e5fbbf3049da2b96eacc7b13b29dd484642 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Jan 2014 12:40:12 +0100 Subject: [ticket/11201] Cast some variables to integer PHPBB3-11201 --- phpBB/phpbb/profilefields/lang_helper.php | 6 +++--- phpBB/phpbb/profilefields/profilefields.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index cf4a248d1b..7bae1bdc18 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -70,9 +70,9 @@ class lang_helper else { $sql = 'SELECT option_id, lang_value - FROM ' . $this->language_table . " - WHERE field_id = $field_id - AND lang_id = $lang_id + FROM ' . $this->language_table . ' + WHERE field_id = ' . (int) $field_id . ' + AND lang_id = ' . (int) $lang_id . " AND field_type = '" . $this->db->sql_escape($field_type) . "' ORDER BY option_id"; $result = $this->db->sql_query($sql); diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index af0b733f32..acb1e6afcb 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -79,9 +79,9 @@ class profilefields FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . " f WHERE f.field_active = 1 $sql_where - AND l.lang_id = $lang_id + AND l.lang_id = " . (int) $lang_id . ' AND l.field_id = f.field_id - ORDER BY f.field_order"; + ORDER BY f.field_order'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) @@ -153,8 +153,8 @@ class profilefields } $sql = 'SELECT l.*, f.* - FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . " f - WHERE l.lang_id = $lang_id + FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f + WHERE l.lang_id = ' . (int) $lang_id . " AND f.field_active = 1 $sql_where AND l.field_id = f.field_id @@ -218,8 +218,8 @@ class profilefields } $sql = 'UPDATE ' . $this->fields_data_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $cp_data_sql) . " - WHERE user_id = $user_id"; + SET ' . $this->db->sql_build_array('UPDATE', $cp_data_sql) . ' + WHERE user_id = ' . (int) $user_id; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows()) -- cgit v1.2.1 From 1c884d07ebd4629611a66e606e369217ffddd7d8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Jan 2014 12:44:24 +0100 Subject: [ticket/11201] Add some commas at the last array entry PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_bool.php | 8 ++++---- phpBB/phpbb/profilefields/type/type_dropdown.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index f466b60099..a44e3ee770 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -46,7 +46,7 @@ class type_bool extends type_base 'field_ident' => 'field_default_value', 'field_type' => $this->get_service_name(), 'field_length' => $field_data['field_length'], - 'lang_options' => $field_data['lang_options'] + 'lang_options' => $field_data['lang_options'], ); $options = array( @@ -180,8 +180,8 @@ class type_bool extends type_base $this->template->assign_block_vars('bool.options', array( 'OPTION_ID' => $option_id, 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '', - 'VALUE' => $option_value) - ); + 'VALUE' => $option_value, + )); } } } @@ -226,7 +226,7 @@ class type_bool extends type_base public function get_language_options_input($field_data) { $field_data['l_lang_name'] = $this->request->variable('l_lang_name', array(0 => ''), true); - $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); + $field_data['l_lang_explain'] = $this->request->variable('l_lang_explain', array(0 => ''), true); $field_data['l_lang_default_value'] = $this->request->variable('l_lang_default_value', array(0 => ''), true); /** diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index c9d0936816..3645ae773c 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -179,8 +179,8 @@ class type_dropdown extends type_base $this->template->assign_block_vars('dropdown.options', array( 'OPTION_ID' => $option_id, 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '', - 'VALUE' => $option_value) - ); + 'VALUE' => $option_value, + )); } } -- cgit v1.2.1 From 7a8818fbc6989015c0abc86c66975fafa91fa3c8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Jan 2014 12:46:48 +0100 Subject: [ticket/11201] Add visibility and remove unused variable PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index acb1e6afcb..b95940aefb 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -15,8 +15,7 @@ namespace phpbb\profilefields; */ 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(); + protected $profile_cache = array(); /** * -- cgit v1.2.1 From 7fac23839893d0a9bd278ed8bc557cbd8ce90dd9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Jan 2014 12:47:19 +0100 Subject: [ticket/11201] Update copyright in class file PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index b95940aefb..7206ffcf0b 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -2,7 +2,7 @@ /** * * @package phpBB3 -* @copyright (c) 2005 phpBB Group +* @copyright (c) 2014 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From b1bed49eae48692a5d621b9fe29187a533840c81 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Jan 2014 12:53:41 +0100 Subject: [ticket/11201] Add variables to classes and add constructor doc blocks PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_base.php | 23 +++++++++++++++ phpBB/phpbb/profilefields/type/type_bool.php | 37 ++++++++++++++++++++++++ phpBB/phpbb/profilefields/type/type_date.php | 30 +++++++++++++++++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 37 ++++++++++++++++++++++++ phpBB/phpbb/profilefields/type/type_int.php | 23 +++++++++++++++ phpBB/phpbb/profilefields/type/type_string.php | 23 +++++++++++++++ phpBB/phpbb/profilefields/type/type_text.php | 23 +++++++++++++++ 7 files changed, 196 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 7aee74d9ff..195186ec86 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -12,7 +12,30 @@ namespace phpbb\profilefields\type; abstract class type_base implements type_interface { /** + * 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) { diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index a44e3ee770..f5f9003e6f 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -12,7 +12,44 @@ namespace phpbb\profilefields\type; class type_bool extends type_base { /** + * Profile fields language helper + * @var \phpbb\profilefields\lang_helper + */ + protected $lang_helper; + + /** + * Profile fields object + * @var \phpbb\profilefields\profilefields + */ + protected $profilefields; + + /** + * 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\profilefields\lang_helper $lang_helper Profile fields language helper + * @param \phpbb\profilefields\profilefields $profilefields Profile fields object + * @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\profilefields\lang_helper $lang_helper, \phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index e59c959f5d..9b13cbac2e 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -12,7 +12,37 @@ namespace phpbb\profilefields\type; class type_date extends type_base { /** + * Profile fields object + * @var \phpbb\profilefields\profilefields + */ + protected $profilefields; + + /** + * 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\profilefields\profilefields $profilefields Profile fields object + * @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\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 3645ae773c..6bbd3f0842 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -12,7 +12,44 @@ namespace phpbb\profilefields\type; class type_dropdown extends type_base { /** + * Profile fields language helper + * @var \phpbb\profilefields\lang_helper + */ + protected $lang_helper; + + /** + * Profile fields object + * @var \phpbb\profilefields\profilefields + */ + protected $profilefields; + + /** + * 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\profilefields\lang_helper $lang_helper Profile fields language helper + * @param \phpbb\profilefields\profilefields $profilefields Profile fields object + * @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\profilefields\lang_helper $lang_helper, \phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 5b5f84d41b..8e43a6e312 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -12,7 +12,30 @@ namespace phpbb\profilefields\type; class type_int extends type_base { /** + * 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) { diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 73563bc579..8b3dd1f73d 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -12,7 +12,30 @@ 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) { diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 1638bffcff..26671d2129 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -12,7 +12,30 @@ 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) { -- cgit v1.2.1 From df85364baa440e8c244ae90235ad74400981eef5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Jan 2014 13:01:29 +0100 Subject: [ticket/11201] Remove db depending code from field class sql_build_array() should already take care of that PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 39 +++-------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index 7206ffcf0b..8b1e10e78d 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -178,56 +178,25 @@ class profilefields /** * Update profile field data directly */ - public function update_profile_field_data($user_id, &$cp_data) + public function update_profile_field_data($user_id, $cp_data) { if (!sizeof($cp_data)) { return; } - switch ($this->db->sql_layer) - { - case 'oracle': - case 'firebird': - case 'postgres': - $right_delim = $left_delim = '"'; - break; - - case 'sqlite': - case 'mssql': - case 'mssql_odbc': - case 'mssqlnative': - $right_delim = ']'; - $left_delim = '['; - break; - - case 'mysql': - case 'mysql4': - case 'mysqli': - $right_delim = $left_delim = '`'; - break; - } - - // use new array for the UPDATE; changes in the key do not affect the original array - $cp_data_sql = array(); - foreach ($cp_data as $key => $value) - { - // Firebird is case sensitive with delimiter - $cp_data_sql[$left_delim . (($this->db->sql_layer == 'firebird' || $this->db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value; - } - $sql = 'UPDATE ' . $this->fields_data_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $cp_data_sql) . ' + SET ' . $this->db->sql_build_array('UPDATE', $cp_data) . ' WHERE user_id = ' . (int) $user_id; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows()) { - $cp_data_sql['user_id'] = (int) $user_id; + $cp_data['user_id'] = (int) $user_id; $this->db->sql_return_on_error(true); - $sql = 'INSERT INTO ' . $this->fields_data_table . ' ' . $this->db->sql_build_array('INSERT', $cp_data_sql); + $sql = 'INSERT INTO ' . $this->fields_data_table . ' ' . $this->db->sql_build_array('INSERT', $cp_data); $this->db->sql_query($sql); $this->db->sql_return_on_error(false); -- cgit v1.2.1 From 197e026699e838c087b6d11a16ed6c2d9f15e0b0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Jan 2014 13:08:15 +0100 Subject: [ticket/11201] Add a method to return the translated full name of the type PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 2 +- phpBB/phpbb/profilefields/type/type_base.php | 10 +++++++++- phpBB/phpbb/profilefields/type/type_bool.php | 2 +- phpBB/phpbb/profilefields/type/type_date.php | 2 +- phpBB/phpbb/profilefields/type/type_dropdown.php | 2 +- phpBB/phpbb/profilefields/type/type_int.php | 2 +- phpBB/phpbb/profilefields/type/type_interface.php | 11 +++++++++-- phpBB/phpbb/profilefields/type/type_string.php | 2 +- phpBB/phpbb/profilefields/type/type_text.php | 2 +- 9 files changed, 25 insertions(+), 10 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index 8b1e10e78d..f63064bd56 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -322,7 +322,7 @@ class profilefields // empty previously filled blockvars foreach ($this->type_collection as $field_key => $field_type) { - $this->template->destroy_block_vars($field_type->get_name()); + $this->template->destroy_block_vars($field_type->get_name_short()); } // Assign template variables diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 195186ec86..6961d208e9 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -44,12 +44,20 @@ abstract class type_base implements type_interface $this->user = $user; } + /** + * {@inheritDoc} + */ + public function get_name() + { + return $this->user->lang('FIELD_' . strtoupper($this->get_name_short())); + } + /** * {@inheritDoc} */ public function get_service_name() { - return 'profilefields.type.' . $this->get_name(); + return 'profilefields.type.' . $this->get_name_short(); } /** diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index f5f9003e6f..68d17fb4cf 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -63,7 +63,7 @@ class type_bool extends type_base /** * {@inheritDoc} */ - public function get_name() + public function get_name_short() { return 'bool'; } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 9b13cbac2e..f874ff33c3 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -55,7 +55,7 @@ class type_date extends type_base /** * {@inheritDoc} */ - public function get_name() + public function get_name_short() { return 'date'; } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 6bbd3f0842..5596e8f172 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -63,7 +63,7 @@ class type_dropdown extends type_base /** * {@inheritDoc} */ - public function get_name() + public function get_name_short() { return 'dropdown'; } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 8e43a6e312..6ffc8fbea0 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -47,7 +47,7 @@ class type_int extends type_base /** * {@inheritDoc} */ - public function get_name() + public function get_name_short() { return 'int'; } diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 5a88200bad..7d0cf7662f 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -12,12 +12,19 @@ namespace phpbb\profilefields\type; interface type_interface { /** - * Get the name of the type, used for error messages and template loops + * Get the translated name of the type * - * @return string lowercase version of the fields type + * @return string Translated name of the field type */ public function get_name(); + /** + * Get the short name of the type, used for error messages and template loops + * + * @return string lowercase version of the fields type + */ + public function get_name_short(); + /** * Get the name of service representing the type * diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 8b3dd1f73d..12a14d9b83 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -47,7 +47,7 @@ class type_string extends type_string_common /** * {@inheritDoc} */ - public function get_name() + public function get_name_short() { return 'string'; } diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 26671d2129..660bb20ef8 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -47,7 +47,7 @@ class type_text extends type_string_common /** * {@inheritDoc} */ - public function get_name() + public function get_name_short() { return 'text'; } -- cgit v1.2.1 From f40f774b2e9b862e9dafa110db07ffe3ffaaccdf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 18 Jan 2014 13:28:17 +0100 Subject: [ticket/11201] Fix some variable names PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_date.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index f874ff33c3..335a63b3f4 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -203,7 +203,7 @@ class type_date extends type_base return $this->user->create_datetime() ->setDate($year, $month, $day) ->setTime(0, 0, 0) - ->format($user->lang['DATE_FORMAT'], true); + ->format($this->user->lang['DATE_FORMAT'], true); } return $field_value; -- cgit v1.2.1 From 0ce98d7eac4724154650e2be357fceec02c44174 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 19 Jan 2014 14:52:51 +0100 Subject: [ticket/11201] Allow translation of profile field name and explanation PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index f63064bd56..772c178c89 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -282,8 +282,8 @@ class profilefields $tpl_fields['row'] += array( 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_' . strtoupper($ident) . '_NAME' => $ident_ary['data']['lang_name'], - 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $ident_ary['data']['lang_explain'], + 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']), 'S_PROFILE_' . strtoupper($ident) => true ); @@ -291,8 +291,8 @@ class profilefields $tpl_fields['blockrow'][] = array( 'PROFILE_FIELD_VALUE' => $value, 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_FIELD_NAME' => $ident_ary['data']['lang_name'], - 'PROFILE_FIELD_EXPLAIN' => $ident_ary['data']['lang_explain'], + 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), 'S_PROFILE_' . strtoupper($ident) => true ); -- cgit v1.2.1 From ec8fd57f284cb902be4ce8bd9c6a56c9a18007ae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 19 Jan 2014 14:55:47 +0100 Subject: [ticket/11201] Add commas on last array entry PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index 772c178c89..deb2eeb036 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -285,7 +285,7 @@ class profilefields 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']), - 'S_PROFILE_' . strtoupper($ident) => true + 'S_PROFILE_' . strtoupper($ident) => true, ); $tpl_fields['blockrow'][] = array( @@ -294,7 +294,7 @@ class profilefields 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), - 'S_PROFILE_' . strtoupper($ident) => true + 'S_PROFILE_' . strtoupper($ident) => true, ); } -- cgit v1.2.1 From 4213b93cde5bb19b8d2fec43bb4043cd057beec9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 19 Jan 2014 15:00:26 +0100 Subject: [ticket/11201] Add parameters and variables to profile field class PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 47 ++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index deb2eeb036..ee5c987d36 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -15,12 +15,57 @@ namespace phpbb\profilefields; */ class profilefields { + /** + * Auth object + * @var \phpbb\auth\auth + */ + protected $auth; + + /** + * Database object + * @var \phpbb\db\driver\driver + */ + protected $db; + + /** + * Request object + * @var \phpbb\request\request + */ + protected $request; + + /** + * Template object + * @var \phpbb\template\template + */ + protected $template; + + /** + * User object + * @var \phpbb\user + */ + protected $user; + + protected $fields_table; + + protected $fields_language_table; + + protected $fields_data_table; + protected $profile_cache = array(); /** + * Construct * + * @param \phpbb\auth\auth $auth Auth object + * @param \phpbb\db\driver\driver $db Database object + * @param \phpbb\request\request $request Request object + * @param \phpbb\template\template $template Template object + * @param \phpbb\user $user User object + * @param string $fields_table + * @param string $fields_language_table + * @param string $fields_data_table */ - public function __construct($auth, $db, $request, $template, $user, $fields_table, $fields_language_table, $fields_data_table) + public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) { $this->auth = $auth; $this->db = $db; -- cgit v1.2.1 From 430a0c1c212015f142777a6a31ce056c11e98ed2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 19 Jan 2014 17:58:12 +0100 Subject: [ticket/11201] Also translate profile fields in UCP and ACP PHPBB3-11201 --- phpBB/phpbb/profilefields/profilefields.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index ee5c987d36..aec2756211 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -135,8 +135,8 @@ class profilefields $profile_field = $this->type_collection[$row['field_type']]; $this->template->assign_block_vars('profile_fields', array( - 'LANG_NAME' => $row['lang_name'], - 'LANG_EXPLAIN' => $row['lang_explain'], + 'LANG_NAME' => $this->user->lang($row['lang_name']), + 'LANG_EXPLAIN' => $this->user->lang($row['lang_explain']), 'FIELD' => $tpl_snippet, 'FIELD_ID' => $profile_field->get_field_ident($row), 'S_REQUIRED' => ($row['field_required']) ? true : false, -- cgit v1.2.1 From 7bcbdfc1b15e0d014a22c76bb1eab6ccbc3d6dc7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 2 Feb 2014 12:53:29 +0100 Subject: [ticket/11201] Rename profilefields class to manager PHPBB3-11201 --- phpBB/phpbb/profilefields/manager.php | 408 +++++++++++++++++++++++ phpBB/phpbb/profilefields/profilefields.php | 408 ----------------------- phpBB/phpbb/profilefields/type/type_bool.php | 10 +- phpBB/phpbb/profilefields/type/type_date.php | 12 +- phpBB/phpbb/profilefields/type/type_dropdown.php | 14 +- 5 files changed, 426 insertions(+), 426 deletions(-) create mode 100644 phpBB/phpbb/profilefields/manager.php delete mode 100644 phpBB/phpbb/profilefields/profilefields.php (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php new file mode 100644 index 0000000000..9f64e1dcf7 --- /dev/null +++ b/phpBB/phpbb/profilefields/manager.php @@ -0,0 +1,408 @@ +auth = $auth; + $this->db = $db; + $this->request = $request; + $this->template = $template; + $this->user = $user; + + $this->fields_table = $fields_table; + $this->fields_language_table = $fields_language_table; + $this->fields_data_table = $fields_data_table; + } + + /** + * Setter for the type collection + * + * We need to set the type collection later, + * in order to avoid a circular dependency + * + * @param \phpbb\di\service_collection $type_collection + * @return null + */ + public function set_type_collection(\phpbb\di\service_collection $type_collection) + { + $this->type_collection = $type_collection; + } + + /** + * Assign editable fields to template, mode can be profile (for profile change) or register (for registration) + * Called by ucp_profile and ucp_register + */ + public function generate_profile_fields($mode, $lang_id) + { + $sql_where = ''; + switch ($mode) + { + case 'register': + // If the field is required we show it on the registration page + $sql_where .= ' AND f.field_show_on_reg = 1'; + break; + + case 'profile': + // Show hidden fields to moderators/admins + if (!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) + { + $sql_where .= ' AND f.field_show_profile = 1'; + } + break; + + default: + trigger_error('Wrong profile mode specified', E_USER_ERROR); + break; + } + + $sql = 'SELECT l.*, f.* + FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . " f + WHERE f.field_active = 1 + $sql_where + AND l.lang_id = " . (int) $lang_id . ' + AND l.field_id = f.field_id + ORDER BY f.field_order'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + // Return templated field + $tpl_snippet = $this->process_field_row('change', $row); + $profile_field = $this->type_collection[$row['field_type']]; + + $this->template->assign_block_vars('profile_fields', array( + 'LANG_NAME' => $this->user->lang($row['lang_name']), + 'LANG_EXPLAIN' => $this->user->lang($row['lang_explain']), + 'FIELD' => $tpl_snippet, + 'FIELD_ID' => $profile_field->get_field_ident($row), + 'S_REQUIRED' => ($row['field_required']) ? true : false, + )); + } + $this->db->sql_freeresult($result); + } + + /** + * Build profile cache, used for display + */ + protected function build_cache() + { + $this->profile_cache = array(); + + // Display hidden/no_view fields for admin/moderator + $sql = 'SELECT l.*, f.* + FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f + WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . ' + AND f.field_active = 1 ' . + ((!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) ? ' AND f.field_hide = 0 ' : '') . ' + AND f.field_no_view = 0 + AND l.field_id = f.field_id + ORDER BY f.field_order'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->profile_cache[$row['field_ident']] = $row; + } + $this->db->sql_freeresult($result); + } + + /** + * Submit profile field for validation + */ + public function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error) + { + $sql_where = ''; + switch ($mode) + { + case 'register': + // If the field is required we show it on the registration page + $sql_where .= ' AND f.field_show_on_reg = 1'; + break; + + case 'profile': + // Show hidden fields to moderators/admins + if (!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) + { + $sql_where .= ' AND f.field_show_profile = 1'; + } + break; + + default: + trigger_error('Wrong profile mode specified', E_USER_ERROR); + break; + } + + $sql = 'SELECT l.*, f.* + FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f + WHERE l.lang_id = ' . (int) $lang_id . " + AND f.field_active = 1 + $sql_where + AND l.field_id = f.field_id + ORDER BY f.field_order"; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $profile_field = $this->type_collection[$row['field_type']]; + $cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row); + $check_value = $cp_data['pf_' . $row['field_ident']]; + + if (($cp_result = $profile_field->validate_profile_field($check_value, $row)) !== false) + { + // If the result is not false, it's an error message + $cp_error[] = $cp_result; + } + } + $this->db->sql_freeresult($result); + } + + /** + * Update profile field data directly + */ + public function update_profile_field_data($user_id, $cp_data) + { + if (!sizeof($cp_data)) + { + return; + } + + $sql = 'UPDATE ' . $this->fields_data_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $cp_data) . ' + WHERE user_id = ' . (int) $user_id; + $this->db->sql_query($sql); + + if (!$this->db->sql_affectedrows()) + { + $cp_data['user_id'] = (int) $user_id; + + $this->db->sql_return_on_error(true); + + $sql = 'INSERT INTO ' . $this->fields_data_table . ' ' . $this->db->sql_build_array('INSERT', $cp_data); + $this->db->sql_query($sql); + + $this->db->sql_return_on_error(false); + } + } + + /** + * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) + * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template + */ + public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false) + { + if ($mode == 'grab') + { + if (!is_array($user_id)) + { + $user_id = array($user_id); + } + + if (!sizeof($this->profile_cache)) + { + $this->build_cache(); + } + + if (!sizeof($user_id)) + { + return array(); + } + + $sql = 'SELECT * + FROM ' . $this->fields_data_table . ' + WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_id)); + $result = $this->db->sql_query($sql); + + $field_data = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $field_data[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + + $user_fields = array(); + + $user_ids = $user_id; + + // Go through the fields in correct order + foreach (array_keys($this->profile_cache) as $used_ident) + { + foreach ($field_data as $user_id => $row) + { + $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident]; + $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident]; + } + + foreach ($user_ids as $user_id) + { + if (!isset($user_fields[$user_id][$used_ident]) && $this->profile_cache[$used_ident]['field_show_novalue']) + { + $user_fields[$user_id][$used_ident]['value'] = ''; + $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident]; + } + } + } + + return $user_fields; + } + else if ($mode == 'show') + { + // $profile_row == $user_fields[$row['user_id']]; + $tpl_fields = array(); + $tpl_fields['row'] = $tpl_fields['blockrow'] = array(); + + foreach ($profile_row as $ident => $ident_ary) + { + $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; + $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); + + if ($value === NULL) + { + continue; + } + + $tpl_fields['row'] += array( + 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, + 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']), + + 'S_PROFILE_' . strtoupper($ident) => true, + ); + + $tpl_fields['blockrow'][] = array( + 'PROFILE_FIELD_VALUE' => $value, + 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), + + 'S_PROFILE_' . strtoupper($ident) => true, + ); + } + + return $tpl_fields; + } + else + { + trigger_error('Wrong mode for custom profile', E_USER_ERROR); + } + } + + /** + * Return Templated value/field. Possible values for $mode are: + * change == user is able to set/enter profile values; preview == just show the value + */ + public function process_field_row($mode, $profile_row) + { + $preview_options = ($mode == 'preview') ? $this->vars['lang_options'] : false; + + // set template filename + $this->template->set_filenames(array( + 'cp_body' => 'custom_profile_fields.html', + )); + + // empty previously filled blockvars + foreach ($this->type_collection as $field_key => $field_type) + { + $this->template->destroy_block_vars($field_type->get_name_short()); + } + + // Assign template variables + $profile_field = $this->type_collection[$profile_row['field_type']]; + $profile_field->generate_field($profile_row, $preview_options); + + // Return templated data + return $this->template->assign_display('cp_body'); + } + + /** + * Build Array for user insertion into custom profile fields table + */ + public function build_insert_sql_array($cp_data) + { + $sql_not_in = array(); + foreach ($cp_data as $key => $null) + { + $sql_not_in[] = (strncmp($key, 'pf_', 3) === 0) ? substr($key, 3) : $key; + } + + $sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value + FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f + WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . ' + ' . ((sizeof($sql_not_in)) ? ' AND ' . $this->db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . ' + AND l.field_id = f.field_id'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $profile_field = $this->type_collection[$row['field_type']]; + $cp_data['pf_' . $row['field_ident']] = $profile_field->get_default_field_value($row); + } + $this->db->sql_freeresult($result); + + return $cp_data; + } +} diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php deleted file mode 100644 index aec2756211..0000000000 --- a/phpBB/phpbb/profilefields/profilefields.php +++ /dev/null @@ -1,408 +0,0 @@ -auth = $auth; - $this->db = $db; - $this->request = $request; - $this->template = $template; - $this->user = $user; - - $this->fields_table = $fields_table; - $this->fields_language_table = $fields_language_table; - $this->fields_data_table = $fields_data_table; - } - - /** - * Setter for the type collection - * - * We need to set the type collection later, - * in order to avoid a circular dependency - * - * @param \phpbb\di\service_collection $type_collection - * @return null - */ - public function set_type_collection(\phpbb\di\service_collection $type_collection) - { - $this->type_collection = $type_collection; - } - - /** - * Assign editable fields to template, mode can be profile (for profile change) or register (for registration) - * Called by ucp_profile and ucp_register - */ - public function generate_profile_fields($mode, $lang_id) - { - $sql_where = ''; - switch ($mode) - { - case 'register': - // If the field is required we show it on the registration page - $sql_where .= ' AND f.field_show_on_reg = 1'; - break; - - case 'profile': - // Show hidden fields to moderators/admins - if (!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) - { - $sql_where .= ' AND f.field_show_profile = 1'; - } - break; - - default: - trigger_error('Wrong profile mode specified', E_USER_ERROR); - break; - } - - $sql = 'SELECT l.*, f.* - FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . " f - WHERE f.field_active = 1 - $sql_where - AND l.lang_id = " . (int) $lang_id . ' - AND l.field_id = f.field_id - ORDER BY f.field_order'; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - // Return templated field - $tpl_snippet = $this->process_field_row('change', $row); - $profile_field = $this->type_collection[$row['field_type']]; - - $this->template->assign_block_vars('profile_fields', array( - 'LANG_NAME' => $this->user->lang($row['lang_name']), - 'LANG_EXPLAIN' => $this->user->lang($row['lang_explain']), - 'FIELD' => $tpl_snippet, - 'FIELD_ID' => $profile_field->get_field_ident($row), - 'S_REQUIRED' => ($row['field_required']) ? true : false, - )); - } - $this->db->sql_freeresult($result); - } - - /** - * Build profile cache, used for display - */ - protected function build_cache() - { - $this->profile_cache = array(); - - // Display hidden/no_view fields for admin/moderator - $sql = 'SELECT l.*, f.* - FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f - WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . ' - AND f.field_active = 1 ' . - ((!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) ? ' AND f.field_hide = 0 ' : '') . ' - AND f.field_no_view = 0 - AND l.field_id = f.field_id - ORDER BY f.field_order'; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $this->profile_cache[$row['field_ident']] = $row; - } - $this->db->sql_freeresult($result); - } - - /** - * Submit profile field for validation - */ - public function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error) - { - $sql_where = ''; - switch ($mode) - { - case 'register': - // If the field is required we show it on the registration page - $sql_where .= ' AND f.field_show_on_reg = 1'; - break; - - case 'profile': - // Show hidden fields to moderators/admins - if (!$this->auth->acl_gets('a_', 'm_') && !$this->auth->acl_getf_global('m_')) - { - $sql_where .= ' AND f.field_show_profile = 1'; - } - break; - - default: - trigger_error('Wrong profile mode specified', E_USER_ERROR); - break; - } - - $sql = 'SELECT l.*, f.* - FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f - WHERE l.lang_id = ' . (int) $lang_id . " - AND f.field_active = 1 - $sql_where - AND l.field_id = f.field_id - ORDER BY f.field_order"; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $profile_field = $this->type_collection[$row['field_type']]; - $cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row); - $check_value = $cp_data['pf_' . $row['field_ident']]; - - if (($cp_result = $profile_field->validate_profile_field($check_value, $row)) !== false) - { - // If the result is not false, it's an error message - $cp_error[] = $cp_result; - } - } - $this->db->sql_freeresult($result); - } - - /** - * Update profile field data directly - */ - public function update_profile_field_data($user_id, $cp_data) - { - if (!sizeof($cp_data)) - { - return; - } - - $sql = 'UPDATE ' . $this->fields_data_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $cp_data) . ' - WHERE user_id = ' . (int) $user_id; - $this->db->sql_query($sql); - - if (!$this->db->sql_affectedrows()) - { - $cp_data['user_id'] = (int) $user_id; - - $this->db->sql_return_on_error(true); - - $sql = 'INSERT INTO ' . $this->fields_data_table . ' ' . $this->db->sql_build_array('INSERT', $cp_data); - $this->db->sql_query($sql); - - $this->db->sql_return_on_error(false); - } - } - - /** - * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) - * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template - */ - public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false) - { - if ($mode == 'grab') - { - if (!is_array($user_id)) - { - $user_id = array($user_id); - } - - if (!sizeof($this->profile_cache)) - { - $this->build_cache(); - } - - if (!sizeof($user_id)) - { - return array(); - } - - $sql = 'SELECT * - FROM ' . $this->fields_data_table . ' - WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_id)); - $result = $this->db->sql_query($sql); - - $field_data = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $field_data[$row['user_id']] = $row; - } - $this->db->sql_freeresult($result); - - $user_fields = array(); - - $user_ids = $user_id; - - // Go through the fields in correct order - foreach (array_keys($this->profile_cache) as $used_ident) - { - foreach ($field_data as $user_id => $row) - { - $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident]; - $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident]; - } - - foreach ($user_ids as $user_id) - { - if (!isset($user_fields[$user_id][$used_ident]) && $this->profile_cache[$used_ident]['field_show_novalue']) - { - $user_fields[$user_id][$used_ident]['value'] = ''; - $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident]; - } - } - } - - return $user_fields; - } - else if ($mode == 'show') - { - // $profile_row == $user_fields[$row['user_id']]; - $tpl_fields = array(); - $tpl_fields['row'] = $tpl_fields['blockrow'] = array(); - - foreach ($profile_row as $ident => $ident_ary) - { - $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; - $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); - - if ($value === NULL) - { - continue; - } - - $tpl_fields['row'] += array( - 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, - 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), - 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']), - - 'S_PROFILE_' . strtoupper($ident) => true, - ); - - $tpl_fields['blockrow'][] = array( - 'PROFILE_FIELD_VALUE' => $value, - 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), - 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), - - 'S_PROFILE_' . strtoupper($ident) => true, - ); - } - - return $tpl_fields; - } - else - { - trigger_error('Wrong mode for custom profile', E_USER_ERROR); - } - } - - /** - * Return Templated value/field. Possible values for $mode are: - * change == user is able to set/enter profile values; preview == just show the value - */ - public function process_field_row($mode, $profile_row) - { - $preview_options = ($mode == 'preview') ? $this->vars['lang_options'] : false; - - // set template filename - $this->template->set_filenames(array( - 'cp_body' => 'custom_profile_fields.html', - )); - - // empty previously filled blockvars - foreach ($this->type_collection as $field_key => $field_type) - { - $this->template->destroy_block_vars($field_type->get_name_short()); - } - - // Assign template variables - $profile_field = $this->type_collection[$profile_row['field_type']]; - $profile_field->generate_field($profile_row, $preview_options); - - // Return templated data - return $this->template->assign_display('cp_body'); - } - - /** - * Build Array for user insertion into custom profile fields table - */ - public function build_insert_sql_array($cp_data) - { - $sql_not_in = array(); - foreach ($cp_data as $key => $null) - { - $sql_not_in[] = (strncmp($key, 'pf_', 3) === 0) ? substr($key, 3) : $key; - } - - $sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value - FROM ' . $this->fields_language_table . ' l, ' . $this->fields_table . ' f - WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . ' - ' . ((sizeof($sql_not_in)) ? ' AND ' . $this->db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . ' - AND l.field_id = f.field_id'; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $profile_field = $this->type_collection[$row['field_type']]; - $cp_data['pf_' . $row['field_ident']] = $profile_field->get_default_field_value($row); - } - $this->db->sql_freeresult($result); - - return $cp_data; - } -} diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 68d17fb4cf..6b34d6923f 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -19,7 +19,7 @@ class type_bool extends type_base /** * Profile fields object - * @var \phpbb\profilefields\profilefields + * @var \phpbb\profilefields\manager */ protected $profilefields; @@ -45,16 +45,16 @@ class type_bool extends type_base * Construct * * @param \phpbb\profilefields\lang_helper $lang_helper Profile fields language helper - * @param \phpbb\profilefields\profilefields $profilefields Profile fields object + * @param \phpbb\profilefields\manager $manager Profile fields object * @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\profilefields\lang_helper $lang_helper, \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\profilefields\manager $manager, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { $this->lang_helper = $lang_helper; - $this->profilefields = $profilefields; + $this->manager = $manager; $this->request = $request; $this->template = $template; $this->user = $user; @@ -88,7 +88,7 @@ class type_bool extends type_base $options = array( 0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => ''), - 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->manager->process_field_row('preview', $profile_row)), ); return $options; diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 335a63b3f4..a71e6fde68 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -13,9 +13,9 @@ class type_date extends type_base { /** * Profile fields object - * @var \phpbb\profilefields\profilefields + * @var \phpbb\profilefields\manager */ - protected $profilefields; + protected $manager; /** * Request object @@ -38,15 +38,15 @@ class type_date extends type_base /** * Construct * - * @param \phpbb\profilefields\profilefields $profilefields Profile fields object + * @param \phpbb\profilefields\manager $manager Profile fields object * @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\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) + public function __construct(\phpbb\profilefields\manager $manager, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { - $this->profilefields = $profilefields; + $this->manager = $manager; $this->request = $request; $this->template = $template; $this->user = $user; @@ -87,7 +87,7 @@ class type_date extends type_base } $options = array( - 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->profilefields->process_field_row('preview', $profile_row)), + 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->manager->process_field_row('preview', $profile_row)), 1 => array('TITLE' => $this->user->lang['ALWAYS_TODAY'], 'FIELD' => ''), ); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 5596e8f172..aee19fda30 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -19,9 +19,9 @@ class type_dropdown extends type_base /** * Profile fields object - * @var \phpbb\profilefields\profilefields + * @var \phpbb\profilefields\manager */ - protected $profilefields; + protected $manager; /** * Request object @@ -45,16 +45,16 @@ class type_dropdown extends type_base * Construct * * @param \phpbb\profilefields\lang_helper $lang_helper Profile fields language helper - * @param \phpbb\profilefields\profilefields $profilefields Profile fields object + * @param \phpbb\profilefields\manager $manager Profile fields object * @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\profilefields\lang_helper $lang_helper, \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\profilefields\manager $manager, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { $this->lang_helper = $lang_helper; - $this->profilefields = $profilefields; + $this->manager = $manager; $this->request = $request; $this->template = $template; $this->user = $user; @@ -91,8 +91,8 @@ class type_dropdown extends type_base $profile_row[1]['field_default_value'] = $field_data['field_novalue']; $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])), + 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->manager->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->manager->process_field_row('preview', $profile_row[1])), ); return $options; -- cgit v1.2.1 From cacd43bfbd547d711bfdd4c424adfef9d20528e7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 2 Feb 2014 16:05:01 +0100 Subject: [ticket/11201] Remove dependency from types on the manager PHPBB3-11201 --- phpBB/phpbb/profilefields/manager.php | 53 +++++------------------- phpBB/phpbb/profilefields/type/type_base.php | 22 ++++++++++ phpBB/phpbb/profilefields/type/type_bool.php | 12 +----- phpBB/phpbb/profilefields/type/type_date.php | 12 +----- phpBB/phpbb/profilefields/type/type_dropdown.php | 14 ++----- 5 files changed, 39 insertions(+), 74 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 9f64e1dcf7..7564c920c9 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -39,6 +39,12 @@ class manager */ protected $template; + /** + * Service Collection object + * @var \phpbb\di\service_collection + */ + protected $type_collection; + /** * User object * @var \phpbb\user @@ -60,17 +66,19 @@ class manager * @param \phpbb\db\driver\driver $db Database object * @param \phpbb\request\request $request Request object * @param \phpbb\template\template $template Template object + * @param \phpbb\di\service_collection $type_collection * @param \phpbb\user $user User object * @param string $fields_table * @param string $fields_language_table * @param string $fields_data_table */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) + public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) { $this->auth = $auth; $this->db = $db; $this->request = $request; $this->template = $template; + $this->type_collection = $type_collection; $this->user = $user; $this->fields_table = $fields_table; @@ -78,20 +86,6 @@ class manager $this->fields_data_table = $fields_data_table; } - /** - * Setter for the type collection - * - * We need to set the type collection later, - * in order to avoid a circular dependency - * - * @param \phpbb\di\service_collection $type_collection - * @return null - */ - public function set_type_collection(\phpbb\di\service_collection $type_collection) - { - $this->type_collection = $type_collection; - } - /** * Assign editable fields to template, mode can be profile (for profile change) or register (for registration) * Called by ucp_profile and ucp_register @@ -131,8 +125,8 @@ class manager while ($row = $this->db->sql_fetchrow($result)) { // Return templated field - $tpl_snippet = $this->process_field_row('change', $row); $profile_field = $this->type_collection[$row['field_type']]; + $tpl_snippet = $profile_field->process_field_row('change', $row); $this->template->assign_block_vars('profile_fields', array( 'LANG_NAME' => $this->user->lang($row['lang_name']), @@ -351,33 +345,6 @@ class manager } } - /** - * Return Templated value/field. Possible values for $mode are: - * change == user is able to set/enter profile values; preview == just show the value - */ - public function process_field_row($mode, $profile_row) - { - $preview_options = ($mode == 'preview') ? $this->vars['lang_options'] : false; - - // set template filename - $this->template->set_filenames(array( - 'cp_body' => 'custom_profile_fields.html', - )); - - // empty previously filled blockvars - foreach ($this->type_collection as $field_key => $field_type) - { - $this->template->destroy_block_vars($field_type->get_name_short()); - } - - // Assign template variables - $profile_field = $this->type_collection[$profile_row['field_type']]; - $profile_field->generate_field($profile_row, $preview_options); - - // Return templated data - return $this->template->assign_display('cp_body'); - } - /** * Build Array for user insertion into custom profile fields table */ diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 6961d208e9..248a89e5ac 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -142,4 +142,26 @@ abstract class type_base implements type_interface { return; } + + /** + * Return templated value/field. Possible values for $mode are: + * change == user is able to set/enter profile values; preview == just show the value + */ + public function process_field_row($mode, $profile_row) + { + $preview_options = ($mode == 'preview') ? $profile_row['lang_options'] : false; + + // set template filename + $this->template->set_filenames(array( + 'cp_' . $this->get_name_short() . '_body' => 'custom_profile_fields.html', + )); + + // empty previously filled blockvars + $this->template->destroy_block_vars($this->get_name_short()); + + // Assign template variables + $this->generate_field($profile_row, $preview_options); + + return $this->template->assign_display('cp_' . $this->get_name_short() . '_body'); + } } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 6b34d6923f..47a5ed4992 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -17,12 +17,6 @@ class type_bool extends type_base */ protected $lang_helper; - /** - * Profile fields object - * @var \phpbb\profilefields\manager - */ - protected $profilefields; - /** * Request object * @var \phpbb\request\request @@ -45,16 +39,14 @@ class type_bool extends type_base * Construct * * @param \phpbb\profilefields\lang_helper $lang_helper Profile fields language helper - * @param \phpbb\profilefields\manager $manager Profile fields object * @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\profilefields\lang_helper $lang_helper, \phpbb\profilefields\manager $manager, \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->lang_helper = $lang_helper; - $this->manager = $manager; $this->request = $request; $this->template = $template; $this->user = $user; @@ -88,7 +80,7 @@ class type_bool extends type_base $options = array( 0 => array('TITLE' => $this->user->lang['FIELD_TYPE'], 'EXPLAIN' => $this->user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => ''), - 1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->manager->process_field_row('preview', $profile_row)), + 1 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)), ); return $options; diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index a71e6fde68..409c2e7be0 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -11,12 +11,6 @@ namespace phpbb\profilefields\type; class type_date extends type_base { - /** - * Profile fields object - * @var \phpbb\profilefields\manager - */ - protected $manager; - /** * Request object * @var \phpbb\request\request @@ -38,15 +32,13 @@ class type_date extends type_base /** * Construct * - * @param \phpbb\profilefields\manager $manager Profile fields object * @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\profilefields\manager $manager, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) + public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { - $this->manager = $manager; $this->request = $request; $this->template = $template; $this->user = $user; @@ -87,7 +79,7 @@ class type_date extends type_base } $options = array( - 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->manager->process_field_row('preview', $profile_row)), + 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)), 1 => array('TITLE' => $this->user->lang['ALWAYS_TODAY'], 'FIELD' => ''), ); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index aee19fda30..9a6545249d 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -17,12 +17,6 @@ class type_dropdown extends type_base */ protected $lang_helper; - /** - * Profile fields object - * @var \phpbb\profilefields\manager - */ - protected $manager; - /** * Request object * @var \phpbb\request\request @@ -45,16 +39,14 @@ class type_dropdown extends type_base * Construct * * @param \phpbb\profilefields\lang_helper $lang_helper Profile fields language helper - * @param \phpbb\profilefields\manager $manager Profile fields object * @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\profilefields\lang_helper $lang_helper, \phpbb\profilefields\manager $manager, \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->lang_helper = $lang_helper; - $this->manager = $manager; $this->request = $request; $this->template = $template; $this->user = $user; @@ -91,8 +83,8 @@ class type_dropdown extends type_base $profile_row[1]['field_default_value'] = $field_data['field_novalue']; $options = array( - 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->manager->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->manager->process_field_row('preview', $profile_row[1])), + 0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->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->process_field_row('preview', $profile_row[1])), ); return $options; -- cgit v1.2.1 From cbad102f88d285ae64e65bf10cddfdf2c615f138 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 2 Feb 2014 16:20:02 +0100 Subject: [ticket/11201] Split template file into multiple files PHPBB3-11201 --- phpBB/phpbb/profilefields/type/type_base.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 248a89e5ac..95e9b8768b 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -60,6 +60,14 @@ abstract class type_base implements type_interface return 'profilefields.type.' . $this->get_name_short(); } + /** + * {@inheritDoc} + */ + public function get_template_filename() + { + return 'profilefields/' . $this->get_name_short() . '.html'; + } + /** * {@inheritDoc} */ @@ -153,7 +161,7 @@ abstract class type_base implements type_interface // set template filename $this->template->set_filenames(array( - 'cp_' . $this->get_name_short() . '_body' => 'custom_profile_fields.html', + 'cp_body' => $this->get_template_filename(), )); // empty previously filled blockvars @@ -162,6 +170,6 @@ abstract class type_base implements type_interface // Assign template variables $this->generate_field($profile_row, $preview_options); - return $this->template->assign_display('cp_' . $this->get_name_short() . '_body'); + return $this->template->assign_display('cp_body'); } } -- cgit v1.2.1 From 6f92996d98239e93b8a6e8002b048b9afd2bf352 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Feb 2014 22:25:43 +0100 Subject: [ticket/12159] Fix codesniffer complaints due to profilefields and passwords The two PRs regarding profilefields and passwords manager that were recently merged caused a few codesniffer complaints that are fixed by these changes. PHPBB3-12159 --- phpBB/phpbb/profilefields/manager.php | 2 +- phpBB/phpbb/profilefields/type/type_date.php | 1 - phpBB/phpbb/profilefields/type/type_dropdown.php | 1 - phpBB/phpbb/profilefields/type/type_int.php | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 7564c920c9..ead978374c 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -313,7 +313,7 @@ class manager $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); - if ($value === NULL) + if ($value === null) { continue; } diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 409c2e7be0..0de80f2baf 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -327,7 +327,6 @@ class type_date extends type_base return $current_value; } - return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); } diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 9a6545249d..b5b393d91b 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -273,7 +273,6 @@ class type_dropdown extends type_base return sizeof(explode("\n", $this->request->variable('lang_options', '', true))); } - return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); } diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 6ffc8fbea0..77a4f813da 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -87,7 +87,7 @@ class type_int extends type_base */ public function get_default_field_value($field_data) { - if ($field_data['field_default_value'] === '') + if ($field_data['field_default_value'] === '') { // We cannot insert an empty string into an integer column. return null; -- cgit v1.2.1 From f97d268a79502243c6bf259cde854519eea42391 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 2 Feb 2014 18:00:17 +0100 Subject: [ticket/12115] Translate profile field name before displaying it in errors PHPBB3-12115 --- phpBB/phpbb/profilefields/type/type_base.php | 8 ++++++++ phpBB/phpbb/profilefields/type/type_bool.php | 2 +- phpBB/phpbb/profilefields/type/type_date.php | 6 +++--- phpBB/phpbb/profilefields/type/type_dropdown.php | 4 ++-- phpBB/phpbb/profilefields/type/type_int.php | 4 ++-- phpBB/phpbb/profilefields/type/type_interface.php | 9 +++++++++ phpBB/phpbb/profilefields/type/type_string_common.php | 12 ++++++------ 7 files changed, 31 insertions(+), 14 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 95e9b8768b..9c363a7b4e 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -76,6 +76,14 @@ abstract class type_base implements type_interface return 'pf_' . $field_data['field_ident']; } + /** + * {@inheritDoc} + */ + public function get_field_name($field_name) + { + return isset($this->user->lang[$field_name]) ? $this->user->lang[$field_name] : $field_name; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 47a5ed4992..fa9c0a8714 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -136,7 +136,7 @@ class type_bool extends type_base if (!$field_value && $field_data['field_required']) { - return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']); + return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name'])); } return false; diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 0de80f2baf..fc012dd97a 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -159,17 +159,17 @@ class type_date extends type_base if ((!$day || !$month || !$year) && $field_data['field_required']) { - return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']); + return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name'])); } if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50) { - return $this->user->lang('FIELD_INVALID_DATE', $field_data['lang_name']); + return $this->user->lang('FIELD_INVALID_DATE', $this->get_field_name($field_data['lang_name'])); } if (checkdate($month, $day, $year) === false) { - return $this->user->lang('FIELD_INVALID_DATE', $field_data['lang_name']); + return $this->user->lang('FIELD_INVALID_DATE', $this->get_field_name($field_data['lang_name'])); } return false; diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index b5b393d91b..bcf0ba05f9 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -137,12 +137,12 @@ class type_dropdown extends type_base 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']); + return $this->user->lang('FIELD_INVALID_VALUE', $this->get_field_name($field_data['lang_name'])); } if ($field_value == $field_data['field_novalue'] && $field_data['field_required']) { - return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']); + return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name'])); } return false; diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 77a4f813da..b89faca018 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -126,11 +126,11 @@ class type_int extends type_base if ($field_value < $field_data['field_minlen']) { - return $this->user->lang('FIELD_TOO_SMALL', (int) $row['field_minlen'], $row['lang_name']); + return $this->user->lang('FIELD_TOO_SMALL', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name'])); } else if ($field_value > $field_data['field_maxlen']) { - return $this->user->lang('FIELD_TOO_LARGE', (int) $row['field_maxlen'], $row['lang_name']); + return $this->user->lang('FIELD_TOO_LARGE', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name'])); } return false; diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 7d0cf7662f..93020935e9 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -174,4 +174,13 @@ interface type_interface * @return null */ public function display_options(&$template_vars, &$field_data); + + /** + * Return templated value/field. Possible values for $mode are: + * change == user is able to set/enter profile values; preview == just show the value + * @param string $mode + * @param array $profile_row + * @return null + */ + public function process_field_row($mode, $profile_row); } diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index d322099c34..f00a7e6a08 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -52,16 +52,16 @@ abstract class type_string_common extends type_base } else if (trim($field_value) === '' && $field_data['field_required']) { - return $this->user->lang('FIELD_REQUIRED', $field_data['lang_name']); + return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name'])); } if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen']) { - return $this->user->lang('FIELD_TOO_SHORT', (int) $row['field_minlen'], $row['lang_name']); + 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($field_value) > $field_data['field_maxlen']) { - return $this->user->lang('FIELD_TOO_LONG', (int) $row['field_maxlen'], $row['lang_name']); + 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'] != '.*') @@ -72,13 +72,13 @@ abstract class type_string_common extends type_base switch ($row['field_validation']) { case '[0-9]+': - return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $row['lang_name']); + return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $this->get_field_name($field_data['lang_name'])); case '[\w]+': - return $this->user->lang('FIELD_INVALID_CHARS_ALPHA_ONLY', $row['lang_name']); + return $this->user->lang('FIELD_INVALID_CHARS_ALPHA_ONLY', $this->get_field_name($field_data['lang_name'])); case '[\w_\+\. \-\[\]]+': - return $this->user->lang('FIELD_INVALID_CHARS_SPACERS_ONLY', $row['lang_name']); + return $this->user->lang('FIELD_INVALID_CHARS_SPACERS_ONLY', $this->get_field_name($field_data['lang_name'])); } } } -- cgit v1.2.1 From 8dab016a7b652e2a0aafe03c085d9c51ab6f3ff2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 2 Feb 2014 18:04:38 +0100 Subject: [ticket/12115] Add methods to interface PHPBB3-12115 --- phpBB/phpbb/profilefields/type/type_interface.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 93020935e9..94f6882524 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -32,6 +32,13 @@ interface type_interface */ public function get_service_name(); + /** + * Get the name of template file for this type + * + * @return string Returns the name of the template file + */ + public function get_template_filename(); + /** * Get dropdown options for second step in ACP * @@ -178,8 +185,9 @@ interface type_interface /** * Return templated value/field. Possible values for $mode are: * change == user is able to set/enter profile values; preview == just show the value - * @param string $mode - * @param array $profile_row + * + * @param string $mode Mode for displaying the field (preview|change) + * @param array $profile_row Array with data for this field * @return null */ public function process_field_row($mode, $profile_row); -- cgit v1.2.1 From 6bee91c42915dd613e9714016006b25fa51cb24a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Feb 2014 15:00:49 +0100 Subject: [ticket/12169] Convert user_from to profile field location Missing changes on memberlist view due to missing functionality PHPBB3-12169 --- phpBB/phpbb/profilefields/type/type_string.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 12a14d9b83..9d241c49ef 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -60,7 +60,7 @@ class type_string extends type_string_common $options = array( 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => ''), ); -- cgit v1.2.1 From 3c46aeb0055d88919e1438941c34b97445a17878 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Feb 2014 16:32:25 +0100 Subject: [ticket/12169] Allow displaying profile fields on memberlist We can not sort by profile field values atm. And also I'm not sure whether this is possible at all. PHPBB3-12169 --- phpBB/phpbb/profilefields/manager.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index ead978374c..3948f32e93 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -246,9 +246,35 @@ class manager * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template */ - public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false) + public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false, $restrict_option = false) { - if ($mode == 'grab') + if ($mode == 'headlines') + { + if (!sizeof($this->profile_cache)) + { + $this->build_cache(); + } + + // Go through the fields in correct order + foreach ($this->profile_cache as $field_ident => $field_data) + { + if ($restrict_option && !$field_data[$restrict_option]) + { + continue; + } + + $profile_field = $this->type_collection[$field_data['field_type']]; + + $tpl_fields[] = array( + 'PROFILE_FIELD_TYPE' => $field_data['field_type'], + 'PROFILE_FIELD_NAME' => $profile_field->get_field_name($field_data['lang_name']), + 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($field_data['lang_explain']), + ); + } + + return $tpl_fields; + } + else if ($mode == 'grab') { if (!is_array($user_id)) { -- cgit v1.2.1 From 5550f0fa870d531879d53d1bfdd76dcd29a16ce6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 10 Feb 2014 19:04:10 +0100 Subject: [ticket/12169] Split mode==headline into it's own function PHPBB3-12169 --- phpBB/phpbb/profilefields/manager.php | 53 ++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 3948f32e93..6a8d32f150 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -243,38 +243,45 @@ class manager } /** - * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) - * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template + * Generate the template arrays in order to display the column names + * + * @param string $restrict_option Restrict the published fields to a certain profile field option + * @return array Returns an array with the template variables type, name and explain for the fields to display */ - public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false, $restrict_option = false) + public function generate_profile_fields_template_headlines($restrict_option = '') { - if ($mode == 'headlines') + if (!sizeof($this->profile_cache)) { - if (!sizeof($this->profile_cache)) + $this->build_cache(); + } + + // Go through the fields in correct order + foreach ($this->profile_cache as $field_ident => $field_data) + { + if ($restrict_option && !$field_data[$restrict_option]) { - $this->build_cache(); + continue; } - // Go through the fields in correct order - foreach ($this->profile_cache as $field_ident => $field_data) - { - if ($restrict_option && !$field_data[$restrict_option]) - { - continue; - } + $profile_field = $this->type_collection[$field_data['field_type']]; - $profile_field = $this->type_collection[$field_data['field_type']]; + $tpl_fields[] = array( + 'PROFILE_FIELD_TYPE' => $field_data['field_type'], + 'PROFILE_FIELD_NAME' => $profile_field->get_field_name($field_data['lang_name']), + 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($field_data['lang_explain']), + ); + } - $tpl_fields[] = array( - 'PROFILE_FIELD_TYPE' => $field_data['field_type'], - 'PROFILE_FIELD_NAME' => $profile_field->get_field_name($field_data['lang_name']), - 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($field_data['lang_explain']), - ); - } + return $tpl_fields; + } - return $tpl_fields; - } - else if ($mode == 'grab') + /** + * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) + * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template + */ + public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false) + { + if ($mode == 'grab') { if (!is_array($user_id)) { -- cgit v1.2.1 From 30fbaab8dee3ff3890ed2b1d86bb56392b4037e0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Feb 2014 19:17:24 +0100 Subject: [ticket/12184] Fix undefined variable tpl_fields in profile field manager PHPBB3-12184 --- phpBB/phpbb/profilefields/manager.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 6a8d32f150..ac2542a6d4 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -255,6 +255,8 @@ class manager $this->build_cache(); } + $tpl_fields = array(); + // Go through the fields in correct order foreach ($this->profile_cache as $field_ident => $field_data) { -- cgit v1.2.1 From 3930978e640d6bfb870329866a079aa19745d7da Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 24 Feb 2014 10:00:45 +0100 Subject: [ticket/12216] Undefined index: lang_options when creating date profile field PHPBB3-12216 --- phpBB/phpbb/profilefields/type/type_date.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index fc012dd97a..af3d65c9b6 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -66,6 +66,7 @@ class type_date extends type_base 'field_ident' => 'field_default_value', 'field_type' => $this->get_service_name(), 'field_length' => $field_data['field_length'], + 'lang_options' => $field_data['lang_options'], ); $always_now = request_var('always_now', -1); -- cgit v1.2.1 From a823205403f2dbbd907c03e59fd232552351d566 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 28 Feb 2014 11:05:48 +0100 Subject: [ticket/12233] Allow profile fields to be contact fields Contact fields are displayed with in the contact section of the user profile and are displayed differently in the mini profile next to posts and private messages PHPBB3-12233 --- phpBB/phpbb/profilefields/manager.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index ac2542a6d4..874d0a21e0 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -353,21 +353,40 @@ class manager continue; } + $field_desc = $this->user->lang($ident_ary['data']['field_contact_desc']); + if (strpos($field_desc, '%s') !== false) + { + $field_desc = sprintf($field_desc, $value); + } + $contact_url = ''; + if (strpos($ident_ary['data']['field_contact_url'], '%s') !== false) + { + $contact_url = sprintf($ident_ary['data']['field_contact_url'], $value); + } + $tpl_fields['row'] += array( + 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, + 'PROFILE_' . strtoupper($ident) . '_CONTACT'=> $contact_url, + 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']), + 'S_PROFILE_' . strtoupper($ident) . '_CONTACT' => $ident_ary['data']['field_is_contact'], 'S_PROFILE_' . strtoupper($ident) => true, ); $tpl_fields['blockrow'][] = array( + 'PROFILE_FIELD_IDENT' => $ident, 'PROFILE_FIELD_VALUE' => $value, + 'PROFILE_FIELD_CONTACT' => $contact_url, + 'PROFILE_FIELD_DESC' => $field_desc, 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), + 'S_PROFILE_CONTACT' => $ident_ary['data']['field_is_contact'], 'S_PROFILE_' . strtoupper($ident) => true, ); } -- cgit v1.2.1 From a2f2629e2a5038aca372cc3e55c408a99b6ca6fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Feb 2014 23:02:54 +0100 Subject: [ticket/12187] Add URL type for profile fields PHPBB3-12187 --- phpBB/phpbb/profilefields/type/type_int.php | 2 +- phpBB/phpbb/profilefields/type/type_string.php | 2 +- phpBB/phpbb/profilefields/type/type_url.php | 83 ++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 phpBB/phpbb/profilefields/type/type_url.php (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 267f522d5d..c98c863e13 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -61,7 +61,7 @@ class type_int extends type_base 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), - 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => ''), + 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => ''), ); return $options; diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 9d241c49ef..9dada592eb 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -109,7 +109,7 @@ class type_string extends type_string_common $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('string', array_change_key_case($profile_row, CASE_UPPER)); + $this->template->assign_block_vars($this->get_name_short(), array_change_key_case($profile_row, CASE_UPPER)); } /** diff --git a/phpBB/phpbb/profilefields/type/type_url.php b/phpBB/phpbb/profilefields/type/type_url.php new file mode 100644 index 0000000000..08f976cf4b --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_url.php @@ -0,0 +1,83 @@ + array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + ); + + return $options; + } + + /** + * {@inheritDoc} + */ + public function get_default_option_values() + { + return array( + 'field_length' => 40, + 'field_minlen' => 0, + 'field_maxlen' => 200, + 'field_validation' => '', + 'field_novalue' => '', + 'field_default_value' => '', + ); + } + + /** + * {@inheritDoc} + */ + public function get_profile_value($field_value, $field_data) + { + if (!$field_value && !$field_data['field_show_novalue']) + { + return null; + } + + return $field_value; + } + + /** + * {@inheritDoc} + */ + public function validate_profile_field(&$field_value, $field_data) + { + $field_value = trim($field_value); + + if ($field_value === '' && !$field_data['field_required']) + { + return false; + } + + if (!preg_match('#^' . get_preg_expression('url') . '$#i', $field_value)) + { + return $this->user->lang('FIELD_INVALID_URL', $this->get_field_name($field_data['lang_name'])); + } + + return false; + } +} -- cgit v1.2.1 From c650078904e41c9dd468b329131ace2fcbd8d1f9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 4 Mar 2014 08:47:47 +0100 Subject: [ticket/12187] Split generate_profile_fields_template() into 2 methods Removing the mode switch that wraps the content of the method PHPBB3-12187 --- phpBB/phpbb/profilefields/manager.php | 192 +++++++++++++++++----------------- 1 file changed, 96 insertions(+), 96 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 874d0a21e0..8b4a3917f2 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -278,125 +278,125 @@ class manager } /** - * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) - * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template + * Grab the user specific profile fields data + * + * @param int|array $user_ids Single user id or an array of ids + * @return array Users profile fields data */ - public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false) + public function grab_profile_fields_data($user_ids = 0) { - if ($mode == 'grab') + if (!is_array($user_ids)) { - if (!is_array($user_id)) - { - $user_id = array($user_id); - } + $user_ids = array($user_ids); + } - if (!sizeof($this->profile_cache)) - { - $this->build_cache(); - } + if (!sizeof($this->profile_cache)) + { + $this->build_cache(); + } - if (!sizeof($user_id)) - { - return array(); - } + if (!sizeof($user_ids)) + { + return array(); + } - $sql = 'SELECT * - FROM ' . $this->fields_data_table . ' - WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_id)); - $result = $this->db->sql_query($sql); + $sql = 'SELECT * + FROM ' . $this->fields_data_table . ' + WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_ids)); + $result = $this->db->sql_query($sql); - $field_data = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $field_data[$row['user_id']] = $row; - } - $this->db->sql_freeresult($result); + $field_data = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $field_data[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); - $user_fields = array(); + $user_fields = array(); - $user_ids = $user_id; + // Go through the fields in correct order + foreach (array_keys($this->profile_cache) as $used_ident) + { + foreach ($field_data as $user_id => $row) + { + $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident]; + $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident]; + } - // Go through the fields in correct order - foreach (array_keys($this->profile_cache) as $used_ident) + foreach ($user_ids as $user_id) { - foreach ($field_data as $user_id => $row) + if (!isset($user_fields[$user_id][$used_ident]) && $this->profile_cache[$used_ident]['field_show_novalue']) { - $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident]; + $user_fields[$user_id][$used_ident]['value'] = ''; $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident]; } - - foreach ($user_ids as $user_id) - { - if (!isset($user_fields[$user_id][$used_ident]) && $this->profile_cache[$used_ident]['field_show_novalue']) - { - $user_fields[$user_id][$used_ident]['value'] = ''; - $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident]; - } - } } - - return $user_fields; } - else if ($mode == 'show') - { - // $profile_row == $user_fields[$row['user_id']]; - $tpl_fields = array(); - $tpl_fields['row'] = $tpl_fields['blockrow'] = array(); - foreach ($profile_row as $ident => $ident_ary) - { - $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; - $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); + return $user_fields; + } - if ($value === null) - { - continue; - } + /** + * Assign the user's profile fields data to the template + * + * @param array $profile_row Array with users profile field data + * @return array + */ + public function generate_profile_fields_template_data($profile_row) + { + // $profile_row == $user_fields[$row['user_id']]; + $tpl_fields = array(); + $tpl_fields['row'] = $tpl_fields['blockrow'] = array(); - $field_desc = $this->user->lang($ident_ary['data']['field_contact_desc']); - if (strpos($field_desc, '%s') !== false) - { - $field_desc = sprintf($field_desc, $value); - } - $contact_url = ''; - if (strpos($ident_ary['data']['field_contact_url'], '%s') !== false) - { - $contact_url = sprintf($ident_ary['data']['field_contact_url'], $value); - } + foreach ($profile_row as $ident => $ident_ary) + { + $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; + $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); - $tpl_fields['row'] += array( - 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, - 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, - 'PROFILE_' . strtoupper($ident) . '_CONTACT'=> $contact_url, - 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, - 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), - 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']), - - 'S_PROFILE_' . strtoupper($ident) . '_CONTACT' => $ident_ary['data']['field_is_contact'], - 'S_PROFILE_' . strtoupper($ident) => true, - ); - - $tpl_fields['blockrow'][] = array( - 'PROFILE_FIELD_IDENT' => $ident, - 'PROFILE_FIELD_VALUE' => $value, - 'PROFILE_FIELD_CONTACT' => $contact_url, - 'PROFILE_FIELD_DESC' => $field_desc, - 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), - 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), - - 'S_PROFILE_CONTACT' => $ident_ary['data']['field_is_contact'], - 'S_PROFILE_' . strtoupper($ident) => true, - ); + if ($value === null) + { + continue; } - return $tpl_fields; - } - else - { - trigger_error('Wrong mode for custom profile', E_USER_ERROR); + $field_desc = $this->user->lang($ident_ary['data']['field_contact_desc']); + if (strpos($field_desc, '%s') !== false) + { + $field_desc = sprintf($field_desc, $value); + } + $contact_url = ''; + if (strpos($ident_ary['data']['field_contact_url'], '%s') !== false) + { + $contact_url = sprintf($ident_ary['data']['field_contact_url'], $value); + } + + $tpl_fields['row'] += array( + 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, + 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, + 'PROFILE_' . strtoupper($ident) . '_CONTACT'=> $contact_url, + 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, + 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']), + + 'S_PROFILE_' . strtoupper($ident) . '_CONTACT' => $ident_ary['data']['field_is_contact'], + 'S_PROFILE_' . strtoupper($ident) => true, + ); + + $tpl_fields['blockrow'][] = array( + 'PROFILE_FIELD_IDENT' => $ident, + 'PROFILE_FIELD_VALUE' => $value, + 'PROFILE_FIELD_CONTACT' => $contact_url, + 'PROFILE_FIELD_DESC' => $field_desc, + 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), + + 'S_PROFILE_CONTACT' => $ident_ary['data']['field_is_contact'], + 'S_PROFILE_' . strtoupper($ident) => true, + ); } + + return $tpl_fields; } /** -- cgit v1.2.1 From 03ef39c1f18584b331b5ddbd59e94848b8d3cd17 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 4 Mar 2014 09:10:57 +0100 Subject: [ticket/12187] Do not make clickable when using as contact field PHPBB3-12187 --- phpBB/phpbb/profilefields/manager.php | 35 +++++++++++++--------- phpBB/phpbb/profilefields/type/type_base.php | 8 +++++ phpBB/phpbb/profilefields/type/type_interface.php | 11 +++++++ .../profilefields/type/type_string_common.php | 13 ++++++++ phpBB/phpbb/profilefields/type/type_url.php | 13 -------- 5 files changed, 53 insertions(+), 27 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 8b4a3917f2..a4626bc5de 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -337,12 +337,14 @@ class manager } /** - * Assign the user's profile fields data to the template - * - * @param array $profile_row Array with users profile field data - * @return array - */ - public function generate_profile_fields_template_data($profile_row) + * Assign the user's profile fields data to the template + * + * @param array $profile_row Array with users profile field data + * @param bool $use_contact_fields Should we display contact fields as such? + * This requires special treatments (links should not be parsed in the values, and more) + * @return array + */ + public function generate_profile_fields_template_data($profile_row, $use_contact_fields = true) { // $profile_row == $user_fields[$row['user_id']]; $tpl_fields = array(); @@ -358,15 +360,20 @@ class manager continue; } - $field_desc = $this->user->lang($ident_ary['data']['field_contact_desc']); - if (strpos($field_desc, '%s') !== false) - { - $field_desc = sprintf($field_desc, $value); - } - $contact_url = ''; - if (strpos($ident_ary['data']['field_contact_url'], '%s') !== false) + $field_desc = $contact_url = ''; + if ($use_contact_fields) { - $contact_url = sprintf($ident_ary['data']['field_contact_url'], $value); + $value = $profile_field->get_profile_contact_value($ident_ary['value'], $ident_ary['data']); + $field_desc = $this->user->lang($ident_ary['data']['field_contact_desc']); + if (strpos($field_desc, '%s') !== false) + { + $field_desc = sprintf($field_desc, $value); + } + $contact_url = ''; + if (strpos($ident_ary['data']['field_contact_url'], '%s') !== false) + { + $contact_url = sprintf($ident_ary['data']['field_contact_url'], $value); + } } $tpl_fields['row'] += array( diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 9c363a7b4e..a96196674d 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -84,6 +84,14 @@ abstract class type_base implements type_interface return isset($this->user->lang[$field_name]) ? $this->user->lang[$field_name] : $field_name; } + /** + * {@inheritDoc} + */ + public function get_profile_contact_value($field_value, $field_data) + { + return $this->get_profile_value($field_value, $field_data); + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 94f6882524..a1c3d879c8 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -89,6 +89,17 @@ interface type_interface */ public function get_profile_value($field_value, $field_data); + /** + * Get Profile Value for display + * + * When displaying a contact field, we don't want to have links already parsed and more + * + * @param mixed $field_value Field value as stored in the database + * @param array $field_data Array with requirements of the field + * @return mixed Field value to display + */ + public function get_profile_contact_value($field_value, $field_data); + /** * Generate the input field for display * diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index f00a7e6a08..d5fb8f4b97 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -102,6 +102,19 @@ abstract class type_string_common extends type_base return $field_value; } + /** + * {@inheritDoc} + */ + public function get_profile_contact_value($field_value, $field_data) + { + if (!$field_value && !$field_data['field_show_novalue']) + { + return null; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_url.php b/phpBB/phpbb/profilefields/type/type_url.php index 08f976cf4b..b1523b9355 100644 --- a/phpBB/phpbb/profilefields/type/type_url.php +++ b/phpBB/phpbb/profilefields/type/type_url.php @@ -48,19 +48,6 @@ class type_url extends type_string ); } - /** - * {@inheritDoc} - */ - public function get_profile_value($field_value, $field_data) - { - if (!$field_value && !$field_data['field_show_novalue']) - { - return null; - } - - return $field_value; - } - /** * {@inheritDoc} */ -- cgit v1.2.1 From e88c61f85e1556238a551f597bff71efff6c17c4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 5 Mar 2014 22:32:03 +0100 Subject: [ticket/12249] Fix "Undefined variable: row" when editing profile PHPBB3-12249 --- phpBB/phpbb/profilefields/type/type_string_common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index d5fb8f4b97..f060fb1054 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -69,7 +69,7 @@ abstract class type_string_common extends type_base $field_validate = ($field_type != 'text') ? $field_value : bbcode_nl2br($field_value); if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate)) { - switch ($row['field_validation']) + switch ($field_data['field_validation']) { case '[0-9]+': return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $this->get_field_name($field_data['lang_name'])); -- cgit v1.2.1 From 600e5f6c1194c7156837f1b9f627896b8c13f691 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Mar 2014 12:28:36 +0100 Subject: [ticket/12251] Add string validation for a-zA-Z0-9 and underscore PHPBB3-12251 --- .../profilefields/type/type_string_common.php | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index f060fb1054..0738cbdafd 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -11,15 +11,21 @@ namespace phpbb\profilefields\type; abstract class type_string_common extends type_base { + protected $validation_options = array( + 'CHARS_ANY' => '.*', + 'NUMBERS_ONLY' => '[0-9]+', + 'ALPHA_ONLY' => '[\w]+', + 'ALPHA_UNDERSCORE' => '[\w_]+', + 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+', + ); + /** * Return possible validation options */ - function validate_options($field_data) + public function validate_options($field_data) { - $validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+'); - $validate_options = ''; - foreach ($validate_ary as $lang => $value) + foreach ($this->validation_options as $lang => $value) { $selected = ($field_data['field_validation'] == $value) ? ' selected="selected"' : ''; $validate_options .= ''; @@ -69,17 +75,12 @@ abstract class type_string_common extends type_base $field_validate = ($field_type != 'text') ? $field_value : bbcode_nl2br($field_value); if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate)) { - switch ($field_data['field_validation']) + $validation = array_search($field_data['field_validation'], $this->validation_options); + if ($validation) { - case '[0-9]+': - return $this->user->lang('FIELD_INVALID_CHARS_NUMBERS_ONLY', $this->get_field_name($field_data['lang_name'])); - - case '[\w]+': - return $this->user->lang('FIELD_INVALID_CHARS_ALPHA_ONLY', $this->get_field_name($field_data['lang_name'])); - - case '[\w_\+\. \-\[\]]+': - return $this->user->lang('FIELD_INVALID_CHARS_SPACERS_ONLY', $this->get_field_name($field_data['lang_name'])); + 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'])); } } -- cgit v1.2.1 From 403ab49716c8bc7d93fc33bbf810e0814e3de049 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Mon, 17 Mar 2014 15:54:28 +0530 Subject: [ticket/9040] Count HTML entities as single in custom profile fields Currently when an user adds a HTML entity to a custom profile field, the length gets incremented by 4 since the code reads > instead of <. However, the length is presentational and not DB storage so it should be treated as a single character even if it takes four lengths in the DB by being stored as a HTML entity. Work around this by decoding html entities before counting. Also, added unit tests for string field type PHPBB3-9040 --- phpBB/phpbb/profilefields/type/type_string_common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 0738cbdafd..78e219a61f 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -65,7 +65,7 @@ abstract class type_string_common extends type_base { 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($field_value) > $field_data['field_maxlen']) + 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'])); } -- cgit v1.2.1 From 86c4d24a8ac14c4339806871ab326aedec4965e9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 30 Mar 2014 15:44:58 +0200 Subject: [ticket/12331] Fix SQL error when inserting a new entry to profile field data There was a "Field 'pf_phpbb_interests' doesn't have a default value" error, because we didn't specify values for the disabled fields. We can not disable the sql_return_on_error() thou, because it otherwise we run into "Duplicate entry '2' for key 'PRIMARY'" errors when the user submits the form again but didn't change any values. PHPBB3-12331 --- phpBB/phpbb/profilefields/manager.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index a4626bc5de..f4baec7a6c 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -231,6 +231,7 @@ class manager if (!$this->db->sql_affectedrows()) { + $cp_data = $this->build_insert_sql_array($cp_data); $cp_data['user_id'] = (int) $user_id; $this->db->sql_return_on_error(true); -- cgit v1.2.1 From 11a9104b8a50cbc62cba0c242dee554b5209a327 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 17 Mar 2014 13:29:35 +0100 Subject: [ticket/12282] Use interface for type hinting PHPBB3-12282 --- phpBB/phpbb/profilefields/lang_helper.php | 4 ++-- phpBB/phpbb/profilefields/manager.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 7bae1bdc18..7ad4722230 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -23,7 +23,7 @@ class lang_helper /** * Database object - * @var \phpbb\db\driver\driver + * @var \phpbb\db\driver\driver_interface */ protected $db; @@ -36,7 +36,7 @@ class lang_helper /** * Construct * - * @param \phpbb\db\driver\driver $db Database object + * @param \phpbb\db\driver\driver_interface $db Database object * @param string $language_table Table where the language strings are stored */ public function __construct($db, $language_table) diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index a4626bc5de..eebdbd07ae 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -23,7 +23,7 @@ class manager /** * Database object - * @var \phpbb\db\driver\driver + * @var \phpbb\db\driver\driver_interface */ protected $db; @@ -63,7 +63,7 @@ class manager * Construct * * @param \phpbb\auth\auth $auth Auth object - * @param \phpbb\db\driver\driver $db Database object + * @param \phpbb\db\driver\driver_interface $db Database object * @param \phpbb\request\request $request Request object * @param \phpbb\template\template $template Template object * @param \phpbb\di\service_collection $type_collection @@ -72,7 +72,7 @@ class manager * @param string $fields_language_table * @param string $fields_data_table */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) + public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) { $this->auth = $auth; $this->db = $db; -- cgit v1.2.1 From b3b0e5ccf2503e7bba72ee922dda175337d1b4e9 Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 31 Mar 2014 14:06:58 +0200 Subject: [ticket/12335] Add Events to phpbb\profilefields\manager PHPBB3-12335 --- phpBB/phpbb/profilefields/manager.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 37449c67c4..7d50fd9f24 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -27,6 +27,12 @@ class manager */ protected $db; + /** + * Event dispatcher object + * @var \phpbb\event\dispatcher + */ + protected $dispatcher; + /** * Request object * @var \phpbb\request\request @@ -64,6 +70,7 @@ class manager * * @param \phpbb\auth\auth $auth Auth object * @param \phpbb\db\driver\driver_interface $db Database object + * @param \phpbb\event\dispatcher $dispatcher Event dispatcher object * @param \phpbb\request\request $request Request object * @param \phpbb\template\template $template Template object * @param \phpbb\di\service_collection $type_collection @@ -72,10 +79,11 @@ class manager * @param string $fields_language_table * @param string $fields_data_table */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) + public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) { $this->auth = $auth; $this->db = $db; + $this->dispatcher = $dispatcher; $this->request = $request; $this->template = $template; $this->type_collection = $type_collection; @@ -313,6 +321,17 @@ class manager } $this->db->sql_freeresult($result); + /** + * Event to modify profile fields data retrieved from the database + * + * @event core.grab_profile_fields_data + * @var int|array $user_ids Single user id or an array of ids + * @var array $field_data Array with profile fields data + * @since 3.1-B3 + */ + $vars = array('user_ids', 'field_data'); + extract($this->dispatcher->trigger_event('core.grab_profile_fields_data', compact($vars))); + $user_fields = array(); // Go through the fields in correct order @@ -404,6 +423,17 @@ class manager ); } + /** + * Event to modify template data of the generated profile fields + * + * @event core.generate_profile_fields_template_data + * @var array profile_row Array with users profile field data + * @var array tpl_fields Array with template data fields + * @since 3.1-B3 + */ + $vars = array('profile_row', 'tpl_fields'); + extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data', compact($vars))); + return $tpl_fields; } -- cgit v1.2.1 From 1fd1803a3bfffd15e0bc85097cd84c3f2d9ec163 Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 7 Apr 2014 08:05:50 +0200 Subject: [ticket/12335] Fix phpBB version number PHPBB3-12335 --- phpBB/phpbb/profilefields/manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 7d50fd9f24..7c0397a563 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -327,7 +327,7 @@ class manager * @event core.grab_profile_fields_data * @var int|array $user_ids Single user id or an array of ids * @var array $field_data Array with profile fields data - * @since 3.1-B3 + * @since 3.1.0-b3 */ $vars = array('user_ids', 'field_data'); extract($this->dispatcher->trigger_event('core.grab_profile_fields_data', compact($vars))); @@ -429,7 +429,7 @@ class manager * @event core.generate_profile_fields_template_data * @var array profile_row Array with users profile field data * @var array tpl_fields Array with template data fields - * @since 3.1-B3 + * @since 3.1.0-b3 */ $vars = array('profile_row', 'tpl_fields'); extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data', compact($vars))); -- cgit v1.2.1 From 2343d9f8d42337353d32a69fddcc1a51e0a49f5a Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 14 Apr 2014 20:50:51 +0200 Subject: [ticket/12335] Documentation fix and added use_contact_fields PHPBB3-12335 --- phpBB/phpbb/profilefields/manager.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 7c0397a563..a7b8f55e34 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -325,7 +325,7 @@ class manager * Event to modify profile fields data retrieved from the database * * @event core.grab_profile_fields_data - * @var int|array $user_ids Single user id or an array of ids + * @var array $user_ids Single user id or an array of ids * @var array $field_data Array with profile fields data * @since 3.1.0-b3 */ @@ -429,9 +429,10 @@ class manager * @event core.generate_profile_fields_template_data * @var array profile_row Array with users profile field data * @var array tpl_fields Array with template data fields + * @var bool use_contact_fields Should we display contact fields as such? * @since 3.1.0-b3 */ - $vars = array('profile_row', 'tpl_fields'); + $vars = array('profile_row', 'tpl_fields', 'use_contact_fields'); extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data', compact($vars))); return $tpl_fields; -- cgit v1.2.1 From 42dfd1aa3c8fda95efd0dac03652a163752575d4 Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 14 Apr 2014 21:15:30 +0200 Subject: [ticket/12335] Added generate_profile_fields _ before PHPBB3-12335 --- phpBB/phpbb/profilefields/manager.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index a7b8f55e34..5b326fe39c 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -370,6 +370,18 @@ class manager $tpl_fields = array(); $tpl_fields['row'] = $tpl_fields['blockrow'] = array(); + /** + * Event to modify data of the generated profile fields, before the template assignment loop + * + * @event core.generate_profile_fields_template_data_before + * @var array profile_row Array with users profile field data + * @var array tpl_fields Array with template data fields + * @var bool use_contact_fields Should we display contact fields as such? + * @since 3.1.0-b3 + */ + $vars = array('profile_row', 'tpl_fields', 'use_contact_fields'); + extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data_before', compact($vars))); + foreach ($profile_row as $ident => $ident_ary) { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; -- cgit v1.2.1 From 5b5b61c6c97d0d4158e6487a47fb5bb584affa34 Mon Sep 17 00:00:00 2001 From: PayBas Date: Fri, 2 May 2014 17:29:52 +0200 Subject: [ticket/12335] Remove $ from desc Come on travis, play nice this time PHPBB3-12335 --- phpBB/phpbb/profilefields/manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 5b326fe39c..7d545a5f72 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -325,8 +325,8 @@ class manager * Event to modify profile fields data retrieved from the database * * @event core.grab_profile_fields_data - * @var array $user_ids Single user id or an array of ids - * @var array $field_data Array with profile fields data + * @var array user_ids Single user id or an array of ids + * @var array field_data Array with profile fields data * @since 3.1.0-b3 */ $vars = array('user_ids', 'field_data'); -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- phpBB/phpbb/profilefields/lang_helper.php | 11 +++++++---- phpBB/phpbb/profilefields/manager.php | 11 +++++++---- phpBB/phpbb/profilefields/type/type_base.php | 10 +++++++--- phpBB/phpbb/profilefields/type/type_bool.php | 10 +++++++--- phpBB/phpbb/profilefields/type/type_date.php | 10 +++++++--- phpBB/phpbb/profilefields/type/type_dropdown.php | 10 +++++++--- phpBB/phpbb/profilefields/type/type_int.php | 10 +++++++--- phpBB/phpbb/profilefields/type/type_interface.php | 10 +++++++--- phpBB/phpbb/profilefields/type/type_string.php | 10 +++++++--- phpBB/phpbb/profilefields/type/type_string_common.php | 10 +++++++--- phpBB/phpbb/profilefields/type/type_text.php | 10 +++++++--- phpBB/phpbb/profilefields/type/type_url.php | 10 +++++++--- 12 files changed, 84 insertions(+), 38 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 7ad4722230..c055931181 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -11,7 +15,6 @@ namespace phpbb\profilefields; /** * Custom Profile Fields -* @package phpBB3 */ class lang_helper { diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 7d545a5f72..490db0419a 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -11,7 +15,6 @@ namespace phpbb\profilefields; /** * Custom Profile Fields -* @package phpBB3 */ class manager { diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index a96196674d..3ca1274458 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index fa9c0a8714..8d3c0cad93 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index af3d65c9b6..aedd6a56d6 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index bcf0ba05f9..053a02d593 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index c98c863e13..8cbcf62b8c 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index a1c3d879c8..489e916fd5 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 9dada592eb..7e994d700b 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 78e219a61f..7d0cb04d7c 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 660bb20ef8..856573292f 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/phpBB/phpbb/profilefields/type/type_url.php b/phpBB/phpbb/profilefields/type/type_url.php index b1523b9355..bc8ac869d0 100644 --- a/phpBB/phpbb/profilefields/type/type_url.php +++ b/phpBB/phpbb/profilefields/type/type_url.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -- cgit v1.2.1 From 5ab6998e0e05e35ab253918a6b95920ef27023a3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 15 Jun 2014 14:50:46 +0200 Subject: [ticket/12715] Cleanup comments in \phpbb\profilefields\* PHPBB3-12715 --- phpBB/phpbb/profilefields/type/type_base.php | 1 - phpBB/phpbb/profilefields/type/type_bool.php | 1 - phpBB/phpbb/profilefields/type/type_date.php | 1 - phpBB/phpbb/profilefields/type/type_dropdown.php | 1 - phpBB/phpbb/profilefields/type/type_int.php | 1 - phpBB/phpbb/profilefields/type/type_string.php | 1 - phpBB/phpbb/profilefields/type/type_text.php | 1 - 7 files changed, 7 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 3ca1274458..c770a0d93c 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -39,7 +39,6 @@ abstract class type_base implements type_interface * @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) { diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 8d3c0cad93..eb8d3e47d6 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -46,7 +46,6 @@ class type_bool extends type_base * @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\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index aedd6a56d6..158eec6a0c 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -39,7 +39,6 @@ class type_date extends type_base * @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) { diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 053a02d593..52c9fcf86a 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -46,7 +46,6 @@ class type_dropdown extends type_base * @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\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) { diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 8cbcf62b8c..78f1c7d2c9 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -39,7 +39,6 @@ class type_int extends type_base * @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) { diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 7e994d700b..67befc457d 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -39,7 +39,6 @@ class type_string extends type_string_common * @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) { diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 856573292f..bacf60a213 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -39,7 +39,6 @@ class type_text extends type_string_common * @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) { -- cgit v1.2.1 From 28012dc9e10339d7ab66a5b2e3cd394728654f47 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Thu, 19 Jun 2014 19:02:10 +0530 Subject: [ticket/12732] Add Skype custom profile field PHPBB3-12732 --- phpBB/phpbb/profilefields/type/type_string_common.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 7d0cb04d7c..a317568ec8 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -21,6 +21,7 @@ abstract class type_string_common extends type_base 'ALPHA_ONLY' => '[\w]+', 'ALPHA_UNDERSCORE' => '[\w_]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+', + 'ALPHA_PUNCTUATION' => '[a-zA-Z][\w\.,\-_]+' ); /** -- cgit v1.2.1 From 352f3b7e78f4020c7ce726981f3faef8cc8f33dc Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 20 Jun 2014 16:37:18 +0530 Subject: [ticket/12732] Missing comma after validation definition PHPBB3-12732 --- phpBB/phpbb/profilefields/type/type_string_common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index a317568ec8..32356c852a 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -21,7 +21,7 @@ abstract class type_string_common extends type_base 'ALPHA_ONLY' => '[\w]+', 'ALPHA_UNDERSCORE' => '[\w_]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+', - 'ALPHA_PUNCTUATION' => '[a-zA-Z][\w\.,\-_]+' + 'ALPHA_PUNCTUATION' => '[a-zA-Z][\w\.,\-_]+', ); /** -- cgit v1.2.1 From 310b8af1482021cf8ab6fbe839a4150ff281c4e1 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Tue, 17 Jun 2014 17:51:07 +0530 Subject: [ticket/12729] Add Facebook custom profile field PHPBB3-12729 --- phpBB/phpbb/profilefields/type/type_string_common.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 7d0cb04d7c..014950c15f 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -21,6 +21,7 @@ abstract class type_string_common extends type_base 'ALPHA_ONLY' => '[\w]+', 'ALPHA_UNDERSCORE' => '[\w_]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+', + 'ALPHA_DOTS' => '[\w.]+', ); /** -- cgit v1.2.1 From 5701a4658cfb293d15a3027d9704f335904a4d0c Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 20 Jun 2014 14:34:46 +0530 Subject: [ticket/12729] Move ALPHA_DOTS to above ALPHA_SPACERS Have easier matches first for better performance PHPBB3-12729 --- phpBB/phpbb/profilefields/type/type_string_common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 014950c15f..91198deec0 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -20,8 +20,8 @@ abstract class type_string_common extends type_base 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_UNDERSCORE' => '[\w_]+', - 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+', 'ALPHA_DOTS' => '[\w.]+', + 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+', ); /** -- cgit v1.2.1 From 3cebb18ce8e8e97a6b95b32dbab5740489c840ea Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Wed, 18 Jun 2014 19:34:14 +0530 Subject: [ticket/12730] Add Google+ profile field type Google+ has a "+" before a custom URL but doesn't for those which are using their integer ID. To cover that we need to have an extra profile field PHPBB3-12730 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 phpBB/phpbb/profilefields/type/type_googleplus.php (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php new file mode 100644 index 0000000000..1bdb04e859 --- /dev/null +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -0,0 +1,56 @@ + + * @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; + +class type_googleplus extends type_string +{ + /** + * {@inheritDoc} + */ + public function get_name_short() + { + return 'googleplus'; + } + + /** + * {@inheritDoc} + */ + public function get_default_option_values() + { + return array( + 'field_length' => 20, + 'field_minlen' => 3, + 'field_maxlen' => '', + 'field_validation' => '[\w]+', + 'field_novalue' => '', + 'field_default_value' => '', + ); + } + + /** + * {@inheritDoc} + */ + public function get_profile_contact_value($field_value, $field_data) + { + if (!$field_value && !$field_data['field_show_novalue']) + { + return null; + } + + if (!is_numeric($field_value)) + $field_value = '+' . $field_value; + + return $field_value; + } +} -- cgit v1.2.1 From 0e04748d7ff2ea7ab11f5b0d9761a54b5e8ebae4 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Wed, 18 Jun 2014 19:44:21 +0530 Subject: [ticket/12730] Spaces in block header PHPBB3-12730 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index 1bdb04e859..42a34f1a8a 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -1,15 +1,15 @@ - * @license GNU General Public License, version 2 (GPL-2.0) - * - * For full copyright and license information, please see - * the docs/CREDITS.txt file. - * - */ +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited +* @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; -- cgit v1.2.1 From d15706bff55cb828eb0972d421bb15d042350652 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Wed, 18 Jun 2014 19:53:43 +0530 Subject: [ticket/12730] Incorrect indentation for type_googleplus PHPBB3-12730 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index 42a34f1a8a..6611f9811d 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -15,28 +15,28 @@ namespace phpbb\profilefields\type; class type_googleplus extends type_string { - /** - * {@inheritDoc} - */ - public function get_name_short() - { - return 'googleplus'; - } + /** + * {@inheritDoc} + */ + public function get_name_short() + { + return 'googleplus'; + } - /** - * {@inheritDoc} - */ - public function get_default_option_values() - { - return array( - 'field_length' => 20, - 'field_minlen' => 3, - 'field_maxlen' => '', - 'field_validation' => '[\w]+', - 'field_novalue' => '', - 'field_default_value' => '', - ); - } + /** + * {@inheritDoc} + */ + public function get_default_option_values() + { + return array( + 'field_length' => 20, + 'field_minlen' => 3, + 'field_maxlen' => '', + 'field_validation' => '[\w]+', + 'field_novalue' => '', + 'field_default_value' => '', + ); + } /** * {@inheritDoc} -- cgit v1.2.1 From e1454ec4872e22d9a3fe6e9a147d9926212c11b7 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Thu, 19 Jun 2014 03:45:51 +0530 Subject: [ticket/12730] Minor formatting fixes PHPBB3-12730 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index 6611f9811d..aec37dffe9 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -16,16 +16,16 @@ namespace phpbb\profilefields\type; class type_googleplus extends type_string { /** - * {@inheritDoc} - */ + * {@inheritDoc} + */ public function get_name_short() { return 'googleplus'; } /** - * {@inheritDoc} - */ + * {@inheritDoc} + */ public function get_default_option_values() { return array( @@ -39,8 +39,8 @@ class type_googleplus extends type_string } /** - * {@inheritDoc} - */ + * {@inheritDoc} + */ public function get_profile_contact_value($field_value, $field_data) { if (!$field_value && !$field_data['field_show_novalue']) -- cgit v1.2.1 From 1363dccf12c66e525cd61f98e417e3957fc05319 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Thu, 19 Jun 2014 03:47:26 +0530 Subject: [ticket/12730] Use string template for Google+ CPF instead of a new one PHPBB3-12730 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index aec37dffe9..a58aa6a97f 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -53,4 +53,12 @@ class type_googleplus extends type_string return $field_value; } + + /** + * {@inheritDoc} + */ + public function get_template_filename() + { + return 'profilefields/string.html'; + } } -- cgit v1.2.1 From 474dc577822e8c1937b35040de563cc81f0867cf Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 20 Jun 2014 17:24:03 +0530 Subject: [ticket/12730] Add missing brackets to type_googleplus.php PHPBB3-12730 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index a58aa6a97f..32c3e77f12 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -49,7 +49,9 @@ class type_googleplus extends type_string } if (!is_numeric($field_value)) + { $field_value = '+' . $field_value; + } return $field_value; } -- cgit v1.2.1 From 83966a575bfac025bd74e193abad3ceade92b4ae Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sat, 21 Jun 2014 01:36:01 +0530 Subject: [ticket/12730] Restore field_length to 10 for type_googleplus PHPBB3-12730 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index 32c3e77f12..37ec0dd999 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -29,11 +29,11 @@ class type_googleplus extends type_string public function get_default_option_values() { return array( - 'field_length' => 20, - 'field_minlen' => 3, - 'field_maxlen' => '', - 'field_validation' => '[\w]+', - 'field_novalue' => '', + 'field_length' => 10, + 'field_minlen' => 3, + 'field_maxlen' => '', + 'field_validation' => '[\w]+', + 'field_novalue' => '', 'field_default_value' => '', ); } -- cgit v1.2.1 From 985dbd448272315e75a071d628209852a62a19c8 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sat, 21 Jun 2014 01:54:15 +0530 Subject: [ticket/12730] Switch service name to googleplus for type_googleplus PHPBB3-12730 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index 37ec0dd999..49fa557fab 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -18,9 +18,9 @@ class type_googleplus extends type_string /** * {@inheritDoc} */ - public function get_name_short() + public function get_service_name() { - return 'googleplus'; + return 'profilefields.type.googleplus'; } /** @@ -55,12 +55,4 @@ class type_googleplus extends type_string return $field_value; } - - /** - * {@inheritDoc} - */ - public function get_template_filename() - { - return 'profilefields/string.html'; - } } -- cgit v1.2.1 From 72f3ff2dcc9f2bdfe161f6bfb6383680125b9bf2 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sat, 21 Jun 2014 03:48:23 +0530 Subject: [ticket/12730] Update field_length to be 20 by default for Google+ PHPBB3-12730 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index 49fa557fab..e7896abc5d 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -29,7 +29,7 @@ class type_googleplus extends type_string public function get_default_option_values() { return array( - 'field_length' => 10, + 'field_length' => 20, 'field_minlen' => 3, 'field_maxlen' => '', 'field_validation' => '[\w]+', -- cgit v1.2.1 From e51a5791dd66870ae056394efca759338dd4d9c4 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sat, 21 Jun 2014 03:51:08 +0530 Subject: [ticket/12730] Update maxlen for type_googleplus to 255 PHPBB3-12730 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index e7896abc5d..df1bcc7f4b 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -31,7 +31,7 @@ class type_googleplus extends type_string return array( 'field_length' => 20, 'field_minlen' => 3, - 'field_maxlen' => '', + 'field_maxlen' => 255, 'field_validation' => '[\w]+', 'field_novalue' => '', 'field_default_value' => '', -- cgit v1.2.1 From 08e2c07f0b7991d89a562e1a78da9462d830e134 Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 31 Mar 2014 13:04:25 +0200 Subject: [ticket/12334] Add PROFILE_FIELD_VALUEID template var PHPBB3-12334 --- phpBB/phpbb/profilefields/manager.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 490db0419a..f075e38ded 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -412,13 +412,14 @@ class manager } $tpl_fields['row'] += array( - 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, - 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, - 'PROFILE_' . strtoupper($ident) . '_CONTACT'=> $contact_url, - 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, - 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), - 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']), + 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, + 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, + 'PROFILE_' . strtoupper($ident) . '_VALUEID' => $ident_ary['value'], + 'PROFILE_' . strtoupper($ident) . '_CONTACT' => $contact_url, + 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, + 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_' . strtoupper($ident) . '_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), 'S_PROFILE_' . strtoupper($ident) . '_CONTACT' => $ident_ary['data']['field_is_contact'], 'S_PROFILE_' . strtoupper($ident) => true, @@ -427,6 +428,7 @@ class manager $tpl_fields['blockrow'][] = array( 'PROFILE_FIELD_IDENT' => $ident, 'PROFILE_FIELD_VALUE' => $value, + 'PROFILE_FIELD_VALUEID' => $ident_ary['value'], 'PROFILE_FIELD_CONTACT' => $contact_url, 'PROFILE_FIELD_DESC' => $field_desc, 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], -- cgit v1.2.1 From 4169fd65f07f67f99e64e7ab962d09c1e10f14dc Mon Sep 17 00:00:00 2001 From: PayBas Date: Sat, 5 Apr 2014 22:32:42 +0200 Subject: [ticket/12334] Added field_novalue fall-back as requested PHPBB3-12334 --- phpBB/phpbb/profilefields/manager.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index f075e38ded..7602abf9aa 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -389,6 +389,7 @@ class manager { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); + $valueid = (!$ident_ary['value'] && !$ident_ary['data']['field_show_novalue']) ? $ident_ary['data']['field_novalue'] : $ident_ary['value']; if ($value === null) { @@ -414,7 +415,7 @@ class manager $tpl_fields['row'] += array( 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, - 'PROFILE_' . strtoupper($ident) . '_VALUEID' => $ident_ary['value'], + 'PROFILE_' . strtoupper($ident) . '_VALUEID' => $valueid, 'PROFILE_' . strtoupper($ident) . '_CONTACT' => $contact_url, 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], @@ -428,7 +429,7 @@ class manager $tpl_fields['blockrow'][] = array( 'PROFILE_FIELD_IDENT' => $ident, 'PROFILE_FIELD_VALUE' => $value, - 'PROFILE_FIELD_VALUEID' => $ident_ary['value'], + 'PROFILE_FIELD_VALUEID' => $valueid, 'PROFILE_FIELD_CONTACT' => $contact_url, 'PROFILE_FIELD_DESC' => $field_desc, 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], -- cgit v1.2.1 From 507eca319d2bff9779d662a36b845017b7464e68 Mon Sep 17 00:00:00 2001 From: PayBas Date: Tue, 29 Apr 2014 16:16:19 +0200 Subject: [ticket/12334] Implemented get_profile_valueid method PHPBB3-12334 --- phpBB/phpbb/profilefields/manager.php | 2 +- phpBB/phpbb/profilefields/type/type_bool.php | 18 ++++++++++++++++++ phpBB/phpbb/profilefields/type/type_date.php | 13 +++++++++++++ phpBB/phpbb/profilefields/type/type_dropdown.php | 18 ++++++++++++++++++ phpBB/phpbb/profilefields/type/type_int.php | 12 ++++++++++++ phpBB/phpbb/profilefields/type/type_interface.php | 9 +++++++++ phpBB/phpbb/profilefields/type/type_string_common.php | 13 +++++++++++++ 7 files changed, 84 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 7602abf9aa..a2b931ce27 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -389,7 +389,7 @@ class manager { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); - $valueid = (!$ident_ary['value'] && !$ident_ary['data']['field_show_novalue']) ? $ident_ary['data']['field_novalue'] : $ident_ary['value']; + $valueid = $profile_field->get_profile_valueid($ident_ary['value'], $ident_ary['data']); if ($value === null) { diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index eb8d3e47d6..64f4f8293f 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -177,6 +177,24 @@ class type_bool extends type_base } } + /** + * {@inheritDoc} + */ + public function get_profile_valueid($field_value, $field_data) + { + if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) + { + return null; + } + + if (!$field_value && $field_data['field_show_novalue']) + { + $field_value = $field_data['field_novalue']; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 158eec6a0c..f59d74c33d 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -205,6 +205,19 @@ class type_date extends type_base return $field_value; } + /** + * {@inheritDoc} + */ + public function get_profile_valueid($field_value, $field_data) + { + if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue']) + { + return null; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 52c9fcf86a..b201c4abbf 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -186,6 +186,24 @@ class type_dropdown extends type_base return $this->lang_helper->get($field_id, $lang_id, $field_value); } + /** + * {@inheritDoc} + */ + public function get_profile_valueid($field_value, $field_data) + { + if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) + { + return null; + } + + if (!$field_value && $field_data['field_show_novalue']) + { + $field_value = $field_data['field_novalue']; + } + + return $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 78f1c7d2c9..8a803293d0 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -151,6 +151,18 @@ class type_int extends type_base return (int) $field_value; } + /** + * {@inheritDoc} + */ + public function get_profile_valueid($field_value, $field_data) + { + if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue']) + { + return null; + } + return (int) $field_value; + } + /** * {@inheritDoc} */ diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 489e916fd5..8fe1bb2be5 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -93,6 +93,15 @@ interface type_interface */ public function get_profile_value($field_value, $field_data); + /** + * Get Profile Value ID for display (the raw, unprocessed user data) + * + * @param mixed $field_value Field value as stored in the database + * @param array $field_data Array with requirements of the field + * @return mixed Field value ID to display + */ + public function get_profile_valueid($field_value, $field_data); + /** * Get Profile Value for display * diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index b48e3c5add..1d26ba5d3a 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -109,6 +109,19 @@ abstract class type_string_common extends type_base return $field_value; } + /** + * {@inheritDoc} + */ + public function get_profile_valueid($field_value, $field_data) + { + if (!$field_value && !$field_data['field_show_novalue']) + { + return null; + } + + return $field_value; + } + /** * {@inheritDoc} */ -- cgit v1.2.1 From 2b451a174bc3cf253dacb3bfb313e9ff3f227de6 Mon Sep 17 00:00:00 2001 From: PayBas Date: Wed, 30 Apr 2014 10:08:21 +0200 Subject: [ticket/12334] Changed from valueid to value_raw PHPBB3-12334 --- phpBB/phpbb/profilefields/manager.php | 20 ++++++++++---------- phpBB/phpbb/profilefields/type/type_bool.php | 2 +- phpBB/phpbb/profilefields/type/type_date.php | 2 +- phpBB/phpbb/profilefields/type/type_dropdown.php | 2 +- phpBB/phpbb/profilefields/type/type_int.php | 2 +- phpBB/phpbb/profilefields/type/type_interface.php | 2 +- .../phpbb/profilefields/type/type_string_common.php | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index a2b931ce27..26c11d9e22 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -389,7 +389,7 @@ class manager { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); - $valueid = $profile_field->get_profile_valueid($ident_ary['value'], $ident_ary['data']); + $value_raw = $profile_field->get_profile_value_raw($ident_ary['value'], $ident_ary['data']); if ($value === null) { @@ -415,7 +415,7 @@ class manager $tpl_fields['row'] += array( 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident, 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, - 'PROFILE_' . strtoupper($ident) . '_VALUEID' => $valueid, + 'PROFILE_' . strtoupper($ident) . '_VALUE_RAW' => $value_raw, 'PROFILE_' . strtoupper($ident) . '_CONTACT' => $contact_url, 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc, 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], @@ -427,14 +427,14 @@ class manager ); $tpl_fields['blockrow'][] = array( - 'PROFILE_FIELD_IDENT' => $ident, - 'PROFILE_FIELD_VALUE' => $value, - 'PROFILE_FIELD_VALUEID' => $valueid, - 'PROFILE_FIELD_CONTACT' => $contact_url, - 'PROFILE_FIELD_DESC' => $field_desc, - 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], - 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), - 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), + 'PROFILE_FIELD_IDENT' => $ident, + 'PROFILE_FIELD_VALUE' => $value, + 'PROFILE_FIELD_VALUE_RAW' => $value_raw, + 'PROFILE_FIELD_CONTACT' => $contact_url, + 'PROFILE_FIELD_DESC' => $field_desc, + 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], + 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']), + 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']), 'S_PROFILE_CONTACT' => $ident_ary['data']['field_is_contact'], 'S_PROFILE_' . strtoupper($ident) => true, diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 64f4f8293f..c34dd9ce88 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -180,7 +180,7 @@ class type_bool extends type_base /** * {@inheritDoc} */ - public function get_profile_valueid($field_value, $field_data) + public function get_profile_value_raw($field_value, $field_data) { if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) { diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index f59d74c33d..90ac9a6703 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -208,7 +208,7 @@ class type_date extends type_base /** * {@inheritDoc} */ - public function get_profile_valueid($field_value, $field_data) + public function get_profile_value_raw($field_value, $field_data) { if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue']) { diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index b201c4abbf..f70693e294 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -189,7 +189,7 @@ class type_dropdown extends type_base /** * {@inheritDoc} */ - public function get_profile_valueid($field_value, $field_data) + public function get_profile_value_raw($field_value, $field_data) { if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) { diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index 8a803293d0..dd08df94c1 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -154,7 +154,7 @@ class type_int extends type_base /** * {@inheritDoc} */ - public function get_profile_valueid($field_value, $field_data) + public function get_profile_value_raw($field_value, $field_data) { if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue']) { diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 8fe1bb2be5..2dd13fa480 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -100,7 +100,7 @@ interface type_interface * @param array $field_data Array with requirements of the field * @return mixed Field value ID to display */ - public function get_profile_valueid($field_value, $field_data); + public function get_profile_value_raw($field_value, $field_data); /** * Get Profile Value for display diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 1d26ba5d3a..c2b951b6c9 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -112,7 +112,7 @@ abstract class type_string_common extends type_base /** * {@inheritDoc} */ - public function get_profile_valueid($field_value, $field_data) + public function get_profile_value_raw($field_value, $field_data) { if (!$field_value && !$field_data['field_show_novalue']) { -- cgit v1.2.1 From 6d23cc3a0e6c71bebc239d3b6ecd55f05f4b98d4 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 17:55:30 +0530 Subject: [ticket/12759] Allow multiple fields to be loaded via get_option_lang PHPBB3-12759 --- phpBB/phpbb/profilefields/lang_helper.php | 21 ++++++++++++++++----- phpBB/phpbb/profilefields/type/type_bool.php | 4 ++-- phpBB/phpbb/profilefields/type/type_dropdown.php | 6 +++--- 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index c055931181..9e4991e94a 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -51,7 +51,7 @@ class lang_helper /** * 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) + public function get_option_lang($field_id, $lang_id, $preview_options) { if ($preview_options !== false) { @@ -72,17 +72,28 @@ class lang_helper } else { - $sql = 'SELECT option_id, lang_value + if (is_array($field_id)) + { + foreach ($field_id as $k => $id) + { + $field_id[$k] = (int) $id; + } + } + else + { + $field_id = array((int) $field_id); + } + + $sql = 'SELECT field_id, option_id, lang_value FROM ' . $this->language_table . ' - WHERE field_id = ' . (int) $field_id . ' + WHERE ' . $this->db->sql_in_set('field_id', $field_id) . ' AND lang_id = ' . (int) $lang_id . " - AND field_type = '" . $this->db->sql_escape($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->options_lang[$row['field_id']][$lang_id][($row['option_id'] + 1)] = $row['lang_value']; } $this->db->sql_freeresult($result); } diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index eb8d3e47d6..86e480f6b3 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -155,7 +155,7 @@ class type_bool extends type_base if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, FIELD_BOOL, false); + $this->lang_helper->get_option_lang($field_id, $lang_id, false); } if (!$field_value && $field_data['field_show_novalue']) @@ -203,7 +203,7 @@ class type_bool extends type_base { if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $this->get_service_name(), $preview_options); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 52c9fcf86a..5ecbf4e167 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -135,7 +135,7 @@ class type_dropdown extends type_base // retrieve option lang data if necessary if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1)) { - $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], $this->get_service_name(), false); + $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], false); } if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value)) @@ -160,7 +160,7 @@ class type_dropdown extends type_base $lang_id = $field_data['lang_id']; if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, $this->get_service_name(), false); + $this->lang_helper->get_option_lang($field_id, $lang_id, false); } if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) @@ -199,7 +199,7 @@ class type_dropdown extends type_base if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $this->get_service_name(), $preview_options); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } $profile_row['field_value'] = (int) $value; -- cgit v1.2.1 From 6cf6ec33545ae3be2cd6f02f0c23f154006a29cf Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 18:13:01 +0530 Subject: [ticket/12759] Cache lang options for all fields while displaying Previously these would be fetched one field at one time, causing a large number of queries in case there were large number of custom profile fields and/or unique number of users in areas such as viewing topics. Resolve this by caching them at once when generating data for displaying them in templates. PHPBB3-12759 --- phpBB/phpbb/profilefields/manager.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 490db0419a..a32baaac56 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -36,6 +36,12 @@ class manager */ protected $dispatcher; + /** + * Profile fields language helper + * @var \phpbb\profilefields\lang_helper + */ + protected $lang_helper; + /** * Request object * @var \phpbb\request\request @@ -74,6 +80,7 @@ class manager * @param \phpbb\auth\auth $auth Auth object * @param \phpbb\db\driver\driver_interface $db Database object * @param \phpbb\event\dispatcher $dispatcher Event dispatcher object + * @param \phpbb\profilefields\lang_helper $lang_helper Language helper object * @param \phpbb\request\request $request Request object * @param \phpbb\template\template $template Template object * @param \phpbb\di\service_collection $type_collection @@ -82,11 +89,12 @@ class manager * @param string $fields_language_table * @param string $fields_data_table */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) + public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) { $this->auth = $auth; $this->db = $db; $this->dispatcher = $dispatcher; + $this->lang_helper = $lang_helper; $this->request = $request; $this->template = $template; $this->type_collection = $type_collection; @@ -385,6 +393,25 @@ class manager $vars = array('profile_row', 'tpl_fields', 'use_contact_fields'); extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data_before', compact($vars))); + if (!empty($profile_row)) + { + $field_ids = array(); + foreach ($profile_row as $ident_ary) + { + if (empty($field_ids[$ident_ary['data']['lang_id']])) + { + $field_ids[$ident_ary['data']['lang_id']] = array(); + + } + $field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id']; + } + + foreach ($field_ids as $lang => $fields) + { + $this->lang_helper->get_option_lang($fields, $lang, false); + } + } + foreach ($profile_row as $ident => $ident_ary) { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; -- cgit v1.2.1 From aebe03f88cb3c2aee6e0b859be82d5235efdacea Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 18:55:35 +0530 Subject: [ticket/12759] Cache the lang options earlier Previously it would re-run on every post PHPBB3-12759 --- phpBB/phpbb/profilefields/manager.php | 47 +++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index a32baaac56..f14aa2a2b4 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -367,6 +367,34 @@ class manager return $user_fields; } + /** + * Cache user's profile fields' language options + * @param array $profile_row Array with users profile field data + * @return void + */ + public function cache_profile_fields_lang_options($profile_row) + { + if (!empty($profile_row)) + { + $field_ids = array(); + foreach ($profile_row as $ident_ary) + { + if (empty($field_ids[$ident_ary['data']['lang_id']])) + { + $field_ids[$ident_ary['data']['lang_id']] = array(); + + } + + $field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id']; + } + + foreach ($field_ids as $lang => $fields) + { + $this->lang_helper->get_option_lang($fields, $lang, false); + } + } + } + /** * Assign the user's profile fields data to the template * @@ -393,25 +421,6 @@ class manager $vars = array('profile_row', 'tpl_fields', 'use_contact_fields'); extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data_before', compact($vars))); - if (!empty($profile_row)) - { - $field_ids = array(); - foreach ($profile_row as $ident_ary) - { - if (empty($field_ids[$ident_ary['data']['lang_id']])) - { - $field_ids[$ident_ary['data']['lang_id']] = array(); - - } - $field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id']; - } - - foreach ($field_ids as $lang => $fields) - { - $this->lang_helper->get_option_lang($fields, $lang, false); - } - } - foreach ($profile_row as $ident => $ident_ary) { $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; -- cgit v1.2.1 From 6251d68be431704086477d143cddadcc1fcebb33 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 19:04:28 +0530 Subject: [ticket/12759] Make sure $field_id has unique elements Otherwise it would cause a bunch of repetitive IDs passed to the IN clause PHPBB3-12759 --- phpBB/phpbb/profilefields/lang_helper.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 9e4991e94a..b950ace872 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -78,6 +78,7 @@ class lang_helper { $field_id[$k] = (int) $id; } + $field_id = array_unique($field_id); } else { -- cgit v1.2.1 From 51bc31da20c402b820d8af41ca7d4bfdb7caaed2 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 19:08:55 +0530 Subject: [ticket/12759] Little code cleanup PHPBB3-12759 --- phpBB/phpbb/profilefields/lang_helper.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index b950ace872..2ea3066f94 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -74,11 +74,7 @@ class lang_helper { if (is_array($field_id)) { - foreach ($field_id as $k => $id) - { - $field_id[$k] = (int) $id; - } - $field_id = array_unique($field_id); + $field_id = array_map('intval', array_unique($field_id)); } else { -- cgit v1.2.1 From c82a0b74cfc009af61aa1bfc5e220ec82b441f7a Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 22 Jun 2014 19:18:08 +0530 Subject: [ticket/12759] Add phpDoc comments to explain get_option_lang PHPBB3-12759 --- phpBB/phpbb/profilefields/lang_helper.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 2ea3066f94..86c4e6ff72 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -50,6 +50,10 @@ class lang_helper /** * Get language entries for options and store them here for later use + * + * @param mixed $field_id Can be an int or an array of int for multiple field IDs + * @param int $lang_id + * @param mixed $preview_options If set to not false, $field_id cannot be an array */ public function get_option_lang($field_id, $lang_id, $preview_options) { -- cgit v1.2.1 From c1df2ce62a62517e840ff30fa11a6cffb84396bc Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Mon, 23 Jun 2014 13:32:46 +0530 Subject: [ticket/12759] Extra line in profilefields_manager PHPBB3-12759 --- phpBB/phpbb/profilefields/manager.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index f14aa2a2b4..251899146b 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -382,7 +382,6 @@ class manager if (empty($field_ids[$ident_ary['data']['lang_id']])) { $field_ids[$ident_ary['data']['lang_id']] = array(); - } $field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id']; -- cgit v1.2.1 From 2cf4a4f6fe74ee6d774956113570d6ed7c5246cc Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Thu, 26 Jun 2014 03:07:45 +0530 Subject: [ticket/12759] Cache all lang_options in lang_helper instead PHPBB3-12759 --- phpBB/phpbb/profilefields/lang_helper.php | 63 +++++++++++------------- phpBB/phpbb/profilefields/manager.php | 27 ---------- phpBB/phpbb/profilefields/type/type_bool.php | 4 +- phpBB/phpbb/profilefields/type/type_dropdown.php | 6 +-- 4 files changed, 34 insertions(+), 66 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 86c4e6ff72..2e353722b2 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -49,55 +49,50 @@ class lang_helper } /** - * Get language entries for options and store them here for later use + * Loads preview options into language entries for options * - * @param mixed $field_id Can be an int or an array of int for multiple field IDs + * @param int $field_id * @param int $lang_id - * @param mixed $preview_options If set to not false, $field_id cannot be an array + * @param mixed $preview_options */ - public function get_option_lang($field_id, $lang_id, $preview_options) + public function load_preview_options($field_id, $lang_id, $preview_options) { - if ($preview_options !== false) - { - $lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options; + $lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options; - foreach ($lang_options as $num => $var) - { - if (!isset($this->options_lang[$field_id])) - { - $this->options_lang[$field_id] = array(); - } - if (!isset($this->options_lang[$field_id][$lang_id])) - { - $this->options_lang[$field_id][$lang_id] = array(); - } - $this->options_lang[$field_id][$lang_id][($num + 1)] = $var; - } - } - else + foreach ($lang_options as $num => $var) { - if (is_array($field_id)) + if (!isset($this->options_lang[$field_id])) { - $field_id = array_map('intval', array_unique($field_id)); + $this->options_lang[$field_id] = array(); } - else + if (!isset($this->options_lang[$field_id][$lang_id])) { - $field_id = array((int) $field_id); + $this->options_lang[$field_id][$lang_id] = array(); } + $this->options_lang[$field_id][$lang_id][($num + 1)] = $var; + } + } - $sql = 'SELECT field_id, option_id, lang_value + /** + * Fetches language entries for options from DB + * + * @param int $lang_id + */ + public function load_option_lang($lang_id) + { + $sql = 'SELECT field_id, option_id, lang_value FROM ' . $this->language_table . ' - WHERE ' . $this->db->sql_in_set('field_id', $field_id) . ' - AND lang_id = ' . (int) $lang_id . " + WHERE lang_id = ' . (int) $lang_id . " ORDER BY option_id"; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $this->options_lang[$row['field_id']][$lang_id][($row['option_id'] + 1)] = $row['lang_value']; - } - $this->db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->options_lang[$row['field_id']][$lang_id][($row['option_id'] + 1)] = $row['lang_value']; } + + $this->db->sql_freeresult($result); } /** diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 251899146b..bd08580431 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -367,33 +367,6 @@ class manager return $user_fields; } - /** - * Cache user's profile fields' language options - * @param array $profile_row Array with users profile field data - * @return void - */ - public function cache_profile_fields_lang_options($profile_row) - { - if (!empty($profile_row)) - { - $field_ids = array(); - foreach ($profile_row as $ident_ary) - { - if (empty($field_ids[$ident_ary['data']['lang_id']])) - { - $field_ids[$ident_ary['data']['lang_id']] = array(); - } - - $field_ids[$ident_ary['data']['lang_id']][] = $ident_ary['data']['field_id']; - } - - foreach ($field_ids as $lang => $fields) - { - $this->lang_helper->get_option_lang($fields, $lang, false); - } - } - } - /** * Assign the user's profile fields data to the template * diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 86e480f6b3..b9a7f93b85 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -155,7 +155,7 @@ class type_bool extends type_base if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, false); + $this->lang_helper->load_option_lang($lang_id); } if (!$field_value && $field_data['field_show_novalue']) @@ -203,7 +203,7 @@ class type_bool extends type_base { if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 5ecbf4e167..7780f70d64 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -135,7 +135,7 @@ class type_dropdown extends type_base // retrieve option lang data if necessary if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1)) { - $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], false); + $this->lang_helper->load_option_lang($field_data['lang_id']); } if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value)) @@ -160,7 +160,7 @@ class type_dropdown extends type_base $lang_id = $field_data['lang_id']; if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, false); + $this->lang_helper->load_option_lang($lang_id); } if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) @@ -199,7 +199,7 @@ class type_dropdown extends type_base if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } $profile_row['field_value'] = (int) $value; -- cgit v1.2.1 From 98262a5a175727b2dacea283d2fec127a35ed819 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Thu, 26 Jun 2014 03:15:12 +0530 Subject: [ticket/12759] Remove lang_helper from profilefields_manager No longer required PHPBB3-12759 --- phpBB/phpbb/profilefields/manager.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index bd08580431..490db0419a 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -36,12 +36,6 @@ class manager */ protected $dispatcher; - /** - * Profile fields language helper - * @var \phpbb\profilefields\lang_helper - */ - protected $lang_helper; - /** * Request object * @var \phpbb\request\request @@ -80,7 +74,6 @@ class manager * @param \phpbb\auth\auth $auth Auth object * @param \phpbb\db\driver\driver_interface $db Database object * @param \phpbb\event\dispatcher $dispatcher Event dispatcher object - * @param \phpbb\profilefields\lang_helper $lang_helper Language helper object * @param \phpbb\request\request $request Request object * @param \phpbb\template\template $template Template object * @param \phpbb\di\service_collection $type_collection @@ -89,12 +82,11 @@ class manager * @param string $fields_language_table * @param string $fields_data_table */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) + public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) { $this->auth = $auth; $this->db = $db; $this->dispatcher = $dispatcher; - $this->lang_helper = $lang_helper; $this->request = $request; $this->template = $template; $this->type_collection = $type_collection; -- cgit v1.2.1 From 6d464e0bc44574687d5d9fce42d5a0515b7c9a01 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Fri, 27 Jun 2014 17:58:28 +0530 Subject: [ticket/12759] Fix type_bool and type_dropdown's UCP fields PHPBB3-12759 --- phpBB/phpbb/profilefields/type/type_bool.php | 9 ++++++++- phpBB/phpbb/profilefields/type/type_dropdown.php | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index b9a7f93b85..f67e58ee3a 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -203,7 +203,14 @@ class type_bool extends type_base { if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + if ($preview_options) + { + $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + } + else + { + $this->lang_helper->load_option_lang($profile_row['lang_id']); + } } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 7780f70d64..118ddf1f37 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -199,7 +199,14 @@ class type_dropdown extends type_base if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + if ($preview_options) + { + $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); + } + else + { + $this->lang_helper->load_option_lang($profile_row['lang_id']); + } } $profile_row['field_value'] = (int) $value; -- cgit v1.2.1 From eb13b4ae28223700034ae7482ab27a6d2cdbccd1 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 28 Jun 2014 13:19:55 +0200 Subject: [ticket/12782] Use an interface for the phpbb event_dispatcher PHPBB3-12782 --- phpBB/phpbb/profilefields/manager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 490db0419a..f9a6d56dd1 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -32,7 +32,7 @@ class manager /** * Event dispatcher object - * @var \phpbb\event\dispatcher + * @var \phpbb\event\dispatcher_interface */ protected $dispatcher; @@ -73,7 +73,7 @@ class manager * * @param \phpbb\auth\auth $auth Auth object * @param \phpbb\db\driver\driver_interface $db Database object - * @param \phpbb\event\dispatcher $dispatcher Event dispatcher object + * @param \phpbb\event\dispatcher_interface $dispatcher Event dispatcher object * @param \phpbb\request\request $request Request object * @param \phpbb\template\template $template Template object * @param \phpbb\di\service_collection $type_collection @@ -82,7 +82,7 @@ class manager * @param string $fields_language_table * @param string $fields_data_table */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) + public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table) { $this->auth = $auth; $this->db = $db; -- cgit v1.2.1 From 690de2113433e0330ca53f928f6b923ea36d41c1 Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Thu, 10 Jul 2014 07:44:09 +0300 Subject: [ticket/12791] String profile fields do not use links ... smilies and line breaks in memberlist The value is overwritten with the contact value Added aditional check if the field is a contact so we don't overwrite it. PHPBB3-12791 --- phpBB/phpbb/profilefields/manager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index f3b1676799..c79e13c958 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -390,6 +390,7 @@ class manager $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); $value_raw = $profile_field->get_profile_value_raw($ident_ary['value'], $ident_ary['data']); + $is_contact = $ident_ary['data']['field_is_contact']; if ($value === null) { @@ -397,7 +398,7 @@ class manager } $field_desc = $contact_url = ''; - if ($use_contact_fields) + if ($use_contact_fields && $is_contact) { $value = $profile_field->get_profile_contact_value($ident_ary['value'], $ident_ary['data']); $field_desc = $this->user->lang($ident_ary['data']['field_contact_desc']); -- cgit v1.2.1 From 27f15c0d5b661c15eeaf98928128b7b176186954 Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Thu, 10 Jul 2014 11:43:52 +0300 Subject: [ticket/12791] Changed the if check Removed unneeded variable PHPBB3-12791 --- phpBB/phpbb/profilefields/manager.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index c79e13c958..98802d2209 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -390,7 +390,6 @@ class manager $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); $value_raw = $profile_field->get_profile_value_raw($ident_ary['value'], $ident_ary['data']); - $is_contact = $ident_ary['data']['field_is_contact']; if ($value === null) { @@ -398,7 +397,7 @@ class manager } $field_desc = $contact_url = ''; - if ($use_contact_fields && $is_contact) + if ($use_contact_fields && $ident_ary['data']['field_is_contact']) { $value = $profile_field->get_profile_contact_value($ident_ary['value'], $ident_ary['data']); $field_desc = $this->user->lang($ident_ary['data']['field_contact_desc']); -- cgit v1.2.1 From 57bbb4548b2761c01fc14345982e00be1ea27af1 Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Thu, 10 Jul 2014 06:12:13 +0300 Subject: [ticket/12793] String '0' does not display for string profile fields See https://github.com/phpbb/phpbb/pull/2647#discussion_r14503051 PHPBB3-12793 --- phpBB/phpbb/profilefields/type/type_string_common.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index c2b951b6c9..0842675a11 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -98,7 +98,7 @@ abstract class type_string_common extends type_base */ public function get_profile_value($field_value, $field_data) { - if (!$field_value && !$field_data['field_show_novalue']) + if (($field_value === null || $field_value === '') && !$field_data['field_show_novalue']) { return null; } @@ -114,7 +114,7 @@ abstract class type_string_common extends type_base */ public function get_profile_value_raw($field_value, $field_data) { - if (!$field_value && !$field_data['field_show_novalue']) + if (($field_value === null || $field_value === '') && !$field_data['field_show_novalue']) { return null; } @@ -127,7 +127,7 @@ abstract class type_string_common extends type_base */ public function get_profile_contact_value($field_value, $field_data) { - if (!$field_value && !$field_data['field_show_novalue']) + if (($field_value === null || $field_value === '') && !$field_data['field_show_novalue']) { return null; } -- cgit v1.2.1 From 223c634bee355f8df521163e33585b0abf1e1f69 Mon Sep 17 00:00:00 2001 From: Stanislav Atanasov Date: Thu, 10 Jul 2014 11:32:30 +0300 Subject: [ticket/12793] Changing get_profile_contact_value to get_profile_value_raw Changing the return to get_profile_value_raw PHPBB3-12793 --- phpBB/phpbb/profilefields/type/type_string_common.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 0842675a11..0eaf7e527d 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -127,12 +127,7 @@ abstract class type_string_common extends type_base */ public function get_profile_contact_value($field_value, $field_data) { - if (($field_value === null || $field_value === '') && !$field_data['field_show_novalue']) - { - return null; - } - - return $field_value; + return $this->get_profile_value_raw($field_value, $field_data); } /** -- cgit v1.2.1 From 8f2395857e785cf8b7ccb338937b7cd30b329aab Mon Sep 17 00:00:00 2001 From: n-aleha Date: Mon, 19 May 2014 04:07:08 +0300 Subject: [ticket/12557] Search, cron and profilefields fixes PHPBB3-12557 --- phpBB/phpbb/profilefields/type/type_interface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index 2dd13fa480..ec770f9467 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -189,8 +189,8 @@ interface type_interface /** * Allows manipulating the intended variables if needed * - * @param string $key Name of the option * @param int $step Step on which the option is hidden + * @param string $key Name of the option * @param string $action Currently performed action (create|edit) * @param array $field_data Array with data for this field * @return mixed Final value of the option -- cgit v1.2.1 From 79cccebc6e93e4e7f1231ad8797e8a94e3033a46 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Sun, 3 Aug 2014 18:25:08 +0530 Subject: [ticket/12910] Set get_name for Google+ fields PHPBB3-12910 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index df1bcc7f4b..887baa3de1 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -15,6 +15,14 @@ namespace phpbb\profilefields\type; class type_googleplus extends type_string { + /** + * {@inheritDoc} + */ + public function get_name() + { + return $this->user->lang('FIELD_GOOGLEPLUS'); + } + /** * {@inheritDoc} */ -- cgit v1.2.1 From a6b275de5cd96f7a2527958e510a628012041a93 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 8 Aug 2014 15:03:33 +0200 Subject: [ticket/12794] Properly validate google+ field against valid character set PHPBB3-12794 --- phpBB/phpbb/profilefields/type/type_googleplus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_googleplus.php b/phpBB/phpbb/profilefields/type/type_googleplus.php index 887baa3de1..e6729b1935 100644 --- a/phpBB/phpbb/profilefields/type/type_googleplus.php +++ b/phpBB/phpbb/profilefields/type/type_googleplus.php @@ -40,7 +40,7 @@ class type_googleplus extends type_string 'field_length' => 20, 'field_minlen' => 3, 'field_maxlen' => 255, - 'field_validation' => '[\w]+', + 'field_validation' => '(?:(?!\.{2,})([^<>=+]))+', 'field_novalue' => '', 'field_default_value' => '', ); -- cgit v1.2.1 From fcd2a2f186641f0c11abc40e196e6d916c87646c Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Wed, 10 Sep 2014 18:37:16 +0200 Subject: [ticket/12734] Remove unnecessary error supressing PHPBB3-12734 --- phpBB/phpbb/profilefields/manager.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 98802d2209..4ad3214ae4 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -245,12 +245,8 @@ class manager $cp_data = $this->build_insert_sql_array($cp_data); $cp_data['user_id'] = (int) $user_id; - $this->db->sql_return_on_error(true); - $sql = 'INSERT INTO ' . $this->fields_data_table . ' ' . $this->db->sql_build_array('INSERT', $cp_data); $this->db->sql_query($sql); - - $this->db->sql_return_on_error(false); } } @@ -328,7 +324,7 @@ class manager * Event to modify profile fields data retrieved from the database * * @event core.grab_profile_fields_data - * @var array user_ids Single user id or an array of ids + * @var array user_ids Single user id or an array of ids * @var array field_data Array with profile fields data * @since 3.1.0-b3 */ @@ -377,7 +373,7 @@ class manager * Event to modify data of the generated profile fields, before the template assignment loop * * @event core.generate_profile_fields_template_data_before - * @var array profile_row Array with users profile field data + * @var array profile_row Array with users profile field data * @var array tpl_fields Array with template data fields * @var bool use_contact_fields Should we display contact fields as such? * @since 3.1.0-b3 @@ -445,7 +441,7 @@ class manager * Event to modify template data of the generated profile fields * * @event core.generate_profile_fields_template_data - * @var array profile_row Array with users profile field data + * @var array profile_row Array with users profile field data * @var array tpl_fields Array with template data fields * @var bool use_contact_fields Should we display contact fields as such? * @since 3.1.0-b3 -- cgit v1.2.1 From dc65058c20f5828dd33c6811c2f65bb14375a12e Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 13 Sep 2014 12:35:44 +0800 Subject: [ticket/13055] Add string profile fields validation options to support unicode PHPBB3-13055 --- phpBB/phpbb/profilefields/type/type_string_common.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index 0eaf7e527d..ff33a7b49c 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -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) -- cgit v1.2.1 From f64a937a57d108cf7cf6343e8d439a5d035c4e53 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Sep 2014 12:27:14 +0200 Subject: [ticket/13111] Dropdown options are already an array in the field data PHPBB3-13111 --- phpBB/phpbb/profilefields/type/type_base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index c770a0d93c..52f5d15511 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -133,7 +133,7 @@ abstract class type_base implements type_interface { foreach ($field_data[$key] as $lang_id => $options) { - $field_data[$key][$lang_id] = explode("\n", $options); + $field_data[$key][$lang_id] = is_array($options) ? $options : explode("\n", $options); } return $current_value; -- cgit v1.2.1 From 3108d0b0608d12e8f1e2e10dfa8d802ad86eb908 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Tue, 11 Nov 2014 16:28:06 -0800 Subject: [ticket/13209] Fix expected request value of CPF language fields. Multiple languages can be edited, thus the expected value is an array. PHPBB3-13209 --- phpBB/phpbb/profilefields/type/type_base.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 52f5d15511..9b4bada26d 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -158,7 +158,19 @@ abstract class type_base implements type_interface } else { - return $this->request->variable($key, '', true); + $default_value = ''; + $lang_fields = array( + 'l_lang_name', + 'l_lang_explain', + 'l_lang_default_value', + 'l_lang_options', + ); + + if (in_array($key, $lang_fields)) + { + $default_value = array(0 => ''); + } + return $this->request->variable($key, $default_value, true); } } -- cgit v1.2.1 From ec220d64946e9fc50df6645087a38c8852625af0 Mon Sep 17 00:00:00 2001 From: Cesar G Date: Tue, 11 Nov 2014 16:32:04 -0800 Subject: [ticket/13209] Gather language field values for boolean CPF's in all steps. The user can move back and forth between all three steps and as such the lang field data should be expected in all steps. PHPBB3-13209 --- phpBB/phpbb/profilefields/type/type_bool.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 0582722833..75934e3be7 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -352,7 +352,7 @@ class type_bool extends type_base } } - if ($step == 3 && ($field_data[$key] || $action != 'edit') && $key == 'l_lang_options') + if ($key == 'l_lang_options' && $this->request->is_set($key)) { $field_data[$key] = $this->request->variable($key, array(0 => array('')), true); -- cgit v1.2.1 From d43f196fa6887fb399be318b30a594f98258aa1a Mon Sep 17 00:00:00 2001 From: Cesar G Date: Tue, 11 Nov 2014 16:48:25 -0800 Subject: [ticket/12642] Ensure CPF type specific options are set when editing booleans. prepare_hidden_fields is expected to return null if the option is not sent in the request. The boolean method returns false instead, which results in the options being set as false in hidden fields when accessing the first edit step. When checking the "Default value" option, there is also a failure to check whether the "Field type" option is set to checkbox, thus resulting in this option getting lost as well. PHPBB3-12642 --- phpBB/phpbb/profilefields/type/type_bool.php | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 0582722833..3a13102117 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -367,29 +367,29 @@ class type_bool extends type_base */ public function prepare_hidden_fields($step, $key, $action, &$field_data) { - if ($key == 'l_lang_options' && $this->request->is_set('l_lang_options')) + if ($key == 'field_default_value') { - return $this->request->variable($key, array(array('')), true); - } - else if ($key == 'field_default_value') - { - return $this->request->variable($key, $field_data[$key]); - } - else - { - if (!$this->request->is_set($key)) - { - return false; - } - else if ($key == 'field_ident' && isset($field_data[$key])) - { - return $field_data[$key]; - } - else + $field_length = $this->request->variable('field_length', 0); + + // Do a simple is set check if using checkbox. + if ($field_length == 2) { - return ($key == 'lang_options') ? $this->request->variable($key, array(''), true) : $this->request->variable($key, '', true); + return $this->request->is_set($key); } + return $this->request->variable($key, $field_data[$key], true); + } + + $default_lang_options = array( + 'l_lang_options' => array(0 => array('')), + 'lang_options' => array(0 => ''), + ); + + if (isset($default_lang_options[$key]) && $this->request->is_set($key)) + { + return $this->request->variable($key, $default_lang_options[$key], true); } + + return parent::prepare_hidden_fields($step, $key, $action, $field_data); } /** -- cgit v1.2.1 From a8c62e707af0971a62b7601f4ac6ea46f57b16c2 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 25 Nov 2014 22:16:30 +0700 Subject: [ticket/12926] Support for IDN (IRI) Add international domain name support for URLs. PHPBB3-12926 --- phpBB/phpbb/profilefields/type/type_url.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_url.php b/phpBB/phpbb/profilefields/type/type_url.php index bc8ac869d0..fe0bffd582 100644 --- a/phpBB/phpbb/profilefields/type/type_url.php +++ b/phpBB/phpbb/profilefields/type/type_url.php @@ -64,7 +64,7 @@ class type_url extends type_string return false; } - if (!preg_match('#^' . get_preg_expression('url') . '$#i', $field_value)) + if (!preg_match('#^' . get_preg_expression('url') . '$#iu', $field_value)) { return $this->user->lang('FIELD_INVALID_URL', $this->get_field_name($field_data['lang_name'])); } -- cgit v1.2.1 From b7f69edaa273fec2b29a9300a766ffb9639686d2 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Sun, 26 Oct 2014 20:08:28 +0100 Subject: [ticket/12866] Assume underscore is part of \w PHPBB3-12866 --- phpBB/phpbb/profilefields/type/type_string_common.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string_common.php b/phpBB/phpbb/profilefields/type/type_string_common.php index ff33a7b49c..f5e1992044 100644 --- a/phpBB/phpbb/profilefields/type/type_string_common.php +++ b/phpBB/phpbb/profilefields/type/type_string_common.php @@ -18,11 +18,11 @@ abstract class type_string_common extends type_base protected $validation_options = array( 'CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', - 'ALPHA_ONLY' => '[\w]+', - 'ALPHA_UNDERSCORE' => '[\w_]+', - 'ALPHA_DOTS' => '[\w.]+', - 'ALPHA_SPACERS' => '[\w\x20_+\-\[\]]+', - 'ALPHA_PUNCTUATION' => '[a-zA-Z][\w\.,\-_]+', + '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.]+', -- cgit v1.2.1 From d1bff80dd1a1edb69d71cee0363f013c21eb36a6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 20 Jan 2015 22:56:33 +0100 Subject: [ticket/13528] Return correct translation instead of is_set() PHPBB3-13528 --- phpBB/phpbb/profilefields/type/type_bool.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 77eedcbd04..f6f3f17a6c 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -173,7 +173,7 @@ class type_bool extends type_base } else { - return $this->lang_helper->is_set($field_id, $lang_id, $field_value + 1); + return $this->lang_helper->is_set($field_id, $lang_id, $field_value + 1) ? $this->lang_helper->get($field_id, $lang_id, $field_value + 1) : null; } } -- cgit v1.2.1 From cf0170d5e38117cf256d45a6c0164ea76b3887bc Mon Sep 17 00:00:00 2001 From: javiexin Date: Sat, 18 Jul 2015 18:29:25 +0200 Subject: [ticket/14037] Allows adapting memberlist profile fields headline Adds an event to allow modifying the profile fields headline in line with modifications to profile fields data. PHPBB3-14037 --- phpBB/phpbb/profilefields/manager.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 4ad3214ae4..822b81e0ad 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -276,12 +276,30 @@ class manager $profile_field = $this->type_collection[$field_data['field_type']]; $tpl_fields[] = array( + 'PROFILE_FIELD_IDENT' => $field_ident, 'PROFILE_FIELD_TYPE' => $field_data['field_type'], 'PROFILE_FIELD_NAME' => $profile_field->get_field_name($field_data['lang_name']), 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($field_data['lang_explain']), ); } + $profile_cache = $this->profile_cache; + /** + * Event to modify template headlines of the generated profile fields + * + * @event core.generate_profile_fields_template_headlines + * @var string restrict_option Restrict the published fields to a certain profile field option + * @var array tpl_fields Array with template data fields + * @var array profile_cache A copy of the profile cache to make additional checks + * @since 3.1.6-RC1 + */ + $vars = array( + 'restrict_option', + 'tpl_fields', + 'profile_cache', + ); + extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_headlines', compact($vars))); + return $tpl_fields; } -- cgit v1.2.1 From 897b9f333bf2ee05d8c4e371d2b324d255fbfd5e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 20 Aug 2015 10:14:07 +0200 Subject: [ticket/14037] Minor coding style improvements to event PHPBB3-14037 --- phpBB/phpbb/profilefields/manager.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php index 822b81e0ad..ea4b24af56 100644 --- a/phpBB/phpbb/profilefields/manager.php +++ b/phpBB/phpbb/profilefields/manager.php @@ -284,6 +284,7 @@ class manager } $profile_cache = $this->profile_cache; + /** * Event to modify template headlines of the generated profile fields * @@ -299,6 +300,7 @@ class manager 'profile_cache', ); extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_headlines', compact($vars))); + unset($profile_cache); return $tpl_fields; } -- cgit v1.2.1 From aca6e64669079abc385f3094d8b6c186d9b46082 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 6 Nov 2015 10:20:05 +0100 Subject: [ticket/14272] Only use maxlength and size for allowed input elements PHPBB3-14272 --- phpBB/phpbb/profilefields/type/type_int.php | 6 +++--- phpBB/phpbb/profilefields/type/type_string.php | 6 +++--- phpBB/phpbb/profilefields/type/type_text.php | 6 +++--- phpBB/phpbb/profilefields/type/type_url.php | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index dd08df94c1..9dc0181cb8 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -61,9 +61,9 @@ class type_int extends type_base public function get_options($default_lang_id, $field_data) { $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), - 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => ''), 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => ''), ); diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 67befc457d..a8432eaae5 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -61,9 +61,9 @@ class type_string extends type_string_common public function get_options($default_lang_id, $field_data) { $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), - 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => ''), ); diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index bacf60a213..79ee82351a 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -61,9 +61,9 @@ class type_text extends type_string_common public function get_options($default_lang_id, $field_data) { $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ' ' . $this->user->lang['ROWS'] . '
' . $this->user->lang['COLUMNS'] . ' '), - 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ' ' . $this->user->lang['ROWS'] . '
' . $this->user->lang['COLUMNS'] . ' '), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => ''), ); diff --git a/phpBB/phpbb/profilefields/type/type_url.php b/phpBB/phpbb/profilefields/type/type_url.php index fe0bffd582..375cf5b19a 100644 --- a/phpBB/phpbb/profilefields/type/type_url.php +++ b/phpBB/phpbb/profilefields/type/type_url.php @@ -29,9 +29,9 @@ class type_url extends type_string public function get_options($default_lang_id, $field_data) { $options = array( - 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), - 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), + 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), ); return $options; -- cgit v1.2.1 From 47e418e50e9d516e768bd675892c3c4f5dfa571e Mon Sep 17 00:00:00 2001 From: javiexin Date: Mon, 5 Dec 2016 01:07:43 +0100 Subject: [ticket/14889] Missing method in profile fields type interface Completes the profile fields type interface by defining a missing required method for all implementations of a type. PHPBB3-14889 --- phpBB/phpbb/profilefields/type/type_interface.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index ec770f9467..93b9e4b893 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -133,6 +133,14 @@ interface type_interface */ public function get_field_ident($field_data); + /** + * Get the localized name of the field + * + * @param string $field_name Unlocalized name of this field + * @return string Localized name of the field + */ + public function get_field_name($field_name); + /** * Get the column type for the database * -- cgit v1.2.1 From 591eff9e78594b7a95203b5bb44ac2883280a9db Mon Sep 17 00:00:00 2001 From: javiexin Date: Mon, 5 Dec 2016 18:35:16 +0100 Subject: [ticket/14890] Typo in input validation of profile fields of type string This bug was introduced by PHPBB3-14272 PHPBB3-14890 --- phpBB/phpbb/profilefields/type/type_string.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index a8432eaae5..8710c8c603 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -63,7 +63,7 @@ class type_string extends type_string_common $options = array( 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => ''), 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => ''), - 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), + 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => ''), 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => ''), ); -- cgit v1.2.1 From 71a3f12d2ad361ce2907f20a14a70095a162e470 Mon Sep 17 00:00:00 2001 From: javiexin Date: Fri, 24 Mar 2017 23:55:27 +0100 Subject: [ticket/15146] Date profile field validation incorrect Fix by changing select input field options to match validation range PHPBB3-15146 --- phpBB/phpbb/profilefields/type/type_date.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/profilefields') diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 90ac9a6703..63a0c79a3d 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -264,7 +264,7 @@ class type_date extends type_base } $profile_row['s_year_options'] = ''; - for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++) + for ($i = 1901; $i <= $now['year'] + 50; $i++) { $profile_row['s_year_options'] .= '"; } -- cgit v1.2.1