예제 #1
0
파일: kernel.php 프로젝트: hubs/yuncms
 /**
  * 框架初始化
  */
 public static function init()
 {
     spl_autoload_register('Core::autoLoad');
     if (!defined('CORE_FUNCTION') && !@(include FW_PATH . 'func.php')) {
         exit('func.php is missing');
     }
     if (!defined('CUSTOM_FUNCTION') && !@(include FW_PATH . 'custom.php')) {
         exit('custom.php is missing');
     }
     if (C('config', 'debug', false)) {
         define('IS_DEBUG', true);
         error_reporting(E_ALL);
     } else {
         define('IS_DEBUG', false);
         error_reporting(0);
     }
     set_error_handler('Core::_errorHandle', error_reporting());
     set_exception_handler('Core::_exceptionHandle');
     register_shutdown_function('Core::_shutdownHandle');
     if (function_exists('date_default_timezone_set')) {
         @date_default_timezone_set(C('config', 'timezone', 'Etc/GMT-8'));
     }
     define('TIME', time());
     define('IP', Base_Request::get_client_ip());
     define('CHARSET', C('config', 'charset', 'UTF-8'));
     define('PHP_FILE', Base_Request::get_script_url());
     define('SCRIPT_NAME', basename(PHP_FILE));
     define('WEB_PATH', substr(PHP_FILE, 0, strrpos(PHP_FILE, '/')) . '/');
     mb_internal_encoding(CHARSET);
     if (MAGIC_QUOTES_GPC) {
         $_POST = String::stripslashes($_POST);
         $_GET = String::stripslashes($_GET);
         $_COOKIE = String::stripslashes($_COOKIE);
         $_REQUEST = String::stripslashes($_REQUEST);
     }
     if (isset($_GET['page'])) {
         $_GET['page'] = max(intval($_GET['page']), 1);
     }
     if (!IS_CLI) {
         /* 协议 */
         define('SITE_PROTOCOL', Base_Request::get_scheme() . '://');
         /* 主机名 */
         define('SITE_HOST', Base_Request::get_server_name());
         /* 基础URL */
         define('SITE_URL', htmlspecialchars(Base_Request::get_base_url(true)) . '/');
         /* 设置来源 */
         define('HTTP_REFERER', Base_Request::get_url_referer());
         define('REQUEST_METHOD', Base_Request::get_request_method());
         define('IS_GET', Base_Request::is_get());
         define('IS_POST', Base_Request::is_post());
         define('IS_PUT', Base_Request::is_put());
         define('IS_DELETE', Base_Request::is_delete());
         define('IS_AJAX', Base_Request::is_ajax());
         @header('Content-Type: text/html; charset=' . CHARSET);
         @header('X-Powered-By: PHP/' . PHP_VERSION . ' Leaps/' . LEAPS_VERSION);
         // 页面压缩输出支持
         if (C('config', 'gzip', true) && function_exists('ob_gzhandler')) {
             ob_start('ob_gzhandler');
         } else {
             ob_start();
         }
     }
 }