<?php
ob_start();
error_reporting(E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE);
@set_magic_quotes_runtime(0);
@ini_set('memory_limit', '512M');
if(PHP_VERSION < '4.1.0') {
	$_GET = &$HTTP_GET_VARS;
	$_POST = &$HTTP_POST_VARS;
	$_COOKIE = &$HTTP_COOKIE_VARS;
	$_SERVER = &$HTTP_SERVER_VARS;
	$_ENV = &$HTTP_ENV_VARS;
	$_FILES = &$HTTP_POST_FILES;
}
$system_start = getSysTime();
define('R_P', dirname(__FILE__));
define('C_P', R_P . '/cache');
define('T_P', R_P . '/templates/');
$channel = $usergroup = $_MODULE = $_SET = array();
include(R_P . '/config/options.php');
include(R_P . '/config/config.php');
define('W_P', $_SET['weburl'].$_SET['webpath']);
define('DEBUG', intval($_SET['debug']) ? true : false);
define('REWRITE', $_SET['rewrite'] ? true : false);
define('AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
define('JSONP', (isset($_GET['jsonp']) && intval($_GET['jsonp'])) ? true : false);
define('CACHE_VERSION', intval($_SET['version']) ? true : false);
define('TABLEPRE', $_SET['tablepre']);
define('QMECMS_CONNECT', 'mysql');
$magic_quote = get_magic_quotes_gpc();
require_once(R_P . '/include/class.db.php');
require_once(R_P . '/include/inc.functions.php');
require_once(R_P . '/include/class.cache_'. $_SET['cache'] .'.php');
if(!@is_file(R_P.'/config/install.lock')) qbase::showmsg("Need to install", "default", "install.php");
if(!@include_once(R_P . '/cache/config/common.php')) qbase::showmsg("Need to refresh the cache", "default", $_SET['admin_path']);
require_once(R_P . '/include/global/global.php');
header("Content-Type: text/html; charset={$_SET['def_charset']}");
if($_SET['ip_banned']){
	$ip_banned_data = array();
	if(false === ($ip_banned_data = cache::get('banned'))){
		$ip_banned_data = qbase::get_object('banned')->cache();
	}
	$ip = qbase::get_ip();
	foreach($ip_banned_data as $ip_area){
		if($ip_area[2] >= $_SERVER['REQUEST_TIME'] && $ip >= $ip_area[0] && $ip <= $ip_area[1]){
			header("HTTP/1.1 403 Forbidden");
			include qbase::template('default/403');
			exit();
		}
	}
}
if(isset($_GET['rewrite'])){
	$rewrite = explode('-',$_GET['rewrite']);
	$len = count($rewrite);
	for($i=0; $i<$len; $i+=2){
		$_GET[$rewrite[$i]] = $rewrite[$i+1];
	}
	unset($_GET['rewrite']);
}
$_GET = qbase::saddslashes($_GET);
$_POST = qbase::saddslashes($_POST);
$_COOKIE = qbase::saddslashes($_COOKIE);
$xml = array('','');
if(AJAX){
	$xml = array("<?xml version=\"1.0\" encoding=\"{$_SET['def_charset']}\"?><root><![CDATA[", "]]></root>");
	header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
	header("Content-Type: text/xml; charset={$_SET['def_charset']}");
}else if(JSONP){
	foreach($_GET as $key=>$val){
		if(substr((string)$key, 0, 6) == '_post_'){
			$_POST[substr((string)$key, 6)] = urldecode($val);
		}
	}
	header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
	header("Content-Type: application/x-javascript; charset={$_SET['def_charset']}");
}
$htmlPageTotal = 0;
$main_domain = qbase::get_domain();
$main_location = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$main_referer = $_SERVER['HTTP_REFERER'];

function getSysTime(){
	$time = explode(' ', microtime());
	return $time[1] + $time[0];
}
?>