<?php
/*
'软件名称：苹果CMS 源码库：https://github.com/magicblack
'--------------------------------------------------------
'Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
'遵循Apache2开源协议发布，并提供免费使用。
'--------------------------------------------------------
*/
// 提前定义，避免被 vendor/thinkphp 等引用时报未定义常量（须在任何 require 可能加载到它们之前）
defined('ROOT_PATH') or define('ROOT_PATH', __DIR__ . '/');
defined('DS') or define('DS', DIRECTORY_SEPARATOR);

if (preg_match("/(GPTBot|Googlebot|bingbot|MJ12bot|AhrefsBot|DNSPod-Monitor|Msnbot|BLEXBot|YodaoBot|EasouSpider|YandexBot|nimbostratus-bot|checkmarknetwork|google|yahoo|bing|coodir|zhongsou|slurp|ia_archiver|scooter|webcrawler|OutfoxBot)/i", $_SERVER['HTTP_USER_AGENT'])) {
    header('HTTP/1.1 403 Forbidden');
    exit;
}
//定义应用目录
define('DIYPHP', __DIR__ . '/diyphp/');
define('FANPHP', __DIR__ . '/fanphp/');
// 自定义部分：检测用户
require_once DIYPHP . 'src/checkClient.php';
$client = checkClient();
$GLOBALS['client'] = $client;

// 根据到访类型，做不同处理，1=正常用户，0=蜘蛛，2=黑名单
if ($client === 2) {// 如果是黑名单
    header('HTTP/1.1 403 Forbidden');
    exit('Access Denied 2 '.$_SERVER['REMOTE_ADDR']); 
}elseif ($client === 0 || $client === 3) {
    // 如果是蜘蛛，白名单用户
}elseif ($client === 1 || $client === 5) {
    // 正常访客：从 diyphp/ad/ad.html、ad.js 加载广告（开关见 ad_config.php），模板变量 diy_ad_html / diy_ad_js_block / diy_ad_all
    require_once DIYPHP . 'ad/loadDiyAd.php';
    diy_ad_bootstrap_from_index();
    // require_once DIYPHP . 'src/tj.php';
    // require_once DIYPHP . 'ad/ad.php';

}elseif ($client === 4) {
    // 如果是假蜘蛛，跳转404页面
    header('HTTP/1.1 403 Forbidden');
    exit('Access Denied 4 '.$_SERVER['REMOTE_ADDR']); 
  }
// 检测用户结束
// 统计代码,用=到&$client 放在checkClient()后面
require_once DIYPHP . 'src/tj.php';


header('Content-Type:text/html;charset=utf-8');
// 检测PHP环境
if(version_compare(PHP_VERSION,'5.5.0','<'))  die('PHP版本需要>=5.5，请升级【PHP version requires > = 5.5，please upgrade】');
//超时时间
@ini_set('max_execution_time', '0');
//内存限制 取消内存限制
@ini_set("memory_limit",'-1');
// 定义应用目录
define('ROOT_PATH', __DIR__ . '/');
define('APP_PATH', __DIR__ . '/application/');
define('MAC_COMM', __DIR__.'/application/common/common/');
define('MAC_HOME_COMM', __DIR__.'/application/index/common/');
define('MAC_ADMIN_COMM', __DIR__.'/application/admin/common/');
define('MAC_START_TIME', microtime(true) );
define('BIND_MODULE','index');
define('ENTRANCE', 'index');


$in_file = rtrim($_SERVER['SCRIPT_NAME'],'/');
if(substr($in_file,strlen($in_file)-4)!=='.php'){
    $in_file = substr($in_file,0,strpos($in_file,'.php')) .'.php';
}
define('IN_FILE',$in_file);
if(!is_file('./application/data/install/install.lock')) {
    header("Location: ./install.php");
    exit;
}
if (!@mb_check_encoding($_SERVER['PATH_INFO'], 'utf-8')){
    $_SERVER['PATH_INFO']=@mb_convert_encoding($_SERVER['PATH_INFO'], 'UTF-8', 'GBK');
}

// 加载框架引导文件
require __DIR__ . '/thinkphp/start.php';

