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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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 7d2d18fb50c5c071098de594ec85897437e57007 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 15 Jan 2014 16:37:21 +0100 Subject: [ticket/11201] Move "get type" code into a new function PHPBB3-11201 --- phpBB/phpbb/db/tools.php | 106 +++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 46 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/db/tools.php b/phpBB/phpbb/db/tools.php index 4360c89ac3..65098b643b 100644 --- a/phpBB/phpbb/db/tools.php +++ b/phpBB/phpbb/db/tools.php @@ -1474,52 +1474,7 @@ class tools } // Get type - if (strpos($column_data[0], ':') !== false) - { - list($orig_column_type, $column_length) = explode(':', $column_data[0]); - if (!is_array($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'])) - { - $column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'], $column_length); - } - else - { - if (isset($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule'])) - { - switch ($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule'][0]) - { - case 'div': - $column_length /= $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule'][1]; - $column_length = ceil($column_length); - $column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'][0], $column_length); - break; - } - } - - if (isset($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'])) - { - switch ($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][0]) - { - case 'mult': - $column_length *= $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][1]; - if ($column_length > $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][2]) - { - $column_type = $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][3]; - } - else - { - $column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'][0], $column_length); - } - break; - } - } - } - $orig_column_type .= ':'; - } - else - { - $orig_column_type = $column_data[0]; - $column_type = $this->dbms_type_map[$this->sql_layer][$column_data[0]]; - } + list($column_type, $orig_column_type) = $this->get_column_type($column_data[0]); // Adjust default value if db-dependent specified if (is_array($column_data[1])) @@ -1694,6 +1649,65 @@ class tools return $return_array; } + /** + * Get the column's database type from the type map + * + * @param string $column_map_type + * @return array column type for this database + * and map type without length + */ + function get_column_type($column_map_type) + { + if (strpos($column_map_type, ':') !== false) + { + list($orig_column_type, $column_length) = explode(':', $column_map_type); + if (!is_array($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'])) + { + $column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'], $column_length); + } + else + { + if (isset($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule'])) + { + switch ($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule'][0]) + { + case 'div': + $column_length /= $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['rule'][1]; + $column_length = ceil($column_length); + $column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'][0], $column_length); + break; + } + } + + if (isset($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'])) + { + switch ($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][0]) + { + case 'mult': + $column_length *= $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][1]; + if ($column_length > $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][2]) + { + $column_type = $this->dbms_type_map[$this->sql_layer][$orig_column_type . ':']['limit'][3]; + } + else + { + $column_type = sprintf($this->dbms_type_map[$this->sql_layer][$orig_column_type . ':'][0], $column_length); + } + break; + } + } + } + $orig_column_type .= ':'; + } + else + { + $orig_column_type = $column_map_type; + $column_type = $this->dbms_type_map[$this->sql_layer][$column_map_type]; + } + + return array($column_type, $orig_column_type); + } + /** * Add new column */ -- 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') 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') 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') 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') 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') 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') 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') 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') 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 --- .../db/migration/data/v310/profilefield_types.php | 106 +++++++++++++++++++++ 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 ++ 11 files changed, 191 insertions(+), 16 deletions(-) create mode 100644 phpBB/phpbb/db/migration/data/v310/profilefield_types.php (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/db/migration/data/v310/profilefield_types.php b/phpBB/phpbb/db/migration/data/v310/profilefield_types.php new file mode 100644 index 0000000000..553ff592a4 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/profilefield_types.php @@ -0,0 +1,106 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_type' => array('VCHAR:100', ''), + ), + $this->table_prefix . 'profile_fields_lang' => array( + 'field_type' => array('VCHAR:100', ''), + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'update_profile_fields_type'))), + array('custom', array(array($this, 'update_profile_fields_lang_type'))), + ); + } + + public function update_profile_fields_type() + { + // Update profile field types + $sql = 'SELECT field_type + FROM ' . $this->table_prefix . 'profile_fields + GROUP BY field_type'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . $this->table_prefix . "profile_fields + SET field_type = '" . $this->db->sql_escape($this->convert_phpbb30_field_type($row['field_type'])) . "' + WHERE field_type = '" . $this->db->sql_escape($row['field_type']) . "'"; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + public function update_profile_fields_lang_type() + { + // Update profile field language types + $sql = 'SELECT field_type + FROM ' . $this->table_prefix . 'profile_fields_lang + GROUP BY field_type'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . $this->table_prefix . "profile_fields_lang + SET field_type = '" . $this->db->sql_escape($this->convert_phpbb30_field_type($row['field_type'])) . "' + WHERE field_type = '" . $this->db->sql_escape($row['field_type']) . "'"; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + /** + * Determine the new field type for a given phpBB 3.0 field type + * + * @param $field_type int Field type in 3.0 + * @return string Field new type which is used since 3.1 + */ + public function convert_phpbb30_field_type($field_type) + { + switch ($field_type) + { + case FIELD_INT: + return 'profilefields.type.int'; + case FIELD_STRING: + return 'profilefields.type.string'; + case FIELD_TEXT: + return 'profilefields.type.text'; + case FIELD_BOOL: + return 'profilefields.type.bool'; + case FIELD_DROPDOWN: + return 'profilefields.type.dropdown'; + case FIELD_DATE: + return 'profilefields.type.date'; + default: + return $field_type; + } + } +} 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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 514a59ffa7b55b30d9af7aadf8735d6c2dfd48e1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 2 Feb 2014 12:39:21 +0100 Subject: [ticket/11201] Fix parameter description PHPBB3-11201 --- phpBB/phpbb/db/migration/data/v310/profilefield_types.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/db/migration/data/v310/profilefield_types.php b/phpBB/phpbb/db/migration/data/v310/profilefield_types.php index 553ff592a4..2152aaee20 100644 --- a/phpBB/phpbb/db/migration/data/v310/profilefield_types.php +++ b/phpBB/phpbb/db/migration/data/v310/profilefield_types.php @@ -80,7 +80,7 @@ class profilefield_types extends \phpbb\db\migration\migration /** * Determine the new field type for a given phpBB 3.0 field type * - * @param $field_type int Field type in 3.0 + * @param $field_type string Field type in 3.0 * @return string Field new type which is used since 3.1 */ public function convert_phpbb30_field_type($field_type) -- 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') 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') 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') 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