孙民选个人论坛

鏍囬: 鍩烘湰鏂囦欢base.php -CACHE_PATH,HTTP_REFERER,SYS_TIME,WEB_PATH,JS_PATH,IMG_PATH [鎵撳嵃鏈〉]

浣滆: admin    鏃堕棿: 2017-11-3 00:56
鏍囬: 鍩烘湰鏂囦欢base.php -CACHE_PATH,HTTP_REFERER,SYS_TIME,WEB_PATH,JS_PATH,IMG_PATH
<?php
/**
*  base.php PHPCMS妗嗘灦鍏ュ彛鏂囦欢
*
* @copyright                        (C) 2005-2010 PHPCMS
* @license                                http://www.phpcms.cn/license/
* @lastmodify                        2010-6-7
*/
define('IN_PHPCMS', true);

//PHPCMS妗嗘灦璺緞
define('PC_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);

if(!defined('PHPCMS_PATH')) define('PHPCMS_PATH', PC_PATH.'..'.DIRECTORY_SEPARATOR);

//缂撳瓨鏂囦欢澶瑰湴鍧
define('CACHE_PATH', PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR);
//涓绘満鍗忚
define('SITE_PROTOCOL', isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');
//褰撳墠璁块棶鐨勪富鏈哄悕
define('SITE_URL', (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''));
//鏉ユ簮
define('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');

//绯荤粺寮濮嬫椂闂
define('SYS_START_TIME', microtime());

//鍔犺浇鍏敤鍑芥暟搴
pc_base::load_sys_func('global');
pc_base::load_sys_func('extention');
pc_base::auto_load_func();

pc_base::load_config('system','errorlog') ? set_error_handler('my_error_handler') : error_reporting(E_ERROR | E_WARNING | E_PARSE);
//璁剧疆鏈湴鏃跺樊
function_exists('date_default_timezone_set') && date_default_timezone_set(pc_base::load_config('system','timezone'));

define('CHARSET' ,pc_base::load_config('system','charset'));
//杈撳嚭椤甸潰瀛楃闆
header('Content-type: text/html; charset='.CHARSET);

define('SYS_TIME', time());
//瀹氫箟缃戠珯鏍硅矾寰
define('WEB_PATH',pc_base::load_config('system','web_path'));
//js 璺緞
define('JS_PATH',pc_base::load_config('system','js_path'));
//css 璺緞
define('CSS_PATH',pc_base::load_config('system','css_path'));
//img 璺緞
define('IMG_PATH',pc_base::load_config('system','img_path'));
//鍔ㄦ佺▼搴忚矾寰
define('APP_PATH',pc_base::load_config('system','app_path'));

//搴旂敤闈欐佹枃浠惰矾寰
define('PLUGIN_STATICS_PATH',WEB_PATH.'statics/plugin/');

if(pc_base::load_config('system','gzip') && function_exists('ob_gzhandler')) {
        ob_start('ob_gzhandler');
} else {
        ob_start();
}

class pc_base {
        
        /**
         * 鍒濆鍖栧簲鐢ㄧ▼搴
         */
        public static function creat_app() {
                return self::load_sys_class('application');
        }
        /**
         * 鍔犺浇绯荤粺绫绘柟娉
         * @param string $classname 绫诲悕
         * @param string $path 鎵╁睍鍦板潃
         * @param intger $initialize 鏄惁鍒濆鍖
         */
        public static function load_sys_class($classname, $path = '', $initialize = 1) {
                        return self::_load_class($classname, $path, $initialize);
        }
        
        /**
         * 鍔犺浇搴旂敤绫绘柟娉
         * @param string $classname 绫诲悕
         * @param string $m 妯″潡
         * @param intger $initialize 鏄惁鍒濆鍖
         */
        public static function load_app_class($classname, $m = '', $initialize = 1) {
                $m = empty($m) && defined('ROUTE_M') ? ROUTE_M : $m;
                if (empty($m)) return false;
                return self::_load_class($classname, 'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.'classes', $initialize);
        }
        
        /**
         * 鍔犺浇鏁版嵁妯″瀷
         * @param string $classname 绫诲悕
         */
        public static function load_model($classname) {
                return self::_load_class($classname,'model');
        }
               
        /**
         * 鍔犺浇绫绘枃浠跺嚱鏁
         * @param string $classname 绫诲悕
         * @param string $path 鎵╁睍鍦板潃
         * @param intger $initialize 鏄惁鍒濆鍖
         */
        private static function _load_class($classname, $path = '', $initialize = 1) {
                static $classes = array();
                if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'classes';

                $key = md5($path.$classname);
                if (isset($classes[$key])) {
                        if (!empty($classes[$key])) {
                                return $classes[$key];
                        } else {
                                return true;
                        }
                }
                if (file_exists(PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php')) {
                        include PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php';
                        $name = $classname;
                        if ($my_path = self::my_path(PC_PATH.$path.DIRECTORY_SEPARATOR.$classname.'.class.php')) {
                                include $my_path;
                                $name = 'MY_'.$classname;
                        }
                        if ($initialize) {
                                $classes[$key] = new $name;
                        } else {
                                $classes[$key] = true;
                        }
                        return $classes[$key];
                } else {
                        return false;
                }
        }
        
        /**
         * 鍔犺浇绯荤粺鐨勫嚱鏁板簱
         * @param string $func 鍑芥暟搴撳悕
         */
        public static function load_sys_func($func) {
                return self::_load_func($func);
        }
        
        /**
         * 鑷姩鍔犺浇autoload鐩綍涓嬪嚱鏁板簱
         * @param string $func 鍑芥暟搴撳悕
         */
        public static function auto_load_func($path='') {
                return self::_auto_load_func($path);
        }
        
        /**
         * 鍔犺浇搴旂敤鍑芥暟搴
         * @param string $func 鍑芥暟搴撳悕
         * @param string $m 妯″瀷鍚
         */
        public static function load_app_func($func, $m = '') {
                $m = empty($m) && defined('ROUTE_M') ? ROUTE_M : $m;
                if (empty($m)) return false;
                return self::_load_func($func, 'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.'functions');
        }
        
        /**
         * 鍔犺浇鎻掍欢绫诲簱
         */
        public static function load_plugin_class($classname, $identification = '' ,$initialize = 1) {
                $identification = empty($identification) && defined('PLUGIN_ID') ? PLUGIN_ID : $identification;
                if (empty($identification)) return false;
                return pc_base::load_sys_class($classname, 'plugin'.DIRECTORY_SEPARATOR.$identification.DIRECTORY_SEPARATOR.'classes', $initialize);
        }
        
        /**
         * 鍔犺浇鎻掍欢鍑芥暟搴
         * @param string $func 鍑芥暟鏂囦欢鍚嶇О
         * @param string $identification 鎻掍欢鏍囪瘑
         */
        public static function load_plugin_func($func,$identification) {
                static $funcs = array();
                $identification = empty($identification) && defined('PLUGIN_ID') ? PLUGIN_ID : $identification;
                if (empty($identification)) return false;
                $path = 'plugin'.DIRECTORY_SEPARATOR.$identification.DIRECTORY_SEPARATOR.'functions'.DIRECTORY_SEPARATOR.$func.'.func.php';
                $key = md5($path);
                if (isset($funcs[$key])) return true;
                if (file_exists(PC_PATH.$path)) {
                        include PC_PATH.$path;
                } else {
                        $funcs[$key] = false;
                        return false;
                }
                $funcs[$key] = true;
                return true;
        }
        
        /**
         * 鍔犺浇鎻掍欢鏁版嵁妯″瀷
         * @param string $classname 绫诲悕
         */
        public static function load_plugin_model($classname,$identification) {
                $identification = empty($identification) && defined('PLUGIN_ID') ? PLUGIN_ID : $identification;
                $path = 'plugin'.DIRECTORY_SEPARATOR.$identification.DIRECTORY_SEPARATOR.'model';
                return self::_load_class($classname,$path);
        }
        
        /**
         * 鍔犺浇鍑芥暟搴
         * @param string $func 鍑芥暟搴撳悕
         * @param string $path 鍦板潃
         */
        private static function _load_func($func, $path = '') {
                static $funcs = array();
                if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'functions';
                $path .= DIRECTORY_SEPARATOR.$func.'.func.php';
                $key = md5($path);
                if (isset($funcs[$key])) return true;
                if (file_exists(PC_PATH.$path)) {
                        include PC_PATH.$path;
                } else {
                        $funcs[$key] = false;
                        return false;
                }
                $funcs[$key] = true;
                return true;
        }
        
        /**
         * 鍔犺浇鍑芥暟搴
         * @param string $func 鍑芥暟搴撳悕
         * @param string $path 鍦板潃
         */
        private static function _auto_load_func($path = '') {
                if (empty($path)) $path = 'libs'.DIRECTORY_SEPARATOR.'functions'.DIRECTORY_SEPARATOR.'autoload';
                $path .= DIRECTORY_SEPARATOR.'*.func.php';
                $auto_funcs = glob(PC_PATH.DIRECTORY_SEPARATOR.$path);
                if(!empty($auto_funcs) && is_array($auto_funcs)) {
                        foreach($auto_funcs as $func_path) {
                                include $func_path;
                        }
                }
        }
        /**
         * 鏄惁鏈夎嚜宸辩殑鎵╁睍鏂囦欢
         * @param string $filepath 璺緞
         */
        public static function my_path($filepath) {
                $path = pathinfo($filepath);
                if (file_exists($path['dirname'].DIRECTORY_SEPARATOR.'MY_'.$path['basename'])) {
                        return $path['dirname'].DIRECTORY_SEPARATOR.'MY_'.$path['basename'];
                } else {
                        return false;
                }
        }
        
        /**
         * 鍔犺浇閰嶇疆鏂囦欢
         * @param string $file 閰嶇疆鏂囦欢
         * @param string $key  瑕佽幏鍙栫殑閰嶇疆鑽
         * @param string $default  榛樿閰嶇疆銆傚綋鑾峰彇閰嶇疆椤圭洰澶辫触鏃惰鍊煎彂鐢熶綔鐢ㄣ
         * @param boolean $reload 寮哄埗閲嶆柊鍔犺浇銆
         */
        public static function load_config($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 = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.$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;
                }
        }
}
浣滆: admin    鏃堕棿: 2017-11-3 01:09
PC_PATH
CACHE_PATH  
SITE_PROTOCOL
SITE_URL
HTTP_REFERER
SYS_START_TIME
CHARSET
SYS_TIME
define('WEB_PATH',pc_base::load_config('system','web_path'));
//js 璺緞
define('JS_PATH',pc_base::load_config('system','js_path'));
//css 璺緞
define('CSS_PATH',pc_base::load_config('system','css_path'));
//img 璺緞
define('IMG_PATH',pc_base::load_config('system','img_path'));
//鍔ㄦ佺▼搴忚矾寰
define('APP_PATH',pc_base::load_config('system','app_path'));




娆㈣繋鍏変复 孙民选个人论坛 (http://www.sunminxuan.cn/bbs/) Powered by Discuz! X3.4