<?php
header("Content-type: text/html; charset=utf-8");
error_reporting(0);
date_default_timezone_set('PRC');
define('DDROOT', str_replace(DIRECTORY_SEPARATOR,'/',dirname(dirname(__FILE__))));
if($_SERVER['PHP_SELF']==''){
	$_SERVER['PHP_SELF']=$_SERVER['SCRIPT_NAME'];
}
if($_SERVER['REQUEST_URI']==''){
	$_SERVER['REQUEST_URI']=$_SERVER['REDIRECT_URL'];
}

if(!is_file(DDROOT.'/data/conn.php')){
    header('Location:install/index.php');
}


//建二开
require DDROOT.'/vendor/autoload.php';
spl_autoload_register(function ($class) { // class = os\Linux
    /* 引入相关文件 */
    $file=DDROOT."/class/$class.php";
    if (file_exists($file)) {
        include $file;
    }
});

function catch_fatal_error(){
	$last_error =  error_get_last();
	if($last_error['type']==1 || $last_error['type']==4 || $last_error['type']==64 || $last_error['type']==4096){
		print_r($last_error['message']);
		print_r("<br/>");
		print_r(str_replace(DDROOT,'',str_replace(DIRECTORY_SEPARATOR,'/',$last_error['file'])).':'.$last_error['line']);
	}
}
register_shutdown_function('catch_fatal_error');

define('TODAY',date('Ymd'));

include (DDROOT . '/data/conn.php');
include (DDROOT . '/comm/lib.php');
//引入config内的所有php文件
$files = scandir(DDROOT."/config");
  foreach ($files as $file) {
      if (strpos($file, "php")){
      	include(DDROOT."/config/".$file);
      }
  }

$banben=include(DDROOT.'/data/banben.php');
include_once(DDROOT.'/data/array/global.php');

include_once(DDROOT.'/class/DdExtend.php');
define('BANBEN',$banben);

$duoduo = new duoduo();
$duoduo->dbserver=$dbserver;
$duoduo->dbuser=$dbuser;
$duoduo->dbpass=$dbpass;
$duoduo->dbname=$dbname;
$duoduo->BIAOTOU=BIAOTOU;
$duoduo_link=$duoduo->connect();


$duoduo1 = new duoduo();
$duoduo1->dbserver=$dbserver;
$duoduo1->dbuser="ht_chinashunshen";
$duoduo1->dbpass="AcMZGWexyYD7z5Kj";
$duoduo1->dbname="ht_chinashunshen";
$duoduo1->BIAOTOU=BIAOTOU;
//$duoduo1->connect();
$errorData=include (DDROOT . '/data/error.php');

$duoduo->errorData=$errorData;
if(!defined('ADMIN')){
	$webset=dd_get_cache('webset');
	$constant=dd_get_cache('constant');
	
	
	   $touch_arr =array("mobile","android","wap","uc","wml","vnd","adr","mqqbrowser","nokiaBrowser","playbook", "blackberry","bb10","ipad","iphone");
		$useragent=$_SERVER["HTTP_USER_AGENT"];//获取浏览器User-Agent (UA)
		$th=str_ireplace($touch_arr,'',$useragent);
		if($useragent<>$th){
			 //$constant['MOBAN']="wap";
		     //$constant['URL']=$domain;
		}
		 //$constant['MOBAN']="wap";
	if(empty($webset) || empty($constant)){  //个别网站配置文件没了
		$duoduo->webset();
		$webset=dd_get_cache('webset');
	}
	$duoduo->webset=$webset;
	
	foreach($constant as $k=>$v){
		if(!defined($k)){
			define($k,$v);
		}
	}
}
else{
	$webset=$duoduo->webset(101);
	$duoduo->webset=$webset;
	$duoduo->errorData=$errorData;
}

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' || isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME']=='https'){
	define('HTTP','https://');
}
else{
	define('HTTP','http://');
}
define('CURURL',HTTP.$_SERVER['HTTP_HOST'].URLMULU);
define('SITEURL',HTTP.URL);
//define('DOMAIN',get_domain());
define('DOMAIN',$_SERVER['SERVER_NAME']);  //阻止多个二级域名cookie混乱
define('TIME',$_SERVER['REQUEST_TIME']+$webset['corrent_time']);
$sj=date('Y-m-d H:i:s',TIME);
define('SJ',$sj);
define('CUR_URL',HTTP.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
define('WEBNICK',WEBNAME);
define('CUR_WEB',$_SERVER['HTTP_HOST']);

$plugin_include=dd_get_cache('plugin_include');
if(!empty($plugin_include)){
	foreach($plugin_include as $code){
		$dir=DDROOT.'/plugin/'.$code.'/comm.php';
		$plugin_data=dd_get_cache('plugin/'.$code);
		if(file_exists($dir) && $plugin_data['status']==1){
			include($dir);
		}
	}
}


if ($_GET['class']){
	$act=$_GET['act'];
	app($_GET['class'])->$act();
	exit();
}
?>