Blame Identity/Webenv/App/phpBB/3.0.4/includes/functions_convert.php

f2e824
f2e824
/**
f2e824
*
f2e824
* @package install
f2e824
* @version $Id: functions_convert.php 8876 2008-09-18 14:26:56Z acydburn $
f2e824
* @copyright (c) 2006 phpBB Group
f2e824
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
f2e824
*
f2e824
*/
f2e824
f2e824
/**
f2e824
* @ignore
f2e824
*/
f2e824
if (!defined('IN_PHPBB'))
f2e824
{
f2e824
	exit;
f2e824
}
f2e824
f2e824
/**
f2e824
* Default avatar width/height
f2e824
* @ignore
f2e824
*/
f2e824
define('DEFAULT_AVATAR_X', 80);
f2e824
define('DEFAULT_AVATAR_Y', 80);
f2e824
f2e824
// Global functions - all functions can be used by convertors
f2e824
f2e824
// SIMPLE FUNCTIONS
f2e824
f2e824
/**
f2e824
* Return the preceding value
f2e824
*/
f2e824
function dec($var)
f2e824
{
f2e824
	return --$var;
f2e824
}
f2e824
f2e824
/**
f2e824
* Return the next value
f2e824
*/
f2e824
function inc($var)
f2e824
{
f2e824
	return ++$var;
f2e824
}
f2e824
f2e824
/**
f2e824
* Return whether the value is positive
f2e824
*/
f2e824
function is_positive($n)
f2e824
{
f2e824
	return ($n > 0) ? 1 : 0;
f2e824
}
f2e824
f2e824
/**
f2e824
* Boolean inverse of the value
f2e824
*/
f2e824
function not($var)
f2e824
{
f2e824
	return ($var) ? 0 : 1;
f2e824
}
f2e824
f2e824
/**
f2e824
* Convert a textual value to it's equivalent boolean value
f2e824
*
f2e824
* @param string $str String to convert (converts yes, on, y, 1 and true to boolean true)
f2e824
* @return boolean The equivalent value
f2e824
*/
f2e824
function str_to_bool($str)
f2e824
{
f2e824
	$str = strtolower($str);
f2e824
	return ($str == 'yes' || $str == 'on' || $str == 'y' || $str == 'true' || $str == '1') ? true : false;
f2e824
}
f2e824
f2e824
/**
f2e824
* Function to mimic php's empty() function (it is the same)
f2e824
*/
f2e824
function is_empty($mixed)
f2e824
{
f2e824
	return empty($mixed);
f2e824
}
f2e824
f2e824
/**
f2e824
* Convert the name of a user's primary group to the appropriate equivalent phpBB group id
f2e824
*
f2e824
* @param string $status The name of the group
f2e824
* @return int The group_id corresponding to the equivalent group
f2e824
*/
f2e824
function str_to_primary_group($status)
f2e824
{
f2e824
	switch (ucfirst(strtolower($status)))
f2e824
	{
f2e824
		case 'Administrator':
f2e824
			return get_group_id('administrators');
f2e824
		break;
f2e824
f2e824
		case 'Super moderator':
f2e824
		case 'Global moderator':
f2e824
		case 'Moderator':
f2e824
			return get_group_id('global_moderators');
f2e824
		break;
f2e824
f2e824
		case 'Guest':
f2e824
		case 'Anonymous':
f2e824
			return get_group_id('guests');
f2e824
		break;
f2e824
f2e824
		default:
f2e824
			return get_group_id('registered');
f2e824
		break;
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Convert a boolean into the appropriate phpBB constant indicating whether the item is locked
f2e824
*/
f2e824
function is_item_locked($bool)
f2e824
{
f2e824
	return ($bool) ? ITEM_LOCKED : ITEM_UNLOCKED;
f2e824
}
f2e824
f2e824
/**
f2e824
* Convert a value from days to seconds
f2e824
*/
f2e824
function days_to_seconds($days)
f2e824
{
f2e824
	return ($days * 86400);
f2e824
}
f2e824
f2e824
/**
f2e824
* Determine whether a user is anonymous and return the appropriate new user_id
f2e824
*/
f2e824
function is_user_anonymous($user_id)
f2e824
{
f2e824
	return ($user_id > ANONYMOUS) ? $user_id : ANONYMOUS;
f2e824
}
f2e824
f2e824
/**
f2e824
* Generate a key value based on existing values
f2e824
*
f2e824
* @param int $pad Amount to add to the maximum value
f2e824
* @return int Key value
f2e824
*/
f2e824
function auto_id($pad = 0)
f2e824
{
f2e824
	global $auto_id, $convert_row;
f2e824
f2e824
	if (!empty($convert_row['max_id']))
f2e824
	{
f2e824
		return $convert_row['max_id'] + $pad;
f2e824
	}
f2e824
f2e824
	return $auto_id + $pad;
f2e824
}
f2e824
f2e824
/**
f2e824
* Convert a boolean into the appropriate phpBB constant indicating whether the user is active
f2e824
*/
f2e824
function set_user_type($user_active)
f2e824
{
f2e824
	return ($user_active) ? USER_NORMAL : USER_INACTIVE;
f2e824
}
f2e824
f2e824
/**
f2e824
* Convert a value from minutes to hours
f2e824
*/
f2e824
function minutes_to_hours($minutes)
f2e824
{
f2e824
	return ($minutes / 3600);
f2e824
}
f2e824
f2e824
/**
f2e824
* Return the group_id for a given group name
f2e824
*/
f2e824
function get_group_id($group_name)
f2e824
{
f2e824
	global $db, $group_mapping;
f2e824
f2e824
	if (empty($group_mapping))
f2e824
	{
f2e824
		$sql = 'SELECT group_name, group_id
f2e824
			FROM ' . GROUPS_TABLE;
f2e824
		$result = $db->sql_query($sql);
f2e824
f2e824
		$group_mapping = array();
f2e824
		while ($row = $db->sql_fetchrow($result))
f2e824
		{
f2e824
			$group_mapping[strtoupper($row['group_name'])] = (int) $row['group_id'];
f2e824
		}
f2e824
		$db->sql_freeresult($result);
f2e824
	}
f2e824
f2e824
	if (!sizeof($group_mapping))
f2e824
	{
f2e824
		add_default_groups();
f2e824
		return get_group_id($group_name);
f2e824
	}
f2e824
f2e824
	if (isset($group_mapping[strtoupper($group_name)]))
f2e824
	{
f2e824
		return $group_mapping[strtoupper($group_name)];
f2e824
	}
f2e824
f2e824
	return $group_mapping['REGISTERED'];
f2e824
}
f2e824
f2e824
/**
f2e824
* Generate the email hash stored in the users table
f2e824
*/
f2e824
function gen_email_hash($email)
f2e824
{
f2e824
	return (crc32(strtolower($email)) . strlen($email));
f2e824
}
f2e824
f2e824
/**
f2e824
* Convert a boolean into the appropriate phpBB constant indicating whether the topic is locked
f2e824
*/
f2e824
function is_topic_locked($bool)
f2e824
{
f2e824
	return (!empty($bool)) ? ITEM_LOCKED : ITEM_UNLOCKED;
f2e824
}
f2e824
f2e824
/**
f2e824
* Generate a bbcode_uid value
f2e824
*/
f2e824
function make_uid($timestamp)
f2e824
{
f2e824
	static $last_timestamp, $last_uid;
f2e824
f2e824
	if (empty($last_timestamp) || $timestamp != $last_timestamp)
f2e824
	{
f2e824
		$last_uid = substr(base_convert(unique_id(), 16, 36), 0, BBCODE_UID_LEN);
f2e824
	}
f2e824
	$last_timestamp = $timestamp;
f2e824
	return $last_uid;
f2e824
}
f2e824
f2e824
f2e824
/**
f2e824
* Validate a website address
f2e824
*/
f2e824
function validate_website($url)
f2e824
{
f2e824
	if ($url === 'http://')
f2e824
	{
f2e824
		return '';
f2e824
	}
f2e824
	else if (!preg_match('#^[a-z0-9]+://#i', $url) && strlen($url) > 0)
f2e824
	{
f2e824
		return 'http://' . $url;
f2e824
	}
f2e824
	return $url;
f2e824
}
f2e824
f2e824
/**
f2e824
* Convert nulls to zeros for fields which allowed a NULL value in the source but not the destination
f2e824
*/
f2e824
function null_to_zero($value)
f2e824
{
f2e824
	return ($value === NULL) ? 0 : $value;
f2e824
}
f2e824
f2e824
/**
f2e824
* Convert nulls to empty strings for fields which allowed a NULL value in the source but not the destination
f2e824
*/
f2e824
function null_to_str($value)
f2e824
{
f2e824
	return ($value === NULL) ? '' : $value;
f2e824
}
f2e824
f2e824
// EXTENDED FUNCTIONS
f2e824
f2e824
/**
f2e824
* Get old config value
f2e824
*/
f2e824
function get_config_value($config_name)
f2e824
{
f2e824
	static $convert_config;
f2e824
f2e824
	if (!isset($convert_config))
f2e824
	{
f2e824
		$convert_config = get_config();
f2e824
	}
f2e824
f2e824
	if (!isset($convert_config[$config_name]))
f2e824
	{
f2e824
		return false;
f2e824
	}
f2e824
f2e824
	return (empty($convert_config[$config_name])) ? '' : $convert_config[$config_name];
f2e824
}
f2e824
f2e824
/**
f2e824
* Convert an IP address from the hexadecimal notation to normal dotted-quad notation
f2e824
*/
f2e824
function decode_ip($int_ip)
f2e824
{
f2e824
	if (!$int_ip)
f2e824
	{
f2e824
		return $int_ip;
f2e824
	}
f2e824
f2e824
	$hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
f2e824
f2e824
	// Any mod changing the way ips are stored? Then we are not able to convert and enter the ip "as is" to not "destroy" anything...
f2e824
	if (sizeof($hexipbang) < 4)
f2e824
	{
f2e824
		return $int_ip;
f2e824
	}
f2e824
f2e824
	return hexdec($hexipbang[0]) . '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
f2e824
}
f2e824
f2e824
/**
f2e824
* Reverse the encoding of wild-carded bans
f2e824
*/
f2e824
function decode_ban_ip($int_ip)
f2e824
{
f2e824
	return str_replace('255', '*', decode_ip($int_ip));
f2e824
}
f2e824
f2e824
/**
f2e824
* Determine the MIME-type of a specified filename
f2e824
* This does not actually inspect the file, but simply uses the file extension
f2e824
*/
f2e824
function mimetype($filename)
f2e824
{
f2e824
	if (!preg_match('/\.([a-z0-9]+)$/i', $filename, $m))
f2e824
	{
f2e824
		return 'application/octet-stream';
f2e824
	}
f2e824
f2e824
	switch (strtolower($m[1]))
f2e824
	{
f2e824
		case 'zip':		return 'application/zip';
f2e824
		case 'jpeg':	return 'image/jpeg';
f2e824
		case 'jpg':		return 'image/jpeg';
f2e824
		case 'jpe':		return 'image/jpeg';
f2e824
		case 'png':		return 'image/png';
f2e824
		case 'gif':		return 'image/gif';
f2e824
		case 'htm':
f2e824
		case 'html':	return 'text/html';
f2e824
		case 'tif':		return 'image/tiff';
f2e824
		case 'tiff':	return 'image/tiff';
f2e824
		case 'ras':		return 'image/x-cmu-raster';
f2e824
		case 'pnm':		return 'image/x-portable-anymap';
f2e824
		case 'pbm':		return 'image/x-portable-bitmap';
f2e824
		case 'pgm':		return 'image/x-portable-graymap';
f2e824
		case 'ppm':		return 'image/x-portable-pixmap';
f2e824
		case 'rgb':		return 'image/x-rgb';
f2e824
		case 'xbm':		return 'image/x-xbitmap';
f2e824
		case 'xpm':		return 'image/x-xpixmap';
f2e824
		case 'xwd':		return 'image/x-xwindowdump';
f2e824
		case 'z':		return 'application/x-compress';
f2e824
		case 'gtar':	return 'application/x-gtar';
f2e824
		case 'tgz':		return 'application/x-gtar';
f2e824
		case 'gz':		return 'application/x-gzip';
f2e824
		case 'tar':		return 'application/x-tar';
f2e824
		case 'xls':		return 'application/excel';
f2e824
		case 'pdf':		return 'application/pdf';
f2e824
		case 'ppt':		return 'application/powerpoint';
f2e824
		case 'rm':		return 'application/vnd.rn-realmedia';
f2e824
		case 'wma':		return 'audio/x-ms-wma';
f2e824
		case 'swf':		return 'application/x-shockwave-flash';
f2e824
		case 'ief':		return 'image/ief';
f2e824
		case 'doc':
f2e824
		case 'dot':
f2e824
		case 'wrd':		return 'application/msword';
f2e824
		case 'ai':
f2e824
		case 'eps':
f2e824
		case 'ps':		return 'application/postscript';
f2e824
		case 'asc':
f2e824
		case 'txt':
f2e824
		case 'c':
f2e824
		case 'cc':
f2e824
		case 'h':
f2e824
		case 'hh':
f2e824
		case 'cpp':
f2e824
		case 'hpp':
f2e824
		case 'php':
f2e824
		case 'php3':	return 'text/plain';
f2e824
		default: 		return 'application/octet-stream';
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Obtain the dimensions of all remotely hosted avatars
f2e824
* This should only be called from execute_last
f2e824
* There can be significant network overhead if there are a large number of remote avatars
f2e824
* @todo Look at the option of allowing the user to decide whether this is called or to force the dimensions
f2e824
*/
f2e824
function remote_avatar_dims()
f2e824
{
f2e824
	global $db;
f2e824
f2e824
	$sql = 'SELECT user_id, user_avatar
f2e824
		FROM ' . USERS_TABLE . '
f2e824
		WHERE user_avatar_type = ' . AVATAR_REMOTE;
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	$remote_avatars = array();
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$remote_avatars[(int) $row['user_id']] = $row['user_avatar'];
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	foreach ($remote_avatars as $user_id => $avatar)
f2e824
	{
f2e824
		$width = (int) get_remote_avatar_dim($avatar, 0);
f2e824
		$height = (int) get_remote_avatar_dim($avatar, 1);
f2e824
f2e824
		$sql = 'UPDATE ' . USERS_TABLE . '
f2e824
			SET user_avatar_width = ' . (int) $width . ', user_avatar_height = ' . (int) $height . '
f2e824
			WHERE user_id = ' . $user_id;
f2e824
		$db->sql_query($sql);
f2e824
	}
f2e824
}
f2e824
f2e824
function import_avatar_gallery($gallery_name = '', $subdirs_as_galleries = false)
f2e824
{
f2e824
	global $config, $convert, $phpbb_root_path, $user;
f2e824
f2e824
	$relative_path = empty($convert->convertor['source_path_absolute']);
f2e824
f2e824
	if (empty($convert->convertor['avatar_gallery_path']))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_NO_GALLERY_PATH'], 'import_avatar_gallery()'), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	$src_path = relative_base(path($convert->convertor['avatar_gallery_path'], $relative_path), $relative_path);
f2e824
f2e824
	if (is_dir($src_path))
f2e824
	{
f2e824
		// Do not die on failure... safe mode restrictions may be in effect.
f2e824
		copy_dir($convert->convertor['avatar_gallery_path'], path($config['avatar_gallery_path']) . $gallery_name, !$subdirs_as_galleries, false, false, $relative_path);
f2e824
f2e824
		// only doing 1 level deep. (ibf 1.x)
f2e824
		// notes: ibf has 2 tiers: directly in the avatar directory for base gallery (handled in the above statement), plus subdirs(handled below).
f2e824
		// recursive subdirs ignored. -- i don't know if other forums support recursive galleries. if they do, this following code could be upgraded to be recursive.
f2e824
		if ($subdirs_as_galleries)
f2e824
		{
f2e824
			$dirlist = array();
f2e824
			if ($handle = @opendir($src_path))
f2e824
			{
f2e824
				while ($entry = readdir($handle))
f2e824
				{
f2e824
					if ($entry[0] == '.' || $entry == 'CVS' || $entry == 'index.htm')
f2e824
					{
f2e824
						continue;
f2e824
					}
f2e824
f2e824
					if (is_dir($src_path . $entry))
f2e824
					{
f2e824
						$dirlist[] = $entry;
f2e824
					}
f2e824
				}
f2e824
				closedir($handle);
f2e824
			}
f2e824
			else if ($dir = @dir($src_path))
f2e824
			{
f2e824
				while ($entry = $dir->read())
f2e824
				{
f2e824
					if ($entry[0] == '.' || $entry == 'CVS' || $entry == 'index.htm')
f2e824
					{
f2e824
						continue;
f2e824
					}
f2e824
f2e824
					if (is_dir($src_path . $entry))
f2e824
					{
f2e824
						$dirlist[] = $entry;
f2e824
					}
f2e824
				}
f2e824
				$dir->close();
f2e824
			}
f2e824
f2e824
			for ($i = 0; $i < sizeof($dirlist); ++$i)
f2e824
			{
f2e824
				$dir = $dirlist[$i];
f2e824
f2e824
				// Do not die on failure... safe mode restrictions may be in effect.
f2e824
				copy_dir(path($convert->convertor['avatar_gallery_path'], $relative_path) . $dir, path($config['avatar_gallery_path']) . $dir, true, false, false, $relative_path);
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
}
f2e824
f2e824
function import_attachment_files($category_name = '')
f2e824
{
f2e824
	global $config, $convert, $phpbb_root_path, $db, $user;
f2e824
f2e824
	$sql = 'SELECT config_value AS upload_path
f2e824
		FROM ' . CONFIG_TABLE . "
f2e824
		WHERE config_name = 'upload_path'";
f2e824
	$result = $db->sql_query($sql);
f2e824
	$config['upload_path'] = $db->sql_fetchfield('upload_path');
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	$relative_path = empty($convert->convertor['source_path_absolute']);
f2e824
f2e824
	if (empty($convert->convertor['upload_path']))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_NO_UPLOAD_DIR'], 'import_attachment_files()'), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	if (is_dir(relative_base(path($convert->convertor['upload_path'], $relative_path), $relative_path)))
f2e824
	{
f2e824
		copy_dir($convert->convertor['upload_path'], path($config['upload_path']) . $category_name, true, false, true, $relative_path);
f2e824
	}
f2e824
}
f2e824
f2e824
function attachment_forum_perms($forum_id)
f2e824
{
f2e824
	if (!is_array($forum_id))
f2e824
	{
f2e824
		$forum_id = array($forum_id);
f2e824
	}
f2e824
f2e824
	return serialize($forum_id);
f2e824
}
f2e824
f2e824
// base64todec function
f2e824
// -> from php manual?
f2e824
function base64_unpack($string)
f2e824
{
f2e824
	$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-';
f2e824
	$base = strlen($chars);
f2e824
f2e824
	$length = strlen($string);
f2e824
	$number = 0;
f2e824
f2e824
	for ($i = 1; $i <= $length; $i++)
f2e824
	{
f2e824
		$pos = $length - $i;
f2e824
		$operand = strpos($chars, substr($string, $pos, 1));
f2e824
		$exponent = pow($base, $i-1);
f2e824
		$dec_value = $operand * $exponent;
f2e824
		$number += $dec_value;
f2e824
	}
f2e824
f2e824
	return $number;
f2e824
}
f2e824
f2e824
function _import_check($config_var, $source, $use_target)
f2e824
{
f2e824
	global $convert, $config;
f2e824
f2e824
	$result = array(
f2e824
		'orig_source'	=> $source,
f2e824
		'copied'		=> false,
f2e824
		'relative_path'	=> (empty($convert->convertor['source_path_absolute'])) ? true : false,
f2e824
	);
f2e824
f2e824
	// copy file will prepend $phpBB_root_path
f2e824
	$target = $config[$config_var] . '/' . basename(($use_target === false) ? $source : $use_target);
f2e824
f2e824
	if (!empty($convert->convertor[$config_var]) && strpos($source, $convert->convertor[$config_var]) !== 0)
f2e824
	{
f2e824
		$source = $convert->convertor[$config_var] . $source;
f2e824
	}
f2e824
f2e824
	$result['source'] = $source;
f2e824
f2e824
	if (file_exists(relative_base($source, $result['relative_path'], __LINE__, __FILE__)))
f2e824
	{
f2e824
		$result['copied'] = copy_file($source, $target, false, false, $result['relative_path']);
f2e824
	}
f2e824
f2e824
	if ($result['copied'])
f2e824
	{
f2e824
		$result['target'] = basename($target);
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		$result['target'] = ($use_target !== false) ? $result['orig_source'] : basename($target);
f2e824
	}
f2e824
f2e824
	return $result;
f2e824
}
f2e824
f2e824
function import_attachment($source, $use_target = false)
f2e824
{
f2e824
	if (empty($source))
f2e824
	{
f2e824
		return '';
f2e824
	}
f2e824
f2e824
	global $convert, $phpbb_root_path, $config, $user;
f2e824
f2e824
	if (empty($convert->convertor['upload_path']))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_NO_UPLOAD_DIR'], 'import_attachment()'), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	$result = _import_check('upload_path', $source, $use_target);
f2e824
f2e824
	if ($result['copied'])
f2e824
	{
f2e824
		// Thumbnails?
f2e824
		if (is_array($convert->convertor['thumbnails']))
f2e824
		{
f2e824
			$thumb_dir = $convert->convertor['thumbnails'][0];
f2e824
			$thumb_prefix = $convert->convertor['thumbnails'][1];
f2e824
			$thumb_source = $thumb_dir . $thumb_prefix . basename($result['source']);
f2e824
f2e824
			if (strpos($thumb_source, $convert->convertor['upload_path']) !== 0)
f2e824
			{
f2e824
				$thumb_source = $convert->convertor['upload_path'] . $thumb_source;
f2e824
			}
f2e824
			$thumb_target = $config['upload_path'] . '/thumb_' . $result['target'];
f2e824
f2e824
			if (file_exists(relative_base($thumb_source, $result['relative_path'], __LINE__, __FILE__)))
f2e824
			{
f2e824
				copy_file($thumb_source, $thumb_target, false, false, $result['relative_path']);
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
f2e824
	return $result['target'];
f2e824
}
f2e824
f2e824
function import_rank($source, $use_target = false)
f2e824
{
f2e824
	if (empty($source))
f2e824
	{
f2e824
		return '';
f2e824
	}
f2e824
f2e824
	global $convert, $phpbb_root_path, $config, $user;
f2e824
f2e824
	if (!isset($convert->convertor['ranks_path']))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_NO_RANKS_PATH'], 'import_rank()'), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	$result = _import_check('ranks_path', $source, $use_target);
f2e824
	return $result['target'];
f2e824
}
f2e824
f2e824
function import_smiley($source, $use_target = false)
f2e824
{
f2e824
	if (empty($source))
f2e824
	{
f2e824
		return '';
f2e824
	}
f2e824
f2e824
	global $convert, $phpbb_root_path, $config, $user;
f2e824
f2e824
	if (!isset($convert->convertor['smilies_path']))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_NO_SMILIES_PATH'], 'import_smiley()'), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	$result = _import_check('smilies_path', $source, $use_target);
f2e824
	return $result['target'];
f2e824
}
f2e824
f2e824
/*
f2e824
*/
f2e824
function import_avatar($source, $use_target = false, $user_id = false)
f2e824
{
f2e824
	if (empty($source) || preg_match('#^https?:#i', $source) || preg_match('#blank\.(gif|png)$#i', $source))
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	global $convert, $phpbb_root_path, $config, $user;
f2e824
f2e824
	if (!isset($convert->convertor['avatar_path']))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_NO_AVATAR_PATH'], 'import_avatar()'), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	if ($use_target === false && $user_id !== false)
f2e824
	{
f2e824
		$use_target = $config['avatar_salt'] . '_' . $user_id . '.' . substr(strrchr($source, '.'), 1);
f2e824
	}
f2e824
f2e824
	$result = _import_check('avatar_path', $source, $use_target);
f2e824
f2e824
	return ((!empty($user_id)) ? $user_id : $use_target) . '.' . substr(strrchr($source, '.'), 1);
f2e824
}
f2e824
f2e824
/**
f2e824
* @todo all image dimension functions below (there are a *lot*) should get revisited and converted to one or two functions (no more needed, really).
f2e824
*/
f2e824
f2e824
/**
f2e824
* Calculate the size of the specified image
f2e824
* Called from the following functions for calculating the size of specific image types
f2e824
*/
f2e824
function get_image_dim($source)
f2e824
{
f2e824
	if (empty($source))
f2e824
	{
f2e824
		return array(0, 0);
f2e824
	}
f2e824
f2e824
	global $convert;
f2e824
f2e824
	$relative_path = empty($convert->convertor['source_path_absolute']);
f2e824
f2e824
	if (file_exists(relative_base($source, $relative_path)))
f2e824
	{
f2e824
		$image = relative_base($source, $relative_path);
f2e824
		return @getimagesize($image);
f2e824
	}
f2e824
f2e824
	return false;
f2e824
}
f2e824
f2e824
/**
f2e824
* Obtain the width of the specified smilie
f2e824
*/
f2e824
function get_smiley_width($src)
f2e824
{
f2e824
	return get_smiley_dim($src, 0);
f2e824
}
f2e824
f2e824
/**
f2e824
* Obtain the height of the specified smilie
f2e824
*/
f2e824
function get_smiley_height($src)
f2e824
{
f2e824
	return get_smiley_dim($src, 1);
f2e824
}
f2e824
f2e824
/**
f2e824
* Obtain the size of the specified smilie (using the cache if possible) and cache the value
f2e824
*/
f2e824
function get_smiley_dim($source, $axis)
f2e824
{
f2e824
	if (empty($source))
f2e824
	{
f2e824
		return 15;
f2e824
	}
f2e824
f2e824
	static $smiley_cache = array();
f2e824
f2e824
	if (isset($smiley_cache[$source]))
f2e824
	{
f2e824
		return $smiley_cache[$source][$axis];
f2e824
	}
f2e824
f2e824
	global $convert, $phpbb_root_path, $config, $user;
f2e824
f2e824
	$orig_source = $source;
f2e824
f2e824
	if (!isset($convert->convertor['smilies_path']))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_NO_SMILIES_PATH'], 'get_smiley_dim()'), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	if (!empty($convert->convertor['smilies_path']) && strpos($source, $convert->convertor['smilies_path']) !== 0)
f2e824
	{
f2e824
		$source = $convert->convertor['smilies_path'] . $source;
f2e824
	}
f2e824
f2e824
	$smiley_cache[$orig_source] = get_image_dim($source);
f2e824
f2e824
	if (empty($smiley_cache[$orig_source]) || empty($smiley_cache[$orig_source][0]) || empty($smiley_cache[$orig_source][1]))
f2e824
	{
f2e824
		$smiley_cache[$orig_source] = array(15, 15);
f2e824
		return 15;
f2e824
	}
f2e824
f2e824
	return $smiley_cache[$orig_source][$axis];
f2e824
}
f2e824
f2e824
/**
f2e824
* Obtain the width of the specified avatar
f2e824
*/
f2e824
function get_avatar_width($src, $func = false, $arg1 = false, $arg2 = false)
f2e824
{
f2e824
	return get_avatar_dim($src, 0, $func, $arg1, $arg2);
f2e824
}
f2e824
f2e824
/**
f2e824
* Obtain the height of the specified avatar
f2e824
*/
f2e824
function get_avatar_height($src, $func = false, $arg1 = false, $arg2 = false)
f2e824
{
f2e824
	return get_avatar_dim($src, 1, $func, $arg1, $arg2);
f2e824
}
f2e824
f2e824
/**
f2e824
*/
f2e824
function get_avatar_dim($src, $axis, $func = false, $arg1 = false, $arg2 = false)
f2e824
{
f2e824
	$avatar_type = AVATAR_UPLOAD;
f2e824
f2e824
	if ($func)
f2e824
	{
f2e824
		if ($arg1 || $arg2)
f2e824
		{
f2e824
			$ary = array($arg1);
f2e824
f2e824
			if ($arg2)
f2e824
			{
f2e824
				$ary[] = $arg2;
f2e824
			}
f2e824
f2e824
			$avatar_type = call_user_func_array($func, $ary);
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$avatar_type = call_user_func($func);
f2e824
		}
f2e824
	}
f2e824
f2e824
	switch ($avatar_type)
f2e824
	{
f2e824
		case AVATAR_UPLOAD:
f2e824
			return get_upload_avatar_dim($src, $axis);
f2e824
		break;
f2e824
f2e824
		case AVATAR_GALLERY:
f2e824
			return get_gallery_avatar_dim($src, $axis);
f2e824
		break;
f2e824
f2e824
		case AVATAR_REMOTE:
f2e824
			 // see notes on this functions usage and (hopefully) model $func to avoid this accordingly
f2e824
			return get_remote_avatar_dim($src, $axis);
f2e824
		break;
f2e824
f2e824
		default:
f2e824
			$default_x = (defined('DEFAULT_AVATAR_X_CUSTOM')) ? DEFAULT_AVATAR_X_CUSTOM : DEFAULT_AVATAR_X;
f2e824
			$default_y = (defined('DEFAULT_AVATAR_Y_CUSTOM')) ? DEFAULT_AVATAR_Y_CUSTOM : DEFAULT_AVATAR_Y;
f2e824
f2e824
			return $axis ? $default_y : $default_x;
f2e824
		break;
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Obtain the size of the specified uploaded avatar (using the cache if possible) and cache the value
f2e824
*/
f2e824
function get_upload_avatar_dim($source, $axis)
f2e824
{
f2e824
	static $cachedims = false;
f2e824
	static $cachekey = false;
f2e824
f2e824
	if (empty($source))
f2e824
	{
f2e824
		return 0;
f2e824
	}
f2e824
f2e824
	if ($cachekey == $source)
f2e824
	{
f2e824
		return $cachedims[$axis];
f2e824
	}
f2e824
f2e824
	$orig_source = $source;
f2e824
f2e824
	if (substr($source, 0, 7) == 'upload:')
f2e824
	{
f2e824
		$source = substr($source, 7);
f2e824
	}
f2e824
f2e824
	global $convert, $phpbb_root_path, $config, $user;
f2e824
f2e824
	if (!isset($convert->convertor['avatar_path']))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_NO_AVATAR_PATH'], 'get_upload_avatar_dim()'), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	if (!empty($convert->convertor['avatar_path']) && strpos($source, $convert->convertor['avatar_path']) !== 0)
f2e824
	{
f2e824
		$source = path($convert->convertor['avatar_path'], empty($convert->convertor['source_path_absolute'])) . $source;
f2e824
	}
f2e824
f2e824
	$cachedims = get_image_dim($source);
f2e824
f2e824
	if (empty($cachedims) || empty($cachedims[0]) || empty($cachedims[1]))
f2e824
	{
f2e824
		$default_x = (defined('DEFAULT_AVATAR_X_CUSTOM')) ? DEFAULT_AVATAR_X_CUSTOM : DEFAULT_AVATAR_X;
f2e824
		$default_y = (defined('DEFAULT_AVATAR_Y_CUSTOM')) ? DEFAULT_AVATAR_Y_CUSTOM : DEFAULT_AVATAR_Y;
f2e824
f2e824
		$cachedims = array($default_x, $default_y);
f2e824
	}
f2e824
f2e824
	return $cachedims[$axis];
f2e824
}
f2e824
f2e824
/**
f2e824
* Obtain the size of the specified gallery avatar (using the cache if possible) and cache the value
f2e824
*/
f2e824
function get_gallery_avatar_dim($source, $axis)
f2e824
{
f2e824
	if (empty($source))
f2e824
	{
f2e824
		return 0;
f2e824
	}
f2e824
f2e824
	static $avatar_cache = array();
f2e824
f2e824
	if (isset($avatar_cache[$source]))
f2e824
	{
f2e824
		return $avatar_cache[$source][$axis];
f2e824
	}
f2e824
f2e824
	global $convert, $phpbb_root_path, $config, $user;
f2e824
f2e824
	$orig_source = $source;
f2e824
f2e824
	if (!isset($convert->convertor['avatar_gallery_path']))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_NO_GALLERY_PATH'], 'get_gallery_avatar_dim()'), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	if (!empty($convert->convertor['avatar_gallery_path']) && strpos($source, $convert->convertor['avatar_gallery_path']) !== 0)
f2e824
	{
f2e824
		$source = path($convert->convertor['avatar_gallery_path'], empty($convert->convertor['source_path_absolute'])) . $source;
f2e824
	}
f2e824
f2e824
	$avatar_cache[$orig_source] = get_image_dim($source);
f2e824
f2e824
	if (empty($avatar_cache[$orig_source]) || empty($avatar_cache[$orig_source][0]) || empty($avatar_cache[$orig_source][1]))
f2e824
	{
f2e824
		$default_x = (defined('DEFAULT_AVATAR_X_CUSTOM')) ? DEFAULT_AVATAR_X_CUSTOM : DEFAULT_AVATAR_X;
f2e824
		$default_y = (defined('DEFAULT_AVATAR_Y_CUSTOM')) ? DEFAULT_AVATAR_Y_CUSTOM : DEFAULT_AVATAR_Y;
f2e824
f2e824
		$avatar_cache[$orig_source] = array($default_x, $default_y);
f2e824
	}
f2e824
f2e824
	return $avatar_cache[$orig_source][$axis];
f2e824
}
f2e824
f2e824
/**
f2e824
* Obtain the size of the specified remote avatar (using the cache if possible) and cache the value
f2e824
* Whilst it's unlikely that remote avatars will be duplicated, it is possible so caching seems the best option
f2e824
* This should only be called from a post processing step due to the possibility of network timeouts
f2e824
*/
f2e824
function get_remote_avatar_dim($src, $axis)
f2e824
{
f2e824
	if (empty($src))
f2e824
	{
f2e824
		return 0;
f2e824
	}
f2e824
f2e824
	static $remote_avatar_cache = array();
f2e824
f2e824
	// an ugly hack: we assume that the dimensions of each remote avatar are accessed exactly twice (x and y)
f2e824
	if (isset($remote_avatar_cache[$src]))
f2e824
	{
f2e824
		$retval = $remote_avatar_cache[$src][$axis];
f2e824
		unset($remote_avatar_cache);
f2e824
		return $retval;
f2e824
	}
f2e824
f2e824
	$url_info = @parse_url($src);
f2e824
	if (empty($url_info['host']))
f2e824
	{
f2e824
		return 0;
f2e824
	}
f2e824
	$host = $url_info['host'];
f2e824
	$port = (isset($url_info['port'])) ? $url_info['port'] : 0;
f2e824
	$protocol = (isset($url_info['scheme'])) ? $url_info['scheme'] : 'http';
f2e824
	if (empty($port))
f2e824
	{
f2e824
		switch(strtolower($protocol))
f2e824
		{
f2e824
			case 'ftp':
f2e824
				$port = 21;
f2e824
				break;
f2e824
f2e824
			case 'https':
f2e824
				$port = 443;
f2e824
				break;
f2e824
f2e824
			default:
f2e824
				$port = 80;
f2e824
		}
f2e824
	}
f2e824
f2e824
	$timeout = @ini_get('default_socket_timeout');
f2e824
	@ini_set('default_socket_timeout', 2);
f2e824
f2e824
	// We're just trying to reach the server to avoid timeouts
f2e824
	$fp = @fsockopen($host, $port, $errno, $errstr, 1);
f2e824
	if ($fp)
f2e824
	{
f2e824
		$remote_avatar_cache[$src] = @getimagesize($src);
f2e824
		fclose($fp);
f2e824
	}
f2e824
f2e824
	$default_x 	= (defined('DEFAULT_AVATAR_X_CUSTOM')) ? DEFAULT_AVATAR_X_CUSTOM : DEFAULT_AVATAR_X;
f2e824
	$default_y 	= (defined('DEFAULT_AVATAR_Y_CUSTOM')) ? DEFAULT_AVATAR_Y_CUSTOM : DEFAULT_AVATAR_Y;
f2e824
	$default 	= array($default_x, $default_y);
f2e824
f2e824
	if (empty($remote_avatar_cache[$src]) || empty($remote_avatar_cache[$src][0]) || empty($remote_avatar_cache[$src][1]))
f2e824
	{
f2e824
		$remote_avatar_cache[$src] = $default;
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		// We trust gallery and uploaded avatars to conform to the size settings; we might have to adjust here
f2e824
		if ($remote_avatar_cache[$src][0] > $default_x || $remote_avatar_cache[$src][1] > $default_y)
f2e824
		{
f2e824
			$bigger = ($remote_avatar_cache[$src][0] > $remote_avatar_cache[$src][1]) ? 0 : 1;
f2e824
			$ratio = $default[$bigger] / $remote_avatar_cache[$src][$bigger];
f2e824
			$remote_avatar_cache[$src][0] = (int)($remote_avatar_cache[$src][0] * $ratio);
f2e824
			$remote_avatar_cache[$src][1] = (int)($remote_avatar_cache[$src][1] * $ratio);
f2e824
		}
f2e824
	}
f2e824
f2e824
	@ini_set('default_socket_timeout', $timeout);
f2e824
	return $remote_avatar_cache[$src][$axis];
f2e824
}
f2e824
f2e824
function set_user_options()
f2e824
{
f2e824
	global $convert_row;
f2e824
f2e824
	// Key need to be set in row, else default value is chosen
f2e824
	$keyoptions = array(
f2e824
		'viewimg'		=> array('bit' => 0, 'default' => 1),
f2e824
		'viewflash'		=> array('bit' => 1, 'default' => 1),
f2e824
		'viewsmilies'	=> array('bit' => 2, 'default' => 1),
f2e824
		'viewsigs'		=> array('bit' => 3, 'default' => 1),
f2e824
		'viewavatars'	=> array('bit' => 4, 'default' => 1),
f2e824
		'viewcensors'	=> array('bit' => 5, 'default' => 1),
f2e824
		'attachsig'		=> array('bit' => 6, 'default' => 0),
f2e824
		'bbcode'		=> array('bit' => 8, 'default' => 1),
f2e824
		'smilies'		=> array('bit' => 9, 'default' => 1),
f2e824
		'popuppm'		=> array('bit' => 10, 'default' => 0),
f2e824
	);
f2e824
f2e824
	$option_field = 0;
f2e824
f2e824
	foreach ($keyoptions as $key => $key_ary)
f2e824
	{
f2e824
		$value = (isset($convert_row[$key])) ? (int) $convert_row[$key] : $key_ary['default'];
f2e824
f2e824
		if ($value && !($option_field & 1 << $key_ary['bit']))
f2e824
		{
f2e824
			$option_field += 1 << $key_ary['bit'];
f2e824
		}
f2e824
	}
f2e824
f2e824
	return $option_field;
f2e824
}
f2e824
f2e824
/**
f2e824
* Index messages on the fly as we convert them
f2e824
* @todo naderman, can you check that this works with the new search plugins as it's use is currently disabled (and thus untested)
f2e824
function search_indexing($message = '')
f2e824
{
f2e824
	global $fulltext_search, $convert_row;
f2e824
f2e824
	if (!isset($convert_row['post_id']))
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	if (!$message)
f2e824
	{
f2e824
		if (!isset($convert_row['message']))
f2e824
		{
f2e824
			return;
f2e824
		}
f2e824
f2e824
		$message = $convert_row['message'];
f2e824
	}
f2e824
f2e824
	$title = (isset($convert_row['title'])) ? $convert_row['title'] : '';
f2e824
f2e824
	$fulltext_search->index('post', $convert_row['post_id'], $message, $title, $convert_row['poster_id'], $convert_row['forum_id']);
f2e824
}
f2e824
*/
f2e824
f2e824
function make_unique_filename($filename)
f2e824
{
f2e824
	if (!strlen($filename))
f2e824
	{
f2e824
		$filename = md5(unique_id()) . '.dat';
f2e824
	}
f2e824
	else if ($filename[0] == '.')
f2e824
	{
f2e824
		$filename = md5(unique_id()) . $filename;
f2e824
	}
f2e824
	else if (preg_match('/\.([a-z]+)$/i', $filename, $m))
f2e824
	{
f2e824
		$filename = preg_replace('/\.([a-z]+)$/i', '_' . md5(unique_id()) . '.\1', $filename);
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		$filename .= '_' . md5(unique_id()) . '.dat';
f2e824
	}
f2e824
f2e824
	return $filename;
f2e824
}
f2e824
f2e824
function words_unique(&$words)
f2e824
{
f2e824
	reset($words);
f2e824
	$return_array = array();
f2e824
f2e824
	$word = current($words);
f2e824
	do
f2e824
	{
f2e824
		$return_array[$word] = $word;
f2e824
	}
f2e824
	while ($word = next($words));
f2e824
f2e824
	return $return_array;
f2e824
}
f2e824
f2e824
/**
f2e824
* Adds a user to the specified group and optionally makes them a group leader
f2e824
* This function does not create the group if it does not exist and so should only be called after the groups have been created
f2e824
*/
f2e824
function add_user_group($group_id, $user_id, $group_leader=false)
f2e824
{
f2e824
	global $convert, $phpbb_root_path, $config, $user, $db;
f2e824
f2e824
	$sql = 'INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array(
f2e824
		'group_id'		=> $group_id,
f2e824
		'user_id'		=> $user_id,
f2e824
		'group_leader'	=> ($group_leader) ? 1 : 0,
f2e824
		'user_pending'	=> 0));
f2e824
	$db->sql_query($sql);
f2e824
}
f2e824
f2e824
// STANDALONE FUNCTIONS
f2e824
f2e824
/**
f2e824
* Add users to the pre-defined "special" groups
f2e824
*
f2e824
* @param string $group The name of the special group to add to
f2e824
* @param string $select_query An SQL query to retrieve the user(s) to add to the group
f2e824
*/
f2e824
function user_group_auth($group, $select_query, $use_src_db)
f2e824
{
f2e824
	global $convert, $phpbb_root_path, $config, $user, $db, $src_db, $same_db;
f2e824
f2e824
	if (!in_array($group, array('guests', 'registered', 'registered_coppa', 'global_moderators', 'administrators', 'bots')))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_WRONG_GROUP'], $group, 'user_group_auth()'), __LINE__, __FILE__, true);
f2e824
		return;
f2e824
	}
f2e824
f2e824
	$sql = 'SELECT group_id
f2e824
		FROM ' . GROUPS_TABLE . "
f2e824
		WHERE group_name = '" . $db->sql_escape(strtoupper($group)) . "'";
f2e824
	$result = $db->sql_query($sql);
f2e824
	$group_id = (int) $db->sql_fetchfield('group_id');
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	if (!$group_id)
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_NO_GROUP'], $group, 'user_group_auth()'), __LINE__, __FILE__, true);
f2e824
		return;
f2e824
	}
f2e824
f2e824
	if ($same_db || !$use_src_db)
f2e824
	{
f2e824
		$sql = 'INSERT INTO ' . USER_GROUP_TABLE . ' (user_id, group_id, user_pending)
f2e824
			' . str_replace('{' . strtoupper($group) . '}', $group_id . ', 0', $select_query);
f2e824
		$db->sql_query($sql);
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		$result = $src_db->sql_query(str_replace('{' . strtoupper($group) . '}', $group_id . ' ', $select_query));
f2e824
		while ($row = $src_db->sql_fetchrow($result))
f2e824
		{
f2e824
			// this might become quite a lot of INSERTS unfortunately
f2e824
			$sql = 'INSERT INTO ' . USER_GROUP_TABLE . " (user_id, group_id, user_pending)
f2e824
				VALUES ({$row['user_id']}, $group_id, 0)";
f2e824
			$db->sql_query($sql);
f2e824
		}
f2e824
		$src_db->sql_freeresult($result);
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Retrieves configuration information from the source forum and caches it as an array
f2e824
* Both database and file driven configuration formats can be handled
f2e824
* (the type used is specified in $config_schema, see convert_phpbb20.php for more details)
f2e824
*/
f2e824
function get_config()
f2e824
{
f2e824
	static $convert_config;
f2e824
	global $user;
f2e824
f2e824
	if (isset($convert_config))
f2e824
	{
f2e824
		return $convert_config;
f2e824
	}
f2e824
f2e824
	global $src_db, $same_db, $phpbb_root_path, $config;
f2e824
	global $convert;
f2e824
f2e824
	if ($convert->config_schema['table_format'] != 'file')
f2e824
	{
f2e824
		if ($convert->mysql_convert && $same_db)
f2e824
		{
f2e824
			$src_db->sql_query("SET NAMES 'binary'");
f2e824
		}
f2e824
f2e824
		$sql = 'SELECT * FROM ' . $convert->src_table_prefix . $convert->config_schema['table_name'];
f2e824
		$result = $src_db->sql_query($sql);
f2e824
		$row = $src_db->sql_fetchrow($result);
f2e824
f2e824
		if (!$row)
f2e824
		{
f2e824
			$convert->p_master->error($user->lang['CONV_ERROR_GET_CONFIG'], __LINE__, __FILE__);
f2e824
		}
f2e824
	}
f2e824
f2e824
	if (is_array($convert->config_schema['table_format']))
f2e824
	{
f2e824
		$convert_config = array();
f2e824
		list($key, $val) = each($convert->config_schema['table_format']);
f2e824
f2e824
		do
f2e824
		{
f2e824
			$convert_config[$row[$key]] = $row[$val];
f2e824
		}
f2e824
		while ($row = $src_db->sql_fetchrow($result));
f2e824
		$src_db->sql_freeresult($result);
f2e824
f2e824
		if ($convert->mysql_convert && $same_db)
f2e824
		{
f2e824
			$src_db->sql_query("SET NAMES 'utf8'");
f2e824
		}
f2e824
	}
f2e824
	else if ($convert->config_schema['table_format'] == 'file')
f2e824
	{
f2e824
		$filename = $convert->options['forum_path'] . '/' . $convert->config_schema['filename'];
f2e824
		if (!file_exists($filename))
f2e824
		{
f2e824
			$convert->p_master->error($user->lang['FILE_NOT_FOUND'] . ': ' . $filename, __LINE__, __FILE__);
f2e824
		}
f2e824
f2e824
		$convert_config = extract_variables_from_file($filename);
f2e824
		if (!empty($convert->config_schema['array_name']))
f2e824
		{
f2e824
			$convert_config = $convert_config[$convert->config_schema['array_name']];
f2e824
		}
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		$convert_config = $row;
f2e824
		if ($convert->mysql_convert && $same_db)
f2e824
		{
f2e824
			$src_db->sql_query("SET NAMES 'utf8'");
f2e824
		}
f2e824
	}
f2e824
f2e824
	if (!sizeof($convert_config))
f2e824
	{
f2e824
		$convert->p_master->error($user->lang['CONV_ERROR_CONFIG_EMPTY'], __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	return $convert_config;
f2e824
}
f2e824
f2e824
/**
f2e824
* Transfers the relevant configuration information from the source forum
f2e824
* The mapping of fields is specified in $config_schema, see convert_phpbb20.php for more details
f2e824
*/
f2e824
function restore_config($schema)
f2e824
{
f2e824
	global $db, $config;
f2e824
f2e824
	$convert_config = get_config();
f2e824
	foreach ($schema['settings'] as $config_name => $src)
f2e824
	{
f2e824
		if (preg_match('/(.*)\((.*)\)/', $src, $m))
f2e824
		{
f2e824
			$var = (empty($m[2]) || empty($convert_config[$m[2]])) ? "''" : "'" . addslashes($convert_config[$m[2]]) . "'";
f2e824
			$exec = '$config_value = ' . $m[1] . '(' . $var . ');';
f2e824
			eval($exec);
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$config_value = (isset($convert_config[$src])) ? $convert_config[$src] : '';
f2e824
		}
f2e824
f2e824
		if ($config_value !== '')
f2e824
		{
f2e824
			// Most are...
f2e824
			if (is_string($config_value))
f2e824
			{
f2e824
				$config_value = truncate_string(utf8_htmlspecialchars($config_value), 255, 255, false);
f2e824
			}
f2e824
f2e824
			set_config($config_name, $config_value);
f2e824
		}
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Update the count of PM's in custom folders for all users
f2e824
*/
f2e824
function update_folder_pm_count()
f2e824
{
f2e824
	global $db, $convert, $user;
f2e824
f2e824
	$sql = 'SELECT user_id, folder_id, COUNT(msg_id) as num_messages
f2e824
		FROM ' . PRIVMSGS_TO_TABLE . '
f2e824
		WHERE folder_id NOT IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ', ' . PRIVMSGS_INBOX . ', ' . PRIVMSGS_OUTBOX . ', ' . PRIVMSGS_SENTBOX . ')
f2e824
		GROUP BY folder_id, user_id';
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$db->sql_query('UPDATE ' . PRIVMSGS_FOLDER_TABLE . ' SET pm_count = ' . $row['num_messages'] . '
f2e824
			WHERE user_id = ' . $row['user_id'] . ' AND folder_id = ' . $row['folder_id']);
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
}
f2e824
f2e824
// Functions mainly used by the main convertor script
f2e824
f2e824
function path($path, $path_relative = true)
f2e824
{
f2e824
	if ($path === false)
f2e824
	{
f2e824
		return '';
f2e824
	}
f2e824
f2e824
	if (substr($path, -1) != '/')
f2e824
	{
f2e824
		$path .= '/';
f2e824
	}
f2e824
f2e824
	if (!$path_relative)
f2e824
	{
f2e824
		return $path;
f2e824
	}
f2e824
f2e824
	if (substr($path, 0, 1) == '/')
f2e824
	{
f2e824
		$path = substr($path, 1);
f2e824
	}
f2e824
f2e824
	return $path;
f2e824
}
f2e824
f2e824
/**
f2e824
* Extract the variables defined in a configuration file
f2e824
* @todo As noted by Xore we need to look at this from a security perspective
f2e824
*/
f2e824
function extract_variables_from_file($_filename)
f2e824
{
f2e824
	include($_filename);
f2e824
f2e824
	$vars = get_defined_vars();
f2e824
	unset($vars['_filename']);
f2e824
f2e824
	return $vars;
f2e824
}
f2e824
f2e824
function get_path($src_path, $src_url, $test_file)
f2e824
{
f2e824
	global $config, $phpbb_root_path, $phpEx;
f2e824
f2e824
	$board_config = get_config();
f2e824
f2e824
	$test_file = preg_replace('/\.php$/i', ".$phpEx", $test_file);
f2e824
	$src_path = path($src_path);
f2e824
f2e824
	if (@file_exists($phpbb_root_path . $src_path . $test_file))
f2e824
	{
f2e824
		return $src_path;
f2e824
	}
f2e824
f2e824
	if (!empty($src_url) && !empty($board_config['server_name']))
f2e824
	{
f2e824
		if (!preg_match('#https?://([^/]+)(.*)#i', $src_url, $m))
f2e824
		{
f2e824
			return false;
f2e824
		}
f2e824
f2e824
		if ($m[1] != $board_config['server_name'])
f2e824
		{
f2e824
			return false;
f2e824
		}
f2e824
f2e824
		$url_parts = explode('/', $m[2]);
f2e824
		if (substr($src_url, -1) != '/')
f2e824
		{
f2e824
			if (preg_match('/.*\.([a-z0-9]{3,4})$/i', $url_parts[sizeof($url_parts) - 1]))
f2e824
			{
f2e824
				$url_parts[sizeof($url_parts) - 1] = '';
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$url_parts[] = '';
f2e824
			}
f2e824
		}
f2e824
f2e824
		$script_path = $board_config['script_path'];
f2e824
		if (substr($script_path, -1) == '/')
f2e824
		{
f2e824
			$script_path = substr($script_path, 0, -1);
f2e824
		}
f2e824
f2e824
		$path_array = array();
f2e824
f2e824
		$phpbb_parts = explode('/', $script_path);
f2e824
		for ($i = 0; $i < sizeof($url_parts); ++$i)
f2e824
		{
f2e824
			if ($i < sizeof($phpbb_parts[$i]) && $url_parts[$i] == $phpbb_parts[$i])
f2e824
			{
f2e824
				$path_array[] = $url_parts[$i];
f2e824
				unset($url_parts[$i]);
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$path = '';
f2e824
				for ($j = $i; $j < sizeof($phpbb_parts); ++$j)
f2e824
				{
f2e824
					$path .= '../';
f2e824
				}
f2e824
				$path .= implode('/', $url_parts);
f2e824
				break;
f2e824
			}
f2e824
		}
f2e824
f2e824
		if (!empty($path))
f2e824
		{
f2e824
			if (@file_exists($phpbb_root_path . $path . $test_file))
f2e824
			{
f2e824
				return $path;
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
f2e824
	return false;
f2e824
}
f2e824
f2e824
function compare_table($tables, $tablename, &$prefixes)
f2e824
{
f2e824
	for ($i = 0, $table_size = sizeof($tables); $i < $table_size; ++$i)
f2e824
	{
f2e824
		if (preg_match('/(.*)' . $tables[$i] . '$/', $tablename, $m))
f2e824
		{
f2e824
			if (empty($m[1]))
f2e824
			{
f2e824
				$m[1] = '*';
f2e824
			}
f2e824
f2e824
			if (isset($prefixes[$m[1]]))
f2e824
			{
f2e824
				$prefixes[$m[1]]++;
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$prefixes[$m[1]] = 1;
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Grant permissions to a specified user or group
f2e824
*
f2e824
* @param string $ug_type user|group|user_role|group_role
f2e824
* @param mixed $forum_id forum ids (array|int|0) -> 0 == all forums
f2e824
* @param mixed $ug_id [int] user_id|group_id : [string] usergroup name
f2e824
* @param mixed $acl_list [string] acl entry : [array] acl entries : [string] role entry
f2e824
* @param int $setting ACL_YES|ACL_NO|ACL_NEVER
f2e824
*/
f2e824
function mass_auth($ug_type, $forum_id, $ug_id, $acl_list, $setting = ACL_NO)
f2e824
{
f2e824
	global $db, $convert, $user, $config;
f2e824
	static $acl_option_ids, $group_ids;
f2e824
f2e824
	if (($ug_type == 'group' || $ug_type == 'group_role') && is_string($ug_id))
f2e824
	{
f2e824
		if (!isset($group_ids[$ug_id]))
f2e824
		{
f2e824
			$sql = 'SELECT group_id
f2e824
				FROM ' . GROUPS_TABLE . "
f2e824
				WHERE group_name = '" . $db->sql_escape(strtoupper($ug_id)) . "'";
f2e824
			$result = $db->sql_query_limit($sql, 1);
f2e824
			$id = (int) $db->sql_fetchfield('group_id');
f2e824
			$db->sql_freeresult($result);
f2e824
f2e824
			if (!$id)
f2e824
			{
f2e824
				return;
f2e824
			}
f2e824
f2e824
			$group_ids[$ug_id] = $id;
f2e824
		}
f2e824
f2e824
		$ug_id = (int) $group_ids[$ug_id];
f2e824
	}
f2e824
f2e824
	$table = ($ug_type == 'user' || $ug_type == 'user_role') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;
f2e824
	$id_field = ($ug_type == 'user' || $ug_type == 'user_role') ? 'user_id' : 'group_id';
f2e824
f2e824
	// Role based permissions are the simplest to handle so check for them first
f2e824
	if ($ug_type == 'user_role' || $ug_type == 'group_role')
f2e824
	{
f2e824
		if (is_numeric($forum_id))
f2e824
		{
f2e824
			$sql = 'SELECT role_id
f2e824
				FROM ' . ACL_ROLES_TABLE . "
f2e824
				WHERE role_name = 'ROLE_" . $db->sql_escape($acl_list) . "'";
f2e824
			$result = $db->sql_query_limit($sql, 1);
f2e824
			$row = $db->sql_fetchrow($result);
f2e824
			$db->sql_freeresult($result);
f2e824
f2e824
			// If we have no role id there is something wrong here
f2e824
			if ($row)
f2e824
			{
f2e824
				$sql = "INSERT INTO $table ($id_field, forum_id, auth_role_id) VALUES ($ug_id, $forum_id, " . $row['role_id'] . ')';
f2e824
				$db->sql_query($sql);
f2e824
			}
f2e824
		}
f2e824
f2e824
		return;
f2e824
	}
f2e824
f2e824
	// Build correct parameters
f2e824
	$auth = array();
f2e824
f2e824
	if (!is_array($acl_list))
f2e824
	{
f2e824
		$auth = array($acl_list => $setting);
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		foreach ($acl_list as $auth_option)
f2e824
		{
f2e824
			$auth[$auth_option] = $setting;
f2e824
		}
f2e824
	}
f2e824
	unset($acl_list);
f2e824
f2e824
	if (!is_array($forum_id))
f2e824
	{
f2e824
		$forum_id = array($forum_id);
f2e824
	}
f2e824
f2e824
	// Set any flags as required
f2e824
	foreach ($auth as $auth_option => $acl_setting)
f2e824
	{
f2e824
		$flag = substr($auth_option, 0, strpos($auth_option, '_') + 1);
f2e824
		if (empty($auth[$flag]))
f2e824
		{
f2e824
			$auth[$flag] = $acl_setting;
f2e824
		}
f2e824
	}
f2e824
f2e824
	if (!is_array($acl_option_ids) || empty($acl_option_ids))
f2e824
	{
f2e824
		$sql = 'SELECT auth_option_id, auth_option
f2e824
			FROM ' . ACL_OPTIONS_TABLE;
f2e824
		$result = $db->sql_query($sql);
f2e824
f2e824
		while ($row = $db->sql_fetchrow($result))
f2e824
		{
f2e824
			$acl_option_ids[$row['auth_option']] = $row['auth_option_id'];
f2e824
		}
f2e824
		$db->sql_freeresult($result);
f2e824
	}
f2e824
f2e824
	$sql_forum = 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id), false, true);
f2e824
f2e824
	$sql = ($ug_type == 'user') ? 'SELECT o.auth_option_id, o.auth_option, a.forum_id, a.auth_setting FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . " o WHERE a.auth_option_id = o.auth_option_id $sql_forum AND a.user_id = $ug_id" : 'SELECT o.auth_option_id, o.auth_option, a.forum_id, a.auth_setting FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . " o WHERE a.auth_option_id = o.auth_option_id $sql_forum AND a.group_id = $ug_id";
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	$cur_auth = array();
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$cur_auth[$row['forum_id']][$row['auth_option_id']] = $row['auth_setting'];
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	$sql_ary = array();
f2e824
	foreach ($forum_id as $forum)
f2e824
	{
f2e824
		foreach ($auth as $auth_option => $setting)
f2e824
		{
f2e824
			$auth_option_id = $acl_option_ids[$auth_option];
f2e824
f2e824
			if (!$auth_option_id)
f2e824
			{
f2e824
				continue;
f2e824
			}
f2e824
f2e824
			switch ($setting)
f2e824
			{
f2e824
				case ACL_NO:
f2e824
					if (isset($cur_auth[$forum][$auth_option_id]))
f2e824
					{
f2e824
						$sql_ary['delete'][] = "DELETE FROM $table
f2e824
							WHERE forum_id = $forum
f2e824
								AND auth_option_id = $auth_option_id
f2e824
								AND $id_field = $ug_id";
f2e824
					}
f2e824
				break;
f2e824
f2e824
				default:
f2e824
					if (!isset($cur_auth[$forum][$auth_option_id]))
f2e824
					{
f2e824
						$sql_ary['insert'][] = "$ug_id, $forum, $auth_option_id, $setting";
f2e824
					}
f2e824
					else if ($cur_auth[$forum][$auth_option_id] != $setting)
f2e824
					{
f2e824
						$sql_ary['update'][] = "UPDATE " . $table . "
f2e824
							SET auth_setting = $setting
f2e824
							WHERE $id_field = $ug_id
f2e824
								AND forum_id = $forum
f2e824
								AND auth_option_id = $auth_option_id";
f2e824
					}
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
	unset($cur_auth);
f2e824
f2e824
	$sql = '';
f2e824
	foreach ($sql_ary as $sql_type => $sql_subary)
f2e824
	{
f2e824
		switch ($sql_type)
f2e824
		{
f2e824
			case 'insert':
f2e824
				switch ($db->sql_layer)
f2e824
				{
f2e824
					case 'mysql':
f2e824
					case 'mysql4':
f2e824
						$sql = 'VALUES ' . implode(', ', preg_replace('#^(.*?)$#', '(\1)', $sql_subary));
f2e824
					break;
f2e824
f2e824
					case 'mssql':
f2e824
					case 'sqlite':
f2e824
						$sql = implode(' UNION ALL ', preg_replace('#^(.*?)$#', 'SELECT \1', $sql_subary));
f2e824
					break;
f2e824
f2e824
					default:
f2e824
						foreach ($sql_subary as $sql)
f2e824
						{
f2e824
							$sql = "INSERT INTO $table ($id_field, forum_id, auth_option_id, auth_setting) VALUES ($sql)";
f2e824
							$db->sql_query($sql);
f2e824
							$sql = '';
f2e824
						}
f2e824
				}
f2e824
f2e824
				if ($sql != '')
f2e824
				{
f2e824
					$sql = "INSERT INTO $table ($id_field, forum_id, auth_option_id, auth_setting) $sql";
f2e824
					$db->sql_query($sql);
f2e824
				}
f2e824
			break;
f2e824
f2e824
			case 'update':
f2e824
			case 'delete':
f2e824
				foreach ($sql_subary as $sql)
f2e824
				{
f2e824
					$db->sql_query($sql);
f2e824
					$sql = '';
f2e824
				}
f2e824
			break;
f2e824
		}
f2e824
		unset($sql_ary[$sql_type]);
f2e824
	}
f2e824
	unset($sql_ary);
f2e824
f2e824
}
f2e824
f2e824
/**
f2e824
* Update the count of unread private messages for all users
f2e824
*/
f2e824
function update_unread_count()
f2e824
{
f2e824
	global $db;
f2e824
f2e824
	$sql = 'SELECT user_id, COUNT(msg_id) as num_messages
f2e824
		FROM ' . PRIVMSGS_TO_TABLE . '
f2e824
		WHERE pm_unread = 1
f2e824
			AND folder_id <> ' . PRIVMSGS_OUTBOX . '
f2e824
		GROUP BY user_id';
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_unread_privmsg = ' . $row['num_messages'] . '
f2e824
			WHERE user_id = ' . $row['user_id']);
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
}
f2e824
f2e824
/**
f2e824
* Add any of the pre-defined "special" groups which are missing from the database
f2e824
*/
f2e824
function add_default_groups()
f2e824
{
f2e824
	global $db;
f2e824
f2e824
	$default_groups = array(
f2e824
		'GUESTS'			=> array('', 0, 0),
f2e824
		'REGISTERED'		=> array('', 0, 0),
f2e824
		'REGISTERED_COPPA'	=> array('', 0, 0),
f2e824
		'GLOBAL_MODERATORS'	=> array('00AA00', 1, 0),
f2e824
		'ADMINISTRATORS'	=> array('AA0000', 1, 1),
f2e824
		'BOTS'				=> array('9E8DA7', 0, 0)
f2e824
	);
f2e824
f2e824
	$sql = 'SELECT *
f2e824
		FROM ' . GROUPS_TABLE . '
f2e824
		WHERE ' . $db->sql_in_set('group_name', array_keys($default_groups));
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		unset($default_groups[strtoupper($row['group_name'])]);
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	$sql_ary = array();
f2e824
f2e824
	foreach ($default_groups as $name => $data)
f2e824
	{
f2e824
		$sql_ary[] = array(
f2e824
			'group_name'			=> (string) $name,
f2e824
			'group_desc'			=> '',
f2e824
			'group_desc_uid'		=> '',
f2e824
			'group_desc_bitfield'	=> '',
f2e824
			'group_type'			=> GROUP_SPECIAL,
f2e824
			'group_colour'			=> (string) $data[0],
f2e824
			'group_legend'			=> (int) $data[1],
f2e824
			'group_founder_manage'	=> (int) $data[2]
f2e824
		);
f2e824
	}
f2e824
f2e824
	if (sizeof($sql_ary))
f2e824
	{
f2e824
		$db->sql_multi_insert(GROUPS_TABLE, $sql_ary);
f2e824
	}
f2e824
}
f2e824
f2e824
f2e824
/**
f2e824
* Sync post count. We might need to do this in batches.
f2e824
*/
f2e824
function sync_post_count($offset, $limit)
f2e824
{
f2e824
	global $db;
f2e824
	$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
f2e824
			FROM ' . POSTS_TABLE . '
f2e824
			WHERE post_postcount = 1
f2e824
				AND post_approved = 1
f2e824
			GROUP BY poster_id
f2e824
			ORDER BY poster_id';
f2e824
	$result = $db->sql_query_limit($sql, $limit, $offset);
f2e824
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['poster_id']}");
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
}
f2e824
f2e824
/**
f2e824
* Add the search bots into the database
f2e824
* This code should be used in execute_last if the source database did not have bots
f2e824
* If you are converting bots this function should not be called
f2e824
* @todo We might want to look at sharing the bot list between the install code and this code for consistancy
f2e824
*/
f2e824
function add_bots()
f2e824
{
f2e824
	global $db, $convert, $user, $config, $phpbb_root_path, $phpEx;
f2e824
f2e824
	$db->sql_query($convert->truncate_statement . BOTS_TABLE);
f2e824
f2e824
	$sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = 'BOTS'";
f2e824
	$result = $db->sql_query($sql);
f2e824
	$group_id = (int) $db->sql_fetchfield('group_id', false, $result);
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	if (!$group_id)
f2e824
	{
f2e824
		add_default_groups();
f2e824
f2e824
		$sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = 'BOTS'";
f2e824
		$result = $db->sql_query($sql);
f2e824
		$group_id = (int) $db->sql_fetchfield('group_id', false, $result);
f2e824
		$db->sql_freeresult($result);
f2e824
f2e824
		if (!$group_id)
f2e824
		{
f2e824
			global $install;
f2e824
			$install->error($user->lang['CONV_ERROR_INCONSISTENT_GROUPS'], __LINE__, __FILE__);
f2e824
		}
f2e824
	}
f2e824
f2e824
	$bots = array(
f2e824
		'AdsBot [Google]'			=> array('AdsBot-Google', ''),
f2e824
		'Alexa [Bot]'				=> array('ia_archiver', ''),
f2e824
		'Alta Vista [Bot]'			=> array('Scooter/', ''),
f2e824
		'Ask Jeeves [Bot]'			=> array('Ask Jeeves', ''),
f2e824
		'Baidu [Spider]'			=> array('Baiduspider+(', ''),
f2e824
		'Exabot [Bot]'				=> array('Exabot/', ''),
f2e824
		'FAST Enterprise [Crawler]'	=> array('FAST Enterprise Crawler', ''),
f2e824
		'FAST WebCrawler [Crawler]'	=> array('FAST-WebCrawler/', ''),
f2e824
		'Francis [Bot]'				=> array('http://www.neomo.de/', ''),
f2e824
		'Gigabot [Bot]'				=> array('Gigabot/', ''),
f2e824
		'Google Adsense [Bot]'		=> array('Mediapartners-Google', ''),
f2e824
		'Google Desktop'			=> array('Google Desktop', ''),
f2e824
		'Google Feedfetcher'		=> array('Feedfetcher-Google', ''),
f2e824
		'Google [Bot]'				=> array('Googlebot', ''),
f2e824
		'Heise IT-Markt [Crawler]'	=> array('heise-IT-Markt-Crawler', ''),
f2e824
		'Heritrix [Crawler]'		=> array('heritrix/1.', ''),
f2e824
		'IBM Research [Bot]'		=> array('ibm.com/cs/crawler', ''),
f2e824
		'ICCrawler - ICjobs'		=> array('ICCrawler - ICjobs', ''),
f2e824
		'ichiro [Crawler]'			=> array('ichiro/2', ''),
f2e824
		'Majestic-12 [Bot]'			=> array('MJ12bot/', ''),
f2e824
		'Metager [Bot]'				=> array('MetagerBot/', ''),
f2e824
		'MSN NewsBlogs'				=> array('msnbot-NewsBlogs/', ''),
f2e824
		'MSN [Bot]'					=> array('msnbot/', ''),
f2e824
		'MSNbot Media'				=> array('msnbot-media/', ''),
f2e824
		'NG-Search [Bot]'			=> array('NG-Search/', ''),
f2e824
		'Nutch [Bot]'				=> array('http://lucene.apache.org/nutch/', ''),
f2e824
		'Nutch/CVS [Bot]'			=> array('NutchCVS/', ''),
f2e824
		'OmniExplorer [Bot]'		=> array('OmniExplorer_Bot/', ''),
f2e824
		'Online link [Validator]'	=> array('online link validator', ''),
f2e824
		'psbot [Picsearch]'			=> array('psbot/0', ''),
f2e824
		'Seekport [Bot]'			=> array('Seekbot/', ''),
f2e824
		'Sensis [Crawler]'			=> array('Sensis Web Crawler', ''),
f2e824
		'SEO Crawler'				=> array('SEO search Crawler/', ''),
f2e824
		'Seoma [Crawler]'			=> array('Seoma [SEO Crawler]', ''),
f2e824
		'SEOSearch [Crawler]'		=> array('SEOsearch/', ''),
f2e824
		'Snappy [Bot]'				=> array('Snappy/1.1 ( http://www.urltrends.com/ )', ''),
f2e824
		'Steeler [Crawler]'			=> array('http://www.tkl.iis.u-tokyo.ac.jp/~crawler/', ''),
f2e824
		'Synoo [Bot]'				=> array('SynooBot/', ''),
f2e824
		'Telekom [Bot]'				=> array('crawleradmin.t-info@telekom.de', ''),
f2e824
		'TurnitinBot [Bot]'			=> array('TurnitinBot/', ''),
f2e824
		'Voyager [Bot]'				=> array('voyager/1.0', ''),
f2e824
		'W3 [Sitesearch]'			=> array('W3 SiteSearch Crawler', ''),
f2e824
		'W3C [Linkcheck]'			=> array('W3C-checklink/', ''),
f2e824
		'W3C [Validator]'			=> array('W3C_*Validator', ''),
f2e824
		'WiseNut [Bot]'				=> array('http://www.WISEnutbot.com', ''),
f2e824
		'YaCy [Bot]'				=> array('yacybot', ''),
f2e824
		'Yahoo MMCrawler [Bot]'		=> array('Yahoo-MMCrawler/', ''),
f2e824
		'Yahoo Slurp [Bot]'			=> array('Yahoo! DE Slurp', ''),
f2e824
		'Yahoo [Bot]'				=> array('Yahoo! Slurp', ''),
f2e824
		'YahooSeeker [Bot]'			=> array('YahooSeeker/', ''),
f2e824
	);
f2e824
f2e824
	if (!function_exists('user_add'))
f2e824
	{
f2e824
		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
f2e824
	}
f2e824
f2e824
	foreach ($bots as $bot_name => $bot_ary)
f2e824
	{
f2e824
		$user_row = array(
f2e824
			'user_type'				=> USER_IGNORE,
f2e824
			'group_id'				=> $group_id,
f2e824
			'username'				=> $bot_name,
f2e824
			'user_regdate'			=> time(),
f2e824
			'user_password'			=> '',
f2e824
			'user_colour'			=> '9E8DA7',
f2e824
			'user_email'			=> '',
f2e824
			'user_lang'				=> $config['default_lang'],
f2e824
			'user_style'			=> 1,
f2e824
			'user_timezone'			=> 0,
f2e824
			'user_allow_massemail'	=> 0,
f2e824
		);
f2e824
f2e824
		$user_id = user_add($user_row);
f2e824
f2e824
		if ($user_id)
f2e824
		{
f2e824
			$sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
f2e824
				'bot_active'	=> 1,
f2e824
				'bot_name'		=> $bot_name,
f2e824
				'user_id'		=> $user_id,
f2e824
				'bot_agent'		=> $bot_ary[0],
f2e824
				'bot_ip'		=> $bot_ary[1])
f2e824
			);
f2e824
			$db->sql_query($sql);
f2e824
		}
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Update any dynamic configuration variables after the conversion is finished
f2e824
* @todo Confirm that this updates all relevant values since it has not necessarily been kept in sync with all changes
f2e824
*/
f2e824
function update_dynamic_config()
f2e824
{
f2e824
	global $db, $config;
f2e824
f2e824
	// Get latest username
f2e824
	$sql = 'SELECT user_id, username, user_colour
f2e824
		FROM ' . USERS_TABLE . '
f2e824
		WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
f2e824
f2e824
	if (!empty($config['increment_user_id']))
f2e824
	{
f2e824
		$sql .= ' AND user_id <> ' . $config['increment_user_id'];
f2e824
	}
f2e824
f2e824
	$sql .= ' ORDER BY user_id DESC';
f2e824
f2e824
	$result = $db->sql_query_limit($sql, 1);
f2e824
	$row = $db->sql_fetchrow($result);
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	if ($row)
f2e824
	{
f2e824
		set_config('newest_user_id', $row['user_id'], true);
f2e824
		set_config('newest_username', $row['username'], true);
f2e824
		set_config('newest_user_colour', $row['user_colour'], true);
f2e824
	}
f2e824
f2e824
//	Also do not reset record online user/date. There will be old data or the fresh data from the schema.
f2e824
//	set_config('record_online_users', 1, true);
f2e824
//	set_config('record_online_date', time(), true);
f2e824
f2e824
	$sql = 'SELECT COUNT(post_id) AS stat
f2e824
		FROM ' . POSTS_TABLE . '
f2e824
		WHERE post_approved = 1';
f2e824
	$result = $db->sql_query($sql);
f2e824
	$row = $db->sql_fetchrow($result);
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	set_config('num_posts', (int) $row['stat'], true);
f2e824
f2e824
	$sql = 'SELECT COUNT(topic_id) AS stat
f2e824
		FROM ' . TOPICS_TABLE . '
f2e824
		WHERE topic_approved = 1';
f2e824
	$result = $db->sql_query($sql);
f2e824
	$row = $db->sql_fetchrow($result);
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	set_config('num_topics', (int) $row['stat'], true);
f2e824
f2e824
	$sql = 'SELECT COUNT(user_id) AS stat
f2e824
		FROM ' . USERS_TABLE . '
f2e824
		WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
f2e824
	$result = $db->sql_query($sql);
f2e824
	$row = $db->sql_fetchrow($result);
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	set_config('num_users', (int) $row['stat'], true);
f2e824
f2e824
	$sql = 'SELECT COUNT(attach_id) as stat
f2e824
		FROM ' . ATTACHMENTS_TABLE . '
f2e824
		WHERE is_orphan = 0';
f2e824
	$result = $db->sql_query($sql);
f2e824
	set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	$sql = 'SELECT SUM(filesize) as stat
f2e824
		FROM ' . ATTACHMENTS_TABLE . '
f2e824
		WHERE is_orphan = 0';
f2e824
	$result = $db->sql_query($sql);
f2e824
	set_config('upload_dir_size', (float) $db->sql_fetchfield('stat'), true);
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	/**
f2e824
	* We do not resync users post counts - this can be done by the admin after conversion if wanted.
f2e824
	$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
f2e824
		FROM ' . POSTS_TABLE . '
f2e824
		WHERE post_postcount = 1
f2e824
		GROUP BY poster_id';
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['poster_id']}");
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
	*/
f2e824
}
f2e824
f2e824
/**
f2e824
* Updates topics_posted entries
f2e824
*/
f2e824
function update_topics_posted()
f2e824
{
f2e824
	global $db, $config;
f2e824
f2e824
	switch ($db->sql_layer)
f2e824
	{
f2e824
		case 'sqlite':
f2e824
		case 'firebird':
f2e824
			$db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
f2e824
		break;
f2e824
f2e824
		default:
f2e824
			$db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
f2e824
		break;
f2e824
	}
f2e824
f2e824
	// This can get really nasty... therefore we only do the last six months
f2e824
	$get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
f2e824
f2e824
	// Select forum ids, do not include categories
f2e824
	$sql = 'SELECT forum_id
f2e824
		FROM ' . FORUMS_TABLE . '
f2e824
		WHERE forum_type <> ' . FORUM_CAT;
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	$forum_ids = array();
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$forum_ids[] = $row['forum_id'];
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	// Any global announcements? ;)
f2e824
	$forum_ids[] = 0;
f2e824
f2e824
	// Now go through the forums and get us some topics...
f2e824
	foreach ($forum_ids as $forum_id)
f2e824
	{
f2e824
		$sql = 'SELECT p.poster_id, p.topic_id
f2e824
			FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
f2e824
			WHERE t.forum_id = ' . $forum_id . '
f2e824
				AND t.topic_moved_id = 0
f2e824
				AND t.topic_last_post_time > ' . $get_from_time . '
f2e824
				AND t.topic_id = p.topic_id
f2e824
				AND p.poster_id <> ' . ANONYMOUS . '
f2e824
			GROUP BY p.poster_id, p.topic_id';
f2e824
		$result = $db->sql_query($sql);
f2e824
f2e824
		$posted = array();
f2e824
		while ($row = $db->sql_fetchrow($result))
f2e824
		{
f2e824
			$posted[$row['poster_id']][] = $row['topic_id'];
f2e824
		}
f2e824
		$db->sql_freeresult($result);
f2e824
f2e824
		$sql_ary = array();
f2e824
		foreach ($posted as $user_id => $topic_row)
f2e824
		{
f2e824
			foreach ($topic_row as $topic_id)
f2e824
			{
f2e824
				$sql_ary[] = array(
f2e824
					'user_id'		=> (int) $user_id,
f2e824
					'topic_id'		=> (int) $topic_id,
f2e824
					'topic_posted'	=> 1,
f2e824
				);
f2e824
			}
f2e824
		}
f2e824
		unset($posted);
f2e824
f2e824
		if (sizeof($sql_ary))
f2e824
		{
f2e824
			$db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
f2e824
		}
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* Ensure that all users have a default group specified and update related information such as their colour
f2e824
*/
f2e824
function fix_empty_primary_groups()
f2e824
{
f2e824
	global $db;
f2e824
f2e824
	// Set group ids for users not already having it
f2e824
	$sql = 'UPDATE ' . USERS_TABLE . ' SET group_id = ' . get_group_id('registered') . '
f2e824
		WHERE group_id = 0 AND user_type = ' . USER_INACTIVE;
f2e824
	$db->sql_query($sql);
f2e824
f2e824
	$sql = 'UPDATE ' . USERS_TABLE . ' SET group_id = ' . get_group_id('registered') . '
f2e824
		WHERE group_id = 0 AND user_type = ' . USER_NORMAL;
f2e824
	$db->sql_query($sql);
f2e824
f2e824
	$db->sql_query('UPDATE ' . USERS_TABLE . ' SET group_id = ' . get_group_id('guests') . ' WHERE user_id = ' . ANONYMOUS);
f2e824
f2e824
	$sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . ' WHERE group_id = ' . get_group_id('administrators');
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	$user_ids = array();
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$user_ids[] = $row['user_id'];
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	if (sizeof($user_ids))
f2e824
	{
f2e824
		$db->sql_query('UPDATE ' . USERS_TABLE . ' SET group_id = ' . get_group_id('administrators') . '
f2e824
			WHERE group_id = 0 AND ' . $db->sql_in_set('user_id', $user_ids));
f2e824
	}
f2e824
f2e824
	$sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . ' WHERE group_id = ' . get_group_id('global_moderators');
f2e824
f2e824
	$user_ids = array();
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$user_ids[] = $row['user_id'];
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	if (sizeof($user_ids))
f2e824
	{
f2e824
		$db->sql_query('UPDATE ' . USERS_TABLE . ' SET group_id = ' . get_group_id('global_moderators') . '
f2e824
			WHERE group_id = 0 AND ' . $db->sql_in_set('user_id', $user_ids));
f2e824
	}
f2e824
f2e824
	// Set user colour
f2e824
	$sql = 'SELECT group_id, group_colour FROM ' . GROUPS_TABLE . "
f2e824
		WHERE group_colour <> ''";
f2e824
	$result = $db->sql_query($sql);
f2e824
f2e824
	while ($row = $db->sql_fetchrow($result))
f2e824
	{
f2e824
		$db->sql_query('UPDATE ' . USERS_TABLE . " SET user_colour = '{$row['group_colour']}' WHERE group_id = {$row['group_id']}");
f2e824
	}
f2e824
	$db->sql_freeresult($result);
f2e824
}
f2e824
f2e824
/**
f2e824
* Cleanly remove invalid user entries after converting the users table...
f2e824
*/
f2e824
function remove_invalid_users()
f2e824
{
f2e824
	global $convert, $db, $phpEx, $phpbb_root_path;
f2e824
f2e824
	// username_clean is UNIQUE
f2e824
	$sql = 'SELECT user_id
f2e824
		FROM ' . USERS_TABLE . "
f2e824
		WHERE username_clean = ''";
f2e824
	$result = $db->sql_query($sql);
f2e824
	$row = $db->sql_fetchrow($result);
f2e824
	$db->sql_freeresult($result);
f2e824
f2e824
	if ($row)
f2e824
	{
f2e824
		if (!function_exists('user_delete'))
f2e824
		{
f2e824
			include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
f2e824
		}
f2e824
f2e824
		user_delete('remove', $row['user_id']);
f2e824
	}
f2e824
}
f2e824
f2e824
function convert_bbcode($message, $convert_size = true, $extended_bbcodes = false)
f2e824
{
f2e824
	static $orig, $repl, $origx, $replx, $str_from, $str_to;
f2e824
f2e824
	if (empty($orig))
f2e824
	{
f2e824
		$orig = $repl = array();
f2e824
f2e824
		$orig[] = '#\[(php|sql)\](.*?)\[/(php|sql)\]#is';
f2e824
		$repl[] = '[code]\2[/code]';
f2e824
f2e824
		$orig[] = '#\[font=[^\]]+\](.*?)\[/font\]#is';
f2e824
		$repl[] = '\1';
f2e824
f2e824
		$orig[] = '#\[align=[a-z]+\](.*?)\[/align\]#is';
f2e824
		$repl[] = '\1';
f2e824
f2e824
		$orig[] = '#\[/list=.*?\]#is';
f2e824
		$repl[] = '[/list]';
f2e824
f2e824
		$origx = array(
f2e824
			'#\[glow[^\]]+\](.*?)\[/glow\]#is',
f2e824
			'#\[shadow[^\]]+\](.*?)\[/shadow\]#is',
f2e824
			'#\[flash[^\]]+\](.*?)\[/flash\]#is'
f2e824
		);
f2e824
f2e824
		$replx = array(
f2e824
			'\1',
f2e824
			'\1',
f2e824
			'[url=\1]Flash[/url]'
f2e824
		);
f2e824
f2e824
		$str_from = array(
f2e824
			'[ftp]',	'[/ftp]',
f2e824
			'[ftp=',	'[/ftp]',
f2e824
			'[pre]',	'[/pre]',
f2e824
			'[table]',	'[/table]',
f2e824
			'[td]',		'[/td]',
f2e824
			'[tr]',		'[/tr]',
f2e824
			'[s]',		'[/s]',
f2e824
			'[left]',	'[/left]',
f2e824
			'[right]',	'[/right]',
f2e824
			'[center]',	'[/center]',
f2e824
			'[sub]',	'[/sub]',
f2e824
			'[sup]',	'[/sup]',
f2e824
			'[tt]',		'[/tt]',
f2e824
			'[move]',	'[/move]',
f2e824
			'[hr]'
f2e824
		);
f2e824
f2e824
		$str_to = array(
f2e824
			'[url]',	'[/url]',
f2e824
			'[url=',	'[/url]',
f2e824
			'[code]',	'[/code]',
f2e824
			"\n",		'',
f2e824
			'',			'',
f2e824
			"\n",		'',
f2e824
			'',			'',
f2e824
			'',			'',
f2e824
			'',			'',
f2e824
			'',			'',
f2e824
			'',			'',
f2e824
			'',			'',
f2e824
			'',			'',
f2e824
			'',			'',
f2e824
			"\n\n"
f2e824
		);
f2e824
f2e824
		for ($i = 0; $i < sizeof($str_from); ++$i)
f2e824
		{
f2e824
			$origx[] = '#\\' . str_replace(']', '\\]', $str_from[$i]) . '#is';
f2e824
			$replx[] = $str_to[$i];
f2e824
		}
f2e824
	}
f2e824
f2e824
	if (preg_match_all('#\[email=([^\]]+)\](.*?)\[/email\]#i', $message, $m))
f2e824
	{
f2e824
		for ($i = 0; $i < sizeof($m[1]); ++$i)
f2e824
		{
f2e824
			if ($m[1][$i] == $m[2][$i])
f2e824
			{
f2e824
				$message = str_replace($m[0][$i], '[email]' . $m[1][$i] . '[/email]', $message);
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$message = str_replace($m[0][$i], $m[2][$i] . ' ([email]' . $m[1][$i] . '[/email])', $message);
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
f2e824
	if ($convert_size && preg_match('#\[size=[0-9]+\].*?\[/size\]#i', $message))
f2e824
	{
f2e824
		$size = array(9, 9, 12, 15, 18, 24, 29, 29, 29, 29);
f2e824
		$message = preg_replace('#\[size=([0-9]+)\](.*?)\[/size\]#i', '[size=\1]\2[/size]', $message);
f2e824
		$message = preg_replace('#\[size=[0-9]{2,}\](.*?)\[/size\]#i', '[size=29]\1[/size]', $message);
f2e824
f2e824
		for ($i = sizeof($size); $i; )
f2e824
		{
f2e824
			$i--;
f2e824
			$message = str_replace('[size=' . $i . ']', '[size=' . $size[$i] . ']', $message);
f2e824
		}
f2e824
	}
f2e824
f2e824
	if ($extended_bbcodes)
f2e824
	{
f2e824
		$message = preg_replace($origx, $replx, $message);
f2e824
	}
f2e824
f2e824
	$message = preg_replace($orig, $repl, $message);
f2e824
	return $message;
f2e824
}
f2e824
f2e824
f2e824
function copy_file($src, $trg, $overwrite = false, $die_on_failure = true, $source_relative_path = true)
f2e824
{
f2e824
	global $convert, $phpbb_root_path, $config, $user, $db;
f2e824
f2e824
	if (substr($trg, -1) == '/')
f2e824
	{
f2e824
		$trg .= basename($src);
f2e824
	}
f2e824
	$src_path = relative_base($src, $source_relative_path, __LINE__, __FILE__);
f2e824
	$trg_path = $trg;
f2e824
f2e824
	if (!$overwrite && @file_exists($trg_path))
f2e824
	{
f2e824
		return true;
f2e824
	}
f2e824
f2e824
	if (!@file_exists($src_path))
f2e824
	{
f2e824
		return;
f2e824
	}
f2e824
f2e824
	$path = $phpbb_root_path;
f2e824
	$parts = explode('/', $trg);
f2e824
	unset($parts[sizeof($parts) - 1]);
f2e824
f2e824
	for ($i = 0; $i < sizeof($parts); ++$i)
f2e824
	{
f2e824
		$path .= $parts[$i] . '/';
f2e824
f2e824
		if (!is_dir($path))
f2e824
		{
f2e824
			@mkdir($path, 0777);
f2e824
		}
f2e824
	}
f2e824
f2e824
	if (!is_writable($path))
f2e824
	{
f2e824
		@chmod($path, 0777);
f2e824
	}
f2e824
f2e824
	if (!@copy($src_path, $phpbb_root_path . $trg_path))
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['COULD_NOT_COPY'], $src_path, $phpbb_root_path . $trg_path), __LINE__, __FILE__, !$die_on_failure);
f2e824
		return;
f2e824
	}
f2e824
f2e824
	if ($perm = @fileperms($src_path))
f2e824
	{
f2e824
		@chmod($phpbb_root_path . $trg_path, $perm);
f2e824
	}
f2e824
f2e824
	return true;
f2e824
}
f2e824
f2e824
function copy_dir($src, $trg, $copy_subdirs = true, $overwrite = false, $die_on_failure = true, $source_relative_path = true)
f2e824
{
f2e824
	global $convert, $phpbb_root_path, $config, $user, $db;
f2e824
f2e824
	$dirlist = $filelist = $bad_dirs = array();
f2e824
	$src = path($src, $source_relative_path);
f2e824
	$trg = path($trg);
f2e824
	$src_path = relative_base($src, $source_relative_path, __LINE__, __FILE__);
f2e824
	$trg_path = $phpbb_root_path . $trg;
f2e824
f2e824
	if (!is_dir($trg_path))
f2e824
	{
f2e824
		@mkdir($trg_path, 0777);
f2e824
		@chmod($trg_path, 0777);
f2e824
	}
f2e824
f2e824
	if (!@is_writable($trg_path))
f2e824
	{
f2e824
		$bad_dirs[] = path($config['script_path']) . $trg;
f2e824
	}
f2e824
f2e824
	if ($handle = @opendir($src_path))
f2e824
	{
f2e824
		while ($entry = readdir($handle))
f2e824
		{
f2e824
			if ($entry[0] == '.' || $entry == 'CVS' || $entry == 'index.htm')
f2e824
			{
f2e824
				continue;
f2e824
			}
f2e824
f2e824
			if (is_dir($src_path . $entry))
f2e824
			{
f2e824
				$dirlist[] = $entry;
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$filelist[] = $entry;
f2e824
			}
f2e824
		}
f2e824
		closedir($handle);
f2e824
	}
f2e824
	else if ($dir = @dir($src_path))
f2e824
	{
f2e824
		while ($entry = $dir->read())
f2e824
		{
f2e824
			if ($entry[0] == '.' || $entry == 'CVS' || $entry == 'index.htm')
f2e824
			{
f2e824
				continue;
f2e824
			}
f2e824
f2e824
			if (is_dir($src_path . $entry))
f2e824
			{
f2e824
				$dirlist[] = $entry;
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$filelist[] = $entry;
f2e824
			}
f2e824
		}
f2e824
		$dir->close();
f2e824
	}
f2e824
	else
f2e824
	{
f2e824
		$convert->p_master->error(sprintf($user->lang['CONV_ERROR_COULD_NOT_READ'], relative_base($src, $source_relative_path)), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	if ($copy_subdirs)
f2e824
	{
f2e824
		for ($i = 0; $i < sizeof($dirlist); ++$i)
f2e824
		{
f2e824
			$dir = $dirlist[$i];
f2e824
f2e824
			if ($dir == 'CVS')
f2e824
			{
f2e824
				continue;
f2e824
			}
f2e824
f2e824
			if (!is_dir($trg_path . $dir))
f2e824
			{
f2e824
				@mkdir($trg_path . $dir, 0777);
f2e824
				@chmod($trg_path . $dir, 0777);
f2e824
			}
f2e824
f2e824
			if (!@is_writable($trg_path . $dir))
f2e824
			{
f2e824
				$bad_dirs[] = $trg . $dir;
f2e824
				$bad_dirs[] = $trg_path . $dir;
f2e824
			}
f2e824
f2e824
			if (!sizeof($bad_dirs))
f2e824
			{
f2e824
				copy_dir($src . $dir, $trg . $dir, true, $overwrite, $die_on_failure, $source_relative_path);
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
f2e824
	if (sizeof($bad_dirs))
f2e824
	{
f2e824
		$str = (sizeof($bad_dirs) == 1) ? $user->lang['MAKE_FOLDER_WRITABLE'] : $user->lang['MAKE_FOLDERS_WRITABLE'];
f2e824
		sort($bad_dirs);
f2e824
		$convert->p_master->error(sprintf($str, implode('
', $bad_dirs)), __LINE__, __FILE__);
f2e824
	}
f2e824
f2e824
	for ($i = 0; $i < sizeof($filelist); ++$i)
f2e824
	{
f2e824
		copy_file($src . $filelist[$i], $trg . $filelist[$i], $overwrite, $die_on_failure, $source_relative_path);
f2e824
	}
f2e824
}
f2e824
f2e824
function relative_base($path, $is_relative = true, $line = false, $file = false)
f2e824
{
f2e824
	global $convert, $phpbb_root_path, $config, $user, $db;
f2e824
f2e824
	if (!$is_relative)
f2e824
	{
f2e824
		return $path;
f2e824
	}
f2e824
f2e824
	if (empty($convert->options['forum_path']) && $is_relative)
f2e824
	{
f2e824
		$line = $line ? $line : __LINE__;
f2e824
		$file = $file ? $file : __FILE__;
f2e824
f2e824
		$convert->p_master->error($user->lang['CONV_ERROR_NO_FORUM_PATH'], $line, $file);
f2e824
	}
f2e824
f2e824
	return $convert->options['forum_path'] . '/' . $path;
f2e824
}
f2e824
f2e824
function get_smiley_display()
f2e824
{
f2e824
	static $smiley_count = 0;
f2e824
	$smiley_count++;
f2e824
	return ($smiley_count < 50) ? 1 : 0;
f2e824
}
f2e824
f2e824
f2e824
function fill_dateformat($user_dateformat)
f2e824
{
f2e824
	global $config;
f2e824
f2e824
	return ((empty($user_dateformat)) ? $config['default_dateformat'] : $user_dateformat);
f2e824
}
f2e824
f2e824
f2e824
f2e824
?>