IPB 2.3.x to phpBB 3

Converting from other board software? Good decision! Need help? Have a question about a convertor? Wish to offer a convertor package? Post here.
Suggested Hosts
Locked
.EC
Registered User
Posts: 4
Joined: Mon Jun 04, 2007 3:03 pm
Location: Florianópolis - SC - Brazil

IPB 2.3.x to phpBB 3

Post by .EC » Fri Aug 24, 2007 11:16 pm

Somebody have the converter of the IPB 2.3.x to phpBB 3?

Sorry my english. I'm from Brazil.
Eduardo Coelho

User avatar
D¡cky
Former Team Member
Posts: 11812
Joined: Tue Jan 25, 2005 8:38 pm
Location: New Hampshire, USA
Name: Richard Foote
Contact:

Re: IPB 2.3.x to phpBB 3

Post by D¡cky » Sun Aug 26, 2007 2:21 am

There is no convertor at the present time. You can convert IPB > phpBB2 > phpBB3.
Have you hugged someone today?

Klia
Registered User
Posts: 21
Joined: Sun Aug 26, 2007 8:28 pm
Contact:

Re: IPB 2.3.x to phpBB 3

Post by Klia » Sun Aug 26, 2007 8:34 pm

i have created one, but it is very limited(ban settings, polls, several fields from profiles not included) and it needs more testing.

mbhpotter
Registered User
Posts: 15
Joined: Sat Mar 22, 2003 3:17 pm

Re: IPB 2.3.x to phpBB 3

Post by mbhpotter » Mon Aug 27, 2007 1:23 pm

Hey Klia, would you post your converter when it's done?
i would really like to use it..
thank you:-)

.EC
Registered User
Posts: 4
Joined: Mon Jun 04, 2007 3:03 pm
Location: Florianópolis - SC - Brazil

Re: IPB 2.3.x to phpBB 3

Post by .EC » Sun Sep 02, 2007 3:26 am

D¡cky,
It only has a problem… The passwords do not function.

Klia,
Please, post your convertor.
Eduardo Coelho

Klia
Registered User
Posts: 21
Joined: Sun Aug 26, 2007 8:28 pm
Contact:

Re: IPB 2.3.x to phpBB 3

Post by Klia » Fri Sep 07, 2007 9:17 pm

Of course!

In my convertor passwords also do not function, because of different password storage system - phpBB3 uses md5(password), IPB 2.3.x uses md5(md5(salt)+md5(password)).

Convertor flags these passwords as "converted" and forces user to change password.

User avatar
D¡cky
Former Team Member
Posts: 11812
Joined: Tue Jan 25, 2005 8:38 pm
Location: New Hampshire, USA
Name: Richard Foote
Contact:

Re: IPB 2.3.x to phpBB 3

Post by D¡cky » Fri Sep 07, 2007 11:25 pm

Passwords can be made to work and they should be made to work. It is much more user friendly.

Klia,
PM me if you want more info.
Have you hugged someone today?

joshuaali
Registered User
Posts: 4
Joined: Thu Sep 06, 2007 10:31 am

Re: IPB 2.3.x to phpBB 3

Post by joshuaali » Mon Sep 10, 2007 10:29 am

There's probably a better way, but this is what I did after using Dicky's IPB->phpBB2 converter, and it works:

http://alz.dzerox.com/phpbb3_auth_mod.txt

Klia
Registered User
Posts: 21
Joined: Sun Aug 26, 2007 8:28 pm
Contact:

Re: IPB 2.3.x to phpBB 3

Post by Klia » Fri Sep 28, 2007 1:54 pm

Done with convertor.
Does not import banlist and config variables, except upload path. also it does not import passwords.

And you can freely replace utf8_strtolower to more standart utf8_cleanstring. I'm used utf8_strtolower, coze some cyrillic characters does not save in database, which causes sign in problems with completely cyrillic logins.

convert_ipb23.php

Code: Select all

<?php
error_reporting(0);
/** 
*
* @package install
* @version $Id: convert_phpbb20.php,v 1.44 2007/08/24 18:26:15 acydburn Exp $
* @copyright (c) 2006 phpBB Group 
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* NOTE to potential convertor authors. Please use this file to get
* familiar with the structure since we added some bare explanations here.
*
* Since this file gets included more than once on one page you are not able to add functions to it.
* Instead use a functions_ file.
*
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

include($phpbb_root_path . 'config.' . $phpEx);
unset($dbpasswd);

/**
* $convertor_data provides some basic information about this convertor which is
* used on the initial list of convertors and to populate the default settings
*/
$convertor_data = array(
	'forum_name'	=> 'Invision Power Board 2.3.x',
	'version'		=> '0.1',
	'phpbb_version'	=> '3.0.0',
	'author'		=> '<a href="mailto:alina0584@gmail.com">Klia</a>',
	'dbms'			=> $dbms,
	'dbhost'		=> $dbhost,
	'dbport'		=> $dbport,
	'dbuser'		=> $dbuser,
	'dbpasswd'		=> '',
	'dbname'		=> 'ipb',
	'table_prefix'	=> 'ibf_',
	'forum_path'	=> 'forums/',
	'author_notes'	=> '',
);

/**
* $tables is a list of the tables (minus prefix) which we expect to find in the
* source forum. It is used to guess the prefix if the specified prefix is incorrect
*/
$tables = array(
	'banfilters',
	'forums',
	'members',
	'member_extra',
	'groups',
	'faq',
	'emoticons',
	'contacts',
	'converge_local', 
	'message_text', 
	'message_topics', 
	'forum_tracker',
	'forum_perms',
	'email_logs',
	'members_partial',
	'pfields_content',
	'pfields_data',
	'dnames_change',
	'cal_events',
	'cal_calendars',
	'cache_store',
	'polls' 
);

/**
* $config_schema details how the board configuration information is stored in the source forum.
*
* 'table_format' can take the value 'file' to indicate a config file. In this case array_name
* is set to indicate the name of the array the config values are stored in
* 'table_format' can be an array if the values are stored in a table which is an assosciative array
* (as per phpBB 2.0.x)
* If left empty, values are assumed to be stored in a table where each config setting is
* a column (as per phpBB 1.x)
*
* In either of the latter cases 'table_name' indicates the name of the table in the database
*
* 'settings' is an array which maps the name of the config directive in the source forum
* to the config directive in phpBB3. It can either be a direct mapping or use a function.
* Please note that the contents of the old config value are passed to the function, therefore
* an in-built function requiring the variable passed by reference is not able to be used. Since
* empty() is such a function we created the function is_empty() to be used instead.
*/
$config_schema = array(
	'table_name'	=>	'conf_settings',
	'table_format'	=>	array('conf_key' => 'conf_value'),
	'settings'		=>	array(
		'msg_allow_code'=> 'allow_bbcode',
		'auth_allow_dnames'=> 'allow_namechange',
		'avatars_on'	=> 'allow_avatar_local',
		'avatar_url'	=> 'allow_avatar_remote',
		'board_offline'			=> 'board_disable',
		'board_name'				=> 'sitename',
		'session_expiration'		=> 'session_length',
		'display_max_posts'		=> 'posts_per_page',
		'display_max_topics'		=> 'topics_per_page',
		'allow_skins'	=> 'override_user_style',
		'max_poll_choices'		=> 'max_poll_options',
		'max_sig_length'			=> 'max_sig_chars',
		'show_max_msg_list'			=> 'max_inbox_privmsgs',
		'smtp_port'			=> 'smtp_delivery',
		'smtp_host'				=> 'smtp_host',
		'smtp_username'			=> 'smtp_username',
		'smtp_password'			=> 'smtp_password',
		'flood_control'		=> 'flood_interval',
		'csite_article_date'	=> 'default_dateformat',
		'time_offset'		=> 'board_timezone',
		'disable_gzip'			=> 'not(gzip_compress)',
		'use_coppa'			=> 'is_empty(coppa_mail)',
		'coppa_fax'				=> 'coppa_fax'
	)
);

/**
* $test_file is the name of a file which is present on the source
* forum which can be used to check that the path specified by the 
* user was correct
*/
$test_file = 'init.php';

/**
* If this is set then we are not generating the first page of information but getting the conversion information.
*/
if (!$get_info)
{
	/**
	* Tests for further MODs can be included here.
	* Please use constants for this, prefixing them with MOD_
	*/

	$src_db->sql_return_on_error(false);

	// Now let us set a temporary config variable for user id incrementing
	$sql = "SELECT id
		FROM {$convert->src_table_prefix}members
		WHERE id = 1";
	$result = $src_db->sql_query($sql);
	$user_id = (int) $src_db->sql_fetchfield('id');
	$src_db->sql_freeresult($result);

	// If there is a user id 1, we need to increment user ids. :/
	if ($user_id === 1)
	{
		// Try to get the maximum user id possible...
		$sql = "SELECT MAX(id) AS max_user_id
			FROM {$convert->src_table_prefix}members";
		$result = $src_db->sql_query($sql);
		$user_id = (int) $src_db->sql_fetchfield('max_user_id');
		$src_db->sql_freeresult($result);

		set_config('increment_user_id', ($user_id + 1), true);
	}
	else
	{
		set_config('increment_user_id', 0, true);
	}


/**
*	Description on how to use the convertor framework.
*
*	'schema' Syntax Description
*		-> 'target'			=> Target Table. If not specified the next table will be handled
*		-> 'primary'		=> Primary Key. If this is specified then this table is processed in batches
*		-> 'query_first'	=> array('target' or 'src', Query to execute before beginning the process
*								(if more than one then specified as array))
*		-> 'function_first'	=> Function to execute before beginning the process (if more than one then specified as array)
*								(This is mostly useful if variables need to be given to the converting process)
*		-> 'test_file'		=> This is not used at the moment but should be filled with a file from the old installation
*
*		// DB Functions
*		'distinct'	=> Add DISTINCT to the select query
*		'where'		=> Add WHERE to the select query
*		'group_by'	=> Add GROUP BY to the select query
*		'left_join'	=> Add LEFT JOIN to the select query (if more than one joins specified as array)
*		'having'	=> Add HAVING to the select query
*
*		// DB INSERT array
*		This one consist of three parameters
*		First Parameter: 
*							The key need to be filled within the target table
*							If this is empty, the target table gets not assigned the source value
*		Second Parameter:
*							Source value. If the first parameter is specified, it will be assigned this value.
*							If the first parameter is empty, this only gets added to the select query
*		Third Parameter:
*							Custom Function. Function to execute while storing source value into target table. 
*							The functions return value get stored.
*							The function parameter consist of the value of the second parameter.
*
*							types:
*								- empty string == execute nothing
*								- string == function to execute
*								- array == complex execution instructions
*		
*		Complex execution instructions:
*		@todo test complex execution instructions - in theory they will work fine
*
*							By defining an array as the third parameter you are able to define some statements to be executed. The key
*							is defining what to execute, numbers can be appended...
*
*							'function' => execute function
*							'execute' => run code, whereby all occurrences of {VALUE} get replaced by the last returned value.
*										The result *must* be assigned/stored to {RESULT}.
*							'typecast'	=> typecast value
*
*							The returned variables will be made always available to the next function to continue to work with.
*
*							example (variable inputted is an integer of 1):
*
*							array(
*								'function1'		=> 'increment_by_one',		// returned variable is 2
*								'typecast'		=> 'string',				// typecast variable to be a string
*								'execute'		=> '{RESULT} = {VALUE} . ' is good';', // returned variable is '2 is good'
*								'function2'		=> 'replace_good_with_bad',				// returned variable is '2 is bad'
*							),
*
*/

	$convertor = array(
		'test_file'				=> 'index.php',
		'avatar_path'			=> get_config_value('avatar_path') . '/',
		'avatar_gallery_path'	=> get_config_value('avatar_gallery_path') . '/',
		'upload_path'			=> phpbb_get_files_dir() . '/',
		'thumbnails'			=> array('thumbs/', 't_'),
		'ranks_path'			=> false, // phpBB 2.0.x had no config value for a ranks path


		// We empty some tables to have clean data available
		'query_first'			=> array(
			array('target', $convert->truncate_statement . SEARCH_RESULTS_TABLE),
			array('target', $convert->truncate_statement . SEARCH_WORDLIST_TABLE),
			array('target', $convert->truncate_statement . SEARCH_WORDMATCH_TABLE),
			array('target', $convert->truncate_statement . LOG_TABLE),
		),
		
//	with this you are able to import all attachment files on the fly. For large boards this is not an option, therefore commented out by default.
//	Instead every file gets copied while processing the corresponding attachment entry.

		// phpBB2 allowed some similar usernames to coexist which would have the same
		// username_clean in phpBB3 which is not possible, so we'll give the admin a list
		// of user ids and usernames and let him deicde what he wants to do with them
		'execute_first'	=> '
			phpbb_insert_forums();
			import_attachment_files();
		',

		'execute_last'	=> array('
			add_bots();
		', 'restore_config();
		',
		'
			update_folder_pm_count();
		', '
			update_unread_count();
		', '
			phpbb_convert_authentication(\'start\');
		', '
			phpbb_convert_authentication(\'first\');
		', '
			phpbb_convert_authentication(\'second\');
		', '
			phpbb_convert_authentication(\'third\');
		'),

		'schema' => array(

			array(
				'target'		=> RANKS_TABLE,
				'query_first'	=> array('target', $convert->truncate_statement . RANKS_TABLE),
				'autoincrement'	=> 'rank_id',

				array('rank_id',					'titles.id',				''),
				array('rank_title',					'titles.title',				array('function1' => 'phpbb_set_default_encoding', 'function2' => 'utf8_htmlspecialchars')),
				array('rank_min',					'titles.posts',				array('typecast' => 'int', 'execute' => '{RESULT} = ({VALUE}[0] < 0) ? 0 : {VALUE}[0];')),
				array('rank_special',				'',			''),
				array('rank_image',					'',				'import_rank'),
			),

			array(
				'target'		=> TOPICS_TABLE,
				'query_first'	=> array('target', $convert->truncate_statement . TOPICS_TABLE),
				'primary'		=> 'topics.tid',
				'autoincrement'	=> 'topic_id',

				array('topic_id',				'topics.tid',					''),
				array('forum_id',				'topics.forum_id',					''),
				array('icon_id',				0,									''),
				array('topic_poster',			'topics.starter_id AS poster_id',	'phpbb_user_id'),
				array('topic_title',			'topics.title',				'phpbb_set_encoding'),
				array('topic_time',			'topics.start_date',				''),
				array('topic_views',			'topics.views',				''),
				array('topic_replies',			'topics.posts',				''),
				array('topic_replies_real',		'topics.posts',				''),
				array('topic_last_post_id',		'topics.last_poster_id',		''),
				array('topic_status',			'',				'is_topic_locked'),
				array('topic_moved_id',			0,									''),
				array('topic_type',			'',				'phpbb_convert_topic_type'),
				array('topic_first_post_id',	'',		''),

				array('poll_title',			'polls.poll_question',	array('function1' => 'null_to_str', 'function2' => 'phpbb_set_encoding', 'function3' => 'utf8_htmlspecialchars')),
				array('poll_start',			'polls.start_date',				'null_to_zero'),
				array('poll_length',			'',			'null_to_zero'),
					array('',			'polls.choices',			'phpbb_poll'),
				array('poll_max_options',		'1',	''),
				array('poll_vote_change',		0,									''),

				'left_join'		=> 'topics LEFT JOIN polls ON polls.tid=topics.tid AND polls.forum_id=topics.forum_id',
				'where'			=> '',
			),

			
			array(
				'target'		=> POLL_VOTES_TABLE,
				'primary'		=> 'voters.tid',
				'query_first'	=> array('target', $convert->truncate_statement . POLL_VOTES_TABLE),

				array('poll_option_id',			1,									''),
				array('topic_id',				'voters.tid',				''),
				array('vote_user_id',			'voters.member_id',			'phpbb_user_id'),
				array('vote_user_ip',			'voters.ip_address',			'decode_ip'),

				'where'			=> 'voters.tid = topics.tid and polls.tid=topics.tid and polls.forum_id=topics.forum_id and poll_state=1',
			),
			array(
				'target'		=> POSTS_TABLE,
				'primary'		=> 'posts.pid',
				'autoincrement'	=> 'post_id',
				'query_first'	=> array('target', $convert->truncate_statement . POSTS_TABLE),
				'execute_first'	=> '
					$config["max_post_chars"] = -1;
					$config["max_quote_depth"] = 0;
				',

				array('post_id',				'posts.pid',					''),
				array('topic_id',				'posts.topic_id',					''),
				array('forum_id',				'',					''),
				array('poster_id',				'posts.author_id',					'phpbb_user_id'),
				array('icon_id',				0,									''),
				array('poster_ip',				'posts.ip_address',					'decode_ip'),
				array('post_time',				'posts.post_date',					''),
				array('enable_bbcode',			'',				''),
				array('',						'posts.post_htmlstate',				''),
				array('enable_smilies',			'posts.use_emo',				''),
				array('enable_sig',			'posts.use_sig',					''),
				array('enable_magic_url',		1,									''),
				array('post_username',			'posts.author_name',				'phpbb_set_encoding'),
				array('post_subject',			'posts.post_title',			'phpbb_set_encoding'),
				array('post_attachment',		'', ''),
				array('post_edit_time',			'posts.edit_time',				array('typecast' => 'int')),
				array('post_edit_count',		'',			''),
				array('post_edit_reason',		'',									''),
				array('post_edit_user',			'',									'phpbb_post_edit_user'),

				array('bbcode_uid',			'posts.post_date',					'make_uid'),
				array('post_text',			'posts.post',				'phpbb_prepare_message'),
				array('',				'',			''),
				array('bbcode_bitfield',		'',									'get_bbcode_bitfield'),
				array('post_checksum',			'',									''),

				// Commented out inline search indexing, this takes up a LOT of time. :D
				// @todo We either need to enable this or call the rebuild search functionality post convert
				/* array('',						'',									'search_indexing'),
				array('',						'',	''),
				array('',						'',	''),*/

				'where'			=>	''
			),

			array(
				'target'		=> PRIVMSGS_TABLE,
				'primary'		=> 'message_text.msg_id',
				'autoincrement'	=> 'msg_id',
				'query_first'	=> array(
					array('target', $convert->truncate_statement . PRIVMSGS_TABLE),
					array('target', $convert->truncate_statement . PRIVMSGS_RULES_TABLE),
				),

				'execute_first'	=> '
					$config["max_post_chars"] = -1;
					$config["max_quote_depth"] = 0;
				',

				array('msg_id',					'message_text.msg_id',				''),
				array('root_level',				0,									''),
				array('author_id',				'message_text.msg_author_id AS poster_id',	'phpbb_user_id'),
				array('icon_id',				0,									''),
				array('author_ip',				'message_text.msg_ip_address',				'decode_ip'),
				array('message_time',			'message_text.msg_date',			''),
				array('enable_bbcode',			'',	''),
				array('',				'',	''),
				array('enable_smilies',			'',	''),
				array('enable_magic_url',		1,									''),
				array('enable_sig',			'',		''),
				array('message_subject',		'message_topics.mt_title',		'phpbb_set_encoding'), // Already specialchared in 2.0.x
				array('message_attachment',		'message_topics..mt_hasattach', ''),
				array('message_edit_reason',	'',									''),
				array('message_edit_user',		0,									''),
				array('message_edit_time',		0,									''),
				array('message_edit_count',		0,									''),

				array('bbcode_uid',			'',	'make_uid'),
				array('message_text',			'message_text.msg_post',			'phpbb_prepare_message'),
				array('',				'',			''),
				array('bbcode_bitfield',		'',										'get_bbcode_bitfield'),
				array('to_address',			'message_topics.mt_to_id',			'phpbb_privmsgs_to_userid'),
				array('bcc_address',			'',										''),

				'where'			=>	'message_topics.mt_id = message_text.msg_id'
			),

			array(
				'target'		=> PRIVMSGS_FOLDER_TABLE,
				'primary'		=> 'members.id',
				'query_first'	=> array('target', $convert->truncate_statement . PRIVMSGS_FOLDER_TABLE),

				array('user_id', 'members.id',						'phpbb_user_id'),
				array('folder_name',	$user->lang['CONV_SAVED_MESSAGES'],		''),
				array('pm_count',				0,										''),
			
				'where'			=> 'members.id <> -1',
			),

array(
				'target'		=>  ATTACHMENTS_TABLE,
				'primary'		=> 'attachments.attach_id',
				'query_first'	=> array('target', $convert->truncate_statement . ATTACHMENTS_TABLE),
				'autoincrement'	=> 'attach_id',

				array('attach_id',				'attachments.attach_id',				''),
				array('post_msg_id',			'attachments.attach_rel_id',					''),
				array('topic_id',				'posts.topic_id',						''),
				array('in_message',				0,										''),
				array('is_orphan',				0,										''),
				array('poster_id',				'attachments.attach_member_id AS poster_id',	'phpbb_user_id'),
				array('physical_filename',		'attachments.attach_file',	'import_attachment'),
				array('real_filename',			'attachments.attach_location',		'phpbb_set_encoding'),
				array('download_count',			'attachments.attach_hits',		''),
				array('attach_comment',			'',				array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')),
				array('extension',				'attachments.attach_ext',			''),
				array('mimetype',				'',			''),
				array('filesize',				'attachments.attach_filesize',			''),
				array('filetime',				'attachments.attach_date',			''),
				array('thumbnail',				'attachments.attach_thumb_location',			''),

				'where'			=> 'attachments.attach_rel_id = posts.pid',
				'group_by'		=> 'attachments.attach_rel_id'
			),

			// Inbox
			array(
				'target'		=> PRIVMSGS_TO_TABLE,
				'primary'		=> 'message_topics.mt_id',
				'query_first'	=> array('target', $convert->truncate_statement . PRIVMSGS_TO_TABLE),

				array('msg_id',					'message_topics.mt_msg_id',					''),
				array('user_id',				'message_topics.mt_to_id',			'phpbb_user_id'),
				array('author_id',				'message_topics.mt_from_id',		'phpbb_user_id'),
				array('pm_deleted',				0,										''),
				array('pm_new',					'',				'phpbb_new_pm'),
				array('pm_unread',				'',				'phpbb_unread_pm'),
				array('pm_replied',				0,										''),
				array('pm_marked',				0,										''),
				array('pm_forwarded',			0,										''),
				array('folder_id',				PRIVMSGS_INBOX,							''),

				'where'			=> 'message_topics.mt_id = message_text.msg_id 
										',
			),
			
			// Outbox
			array(
				'target'		=> PRIVMSGS_TO_TABLE,
				'primary'		=> 'message_topics.mt_id',

				array('msg_id',					'message_topics.mt_msg_id',					''),
				array('user_id',				'message_topics.mt_from_id',		'phpbb_user_id'),
				array('author_id',				'message_topics.mt_from_id',		'phpbb_user_id'),
				array('pm_deleted',				0,										''),
				array('pm_new',					0,										''),
				array('pm_unread',				0,										''),
				array('pm_replied',				0,										''),
				array('pm_marked',				0,										''),
				array('pm_forwarded',			0,										''),
				array('folder_id',				PRIVMSGS_OUTBOX,						''),

				'where'			=> 'message_topics.mt_id = message_text.msg_id
										',
			),

			// Sentbox
			array(
				'target'		=> PRIVMSGS_TO_TABLE,
				'primary'		=> 'message_topics.mt_id',

				array('msg_id',					'message_topics.mt_msg_id',					''),
				array('user_id',				'message_topics.mt_from_id',		'phpbb_user_id'),
				array('author_id',				'message_topics.mt_from_id',		'phpbb_user_id'),
				array('pm_deleted',				0,										''),
				array('pm_new',					'',				'phpbb_new_pm'),
				array('pm_unread',				'',				'phpbb_unread_pm'),
				array('pm_replied',				0,										''),
				array('pm_marked',				0,										''),
				array('pm_forwarded',			0,										''),
				array('folder_id',				PRIVMSGS_SENTBOX,						''),

				'where'			=> 'message_topics.mt_id = message_text.msg_id 
										',
			),

			array(
				'target'		=> GROUPS_TABLE,
				'autoincrement'	=> 'group_id',
				'query_first'	=> array('target', $convert->truncate_statement . GROUPS_TABLE),

				array('group_id',				'groups.g_id',					''),
				array('group_type',				0,				'phpbb_convert_group_type'),
				array('group_display',			0,									''),
				array('group_legend',			0,									''),
				array('group_name',				'groups.g_title',				'phpbb_convert_group_name'), // phpbb_set_encoding called in phpbb_convert_group_name
				array('group_desc',				'',			'phpbb_set_encoding'),

				'where'			=> '',
			),

			array(
				'target'		=> USER_GROUP_TABLE,
				'query_first'	=> array('target', $convert->truncate_statement . USER_GROUP_TABLE),
				'execute_first'	=> '
					add_default_groups();
				',

				array('group_id',		'groups.g_id',					''),
				array('user_id',	'members.id',			'phpbb_user_id'),
				array('group_leader',	1,									''),
				array('user_pending',	0,									''),

				'where'			=> '',
			),

			array(
				'target'		=> USER_GROUP_TABLE,

				array('group_id',		'members.mgroup',				''),
				array('user_id',		'members.id',				'phpbb_user_id'),
				array('group_leader',	0,									''),
				array('user_pending',	'',			''),

				'where'			=> '',
			),

			array(
				'target'		=> USERS_TABLE,
				'primary'		=> 'members.id',
				'autoincrement'	=> 'id',
				'query_first'	=> array(
					array('target', 'DELETE FROM ' . USERS_TABLE . ' WHERE user_id <> ' . ANONYMOUS),
					array('target', $convert->truncate_statement . BOTS_TABLE)
				),

				'execute_last'	=> '
					remove_invalid_users();
				',

				array('user_id',				'members.id',					'phpbb_user_id'),
				array('',					'members.id AS poster_id',		'phpbb_user_id'),
				array('user_type',				'0',				'set_user_type'),
				array('group_id',				'members.mgroup',					'phpbb_set_primary_group'),
				array('user_regdate',			'members.joined',				''),
				array('username',				'members.members_display_name',					'phpbb_set_default_encoding'), // recode to utf8 with default lang
				array('username_clean',			'members.name',			'phpbb_set_clean_name'),
				array('user_password',			'members_converge.converge_pass_hash',				''),
				array('user_pass_convert',		1,									''),
				array('user_posts',			'members.posts',					''),
				array('user_email',			'members.email',					''),
				array('user_email_hash',		'members.email',					'gen_email_hash'),
				array('user_birthday',			'members.id',	'phpbb_birthday'),
				array('user_lastvisit',			'members.last_activity',				''),
				array('user_lastmark',			'members.last_activity',				''),
				array('user_lang',			$config['default_lang'],			''),
				array('',				'',					''),
				array('user_timezone',			'members.time_offset',				''),
				array('user_dateformat',		'',			array('function1' => 'phpbb_set_encoding', 'function2' => 'fill_dateformat')),
				array('user_inactive_reason',	'',									'phpbb_inactive_reason'),
				array('user_inactive_time',		'',									'phpbb_inactive_time'),

				array('user_interests',			'member_extra.interests',				array('function1' => 'phpbb_set_encoding')),
				array('user_occ',			'',					array('function1' => 'phpbb_set_encoding')),
				array('user_website',			'member_extra.website',				'validate_website'),
				array('user_jabber',			'',									''),
				array('user_msnm',			'member_extra.msnname',					array('function1' => 'phpbb_set_encoding')),
				array('user_yim',			'member_extra.yahoo',					array('function1' => 'phpbb_set_encoding')),
				array('user_aim',			'member_extra.aim_name',					array('function1' => 'phpbb_set_encoding')),
				array('user_icq',			'member_extra.icq_number',					array('function1' => 'phpbb_set_encoding')),
				array('user_from',			'member_extra.location',					array('function1' => 'phpbb_set_encoding')),
				array('user_rank',			'members.title',					''),
				array('user_permissions',		'',									''),

				array('user_avatar',			'member_extra.avatar_location',				'phpbb_import_avatar'),
				array('user_avatar_type',		'member_extra.avatar_type',			'phpbb_avatar_type'),
				array('user_avatar_width',		'member_extra.avatar_size',				'phpbb_get_avatar_width'),
				array('user_avatar_height',		'member_extra.avatar_size',				'phpbb_get_avatar_height'),

				array('user_new_privmsg',		'',			''),
				array('user_unread_privmsg',	0,									''), //'users.user_unread_privmsg'
				array('user_last_privmsg',		'',			''),
				array('user_emailtime',			'',				'null_to_zero'),
				array('user_notify',			'',				''),
				array('user_notify_pm',			'',				''),
				array('user_notify_type',		NOTIFY_EMAIL,						''),
				array('user_allow_pm',			'',				''),
				array('user_allow_viewonline',	'',		''),
				array('user_allow_viewemail',	'',				''),
				array('user_actkey',			'',				''),
				array('user_newpasswd',			'',									''), // Users need to re-request their password...
				array('user_style',				$config['default_style'],			''),

				array('user_options',			'',									'set_user_options'),
				array('',						'',	''),
				array('',						'',		''),
				array('',						'',	''),
				array('',						'',
''),
				array('',						'',''),

				array('user_sig_bbcode_uid',		'',							'make_uid'),
				array('user_sig',					'member_extra.signature',								'phpbb_prepare_message'),
				array('',			'',	''),
				array('user_sig_bbcode_bitfield',	'',												'get_bbcode_bitfield'),
				array('',							'',				''),

				'where'			=> 'members.id <> -1 and member_extra.id=members.id and members.email=members_converge.converge_email',
			),
		),
	);
}

?>
functions_ipb23.php

Code: Select all

<?php                                                                                                              
/** 
*
* @package install
* @version $Id: functions_phpbb20.php,v 1.57 2007/08/21 14:08:22 kellanved Exp $
* @copyright (c) 2006 phpBB Group 
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* Helper functions for phpBB 2.0.x to phpBB 3.0.x conversion
*/

function phpbb_poll($choices)
{
	global $db,$src_db,$convert;
	

	
	$poll=unserialize($choices);
$count=0;
	$sql = 'TRUNCATE TABLE '.POLL_OPTIONS_TABLE;
	$db->sql_query($sql);
	foreach($poll as $k =>$v)
	{
		$sql = "SELECT {$convert->src_table_prefix}topics.tid
		FROM {$convert->src_table_prefix}topics,{$convert->src_table_prefix}polls
		WHERE {$convert->src_table_prefix}topics.tid={$convert->src_table_prefix}polls.tid and {$convert->src_table_prefix}polls.pid = ".$k;
	$result = $src_db->sql_query($sql);
	$topic = (int) $src_db->sql_fetchfield('tid');
	$src_db->sql_freeresult($result);
	foreach($poll[$k]['choice'] as $kk =>$vk)
	{
	$sql_ary['poll_option_id']=$kk;
	$sql_ary['poll_option_text']=$vk;
	$sql_ary['poll_option_total']=$poll[$k]['votes'][$kk];
	$sql_ary['topic_id']=$topic;
	$sql = 'INSERT INTO '.POLL_OPTIONS_TABLE.' '.$db->sql_build_array('INSERT', $sql_ary);
	$db->sql_query($sql);
	}
	$count=count($poll[$k]['choice']);
	}
	return $count;
}

/**
* Set forum flags - only prune old polls by default
*/
function phpbb_forum_flags()
{
	// Set forum flags
	$forum_flags = 0;

	// FORUM_FLAG_LINK_TRACK
	$forum_flags += 0;

	// FORUM_FLAG_PRUNE_POLL
	$forum_flags += FORUM_FLAG_PRUNE_POLL;

	// FORUM_FLAG_PRUNE_ANNOUNCE
	$forum_flags += 0;

	// FORUM_FLAG_PRUNE_STICKY
	$forum_flags += 0;

	// FORUM_FLAG_ACTIVE_TOPICS
	$forum_flags += 0;

	// FORUM_FLAG_POST_REVIEW
	$forum_flags += FORUM_FLAG_POST_REVIEW;

	return $forum_flags;
}

/**
* Insert/Convert forums
*/
function phpbb_insert_forums()
{
	global $db, $src_db, $same_db, $convert, $user, $config;
	
	$db->sql_query($convert->truncate_statement . FORUMS_TABLE);

	// Determine the highest id used within the old forums table (we add the categories after the forum ids)
	$sql = 'SELECT MAX(id) AS max_forum_id
		FROM ' . $convert->src_table_prefix . 'forums';
	$result = $src_db->sql_query($sql);
	$max_forum_id = (int) $src_db->sql_fetchfield('max_forum_id');
	$src_db->sql_freeresult($result);

	$max_forum_id++;

	// pruning disabled globally?
	$sql = "SELECT conf_value
		FROM {$convert->src_table_prefix}conf_settings
		WHERE conf_key = 'prune_enable'";
	$result = $src_db->sql_query($sql);
	$prune_enabled = (int) $src_db->sql_fetchfield('conf_value');
	$src_db->sql_freeresult($result);
	
	
	// Insert categories
	$sql = 'SELECT id, name
		FROM ' . $convert->src_table_prefix . 'forums WHERE parent_id=-1
		ORDER BY position';

	if ($convert->mysql_convert && $same_db)
	{
		$src_db->sql_query("SET NAMES 'binary'");
	}

	$result = $src_db->sql_query($sql);

	if ($convert->mysql_convert && $same_db)
	{
		$src_db->sql_query("SET NAMES 'utf8'");
	}

	switch ($db->sql_layer)
	{
		case 'mssql':
		case 'mssql_odbc':
			$db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' ON');
		break;
	}

	$cats_added = array();
	while ($row = $src_db->sql_fetchrow($result))
	{
		$sql_ary = array(
			'forum_id'		=> (int) $max_forum_id,
			'forum_name'	=> ($row['name']) ? iconv('cp1251','utf-8',$row['name']) : $user->lang['CATEGORY'],
			'parent_id'		=> 0,
			'forum_parents'	=> '',
			'forum_desc'	=> '',
			'forum_type'	=> FORUM_CAT,
			'forum_status'	=> ITEM_UNLOCKED,
			'forum_rules'	=> '',
		);

		$sql = 'SELECT MAX(right_id) AS right_id
			FROM ' . FORUMS_TABLE;
		$_result = $db->sql_query($sql);
		$cat_row = $db->sql_fetchrow($_result);
		$db->sql_freeresult($_result);

		$sql_ary['left_id'] = (int) ($cat_row['right_id'] + 1);
		$sql_ary['right_id'] = (int) ($cat_row['right_id'] + 2);

		$sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
		$db->sql_query($sql);

		$cats_added[$row['id']] = $max_forum_id;
		$max_forum_id++;
	}
	$src_db->sql_freeresult($result);

	// Now insert the forums
	$sql = 'SELECT id, parent_id, name, description FROM ' . $convert->src_table_prefix . 'forums
		ORDER BY position';

	if ($convert->mysql_convert && $same_db)
	{
		$src_db->sql_query("SET NAMES 'binary'");
	}

	$result = $src_db->sql_query($sql);

	if ($convert->mysql_convert && $same_db)
	{
		$src_db->sql_query("SET NAMES 'utf8'");
	}

	while ($row = $src_db->sql_fetchrow($result))
	{

		if (!isset($cats_added[$row['parent_id']]))
		{
			continue;
		}

		// Define the new forums sql ary
		$sql_ary = array(
			'forum_id'			=> (int) $row['id'],
			'forum_name'		=> iconv('cp1251','utf-8',$row['name']),
			'parent_id'			=> (int) $cats_added[$row['parent_id']],
			'forum_parents'		=> 0,
			'forum_desc'		=> iconv('cp1251','utf-8',$row['description']),
			'forum_type'		=> FORUM_POST,
			'forum_status'		=> is_item_locked($row['status']),
			'enable_prune'		=> 0,
			'prune_next'		=> 0,
			'prune_days'		=> 0,
			'prune_viewed'		=> 0,
			'prune_freq'		=> 0,

			'forum_flags'		=> phpbb_forum_flags(),

			// Default values
			'forum_desc_bitfield'		=> '',
			'forum_desc_options'		=> 7,
			'forum_desc_uid'			=> '',
			'forum_link'				=> '',
			'forum_password'			=> '',
			'forum_style'				=> 0,
			'forum_image'				=> '',
			'forum_rules'				=> '',
			'forum_rules_link'			=> '',
			'forum_rules_bitfield'		=> '',
			'forum_rules_options'		=> 7,
			'forum_rules_uid'			=> '',
			'forum_topics_per_page'		=> 0,
			'forum_posts'				=> 0,
			'forum_topics'				=> 0,
			'forum_topics_real'			=> 0,
			'forum_last_post_id'		=> 0,
			'forum_last_poster_id'		=> 0,
			'forum_last_post_subject'	=> '',
			'forum_last_post_time'		=> 0,
			'forum_last_poster_name'	=> '',
			'forum_last_poster_colour'	=> '',
			'display_on_index'			=> 1,
			'enable_indexing'			=> 1,
			'enable_icons'				=> 0,
		);

		// Now add the forums with proper left/right ids
		$sql = 'SELECT left_id, right_id
			FROM ' . FORUMS_TABLE . '
			WHERE forum_id = ' . $cats_added[$row['parent_id']];
		$_result = $db->sql_query($sql);
		$cat_row = $db->sql_fetchrow($_result);
		$db->sql_freeresult($_result);

		$sql = 'UPDATE ' . FORUMS_TABLE . '
			SET left_id = left_id + 2, right_id = right_id + 2
			WHERE left_id > ' . $cat_row['right_id'];
		$db->sql_query($sql);

		$sql = 'UPDATE ' . FORUMS_TABLE . '
			SET right_id = right_id + 2
			WHERE ' . $cat_row['left_id'] . ' BETWEEN left_id AND right_id';
		$db->sql_query($sql);

		$sql_ary['left_id'] = (int) $cat_row['right_id'];
		$sql_ary['right_id'] = (int) ($cat_row['right_id'] + 1);

		$sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
		$db->sql_query($sql);
	}
	$src_db->sql_freeresult($result);

	switch ($db->sql_layer)
	{
		case 'postgres':
			$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 . '));');
		break;

		case 'mssql':
		case 'mssql_odbc':
			$db->sql_query('SET IDENTITY_INSERT ' . FORUMS_TABLE . ' OFF');
		break;

		case 'oracle':
			$result = $db->sql_query('SELECT MAX(forum_id) as max_id FROM ' . FORUMS_TABLE);
			$row = $db->sql_fetchrow($result);
			$db->sql_freeresult($result);

			$largest_id = (int) $row['max_id'];

			if ($largest_id)
			{
				$db->sql_query('DROP SEQUENCE ' . FORUMS_TABLE . '_seq');
				$db->sql_query('CREATE SEQUENCE ' . FORUMS_TABLE . '_seq START WITH ' . ($largest_id + 1));
			}
		break;
	}
}

/**
* Function for recoding text with the default language
*
* @param string $text text to recode to utf8
* @param bool $grab_user_lang if set to true the function tries to use $convert_row['user_lang'] (and falls back to $convert_row['poster_id']) instead of the boards default language
*/
function phpbb_set_encoding($text, $grab_user_lang = true)
{
return iconv('cp1251','utf-8',$text);
}

/**
* Same as phpbb_set_encoding, but forcing boards default language
*/
function phpbb_set_default_encoding($text)
{
	return phpbb_set_encoding($text, false);
}

/**
* Return correct user id value
* Everyone's id will be one higher to allow the guest/anonymous user to have a positive id as well
*/
function phpbb_user_id($user_id)
{
	global $config;

	// Increment user id if the old forum is having a user with the id 1
	if (!isset($config['increment_user_id']))
	{
		global $src_db, $same_db, $convert;

		if ($convert->mysql_convert && $same_db)
		{
			$src_db->sql_query("SET NAMES 'binary'");
		}

		// Now let us set a temporary config variable for user id incrementing
		$sql = "SELECT id
			FROM {$convert->src_table_prefix}members
			WHERE id = 1";
		$result = $src_db->sql_query($sql);
		$id = (int) $src_db->sql_fetchfield('user_id');
		$src_db->sql_freeresult($result);

		// Try to get the maximum user id possible...
		$sql = "SELECT MAX(id) AS max_user_id
			FROM {$convert->src_table_prefix}members";
		$result = $src_db->sql_query($sql);
		$max_id = (int) $src_db->sql_fetchfield('max_user_id');
		$src_db->sql_freeresult($result);

		if ($convert->mysql_convert && $same_db)
		{
			$src_db->sql_query("SET NAMES 'utf8'");
		}

		// If there is a user id 1, we need to increment user ids. :/
		if ($id === 1)
		{
			set_config('increment_user_id', ($max_id + 1), true);
			$config['increment_user_id'] = $max_id + 1;
		}
		else
		{
			set_config('increment_user_id', 0, true);
			$config['increment_user_id'] = 0;
		}
	}

	if (!empty($config['increment_user_id']) && $user_id == 1)
	{
		return $config['increment_user_id'];
	}

	// A user id of 0 can happen, for example within the ban table if no user is banned...
	// Within the posts and topics table this can be "dangerous" but is the fault of the user
	// having mods installed (a poster id of 0 is not possible in 2.0.x). 
	// Therefore, we return the user id "as is".

	return (int) $user_id;
}

/* Copy additional table fields from old forum to new forum if user wants this (for Mod compatibility for example)
function phpbb_copy_table_fields()
{
}
*/

/**
* Convert authentication
* user, group and forum table has to be filled in order to work
*/
function phpbb_convert_authentication($mode)
{
	global $db, $src_db, $same_db, $convert, $user, $config, $cache;

	if ($mode == 'start')
	{
		$db->sql_query($convert->truncate_statement . ACL_USERS_TABLE);
		$db->sql_query($convert->truncate_statement . ACL_GROUPS_TABLE);

		// What we will do is handling all 2.0.x admins as founder to replicate what is common in 2.0.x.
		// After conversion the main admin need to make sure he is removing permissions and the founder status if wanted.


		// Grab user ids of users with user_level of ADMIN
		$sql = "SELECT id
			FROM {$convert->src_table_prefix}members
			WHERE mgroup = 4
			ORDER BY joined ASC";
		$result = $src_db->sql_query($sql);

		while ($row = $src_db->sql_fetchrow($result))
		{
			$user_id = (int) phpbb_user_id($row['id']);
			// Set founder admin...
			$sql = 'UPDATE ' . USERS_TABLE . '
				SET user_type = ' . USER_FOUNDER . "
				WHERE user_id = $user_id";
			$db->sql_query($sql);
		}
		$src_db->sql_freeresult($result);

		$sql = 'SELECT group_id
			FROM ' . GROUPS_TABLE . "
			WHERE group_name = '" . $db->sql_escape('BOTS') . "'";
		$result = $db->sql_query($sql);
		$bot_group_id = (int) $db->sql_fetchfield('group_id');
		$db->sql_freeresult($result);
	}

	// Grab forum auth information
	$sql = "SELECT *
		FROM {$convert->src_table_prefix}forums";
	$result = $src_db->sql_query($sql);

	$forum_access = array();
	while ($row = $src_db->sql_fetchrow($result))
	{
		$forum_access[$row['id']] = $row;
	}
	$src_db->sql_freeresult($result);

	if ($convert->mysql_convert && $same_db)
	{
		$src_db->sql_query("SET NAMES 'binary'");
	}
	if ($convert->mysql_convert && $same_db)
	{
		$src_db->sql_query("SET NAMES 'utf8'");
	}

	// Add Forum Access List
	$auth_map = array(
		'auth_view'			=> array('f_', 'f_list'),
		'auth_read'			=> array('f_read', 'f_search'),
		'auth_post'			=> array('f_post', 'f_bbcode', 'f_smilies', 'f_img', 'f_sigs', 'f_postcount', 'f_report', 'f_subscribe', 'f_print', 'f_email'),
		'auth_reply'		=> 'f_reply',
		'auth_edit'			=> 'f_edit',
		'auth_delete'		=> 'f_delete',
		'auth_pollcreate'	=> 'f_poll',
		'auth_vote'			=> 'f_vote',
		'auth_announce'		=> 'f_announce',
		'auth_sticky'		=> 'f_sticky',
		'auth_attachments'	=> array('f_attach', 'f_download'),
		'auth_download'		=> 'f_download',
	);

	// Define the ACL constants used in 2.0 to make the code slightly more readable
	define('AUTH_ALL', 2);
	define('AUTH_REG', 3);
	define('AUTH_ACL', 1);
	define('AUTH_MOD', 3);
	define('AUTH_ADMIN', 6);

	// A mapping of the simple permissions used by 2.0
	$simple_auth_ary = array(
		'public'			=> array(
			'auth_view'			=> AUTH_ALL,
			'auth_read'			=> AUTH_ALL,
			'auth_post'			=> AUTH_ALL,
			'auth_reply'		=> AUTH_ALL,
			'auth_edit'			=> AUTH_REG,
			'auth_delete'		=> AUTH_REG,
			'auth_sticky'		=> AUTH_MOD,
			'auth_announce'		=> AUTH_MOD,
			'auth_vote'			=> AUTH_REG,
			'auth_pollcreate'	=> AUTH_REG,
		),
		'registered'		=> array(
			'auth_view'			=> AUTH_ALL,
			'auth_read'			=> AUTH_ALL,
			'auth_post'			=> AUTH_REG,
			'auth_reply'		=> AUTH_REG,
			'auth_edit'			=> AUTH_REG,
			'auth_delete'		=> AUTH_REG,
			'auth_sticky'		=> AUTH_MOD,
			'auth_announce'		=> AUTH_MOD,
			'auth_vote'			=> AUTH_REG,
			'auth_pollcreate'	=> AUTH_REG,
		),
		'registered_hidden'	=> array(
			'auth_view'			=> AUTH_REG,
			'auth_read'			=> AUTH_REG,
			'auth_post'			=> AUTH_REG,
			'auth_reply'		=> AUTH_REG,
			'auth_edit'			=> AUTH_REG,
			'auth_delete'		=> AUTH_REG,
			'auth_sticky'		=> AUTH_MOD,
			'auth_announce'		=> AUTH_MOD,
			'auth_vote'			=> AUTH_REG,
			'auth_pollcreate'	=> AUTH_REG,
		),
		'private'			=> array(
			'auth_view'			=> AUTH_ALL,
			'auth_read'			=> AUTH_ACL,
			'auth_post'			=> AUTH_ACL,
			'auth_reply'		=> AUTH_ACL,
			'auth_edit'			=> AUTH_ACL,
			'auth_delete'		=> AUTH_ACL,
			'auth_sticky'		=> AUTH_ACL,
			'auth_announce'		=> AUTH_MOD,
			'auth_vote'			=> AUTH_ACL,
			'auth_pollcreate'	=> AUTH_ACL,
		),
		'private_hidden'	=> array(
			'auth_view'			=> AUTH_ACL,
			'auth_read'			=> AUTH_ACL,
			'auth_post'			=> AUTH_ACL,
			'auth_reply'		=> AUTH_ACL,
			'auth_edit'			=> AUTH_ACL,
			'auth_delete'		=> AUTH_ACL,
			'auth_sticky'		=> AUTH_ACL,
			'auth_announce'		=> AUTH_MOD,
			'auth_vote'			=> AUTH_ACL,
			'auth_pollcreate'	=> AUTH_ACL,
		),
		'moderator'			=> array(
			'auth_view'			=> AUTH_ALL,
			'auth_read'			=> AUTH_MOD,
			'auth_post'			=> AUTH_MOD,
			'auth_reply'		=> AUTH_MOD,
			'auth_edit'			=> AUTH_MOD,
			'auth_delete'		=> AUTH_MOD,
			'auth_sticky'		=> AUTH_MOD,
			'auth_announce'		=> AUTH_MOD,
			'auth_vote'			=> AUTH_MOD,
			'auth_pollcreate'	=> AUTH_MOD,
		),
		'moderator_hidden'	=> array(
			'auth_view'			=> AUTH_MOD,
			'auth_read'			=> AUTH_MOD,
			'auth_post'			=> AUTH_MOD,
			'auth_reply'		=> AUTH_MOD,
			'auth_edit'			=> AUTH_MOD,
			'auth_delete'		=> AUTH_MOD,
			'auth_sticky'		=> AUTH_MOD,
			'auth_announce'		=> AUTH_MOD,
			'auth_vote'			=> AUTH_MOD,
			'auth_pollcreate'	=> AUTH_MOD,
		),
	);

	if ($mode == 'start')
	{
		// Selecting from old table
		if (!empty($config['increment_user_id']))
		{
			$auth_sql = 'SELECT id as user_id FROM ' . $convert->src_table_prefix . 'members WHERE mgroup = 4 AND id <> 1';
			user_group_auth('administrators', $auth_sql, true);

			$auth_sql = 'SELECT id as user_id FROM ' . $convert->src_table_prefix . 'members WHERE mgroup = 4 AND id = 1';

			user_group_auth('administrators', $auth_sql, true);
		}
		else
		{
			$auth_sql = 'SELECT id as user_id FROM ' . $convert->src_table_prefix . 'members WHERE mgroup = 4';
			user_group_auth('administrators', $auth_sql, true);
		}

	
	}
	else if ($mode == 'first')
	{
		// Go through all 2.0.x forums
		foreach ($forum_access as $forum)
		{
			$new_forum_id = (int) $forum['id'];

			// Administrators have full access to all forums whatever happens
			mass_auth('group_role', $new_forum_id, 'administrators', 'FORUM_FULL');

			$matched_type = '';
			foreach ($simple_auth_ary as $key => $auth_levels)
			{
				$matched = 1;
				foreach ($auth_levels as $k => $level)
				{
					if ($forum[$k] != $auth_levels[$k])
					{
						$matched = 0;
					}
				}

				if ($matched)
				{
					$matched_type = $key;
					break;
				}
			}

			switch ($matched_type)
			{
				case 'public':
					mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_READONLY');
					mass_auth('group_role', $new_forum_id, 'bots', 'FORUM_BOT');
				break;

				case 'registered':
					mass_auth('group_role', $new_forum_id, 'guests', 'FORUM_READONLY');
					mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_POLLS');

				// no break;

				case 'registered_hidden':
					mass_auth('group_role', $new_forum_id, 'registered', 'FORUM_POLLS');
				break;

				case 'private':
				case 'private_hidden':
				case 'moderator':
				case 'moderator_hidden':
				default:
					// The permissions don't match a simple set, so we're going to have to map them directly

					// No post approval for all, in 2.0.x this feature does not exist
					mass_auth('group', $new_forum_id, 'guests', 'f_noapprove', ACL_YES);
					mass_auth('group', $new_forum_id, 'registered', 'f_noapprove', ACL_YES);

					// Go through authentication map
					foreach ($auth_map as $old_auth_key => $new_acl)
					{
						// If old authentication key does not exist we continue
						// This is helpful for mods adding additional authentication fields, we need to add them to the auth_map array
						if (!isset($forum[$old_auth_key]))
						{
							continue;
						}

						// Now set the new ACL correctly
						switch ($forum[$old_auth_key])
						{
							// AUTH_ALL
							case AUTH_ALL:
								mass_auth('group', $new_forum_id, 'guests', $new_acl, ACL_YES);
								mass_auth('group', $new_forum_id, 'bots', $new_acl, ACL_YES);
								mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
							break;

							// AUTH_REG
							case AUTH_REG:
								mass_auth('group', $new_forum_id, 'registered', $new_acl, ACL_YES);
							break;

							// AUTH_ACL
							case AUTH_ACL:
								// Go through the old group access list for this forum
								if (isset($group_access[$forum['forum_id']]))
								{
									foreach ($group_access[$forum['forum_id']] as $index => $access)
									{
										// We only check for ACL_YES equivalence entry
										if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
										{
											mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
										}
									}
								}

								if (isset($user_access[$forum['forum_id']]))
								{
									foreach ($user_access[$forum['forum_id']] as $index => $access)
									{
										// We only check for ACL_YES equivalence entry
										if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
										{
											mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
										}
									}
								}
							break;

							// AUTH_MOD
							case AUTH_MOD:
								if (isset($group_access[$forum['forum_id']]))
								{
									foreach ($group_access[$forum['forum_id']] as $index => $access)
									{
										// We only check for ACL_YES equivalence entry
										if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
										{
											mass_auth('group', $new_forum_id, (int) $access['group_id'], $new_acl, ACL_YES);
										}
									}
								}

								if (isset($user_access[$forum['forum_id']]))
								{
									foreach ($user_access[$forum['forum_id']] as $index => $access)
									{
										// We only check for ACL_YES equivalence entry
										if (isset($access[$old_auth_key]) && $access[$old_auth_key] == 1)
										{
											mass_auth('user', $new_forum_id, (int) phpbb_user_id($access['user_id']), $new_acl, ACL_YES);
										}
									}
								}
							break;
						}
					}
				break;
			}
		}
	}
	else if ($mode == 'second')
	{
		// Assign permission roles and other default permissions

		// guests having u_download and u_search ability
		$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')");

		// administrators/global mods having full user features
		mass_auth('group_role', 0, 'administrators', 'USER_FULL');
		mass_auth('group_role', 0, 'global_moderators', 'USER_FULL');

		// By default all converted administrators are given full access
		mass_auth('group_role', 0, 'administrators', 'ADMIN_FULL');

		// All registered users are assigned the standard user role
		mass_auth('group_role', 0, 'registered', 'USER_STANDARD');
		mass_auth('group_role', 0, 'registered_coppa', 'USER_STANDARD');

		// Instead of administrators being global moderators we give the MOD_FULL role to global mods (admins already assigned to this group)
		mass_auth('group_role', 0, 'global_moderators', 'MOD_FULL');

	}
	else if ($mode == 'third')
	{
		// And now the moderators
		// We make sure that they have at least standard access to the forums they moderate in addition to the moderating permissions
		
		$mod_post_map = array(
			'auth_announce'		=> 'f_announce',
			'auth_sticky'		=> 'f_sticky'
		);
		
		foreach ($user_access as $forum_id => $access_map)
		{
			$forum_id = (int) $forum_id;

			foreach ($access_map as $access)
			{
				if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
				{
					mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'MOD_STANDARD');
					mass_auth('user_role', $forum_id, (int) phpbb_user_id($access['user_id']), 'FORUM_STANDARD');
					foreach ($mod_post_map as $old => $new)
					{
						if (isset($forum_access[$forum_id]) && isset($forum_access[$forum_id][$old]) && $forum_access[$forum_id][$old] == AUTH_MOD)
						{
							mass_auth('user', $forum_id, (int) phpbb_user_id($access['user_id']), $new, ACL_YES);
						}
					}
				}
			}
		}

		foreach ($group_access as $forum_id => $access_map)
		{
			$forum_id = (int) $forum_id;

			foreach ($access_map as $access)
			{
				if (isset($access['auth_mod']) && $access['auth_mod'] == 1)
				{
					mass_auth('group_role', $forum_id, (int) $access['group_id'], 'MOD_STANDARD');
					mass_auth('group_role', $forum_id, (int) $access['group_id'], 'FORUM_STANDARD');
					foreach ($mod_post_map as $old => $new)
					{
						if (isset($forum_access[$forum_id]) && isset($forum_access[$forum_id][$old]) && $forum_access[$forum_id][$old] == AUTH_MOD)
						{
							mass_auth('group', $forum_id, (int) $access['group_id'], $new, ACL_YES);
						}
					}
				}
			}
		}

		// We grant everyone readonly access to the categories to ensure that the forums are visible
		$sql = 'SELECT forum_id, forum_name, parent_id, left_id, right_id
			FROM ' . FORUMS_TABLE . '
			ORDER BY left_id ASC';
		$result = $db->sql_query($sql);

		$parent_forums = $forums = array();
		while ($row = $db->sql_fetchrow($result))
		{
			if ($row['parent_id'] == 0)
			{
				mass_auth('group_role', $row['forum_id'], 'administrators', 'FORUM_FULL');
				mass_auth('group_role', $row['forum_id'], 'global_moderators', 'FORUM_FULL');
				$parent_forums[] = $row;
			}
			else
			{
				$forums[] = $row;
			}
		}
		$db->sql_freeresult($result);

		global $auth;

		// Let us see which groups have access to these forums...
		foreach ($parent_forums as $row)
		{
			// Get the children
			$branch = $forum_ids = array();

			foreach ($forums as $key => $_row)
			{
				if ($_row['left_id'] > $row['left_id'] && $_row['left_id'] < $row['right_id'])
				{
					$branch[] = $_row;
					$forum_ids[] = $_row['forum_id'];
					continue;
				}
			}

			if (sizeof($forum_ids))
			{
				// Now make sure the user is able to read these forums
				$hold_ary = $auth->acl_group_raw_data(false, 'f_list', $forum_ids);

				if (empty($hold_ary))
				{
					continue;
				}

				foreach ($hold_ary as $g_id => $f_id_ary)
				{
					$set_group = false;

					foreach ($f_id_ary as $f_id => $auth_ary)
					{
						foreach ($auth_ary as $auth_option => $setting)
						{
							if ($setting == ACL_YES)
							{
								$set_group = true;
								break 2;
							}
						}
					}

					if ($set_group)
					{
						mass_auth('group', $row['forum_id'], $g_id, 'f_list', ACL_YES);
					}
				}
			}
		}
	}
}

/**
* Set primary group.
* Really simple and only based on user_level (remaining groups will be assigned later)
*/
function phpbb_set_primary_group($user_level)
{
	global $convert_row;

	if ($user_level == 1)
	{
		return get_group_id('administrators');
	}
/*	else if ($user_level == 2)
	{
		return get_group_id('global_moderators');
	}
	else if ($user_level == 0 && $convert_row['user_active'])*/
	else if ($convert_row['user_active'])
	{
		return get_group_id('registered');
	}

	return 0;
}

/**
* Convert the group name, making sure to avoid conflicts with 3.0 special groups
*/
function phpbb_convert_group_name($group_name)
{
	$default_groups = array(
		'GUESTS',
		'REGISTERED',
		'REGISTERED_COPPA',
		'GLOBAL_MODERATORS',
		'ADMINISTRATORS',
		'BOTS',
	);

	if (in_array(strtoupper($group_name), $default_groups))
	{
		return 'phpBB2 - ' . $group_name;
	}

	return phpbb_set_default_encoding($group_name);
}

/**
* Convert the group type constants
*/
function phpbb_convert_group_type($group_type)
{
	switch ($group_type)
	{
		case 0:
			return GROUP_OPEN;
		break;

		case 1:
			return GROUP_CLOSED;
		break;

		case 2:
			return GROUP_HIDDEN;
		break;
	}

	// Never return GROUP_SPECIAL here, because only phpBB3's default groups are allowed to have this type set.
	return GROUP_HIDDEN;
}

/**
* Convert the topic type constants
*/
function phpbb_convert_topic_type($topic_type)
{
	switch ($topic_type)
	{
		case 0:
			return POST_NORMAL;
		break;

		case 1:
			return POST_STICKY;
		break;

		case 2:
			return POST_ANNOUNCE;
		break;

		case 3:
			return POST_GLOBAL;
		break;
	}

	return POST_NORMAL;
}

function phpbb_replace_size($matches)
{
	return '[size=' . min(200, ceil(100.0 * (((double) $matches[1])/12.0))) . ':' . $matches[2] . ']';
}

/**
* Reparse the message stripping out the bbcode_uid values and adding new ones and setting the bitfield
* @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
*/
function phpbb_prepare_message($message)
{
	global $phpbb_root_path, $phpEx, $db, $convert, $user, $config, $cache, $convert_row, $message_parser;

	if (!$message)
	{
		$convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = 0;
		return '';
	}

	// Already the new user id ;)
	$user_id = $convert->row['poster_id'];
    $message = str_replace('<i>', '[i]', $message);
	$message = str_replace('</i>', '[/i]', $message);
	$message = str_replace('<b>', '[b]', $message);
	$message = str_replace('</b>', '[/b]', $message);
	$message = str_replace('<u>', '[u]', $message);
	$message = str_replace('<br />',"\r\n",$message);
	$message = str_replace('<blockquote>','[quote]',$message);
	$message = str_replace('</blockquote>','[/quote]',$message);
	$message = preg_replace('/<a href="http\:\/\/([\w\W]+)" target="_blank">([\w\W]+)<\/a>/siU','[url=http://\\1]\\2[/url]',$message);
	$message = preg_replace('/<img src="style_emoticons\/<#EMO_DIR#>\/([\w\W]+)" style="vertical-align:middle" emoid="([\w\W]+)" border="0" alt="([\w\W]+)" \/>/siU','\\2',$message);
	$message = preg_replace('/<!--quoteo\(post=([\d]+):date=([\w\W]+):name=([\w\W]+)\)-->/siU',"[quote=\"\\3\"]\r\n",$message);
	$message = preg_replace('/<!--QuoteEnd--><\/div><!--QuoteEEnd-->/siU',"\r\n[/quote]\r\n",$message);
	$message = str_replace('<div class=\'quotemain\'><!--quotec-->','',$message);
	$message = preg_replace('/<div class=\'quotetop\'>([\w\W]+)<a href="([\w\W]+)">([\w\W]+)<\/a><\/div>/siU','',$message);
	$message = str_replace('</u>', '[/u]', $message);
	$message = preg_replace('/<!--quoteo--><div class=\'quotetop\'>([\w\W]+)<\/div>/siU','[quote]',$message);
	if (strpos($message, '[quote=') !== false)
	{
		$message = preg_replace('/\[quote="(.*?)"\]/s', '[quote="\1"]', $message);
		$message = preg_replace('/\[quote=\\\"(.*?)\\\"\]/s', '[quote="\1"]', $message);
		
		// let's hope that this solves more problems than it causes. Deal with escaped quotes.
		$message = str_replace('\"', '"', $message);
		$message = str_replace('\"', '"', $message);
	}
	
	// make the post UTF-8
	$message = phpbb_set_encoding($message);

		$enable_html = (!isset($row['enable_html'])) ? false : $row['enable_html'];
	$enable_bbcode = (!isset($convert->row['enable_bbcode'])) ? true : $convert->row['enable_bbcode'];
	$enable_smilies = (!isset($convert->row['enable_smilies'])) ? true : $convert->row['enable_smilies'];
	$enable_magic_url = (!isset($convert->row['enable_magic_url'])) ? true : $convert->row['enable_magic_url'];

	$message_parser->warn_msg = array(); // Reset the errors from the previous message
	$message_parser->bbcode_uid = make_uid($convert->row['post_time']);
	$message_parser->message = $message;
	unset($message);


	// Make sure options are set.
$message_parser->prepare_bbcodes();
$message_parser->parse_bbcode();
	// 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')
	$message_parser->parse($enable_bbcode, $enable_magic_url, $enable_smilies);
	
	if (sizeof($message_parser->warn_msg))
	{
		$msg_id = isset($convert->row['post_id']) ? $convert->row['post_id'] : $convert->row['privmsgs_id'];
		$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);
	}

	$convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = $message_parser->bbcode_bitfield;

	$message = $message_parser->message;
	unset($message_parser->message);

	return $message;
}

/**
* Return the bitfield calculated by the previous function
*/
function get_bbcode_bitfield()
{
	global $convert_row;

	return $convert_row['mp_bbcode_bitfield'];
}

/**
* Determine the last user to edit a post
* 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
*/
function phpbb_post_edit_user()
{
	global $convert_row, $config;

	if (isset($convert_row['post_edit_count']))
	{
		return phpbb_user_id($convert_row['poster_id']);
	}

	return 0;
}

/**
* Obtain the path to uploaded files on the 2.0.x forum
* This is only used if the Attachment MOD was installed
*/
function phpbb_get_files_dir()
{
	global $src_db, $same_db, $convert, $user, $config, $cache;

	$sql = 'SELECT conf_value AS upload_dir
		FROM ' . $convert->src_table_prefix . "conf_settings
		WHERE conf_key = 'upload_dir'";
	$result = $src_db->sql_query($sql);
	$upload_path = $src_db->sql_fetchfield('upload_dir');
	$src_db->sql_freeresult($result);

	return $upload_path;
}

/**
* Copy thumbnails of uploaded images from the 2.0.x forum
* This is only used if the Attachment MOD was installed
*/
function phpbb_copy_thumbnails()
{
	global $db, $convert, $user, $config, $cache, $phpbb_root_path;

	$src_path = $convert->options['forum_path'] . '/' . phpbb_get_files_dir() . '/thumbs/';
	
	if ($handle = @opendir($src_path))
	{
		while ($entry = readdir($handle))
		{
			if ($entry[0] == '.')
			{
				continue;
			}

			if (is_dir($src_path . $entry))
			{
				continue;
			}
			else
			{
				copy_file($src_path . $entry, $config['upload_path'] . '/' . preg_replace('/^t_/', 'thumb_', $entry));
				@unlink($phpbb_root_path . $config['upload_path'] . '/thumbs/' . $entry);
			}
		}
		closedir($handle);
	}
}

/**
* Convert the attachment category constants
* This is only used if the Attachment MOD was installed
*/
function phpbb_attachment_category($cat_id)
{
	switch ($cat_id)
	{
		case 1:
			return ATTACHMENT_CATEGORY_IMAGE;
		break;

		case 2:
			return ATTACHMENT_CATEGORY_WM;
		break;

		case 3:
			return ATTACHMENT_CATEGORY_FLASH;
		break;
	}

	return ATTACHMENT_CATEGORY_NONE;
}

/**
* Obtain list of forums in which different attachment categories can be used
*/
function phpbb_attachment_forum_perms($forum_permissions)
{
	if (empty($forum_permissions))
	{
		return '';
	}

	// Decode forum permissions
	$forum_ids = array();

	$one_char_encoding = '#';
	$two_char_encoding = '.';

	$auth_len = 1;
	for ($pos = 0; $pos < strlen($forum_permissions); $pos += $auth_len)
	{
		$forum_auth = substr($forum_permissions, $pos, 1);
		if ($forum_auth == $one_char_encoding)
		{
			$auth_len = 1;
			continue;
		}
		else if ($forum_auth == $two_char_encoding)
		{
			$auth_len = 2;
			$pos--;
			continue;
		}
		
		$forum_auth = substr($forum_permissions, $pos, $auth_len);
		$forum_id = base64_unpack($forum_auth);

		$forum_ids[] = (int) $forum_id;
	}
	
	if (sizeof($forum_ids))
	{
		return attachment_forum_perms($forum_ids);
	}

	return '';
}

/**
* Convert the avatar type constants
*/
function phpbb_avatar_type($type)
{
	switch ($type)
	{
		case 'upload':
		case 'local':
			return AVATAR_UPLOAD;
		break;

		case 'url':
			return AVATAR_REMOTE;
		break;

		case 3:
			return AVATAR_GALLERY;
		break;
	}

	return 0;
}


/**
* Just undos the replacing of '<' and '>'
*/
function  phpbb_smilie_html_decode($code)
{
	$code = str_replace('<', '<', $code);
	return str_replace('>', '>', $code);
}

/**
* Transfer avatars, copying the image if it was uploaded
*/
function phpbb_import_avatar($user_avatar)
{
		return $user_avatar;
}

function phpbb_birthday($user_id)
{
	global $src_db, $convert;
		$sql = 'SELECT bday_day, bday_month, bday_year 
		FROM ' . $convert->src_table_prefix . "members
		WHERE id=".$user_id;
	$result = $src_db->sql_query($sql);
	while($row=$src_db->sql_fetchrow($result))
	{
	$day = $row['bday_day'];
	$month = $row['bday_month'];
	$year = $row['bday_year'];
	}
	$src_db->sql_freeresult($result);
	return $day.'-'.$month.'-'.$year;
}

/**
* Find out about the avatar's dimensions
*/
function phpbb_get_avatar_height($user_avatar)
{
	$dims=explode('x',$user_avatar);
	return $dims[1];
}


/**
* Find out about the avatar's dimensions
*/
function phpbb_get_avatar_width($user_avatar)
{
	$dims=explode('x',$user_avatar);
	return $dims[0];
}


/**
* Calculate the correct to_address field for private messages
*/
function phpbb_privmsgs_to_userid($to_userid)
{
	global $config;

	return 'u_' . phpbb_user_id($to_userid);
}

/**
* Calculate whether a private message was unread using the bitfield
*/
function phpbb_unread_pm($pm_type)
{
	return ($pm_type == 5) ? 1 : 0;
}

/**
* Calculate whether a private message was new using the bitfield
*/
function phpbb_new_pm($pm_type)
{
	return ($pm_type == 1) ? 1 : 0;
}

/**
* Obtain the folder_id for the custom folder created to replace the savebox from 2.0.x (used to store saved private messages)
*/
function phpbb_get_savebox_id($user_id)
{
	global $db;

	$user_id = phpbb_user_id($user_id);

	// Only one custom folder, check only one
	$sql = 'SELECT folder_id
		FROM ' . PRIVMSGS_FOLDER_TABLE . '
		WHERE user_id = ' . $user_id;
	$result = $db->sql_query_limit($sql, 1);
	$folder_id = (int) $db->sql_fetchfield('folder_id');
	$db->sql_freeresult($result);

	return $folder_id;
}

/**
* Transfer attachment specific configuration options
* These were not stored in the main config table on 2.0.x
* This is only used if the Attachment MOD was installed
*/
function phpbb_import_attach_config()
{
	global $db, $src_db, $same_db, $convert, $config;

	if ($convert->mysql_convert && $same_db)
	{
		$src_db->sql_query("SET NAMES 'binary'");
	}

	$sql = 'SELECT *
		FROM ' . $convert->src_table_prefix . 'attachments_config';
	$result = $src_db->sql_query($sql);

	if ($convert->mysql_convert && $same_db)
	{
		$src_db->sql_query("SET NAMES 'utf8'");
	}

	$attach_config = array();
	while ($row = $src_db->sql_fetchrow($result))
	{
		$attach_config[$row['config_name']] = $row['config_value'];
	}
	$src_db->sql_freeresult($result);

	set_config('allow_attachments', 1);

	// old attachment mod? Must be very old if this entry do not exist...
	if (!empty($attach_config['display_order']))
	{
		set_config('display_order', $attach_config['display_order']);
	}
	set_config('max_filesize', $attach_config['max_filesize']);
	set_config('max_filesize_pm', $attach_config['max_filesize_pm']);
	set_config('attachment_quota', $attach_config['attachment_quota']);
	set_config('max_attachments', $attach_config['max_attachments']);
	set_config('max_attachments_pm', $attach_config['max_attachments_pm']);
	set_config('allow_pm_attach', $attach_config['allow_pm_attach']);

	set_config('img_display_inlined', $attach_config['img_display_inlined']);
	set_config('img_max_width', $attach_config['img_max_width']);
	set_config('img_max_height', $attach_config['img_max_height']);
	set_config('img_link_width', $attach_config['img_link_width']);
	set_config('img_link_height', $attach_config['img_link_height']);
	set_config('img_create_thumbnail', $attach_config['img_create_thumbnail']);
	set_config('img_max_thumb_width', 400);
	set_config('img_min_thumb_filesize', $attach_config['img_min_thumb_filesize']);
	set_config('img_imagick', $attach_config['img_imagick']);
}

/**
* Calculate the date a user became inactive
*/
function phpbb_inactive_time()
{
	global $convert_row;

	if ($convert_row['user_active'])
	{
		return 0;
	}

	if ($convert_row['user_lastvisit'])
	{
		return $convert_row['user_lastvisit'];
	}

	return $convert_row['user_regdate'];
}

/**
* Calculate the reason a user became inactive
* We can't actually tell the difference between a manual deactivation and one for profile changes
* from the data available to assume the latter
*/
function phpbb_inactive_reason()
{
	global $convert_row;

	if ($convert_row['user_active'])
	{
		return 0;
	}

	if ($convert_row['user_lastvisit'])
	{
		return INACTIVE_PROFILE;
	}

	return INACTIVE_REGISTER;
}

/**
* Adjust 2.0.x disallowed names to 3.0.x format
*/
function phpbb_disallowed_username($username)
{
	// Replace * with %
	$username = phpbb_set_default_encoding(str_replace('*', '%', $username));
	return utf8_htmlspecialchars($username);
}

function phpbb_set_clean_name($name)
{
return utf8_strtolower(phpbb_set_default_encoding($name));;
}

?>

Klia
Registered User
Posts: 21
Joined: Sun Aug 26, 2007 8:28 pm
Contact:

Re: IPB 2.3.x to phpBB 3

Post by Klia » Sun Sep 30, 2007 8:57 pm

auth_ipb.php - for transparent authentification of IPB users.

Code: Select all

<?php
/**
* Database auth plug-in for phpBB3
*
* Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him.
*
* This is for authentication via the integrated user table
*
* @package login
* @version $Id: auth_db.php,v 1.21 2007/05/14 20:08:11 naderman Exp $
* @copyright (c) 2005 phpBB Group 
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* Login function
*/
function login_ipb(&$username, &$password)
{
	global $db, $config;

	$sql = 'SELECT user_id, username, user_password, user_passchg, user_pass_convert, user_email, user_type, user_login_attempts
		FROM ' . USERS_TABLE . "
		WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
	$result = $db->sql_query($sql);
	$row = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

	if (!$row)
	{
		return array(
			'status'	=> LOGIN_ERROR_USERNAME,
			'error_msg'	=> 'LOGIN_ERROR_USERNAME',
			'user_row'	=> array('user_id' => ANONYMOUS),
		);
	}

	// If there are too much login attempts, we need to check for an confirm image
	// Every auth module is able to define what to do by itself...
	if ($config['max_login_attempts'] && $row['user_login_attempts'] >= $config['max_login_attempts'])
	{
		$confirm_id = request_var('confirm_id', '');
		$confirm_code = request_var('confirm_code', '');

		// Visual Confirmation handling
		if (!$confirm_id)
		{
			return array(
				'status'		=> LOGIN_ERROR_ATTEMPTS,
				'error_msg'		=> 'LOGIN_ERROR_ATTEMPTS',
				'user_row'		=> $row,
			);
		}
		else
		{
			global $user;

			$sql = 'SELECT code
				FROM ' . CONFIRM_TABLE . "
				WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
					AND session_id = '" . $db->sql_escape($user->session_id) . "'
					AND confirm_type = " . CONFIRM_LOGIN;
			$result = $db->sql_query($sql);
			$confirm_row = $db->sql_fetchrow($result);
			$db->sql_freeresult($result);

			if ($confirm_row)
			{
				if (strcasecmp($confirm_row['code'], $confirm_code) === 0)
				{
					$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
						WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
							AND session_id = '" . $db->sql_escape($user->session_id) . "'
							AND confirm_type = " . CONFIRM_LOGIN;
					$db->sql_query($sql);
				}
				else
				{
					return array(
						'status'		=> LOGIN_ERROR_ATTEMPTS,
						'error_msg'		=> 'CONFIRM_CODE_WRONG',
						'user_row'		=> $row,
					);
				}
			}
			else
			{
				return array(
					'status'		=> LOGIN_ERROR_ATTEMPTS,
					'error_msg'		=> 'CONFIRM_CODE_WRONG',
					'user_row'		=> $row,
				);
			}
		}
	}

	// If the password convert flag is set we need to convert it
	if ($row['user_pass_convert'])
	{
		$prefix='ibf_';
		$sql2="SELECT ".$prefix."members_converge.converge_pass_hash, ".$prefix."members_converge.converge_pass_salt,".$prefix."members.name FROM ".$prefix."members_converge,".$prefix."members WHERE ".$prefix."members.name REGEXP ('" . $db->sql_escape(utf8_clean_string($username)) . "')";
		$resulty = $db->sql_query($sql2);
	$rowu = $db->sql_fetchrow($resulty);
	$db->sql_freeresult($resulty);

			$password = isset($_REQUEST['password']) ? (string) $_REQUEST['password'] : '';
			// cp1252 is phpBB2's default encoding, characters outside ASCII range might work when converted into that encoding
			if (md5(md5($rowu['converge_pass_salt']).md5($password)) == $rowu['converge_pass_hash'])
			{
				// Update the password in the users table to the new format and remove user_pass_convert flag
				$sql = 'UPDATE ' . USERS_TABLE . '
					SET user_password = \'' . $db->sql_escape(md5($password)) . '\',
						user_pass_convert = 0
					WHERE user_id = ' . $row['user_id'];
				$db->sql_query($sql);

				$row['user_pass_convert'] = 0;
				$row['user_password'] = md5($password);
			}
			else
			{
				// Although we weren't able to convert this password we have to
				// increase login attempt count to make sure this cannot be exploited
				/*
				$sql = 'UPDATE ' . USERS_TABLE . '
					SET user_login_attempts = user_login_attempts + 1
					WHERE user_id = ' . $row['user_id'];
				$db->sql_query($sql);*/

				return array(
					'status'		=> LOGIN_ERROR_PASSWORD_CONVERT,
					'error_msg'		=> 'LOGIN_ERROR_PASSWORD_CONVERT',
					'user_row'		=> $row,
				);
			}
		}

	// Check password ...
	if (!$row['user_pass_convert'] && md5($password) == $row['user_password'])
	{
		if ($row['user_login_attempts'] != 0)
		{
			// Successful, reset login attempts (the user passed all stages)
			$sql = 'UPDATE ' . USERS_TABLE . '
				SET user_login_attempts = 0
				WHERE user_id = ' . $row['user_id'];
			$db->sql_query($sql);
		}

		// User inactive...
		if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
		{
			return array(
				'status'		=> LOGIN_ERROR_ACTIVE,
				'error_msg'		=> 'ACTIVE_ERROR',
				'user_row'		=> $row,
			);
		}

		// Successful login... set user_login_attempts to zero...
		return array(
			'status'		=> LOGIN_SUCCESS,
			'error_msg'		=> false,
			'user_row'		=> $row,
		);
	}

	// Password incorrect - increase login attempts
	$sql = 'UPDATE ' . USERS_TABLE . '
		SET user_login_attempts = user_login_attempts + 1
		WHERE user_id = ' . $row['user_id'];
	$db->sql_query($sql);

	// Give status about wrong password...
	return array(
		'status'		=> LOGIN_ERROR_PASSWORD,
		'error_msg'		=> 'LOGIN_ERROR_PASSWORD',
		'user_row'		=> $row,
	);
}

?>

joshuaali
Registered User
Posts: 4
Joined: Thu Sep 06, 2007 10:31 am

Re: IPB 2.3.x to phpBB 3

Post by joshuaali » Wed Oct 03, 2007 12:16 pm

Kila: I tested your converter. Posts, private messages and topics are converted, however, users are not. My old IPB board had almost 85,000 users. My users table was empty (other than the Anonymous account) and my user_group table had over 2,000,000 rows, all of which was not in the right format (e.g. user_id in the group_id column).

I guess there's still only one safe way to convert for now.

Klia
Registered User
Posts: 21
Joined: Sun Aug 26, 2007 8:28 pm
Contact:

Re: IPB 2.3.x to phpBB 3

Post by Klia » Wed Oct 03, 2007 2:17 pm

hmm.. very strange thing.
I'm successfully converted all my groups(8) and users(105).

joshiejack
Registered User
Posts: 2
Joined: Mon Feb 19, 2007 9:22 pm
Contact:

Re: IPB 2.3.x to phpBB 3

Post by joshiejack » Thu Oct 04, 2007 4:52 pm

How do you actually use this :?

Klia
Registered User
Posts: 21
Joined: Sun Aug 26, 2007 8:28 pm
Contact:

Re: IPB 2.3.x to phpBB 3

Post by Klia » Thu Oct 04, 2007 7:29 pm


joshiejack
Registered User
Posts: 2
Joined: Mon Feb 19, 2007 9:22 pm
Contact:

Re: IPB 2.3.x to phpBB 3

Post by joshiejack » Fri Oct 05, 2007 11:40 am

lol.

I feel stupid :?


index.php?mode=convert&sub=in_progress&tag=ipb23&confirm=1

When I get to there... the page just goes blank :S

Locked

Return to “[3.0.x] Convertors”

Who is online

Users browsing this forum: No registered users and 13 guests