Merge branch 'master' of /var/cache/git/phpfspot
authorAndreas Unterkircher <unki@netshadow.at>
Wed, 15 Oct 2008 19:48:06 +0000 (21:48 +0200)
committerAndreas Unterkircher <unki@netshadow.at>
Wed, 15 Oct 2008 19:48:06 +0000 (21:48 +0200)
1  2 
phpfspot.class.php

diff --combined phpfspot.class.php
index edfed95e1cae4294c6305f3f460a4f162f5eff37,ba33c89af6f18f319d8a4f033437e8de3bd89275..11b5292858cc177c443c5a0174cfbeaea6e4ad1b
@@@ -141,12 -141,6 +141,12 @@@ class PHPFSPOT 
  
        /******* Opening F-Spot's sqlite database *********/
  
 +      /* Check if database file exists and is readable */
 +      if(!file_exists($this->cfg->fspot_db) || !is_readable($this->cfg->fspot_db)) {
 +         print "Error: ". $this->cfg->fspot_db ." does not exist or is not readable for user ". $this->getuid() .".\n";
 +         exit(1);
 +      }
 +
        /* Check if database file is writeable */
        if(!is_writeable($this->cfg->fspot_db)) {
           print "Error: ". $this->cfg->fspot_db ." is not writeable for user ". $this->getuid() .".\n";
        }
  
        /* Check if database file is writeable */
 -      if(!is_writeable($this->cfg->phpfspot_db)) {
 +      if(file_exists($this->cfg->phpfspot_db) && !is_writeable($this->cfg->phpfspot_db)) {
           print "Error: ". $this->cfg->phpfspot_db ." is not writeable for user ". $this->getuid() .".\n";
           print "Please fix permissions so phpfspot can create its own sqlite database to store some settings.\n";
           exit(1);
           $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
              error_log($text);
              break;
           case 'logfile':
-             error_log($text, 3, $his->cfg->log_file);
+             error_log($text, 3, $this->cfg->log_file);
              break;
        }
  
     {
        $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);