<?	
/* Nulled by Wizzywig */

	function is__writable($path) {
		if ($path{strlen($path)-1}=='/')
			return is__writable($path.uniqid(mt_rand()).'.tmp');
		else if (is_dir($path))
			return is__writable($path.'/'.uniqid(mt_rand()).'.tmp');
		$rm = file_exists($path);
		$f = @fopen($path, 'a');
		if ($f===false)
			return false;
		fclose($f);
		if (!$rm)
			unlink($path);
		return true;
	}
	
	function can_load_dll($dll)
	{
		// SQLite2 is a tricky thing, from 5.0.0 it requires PDO; if PDO is not loaded we must state that SQLite is unavailable
		// as the installer doesn't understand that the extension has a prerequisite.
		if ($dll == 'sqlite' && version_compare(PHP_VERSION, '5.0.0', '>=') && !extension_loaded('pdo'))
		{
			return false;
		}
		return ((@ini_get('enable_dl') || strtolower(@ini_get('enable_dl')) == 'on') && (!@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off') && function_exists('dl') && @dl($dll . '.' . PHP_SHLIB_SUFFIX)) ? true : false;
	}
	
	function checkDB() {
		$available_dbms = array(
			'mysql'		=> array(
				'LABEL'			=> 'MySQL',
				'SCHEMA'		=> 'mysql',
				'MODULE'		=> 'mysql',
				'DELIM'			=> ';',
				'COMMENTS'		=> 'remove_remarks',
				'DRIVER'		=> 'mysql',
				'AVAILABLE'		=> true,
				'2.0.x'			=> true,
			)
		);
		
		foreach ($available_dbms as $db_name => $db_ary)
		{
			if ($only_20x_options && !$db_ary['2.0.x'])
			{
				if ($return_unavailable)
				{
					$available_dbms[$db_name]['AVAILABLE'] = false;
				}
				else
				{
					unset($available_dbms[$db_name]);
				}
				continue;
			}

			$dll = $db_ary['MODULE'];

			if (!@extension_loaded($dll))
			{
				if (!can_load_dll($dll))
				{
					if ($return_unavailable)
					{
						$available_dbms[$db_name]['AVAILABLE'] = false;
					}
					else
					{
						unset($available_dbms[$db_name]);
					}
					continue;
				}
			}
			$any_db_support = true;
		}
		
		if ($any_db_support)
			$check = true;
		else
			$check = false;
			
		return $check;
	}
	
	function showNext() {
		return '<div class="clear"></div><br /><input class="button" type="submit" value="Continue to Next Step" />';
	}
	
	function split_sql_file($sql, $delimiter)
	{
		$sql = str_replace("\r" , '', $sql);
		$data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);

		$data = array_map('trim', $data);

		// The empty case
		$end_data = end($data);

		if (empty($end_data))
		{
			unset($data[key($data)]);
		}

		return $data;
	}
	
	function remove_remarks(&$sql)
	{
		$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
	}
	
	function write_config_file()
	{
		if ($_SESSION['version'] == "phpbb")
			$include_data = "require_once dirname(dirname(__FILE__)).\"/config.php\";";
		if ($_SESSION['version'] == "vbulletin")
			$include_data = "require_once dirname(dirname(__FILE__)).\"/includes/config.php\";";
		if ($_SESSION['version'] == "wordpress")
			$include_data = "require_once dirname(dirname(__FILE__)).\"/wp-load.php\";";
		if ($_SESSION['version'] == "buddypress")
			$include_data = "require_once dirname(dirname(__FILE__)).\"/wp-load.php\";";
		if ($_SESSION['version'] == "smf")
			$include_data = "require_once dirname(dirname(__FILE__)).\"/Settings.php\";";
		if ($_SESSION['version'] == "socialengine")
			$include_data = "require_once dirname(dirname(__FILE__)).\"/include/database_config.php\";";
		if ($_SESSION['version'] == "dzoic")
			$include_data = "require_once dirname(dirname(__FILE__)).\"/includes/config/config.inc.php\";";
		if ($_SESSION['version'] == "ipboard")
			$include_data = "require_once dirname(dirname(__FILE__)).\"/conf_global.php\";";
		if ($_SESSION['version'] == "drupal")
			$include_data = "if (empty(\$_COOKIE['ac_drupal_id'])) {
	chdir('./../');
	require_once './includes/bootstrap.inc';
	drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); 
	global \$user;
	setcookie('ac_drupal_id', \$user->uid);
}";
		if ($_SESSION['version'] == "jomsocial")
			$include_data = "define('_JEXEC',1);
define('DS',DIRECTORY_SEPARATOR);
define('JPATH_BASE',dirname(dirname(__FILE__)));
require_once dirname(dirname(__FILE__)).'/includes/defines.php';
require_once dirname(dirname(__FILE__)).'/includes/framework.php';
\$mainframe =& JFactory::getApplication('site');
\$mainframe->initialise();";
		if ($_SESSION['version'] == "standalone")
			$include_data = "";
	
		$stringData = "<?php 
".$include_data." 
define('DB_SERVER','".$_SESSION[db_host]."'); 
define('DB_PORT','".$_SESSION[db_port]."'); 
define('DB_USERNAME','".$_SESSION[db_username]."'); 
define('DB_PASSWORD','".$_SESSION[db_password]."'); 
define('DB_NAME','".$_SESSION[db_name]."'); 
define('TABLE_PREFIX','".$_SESSION[db_prefix]."'); 
define('DB_USERTABLE','".$_SESSION[config_table_user]."'); 
define('DB_USERTABLE_NAME','".$_SESSION[config_field_username]."'); 
define('DB_USERTABLE_USERID','".$_SESSION[config_field_userid]."'); 
define('DB_USERTABLE_AVATAR','".$_SESSION[config_field_avatar]."'); 
define('DB_FRIENDSTABLE','".$_SESSION[config_table_friends]."'); 
define('DB_FRIENDSTABLE_USERID', '".$_SESSION[config_field_friend_userid]."'); 
define('DB_FRIENDSTABLE_FRIENDID', '".$_SESSION[config_field_friendid]."'); 
define('DB_FRIENDSTABLE_FRIENDS', '".$_SESSION[config_field_friend_check]."'); 
include_once dirname(__FILE__).'/version.php';

\$dbh = mysql_connect(DB_SERVER.':'.DB_PORT,DB_USERNAME,DB_PASSWORD); 
if (!\$dbh) { 
	echo \"<h3>Unable to connect to database. Please check details in configuration file.</h3>\"; 
	exit(); 
} 
mysql_selectdb(DB_NAME,\$dbh); 
mysql_query(\"SET NAMES utf8\"); 
mysql_query(\"SET CHARACTER SET utf8\"); 
mysql_query(\"SET COLLATION_CONNECTION = 'utf8_general_ci'\"); 

?>";
				
		$myFile = "../config.php";
		$fh = fopen($myFile, 'w') or die("can't open file");
		fwrite($fh, $stringData);
		fclose($fh);
		
		$stringData = "<?php 

define('DB_SERVER','".$_SESSION[db_host]."'); 
define('DB_PORT','".$_SESSION[db_port]."'); 
define('DB_USERNAME','".$_SESSION[db_username]."'); 
define('DB_PASSWORD','".$_SESSION[db_password]."'); 
define('DB_NAME','".$_SESSION[db_name]."'); 
define('TABLE_PREFIX','".$_SESSION[db_prefix]."'); 
define('DB_USERTABLE','".$_SESSION[config_table_user]."'); 
define('DB_USERTABLE_NAME','".$_SESSION[config_field_username]."'); 
define('DB_USERTABLE_USERID','".$_SESSION[config_field_userid]."'); 
define('DB_USERTABLE_AVATAR','".$_SESSION[config_field_avatar]."'); 
define('DB_FRIENDSTABLE','".$_SESSION[config_table_friends]."'); 
define('DB_FRIENDSTABLE_USERID', '".$_SESSION[config_field_friend_userid]."'); 
define('DB_FRIENDSTABLE_FRIENDID', '".$_SESSION[config_field_friendid]."'); 
define('DB_FRIENDSTABLE_FRIENDS', '".$_SESSION[config_field_friend_check]."');  

\$dbh = mysql_connect(DB_SERVER.':'.DB_PORT,DB_USERNAME,DB_PASSWORD); 
if (!\$dbh) { 
	echo \"<h3>Unable to connect to database. Please check details in configuration file.</h3>\"; 
	exit(); 
} 
mysql_selectdb(DB_NAME,\$dbh); 
mysql_query(\"SET NAMES utf8\"); 
mysql_query(\"SET CHARACTER SET utf8\"); 
mysql_query(\"SET COLLATION_CONNECTION = 'utf8_general_ci'\"); 

?>";

		$myFile = "../cache/config.php";
		$fh = fopen($myFile, 'w') or die("can't open file");
		fwrite($fh, $stringData);
		fclose($fh);
	
	}
	
	function write_cache_file()
	{
	
		$stringData = '<? $theme="new_facebook";$channel_name="'.$_SESSION[config_subdomain].'";$base_url="'.$_SESSION[config_path].'";$online_timeout="30";$disable_long_polling="0";$disable_smilies="0";$auto_popup_chatbox="1";$heart_beat="2";$language="ar";$idle_time="5";$install_time="'.time().'";$chatrooms_on="0";$notifications_on="0";$hide_bar_on="1";$applications_on="0";$popout_chat_on="0";$theme_change_on="0"; $smileys = array(":)" => "smiley",":(" => "smiley-sad",":D" => "smiley-lol",";)" => "smiley-wink",":o" => "smiley-surprise","8)" => "smiley-cool",":|" => "smiley-neutral",":\'(" => "smiley-cry",":p" => "smiley-razz",":s" => "smiley-confuse",":-)" => "smiley",":-(" => "smiley-sad",";-)" => "smiley-wink",":-o" => "smiley-surprise","8-)" => "smiley-cool",":-|" => "smiley-neutral",":-p" => "smiley-razz",":-s" => "smiley-confuse",">:(" => "smiley-mad",); $banlist = array();$trayicon = array();$plugins = array();$apps = array(); ?>';
	
		$myFile = "../cache/data_admin_options.php";
		$fh = fopen($myFile, 'w') or die("can't open file");
		fwrite($fh, $stringData);
		fclose($fh);
	
	}
	
	function write_functions_file()
	{
		$rename = false;
		if (file_exists("../includes/functions_receive_".$_SESSION[version].".php"))
			$rename = rename("../includes/functions_receive_".$_SESSION[version].".php", "../includes/functions_receive.php");
		
		return $rename;
	}
	
	function getFinalInstructions($version) {
	
		switch($version){
		
			case "phpbb":
				return "In phpBB, you can edit the header and footer files by going to the admin panel > styles > templates > Edit your active style > choose overall_footer.html and overall_header.html.";
				break;
				
			case "vbulletin":
				return "In vBulletin, you can edit the header and footer files by going to the admin panel > Styles & Templates > Style Manager > Edit Templates > headerinclude/footer > Customize.";
				break;
			
			case "jomsocial":
				return "In JomSocial, you can edit the header and footer files by going to the admin panel > Extensions > Template Manager > Edit Active Template > Edit HTML.";
				break;
				
			case "wordpress":
				return "In WordPress, you can edit the header and footer files by going to the admin panel > Appearance > Editor > Edit the Header and Footer files of your active theme.";
				break;
				
			case "buddypress":
				return "In BuddyPress, you can edit the header and footer files by going to the admin panel > Appearance > Editor > Edit the Header and Footer files of your active theme.";
				break;
				
			case "dzoic":
				return "In DZOIC, you can edit the header and footer files by going to the following FTP location: themes/{your theme}/templates/source.  Then, edit the header.tpl and footer.tpl files.";
				break;
				
			case "smf":
				return "In Simple Machines Forum, you can edit the header and footer files by going to the following FTP location: themes/{your theme}/.  Then, edit the index.template.php file.  Be sure that you put the code after the &lt;head&gt; tag and before the &lt;/body&gt; tag.  You can do ctrl+F to find these in the file.";
				break;
				
			case "socialengine":
				return "In Social Engine, you can edit the header and footer files by going to the admin panel > HTML Templates > Edit the header_global.tpl and footer.tpl files.";
				break;
				
			case "drupal":
				return "In Drupal, you can edit the header and footer files by going to the admin panel > Look & Feel > Select your active template > Select globalTemplate";
				break;
				
			case "ipboard":
				return "In IP.BOARD, you can edit the header and footer files by going to the admin panel > Look & Feel > Select your active template > Select globalTemplate";
				break;
				
			case "phpnuke":
				return "In PHP-Nuke, you can edit the header and footer files by going to the following FTP location: /php-nuke root/.  Then, edit the header.php and footer.php files.  Be sure that you put the code before the &lt;/head&gt; tag and before the &lt;/body&gt; tag.  You can do ctrl+F to find these in the file.";
				break;
				
			case "phpfox":
				return "In phpFox, you can edit the header and footer files by going to the following admin panel location: Extensions > Theme > Manage Themes > Edit Templates (click arrowchat).  Be sure that you put the code before the &lt;/head&gt; tag and before the &lt;/body&gt; tag.  You can do ctrl+F to find these in the file.<br /><br />You also must disable the phpFox footer bar.  This can be done in the admin panel > Settings > System Settings > Manage Settings > Core.";
				break;
				
			case "standalone":
				return "If you have a header and footer file you can simply add this code to them, otherwise, you will need to add this code to each page you wish ArrowChat to be on.";
				break;
				
		}
	
	}
	
?>