📄 functions_phpbb20.php
字号:
<?php/** ** @package install* @version $Id: functions_phpbb20.php,v 1.10 2007/01/24 11:29:35 acydburn Exp $* @copyright (c) 2006 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License **//*** Helper functions for phpBB 2.0.x to phpBB 3.0.x conversion*//*** Set forum flags - only prune old polls by default*/function phpbb_forum_flags(){ // Set forum flags $forum_flags = 0; // FORUM_FLAG_LINK_TRACK $forum_flags += 0; // FORUM_FLAG_PRUNE_POLL $forum_flags += FORUM_FLAG_PRUNE_POLL; // FORUM_FLAG_PRUNE_ANNOUNCE $forum_flags += 0; // FORUM_FLAG_PRUNE_STICKY $forum_flags += 0; // FORUM_FLAG_ACTIVE_TOPICS $forum_flags += 0; // FORUM_FLAG_POST_REVIEW $forum_flags += FORUM_FLAG_POST_REVIEW; return $forum_flags;}/*** Insert/Convert forums*/function phpbb_insert_forums(){ global $db, $convert, $user, $config; $db->sql_query($convert->truncate_statement . FORUMS_TABLE); // Determine the highest id used within the old forums table (we add the categories after the forum ids) $sql = 'SELECT MAX(forum_id) AS max_forum_id FROM ' . $convert->src_table_prefix . 'forums'; $result = $db->sql_query($sql); $max_forum_id = (int) $db->sql_fetchfield('max_forum_id'); $db->sql_freeresult($result); $max_forum_id++; // Insert categories $sql = 'SELECT cat_id, cat_title FROM ' . $convert->src_table_prefix . 'categories ORDER BY cat_order'; if ($convert->mysql_convert) { $db->sql_query("SET NAMES 'binary'"); } $result = $db->sql_query($sql); if ($convert->mysql_convert) { $db->sql_query("SET NAMES 'utf8'"); } $cats_added = array(); while ($row = $db->sql_fetchrow($result)) { $sql_ary = array( 'forum_id' => $max_forum_id, 'forum_name' => ($row['cat_title']) ? htmlspecialchars(phpbb_set_encoding($row['cat_title'], false), ENT_COMPAT, 'UTF-8') : $user->lang['CATEGORY'], 'parent_id' => 0, 'forum_parents' => '', 'forum_desc' => '', 'forum_type' => FORUM_CAT, 'forum_status' => ITEM_UNLOCKED, 'forum_rules' => '', ); $sql = 'SELECT MAX(right_id) AS right_id FROM ' . FORUMS_TABLE; $_result = $db->sql_query($sql); $cat_row = $db->sql_fetchrow($_result); $db->sql_freeresult($_result); $sql_ary['left_id'] = $cat_row['right_id'] + 1; $sql_ary['right_id'] = $cat_row['right_id'] + 2; $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); $cats_added[$row['cat_id']] = $max_forum_id; $max_forum_id++; } $db->sql_freeresult($result); // There may be installations having forums with non-existant category ids. // We try to catch them and add them to an "unknown" category instead of leaving them out. $sql = 'SELECT cat_id FROM ' . $convert->src_table_prefix . 'forums GROUP BY cat_id'; $result = $db->sql_query($sql); $unknown_cat_id = false; while ($row = $db->sql_fetchrow($result)) { // Catch those categories not been added before if (!isset($cats_added[$row['cat_id']])) { $unknown_cat_id = true; } } $db->sql_freeresult($result); // Is there at least one category not known? if ($unknown_cat_id === true) { $unknown_cat_id = 'ghost'; $sql_ary = array( 'forum_id' => $max_forum_id, 'forum_name' => $user->lang['CATEGORY'], 'parent_id' => 0, 'forum_parents' => '', 'forum_desc' => '', 'forum_type' => FORUM_CAT, 'forum_status' => ITEM_UNLOCKED, 'forum_rules' => '', ); $sql = 'SELECT MAX(right_id) AS right_id FROM ' . FORUMS_TABLE; $_result = $db->sql_query($sql); $cat_row = $db->sql_fetchrow($_result); $db->sql_freeresult($_result); $sql_ary['left_id'] = $cat_row['right_id'] + 1; $sql_ary['right_id'] = $cat_row['right_id'] + 2; $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); $cats_added[$unknown_cat_id] = $max_forum_id; $max_forum_id++; } // Now insert the forums $sql = 'SELECT f.*, fp.prune_days, fp.prune_freq FROM ' . $convert->src_table_prefix . 'forums f LEFT JOIN ' . $convert->src_table_prefix . 'forum_prune fp ON f.forum_id = fp.forum_id GROUP BY f.forum_id ORDER BY f.cat_id, f.forum_order'; if ($convert->mysql_convert) { $db->sql_query("SET NAMES 'binary'"); } $result = $db->sql_query($sql); if ($convert->mysql_convert) { $db->sql_query("SET NAMES 'utf8'"); } while ($row = $db->sql_fetchrow($result)) { // Some might have forums here with an id not being "possible"... // To be somewhat friendly we "change" the category id for those to a previously created ghost category if (!isset($cats_added[$row['cat_id']]) && $unknown_cat_id !== false) { $row['cat_id'] = $unknown_cat_id; } if (!isset($cats_added[$row['cat_id']])) { continue; } // Define the new forums sql ary $sql_ary = array( 'forum_id' => (int) $row['forum_id'], 'forum_name' => htmlspecialchars(phpbb_set_encoding($row['forum_name'], false), ENT_COMPAT, 'UTF-8'), 'parent_id' => $cats_added[$row['cat_id']], 'forum_parents' => '', 'forum_desc' => htmlspecialchars(phpbb_set_encoding($row['forum_desc'], false), ENT_COMPAT, 'UTF-8'), 'forum_type' => FORUM_POST, 'forum_status' => is_item_locked($row['forum_status']), 'enable_prune' => $row['prune_enable'], 'prune_next' => null_to_zero($row['prune_next']), 'prune_days' => null_to_zero($row['prune_days']), 'prune_viewed' => 0, 'prune_freq' => null_to_zero($row['prune_freq']), 'forum_flags' => phpbb_forum_flags(), // Default values 'forum_desc_bitfield' => '', 'forum_desc_options' => 7, 'forum_desc_uid' => '', 'forum_link' => '', 'forum_password' => '', 'forum_style' => 0, 'forum_image' => '', 'forum_rules' => '', 'forum_rules_link' => '', 'forum_rules_bitfield' => '', 'forum_rules_options' => 7, 'forum_rules_uid' => '', 'forum_topics_per_page' => 0, 'forum_posts' => 0, 'forum_topics' => 0, 'forum_topics_real' => 0, 'forum_last_post_id' => 0, 'forum_last_poster_id' => 0, 'forum_last_post_subject' => '', 'forum_last_post_time' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => '', 'display_on_index' => 1, 'enable_indexing' => 1, 'enable_icons' => 0, ); // Now add the forums with proper left/right ids $sql = 'SELECT left_id, right_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $cats_added[$row['cat_id']]; $_result = $db->sql_query($sql); $cat_row = $db->sql_fetchrow($_result); $db->sql_freeresult($_result); $sql = 'UPDATE ' . FORUMS_TABLE . ' SET left_id = left_id + 2, right_id = right_id + 2 WHERE left_id > ' . $cat_row['right_id']; $db->sql_query($sql); $sql = 'UPDATE ' . FORUMS_TABLE . ' SET right_id = right_id + 2 WHERE ' . $cat_row['left_id'] . ' BETWEEN left_id AND right_id'; $db->sql_query($sql); $sql_ary['left_id'] = $cat_row['right_id']; $sql_ary['right_id'] = $cat_row['right_id'] + 1; $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); } $db->sql_freeresult($result);}/*** Function for recoding text with the default language** @param string $text text to recode to utf8* @param bool $grab_user_lang if set to true the function tries to use $convert_row['user_lang'] (and falls back to $convert_row['poster_id']) instead of the boards default language*/function phpbb_set_encoding($text, $grab_user_lang = true){ global $lang_enc_array, $convert_row; global $convert, $phpEx; /*static $lang_enc_array = array( 'korean' => 'euc-kr', 'serbian' => 'windows-1250', 'polish' => 'iso-8859-2', 'kurdish' => 'windows-1254', 'slovak' => 'Windows-1250', 'russian' => 'windows-1251', 'estonian' => 'iso-8859-4', 'chinese_simplified' => 'gb2312', 'macedonian' => 'windows-1251', 'azerbaijani' => 'UTF-8', 'romanian' => 'iso-8859-2', 'romanian_diacritice' => 'iso-8859-2', 'lithuanian' => 'windows-1257', 'turkish' => 'iso-8859-9', 'ukrainian' => 'windows-1251', 'japanese' => 'shift_jis', 'hungarian' => 'ISO-8859-2', 'romanian_no_diacritics' => 'iso-8859-2', 'mongolian' => 'UTF-8', 'slovenian' => 'windows-1250', 'bosnian' => 'windows-1250', 'czech' => 'Windows-1250', 'farsi' => 'Windows-1256', 'croatian' => 'windows-1250', 'greek' => 'iso-8859-7', 'russian_tu' => 'windows-1251', 'sakha' => 'UTF-8', 'serbian_cyrillic' => 'windows-1251', 'bulgarian' => 'windows-1251', 'chinese_traditional_taiwan' => 'big5', 'chinese_traditional' => 'big5', 'arabic' => 'windows-1256', 'hebrew' => 'WINDOWS-1255', 'thai' => 'windows-874', //'chinese_traditional_taiwan' => 'utf-8' // custom modified, we may have to do an include :-( );*/ if (empty($lang_enc_array)) { $lang_enc_array = array(); } $get_lang = trim(get_config_value('default_lang')); // Do we need the users language encoding? if ($grab_user_lang && !empty($convert_row)) { if (!empty($convert_row['user_lang'])) { $get_lang = trim($convert_row['user_lang']); } else if (!empty($convert_row['poster_id'])) { global $db; $sql = 'SELECT user_lang FROM ' . $convert->src_table_prefix . 'users WHERE user_id = ' . (int) $convert_row['poster_id']; $result = $db->sql_query($sql); $get_lang = (string) $db->sql_fetchfield('user_lang'); $db->sql_freeresult($result); $get_lang = (!trim($get_lang)) ? trim(get_config_value('default_lang')) : trim($get_lang); } } if (!isset($lang_enc_array[$get_lang])) { $filename = $convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx; if (!file_exists($filename)) { $get_lang = trim(get_config_value('default_lang')); } if (!isset($lang_enc_array[$get_lang])) { include($convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx); $lang_enc_array[$get_lang] = $lang['ENCODING']; unset($lang); } } $encoding = $lang_enc_array[$get_lang]; return utf8_recode($text, $lang_enc_array[$get_lang]);}/*** Same as phpbb_set_encoding, but forcing boards default language*/function phpbb_set_default_encoding($text){ return phpbb_set_encoding($text, false);}/*** Convert Birthday from Birthday MOD to phpBB Format*/function phpbb_get_birthday($birthday = ''){ $birthday = (int) $birthday; if (defined('MOD_BIRTHDAY_TERRA')) { // stored as month, day, year if (!$birthday) { return ' 0- 0- 0'; } $birthday = (string) $birthday; $month = substr($birthday, 0, 2); $day = substr($birthday, 2, 2); $year = substr($birthday, -4); return sprintf('%2d-%2d-%4d', $day, $month, $year); } else { if (!$birthday || $birthday == 999999 || $birthday < 0) { return ' 0- 0- 0'; } // The birthday mod from niels is using this code to transform to day/month/year return gmdate('d-m-Y', $birthday * 86400 + 1); }}/*** Return correct user id value* Everyone's id will be one higher to allow the guest/anonymous user to have a positive id as well*/function phpbb_user_id($user_id){ if (!$user_id) { return 0; } if ($user_id == -1) { return ANONYMOUS; } global $config; // Increment user id if the old forum is having a user with the id 1 if (!isset($config['increment_user_id'])) { global $db, $convert; // Now let us set a temporary config variable for user id incrementing $sql = "SELECT user_id FROM {$convert->src_table_prefix}users WHERE user_id = 1"; $result = $db->sql_query($sql); $id = (int) $db->sql_fetchfield('user_id'); $db->sql_freeresult($result); // If there is a user id 1, we need to increment user ids. :/ if ($id === 1) { set_config('increment_user_id', 1, true); $config['increment_user_id'] = 1; } else { set_config('increment_user_id', 0, true); $config['increment_user_id'] = 0; } } if (!empty($config['increment_user_id'])) { $user_id++; } return $user_id;}/* Copy additional table fields from old forum to new forum if user wants this (for Mod compatibility for example)function phpbb_copy_table_fields(){}*//*** Convert authentication* user, group and forum table has to be filled in order to work*/function phpbb_convert_authentication($mode){ global $db, $convert, $user, $config, $cache; if ($mode == 'start') { $db->sql_query($convert->truncate_statement . ACL_USERS_TABLE); $db->sql_query($convert->truncate_statement . ACL_GROUPS_TABLE); // Grab user id of first user with user_level of ADMIN $sql = "SELECT user_id FROM {$convert->src_table_prefix}users WHERE user_level = 1 ORDER BY user_regdate ASC"; $result = $db->sql_query_limit($sql, 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -