<?PHP
// +----------------------------------------------------------------------
// 最便捷的php框架
// +----------------------------------------------------------------------
// | Copyright (c) 2011 http://www.ky53.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.ky53.net )
// +----------------------------------------------------------------------

/**
 
 * @author   qq:974005652(zhx626@126.com) by老顽童
 * @version  1.0
 +------------------------------------------------------------------------------
 */
  
  @require KY_PATH."/kycmd/message.php";
  require KY_PATH."/kycmd/cmd.php";
  
  require APP_PATH."/".TEMP_PATH."/data.bat";
  require KY_PATH."/kyclass/cache_class.php";
  require KY_PATH."/kydata/data.php";
  
  if(empty($conf['DEFAULT_HTML_PATH']))$conf['DEFAULT_HTML_PATH']='html';
  if(empty($conf['DEFAULT_LIB_PATH']))$conf['DEFAULT_LIB_PATH']='lib';  
  if(empty($conf['DEFAULT_TPL_PATH']))$conf['DEFAULT_TPL_PATH']='tpl';
  if(empty($conf['DEFAULT_CMD_PATH']))$conf['DEFAULT_CMD_PATH']='cmd';
  if(empty($conf['PATH_KEY']))$conf['PATH_KEY']=3;
  $geturl=strtolower(isset($_GET['k'])?$_GET['k']:'');
  if(!empty($conf['WEBURL'])) define('__WEBURL__', $conf['WEBURL']);
  if($conf['PATH_KEY']==1||$conf['PATH_KEY']==2)$geturl=$_SERVER['"PATH_INFO"'];
  //if(empty($geturl))$geturl=$_SERVER['"PATH_INFO"'];
  
  $urlarr=explode("/",$geturl);
  $j=0;
  
  foreach($urlarr as $key=>$i){
    if($j%2!=0){
     $_GET[$i]=isset($urlarr[$j+1])?$urlarr[$j+1]:'';
	 }
	 
  $j++;
  }
  
 
  $temp=new temp();
  $tindex='';
  if(isset($urlarr['1']))$tindex=$_GET[isset($urlarr['1'])?$urlarr['1']:''];
 
  if(!$tindex)$tindex='index';
  
  $aindex=isset($urlarr['1'])?$urlarr['1']:'';
  
	 
	  if(!$aindex){$aindex='index';
	   
	    if($conf['DEFAULT_MODULE']){	  
	       $aindex=$conf['DEFAULT_MODULE'];
		  
	    }
	  }
	  
	  if($conf['PATH_KEY']==3){
	   define('__URL__', $_SERVER['PHP_SELF'].'?k=/'.$aindex);
		 define('__APP__', $_SERVER['PHP_SELF'].'?k=');
		  define('__ROOT__', APP_PATH);
		  }
		   
		  if($conf['PATH_KEY']==1){
	   define('__URL__', $_SERVER['PHP_SELF'].'/'.$aindex);
		 define('__APP__', $_SERVER['PHP_SELF'].'');
		  define('__ROOT__', APP_PATH);
		  }
		  if($conf['PATH_KEY']==2){
	   define('__URL__', APP_PATH.'/'.$aindex);
		 define('__APP__', APP_PATH);
		  define('__ROOT__', APP_PATH);
		  }
		  if($conf['PATH_KEY']==4){
		$locurl=preg_replace("/\/(\w+)\.(\w+)/eis",'',$_SERVER["SCRIPT_NAME"]);
		
		
		  
	   define('__URL__', $locurl.'/'.$conf['DEFAULT_HTML_PATH'].'/'.$aindex);
		 define('__APP__', $locurl.'/'.$conf['DEFAULT_HTML_PATH']);
		  define('__ROOT__', $locurl);
		  }
		  if($conf['PATH_KEY']>4||$conf['PATH_KEY']<0){
	      error(3,"系统错误，请正确设置系统PATH_KEY模式");
		  }
		  @require APP_PATH."/".$conf['DEFAULT_CMD_PATH']."/cmd.php";

	  $pbstr='@require APP_PATH."/'.$conf['DEFAULT_LIB_PATH'].'/public.class.php";';
	 
	  if($aindex=='public'){$pbstr='';}
	  if(empty($conf['DEFAULT_TPL'])){
	  $conf['DEFAULT_TPL']='default';
	    }else{ 
		if($_COOKIE['default_tpl']){
		$conf['DEFAULT_TPL']=$_COOKIE['default_tpl'];		
	    }
	   }
	   if(!empty($conf['DEFAULT_M_PATH'])){
	   require KY_PATH."/kyclass/model_class.php";
	   
	   if(@file_exists(APP_PATH."/".$conf['DEFAULT_M_PATH']."/$aindex.class.php"))@require APP_PATH."/".$conf['DEFAULT_M_PATH']."/$aindex.class.php";
	   
	   if(!@class_exists($aindex.'Model'))error(2,$aindex.'Model');
	   
	   }
	  
	  if(!empty($conf['MYDATA_PATH'])){
		  $mydatapath=APP_PATH.'/'.$conf['MYDATA_PATH'].'/*';
		     foreach(glob($mydatapath) as $key){
			 require $key;
		
		      }
	   }
	   

	  if($aindex!='public')@require APP_PATH."/".$conf['DEFAULT_LIB_PATH']."/public.class.php";
	  if(@file_exists(APP_PATH."/".$conf['DEFAULT_LIB_PATH']."/cmd.class.php"))@require APP_PATH."/".$conf['DEFAULT_LIB_PATH']."/cmd.class.php";
	  if(!@file_exists(APP_PATH."/".$conf['DEFAULT_LIB_PATH']."/".$aindex.".class.php"))error(0,APP_PATH."/".$conf['DEFAULT_LIB_PATH']."/".$aindex.".class.php");
	
	   require APP_PATH."/".$conf['DEFAULT_LIB_PATH']."/".$aindex.".class.php";
	   if(!@class_exists($aindex.'Action'))error(2,$aindex.'Action');
	   $aindexclass=$aindex.'Action';
	   $index=new $aindexclass();
	   $index->_initialize();
	   if(!method_exists($index,$tindex))error(1,$tindex);
	   $index->$tindex();
	   
	   /*
  $file='<?php '.chr(13).'//科亿php'.chr(13).'if(@file_exists(APP_PATH."/'.$conf['DEFAULT_LIB_PATH'].'/cmd.class.php"))@require APP_PATH."/'.$conf['DEFAULT_LIB_PATH'].'/cmd.class.php";'.chr(13).$pbstr.chr(13).'if(!@file_exists(APP_PATH."/'.$conf['DEFAULT_LIB_PATH'].'/'.$aindex.'.class.php"))error(0,APP_PATH."/'.$conf['DEFAULT_LIB_PATH'].'/'.$aindex.'.class.php");'.chr(13).'require APP_PATH."/'.$conf['DEFAULT_LIB_PATH'].'/'.$aindex.'.class.php";if(!@class_exists('.$aindex.'Action))error(2,"'.$aindex.'Action");'.chr(13).'  $index=new '.$aindex.'Action();'.chr(13).' $index->_initialize();'.chr(13).'if(!method_exists($index,$tindex))error(1,$tindex);'.chr(13).' $index->'.$tindex.'();?>';
  
  $temp->tempwrite("cahe/run.$aindex.$tindex.php",$file,"");
 
  require APP_PATH."/".TEMP_PATH."/cahe/run.$aindex.$tindex.php";
 
 */
 
?>