1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/install/convertors/functions_phpbb20.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,1870 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package install
1.8 +* @version $Id$
1.9 +* @copyright (c) 2006 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +if (!defined('IN_PHPBB'))
1.15 +{
1.16 + exit;
1.17 +}
1.18 +
1.19 +/**
1.20 +* Helper functions for phpBB 2.0.x to phpBB 3.0.x conversion
1.21 +*/
1.22 +
1.23 +/**
1.24 +* Set forum flags - only prune old polls by default
1.25 +*/
1.26 +function phpbb_forum_flags()
1.27 +{
1.28 + // Set forum flags
1.29 + $forum_flags = 0;
1.30 +
1.31 + // FORUM_FLAG_LINK_TRACK
1.32 + $forum_flags += 0;
1.33 +
1.34 + // FORUM_FLAG_PRUNE_POLL
1.35 + $forum_flags += FORUM_FLAG_PRUNE_POLL;
1.36 +
1.37 + // FORUM_FLAG_PRUNE_ANNOUNCE
1.38 + $forum_flags += 0;
1.39 +
1.40 + // FORUM_FLAG_PRUNE_STICKY
1.41 + $forum_flags += 0;
1.42 +
1.43 + // FORUM_FLAG_ACTIVE_TOPICS
1.44 + $forum_flags += 0;
1.45 +
1.46 + // FORUM_FLAG_POST_REVIEW
1.47 + $forum_flags += FORUM_FLAG_POST_REVIEW;
1.48 +
1.49 + return $forum_flags;
1.50 +}
1.51 +
1.52 +/**
1.53 +* Insert/Convert forums
1.54 +*/
1.55 +function phpbb_insert_forums()
1.56 +{
1.57 + global $db, $src_db, $same_db, $convert, $user, $config;
1.58 +
1.59 + $db->sql_query($convert->truncate_statement . FORUMS_TABLE);
1.60 +
1.61 + // Determine the highest id used within the old forums table (we add the categories after the forum ids)
1.62 + $sql = 'SELECT MAX(forum_id) AS max_forum_id
1.63 + FROM ' . $convert->src_table_prefix . 'forums';
1.64 + $result = $src_db->sql_query($sql);
1.65 + $max_forum_id = (int) $src_db->sql_fetchfield('max_forum_id');
1.66 + $src_db->sql_freeresult($result);
1.67 +
1.68 + $max_forum_id++;
1.69 +
1.70 + // pruning disabled globally?
1.71 + $sql = "SELECT config_value
1.72 + FROM {$convert->src_table_prefix}config
1.73 + WHERE config_name = 'prune_enable'";
1.74 + $result = $src_db->sql_query($sql);
1.75 + $prune_enabled = (int) $src_db->sql_fetchfield('config_value');
1.76 + $src_db->sql_freeresult($result);
1.77 +
1.78 +
1.79 + // Insert categories
1.80 + $sql = 'SELECT cat_id, cat_title
1.81 + FROM ' . $convert->src_table_prefix . 'categories
1.82 + ORDER BY cat_order';
1.83 +
1.84 + if ($convert->mysql_convert && $same_db)
1.85 + {
1.86 + $src_db->sql_query("SET NAMES 'binary'");
1.87 + }
1.88 +
1.89 + $result = $src_db->sql_query($sql);
1.90 +
1.91 + if ($convert->mysql_convert && $same_db)
1.92 + {
1.93 + $src_db->sql_query("SET NAMES 'utf8'");
1.94 + }
1.95 +
1.96 + switch ($db->sql_layer)
1.97 + {
1.98 + case 'mssql':
1.99 + case 'mssql_odbc':
1.100 + case 'mssqlnative':
1.101 + $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' ON');
1.102 + break;
1.103 + }
1.104 +
1.105 + $cats_added = array();
1.106 + while ($row = $src_db->sql_fetchrow($result))
1.107 + {
1.108 + $sql_ary = array(
1.109 + 'forum_id' => (int) $max_forum_id,
1.110 + 'forum_name' => ($row['cat_title']) ? htmlspecialchars(phpbb_set_default_encoding($row['cat_title']), ENT_COMPAT, 'UTF-8') : $user->lang['CATEGORY'],
1.111 + 'parent_id' => 0,
1.112 + 'forum_parents' => '',
1.113 + 'forum_desc' => '',
1.114 + 'forum_type' => FORUM_CAT,
1.115 + 'forum_status' => ITEM_UNLOCKED,
1.116 + 'forum_rules' => '',
1.117 + );
1.118 +
1.119 + $sql = 'SELECT MAX(right_id) AS right_id
1.120 + FROM ' . FORUMS_TABLE;
1.121 + $_result = $db->sql_query($sql);
1.122 + $cat_row = $db->sql_fetchrow($_result);
1.123 + $db->sql_freeresult($_result);
1.124 +
1.125 + $sql_ary['left_id'] = (int) ($cat_row['right_id'] + 1);
1.126 + $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 2);
1.127 +
1.128 + $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1.129 + $db->sql_query($sql);
1.130 +
1.131 + $cats_added[$row['cat_id']] = $max_forum_id;
1.132 + $max_forum_id++;
1.133 + }
1.134 + $src_db->sql_freeresult($result);
1.135 +
1.136 + // There may be installations having forums with non-existant category ids.
1.137 + // We try to catch them and add them to an "unknown" category instead of leaving them out.
1.138 + $sql = 'SELECT cat_id
1.139 + FROM ' . $convert->src_table_prefix . 'forums
1.140 + GROUP BY cat_id';
1.141 + $result = $src_db->sql_query($sql);
1.142 +
1.143 + $unknown_cat_id = false;
1.144 + while ($row = $src_db->sql_fetchrow($result))
1.145 + {
1.146 + // Catch those categories not been added before
1.147 + if (!isset($cats_added[$row['cat_id']]))
1.148 + {
1.149 + $unknown_cat_id = true;
1.150 + }
1.151 + }
1.152 + $src_db->sql_freeresult($result);
1.153 +
1.154 + // Is there at least one category not known?
1.155 + if ($unknown_cat_id === true)
1.156 + {
1.157 + $unknown_cat_id = 'ghost';
1.158 +
1.159 + $sql_ary = array(
1.160 + 'forum_id' => (int) $max_forum_id,
1.161 + 'forum_name' => (string) $user->lang['CATEGORY'],
1.162 + 'parent_id' => 0,
1.163 + 'forum_parents' => '',
1.164 + 'forum_desc' => '',
1.165 + 'forum_type' => FORUM_CAT,
1.166 + 'forum_status' => ITEM_UNLOCKED,
1.167 + 'forum_rules' => '',
1.168 + );
1.169 +
1.170 + $sql = 'SELECT MAX(right_id) AS right_id
1.171 + FROM ' . FORUMS_TABLE;
1.172 + $_result = $db->sql_query($sql);
1.173 + $cat_row = $db->sql_fetchrow($_result);
1.174 + $db->sql_freeresult($_result);
1.175 +
1.176 + $sql_ary['left_id'] = (int) ($cat_row['right_id'] + 1);
1.177 + $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 2);
1.178 +
1.179 + $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1.180 + $db->sql_query($sql);
1.181 +
1.182 + $cats_added[$unknown_cat_id] = $max_forum_id;
1.183 + $max_forum_id++;
1.184 + }
1.185 +
1.186 + // Now insert the forums
1.187 + $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
1.188 + LEFT JOIN ' . $convert->src_table_prefix . 'forum_prune fp ON f.forum_id = fp.forum_id
1.189 + 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
1.190 + ORDER BY f.cat_id, f.forum_order';
1.191 +
1.192 + if ($convert->mysql_convert && $same_db)
1.193 + {
1.194 + $src_db->sql_query("SET NAMES 'binary'");
1.195 + }
1.196 +
1.197 + $result = $src_db->sql_query($sql);
1.198 +
1.199 + if ($convert->mysql_convert && $same_db)
1.200 + {
1.201 + $src_db->sql_query("SET NAMES 'utf8'");
1.202 + }
1.203 +
1.204 + while ($row = $src_db->sql_fetchrow($result))
1.205 + {
1.206 + // Some might have forums here with an id not being "possible"...
1.207 + // To be somewhat friendly we "change" the category id for those to a previously created ghost category
1.208 + if (!isset($cats_added[$row['cat_id']]) && $unknown_cat_id !== false)
1.209 + {
1.210 + $row['cat_id'] = $unknown_cat_id;
1.211 + }
1.212 +
1.213 + if (!isset($cats_added[$row['cat_id']]))
1.214 + {
1.215 + continue;
1.216 + }
1.217 +
1.218 + // Define the new forums sql ary
1.219 + $sql_ary = array(
1.220 + 'forum_id' => (int) $row['forum_id'],
1.221 + 'forum_name' => htmlspecialchars(phpbb_set_default_encoding($row['forum_name']), ENT_COMPAT, 'UTF-8'),
1.222 + 'parent_id' => (int) $cats_added[$row['cat_id']],
1.223 + 'forum_parents' => '',
1.224 + 'forum_desc' => htmlspecialchars(phpbb_set_default_encoding($row['forum_desc']), ENT_COMPAT, 'UTF-8'),
1.225 + 'forum_type' => FORUM_POST,
1.226 + 'forum_status' => is_item_locked($row['forum_status']),
1.227 + 'enable_prune' => ($prune_enabled) ? (int)$row['prune_enable'] : 0,
1.228 + 'prune_next' => (int) null_to_zero($row['prune_next']),
1.229 + 'prune_days' => (int) null_to_zero($row['prune_days']),
1.230 + 'prune_viewed' => 0,
1.231 + 'prune_freq' => (int) null_to_zero($row['prune_freq']),
1.232 +
1.233 + 'forum_flags' => phpbb_forum_flags(),
1.234 + 'forum_options' => 0,
1.235 +
1.236 + // Default values
1.237 + 'forum_desc_bitfield' => '',
1.238 + 'forum_desc_options' => 7,
1.239 + 'forum_desc_uid' => '',
1.240 + 'forum_link' => '',
1.241 + 'forum_password' => '',
1.242 + 'forum_style' => 0,
1.243 + 'forum_image' => '',
1.244 + 'forum_rules' => '',
1.245 + 'forum_rules_link' => '',
1.246 + 'forum_rules_bitfield' => '',
1.247 + 'forum_rules_options' => 7,
1.248 + 'forum_rules_uid' => '',
1.249 + 'forum_topics_per_page' => 0,
1.250 + 'forum_posts' => 0,
1.251 + 'forum_topics' => 0,
1.252 + 'forum_topics_real' => 0,
1.253 + 'forum_last_post_id' => 0,
1.254 + 'forum_last_poster_id' => 0,
1.255 + 'forum_last_post_subject' => '',
1.256 + 'forum_last_post_time' => 0,
1.257 + 'forum_last_poster_name' => '',
1.258 + 'forum_last_poster_colour' => '',
1.259 + 'display_on_index' => 1,
1.260 + 'enable_indexing' => 1,
1.261 + 'enable_icons' => 0,
1.262 + );
1.263 +
1.264 + // Now add the forums with proper left/right ids
1.265 + $sql = 'SELECT left_id, right_id
1.266 + FROM ' . FORUMS_TABLE . '
1.267 + WHERE forum_id = ' . $cats_added[$row['cat_id']];
1.268 + $_result = $db->sql_query($sql);
1.269 + $cat_row = $db->sql_fetchrow($_result);
1.270 + $db->sql_freeresult($_result);
1.271 +
1.272 + $sql = 'UPDATE ' . FORUMS_TABLE . '
1.273 + SET left_id = left_id + 2, right_id = right_id + 2
1.274 + WHERE left_id > ' . $cat_row['right_id'];
1.275 + $db->sql_query($sql);
1.276 +
1.277 + $sql = 'UPDATE ' . FORUMS_TABLE . '
1.278 + SET right_id = right_id + 2
1.279 + WHERE ' . $cat_row['left_id'] . ' BETWEEN left_id AND right_id';
1.280 + $db->sql_query($sql);
1.281 +
1.282 + $sql_ary['left_id'] = (int) $cat_row['right_id'];
1.283 + $sql_ary['right_id'] = (int) ($cat_row['right_id'] + 1);
1.284 +
1.285 + $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1.286 + $db->sql_query($sql);
1.287 + }
1.288 + $src_db->sql_freeresult($result);
1.289 +
1.290 + switch ($db->sql_layer)
1.291 + {
1.292 + case 'postgres':
1.293 + $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 . '));');
1.294 + break;
1.295 +
1.296 + case 'mssql':
1.297 + case 'mssql_odbc':
1.298 + case 'mssqlnative':
1.299 + $db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' OFF');
1.300 + break;
1.301 +
1.302 + case 'oracle':
1.303 + $result = $db->sql_query('SELECT MAX(forum_id) as max_id FROM ' . FORUMS_TABLE);
1.304 + $row = $db->sql_fetchrow($result);
1.305 + $db->sql_freeresult($result);
1.306 +
1.307 + $largest_id = (int) $row['max_id'];
1.308 +
1.309 + if ($largest_id)
1.310 + {
1.311 + $db->sql_query('DROP SEQUENCE ' . FORUMS_TABLE . '_seq');
1.312 + $db->sql_query('CREATE SEQUENCE ' . FORUMS_TABLE . '_seq START WITH ' . ($largest_id + 1));
1.313 + }
1.314 + break;
1.315 + }
1.316 +}
1.317 +
1.318 +/**
1.319 +* Function for recoding text with the default language
1.320 +*
1.321 +* @param string $text text to recode to utf8
1.322 +* @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
1.323 +*/
1.324 +function phpbb_set_encoding($text, $grab_user_lang = true)
1.325 +{
1.326 + global $lang_enc_array, $convert_row;
1.327 + global $convert, $phpEx;
1.328 +
1.329 + /*static $lang_enc_array = array(
1.330 + 'korean' => 'euc-kr',
1.331 + 'serbian' => 'windows-1250',
1.332 + 'polish' => 'iso-8859-2',
1.333 + 'kurdish' => 'windows-1254',
1.334 + 'slovak' => 'Windows-1250',
1.335 + 'russian' => 'windows-1251',
1.336 + 'estonian' => 'iso-8859-4',
1.337 + 'chinese_simplified' => 'gb2312',
1.338 + 'macedonian' => 'windows-1251',
1.339 + 'azerbaijani' => 'UTF-8',
1.340 + 'romanian' => 'iso-8859-2',
1.341 + 'romanian_diacritice' => 'iso-8859-2',
1.342 + 'lithuanian' => 'windows-1257',
1.343 + 'turkish' => 'iso-8859-9',
1.344 + 'ukrainian' => 'windows-1251',
1.345 + 'japanese' => 'shift_jis',
1.346 + 'hungarian' => 'ISO-8859-2',
1.347 + 'romanian_no_diacritics' => 'iso-8859-2',
1.348 + 'mongolian' => 'UTF-8',
1.349 + 'slovenian' => 'windows-1250',
1.350 + 'bosnian' => 'windows-1250',
1.351 + 'czech' => 'Windows-1250',
1.352 + 'farsi' => 'Windows-1256',
1.353 + 'croatian' => 'windows-1250',
1.354 + 'greek' => 'iso-8859-7',
1.355 + 'russian_tu' => 'windows-1251',
1.356 + 'sakha' => 'UTF-8',
1.357 + 'serbian_cyrillic' => 'windows-1251',
1.358 + 'bulgarian' => 'windows-1251',
1.359 + 'chinese_traditional_taiwan' => 'big5',
1.360 + 'chinese_traditional' => 'big5',
1.361 + 'arabic' => 'windows-1256',
1.362 + 'hebrew' => 'WINDOWS-1255',
1.363 + 'thai' => 'windows-874',
1.364 + //'chinese_traditional_taiwan' => 'utf-8' // custom modified, we may have to do an include :-(
1.365 + );*/
1.366 +
1.367 + if (empty($lang_enc_array))
1.368 + {
1.369 + $lang_enc_array = array();
1.370 + }
1.371 +
1.372 + $get_lang = trim(get_config_value('default_lang'));
1.373 +
1.374 + // Do we need the users language encoding?
1.375 + if ($grab_user_lang && !empty($convert_row))
1.376 + {
1.377 + if (!empty($convert_row['user_lang']))
1.378 + {
1.379 + $get_lang = trim($convert_row['user_lang']);
1.380 + }
1.381 + else if (!empty($convert_row['poster_id']))
1.382 + {
1.383 + global $src_db, $same_db;
1.384 +
1.385 + if ($convert->mysql_convert && $same_db)
1.386 + {
1.387 + $src_db->sql_query("SET NAMES 'binary'");
1.388 + }
1.389 +
1.390 + $sql = 'SELECT user_lang
1.391 + FROM ' . $convert->src_table_prefix . 'users
1.392 + WHERE user_id = ' . (int) $convert_row['poster_id'];
1.393 + $result = $src_db->sql_query($sql);
1.394 + $get_lang = (string) $src_db->sql_fetchfield('user_lang');
1.395 + $src_db->sql_freeresult($result);
1.396 +
1.397 + if ($convert->mysql_convert && $same_db)
1.398 + {
1.399 + $src_db->sql_query("SET NAMES 'utf8'");
1.400 + }
1.401 +
1.402 + $get_lang = (!trim($get_lang)) ? trim(get_config_value('default_lang')) : trim($get_lang);
1.403 + }
1.404 + }
1.405 +
1.406 + if (!isset($lang_enc_array[$get_lang]))
1.407 + {
1.408 + $filename = $convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx;
1.409 +
1.410 + if (!file_exists($filename))
1.411 + {
1.412 + $get_lang = trim(get_config_value('default_lang'));
1.413 + }
1.414 +
1.415 + if (!isset($lang_enc_array[$get_lang]))
1.416 + {
1.417 + include($convert->options['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx);
1.418 + $lang_enc_array[$get_lang] = $lang['ENCODING'];
1.419 + unset($lang);
1.420 + }
1.421 + }
1.422 +
1.423 + $encoding = $lang_enc_array[$get_lang];
1.424 +
1.425 + return utf8_recode($text, $lang_enc_array[$get_lang]);
1.426 +}
1.427 +
1.428 +/**
1.429 +* Same as phpbb_set_encoding, but forcing boards default language
1.430 +*/
1.431 +function phpbb_set_default_encoding($text)
1.432 +{
1.433 + return phpbb_set_encoding($text, false);
1.434 +}
1.435 +
1.436 +/**
1.437 +* Convert Birthday from Birthday MOD to phpBB Format
1.438 +*/
1.439 +function phpbb_get_birthday($birthday = '')
1.440 +{
1.441 + if (defined('MOD_BIRTHDAY_TERRA'))
1.442 + {
1.443 + $birthday = (string) $birthday;
1.444 +
1.445 + // stored as month, day, year
1.446 + if (!$birthday)
1.447 + {
1.448 + return ' 0- 0- 0';
1.449 + }
1.450 +
1.451 + // We use the original mod code to retrieve the birthday (not ideal)
1.452 + preg_match('/(..)(..)(....)/', sprintf('%08d', $birthday), $birthday_parts);
1.453 +
1.454 + $month = $birthday_parts[1];
1.455 + $day = $birthday_parts[2];
1.456 + $year = $birthday_parts[3];
1.457 +
1.458 + return sprintf('%2d-%2d-%4d', $day, $month, $year);
1.459 + }
1.460 + else
1.461 + {
1.462 + $birthday = (int) $birthday;
1.463 +
1.464 + if (!$birthday || $birthday == 999999 || ((version_compare(PHP_VERSION, '5.1.0') < 0) && $birthday < 0))
1.465 + {
1.466 + return ' 0- 0- 0';
1.467 + }
1.468 +
1.469 + // The birthday mod from niels is using this code to transform to day/month/year
1.470 + return sprintf('%2d-%2d-%4d', gmdate('j', $birthday * 86400 + 1), gmdate('n', $birthday * 86400 + 1), gmdate('Y', $birthday * 86400 + 1));
1.471 + }
1.472 +}
1.473 +
1.474 +/**
1.475 +* Return correct user id value
1.476 +* Everyone's id will be one higher to allow the guest/anonymous user to have a positive id as well
1.477 +*/
1.478 +function phpbb_user_id($user_id)
1.479 +{
1.480 + global $config;
1.481 +
1.482 + // Increment user id if the old forum is having a user with the id 1
1.483 + if (!isset($config['increment_user_id']))
1.484 + {
1.485 + global $src_db, $same_db, $convert;
1.486 +
1.487 + if ($convert->mysql_convert && $same_db)
1.488 + {
1.489 + $src_db->sql_query("SET NAMES 'binary'");
1.490 + }
1.491 +
1.492 + // Now let us set a temporary config variable for user id incrementing
1.493 + $sql = "SELECT user_id
1.494 + FROM {$convert->src_table_prefix}users
1.495 + WHERE user_id = 1";
1.496 + $result = $src_db->sql_query($sql);
1.497 + $id = (int) $src_db->sql_fetchfield('user_id');
1.498 + $src_db->sql_freeresult($result);
1.499 +
1.500 + // Try to get the maximum user id possible...
1.501 + $sql = "SELECT MAX(user_id) AS max_user_id
1.502 + FROM {$convert->src_table_prefix}users";
1.503 + $result = $src_db->sql_query($sql);
1.504 + $max_id = (int) $src_db->sql_fetchfield('max_user_id');
1.505 + $src_db->sql_freeresult($result);
1.506 +
1.507 + if ($convert->mysql_convert && $same_db)
1.508 + {
1.509 + $src_db->sql_query("SET NAMES 'utf8'");
1.510 + }
1.511 +
1.512 + // If there is a user id 1, we need to increment user ids. :/
1.513 + if ($id === 1)
1.514 + {
1.515 + set_config('increment_user_id', ($max_id + 1), true);
1.516 + $config['increment_user_id'] = $max_id + 1;
1.517 + }
1.518 + else
1.519 + {
1.520 + set_config('increment_user_id', 0, true);
1.521 + $config['increment_user_id'] = 0;
1.522 + }
1.523 + }
1.524 +
1.525 + // If the old user id is -1 in 2.0.x it is the anonymous user...
1.526 + if ($user_id == -1)
1.527 + {
1.528 + return ANONYMOUS;
1.529 + }
1.530 +
1.531 + if (!empty($config['increment_user_id']) && $user_id == 1)
1.532 + {
1.533 + return $config['increment_user_id'];
1.534 + }
1.535 +
1.536 + // A user id of 0 can happen, for example within the ban table if no user is banned...
1.537 + // Within the posts and topics table this can be "dangerous" but is the fault of the user
1.538 + // having mods installed (a poster id of 0 is not possible in 2.0.x).
1.539 + // Therefore, we return the user id "as is".
1.540 +
1.541 + return (int) $user_id;
1.542 +}
1.543 +
1.544 +/* Copy additional table fields from old forum to new forum if user wants this (for Mod compatibility for example)
1.545 +function phpbb_copy_table_fields()
1.546 +{
1.547 +}
1.548 +*/
1.549 +
1.550 +/**
1.551 +* Convert authentication
1.552 +* user, group and forum table has to be filled in order to work
1.553 +*/
1.554 +function phpbb_convert_authentication($mode)
1.555 +{
1.556 + global $db, $src_db, $same_db, $convert, $user, $config, $cache;
1.557 +
1.558 + if ($mode == 'start')
1.559 + {
1.560 + $db->sql_query($convert->truncate_statement . ACL_USERS_TABLE);
1.561 + $db->sql_query($convert->truncate_statement . ACL_GROUPS_TABLE);
1.562 +
1.563 + // What we will do is handling all 2.0.x admins as founder to replicate what is common in 2.0.x.
1.564 + // After conversion the main admin need to make sure he is removing permissions and the founder status if wanted.
1.565 +
1.566 +
1.567 + // Grab user ids of users with user_level of ADMIN
1.568 + $sql = "SELECT user_id
1.569 + FROM {$convert->src_table_prefix}users
1.570 + WHERE user_level = 1
1.571 + ORDER BY user_regdate ASC";
1.572 + $result = $src_db->sql_query($sql);
1.573 +
1.574 + while ($row = $src_db->sql_fetchrow($result))
1.575 + {
1.576 + $user_id = (int) phpbb_user_id($row['user_id']);
1.577 + // Set founder admin...
1.578 + $sql = 'UPDATE ' . USERS_TABLE . '
1.579 + SET user_type = ' . USER_FOUNDER . "
1.580 + WHERE user_id = $user_id";
1.581 + $db->sql_query($sql);
1.582 + }
1.583 + $src_db->sql_freeresult($result);
1.584 +
1.585 + $sql = 'SELECT group_id
1.586 + FROM ' . GROUPS_TABLE . "
1.587 + WHERE group_name = '" . $db->sql_escape('BOTS') . "'";
1.588 + $result = $db->sql_query($sql);
1.589 + $bot_group_id = (int) $db->sql_fetchfield('group_id');
1.590 + $db->sql_freeresult($result);
1.591 + }
1.592 +
1.593 + // Grab forum auth information
1.594 + $sql = "SELECT *
1.595 + FROM {$convert->src_table_prefix}forums";
1.596 + $result = $src_db->sql_query($sql);
1.597 +
1.598 + $forum_access = array();
1.599 + while ($row = $src_db->sql_fetchrow($result))
1.600 + {
1.601 + $forum_access[$row['forum_id']] = $row;
1.602 + }
1.603 + $src_db->sql_freeresult($result);
1.604 +
1.605 + if ($convert->mysql_convert && $same_db)
1.606 + {
1.607 + $src_db->sql_query("SET NAMES 'binary'");
1.608 + }
1.609 + // Grab user auth information from 2.0.x board
1.610 + $sql = "SELECT ug.user_id, aa.*
1.611 + 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
1.612 + WHERE g.group_id = aa.group_id
1.613 + AND g.group_single_user = 1
1.614 + AND ug.group_id = g.group_id
1.615 + AND f.forum_id = aa.forum_id";
1.616 + $result = $src_db->sql_query($sql);
1.617 +
1.618 + $user_access = array();
1.619 + while ($row = $src_db->sql_fetchrow($result))
1.620 + {
1.621 + $user_access[$row['forum_id']][] = $row;
1.622 + }
1.623 + $src_db->sql_freeresult($result);
1.624 +
1.625 + // Grab group auth information
1.626 + $sql = "SELECT g.group_id, aa.*
1.627 + FROM {$convert->src_table_prefix}auth_access aa, {$convert->src_table_prefix}groups g
1.628 + WHERE g.group_id = aa.group_id
1.629 + AND g.group_single_user <> 1";
1.630 + $result = $src_db->sql_query($sql);
1.631 +
1.632 + $group_access = array();
1.633 + while ($row = $src_db->sql_fetchrow($result))
1.634 + {
1.635 + $group_access[$row['forum_id']][] = $row;
1.636 + }
1.637 + $src_db->sql_freeresult($result);
1.638 +
1.639 + if ($convert->mysql_convert && $same_db)
1.640 + {
1.641 + $src_db->sql_query("SET NAMES 'utf8'");
1.642 + }
1.643 +
1.644 + // Add Forum Access List
1.645 + $auth_map = array(
1.646 + 'auth_view' => array('f_', 'f_list'),
1.647 + 'auth_read' => array('f_read', 'f_search'),
1.648 + 'auth_post' => array('f_post', 'f_bbcode', 'f_smilies', 'f_img', 'f_sigs', 'f_postcount', 'f_report', 'f_subscribe', 'f_print', 'f_email'),
1.649 + 'auth_reply' => 'f_reply',
1.650 + 'auth_edit' => 'f_edit',
1.651 + 'auth_delete' => 'f_delete',
1.652 + 'auth_pollcreate' => 'f_poll',
1.653 + 'auth_vote' => 'f_vote',
1.654 + 'auth_announce' => 'f_announce',
1.655 + 'auth_sticky' => 'f_sticky',
1.656 + 'auth_attachments' => array('f_attach', 'f_download'),
1.657 + 'auth_download' => 'f_download',
1.658 + );
1.659 +
1.660 + // Define the ACL constants used in 2.0 to make the code slightly more readable
1.661 + define('AUTH_ALL', 0);
1.662 + define('AUTH_REG', 1);
1.663 + define('AUTH_ACL', 2);
1.664 + define('AUTH_MOD', 3);
1.665 + define('AUTH_ADMIN', 5);
1.666 +
1.667 + // A mapping of the simple permissions used by 2.0
1.668 + $simple_auth_ary = array(
1.669 + 'public' => array(
1.670 + 'auth_view' => AUTH_ALL,
1.671 + 'auth_read' => AUTH_ALL,
1.672 + 'auth_post' => AUTH_ALL,
1.673 + 'auth_reply' => AUTH_ALL,
1.674 + 'auth_edit' => AUTH_REG,
1.675 + 'auth_delete' => AUTH_REG,
1.676 + 'auth_sticky' => AUTH_MOD,
1.677 + 'auth_announce' => AUTH_MOD,
1.678 + 'auth_vote' => AUTH_REG,
1.679 + 'auth_pollcreate' => AUTH_REG,
1.680 + ),
1.681 + 'registered' => array(
1.682 + 'auth_view' => AUTH_ALL,
1.683 + 'auth_read' => AUTH_ALL,
1.684 + 'auth_post' => AUTH_REG,
1.685 + 'auth_reply' => AUTH_REG,
1.686 + 'auth_edit' => AUTH_REG,
1.687 + 'auth_delete' => AUTH_REG,
1.688 + 'auth_sticky' => AUTH_MOD,
1.689 + 'auth_announce' => AUTH_MOD,
1.690 + 'auth_vote' => AUTH_REG,
1.691 + 'auth_pollcreate' => AUTH_REG,
1.692 + ),
1.693 + 'registered_hidden' => array(
1.694 + 'auth_view' => AUTH_REG,
1.695 + 'auth_read' => AUTH_REG,
1.696 + 'auth_post' => AUTH_REG,
1.697 + 'auth_reply' => AUTH_REG,
1.698 + 'auth_edit' => AUTH_REG,
1.699 + 'auth_delete' => AUTH_REG,
1.700 + 'auth_sticky' => AUTH_MOD,
1.701 + 'auth_announce' => AUTH_MOD,
1.702 + 'auth_vote' => AUTH_REG,
1.703 + 'auth_pollcreate' => AUTH_REG,
1.704 + ),
1.705 + 'private' => array(
1.706 + 'auth_view' => AUTH_ALL,
1.707 + 'auth_read' => AUTH_ACL,
1.708 + 'auth_post' => AUTH_ACL,
1.709 + 'auth_reply' => AUTH_ACL,
1.710 + 'auth_edit' => AUTH_ACL,
1.711 + 'auth_delete' => AUTH_ACL,
1.712 + 'auth_sticky' => AUTH_ACL,
1.713 + 'auth_announce' => AUTH_MOD,
1.714 + 'auth_vote' => AUTH_ACL,
1.715 + 'auth_pollcreate' => AUTH_ACL,
1.716 + ),
1.717 + 'private_hidden' => array(
1.718 + 'auth_view' => AUTH_ACL,
1.719 + 'auth_read' => AUTH_ACL,
1.720 + 'auth_post' => AUTH_ACL,
1.721 + 'auth_reply' => AUTH_ACL,
1.722 + 'auth_edit' => AUTH_ACL,
1.723 + 'auth_delete' => AUTH_ACL,
1.724 + 'auth_sticky' => AUTH_ACL,
1.725 + 'auth_announce' => AUTH_MOD,
1.726 + 'auth_vote' => AUTH_ACL,
1.727 + 'auth_pollcreate' => AUTH_ACL,
1.728 + ),
1.729 + 'moderator' => array(
1.730 + 'auth_view' => AUTH_ALL,
1.731 + 'auth_read' => AUTH_MOD,
1.732 + 'auth_post' => AUTH_MOD,
1.733 + 'auth_reply' => AUTH_MOD,
1.734 + 'auth_edit' => AUTH_MOD,
1.735 + 'auth_delete' => AUTH_MOD,
1.736 + 'auth_sticky' => AUTH_MOD,
1.737 + 'auth_announce' => AUTH_MOD,
1.738 + 'auth_vote' => AUTH_MOD,
1.739 + 'auth_pollcreate' => AUTH_MOD,
1.740 + ),
1.741 + 'moderator_hidden' => array(
1.742 + 'auth_view' => AUTH_MOD,
1.743 + 'auth_read' => AUTH_MOD,
1.744 + 'auth_post' => AUTH_MOD,
1.745 + 'auth_reply' => AUTH_MOD,
1.746 + 'auth_edit' => AUTH_MOD,
1.747 + 'auth_delete' => AUTH_MOD,
1.748 + 'auth_sticky' => AUTH_MOD,
1.749 + 'auth_announce' => AUTH_MOD,
1.750 + 'auth_vote' => AUTH_MOD,
1.751 + 'auth_pollcreate' => AUTH_MOD,
1.752 + ),
1.753 + );
1.754 +
1.755 + if ($mode == 'start')
1.756 + {
1.757 + user_group_auth('guests', 'SELECT user_id, {GUESTS} FROM ' . USERS_TABLE . ' WHERE user_id = ' . ANONYMOUS, false);
1.758 + user_group_auth('registered', 'SELECT user_id, {REGISTERED} FROM ' . USERS_TABLE . ' WHERE user_id <> ' . ANONYMOUS . " AND group_id <> $bot_group_id", false);
1.759 +
1.760 + // Selecting from old table
1.761 + if (!empty($config['increment_user_id']))
1.762 + {
1.763 + $auth_sql = 'SELECT user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id <> 1';
1.764 + user_group_auth('administrators', $auth_sql, true);
1.765 +
1.766 + $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';
1.767 + user_group_auth('administrators', $auth_sql, true);
1.768 + }
1.769 + else
1.770 + {
1.771 + $auth_sql = 'SELECT user_id, {ADMINISTRATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1';
1.772 + user_group_auth('administrators', $auth_sql, true);
1.773 + }
1.774 +
1.775 + if (!empty($config['increment_user_id']))
1.776 + {
1.777 + $auth_sql = 'SELECT user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1 AND user_id <> 1';
1.778 + user_group_auth('global_moderators', $auth_sql, true);
1.779 +
1.780 + $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';
1.781 + user_group_auth('global_moderators', $auth_sql, true);
1.782 + }
1.783 + else
1.784 + {
1.785 + $auth_sql = 'SELECT user_id, {GLOBAL_MODERATORS} FROM ' . $convert->src_table_prefix . 'users WHERE user_level = 1';
1.786 + user_group_auth('global_moderators', $auth_sql, true);
1.787 + }
1.788 + }
1.789 + else if ($mode == 'first')
1.790 + {
1.791 + // Go through all 2.0.x forums
1.792 + foreach ($forum_access as $forum)
1.793 + {
1.794 + $new_forum_id = (int) $forum['forum_id'];
1.795 +
1.796 + // Administrators have full access to all forums whatever happens
1.797 + mass_auth('group_role', $new_forum_id, 'administrators', 'FORUM_FULL');
1.798 +
1.799 + $matched_type = '';
1.800 + foreach ($simple_auth_ary as $key => $auth_levels)
1.801 + {
1.802 + $matched = 1;
1.803 + foreach ($auth_levels as $k => $level)
1.804 + {
1.805 + if ($forum[$k] != $auth_levels[$k])
1.806 + {
1.807 + $matched = 0;
1.808 + }
1.809 + }
1.810 +
1.811 + if ($matched)
1.812 + {
1.813 + $matched_type = $key;
1.814 + break;
1.815 + }
1.816 + }
1.817 +
1.818 + switch ($matched_type)
1.819 + {
1.820 + case 'public':
1.821 + mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_LIMITED');
1.822 + mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_LIMITED_POLLS');
1.823 + mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
1.824 + break;
1.825 +
1.826 + case 'registered':
1.827 + mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_READONLY');
1.828 + mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
1.829 +
1.830 + // no break;
1.831 +
1.832 + case 'registered_hidden':
1.833 + mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_POLLS');
1.834 + break;
1.835 +
1.836 + case 'private':
1.837 + case 'private_hidden':
1.838 + case 'moderator':
1.839 + case 'moderator_hidden':
1.840 + default:
1.841 + // The permissions don't match a simple set, so we're going to have to map them directly
1.842 +
1.843 + // No post approval for all, in 2.0.x this feature does not exist
1.844 + mass_auth('group', $new_forum_id, 'guests', 'f_noapprove', ACL_YES);
1.845 + mass_auth('group', $new_forum_id, 'registered', 'f_noapprove', ACL_YES);
1.846 +
1.847 + // Go through authentication map
1.848 + foreach ($auth_map as $old_auth_key => $new_acl)
1.849 + {
1.850 + // If old authentication key does not exist we continue
1.851 + // This is helpful for mods adding additional authentication fields, we need to add them to the auth_map array
1.852 + if (!isset($forum[$old_auth_key]))
1.853 + {
1.854 + continue;
1.855 + }
1.856 +
1.857 + // Now set the new ACL correctly
1.858 + switch ($forum[$old_auth_key])
1.859 + {
1.860 + // AUTH_ALL
1.861 + case AUTH_ALL:
1.862 + mass_auth('group', $new_forum_id, 'guests', $new_acl, ACL_YES);
1.863 + mass_auth('group', $new_forum_id, 'bots', $new_acl, ACL_YES);
1.864 + mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
1.865 + break;
1.866 +
1.867 + // AUTH_REG
1.868 + case AUTH_REG:
1.869 + mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
1.870 + break;
1.871 +
1.872 + // AUTH_ACL
1.873 + case AUTH_ACL:
1.874 + // Go through the old group access list for this forum
1.875 + if (isset($group_access[$forum['forum_id']]))
1.876 + {
1.877 + foreach ($group_access[$forum['forum_id']] as $index => $access)
1.878 + {
1.879 + // We only check for ACL_YES equivalence entry
1.880 + if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
1.881 + {
1.882 + mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
1.883 + }
1.884 + }
1.885 + }
1.886 +
1.887 + if (isset($user_access[$forum['forum_id']]))
1.888 + {
1.889 + foreach ($user_access[$forum['forum_id']] as $index => $access)
1.890 + {
1.891 + // We only check for ACL_YES equivalence entry
1.892 + if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
1.893 + {
1.894 + mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
1.895 + }
1.896 + }
1.897 + }
1.898 + break;
1.899 +
1.900 + // AUTH_MOD
1.901 + case AUTH_MOD:
1.902 + if (isset($group_access[$forum['forum_id']]))
1.903 + {
1.904 + foreach ($group_access[$forum['forum_id']] as $index => $access)
1.905 + {
1.906 + // We only check for ACL_YES equivalence entry
1.907 + if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
1.908 + {
1.909 + mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
1.910 + }
1.911 + }
1.912 + }
1.913 +
1.914 + if (isset($user_access[$forum['forum_id']]))
1.915 + {
1.916 + foreach ($user_access[$forum['forum_id']] as $index => $access)
1.917 + {
1.918 + // We only check for ACL_YES equivalence entry
1.919 + if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
1.920 + {
1.921 + mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
1.922 + }
1.923 + }
1.924 + }
1.925 + break;
1.926 + }
1.927 + }
1.928 + break;
1.929 + }
1.930 + }
1.931 + }
1.932 + else if ($mode == 'second')
1.933 + {
1.934 + // Assign permission roles and other default permissions
1.935 +
1.936 + // guests having u_download and u_search ability
1.937 + $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')");
1.938 +
1.939 + // administrators/global mods having full user features
1.940 + mass_auth('group_role', 0, 'administrators', 'USER_FULL');
1.941 + mass_auth('group_role', 0, 'global_moderators', 'USER_FULL');
1.942 +
1.943 + // By default all converted administrators are given full access
1.944 + mass_auth('group_role', 0, 'administrators', 'ADMIN_FULL');
1.945 +
1.946 + // All registered users are assigned the standard user role
1.947 + mass_auth('group_role', 0, 'registered', 'USER_STANDARD');
1.948 + mass_auth('group_role', 0, 'registered_coppa', 'USER_STANDARD');
1.949 +
1.950 + // Instead of administrators being global moderators we give the MOD_FULL role to global mods (admins already assigned to this group)
1.951 + mass_auth('group_role', 0, 'global_moderators', 'MOD_FULL');
1.952 +
1.953 + // And now those who have had their avatar rights removed get assigned a more restrictive role
1.954 + $sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
1.955 + WHERE user_allowavatar = 0
1.956 + AND user_id > 0';
1.957 + $result = $src_db->sql_query($sql);
1.958 +
1.959 + while ($row = $src_db->sql_fetchrow($result))
1.960 + {
1.961 + mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOAVATAR');
1.962 + }
1.963 + $src_db->sql_freeresult($result);
1.964 +
1.965 + // And the same for those who have had their PM rights removed
1.966 + $sql = 'SELECT user_id FROM ' . $convert->src_table_prefix . 'users
1.967 + WHERE user_allow_pm = 0
1.968 + AND user_id > 0';
1.969 + $result = $src_db->sql_query($sql);
1.970 +
1.971 + while ($row = $src_db->sql_fetchrow($result))
1.972 + {
1.973 + mass_auth('user_role', 0, (int) phpbb_user_id($row['user_id']), 'USER_NOPM');
1.974 + }
1.975 + $src_db->sql_freeresult($result);
1.976 + }
1.977 + else if ($mode == 'third')
1.978 + {
1.979 + // And now the moderators
1.980 + // We make sure that they have at least standard access to the forums they moderate in addition to the moderating permissions
1.981 +
1.982 + $mod_post_map = array(
1.983 + 'auth_announce' => 'f_announce',
1.984 + 'auth_sticky' => 'f_sticky'
1.985 + );
1.986 +
1.987 + foreach ($user_access as $forum_id => $access_map)
1.988 + {
1.989 + $forum_id = (int) $forum_id;
1.990 +
1.991 + foreach ($access_map as $access)
1.992 + {
1.993 + if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
1.994 + {
1.995 + mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'MOD_STANDARD');
1.996 + mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'FORUM_STANDARD');
1.997 + foreach ($mod_post_map as $old => $new)
1.998 + {
1.999 + if (isset($forum_access[$forum_id]) && isset($forum_access[$forum_id][$old]) && $forum_access[$forum_id][$old] == AUTH_MOD)
1.1000 + {
1.1001 + mass_auth('user', $forum_id, (int) phpbb_user_id($access['user_id']), $new, ACL_YES);
1.1002 + }
1.1003 + }
1.1004 + }
1.1005 + }
1.1006 + }
1.1007 +
1.1008 + foreach ($group_access as $forum_id => $access_map)
1.1009 + {
1.1010 + $forum_id = (int) $forum_id;
1.1011 +
1.1012 + foreach ($access_map as $access)
1.1013 + {
1.1014 + if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
1.1015 + {
1.1016 + mass_auth('group_role', $forum_id, (int) $access['group_id'], 'MOD_STANDARD');
1.1017 + mass_auth('group_role', $forum_id, (int) $access['group_id'], 'FORUM_STANDARD');
1.1018 + foreach ($mod_post_map as $old => $new)
1.1019 + {
1.1020 + if (isset($forum_access[$forum_id]) && isset($forum_access[$forum_id][$old]) && $forum_access[$forum_id][$old] == AUTH_MOD)
1.1021 + {
1.1022 + mass_auth('group', $forum_id, (int) $access['group_id'], $new, ACL_YES);
1.1023 + }
1.1024 + }
1.1025 + }
1.1026 + }
1.1027 + }
1.1028 +
1.1029 + // We grant everyone readonly access to the categories to ensure that the forums are visible
1.1030 + $sql = 'SELECT forum_id, forum_name, parent_id, left_id, right_id
1.1031 + FROM ' . FORUMS_TABLE . '
1.1032 + ORDER BY left_id ASC';
1.1033 + $result = $db->sql_query($sql);
1.1034 +
1.1035 + $parent_forums = $forums = array();
1.1036 + while ($row = $db->sql_fetchrow($result))
1.1037 + {
1.1038 + if ($row['parent_id'] == 0)
1.1039 + {
1.1040 + mass_auth('group_role', $row['forum_id'], 'administrators', 'FORUM_FULL');
1.1041 + mass_auth('group_role', $row['forum_id'], 'global_moderators', 'FORUM_FULL');
1.1042 + $parent_forums[] = $row;
1.1043 + }
1.1044 + else
1.1045 + {
1.1046 + $forums[] = $row;
1.1047 + }
1.1048 + }
1.1049 + $db->sql_freeresult($result);
1.1050 +
1.1051 + global $auth;
1.1052 +
1.1053 + // Let us see which groups have access to these forums...
1.1054 + foreach ($parent_forums as $row)
1.1055 + {
1.1056 + // Get the children
1.1057 + $branch = $forum_ids = array();
1.1058 +
1.1059 + foreach ($forums as $key => $_row)
1.1060 + {
1.1061 + if ($_row['left_id'] > $row['left_id'] && $_row['left_id'] < $row['right_id'])
1.1062 + {
1.1063 + $branch[] = $_row;
1.1064 + $forum_ids[] = $_row['forum_id'];
1.1065 + continue;
1.1066 + }
1.1067 + }
1.1068 +
1.1069 + if (sizeof($forum_ids))
1.1070 + {
1.1071 + // Now make sure the user is able to read these forums
1.1072 + $hold_ary = $auth->acl_group_raw_data(false, 'f_list', $forum_ids);
1.1073 +
1.1074 + if (empty($hold_ary))
1.1075 + {
1.1076 + continue;
1.1077 + }
1.1078 +
1.1079 + foreach ($hold_ary as $g_id => $f_id_ary)
1.1080 + {
1.1081 + $set_group = false;
1.1082 +
1.1083 + foreach ($f_id_ary as $f_id => $auth_ary)
1.1084 + {
1.1085 + foreach ($auth_ary as $auth_option => $setting)
1.1086 + {
1.1087 + if ($setting == ACL_YES)
1.1088 + {
1.1089 + $set_group = true;
1.1090 + break 2;
1.1091 + }
1.1092 + }
1.1093 + }
1.1094 +
1.1095 + if ($set_group)
1.1096 + {
1.1097 + mass_auth('group', $row['forum_id'], $g_id, 'f_list', ACL_YES);
1.1098 + }
1.1099 + }
1.1100 + }
1.1101 + }
1.1102 + }
1.1103 +}
1.1104 +
1.1105 +/**
1.1106 +* Set primary group.
1.1107 +* Really simple and only based on user_level (remaining groups will be assigned later)
1.1108 +*/
1.1109 +function phpbb_set_primary_group($user_level)
1.1110 +{
1.1111 + global $convert_row;
1.1112 +
1.1113 + if ($user_level == 1)
1.1114 + {
1.1115 + return get_group_id('administrators');
1.1116 + }
1.1117 +/* else if ($user_level == 2)
1.1118 + {
1.1119 + return get_group_id('global_moderators');
1.1120 + }
1.1121 + else if ($user_level == 0 && $convert_row['user_active'])*/
1.1122 + else if ($convert_row['user_active'])
1.1123 + {
1.1124 + return get_group_id('registered');
1.1125 + }
1.1126 +
1.1127 + return 0;
1.1128 +}
1.1129 +
1.1130 +/**
1.1131 +* Convert the group name, making sure to avoid conflicts with 3.0 special groups
1.1132 +*/
1.1133 +function phpbb_convert_group_name($group_name)
1.1134 +{
1.1135 + $default_groups = array(
1.1136 + 'GUESTS',
1.1137 + 'REGISTERED',
1.1138 + 'REGISTERED_COPPA',
1.1139 + 'GLOBAL_MODERATORS',
1.1140 + 'ADMINISTRATORS',
1.1141 + 'BOTS',
1.1142 + );
1.1143 +
1.1144 + if (in_array(strtoupper($group_name), $default_groups))
1.1145 + {
1.1146 + return 'phpBB2 - ' . $group_name;
1.1147 + }
1.1148 +
1.1149 + return phpbb_set_default_encoding($group_name);
1.1150 +}
1.1151 +
1.1152 +/**
1.1153 +* Convert the group type constants
1.1154 +*/
1.1155 +function phpbb_convert_group_type($group_type)
1.1156 +{
1.1157 + switch ($group_type)
1.1158 + {
1.1159 + case 0:
1.1160 + return GROUP_OPEN;
1.1161 + break;
1.1162 +
1.1163 + case 1:
1.1164 + return GROUP_CLOSED;
1.1165 + break;
1.1166 +
1.1167 + case 2:
1.1168 + return GROUP_HIDDEN;
1.1169 + break;
1.1170 + }
1.1171 +
1.1172 + // Never return GROUP_SPECIAL here, because only phpBB3's default groups are allowed to have this type set.
1.1173 + return GROUP_HIDDEN;
1.1174 +}
1.1175 +
1.1176 +/**
1.1177 +* Convert the topic type constants
1.1178 +*/
1.1179 +function phpbb_convert_topic_type($topic_type)
1.1180 +{
1.1181 + switch ($topic_type)
1.1182 + {
1.1183 + case 0:
1.1184 + return POST_NORMAL;
1.1185 + break;
1.1186 +
1.1187 + case 1:
1.1188 + return POST_STICKY;
1.1189 + break;
1.1190 +
1.1191 + case 2:
1.1192 + return POST_ANNOUNCE;
1.1193 + break;
1.1194 +
1.1195 + case 3:
1.1196 + return POST_GLOBAL;
1.1197 + break;
1.1198 + }
1.1199 +
1.1200 + return POST_NORMAL;
1.1201 +}
1.1202 +
1.1203 +function phpbb_replace_size($matches)
1.1204 +{
1.1205 + return '[size=' . min(200, ceil(100.0 * (((double) $matches[1])/12.0))) . ':' . $matches[2] . ']';
1.1206 +}
1.1207 +
1.1208 +/**
1.1209 +* Reparse the message stripping out the bbcode_uid values and adding new ones and setting the bitfield
1.1210 +* @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
1.1211 +*/
1.1212 +function phpbb_prepare_message($message)
1.1213 +{
1.1214 + global $phpbb_root_path, $phpEx, $db, $convert, $user, $config, $cache, $convert_row, $message_parser;
1.1215 +
1.1216 + if (!$message)
1.1217 + {
1.1218 + $convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = 0;
1.1219 + return '';
1.1220 + }
1.1221 +
1.1222 + // Decode phpBB 2.0.x Message
1.1223 + if (isset($convert->row['old_bbcode_uid']) && $convert->row['old_bbcode_uid'] != '')
1.1224 + {
1.1225 + // Adjust size...
1.1226 + if (strpos($message, '[size=') !== false)
1.1227 + {
1.1228 + $message = preg_replace_callback('/\[size=(\d*):(' . $convert->row['old_bbcode_uid'] . ')\]/', 'phpbb_replace_size', $message);
1.1229 + }
1.1230 +
1.1231 + $message = preg_replace('/\:(([a-z0-9]:)?)' . $convert->row['old_bbcode_uid'] . '/s', '', $message);
1.1232 + }
1.1233 +
1.1234 + if (strpos($message, '[quote=') !== false)
1.1235 + {
1.1236 + $message = preg_replace('/\[quote="(.*?)"\]/s', '[quote="\1"]', $message);
1.1237 + $message = preg_replace('/\[quote=\\\"(.*?)\\\"\]/s', '[quote="\1"]', $message);
1.1238 +
1.1239 + // let's hope that this solves more problems than it causes. Deal with escaped quotes.
1.1240 + $message = str_replace('\"', '"', $message);
1.1241 + $message = str_replace('\"', '"', $message);
1.1242 + }
1.1243 +
1.1244 + // Already the new user id ;)
1.1245 + $user_id = $convert->row['poster_id'];
1.1246 +
1.1247 + $message = str_replace('<br />', "\n", $message);
1.1248 + $message = str_replace('<', '<', $message);
1.1249 + $message = str_replace('>', '>', $message);
1.1250 +
1.1251 + // make the post UTF-8
1.1252 + $message = phpbb_set_encoding($message);
1.1253 +
1.1254 + $message_parser->warn_msg = array(); // Reset the errors from the previous message
1.1255 + $message_parser->bbcode_uid = make_uid($convert->row['post_time']);
1.1256 + $message_parser->message = $message;
1.1257 + unset($message);
1.1258 +
1.1259 + // Make sure options are set.
1.1260 +// $enable_html = (!isset($row['enable_html'])) ? false : $row['enable_html'];
1.1261 + $enable_bbcode = (!isset($convert->row['enable_bbcode'])) ? true : $convert->row['enable_bbcode'];
1.1262 + $enable_smilies = (!isset($convert->row['enable_smilies'])) ? true : $convert->row['enable_smilies'];
1.1263 + $enable_magic_url = (!isset($convert->row['enable_magic_url'])) ? true : $convert->row['enable_magic_url'];
1.1264 +
1.1265 + // 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')
1.1266 + $message_parser->parse($enable_bbcode, $enable_magic_url, $enable_smilies);
1.1267 +
1.1268 + if (sizeof($message_parser->warn_msg))
1.1269 + {
1.1270 + $msg_id = isset($convert->row['post_id']) ? $convert->row['post_id'] : $convert->row['privmsgs_id'];
1.1271 + $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);
1.1272 + }
1.1273 +
1.1274 + $convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = $message_parser->bbcode_bitfield;
1.1275 +
1.1276 + $message = $message_parser->message;
1.1277 + unset($message_parser->message);
1.1278 +
1.1279 + return $message;
1.1280 +}
1.1281 +
1.1282 +/**
1.1283 +* Return the bitfield calculated by the previous function
1.1284 +*/
1.1285 +function get_bbcode_bitfield()
1.1286 +{
1.1287 + global $convert_row;
1.1288 +
1.1289 + return $convert_row['mp_bbcode_bitfield'];
1.1290 +}
1.1291 +
1.1292 +/**
1.1293 +* Determine the last user to edit a post
1.1294 +* 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
1.1295 +*/
1.1296 +function phpbb_post_edit_user()
1.1297 +{
1.1298 + global $convert_row, $config;
1.1299 +
1.1300 + if (isset($convert_row['post_edit_count']))
1.1301 + {
1.1302 + return phpbb_user_id($convert_row['poster_id']);
1.1303 + }
1.1304 +
1.1305 + return 0;
1.1306 +}
1.1307 +
1.1308 +/**
1.1309 +* Obtain the path to uploaded files on the 2.0.x forum
1.1310 +* This is only used if the Attachment MOD was installed
1.1311 +*/
1.1312 +function phpbb_get_files_dir()
1.1313 +{
1.1314 + if (!defined('MOD_ATTACHMENT'))
1.1315 + {
1.1316 + return;
1.1317 + }
1.1318 +
1.1319 + global $src_db, $same_db, $convert, $user, $config, $cache;
1.1320 +
1.1321 + if ($convert->mysql_convert && $same_db)
1.1322 + {
1.1323 + $src_db->sql_query("SET NAMES 'binary'");
1.1324 + }
1.1325 + $sql = 'SELECT config_value AS upload_dir
1.1326 + FROM ' . $convert->src_table_prefix . "attachments_config
1.1327 + WHERE config_name = 'upload_dir'";
1.1328 + $result = $src_db->sql_query($sql);
1.1329 + $upload_path = $src_db->sql_fetchfield('upload_dir');
1.1330 + $src_db->sql_freeresult($result);
1.1331 +
1.1332 + $sql = 'SELECT config_value AS ftp_upload
1.1333 + FROM ' . $convert->src_table_prefix . "attachments_config
1.1334 + WHERE config_name = 'allow_ftp_upload'";
1.1335 + $result = $src_db->sql_query($sql);
1.1336 + $ftp_upload = (int) $src_db->sql_fetchfield('ftp_upload');
1.1337 + $src_db->sql_freeresult($result);
1.1338 +
1.1339 + if ($convert->mysql_convert && $same_db)
1.1340 + {
1.1341 + $src_db->sql_query("SET NAMES 'utf8'");
1.1342 + }
1.1343 +
1.1344 + if ($ftp_upload)
1.1345 + {
1.1346 + $convert->p_master->error($user->lang['CONV_ERROR_ATTACH_FTP_DIR'], __LINE__, __FILE__);
1.1347 + }
1.1348 +
1.1349 + return $upload_path;
1.1350 +}
1.1351 +
1.1352 +/**
1.1353 +* Copy thumbnails of uploaded images from the 2.0.x forum
1.1354 +* This is only used if the Attachment MOD was installed
1.1355 +*/
1.1356 +function phpbb_copy_thumbnails()
1.1357 +{
1.1358 + global $db, $convert, $user, $config, $cache, $phpbb_root_path;
1.1359 +
1.1360 + $src_path = $convert->options['forum_path'] . '/' . phpbb_get_files_dir() . '/thumbs/';
1.1361 +
1.1362 + if ($handle = @opendir($src_path))
1.1363 + {
1.1364 + while ($entry = readdir($handle))
1.1365 + {
1.1366 + if ($entry[0] == '.')
1.1367 + {
1.1368 + continue;
1.1369 + }
1.1370 +
1.1371 + if (is_dir($src_path . $entry))
1.1372 + {
1.1373 + continue;
1.1374 + }
1.1375 + else
1.1376 + {
1.1377 + copy_file($src_path . $entry, $config['upload_path'] . '/' . preg_replace('/^t_/', 'thumb_', $entry));
1.1378 + @unlink($phpbb_root_path . $config['upload_path'] . '/thumbs/' . $entry);
1.1379 + }
1.1380 + }
1.1381 + closedir($handle);
1.1382 + }
1.1383 +}
1.1384 +
1.1385 +/**
1.1386 +* Convert the attachment category constants
1.1387 +* This is only used if the Attachment MOD was installed
1.1388 +*/
1.1389 +function phpbb_attachment_category($cat_id)
1.1390 +{
1.1391 + switch ($cat_id)
1.1392 + {
1.1393 + case 1:
1.1394 + return ATTACHMENT_CATEGORY_IMAGE;
1.1395 + break;
1.1396 +
1.1397 + case 2:
1.1398 + return ATTACHMENT_CATEGORY_WM;
1.1399 + break;
1.1400 +
1.1401 + case 3:
1.1402 + return ATTACHMENT_CATEGORY_FLASH;
1.1403 + break;
1.1404 + }
1.1405 +
1.1406 + return ATTACHMENT_CATEGORY_NONE;
1.1407 +}
1.1408 +
1.1409 +/**
1.1410 +* Obtain list of forums in which different attachment categories can be used
1.1411 +*/
1.1412 +function phpbb_attachment_forum_perms($forum_permissions)
1.1413 +{
1.1414 + if (empty($forum_permissions))
1.1415 + {
1.1416 + return '';
1.1417 + }
1.1418 +
1.1419 + // Decode forum permissions
1.1420 + $forum_ids = array();
1.1421 +
1.1422 + $one_char_encoding = '#';
1.1423 + $two_char_encoding = '.';
1.1424 +
1.1425 + $auth_len = 1;
1.1426 + for ($pos = 0; $pos < strlen($forum_permissions); $pos += $auth_len)
1.1427 + {
1.1428 + $forum_auth = substr($forum_permissions, $pos, 1);
1.1429 + if ($forum_auth == $one_char_encoding)
1.1430 + {
1.1431 + $auth_len = 1;
1.1432 + continue;
1.1433 + }
1.1434 + else if ($forum_auth == $two_char_encoding)
1.1435 + {
1.1436 + $auth_len = 2;
1.1437 + $pos--;
1.1438 + continue;
1.1439 + }
1.1440 +
1.1441 + $forum_auth = substr($forum_permissions, $pos, $auth_len);
1.1442 + $forum_id = base64_unpack($forum_auth);
1.1443 +
1.1444 + $forum_ids[] = (int) $forum_id;
1.1445 + }
1.1446 +
1.1447 + if (sizeof($forum_ids))
1.1448 + {
1.1449 + return attachment_forum_perms($forum_ids);
1.1450 + }
1.1451 +
1.1452 + return '';
1.1453 +}
1.1454 +
1.1455 +/**
1.1456 +* Convert the avatar type constants
1.1457 +*/
1.1458 +function phpbb_avatar_type($type)
1.1459 +{
1.1460 + switch ($type)
1.1461 + {
1.1462 + case 1:
1.1463 + return AVATAR_UPLOAD;
1.1464 + break;
1.1465 +
1.1466 + case 2:
1.1467 + return AVATAR_REMOTE;
1.1468 + break;
1.1469 +
1.1470 + case 3:
1.1471 + return AVATAR_GALLERY;
1.1472 + break;
1.1473 + }
1.1474 +
1.1475 + return 0;
1.1476 +}
1.1477 +
1.1478 +
1.1479 +/**
1.1480 +* Just undos the replacing of '<' and '>'
1.1481 +*/
1.1482 +function phpbb_smilie_html_decode($code)
1.1483 +{
1.1484 + $code = str_replace('<', '<', $code);
1.1485 + return str_replace('>', '>', $code);
1.1486 +}
1.1487 +
1.1488 +/**
1.1489 +* Transfer avatars, copying the image if it was uploaded
1.1490 +*/
1.1491 +function phpbb_import_avatar($user_avatar)
1.1492 +{
1.1493 + global $convert_row;
1.1494 +
1.1495 + if (!$convert_row['user_avatar_type'])
1.1496 + {
1.1497 + return '';
1.1498 + }
1.1499 + else if ($convert_row['user_avatar_type'] == 1)
1.1500 + {
1.1501 + // Uploaded avatar
1.1502 + return import_avatar($user_avatar, false, $convert_row['user_id']);
1.1503 + }
1.1504 + else if ($convert_row['user_avatar_type'] == 2)
1.1505 + {
1.1506 + // Remote avatar
1.1507 + return $user_avatar;
1.1508 + }
1.1509 + else if ($convert_row['user_avatar_type'] == 3)
1.1510 + {
1.1511 + // Gallery avatar
1.1512 + return $user_avatar;
1.1513 + }
1.1514 +
1.1515 + return '';
1.1516 +}
1.1517 +
1.1518 +
1.1519 +/**
1.1520 +* Find out about the avatar's dimensions
1.1521 +*/
1.1522 +function phpbb_get_avatar_height($user_avatar)
1.1523 +{
1.1524 + global $convert_row;
1.1525 +
1.1526 + if (empty($convert_row['user_avatar_type']))
1.1527 + {
1.1528 + return 0;
1.1529 + }
1.1530 + return get_avatar_height($user_avatar, 'phpbb_avatar_type', $convert_row['user_avatar_type']);
1.1531 +}
1.1532 +
1.1533 +
1.1534 +/**
1.1535 +* Find out about the avatar's dimensions
1.1536 +*/
1.1537 +function phpbb_get_avatar_width($user_avatar)
1.1538 +{
1.1539 + global $convert_row;
1.1540 +
1.1541 + if (empty($convert_row['user_avatar_type']))
1.1542 + {
1.1543 + return 0;
1.1544 + }
1.1545 +
1.1546 + return get_avatar_width($user_avatar, 'phpbb_avatar_type', $convert_row['user_avatar_type']);
1.1547 +}
1.1548 +
1.1549 +
1.1550 +/**
1.1551 +* Calculate the correct to_address field for private messages
1.1552 +*/
1.1553 +function phpbb_privmsgs_to_userid($to_userid)
1.1554 +{
1.1555 + global $config;
1.1556 +
1.1557 + return 'u_' . phpbb_user_id($to_userid);
1.1558 +}
1.1559 +
1.1560 +/**
1.1561 +* Calculate whether a private message was unread using the bitfield
1.1562 +*/
1.1563 +function phpbb_unread_pm($pm_type)
1.1564 +{
1.1565 + return ($pm_type == 5) ? 1 : 0;
1.1566 +}
1.1567 +
1.1568 +/**
1.1569 +* Calculate whether a private message was new using the bitfield
1.1570 +*/
1.1571 +function phpbb_new_pm($pm_type)
1.1572 +{
1.1573 + return ($pm_type == 1) ? 1 : 0;
1.1574 +}
1.1575 +
1.1576 +/**
1.1577 +* Obtain the folder_id for the custom folder created to replace the savebox from 2.0.x (used to store saved private messages)
1.1578 +*/
1.1579 +function phpbb_get_savebox_id($user_id)
1.1580 +{
1.1581 + global $db;
1.1582 +
1.1583 + $user_id = phpbb_user_id($user_id);
1.1584 +
1.1585 + // Only one custom folder, check only one
1.1586 + $sql = 'SELECT folder_id
1.1587 + FROM ' . PRIVMSGS_FOLDER_TABLE . '
1.1588 + WHERE user_id = ' . $user_id;
1.1589 + $result = $db->sql_query_limit($sql, 1);
1.1590 + $folder_id = (int) $db->sql_fetchfield('folder_id');
1.1591 + $db->sql_freeresult($result);
1.1592 +
1.1593 + return $folder_id;
1.1594 +}
1.1595 +
1.1596 +/**
1.1597 +* Transfer attachment specific configuration options
1.1598 +* These were not stored in the main config table on 2.0.x
1.1599 +* This is only used if the Attachment MOD was installed
1.1600 +*/
1.1601 +function phpbb_import_attach_config()
1.1602 +{
1.1603 + global $db, $src_db, $same_db, $convert, $config;
1.1604 +
1.1605 + if ($convert->mysql_convert && $same_db)
1.1606 + {
1.1607 + $src_db->sql_query("SET NAMES 'binary'");
1.1608 + }
1.1609 +
1.1610 + $sql = 'SELECT *
1.1611 + FROM ' . $convert->src_table_prefix . 'attachments_config';
1.1612 + $result = $src_db->sql_query($sql);
1.1613 +
1.1614 + if ($convert->mysql_convert && $same_db)
1.1615 + {
1.1616 + $src_db->sql_query("SET NAMES 'utf8'");
1.1617 + }
1.1618 +
1.1619 + $attach_config = array();
1.1620 + while ($row = $src_db->sql_fetchrow($result))
1.1621 + {
1.1622 + $attach_config[$row['config_name']] = $row['config_value'];
1.1623 + }
1.1624 + $src_db->sql_freeresult($result);
1.1625 +
1.1626 + set_config('allow_attachments', 1);
1.1627 +
1.1628 + // old attachment mod? Must be very old if this entry do not exist...
1.1629 + if (!empty($attach_config['display_order']))
1.1630 + {
1.1631 + set_config('display_order', $attach_config['display_order']);
1.1632 + }
1.1633 + set_config('max_filesize', $attach_config['max_filesize']);
1.1634 + set_config('max_filesize_pm', $attach_config['max_filesize_pm']);
1.1635 + set_config('attachment_quota', $attach_config['attachment_quota']);
1.1636 + set_config('max_attachments', $attach_config['max_attachments']);
1.1637 + set_config('max_attachments_pm', $attach_config['max_attachments_pm']);
1.1638 + set_config('allow_pm_attach', $attach_config['allow_pm_attach']);
1.1639 +
1.1640 + set_config('img_display_inlined', $attach_config['img_display_inlined']);
1.1641 + set_config('img_max_width', $attach_config['img_max_width']);
1.1642 + set_config('img_max_height', $attach_config['img_max_height']);
1.1643 + set_config('img_link_width', $attach_config['img_link_width']);
1.1644 + set_config('img_link_height', $attach_config['img_link_height']);
1.1645 + set_config('img_create_thumbnail', $attach_config['img_create_thumbnail']);
1.1646 + set_config('img_max_thumb_width', 400);
1.1647 + set_config('img_min_thumb_filesize', $attach_config['img_min_thumb_filesize']);
1.1648 + set_config('img_imagick', $attach_config['img_imagick']);
1.1649 +}
1.1650 +
1.1651 +/**
1.1652 +* Calculate the date a user became inactive
1.1653 +*/
1.1654 +function phpbb_inactive_time()
1.1655 +{
1.1656 + global $convert_row;
1.1657 +
1.1658 + if ($convert_row['user_active'])
1.1659 + {
1.1660 + return 0;
1.1661 + }
1.1662 +
1.1663 + if ($convert_row['user_lastvisit'])
1.1664 + {
1.1665 + return $convert_row['user_lastvisit'];
1.1666 + }
1.1667 +
1.1668 + return $convert_row['user_regdate'];
1.1669 +}
1.1670 +
1.1671 +/**
1.1672 +* Calculate the reason a user became inactive
1.1673 +* We can't actually tell the difference between a manual deactivation and one for profile changes
1.1674 +* from the data available to assume the latter
1.1675 +*/
1.1676 +function phpbb_inactive_reason()
1.1677 +{
1.1678 + global $convert_row;
1.1679 +
1.1680 + if ($convert_row['user_active'])
1.1681 + {
1.1682 + return 0;
1.1683 + }
1.1684 +
1.1685 + if ($convert_row['user_lastvisit'])
1.1686 + {
1.1687 + return INACTIVE_PROFILE;
1.1688 + }
1.1689 +
1.1690 + return INACTIVE_REGISTER;
1.1691 +}
1.1692 +
1.1693 +/**
1.1694 +* Adjust 2.0.x disallowed names to 3.0.x format
1.1695 +*/
1.1696 +function phpbb_disallowed_username($username)
1.1697 +{
1.1698 + // Replace * with %
1.1699 + $username = phpbb_set_default_encoding(str_replace('*', '%', $username));
1.1700 + return utf8_htmlspecialchars($username);
1.1701 +}
1.1702 +
1.1703 +/**
1.1704 +* Checks whether there are any usernames on the old board that would map to the same
1.1705 +* username_clean on phpBB3. Prints out a list if any exist and exits.
1.1706 +*/
1.1707 +function phpbb_create_userconv_table()
1.1708 +{
1.1709 + global $db, $src_db, $convert, $table_prefix, $user, $lang;
1.1710 +
1.1711 + $map_dbms = '';
1.1712 + switch ($db->sql_layer)
1.1713 + {
1.1714 + case 'mysql':
1.1715 + $map_dbms = 'mysql_40';
1.1716 + break;
1.1717 +
1.1718 + case 'mysql4':
1.1719 + if (version_compare($db->sql_server_info(true), '4.1.3', '>='))
1.1720 + {
1.1721 + $map_dbms = 'mysql_41';
1.1722 + }
1.1723 + else
1.1724 + {
1.1725 + $map_dbms = 'mysql_40';
1.1726 + }
1.1727 + break;
1.1728 +
1.1729 + case 'mysqli':
1.1730 + $map_dbms = 'mysql_41';
1.1731 + break;
1.1732 +
1.1733 + case 'mssql':
1.1734 + case 'mssql_odbc':
1.1735 + case 'mssqlnative':
1.1736 + $map_dbms = 'mssql';
1.1737 + break;
1.1738 +
1.1739 + default:
1.1740 + $map_dbms = $db->sql_layer;
1.1741 + break;
1.1742 + }
1.1743 +
1.1744 + // create a temporary table in which we store the clean usernames
1.1745 + $drop_sql = 'DROP TABLE ' . USERCONV_TABLE;
1.1746 + switch ($map_dbms)
1.1747 + {
1.1748 + case 'firebird':
1.1749 + $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1.1750 + user_id INTEGER NOT NULL,
1.1751 + username_clean VARCHAR(255) CHARACTER SET UTF8 DEFAULT \'\' NOT NULL COLLATE UNICODE
1.1752 + )';
1.1753 + break;
1.1754 +
1.1755 + case 'mssql':
1.1756 + $create_sql = 'CREATE TABLE [' . USERCONV_TABLE . '] (
1.1757 + [user_id] [int] NOT NULL ,
1.1758 + [username_clean] [varchar] (255) DEFAULT (\'\') NOT NULL
1.1759 + )';
1.1760 + break;
1.1761 +
1.1762 + case 'mysql_40':
1.1763 + $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1.1764 + user_id mediumint(8) NOT NULL,
1.1765 + username_clean blob NOT NULL
1.1766 + )';
1.1767 + break;
1.1768 +
1.1769 + case 'mysql_41':
1.1770 + $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1.1771 + user_id mediumint(8) NOT NULL,
1.1772 + username_clean varchar(255) DEFAULT \'\' NOT NULL
1.1773 + ) CHARACTER SET `utf8` COLLATE `utf8_bin`';
1.1774 + break;
1.1775 +
1.1776 + case 'oracle':
1.1777 + $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1.1778 + user_id number(8) NOT NULL,
1.1779 + username_clean varchar2(255) DEFAULT \'\'
1.1780 + )';
1.1781 + break;
1.1782 +
1.1783 + case 'postgres':
1.1784 + $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1.1785 + user_id INT4 DEFAULT \'0\',
1.1786 + username_clean varchar_ci DEFAULT \'\' NOT NULL
1.1787 + )';
1.1788 + break;
1.1789 +
1.1790 + case 'sqlite':
1.1791 + $create_sql = 'CREATE TABLE ' . USERCONV_TABLE . ' (
1.1792 + user_id INTEGER NOT NULL DEFAULT \'0\',
1.1793 + username_clean varchar(255) NOT NULL DEFAULT \'\'
1.1794 + )';
1.1795 + break;
1.1796 + }
1.1797 +
1.1798 + $db->sql_return_on_error(true);
1.1799 + $db->sql_query($drop_sql);
1.1800 + $db->sql_return_on_error(false);
1.1801 + $db->sql_query($create_sql);
1.1802 +}
1.1803 +
1.1804 +function phpbb_check_username_collisions()
1.1805 +{
1.1806 + global $db, $src_db, $convert, $table_prefix, $user, $lang;
1.1807 +
1.1808 + // now find the clean version of the usernames that collide
1.1809 + $sql = 'SELECT username_clean
1.1810 + FROM ' . USERCONV_TABLE .'
1.1811 + GROUP BY username_clean
1.1812 + HAVING COUNT(user_id) > 1';
1.1813 + $result = $db->sql_query($sql);
1.1814 +
1.1815 + $colliding_names = array();
1.1816 + while ($row = $db->sql_fetchrow($result))
1.1817 + {
1.1818 + $colliding_names[] = $row['username_clean'];
1.1819 + }
1.1820 + $db->sql_freeresult($result);
1.1821 +
1.1822 + // there was at least one collision, the admin will have to solve it before conversion can continue
1.1823 + if (sizeof($colliding_names))
1.1824 + {
1.1825 + $sql = 'SELECT user_id, username_clean
1.1826 + FROM ' . USERCONV_TABLE . '
1.1827 + WHERE ' . $db->sql_in_set('username_clean', $colliding_names);
1.1828 + $result = $db->sql_query($sql);
1.1829 + unset($colliding_names);
1.1830 +
1.1831 + $colliding_user_ids = array();
1.1832 + while ($row = $db->sql_fetchrow($result))
1.1833 + {
1.1834 + $colliding_user_ids[(int) $row['user_id']] = $row['username_clean'];
1.1835 + }
1.1836 + $db->sql_freeresult($result);
1.1837 +
1.1838 + $sql = 'SELECT username, user_id, user_posts
1.1839 + FROM ' . $convert->src_table_prefix . 'users
1.1840 + WHERE ' . $src_db->sql_in_set('user_id', array_keys($colliding_user_ids));
1.1841 + $result = $src_db->sql_query($sql);
1.1842 +
1.1843 + $colliding_users = array();
1.1844 + while ($row = $src_db->sql_fetchrow($result))
1.1845 + {
1.1846 + $row['user_id'] = (int) $row['user_id'];
1.1847 + if (isset($colliding_user_ids[$row['user_id']]))
1.1848 + {
1.1849 + $colliding_users[$colliding_user_ids[$row['user_id']]][] = $row;
1.1850 + }
1.1851 + }
1.1852 + $src_db->sql_freeresult($result);
1.1853 + unset($colliding_user_ids);
1.1854 +
1.1855 + $list = '';
1.1856 + foreach ($colliding_users as $username_clean => $users)
1.1857 + {
1.1858 + $list .= sprintf($user->lang['COLLIDING_CLEAN_USERNAME'], $username_clean) . "<br />\n";
1.1859 + foreach ($users as $i => $row)
1.1860 + {
1.1861 + $list .= sprintf($user->lang['COLLIDING_USER'], $row['user_id'], phpbb_set_default_encoding($row['username']), $row['user_posts']) . "<br />\n";
1.1862 + }
1.1863 + }
1.1864 +
1.1865 + $lang['INST_ERR_FATAL'] = $user->lang['CONV_ERR_FATAL'];
1.1866 + $convert->p_master->error('<span style="color:red">' . $user->lang['COLLIDING_USERNAMES_FOUND'] . '</span></b><br /><br />' . $list . '<b>', __LINE__, __FILE__);
1.1867 + }
1.1868 +
1.1869 + $drop_sql = 'DROP TABLE ' . USERCONV_TABLE;
1.1870 + $db->sql_query($drop_sql);
1.1871 +}
1.1872 +
1.1873 +?>
1.1874 \ No newline at end of file