<?php
/*******************************************************************
 * 总入口
 * Date 2012-3-5
 *******************************************************************/
//固件方案专属站点，禁止直接访问域名
//return '';
error_reporting(E_ERROR);
ini_set("arg_seperator.output", "&amp;");
ini_set("magic_quotes_runtime", 0);

$time_start = microtime_float();

define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());


define('SUNCAM_CITY_INDEX',true);
require_once 'define.php';

class initialize
{


	function init()
	{
		
		$config=array();
		require(ROOT_PATH . 'setting/settings.php');
		@header('Content-Type: text/html; charset=' . $config['charset']);
		@header('P3P: CP="CAO PSA OUR"');

		/*if($config['install_lock_time'] < 1)
		{
			//判断是否安装
			if (!is_file(ROOT_PATH . 'install/install.lock') && is_file(ROOT_PATH . 'install.php'))
			{
				die("<a href='./install.php'>请点此进行系统的安装</a>");
			}
		}*/
		
		if ($config['upgrade_lock_time'] > 0)
		{
			if(($config['upgrade_lock_time'] + 600 > time()) || (is_file(ROOT_PATH . 'cache/upgrade.lock') && @filemtime(ROOT_PATH . 'cache/upgrade.lock')+600>time()))
			{
				die('系统升级中，请稍候……');
			}
		}

		if ($config['site_closed'])
		{
			if ('login'!=$_GET['mod'] && $site_enable_msg=file_get_contents('./cache/site_enable.php'))
			{
				die($site_enable_msg);
			}
		}

		require(ROOT_PATH . 'setting/constants.php');

		if ($config['rewrite_enable'])
		{
			include(ROOT_PATH . 'include/rewrite.php');
		}
		//设置机器人
		if($config['robot_enable'])
		{
			include(ROOT_PATH . 'setting/robot.php');
		}
		//设置广告
		if($config['ad_enable'])
		{
			include(ROOT_PATH . 'setting/ad.php');
		}
		//设置金币
		if ($config['extcredits_enable'])
		{
		//	include(ROOT_PATH . 'setting/credits.php');
		}

		require_once(ROOT_PATH . 'include/function/global.func.php');
		
        require_once(ROOT_PATH . 'setting/left_menu.php');
		require_once(ROOT_PATH . 'modules/master.mod.php');

		//$mod_ary = $this->SetEvent($config['default_module']);
		$mod_ary = $this->SetEvent();
		if(strpos($_SERVER['HTTP_HOST'],"open.") === 0){
			define("SITE_DOMAIN",$_SERVER['HTTP_HOST']);
			require_once(ROOT_PATH . 'modules/sysopen/' . $mod_ary . '.mod.php');
		}
		else{
			define("SITE_DOMAIN",$config['site_domain']);
			require_once(ROOT_PATH . 'modules/' . $mod_ary . '.mod.php');
		}
		
		
		
		if($_GET)
		{
			$_GET		= jaddslashes($_GET, 1, TRUE);
		}
		if($_POST)
		{
			$_POST		= jaddslashes($_POST, 1, TRUE);
		}

		set_config_domain($config);
		$moduleobject = new ModuleObject($config);

	}


	function SetEvent($default='index')
	{
		$modss = array(
			'topic'=>1,
			'pm'=>1,
			'login'=>1,
			'member'=>1,
			'profile'=>1,
			'tag'=>1,
			'get_password'=>1,
			'report'=>1,
			'url'=>1,
			'share'=>1,
			'other'=>1,
			'show'=>1,
			'user_tag'=>1,
			'theme'=>1,
			'search'=>1,
			'blacklist'=>1,
			'xwb'=>1,
			'settings'=>1,
			'qqwb'=>1,
		    'qq'=>1,
			'tools' => 1,
			'product'=>1,
			'mystore'=>1,
			'vod_mytv'=>1,
			'vod'=>1,

			'live' => 1,
			'live_view_ch' => 1,
		    'test' => 1,
		    'lottery' => 1,
			'column' => 1,
			'channel' => 1,
			'wx' => 1,
		    'index' => 1,
			'work' => 1,
			'weibofordelphi' => 1,
			'dc' => 1,//开发者中心
			'ueiir' => 1,//UEI码库学习
			'help' => 1,//帮助文档			
		);
		
		$mod = (isset($_POST['mod']) ? $_POST['mod'] : $_GET['mod']);
		if(!isset($modss[$mod]))
		{
			if($mod)
			{
				$_POST['mod_original'] = $_GET['mod_original'] = $mod;
			}

			$mod = ($default ? $default : 'index');
			
		}
		$_POST['mod'] = $_GET['mod'] = $mod;

		define('CURMODULE',$mod);

		Return $mod;
	}
}

ob_start("my_output");
$init=new initialize;

$init->init();
unset($init);
			
ob_end_flush();

function my_output(&$buffer,$mode=5)
{
	$modss = array('share'=>1);

	if(GZIP===true && function_exists('ob_gzhandler') && substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && !isset($modss[$_GET['mod']])) {
		$buffer=ob_gzhandler($buffer,$mode);
	}
	return $buffer;
}

function microtime_float()
{
	list($usec, $sec) = explode(" ", microtime());
	return ((float)$usec + (float)$sec);
}

?>