BBCode enabled profile fields, removed field_name from profile fields, fixed some uninitialised variable issues, some small conversion issues

git-svn-id: file:///svn/phpbb/trunk@5076 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Bart van Bragt 2005-01-24 13:14:31 +00:00
parent 61fbde5a72
commit 0a1b040588
14 changed files with 197 additions and 86 deletions

View file

@ -225,14 +225,14 @@ switch ($submit)
// Do we need to recache the moderator lists? We do if the mode // Do we need to recache the moderator lists? We do if the mode
// was mod or auth_settings['mod'] is a non-zero size array // was mod or auth_settings['mod'] is a non-zero size array
if ($mode == 'mod' || sizeof($auth_settings['mod'])) if ($mode == 'mod' || (isset($auth_settings['mod']) && sizeof($auth_settings['mod'])))
{ {
cache_moderators(); cache_moderators();
} }
// Remove users who are now moderators or admins from everyones foes // Remove users who are now moderators or admins from everyones foes
// list // list
if ($mode == 'mod' || sizeof($auth_settings['mod']) || $mode == 'admin' || sizeof($auth_settings['admin'])) if ($mode == 'mod' || (isset($auth_settings['mod']) && sizeof($auth_settings['mod'])) || $mode == 'admin' || (isset($auth_settings['admin']) && sizeof($auth_settings['admin'])))
{ {
update_foes(); update_foes();
} }

View file

@ -17,20 +17,21 @@
Taking into consideration Taking into consideration
... admin is NOT able to change the field type later ... admin is NOT able to change the field type later
... admin can NOT change field name after creation
Admin is able to preview/test the input and output of a profile field at any time. Admin is able to preview/test the input and output of a profile field at any time.
If the admin adds a field, he have to enter at least the default board language params. Without doing so, he If the admin adds a field, he needs to enter at least the default board language params. Without doing so, he
is not able to activate the field. is not able to activate the field.
If the default board language is changed, a check has to be made if the profile field language entries are If the default board language is changed a check has to be made if the profile field language entries are
still valid. still valid.
TODO: TODO:
* Show at profile view (yes/no) * Show at profile view (yes/no)
* Viewtopic Integration (Load Switch, Able to show fields with additional template vars populated if enabled) * Viewtopic Integration (Load Switch, Able to show fields with additional template vars populated if enabled)
* Custom Validation (Regex) - not in 2.2 * Custom Validation (Regex) - not in 2.2
* Able to use bbcode/smilies/urls - not in 2.2 * Fix novalue/default for dropdown boxes. These fields seem to get saved +1 in the database
*/ */
@ -72,7 +73,7 @@ $default_values = array(
FIELD_INT => array('field_length' => 5, 'field_minlen' => 0, 'field_maxlen' => 100, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0), FIELD_INT => array('field_length' => 5, 'field_minlen' => 0, 'field_maxlen' => 100, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
FIELD_DATE => array('field_length' => 10, 'field_minlen' => 10, 'field_maxlen' => 10, 'field_validation' => '', 'field_novalue' => ' 0- 0- 0', 'field_default_value' => ' 0- 0- 0'), FIELD_DATE => array('field_length' => 10, 'field_minlen' => 10, 'field_maxlen' => 10, 'field_validation' => '', 'field_novalue' => ' 0- 0- 0', 'field_default_value' => ' 0- 0- 0'),
FIELD_BOOL => array('field_length' => 1, 'field_minlen' => 0, 'field_maxlen' => 0, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0), FIELD_BOOL => array('field_length' => 1, 'field_minlen' => 0, 'field_maxlen' => 0, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
FIELD_DROPDOWN => array('field_length' => 0, 'field_minlen' => 0, 'field_maxlen' => 5, 'field_validation' => '', 'field_novalue' => 1, 'field_default_value' => 1), FIELD_DROPDOWN => array('field_length' => 0, 'field_minlen' => 0, 'field_maxlen' => 5, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
); );
$cp = new custom_profile_admin(); $cp = new custom_profile_admin();
@ -87,6 +88,7 @@ $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
// Make some arrays with all available languages
$lang_defs['id'][] = $row['lang_id']; $lang_defs['id'][] = $row['lang_id'];
$lang_defs['iso'][$row['lang_iso']] = $row['lang_id']; $lang_defs['iso'][$row['lang_iso']] = $row['lang_id'];
} }
@ -99,14 +101,17 @@ $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
// Which languages are available for each item
$lang_defs['entry'][$row['field_id']][] = $row['lang_id']; $lang_defs['entry'][$row['field_id']][] = $row['lang_id'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
// Have some fields been defined?
if (isset($lang_defs['entry'])) if (isset($lang_defs['entry']))
{ {
foreach ($lang_defs['entry'] as $field_id => $field_ary) foreach ($lang_defs['entry'] as $field_id => $field_ary)
{ {
// Fill an array with the languages that are missing for each field
$lang_defs['diff'][$field_id] = array_diff($lang_defs['id'], $field_ary); $lang_defs['diff'][$field_id] = array_diff($lang_defs['id'], $field_ary);
} }
} }
@ -181,7 +186,7 @@ if ($mode == 'create' || $mode == 'edit')
} }
$field_row = array_merge($default_values[$field_type], array( $field_row = array_merge($default_values[$field_type], array(
'field_name' => request_var('field_name', ''), 'field_ident' => request_var('field_ident', ''),
'field_required' => 0, 'field_required' => 0,
'field_hide' => 0, 'field_hide' => 0,
'field_show_on_reg' => 0, 'field_show_on_reg' => 0,
@ -194,14 +199,14 @@ if ($mode == 'create' || $mode == 'edit')
$s_hidden_fields = '<input type="hidden" name="field_type" value="' . $field_type . '" />'; $s_hidden_fields = '<input type="hidden" name="field_type" value="' . $field_type . '" />';
} }
// Get all relevant informations about entered values within all steps // $exclude contains the data that we gather in each ste
$exclude = array( $exclude = array(
1 => array('lang_name', 'lang_explain', 'field_name'), 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'), 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'),
3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options') 3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
); );
// Text-based fields require lang_default_value to be excluded // Text-based fields require the lang_default_value to be excluded
if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT) if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT)
{ {
$exclude[1][] = 'lang_default_value'; $exclude[1][] = 'lang_default_value';
@ -213,19 +218,22 @@ if ($mode == 'create' || $mode == 'edit')
$exclude[1][] = 'lang_options'; $exclude[1][] = 'lang_options';
} }
$cp->vars['field_name'] = request_var('field_name', $field_row['field_name']); $cp->vars['field_ident'] = request_var('field_ident', $field_row['field_ident']);
$cp->vars['lang_name'] = request_var('lang_name', $field_row['lang_name']); $cp->vars['lang_name'] = request_var('field_ident', $field_row['lang_name']);
$cp->vars['lang_explain'] = request_var('lang_explain', $field_row['lang_explain']); $cp->vars['lang_explain'] = request_var('lang_explain', $field_row['lang_explain']);
$cp->vars['lang_default_value'] = request_var('lang_default_value', $field_row['lang_default_value']); $cp->vars['lang_default_value'] = request_var('lang_default_value', $field_row['lang_default_value']);
$options = request_var('lang_options', ''); $options = request_var('lang_options', '');
if ($options) // If the user has submitted a form with options (i.e. dropdown field)
{ if (!empty($options))
if (sizeof(explode("\n", $options)) == sizeof($lang_options)) {
if (sizeof(explode("\n", $options)) == sizeof($lang_options) || $mode == 'create')
{ {
// The number of options in the field is equal to the number of options already in the database
// Or we are creating a new dropdown list.
$cp->vars['lang_options'] = explode("\n", $options); $cp->vars['lang_options'] = explode("\n", $options);
} }
else else if($mode == 'edit')
{ {
$cp->vars['lang_options'] = $lang_options; $cp->vars['lang_options'] = $lang_options;
$error[] = 'You are not allowed to remove or add options within already existing profile fields'; $error[] = 'You are not allowed to remove or add options within already existing profile fields';
@ -241,6 +249,7 @@ if ($mode == 'create' || $mode == 'edit')
{ {
if ($key == 'field_required' || $key == 'field_show_on_reg' || $key == 'field_hide') if ($key == 'field_required' || $key == 'field_show_on_reg' || $key == 'field_hide')
{ {
// Are we creating or editing a field?
$var = (!$submit && $step == 1) ? $field_row[$key] : request_var($key, 0); $var = (!$submit && $step == 1) ? $field_row[$key] : request_var($key, 0);
// Damn checkboxes... // Damn checkboxes...
@ -257,6 +266,7 @@ if ($mode == 'create' || $mode == 'edit')
// Manipulate the intended variables a little bit if needed // Manipulate the intended variables a little bit if needed
if ($field_type == FIELD_DROPDOWN && $key == 'field_maxlen') if ($field_type == FIELD_DROPDOWN && $key == 'field_maxlen')
{ {
// Get the number of options if this key is 'field_maxlen'
$var = sizeof(explode("\n", request_var('lang_options', ''))); $var = sizeof(explode("\n", request_var('lang_options', '')));
} }
@ -348,7 +358,7 @@ if ($mode == 'create' || $mode == 'edit')
{ {
$cp->vars[$key] = $$key; $cp->vars[$key] = $$key;
} }
else if ($key == 'l_lang_options') else if ($key == 'l_lang_options' && sizeof($cp->vars[$key]) > 1)
{ {
foreach ($cp->vars[$key] as $lang_id => $options) foreach ($cp->vars[$key] as $lang_id => $options)
{ {
@ -360,13 +370,20 @@ if ($mode == 'create' || $mode == 'edit')
if ($submit && $step == 1) if ($submit && $step == 1)
{ {
// Check values for step 1 // Check values for step 1
if ($cp->vars['field_name'] == '') if ($cp->vars['field_ident'] == '')
{ {
$error[] = $user->lang['EMPTY_FIELD_NAME']; // Rename $user->lang['EMPTY_FIELD_NAME'] to $user->lang['EMPTY_FIELD_IDENT']
$error[] = $user->lang['EMPTY_FIELD_IDENT'];
} }
if(!preg_match('/^[a-z_]$/', $cp->vars['field_ident']))
{
$error[] = $user->lang['INVALID_CHARS_FIELD_IDENT'];
}
if ($cp->vars['lang_name'] == '') if ($cp->vars['lang_name'] == '')
{ {
$error[] = $user->lang['EMPTY_USER_FIELD_NAME']; $error[] = $user->lang['EMPTY_USER_FIELD_IDENT'];
} }
if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN) if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
@ -454,8 +471,8 @@ if ($mode == 'create' || $mode == 'edit')
<td class="row2"><b><?php echo $user->lang['FIELD_' . strtoupper($cp->profile_types[$field_type])]; ?></b></td> <td class="row2"><b><?php echo $user->lang['FIELD_' . strtoupper($cp->profile_types[$field_type])]; ?></b></td>
</tr> </tr>
<tr> <tr>
<td class="row1"><b><?php echo $user->lang['FIELD_NAME']; ?>: </b><br /><span class="gensmall"><?php echo $user->lang['FIELD_NAME_EXPLAIN']; ?></span></td> <td class="row1"><b><?php echo $user->lang['FIELD_IDENT']; ?>: </b><br /><span class="gensmall"><?php echo $user->lang['FIELD_IDENT_EXPLAIN']; ?></span></td>
<td class="row2"><input class="post" type="text" name="field_name" size="20" value="<?php echo $cp->vars['field_name']; ?>" /></td> <td class="row2"><input class="post" type="text" name="field_ident" size="20" value="<?php echo $cp->vars['field_ident']; ?>" /></td>
</tr> </tr>
<tr> <tr>
<th align="center" colspan="2"><?php echo sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']); ?></th> <th align="center" colspan="2"><?php echo sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']); ?></th>
@ -482,10 +499,20 @@ if ($mode == 'create' || $mode == 'edit')
if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN) if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
{ {
if ($field_type == FIELD_BOOL && !sizeof($cp->vars['lang_options'])) // Initialize these array elements if we are creating a new field
if (!sizeof($cp->vars['lang_options']))
{ {
$cp->vars['lang_options'][0] = ''; if($field_type == FIELD_BOOL)
$cp->vars['lang_options'][1] = ''; {
// No options have been defined for a boolean field.
$cp->vars['lang_options'][0] = '';
$cp->vars['lang_options'][1] = '';
}
else
{
// No options have been defined for the dropdown menu
$cp->vars['lang_options'] = array();
}
} }
?> ?>
<tr> <tr>
@ -623,7 +650,7 @@ if ($mode == 'create' || $mode == 'edit')
<td align="center" class="row3" colspan="2"><?php echo ($lang_ary['lang_iso'] == $config['default_lang']) ? sprintf($user->lang['DEFAULT_ISO_LANGUAGE'], $config['default_lang']) : sprintf($user->lang['ISO_LANGUAGE'], $lang_ary['lang_iso']) ?></td> <td align="center" class="row3" colspan="2"><?php echo ($lang_ary['lang_iso'] == $config['default_lang']) ? sprintf($user->lang['DEFAULT_ISO_LANGUAGE'], $config['default_lang']) : sprintf($user->lang['ISO_LANGUAGE'], $lang_ary['lang_iso']) ?></td>
</tr> </tr>
<?php <?php
foreach ($lang_ary['fields'] as $field_name => $field_ary) foreach ($lang_ary['fields'] as $field_ident => $field_ary)
{ {
?> ?>
<tr> <tr>
@ -774,7 +801,6 @@ if ($mode == 'manage')
<table class="bg" cellspacing="1" cellpadding="4" border="0" align="center" width="99%"> <table class="bg" cellspacing="1" cellpadding="4" border="0" align="center" width="99%">
<tr> <tr>
<th nowrap="nowrap">Name</th> <th nowrap="nowrap">Name</th>
<th nowrap="nowrap">Template Variable</th>
<th nowrap="nowrap">Type</th> <th nowrap="nowrap">Type</th>
<th colspan="3" nowrap="nowrap">Options</th> <th colspan="3" nowrap="nowrap">Options</th>
<th nowrap="nowrap">Reorder</th> <th nowrap="nowrap">Reorder</th>
@ -795,7 +821,6 @@ if ($mode == 'manage')
$id = $row['field_id']; $id = $row['field_id'];
?> ?>
<tr> <tr>
<td class="<?php echo $row_class; ?>"><?php echo $row['field_name']; ?></td>
<td class="<?php echo $row_class; ?>"><?php echo $row['field_ident']; ?></td> <td class="<?php echo $row_class; ?>"><?php echo $row['field_ident']; ?></td>
<td class="<?php echo $row_class; ?>"><?php echo $user->lang['FIELD_' . strtoupper($cp->profile_types[$row['field_type']])]; ?></td> <td class="<?php echo $row_class; ?>"><?php echo $user->lang['FIELD_' . strtoupper($cp->profile_types[$row['field_type']])]; ?></td>
<td class="<?php echo $row_class; ?>"><a href="admin_profile.<?php echo $phpEx . $SID; ?>&amp;mode=<?php echo $active_value; ?>&amp;field_id=<?php echo $id; ?>"><?php echo $user->lang[$active_lang]; ?></a></td> <td class="<?php echo $row_class; ?>"><a href="admin_profile.<?php echo $phpEx . $SID; ?>&amp;mode=<?php echo $active_value; ?>&amp;field_id=<?php echo $id; ?>"><?php echo $user->lang[$active_lang]; ?></a></td>
@ -814,7 +839,7 @@ if ($mode == 'manage')
} }
?> ?>
<tr> <tr>
<td class="cat" colspan="7"><input class="post" type="text" name="field_name" size="20" /> <select name="field_type"><?php echo $s_select_type; ?></select> <input class="btnlite" type="submit" name="add" value="<?php echo $user->lang['CREATE_NEW_FIELD']; ?>" /></td> <td class="cat" colspan="7"><input class="post" type="text" name="field_ident" size="20" /> <select name="field_type"><?php echo $s_select_type; ?></select> <input class="btnlite" type="submit" name="add" value="<?php echo $user->lang['CREATE_NEW_FIELD']; ?>" /></td>
</tr> </tr>
</table> </table>
</form> </form>
@ -965,14 +990,12 @@ function save_profile_field($field_type, $mode = 'create')
$result = $db->sql_query('SELECT MAX(field_order) as max_field_order FROM ' . PROFILE_FIELDS_TABLE); $result = $db->sql_query('SELECT MAX(field_order) as max_field_order FROM ' . PROFILE_FIELDS_TABLE);
$new_field_order = (int) $db->sql_fetchfield('max_field_order', 0, $result); $new_field_order = (int) $db->sql_fetchfield('max_field_order', 0, $result);
$db->sql_freeresult($result); $db->sql_freeresult($result);
// We do not use a stripped down field name as identifier in order to retain sql compatibility, of course it would be nice to not have to look up the identifier and instead having a descriptive name, but this would produce more errors than needed, and do you want to have a totally crypted name just because of stripped characters? ;) $field_ident = $cp->vars['field_ident'];
$field_ident = 'field_' . ($new_field_order + 1);
} }
// Save the field // Save the field
$profile_fields = array( $profile_fields = array(
'field_name' => $cp->vars['field_name'],
'field_length' => $cp->vars['field_length'], 'field_length' => $cp->vars['field_length'],
'field_minlen' => $cp->vars['field_minlen'], 'field_minlen' => $cp->vars['field_minlen'],
'field_maxlen' => $cp->vars['field_maxlen'], 'field_maxlen' => $cp->vars['field_maxlen'],
@ -1018,7 +1041,9 @@ function save_profile_field($field_type, $mode = 'create')
break; break;
case FIELD_TEXT: case FIELD_TEXT:
$sql .= 'TEXT NULL'; $sql .= "TEXT NULL,
ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
ADD {$field_ident}_bbcode_bitfield INT(11) UNSIGNED";
break; break;
case FIELD_BOOL: case FIELD_BOOL:
@ -1117,6 +1142,7 @@ function save_profile_field($field_type, $mode = 'create')
} }
} }
// TODO: sizeof() returns 1 if it's argument is something else than an array. It also seems to do that on empty array elements :?
if (sizeof($cp->vars['l_lang_options'])) if (sizeof($cp->vars['l_lang_options']))
{ {
foreach ($cp->vars['l_lang_options'] as $lang_id => $lang_ary) foreach ($cp->vars['l_lang_options'] as $lang_id => $lang_ary)

View file

@ -34,7 +34,7 @@ if ($user->data['user_id'] == ANONYMOUS)
} }
// Have they authenticated (again) as an admin for this session? // Have they authenticated (again) as an admin for this session?
if (!$user->data['session_admin']) if (!isset($user->data['session_admin']))
{ {
login_box('', $user->lang['LOGIN_ADMIN_CONFIRM'], $user->lang['LOGIN_ADMIN_SUCCESS'], true, false); login_box('', $user->lang['LOGIN_ADMIN_CONFIRM'], $user->lang['LOGIN_ADMIN_SUCCESS'], true, false);
} }

View file

@ -598,7 +598,7 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false)
} }
// Default tracking type // Default tracking type
// $type = TRACK_NORMAL; $type = TRACK_NORMAL;
$current_time = ($marktime) ? $marktime : time(); $current_time = ($marktime) ? $marktime : time();
$topic_id = (int) $topic_id; $topic_id = (int) $topic_id;

View file

@ -1344,7 +1344,9 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = FALSE,
unset($topic_data); unset($topic_data);
// if some topics have been resync'ed then resync parent forums // if some topics have been resync'ed then resync parent forums
if ($resync_parents && sizeof($resync_forums)) // except when we're only syncing a range, we don't want to sync forums during
// batch processing.
if ($resync_parents && sizeof($resync_forums) && $where_type != 'range')
{ {
sync('forum', 'forum_id', $resync_forums, TRUE); sync('forum', 'forum_id', $resync_forums, TRUE);
} }

View file

@ -92,8 +92,27 @@ class custom_profile
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$cp_data[$row['field_ident']] = $this->get_profile_field($row); $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'];
if (($cp_result = $this->validate_profile_field($row['field_type'], $cp_data[$row['field_ident']], $row)) !== false) foreach($cp_data[$row['field_ident']] as $key => $value)
{
if($key != 'submitted')
{
$cp_data[$key] = $value;
}
}
}
else
{
$check_value = $cp_data[$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 // If not and only showing common error messages, use this one
$error = ''; $error = '';
@ -193,34 +212,40 @@ class custom_profile
{ {
return array(); return array();
} }
$user_fields = array(); $user_fields = array();
do do
{ {
foreach ($row as $ident => $value) foreach ($row as $ident => $value)
{ {
if ($ident != 'user_id') if (isset($this->profile_cache[$ident]))
{ {
$user_fields[$row['user_id']][$ident]['value'] = $value; $user_fields[$row['user_id']][$ident]['value'] = $value;
$user_fields[$row['user_id']][$ident]['data'] = $this->profile_cache[$ident]; $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)); while ($row = $db->sql_fetchrow($result));
$db->sql_freeresult($result); $db->sql_freeresult($result);
return $user_fields; return $user_fields;
} }
else if ($mode == 'show') else if ($mode == 'show')
{ {
// $profile_row == $user_fields[$row['user_id']] // $profile_row == $user_fields[$row['user_id']];
$tpl_fields = array(); $tpl_fields = array();
foreach ($profile_row as $ident => $ident_ary) foreach ($profile_row as $ident => $ident_ary)
{ {
$tpl_fields += array( $tpl_fields += array(
'PROFILE_' . strtoupper($ident) . '_VALUE' => $this->get_profile_value($ident_ary['data']['field_id'], $ident_ary['data']['lang_id'], $ident_ary['data']['field_type'], $ident_ary['value']), 'PROFILE_' . strtoupper($ident) . '_VALUE' => $this->get_profile_value($ident_ary),
'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'],
'PROFILE_' . strtoupper($ident) . '_NAME' => $ident_ary['data']['lang_name'], 'PROFILE_' . strtoupper($ident) . '_NAME' => $ident_ary['data']['lang_name'],
'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $ident_ary['data']['lang_explain'], 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $ident_ary['data']['lang_explain'],
@ -291,6 +316,7 @@ class custom_profile
break; break;
case FIELD_DROPDOWN: case FIELD_DROPDOWN:
print_r($field_data['field_novalue']);
if ($field_value == $field_data['field_novalue'] && $field_data['field_required']) if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
{ {
return 'FIELD_REQUIRED'; return 'FIELD_REQUIRED';
@ -331,23 +357,37 @@ class custom_profile
return false; return false;
} }
// Get Profile Value // Get Profile Value for display
function get_profile_value($field_id, $lang_id, $field_type, $value) function get_profile_value($ident_ary)
{ {
$value = $ident_ary['value'];
$field_type = $ident_ary['data']['field_type'];
switch ($this->profile_types[$field_type]) switch ($this->profile_types[$field_type])
{ {
case 'int': case 'int':
return (int) $value; return (int) $value;
break; break;
case 'string': case 'string':
return str_replace("\n", '<br />', $value);
break;
case 'text': case 'text':
// Prepare further, censor_text, smilies, bbcode, html, whatever // Prepare further, censor_text, smilies, bbcode, html, whatever
if ($ident_ary['data']['bbcode_bitfield'])
{
$bbcode = new bbcode($ident_ary['data']['bbcode_bitfield']);
$bbcode->bbcode_second_pass($value, $ident_ary['data']['bbcode_uid'], $ident_ary['data']['bbcode_bitfield']);
$value = smilie_text($value);
$value = censor_text($value);
}
return str_replace("\n", '<br />', $value); return str_replace("\n", '<br />', $value);
break; break;
case 'date': case 'date':
break; break;
case 'dropdown': case 'dropdown':
if (!sizeof($this->options_lang[$field_id][$lang_id])) $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); $this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
} }
@ -356,6 +396,9 @@ class custom_profile
break; break;
case 'bool': case 'bool':
break; break;
default:
trigger_error('Unknown profile type');
break;
} }
} }
@ -364,16 +407,16 @@ class custom_profile
{ {
global $user; global $user;
$profile_row['field_name'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
// checkbox - only testing for isset // checkbox - only testing for isset
if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2) if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2)
{ {
$value = (isset($_REQUEST[$profile_row['field_name']])) ? 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[$profile_row['field_ident']]) || $preview) ? $default_value : $user->profile_fields[$profile_row['field_ident']]);
} }
else else
{ {
$value = (isset($_REQUEST[$profile_row['field_name']])) ? request_var($profile_row['field_name'], $default_value) : ((!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']])) ? request_var($profile_row['field_ident'], $default_value) : ((!isset($user->profile_fields[$profile_row['field_ident']]) || $preview) ? $default_value : $user->profile_fields[$profile_row['field_ident']]);
} }
switch ($field_validation) switch ($field_validation)
@ -401,10 +444,10 @@ class custom_profile
{ {
global $user; global $user;
$profile_row['field_name'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
$now = getdate(); $now = getdate();
if (!isset($_REQUEST[$profile_row['field_name'] . '_day'])) if (!isset($_REQUEST[$profile_row['field_ident'] . '_day']))
{ {
if ($profile_row['field_default_value'] == 'now') if ($profile_row['field_default_value'] == 'now')
{ {
@ -421,9 +464,9 @@ class custom_profile
} }
else else
{ {
$day = request_var($profile_row['field_name'] . '_day', 0); $day = request_var($profile_row['field_ident'] . '_day', 0);
$month = request_var($profile_row['field_name'] . '_month', 0); $month = request_var($profile_row['field_ident'] . '_month', 0);
$year = request_var($profile_row['field_name'] . '_year', 0); $year = request_var($profile_row['field_ident'] . '_year', 0);
} }
} }
@ -482,7 +525,8 @@ class custom_profile
{ {
global $template; global $template;
$value = $this->get_var('', $profile_row, $profile_row['lang_default_value'], $preview); // 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); $this->set_tpl_vars($profile_row, $value);
return $this->get_cp_html(); return $this->get_cp_html();
@ -491,8 +535,16 @@ class custom_profile
function generate_text($profile_row, $preview = false) function generate_text($profile_row, $preview = false)
{ {
global $template; global $template;
global $user;
$value = $this->get_var('', $profile_row, $profile_row['lang_default_value'], $preview); $value = $this->get_var('', $profile_row, $profile_row['lang_default_value'], $preview);
if($preview == false)
{
$message_parser = new parse_message();
$message_parser->message = $value;
$message_parser->decode_message($user->profile_fields[$profile_row['field_ident'] . '_bbcode_uid']);
$value = $message_parser->message;
}
$field_length = explode('|', $profile_row['field_length']); $field_length = explode('|', $profile_row['field_length']);
$profile_row['field_rows'] = $field_length[0]; $profile_row['field_rows'] = $field_length[0];
@ -529,7 +581,7 @@ class custom_profile
} }
// Return Templated value (change == user is able to set/enter profile values; show == just show the value) // Return Templated value (change == user is able to set/enter profile values; preview == just show the value)
function process_field_row($mode, $profile_row) function process_field_row($mode, $profile_row)
{ {
$preview = false; $preview = false;
@ -579,11 +631,14 @@ class custom_profile
function get_profile_field($profile_row) function get_profile_field($profile_row)
{ {
global $phpbb_root_path, $phpEx;
global $config;
$var_name = 'pf_' . $profile_row['field_ident'];
switch ($profile_row['field_type']) switch ($profile_row['field_type'])
{ {
case FIELD_DATE: case FIELD_DATE:
$var_name = 'pf_' . $profile_row['field_ident'];
if (!isset($_REQUEST[$var_name . '_day'])) if (!isset($_REQUEST[$var_name . '_day']))
{ {
if ($profile_row['field_default_value'] == 'now') if ($profile_row['field_default_value'] == 'now')
@ -602,9 +657,22 @@ class custom_profile
$var = sprintf('%2d-%2d-%4d', $day, $month, $year); $var = sprintf('%2d-%2d-%4d', $day, $month, $year);
break; 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_html'], $config['allow_bbcode'], true, $config['allow_smilies']);
$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, ''));
break;
default: default:
$var = request_var('pf_' . $profile_row['field_ident'], $profile_row['field_default_value']); $var = request_var($var_name, $profile_row['field_default_value']);
break;
} }
return $var; return $var;
@ -795,4 +863,4 @@ class custom_profile_admin extends custom_profile
} }
} }
?> ?>

View file

@ -659,13 +659,16 @@ class parse_message extends bbcode_firstpass
$replace = array("\n", '', "\n\n"); $replace = array("\n", '', "\n\n");
$this->message = preg_replace($match, $replace, trim($this->message)); $this->message = preg_replace($match, $replace, trim($this->message));
// Message length check // Message length check. -1 disables this check completely, even allows empty messsages.
$msg_len = ($mode == 'post') ? strlen($this->message) : strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#is', ' ', $this->message)); if($config['max_' . $mode . '_chars'] != -1)
if (!$msg_len || ($config['max_' . $mode . '_chars'] && $msg_len > $config['max_' . $mode . '_chars']))
{ {
$this->warn_msg[] = (!$msg_len) ? $user->lang['TOO_FEW_CHARS'] : $user->lang['TOO_MANY_CHARS']; $msg_len = ($mode == 'post') ? strlen($this->message) : strlen(preg_replace('#\[\/?[a-z\*\+\-]+(=[\S]+)?\]#is', ' ', $this->message));
return $this->warn_msg;
if (!$msg_len || ($config['max_' . $mode . '_chars'] && $msg_len > $config['max_' . $mode . '_chars']))
{
$this->warn_msg[] = (!$msg_len) ? $user->lang['TOO_FEW_CHARS'] : $user->lang['TOO_MANY_CHARS'];
return $this->warn_msg;
}
} }
// Parse HTML // Parse HTML

View file

@ -78,7 +78,7 @@ class session
} }
// session_id exists so go ahead and attempt to grab all data in preparation // session_id exists so go ahead and attempt to grab all data in preparation
if (!empty($this->session_id) && (!defined('NEED_SID') || $this->session_id == $_GET['sid'])) if (!empty($this->session_id) && (!defined('NEED_SID') || (isset($_GET['sid']) && $this->session_id == $_GET['sid'])))
{ {
$sql = 'SELECT u.*, s.* $sql = 'SELECT u.*, s.*
FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u

View file

@ -421,13 +421,16 @@ function get_user_informations($user_id, $user_row)
} }
else else
{ {
foreach ($ranks['normal'] as $rank) if(isset($ranks['normal']))
{ {
if ($user_row['user_posts'] >= $rank['rank_min']) foreach ($ranks['normal'] as $rank)
{ {
$user_row['rank_title'] = $rank['rank_title']; if ($user_row['user_posts'] >= $rank['rank_min'])
$user_row['rank_image'] = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" border="0" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" /><br />' : ''; {
break; $user_row['rank_title'] = $rank['rank_title'];
$user_row['rank_image'] = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" border="0" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" /><br />' : '';
break;
}
} }
} }
} }

View file

@ -202,6 +202,10 @@ class ucp_profile extends module
case 'profile_info': case 'profile_info':
include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx); include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.'.$phpEx);
// TODO: The posting file is included because $message_parser->decode_message() relies on decode_message() in the posting functions.
include($phpbb_root_path . 'includes/functions_posting.'.$phpEx);
$cp = new custom_profile(); $cp = new custom_profile();
$cp_data = $cp_error = array(); $cp_data = $cp_error = array();

View file

@ -2056,7 +2056,8 @@ $lang += array(
'NO_FIELD_TYPE' => 'No Field type specified', 'NO_FIELD_TYPE' => 'No Field type specified',
'FIRST_OPTION' => 'First Option', 'FIRST_OPTION' => 'First Option',
'SECOND_OPTION' => 'Second Option', 'SECOND_OPTION' => 'Second Option',
'EMPTY_FIELD_NAME' => 'Empty field name', 'EMPTY_FIELD_IDENT' => 'Empty field name',
'INVALID_CHARS_FIELD_IDENT' => 'Field name can only contain lowercase a-z and _',
'EMPTY_USER_FIELD_NAME' => 'Empty Field Name presented to the user', 'EMPTY_USER_FIELD_NAME' => 'Empty Field Name presented to the user',
'PROFILE_BASIC_OPTIONS' => 'Basic Options', 'PROFILE_BASIC_OPTIONS' => 'Basic Options',
@ -2112,8 +2113,8 @@ $lang += array(
'FIELD_TYPE' => 'Field Type', 'FIELD_TYPE' => 'Field Type',
'FIELD_TYPE_EXPLAIN' => 'You are not able to change the field type later.', 'FIELD_TYPE_EXPLAIN' => 'You are not able to change the field type later.',
'FIELD_NAME' => 'Field Name', 'FIELD_IDENT' => 'Field Name',
'FIELD_NAME_EXPLAIN' => 'The Field Name is a name for you to identify the profile field, it is not displayed to the user.', 'FIELD_IDENT_EXPLAIN' => 'The Field Name is a name for you to identify the profile field, it is not displayed to the user.',
'LANG_SPECIFIC_OPTIONS' => 'Language specific options [<b>%s</b>]', 'LANG_SPECIFIC_OPTIONS' => 'Language specific options [<b>%s</b>]',
'USER_FIELD_NAME' => 'Field Name presented to the user', 'USER_FIELD_NAME' => 'Field Name presented to the user',
'FIELD_DESCRIPTION' => 'Field Description', 'FIELD_DESCRIPTION' => 'Field Description',

View file

@ -973,7 +973,7 @@ page_footer();
// //
function show_profile($data) function show_profile($data)
{ {
global $config, $auth, $template, $user, $ranks, $SID, $phpEx; global $config, $auth, $template, $user, $ranks, $SID, $phpEx, $phpbb_root_path;
$username = $data['username']; $username = $data['username'];
$user_id = $data['user_id']; $user_id = $data['user_id'];
@ -986,13 +986,16 @@ function show_profile($data)
} }
else else
{ {
foreach ($ranks['normal'] as $rank) if(isset($ranks['normal']))
{ {
if ($data['user_posts'] >= $rank['rank_min']) foreach ($ranks['normal'] as $rank)
{ {
$rank_title = $rank['rank_title']; if ($data['user_posts'] >= $rank['rank_min'])
$rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" border="0" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" /><br />' : ''; {
break; $rank_title = $rank['rank_title'];
$rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" border="0" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" /><br />' : '';
break;
}
} }
} }
} }

View file

@ -120,10 +120,11 @@
<td class="gen" align="right" nowrap="nowrap">{L_WEBSITE}: </td> <td class="gen" align="right" nowrap="nowrap">{L_WEBSITE}: </td>
<td><b><!-- IF U_WWW --><a class="genmed" href="{U_WWW}" target="_userwww">{U_WWW}</a><!-- ENDIF --></b></td> <td><b><!-- IF U_WWW --><a class="genmed" href="{U_WWW}" target="_userwww">{U_WWW}</a><!-- ENDIF --></b></td>
</tr> </tr>
<!-- IF S_PROFILE_FIELD_1 --> <!-- IF S_PROFILE_FIELD1 -->
<!-- Use a construct like this to include admin defined profile fields. Replace FIELD1 with the name of your field. -->
<tr> <tr>
<td class="gen" align="right" nowrap="nowrap">{PROFILE_FIELD_1_NAME}: </td> <td class="gen" align="right" nowrap="nowrap">{PROFILE_FIELD1_NAME}: </td>
<td><b class="genmed">{PROFILE_FIELD_1_VALUE}</b></td> <td><b class="genmed">{PROFILE_FIELD1_VALUE}</b></td>
</tr> </tr>
<!-- ENDIF --> <!-- ENDIF -->
</table></td> </table></td>

View file

@ -163,7 +163,7 @@ class module
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
if (!$module_id) if (!isset($module_id) || !$module_id)
{ {
trigger_error('MODULE_NOT_EXIST'); trigger_error('MODULE_NOT_EXIST');
} }