Skip to content

Commit

Permalink
Fix for issue #1055
Browse files Browse the repository at this point in the history
  • Loading branch information
mystralkk committed Jan 12, 2022
1 parent 2b3ce62 commit 58d56c1
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 65 deletions.
63 changes: 1 addition & 62 deletions public_html/lib-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -6984,69 +6984,8 @@ function COM_isAjax()
function COM_getCurrentURL()
{
global $_CONF;
static $thisUrl;

if ($thisUrl !== null) {
return $thisUrl;
}

$thisUrl = '';

if (empty($_SERVER['SCRIPT_URI'])) {
if (!empty($_SERVER['DOCUMENT_URI'])) {
$document_uri = $_SERVER['DOCUMENT_URI'];
$firstSlash = strpos($_CONF['site_url'], '/');

if ($firstSlash === false) {
// special case - assume it's okay
$thisUrl = $_CONF['site_url'] . $document_uri;
} elseif ($firstSlash + 1 == strrpos($_CONF['site_url'], '/')) {
// site is in the document root
$thisUrl = $_CONF['site_url'] . $document_uri;
} else {
// extract server name first
$pos = strpos($_CONF['site_url'], '/', $firstSlash + 2);
$thisUrl = substr($_CONF['site_url'], 0, $pos) . $document_uri;
}
}
} else {
$thisUrl = $_SERVER['SCRIPT_URI'];
}

if (!empty($thisUrl) && !empty($_SERVER['QUERY_STRING'])) {
$thisUrl .= '?' . $_SERVER['QUERY_STRING'];
}

if (empty($thisUrl)) {
$requestUri = $_SERVER['REQUEST_URI'];
if (empty($_SERVER['REQUEST_URI'])) {
if (empty($_SERVER['PATH_INFO'])) {
$requestUri = $_SERVER['SCRIPT_NAME'];
} else {
$requestUri = $_SERVER['PATH_INFO'];
}

if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
}

$firstSlash = strpos($_CONF['site_url'], '/');

if ($firstSlash === false) {
// special case - assume it's okay
$thisUrl = $_CONF['site_url'] . $requestUri;
} elseif ($firstSlash + 1 == strrpos($_CONF['site_url'], '/')) {
// site is in the document root
$thisUrl = $_CONF['site_url'] . $requestUri;
} else {
// extract server name first
$pos = strpos($_CONF['site_url'], '/', $firstSlash + 2);
$thisUrl = substr($_CONF['site_url'], 0, $pos) . $requestUri;
}
}

return $thisUrl;
return Url::getCurrentURL($_CONF['site_url']);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions system/classes/router.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,13 @@ public static function dispatch()
return false;
}

// $_SERVER['PATH_INFO'] is unavailable
if (empty($_SERVER['PATH_INFO'])) {
// Get $_SERVER['PATH_INFO']
$pathInfo = Url::getPathInfo($_CONF['site_url']);
if (empty($pathInfo) || ($pathInfo === '/')) {
return false;
}

$pathInfo = COM_applyBasicFilter($_SERVER['PATH_INFO']);
$pathInfo = COM_applyBasicFilter($pathInfo);
// Note: For URL Routing with no "Index.php" and when Geeklog site url has a sub directory the rules in the Route Manager
// need to be updated to include the sub directory in the rule part only (not the route).
// At some point we should look into striping the sub directory from the pathinfo for this case only instead of having the Admins do
Expand Down
96 changes: 96 additions & 0 deletions system/classes/url.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,100 @@ public function setEnabled($switch)
{
$this->urlRewrite = (bool) $switch;
}

/**
* Return the current URL
*
* @param string $siteUrl
* @return string
*/
public static function getCurrentURL($siteUrl)
{
static $thisUrl;

if ($thisUrl !== null) {
return $thisUrl;
}

$thisUrl = '';

if (empty($_SERVER['SCRIPT_URI'])) {
if (!empty($_SERVER['DOCUMENT_URI'])) {
$document_uri = $_SERVER['DOCUMENT_URI'];
$firstSlash = strpos($siteUrl, '/');

if ($firstSlash === false) {
// special case - assume it's okay
$thisUrl = $siteUrl . $document_uri;
} elseif ($firstSlash + 1 == strrpos($siteUrl, '/')) {
// site is in the document root
$thisUrl = $siteUrl . $document_uri;
} else {
// extract server name first
$pos = strpos($siteUrl, '/', $firstSlash + 2);
$thisUrl = substr($siteUrl, 0, $pos) . $document_uri;
}
}
} else {
$thisUrl = $_SERVER['SCRIPT_URI'];
}

if (!empty($thisUrl) && !empty($_SERVER['QUERY_STRING'])) {
$thisUrl .= '?' . $_SERVER['QUERY_STRING'];
}

if (empty($thisUrl)) {
$requestUri = $_SERVER['REQUEST_URI'];
if (empty($_SERVER['REQUEST_URI'])) {
if (empty($_SERVER['PATH_INFO'])) {
$requestUri = $_SERVER['SCRIPT_NAME'];
} else {
$requestUri = $_SERVER['PATH_INFO'];
}

if (!empty($_SERVER['QUERY_STRING'])) {
$requestUri .= '?' . $_SERVER['QUERY_STRING'];
}
}

$firstSlash = strpos($siteUrl, '/');

if ($firstSlash === false) {
// special case - assume it's okay
$thisUrl = $siteUrl . $requestUri;
} elseif ($firstSlash + 1 == strrpos($siteUrl, '/')) {
// site is in the document root
$thisUrl = $siteUrl . $requestUri;
} else {
// extract server name first
$pos = strpos($siteUrl, '/', $firstSlash + 2);
$thisUrl = substr($siteUrl, 0, $pos) . $requestUri;
}
}

return $thisUrl;
}

/**
* Return $_SERVER['PATH_INFO']
*
* @param string $siteUrl
* @return string
*/
public static function getPathInfo($siteUrl)
{
if (isset($_SERVER['PATH_INFO'])) {
return $_SERVER['PATH_INFO'];
} else {
$retval = str_replace($siteUrl, '', self::getCurrentURL($siteUrl));

if (preg_match('@^.+?\.php/@i', $retval, $match)) {
$retval = '/' . str_replace($match[0], '', $retval);
} elseif (($retval !== '') && (strpos($retval, '/') !== 0)) {
$retval = '/' . $retval;
}

return $retval;
}
}
}

0 comments on commit 58d56c1

Please sign in to comment.