|
@@ -40,13 +40,15 @@ class Url
|
|
|
*/
|
|
|
public static function getPathInfo()
|
|
|
{
|
|
|
- if(PATH_INFO) return PATH_INFO;
|
|
|
-
|
|
|
- $path = pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME);
|
|
|
- $pathinfo = $_SERVER['REQUEST_URI'];
|
|
|
- if (substr($_SERVER['REQUEST_URI'], 0, strlen($path)) == $path) {
|
|
|
- $pathinfo = substr($_SERVER['REQUEST_URI'], strlen($path));
|
|
|
- }
|
|
|
+ if (PATH_INFO) {
|
|
|
+ return PATH_INFO;
|
|
|
+ }
|
|
|
+
|
|
|
+ $path = pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME);
|
|
|
+ $pathinfo = $_SERVER['REQUEST_URI'];
|
|
|
+ if (substr($_SERVER['REQUEST_URI'], 0, strlen($path)) == $path) {
|
|
|
+ $pathinfo = substr($_SERVER['REQUEST_URI'], strlen($path));
|
|
|
+ }
|
|
|
return explode('?', $pathinfo)[0];
|
|
|
}
|
|
|
|
|
@@ -80,7 +82,7 @@ class Url
|
|
|
$host = \Qii\Request\Url::getInstance($rewriteRule)->request->getWebHost();
|
|
|
$domain = parse_url($host)['host'] ?? "";
|
|
|
|
|
|
- if(stristr($domain,".")) {
|
|
|
+ if (stristr($domain, ".")) {
|
|
|
return explode(".", $domain)[0];
|
|
|
}
|
|
|
return "";
|
|
@@ -122,14 +124,20 @@ class Url
|
|
|
if (isset($query['query'])) {
|
|
|
parse_str($query['query'], $params);
|
|
|
}
|
|
|
- if ($url == '/') $url = 'index';
|
|
|
+
|
|
|
+ if ($url == '/') {
|
|
|
+ $url = 'index';
|
|
|
+ }
|
|
|
if ($ext == null) {
|
|
|
$ext = '';
|
|
|
}
|
|
|
- $query = count($params) > 0 ? '?' . http_build_query($params) : '';
|
|
|
//去掉url中末尾的扩展名,避免重复
|
|
|
$url = preg_replace('/' . $ext . '$/', '', $url);
|
|
|
- return rtrim(self::pathUrl(), '/') . '/' . ltrim($url, '/') . $ext . (count($params) > 0 ? '?' . http_build_query($params) : '');
|
|
|
+ $url = rtrim(self::pathUrl(), '/') . '/' . ltrim($url, '/') . $ext . (count($params) > 0 ? '?' . http_build_query($params) : '');
|
|
|
+ if (isset($query['fragment']) && !empty($query['fragment'])) {
|
|
|
+ $url .= "#". $query['fragment'];
|
|
|
+ }
|
|
|
+ return $url;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -170,7 +178,9 @@ class Url
|
|
|
public static function refererFromCurrentSite($currentURL = null)
|
|
|
{
|
|
|
$referer = self::getRefererURL();
|
|
|
- if (!$currentURL) $currentURL = self::getCurrentURL();
|
|
|
+ if (!$currentURL) {
|
|
|
+ $currentURL = self::getCurrentURL();
|
|
|
+ }
|
|
|
if (parse_url($referer, PHP_URL_HOST) != parse_url($currentURL, PHP_URL_HOST)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -187,5 +197,4 @@ class Url
|
|
|
}
|
|
|
return call_user_func_array(array($this->request, $method), $args);
|
|
|
}
|
|
|
-
|
|
|
}
|