Skip to content

Commit

Permalink
Null coalescing for $_SERVER keys in e107_class.php
Browse files Browse the repository at this point in the history
Removes CLI-invoked E_NOTICE in:
* e107::prepare_request()
* e107::set_constants()
* e107::set_urls()
  • Loading branch information
Deltik committed Jan 17, 2020
1 parent b9d4961 commit be36462
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions e107_handlers/e107_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3852,7 +3852,12 @@ public function prepare_request($checkS = true)
if(isset($GLOBALS['_E107']) && is_array($GLOBALS['_E107'])) $this->_E107 = & $GLOBALS['_E107'];

// remove ajax_used=1 from query string to avoid SELF problems, ajax should always be detected via e_AJAX_REQUEST constant
$_SERVER['QUERY_STRING'] = trim(str_replace(array('ajax_used=1', '&&'), array('', '&'), $_SERVER['QUERY_STRING']), '&');
$_SERVER['QUERY_STRING'] = trim(
str_replace(
array('ajax_used=1', '&&'),
array('', '&'),
(isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '')
), '&');

/* PathInfo doesn't break anything, URLs should be always absolute. Disabling the below forever.
// e107 uses relative url's, which are broken by "pretty" URL's. So for now we don't support / after .php
Expand Down Expand Up @@ -4100,13 +4105,16 @@ public function set_constants()
$subdomain = false;

// Define the domain name and subdomain name.
if(is_numeric(str_replace(".","",$_SERVER['HTTP_HOST'])))
if (is_numeric(str_replace(".", "",
(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')
)))
{
$domain = false;
$subdomain = false;
}
else
{
$_SERVER['SERVER_NAME'] = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
$host = !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$domain = preg_replace('/^www\.|:\d*$/', '', $host); // remove www. and port numbers.

Expand Down Expand Up @@ -4182,9 +4190,12 @@ public function set_paths()
{
// ssl_enabled pref not needed anymore, scheme is auto-detected
$this->HTTP_SCHEME = 'http';
if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443)
if (
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ||
(!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)
)
{
$this->HTTP_SCHEME = 'https';
$this->HTTP_SCHEME = 'https';
}

$path = ""; $i = 0;
Expand Down Expand Up @@ -4232,6 +4243,7 @@ public function set_paths()


$this->relative_base_path = (!self::isCli()) ? $path : e_ROOT;
$_SERVER['HTTP_HOST'] = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
$this->http_path = filter_var("http://{$_SERVER['HTTP_HOST']}{$this->server_path}", FILTER_SANITIZE_URL);
$this->https_path = filter_var("https://{$_SERVER['HTTP_HOST']}{$this->server_path}", FILTER_SANITIZE_URL);

Expand Down Expand Up @@ -4518,6 +4530,7 @@ public function set_urls($no_cbrace = true)
$isPluginDir = strpos($_self,'/'.$PLUGINS_DIRECTORY) !== FALSE; // True if we're in a plugin
$e107Path = str_replace($this->base_path, '', $_self); // Knock off the initial bits
$curPage = basename($_SERVER['SCRIPT_FILENAME']);
$_SERVER['REQUEST_URI'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';

if (
(!$isPluginDir && strpos($e107Path, $ADMIN_DIRECTORY) === 0 ) // Core admin directory
Expand Down

0 comments on commit be36462

Please sign in to comment.