From 0b7778c4ade123b52da9ed4e723330a74e3b10c5 Mon Sep 17 00:00:00 2001
From: Andreas Unterkircher <unki@netshadow.at>
Date: Sat, 9 Jan 2010 10:18:25 +0100
Subject: photos table now contains separate columns for path and filename,
 fixes #316

Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
---
 phpfspot.class.php | 74 ++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 58 insertions(+), 16 deletions(-)

(limited to 'phpfspot.class.php')

diff --git a/phpfspot.class.php b/phpfspot.class.php
index a5b4a4d..a69cdde 100644
--- a/phpfspot.class.php
+++ b/phpfspot.class.php
@@ -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
@@ -556,19 +569,39 @@ class PHPFSPOT {
             v9.
          */
          if($version_idx > 0 && $this->dbver >= 9) {
-            /* check for alternative versions */
-            if($version = $this->db->db_fetchSingleRow("
-               SELECT
-                  version_id, name, uri
-               FROM
-                  photo_versions
-               WHERE
-                  photo_id LIKE '". $idx ."'
-               AND
-                  version_id LIKE '". $version_idx ."'")) {
-
-               $row['name'] = $version['name'];
-               $row['uri'] = $version['uri'];
+            if ($this->dbver < 17) {
+               /* check for alternative versions */
+               if($version = $this->db->db_fetchSingleRow("
+                  SELECT
+                     version_id, name, uri
+                  FROM
+                     photo_versions
+                  WHERE
+                     photo_id LIKE '". $idx ."'
+                  AND
+                     version_id LIKE '". $version_idx ."'")) {
+
+                  $row['name'] = $version['name'];
+                  $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 ."'")) {
+
+                  $row['name'] = $version['name'];
+                  $row['uri'] = $version['uri'];
+               }
             }
          }
 
@@ -1245,7 +1278,7 @@ class PHPFSPOT {
                   )
             ";
          }
-         else {
+         if($this->dbver < 17) {
             $additional_where_cond.= "
                   (
                         basename(p.uri) LIKE '%". $_SESSION['searchfor_name'] ."%'
@@ -1254,6 +1287,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 */
-- 
cgit v1.2.3-18-g5258