6 * @copyright (c) 2006 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 if (!defined('IN_PHPBB'))
17 * Helper functions for phpBB 2.0.x to phpBB 3.0.x conversion
21 * Set forum flags - only prune old polls by default
23 function phpbb_forum_flags()
28 // FORUM_FLAG_LINK_TRACK
31 // FORUM_FLAG_PRUNE_POLL
32 $forum_flags += FORUM_FLAG_PRUNE_POLL;
34 // FORUM_FLAG_PRUNE_ANNOUNCE
37 // FORUM_FLAG_PRUNE_STICKY
40 // FORUM_FLAG_ACTIVE_TOPICS
43 // FORUM_FLAG_POST_REVIEW
44 $forum_flags += FORUM_FLAG_POST_REVIEW;
50 * Insert/Convert forums
52 function phpbb_insert_forums()
54 global $db, $src_db, $same_db, $convert, $user, $config;
56 $db->sql_query($convert->truncate_statement . FORUMS_TABLE);
58 // Determine the highest id used within the old forums table (we add the categories after the forum ids)
59 $sql = 'SELECT MAX(forum_id) AS max_forum_id
60 FROM ' . $convert->src_table_prefix . 'forums';
61 $result = $src_db->sql_query($sql);
62 $max_forum_id = (int) $src_db->sql_fetchfield('max_forum_id');
63 $src_db->sql_freeresult($result);
67 // pruning disabled globally?
68 $sql = "SELECT config_value
69 FROM {$convert->src_table_prefix}config
70 WHERE config_name = 'prune_enable'";
71 $result = $src_db->sql_query($sql);
72 $prune_enabled = (int) $src_db->sql_fetchfield('config_value');
73 $src_db->sql_freeresult($result);
77 $sql = 'SELECT cat_id, cat_title
78 FROM ' . $convert->src_table_prefix . 'categories
81 if ($convert->mysql_convert && $same_db)
83 $src_db->sql_query("SET NAMES 'binary'");
86 $result = $src_db->sql_query($sql);
88 if ($convert->mysql_convert && $same_db)
90 $src_db->sql_query("SET NAMES 'utf8'");
93 switch ($db->sql_layer)
98 $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' ON');
102 $cats_added = array();
103 while ($row = $src_db->sql_fetchrow($result))
106 'forum_id' => (int) $max_forum_id,
107 'forum_name' => ($row['cat_title']) ? htmlspecialchars(phpbb_set_default_encoding($row['cat_title']), ENT_COMPAT, 'UTF-8') : $user->lang['CATEGORY'],
109 'forum_parents' => '',
111 'forum_type' => FORUM_CAT,
112 'forum_status' => ITEM_UNLOCKED,
116 $sql = 'SELECT MAX(right_id) AS right_id
117 FROM ' . FORUMS_TABLE;
118 $_result = $db->sql_query($sql);
119 $cat_row = $db->sql_fetchrow($_result);
120 $db->sql_freeresult($_result);
122 $sql_ary['left_id'] = (int) ($cat_row['right_id'] + 1);
123 $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 2);
125 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
126 $db->sql_query($sql);
128 $cats_added[$row['cat_id']] = $max_forum_id;
131 $src_db->sql_freeresult($result);
133 // There may be installations having forums with non-existant category ids.
134 // We try to catch them and add them to an "unknown" category instead of leaving them out.
135 $sql = 'SELECT cat_id
136 FROM ' . $convert->src_table_prefix . 'forums
138 $result = $src_db->sql_query($sql);
140 $unknown_cat_id = false;
141 while ($row = $src_db->sql_fetchrow($result))
143 // Catch those categories not been added before
144 if (!isset($cats_added[$row['cat_id']]))
146 $unknown_cat_id = true;
149 $src_db->sql_freeresult($result);
151 // Is there at least one category not known?
152 if ($unknown_cat_id === true)
154 $unknown_cat_id = 'ghost';
157 'forum_id' => (int) $max_forum_id,
158 'forum_name' => (string) $user->lang['CATEGORY'],
160 'forum_parents' => '',
162 'forum_type' => FORUM_CAT,
163 'forum_status' => ITEM_UNLOCKED,
167 $sql = 'SELECT MAX(right_id) AS right_id
168 FROM ' . FORUMS_TABLE;
169 $_result = $db->sql_query($sql);
170 $cat_row = $db->sql_fetchrow($_result);
171 $db->sql_freeresult($_result);
173 $sql_ary['left_id'] = (int) ($cat_row['right_id'] + 1);
174 $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 2);
176 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
177 $db->sql_query($sql);
179 $cats_added[$unknown_cat_id] = $max_forum_id;
183 // Now insert the forums
184 $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
185 LEFT JOIN ' . $convert->src_table_prefix . 'forum_prune fp ON f.forum_id = fp.forum_id
186 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
187 ORDER BY f.cat_id, f.forum_order';
189 if ($convert->mysql_convert && $same_db)
191 $src_db->sql_query("SET NAMES 'binary'");
194 $result = $src_db->sql_query($sql);
196 if ($convert->mysql_convert && $same_db)
198 $src_db->sql_query("SET NAMES 'utf8'");
201 while ($row = $src_db->sql_fetchrow($result))
203 // Some might have forums here with an id not being "possible"...
204 // To be somewhat friendly we "change" the category id for those to a previously created ghost category
205 if (!isset($cats_added[$row['cat_id']]) && $unknown_cat_id !== false)
207 $row['cat_id'] = $unknown_cat_id;
210 if (!isset($cats_added[$row['cat_id']]))
215 // Define the new forums sql ary
217 'forum_id' => (int) $row['forum_id'],
218 'forum_name' => htmlspecialchars(phpbb_set_default_encoding($row['forum_name']), ENT_COMPAT, 'UTF-8'),
219 'parent_id' => (int) $cats_added[$row['cat_id']],
220 'forum_parents' => '',
221 'forum_desc' => htmlspecialchars(phpbb_set_default_encoding($row['forum_desc']), ENT_COMPAT, 'UTF-8'),
222 'forum_type' => FORUM_POST,
223 'forum_status' => is_item_locked($row['forum_status']),
224 'enable_prune' => ($prune_enabled) ? (int)$row['prune_enable'] : 0,
225 'prune_next' => (int) null_to_zero($row['prune_next']),
226 'prune_days' => (int) null_to_zero($row['prune_days']),
228 'prune_freq' => (int) null_to_zero($row['prune_freq']),
230 'forum_flags' => phpbb_forum_flags(),
231 'forum_options' => 0,
234 'forum_desc_bitfield' => '',
235 'forum_desc_options' => 7,
236 'forum_desc_uid' => '',
238 'forum_password' => '',
242 'forum_rules_link' => '',
243 'forum_rules_bitfield' => '',
244 'forum_rules_options' => 7,
245 'forum_rules_uid' => '',
246 'forum_topics_per_page' => 0,
249 'forum_topics_real' => 0,
250 'forum_last_post_id' => 0,
251 'forum_last_poster_id' => 0,
252 'forum_last_post_subject' => '',
253 'forum_last_post_time' => 0,
254 'forum_last_poster_name' => '',
255 'forum_last_poster_colour' => '',
256 'display_on_index' => 1,
257 'enable_indexing' => 1,
261 // Now add the forums with proper left/right ids
262 $sql = 'SELECT left_id, right_id
263 FROM ' . FORUMS_TABLE . '
264 WHERE forum_id = ' . $cats_added[$row['cat_id']];
265 $_result = $db->sql_query($sql);
266 $cat_row = $db->sql_fetchrow($_result);
267 $db->sql_freeresult($_result);
269 $sql = 'UPDATE ' . FORUMS_TABLE . '
270 SET left_id = left_id + 2, right_id = right_id + 2
271 WHERE left_id > ' . $cat_row['right_id'];
272 $db->sql_query($sql);
274 $sql = 'UPDATE ' . FORUMS_TABLE . '
275 SET right_id = right_id + 2
276 WHERE ' . $cat_row['left_id'] . ' BETWEEN left_id AND right_id';
277 $db->sql_query($sql);
279 $sql_ary['left_id'] = (int) $cat_row['right_id'];
280 $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 1);
282 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
283 $db->sql_query($sql);
285 $src_db->sql_freeresult($result);
287 switch ($db->sql_layer)
290 $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 . '));');
296 $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' OFF');
300 $result = $db->sql_query('SELECT MAX(forum_id) as max_id FROM ' . FORUMS_TABLE);
301 $row = $db->sql_fetchrow($result);
302 $db->sql_freeresult($result);
304 $largest_id = (int) $row['max_id'];
308 $db->sql_query('DROP SEQUENCE ' . FORUMS_TABLE . '_seq');
309 $db->sql_query('CREATE SEQUENCE ' . FORUMS_TABLE . '_seq START WITH ' . ($largest_id + 1));
316 * Function for recoding text with the default language
318 * @param string $text text to recode to utf8
319 * @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
321 function phpbb_set_encoding($text, $grab_user_lang = true)
323 global $lang_enc_array, $convert_row;
324 global $convert, $phpEx;
326 /*static $lang_enc_array = array(
327 'korean' => 'euc-kr',
328 'serbian' => 'windows-1250',
329 'polish' => 'iso-8859-2',
330 'kurdish' => 'windows-1254',
331 'slovak' => 'Windows-1250',
332 'russian' => 'windows-1251',
333 'estonian' => 'iso-8859-4',
334 'chinese_simplified' => 'gb2312',
335 'macedonian' => 'windows-1251',
336 'azerbaijani' => 'UTF-8',
337 'romanian' => 'iso-8859-2',
338 'romanian_diacritice' => 'iso-8859-2',
339 'lithuanian' => 'windows-1257',
340 'turkish' => 'iso-8859-9',
341 'ukrainian' => 'windows-1251',
342 'japanese' => 'shift_jis',
343 'hungarian' => 'ISO-8859-2',
344 'romanian_no_diacritics' => 'iso-8859-2',
345 'mongolian' => 'UTF-8',
346 'slovenian' => 'windows-1250',
347 'bosnian' => 'windows-1250',
348 'czech' => 'Windows-1250',
349 'farsi' => 'Windows-1256',
350 'croatian' => 'windows-1250',
351 'greek' => 'iso-8859-7',
352 'russian_tu' => 'windows-1251',
354 'serbian_cyrillic' => 'windows-1251',
355 'bulgarian' => 'windows-1251',
356 'chinese_traditional_taiwan' => 'big5',
357 'chinese_traditional' => 'big5',
358 'arabic' => 'windows-1256',
359 'hebrew' => 'WINDOWS-1255',
360 'thai' => 'windows-874',
361 //'chinese_traditional_taiwan' => 'utf-8' // custom modified, we may have to do an include :-(
364 if (empty($lang_enc_array))
366 $lang_enc_array = array();
369 $get_lang = trim(get_config_value('default_lang'));
371 // Do we need the users language encoding?
372 if ($grab_user_lang && !empty($convert_row))
374 if (!empty($convert_row['user_lang']))
376 $get_lang = trim($convert_row['user_lang']);
378 else if (!empty($convert_row['poster_id']))
380 global $src_db, $same_db;
382 if ($convert->mysql_convert && $same_db)
384 $src_db->sql_query("SET NAMES 'binary'");
387 $sql = 'SELECT user_lang
388 FROM ' . $convert->src_table_prefix . 'users
389 WHERE user_id = ' . (int) $convert_row['poster_id'];
390 $result = $src_db->sql_query($sql);
391 $get_lang = (string) $src_db->sql_fetchfield('user_lang');
392 $src_db->sql_freeresult($result);
394 if ($convert->mysql_convert && $same_db)
396 $src_db->sql_query("SET NAMES 'utf8'");
399 $get_lang = (!trim($get_lang)) ? trim(get_config_value('default_lang')) : trim($get_lang);
403 if (!isset($lang_enc_array[$get_lang]))
405 $filename = $convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx;
407 if (!file_exists($filename))
409 $get_lang = trim(get_config_value('default_lang'));
412 if (!isset($lang_enc_array[$get_lang]))
414 include($convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx);
415 $lang_enc_array[$get_lang] = $lang['ENCODING'];
420 $encoding = $lang_enc_array[$get_lang];
422 return utf8_recode($text, $lang_enc_array[$get_lang]);
426 * Same as phpbb_set_encoding, but forcing boards default language
428 function phpbb_set_default_encoding($text)
430 return phpbb_set_encoding($text, false);
434 * Convert Birthday from Birthday MOD to phpBB Format
436 function phpbb_get_birthday($birthday = '')
438 if (defined('MOD_BIRTHDAY_TERRA'))
440 $birthday = (string) $birthday;
442 // stored as month, day, year
448 // We use the original mod code to retrieve the birthday (not ideal)
449 preg_match('/(..)(..)(....)/', sprintf('%08d', $birthday), $birthday_parts);
451 $month = $birthday_parts[1];
452 $day = $birthday_parts[2];
453 $year = $birthday_parts[3];
455 return sprintf('%2d-%2d-%4d', $day, $month, $year);
459 $birthday = (int) $birthday;
461 if (!$birthday || $birthday == 999999 || ((version_compare(PHP_VERSION, '5.1.0') < 0) && $birthday < 0))
466 // The birthday mod from niels is using this code to transform to day/month/year
467 return sprintf('%2d-%2d-%4d', gmdate('j', $birthday * 86400 + 1), gmdate('n', $birthday * 86400 + 1), gmdate('Y', $birthday * 86400 + 1));
472 * Return correct user id value
473 * Everyone's id will be one higher to allow the guest/anonymous user to have a positive id as well
475 function phpbb_user_id($user_id)
479 // Increment user id if the old forum is having a user with the id 1
480 if (!isset($config['increment_user_id']))
482 global $src_db, $same_db, $convert;
484 if ($convert->mysql_convert && $same_db)
486 $src_db->sql_query("SET NAMES 'binary'");
489 // Now let us set a temporary config variable for user id incrementing
490 $sql = "SELECT user_id
491 FROM {$convert->src_table_prefix}users
493 $result = $src_db->sql_query($sql);
494 $id = (int) $src_db->sql_fetchfield('user_id');
495 $src_db->sql_freeresult($result);
497 // Try to get the maximum user id possible...
498 $sql = "SELECT MAX(user_id) AS max_user_id
499 FROM {$convert->src_table_prefix}users";
500 $result = $src_db->sql_query($sql);
501 $max_id = (int) $src_db->sql_fetchfield('max_user_id');
502 $src_db->sql_freeresult($result);
504 if ($convert->mysql_convert && $same_db)
506 $src_db->sql_query("SET NAMES 'utf8'");
509 // If there is a user id 1, we need to increment user ids. :/
512 set_config('increment_user_id', ($max_id + 1), true);
513 $config['increment_user_id'] = $max_id + 1;
517 set_config('increment_user_id', 0, true);
518 $config['increment_user_id'] = 0;
522 // If the old user id is -1 in 2.0.x it is the anonymous user...
528 if (!empty($config['increment_user_id']) && $user_id == 1)
530 return $config['increment_user_id'];
533 // A user id of 0 can happen, for example within the ban table if no user is banned...
534 // Within the posts and topics table this can be "dangerous" but is the fault of the user
535 // having mods installed (a poster id of 0 is not possible in 2.0.x).
536 // Therefore, we return the user id "as is".
538 return (int) $user_id;
541 /* Copy additional table fields from old forum to new forum if user wants this (for Mod compatibility for example)
542 function phpbb_copy_table_fields()
548 * Convert authentication
549 * user, group and forum table has to be filled in order to work
551 function phpbb_convert_authentication($mode)
553 global $db, $src_db, $same_db, $convert, $user, $config, $cache;
555 if ($mode == 'start')
557 $db->sql_query($convert->truncate_statement . ACL_USERS_TABLE);
558 $db->sql_query($convert->truncate_statement . ACL_GROUPS_TABLE);
560 // What we will do is handling all 2.0.x admins as founder to replicate what is common in 2.0.x.
561 // After conversion the main admin need to make sure he is removing permissions and the founder status if wanted.
564 // Grab user ids of users with user_level of ADMIN
565 $sql = "SELECT user_id
566 FROM {$convert->src_table_prefix}users
568 ORDER BY user_regdate ASC";
569 $result = $src_db->sql_query($sql);
571 while ($row = $src_db->sql_fetchrow($result))
573 $user_id = (int) phpbb_user_id($row['user_id']);
574 // Set founder admin...
575 $sql = 'UPDATE ' . USERS_TABLE . '
576 SET user_type = ' . USER_FOUNDER . "
577 WHERE user_id = $user_id";
578 $db->sql_query($sql);
580 $src_db->sql_freeresult($result);
582 $sql = 'SELECT group_id
583 FROM ' . GROUPS_TABLE . "
584 WHERE group_name = '" . $db->sql_escape('BOTS') . "'";
585 $result = $db->sql_query($sql);
586 $bot_group_id = (int) $db->sql_fetchfield('group_id');
587 $db->sql_freeresult($result);
590 // Grab forum auth information
592 FROM {$convert->src_table_prefix}forums";
593 $result = $src_db->sql_query($sql);
595 $forum_access = array();
596 while ($row = $src_db->sql_fetchrow($result))
598 $forum_access[$row['forum_id']] = $row;
600 $src_db->sql_freeresult($result);
602 if ($convert->mysql_convert && $same_db)
604 $src_db->sql_query("SET NAMES 'binary'");
606 // Grab user auth information from 2.0.x board
607 $sql = "SELECT ug.user_id, aa.*
608 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
609 WHERE g.group_id = aa.group_id
610 AND g.group_single_user = 1
611 AND ug.group_id = g.group_id
612 AND f.forum_id = aa.forum_id";
613 $result = $src_db->sql_query($sql);
615 $user_access = array();
616 while ($row = $src_db->sql_fetchrow($result))
618 $user_access[$row['forum_id']][] = $row;
620 $src_db->sql_freeresult($result);
622 // Grab group auth information
623 $sql = "SELECT g.group_id, aa.*
624 FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}groups g
625 WHERE g.group_id = aa.group_id
626 AND g.group_single_user <> 1";
627 $result = $src_db->sql_query($sql);
629 $group_access = array();
630 while ($row = $src_db->sql_fetchrow($result))
632 $group_access[$row['forum_id']][] = $row;
634 $src_db->sql_freeresult($result);
636 if ($convert->mysql_convert && $same_db)
638 $src_db->sql_query("SET NAMES 'utf8'");
641 // Add Forum Access List
643 'auth_view' => array('f_', 'f_list'),
644 'auth_read' => array('f_read', 'f_search'),
645 'auth_post' => array('f_post', 'f_bbcode', 'f_smilies', 'f_img', 'f_sigs', 'f_postcount', 'f_report', 'f_subscribe', 'f_print', 'f_email'),
646 'auth_reply' => 'f_reply',
647 'auth_edit' => 'f_edit',
648 'auth_delete' => 'f_delete',
649 'auth_pollcreate' => 'f_poll',
650 'auth_vote' => 'f_vote',
651 'auth_announce' => 'f_announce',
652 'auth_sticky' => 'f_sticky',
653 'auth_attachments' => array('f_attach', 'f_download'),
654 'auth_download' => 'f_download',
657 // Define the ACL constants used in 2.0 to make the code slightly more readable
658 define('AUTH_ALL', 0);
659 define('AUTH_REG', 1);
660 define('AUTH_ACL', 2);
661 define('AUTH_MOD', 3);
662 define('AUTH_ADMIN', 5);
664 // A mapping of the simple permissions used by 2.0
665 $simple_auth_ary = array(
667 'auth_view' => AUTH_ALL,
668 'auth_read' => AUTH_ALL,
669 'auth_post' => AUTH_ALL,
670 'auth_reply' => AUTH_ALL,
671 'auth_edit' => AUTH_REG,
672 'auth_delete' => AUTH_REG,
673 'auth_sticky' => AUTH_MOD,
674 'auth_announce' => AUTH_MOD,
675 'auth_vote' => AUTH_REG,
676 'auth_pollcreate' => AUTH_REG,
678 'registered' => array(
679 'auth_view' => AUTH_ALL,
680 'auth_read' => AUTH_ALL,
681 'auth_post' => AUTH_REG,
682 'auth_reply' => AUTH_REG,
683 'auth_edit' => AUTH_REG,
684 'auth_delete' => AUTH_REG,
685 'auth_sticky' => AUTH_MOD,
686 'auth_announce' => AUTH_MOD,
687 'auth_vote' => AUTH_REG,
688 'auth_pollcreate' => AUTH_REG,
690 'registered_hidden' => array(
691 'auth_view' => AUTH_REG,
692 'auth_read' => AUTH_REG,
693 'auth_post' => AUTH_REG,
694 'auth_reply' => AUTH_REG,
695 'auth_edit' => AUTH_REG,
696 'auth_delete' => AUTH_REG,
697 'auth_sticky' => AUTH_MOD,
698 'auth_announce' => AUTH_MOD,
699 'auth_vote' => AUTH_REG,
700 'auth_pollcreate' => AUTH_REG,
703 'auth_view' => AUTH_ALL,
704 'auth_read' => AUTH_ACL,
705 'auth_post' => AUTH_ACL,
706 'auth_reply' => AUTH_ACL,
707 'auth_edit' => AUTH_ACL,
708 'auth_delete' => AUTH_ACL,
709 'auth_sticky' => AUTH_ACL,
710 'auth_announce' => AUTH_MOD,
711 'auth_vote' => AUTH_ACL,
712 'auth_pollcreate' => AUTH_ACL,
714 'private_hidden' => array(
715 'auth_view' => AUTH_ACL,
716 'auth_read' => AUTH_ACL,
717 'auth_post' => AUTH_ACL,
718 'auth_reply' => AUTH_ACL,
719 'auth_edit' => AUTH_ACL,
720 'auth_delete' => AUTH_ACL,
721 'auth_sticky' => AUTH_ACL,
722 'auth_announce' => AUTH_MOD,
723 'auth_vote' => AUTH_ACL,
724 'auth_pollcreate' => AUTH_ACL,
726 'moderator' => array(
727 'auth_view' => AUTH_ALL,
728 'auth_read' => AUTH_MOD,
729 'auth_post' => AUTH_MOD,
730 'auth_reply' => AUTH_MOD,
731 'auth_edit' => AUTH_MOD,
732 'auth_delete' => AUTH_MOD,
733 'auth_sticky' => AUTH_MOD,
734 'auth_announce' => AUTH_MOD,
735 'auth_vote' => AUTH_MOD,
736 'auth_pollcreate' => AUTH_MOD,
738 'moderator_hidden' => array(
739 'auth_view' => AUTH_MOD,
740 'auth_read' => AUTH_MOD,
741 'auth_post' => AUTH_MOD,
742 'auth_reply' => AUTH_MOD,
743 'auth_edit' => AUTH_MOD,
744 'auth_delete' => AUTH_MOD,
745 'auth_sticky' => AUTH_MOD,
746 'auth_announce' => AUTH_MOD,
747 'auth_vote' => AUTH_MOD,
748 'auth_pollcreate' => AUTH_MOD,
752 if ($mode == 'start')
754 user_group_auth('guests', 'SELECT user_id, {GUESTS} FROM ' . USERS_TABLE . ' WHERE user_id = ' . ANONYMOUS, false);
755 user_group_auth('registered', 'SELECT user_id, {REGISTERED} FROM ' . USERS_TABLE . ' WHERE user_id <> ' . ANONYMOUS . " AND group_id <> $bot_group_id", false);
757 // Selecting from old table
758 if (!empty($config['increment_user_id']))
760 $auth_sql = 'SELECT user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id <> 1';
761 user_group_auth('administrators', $auth_sql, true);
763 $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';
764 user_group_auth('administrators', $auth_sql, true);
768 $auth_sql = 'SELECT user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1';
769 user_group_auth('administrators', $auth_sql, true);
772 if (!empty($config['increment_user_id']))
774 $auth_sql = 'SELECT user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id <> 1';
775 user_group_auth('global_moderators', $auth_sql, true);
777 $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';
778 user_group_auth('global_moderators', $auth_sql, true);
782 $auth_sql = 'SELECT user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1';
783 user_group_auth('global_moderators', $auth_sql, true);
786 else if ($mode == 'first')
788 // Go through all 2.0.x forums
789 foreach ($forum_access as $forum)
791 $new_forum_id = (int) $forum['forum_id'];
793 // Administrators have full access to all forums whatever happens
794 mass_auth('group_role', $new_forum_id, 'administrators', 'FORUM_FULL');
797 foreach ($simple_auth_ary as $key => $auth_levels)
800 foreach ($auth_levels as $k => $level)
802 if ($forum[$k] != $auth_levels[$k])
810 $matched_type = $key;
815 switch ($matched_type)
818 mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_LIMITED');
819 mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_LIMITED_POLLS');
820 mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
824 mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_READONLY');
825 mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
829 case 'registered_hidden':
830 mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_POLLS');
834 case 'private_hidden':
836 case 'moderator_hidden':
838 // The permissions don't match a simple set, so we're going to have to map them directly
840 // No post approval for all, in 2.0.x this feature does not exist
841 mass_auth('group', $new_forum_id, 'guests', 'f_noapprove', ACL_YES);
842 mass_auth('group', $new_forum_id, 'registered', 'f_noapprove', ACL_YES);
844 // Go through authentication map
845 foreach ($auth_map as $old_auth_key => $new_acl)
847 // If old authentication key does not exist we continue
848 // This is helpful for mods adding additional authentication fields, we need to add them to the auth_map array
849 if (!isset($forum[$old_auth_key]))
854 // Now set the new ACL correctly
855 switch ($forum[$old_auth_key])
859 mass_auth('group', $new_forum_id, 'guests', $new_acl, ACL_YES);
860 mass_auth('group', $new_forum_id, 'bots', $new_acl, ACL_YES);
861 mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
866 mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
871 // Go through the old group access list for this forum
872 if (isset($group_access[$forum['forum_id']]))
874 foreach ($group_access[$forum['forum_id']] as $index => $access)
876 // We only check for ACL_YES equivalence entry
877 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
879 mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
884 if (isset($user_access[$forum['forum_id']]))
886 foreach ($user_access[$forum['forum_id']] as $index => $access)
888 // We only check for ACL_YES equivalence entry
889 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
891 mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
899 if (isset($group_access[$forum['forum_id']]))
901 foreach ($group_access[$forum['forum_id']] as $index => $access)
903 // We only check for ACL_YES equivalence entry
904 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
906 mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
911 if (isset($user_access[$forum['forum_id']]))
913 foreach ($user_access[$forum['forum_id']] as $index => $access)
915 // We only check for ACL_YES equivalence entry
916 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
918 mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
929 else if ($mode == 'second')
931 // Assign permission roles and other default permissions
933 // guests having u_download and u_search ability
934 $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')");
936 // administrators/global mods having full user features
937 mass_auth('group_role', 0, 'administrators', 'USER_FULL');
938 mass_auth('group_role', 0, 'global_moderators', 'USER_FULL');
940 // By default all converted administrators are given full access
941 mass_auth('group_role', 0, 'administrators', 'ADMIN_FULL');
943 // All registered users are assigned the standard user role
944 mass_auth('group_role', 0, 'registered', 'USER_STANDARD');
945 mass_auth('group_role', 0, 'registered_coppa', 'USER_STANDARD');
947 // Instead of administrators being global moderators we give the MOD_FULL role to global mods (admins already assigned to this group)
948 mass_auth('group_role', 0, 'global_moderators', 'MOD_FULL');
950 // And now those who have had their avatar rights removed get assigned a more restrictive role
951 $sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
952 WHERE user_allowavatar = 0
954 $result = $src_db->sql_query($sql);
956 while ($row = $src_db->sql_fetchrow($result))
958 mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOAVATAR');
960 $src_db->sql_freeresult($result);
962 // And the same for those who have had their PM rights removed
963 $sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
964 WHERE user_allow_pm = 0
966 $result = $src_db->sql_query($sql);
968 while ($row = $src_db->sql_fetchrow($result))
970 mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOPM');
972 $src_db->sql_freeresult($result);
974 else if ($mode == 'third')
976 // And now the moderators
977 // We make sure that they have at least standard access to the forums they moderate in addition to the moderating permissions
979 $mod_post_map = array(
980 'auth_announce' => 'f_announce',
981 'auth_sticky' => 'f_sticky'
984 foreach ($user_access as $forum_id => $access_map)
986 $forum_id = (int) $forum_id;
988 foreach ($access_map as $access)
990 if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
992 mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'MOD_STANDARD');
993 mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'FORUM_STANDARD');
994 foreach ($mod_post_map as $old => $new)
996 if (isset($forum_access[$forum_id]) && isset($forum_access[$forum_id][$old]) && $forum_access[$forum_id][$old] == AUTH_MOD)
998 mass_auth('user', $forum_id, (int) phpbb_user_id($access['user_id']), $new, ACL_YES);
1005 foreach ($group_access as $forum_id => $access_map)
1007 $forum_id = (int) $forum_id;
1009 foreach ($access_map as $access)
1011 if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
1013 mass_auth('group_role', $forum_id, (int) $access['group_id'], 'MOD_STANDARD');
1014 mass_auth('group_role', $forum_id, (int) $access['group_id'], 'FORUM_STANDARD');
1015 foreach ($mod_post_map as $old => $new)
1017 if (isset($forum_access[$forum_id]) && isset($forum_access[$forum_id][$old]) && $forum_access[$forum_id][$old] == AUTH_MOD)
1019 mass_auth('group', $forum_id, (int) $access['group_id'], $new, ACL_YES);
1026 // We grant everyone readonly access to the categories to ensure that the forums are visible
1027 $sql = 'SELECT forum_id, forum_name, parent_id, left_id, right_id
1028 FROM ' . FORUMS_TABLE . '
1029 ORDER BY left_id ASC';
1030 $result = $db->sql_query($sql);
1032 $parent_forums = $forums = array();
1033 while ($row = $db->sql_fetchrow($result))
1035 if ($row['parent_id'] == 0)
1037 mass_auth('group_role', $row['forum_id'], 'administrators', 'FORUM_FULL');
1038 mass_auth('group_role', $row['forum_id'], 'global_moderators', 'FORUM_FULL');
1039 $parent_forums[] = $row;
1046 $db->sql_freeresult($result);
1050 // Let us see which groups have access to these forums...
1051 foreach ($parent_forums as $row)
1054 $branch = $forum_ids = array();
1056 foreach ($forums as $key => $_row)
1058 if ($_row['left_id'] > $row['left_id'] && $_row['left_id'] < $row['right_id'])
1061 $forum_ids[] = $_row['forum_id'];
1066 if (sizeof($forum_ids))
1068 // Now make sure the user is able to read these forums
1069 $hold_ary = $auth->acl_group_raw_data(false, 'f_list', $forum_ids);
1071 if (empty($hold_ary))
1076 foreach ($hold_ary as $g_id => $f_id_ary)
1080 foreach ($f_id_ary as $f_id => $auth_ary)
1082 foreach ($auth_ary as $auth_option => $setting)
1084 if ($setting == ACL_YES)
1094 mass_auth('group', $row['forum_id'], $g_id, 'f_list', ACL_YES);
1103 * Set primary group.
1104 * Really simple and only based on user_level (remaining groups will be assigned later)
1106 function phpbb_set_primary_group($user_level)
1108 global $convert_row;
1110 if ($user_level == 1)
1112 return get_group_id('administrators');
1114 /* else if ($user_level == 2)
1116 return get_group_id('global_moderators');
1118 else if ($user_level == 0 && $convert_row['user_active'])*/
1119 else if ($convert_row['user_active'])
1121 return get_group_id('registered');
1128 * Convert the group name, making sure to avoid conflicts with 3.0 special groups
1130 function phpbb_convert_group_name($group_name)
1132 $default_groups = array(
1136 'GLOBAL_MODERATORS',
1141 if (in_array(strtoupper($group_name), $default_groups))
1143 return 'phpBB2 - ' . $group_name;
1146 return phpbb_set_default_encoding($group_name);
1150 * Convert the group type constants
1152 function phpbb_convert_group_type($group_type)
1154 switch ($group_type)
1161 return GROUP_CLOSED;
1165 return GROUP_HIDDEN;
1169 // Never return GROUP_SPECIAL here, because only phpBB3's default groups are allowed to have this type set.
1170 return GROUP_HIDDEN;
1174 * Convert the topic type constants
1176 function phpbb_convert_topic_type($topic_type)
1178 switch ($topic_type)
1189 return POST_ANNOUNCE;
1200 function phpbb_replace_size($matches)
1202 return '[size=' . min(200, ceil(100.0 * (((double) $matches[1])/12.0))) . ':' . $matches[2] . ']';
1206 * Reparse the message stripping out the bbcode_uid values and adding new ones and setting the bitfield
1207 * @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
1209 function phpbb_prepare_message($message)
1211 global $phpbb_root_path, $phpEx, $db, $convert, $user, $config, $cache, $convert_row, $message_parser;
1215 $convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = 0;
1219 // Decode phpBB 2.0.x Message
1220 if (isset($convert->row['old_bbcode_uid']) && $convert->row['old_bbcode_uid'] != '')
1223 if (strpos($message, '[size=') !== false)
1225 $message = preg_replace_callback('/\[size=(\d*):(' . $convert->row['old_bbcode_uid'] . ')\]/', 'phpbb_replace_size', $message);
1228 $message = preg_replace('/\:(([a-z0-9]:)?)' . $convert->row['old_bbcode_uid'] . '/s', '', $message);
1231 if (strpos($message, '[quote=') !== false)
1233 $message = preg_replace('/\[quote="(.*?)"\]/s', '[quote="\1"]', $message);
1234 $message = preg_replace('/\[quote=\\\"(.*?)\\\"\]/s', '[quote="\1"]', $message);
1236 // let's hope that this solves more problems than it causes. Deal with escaped quotes.
1237 $message = str_replace('\"', '"', $message);
1238 $message = str_replace('\"', '"', $message);
1241 // Already the new user id ;)
1242 $user_id = $convert->row['poster_id'];
1244 $message = str_replace('<br />', "\n", $message);
1245 $message = str_replace('<', '<', $message);
1246 $message = str_replace('>', '>', $message);
1248 // make the post UTF-8
1249 $message = phpbb_set_encoding($message);
1251 $message_parser->warn_msg = array(); // Reset the errors from the previous message
1252 $message_parser->bbcode_uid = make_uid($convert->row['post_time']);
1253 $message_parser->message = $message;
1256 // Make sure options are set.
1257 // $enable_html = (!isset($row['enable_html'])) ? false : $row['enable_html'];
1258 $enable_bbcode = (!isset($convert->row['enable_bbcode'])) ? true : $convert->row['enable_bbcode'];
1259 $enable_smilies = (!isset($convert->row['enable_smilies'])) ? true : $convert->row['enable_smilies'];
1260 $enable_magic_url = (!isset($convert->row['enable_magic_url'])) ? true : $convert->row['enable_magic_url'];
1262 // 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')
1263 $message_parser->parse($enable_bbcode, $enable_magic_url, $enable_smilies);
1265 if (sizeof($message_parser->warn_msg))
1267 $msg_id = isset($convert->row['post_id']) ? $convert->row['post_id'] : $convert->row['privmsgs_id'];
1268 $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);
1271 $convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = $message_parser->bbcode_bitfield;
1273 $message = $message_parser->message;
1274 unset($message_parser->message);
1280 * Return the bitfield calculated by the previous function
1282 function get_bbcode_bitfield()
1284 global $convert_row;
1286 return $convert_row['mp_bbcode_bitfield'];
1290 * Determine the last user to edit a post
1291 * 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
1293 function phpbb_post_edit_user()
1295 global $convert_row, $config;
1297 if (isset($convert_row['post_edit_count']))
1299 return phpbb_user_id($convert_row['poster_id']);
1306 * Obtain the path to uploaded files on the 2.0.x forum
1307 * This is only used if the Attachment MOD was installed
1309 function phpbb_get_files_dir()
1311 if (!defined('MOD_ATTACHMENT'))
1316 global $src_db, $same_db, $convert, $user, $config, $cache;
1318 if ($convert->mysql_convert && $same_db)
1320 $src_db->sql_query("SET NAMES 'binary'");
1322 $sql = 'SELECT config_value AS upload_dir
1323 FROM ' . $convert->src_table_prefix . "attachments_config
1324 WHERE config_name = 'upload_dir'";
1325 $result = $src_db->sql_query($sql);
1326 $upload_path = $src_db->sql_fetchfield('upload_dir');
1327 $src_db->sql_freeresult($result);
1329 $sql = 'SELECT config_value AS ftp_upload
1330 FROM ' . $convert->src_table_prefix . "attachments_config
1331 WHERE config_name = 'allow_ftp_upload'";
1332 $result = $src_db->sql_query($sql);
1333 $ftp_upload = (int) $src_db->sql_fetchfield('ftp_upload');
1334 $src_db->sql_freeresult($result);
1336 if ($convert->mysql_convert && $same_db)
1338 $src_db->sql_query("SET NAMES 'utf8'");
1343 $convert->p_master->error($user->lang['CONV_ERROR_ATTACH_FTP_DIR'], __LINE__, __FILE__);
1346 return $upload_path;
1350 * Copy thumbnails of uploaded images from the 2.0.x forum
1351 * This is only used if the Attachment MOD was installed
1353 function phpbb_copy_thumbnails()
1355 global $db, $convert, $user, $config, $cache, $phpbb_root_path;
1357 $src_path = $convert->options['forum_path'] . '/' . phpbb_get_files_dir() . '/thumbs/';
1359 if ($handle = @opendir($src_path))
1361 while ($entry = readdir($handle))
1363 if ($entry[0] == '.')
1368 if (is_dir($src_path . $entry))
1374 copy_file($src_path . $entry, $config['upload_path'] . '/' . preg_replace('/^t_/', 'thumb_', $entry));
1375 @unlink($phpbb_root_path . $config['upload_path'] . '/thumbs/' . $entry);
1383 * Convert the attachment category constants
1384 * This is only used if the Attachment MOD was installed
1386 function phpbb_attachment_category($cat_id)
1391 return ATTACHMENT_CATEGORY_IMAGE;
1395 return ATTACHMENT_CATEGORY_WM;
1399 return ATTACHMENT_CATEGORY_FLASH;
1403 return ATTACHMENT_CATEGORY_NONE;
1407 * Obtain list of forums in which different attachment categories can be used
1409 function phpbb_attachment_forum_perms($forum_permissions)
1411 if (empty($forum_permissions))
1416 // Decode forum permissions
1417 $forum_ids = array();
1419 $one_char_encoding = '#';
1420 $two_char_encoding = '.';
1423 for ($pos = 0; $pos < strlen($forum_permissions); $pos += $auth_len)
1425 $forum_auth = substr($forum_permissions, $pos, 1);
1426 if ($forum_auth == $one_char_encoding)
1431 else if ($forum_auth == $two_char_encoding)
1438 $forum_auth = substr($forum_permissions, $pos, $auth_len);
1439 $forum_id = base64_unpack($forum_auth);
1441 $forum_ids[] = (int) $forum_id;
1444 if (sizeof($forum_ids))
1446 return attachment_forum_perms($forum_ids);
1453 * Convert the avatar type constants
1455 function phpbb_avatar_type($type)
1460 return AVATAR_UPLOAD;
1464 return AVATAR_REMOTE;
1468 return AVATAR_GALLERY;
1477 * Just undos the replacing of '<' and '>'
1479 function phpbb_smilie_html_decode($code)
1481 $code = str_replace('<', '<', $code);
1482 return str_replace('>', '>', $code);
1486 * Transfer avatars, copying the image if it was uploaded
1488 function phpbb_import_avatar($user_avatar)
1490 global $convert_row;
1492 if (!$convert_row['user_avatar_type'])
1496 else if ($convert_row['user_avatar_type'] == 1)
1499 return import_avatar($user_avatar, false, $convert_row['user_id']);
1501 else if ($convert_row['user_avatar_type'] == 2)
1504 return $user_avatar;
1506 else if ($convert_row['user_avatar_type'] == 3)
1509 return $user_avatar;
1517 * Find out about the avatar's dimensions
1519 function phpbb_get_avatar_height($user_avatar)
1521 global $convert_row;
1523 if (empty($convert_row['user_avatar_type']))
1527 return get_avatar_height($user_avatar, 'phpbb_avatar_type', $convert_row['user_avatar_type']);
1532 * Find out about the avatar's dimensions
1534 function phpbb_get_avatar_width($user_avatar)
1536 global $convert_row;
1538 if (empty($convert_row['user_avatar_type']))
1543 return get_avatar_width($user_avatar, 'phpbb_avatar_type', $convert_row['user_avatar_type']);
1548 * Calculate the correct to_address field for private messages
1550 function phpbb_privmsgs_to_userid($to_userid)
1554 return 'u_' . phpbb_user_id($to_userid);
1558 * Calculate whether a private message was unread using the bitfield
1560 function phpbb_unread_pm($pm_type)
1562 return ($pm_type == 5) ? 1 : 0;
1566 * Calculate whether a private message was new using the bitfield
1568 function phpbb_new_pm($pm_type)
1570 return ($pm_type == 1) ? 1 : 0;
1574 * Obtain the folder_id for the custom folder created to replace the savebox from 2.0.x (used to store saved private messages)
1576 function phpbb_get_savebox_id($user_id)
1580 $user_id = phpbb_user_id($user_id);
1582 // Only one custom folder, check only one
1583 $sql = 'SELECT folder_id
1584 FROM ' . PRIVMSGS_FOLDER_TABLE . '
1585 WHERE user_id = ' . $user_id;
1586 $result = $db->sql_query_limit($sql, 1);
1587 $folder_id = (int) $db->sql_fetchfield('folder_id');
1588 $db->sql_freeresult($result);
1594 * Transfer attachment specific configuration options
1595 * These were not stored in the main config table on 2.0.x
1596 * This is only used if the Attachment MOD was installed
1598 function phpbb_import_attach_config()
1600 global $db, $src_db, $same_db, $convert, $config;
1602 if ($convert->mysql_convert && $same_db)
1604 $src_db->sql_query("SET NAMES 'binary'");
1608 FROM ' . $convert->src_table_prefix . 'attachments_config';
1609 $result = $src_db->sql_query($sql);
1611 if ($convert->mysql_convert && $same_db)
1613 $src_db->sql_query("SET NAMES 'utf8'");
1616 $attach_config = array();
1617 while ($row = $src_db->sql_fetchrow($result))
1619 $attach_config[$row['config_name']] = $row['config_value'];
1621 $src_db->sql_freeresult($result);
1623 set_config('allow_attachments', 1);
1625 // old attachment mod? Must be very old if this entry do not exist...
1626 if (!empty($attach_config['display_order']))
1628 set_config('display_order', $attach_config['display_order']);
1630 set_config('max_filesize', $attach_config['max_filesize']);
1631 set_config('max_filesize_pm', $attach_config['max_filesize_pm']);
1632 set_config('attachment_quota', $attach_config['attachment_quota']);
1633 set_config('max_attachments', $attach_config['max_attachments']);
1634 set_config('max_attachments_pm', $attach_config['max_attachments_pm']);
1635 set_config('allow_pm_attach', $attach_config['allow_pm_attach']);
1637 set_config('img_display_inlined', $attach_config['img_display_inlined']);
1638 set_config('img_max_width', $attach_config['img_max_width']);
1639 set_config('img_max_height', $attach_config['img_max_height']);
1640 set_config('img_link_width', $attach_config['img_link_width']);
1641 set_config('img_link_height', $attach_config['img_link_height']);
1642 set_config('img_create_thumbnail', $attach_config['img_create_thumbnail']);
1643 set_config('img_max_thumb_width', 400);
1644 set_config('img_min_thumb_filesize', $attach_config['img_min_thumb_filesize']);
1645 set_config('img_imagick', $attach_config['img_imagick']);
1649 * Calculate the date a user became inactive
1651 function phpbb_inactive_time()
1653 global $convert_row;
1655 if ($convert_row['user_active'])
1660 if ($convert_row['user_lastvisit'])
1662 return $convert_row['user_lastvisit'];
1665 return $convert_row['user_regdate'];
1669 * Calculate the reason a user became inactive
1670 * We can't actually tell the difference between a manual deactivation and one for profile changes
1671 * from the data available to assume the latter
1673 function phpbb_inactive_reason()
1675 global $convert_row;
1677 if ($convert_row['user_active'])
1682 if ($convert_row['user_lastvisit'])
1684 return INACTIVE_PROFILE;
1687 return INACTIVE_REGISTER;
1691 * Adjust 2.0.x disallowed names to 3.0.x format
1693 function phpbb_disallowed_username($username)
1696 $username = phpbb_set_default_encoding(str_replace('*', '%', $username));
1697 return utf8_htmlspecialchars($username);
1701 * Checks whether there are any usernames on the old board that would map to the same
1702 * username_clean on phpBB3. Prints out a list if any exist and exits.
1704 function phpbb_create_userconv_table()
1706 global $db, $src_db, $convert, $table_prefix, $user, $lang;
1709 switch ($db->sql_layer)
1712 $map_dbms = 'mysql_40';
1716 if (version_compare($db->sql_server_info(true), '4.1.3', '>='))
1718 $map_dbms = 'mysql_41';
1722 $map_dbms = 'mysql_40';
1727 $map_dbms = 'mysql_41';
1733 $map_dbms = 'mssql';
1737 $map_dbms = $db->sql_layer;
1741 // create a temporary table in which we store the clean usernames
1742 $drop_sql = 'DROP TABLE ' . USERCONV_TABLE;
1746 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1747 user_id INTEGER NOT NULL,
1748 username_clean VARCHAR(255) CHARACTER SET UTF8 DEFAULT \'\' NOT NULL COLLATE UNICODE
1753 $create_sql = 'CREATE TABLE [' . USERCONV_TABLE . '] (
1754 [user_id] [int] NOT NULL ,
1755 [username_clean] [varchar] (255) DEFAULT (\'\') NOT NULL
1760 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1761 user_id mediumint(8) NOT NULL,
1762 username_clean blob NOT NULL
1767 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1768 user_id mediumint(8) NOT NULL,
1769 username_clean varchar(255) DEFAULT \'\' NOT NULL
1770 ) CHARACTER SET `utf8` COLLATE `utf8_bin`';
1774 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1775 user_id number(8) NOT NULL,
1776 username_clean varchar2(255) DEFAULT \'\'
1781 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1782 user_id INT4 DEFAULT \'0\',
1783 username_clean varchar_ci DEFAULT \'\' NOT NULL
1788 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1789 user_id INTEGER NOT NULL DEFAULT \'0\',
1790 username_clean varchar(255) NOT NULL DEFAULT \'\'
1795 $db->sql_return_on_error(true);
1796 $db->sql_query($drop_sql);
1797 $db->sql_return_on_error(false);
1798 $db->sql_query($create_sql);
1801 function phpbb_check_username_collisions()
1803 global $db, $src_db, $convert, $table_prefix, $user, $lang;
1805 // now find the clean version of the usernames that collide
1806 $sql = 'SELECT username_clean
1807 FROM ' . USERCONV_TABLE .'
1808 GROUP BY username_clean
1809 HAVING COUNT(user_id) > 1';
1810 $result = $db->sql_query($sql);
1812 $colliding_names = array();
1813 while ($row = $db->sql_fetchrow($result))
1815 $colliding_names[] = $row['username_clean'];
1817 $db->sql_freeresult($result);
1819 // there was at least one collision, the admin will have to solve it before conversion can continue
1820 if (sizeof($colliding_names))
1822 $sql = 'SELECT user_id, username_clean
1823 FROM ' . USERCONV_TABLE . '
1824 WHERE ' . $db->sql_in_set('username_clean', $colliding_names);
1825 $result = $db->sql_query($sql);
1826 unset($colliding_names);
1828 $colliding_user_ids = array();
1829 while ($row = $db->sql_fetchrow($result))
1831 $colliding_user_ids[(int) $row['user_id']] = $row['username_clean'];
1833 $db->sql_freeresult($result);
1835 $sql = 'SELECT username, user_id, user_posts
1836 FROM ' . $convert->src_table_prefix . 'users
1837 WHERE ' . $src_db->sql_in_set('user_id', array_keys($colliding_user_ids));
1838 $result = $src_db->sql_query($sql);
1840 $colliding_users = array();
1841 while ($row = $src_db->sql_fetchrow($result))
1843 $row['user_id'] = (int) $row['user_id'];
1844 if (isset($colliding_user_ids[$row['user_id']]))
1846 $colliding_users[$colliding_user_ids[$row['user_id']]][] = $row;
1849 $src_db->sql_freeresult($result);
1850 unset($colliding_user_ids);
1853 foreach ($colliding_users as $username_clean => $users)
1855 $list .= sprintf($user->lang['COLLIDING_CLEAN_USERNAME'], $username_clean) . "<br />\n";
1856 foreach ($users as $i => $row)
1858 $list .= sprintf($user->lang['COLLIDING_USER'], $row['user_id'], phpbb_set_default_encoding($row['username']), $row['user_posts']) . "<br />\n";
1862 $lang['INST_ERR_FATAL'] = $user->lang['CONV_ERR_FATAL'];
1863 $convert->p_master->error('<span style="color:red">' . $user->lang['COLLIDING_USERNAMES_FOUND'] . '</span></b><br /><br />' . $list . '<b>', __LINE__, __FILE__);
1866 $drop_sql = 'DROP TABLE ' . USERCONV_TABLE;
1867 $db->sql_query($drop_sql);