fixed path problem (missing "/")
[phpfspot.git] / phpfspot.class.php
index 89f924d04d21ea56fc376894d60d0301d8373bc0..f611391ae044ed2a234ef942ab622bd009c287b9 100644 (file)
@@ -505,8 +505,8 @@ class PHPFSPOT {
                   photos p
             ";
          }
-         else {
-            /* rating value got introduced */
+         elseif($this->dbver < 17) {
+             /* rating value got introduced */
             $query_str = "
                SELECT
                   p.id as id,
@@ -518,6 +518,19 @@ class PHPFSPOT {
                   photos p
             ";
          }
+         else {
+            /* path & filename now splited in base_uri & filename */
+            $query_str = "
+               SELECT
+                  p.id as id,
+                  p.base_uri ||'/'|| p.filename as uri,
+                  p.time as time,
+                  p.description as description,
+                  p.rating as rating
+               FROM
+                  photos p
+            ";
+         }
       }
 
       /* if show_tags is set, only return details of photos which are
@@ -538,24 +551,30 @@ class PHPFSPOT {
          ";
       }
 
-      if($row = $this->db->db_fetchSingleRow($query_str)) {
+      if(!$row = $this->db->db_fetchSingleRow($query_str))
+         return null;
 
-         /* before F-Spot db version 9 there was no uri column but
-            seperated fields for directory_path and name (= filename).
-         */
-         if($this->dbver < 9) {
-            $row['uri'] = "file://". $row['directory_path'] ."/". $row['name'];
-         }
+      /* before F-Spot db version 9 there was no uri column but
+         seperated fields for directory_path and name (= filename).
+      */
+      if($this->dbver < 9) {
+         $row['uri'] = "file://". $row['directory_path'] ."/". $row['name'];
+      }
+      /* starting with dbversion >= 17 we need to rawurldecode() uri */
+      elseif($this->dbver >= 17) {
+         $row['uri'] = rawurldecode($row['uri']);
+      }
 
-         /* if version-idx has not yet been set, get the latest photo version */
-         if(!isset($version_idx) || !$this->is_valid_version($idx, $version_idx))
-            $version_idx = $this->get_latest_version($idx);
+      /* if version-idx has not yet been set, get the latest photo version */
+      if(!isset($version_idx) || !$this->is_valid_version($idx, $version_idx))
+         $version_idx = $this->get_latest_version($idx);
 
-         /* if an alternative version has been requested. But we
-            support this only for F-Spot database versions from
-            v9.
-         */
-         if($version_idx > 0 && $this->dbver >= 9) {
+      /* if an alternative version has been requested. But we
+         support this only for F-Spot database versions from
+         v9.
+      */
+      if($version_idx > 0 && $this->dbver >= 9) {
+         if ($this->dbver < 17) {
             /* check for alternative versions */
             if($version = $this->db->db_fetchSingleRow("
                SELECT
@@ -571,12 +590,27 @@ class PHPFSPOT {
                $row['uri'] = $version['uri'];
             }
          }
+         else {
+            /* path & filename now splited in base_uri & filename */
+            if($version = $this->db->db_fetchSingleRow("
+               SELECT
+                  version_id,
+                  name,
+                  base_uri || '/'||filename as uri
+               FROM
+                  photo_versions
+               WHERE
+                  photo_id LIKE '". $idx ."'
+               AND
+                  version_id LIKE '". $version_idx ."'")) {
 
-         return $row;
-
+               $row['name'] = $version['name'];
+               $row['uri'] = rawurldecode($version['uri']);
+            }
+         }
       }
 
-      return null;
+      return $row;
 
    } // get_photo_details()
 
@@ -703,8 +737,13 @@ class PHPFSPOT {
     * @return string
     */
    public function translate_path($path)
-   {  
-      return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
+   {
+      if($this->cfg->enable_replace_path == true)
+         return str_replace(
+            $this->cfg->path_replace_from,
+            $this->cfg->path_replace_to, $path);
+
+      return $path;
 
    } // translate_path
 
@@ -1240,7 +1279,7 @@ class PHPFSPOT {
                   )
             ";
          }
-         else {
+         if($this->dbver < 17) {
             $additional_where_cond.= "
                   (
                         basename(p.uri) LIKE '%". $_SESSION['searchfor_name'] ."%'
@@ -1249,6 +1288,15 @@ class PHPFSPOT {
                   )
             ";
          }
+         else {
+            $additional_where_cond.= "
+                  (
+                        p.filename LIKE '%". $_SESSION['searchfor_name'] ."%'
+                     OR
+                        p.description LIKE '%". $_SESSION['searchfor_name'] ."%'
+                  )
+            ";
+         }
       }
 
       /* limit result based on rate-search */
@@ -1722,13 +1770,13 @@ class PHPFSPOT {
                   case 4: /* bottom, right */
                      $flip_vert = true; break;
                   case 5: /* left side, top */
-                     $rotate = 90; $flip_vert = true; break;
+                     $rotate = 270; $flip_vert = true; break;
                   case 6: /* right side, top */
-                     $rotate = 90; break;
+                     $rotate = 270; break;
                   case 7: /* left side, bottom */
-                     $rotate = 270; $flip_vert = true; break;
+                     $rotate = 90; $flip_vert = true; break;
                   case 8: /* right side, bottom */
-                     $rotate = 270; break;
+                     $rotate = 90; break;
                }
             }
 
@@ -2544,6 +2592,13 @@ class PHPFSPOT {
          $missing = true;
       }
 
+      if($this->cfg->db_access == "pdo") {
+         if(array_search("sqlite", PDO::getAvailableDrivers()) === false) {
+            print "PDO SQLite3 driver is missing<br />\n";
+            $missing = true;
+         }
+      }
+
       /* Check for HTML_AJAX PEAR package, lent from Horde project */
       ini_set('track_errors', 1);
       @include_once 'HTML/AJAX/Server.php';
@@ -3446,23 +3501,24 @@ class PHPFSPOT {
     */
    public function parse_uri($uri, $mode)
    {
-      if(($components = parse_url($uri)) !== false) {
+      if(($components = parse_url($uri)) === false)
+         return $uri;
 
-         switch($mode) {
-            case 'filename':
-               return basename($components['path']);
-               break;
-            case 'dirname':
-               return dirname($components['path']);
-               break;
-            case 'fullpath':
-               return $components['path'];
-               break;
-         }
+      switch($mode) {
+         case 'filename':
+            return basename($components['path']);
+            break;
+         case 'dirname':
+            return dirname($components['path']);
+            break;
+         case 'fullpath':
+            return $components['path'];
+            break;
+         default:
+            $this->throwError("unknown mode ". $mode);
+            break;
       }
 
-      return $uri;
-
    } // parse_uri()
 
    /**
@@ -3513,11 +3569,16 @@ class PHPFSPOT {
       if(!isset($this->cfg->thumbs_per_page))
          $this->_error("Please set \$thumbs_per_page in phpfspot_cfg");
 
-      if(!isset($this->cfg->path_replace_from) || $this->cfg->path_replace_from == "")
-         $this->_error("Please set \$path_replace_from in phpfspot_cfg");
+      if(!isset($this->cfg->enable_replace_path))
+         $this->_error("Please set \$enable_replace_path in phpfspot_cfg");
 
-      if(!isset($this->cfg->path_replace_to) || $this->cfg->path_replace_to == "")
-         $this->_error("Please set \$path_replace_to in phpfspot_cfg");
+      if($this->cfg->enable_replace_path == true) {
+         if(!isset($this->cfg->path_replace_from) || $this->cfg->path_replace_from == "")
+            $this->_error("Please set \$path_replace_from in phpfspot_cfg");
+
+         if(!isset($this->cfg->path_replace_to) || $this->cfg->path_replace_to == "")
+            $this->_error("Please set \$path_replace_to in phpfspot_cfg");
+      }
 
       if(!isset($this->cfg->hide_tags))
          $this->_error("Please set \$hide_tags in phpfspot_cfg");