Beispiel #1
0
 /**
  * url检查
  *
  * 当$absolute === true且url不包含协议部分时,默认加上当前应用的协议部分.
  *
  * @param string $url 需要检查合法性的url
  * @param boolean $absolute 是否为绝对路径
  * @return string
  */
 public static function check_url($url, $absolute = true)
 {
     if ($absolute) {
         $_baseUrl = $absolute === true ? Base_Request::get_base_url(true) : $absolute;
         if (strpos($url, '://') === false) {
             $url = trim($_baseUrl, '/') . '/' . trim($url, '/');
         }
     }
     return $url;
 }
Beispiel #2
0
 public function _initialize()
 {
     if (C('router', SITE_HOST)) {
         // 加载基于域名的URL 路由配置
         $this->_config = C('router', SITE_HOST);
         define('SUB_DOMAIN', strtolower(substr(SITE_HOST, 0, strpos(SITE_HOST, '.'))));
         // 二级域名定义
         $this->params = array('action' => 2, 'controller' => 1);
     } else {
         // 使用默认路由配置
         $this->_config = C('router', 'default');
     }
     $full_url = Base_Request::get_host_info() . Base_Request::get_request_uri();
     $this->_pathinfo = $_pathinfo = trim(str_replace(Base_Request::get_base_url(true), '', $full_url), '/');
 }
Beispiel #3
0
 /**
  * 框架初始化
  */
 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();
         }
     }
 }
Beispiel #4
0
 /**
  * (non-PHPdoc)
  *
  * @see Base_Router::_initialize()
  */
 public function _initialize()
 {
     $this->_config = C('router', 'api');
     $full_url = Base_Request::get_host_info() . Base_Request::get_request_uri();
     $this->_pathinfo = $_pathinfo = trim(str_replace(Base_Request::get_base_url(true), '', $full_url), '/');
 }