issue115, display tag-selection in photo-index
[phpfspot.git] / phpfspot.class.php
index c56ececc94c7998a273ab0c602ddd6cd59f72e42..97deb968dacb5b6b98dd967d73a379480f4bf21d 100644 (file)
@@ -122,7 +122,7 @@ class PHPFSPOT {
 
       /* set application name and version information */
       $this->cfg->product = "phpfspot";
-      $this->cfg->version = "1.4";
+      $this->cfg->version = "1.5";
 
       $this->sort_orders= array(
          'date_asc' => 'Date ↑',
@@ -726,7 +726,7 @@ class PHPFSPOT {
     * session-variable $_SESSION['selected_tags']
     * @return string
     */
-   public function getSelectedTags()
+   public function getSelectedTags($type = 'link')
    {
       /* retrive tags from database */
       $this->get_tags();
@@ -737,7 +737,29 @@ class PHPFSPOT {
       {
          // return all selected tags
          if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
-            $output.= "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a>, ";
+
+            switch($type) {
+               default:
+               case 'link':
+                  $output.= "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a>, ";
+                  break;
+               case 'img':
+                  $output.= "
+                  <div style=\"display: table-cell;\">
+                   <div style=\"display: table-row; text-align: center;\">
+                    <a href=\"javascript:Tags('del', ". $tag .");\" title=\"". $this->tags[$tag] ."\">
+                     <img src=\"phpfspot_img.php?tagidx=". $tag ."\" />
+                    </a>
+                   </div>
+                   <div style=\"display: table-row; text-align: center;\">
+                    <a href=\"javascript:Tags('del', ". $tag .");\" title=\"". $this->tags[$tag] ."\">
+                     <img src=\"resources/underbar.png\" />
+                    </a>
+                   </div>
+                  </div>
+                  ";
+                  break;
+            }
          }
       }
 
@@ -1315,6 +1337,7 @@ class PHPFSPOT {
       $this->tmpl->assign('img_fullname', $img_fullname);
       $this->tmpl->assign('img_title', $img_title);
       $this->tmpl->assign('thumbs', $thumbs);
+      $this->tmpl->assign('selected_tags', $this->getSelectedTags('img'));
 
       $this->tmpl->show("photo_index.tpl");
 
@@ -1634,6 +1657,7 @@ class PHPFSPOT {
          $this->cfg->thumb_width,
          $this->cfg->photo_width,
          $this->cfg->mini_width,
+         30,
       );
 
       /* get details from F-Spot's database */
@@ -2563,6 +2587,56 @@ class PHPFSPOT {
 
    } // get_random_photo()
 
+   /**
+    * get random photo tag photo
+    *
+    * this function will get all photos tagged with the requested
+    * tag from the fspot database and randomly return ONE entry
+    *
+    * saddly there is yet no sqlite3 function which returns
+    * the bulk result in array, so we have to fill up our
+    * own here.
+    * @return array
+    */
+   public function get_random_tag_photo($tagidx)
+   {
+      $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
+         ";
+      }
+      $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);
+
+      while($row = $this->db->db_fetch_object($result)) {
+         array_push($all, $row['id']);
+      }
+
+      return $all[array_rand($all)];
+
+   } // get_random_tag_photo()
+
    /**
     * validates provided date
     *