PageRenderTime 54ms CodeModel.GetById 16ms app.highlight 31ms RepoModel.GetById 2ms app.codeStats 0ms

/Upload/DoYouHaoBaby/LibPHP/Core/App.class.php

http://dyhb-frame.googlecode.com/
PHP | 162 lines | 135 code | 23 blank | 4 comment | 29 complexity | 172c87e70fe53fecfeebd3d24820dcd9 MD5 | raw file
  1<?php
  2/* [DoYouHaoBaby!] (C)Dianniu From 2010.
  3   ?????($)*/
  4
  5!defined('DYHB_PATH') && exit;
  6
  7/** PHP __autoload???? */
  8function __autoload($sClassName){Package::autoLoad($sClassName);}
  9
 10class App{
 11
 12	private static $_oControl;
 13	private static $_bEmptyModel=false;
 14
 15	static private function init_(){
 16		header('DoYouHaoBaby-Framework | '.DYHB_VERSION);
 17		header("Content-type:text/html;charset=utf-8");
 18		session_start();// ???Session
 19		LangPackage::addPackageDir(DYHB_PATH.'/Resource/Lang'); // ???????
 20		register_shutdown_function(array('RunTime','runtimeShutdown'));// ?????
 21		RunTime::registerShutdown(array('RunTime','exitBeforeShutdown'));
 22		set_error_handler(array('RunTime','errorHandel'));
 23
 24		Package::import(DYHB_PATH.'/LibPHP');// ?? DoYouHaoBaby ??
 25		//if(!is_file(DYHB_PATH.'/LibCom/Js/Dyhb.package.js')){Package::importJsPackage('Dyhb',false);}
 26
 27		if(function_exists('date_default_timezone_set')){
 28			date_default_timezone_set($GLOBALS['_commonConfig_']['TIME_ZONE']);
 29		}
 30		if($GLOBALS['_commonConfig_']['START_GZIP'] && function_exists('gz_handler')){
 31			ob_start('gz_handler');
 32		}
 33
 34		$oUrl=new Url();// URL??
 35		$oUrl->parseUrl();
 36		require(APP_PATH.'/App/DoYouHaoBaby.php');// ?????????
 37		self::checkTemplate();// ????????
 38		self::checkLanguage();
 39 		self::constantDefine();// ????
 40
 41		if($GLOBALS['_commonConfig_']['HTML_CACHE_ON']){// ??????
 42			if(file_exists(APP_PATH.'/App/Config/Html.php')){
 43				G::C('_HTML_',(array)(include APP_PATH.'/App/Config/Html.php'));
 44			}
 45			Html::R();
 46		}
 47		Package::import(APP_PATH.'/App/Class');
 48		return;
 49	}
 50
 51	static public function RUN(){
 52		self::init_();
 53		self::execute();
 54		if($GLOBALS['_commonConfig_']['LOG_RECORD']){Log::S();}
 55		return;
 56	}
 57
 58	static public function execute(){
 59		$sModule=ucfirst(MODULE_NAME)."Controller";
 60		if(Package::classExists($sModule,false,true)){$oModule=new $sModule();}
 61		elseif(isset($GLOBALS['_commonConfig_'][strtoupper('_M_'.MODULE_NAME)])){
 62			$sModule=ucfirst(strtolower($GLOBALS['_commonConfig_'][strtoupper('_M_'.MODULE_NAME)]))."Controller";
 63			if(!class_exists($sModule,false)){G::E(G::L('%s ?????%s ???','dyhb',null,MODULE_NAME,$sModule));}
 64			$oModule=new $sModule();
 65		}else{
 66			$oModule=self::emptyModule();
 67		}
 68
 69		if($oModule===false){$bResult=self::display();}
 70		self::$_oControl=$oModule;
 71		if(method_exists( $oModule,'init__')){call_user_func(array($oModule,'init__'));}
 72		if(defined('DOYOUHAOBABY_TEMPLATE_BASE') && ucfirst(DOYOUHAOBABY_TEMPLATE_BASE)!==TEMPLATE_NAME && is_dir(APP_PATH."/Theme/".ucfirst(DOYOUHAOBABY_TEMPLATE_BASE)."/Public/Php/Lang")){LangPackage::addPackageDir(APP_PATH."/Theme/".ucfirst(DOYOUHAOBABY_TEMPLATE_BASE)."/Public/Php/Lang");}
 73		if(method_exists( $oModule,'b'.ucfirst(ACTION_NAME).'_')){call_user_func(array($oModule,'b'.ucfirst(ACTION_NAME).'_'));}
 74		if(method_exists( $oModule,ACTION_NAME)){
 75			call_user_func(array($oModule,ACTION_NAME));
 76			$bResult=true;
 77		}else{
 78			$bResult=self::emptyAction($oModule);
 79		}
 80		if($bResult===false){$bResult=self::display();}
 81		if(method_exists($oModule,'a'.ucfirst(ACTION_NAME).'_')){call_user_func(array($oModule,'a'.ucwords(ACTION_NAME).'_'));}
 82	}
 83
 84	private static function emptyModule(){
 85		self::$_bEmptyModel=true;
 86		$sModule=ucfirst(strtolower($GLOBALS['_commonConfig_']['EMPTY_MODULE_NAME']))."Controller";
 87		if(!Package::classExists($sModule,false,true)){return false;}
 88		return new $sModule();
 89	}
 90
 91	private static function emptyAction($oModule){
 92		if(method_exists( $oModule,$GLOBALS['_commonConfig_']['EMPTY_ACTION_NAME'])){call_user_func(array($oModule,$GLOBALS['_commonConfig_']['EMPTY_ACTION_NAME']));}
 93		else{return false;}
 94	}
 95
 96	static private function display(){
 97		$oController=new Controller();
 98		return $oController->display();
 99	}
100
101	static private function checkTemplate(){
102		if(isset($_GET['t'])){
103			$sTemplateSet=ucfirst($_GET['t']);
104			G::cookie(APP_NAME.'_template',$sTemplateSet,3600);
105		}else{
106			if(G::cookie(APP_NAME.'_template')){$sTemplateSet=G::cookie(APP_NAME.'_template');}
107			else{
108				$sTemplateSet=ucfirst($GLOBALS['_commonConfig_']['TPL_DIR']);
109				G::cookie(APP_NAME.'_template',$sTemplateSet,3600);
110			}
111		}
112
113		define('TEMPLATE_NAME',$sTemplateSet);
114		define('TEMPLATE_PATH',APP_PATH.'/Theme/'.TEMPLATE_NAME);
115		TemplateHtml::setTemplateDir(APP_PATH.'/Theme/'.TEMPLATE_NAME);
116
117		if(is_dir(APP_PATH."/Theme/{$sTemplateSet}/Public/Php/Lang")){LangPackage::addPackageDir(APP_PATH."/Theme/{$sTemplateSet}/Public/Php/Lang");}
118		if($sTemplateSet!='Default' && is_dir(APP_PATH."/Theme/Default/Public/Php/Lang")){LangPackage::addPackageDir(APP_PATH."/Theme/Default/Public/Php/Lang");}
119		return;
120	}
121
122	static private function checkLanguage(){
123		LangPackage::addPackageDir(APP_PATH.'/App/Lang');
124		if(isset($_GET['l'])){
125			$sLangSet=ucfirst($_GET['l']);
126			G::cookie(APP_NAME.'_language',$sLangSet,3600);
127		}
128		elseif(G::cookie(APP_NAME.'_language')){$sLangSet=G::cookie(APP_NAME.'_language');}
129		elseif($GLOBALS['_commonConfig_']['AUTO_ACCEPT_LANGUAGE'] && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
130			preg_match('/^([a-z\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $arrMatches);
131			$sLangSet=ucfirst($arrMatches[1]);
132			G::cookie(APP_NAME.'_language',$sLangSet,3600);
133		}
134		else{$sLangSet=ucfirst($GLOBALS['_commonConfig_']['LANG']);}
135		define('LANG_NAME',$sLangSet);
136		Lang::setCurrentLang($sLangSet);
137		define('LANG_PATH',APP_PATH.'/App/Lang/'.LANG_NAME);
138		return;
139	}
140
141	static private function constantDefine(){
142		define('__ENTER__',basename(__APP__));
143		define('__FRAMEWORK__',__ROOT__.'/'.G::getRelativePath(__ROOT__.'/'.APP_NAME,WEB_ADMIN_HTTPPATH));// ????????
144		define('__LIBCOM__',__FRAMEWORK__.'/LibCom');// LibCom????
145		define('__APPPUB__',__ROOT__.'/'.APP_NAME.'/Static');// ????????????(???????)
146		define('__THEME__',__ROOT__.'/'.APP_NAME.'/Theme');// ????
147		define('__TMPL__',__THEME__.'/'.TEMPLATE_NAME);// ??????
148		define('__PUBLIC__',__ROOT__.'/Public');// ????????
149		define('__TMPLPUB__',__TMPL__.'/Public');// ????????
150		define('__TMPL_FILE_NAME__',__TMPL__.'/'.($GLOBALS['_commonConfig_']['TMPL_MODULE_ACTION_DEPR']=='/' && MODULE_NAME==='public'?'Public':MODULE_NAME).$GLOBALS['_commonConfig_']['TMPL_MODULE_ACTION_DEPR'].ACTION_NAME.$GLOBALS['_commonConfig_']['TEMPLATE_SUFFIX']);// ??????
151		define('__TMPL_FILE_PATH__',TEMPLATE_PATH.'/'.($GLOBALS['_commonConfig_']['TMPL_MODULE_ACTION_DEPR']=='/' && MODULE_NAME==='public'?'Public':MODULE_NAME).$GLOBALS['_commonConfig_']['TMPL_MODULE_ACTION_DEPR'].ACTION_NAME.$GLOBALS['_commonConfig_']['TEMPLATE_SUFFIX']);
152	}
153
154	static public function U(){
155		return "var _ROOT_='".__ROOT__."',_MODULE_NAME_='".MODULE_NAME."',_ACTION_NAME_='".ACTION_NAME."',_ENTER_ ='".__ENTER__."',_APP_VAR_NAME_='app',_CONTROL_VAR_NAME_='c',_ACTION_VAR_NAME_='a',_URL_HTML_SUFFIX_='".$GLOBALS['_commonConfig_']['URL_HTML_SUFFIX']."';";
156	}
157
158	static public function U2(){
159		return "var _ROOT_='".__ROOT__."',_MODULE_NAME_='".MODULE_NAME."',_ACTION_NAME_='".ACTION_NAME."',_APP_NAME_ ='".APP_NAME."',_APP_VAR_NAME_='app',_CONTROL_VAR_NAME_='c',_ACTION_VAR_NAME_='a',_URL_HTML_SUFFIX_='".$GLOBALS['_commonConfig_']['URL_HTML_SUFFIX']."';";
160	}
161
162}