示例#1
0
文件: index.php 项目: Jnnock/myyyk
<?php

include "../YYKFrame/yyk.class.php";
YYK::start('.', 'development.php', true);
示例#2
0
文件: index.php 项目: Jnnock/myyyk
<?php

//var_dump($_SERVER);
include "../YYKFrame/yyk.class.php";
//参数:项目存储路径
YYK::start('.', 'development.php');
示例#3
0
	/**
	* 系统入口
	* 并且支持配置自动加载路径
	* @return void
	*/
	public static function start($appDirectory,$conf='config.php', $debug=false){
		//var_dump( $_SERVER);
		// 设定错误和异常处理
		//register_shutdown_function(array('YYK','fatalError'));
		self::$debug = $debug;
		set_error_handler(array('YYK','appError'), E_ALL);
		set_exception_handler(array('YYK','appException'));
		//取当前框架路径
		self::$YYK_path = pathinfo(__FILE__, PATHINFO_DIRNAME);
		//取当前项目路径
		self::$APP_path = realpath( $appDirectory);
		//self::$APP_path = pathinfo(realpath( $appDirectory), PATHINFO_DIRNAME);//pathinfo($_SERVER["SCRIPT_FILENAME"], PATHINFO_DIRNAME);

		//加载常用方法
		include self::$YYK_path. DIRECTORY_SEPARATOR . 'common.php';

		if (file_exists(self::$APP_path. DIRECTORY_SEPARATOR . 'common.php')) {
			//加载项目自定义方法
			include self::$APP_path. DIRECTORY_SEPARATOR . 'common.php';
		}
		//加载默认配置
		/*
		$tmp = array();
		if (file_exists(self::$YYK_path. DIRECTORY_SEPARATOR . 'config.php')) {
		$tmp = include self::$YYK_path. DIRECTORY_SEPARATOR . 'config.php';
		}
		*/

		//加载用户配置
		$conf = empty($conf) ? "config.php" : $conf;
		if (file_exists(self::$APP_path. DIRECTORY_SEPARATOR . $conf)){
			self::$config = include self::$APP_path. DIRECTORY_SEPARATOR . $conf;
		}

		//合并配置
		/*
		self::$config = array_merge($tmp, self::$config);
		unset($tmp);
		*/

		// 注册AUTOLOAD方法
		//加载用户控制器类
		spl_autoload_register(array('YYK', 'appCtrl'));

		//加载用户模型类
		spl_autoload_register(array('YYK', 'appModel'));

		//加载YYK核心类
		spl_autoload_register(array('YYK', 'YYKClass'));

		//加载框架扩展类

		//加载第三方类
		spl_autoload_register(array('YYK', 'otherClass'));

		//启动session
		session_start();

		//设置时区
		date_default_timezone_set(self::$config['timeZone']);

		//启用smart static server 智能选择静态服务器
		/**/
		if (isset(self::$config['cacheRedis']) && count(self::$config['cacheRedis'])>0 && isset(self::$config['s3']) && count(self::$config['s3'])>0){
			$mem = CacheRedis::create();
			$s3_key = 's3_' . ip2long(getIp());
			$country = $mem->get($s3_key);

			if (!$country) {
				if($ipInfo = getIpInfo(getIP())){
					$country = $ipInfo['country_id'];
				}
			}

			if (isset(self::$config['s3'][$country]) && is_array(self::$config['s3'][$country]) ) {
				self::$config['tplConst'] =array_merge( self::$config['tplConst'], self::$config['s3'][$country]);
			}

			$mem->set($s3_key, $country);
			$mem->expire($s3_key, 600);
		}
		
		//路由分析
		$requestRoute = self::parseRoute();
		self::$ctrlName = $requestRoute[0];
		self::$methodName = $requestRoute[1];

		//启用语言包
		if (isset(self::$config['useMultiLang']) && self::$config['useMultiLang']==true ) {
			if (isset($_GET['l'])) {
				setLang($_GET['l']);
				self::$defaultLang = $_GET['l'];
			}
			else{
				setLang(getLang());
				self::$defaultLang = getLang();
			}
		}


		//检查是否开启了模板静态缓存
		$staticCacheRoute = strstr($_SERVER['REQUEST_URI'], self::$ctrlName . DIRECTORY_SEPARATOR . self::$methodName);
		$staticCacheType = false;

		if (isset( self::$config['staticCache'][$staticCacheRoute] )) {
			$staticCacheType = $staticCacheType = isset(self::$config['staticCacheType']) ? self::$config['staticCacheType'] : 'FS';

			$staticCacheKey = 'staticCache' . str_replace(DIRECTORY_SEPARATOR, '_', self::$APP_path) . str_replace(DIRECTORY_SEPARATOR, '_', $staticCacheRoute);
			
			header('Server: Microsoft-IIS/8.0');
			header('X-Powered-By: ASP.NET');
			$content ='';
			switch(strtolower($staticCacheType)) {
				case 'redis':
					$redis = CacheRedis::create();
					$cacheTtl = $redis->ttl($staticCacheKey);
					$cacheTtl = $cacheTtl>0 ? $cacheTtl : 0;
					$cacheModifyTime   = time() -( self::$config['staticCache'][$staticCacheRoute] - $cacheTtl);
					$requestModifyTime= isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])-3600*8 : 0 ;
					$cacheExpire = $cacheModifyTime + self::$config['staticCache'][$staticCacheRoute];
					if ($cacheExpire > time()) {
						if ($cacheModifyTime <= $requestModifyTime ) {
							header("HTTP/1.1 304 Not Modified");
							header("Date: " . date('D, d M Y H:i:s', time()) . ' GMT');
							header("Last-Modified: " . date('D, d M Y H:i:s', $cacheModifyTime) . ' GMT');
							header("Cache-Control: max-age=" . $cacheTtl);
							header("Expires: ".date('D, d M Y H:i:s', $cacheExpire) . ' GMT');
							exit(0);
						}
						$content = $redis->get($staticCacheKey);
					}
					break;

				case 'memcache':
					$memcache = CacheMem::create();
					$content =  $memcache->get($staticCacheKey);
					$cacheModifyTime = substr($content, 0, strpos($content, ','));
					$cacheTtl = self::$config['staticCache'][$staticCacheRoute] - ( time()-$cacheModifyTime );
					$cacheTtl = $cacheTtl>0 ? $cacheTtl : 0;
					$requestModifyTime= isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])-3600*8 : 0 ;
					$cacheExpire = $cacheModifyTime + self::$config['staticCache'][$staticCacheRoute];
					if ($cacheExpire > time()) {
						if ($cacheModifyTime <= $requestModifyTime ) {
							header("HTTP/1.1 304 Not Modified");
							header("Date: " . date('D, d M Y H:i:s', time()) . ' GMT');
							header("Last-Modified: " . date('D, d M Y H:i:s', $cacheModifyTime) . ' GMT');
							header("Cache-Control: max-age=" . $cacheTtl);
							header("Expires: ".date('D, d M Y H:i:s', $cacheExpire) . ' GMT');
							exit(0);
						}
						$content = substr($content, strpos($content, ',')+1);
					}
					break;

				default:	//默认文件系统缓存
					$tplCache = self::$APP_path . DIRECTORY_SEPARATOR . 'html' . DIRECTORY_SEPARATOR . self::$ctrlName . DIRECTORY_SEPARATOR . self::$methodName . '.html';
					if (!file_exists($tplCache)) {
						break;
					}
					$cacheModifyTime = filemtime($tplCache);
					$cacheTtl = self::$config['staticCache'][$staticCacheRoute] - ( time()-$cacheModifyTime );
					$cacheTtl = $cacheTtl>0 ? $cacheTtl : 0;
					$requestModifyTime= isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])-3600*8 : 0 ;
					$cacheExpire = $cacheModifyTime + self::$config['staticCache'][$staticCacheRoute];
					//echo $cacheModifyTime . "<br>";
					//echo $requestModifyTime . "<br>";
					//echo time();
					if ($cacheExpire > time()) {
						if ($cacheModifyTime <= $requestModifyTime ) {
							header("HTTP/1.1 304 Not Modified");
							header("Date: " . date('D, d M Y H:i:s', time()) . ' GMT');
							header("Last-Modified: " . date('D, d M Y H:i:s', $cacheModifyTime) . ' GMT');
							header("Cache-Control: max-age=" . $cacheTtl);
							header("Expires: ".date('D, d M Y H:i:s', $cacheExpire) . ' GMT');
							exit(0);
						}
						else{
							$content = file_get_contents($tplCache);
						}
					}

					break;
			}

			if (strlen($content)>0) {
				header("Date: " . date('D, d M Y H:i:s', time()) . ' GMT');
				header("Last-Modified: " . date('D, d M Y H:i:s', $cacheModifyTime) . ' GMT');
				header("Cache-Control: max-age=" . $cacheTtl);
				header("Expires: ".date('D, d M Y H:i:s', $cacheExpire) . ' GMT');
				echo $content;exit(0);
			}
		}
		self::$ctrlName = $requestRoute[0] . 'Ctrl';

		//检查路由是否存在
		if (class_exists(self::$ctrlName)){
			$C = new self::$ctrlName();
			if (method_exists($C, self::$methodName)){
				self::$ctrlName = $requestRoute[0];
				call_user_func(array($C, self::$methodName));
			}
			else{
				//E( 'None method:'.self::$methodName);
				_404();
			}
		}
		else{
			//控制器不存在
			//E( 'None Controller:' . self::$ctrlName);
			_404();
		}
	}
示例#4
0
文件: common.php 项目: Jnnock/myyyk
function S($str, $url = '', $wait = 3)
{
    if ($url == "") {
        $url = $_SERVER['HTTP_REFERER'];
        //"javascript:history.go(-1);";
    }
    if (isset(YYK::$config['tplHit']['S']) && file_exists(YYK::$APP_path . DIRECTORY_SEPARATOR . YYK::$config['tplHit']['S'])) {
        $content = file_get_contents(YYK::$APP_path . DIRECTORY_SEPARATOR . YYK::$config['tplHit']['S']);
    } else {
        $content = file_get_contents(YYK::getYYK_path() . '/tpl/S.html');
    }
    $content = str_replace('{$str}', $str, $content);
    $content = str_replace('{$url}', $url, $content);
    $content = str_replace('{$wait}', $wait, $content);
    echo $content;
    exit;
}