From 2fa463cdeb5d8e4f2373aa834154ca27ea21c97a Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 16 Sep 2004 18:33:22 +0000 Subject: [PATCH] - more updates, mostly bugfixes to the bbcode parser - changed current_user in sessions (please review) - give more flexibility to style authors in regard to the pagination elements - profile fields updates (included a sample constuct into viewtopic_body.html - have to be documented extensivly) - code optimizations (use of strpos, sizeof, loops not iterating functions on every call, memory savings...) - and last but not least --- hopefully not introduced more bugs than healthy (*cough*) git-svn-id: file:///svn/phpbb/trunk@4984 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/adm/admin_attachments.php | 24 +- phpBB/adm/admin_database.php | 2 +- phpBB/adm/admin_profile.php | 507 +++++++++++++----- phpBB/common.php | 19 +- phpBB/download.php | 2 +- phpBB/faq.php | 4 +- phpBB/includes/bbcode.php | 33 +- phpBB/includes/functions.php | 69 ++- phpBB/includes/functions_admin.php | 6 +- phpBB/includes/functions_display.php | 26 +- phpBB/includes/functions_posting.php | 38 +- phpBB/includes/functions_privmsgs.php | 14 +- phpBB/includes/functions_profile_fields.php | 330 +++++++----- phpBB/includes/message_parser.php | 95 ++-- phpBB/includes/session.php | 7 +- phpBB/includes/template.php | 8 +- phpBB/includes/ucp/ucp_pm_viewfolder.php | 7 +- phpBB/includes/ucp/ucp_profile.php | 11 +- phpBB/includes/ucp/ucp_register.php | 4 +- phpBB/install/install.php | 6 +- phpBB/install/schemas/schema_data.sql | 3 + phpBB/language/en/admin.php | 34 +- phpBB/language/en/common.php | 4 +- phpBB/language/en/ucp.php | 10 + phpBB/memberlist.php | 18 + phpBB/posting.php | 24 +- .../styles/subSilver/template/mcp_footer.html | 2 +- .../subSilver/template/mcp_reports.html | 2 +- .../subSilver/template/mcp_viewlogs.html | 2 +- .../subSilver/template/memberlist_body.html | 2 +- .../subSilver/template/memberlist_view.html | 6 + .../subSilver/template/posting_preview.html | 2 +- .../template/search_results_posts.html | 2 +- .../template/search_results_topics.html | 2 +- .../subSilver/template/ucp_attachments.html | 2 +- .../template/ucp_pm_message_footer.html | 2 +- .../template/ucp_pm_message_header.html | 2 +- .../subSilver/template/viewforum_body.html | 16 +- .../subSilver/template/viewtopic_body.html | 5 +- phpBB/ucp.php | 2 +- phpBB/viewforum.php | 15 +- phpBB/viewtopic.php | 81 ++- 42 files changed, 945 insertions(+), 505 deletions(-) diff --git a/phpBB/adm/admin_attachments.php b/phpBB/adm/admin_attachments.php index 0ffc556241..5bc7441978 100644 --- a/phpBB/adm/admin_attachments.php +++ b/phpBB/adm/admin_attachments.php @@ -302,7 +302,7 @@ if ($submit && $mode == 'ext_groups') $group_ary = array( 'group_name' => $group_name, - 'cat_id' => request_var('special_category', NONE_CAT), + 'cat_id' => request_var('special_category', ATTACHMENT_CATEGORY_NONE), 'allow_group' => (isset($_REQUEST['allow_group'])) ? 1 : 0, 'download_mode' => request_var('download_mode', INLINE_LINK), 'upload_icon' => ($upload_icon == 'no_image') ? '' : $upload_icon, @@ -570,7 +570,7 @@ if ($mode == 'attach') lang['SETTINGS_CAT_IMAGES']; ?> - lang['ASSIGNED_GROUP']; ?>: lang['NONE']); ?> + lang['ASSIGNED_GROUP']; ?>: lang['NONE']); ?> lang['DISPLAY_INLINED']; ?>:
lang['DISPLAY_INLINED_EXPLAIN']; ?> @@ -710,10 +710,10 @@ if ($mode == 'attach') if ($mode == 'ext_groups') { $cat_lang = array( - NONE_CAT => $user->lang['NONE'], - IMAGE_CAT => $user->lang['CAT_IMAGES'], - WM_CAT => $user->lang['CAT_WM_FILES'], - RM_CAT => $user->lang['CAT_RM_FILES'] + ATTACHMENT_CATEGORY_NONE => $user->lang['NONE'], + ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'], + ATTACHMENT_CATEGORY_WM => $user->lang['CAT_WM_FILES'], + ATTACHMENT_CATEGORY_RM => $user->lang['CAT_RM_FILES'] ); @@ -1281,10 +1281,10 @@ function category_select($select_name, $group_id = FALSE) global $db, $user; $types = array( - NONE_CAT => $user->lang['NONE'], - IMAGE_CAT => $user->lang['CAT_IMAGES'], - WM_CAT => $user->lang['CAT_WM_FILES'], - RM_CAT => $user->lang['CAT_RM_FILES'] + ATTACHMENT_CATEGORY_NONE => $user->lang['NONE'], + ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'], + ATTACHMENT_CATEGORY_WM => $user->lang['CAT_WM_FILES'], + ATTACHMENT_CATEGORY_RM => $user->lang['CAT_RM_FILES'] ); if ($group_id) @@ -1294,13 +1294,13 @@ function category_select($select_name, $group_id = FALSE) WHERE group_id = ' . intval($group_id); $result = $db->sql_query($sql); - $cat_type = (!($row = $db->sql_fetchrow($result))) ? NONE_CAT : $row['cat_id']; + $cat_type = (!($row = $db->sql_fetchrow($result))) ? ATTACHMENT_CATEGORY_NONE : $row['cat_id']; $db->sql_freeresult($result); } else { - $cat_type = NONE_CAT; + $cat_type = ATTACHMENT_CATEGORY_NONE; } $group_select = ''; - + $error = array(); + $submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false; $update = (isset($_REQUEST['update'])) ? true : false; $save = (isset($_REQUEST['save'])) ? true : false; - if (!$field_type) + // We are editing... we need to grab basic things + if ($mode == 'edit') { - trigger_error('NO_FIELD_TYPE'); + if (!$field_id) + { + trigger_error('No field id specified'); + } + + $sql = 'SELECT l.*, f.* + FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f + WHERE l.lang_id = ' . $lang_defs['iso'][$config['default_lang']] . " + AND f.field_id = $field_id + AND l.field_id = f.field_id"; + $result = $db->sql_query($sql); + $field_row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$field_row) + { + trigger_error('Profile field not found'); + } + $field_type = $field_row['field_type']; + + // Get language entries + $sql = 'SELECT * FROM ' . PROFILE_FIELDS_LANG_TABLE . ' + WHERE lang_id = ' . $lang_defs['iso'][$config['default_lang']] . " + AND field_id = $field_id + ORDER BY option_id ASC"; + $result = $db->sql_query($sql); + + $lang_options = array(); + while ($row = $db->sql_fetchrow($result)) + { + $lang_options[$row['option_id']] = $row['value']; + } + $db->sql_freeresult($result); + + $field_row['pf_preview'] = ''; + + $s_hidden_fields = ''; + } + else + { + // We are adding a new field, define basic params + $lang_options = array(); + $field_row = array(); + + $field_type = request_var('field_type', 0); + + if (!$field_type) + { + trigger_error('NO_FIELD_TYPE'); + } + + $field_row = array_merge($default_values[$field_type], array( + 'field_name' => request_var('field_name', ''), + 'field_required' => 0, + 'field_hide' => 0, + 'field_show_on_reg' => 0, + 'lang_name' => '', + 'lang_explain' => '', + 'lang_default_value'=> '', + 'pf_preview' => '') + ); + + $s_hidden_fields = ''; } // Get all relevant informations about entered values within all steps - $exclude = array( 1 => array('lang_name', 'lang_explain', 'field_name'), 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'), @@ -153,16 +213,41 @@ if ($mode == 'create') $exclude[1][] = 'lang_options'; } - $cp->vars['lang_name'] = request_var('lang_name', ''); - $cp->vars['lang_explain'] = request_var('lang_explain', ''); - $cp->vars['lang_default_value'] = request_var('lang_default_value', ''); - $cp->vars['lang_options'] = request_var('lang_options', ''); + $cp->vars['field_name'] = request_var('field_name', $field_row['field_name']); + $cp->vars['lang_name'] = request_var('lang_name', $field_row['lang_name']); + $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']); + + $options = request_var('lang_options', ''); + if ($options) + { + if (sizeof(explode("\n", $options)) == sizeof($lang_options)) + { + $cp->vars['lang_options'] = explode("\n", $options); + } + else + { + $cp->vars['lang_options'] = $lang_options; + $error[] = 'You are not allowed to remove or add options within already existing profile fields'; + } + } + else + { + $cp->vars['lang_options'] = $lang_options; + } // step 2 foreach ($exclude[2] as $key) { - $var = request_var($key, $default_values[$key][$field_type]); - + if ($key == 'field_required' || $key == 'field_hide' || $key == 'field_show_on_reg') + { + $var = (isset($_REQUEST[$key])) ? request_var($key, 0) : $field_row[$key]; + } + else + { + $var = request_var($key, $field_row[$key]); + } + // Manipulate the intended variables a little bit if needed if ($field_type == FIELD_DROPDOWN && $key == 'field_maxlen') { @@ -216,12 +301,56 @@ if ($mode == 'create') } // step 3 - all arrays + if ($mode == 'edit') + { + // Get language entries + $sql = 'SELECT * FROM ' . PROFILE_FIELDS_LANG_TABLE . ' + WHERE lang_id <> ' . $lang_defs['iso'][$config['default_lang']] . " + AND field_id = $field_id + ORDER BY option_id ASC"; + $result = $db->sql_query($sql); + + $l_lang_options = array(); + while ($row = $db->sql_fetchrow($result)) + { + $l_lang_options[$row['lang_id']][$row['option_id']] = $row['value']; + } + $db->sql_freeresult($result); + + + $sql = 'SELECT lang_id, lang_name, lang_explain, lang_default_value FROM ' . PROFILE_LANG_TABLE . ' + WHERE lang_id <> ' . $lang_defs['iso'][$config['default_lang']] . " + AND field_id = $field_id + ORDER BY lang_id ASC"; + $result = $db->sql_query($sql); + + $l_lang_name = $l_lang_explain = $l_lang_default_value = array(); + while ($row = $db->sql_fetchrow($result)) + { + $l_lang_name[$row['lang_id']] = $row['lang_name']; + $l_lang_explain[$row['lang_id']] = $row['lang_explain']; + $l_lang_default_value[$row['lang_id']] = $row['lang_default_value']; + } + $db->sql_freeresult($result); + } + foreach ($exclude[3] as $key) { $cp->vars[$key] = request_var($key, ''); + + if (!$cp->vars[$key] && $mode == 'edit') + { + $cp->vars[$key] = $$key; + } + else if ($key == 'l_lang_options') + { + foreach ($cp->vars[$key] as $lang_id => $options) + { + $cp->vars[$key][$lang_id] = explode("\n", $options); + } + } } - $error = array(); if ($submit && $step == 1) { // Check values for step 1 @@ -233,16 +362,14 @@ if ($mode == 'create') { $error[] = $user->lang['EMPTY_USER_FIELD_NAME']; } - - $sql = 'SELECT field_ident - FROM ' . PROFILE_FIELDS_TABLE . " - WHERE field_ident = '$field_ident'"; - $result = $db->sql_query($sql); - if ($row = $db->sql_fetchrow($result)) + if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN) { - $error[] = sprintf($user->lang['FIELD_IDENT_ALREADY_EXIST'], $field_ident); - } + if (!sizeof($cp->vars['lang_options'])) + { + $error[] = 'No Entries defined'; + } + } } $user_error = false; @@ -282,18 +409,18 @@ if ($mode == 'create') { if ($step == 3 && (sizeof($lang_defs['iso']) == 1 || $save)) { - save_profile_field($field_type, $field_ident); + save_profile_field($field_type, $mode); } } ?> -

lang['STEP_' . $step . '_EXPLAIN']; ?>

+

lang['STEP_' . $step . '_EXPLAIN_' . strtoupper($mode)]; ?>

"> - + vars['lang_options'])) + if ($field_type == FIELD_BOOL && !sizeof($cp->vars['lang_options'])) { $cp->vars['lang_options'][0] = ''; $cp->vars['lang_options'][1] = ''; @@ -357,13 +484,13 @@ if ($mode == 'create') ?> - + - +
lang['STEP_' . $step . '_TITLE']; ?>lang['STEP_' . $step . '_TITLE_' . strtoupper($mode)]; ?>
lang['ENTRIES']; ?>:
lang[strtoupper($cp->profile_types[$field_type]) . '_ENTRIES_EXPLAIN']; ?>
' . $cp->vars['lang_options'] . '' : '
[ ' . $user->lang['FIRST_OPTION'] . ' ]
[ ' . $user->lang['SECOND_OPTION'] . ' ]
'; ?>
' . implode("\n", $cp->vars['lang_options']) . '' : '
[ ' . $user->lang['FIRST_OPTION'] . ' ]
[ ' . $user->lang['SECOND_OPTION'] . ' ]
'; ?>
@@ -402,7 +529,7 @@ if ($mode == 'create') } ?> -
 
+
 
@@ -415,6 +542,39 @@ if ($mode == 'create') lang[$user_error], $cp->vars['lang_name']); + break; + case 'FIELD_TOO_SHORT': + case 'FIELD_TOO_SMALL': + $user_error = sprintf($user->lang[$user_error], $cp->vars['lang_name'], $cp->vars['field_minlen']); + break; + case 'FIELD_TOO_LONG': + case 'FIELD_TOO_LARGE': + $user_error = sprintf($user->lang[$user_error], $cp->vars['lang_name'], $cp->vars['field_maxlen']); + break; + case 'FIELD_INVALID_CHARS': + switch ($cp->vars['field_validation']) + { + case '[0-9]+': + $user_error = sprintf($user->lang[$user_error . '_NUMBERS_ONLY'], $cp->vars['lang_name']); + break; + case '[\w]+': + $user_error = sprintf($user->lang[$user_error . '_ALPHA_ONLY'], $cp->vars['lang_name']); + break; + case '[\w_\+\. \-\[\]]+': + $user_error = sprintf($user->lang[$user_error . '_SPACERS_ONLY'], $cp->vars['lang_name']); + break; + } + + default: + $user_error = ''; + } + ?> ' . $user_error . '' : '' . $user->lang['EVERYTHING_OK'] . ''; ?> @@ -449,7 +609,7 @@ if ($mode == 'create') // Define remaining language variables case 3: - $options = build_language_options($field_type); + $options = build_language_options($field_type, $mode); foreach ($options as $lang_id => $lang_ary) { @@ -470,7 +630,7 @@ if ($mode == 'create') } ?> -
+
@@ -673,13 +833,13 @@ function preview_field($field_data) } // Build all Language specific options -function build_language_options($field_type, $mode = 'new') +function build_language_options($field_type, $mode = 'create') { global $user, $config, $db, $cp; $sql = 'SELECT lang_id, lang_iso - FROM ' . LANG_TABLE . - (($mode == 'new') ? " WHERE lang_iso <> '" . $config['default_lang'] . "'" : ''); + FROM ' . LANG_TABLE . " + WHERE lang_iso <> '" . $config['default_lang'] . "'"; $result = $db->sql_query($sql); $languages = array(); @@ -715,20 +875,17 @@ function build_language_options($field_type, $mode = 'new') $lang_options = array(); - if ($mode == 'new') + foreach ($options as $field => $field_type) { - foreach ($options as $field => $field_type) - { - $lang_options[1]['lang_iso'] = $config['default_lang']; - $lang_options[1]['fields'][$field] = array( - 'TITLE' => $user->lang['CP_' . strtoupper($field)], - 'FIELD' => '' . ((is_array($cp->vars[$field])) ? implode('
', $cp->vars[$field]) : str_replace("\n", '
', $cp->vars[$field])) . '
' - ); + $lang_options[1]['lang_iso'] = $config['default_lang']; + $lang_options[1]['fields'][$field] = array( + 'TITLE' => $user->lang['CP_' . strtoupper($field)], + 'FIELD' => '' . ((is_array($cp->vars[$field])) ? implode('
', $cp->vars[$field]) : str_replace("\n", '
', $cp->vars[$field])) . '
' + ); - if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN'])) - { - $lang_options[1]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN']; - } + if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN'])) + { + $lang_options[1]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN']; } } @@ -737,11 +894,11 @@ function build_language_options($field_type, $mode = 'new') $lang_options[$lang_id]['lang_iso'] = $lang_iso; foreach ($options as $field => $field_type) { - $value = ($mode == 'new') ? request_var('l_' . $field, '') : $cp->vars['l_' . $field]; + $value = ($mode == 'create') ? request_var('l_' . $field, '') : $cp->vars['l_' . $field]; if ($field == 'lang_options') { - $var = ($mode == 'new') ? $cp->vars['lang_options'] : $cp->vars['lang_options'][$lang_id]; + $var = ($mode == 'create') ? $cp->vars['lang_options'] : $cp->vars['lang_options'][$lang_id]; switch ($field_type) { @@ -757,7 +914,7 @@ function build_language_options($field_type, $mode = 'new') $lang_options[$lang_id]['fields'][$field] = array( 'TITLE' => $user->lang['CP_' . strtoupper($field)], - 'FIELD' => '' + 'FIELD' => '' ); break; } @@ -769,7 +926,7 @@ function build_language_options($field_type, $mode = 'new') } else { - $var = ($mode == 'new') ? $cp->vars[$field] : $cp->vars[$field][$lang_id]; + $var = ($mode == 'create') ? $cp->vars[$field] : $cp->vars[$field][$lang_id]; $lang_options[$lang_id]['fields'][$field] = array( 'TITLE' => $user->lang['CP_' . strtoupper($field)], @@ -787,24 +944,30 @@ function build_language_options($field_type, $mode = 'new') return $lang_options; } -function save_profile_field($field_type, $field_ident) +function save_profile_field($field_type, $mode = 'create') { global $cp, $db, $config, $user, $lang_defs; + $field_id = request_var('field_id', 0); + // Collect all informations, if something is going wrong, abort the operation $profile_sql = $profile_lang = $empty_lang = $profile_lang_fields = array(); $default_lang_id = $lang_defs['iso'][$config['default_lang']]; - $result = $db->sql_query('SELECT MAX(field_order) as max_field_order FROM phpbb_profile_fields'); - $new_field_order = (int) $db->sql_fetchfield('max_field_order', 0, $result); - $db->sql_freeresult($result); + if ($mode == 'create') + { + $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); + $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 = 'field_' . ($new_field_order + 1); + } // Save the field $profile_fields = array( 'field_name' => $cp->vars['field_name'], - 'field_type' => $field_type, - 'field_ident' => $field_ident, 'field_length' => $cp->vars['field_length'], 'field_minlen' => $cp->vars['field_minlen'], 'field_maxlen' => $cp->vars['field_maxlen'], @@ -813,52 +976,78 @@ function save_profile_field($field_type, $field_ident) 'field_validation' => $cp->vars['field_validation'], 'field_required' => $cp->vars['field_required'], 'field_show_on_reg' => $cp->vars['field_show_on_reg'], - 'field_hide' => $cp->vars['field_hide'], - 'field_order' => $new_field_order + 1, - 'field_active' => 1 + 'field_hide' => $cp->vars['field_hide'] ); - $db->sql_query('INSERT INTO phpbb_profile_fields ' . $db->sql_build_array('INSERT', $profile_fields)); - - $field_id = $db->sql_nextid(); - - $sql = 'ALTER TABLE ' . PROFILE_DATA_TABLE . " ADD $field_ident "; - switch ($field_type) + if ($mode == 'create') { - case FIELD_STRING: - $sql .= " VARCHAR(255) DEFAULT NULL NULL"; - break; + $profile_fields += array( + 'field_type' => $field_type, + 'field_ident' => $field_ident, + 'field_order' => $new_field_order + 1, + 'field_active' => 1 + ); - case FIELD_DATE: - $sql .= "VARCHAR(10) DEFAULT NULL NULL"; - break; + $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_TABLE . ' ' . $db->sql_build_array('INSERT', $profile_fields)); - case FIELD_TEXT: - $sql .= "TEXT NULL"; - break; - - case FIELD_BOOL: - $sql .= "TINYINT(2) DEFAULT NULL NULL"; - break; - - case FIELD_DROPDOWN: - $sql .= "MEDIUMINT(8) DEFAULT NULL NULL"; - break; - - case FIELD_INT: - $sql .= (($cp->vars['field_maxlen'] > 60000) ? 'BIGINT(20)' : 'MEDIUMINT(8)') . (($cp->vars['field_minlen'] >= 0) ? ' UNSIGNED' : ' ') . " DEFAULT NULL NULL"; - break; + $field_id = $db->sql_nextid(); + } + else + { + $db->sql_query('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $profile_fields) . " + WHERE field_id = $field_id"); + } + + if ($mode == 'create') + { + // We are defining the biggest common value, because of the possibility to edit the min/max values of each field. + $sql = 'ALTER TABLE ' . PROFILE_DATA_TABLE . " ADD $field_ident "; + switch ($field_type) + { + case FIELD_STRING: + $sql .= ' VARCHAR(255) DEFAULT NULL NULL'; + break; + + case FIELD_DATE: + $sql .= 'VARCHAR(10) DEFAULT NULL NULL'; + break; + + case FIELD_TEXT: + $sql .= 'TEXT NULL'; + break; + + case FIELD_BOOL: + $sql .= 'TINYINT(2) DEFAULT NULL NULL'; + break; + + case FIELD_DROPDOWN: + $sql .= 'MEDIUMINT(8) DEFAULT NULL NULL'; + break; + + case FIELD_INT: + $sql .= 'BIGINT(20) DEFAULT NULL NULL'; + break; + } + $profile_sql[] = $sql; } - $profile_sql[] = $sql; $sql_ary = array( - 'field_id' => $field_id, - 'lang_id' => $default_lang_id, 'lang_name' => $cp->vars['lang_name'], 'lang_explain' => $cp->vars['lang_explain'], 'lang_default_value' => $cp->vars['lang_default_value'] ); - $profile_sql[] = 'INSERT INTO phpbb_profile_lang ' . $db->sql_build_array('INSERT', $sql_ary); + + if ($mode == 'create') + { + $sql_ary['field_id'] = $field_id; + $sql_ary['lang_id'] = $default_lang_id; + + $profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + } + else + { + update_insert(PROFILE_LANG_TABLE, $sql_ary, array('field_id' => $field_id, 'lang_id' => $default_lang_id)); + } if (sizeof($cp->vars['l_lang_name'])) { @@ -900,13 +1089,26 @@ function save_profile_field($field_type, $field_ident) foreach ($cp->vars['lang_options'] as $option_id => $value) { $sql_ary = array( - 'field_id' => $field_id, - 'lang_id' => $default_lang_id, - 'option_id' => $option_id, - 'field_type' => $field_type, + 'field_type' => (int) $field_type, 'value' => $value ); - $profile_sql[] = 'INSERT INTO phpbb_profile_fields_lang ' . $db->sql_build_array('INSERT', $sql_ary); + + if ($mode == 'create') + { + $sql_ary['field_id'] = $field_id; + $sql_ary['lang_id'] = $default_lang_id; + $sql_ary['option_id'] = (int) $option_id; + + $profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + } + else + { + update_insert(PROFILE_FIELDS_LANG_TABLE, $sql_ary, array( + 'field_id' => $field_id, + 'lang_id' => (int) $default_lang_id, + 'option_id' => (int) $option_id) + ); + } } } @@ -929,10 +1131,10 @@ function save_profile_field($field_type, $field_ident) foreach ($lang_ary as $option_id => $value) { $profile_lang_fields[] = array( - 'field_id' => $field_id, - 'lang_id' => $lang_id, - 'option_id' => $option_id, - 'field_type' => $field_type, + 'field_id' => (int) $field_id, + 'lang_id' => (int) $lang_id, + 'option_id' => (int) $option_id, + 'field_type' => (int) $field_type, 'value' => $value ); } @@ -942,21 +1144,47 @@ function save_profile_field($field_type, $field_ident) foreach ($profile_lang as $sql) { - $profile_sql[] = 'INSERT INTO phpbb_profile_lang ' . $db->sql_build_array('INSERT', $sql); + if ($mode == 'create') + { + $profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql); + } + else + { + $lang_id = $sql['lang_id']; + unset($sql['lang_id'], $sql['field_id']); + update_insert(PROFILE_LANG_TABLE, $sql, array('lang_id' => (int) $lang_id, 'field_id' => $field_id)); + } } if (sizeof($profile_lang_fields)) { foreach ($profile_lang_fields as $sql) { - $profile_sql[] = 'INSERT INTO phpbb_profile_fields_lang ' . $db->sql_build_array('INSERT', $sql); + if ($mode == 'create') + { + $profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql); + } + else + { + $lang_id = $sql['lang_id']; + $option_id = $sql['option_id']; + unset($sql['lang_id'], $sql['field_id'], $sql['option_id']); + update_insert(PROFILE_FIELDS_LANG_TABLE, $sql, array( + 'lang_id' => $lang_id, + 'field_id' => $field_id, + 'option_id' => $option_id) + ); + } } } // $db->sql_transaction(); - foreach ($profile_sql as $sql) + if ($mode == 'create') { - $db->sql_query($sql); + foreach ($profile_sql as $sql) + { + $db->sql_query($sql); + } } // $db->sql_transaction('commit'); @@ -964,6 +1192,33 @@ function save_profile_field($field_type, $field_ident) trigger_error($user->lang['ADDED_PROFILE_FIELD']); } +// Update, then insert if not successfull +function update_insert($table, $sql_ary, $where_fields) +{ + global $db; + + $where_sql = array(); + foreach ($where_fields as $key => $value) + { + $where_sql[] = $key . ' = ' . ((is_string($value)) ? "'" . $db->sql_escape($value) . "'" : $value); + } + + $db->sql_return_on_error(true); + + $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE ' . implode(' AND ', $where_sql); + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + if (!$result) + { + $sql_ary = array_merge($where_fields, $sql_ary); + $db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql_ary)); + } + +} + function build_hidden_fields($key_ary) { $hidden_fields = ''; @@ -971,7 +1226,15 @@ function build_hidden_fields($key_ary) foreach ($key_ary as $key) { $var = isset($_POST[$key]) ? $_POST[$key] : false; - if (!$var) + + if ($key == 'field_required' || $key == 'field_hide' || $key == 'field_show_on_reg') + { + if (!$var) + { + $var = 0; + } + } + else if (!$var) { continue; } diff --git a/phpBB/common.php b/phpBB/common.php index 13ce9e45e2..efcb6eeb68 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -40,6 +40,15 @@ if (!defined('PHPBB_INSTALLED')) exit; } +if (defined('DEBUG_EXTRA')) +{ + $base_memory_usage = 0; + if (function_exists('memory_get_usage')) + { + $base_memory_usage = memory_get_usage(); + } +} + // Load Extensions if (!empty($load_extensions)) { @@ -138,11 +147,11 @@ define('INLINE_LINK', 1); define('PHYSICAL_LINK', 2); // Categories - Attachments -define('NONE_CAT', 0); -define('IMAGE_CAT', 1); // Inline Images -define('WM_CAT', 2); // Windows Media Files - Streaming -define('RM_CAT', 3); // Real Media Files - Streaming -define('THUMB_CAT', 4); // Not used within the database, only while displaying posts +define('ATTACHMENT_CATEGORY_NONE', 0); +define('ATTACHMENT_CATEGORY_IMAGE', 1); // Inline Images +define('ATTACHMENT_CATEGORY_WM', 2); // Windows Media Files - Streaming +define('ATTACHMENT_CATEGORY_RM', 3); // Real Media Files - Streaming +define('ATTACHMENT_CATEGORY_THUMB', 4); // Not used within the database, only while displaying posts //define('SWF_CAT', 5); // Replaced by [flash]? or an additional possibility? // BBCode UID length diff --git a/phpBB/download.php b/phpBB/download.php index 4640098c27..eff6d0c603 100644 --- a/phpBB/download.php +++ b/phpBB/download.php @@ -186,7 +186,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) // Correct the mime type - we force application/octetstream for all files, except images // Please do not change this, it is a security precaution - if ($category == NONE_CAT && !strstr($attachment['mimetype'], 'image')) + if ($category == ATTACHMENT_CATEGORY_NONE && strpos($attachment['mimetype'], 'image') === false) { $attachment['mimetype'] = ($browser_agent == 'ie' || $browser_agent == 'opera') ? 'application/octetstream' : 'application/octet-stream'; } diff --git a/phpBB/faq.php b/phpBB/faq.php index 845c12b2ac..d1317663f5 100644 --- a/phpBB/faq.php +++ b/phpBB/faq.php @@ -72,7 +72,7 @@ $template->assign_vars(array( 'L_BACK_TO_TOP' => $user->lang['BACK_TO_TOP']) ); -for ($i = 0; $i < count($help_block); $i++) +for ($i = 0, $size = sizeof($help_block); $i < $size; $i++) { if (sizeof($help_block[$i])) { @@ -84,7 +84,7 @@ for ($i = 0; $i < count($help_block); $i++) 'BLOCK_TITLE' => $help_block_titles[$i]) ); - for ($j = 0; $j < count($help_block[$i]); $j++) + for ($j = 0, $_size = sizeof($help_block[$i]); $j < $_size; $j++) { $template->assign_block_vars('faq_block.faq_row', array( 'FAQ_QUESTION' => $help_block[$i][$j]['question'], diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index f9b8fcbce3..4e56a2be77 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -257,10 +257,12 @@ class bbcode } break; case 12: - $this->bbcode_cache[$bbcode_id] = array('preg' => array( - '#\[attachment=([0-9]+):$uid\]#' => $this->bbcode_tpl('inline_attachment_open', $bbcode_id), - '#\[\/attachment:$uid\]#' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id) - )); + $this->bbcode_cache[$bbcode_id] = array( + 'str' => array( + '[/attachment:$uid]' => $this->bbcode_tpl('inline_attachment_close', $bbcode_id)), + 'preg' => array( + '#\[attachment=([0-9]+):$uid\]#' => $this->bbcode_tpl('inline_attachment_open', $bbcode_id)) + ); break; default: if (isset($rowset[$bbcode_id])) @@ -461,23 +463,22 @@ class bbcode switch ($type) { case 'php': + // Not the english way, but valid because of hardcoded syntax highlighting + if (strpos($code, '
') === 0) + { + $code = substr($code, 41); + } + default: $code = str_replace("\t", '   ', $code); $code = str_replace(' ', '  ', $code); $code = str_replace(' ', '  ', $code); - $match = array( - '#.*?#', - '#.*?#', - '#.*?#', - '#.*?#', - '#bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close'); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 33dd4f2295..6589f804bd 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -118,7 +118,7 @@ function get_userdata($user) } // Create forum rules for given forum -function generate_forum_rules($forum_data) +function generate_forum_rules(&$forum_data) { if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link']) { @@ -750,7 +750,8 @@ function markread($mode, $forum_id = 0, $topic_id = 0, $marktime = false) // Pagination routine, generates page number sequence -function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE) +// tpl_prefix is for using different pagination blocks at one page +function generate_pagination($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = true, $tpl_prefix = '') { global $template, $user; @@ -765,7 +766,7 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add $on_page = floor($start_item / $per_page) + 1; - $page_string = ($on_page == 1) ? '1' : '' . $user->lang['PREVIOUS'] . '  1'; + $page_string = ($on_page == 1) ? '1' : '1'; if ($total_pages > 5) { @@ -799,13 +800,17 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add } } - $page_string .= ($on_page == $total_pages) ? '' . $total_pages . '' : '' . $total_pages . '  ' . $user->lang['NEXT'] . ''; - + $page_string .= ($on_page == $total_pages) ? '' . $total_pages . '' : '' . $total_pages . ''; // $page_string = $user->lang['GOTO_PAGE'] . ' ' . $page_string; - $page_string = '' . $user->lang['GOTO_PAGE'] . ' ' . $page_string; +// $page_string = '' . $user->lang['GOTO_PAGE'] . ' ' . $page_string; - $template->assign_var('BASE_URL', $base_url); - $template->assign_var('PER_PAGE', $per_page); + $template->assign_vars(array( + $tpl_prefix . 'BASE_URL' => $base_url, + $tpl_prefix . 'PER_PAGE' => $per_page, + + $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page == 1) ? '' : $base_url . '&start=' . (($on_page - 2) * $per_page), + $tpl_prefix . 'NEXT_PAGE' => ($on_page == $total_pages) ? '' : $base_url . '&start=' . ($on_page * $per_page)) + ); return $page_string; } @@ -1005,7 +1010,7 @@ function redirect($url) $url = str_replace('&', '&', $url); // Local redirect? If not, prepend the boards url - $url = (!strstr($url, '://')) ? (generate_board_url() . preg_replace('#^/?(.*?)/?$#', '/\1', trim($url))) : $url; + $url = (strpos($url, '://') === false) ? (generate_board_url() . preg_replace('#^/?(.*?)/?$#', '/\1', trim($url))) : $url; // Redirect via an HTML form for PITA webservers if (@preg_match('#Microsoft|WebSTAR|Xitami#', getenv('SERVER_SOFTWARE'))) @@ -1165,7 +1170,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa 'U_PRIVACY' => "{$phpbb_root_path}ucp.$phpEx$SID&mode=privacy", 'S_DISPLAY_FULL_LOGIN' => ($s_display) ? true : false, - 'S_LOGIN_ACTION' => $redirect_page, + 'S_LOGIN_ACTION' => (!$admin) ? "{$phpbb_root_path}ucp.$phpEx$SID&mode=login" : "index.$phpEx$SID", 'S_HIDDEN_FIELDS' => $s_hidden_fields) ); @@ -1303,6 +1308,38 @@ function smilie_text($text, $force_option = false) return ($force_option || !$config['allow_smilies'] || !$user->optionget('viewsmilies')) ? preg_replace('#PHP Notice: in file $errfile on line $errline: $msg_text
"; @@ -1430,6 +1468,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) exit; break; +/* remove me default: if (defined('DEBUG_EXTRA')) { @@ -1438,7 +1477,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) echo "Another Error: in file $errfile on line $errline: $msg_text
"; } } - break; + break;*/ } } @@ -1732,21 +1771,23 @@ function page_footer() $db->sql_report('display'); } - $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . ( ( $config['gzip_compress'] ) ? 'On' : 'Off' ) . ' | Load : ' . (($user->load) ? $user->load : 'N/A'), $totaltime); + $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off' ) . ' | Load : ' . (($user->load) ? $user->load : 'N/A'), $totaltime); - if ($auth->acl_get('a_')) + if ($auth->acl_get('a_') && defined('DEBUG_EXTRA')) { if (function_exists('memory_get_usage')) { if ($memory_usage = memory_get_usage()) { + global $base_memory_usage; + $memory_usage -= $base_memory_usage; $memory_usage = ($memory_usage >= 1048576) ? round((round($memory_usage / 1048576 * 100) / 100), 2) . ' ' . $user->lang['MB'] : (($memory_usage >= 1024) ? round((round($memory_usage / 1024 * 100) / 100), 2) . ' ' . $user->lang['KB'] : $memory_usage . ' ' . $user->lang['BYTES']); $debug_output .= ' | Memory Usage: ' . $memory_usage; } } - $debug_output .= ' | Explain'; + $debug_output .= ' | Explain'; } } diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 097a7769fc..2ffda2ac72 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -81,7 +81,7 @@ function size_select($select_name, $size_compare) $select_field = '