From b21bf52e4d1a55dcb704c063644418c9a98073b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20BENO=C3=8ET?= Date: Sun, 5 Jan 2025 19:04:03 +0100 Subject: [PATCH] feat: make server root configurable --- includes/core/page.inc.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/includes/core/page.inc.php b/includes/core/page.inc.php index f963a3b..d35a7d3 100644 --- a/includes/core/page.inc.php +++ b/includes/core/page.inc.php @@ -10,10 +10,7 @@ abstract class Page public function __construct( ) { - $this->baseURL = dirname( $_SERVER[ 'SCRIPT_NAME' ] ); - if ( $this->baseURL == '/' ) { - $this->baseURL = ''; - } + $this->baseURL = rtrim(dirname( $_SERVER[ 'SCRIPT_NAME' ] ), '/'); } public final function addController( Controller $controller ) @@ -29,6 +26,16 @@ abstract class Page return $this; } + public final function getServerRoot( ) + { + $root = Loader::PackageConfig( 'core' )->get( 'pages/baseURL' , null , false ); + if (is_null($root)) { + $root = ( ( $_SERVER[ 'HTTPS' ] ?: false ) ? 'https' : 'http' ) + . '://' . $_SERVER[ 'HTTP_HOST' ]; + } + return rtrim($root, '/'); + } + public final function getBaseURL( ) { return $this->baseURL; @@ -55,8 +62,7 @@ abstract class Page if ( $rc[0] != '/' ) { $rc = $this->baseURL . '/' . $rc; } - $rc = ( ( array_key_exists( 'HTTPS' , $_SERVER ) && $_SERVER[ 'HTTPS' ] ) ? 'https' : 'http' ) . '://' . $_SERVER[ 'SERVER_NAME' ] - . ':' . $_SERVER[ 'SERVER_PORT' ] . $rc; + $rc = $this->getServerRoot() . $rc; header( "Location: $rc" ); $rv = true; }