<?php
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
class Factory {
	static private $_obj = null;	
	static public function setAction(){	
		//是否允许蜘蛛访问
		$ban_spider=self::getBanspider();
		if($ban_spider){			
			Tool::banspider($ban_spider);
		}
		//判断是否允许ip访问	
		$banip=self::getBanip();
		if($banip){			
			foreach ($banip as $key=>$value){
				Tool::banip($value[0], $value[1]);
			}
		}
		$_a = self::getA();
		//每爬行一次首页执行更新操作
		if(strtolower($_a)=='index'){
			//蜘蛛爬行日志
			$bootname=Tool::get_bot();
			$bootarray=array('baiduspider','googlebot','sogou','sosospider','bingbot','msnbot','ia_archiver','slurp','youdaobot','banip','banspider','');
			if($bootname){
				if(in_array($bootname, $bootarray)){
					$report_bot=new ReportbotModel();
					$one_data=$report_bot->findOne($bootname);
					$report_bot->update($bootname,$one_data[0]->botcount);
				}	
			}
		}
		//判断是否有session
		$level= array(
			'manage', 
			'nav',
			'level',
			'ad',
			'homenav',
			'api',
			'artile',
			'artilenav',
			'imgsider',
			'keywords',
			'link',
			'recshop',
			'seo',
			'settingbasic',
			'shopcategory',
			'template',
			'upload',
			'banip',
			'banspider',
			'reportbot',
			'clearcache',
			'sellercate',
			'sellerlist'
		);
		if (Validate::inArray($_a,$level)) {
			if (!isset($_SESSION['admin'])){
				Redirect::getInstance()->succ('?a=admin&m=login');	
			}
			require_once './public/PageAdmin.php';	
			TPL::getInstance()->caching=0;	//后台不缓存
		}
		else{
			require_once './public/PageFront.php';
		}
		if (!file_exists(ROOT_PATH.'/controller/'.ucfirst($_a).'Action.class.php')) $_a = 'Index';
		eval('self::$_obj = new '.ucfirst($_a).'Action();');
		return self::$_obj;
	}
	
	static public function setModel(){
		$_a = self::getA();
		if (file_exists(ROOT_PATH.'/model/'.ucfirst($_a).'Model.class.php')) eval('self::$_obj = new '.ucfirst($_a).'Model();');
		return self::$_obj;
	}
	
	static public function getA() {
		if (isset($_GET['a']) && !empty($_GET['a'])) {
			return $_GET['a'];
		}
		return 'Index';
	}
	static function _runtime(){
			$_mtime = explode(' ',microtime());
			return $_mtime[1] + $_mtime[0];
	}
	//调取屏蔽ip文件
	static public function getBanip(){
		if(file_exists('./configs/banip_config_inc.php')){
			$banip=@file_get_contents('./configs/banip_config_inc.php');
			$banip=Tool::UnSerialize($banip);
			return $banip;
		}
		else{
			return false;
		}
	}
	//屏蔽蜘蛛
	static public function getBanspider(){
		if(file_exists('./configs/banspider_config_inc.php')){
			$ban_spider=@file_get_contents('./configs/banspider_config_inc.php');
			return $ban_spider;
		}
		else{
			return false;
		}
	
	}
	
	
}
?>