make phpfspot runnable again on Debian Lenny when SQLite3 PDO support is used, resolv...
[phpfspot.git] / phpfspot.class.php
index edfed95e1cae4294c6305f3f460a4f162f5eff37..b82efa55d3c9c8711811be3e33588d5da3823fd1 100644 (file)
@@ -410,7 +410,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
@@ -428,7 +428,7 @@ class PHPFSPOT {
       else
       {
          $result = $this->db->db_query("
-            SELECT id,name
+            SELECT id as id,name as name
             FROM tags
             ORDER BY sort_priority ASC
          ");
@@ -481,23 +481,40 @@ class PHPFSPOT {
       /* ~ F-Spot version 0.3.x */
       if($this->dbver < 9) {
          $query_str = "
-            SELECT p.id, p.name, p.time, p.directory_path, p.description
-            FROM photos p
+            SELECT
+               p.id as id,
+               p.name as name,
+               p.time as time,
+               p.directory_path as directory_path,
+               p.description as description
+            FROM
+               photos p
          ";
       }
       else {
          /* till F-Spot version 0.4.1 */
          if($this->dbver < 11) {
             $query_str = "
-               SELECT p.id, p.uri, p.time, p.description
-               FROM photos p
+               SELECT
+                  p.id as id,
+                  p.uri as uri,
+                  p.time as time,
+                  p.description as description
+               FROM
+                  photos p
             ";
          }
          else {
             /* rating value got introduced */
             $query_str = "
-               SELECT p.id, p.uri, p.time, p.description, p.rating
-               FROM photos p
+               SELECT
+                  p.id as id,
+                  p.uri as uri,
+                  p.time as time,
+                  p.description as description,
+                  p.rating as rating
+               FROM
+                  photos p
             ";
          }
       }
@@ -533,24 +550,24 @@ class PHPFSPOT {
          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 */
-         if($version_idx > 0) {
-
+         /* 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) {
             /* 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 ."'
-            ")) {
+               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'];
-
             }
          }
 
@@ -1192,7 +1209,7 @@ class PHPFSPOT {
     * @return array
     */
    public function getPhotoSelection()
-   {  
+   {
       $matched_photos = Array();
       $additional_where_cond = "";
 
@@ -1258,8 +1275,10 @@ class PHPFSPOT {
       /* return a search result */
       if(isset($_SESSION['searchfor_tag']) && $_SESSION['searchfor_tag'] != '') {
          $query_str = "
-            SELECT DISTINCT pt1.photo_id
-               FROM photo_tags pt1
+            SELECT DISTINCT
+               pt1.photo_id as photo_id
+            FROM
+               photo_tags pt1
             INNER JOIN photo_tags pt2
                ON pt1.photo_id=pt2.photo_id
             INNER JOIN tags t
@@ -1297,8 +1316,10 @@ class PHPFSPOT {
          /* photo has to match at least on of the selected tags */
          if($_SESSION['tag_condition'] == 'or') {
             $query_str = "
-               SELECT DISTINCT pt1.photo_id
-                  FROM photo_tags pt1
+               SELECT DISTINCT
+                  pt1.photo_id as photo_id
+               FROM
+                  photo_tags pt1
                INNER JOIN photo_tags pt2
                   ON pt1.photo_id=pt2.photo_id
                INNER JOIN tags t
@@ -1336,8 +1357,10 @@ class PHPFSPOT {
             */
 
             $query_str = "
-               SELECT DISTINCT pt1.photo_id
-                  FROM photo_tags pt1
+               SELECT DISTINCT
+                  pt1.photo_id as photo_id
+               FROM
+                  photo_tags pt1
             ";
 
             if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
@@ -1384,8 +1407,10 @@ class PHPFSPOT {
 
       /* return all available photos */
       $query_str = "
-         SELECT DISTINCT p.id
-         FROM photos p
+         SELECT DISTINCT
+            p.id as id
+         FROM
+            photos p
          LEFT JOIN photo_tags pt
             ON p.id=pt.photo_id
          LEFT JOIN tags t
@@ -2061,7 +2086,7 @@ class PHPFSPOT {
          $full_path = $this->translate_path($this->parse_uri($details['uri'], 'fullpath'));
 
          if(!file_exists($full_path)) {
-            $this->_error("File ". $full_path ." does not exist\n");
+            $this->_error("File ". $full_path ." does not exist");
             return;
          }
 
@@ -2440,7 +2465,7 @@ class PHPFSPOT {
    private function get_photo_tags($idx)
    {
       $result = $this->db->db_query("
-         SELECT t.id, t.name
+         SELECT t.id as id, t.name as name
          FROM tags t
          INNER JOIN photo_tags pt
             ON t.id=pt.tag_id
@@ -2578,14 +2603,18 @@ class PHPFSPOT {
       switch($this->cfg->logging) {
          default:
          case 'display':
-            print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";
-            print $text ."<br />\n";
+            if(isset($this->fromcmd))
+               print $text ."\n";
+            else {
+               print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";
+               print $text ."<br />\n";
+            }
             break;
          case 'errorlog':  
             error_log($text);
             break;
          case 'logfile':
-            error_log($text, 3, $his->cfg->log_file);
+            error_log($text, 3, $this->cfg->log_file);
             break;
       }
 
@@ -3103,7 +3132,7 @@ class PHPFSPOT {
       $all = Array();
 
       $query_str = "
-         SELECT p.id
+         SELECT p.id as id
          FROM photos p
       ";
 
@@ -3145,30 +3174,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 as 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);
 
@@ -3494,14 +3529,14 @@ class PHPFSPOT {
       $to_delete = Array();
 
       $result = $this->cfg_db->db_query("
-         SELECT img_idx
+         SELECT img_idx as img_idx
          FROM images
          ORDER BY img_idx ASC
       ");
 
       while($row = $this->cfg_db->db_fetch_object($result)) {
          if(!$this->db->db_fetchSingleRow("
-            SELECT id
+            SELECT id as id
             FROM photos
             WHERE id='". $row['img_idx'] ."'")) {
 
@@ -3580,7 +3615,7 @@ class PHPFSPOT {
    public function get_tag_name($idx)
    {
        if($result = $this->db->db_fetchSingleRow("
-         SELECT name
+         SELECT name as name
          FROM tags
          WHERE
             id LIKE '". $idx ."'")) {
@@ -3687,7 +3722,7 @@ class PHPFSPOT {
    public function get_db_version()
    {
       if($row = $this->cfg_db->db_fetchSingleRow("
-         SELECT meta_value
+         SELECT meta_value as meta_value
          FROM
             meta
          WHERE