make get_random_tag_photo() behave correct when show_tags is set, fixes #81
authorAndreas Unterkircher <unki@netshadow.at>
Sat, 4 Oct 2008 07:43:22 +0000 (09:43 +0200)
committerAndreas Unterkircher <unki@netshadow.at>
Sat, 4 Oct 2008 07:43:22 +0000 (09:43 +0200)
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
phpfspot.class.php
phpfspot_img.php

index 18c1c52c3526413d029857ca263de624b576cd4c..ba33c89af6f18f319d8a4f033437e8de3bd89275 100644 (file)
@@ -404,7 +404,7 @@ class PHPFSPOT {
          $query_str="
             SELECT
                DISTINCT t1.id as id, t1.name as name
-            FROM  
+            FROM
                photo_tags pt1
             INNER JOIN photo_tags
                pt2 ON pt1.photo_id=pt2.photo_id
@@ -3139,30 +3139,36 @@ class PHPFSPOT {
    {
       $all = Array();
 
-      $query_str = "
-         SELECT p.id
-         FROM photos p
-         INNER JOIN photo_tags pt
-            ON p.id=pt.photo_id
-      ";
-
       if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
          $query_str.= "
-            INNER JOIN tags t
-               ON pt.tag_id=t.id
-         ";
+            SELECT
+               DISTINCT pt1.photo_id as id
+            FROM
+               photo_tags pt1
+            INNER JOIN photo_tags
+               pt2 ON pt1.photo_id=pt2.photo_id
+            INNER JOIN tags t1
+               ON t1.id=pt1.tag_id
+            INNER JOIN tags t2
+               ON t2.id=pt2.tag_id
+            WHERE
+               pt1.tag_id LIKE '". $tagidx ."'
+            AND
+               t2.name IN  ('".implode("','",$this->cfg->show_tags)."')
+            ORDER BY
+               t1.sort_priority ASC";
+      }
+      else {
+         $query_str = "
+            SELECT
+               p.id
+            FROM
+               photos p
+            INNER JOIN photo_tags pt
+               ON p.id=pt.photo_id
+            WHERE
+               pt.tag_id LIKE '". $tagidx ."'";
       }
-      $query_str.= "
-         WHERE
-            pt.tag_id LIKE '". $tagidx ."'
-      ";
-
-      /*if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
-         $query_str.= "
-           AND
-               t.name IN ('".implode("','",$this->cfg->show_tags)."')
-         ";
-      }*/
 
       $result = $this->db->db_query($query_str);
 
index bb7e93f15f0c5890f8bf8b0e0f57496b7bdcdabc..b6952041dcedc69b0451baac8302aca8363eea62 100644 (file)
@@ -163,7 +163,7 @@ class PHPFSPOT_IMG {
          $this->parent->gen_thumb($idx);
       }
 
-      $version = $this->parent­>get_latest_version($idx);
+      $version = $this->parent->get_latest_version($idx);
 
       $fullpath = $this->parent->get_thumb_path($width, $idx, $version);
       /* if the thumb file does not exist, create it */