<?php
// 鎖定讀取INIT的權限
if (!defined('IN_AUTH'))
{
    die('Hacking attempt');
}
// 如果有錯誤訊息則顯示
 error_reporting(E_ALL);
 
// 取得網站根目錄
define('ROOT_PATH', str_replace('includes/init.php', '', str_replace('\\', '/', __FILE__)));

/* 初始化設定 */
@ini_set('memory_limit',          '64M');
@ini_set('display_errors',        1);
/* 依建置環境設定 */
if (DIRECTORY_SEPARATOR == '\\')
{
    @ini_set('include_path', '.;' . ROOT_PATH);
}
else
{
    @ini_set('include_path', '.:' . ROOT_PATH);
}

require(ROOT_PATH . 'config/config.php');
if (PHP_VERSION >= '5.1' && !empty($timezone))
{
    date_default_timezone_set($timezone);
	
}

require(ROOT_PATH . 'includes/lib_main.php');
/* 对用户传入的变量进行转义操作。*/
if (!get_magic_quotes_gpc())
{
    if (!empty($_GET))
    {
        $_GET  = addslashes_deep($_GET);
    }
    if (!empty($_POST))
    {
        $_POST = addslashes_deep($_POST);
    }

    $_COOKIE   = addslashes_deep($_COOKIE);
    $_REQUEST  = addslashes_deep($_REQUEST);
}

/* 载入语言文件 */
if(isset($_GET['lang'])||isset($_COOKIE['GUOPIN_LANG'])){
	if(isset($_GET['lang'])){
		require(ROOT_PATH . 'languages/' . $_GET['lang'] . '.php');
	}else{
		require(ROOT_PATH . 'languages/' . $_COOKIE['GUOPIN_LANG'] . '.php');
	}
	
}else{
	setcookie("GUOPIN_LANG","tw",time()+3600);
	require(ROOT_PATH . 'languages/tw.php');
}

if (!defined('INIT_NO_SMARTY'))
{
	header('Cache-control: private');
	header('Content-type: text/html; charset=UTF-8');

	/* 创建 Smarty 对象。*/
	require(ROOT_PATH . 'libs/Smarty/Smarty.class.php');
	$smarty = new Smarty();

	//$smarty->cache_lifetime = $_CFG['cache_time'];
	$smarty->setTemplateDir(ROOT_PATH . 'template/');
	$smarty->setCacheDir(ROOT_PATH . 'temp/caches');
	$smarty->setCompileDir(ROOT_PATH . 'temp/compiled');
	
	$smarty->assign('css_path', 'template/css');

	//$smarty->assign('category', $category);
	$header = "template/common/header.tpl";
	$footer = "template/common/footer.tpl";
}
?>