|
@@ -24,7 +24,13 @@ function site_url()
|
|
|
|
|
|
|
|
function generateSiteUrl()
|
|
function generateSiteUrl()
|
|
|
{
|
|
{
|
|
|
- $dir = trim(dirname(substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"]))), '/');
|
|
|
|
|
|
|
+ // Collapse repeated slashes and strip by prefix, not by string length: some
|
|
|
|
|
+ // hosts hand PHP a SCRIPT_FILENAME whose leading slash is doubled, which
|
|
|
|
|
+ // makes a length-based substr() slice one character into the real path.
|
|
|
|
|
+ $root = rtrim(preg_replace('#/+#', '/', $_SERVER["DOCUMENT_ROOT"]), '/');
|
|
|
|
|
+ $script = preg_replace('#/+#', '/', $_SERVER["SCRIPT_FILENAME"]);
|
|
|
|
|
+ $relative = strpos($script, $root . '/') === 0 ? substr($script, strlen($root)) : $script;
|
|
|
|
|
+ $dir = trim(dirname($relative), '/');
|
|
|
if ($dir == '.' || $dir == '..') {
|
|
if ($dir == '.' || $dir == '..') {
|
|
|
$dir = '';
|
|
$dir = '';
|
|
|
}
|
|
}
|
|
@@ -41,12 +47,10 @@ function generateSiteUrl()
|
|
|
|
|
|
|
|
function site_path()
|
|
function site_path()
|
|
|
{
|
|
{
|
|
|
- static $_path;
|
|
|
|
|
-
|
|
|
|
|
- if (!$_path)
|
|
|
|
|
- $_path = rtrim(parse_url(site_url(), PHP_URL_PATH), '/');
|
|
|
|
|
-
|
|
|
|
|
- return $_path;
|
|
|
|
|
|
|
+ // Not cached in a static: session.php calls this during autoload, before
|
|
|
|
|
+ // config/config.ini is loaded, which would pin the auto-detected path and
|
|
|
|
|
+ // make [site.url] ineffective for routing.
|
|
|
|
|
+ return rtrim(parse_url(site_url(), PHP_URL_PATH), '/');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function theme_path()
|
|
function theme_path()
|