<?php
date_default_timezone_set('Asia/Shanghai');
require_once WEBROOT."include/application.php";
require_once WEBROOT."data/configdata.php";
require_once WEBROOT.'include/Taoapi.php';

//变量初始化。
$read_data_num = 0;
$read_cache_num = 0;
$pagestartime = microtime();


$applicationarray = array ();
$applicationarray = application("",ROOT."applicationdate.php");

//检查是否需要屏蔽蜘蛛访问
$useragent=strtolower($_SERVER['HTTP_USER_AGENT']);
$badrobots = $applicationarray["badrobots"];
if(is_array($badrobots)){
	foreach($badrobots as $k=>$v){
		if(intval($v)==1){
			if(stripos($useragent,strtolower($k))!==false){
				exit($k."禁止访问！");
			}
		}
	}
}

//检查是否需要屏蔽IP
$userip=strtolower($_SERVER['REMOTE_ADDR']);
$useripnum = sprintf("%u", ip2long($userip));
$pbips = $applicationarray["pbips"];
foreach($pbips as $ip){
	$startip = sprintf("%u", ip2long($ip["startip"]));
	$endip = sprintf("%u", ip2long($ip["endip"]));
	if($useripnum>=$startip && $endip>=$useripnum){
		exit($userip."禁止访问！");
	}
}
$GJconfig = $applicationarray["GJconfig"];
//读取高级配置

	$shoplevelstart=$GJconfig["shoplevelstart"];
	$shoplevelend=$GJconfig["shoplevelend"];
	$indexsort=$GJconfig["indexsort"];
	$indexpage=$GJconfig["indexpage"];
	$pagenumKeys=$GJconfig["pagenumKeys"];
	$pagenums=$GJconfig["pagenums"];
	$stratmoneyKeys=$GJconfig["stratmoneyKeys"];
	$endmoneyKeys=$GJconfig["endmoneyKeys"];
	$indexupdatenum=$GJconfig["indexupdatenum"];
	$listlinktype=$GJconfig["listlinktype"];
	$searchdefault=$GJconfig["searchdefault"];
	$searchkeypb=$GJconfig["searchkeypb"];
	$catidpb=$GJconfig["catidpb"];
	$numidpb=$GJconfig["numidpb"];
	$logo=$GJconfig["logo"];
	$goto301=$GJconfig["goto301"];
	
	$indexpagernd=$GJconfig["indexpagernd"];
	
	$ismall=$GJconfig["ismall"];
	$httplink=$GJconfig["httplink"];
	$AppErrPages=$GJconfig["AppErrPages"];
	$gonggao=$GJconfig["gonggao"];

	$defaultarea = $GJconfig["defaultarea"];
	$defaultsort = $GJconfig["defaultsort"];

	if(empty($shoplevelstart)) $shoplevelstart="1heart";
	if(empty($shoplevelend)) $shoplevelend="5goldencrown";
	if(empty($indexsort)) $indexsort="commissionNum_desc";
	if(empty($indexpage)) $indexpage="1";
	if(empty($pagenumKeys)) $pagenumKeys="18";
	if(empty($pagenums)) $pagenums="100";
	if(empty($stratmoneyKeys)) $stratmoneyKeys="100";
	if(empty($endmoneyKeys)) $endmoneyKeys="5000";
	if(empty($indexupdatenum)) $indexupdatenum="5";
	if(empty($listlinktype)) $listlinktype="item";
	if(empty($searchdefault)) $searchdefault="0";
	if(empty($logo)) $logo=$rootroad."/img/logo.gif";
	if(empty($goto301)) $goto301="0";
	
	if(empty($indexpagernd)) $indexpagernd="";
	if(empty($ismall)) $ismall="0";
	if(empty($httplink)) $httplink="0";
	if(empty($AppErrPages)) $AppErrPages="http://www.taobao.com/go/chn/tbk_channel/channelcode.php?pid={#PID#}&eventid=101329";
	if(empty($gonggao)) $gonggao="";
	if(empty($defaultsort)) $defaultsort="";


	//读取伪原创配置
	$WYCconfig = $applicationarray["WYCconfig"];

	$WYCpictype=$WYCconfig["pictype"];
	$WYCUrlEncodeType=$WYCconfig["UrlEncodeType"];
	$WYCUrlRewriteJr=$WYCconfig["UrlRewriteJr"];
	$WYCdescJs=$WYCconfig["descJs"];
	$WYCdeschead=$WYCconfig["deschead"];
	$WYCdescfooter=$WYCconfig["descfooter"];
	
	$WYCzhengheTaoBao_open=$WYCconfig["zhengheTaoBao_open"];
	$WYCzhengheTaoBao_site=$WYCconfig["zhengheTaoBao_site"];
	$WYCzhengheTaoBao_area=$WYCconfig["zhengheTaoBao_area"];
	$WYCzhengheTaoBao_url= stripslashes(html_entity_decode($WYCconfig["zhengheTaoBao_url"],ENT_QUOTES));
	$WYCzhengheTaoBao_hiddentop=$WYCconfig["zhengheTaoBao_hiddentop"];
	$WYCzhengheTaoBao_hiddenhigh=$WYCconfig["zhengheTaoBao_hiddenhigh"];

	if(empty($WYCpictype)) $WYCpictype="js";
	if(empty($WYCUrlEncodeType)) $WYCUrlEncodeType="auto";
	if(empty($WYCUrlRewriteJr)) $WYCUrlRewriteJr="1";
	if(empty($WYCdescJs)) $WYCdescJs="1";
	if(empty($WYCdeschead)) $WYCdeschead="";
	if(empty($WYCdescfooter)) $WYCdescfooter="";





if($httplink=="1"){
	$rootroad = $sitetitleurl.$rootroad;
}



//模板目录设置
if($templatefolder==""){
	$templatefolder = "default";	
}

if(is_file(WEBROOT.'/template/'.$templatefolder.'/config.php')){
	include_once(WEBROOT.'/template/'.$templatefolder.'/config.php');
}else{
	exit("模板设置错误，请检查模板。");	
}

//模板根路径，网址用
$templateroot = $rootroad."/template/".$templatefolder;
//模板根路径，文件用
$WEBROOT_TEMP = WEBROOT."template/".$templatefolder."/";

$pidsplit = array();
$pidsplit["{#PID#}"] = $userpid;
$pidsplit["{#SPID#}"] = $userpiddp;
$pidsplit["{#ROOT#}"] = $rootroad;
$pidsplit["{#templateroot#}"] = $templateroot;


$array_guanggao = application("array_guanggao",WEBROOT."data/guanggao.php");
if(is_array($array_guanggao)){
	$ggtop = strtr(stripslashes(html_entity_decode($array_guanggao["top"],ENT_QUOTES)),$pidsplit);
	$ggleft = strtr(stripslashes(html_entity_decode($array_guanggao["left"],ENT_QUOTES)),$pidsplit);
	$ggleftcontent = strtr(stripslashes(html_entity_decode($array_guanggao["leftcontent"],ENT_QUOTES)),$pidsplit);
}
$AppErrPages =  strtr(stripslashes(html_entity_decode($AppErrPages,ENT_QUOTES)),$pidsplit);
$WYCzhengheTaoBao_url =  strtr(stripslashes(html_entity_decode($WYCzhengheTaoBao_url,ENT_QUOTES)),$pidsplit);


//整合淘宝页面的代码
if($WYCzhengheTaoBao_open=="1"){
	
	
	
	if($WYCzhengheTaoBao_site=="all" || $isindexpage=="ok" && $WYCzhengheTaoBao_site=="index" ){
		
		switch($WYCzhengheTaoBao_area){
			case "top":
				$WYCzhengheTaoBao_topCode = "<script src='".$rootroad."/js/showPage.php'></script>";
				break;
			case "middle":
				$WYCzhengheTaoBao_centerCode = "<script src='".$rootroad."/js/showPage.php'></script>";
				break;
			default:
				break;	
		}
		
	}
}


//伪静态功能
$WJTconfig = $applicationarray['WJTconfig'];

if(isset($WJTconfig["pagelist"])){
	$wjtpagelist=$WJTconfig["pagelist"];
	$wjtpageproduct=$WJTconfig["pageproduct"];
	$wjtpageshop=$WJTconfig["pageshop"];
	$wjtpageshopsearch=$WJTconfig["pageshopsearch"];
	$wjtpagehz=$WJTconfig["pagehz"];
	$wjtpagepicture=$WJTconfig["pagepicture"];
}else{
	$wjtpagelist="list.php/";
	$wjtpageproduct="product.php/";
	$wjtpageshopsearch="shopsearch.php/";
	$wjtpageshop="shop.php/";
	$wjtpagehz=".html";
	$wjtpagepicture="pic.php/";
}

if($WYCUrlEncodeType=="auto"){
	if($wjtpagelist!="list.php/" && $wjtpageproduct!="product.php/" && $wjtpageshop!="shop.php/"){
		$wjturlencode = "base64";
	}else{
		$wjturlencode="2urlencode";
	}	
}else{
	$wjturlencode = $WYCUrlEncodeType;
}



//跳转301：
if($goto301){
	$hostnow = str_replace("http://","",$sitetitleurl);
	if(strpos($hostnow,"/")>0){
		$hostarr = explode("/",$hostnow);
		$hostnow = $hostarr[0];
	}

	$the_host = $_SERVER['HTTP_HOST'];//取得进入所输入的域名
	if($_SERVER['REQUEST_URI']=="/index.php"){
		$_SERVER['REQUEST_URI'] = "";
	}
	$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//判断地址后面部分
	if($the_host != $hostnow)//这是我要以前的域名地址
	{
		
	  header('HTTP/1.1 301 Moved Permanently');//发出301头部 
	  header('Location: http://'.$hostnow.$request_uri);//跳转到我的新域名地址
	}
}

require_once WEBROOT.'include/sysfunction.php';

if($weijingtai=="1"){
	mod_rewrite();
}
if($weijingtai=="0" && $WYCUrlRewriteJr){
	mod_rewrite();
}


$arr_app = getoneapp();

$Taoapi_Config = Taoapi_Config::Init();
$Taoapi_Config->setTestMode(false)			//设置测试模式
              ->setVersion(2)		 		//这里填写申请来的 App Key
              ->setAppKey($arr_app[0])		 		//这里填写申请来的 App Key
              ->setAppSecret($arr_app[1]);			//这里填写申请来的 App Sevret



$Taoapi = new Taoapi;
$Taoapi->Cache->setCacheTime($setCacheTime);	//缓存时间设置单位为小时(设置为0表示关闭缓存功能)




//SEO设置
$seoconfig = $applicationarray["seoconfig"];

$list_title=$seoconfig["list_title"];
$list_keyword=$seoconfig["list_keyword"];
$list_discription=$seoconfig["list_discription"];

$shopsearch_title=$seoconfig["shopsearch_title"];
$shopsearch_keyword=$seoconfig["shopsearch_keyword"];
$shopsearch_discription=$seoconfig["shopsearch_discription"];

$shop_title=$seoconfig["shop_title"];
$shop_keyword=$seoconfig["shop_keyword"];
$shop_discription=$seoconfig["shop_discription"];

$product_title=$seoconfig["product_title"];
$product_keyword=$seoconfig["product_keyword"];
$product_discription=$seoconfig["product_discription"];

foreach($_GET as $value){
	if(strpos("_".$value,"'")>0 || strpos("_".$value,"\"") > 0 || strpos("_".$value,"script") > 0 || strpos("_".$value,"alert") > 0 || strpos("_".$value,"<") > 0){
		exit("禁止提交违禁参数。");	
	}
}
require_once WEBROOT.'include/newsfunction.php';
$defaultarea = Newiconv( "GBK","UTF-8",$defaultarea);

//header("Content-Type: text/html; charset=".$default_soft_lang."");

if((time() % 5000)==0){
//自动删除缓存
	set_time_limit(0);
	deldir("Apicache",$setCacheTime*24*60*60);
}
?>