defined('IN') or exit('Access Denied.'); //路径分隔符 define('DS', DIRECTORY_SEPARATOR); //系统路径 define('SYSDIR', dirname(__FILE__).DS); //网站跟路径 defined('BASEDIR') or define('BASEDIR', realpath(SYSDIR.'..'.DS).DS); //defined('BASEDIR') or define('BASEDIR', realpath(SYSDIR.'..'.DS)); //缓存路径 define('CACHEDIR', BASEDIR.'caches'.DS); //来源 define('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); //主机协议 define('SITE_PROTOCOL', isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://'); //当前访问的主机名 define('SITE_URL', (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')); //系统时间 define('SYS_TIME', time()); //来源URL define('REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); //加载函数库 Ck::loadFunc('global', 'sys'); Ck::loadFunc('ext', 'sys'); //网站url define('BASEURL', SITE_PROTOCOL.SITE_URL.'/'); define('_BASEURL', SITE_PROTOCOL.SITE_URL); //静态资源路径 define('STATICDIR', BASEURL.'statics/'); //主题路径 define('THEME', BASEURL.'theme/'); class Ck { //初始化webApp public static function webApp() { return self::loadClass('App', 'sys'); } /** * 类加载 * @param string:$className 类名 * @param string:$classType 类 类型 sys/app/model * @param string:$moduleName 模块名 * @param int:$initialize 是否生成实例 */ public static function loadClass($className, $classType, $moduleName='', $initialize=1) { static $classes = array(); if(preg_match("/_/", $className)) { $explode = explode('_', $className); foreach($explode as $k=>$v) { $explode[$k] = ucfirst($v); } $className = implode('', $explode); } if($classType == 'sys') { $path = 'libs'.DS.'classes'.DS; }elseif($classType == 'app') { $m = empty($moduleName) && defined('M') ? M : $moduleName; if(empty($m)) return false; $path = 'modules'.DS.$m.DS.'classes'.DS; }elseif($classType == 'model') { $m = empty($moduleName) && defined('M') ? M : $moduleName; if(empty($m)) return false; $path = 'modules'.DS.$m.DS.'models'.DS; }else { return false; } $key = md5($path.ucfirst($className)); if(isset($classes[$key])) { if(!empty($classes[$key])) { return $classes[$key]; }else { return true; } } $file = SYSDIR.$path.ucfirst($className).'.class.php'; if(file_exists($file)) { include $file; if($initialize) { $classes[$key] = new $className; }else { $classes[$key] = true; } return $classes[$key]; }else { return false; } } public static function loadFunc($funcName, $funcType, $moduleName='') { static $funcs = array(); if($funcType == 'sys') { $file = 'libs'.DS.'functions'.DS.$funcName.'.func.php'; }elseif($funcType == 'app') { $m = empty($moduleName) && defined('M') ? M : $moduleName; if(empty($m)) return false; $file = 'modules'.DS.$m.DS.'functions'.DS.$func.'.func.php'; }else { return false; } $key = md5($file); if(isset($funcs[$key])) { return true; } if(file_exists(SYSDIR.$file)) { include $file; }else { $funcs[$key] = false; return false; } $func[$key] = true; return true; } /** * 加载配置文件 * @param string $file 配置文件 * @param string $key 要获取的配置荐 * @param string $default 默认配置。当获取配置项目失败时该值发生作用。 * @param boolean $reload 强制重新加载。 */ public static function loadConfig($file, $key = '', $default = '', $reload = false) { static $configs = array(); if (!$reload && isset($configs[$file])) { if (empty($key)) { return $configs[$file]; }elseif (isset($configs[$file][$key])) { return $configs[$file][$key]; }else { return $default; } } $path = CACHEDIR.'configs'.DS.$file.'.php'; if (file_exists($path)) { $configs[$file] = include $path; } if (empty($key)) { return $configs[$file]; }elseif (isset($configs[$file][$key])) { return $configs[$file][$key]; }else { return $default; } } }