Add relative root path calculation
authorJoey Schulze <joey@infodrom.org>
Sun, 17 Jul 2016 11:11:05 +0000 (13:11 +0200)
committerJoey Schulze <joey@infodrom.org>
Sun, 17 Jul 2016 11:11:05 +0000 (13:11 +0200)
class/ajaxbackendbase.class.php

index e8f2723..cd12b17 100644 (file)
@@ -2,11 +2,26 @@
 
 class AJAXBackendBase {
   protected $db;
+  protected $relativeRootPath;
 
-  public function __construct__()
+  public function __construct()
   {
     global $db;
     $this->db = $db;
+
+    $path = substr($_SERVER['HTTP_REFERER'], strpos($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME'])+strlen($_SERVER['SERVER_NAME'])+1);
+
+    $pos = 0;
+    $this->relativeRootPath = '';
+    while (($pos = strpos($path, '/', $pos)) !== false) {
+      $this->relativeRootPath .= '../';
+      $pos++;
+    }
+  }
+
+  public function relativeRootPath()
+  {
+    return $this->relativeRootPath;
   }
 
 }