diff --git a/core/classes/core.class.php b/core/classes/core.class.php index 5e3ed1c..c1d05cc 100644 --- a/core/classes/core.class.php +++ b/core/classes/core.class.php @@ -160,6 +160,13 @@ abstract class Core_Core extends Bootstrap */ protected static $change_project_callback = array(); + /** + * 使用 Core::url() 会附带的参数列表 + * + * @var array + */ + protected static $_url_auto_args = array(); + /** * 系统启动 * @@ -398,12 +405,31 @@ public static function url($uri = '' , $isfullurl_or_project = false) $url = Core::$base_url. ltrim($url, '/') . ($url!='' && substr($url,-1)!='/' && false===strpos($url, '.') && Core::$config['url_suffix']?Core::$config['url_suffix']:'') . ($query?'?'.$query:''); - // 返回完整URL - if ( true===$isfullurl_or_project && !preg_match('#^http(s)?://#i', $url) ) + # 返回完整URL + if (true===$isfullurl_or_project && !preg_match('#^http(s)?://#i', $url)) { $url = HttpIO::PROTOCOL . $_SERVER["HTTP_HOST"] . $url; } + # 添加自动追加的参数 + if (Core::$_url_auto_args) + { + list($url, $hash) = explode('#', $url, 2); + list($u, $q) = explode('?', $url, 2); + if (!$q) + { + $q = ''; + parse_str($q, $q); + $q += Core::$_url_auto_args; + } + else + { + $q = Core::$_url_auto_args; + } + + $url = $u .'?'. http_build_query($q, '', '&') . ($hash?'#'.$hash:''); + } + return $url; } @@ -433,6 +459,33 @@ public static function url_assets($uri = '') return $url_asstes . $url; } + /** + * 增加URL默认参数 + * + * 比如用在URL跟踪访客统计上,不支持Session的时候通过URL传送的SessionID等 + * + * 增加的参数在所有使用 `Core::url()` 返回的内容里都会附带这个参数 + * + * Core::add_url_args('debug', 'test'); + * + * Core::add_url_args(array('debug'=>'test', 't2'=>'v'2)); + * + * @param $key 参数名称 + * @param $value 参数值 + * @since v3.0 + */ + public static function add_url_args($key, $value) + { + if (is_array($key)) + { + Core::$_url_auto_args += $key; + } + else + { + Core::$_url_auto_args[$key] = $value; + } + } + /** * Include一个指定URI的控制器 * @@ -1472,12 +1525,13 @@ public static function show_500($msg = null) { if ($msg instanceof Exception) { - $error = $msg->getMessage(); + print_r($msg);exit; + $error = $msg->getMessage(); $trace_obj = $msg; } else { - $error = $msg; + $error = $msg; $trace_obj = new Exception($msg); } @@ -1594,7 +1648,7 @@ public static function show_500($msg = null) CRLF . 'Internal Server Error' . CRLF . '' . CRLF . '' . - CRLF . '

'.__('Internal Server Error').'

' . + CRLF . '

Internal Server Error

' . CRLF . '

The requested URL ' . $REQUEST_URI . ' was error on this server.

' . CRLF . '
' . CRLF . $_SERVER['SERVER_SIGNATURE'] .