detect baseurl automatically, load config file from .phar
authorChristian Weiske <cweiske@cweiske.de>
Fri, 4 Jul 2014 05:33:29 +0000 (07:33 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 4 Jul 2014 05:33:29 +0000 (07:33 +0200)
data/config.default.php
src/phorkie/Tools.php
www/www-header.php

index 8f796f4109b992afca7a901e1acae8873fe9de2e..eb98efd7076a12d5fe45736cb1bc3b5216d20c0f 100644 (file)
@@ -4,7 +4,7 @@ $GLOBALS['phorkie']['cfg'] = array(
     'gitdir'        => __DIR__ . '/../repos/git/',
     'workdir'       => __DIR__ . '/../repos/work/',
     'tpl'           => __DIR__ . '/templates/',
     'gitdir'        => __DIR__ . '/../repos/git/',
     'workdir'       => __DIR__ . '/../repos/work/',
     'tpl'           => __DIR__ . '/templates/',
-    'baseurl'       => '/',
+    'baseurl'       => null,
     'avatars'       => true,
     'css'           => '',
     'iconpng'       => '',//phorkie browser icon (favicon)
     'avatars'       => true,
     'css'           => '',
     'iconpng'       => '',//phorkie browser icon (favicon)
index fc815cc5679085c139028f35fab58ea1531f819b..7c9c46eb84a540709c52cc6932b5329095c68204 100644 (file)
@@ -70,6 +70,31 @@ class Tools
         return $file;
     }
 
         return $file;
     }
 
-}
 
 
+    public static function detectBaseUrl()
+    {
+        if (!isset($_SERVER['REQUEST_URI'])
+            || !isset($_SERVER['SCRIPT_NAME'])
+        ) {
+            return '/';
+        }
+
+        $scriptName = $_SERVER['SCRIPT_NAME'];
+        $requestUri = $_SERVER['REQUEST_URI'];
+        if (substr($scriptName, -4) != '.php') {
+            //a phar
+            return $scriptName . '/';
+        }
+
+        if (substr($requestUri, -4) != '.php') {
+            $requestUri .= '.php';
+        }
+        $snl = strlen($scriptName);
+        if (substr($requestUri, -$snl) == $scriptName) {
+            return substr($requestUri, 0, -$snl) . '/';
+        }
+
+        return '/';
+    }
+}
 ?>
 ?>
index b58bd95ed659306b764ca40b67fc381002e0b756..94ee1d7e658424d160f58aa803b4289988bb5b2c 100644 (file)
@@ -30,8 +30,21 @@ set_exception_handler(
 );
 
 require_once __DIR__ . '/../data/config.default.php';
 );
 
 require_once __DIR__ . '/../data/config.default.php';
-if (file_exists(__DIR__ . '/../data/config.php')) {
-    require_once __DIR__ . '/../data/config.php';
+$pharFile = \Phar::running();
+if ($pharFile == '') {
+    $cfgFilePath = __DIR__ . '/../data/config.php';
+} else {
+    //remove phar:// from the path
+    $cfgFilePath = substr($pharFile, 7) . '.config.php';
+}
+$GLOBALS['phorkie']['cfgfiles'][$cfgFilePath] = false;
+if (file_exists($cfgFilePath)) {
+    $GLOBALS['phorkie']['cfgfiles'][$cfgFilePath] = true;
+    require_once $cfgFilePath;
+}
+
+if ($GLOBALS['phorkie']['cfg']['baseurl'] === null) {
+    $GLOBALS['phorkie']['cfg']['baseurl'] = Tools::detectBaseUrl();
 }
 
 // Set/Get git commit session variables
 }
 
 // Set/Get git commit session variables