Add relative root path calculation
[infodrom.org/service.infodrom.org] / 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;
   }
 
 }