diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2006-05-25 19:15:04 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2006-05-25 19:15:04 +0000 |
commit | fec41273a4ae2f24ec8beb11dc473222cfd04b53 (patch) | |
tree | 9ba645f3829d1391c1b18904b813c16519f00beb /phpBB/includes/functions_profile_fields.php | |
parent | a59f59de21aa0abc311cd4601939c08259413d95 (diff) | |
download | forums-fec41273a4ae2f24ec8beb11dc473222cfd04b53.tar forums-fec41273a4ae2f24ec8beb11dc473222cfd04b53.tar.gz forums-fec41273a4ae2f24ec8beb11dc473222cfd04b53.tar.bz2 forums-fec41273a4ae2f24ec8beb11dc473222cfd04b53.tar.xz forums-fec41273a4ae2f24ec8beb11dc473222cfd04b53.zip |
first round of custom profile changes
git-svn-id: file:///svn/phpbb/trunk@5965 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_profile_fields.php')
-rw-r--r-- | phpBB/includes/functions_profile_fields.php | 723 |
1 files changed, 403 insertions, 320 deletions
diff --git a/phpBB/includes/functions_profile_fields.php b/phpBB/includes/functions_profile_fields.php index f3f78e625b..6bea346ef3 100644 --- a/phpBB/includes/functions_profile_fields.php +++ b/phpBB/includes/functions_profile_fields.php @@ -19,7 +19,161 @@ class custom_profile var $options_lang = array(); /** + * 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) + { + global $db, $template, $auth; + + $sql_where = ''; + switch ($mode) + { + case 'register': + // If the field is required we show it on the registration page and do not show hidden fields + $sql_where .= ' AND (f.field_show_on_reg = 1 OR f.field_required = 1) AND f.field_hide = 0'; + break; + + case 'profile': + // Show hidden fields to moderators/admins + if (!$auth->acl_gets('a_', 'm_')) + { + $sql_where .= ' AND f.field_hide = 0'; + } + 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 = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + // Return templated field + $tpl_snippet = $this->process_field_row('change', $row); + + $template->assign_block_vars('profile_fields', array( + 'LANG_NAME' => $row['lang_name'], + 'LANG_EXPLAIN' => $row['lang_explain'], + 'FIELD' => $tpl_snippet) + ); + } + $db->sql_freeresult($result); + } + + /** + * Validate entered profile field data + * @public + */ + function validate_profile_field($field_type, &$field_value, $field_data) + { + switch ($field_type) + { + case FIELD_INT: + case FIELD_DROPDOWN: + $field_value = (int) $field_value; + break; + + case FIELD_BOOL: + $field_value = (bool) $field_value; + break; + } + + 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())) + { + return 'FIELD_INVALID_DATE'; + } + break; + + case FIELD_INT: + if (empty($field_value) && !$field_data['field_required']) + { + return false; + } + + 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: + if ($field_value == $field_data['field_novalue'] && $field_data['field_required']) + { + return 'FIELD_REQUIRED'; + } + break; + + case FIELD_STRING: + case FIELD_TEXT: + if (empty($field_value) && !$field_data['field_required']) + { + return false; + } + else if (empty($field_value) && $field_data['field_required']) + { + return 'FIELD_REQUIRED'; + } + + if ($field_data['field_minlen'] && strlen($field_value) < $field_data['field_minlen']) + { + return 'FIELD_TOO_SHORT'; + } + else if ($field_data['field_maxlen'] && 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 : str_replace("\n", ' ', $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 + * @private */ function build_cache() { @@ -32,7 +186,8 @@ class custom_profile FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f WHERE l.lang_id = ' . $user->get_iso_lang_id() . ' AND f.field_active = 1 ' . - ((!$auth->acl_gets('a_', 'm_')) ? ' AND f.field_hide = 0 AND f.field_no_view = 0 ' : '') . ' + ((!$auth->acl_gets('a_', '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 = $db->sql_query($sql); @@ -57,7 +212,7 @@ class custom_profile foreach ($lang_options as $num => $var) { - $this->options_lang[$field_id][$lang_id][($num+1)] = $var; + $this->options_lang[$field_id][$lang_id][($num + 1)] = $var; } } else @@ -72,7 +227,7 @@ class custom_profile while ($row = $db->sql_fetchrow($result)) { - $this->options_lang[$field_id][$lang_id][$row['option_id']] = $row['value']; + $this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['value']; } $db->sql_freeresult($result); } @@ -80,44 +235,46 @@ class custom_profile /** * Submit profile field + * @public */ function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error) { global $auth, $db, $user; + $sql_where = ''; + switch ($mode) + { + case 'register': + // If the field is required we show it on the registration page and do not show hidden fields + $sql_where .= ' AND (f.field_show_on_reg = 1 OR f.field_required = 1) AND f.field_hide = 0'; + break; + + case 'profile': + // Show hidden fields to moderators/admins + if (!$auth->acl_gets('a_', 'm_')) + { + $sql_where .= ' AND f.field_hide = 0'; + } + 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 - " . (($mode == 'register') ? ' AND f.field_show_on_reg = 1' : '') . - (($auth->acl_gets('a_', 'm_') && $mode == 'profile') ? '' : ' AND f.field_hide = 0') . ' + $sql_where AND l.field_id = f.field_id - ORDER BY f.field_order'; + ORDER BY f.field_order"; $result = $db->sql_query($sql); - + while ($row = $db->sql_fetchrow($result)) { $cp_data[$row['field_ident']] = $this->get_profile_field($row); - - // get_profile_field returns an array with values for TEXT fields. - if (is_array($cp_data[$row['field_ident']])) - { - // Contains the original text without bbcode processing etc -// $check_value = $cp_data[$row['field_ident']]['submitted']; - - foreach ($cp_data[$row['field_ident']] as $key => $value) - { - $cp_data[$key] = $value; -/* if ($key != 'submitted') - { - $cp_data[$key] = $value; - }*/ - } - } - else - { - $check_value = $cp_data[$row['field_ident']]; - } + $check_value = $cp_data[$row['field_ident']]; if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false) { @@ -128,29 +285,34 @@ class custom_profile case 'FIELD_INVALID_DATE': case 'FIELD_REQUIRED': $error = sprintf($user->lang[$cp_result], $row['lang_name']); - break; + break; + case 'FIELD_TOO_SHORT': case 'FIELD_TOO_SMALL': $error = sprintf($user->lang[$cp_result], $row['lang_name'], $row['field_minlen']); - break; + break; + case 'FIELD_TOO_LONG': case 'FIELD_TOO_LARGE': $error = sprintf($user->lang[$cp_result], $row['lang_name'], $row['field_maxlen']); - break; + break; + case 'FIELD_INVALID_CHARS': switch ($row['field_validation']) { case '[0-9]+': $error = sprintf($user->lang[$cp_result . '_NUMBERS_ONLY'], $row['lang_name']); - break; + break; + case '[\w]+': $error = sprintf($user->lang[$cp_result . '_ALPHA_ONLY'], $row['lang_name']); - break; + break; + case '[\w_\+\. \-\[\]]+': $error = sprintf($user->lang[$cp_result . '_SPACERS_ONLY'], $row['lang_name']); - break; + break; } - break; + break; } if ($error != '') @@ -161,39 +323,11 @@ class custom_profile } $db->sql_freeresult($result); } - - /** - * Assign fields to template, mode can be profile (for profile change) or register (for registration) - */ - function generate_profile_fields($mode, $lang_id) - { - global $db, $template, $auth; - - $sql = 'SELECT l.*, f.* - FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f - WHERE l.lang_id = $lang_id - AND f.field_active = 1 - " . (($mode == 'register') ? ' AND f.field_show_on_reg = 1' : '') . - (($auth->acl_gets('a_', 'm_') && $mode == 'profile') ? '' : ' AND f.field_hide = 0') . ' - AND l.field_id = f.field_id - ORDER BY f.field_order'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $template->assign_block_vars('profile_fields', array( - 'LANG_NAME' => $row['lang_name'], - 'LANG_EXPLAIN' => $row['lang_explain'], - 'FIELD' => $this->process_field_row('change', $row)) -// 'ERROR' => $error) - ); - } - $db->sql_freeresult($result); - } /** * 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) { @@ -205,7 +339,7 @@ class custom_profile { $user_id = array($user_id); } - + if (!sizeof($this->profile_cache)) { $this->build_cache(); @@ -223,6 +357,7 @@ class custom_profile if (!($row = $db->sql_fetchrow($result))) { + $db->sql_freeresult($result); return array(); } @@ -236,14 +371,6 @@ class custom_profile $user_fields[$row['user_id']][$ident]['value'] = $value; $user_fields[$row['user_id']][$ident]['data'] = $this->profile_cache[$ident]; } -/* else if ($i = strpos($ident, '_bbcode')) - { - // Add extra data (bbcode_uid and bbcode_bitfield) to the data for this profile field. - // TODO: Maybe we should try to make this a bit more generic (not limited to bbcode)? - $field = substr($ident, 0, $i); - $subfield = substr($ident, $i+1); - $user_fields[$row['user_id']][$field]['data'][$subfield] = $value; - }*/ } } while ($row = $db->sql_fetchrow($result)); @@ -256,10 +383,18 @@ class custom_profile // $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' => $this->get_profile_value($ident_ary), + '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'], @@ -268,7 +403,7 @@ class custom_profile ); $tpl_fields['blockrow'][] = array( - 'PROFILE_FIELD_VALUE' => $this->get_profile_value($ident_ary), + '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'], @@ -281,104 +416,9 @@ class custom_profile } } - // VALIDATE Function - validate entered data - function validate_profile_field($field_type, &$field_value, $field_data) - { - switch ($field_type) - { - case FIELD_INT: - case FIELD_DROPDOWN: - $field_value = (int) $field_value; - break; - - case FIELD_BOOL: - $field_value = (bool) $field_value; - break; - } - - 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())) - { - return 'FIELD_INVALID_DATE'; - } - break; - - case FIELD_INT: - if (empty($field_value) && !$field_data['field_required']) - { - return false; - } - - 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: - if ($field_value == $field_data['field_novalue'] && $field_data['field_required']) - { - return 'FIELD_REQUIRED'; - } - break; - - case FIELD_STRING: - case FIELD_TEXT: - if (empty($field_value) && !$field_data['field_required']) - { - return false; - } - else if (empty($field_value) && $field_data['field_required']) - { - return 'FIELD_REQUIRED'; - } - - if ($field_data['field_minlen'] && strlen($field_value) < $field_data['field_minlen']) - { - return 'FIELD_TOO_SHORT'; - } - else if ($field_data['field_maxlen'] && 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 : str_replace("\n", ' ', $field_value); - if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate)) - { - return 'FIELD_INVALID_CHARS'; - } - } - break; - } - - return false; - } - - // Get Profile Value for display + /** + * Get Profile Value for display + */ function get_profile_value($ident_ary) { $value = $ident_ary['value']; @@ -391,33 +431,36 @@ class custom_profile break; case 'string': - $value = make_clickable($value); - $value = censor_text($value); - $value = str_replace("\n", '<br />', $value); - return $value; - break; - case 'text': - /* - @todo Prepare further, censor_text, smilies, bbcode, whatever - - if ($ident_ary['data']['bbcode_bitfield']) + if (!$value) { - $bbcode = new bbcode($ident_ary['data']['bbcode_bitfield']); - $bbcode->bbcode_second_pass($value, $ident_ary['data']['bbcode_uid'], $ident_ary['data']['bbcode_bitfield']); - $value = smiley_text($value); - $value = censor_text($value); + return NULL; } - return str_replace("\n", '<br />', $value);*/ $value = make_clickable($value); $value = censor_text($value); $value = str_replace("\n", '<br />', $value); return $value; - break; - + case 'date': + $date = explode('-', $value); + $month = (isset($date[0])) ? (int) $date[0] : 0; + $day = (isset($date[1])) ? (int) $date[1] : 0; + $year = (isset($date[2])) ? (int) $date[2] : 0; + + if (!$day && !$month && !$year) + { + return NULL; + } + else if ($day && $month && $year) + { + global $user; + + return $user->format_date(mktime(0, 0, 1, $day, $month, $year)); + } + + return $value; break; case 'dropdown': @@ -428,19 +471,46 @@ class custom_profile $this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); } + if ($value == $ident_ary['data']['field_novalue']) + { + return NULL; + } + return $this->options_lang[$field_id][$lang_id][(int) $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 ($ident_ary['data']['field_length'] == 1) + { + $this->options_lang[$field_id][$lang_id][(int) $value]; + } + else if (!$value) + { + return NULL; + } + else + { + return $this->options_lang[$field_id][$lang_id][(int) ($value + 1)]; + } break; default: - trigger_error('Unknown profile type'); + trigger_error('Unknown profile type', E_USER_ERROR); break; } } - // Get field value for registration/profile + /** + * Get field value for registration/profile + * @private + */ function get_var($field_validation, &$profile_row, $default_value, $preview) { global $user; @@ -450,7 +520,7 @@ class custom_profile // checkbox - only testing for isset if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2) { - $value = (isset($_REQUEST[$profile_row['field_ident']])) ? true : ((!isset($user->profile_fields[$profile_row['field_ident']]) || $preview) ? $default_value : $user->profile_fields[$profile_row['field_ident']]); + $value = (isset($_REQUEST[$profile_row['field_ident']])) ? true : ((!isset($user->profile_fields[str_replace('pf_', '', $profile_row['field_ident'])]) || $preview) ? $default_value : $user->profile_fields[str_replace('pf_', '', $profile_row['field_ident'])]); } else { @@ -461,26 +531,31 @@ class custom_profile { case 'int': return (int) $value; - break; + break; } return $value; } - - // GENERATE_* Functions - return templated, storable profile fields + + /** + * Process int-type + * @private + */ function generate_int($profile_row, $preview = false) { global $template; - $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); - $this->set_tpl_vars($profile_row, $value); - - return $this->get_cp_html(); + $profile_row['field_value'] = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); + $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); } + /** + * Process date-type + * @private + */ function generate_date($profile_row, $preview = false) { - global $user; + global $user, $template; $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $now = getdate(); @@ -527,70 +602,75 @@ class custom_profile } unset($now); - $this->set_tpl_vars($profile_row, 0); - return $this->get_cp_html(); + $profile_row['field_value'] = 0; + $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); } + /** + * Process bool-type + * @private + */ function generate_bool($profile_row, $preview = false) { global $template; $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); - $this->set_tpl_vars($profile_row, $value); + $profile_row['field_value'] = $value; + $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); + $s_preview = ($preview || isset($profile_row['acp_preview'])) ? true : false; + $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $s_preview); } foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) { $template->assign_block_vars('bool.options', array( - 'OPTION_ID' => $option_id, - 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '', - 'VALUE' => $option_value) + 'OPTION_ID' => $option_id, + 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '', + 'VALUE' => $option_value) ); } } - - return $this->get_cp_html(); } + /** + * Process string-type + * @private + */ function generate_string($profile_row, $preview = false) { global $template; - // Get the data associated with this field for this user - $value = $this->get_var('', $profile_row, $profile_row['lang_default_value'], $preview); - $this->set_tpl_vars($profile_row, $value); - - return $this->get_cp_html(); + $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview); + $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); } + /** + * Process text-type + * @private + */ function generate_text($profile_row, $preview = false) { global $template; global $user, $phpEx, $phpbb_root_path; - $value = $this->get_var('', $profile_row, $profile_row['lang_default_value'], $preview); - -/* if ($preview == false) - { - decode_message($value, $user->profile_fields[str_replace('pf_', '', $profile_row['field_ident']) . '_bbcode_uid']); - }*/ - $field_length = explode('|', $profile_row['field_length']); $profile_row['field_rows'] = $field_length[0]; $profile_row['field_cols'] = $field_length[1]; - $this->set_tpl_vars($profile_row, $value); - - return $this->get_cp_html(); + $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview); + $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); } + /** + * Process dropdown-type + * @private + */ function generate_dropdown($profile_row, $preview = false) { global $user, $template; @@ -599,54 +679,70 @@ class custom_profile 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); + $s_preview = ($preview || isset($profile_row['acp_preview'])) ? true : false; + $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $s_preview); } - $this->set_tpl_vars($profile_row, $value); + $profile_row['field_value'] = $value; + $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) { $template->assign_block_vars('dropdown.options', array( - 'OPTION_ID' => $option_id, - 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '', - 'VALUE' => $option_value) + 'OPTION_ID' => $option_id, + 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '', + 'VALUE' => $option_value) ); } - - return $this->get_cp_html(); } - - // Return Templated value (change == user is able to set/enter profile values; preview == just show the value) + /** + * Return Templated value/field. Possible values for $mode are: + * change == user is able to set/enter profile values; preview == just show the value + * @private + */ function process_field_row($mode, $profile_row) { - $preview = false; + global $template; - switch ($mode) + $preview = ($mode == 'preview') ? true : false; + + // set template filename + $template->set_filenames(array( + 'cp_body' => 'custom_profile_fields.html') + ); + + // empty previously filled blockvars + foreach ($this->profile_types as $field_case => $field_type) { - case 'preview': - $preview = true; - case 'change': - $type_func = 'generate_' . $this->profile_types[$profile_row['field_type']]; - break; - default: - return; + $template->destroy_block_vars($field_type); } - return $this->$type_func($profile_row, $preview); + // Assign template variables + $type_func = 'generate_' . $this->profile_types[$profile_row['field_type']]; + $this->$type_func($profile_row, $preview); + + // Return templated data + return $template->assign_display('cp_body'); } - // Build Array for user insertion into custom profile fields table + /** + * Build Array for user insertion into custom profile fields table + */ function build_insert_sql_array($cp_data) { global $db, $user, $auth; + $sql_not_in = array(); + foreach ($cp_data as $key => $null) + { + $sql_not_in[] = "'" . $db->sql_escape($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 = ' . $user->get_iso_lang_id() . ' - AND f.field_active = 1 - AND f.field_show_on_reg = 0 - ' . (($auth->acl_gets('a_', 'm_')) ? '' : ' AND f.field_hide = 0') . ' + ' . ((sizeof($sql_not_in)) ? ' AND f.field_ident NOT IN (' . implode(', ', $sql_not_in) . ')' : '') . ' AND l.field_id = f.field_id'; $result = $db->sql_query($sql); @@ -664,6 +760,10 @@ class custom_profile return $cp_data; } + /** + * Get profile field value on submit + * @private + */ function get_profile_field($profile_row) { global $phpbb_root_path, $phpEx; @@ -694,69 +794,30 @@ class custom_profile $var = sprintf('%2d-%2d-%4d', $day, $month, $year); break; -/** - case FIELD_TEXT: - include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx); - - $message_parser = new parse_message(request_var($var_name, '')); - - * Get the allowed settings from the global settings. Magic URLs are always set to true. - * @todo It might be nice to make this a per field setting. - - $message_parser->parse($config['allow_bbcode'], true, $config['allow_smilies']); + case FIELD_BOOL: + // Checkbox + if ($profile_row['field_length'] == 2) + { + $var = (isset($_REQUEST[$var_name])) ? 1 : 0; + } + else + { + $var = request_var($var_name, $profile_row['field_default_value']); + } + break; - $var = array( - $profile_row['field_ident'] => $message_parser->message, - $profile_row['field_ident'] . '_bbcode_uid' => $message_parser->bbcode_uid, - $profile_row['field_ident'] . '_bbcode_bitfield' => $message_parser->bbcode_bitfield, - 'submitted' => request_var($var_name, '') - ); + case FIELD_STRING: + case FIELD_TEXT: + $var = request_var($var_name, $profile_row['field_default_value'], true); break; -*/ default: - $var = request_var($var_name, $profile_row['field_default_value'], true); + $var = request_var($var_name, $profile_row['field_default_value']); break; } return $var; } - - function set_tpl_vars($profile_row, $field_value) - { - global $template; - - $template->set_filenames(array( - 'cp' => 'custom_profile_fields.html') - ); - - foreach ($this->profile_types as $field_case => $field_type) - { - unset($template->_tpldata[$field_type]); - } - - foreach ($profile_row as $key => $value) - { - unset($profile_row[$key]); - $profile_row[strtoupper($key)] = $value; - } - - $profile_row['FIELD_VALUE'] = $field_value; - - $template->assign_block_vars($this->profile_types[$profile_row['FIELD_TYPE']], $profile_row); - } - - function get_cp_html() - { - global $template; - - ob_start(); - $template->display('cp', false); - $data = ob_get_contents(); - ob_end_clean(); - - return $data; - } } /** @@ -766,8 +827,10 @@ class custom_profile class custom_profile_admin extends custom_profile { var $vars = array(); - + /** + * Return possible validation options + */ function validate_options() { global $user; @@ -784,49 +847,60 @@ class custom_profile_admin extends custom_profile return $validate_options; } - // GET_* get admin options for second step + /** + * Get string options for second step in ACP + */ function get_string_options() { global $user; $options = array( - 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'), - 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'), - 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'), - 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>') + 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'), + 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'), + 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'), + 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>') ); 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' => '<input name="rows" size="5" value="' . $this->vars['rows'] . '" /> ' . $user->lang['ROWS'] . '</dd><dd><input name="columns" size="5" value="' . $this->vars['columns'] . '" /> ' . $user->lang['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $this->vars['field_length'] . '" />'), - 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="10" value="' . $this->vars['field_minlen'] . '" />'), - 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="10" value="' . $this->vars['field_maxlen'] . '" />'), - 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>') + 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input name="rows" size="5" value="' . $this->vars['rows'] . '" /> ' . $user->lang['ROWS'] . '</dd><dd><input name="columns" size="5" value="' . $this->vars['columns'] . '" /> ' . $user->lang['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $this->vars['field_length'] . '" />'), + 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="10" value="' . $this->vars['field_minlen'] . '" />'), + 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="10" value="' . $this->vars['field_maxlen'] . '" />'), + 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>') ); 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' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'), - 1 => array('TITLE' => $user->lang['MIN_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'), - 2 => array('TITLE' => $user->lang['MAX_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'), - 3 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $this->vars['field_default_value'] . '" />') + 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'), + 1 => array('TITLE' => $user->lang['MIN_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'), + 2 => array('TITLE' => $user->lang['MAX_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'), + 3 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $this->vars['field_default_value'] . '" />') ); return $options; } + /** + * Get bool options for second step in ACP + */ function get_bool_options() { global $user, $config, $lang_defs; @@ -848,12 +922,15 @@ class custom_profile_admin extends custom_profile $options = array( 0 => array('TITLE' => $user->lang['FIELD_TYPE'], 'EXPLAIN' => $user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => '<input type="radio" name="field_length" value="1"' . (($this->vars['field_length'] == 1) ? ' checked="checked"' : '') . ' />' . $user->lang['RADIO_BUTTONS'] . ' <input type="radio" name="field_length" value="2"' . (($this->vars['field_length'] == 2) ? ' checked="checked"' : '') . ' />' . $user->lang['CHECKBOX'] . ' '), - 1 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->generate_bool($profile_row, true)) + 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; @@ -877,15 +954,17 @@ class custom_profile_admin extends custom_profile $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->generate_dropdown($profile_row[0], true)), - 1 => array('TITLE' => $user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->generate_dropdown($profile_row[1], true)) + 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; @@ -903,8 +982,12 @@ class custom_profile_admin extends custom_profile 'field_length' => $this->vars['field_length'] ); + $always_now = request_var('always_now', 0); + $s_checked = ($always_now || $this->vars['field_default_value'] == 'now') ? true : false; + $options = array( - 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->generate_date($profile_row, true) . '</dd><dd><input type="checkbox" name="always_now"' . ((isset($_REQUEST['always_now']) || $this->vars['field_default_value'] == 'now') ? ' checked="checked"' : '') . ' /> ' . $user->lang['ALWAYS_TODAY']) + 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)), + 1 => array('TITLE' => $user->lang['ALWAYS_TODAY'], 'FIELD' => '<input type="radio" name="always_now" value="1"' . (($s_checked) ? ' checked="checked"' : '') . ' /> ' . $user->lang['YES'] . ' <input type="radio" name="always_now" value="0"' . ((!$s_checked) ? ' checked="checked"' : '') . ' /> ' . $user->lang['NO']), ); return $options; |