aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2006-05-25 19:15:04 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2006-05-25 19:15:04 +0000
commitfec41273a4ae2f24ec8beb11dc473222cfd04b53 (patch)
tree9ba645f3829d1391c1b18904b813c16519f00beb /phpBB
parenta59f59de21aa0abc311cd4601939c08259413d95 (diff)
downloadforums-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')
-rw-r--r--phpBB/adm/style/acp_profile.html65
-rw-r--r--phpBB/adm/style/custom_profile_fields.html2
-rw-r--r--phpBB/includes/acp/acp_profile.php96
-rw-r--r--phpBB/includes/functions_display.php2
-rw-r--r--phpBB/includes/functions_profile_fields.php723
-rw-r--r--phpBB/includes/template.php60
-rw-r--r--phpBB/language/en/acp/profile.php14
-rw-r--r--phpBB/language/en/common.php1
-rw-r--r--phpBB/styles/subSilver/template/custom_profile_fields.html2
9 files changed, 544 insertions, 421 deletions
diff --git a/phpBB/adm/style/acp_profile.html b/phpBB/adm/style/acp_profile.html
index 1cfa154da1..ce260d1b98 100644
--- a/phpBB/adm/style/acp_profile.html
+++ b/phpBB/adm/style/acp_profile.html
@@ -31,9 +31,39 @@
<dt><label for="field_ident">{L_FIELD_IDENT}:</label><br /><span>{L_FIELD_IDENT_EXPLAIN}</span></dt>
<dd><input class="medium" type="text" id="field_ident" name="field_ident" value="{FIELD_IDENT}" /></dd>
</dl>
+ <dl>
+ <dt><label for="field_no_view">{L_DISPLAY_PROFILE_FIELD}:</label><br /><span>{L_DISPLAY_PROFILE_FIELD_EXPLAIN}</span></dt>
+ <dd><input type="radio" id="field_no_view" name="field_no_view" value="0"<!-- IF not S_FIELD_NO_VIEW --> checked="checked"<!-- ENDIF --> /> {L_YES} <input type="radio" name="field_no_view" value="1"<!-- IF S_FIELD_NO_VIEW --> checked="checked"<!-- ENDIF --> /> {L_NO}</dd>
+ </dl>
</fieldset>
<fieldset>
+ <legend>{L_VISIBILITY_OPTION}</legend>
+ <dl>
+ <dt><label for="field_option_none">{L_DISPLAY_AT_PROFILE}:</label></dt>
+ <dd><input type="radio" id="field_option_none" name="field_option" value="none"<!-- IF not S_SHOW_ON_REG and not S_FIELD_REQUIRED and not S_FIELD_HIDE --> checked="checked"<!-- ENDIF --> /></dd>
+ </dl>
+ <dl>
+ <dt><label for="field_show_on_reg">{L_DISPLAY_AT_REGISTER}:</label><br /><span>{L_DISPLAY_AT_REGISTER_EXPLAIN}</span></dt>
+ <dd><input type="radio" id="field_show_on_reg" name="field_option" value="field_show_on_reg"<!-- IF S_SHOW_ON_REG --> checked="checked"<!-- ENDIF --> /></dd>
+ </dl>
+ <dl>
+ <dt><label for="field_required">{L_REQUIRED_FIELD}:</label><br /><span>{L_REQUIRED_FIELD_EXPLAIN}</span></dt>
+ <dd><input type="radio" id="field_required" name="field_option" value="field_required"<!-- IF S_FIELD_REQUIRED --> checked="checked"<!-- ENDIF --> /></dd>
+ </dl>
+ <dl>
+ <dt><label for="field_hide">{L_HIDE_PROFILE_FIELD}:</label><br /><span>{L_HIDE_PROFILE_FIELD_EXPLAIN}</span></dt>
+ <dd><input type="radio" id="field_hide" name="field_option" value="field_hide"<!-- IF S_FIELD_HIDE --> checked="checked"<!-- ENDIF --> /></dd>
+ </dl>
+ </fieldset>
+
+ <!-- IF S_EDIT_MODE -->
+ <fieldset class="quick">
+ <input class="button1" type="submit" name="save" value="{L_SAVE}" />
+ </fieldset>
+ <!-- ENDIF -->
+
+ <fieldset>
<legend>{L_LANG_SPECIFIC}</legend>
<dl>
<dt><label for="lang_name">{L_USER_FIELD_NAME}:</label></dt>
@@ -71,22 +101,6 @@
<fieldset>
<legend>{L_TITLE}</legend>
- <dl>
- <dt><label for="field_required">{L_REQUIRED_FIELD}:</label><br /><span>{L_REQUIRED_FIELD_EXPLAIN}</span></dt>
- <dd><input type="checkbox" id="field_required" name="field_required" value="1"<!-- IF S_FIELD_REQUIRED --> checked="checked"<!-- ENDIF --> /></dd>
- </dl>
- <dl>
- <dt><label for="field_show_on_reg">{L_DISPLAY_AT_REGISTRATION}:</label></dt>
- <dd><input type="checkbox" id="field_show_on_reg" name="field_show_on_reg" value="1"<!-- IF S_SHOW_ON_REG --> checked="checked"<!-- ENDIF --> /></dd>
- </dl>
- <dl>
- <dt><label for="field_hide">{L_HIDE_PROFILE_FIELD}:</label><br /><span>{L_HIDE_PROFILE_FIELD_EXPLAIN}</span></dt>
- <dd><input type="checkbox" id="field_hide" name="field_hide" value="1"<!-- IF S_FIELD_HIDE --> checked="checked"<!-- ENDIF --> /></dd>
- </dl>
- <dl>
- <dt><label for="field_no_view">{L_EXCLUDE_FROM_VIEW}:</label><br /><span>{L_EXCLUDE_FROM_VIEW_EXPLAIN}</span></dt>
- <dd><input type="checkbox" id="field_no_view" name="field_no_view" value="1"<!-- IF S_FIELD_NO_VIEW --> checked="checked"<!-- ENDIF --> /></dd>
- </dl>
<!-- BEGIN option -->
<dl>
<dt><label>{option.TITLE}:</label><!-- IF option.EXPLAIN --><br /><span>{option.EXPLAIN}</span><!-- ENDIF --></dt>
@@ -117,7 +131,7 @@
</fieldset>
<fieldset class="quick">
- <input class="button1" type="submit" name="update" value="{L_SUBMIT}" />
+ <input class="button1" type="submit" name="update_preview" value="{L_SUBMIT}" />
</fieldset>
<!-- ELSEIF S_STEP_THREE -->
@@ -156,8 +170,8 @@
<tr>
<th>{L_FIELD_IDENT}</th>
<th>{L_FIELD_TYPE}</th>
- <th colspan="3">{L_OPTIONS}</th>
- <th>{L_REORDER}</th>
+ <th>&nbsp;</th>
+ <th>{L_OPTIONS}</th>
</tr>
</thead>
<tbody>
@@ -166,10 +180,15 @@
<td>{fields.FIELD_IDENT}</td>
<td>{fields.FIELD_TYPE}</td>
- <td><a href="{fields.U_ACTIVATE_DEACTIVATE}">{fields.L_ACTIVATE_DEACTIVATE}</a></td>
- <td><a href="{fields.U_EDIT}"><!-- IF fields.S_NEED_EDIT --><span style="color:red">{L_EDIT}</span><!-- ELSE -->{L_EDIT}<!-- ENDIF --></a></td>
- <td><a href="{fields.U_DELETE}">{L_DELETE}</a></td>
- <td style="text-align: center;"><a href="{fields.U_MOVE_UP}">{L_MOVE_UP}</a> | <a href="{fields.U_MOVE_DOWN}">{L_MOVE_DOWN}</a></td>
+ <td><a href="{fields.U_ACTIVATE_DEACTIVATE}">{fields.L_ACTIVATE_DEACTIVATE}</a><!-- IF fields.S_NEED_EDIT --> | <a href="{fields.U_EDIT}"><span style="color:red;">{L_EDIT}</span><!-- ENDIF --></td>
+
+ <td style="width: 15%; text-align: right; white-space: nowrap;">
+ <!-- IF not fields.S_FIRST_ROW --><a href="{fields.U_MOVE_UP}"><img src="images/icon_up.gif" alt="{L_MOVE_UP}" title="{L_MOVE_UP}" width="16" height="16" /></a> <!-- ENDIF -->
+ <!-- IF not fields.S_LAST_ROW --><a href="{fields.U_MOVE_DOWN}"><img src="images/icon_down.gif" alt="{L_MOVE_DOWN}" title="{L_MOVE_DOWN}" width="16" height="16" /></a> <!-- ENDIF -->
+ <!-- IF not fields.S_NEED_EDIT --><a href="{fields.U_EDIT}"><img src="images/icon_edit.gif" alt="{L_EDIT}" title="{L_EDIT}" width="16" height="16" /></a> <!-- ENDIF -->
+ <a href="{fields.U_DELETE}"><img src="images/icon_delete.gif" alt="{L_DELETE}" title="{L_DELETE}" width="16" height="16" /></a>
+ </td>
+
</tr>
<!-- END fields -->
</tbody>
diff --git a/phpBB/adm/style/custom_profile_fields.html b/phpBB/adm/style/custom_profile_fields.html
index abca1c9ff3..c1f0d5c216 100644
--- a/phpBB/adm/style/custom_profile_fields.html
+++ b/phpBB/adm/style/custom_profile_fields.html
@@ -17,7 +17,7 @@
<!-- IF bool.FIELD_LENGTH eq 1 -->
<!-- BEGIN options --><input type="radio" class="radio" name="{bool.FIELD_IDENT}" value="{bool.options.OPTION_ID}"{bool.options.CHECKED} /> {bool.options.VALUE}&nbsp; &nbsp;<!-- END options -->
<!-- ELSE -->
- <input type="checkbox" name="{bool.FIELD_IDENT}"<!-- IF bool.FIELD_VALUE --> checked="checked"<!-- ENDIF --> />
+ <input type="checkbox" name="{bool.FIELD_IDENT}" value="1"<!-- IF bool.FIELD_VALUE --> checked="checked"<!-- ENDIF --> />
<!-- ENDIF -->
<!-- END bool -->
diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php
index 4c7a268f09..853d54b14f 100644
--- a/phpBB/includes/acp/acp_profile.php
+++ b/phpBB/includes/acp/acp_profile.php
@@ -223,7 +223,8 @@ class acp_profile
$step = request_var('step', 1);
$submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false;
- $update = (isset($_REQUEST['update'])) ? true : false;
+ $update_preview = (isset($_REQUEST['update_preview'])) ? true : false;
+ $update = (isset($_REQUEST['update']) || $update_preview) ? true : false;
$save = (isset($_REQUEST['save'])) ? true : false;
// We are editing... we need to grab basic things
@@ -294,10 +295,10 @@ class acp_profile
$s_hidden_fields = '<input type="hidden" name="field_type" value="' . $field_type . '" />';
}
- // $exclude contains the data that we gather in each step
+ // $exclude contains the data we gather in each step
$exclude = array(
- 1 => array('field_ident', 'lang_name', 'lang_explain'),
- 2 => array('field_length', 'pf_preview', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value', 'field_required', 'field_show_on_reg', 'field_hide', 'field_no_view'),
+ 1 => array('field_ident', 'lang_name', 'lang_explain', 'field_option', 'field_no_view'),
+ 2 => array('field_length', 'pf_preview', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'),
3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
);
@@ -317,6 +318,26 @@ class acp_profile
$cp->vars['lang_name'] = request_var('lang_name', $field_row['lang_name'], true);
$cp->vars['lang_explain'] = request_var('lang_explain', $field_row['lang_explain'], true);
$cp->vars['lang_default_value'] = request_var('lang_default_value', $field_row['lang_default_value'], true);
+
+ // Field option...
+ if (isset($_REQUEST['field_option']))
+ {
+ $field_option = request_var('field_option', '');
+
+ $cp->vars['field_required'] = ($field_option == 'field_required') ? 1 : 0;
+ $cp->vars['field_show_on_reg'] = ($field_option == 'field_show_on_reg') ? 1 : 0;
+ $cp->vars['field_hide'] = ($field_option == 'field_hide') ? 1 : 0;
+ }
+ else
+ {
+ $cp->vars['field_required'] = $field_row['field_required'];
+ $cp->vars['field_show_on_reg'] = $field_row['field_show_on_reg'];
+ $cp->vars['field_hide'] = $field_row['field_hide'];
+
+ $field_option = ($field_row['field_required']) ? 'field_required' : (($field_row['field_show_on_reg']) ? 'field_show_on_reg' : (($field_row['field_hide']) ? 'field_hide' : ''));
+ }
+
+ $cp->vars['field_no_view'] = request_var('field_no_view', $field_row['field_no_view']);
// A boolean field expects an array as the lang options
if ($field_type == FIELD_BOOL)
@@ -353,21 +374,7 @@ class acp_profile
// step 2
foreach ($exclude[2] as $key)
{
- if ($key == 'field_required' || $key == 'field_show_on_reg' || $key == 'field_hide' || $key == 'field_no_view')
- {
- // Are we creating or editing a field?
- $var = (!$submit && $step == 1) ? $field_row[$key] : request_var($key, 0);
-
- // Damn checkboxes...
- if (!$submit && $step == 1)
- {
- $_REQUEST[$key] = $var;
- }
- }
- else
- {
- $var = request_var($key, $field_row[$key], true);
- }
+ $var = request_var($key, $field_row[$key], true);
// Manipulate the intended variables a little bit if needed
if ($field_type == FIELD_DROPDOWN && $key == 'field_maxlen')
@@ -394,7 +401,9 @@ class acp_profile
if ($field_type == FIELD_DATE && $key == 'field_default_value')
{
- if (isset($_REQUEST['always_now']) || $var == 'now')
+ $always_now = request_var('always_now', 0);
+
+ if ($always_now || $var == 'now')
{
$now = getdate();
@@ -529,9 +538,9 @@ class acp_profile
{
continue;
}
-
+
$_new_key_ary = array();
-
+
foreach ($key_ary as $key)
{
if (!isset($_REQUEST[$key]))
@@ -553,10 +562,15 @@ class acp_profile
{
$this->save_profile_field($cp, $field_type, $lang_defs, $action);
}
+ else if ($action == 'edit' && $save)
+ {
+ $this->save_profile_field($cp, $field_type, $lang_defs, $action);
+ }
}
$template->assign_vars(array(
'S_EDIT' => true,
+ 'S_EDIT_MODE' => ($action == 'edit') ? true : false,
'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
'L_TITLE' => $user->lang['STEP_' . $step . '_TITLE_' . strtoupper($action)],
@@ -575,7 +589,10 @@ class acp_profile
// Build common create options
$template->assign_vars(array(
'S_STEP_ONE' => true,
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
+ 'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false,
+ 'S_SHOW_ON_REG' => ($cp->vars['field_show_on_reg']) ? true : false,
+ 'S_FIELD_HIDE' => ($cp->vars['field_hide']) ? true : false,
+ 'S_FIELD_NO_VIEW' => ($cp->vars['field_no_view']) ? true : false,
'L_LANG_SPECIFIC' => sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']),
'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$field_type])],
@@ -631,12 +648,6 @@ class acp_profile
$template->assign_vars(array(
'S_STEP_TWO' => true,
- 'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false,
- 'S_SHOW_ON_REG' => ($cp->vars['field_show_on_reg']) ? true : false,
- 'S_FIELD_HIDE' => ($cp->vars['field_hide']) ? true : false,
- 'S_FIELD_NO_VIEW' => ($cp->vars['field_no_view']) ? true : false,
- 'S_HIDDEN_FIELDS' => $s_hidden_fields,
-
'L_NEXT' => (sizeof($lang_defs['iso']) == 1) ? $user->lang['SAVE'] : $user->lang['PROFILE_LANG_OPTIONS'])
);
@@ -692,8 +703,8 @@ class acp_profile
$template->assign_var('USER_ERROR', $user_error);
}
-
- $preview_field = $cp->process_field_row('preview', array(
+
+ $preview_field = array(
'lang_name' => $cp->vars['lang_name'],
'lang_explain' => $cp->vars['lang_explain'],
'lang_id' => $lang_defs['iso'][$config['default_lang']],
@@ -706,13 +717,18 @@ class acp_profile
'field_length' => $cp->vars['field_length'],
'field_maxlen' => $cp->vars['field_maxlen'],
- 'lang_options' => $cp->vars['lang_options'])
+ 'lang_options' => $cp->vars['lang_options'],
);
-
+
+ if ($update_preview)
+ {
+ $preview_field['acp_preview'] = true;
+ }
+
$template->assign_vars(array(
'PREVIEW_LANG_NAME' => $cp->vars['lang_name'],
'PREVIEW_LANG_EXPLAIN' => $cp->vars['lang_explain'],
- 'PREVIEW_FIELD' => $preview_field)
+ 'PREVIEW_FIELD' => $cp->process_field_row(($update_preview) ? 'change' : 'preview', $preview_field))
);
break;
@@ -720,11 +736,7 @@ class acp_profile
// Define remaining language variables
case 3:
- $template->assign_vars(array(
- 'S_STEP_THREE' => true,
- 'S_HIDDEN_FIELDS' => $s_hidden_fields)
- );
-
+ $template->assign_var('S_STEP_THREE', true);
$options = $this->build_language_options($cp, $field_type, $action);
foreach ($options as $lang_id => $lang_ary)
@@ -745,7 +757,11 @@ class acp_profile
break;
}
-
+
+ $template->assign_vars(array(
+ 'S_HIDDEN_FIELDS' => $s_hidden_fields)
+ );
+
return;
break;
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php
index 7dc2fe9a98..407a592c13 100644
--- a/phpBB/includes/functions_display.php
+++ b/phpBB/includes/functions_display.php
@@ -703,7 +703,7 @@ function display_attachments($forum_id, $blockname, &$attachment_data, &$update_
foreach ($attachment_data as $attachment)
{
// We need to reset/empty the _file block var, because this function might be called more than once
- $template->reset_block_vars('_file');
+ $template->destroy_block_vars('_file');
$block_array = array();
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'] . '&nbsp; &nbsp;<input type="radio" name="field_length" value="2"' . (($this->vars['field_length'] == 2) ? ' checked="checked"' : '') . ' />' . $user->lang['CHECKBOX'] . '&nbsp; &nbsp;'),
- 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"' : '') . ' />&nbsp; ' . $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;
diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php
index 9ba7086913..d8f78a77c1 100644
--- a/phpBB/includes/template.php
+++ b/phpBB/includes/template.php
@@ -106,6 +106,36 @@ class template
}
/**
+ * Reset/empty complete block
+ * @public
+ */
+ function destroy_block_vars($blockname)
+ {
+ if (strpos($blockname, '.') !== false)
+ {
+ // Nested block.
+ $blocks = explode('.', $blockname);
+ $blockcount = sizeof($blocks) - 1;
+
+ $str = &$this->_tpldata;
+ for ($i = 0; $i < $blockcount; $i++)
+ {
+ $str = &$str[$blocks[$i]];
+ $str = &$str[sizeof($str) - 1];
+ }
+
+ unset($str[$blocks[$blockcount]]);
+ }
+ else
+ {
+ // Top-level block.
+ unset($this->_tpldata[$blockname]);
+ }
+
+ return true;
+ }
+
+ /**
* Display handle
* @public
*/
@@ -334,36 +364,6 @@ class template
}
/**
- * Reset/empty complete block
- * @public
- */
- function reset_block_vars($blockname)
- {
- if (strpos($blockname, '.') !== false)
- {
- // Nested block.
- $blocks = explode('.', $blockname);
- $blockcount = sizeof($blocks) - 1;
-
- $str = &$this->_tpldata;
- for ($i = 0; $i < $blockcount; $i++)
- {
- $str = &$str[$blocks[$i]];
- $str = &$str[sizeof($str) - 1];
- }
-
- unset($str[$blocks[$blockcount]]);
- }
- else
- {
- // Top-level block.
- unset($this->_tpldata[$blockname]);
- }
-
- return true;
- }
-
- /**
* Change already assigned key variable pair (one-dimensional - single loop entry)
*
* Some Examples:
diff --git a/phpBB/language/en/acp/profile.php b/phpBB/language/en/acp/profile.php
index 2ca370a731..252ab1c683 100644
--- a/phpBB/language/en/acp/profile.php
+++ b/phpBB/language/en/acp/profile.php
@@ -53,15 +53,17 @@ $lang = array_merge($lang, array(
'DEFAULT_VALUE' => 'Default Value',
'DELETE_PROFILE_FIELD' => 'Remove profile field',
'DELETE_PROFILE_FIELD_CONFIRM' => 'Are you sure you want to delete this profile field?',
- 'DISPLAY_AT_REGISTRATION' => 'Display at registration screen',
+ 'DISPLAY_AT_PROFILE' => 'Display at users profile',
+ 'DISPLAY_AT_REGISTER' => 'Display at registration screen',
+ 'DISPLAY_AT_REGISTER_EXPLAIN' => 'If this option is enabled, the field will be additionally displayed on registration.',
+ 'DISPLAY_PROFILE_FIELD' => 'Display profile field',
+ 'DISPLAY_PROFILE_FIELD_EXPLAIN' => 'The profile field will be shown on viewtopic/viewprofile/memberlist/etc.',
'DROPDOWN_ENTRIES_EXPLAIN' => 'Enter your options now, every option in one line',
'EMPTY_FIELD_IDENT' => 'Empty field name',
'EMPTY_USER_FIELD_NAME' => 'Empty Field Name presented to the user',
'ENTRIES' => 'Entries',
'EVERYTHING_OK' => 'Everything OK',
- 'EXCLUDE_FROM_VIEW' => 'Do not display profile field',
- 'EXCLUDE_FROM_VIEW_EXPLAIN' => 'The profile field will not be shown on viewtopic/viewprofile/memberlist/etc.',
'FIELD_BOOL' => 'Boolean (Yes/No)',
'FIELD_DATE' => 'Date',
@@ -81,7 +83,7 @@ $lang = array_merge($lang, array(
'FIRST_OPTION' => 'First Option',
'HIDE_PROFILE_FIELD' => 'Hide Profile Field',
- 'HIDE_PROFILE_FIELD_EXPLAIN' => 'Only Administrators and Moderators are able to see/fill out this profile field',
+ 'HIDE_PROFILE_FIELD_EXPLAIN' => 'Only Administrators and Moderators are able to see/fill out this profile field. If this option is enabled, the profile field will be only displayed in user profiles.',
'INVALID_CHARS_FIELD_IDENT' => 'Field name can only contain lowercase a-z and _',
'ISO_LANGUAGE' => 'Language [%s]',
@@ -110,7 +112,7 @@ $lang = array_merge($lang, array(
'RADIO_BUTTONS' => 'Radio Buttons',
'REMOVED_PROFILE_FIELD' => 'Successfully removed profile field.',
'REQUIRED_FIELD' => 'Required Field',
- 'REQUIRED_FIELD_EXPLAIN' => 'Force profile field to be filled out or specified by user',
+ 'REQUIRED_FIELD_EXPLAIN' => 'Force profile field to be filled out or specified by user. This will display the profile field at registration too.',
'ROWS' => 'Rows',
'SAVE' => 'Save',
@@ -133,6 +135,8 @@ $lang = array_merge($lang, array(
'UPDATE_PREVIEW' => 'Update Preview',
'USER_FIELD_NAME' => 'Field Name presented to the user',
+
+ 'VISIBILITY_OPTION' => 'Visibility Option',
));
?> \ No newline at end of file
diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php
index ea0bb08680..00c1383a92 100644
--- a/phpBB/language/en/common.php
+++ b/phpBB/language/en/common.php
@@ -426,6 +426,7 @@ $lang = array_merge($lang, array(
'TOO_LONG_USER_PASSWORD' => 'The password you entered is too long.',
'TOO_LONG_USERNAME' => 'The username you entered is too long.',
'TOO_MANY_VOTE_OPTIONS' => 'You have tried to vote for too many options.',
+ 'TOO_SHORT_CONFIRM_CODE' => 'The confirm code you entered is too short.',
'TOO_SHORT_NEW_PASSWORD' => 'The password you entered is too short.',
'TOO_SHORT_PASSWORD_CONFIRM' => 'The password confirmation you entered is too short.',
'TOO_SHORT_USER_PASSWORD' => 'The password you entered is too short.',
diff --git a/phpBB/styles/subSilver/template/custom_profile_fields.html b/phpBB/styles/subSilver/template/custom_profile_fields.html
index df45191f58..0a1448a9f8 100644
--- a/phpBB/styles/subSilver/template/custom_profile_fields.html
+++ b/phpBB/styles/subSilver/template/custom_profile_fields.html
@@ -16,7 +16,7 @@
<!-- IF bool.FIELD_LENGTH eq 1 -->
<!-- BEGIN options --><input type="radio" name="{bool.FIELD_IDENT}" value="{bool.options.OPTION_ID}"{bool.options.CHECKED} /><span class="genmed">{bool.options.VALUE}</span>&nbsp; &nbsp;<!-- END options -->
<!-- ELSE -->
- <input type="checkbox" name="{bool.FIELD_IDENT}"<!-- IF bool.FIELD_VALUE --> checked="checked"<!-- ENDIF --> />
+ <input type="checkbox" name="{bool.FIELD_IDENT}" value="1"<!-- IF bool.FIELD_VALUE eq 1 --> checked="checked"<!-- ENDIF --> />
<!-- ENDIF -->
<!-- END bool -->