Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
functions_phpbb20.php
0001 <?php
0002 /**
0003 *
0004 * @package install
0005 * @version $Id$
0006 * @copyright (c) 2006 phpBB Group
0007 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
0008 *
0009 */
0010
0011 if (!defined('IN_PHPBB'))
0012 {
0013 exit;
0014 }
0015
0016 /**
0017 * Helper functions for phpBB 2.0.x to phpBB 3.0.x conversion
0018 */
0019
0020 /**
0021 * Set forum flags - only prune old polls by default
0022 */
0023 function phpbb_forum_flags()
0024 {
0025 // Set forum flags
0026 $forum_flags = 0;
0027
0028 // FORUM_FLAG_LINK_TRACK
0029 $forum_flags += 0;
0030
0031 // FORUM_FLAG_PRUNE_POLL
0032 $forum_flags += FORUM_FLAG_PRUNE_POLL;
0033
0034 // FORUM_FLAG_PRUNE_ANNOUNCE
0035 $forum_flags += 0;
0036
0037 // FORUM_FLAG_PRUNE_STICKY
0038 $forum_flags += 0;
0039
0040 // FORUM_FLAG_ACTIVE_TOPICS
0041 $forum_flags += 0;
0042
0043 // FORUM_FLAG_POST_REVIEW
0044 $forum_flags += FORUM_FLAG_POST_REVIEW;
0045
0046 return $forum_flags;
0047 }
0048
0049 /**
0050 * Insert/Convert forums
0051 */
0052 function phpbb_insert_forums()
0053 {
0054 global $db, $src_db, $same_db, $convert, $user, $config;
0055
0056 $db->sql_query($convert->truncate_statement . FORUMS_TABLE);
0057
0058 // Determine the highest id used within the old forums table (we add the categories after the forum ids)
0059 $sql = 'SELECT MAX(forum_id) AS max_forum_id
0060 FROM ' . $convert->src_table_prefix . 'forums';
0061 $result = $src_db->sql_query($sql);
0062 $max_forum_id = (int) $src_db->sql_fetchfield('max_forum_id');
0063 $src_db->sql_freeresult($result);
0064
0065 $max_forum_id++;
0066
0067 // pruning disabled globally?
0068 $sql = "SELECT config_value
0069 FROM {$convert->src_table_prefix}config
0070 WHERE config_name = 'prune_enable'";
0071 $result = $src_db->sql_query($sql);
0072 $prune_enabled = (int) $src_db->sql_fetchfield('config_value');
0073 $src_db->sql_freeresult($result);
0074
0075
0076 // Insert categories
0077 $sql = 'SELECT cat_id, cat_title
0078 FROM ' . $convert->src_table_prefix . 'categories
0079 ORDER BY cat_order';
0080
0081 if ($convert->mysql_convert && $same_db)
0082 {
0083 $src_db->sql_query("SET NAMES 'binary'");
0084 }
0085
0086 $result = $src_db->sql_query($sql);
0087
0088 if ($convert->mysql_convert && $same_db)
0089 {
0090 $src_db->sql_query("SET NAMES 'utf8'");
0091 }
0092
0093 switch ($db->sql_layer)
0094 {
0095 case 'mssql':
0096 case 'mssql_odbc':
0097 $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' ON');
0098 break;
0099 }
0100
0101 $cats_added = array();
0102 while ($row = $src_db->sql_fetchrow($result))
0103 {
0104 $sql_ary = array(
0105 'forum_id' => (int) $max_forum_id,
0106 'forum_name' => ($row['cat_title']) ? htmlspecialchars(phpbb_set_default_encoding($row['cat_title']), ENT_COMPAT, 'UTF-8') : $user->lang['CATEGORY'],
0107 'parent_id' => 0,
0108 'forum_parents' => '',
0109 'forum_desc' => '',
0110 'forum_type' => FORUM_CAT,
0111 'forum_status' => ITEM_UNLOCKED,
0112 'forum_rules' => '',
0113 );
0114
0115 $sql = 'SELECT MAX(right_id) AS right_id
0116 FROM ' . FORUMS_TABLE;
0117 $_result = $db->sql_query($sql);
0118 $cat_row = $db->sql_fetchrow($_result);
0119 $db->sql_freeresult($_result);
0120
0121 $sql_ary['left_id'] = (int) ($cat_row['right_id'] + 1);
0122 $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 2);
0123
0124 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
0125 $db->sql_query($sql);
0126
0127 $cats_added[$row['cat_id']] = $max_forum_id;
0128 $max_forum_id++;
0129 }
0130 $src_db->sql_freeresult($result);
0131
0132 // There may be installations having forums with non-existant category ids.
0133 // We try to catch them and add them to an "unknown" category instead of leaving them out.
0134 $sql = 'SELECT cat_id
0135 FROM ' . $convert->src_table_prefix . 'forums
0136 GROUP BY cat_id';
0137 $result = $src_db->sql_query($sql);
0138
0139 $unknown_cat_id = false;
0140 while ($row = $src_db->sql_fetchrow($result))
0141 {
0142 // Catch those categories not been added before
0143 if (!isset($cats_added[$row['cat_id']]))
0144 {
0145 $unknown_cat_id = true;
0146 }
0147 }
0148 $src_db->sql_freeresult($result);
0149
0150 // Is there at least one category not known?
0151 if ($unknown_cat_id === true)
0152 {
0153 $unknown_cat_id = 'ghost';
0154
0155 $sql_ary = array(
0156 'forum_id' => (int) $max_forum_id,
0157 'forum_name' => (string) $user->lang['CATEGORY'],
0158 'parent_id' => 0,
0159 'forum_parents' => '',
0160 'forum_desc' => '',
0161 'forum_type' => FORUM_CAT,
0162 'forum_status' => ITEM_UNLOCKED,
0163 'forum_rules' => '',
0164 );
0165
0166 $sql = 'SELECT MAX(right_id) AS right_id
0167 FROM ' . FORUMS_TABLE;
0168 $_result = $db->sql_query($sql);
0169 $cat_row = $db->sql_fetchrow($_result);
0170 $db->sql_freeresult($_result);
0171
0172 $sql_ary['left_id'] = (int) ($cat_row['right_id'] + 1);
0173 $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 2);
0174
0175 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
0176 $db->sql_query($sql);
0177
0178 $cats_added[$unknown_cat_id] = $max_forum_id;
0179 $max_forum_id++;
0180 }
0181
0182 // Now insert the forums
0183 $sql = 'SELECT f.forum_id, f.forum_name, f.cat_id, f.forum_desc, f.forum_status, f.prune_enable, f.prune_next, fp.prune_days, fp.prune_freq FROM ' . $convert->src_table_prefix . 'forums f
0184 LEFT JOIN ' . $convert->src_table_prefix . 'forum_prune fp ON f.forum_id = fp.forum_id
0185 GROUP BY f.forum_id, f.forum_name, f.cat_id, f.forum_desc, f.forum_status, f.prune_enable, f.prune_next, f.forum_order, fp.prune_days, fp.prune_freq
0186 ORDER BY f.cat_id, f.forum_order';
0187
0188 if ($convert->mysql_convert && $same_db)
0189 {
0190 $src_db->sql_query("SET NAMES 'binary'");
0191 }
0192
0193 $result = $src_db->sql_query($sql);
0194
0195 if ($convert->mysql_convert && $same_db)
0196 {
0197 $src_db->sql_query("SET NAMES 'utf8'");
0198 }
0199
0200 while ($row = $src_db->sql_fetchrow($result))
0201 {
0202 // Some might have forums here with an id not being "possible"...
0203 // To be somewhat friendly we "change" the category id for those to a previously created ghost category
0204 if (!isset($cats_added[$row['cat_id']]) && $unknown_cat_id !== false)
0205 {
0206 $row['cat_id'] = $unknown_cat_id;
0207 }
0208
0209 if (!isset($cats_added[$row['cat_id']]))
0210 {
0211 continue;
0212 }
0213
0214 // Define the new forums sql ary
0215 $sql_ary = array(
0216 'forum_id' => (int) $row['forum_id'],
0217 'forum_name' => htmlspecialchars(phpbb_set_default_encoding($row['forum_name']), ENT_COMPAT, 'UTF-8'),
0218 'parent_id' => (int) $cats_added[$row['cat_id']],
0219 'forum_parents' => '',
0220 'forum_desc' => htmlspecialchars(phpbb_set_default_encoding($row['forum_desc']), ENT_COMPAT, 'UTF-8'),
0221 'forum_type' => FORUM_POST,
0222 'forum_status' => is_item_locked($row['forum_status']),
0223 'enable_prune' => ($prune_enabled) ? (int)$row['prune_enable'] : 0,
0224 'prune_next' => (int) null_to_zero($row['prune_next']),
0225 'prune_days' => (int) null_to_zero($row['prune_days']),
0226 'prune_viewed' => 0,
0227 'prune_freq' => (int) null_to_zero($row['prune_freq']),
0228
0229 'forum_flags' => phpbb_forum_flags(),
0230
0231 // Default values
0232 'forum_desc_bitfield' => '',
0233 'forum_desc_options' => 7,
0234 'forum_desc_uid' => '',
0235 'forum_link' => '',
0236 'forum_password' => '',
0237 'forum_style' => 0,
0238 'forum_image' => '',
0239 'forum_rules' => '',
0240 'forum_rules_link' => '',
0241 'forum_rules_bitfield' => '',
0242 'forum_rules_options' => 7,
0243 'forum_rules_uid' => '',
0244 'forum_topics_per_page' => 0,
0245 'forum_posts' => 0,
0246 'forum_topics' => 0,
0247 'forum_topics_real' => 0,
0248 'forum_last_post_id' => 0,
0249 'forum_last_poster_id' => 0,
0250 'forum_last_post_subject' => '',
0251 'forum_last_post_time' => 0,
0252 'forum_last_poster_name' => '',
0253 'forum_last_poster_colour' => '',
0254 'display_on_index' => 1,
0255 'enable_indexing' => 1,
0256 'enable_icons' => 0,
0257 );
0258
0259 // Now add the forums with proper left/right ids
0260 $sql = 'SELECT left_id, right_id
0261 FROM ' . FORUMS_TABLE . '
0262 WHERE forum_id = ' . $cats_added[$row['cat_id']];
0263 $_result = $db->sql_query($sql);
0264 $cat_row = $db->sql_fetchrow($_result);
0265 $db->sql_freeresult($_result);
0266
0267 $sql = 'UPDATE ' . FORUMS_TABLE . '
0268 SET left_id = left_id + 2, right_id = right_id + 2
0269 WHERE left_id > ' . $cat_row['right_id'];
0270 $db->sql_query($sql);
0271
0272 $sql = 'UPDATE ' . FORUMS_TABLE . '
0273 SET right_id = right_id + 2
0274 WHERE ' . $cat_row['left_id'] . ' BETWEEN left_id AND right_id';
0275 $db->sql_query($sql);
0276
0277 $sql_ary['left_id'] = (int) $cat_row['right_id'];
0278 $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 1);
0279
0280 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
0281 $db->sql_query($sql);
0282 }
0283 $src_db->sql_freeresult($result);
0284
0285 switch ($db->sql_layer)
0286 {
0287 case 'postgres':
0288 $db->sql_query("SELECT SETVAL('" . FORUMS_TABLE . "_seq',(select case when max(forum_id)>0 then max(forum_id)+1 else 1 end from " . FORUMS_TABLE . '));');
0289 break;
0290
0291 case 'mssql':
0292 case 'mssql_odbc':
0293 $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' OFF');
0294 break;
0295
0296 case 'oracle':
0297 $result = $db->sql_query('SELECT MAX(forum_id) as max_id FROM ' . FORUMS_TABLE);
0298 $row = $db->sql_fetchrow($result);
0299 $db->sql_freeresult($result);
0300
0301 $largest_id = (int) $row['max_id'];
0302
0303 if ($largest_id)
0304 {
0305 $db->sql_query('DROP SEQUENCE ' . FORUMS_TABLE . '_seq');
0306 $db->sql_query('CREATE SEQUENCE ' . FORUMS_TABLE . '_seq START WITH ' . ($largest_id + 1));
0307 }
0308 break;
0309 }
0310 }
0311
0312 /**
0313 * Function for recoding text with the default language
0314 *
0315 * @param string $text text to recode to utf8
0316 * @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
0317 */
0318 function phpbb_set_encoding($text, $grab_user_lang = true)
0319 {
0320 global $lang_enc_array, $convert_row;
0321 global $convert, $phpEx;
0322
0323 /*static $lang_enc_array = array(
0324 'korean' => 'euc-kr',
0325 'serbian' => 'windows-1250',
0326 'polish' => 'iso-8859-2',
0327 'kurdish' => 'windows-1254',
0328 'slovak' => 'Windows-1250',
0329 'russian' => 'windows-1251',
0330 'estonian' => 'iso-8859-4',
0331 'chinese_simplified' => 'gb2312',
0332 'macedonian' => 'windows-1251',
0333 'azerbaijani' => 'UTF-8',
0334 'romanian' => 'iso-8859-2',
0335 'romanian_diacritice' => 'iso-8859-2',
0336 'lithuanian' => 'windows-1257',
0337 'turkish' => 'iso-8859-9',
0338 'ukrainian' => 'windows-1251',
0339 'japanese' => 'shift_jis',
0340 'hungarian' => 'ISO-8859-2',
0341 'romanian_no_diacritics' => 'iso-8859-2',
0342 'mongolian' => 'UTF-8',
0343 'slovenian' => 'windows-1250',
0344 'bosnian' => 'windows-1250',
0345 'czech' => 'Windows-1250',
0346 'farsi' => 'Windows-1256',
0347 'croatian' => 'windows-1250',
0348 'greek' => 'iso-8859-7',
0349 'russian_tu' => 'windows-1251',
0350 'sakha' => 'UTF-8',
0351 'serbian_cyrillic' => 'windows-1251',
0352 'bulgarian' => 'windows-1251',
0353 'chinese_traditional_taiwan' => 'big5',
0354 'chinese_traditional' => 'big5',
0355 'arabic' => 'windows-1256',
0356 'hebrew' => 'WINDOWS-1255',
0357 'thai' => 'windows-874',
0358 //'chinese_traditional_taiwan' => 'utf-8' // custom modified, we may have to do an include :-(
0359 );*/
0360
0361 if (empty($lang_enc_array))
0362 {
0363 $lang_enc_array = array();
0364 }
0365
0366 $get_lang = trim(get_config_value('default_lang'));
0367
0368 // Do we need the users language encoding?
0369 if ($grab_user_lang && !empty($convert_row))
0370 {
0371 if (!empty($convert_row['user_lang']))
0372 {
0373 $get_lang = trim($convert_row['user_lang']);
0374 }
0375 else if (!empty($convert_row['poster_id']))
0376 {
0377 global $src_db, $same_db;
0378
0379 if ($convert->mysql_convert && $same_db)
0380 {
0381 $src_db->sql_query("SET NAMES 'binary'");
0382 }
0383
0384 $sql = 'SELECT user_lang
0385 FROM ' . $convert->src_table_prefix . 'users
0386 WHERE user_id = ' . (int) $convert_row['poster_id'];
0387 $result = $src_db->sql_query($sql);
0388 $get_lang = (string) $src_db->sql_fetchfield('user_lang');
0389 $src_db->sql_freeresult($result);
0390
0391 if ($convert->mysql_convert && $same_db)
0392 {
0393 $src_db->sql_query("SET NAMES 'utf8'");
0394 }
0395
0396 $get_lang = (!trim($get_lang)) ? trim(get_config_value('default_lang')) : trim($get_lang);
0397 }
0398 }
0399
0400 if (!isset($lang_enc_array[$get_lang]))
0401 {
0402 $filename = $convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx;
0403
0404 if (!file_exists($filename))
0405 {
0406 $get_lang = trim(get_config_value('default_lang'));
0407 }
0408
0409 if (!isset($lang_enc_array[$get_lang]))
0410 {
0411 include($convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx);
0412 $lang_enc_array[$get_lang] = $lang['ENCODING'];
0413 unset($lang);
0414 }
0415 }
0416
0417 $encoding = $lang_enc_array[$get_lang];
0418
0419 return utf8_recode($text, $lang_enc_array[$get_lang]);
0420 }
0421
0422 /**
0423 * Same as phpbb_set_encoding, but forcing boards default language
0424 */
0425 function phpbb_set_default_encoding($text)
0426 {
0427 return phpbb_set_encoding($text, false);
0428 }
0429
0430 /**
0431 * Convert Birthday from Birthday MOD to phpBB Format
0432 */
0433 function phpbb_get_birthday($birthday = '')
0434 {
0435 if (defined('MOD_BIRTHDAY_TERRA'))
0436 {
0437 $birthday = (string) $birthday;
0438
0439 // stored as month, day, year
0440 if (!$birthday)
0441 {
0442 return ' 0- 0- 0';
0443 }
0444
0445 // We use the original mod code to retrieve the birthday (not ideal)
0446 preg_match('/(..)(..)(....)/', sprintf('%08d', $birthday), $birthday_parts);
0447
0448 $month = $birthday_parts[1];
0449 $day = $birthday_parts[2];
0450 $year = $birthday_parts[3];
0451
0452 return sprintf('%2d-%2d-%4d', $day, $month, $year);
0453 }
0454 else
0455 {
0456 $birthday = (int) $birthday;
0457
0458 if (!$birthday || $birthday == 999999 || $birthday < 0)
0459 {
0460 return ' 0- 0- 0';
0461 }
0462
0463 // The birthday mod from niels is using this code to transform to day/month/year
0464 return gmdate('d-m-Y', $birthday * 86400 + 1);
0465 }
0466 }
0467
0468 /**
0469 * Return correct user id value
0470 * Everyone's id will be one higher to allow the guest/anonymous user to have a positive id as well
0471 */
0472 function phpbb_user_id($user_id)
0473 {
0474 global $config;
0475
0476 // Increment user id if the old forum is having a user with the id 1
0477 if (!isset($config['increment_user_id']))
0478 {
0479 global $src_db, $same_db, $convert;
0480
0481 if ($convert->mysql_convert && $same_db)
0482 {
0483 $src_db->sql_query("SET NAMES 'binary'");
0484 }
0485
0486 // Now let us set a temporary config variable for user id incrementing
0487 $sql = "SELECT user_id
0488 FROM {$convert->src_table_prefix}users
0489 WHERE user_id = 1";
0490 $result = $src_db->sql_query($sql);
0491 $id = (int) $src_db->sql_fetchfield('user_id');
0492 $src_db->sql_freeresult($result);
0493
0494 // Try to get the maximum user id possible...
0495 $sql = "SELECT MAX(user_id) AS max_user_id
0496 FROM {$convert->src_table_prefix}users";
0497 $result = $src_db->sql_query($sql);
0498 $max_id = (int) $src_db->sql_fetchfield('max_user_id');
0499 $src_db->sql_freeresult($result);
0500
0501 if ($convert->mysql_convert && $same_db)
0502 {
0503 $src_db->sql_query("SET NAMES 'utf8'");
0504 }
0505
0506 // If there is a user id 1, we need to increment user ids. :/
0507 if ($id === 1)
0508 {
0509 set_config('increment_user_id', ($max_id + 1), true);
0510 $config['increment_user_id'] = $max_id + 1;
0511 }
0512 else
0513 {
0514 set_config('increment_user_id', 0, true);
0515 $config['increment_user_id'] = 0;
0516 }
0517 }
0518
0519 // If the old user id is -1 in 2.0.x it is the anonymous user...
0520 if ($user_id == -1)
0521 {
0522 return ANONYMOUS;
0523 }
0524
0525 if (!empty($config['increment_user_id']) && $user_id == 1)
0526 {
0527 return $config['increment_user_id'];
0528 }
0529
0530 // A user id of 0 can happen, for example within the ban table if no user is banned...
0531 // Within the posts and topics table this can be "dangerous" but is the fault of the user
0532 // having mods installed (a poster id of 0 is not possible in 2.0.x).
0533 // Therefore, we return the user id "as is".
0534
0535 return (int) $user_id;
0536 }
0537
0538 /* Copy additional table fields from old forum to new forum if user wants this (for Mod compatibility for example)
0539 function phpbb_copy_table_fields()
0540 {
0541 }
0542 */
0543
0544 /**
0545 * Convert authentication
0546 * user, group and forum table has to be filled in order to work
0547 */
0548 function phpbb_convert_authentication($mode)
0549 {
0550 global $db, $src_db, $same_db, $convert, $user, $config, $cache;
0551
0552 if ($mode == 'start')
0553 {
0554 $db->sql_query($convert->truncate_statement . ACL_USERS_TABLE);
0555 $db->sql_query($convert->truncate_statement . ACL_GROUPS_TABLE);
0556
0557 // What we will do is handling all 2.0.x admins as founder to replicate what is common in 2.0.x.
0558 // After conversion the main admin need to make sure he is removing permissions and the founder status if wanted.
0559
0560
0561 // Grab user ids of users with user_level of ADMIN
0562 $sql = "SELECT user_id
0563 FROM {$convert->src_table_prefix}users
0564 WHERE user_level = 1
0565 ORDER BY user_regdate ASC";
0566 $result = $src_db->sql_query($sql);
0567
0568 while ($row = $src_db->sql_fetchrow($result))
0569 {
0570 $user_id = (int) phpbb_user_id($row['user_id']);
0571 // Set founder admin...
0572 $sql = 'UPDATE ' . USERS_TABLE . '
0573 SET user_type = ' . USER_FOUNDER . "
0574 WHERE user_id = $user_id";
0575 $db->sql_query($sql);
0576 }
0577 $src_db->sql_freeresult($result);
0578
0579 $sql = 'SELECT group_id
0580 FROM ' . GROUPS_TABLE . "
0581 WHERE group_name = '" . $db->sql_escape('BOTS') . "'";
0582 $result = $db->sql_query($sql);
0583 $bot_group_id = (int) $db->sql_fetchfield('group_id');
0584 $db->sql_freeresult($result);
0585 }
0586
0587 // Grab forum auth information
0588 $sql = "SELECT *
0589 FROM {$convert->src_table_prefix}forums";
0590 $result = $src_db->sql_query($sql);
0591
0592 $forum_access = array();
0593 while ($row = $src_db->sql_fetchrow($result))
0594 {
0595 $forum_access[$row['forum_id']] = $row;
0596 }
0597 $src_db->sql_freeresult($result);
0598
0599 if ($convert->mysql_convert && $same_db)
0600 {
0601 $src_db->sql_query("SET NAMES 'binary'");
0602 }
0603 // Grab user auth information from 2.0.x board
0604 $sql = "SELECT ug.user_id, aa.*
0605 FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}user_group ug, {$convert->src_table_prefix}groups g, {$convert->src_table_prefix}forums f
0606 WHERE g.group_id = aa.group_id
0607 AND g.group_single_user = 1
0608 AND ug.group_id = g.group_id
0609 AND f.forum_id = aa.forum_id";
0610 $result = $src_db->sql_query($sql);
0611
0612 $user_access = array();
0613 while ($row = $src_db->sql_fetchrow($result))
0614 {
0615 $user_access[$row['forum_id']][] = $row;
0616 }
0617 $src_db->sql_freeresult($result);
0618
0619 // Grab group auth information
0620 $sql = "SELECT g.group_id, aa.*
0621 FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}groups g
0622 WHERE g.group_id = aa.group_id
0623 AND g.group_single_user <> 1";
0624 $result = $src_db->sql_query($sql);
0625
0626 $group_access = array();
0627 while ($row = $src_db->sql_fetchrow($result))
0628 {
0629 $group_access[$row['forum_id']][] = $row;
0630 }
0631 $src_db->sql_freeresult($result);
0632
0633 if ($convert->mysql_convert && $same_db)
0634 {
0635 $src_db->sql_query("SET NAMES 'utf8'");
0636 }
0637
0638 // Add Forum Access List
0639 $auth_map = array(
0640 'auth_view' => array('f_', 'f_list'),
0641 'auth_read' => array('f_read', 'f_search'),
0642 'auth_post' => array('f_post', 'f_bbcode', 'f_smilies', 'f_img', 'f_sigs', 'f_postcount', 'f_report', 'f_subscribe', 'f_print', 'f_email'),
0643 'auth_reply' => 'f_reply',
0644 'auth_edit' => 'f_edit',
0645 'auth_delete' => 'f_delete',
0646 'auth_pollcreate' => 'f_poll',
0647 'auth_vote' => 'f_vote',
0648 'auth_announce' => 'f_announce',
0649 'auth_sticky' => 'f_sticky',
0650 'auth_attachments' => array('f_attach', 'f_download'),
0651 'auth_download' => 'f_download',
0652 );
0653
0654 // Define the ACL constants used in 2.0 to make the code slightly more readable
0655 define('AUTH_ALL', 0);
0656 define('AUTH_REG', 1);
0657 define('AUTH_ACL', 2);
0658 define('AUTH_MOD', 3);
0659 define('AUTH_ADMIN', 5);
0660
0661 // A mapping of the simple permissions used by 2.0
0662 $simple_auth_ary = array(
0663 'public' => array(
0664 'auth_view' => AUTH_ALL,
0665 'auth_read' => AUTH_ALL,
0666 'auth_post' => AUTH_ALL,
0667 'auth_reply' => AUTH_ALL,
0668 'auth_edit' => AUTH_REG,
0669 'auth_delete' => AUTH_REG,
0670 'auth_sticky' => AUTH_MOD,
0671 'auth_announce' => AUTH_MOD,
0672 'auth_vote' => AUTH_REG,
0673 'auth_pollcreate' => AUTH_REG,
0674 ),
0675 'registered' => array(
0676 'auth_view' => AUTH_ALL,
0677 'auth_read' => AUTH_ALL,
0678 'auth_post' => AUTH_REG,
0679 'auth_reply' => AUTH_REG,
0680 'auth_edit' => AUTH_REG,
0681 'auth_delete' => AUTH_REG,
0682 'auth_sticky' => AUTH_MOD,
0683 'auth_announce' => AUTH_MOD,
0684 'auth_vote' => AUTH_REG,
0685 'auth_pollcreate' => AUTH_REG,
0686 ),
0687 'registered_hidden' => array(
0688 'auth_view' => AUTH_REG,
0689 'auth_read' => AUTH_REG,
0690 'auth_post' => AUTH_REG,
0691 'auth_reply' => AUTH_REG,
0692 'auth_edit' => AUTH_REG,
0693 'auth_delete' => AUTH_REG,
0694 'auth_sticky' => AUTH_MOD,
0695 'auth_announce' => AUTH_MOD,
0696 'auth_vote' => AUTH_REG,
0697 'auth_pollcreate' => AUTH_REG,
0698 ),
0699 'private' => array(
0700 'auth_view' => AUTH_ALL,
0701 'auth_read' => AUTH_ACL,
0702 'auth_post' => AUTH_ACL,
0703 'auth_reply' => AUTH_ACL,
0704 'auth_edit' => AUTH_ACL,
0705 'auth_delete' => AUTH_ACL,
0706 'auth_sticky' => AUTH_ACL,
0707 'auth_announce' => AUTH_MOD,
0708 'auth_vote' => AUTH_ACL,
0709 'auth_pollcreate' => AUTH_ACL,
0710 ),
0711 'private_hidden' => array(
0712 'auth_view' => AUTH_ACL,
0713 'auth_read' => AUTH_ACL,
0714 'auth_post' => AUTH_ACL,
0715 'auth_reply' => AUTH_ACL,
0716 'auth_edit' => AUTH_ACL,
0717 'auth_delete' => AUTH_ACL,
0718 'auth_sticky' => AUTH_ACL,
0719 'auth_announce' => AUTH_MOD,
0720 'auth_vote' => AUTH_ACL,
0721 'auth_pollcreate' => AUTH_ACL,
0722 ),
0723 'moderator' => array(
0724 'auth_view' => AUTH_ALL,
0725 'auth_read' => AUTH_MOD,
0726 'auth_post' => AUTH_MOD,
0727 'auth_reply' => AUTH_MOD,
0728 'auth_edit' => AUTH_MOD,
0729 'auth_delete' => AUTH_MOD,
0730 'auth_sticky' => AUTH_MOD,
0731 'auth_announce' => AUTH_MOD,
0732 'auth_vote' => AUTH_MOD,
0733 'auth_pollcreate' => AUTH_MOD,
0734 ),
0735 'moderator_hidden' => array(
0736 'auth_view' => AUTH_MOD,
0737 'auth_read' => AUTH_MOD,
0738 'auth_post' => AUTH_MOD,
0739 'auth_reply' => AUTH_MOD,
0740 'auth_edit' => AUTH_MOD,
0741 'auth_delete' => AUTH_MOD,
0742 'auth_sticky' => AUTH_MOD,
0743 'auth_announce' => AUTH_MOD,
0744 'auth_vote' => AUTH_MOD,
0745 'auth_pollcreate' => AUTH_MOD,
0746 ),
0747 );
0748
0749 if ($mode == 'start')
0750 {
0751 user_group_auth('guests', 'SELECT user_id, {GUESTS} FROM ' . USERS_TABLE . ' WHERE user_id = ' . ANONYMOUS, false);
0752 user_group_auth('registered', 'SELECT user_id, {REGISTERED} FROM ' . USERS_TABLE . ' WHERE user_id <> ' . ANONYMOUS . " AND group_id <> $bot_group_id", false);
0753
0754 // Selecting from old table
0755 if (!empty($config['increment_user_id']))
0756 {
0757 $auth_sql = 'SELECT user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id <> 1';
0758 user_group_auth('administrators', $auth_sql, true);
0759
0760 $auth_sql = 'SELECT ' . $config['increment_user_id'] . ' as user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id = 1';
0761 user_group_auth('administrators', $auth_sql, true);
0762 }
0763 else
0764 {
0765 $auth_sql = 'SELECT user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1';
0766 user_group_auth('administrators', $auth_sql, true);
0767 }
0768
0769 if (!empty($config['increment_user_id']))
0770 {
0771 $auth_sql = 'SELECT user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id <> 1';
0772 user_group_auth('global_moderators', $auth_sql, true);
0773
0774 $auth_sql = 'SELECT ' . $config['increment_user_id'] . ' as user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id = 1';
0775 user_group_auth('global_moderators', $auth_sql, true);
0776 }
0777 else
0778 {
0779 $auth_sql = 'SELECT user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1';
0780 user_group_auth('global_moderators', $auth_sql, true);
0781 }
0782 }
0783 else if ($mode == 'first')
0784 {
0785 // Go through all 2.0.x forums
0786 foreach ($forum_access as $forum)
0787 {
0788 $new_forum_id = (int) $forum['forum_id'];
0789
0790 // Administrators have full access to all forums whatever happens
0791 mass_auth('group_role', $new_forum_id, 'administrators', 'FORUM_FULL');
0792
0793 $matched_type = '';
0794 foreach ($simple_auth_ary as $key => $auth_levels)
0795 {
0796 $matched = 1;
0797 foreach ($auth_levels as $k => $level)
0798 {
0799 if ($forum[$k] != $auth_levels[$k])
0800 {
0801 $matched = 0;
0802 }
0803 }
0804
0805 if ($matched)
0806 {
0807 $matched_type = $key;
0808 break;
0809 }
0810 }
0811
0812 switch ($matched_type)
0813 {
0814 case 'public':
0815 mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_LIMITED');
0816 mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_LIMITED_POLLS');
0817 mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
0818 break;
0819
0820 case 'registered':
0821 mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_READONLY');
0822 mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
0823
0824 // no break;
0825
0826 case 'registered_hidden':
0827 mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_POLLS');
0828 break;
0829
0830 case 'private':
0831 case 'private_hidden':
0832 case 'moderator':
0833 case 'moderator_hidden':
0834 default:
0835 // The permissions don't match a simple set, so we're going to have to map them directly
0836
0837 // No post approval for all, in 2.0.x this feature does not exist
0838 mass_auth('group', $new_forum_id, 'guests', 'f_noapprove', ACL_YES);
0839 mass_auth('group', $new_forum_id, 'registered', 'f_noapprove', ACL_YES);
0840
0841 // Go through authentication map
0842 foreach ($auth_map as $old_auth_key => $new_acl)
0843 {
0844 // If old authentication key does not exist we continue
0845 // This is helpful for mods adding additional authentication fields, we need to add them to the auth_map array
0846 if (!isset($forum[$old_auth_key]))
0847 {
0848 continue;
0849 }
0850
0851 // Now set the new ACL correctly
0852 switch ($forum[$old_auth_key])
0853 {
0854 // AUTH_ALL
0855 case AUTH_ALL:
0856 mass_auth('group', $new_forum_id, 'guests', $new_acl, ACL_YES);
0857 mass_auth('group', $new_forum_id, 'bots', $new_acl, ACL_YES);
0858 mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
0859 break;
0860
0861 // AUTH_REG
0862 case AUTH_REG:
0863 mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
0864 break;
0865
0866 // AUTH_ACL
0867 case AUTH_ACL:
0868 // Go through the old group access list for this forum
0869 if (isset($group_access[$forum['forum_id']]))
0870 {
0871 foreach ($group_access[$forum['forum_id']] as $index => $access)
0872 {
0873 // We only check for ACL_YES equivalence entry
0874 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
0875 {
0876 mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
0877 }
0878 }
0879 }
0880
0881 if (isset($user_access[$forum['forum_id']]))
0882 {
0883 foreach ($user_access[$forum['forum_id']] as $index => $access)
0884 {
0885 // We only check for ACL_YES equivalence entry
0886 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
0887 {
0888 mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
0889 }
0890 }
0891 }
0892 break;
0893
0894 // AUTH_MOD
0895 case AUTH_MOD:
0896 if (isset($group_access[$forum['forum_id']]))
0897 {
0898 foreach ($group_access[$forum['forum_id']] as $index => $access)
0899 {
0900 // We only check for ACL_YES equivalence entry
0901 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
0902 {
0903 mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
0904 }
0905 }
0906 }
0907
0908 if (isset($user_access[$forum['forum_id']]))
0909 {
0910 foreach ($user_access[$forum['forum_id']] as $index => $access)
0911 {
0912 // We only check for ACL_YES equivalence entry
0913 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
0914 {
0915 mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
0916 }
0917 }
0918 }
0919 break;
0920 }
0921 }
0922 break;
0923 }
0924 }
0925 }
0926 else if ($mode == 'second')
0927 {
0928 // Assign permission roles and other default permissions
0929
0930 // guests having u_download and u_search ability
0931 $db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) SELECT ' . get_group_id('guests') . ', 0, auth_option_id, 0, 1 FROM ' . ACL_OPTIONS_TABLE . " WHERE auth_option IN ('u_', 'u_download', 'u_search')");
0932
0933 // administrators/global mods having full user features
0934 mass_auth('group_role', 0, 'administrators', 'USER_FULL');
0935 mass_auth('group_role', 0, 'global_moderators', 'USER_FULL');
0936
0937 // By default all converted administrators are given full access
0938 mass_auth('group_role', 0, 'administrators', 'ADMIN_FULL');
0939
0940 // All registered users are assigned the standard user role
0941 mass_auth('group_role', 0, 'registered', 'USER_STANDARD');
0942 mass_auth('group_role', 0, 'registered_coppa', 'USER_STANDARD');
0943
0944 // Instead of administrators being global moderators we give the MOD_FULL role to global mods (admins already assigned to this group)
0945 mass_auth('group_role', 0, 'global_moderators', 'MOD_FULL');
0946
0947 // And now those who have had their avatar rights removed get assigned a more restrictive role
0948 $sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
0949 WHERE user_allowavatar = 0
0950 AND user_id > 0';
0951 $result = $src_db->sql_query($sql);
0952
0953 while ($row = $src_db->sql_fetchrow($result))
0954 {
0955 mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOAVATAR');
0956 }
0957 $src_db->sql_freeresult($result);
0958
0959 // And the same for those who have had their PM rights removed
0960 $sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
0961 WHERE user_allow_pm = 0
0962 AND user_id > 0';
0963 $result = $src_db->sql_query($sql);
0964
0965 while ($row = $src_db->sql_fetchrow($result))
0966 {
0967 mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOPM');
0968 }
0969 $src_db->sql_freeresult($result);
0970 }
0971 else if ($mode == 'third')
0972 {
0973 // And now the moderators
0974 // We make sure that they have at least standard access to the forums they moderate in addition to the moderating permissions
0975
0976 $mod_post_map = array(
0977 'auth_announce' => 'f_announce',
0978 'auth_sticky' => 'f_sticky'
0979 );
0980
0981 foreach ($user_access as $forum_id => $access_map)
0982 {
0983 $forum_id = (int) $forum_id;
0984
0985 foreach ($access_map as $access)
0986 {
0987 if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
0988 {
0989 mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'MOD_STANDARD');
0990 mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'FORUM_STANDARD');
0991 foreach ($mod_post_map as $old => $new)
0992 {
0993 if (isset($forum_access[$forum_id]) && isset($forum_access[$forum_id][$old]) && $forum_access[$forum_id][$old] == AUTH_MOD)
0994 {
0995 mass_auth('user', $forum_id, (int) phpbb_user_id($access['user_id']), $new, ACL_YES);
0996 }
0997 }
0998 }
0999 }
1000 }
1001
1002 foreach ($group_access as $forum_id => $access_map)
1003 {
1004 $forum_id = (int) $forum_id;
1005
1006 foreach ($access_map as $access)
1007 {
1008 if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
1009 {
1010 mass_auth('group_role', $forum_id, (int) $access['group_id'], 'MOD_STANDARD');
1011 mass_auth('group_role', $forum_id, (int) $access['group_id'], 'FORUM_STANDARD');
1012 foreach ($mod_post_map as $old => $new)
1013 {
1014 if (isset($forum_access[$forum_id]) && isset($forum_access[$forum_id][$old]) && $forum_access[$forum_id][$old] == AUTH_MOD)
1015 {
1016 mass_auth('group', $forum_id, (int) $access['group_id'], $new, ACL_YES);
1017 }
1018 }
1019 }
1020 }
1021 }
1022
1023 // We grant everyone readonly access to the categories to ensure that the forums are visible
1024 $sql = 'SELECT forum_id, forum_name, parent_id, left_id, right_id
1025 FROM ' . FORUMS_TABLE . '
1026 ORDER BY left_id ASC';
1027 $result = $db->sql_query($sql);
1028
1029 $parent_forums = $forums = array();
1030 while ($row = $db->sql_fetchrow($result))
1031 {
1032 if ($row['parent_id'] == 0)
1033 {
1034 mass_auth('group_role', $row['forum_id'], 'administrators', 'FORUM_FULL');
1035 mass_auth('group_role', $row['forum_id'], 'global_moderators', 'FORUM_FULL');
1036 $parent_forums[] = $row;
1037 }
1038 else
1039 {
1040 $forums[] = $row;
1041 }
1042 }
1043 $db->sql_freeresult($result);
1044
1045 global $auth;
1046
1047 // Let us see which groups have access to these forums...
1048 foreach ($parent_forums as $row)
1049 {
1050 // Get the children
1051 $branch = $forum_ids = array();
1052
1053 foreach ($forums as $key => $_row)
1054 {
1055 if ($_row['left_id'] > $row['left_id'] && $_row['left_id'] < $row['right_id'])
1056 {
1057 $branch[] = $_row;
1058 $forum_ids[] = $_row['forum_id'];
1059 continue;
1060 }
1061 }
1062
1063 if (sizeof($forum_ids))
1064 {
1065 // Now make sure the user is able to read these forums
1066 $hold_ary = $auth->acl_group_raw_data(false, 'f_list', $forum_ids);
1067
1068 if (empty($hold_ary))
1069 {
1070 continue;
1071 }
1072
1073 foreach ($hold_ary as $g_id => $f_id_ary)
1074 {
1075 $set_group = false;
1076
1077 foreach ($f_id_ary as $f_id => $auth_ary)
1078 {
1079 foreach ($auth_ary as $auth_option => $setting)
1080 {
1081 if ($setting == ACL_YES)
1082 {
1083 $set_group = true;
1084 break 2;
1085 }
1086 }
1087 }
1088
1089 if ($set_group)
1090 {
1091 mass_auth('group', $row['forum_id'], $g_id, 'f_list', ACL_YES);
1092 }
1093 }
1094 }
1095 }
1096 }
1097 }
1098
1099 /**
1100 * Set primary group.
1101 * Really simple and only based on user_level (remaining groups will be assigned later)
1102 */
1103 function phpbb_set_primary_group($user_level)
1104 {
1105 global $convert_row;
1106
1107 if ($user_level == 1)
1108 {
1109 return get_group_id('administrators');
1110 }
1111 /* else if ($user_level == 2)
1112 {
1113 return get_group_id('global_moderators');
1114 }
1115 else if ($user_level == 0 && $convert_row['user_active'])*/
1116 else if ($convert_row['user_active'])
1117 {
1118 return get_group_id('registered');
1119 }
1120
1121 return 0;
1122 }
1123
1124 /**
1125 * Convert the group name, making sure to avoid conflicts with 3.0 special groups
1126 */
1127 function phpbb_convert_group_name($group_name)
1128 {
1129 $default_groups = array(
1130 'GUESTS',
1131 'REGISTERED',
1132 'REGISTERED_COPPA',
1133 'GLOBAL_MODERATORS',
1134 'ADMINISTRATORS',
1135 'BOTS',
1136 );
1137
1138 if (in_array(strtoupper($group_name), $default_groups))
1139 {
1140 return 'phpBB2 - ' . $group_name;
1141 }
1142
1143 return phpbb_set_default_encoding($group_name);
1144 }
1145
1146 /**
1147 * Convert the group type constants
1148 */
1149 function phpbb_convert_group_type($group_type)
1150 {
1151 switch ($group_type)
1152 {
1153 case 0:
1154 return GROUP_OPEN;
1155 break;
1156
1157 case 1:
1158 return GROUP_CLOSED;
1159 break;
1160
1161 case 2:
1162 return GROUP_HIDDEN;
1163 break;
1164 }
1165
1166 // Never return GROUP_SPECIAL here, because only phpBB3's default groups are allowed to have this type set.
1167 return GROUP_HIDDEN;
1168 }
1169
1170 /**
1171 * Convert the topic type constants
1172 */
1173 function phpbb_convert_topic_type($topic_type)
1174 {
1175 switch ($topic_type)
1176 {
1177 case 0:
1178 return POST_NORMAL;
1179 break;
1180
1181 case 1:
1182 return POST_STICKY;
1183 break;
1184
1185 case 2:
1186 return POST_ANNOUNCE;
1187 break;
1188
1189 case 3:
1190 return POST_GLOBAL;
1191 break;
1192 }
1193
1194 return POST_NORMAL;
1195 }
1196
1197 function phpbb_replace_size($matches)
1198 {
1199 return '[size=' . min(200, ceil(100.0 * (((double) $matches[1])/12.0))) . ':' . $matches[2] . ']';
1200 }
1201
1202 /**
1203 * Reparse the message stripping out the bbcode_uid values and adding new ones and setting the bitfield
1204 * @todo What do we want to do about HTML in messages - currently it gets converted to the entities, but there may be some objections to this
1205 */
1206 function phpbb_prepare_message($message)
1207 {
1208 global $phpbb_root_path, $phpEx, $db, $convert, $user, $config, $cache, $convert_row, $message_parser;
1209
1210 if (!$message)
1211 {
1212 $convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = 0;
1213 return '';
1214 }
1215
1216 // Decode phpBB 2.0.x Message
1217 if (isset($convert->row['old_bbcode_uid']) && $convert->row['old_bbcode_uid'] != '')
1218 {
1219 // Adjust size...
1220 if (strpos($message, '[size=') !== false)
1221 {
1222 $message = preg_replace_callback('/\[size=(\d*):(' . $convert->row['old_bbcode_uid'] . ')\]/', 'phpbb_replace_size', $message);
1223 }
1224
1225 $message = preg_replace('/\:(([a-z0-9]:)?)' . $convert->row['old_bbcode_uid'] . '/s', '', $message);
1226 }
1227
1228 if (strpos($message, '[quote=') !== false)
1229 {
1230 $message = preg_replace('/\[quote="(.*?)"\]/s', '[quote="\1"]', $message);
1231 $message = preg_replace('/\[quote=\\\"(.*?)\\\"\]/s', '[quote="\1"]', $message);
1232
1233 // let's hope that this solves more problems than it causes. Deal with escaped quotes.
1234 $message = str_replace('\"', '"', $message);
1235 $message = str_replace('\"', '"', $message);
1236 }
1237
1238 // Already the new user id ;)
1239 $user_id = $convert->row['poster_id'];
1240
1241 $message = str_replace('<', '<', $message);
1242 $message = str_replace('>', '>', $message);
1243 $message = str_replace('<br />', "\n", $message);
1244
1245 // make the post UTF-8
1246 $message = phpbb_set_encoding($message);
1247
1248 $message_parser->warn_msg = array(); // Reset the errors from the previous message
1249 $message_parser->bbcode_uid = make_uid($convert->row['post_time']);
1250 $message_parser->message = $message;
1251 unset($message);
1252
1253 // Make sure options are set.
1254 // $enable_html = (!isset($row['enable_html'])) ? false : $row['enable_html'];
1255 $enable_bbcode = (!isset($convert->row['enable_bbcode'])) ? true : $convert->row['enable_bbcode'];
1256 $enable_smilies = (!isset($convert->row['enable_smilies'])) ? true : $convert->row['enable_smilies'];
1257 $enable_magic_url = (!isset($convert->row['enable_magic_url'])) ? true : $convert->row['enable_magic_url'];
1258
1259 // parse($allow_bbcode, $allow_magic_url, $allow_smilies, $allow_img_bbcode = true, $allow_flash_bbcode = true, $allow_quote_bbcode = true, $allow_url_bbcode = true, $update_this_message = true, $mode = 'post')
1260 $message_parser->parse($enable_bbcode, $enable_magic_url, $enable_smilies);
1261
1262 if (sizeof($message_parser->warn_msg))
1263 {
1264 $msg_id = isset($convert->row['post_id']) ? $convert->row['post_id'] : $convert->row['privmsgs_id'];
1265 $convert->p_master->error('<span style="color:red">' . $user->lang['POST_ID'] . ': ' . $msg_id . ' ' . $user->lang['CONV_ERROR_MESSAGE_PARSER'] . ': <br /><br />' . implode('<br />', $message_parser->warn_msg), __LINE__, __FILE__, true);
1266 }
1267
1268 $convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = $message_parser->bbcode_bitfield;
1269
1270 $message = $message_parser->message;
1271 unset($message_parser->message);
1272
1273 return $message;
1274 }
1275
1276 /**
1277 * Return the bitfield calculated by the previous function
1278 */
1279 function get_bbcode_bitfield()
1280 {
1281 global $convert_row;
1282
1283 return $convert_row['mp_bbcode_bitfield'];
1284 }
1285
1286 /**
1287 * Determine the last user to edit a post
1288 * In practice we only tracked edits by the original poster in 2.0.x so this will only be set if they had edited their own post
1289 */
1290 function phpbb_post_edit_user()
1291 {
1292 global $convert_row, $config;
1293
1294 if (isset($convert_row['post_edit_count']))
1295 {
1296 return phpbb_user_id($convert_row['poster_id']);
1297 }
1298
1299 return 0;
1300 }
1301
1302 /**
1303 * Obtain the path to uploaded files on the 2.0.x forum
1304 * This is only used if the Attachment MOD was installed
1305 */
1306 function phpbb_get_files_dir()
1307 {
1308 if (!defined('MOD_ATTACHMENT'))
1309 {
1310 return;
1311 }
1312
1313 global $src_db, $same_db, $convert, $user, $config, $cache;
1314
1315 if ($convert->mysql_convert && $same_db)
1316 {
1317 $src_db->sql_query("SET NAMES 'binary'");
1318 }
1319 $sql = 'SELECT config_value AS upload_dir
1320 FROM ' . $convert->src_table_prefix . "attachments_config
1321 WHERE config_name = 'upload_dir'";
1322 $result = $src_db->sql_query($sql);
1323 $upload_path = $src_db->sql_fetchfield('upload_dir');
1324 $src_db->sql_freeresult($result);
1325
1326 $sql = 'SELECT config_value AS ftp_upload
1327 FROM ' . $convert->src_table_prefix . "attachments_config
1328 WHERE config_name = 'allow_ftp_upload'";
1329 $result = $src_db->sql_query($sql);
1330 $ftp_upload = (int) $src_db->sql_fetchfield('ftp_upload');
1331 $src_db->sql_freeresult($result);
1332
1333 if ($convert->mysql_convert && $same_db)
1334 {
1335 $src_db->sql_query("SET NAMES 'utf8'");
1336 }
1337
1338 if ($ftp_upload)
1339 {
1340 $convert->p_master->error($user->lang['CONV_ERROR_ATTACH_FTP_DIR'], __LINE__, __FILE__);
1341 }
1342
1343 return $upload_path;
1344 }
1345
1346 /**
1347 * Copy thumbnails of uploaded images from the 2.0.x forum
1348 * This is only used if the Attachment MOD was installed
1349 */
1350 function phpbb_copy_thumbnails()
1351 {
1352 global $db, $convert, $user, $config, $cache, $phpbb_root_path;
1353
1354 $src_path = $convert->options['forum_path'] . '/' . phpbb_get_files_dir() . '/thumbs/';
1355
1356 if ($handle = @opendir($src_path))
1357 {
1358 while ($entry = readdir($handle))
1359 {
1360 if ($entry[0] == '.')
1361 {
1362 continue;
1363 }
1364
1365 if (is_dir($src_path . $entry))
1366 {
1367 continue;
1368 }
1369 else
1370 {
1371 copy_file($src_path . $entry, $config['upload_path'] . '/' . preg_replace('/^t_/', 'thumb_', $entry));
1372 @unlink($phpbb_root_path . $config['upload_path'] . '/thumbs/' . $entry);
1373 }
1374 }
1375 closedir($handle);
1376 }
1377 }
1378
1379 /**
1380 * Convert the attachment category constants
1381 * This is only used if the Attachment MOD was installed
1382 */
1383 function phpbb_attachment_category($cat_id)
1384 {
1385 switch ($cat_id)
1386 {
1387 case 1:
1388 return ATTACHMENT_CATEGORY_IMAGE;
1389 break;
1390
1391 case 2:
1392 return ATTACHMENT_CATEGORY_WM;
1393 break;
1394
1395 case 3:
1396 return ATTACHMENT_CATEGORY_FLASH;
1397 break;
1398 }
1399
1400 return ATTACHMENT_CATEGORY_NONE;
1401 }
1402
1403 /**
1404 * Obtain list of forums in which different attachment categories can be used
1405 */
1406 function phpbb_attachment_forum_perms($forum_permissions)
1407 {
1408 if (empty($forum_permissions))
1409 {
1410 return '';
1411 }
1412
1413 // Decode forum permissions
1414 $forum_ids = array();
1415
1416 $one_char_encoding = '#';
1417 $two_char_encoding = '.';
1418
1419 $auth_len = 1;
1420 for ($pos = 0; $pos < strlen($forum_permissions); $pos += $auth_len)
1421 {
1422 $forum_auth = substr($forum_permissions, $pos, 1);
1423 if ($forum_auth == $one_char_encoding)
1424 {
1425 $auth_len = 1;
1426 continue;
1427 }
1428 else if ($forum_auth == $two_char_encoding)
1429 {
1430 $auth_len = 2;
1431 $pos--;
1432 continue;
1433 }
1434
1435 $forum_auth = substr($forum_permissions, $pos, $auth_len);
1436 $forum_id = base64_unpack($forum_auth);
1437
1438 $forum_ids[] = (int) $forum_id;
1439 }
1440
1441 if (sizeof($forum_ids))
1442 {
1443 return attachment_forum_perms($forum_ids);
1444 }
1445
1446 return '';
1447 }
1448
1449 /**
1450 * Convert the avatar type constants
1451 */
1452 function phpbb_avatar_type($type)
1453 {
1454 switch ($type)
1455 {
1456 case 1:
1457 return AVATAR_UPLOAD;
1458 break;
1459
1460 case 2:
1461 return AVATAR_REMOTE;
1462 break;
1463
1464 case 3:
1465 return AVATAR_GALLERY;
1466 break;
1467 }
1468
1469 return 0;
1470 }
1471
1472
1473 /**
1474 * Just undos the replacing of '<' and '>'
1475 */
1476 function phpbb_smilie_html_decode($code)
1477 {
1478 $code = str_replace('<', '<', $code);
1479 return str_replace('>', '>', $code);
1480 }
1481
1482 /**
1483 * Transfer avatars, copying the image if it was uploaded
1484 */
1485 function phpbb_import_avatar($user_avatar)
1486 {
1487 global $convert_row;
1488
1489 if (!$convert_row['user_avatar_type'])
1490 {
1491 return '';
1492 }
1493 else if ($convert_row['user_avatar_type'] == 1)
1494 {
1495 // Uploaded avatar
1496 return import_avatar($user_avatar, false, $convert_row['user_id']);
1497 }
1498 else if ($convert_row['user_avatar_type'] == 2)
1499 {
1500 // Remote avatar
1501 return $user_avatar;
1502 }
1503 else if ($convert_row['user_avatar_type'] == 3)
1504 {
1505 // Gallery avatar
1506 return $user_avatar;
1507 }
1508
1509 return '';
1510 }
1511
1512
1513 /**
1514 * Find out about the avatar's dimensions
1515 */
1516 function phpbb_get_avatar_height($user_avatar)
1517 {
1518 global $convert_row;
1519
1520 if (empty($convert_row['user_avatar_type']))
1521 {
1522 return 0;
1523 }
1524 return get_avatar_height($user_avatar, 'phpbb_avatar_type', $convert_row['user_avatar_type']);
1525 }
1526
1527
1528 /**
1529 * Find out about the avatar's dimensions
1530 */
1531 function phpbb_get_avatar_width($user_avatar)
1532 {
1533 global $convert_row;
1534
1535 if (empty($convert_row['user_avatar_type']))
1536 {
1537 return 0;
1538 }
1539
1540 return get_avatar_width($user_avatar, 'phpbb_avatar_type', $convert_row['user_avatar_type']);
1541 }
1542
1543
1544 /**
1545 * Calculate the correct to_address field for private messages
1546 */
1547 function phpbb_privmsgs_to_userid($to_userid)
1548 {
1549 global $config;
1550
1551 return 'u_' . phpbb_user_id($to_userid);
1552 }
1553
1554 /**
1555 * Calculate whether a private message was unread using the bitfield
1556 */
1557 function phpbb_unread_pm($pm_type)
1558 {
1559 return ($pm_type == 5) ? 1 : 0;
1560 }
1561
1562 /**
1563 * Calculate whether a private message was new using the bitfield
1564 */
1565 function phpbb_new_pm($pm_type)
1566 {
1567 return ($pm_type == 1) ? 1 : 0;
1568 }
1569
1570 /**
1571 * Obtain the folder_id for the custom folder created to replace the savebox from 2.0.x (used to store saved private messages)
1572 */
1573 function phpbb_get_savebox_id($user_id)
1574 {
1575 global $db;
1576
1577 $user_id = phpbb_user_id($user_id);
1578
1579 // Only one custom folder, check only one
1580 $sql = 'SELECT folder_id
1581 FROM ' . PRIVMSGS_FOLDER_TABLE . '
1582 WHERE user_id = ' . $user_id;
1583 $result = $db->sql_query_limit($sql, 1);
1584 $folder_id = (int) $db->sql_fetchfield('folder_id');
1585 $db->sql_freeresult($result);
1586
1587 return $folder_id;
1588 }
1589
1590 /**
1591 * Transfer attachment specific configuration options
1592 * These were not stored in the main config table on 2.0.x
1593 * This is only used if the Attachment MOD was installed
1594 */
1595 function phpbb_import_attach_config()
1596 {
1597 global $db, $src_db, $same_db, $convert, $config;
1598
1599 if ($convert->mysql_convert && $same_db)
1600 {
1601 $src_db->sql_query("SET NAMES 'binary'");
1602 }
1603
1604 $sql = 'SELECT *
1605 FROM ' . $convert->src_table_prefix . 'attachments_config';
1606 $result = $src_db->sql_query($sql);
1607
1608 if ($convert->mysql_convert && $same_db)
1609 {
1610 $src_db->sql_query("SET NAMES 'utf8'");
1611 }
1612
1613 $attach_config = array();
1614 while ($row = $src_db->sql_fetchrow($result))
1615 {
1616 $attach_config[$row['config_name']] = $row['config_value'];
1617 }
1618 $src_db->sql_freeresult($result);
1619
1620 set_config('allow_attachments', 1);
1621
1622 // old attachment mod? Must be very old if this entry do not exist...
1623 if (!empty($attach_config['display_order']))
1624 {
1625 set_config('display_order', $attach_config['display_order']);
1626 }
1627 set_config('max_filesize', $attach_config['max_filesize']);
1628 set_config('max_filesize_pm', $attach_config['max_filesize_pm']);
1629 set_config('attachment_quota', $attach_config['attachment_quota']);
1630 set_config('max_attachments', $attach_config['max_attachments']);
1631 set_config('max_attachments_pm', $attach_config['max_attachments_pm']);
1632 set_config('allow_pm_attach', $attach_config['allow_pm_attach']);
1633
1634 set_config('img_display_inlined', $attach_config['img_display_inlined']);
1635 set_config('img_max_width', $attach_config['img_max_width']);
1636 set_config('img_max_height', $attach_config['img_max_height']);
1637 set_config('img_link_width', $attach_config['img_link_width']);
1638 set_config('img_link_height', $attach_config['img_link_height']);
1639 set_config('img_create_thumbnail', $attach_config['img_create_thumbnail']);
1640 set_config('img_max_thumb_width', 400);
1641 set_config('img_min_thumb_filesize', $attach_config['img_min_thumb_filesize']);
1642 set_config('img_imagick', $attach_config['img_imagick']);
1643 }
1644
1645 /**
1646 * Calculate the date a user became inactive
1647 */
1648 function phpbb_inactive_time()
1649 {
1650 global $convert_row;
1651
1652 if ($convert_row['user_active'])
1653 {
1654 return 0;
1655 }
1656
1657 if ($convert_row['user_lastvisit'])
1658 {
1659 return $convert_row['user_lastvisit'];
1660 }
1661
1662 return $convert_row['user_regdate'];
1663 }
1664
1665 /**
1666 * Calculate the reason a user became inactive
1667 * We can't actually tell the difference between a manual deactivation and one for profile changes
1668 * from the data available to assume the latter
1669 */
1670 function phpbb_inactive_reason()
1671 {
1672 global $convert_row;
1673
1674 if ($convert_row['user_active'])
1675 {
1676 return 0;
1677 }
1678
1679 if ($convert_row['user_lastvisit'])
1680 {
1681 return INACTIVE_PROFILE;
1682 }
1683
1684 return INACTIVE_REGISTER;
1685 }
1686
1687 /**
1688 * Adjust 2.0.x disallowed names to 3.0.x format
1689 */
1690 function phpbb_disallowed_username($username)
1691 {
1692 // Replace * with %
1693 $username = phpbb_set_default_encoding(str_replace('*', '%', $username));
1694 return utf8_htmlspecialchars($username);
1695 }
1696
1697 /**
1698 * Checks whether there are any usernames on the old board that would map to the same
1699 * username_clean on phpBB3. Prints out a list if any exist and exits.
1700 */
1701 function phpbb_check_username_collisions()
1702 {
1703 global $db, $src_db, $convert, $table_prefix, $user, $lang;
1704
1705 $map_dbms = '';
1706 switch ($db->sql_layer)
1707 {
1708 case 'mysql':
1709 $map_dbms = 'mysql_40';
1710 break;
1711
1712 case 'mysql4':
1713 if (version_compare($db->mysql_version, '4.1.3', '>='))
1714 {
1715 $map_dbms = 'mysql_41';
1716 }
1717 else
1718 {
1719 $map_dbms = 'mysql_40';
1720 }
1721 break;
1722
1723 case 'mysqli':
1724 $map_dbms = 'mysql_41';
1725 break;
1726
1727 case 'mssql':
1728 case 'mssql_odbc':
1729 $map_dbms = 'mssql';
1730 break;
1731
1732 default:
1733 $map_dbms = $db->sql_layer;
1734 break;
1735 }
1736
1737 // create a temporary table in which we store the clean usernames
1738 $drop_sql = 'DROP TABLE ' . $table_prefix . 'userconv';
1739 switch ($map_dbms)
1740 {
1741 case 'firebird':
1742 $create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
1743 user_id INTEGER NOT NULL,
1744 username_clean VARCHAR(255) CHARACTER SET UTF8 DEFAULT \'\' NOT NULL COLLATE UNICODE
1745 )';
1746 break;
1747
1748 case 'mssql':
1749 $create_sql = 'CREATE TABLE [' . $table_prefix . 'userconv] (
1750 [user_id] [int] NOT NULL ,
1751 [username_clean] [varchar] (255) DEFAULT (\'\') NOT NULL
1752 )';
1753 break;
1754
1755 case 'mysql_40':
1756 $create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
1757 user_id mediumint(8) NOT NULL,
1758 username_clean blob NOT NULL
1759 )';
1760 break;
1761
1762 case 'mysql_41':
1763 $create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
1764 user_id mediumint(8) NOT NULL,
1765 username_clean varchar(255) DEFAULT \'\' NOT NULL
1766 ) CHARACTER SET `utf8` COLLATE `utf8_bin`';
1767 break;
1768
1769 case 'oracle':
1770 $create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
1771 user_id number(8) NOT NULL,
1772 username_clean varchar2(255) DEFAULT \'\'
1773 )';
1774 break;
1775
1776 case 'postgres':
1777 $create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
1778 user_id INT4 DEFAULT \'0\',
1779 username_clean varchar_ci DEFAULT \'\' NOT NULL
1780 )';
1781 break;
1782
1783 case 'sqlite':
1784 $create_sql = 'CREATE TABLE ' . $table_prefix . 'userconv (
1785 user_id INTEGER NOT NULL DEFAULT \'0\',
1786 username_clean varchar(255) NOT NULL DEFAULT \'\'
1787 )';
1788 break;
1789 }
1790
1791 $db->sql_return_on_error(true);
1792 $db->sql_query($drop_sql);
1793 $db->sql_return_on_error(false);
1794 $db->sql_query($create_sql);
1795
1796 // now select all user_ids and usernames and then convert the username (this can take quite a while!)
1797 $sql = 'SELECT user_id, username
1798 FROM ' . $convert->src_table_prefix . 'users';
1799 $result = $src_db->sql_query($sql);
1800
1801 $insert_ary = array();
1802 $i = 0;
1803 while ($row = $src_db->sql_fetchrow($result))
1804 {
1805 $clean_name = utf8_clean_string(phpbb_set_default_encoding($row['username']));
1806 $insert_ary[] = array('user_id' => (int) $row['user_id'], 'username_clean' => (string) $clean_name);
1807
1808 if ($i % 1000 == 999)
1809 {
1810 $db->sql_multi_insert($table_prefix . 'userconv', $insert_ary);
1811 $insert_ary = array();
1812 }
1813 $i++;
1814 }
1815 $src_db->sql_freeresult($result);
1816
1817 if (sizeof($insert_ary))
1818 {
1819 $db->sql_multi_insert($table_prefix . 'userconv', $insert_ary);
1820 }
1821 unset($insert_ary);
1822
1823 // now find the clean version of the usernames that collide
1824 $sql = 'SELECT username_clean
1825 FROM ' . $table_prefix . 'userconv
1826 GROUP BY username_clean
1827 HAVING COUNT(user_id) > 1';
1828 $result = $db->sql_query($sql);
1829
1830 $colliding_names = array();
1831 while ($row = $db->sql_fetchrow($result))
1832 {
1833 $colliding_names[] = $row['username_clean'];
1834 }
1835 $db->sql_freeresult($result);
1836
1837 // there was at least one collision, the admin will have to solve it before conversion can continue
1838 if (sizeof($colliding_names))
1839 {
1840 $sql = 'SELECT user_id, username_clean
1841 FROM ' . $table_prefix . 'userconv
1842 WHERE ' . $db->sql_in_set('username_clean', $colliding_names);
1843 $result = $db->sql_query($sql);
1844 unset($colliding_names);
1845
1846 $colliding_user_ids = array();
1847 while ($row = $db->sql_fetchrow($result))
1848 {
1849 $colliding_user_ids[(int) $row['user_id']] = $row['username_clean'];
1850 }
1851 $db->sql_freeresult($result);
1852
1853 $sql = 'SELECT username, user_id, user_posts
1854 FROM ' . $convert->src_table_prefix . 'users
1855 WHERE ' . $src_db->sql_in_set('user_id', array_keys($colliding_user_ids));
1856 $result = $src_db->sql_query($sql);
1857
1858 $colliding_users = array();
1859 while ($row = $db->sql_fetchrow($result))
1860 {
1861 $row['user_id'] = (int) $row['user_id'];
1862 if (isset($colliding_user_ids[$row['user_id']]))
1863 {
1864 $colliding_users[$colliding_user_ids[$row['user_id']]][] = $row;
1865 }
1866 }
1867 $db->sql_freeresult($result);
1868 unset($colliding_user_ids);
1869
1870 $list = '';
1871 foreach ($colliding_users as $username_clean => $users)
1872 {
1873 $list .= sprintf($user->lang['COLLIDING_CLEAN_USERNAME'], $username_clean) . "<br />\n";
1874 foreach ($users as $i => $row)
1875 {
1876 $list .= sprintf($user->lang['COLLIDING_USER'], $row['user_id'], phpbb_set_default_encoding($row['username']), $row['user_posts']) . "<br />\n";
1877 }
1878 }
1879
1880 $lang['INST_ERR_FATAL'] = $user->lang['CONV_ERR_FATAL'];
1881 $convert->p_master->error('<span style="color:red">' . $user->lang['COLLIDING_USERNAMES_FOUND'] . '</span></b><br /><br />' . $list . '<b>', __LINE__, __FILE__);
1882 }
1883
1884 $db->sql_query($drop_sql);
1885 }
1886
1887 ?>