Update code_sniffer build.xml file to be executable on our system
[phpbb.git] / phpBB / install / convertors / functions_phpbb20.php
blob4b04f85ba74fe4d59fd3e02c185732216a0858cb
1 <?php
2 /**
4 * @package install
5 * @version $Id$
6 * @copyright (c) 2006 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 if (!defined('IN_PHPBB'))
13 exit;
16 /**
17 * Helper functions for phpBB 2.0.x to phpBB 3.0.x conversion
20 /**
21 * Set forum flags - only prune old polls by default
23 function phpbb_forum_flags()
25 // Set forum flags
26 $forum_flags = 0;
28 // FORUM_FLAG_LINK_TRACK
29 $forum_flags += 0;
31 // FORUM_FLAG_PRUNE_POLL
32 $forum_flags += FORUM_FLAG_PRUNE_POLL;
34 // FORUM_FLAG_PRUNE_ANNOUNCE
35 $forum_flags += 0;
37 // FORUM_FLAG_PRUNE_STICKY
38 $forum_flags += 0;
40 // FORUM_FLAG_ACTIVE_TOPICS
41 $forum_flags += 0;
43 // FORUM_FLAG_POST_REVIEW
44 $forum_flags += FORUM_FLAG_POST_REVIEW;
46 return $forum_flags;
49 /**
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);
65 $max_forum_id++;
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);
76 // Insert categories
77 $sql = 'SELECT cat_id, cat_title
78 FROM ' . $convert->src_table_prefix . 'categories
79 ORDER BY cat_order';
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 if ($db->dbms_type == 'mssql')
95 $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' ON');
98 $cats_added = array();
99 while ($row = $src_db->sql_fetchrow($result))
101 $sql_ary = array(
102 'forum_id' => (int) $max_forum_id,
103 'forum_name' => ($row['cat_title']) ? htmlspecialchars(phpbb_set_default_encoding($row['cat_title']), ENT_COMPAT, 'UTF-8') : $user->lang['CATEGORY'],
104 'parent_id' => 0,
105 'forum_parents' => '',
106 'forum_desc' => '',
107 'forum_type' => FORUM_CAT,
108 'forum_status' => ITEM_UNLOCKED,
109 'forum_rules' => '',
112 $sql = 'SELECT MAX(right_id) AS right_id
113 FROM ' . FORUMS_TABLE;
114 $_result = $db->sql_query($sql);
115 $cat_row = $db->sql_fetchrow($_result);
116 $db->sql_freeresult($_result);
118 $sql_ary['left_id'] = (int) ($cat_row['right_id'] + 1);
119 $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 2);
121 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
122 $db->sql_query($sql);
124 $cats_added[$row['cat_id']] = $max_forum_id;
125 $max_forum_id++;
127 $src_db->sql_freeresult($result);
129 // There may be installations having forums with non-existant category ids.
130 // We try to catch them and add them to an "unknown" category instead of leaving them out.
131 $sql = 'SELECT cat_id
132 FROM ' . $convert->src_table_prefix . 'forums
133 GROUP BY cat_id';
134 $result = $src_db->sql_query($sql);
136 $unknown_cat_id = false;
137 while ($row = $src_db->sql_fetchrow($result))
139 // Catch those categories not been added before
140 if (!isset($cats_added[$row['cat_id']]))
142 $unknown_cat_id = true;
145 $src_db->sql_freeresult($result);
147 // Is there at least one category not known?
148 if ($unknown_cat_id === true)
150 $unknown_cat_id = 'ghost';
152 $sql_ary = array(
153 'forum_id' => (int) $max_forum_id,
154 'forum_name' => (string) $user->lang['CATEGORY'],
155 'parent_id' => 0,
156 'forum_parents' => '',
157 'forum_desc' => '',
158 'forum_type' => FORUM_CAT,
159 'forum_status' => ITEM_UNLOCKED,
160 'forum_rules' => '',
163 $sql = 'SELECT MAX(right_id) AS right_id
164 FROM ' . FORUMS_TABLE;
165 $_result = $db->sql_query($sql);
166 $cat_row = $db->sql_fetchrow($_result);
167 $db->sql_freeresult($_result);
169 $sql_ary['left_id'] = (int) ($cat_row['right_id'] + 1);
170 $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 2);
172 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
173 $db->sql_query($sql);
175 $cats_added[$unknown_cat_id] = $max_forum_id;
176 $max_forum_id++;
179 // Now insert the forums
180 $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
181 LEFT JOIN ' . $convert->src_table_prefix . 'forum_prune fp ON f.forum_id = fp.forum_id
182 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
183 ORDER BY f.cat_id, f.forum_order';
185 if ($convert->mysql_convert && $same_db)
187 $src_db->sql_query("SET NAMES 'binary'");
190 $result = $src_db->sql_query($sql);
192 if ($convert->mysql_convert && $same_db)
194 $src_db->sql_query("SET NAMES 'utf8'");
197 while ($row = $src_db->sql_fetchrow($result))
199 // Some might have forums here with an id not being "possible"...
200 // To be somewhat friendly we "change" the category id for those to a previously created ghost category
201 if (!isset($cats_added[$row['cat_id']]) && $unknown_cat_id !== false)
203 $row['cat_id'] = $unknown_cat_id;
206 if (!isset($cats_added[$row['cat_id']]))
208 continue;
211 // Define the new forums sql ary
212 $sql_ary = array(
213 'forum_id' => (int) $row['forum_id'],
214 'forum_name' => htmlspecialchars(phpbb_set_default_encoding($row['forum_name']), ENT_COMPAT, 'UTF-8'),
215 'parent_id' => (int) $cats_added[$row['cat_id']],
216 'forum_parents' => '',
217 'forum_desc' => htmlspecialchars(phpbb_set_default_encoding($row['forum_desc']), ENT_COMPAT, 'UTF-8'),
218 'forum_type' => FORUM_POST,
219 'forum_status' => is_item_locked($row['forum_status']),
220 'enable_prune' => ($prune_enabled) ? (int)$row['prune_enable'] : 0,
221 'prune_next' => (int) null_to_zero($row['prune_next']),
222 'prune_days' => (int) null_to_zero($row['prune_days']),
223 'prune_viewed' => 0,
224 'prune_freq' => (int) null_to_zero($row['prune_freq']),
226 'forum_flags' => phpbb_forum_flags(),
228 // Default values
229 'forum_desc_bitfield' => '',
230 'forum_desc_options' => 7,
231 'forum_desc_uid' => '',
232 'forum_link' => '',
233 'forum_password' => '',
234 'forum_style' => 0,
235 'forum_image' => '',
236 'forum_rules' => '',
237 'forum_rules_link' => '',
238 'forum_rules_bitfield' => '',
239 'forum_rules_options' => 7,
240 'forum_rules_uid' => '',
241 'forum_topics_per_page' => 0,
242 'forum_posts' => 0,
243 'forum_topics' => 0,
244 'forum_topics_real' => 0,
245 'forum_last_post_id' => 0,
246 'forum_last_poster_id' => 0,
247 'forum_last_post_subject' => '',
248 'forum_last_post_time' => 0,
249 'forum_last_poster_name' => '',
250 'forum_last_poster_colour' => '',
251 'display_on_index' => 1,
252 'enable_indexing' => 1,
253 'enable_icons' => 0,
256 // Now add the forums with proper left/right ids
257 $sql = 'SELECT left_id, right_id
258 FROM ' . FORUMS_TABLE . '
259 WHERE forum_id = ' . $cats_added[$row['cat_id']];
260 $_result = $db->sql_query($sql);
261 $cat_row = $db->sql_fetchrow($_result);
262 $db->sql_freeresult($_result);
264 $sql = 'UPDATE ' . FORUMS_TABLE . '
265 SET left_id = left_id + 2, right_id = right_id + 2
266 WHERE left_id > ' . $cat_row['right_id'];
267 $db->sql_query($sql);
269 $sql = 'UPDATE ' . FORUMS_TABLE . '
270 SET right_id = right_id + 2
271 WHERE ' . $cat_row['left_id'] . ' BETWEEN left_id AND right_id';
272 $db->sql_query($sql);
274 $sql_ary['left_id'] = (int) $cat_row['right_id'];
275 $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 1);
277 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
278 $db->sql_query($sql);
280 $src_db->sql_freeresult($result);
282 switch ($db->dbms_type)
284 case 'postgres':
285 $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 . '));');
286 break;
288 case 'mssql':
289 $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' OFF');
290 break;
292 case 'oracle':
293 $result = $db->sql_query('SELECT MAX(forum_id) as max_id FROM ' . FORUMS_TABLE);
294 $row = $db->sql_fetchrow($result);
295 $db->sql_freeresult($result);
297 $largest_id = (int) $row['max_id'];
299 if ($largest_id)
301 $db->sql_query('DROP SEQUENCE ' . FORUMS_TABLE . '_seq');
302 $db->sql_query('CREATE SEQUENCE ' . FORUMS_TABLE . '_seq START WITH ' . ($largest_id + 1));
304 break;
309 * Function for recoding text with the default language
311 * @param string $text text to recode to utf8
312 * @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
314 function phpbb_set_encoding($text, $grab_user_lang = true)
316 global $lang_enc_array, $convert_row;
317 global $convert;
319 /*static $lang_enc_array = array(
320 'korean' => 'euc-kr',
321 'serbian' => 'windows-1250',
322 'polish' => 'iso-8859-2',
323 'kurdish' => 'windows-1254',
324 'slovak' => 'Windows-1250',
325 'russian' => 'windows-1251',
326 'estonian' => 'iso-8859-4',
327 'chinese_simplified' => 'gb2312',
328 'macedonian' => 'windows-1251',
329 'azerbaijani' => 'UTF-8',
330 'romanian' => 'iso-8859-2',
331 'romanian_diacritice' => 'iso-8859-2',
332 'lithuanian' => 'windows-1257',
333 'turkish' => 'iso-8859-9',
334 'ukrainian' => 'windows-1251',
335 'japanese' => 'shift_jis',
336 'hungarian' => 'ISO-8859-2',
337 'romanian_no_diacritics' => 'iso-8859-2',
338 'mongolian' => 'UTF-8',
339 'slovenian' => 'windows-1250',
340 'bosnian' => 'windows-1250',
341 'czech' => 'Windows-1250',
342 'farsi' => 'Windows-1256',
343 'croatian' => 'windows-1250',
344 'greek' => 'iso-8859-7',
345 'russian_tu' => 'windows-1251',
346 'sakha' => 'UTF-8',
347 'serbian_cyrillic' => 'windows-1251',
348 'bulgarian' => 'windows-1251',
349 'chinese_traditional_taiwan' => 'big5',
350 'chinese_traditional' => 'big5',
351 'arabic' => 'windows-1256',
352 'hebrew' => 'WINDOWS-1255',
353 'thai' => 'windows-874',
354 //'chinese_traditional_taiwan' => 'utf-8' // custom modified, we may have to do an include :-(
355 );*/
357 if (empty($lang_enc_array))
359 $lang_enc_array = array();
362 $get_lang = trim(get_config_value('default_lang'));
364 // Do we need the users language encoding?
365 if ($grab_user_lang && !empty($convert_row))
367 if (!empty($convert_row['user_lang']))
369 $get_lang = trim($convert_row['user_lang']);
371 else if (!empty($convert_row['poster_id']))
373 global $src_db, $same_db;
375 if ($convert->mysql_convert && $same_db)
377 $src_db->sql_query("SET NAMES 'binary'");
380 $sql = 'SELECT user_lang
381 FROM ' . $convert->src_table_prefix . 'users
382 WHERE user_id = ' . (int) $convert_row['poster_id'];
383 $result = $src_db->sql_query($sql);
384 $get_lang = (string) $src_db->sql_fetchfield('user_lang');
385 $src_db->sql_freeresult($result);
387 if ($convert->mysql_convert && $same_db)
389 $src_db->sql_query("SET NAMES 'utf8'");
392 $get_lang = (!trim($get_lang)) ? trim(get_config_value('default_lang')) : trim($get_lang);
396 if (!isset($lang_enc_array[$get_lang]))
398 $filename = $convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . PHP_EXT;
400 if (!file_exists($filename))
402 $get_lang = trim(get_config_value('default_lang'));
405 if (!isset($lang_enc_array[$get_lang]))
407 include($convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . PHP_EXT);
408 $lang_enc_array[$get_lang] = $lang['ENCODING'];
409 unset($lang);
413 $encoding = $lang_enc_array[$get_lang];
415 return utf8_recode($text, $lang_enc_array[$get_lang]);
419 * Same as phpbb_set_encoding, but forcing boards default language
421 function phpbb_set_default_encoding($text)
423 return phpbb_set_encoding($text, false);
427 * Convert Birthday from Birthday MOD to phpBB Format
429 function phpbb_get_birthday($birthday = '')
431 if (defined('MOD_BIRTHDAY_TERRA'))
433 $birthday = (string) $birthday;
435 // stored as month, day, year
436 if (!$birthday)
438 return ' 0- 0- 0';
441 // We use the original mod code to retrieve the birthday (not ideal)
442 preg_match('/(..)(..)(....)/', sprintf('%08d', $birthday), $birthday_parts);
444 $month = $birthday_parts[1];
445 $day = $birthday_parts[2];
446 $year = $birthday_parts[3];
448 return sprintf('%2d-%2d-%4d', $day, $month, $year);
450 else
452 $birthday = (int) $birthday;
454 if (!$birthday || $birthday == 999999 || $birthday < 0)
456 return ' 0- 0- 0';
459 // The birthday mod from niels is using this code to transform to day/month/year
460 return sprintf('%2d-%2d-%4d', gmdate('j', $birthday * 86400 + 1), gmdate('n', $birthday * 86400 + 1), gmdate('Y', $birthday * 86400 + 1));
465 * Return correct user id value
466 * Everyone's id will be one higher to allow the guest/anonymous user to have a positive id as well
468 function phpbb_user_id($user_id)
470 global $config;
472 // Increment user id if the old forum is having a user with the id 1
473 if (!isset($config['increment_user_id']))
475 global $src_db, $same_db, $convert;
477 if ($convert->mysql_convert && $same_db)
479 $src_db->sql_query("SET NAMES 'binary'");
482 // Now let us set a temporary config variable for user id incrementing
483 $sql = "SELECT user_id
484 FROM {$convert->src_table_prefix}users
485 WHERE user_id = 1";
486 $result = $src_db->sql_query($sql);
487 $id = (int) $src_db->sql_fetchfield('user_id');
488 $src_db->sql_freeresult($result);
490 // Try to get the maximum user id possible...
491 $sql = "SELECT MAX(user_id) AS max_user_id
492 FROM {$convert->src_table_prefix}users";
493 $result = $src_db->sql_query($sql);
494 $max_id = (int) $src_db->sql_fetchfield('max_user_id');
495 $src_db->sql_freeresult($result);
497 if ($convert->mysql_convert && $same_db)
499 $src_db->sql_query("SET NAMES 'utf8'");
502 // If there is a user id 1, we need to increment user ids. :/
503 if ($id === 1)
505 set_config('increment_user_id', ($max_id + 1), true);
506 $config['increment_user_id'] = $max_id + 1;
508 else
510 set_config('increment_user_id', 0, true);
511 $config['increment_user_id'] = 0;
515 // If the old user id is -1 in 2.0.x it is the anonymous user...
516 if ($user_id == -1)
518 return ANONYMOUS;
521 if (!empty($config['increment_user_id']) && $user_id == 1)
523 return $config['increment_user_id'];
526 // A user id of 0 can happen, for example within the ban table if no user is banned...
527 // Within the posts and topics table this can be "dangerous" but is the fault of the user
528 // having mods installed (a poster id of 0 is not possible in 2.0.x).
529 // Therefore, we return the user id "as is".
531 return (int) $user_id;
534 /* Copy additional table fields from old forum to new forum if user wants this (for Mod compatibility for example)
535 function phpbb_copy_table_fields()
541 * Convert authentication
542 * user, group and forum table has to be filled in order to work
544 function phpbb_convert_authentication($mode)
546 global $db, $src_db, $same_db, $convert, $user, $config;
548 if ($mode == 'start')
550 $db->sql_query($convert->truncate_statement . ACL_USERS_TABLE);
551 $db->sql_query($convert->truncate_statement . ACL_GROUPS_TABLE);
553 // What we will do is handling all 2.0.x admins as founder to replicate what is common in 2.0.x.
554 // After conversion the main admin need to make sure he is removing permissions and the founder status if wanted.
557 // Grab user ids of users with user_level of ADMIN
558 $sql = "SELECT user_id
559 FROM {$convert->src_table_prefix}users
560 WHERE user_level = 1
561 ORDER BY user_regdate ASC";
562 $result = $src_db->sql_query($sql);
564 while ($row = $src_db->sql_fetchrow($result))
566 $user_id = (int) phpbb_user_id($row['user_id']);
567 // Set founder admin...
568 $sql = 'UPDATE ' . USERS_TABLE . '
569 SET user_type = ' . USER_FOUNDER . "
570 WHERE user_id = $user_id";
571 $db->sql_query($sql);
573 $src_db->sql_freeresult($result);
575 $sql = 'SELECT group_id
576 FROM ' . GROUPS_TABLE . "
577 WHERE group_name_clean = '" . $db->sql_escape('bots') . "'";
578 $result = $db->sql_query($sql);
579 $bot_group_id = (int) $db->sql_fetchfield('group_id');
580 $db->sql_freeresult($result);
583 // Grab forum auth information
584 $sql = "SELECT *
585 FROM {$convert->src_table_prefix}forums";
586 $result = $src_db->sql_query($sql);
588 $forum_access = array();
589 while ($row = $src_db->sql_fetchrow($result))
591 $forum_access[$row['forum_id']] = $row;
593 $src_db->sql_freeresult($result);
595 if ($convert->mysql_convert && $same_db)
597 $src_db->sql_query("SET NAMES 'binary'");
599 // Grab user auth information from 2.0.x board
600 $sql = "SELECT ug.user_id, aa.*
601 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
602 WHERE g.group_id = aa.group_id
603 AND g.group_single_user = 1
604 AND ug.group_id = g.group_id
605 AND f.forum_id = aa.forum_id";
606 $result = $src_db->sql_query($sql);
608 $user_access = array();
609 while ($row = $src_db->sql_fetchrow($result))
611 $user_access[$row['forum_id']][] = $row;
613 $src_db->sql_freeresult($result);
615 // Grab group auth information
616 $sql = "SELECT g.group_id, aa.*
617 FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}groups g
618 WHERE g.group_id = aa.group_id
619 AND g.group_single_user <> 1";
620 $result = $src_db->sql_query($sql);
622 $group_access = array();
623 while ($row = $src_db->sql_fetchrow($result))
625 $group_access[$row['forum_id']][] = $row;
627 $src_db->sql_freeresult($result);
629 if ($convert->mysql_convert && $same_db)
631 $src_db->sql_query("SET NAMES 'utf8'");
634 // Add Forum Access List
635 $auth_map = array(
636 'auth_view' => array('f_', 'f_list'),
637 'auth_read' => array('f_read', 'f_search'),
638 'auth_post' => array('f_post', 'f_bbcode', 'f_smilies', 'f_img', 'f_sigs', 'f_postcount', 'f_report', 'f_subscribe', 'f_print', 'f_email'),
639 'auth_reply' => 'f_reply',
640 'auth_edit' => 'f_edit',
641 'auth_delete' => 'f_delete',
642 'auth_pollcreate' => 'f_poll',
643 'auth_vote' => 'f_vote',
644 'auth_announce' => 'f_announce',
645 'auth_sticky' => 'f_sticky',
646 'auth_attachments' => array('f_attach', 'f_download'),
647 'auth_download' => 'f_download',
650 // Define the ACL constants used in 2.0 to make the code slightly more readable
651 define('AUTH_ALL', 0);
652 define('AUTH_REG', 1);
653 define('AUTH_ACL', 2);
654 define('AUTH_MOD', 3);
655 define('AUTH_ADMIN', 5);
657 // A mapping of the simple permissions used by 2.0
658 $simple_auth_ary = array(
659 'public' => array(
660 'auth_view' => AUTH_ALL,
661 'auth_read' => AUTH_ALL,
662 'auth_post' => AUTH_ALL,
663 'auth_reply' => AUTH_ALL,
664 'auth_edit' => AUTH_REG,
665 'auth_delete' => AUTH_REG,
666 'auth_sticky' => AUTH_MOD,
667 'auth_announce' => AUTH_MOD,
668 'auth_vote' => AUTH_REG,
669 'auth_pollcreate' => AUTH_REG,
671 'registered' => array(
672 'auth_view' => AUTH_ALL,
673 'auth_read' => AUTH_ALL,
674 'auth_post' => AUTH_REG,
675 'auth_reply' => AUTH_REG,
676 'auth_edit' => AUTH_REG,
677 'auth_delete' => AUTH_REG,
678 'auth_sticky' => AUTH_MOD,
679 'auth_announce' => AUTH_MOD,
680 'auth_vote' => AUTH_REG,
681 'auth_pollcreate' => AUTH_REG,
683 'registered_hidden' => array(
684 'auth_view' => AUTH_REG,
685 'auth_read' => AUTH_REG,
686 'auth_post' => AUTH_REG,
687 'auth_reply' => AUTH_REG,
688 'auth_edit' => AUTH_REG,
689 'auth_delete' => AUTH_REG,
690 'auth_sticky' => AUTH_MOD,
691 'auth_announce' => AUTH_MOD,
692 'auth_vote' => AUTH_REG,
693 'auth_pollcreate' => AUTH_REG,
695 'private' => array(
696 'auth_view' => AUTH_ALL,
697 'auth_read' => AUTH_ACL,
698 'auth_post' => AUTH_ACL,
699 'auth_reply' => AUTH_ACL,
700 'auth_edit' => AUTH_ACL,
701 'auth_delete' => AUTH_ACL,
702 'auth_sticky' => AUTH_ACL,
703 'auth_announce' => AUTH_MOD,
704 'auth_vote' => AUTH_ACL,
705 'auth_pollcreate' => AUTH_ACL,
707 'private_hidden' => array(
708 'auth_view' => AUTH_ACL,
709 'auth_read' => AUTH_ACL,
710 'auth_post' => AUTH_ACL,
711 'auth_reply' => AUTH_ACL,
712 'auth_edit' => AUTH_ACL,
713 'auth_delete' => AUTH_ACL,
714 'auth_sticky' => AUTH_ACL,
715 'auth_announce' => AUTH_MOD,
716 'auth_vote' => AUTH_ACL,
717 'auth_pollcreate' => AUTH_ACL,
719 'moderator' => array(
720 'auth_view' => AUTH_ALL,
721 'auth_read' => AUTH_MOD,
722 'auth_post' => AUTH_MOD,
723 'auth_reply' => AUTH_MOD,
724 'auth_edit' => AUTH_MOD,
725 'auth_delete' => AUTH_MOD,
726 'auth_sticky' => AUTH_MOD,
727 'auth_announce' => AUTH_MOD,
728 'auth_vote' => AUTH_MOD,
729 'auth_pollcreate' => AUTH_MOD,
731 'moderator_hidden' => array(
732 'auth_view' => AUTH_MOD,
733 'auth_read' => AUTH_MOD,
734 'auth_post' => AUTH_MOD,
735 'auth_reply' => AUTH_MOD,
736 'auth_edit' => AUTH_MOD,
737 'auth_delete' => AUTH_MOD,
738 'auth_sticky' => AUTH_MOD,
739 'auth_announce' => AUTH_MOD,
740 'auth_vote' => AUTH_MOD,
741 'auth_pollcreate' => AUTH_MOD,
745 if ($mode == 'start')
747 user_group_auth('guests', 'SELECT user_id, {GUESTS} FROM ' . USERS_TABLE . ' WHERE user_id = ' . ANONYMOUS, false);
748 user_group_auth('registered', 'SELECT user_id, {REGISTERED} FROM ' . USERS_TABLE . ' WHERE user_id <> ' . ANONYMOUS . " AND group_id <> $bot_group_id", false);
750 // Selecting from old table
751 if (!empty($config['increment_user_id']))
753 $auth_sql = 'SELECT user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id <> 1';
754 user_group_auth('administrators', $auth_sql, true);
756 $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';
757 user_group_auth('administrators', $auth_sql, true);
759 else
761 $auth_sql = 'SELECT user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1';
762 user_group_auth('administrators', $auth_sql, true);
765 if (!empty($config['increment_user_id']))
767 $auth_sql = 'SELECT user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id <> 1';
768 user_group_auth('global_moderators', $auth_sql, true);
770 $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';
771 user_group_auth('global_moderators', $auth_sql, true);
773 else
775 $auth_sql = 'SELECT user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1';
776 user_group_auth('global_moderators', $auth_sql, true);
779 else if ($mode == 'first')
781 // Go through all 2.0.x forums
782 foreach ($forum_access as $forum)
784 $new_forum_id = (int) $forum['forum_id'];
786 // Administrators have full access to all forums whatever happens
787 mass_auth('group_role', $new_forum_id, 'administrators', 'FORUM_FULL');
789 $matched_type = '';
790 foreach ($simple_auth_ary as $key => $auth_levels)
792 $matched = 1;
793 foreach ($auth_levels as $k => $level)
795 if ($forum[$k] != $auth_levels[$k])
797 $matched = 0;
801 if ($matched)
803 $matched_type = $key;
804 break;
808 switch ($matched_type)
810 case 'public':
811 mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_LIMITED');
812 mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_LIMITED_POLLS');
813 mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
814 break;
816 case 'registered':
817 mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_READONLY');
818 mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
820 // no break;
822 case 'registered_hidden':
823 mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_POLLS');
824 break;
826 case 'private':
827 case 'private_hidden':
828 case 'moderator':
829 case 'moderator_hidden':
830 default:
831 // The permissions don't match a simple set, so we're going to have to map them directly
833 // No post approval for all, in 2.0.x this feature does not exist
834 mass_auth('group', $new_forum_id, 'guests', 'f_noapprove', ACL_YES);
835 mass_auth('group', $new_forum_id, 'registered', 'f_noapprove', ACL_YES);
837 // Go through authentication map
838 foreach ($auth_map as $old_auth_key => $new_acl)
840 // If old authentication key does not exist we continue
841 // This is helpful for mods adding additional authentication fields, we need to add them to the auth_map array
842 if (!isset($forum[$old_auth_key]))
844 continue;
847 // Now set the new ACL correctly
848 switch ($forum[$old_auth_key])
850 // AUTH_ALL
851 case AUTH_ALL:
852 mass_auth('group', $new_forum_id, 'guests', $new_acl, ACL_YES);
853 mass_auth('group', $new_forum_id, 'bots', $new_acl, ACL_YES);
854 mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
855 break;
857 // AUTH_REG
858 case AUTH_REG:
859 mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
860 break;
862 // AUTH_ACL
863 case AUTH_ACL:
864 // Go through the old group access list for this forum
865 if (isset($group_access[$forum['forum_id']]))
867 foreach ($group_access[$forum['forum_id']] as $index => $access)
869 // We only check for ACL_YES equivalence entry
870 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
872 mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
877 if (isset($user_access[$forum['forum_id']]))
879 foreach ($user_access[$forum['forum_id']] as $index => $access)
881 // We only check for ACL_YES equivalence entry
882 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
884 mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
888 break;
890 // AUTH_MOD
891 case AUTH_MOD:
892 if (isset($group_access[$forum['forum_id']]))
894 foreach ($group_access[$forum['forum_id']] as $index => $access)
896 // We only check for ACL_YES equivalence entry
897 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
899 mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
904 if (isset($user_access[$forum['forum_id']]))
906 foreach ($user_access[$forum['forum_id']] as $index => $access)
908 // We only check for ACL_YES equivalence entry
909 if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
911 mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
915 break;
918 break;
922 else if ($mode == 'second')
924 // Assign permission roles and other default permissions
926 // guests having u_download and u_search ability
927 $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')");
929 // administrators/global mods having full user features
930 mass_auth('group_role', 0, 'administrators', 'USER_FULL');
931 mass_auth('group_role', 0, 'global_moderators', 'USER_FULL');
933 // By default all converted administrators are given full access
934 mass_auth('group_role', 0, 'administrators', 'ADMIN_FULL');
936 // All registered users are assigned the standard user role
937 mass_auth('group_role', 0, 'registered', 'USER_STANDARD');
938 mass_auth('group_role', 0, 'registered_coppa', 'USER_STANDARD');
940 // Instead of administrators being global moderators we give the MOD_FULL role to global mods (admins already assigned to this group)
941 mass_auth('group_role', 0, 'global_moderators', 'MOD_FULL');
943 // And now those who have had their avatar rights removed get assigned a more restrictive role
944 $sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
945 WHERE user_allowavatar = 0
946 AND user_id > 0';
947 $result = $src_db->sql_query($sql);
949 while ($row = $src_db->sql_fetchrow($result))
951 mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOAVATAR');
953 $src_db->sql_freeresult($result);
955 // And the same for those who have had their PM rights removed
956 $sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
957 WHERE user_allow_pm = 0
958 AND user_id > 0';
959 $result = $src_db->sql_query($sql);
961 while ($row = $src_db->sql_fetchrow($result))
963 mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOPM');
965 $src_db->sql_freeresult($result);
967 else if ($mode == 'third')
969 // And now the moderators
970 // We make sure that they have at least standard access to the forums they moderate in addition to the moderating permissions
972 $mod_post_map = array(
973 'auth_announce' => 'f_announce',
974 'auth_sticky' => 'f_sticky'
977 foreach ($user_access as $forum_id => $access_map)
979 $forum_id = (int) $forum_id;
981 foreach ($access_map as $access)
983 if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
985 mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'MOD_STANDARD');
986 mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'FORUM_STANDARD');
987 foreach ($mod_post_map as $old => $new)
989 if (isset($forum_access[$forum_id]) && isset($forum_access[$forum_id][$old]) && $forum_access[$forum_id][$old] == AUTH_MOD)
991 mass_auth('user', $forum_id, (int) phpbb_user_id($access['user_id']), $new, ACL_YES);
998 foreach ($group_access as $forum_id => $access_map)
1000 $forum_id = (int) $forum_id;
1002 foreach ($access_map as $access)
1004 if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
1006 mass_auth('group_role', $forum_id, (int) $access['group_id'], 'MOD_STANDARD');
1007 mass_auth('group_role', $forum_id, (int) $access['group_id'], 'FORUM_STANDARD');
1008 foreach ($mod_post_map as $old => $new)
1010 if (isset($forum_access[$forum_id]) && isset($forum_access[$forum_id][$old]) && $forum_access[$forum_id][$old] == AUTH_MOD)
1012 mass_auth('group', $forum_id, (int) $access['group_id'], $new, ACL_YES);
1019 // We grant everyone readonly access to the categories to ensure that the forums are visible
1020 $sql = 'SELECT forum_id, forum_name, parent_id, left_id, right_id
1021 FROM ' . FORUMS_TABLE . '
1022 ORDER BY left_id ASC';
1023 $result = $db->sql_query($sql);
1025 $parent_forums = $forums = array();
1026 while ($row = $db->sql_fetchrow($result))
1028 if ($row['parent_id'] == 0)
1030 mass_auth('group_role', $row['forum_id'], 'administrators', 'FORUM_FULL');
1031 mass_auth('group_role', $row['forum_id'], 'global_moderators', 'FORUM_FULL');
1032 $parent_forums[] = $row;
1034 else
1036 $forums[] = $row;
1039 $db->sql_freeresult($result);
1041 global $auth;
1043 // Let us see which groups have access to these forums...
1044 foreach ($parent_forums as $row)
1046 // Get the children
1047 $branch = $forum_ids = array();
1049 foreach ($forums as $key => $_row)
1051 if ($_row['left_id'] > $row['left_id'] && $_row['left_id'] < $row['right_id'])
1053 $branch[] = $_row;
1054 $forum_ids[] = $_row['forum_id'];
1055 continue;
1059 if (sizeof($forum_ids))
1061 // Now make sure the user is able to read these forums
1062 $hold_ary = $auth->acl_group_raw_data(false, 'f_list', $forum_ids);
1064 if (empty($hold_ary))
1066 continue;
1069 foreach ($hold_ary as $g_id => $f_id_ary)
1071 $set_group = false;
1073 foreach ($f_id_ary as $f_id => $auth_ary)
1075 foreach ($auth_ary as $auth_option => $setting)
1077 if ($setting == ACL_YES)
1079 $set_group = true;
1080 break 2;
1085 if ($set_group)
1087 mass_auth('group', $row['forum_id'], $g_id, 'f_list', ACL_YES);
1096 * Set primary group.
1097 * Really simple and only based on user_level (remaining groups will be assigned later)
1099 function phpbb_set_primary_group($user_level)
1101 global $convert_row;
1103 if ($user_level == 1)
1105 return get_group_id('administrators');
1107 /* else if ($user_level == 2)
1109 return get_group_id('global_moderators');
1111 else if ($user_level == 0 && $convert_row['user_active'])*/
1112 else if ($convert_row['user_active'])
1114 return get_group_id('registered');
1117 return 0;
1121 * Convert the group name, making sure to avoid conflicts with 3.0 special groups
1123 function phpbb_convert_group_name($group_name)
1125 $default_groups = array(
1126 'GUESTS',
1127 'REGISTERED',
1128 'REGISTERED_COPPA',
1129 'GLOBAL_MODERATORS',
1130 'ADMINISTRATORS',
1131 'BOTS',
1134 if (in_array(strtoupper($group_name), $default_groups))
1136 return 'phpBB2 - ' . $group_name;
1139 return phpbb_set_default_encoding($group_name);
1143 * Convert the group name, making sure to avoid conflicts with 3.0 special groups
1145 function phpbb_convert_group_name_clean($group_name)
1147 $default_groups = array(
1148 'GUESTS',
1149 'REGISTERED',
1150 'REGISTERED_COPPA',
1151 'GLOBAL_MODERATORS',
1152 'ADMINISTRATORS',
1153 'BOTS',
1156 if (in_array(strtoupper($group_name), $default_groups))
1158 return utf8_clean_string('phpBB2 - ' . $group_name);
1161 return utf8_clean_string(phpbb_set_default_encoding($group_name));
1165 * Convert the group type constants
1167 function phpbb_convert_group_type($group_type)
1169 switch ($group_type)
1171 case 0:
1172 return GROUP_OPEN;
1173 break;
1175 case 1:
1176 return GROUP_CLOSED;
1177 break;
1179 case 2:
1180 return GROUP_HIDDEN;
1181 break;
1184 // Never return GROUP_SPECIAL here, because only phpBB3's default groups are allowed to have this type set.
1185 return GROUP_HIDDEN;
1189 * Convert the topic type constants
1191 function phpbb_convert_topic_type($topic_type)
1193 switch ($topic_type)
1195 case 0:
1196 return POST_NORMAL;
1197 break;
1199 case 1:
1200 return POST_STICKY;
1201 break;
1203 case 2:
1204 return POST_ANNOUNCE;
1205 break;
1207 case 3:
1208 return POST_GLOBAL;
1209 break;
1212 return POST_NORMAL;
1215 function phpbb_replace_size($matches)
1217 return '[size=' . min(200, ceil(100.0 * (((double) $matches[1])/12.0))) . ':' . $matches[2] . ']';
1221 * Reparse the message stripping out the bbcode_uid values and adding new ones and setting the bitfield
1222 * @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
1224 function phpbb_prepare_message($message)
1226 global $db, $convert, $user, $config, $convert_row, $message_parser;
1228 if (!$message)
1230 $convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = 0;
1231 return '';
1234 // Decode phpBB 2.0.x Message
1235 if (isset($convert->row['old_bbcode_uid']) && $convert->row['old_bbcode_uid'] != '')
1237 // Adjust size...
1238 if (strpos($message, '[size=') !== false)
1240 $message = preg_replace_callback('/\[size=(\d*):(' . $convert->row['old_bbcode_uid'] . ')\]/', 'phpbb_replace_size', $message);
1243 $message = preg_replace('/\:(([a-z0-9]:)?)' . $convert->row['old_bbcode_uid'] . '/s', '', $message);
1246 if (strpos($message, '[quote=') !== false)
1248 $message = preg_replace('/\[quote="(.*?)"\]/s', '[quote=&quot;\1&quot;]', $message);
1249 $message = preg_replace('/\[quote=\\\"(.*?)\\\"\]/s', '[quote=&quot;\1&quot;]', $message);
1251 // let's hope that this solves more problems than it causes. Deal with escaped quotes.
1252 $message = str_replace('\"', '&quot;', $message);
1253 $message = str_replace('\&quot;', '&quot;', $message);
1256 // Already the new user id ;)
1257 $user_id = $convert->row['poster_id'];
1259 $message = str_replace('<', '&lt;', $message);
1260 $message = str_replace('>', '&gt;', $message);
1261 $message = str_replace('<br />', "\n", $message);
1263 // make the post UTF-8
1264 $message = phpbb_set_encoding($message);
1266 $message_parser->warn_msg = array(); // Reset the errors from the previous message
1267 $message_parser->bbcode_uid = make_uid($convert->row['post_time']);
1268 $message_parser->message = $message;
1269 unset($message);
1271 // Make sure options are set.
1272 // $enable_html = (!isset($row['enable_html'])) ? false : $row['enable_html'];
1273 $enable_bbcode = (!isset($convert->row['enable_bbcode'])) ? true : $convert->row['enable_bbcode'];
1274 $enable_smilies = (!isset($convert->row['enable_smilies'])) ? true : $convert->row['enable_smilies'];
1275 $enable_magic_url = (!isset($convert->row['enable_magic_url'])) ? true : $convert->row['enable_magic_url'];
1277 // 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')
1278 $message_parser->parse($enable_bbcode, $enable_magic_url, $enable_smilies);
1280 if (sizeof($message_parser->warn_msg))
1282 $msg_id = isset($convert->row['post_id']) ? $convert->row['post_id'] : $convert->row['privmsgs_id'];
1283 $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);
1286 $convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = $message_parser->bbcode_bitfield;
1288 $message = $message_parser->message;
1289 unset($message_parser->message);
1291 return $message;
1295 * Return the bitfield calculated by the previous function
1297 function get_bbcode_bitfield()
1299 global $convert_row;
1301 return $convert_row['mp_bbcode_bitfield'];
1305 * Determine the last user to edit a post
1306 * 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
1308 function phpbb_post_edit_user()
1310 global $convert_row, $config;
1312 if (isset($convert_row['post_edit_count']))
1314 return phpbb_user_id($convert_row['poster_id']);
1317 return 0;
1321 * Obtain the path to uploaded files on the 2.0.x forum
1322 * This is only used if the Attachment MOD was installed
1324 function phpbb_get_files_dir()
1326 if (!defined('MOD_ATTACHMENT'))
1328 return;
1331 global $src_db, $same_db, $convert, $user, $config;
1333 if ($convert->mysql_convert && $same_db)
1335 $src_db->sql_query("SET NAMES 'binary'");
1337 $sql = 'SELECT config_value AS upload_dir
1338 FROM ' . $convert->src_table_prefix . "attachments_config
1339 WHERE config_name = 'upload_dir'";
1340 $result = $src_db->sql_query($sql);
1341 $upload_path = $src_db->sql_fetchfield('upload_dir');
1342 $src_db->sql_freeresult($result);
1344 $sql = 'SELECT config_value AS ftp_upload
1345 FROM ' . $convert->src_table_prefix . "attachments_config
1346 WHERE config_name = 'allow_ftp_upload'";
1347 $result = $src_db->sql_query($sql);
1348 $ftp_upload = (int) $src_db->sql_fetchfield('ftp_upload');
1349 $src_db->sql_freeresult($result);
1351 if ($convert->mysql_convert && $same_db)
1353 $src_db->sql_query("SET NAMES 'utf8'");
1356 if ($ftp_upload)
1358 $convert->p_master->error($user->lang['CONV_ERROR_ATTACH_FTP_DIR'], __LINE__, __FILE__);
1361 return $upload_path;
1365 * Copy thumbnails of uploaded images from the 2.0.x forum
1366 * This is only used if the Attachment MOD was installed
1368 function phpbb_copy_thumbnails()
1370 global $db, $convert, $user, $config;
1372 $src_path = $convert->options['forum_path'] . '/' . phpbb_get_files_dir() . '/thumbs/';
1374 if ($handle = @opendir($src_path))
1376 while ($entry = readdir($handle))
1378 if ($entry[0] == '.')
1380 continue;
1383 if (is_dir($src_path . $entry))
1385 continue;
1387 else
1389 copy_file($src_path . $entry, $config['upload_path'] . '/' . preg_replace('/^t_/', 'thumb_', $entry));
1390 @unlink(PHPBB_ROOT_PATH . $config['upload_path'] . '/thumbs/' . $entry);
1393 closedir($handle);
1398 * Convert the attachment category constants
1399 * This is only used if the Attachment MOD was installed
1401 function phpbb_attachment_category($cat_id)
1403 switch ($cat_id)
1405 case 1:
1406 return ATTACHMENT_CATEGORY_IMAGE;
1407 break;
1409 case 2:
1410 return ATTACHMENT_CATEGORY_WM;
1411 break;
1413 case 3:
1414 return ATTACHMENT_CATEGORY_FLASH;
1415 break;
1418 return ATTACHMENT_CATEGORY_NONE;
1422 * Obtain list of forums in which different attachment categories can be used
1424 function phpbb_attachment_forum_perms($forum_permissions)
1426 if (empty($forum_permissions))
1428 return '';
1431 // Decode forum permissions
1432 $forum_ids = array();
1434 $one_char_encoding = '#';
1435 $two_char_encoding = '.';
1437 $auth_len = 1;
1438 for ($pos = 0; $pos < strlen($forum_permissions); $pos += $auth_len)
1440 $forum_auth = substr($forum_permissions, $pos, 1);
1441 if ($forum_auth == $one_char_encoding)
1443 $auth_len = 1;
1444 continue;
1446 else if ($forum_auth == $two_char_encoding)
1448 $auth_len = 2;
1449 $pos--;
1450 continue;
1453 $forum_auth = substr($forum_permissions, $pos, $auth_len);
1454 $forum_id = base64_unpack($forum_auth);
1456 $forum_ids[] = (int) $forum_id;
1459 if (sizeof($forum_ids))
1461 return attachment_forum_perms($forum_ids);
1464 return '';
1468 * Convert the avatar type constants
1470 function phpbb_avatar_type($type)
1472 switch ($type)
1474 case 1:
1475 return AVATAR_UPLOAD;
1476 break;
1478 case 2:
1479 return AVATAR_REMOTE;
1480 break;
1482 case 3:
1483 return AVATAR_GALLERY;
1484 break;
1487 return 0;
1492 * Just undos the replacing of '<' and '>'
1494 function phpbb_smilie_html_decode($code)
1496 $code = str_replace('&lt;', '<', $code);
1497 return str_replace('&gt;', '>', $code);
1501 * Transfer avatars, copying the image if it was uploaded
1503 function phpbb_import_avatar($user_avatar)
1505 global $convert_row;
1507 if (!$convert_row['user_avatar_type'])
1509 return '';
1511 else if ($convert_row['user_avatar_type'] == 1)
1513 // Uploaded avatar
1514 return import_avatar($user_avatar, false, $convert_row['user_id']);
1516 else if ($convert_row['user_avatar_type'] == 2)
1518 // Remote avatar
1519 return $user_avatar;
1521 else if ($convert_row['user_avatar_type'] == 3)
1523 // Gallery avatar
1524 return $user_avatar;
1527 return '';
1532 * Find out about the avatar's dimensions
1534 function phpbb_get_avatar_height($user_avatar)
1536 global $convert_row;
1538 if (empty($convert_row['user_avatar_type']))
1540 return 0;
1542 return get_avatar_height($user_avatar, 'phpbb_avatar_type', $convert_row['user_avatar_type']);
1547 * Find out about the avatar's dimensions
1549 function phpbb_get_avatar_width($user_avatar)
1551 global $convert_row;
1553 if (empty($convert_row['user_avatar_type']))
1555 return 0;
1558 return get_avatar_width($user_avatar, 'phpbb_avatar_type', $convert_row['user_avatar_type']);
1563 * Calculate the correct to_address field for private messages
1565 function phpbb_privmsgs_to_userid($to_userid)
1567 global $config;
1569 return 'u_' . phpbb_user_id($to_userid);
1573 * Calculate whether a private message was unread using the bitfield
1575 function phpbb_unread_pm($pm_type)
1577 return ($pm_type == 5) ? 1 : 0;
1581 * Calculate whether a private message was new using the bitfield
1583 function phpbb_new_pm($pm_type)
1585 return ($pm_type == 1) ? 1 : 0;
1589 * Obtain the folder_id for the custom folder created to replace the savebox from 2.0.x (used to store saved private messages)
1591 function phpbb_get_savebox_id($user_id)
1593 global $db;
1595 $user_id = phpbb_user_id($user_id);
1597 // Only one custom folder, check only one
1598 $sql = 'SELECT folder_id
1599 FROM ' . PRIVMSGS_FOLDER_TABLE . '
1600 WHERE user_id = ' . $user_id;
1601 $result = $db->sql_query_limit($sql, 1);
1602 $folder_id = (int) $db->sql_fetchfield('folder_id');
1603 $db->sql_freeresult($result);
1605 return $folder_id;
1609 * Transfer attachment specific configuration options
1610 * These were not stored in the main config table on 2.0.x
1611 * This is only used if the Attachment MOD was installed
1613 function phpbb_import_attach_config()
1615 global $db, $src_db, $same_db, $convert, $config;
1617 if ($convert->mysql_convert && $same_db)
1619 $src_db->sql_query("SET NAMES 'binary'");
1622 $sql = 'SELECT *
1623 FROM ' . $convert->src_table_prefix . 'attachments_config';
1624 $result = $src_db->sql_query($sql);
1626 if ($convert->mysql_convert && $same_db)
1628 $src_db->sql_query("SET NAMES 'utf8'");
1631 $attach_config = array();
1632 while ($row = $src_db->sql_fetchrow($result))
1634 $attach_config[$row['config_name']] = $row['config_value'];
1636 $src_db->sql_freeresult($result);
1638 set_config('allow_attachments', 1);
1640 // old attachment mod? Must be very old if this entry do not exist...
1641 if (!empty($attach_config['display_order']))
1643 set_config('display_order', $attach_config['display_order']);
1645 set_config('max_filesize', $attach_config['max_filesize']);
1646 set_config('max_filesize_pm', $attach_config['max_filesize_pm']);
1647 set_config('attachment_quota', $attach_config['attachment_quota']);
1648 set_config('max_attachments', $attach_config['max_attachments']);
1649 set_config('max_attachments_pm', $attach_config['max_attachments_pm']);
1650 set_config('allow_pm_attach', $attach_config['allow_pm_attach']);
1652 set_config('img_display_inlined', $attach_config['img_display_inlined']);
1653 set_config('img_max_width', $attach_config['img_max_width']);
1654 set_config('img_max_height', $attach_config['img_max_height']);
1655 set_config('img_link_width', $attach_config['img_link_width']);
1656 set_config('img_link_height', $attach_config['img_link_height']);
1657 set_config('img_create_thumbnail', $attach_config['img_create_thumbnail']);
1658 set_config('img_max_thumb_width', 400);
1659 set_config('img_min_thumb_filesize', $attach_config['img_min_thumb_filesize']);
1660 set_config('img_imagick', $attach_config['img_imagick']);
1664 * Calculate the date a user became inactive
1666 function phpbb_inactive_time()
1668 global $convert_row;
1670 if ($convert_row['user_active'])
1672 return 0;
1675 if ($convert_row['user_lastvisit'])
1677 return $convert_row['user_lastvisit'];
1680 return $convert_row['user_regdate'];
1684 * Calculate the reason a user became inactive
1685 * We can't actually tell the difference between a manual deactivation and one for profile changes
1686 * from the data available to assume the latter
1688 function phpbb_inactive_reason()
1690 global $convert_row;
1692 if ($convert_row['user_active'])
1694 return 0;
1697 if ($convert_row['user_lastvisit'])
1699 return INACTIVE_PROFILE;
1702 return INACTIVE_REGISTER;
1706 * Adjust 2.0.x disallowed names to 3.0.x format
1708 function phpbb_disallowed_username($username)
1710 // Replace * with %
1711 $username = phpbb_set_default_encoding(str_replace('*', '%', $username));
1712 return utf8_htmlspecialchars($username);
1716 * Checks whether there are any usernames on the old board that would map to the same
1717 * username_clean on phpBB3. Prints out a list if any exist and exits.
1719 function phpbb_create_userconv_table()
1721 global $db, $src_db, $convert, $table_prefix, $user, $lang;
1723 // create a temporary table in which we store the clean usernames
1724 $drop_sql = 'DROP TABLE ' . USERCONV_TABLE;
1725 switch ($db->dbms_type)
1727 case 'firebird':
1728 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1729 user_id INTEGER NOT NULL,
1730 username_clean VARCHAR(255) CHARACTER SET UTF8 DEFAULT \'\' NOT NULL COLLATE UNICODE
1732 break;
1734 case 'mssql':
1735 $create_sql = 'CREATE TABLE [' . USERCONV_TABLE . '] (
1736 [user_id] [int] NOT NULL ,
1737 [username_clean] [varchar] (255) DEFAULT (\'\') NOT NULL
1739 break;
1741 case 'mysql':
1742 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1743 user_id mediumint(8) NOT NULL,
1744 username_clean varchar(255) DEFAULT \'\' NOT NULL
1745 ) CHARACTER SET `utf8` COLLATE `utf8_bin`';
1746 break;
1748 case 'oracle':
1749 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1750 user_id number(8) NOT NULL,
1751 username_clean varchar2(255) DEFAULT \'\'
1753 break;
1755 case 'postgres':
1756 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1757 user_id INT4 DEFAULT \'0\',
1758 username_clean varchar_ci DEFAULT \'\' NOT NULL
1760 break;
1762 case 'sqlite':
1763 $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1764 user_id INTEGER NOT NULL DEFAULT \'0\',
1765 username_clean varchar(255) NOT NULL DEFAULT \'\'
1767 break;
1770 $db->sql_return_on_error(true);
1771 $db->sql_query($drop_sql);
1772 $db->sql_return_on_error(false);
1773 $db->sql_query($create_sql);
1776 function phpbb_check_username_collisions()
1778 global $db, $src_db, $convert, $table_prefix, $user, $lang;
1780 // now find the clean version of the usernames that collide
1781 $sql = 'SELECT username_clean
1782 FROM ' . USERCONV_TABLE .'
1783 GROUP BY username_clean
1784 HAVING COUNT(user_id) > 1';
1785 $result = $db->sql_query($sql);
1787 $colliding_names = array();
1788 while ($row = $db->sql_fetchrow($result))
1790 $colliding_names[] = $row['username_clean'];
1792 $db->sql_freeresult($result);
1794 // there was at least one collision, the admin will have to solve it before conversion can continue
1795 if (sizeof($colliding_names))
1797 $sql = 'SELECT user_id, username_clean
1798 FROM ' . USERCONV_TABLE . '
1799 WHERE ' . $db->sql_in_set('username_clean', $colliding_names);
1800 $result = $db->sql_query($sql);
1801 unset($colliding_names);
1803 $colliding_user_ids = array();
1804 while ($row = $db->sql_fetchrow($result))
1806 $colliding_user_ids[(int) $row['user_id']] = $row['username_clean'];
1808 $db->sql_freeresult($result);
1810 $sql = 'SELECT username, user_id, user_posts
1811 FROM ' . $convert->src_table_prefix . 'users
1812 WHERE ' . $src_db->sql_in_set('user_id', array_keys($colliding_user_ids));
1813 $result = $src_db->sql_query($sql);
1815 $colliding_users = array();
1816 while ($row = $src_db->sql_fetchrow($result))
1818 $row['user_id'] = (int) $row['user_id'];
1819 if (isset($colliding_user_ids[$row['user_id']]))
1821 $colliding_users[$colliding_user_ids[$row['user_id']]][] = $row;
1824 $src_db->sql_freeresult($result);
1825 unset($colliding_user_ids);
1827 $list = '';
1828 foreach ($colliding_users as $username_clean => $users)
1830 $list .= sprintf($user->lang['COLLIDING_CLEAN_USERNAME'], $username_clean) . "<br />\n";
1831 foreach ($users as $i => $row)
1833 $list .= sprintf($user->lang['COLLIDING_USER'], $row['user_id'], phpbb_set_default_encoding($row['username']), $row['user_posts']) . "<br />\n";
1837 $lang['INST_ERR_FATAL'] = $user->lang['CONV_ERR_FATAL'];
1838 $convert->p_master->error('<span style="color:red">' . $user->lang['COLLIDING_USERNAMES_FOUND'] . '</span></b><br /><br />' . $list . '<b>', __LINE__, __FILE__);
1841 $drop_sql = 'DROP TABLE ' . USERCONV_TABLE;
1842 $db->sql_query($drop_sql);