Skip to content

Commit

Permalink
Made COM_onFrontpage() more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
mystralkk committed Jan 22, 2022
1 parent 3872ecc commit 57cf1a4
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions public_html/lib-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -7001,21 +7001,25 @@ function COM_getCurrentURL()
function COM_onFrontpage()
{
global $_CONF, $page;
static $onFrontPage = null; // Cache the result since this function is called many times

// Some plugin may still be using Global $topic variable so check and update $_USER array as needed
_depreciatedCheckGlobalTopicVariableUsed();
// Some plugin may still be using Global $topic variable so check and update $_USER array as needed
_depreciatedCheckGlobalTopicVariableUsed();

// Note: We can't use $PHP_SELF here since the site may not be in the DocumentRoot
$onFrontPage = false;
if ($onFrontPage === null) {
// Note: We can't use $PHP_SELF here since the site may not be in the DocumentRoot
$onFrontPage = false;

$current_topic = TOPIC_currentTopic();
$current_topic = TOPIC_currentTopic();

$scriptName = empty($_SERVER['PATH_INFO']) ? $_SERVER['SCRIPT_NAME'] : $_SERVER['PATH_INFO'];
preg_match('/\/\/[^\/]*(.*)/', $_CONF['site_url'], $pathonly);
if (($scriptName == $pathonly[1] . '/index.php') &&
empty($current_topic) && (empty($page) || ($page == 1))
) {
$onFrontPage = true;
$scriptName = empty($_SERVER['PATH_INFO']) ? $_SERVER['SCRIPT_NAME'] : $_SERVER['PATH_INFO'];
$posDoubleSlashes = strpos($_CONF['site_url'], '//');
$posSlash = strpos($_CONF['site_url'], '/', $posDoubleSlashes + 2);
$pathOnly = substr($_CONF['site_url'], $posSlash);

if (($scriptName == $pathOnly . '/index.php') && empty($current_topic) && (empty($page) || ($page == 1))) {
$onFrontPage = true;
}
}

return $onFrontPage;
Expand Down

0 comments on commit 57cf1a4

Please sign in to comment.