<?php
error_reporting(0);
define('ROOT_PATH',str_replace('\\','/',substr(dirname(__FILE__),0,-3)));
define('IN_PHPUP',1);
$GLOBALS['charset']='utf-8';

require(ROOT_PATH.'/data/config.inc.php');
header("Content-type:text/html;charset=".$GLOBALS['charset']);
require(ROOT_PATH.'/data/config.uc.php');
require(ROOT_PATH.'/inc/mysql.class.php');
require(ROOT_PATH.'/inc/global.func.php');


//初始化数据连接
$db=new mysql();

$db->connect($dbhost,$dbuser,$dbpw,$dbname);

if(!checkfile('setting',0))
{
	$query=$db->query('select variable,content from '.tname('setting'));
	while($rows=$db->fetch_array($query))
	{
		$setting[$rows['variable']]=$rows['content'];
	}
	write('setting',$setting);
}
else
{
	$setting=read('setting');
}

$GLOBALS["setting"]["adminpath"]=!empty($GLOBALS["setting"]["adminpath"])?$GLOBALS["setting"]["adminpath"]:'admin';
$GLOBALS['setting']['site_imgurl']=!empty($GLOBALS['setting']['site_imgurl'])?$GLOBALS['setting']['site_imgurl']:$GLOBALS['setting']['site_url'];
define('SITE_ROOT',$GLOBALS['setting']['site_url']);
define('STATIC_ROOT',$GLOBALS['setting']['site_imgurl']);
define('ADMIN_ROOT',$GLOBALS["setting"]["adminpath"]);
define('REMOTEHOST','http://www.tgwowo.com');

define('TPL_DIR',!empty($GLOBALS['setting']['site_template_dir'])?$GLOBALS['setting']['site_template_dir']:'default4');
require(ROOT_PATH.'/inc/sql.inc.php');
require(ROOT_PATH.'/inc/page.class.php');
define('VERSION','Lht_V4.0.4_110418');
define('LHT_V',"Lht_V4.0.4_110418");
$timezone='Asia/Shanghai';
date_default_timezone_set($timezone);

$mtime = explode(' ', microtime());
$serveru_starttime = $mtime[1] + $mtime[0];
//缓存会员等级
if(!checkfile('user_group',86400))
{
	$query=$db->query('select * from '.tname('user_group'));
	while($rows=$db->fetch_array($query))
	{
		$user_group[$rows['groupkey']]=$rows;
	}
	write('user_group',$user_group);
}
else
{
	$user_group=read('user_group');
}

//缓存插件
if(!checkfile('plugins',86400))
{
	$query=$db->query('select * from '.tname('plugins'));
	while($rows=$db->fetch_array($query))
	{
		$rows['pluginsname']=unserialize($rows['pluginsname']);
		$plugins[$rows['id']]=$rows;
	}
	write('plugins',$plugins);
}
else
{
	$plugins=read('plugins');
}
//缓存分类
if(!checkfile('cate',86400))
{
	$query=$db->query('select * from '.tname('catelist').' where parentid=0 order by sortorder desc');
	while($rows=$db->fetch_array($query))
	{
		$cate[$rows['id']]=array('catename'=>$rows['catename'],'sortorder'=>intval($rows['sortorder']));
	}
	write('cate',$cate);
}
else
{
	$cate=read('cate');
}

//缓存城市
if(!checkfile('city',86400))
{
	$query=$db->query('select * from '.tname('city').' where pinyin!="" order by pinyin asc');
	
	while($rows=$db->fetch_array($query))
	{
		$city[$rows['pinyin']]=array('cityname'=>$rows['cityname'],'sortorder'=>intval($rows['sortorder']),'isshow'=>$rows['isshow'],'cityid'=>$rows['cityid']);
	}
	write('city',$city);
}
else
{
	$city=read('city');
}
//缓存网站分类
if(!checkfile('sitecate',86400))
{
	$query=$db->query('select * from '.tname('sitecate').' order by sortorder desc');
	while($rows=$db->fetch_array($query))
	{
		$sitecate[$rows['id']]=array('sitecatename'=>$rows['sitecatename'],'sortorder'=>intval($rows['sortorder']),'isshow'=>intval($rows['isshow']));
	}
	write('sitecate',$sitecate);
}
else
{
	$sitecate=read('sitecate');
}

//缓存网站名
if(!checkfile('site',86400))
{
	$query=$db->query('select id,sitename,sitetype,cityid,pinyin,recommend from '.tname('site').' order by level desc');
	
	while($rows=$db->fetch_array($query))
	{
		$site[$rows['id']]=array('sitename'=>$rows['sitename'],'sitetype'=>$rows['sitetype'],'cityid'=>$rows['cityid'],'pinyin'=>$rows['pinyin'],'recommend'=>$rows['recommend']);
	}
	write('site',$site);
}
else
{
	$site=read('site');
}
//缓存商圈
if(!checkfile('bizgroup',86400))
{
	$query=$db->query('select id,cityid,bizname from '.tname('bizgroup'));
	while($rows=$db->fetch_array($query))
	{
		$bizgroup[$rows['id']]=array('cityid'=>$rows['cityid'],'bizname'=>$rows['bizname']);
	}
	write('bizgroup',$bizgroup);
}
else
{
	$bizgroup=read('bizgroup');
}
//缓存友情链接
if(!checkfile('link',86400))
{
	$query=$db->query('select id,title,url,decs,thumb,sortorder,type  from '.tname('link'));
	while($rows=$db->fetch_array($query))
	{
		$link[$rows['id']]=array('title'=>$rows['title'],'url'=>$rows['url'],'decs'=>$rows['decs'],'thumb'=>$rows['thumb'],'sortorder'=>$rows['sortorder'],'type'=>$rows['type']);
	}
	write('link',$link);
}
else
{
	$link=read('link');
}
//缓存其他网站
if(!checkfile('othersite',86400))
{
	$query=$db->query('select id,sitename,url,img,cate,istop,recommend,color,font,sort  from '.tname('othersite')." order by sort desc ");
	while($rows=$db->fetch_array($query))
	{
		$othersite[$rows['id']]=array('id'=>$rows['id'],'sitename'=>$rows['sitename'],'url'=>$rows['url'],'img'=>$rows['img'],'cate'=>$rows['cate'],'istop'=>$rows['istop'],'recommend'=>$rows['recommend'],'color'=>$rows['color'],'font'=>$rows['font'],'sort'=>$rows['sort']);
	}
	write('othersite',$othersite);
}
else
{
	$othersite=read('othersite');
}


require(ROOT_PATH.'/uc_client/client.php');
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;
}

if (isset($_REQUEST['GLOBALS']) OR isset($_FILES['GLOBALS'])) {
	exit('Request tainting attempted.');
}
include ROOT_PATH.'/inc/rep.inc.php'; //采集规则包
$usertype=array('normaluser'=>'会员','adminuser'=>'管理员','siteuser'=>'站长');
$level=array(0=>'Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y');
$pluginsshow=array('主导航','上部','底部');