warn about remote fork config in setup and help
[phorkie.git] / src / phorkie / Tools.php
index 1d3d2260ebc8aaa27af0ac06aa753f68977f3d45..7c9c46eb84a540709c52cc6932b5329095c68204 100644 (file)
@@ -38,14 +38,14 @@ class Tools
      *
      * @return string Full URL
      */
-    public static function fullUrl($path)
+    public static function fullUrl($path = '')
     {
         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
             $prot = 'https';
         } else {
             $prot = 'http';
         }
-        return $prot . '://' . $_SERVER['HTTP_HOST'] . $path;
+        return $prot . '://' . $_SERVER['HTTP_HOST'] . $GLOBALS['phorkie']['cfg']['baseurl'] . $path;
     }
 
     /**
@@ -70,6 +70,31 @@ class Tools
         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 '/';
+    }
+}
 ?>