Skip to content

Commit b03d0fc

Browse files
authored
Merge pull request #3735 from Spuds/Working
Rework of the theme classes
2 parents 781f221 + 750b726 commit b03d0fc

File tree

9 files changed

+1624
-1436
lines changed

9 files changed

+1624
-1436
lines changed

bootstrap.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,18 @@ private function loadSettingsFile()
171171
$redirec_file = 'install.php';
172172
}
173173

174+
// To early for constants or autoloader
175+
require_once($boarddir . '/sources/ElkArte/Server.php');
176+
$server = new \ElkArte\Server($_SERVER);
177+
174178
$version_running = str_replace('ElkArte ', '', FORUM_VERSION);
175-
$proto = 'http' . (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on' ? 's' : '');
176-
$port = empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] === '80' ? '' : ':' . $_SERVER['SERVER_PORT'];
177-
$host = empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . $port : $_SERVER['HTTP_HOST'];
178-
$path = strtr(dirname($_SERVER['PHP_SELF']), '\\', '/') == '/' ? '' : strtr(dirname($_SERVER['PHP_SELF']), '\\', '/');
179+
$location = $server->supportsSSL() ? 'https://' : 'http://';
180+
$location .= $server->getHost();
181+
$temp = preg_replace('~/' . preg_quote(basename($boardurl . '/index.php'), '~') . '(/.+)?$~', '', str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])));
182+
$location .= ($temp !== '/') ? $temp : '';
179183

180184
// Too early to use Headers class etc.
181-
header('Location:' . $proto . '://' . $host . $path . '/install/' . $redirec_file . '?v=' . $version_running);
185+
header('Location:' . $location. '/install/' . $redirec_file . '?v=' . $version_running);
182186
die();
183187
}
184188
}

sources/ElkArte/Server.php

+22-8
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
*/
2424
class Server extends \ArrayObject
2525
{
26-
/** @var mixed */
26+
/** @var array */
2727
public $SERVER_SOFTWARE;
28-
29-
/** @var mixed */
28+
/** @var array */
3029
public $HTTPS;
31-
32-
/** @var mixed */
30+
/** @var array */
3331
public $SERVER_PORT;
3432

3533
/**
@@ -41,7 +39,7 @@ public function __construct($server = null)
4139
{
4240
if (!is_array($server))
4341
{
44-
$server = $_SERVER ?? array();
42+
$server = $_SERVER ?? [];
4543
}
4644

4745
parent::__construct($server, \ArrayObject::ARRAY_AS_PROPS);
@@ -211,12 +209,28 @@ public function outPutCompressionEnabled()
211209
public function supportsSSL()
212210
{
213211
return
214-
(isset($this->HTTPS) && ($this->HTTPS === 'on' || $this->HTTPS == 1))
212+
(isset($this->HTTPS) && ($this->HTTPS === 'on' || (int) $this->HTTPS === 1))
215213
|| (isset($this->REQUEST_SCHEME) && $this->REQUEST_SCHEME === 'https')
216-
|| (isset($this->SERVER_PORT) && $this->SERVER_PORT == 443)
214+
|| (isset($this->SERVER_PORT) && (int) $this->SERVER_PORT === 443)
217215
|| (isset($this->HTTP_X_FORWARDED_PROTO) && $this->HTTP_X_FORWARDED_PROTO === 'https');
218216
}
219217

218+
public function getHost()
219+
{
220+
$host = $this->HTTP_HOST;
221+
if (!$host)
222+
{
223+
$host = $this->SERVER_NAME;
224+
$port = (int) $this->SERVER_PORT;
225+
if ($port && $port !== 80 && $port !== 443)
226+
{
227+
$host .= ":$port";
228+
}
229+
}
230+
231+
return $host;
232+
}
233+
220234
/**
221235
* Try to determine a FQDN for the server
222236
*

0 commit comments

Comments
 (0)