Merge branch 'rating'
authorAndreas Unterkircher <unki@netshadow.at>
Sat, 24 May 2008 11:01:13 +0000 (13:01 +0200)
committerAndreas Unterkircher <unki@netshadow.at>
Sat, 24 May 2008 11:01:13 +0000 (13:01 +0200)
CHANGELOG
phpfspot.class.php
phpfspot.js
resources/empty_rate.png [new file with mode: 0644]
resources/rating.png [new file with mode: 0644]
resources/star.png [new file with mode: 0644]
rpc.php
themes/default/templates/photo_index.tpl
themes/default/templates/search.tpl
themes/default/templates/single_photo.tpl

index c0befcba97b4d29727c15fb8bcfdfa9e9d5e59e0..e6fee40125bb562252a1685543684f5b8d3af69d 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,7 @@ phpfspot (1.5)
   * feature, display tag-selection with preview-icons in photo index.
   * feature, support for Nikon's NEF RAW photo format (via dcraw and ImageMagick).
   * feature, auto-scroll in photo index if thumbnails are out of sight.
+  * feature, support F-Spot's rating values.
   * bug, if tag added to hide-tags, don't show up in photo-details box (single-photo).
   * bug, if tag added to hide-tags, don't allow adding to selected-tags list.
   * bug, if tag added to hide-tags, random-photo needs to take care of it.
index 1d20ab19e3e17a140313a0a433bf6b4f4204d9f6..58cda4e2f5776452aa56e07762aa107f17aa6834 100644 (file)
@@ -157,6 +157,7 @@ class PHPFSPOT {
          ");
       }
 
+      /* get F-Spot database version */
       $this->dbver = $this->getFspotDBVersion();
 
       if(!is_writeable($this->cfg->base_path ."/templates_c")) {
@@ -203,6 +204,15 @@ class PHPFSPOT {
 
       $this->tmpl->assign('web_path', $this->cfg->web_path);
 
+      /* Starting with F-Spot 0.4.2, the rating-feature was available */
+      if($this->dbver > 10) {
+         $this->tmpl->assign('has_rating', true);
+         $this->sort_orders = array_merge($this->sort_orders, array(
+            'rate_asc' => 'Rate &uarr;',
+            'rate_desc' => 'Rate &darr;',
+         ));
+      }
+
       /* check if all necessary indices exist */
       $this->checkDbIndices();
 
@@ -312,15 +322,26 @@ class PHPFSPOT {
          }
       }
 
+      /* if date-search variables are registered in the session, set the check
+         for "consider date-range" in the html output
+      */
       if(isset($_SESSION['from_date']) && isset($_SESSION['to_date']))
          $this->tmpl->assign('date_search_enabled', true);
 
+      /* if rate-search variables are registered in the session, set the check
+         for "consider rate-range" in the html output
+      */
+      if(isset($_SESSION['rate_from']) && isset($_SESSION['rate_to'])) {
+         $this->tmpl->assign('rate_search_enabled', true);
+      }
+
       $this->tmpl->register_function("sort_select_list", array(&$this, "smarty_sort_select_list"), false);
       $this->tmpl->assign('search_from_date', $this->get_calendar('from'));
       $this->tmpl->assign('search_to_date', $this->get_calendar('to'));
 
       $this->tmpl->assign('preset_selected_tags', $this->getSelectedTags());
       $this->tmpl->assign('preset_available_tags', $this->getAvailableTags());
+      $this->tmpl->assign('rate_search', $this->get_rate_search());
 
       if(!isset($content)) {
          if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags']))
@@ -425,10 +446,19 @@ class PHPFSPOT {
          ";
       }
       else {
-         $query_str = "
-            SELECT p.id, p.uri, p.time, p.description
-            FROM photos p
-         ";
+         /* 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
+            ";
+         }
+         else {
+            $query_str = "
+               SELECT p.id, p.uri, p.time, p.description, p.rating
+               FROM photos p
+            ";
+         }
       }
 
       /* if show_tags is set, only return details for photos which
@@ -488,6 +518,75 @@ class PHPFSPOT {
 
    } // getPhotoName()
 
+   /**
+    * get photo rating level
+    *
+    * this function will return the integer-based rating
+    * level of the photo. This can only be done, if the F-Spot
+    * database is at a specific level. If rating value can not
+    * be found, zero will be returned indicating no rating value
+    * is available.
+    * @param integer idx
+    * @return integer
+    */
+   public function get_photo_rating($idx)
+   {
+      if($detail = $this->get_photo_details($idx)) {
+         if(isset($detail['rating']))
+            return $detail['rating'];
+      }
+
+      return 0;
+
+   } // get_photo_rating()
+
+   /**
+    * get rate-search bars
+    *
+    * this function will return the rating-bars for the
+    * search field.
+    * @return string
+    */
+   public function get_rate_search()
+   {
+      $bar = "";
+
+      for($i = 1; $i <= 5; $i++) {
+
+         $bar.= "<img id=\"rate_from_". $i ."\" src=\"";
+
+         if(isset($_SESSION['rate_from']) && $i <= $_SESSION['rate_from'])
+            $bar.= $this->cfg->web_path ."/resources/star.png";
+         else
+            $bar.= $this->cfg->web_path ."/resources/empty_rate.png";
+
+         $bar.= "\"
+            onmouseover=\"show_rate('from', ". $i .");\"
+            onmouseout=\"reset_rate('from');\"
+            onclick=\"set_rate('from', ". $i .")\" />";
+      }
+
+      $bar.= "<br />\n";
+
+       for($i = 1; $i <= 5; $i++) {
+
+         $bar.= "<img id=\"rate_to_". $i ."\" src=\"";
+
+         if(isset($_SESSION['rate_to']) && $i <= $_SESSION['rate_to'])
+            $bar.= $this->cfg->web_path ."/resources/star.png";
+         else
+            $bar.= $this->cfg->web_path ."/resources/empty_rate.png";
+
+         $bar.= "\"
+            onmouseover=\"show_rate('to', ". $i .");\"
+            onmouseout=\"reset_rate('to');\"
+            onclick=\"set_rate('to', ". $i .");\" />";
+      }
+
+      return $bar;
+
+   } // get_rate_search()
+
    /**
     * shrink text according provided limit
     *
@@ -625,6 +724,7 @@ class PHPFSPOT {
 
       $this->tmpl->assign('description', $details['description']);
       $this->tmpl->assign('image_name', $this->parse_uri($details['uri'], 'filename'));
+      $this->tmpl->assign('image_rating', $this->get_photo_rating($photo));
 
       $this->tmpl->assign('width', $info_thumb[0]);
       $this->tmpl->assign('height', $info_thumb[1]);
@@ -956,8 +1056,7 @@ class PHPFSPOT {
    /**
     * reset date search
     *
-    * if any date search has taken place, reset
-    * it now
+    * if any date search has taken place, reset it now.
     */
    public function resetDateSearch()
    {
@@ -968,6 +1067,20 @@ class PHPFSPOT {
 
    } // resetDateSearch();
 
+   /**
+    * reset rate search
+    *
+    * if any rate search has taken place, reset it now.
+    */
+   public function resetRateSearch()
+   {
+      if(isset($_SESSION['rate_from']))
+         unset($_SESSION['rate_from']);
+      if(isset($_SESSION['rate_to']))
+         unset($_SESSION['rate_to']);
+
+   } // resetRateSearch();
+
    /**
     * return all photo according selection
     *
@@ -993,6 +1106,12 @@ class PHPFSPOT {
       } 
 
       if(isset($_SESSION['searchfor_name'])) {
+
+         /* check for previous conditions. if so add 'AND' */
+         if(!empty($additional_where_cond)) {
+            $additional_where_cond.= " AND ";
+         }
+
          if($this->dbver < 9) {
             $additional_where_cond.= "
                   (
@@ -1013,6 +1132,24 @@ class PHPFSPOT {
          }
       }
 
+      /* limit result based on rate-search */
+      if(isset($_SESSION['rate_from']) && isset($_SESSION['rate_to'])) {
+
+         if($this->dbver > 10) {
+
+            /* check for previous conditions. if so add 'AND' */
+            if(!empty($additional_where_cond)) {
+               $additional_where_cond.= " AND ";
+            }
+
+            $additional_where_cond.= "
+                     p.rating >= ". $_SESSION['rate_from'] ."
+                  AND
+                     p.rating <= ". $_SESSION['rate_to'] ."
+            ";
+         }
+      }
+
       if(isset($_SESSION['sort_order'])) {
          $order_str = $this->get_sort_order();
       }
@@ -1032,7 +1169,7 @@ class PHPFSPOT {
                ON pt2.tag_id=t2.id
             WHERE t.name LIKE '%". $_SESSION['searchfor_tag'] ."%' ";
 
-         if(isset($additional_where_cond) && !empty($additional_where_cond))
+         if(!empty($additional_where_cond))
             $query_str.= "AND ". $additional_where_cond ." ";
 
          if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
@@ -1069,7 +1206,7 @@ class PHPFSPOT {
                   ON pt1.photo_id=p.id
                WHERE pt1.tag_id IN (". $selected .")
             ";
-            if(isset($additional_where_cond) && !empty($additional_where_cond)) 
+            if(!empty($additional_where_cond))
                $query_str.= "AND ". $additional_where_cond ." ";
 
             if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
@@ -1125,7 +1262,7 @@ class PHPFSPOT {
                   AND pt". ($i+2) .".tag_id=". $_SESSION['selected_tags'][$i] ."
                "; 
             }
-            if(isset($additional_where_cond) && !empty($additional_where_cond)) 
+            if(!empty($additional_where_cond))
                $query_str.= "AND ". $additional_where_cond;
 
             if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
@@ -1154,11 +1291,11 @@ class PHPFSPOT {
             ON pt.tag_id=t.id
       ";
 
-      if(isset($additional_where_cond) && !empty($additional_where_cond)) 
+      if(!empty($additional_where_cond))
          $query_str.= "WHERE ". $additional_where_cond ." ";
 
       if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
-         if(isset($additional_where_cond) && !empty($additional_where_cond))
+         if(!empty($additional_where_cond))
             $query_str.= "AND t.name IN ('".implode("','",$this->cfg->show_tags). "')";
          else
             $query_str.= "WHERE t.name IN ('".implode("','",$this->cfg->show_tags). "')";
@@ -1214,6 +1351,7 @@ class PHPFSPOT {
       $img_name[$thumbs] = Array();
       $img_fullname[$thumbs] = Array();
       $img_title = Array();
+      $img_rating = Array();
 
       for($i = $begin_with; $i < $end_with; $i++) {
 
@@ -1224,6 +1362,7 @@ class PHPFSPOT {
             $img_name[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 15));
             $img_fullname[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 0));
             $img_title[$thumbs] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0));
+            $img_rating[$thumbs] = $this->get_photo_rating($photos[$i]);
 
             $thumb_path = $this->get_thumb_path($this->cfg->thumb_width, $photos[$i]);
 
@@ -1371,6 +1510,7 @@ class PHPFSPOT {
       $this->tmpl->assign('img_name', $img_name);
       $this->tmpl->assign('img_fullname', $img_fullname);
       $this->tmpl->assign('img_title', $img_title);
+      $this->tmpl->assign('img_rating', $img_rating);
       $this->tmpl->assign('thumbs', $thumbs);
       $this->tmpl->assign('selected_tags', $this->getSelectedTags('img'));
 
@@ -1846,6 +1986,7 @@ class PHPFSPOT {
     */
    public function startSearch()
    {
+      /* date search */
       if(isset($_POST['from']) && $this->isValidDate($_POST['from'])) {
          $from = $_POST['from'];
       }
@@ -1853,15 +1994,36 @@ class PHPFSPOT {
          $to = $_POST['to'];
       }
 
+      /* tag-name search */
       if(isset($_POST['for_tag']) && is_string($_POST['for_tag'])) {
          $searchfor_tag = $_POST['for_tag'];
          $_SESSION['searchfor_tag'] = $_POST['for_tag'];
       }
+      else {
+         unset($_SESSION['searchfor_tag']);
+      }
 
+      /* file-name search */
       if(isset($_POST['for_name']) && is_string($_POST['for_name'])) {
-         $searchfor_name = $_POST['for_name'];
          $_SESSION['searchfor_name'] = $_POST['for_name'];
       }
+      else {
+         unset($_SESSION['searchfor_name']);
+      }
+
+      /* rate-search */
+      if(isset($_POST['rate_from']) && is_numeric($_POST['rate_from'])) {
+
+         $_SESSION['rate_from'] = $_POST['rate_from'];
+
+         if(isset($_POST['rate_to']) && is_numeric($_POST['rate_to'])) {
+            $_SESSION['rate_to'] = $_POST['rate_to'];
+         }
+      }
+      else {
+         /* delete any previously set value */
+         unset($_SESSION['rate_to'], $_SESSION['rate_from']);
+      }
 
       $this->get_tags();
 
@@ -2538,6 +2700,12 @@ class PHPFSPOT {
          case 'tags_desc':
             return " ORDER BY t.name DESC ,p.time ASC";
             break;
+         case 'rate_asc':
+            return " ORDER BY t.name ASC, p.rating ASC";
+            break;
+         case 'rate_desc':
+            return " ORDER BY t.name DESC, p.rating DESC";
+            break;
       }
 
    } // get_sort_order()
index 2aee155ec5650e10e43997d687fc17b161743728..8db1f651b132cbf964f6fe4ef06280a5f31c2d2e 100644 (file)
@@ -277,16 +277,24 @@ function startSearch()
    var objTemp = new Object();
    objTemp['action'] = 'search';
 
-   if(document.getElementsByName('searchfor_tag')[0].value != "") {
+   if(document.getElementsByName('searchfor_tag')[0] != undefined &&
+      document.getElementsByName('searchfor_tag')[0].value != "") {
       objTemp['for_tag'] = document.getElementsByName('searchfor_tag')[0].value;
    }
-   if(document.getElementsByName('searchfor_name')[0].value != "") {
+   if(document.getElementsByName('searchfor_name')[0] != undefined &&
+      document.getElementsByName('searchfor_name')[0].value != "") {
       objTemp['for_name'] = document.getElementsByName('searchfor_name')[0].value;
    }
-   if(document.getElementsByName('consider_date')[0].checked == true) {
+   if(document.getElementsByName('consider_date')[0] != undefined &&
+      document.getElementsByName('consider_date')[0].checked == true) {
       objTemp['from'] = from;
       objTemp['to'] = to;
    }
+   if(document.getElementsByName('consider_rate')[0] != undefined &&
+      document.getElementsByName('consider_rate')[0].checked == true) {
+      objTemp['rate_from'] = rate_search['from'];
+      objTemp['rate_to'] = rate_search['to'];
+   }
 
    var retr = HTML_AJAX.post(web_path + '/rpc.php', objTemp);
    if(retr == "ok") {
@@ -342,13 +350,20 @@ function setViewMode(mode)
  */
 function clearSearch()
 {
-   document.getElementsByName('searchfor_tag')[0].value = '';
-   document.getElementsByName('searchfor_name')[0].value = '';
+   if(document.getElementsByName('searchfor_tag')[0] != undefined)
+      document.getElementsByName('searchfor_tag')[0].value = '';
+   if(document.getElementsByName('searchfor_name')[0] != undefined)
+      document.getElementsByName('searchfor_name')[0].value = '';
 
-   if(document.getElementsByName('consider_date')[0].checked == true) {
+   if(document.getElementsByName('consider_date')[0] != undefined &&
+      document.getElementsByName('consider_date')[0].checked == true) {
       document.getElementsByName('consider_date')[0].checked = false;
       datesearch();
-   }  
+   }
+   if(document.getElementsByName('consider_rate')[0] != undefined &&
+      document.getElementsByName('consider_rate')[0].checked == true) {
+      document.getElementsByName('consider_rate')[0].checked = false;
+   }
 
 } // clearSearch()
 
@@ -799,6 +814,64 @@ function update_sort_order(obj)
 
 } // update_sort_order()
 
+/**
+ * show rate stars
+ *
+ * this function will show the requested amount of
+ * rate-stars.
+ *
+ * @param string mode
+ * @param int level
+ */
+function show_rate(mode, level)
+{
+   var i;
+
+   for(i = 1; i <= 5; i++) {
+      if(i <= level) {
+         document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/star.png';
+      }
+      else {
+         document.getElementById('rate_' + mode + '_' + i).src = web_path + '/resources/empty_rate.png';
+      }
+   }
+
+} // show_rate()
+
+/**
+ * set rate stars
+ *
+ *
+ * this function will set the requested rate-stars-amount into a global
+ * variable (which will then later be used on form-submit) and will also
+ * update the display.
+ *
+ * @param string mode
+ * @param int level
+ */
+function set_rate(mode, level)
+{
+   rate_search[mode] = level;
+   show_rate(mode, level);
+
+} // set_rate()
+
+/**
+ * reset rate stars
+ *
+ * this function will reset the rate-star to their initial value.
+ *
+ * @param string mode
+ */
+function reset_rate(mode)
+{
+   if(rate_search[mode] == undefined)
+      rate_search[mode] = 0;
+
+   show_rate(mode, rate_search[mode]);
+
+} // reset_rate()
+
 /**
  * handle key events
  */
@@ -858,3 +931,4 @@ var origWidth;
 // position of the last shown photo in photo-index
 var photo_details_pos;
 var web_path;
+var rate_search = new Array();
diff --git a/resources/empty_rate.png b/resources/empty_rate.png
new file mode 100644 (file)
index 0000000..dcf5feb
Binary files /dev/null and b/resources/empty_rate.png differ
diff --git a/resources/rating.png b/resources/rating.png
new file mode 100644 (file)
index 0000000..c39b428
Binary files /dev/null and b/resources/rating.png differ
diff --git a/resources/star.png b/resources/star.png
new file mode 100644 (file)
index 0000000..b88c857
Binary files /dev/null and b/resources/star.png differ
diff --git a/rpc.php b/rpc.php
index f4a93ce6eb728a8232616ec6584a558e762cb19b..ada2857a1083fbfec0cb70ee7dd206f025d166d0 100644 (file)
--- a/rpc.php
+++ b/rpc.php
@@ -98,6 +98,7 @@ class PHPFSPOT_RPC {
             $phpfspot->resetNameSearch();
             $phpfspot->resetTags();
             $phpfspot->resetDateSearch();
+            $phpfspot->resetRateSearch();
             $phpfspot->resetPhotoView();
             break;
 
index c9da47778b0e8e40b327b693f7679da52fdd7b04..7fe04ab053e00c788340269aa0ab6c88b256cf55 100644 (file)
      <br />
     {$img_name[thumb]}
     </a>
+    <!-- show lightbox eyes, if enabled -->
     { if $use_lightbox }
     <a href="{$web_path}/phpfspot_img.php?idx={$images[thumb]}&amp;width={$preview_width}" alt="thumb_{$images[thumb]}" rel="lightbox[photoidx]" title="Preview of {$img_fullname[thumb]}"><img src="{$web_path}/resources/eyes.png" /></a>
     { /if }
+    <!-- show F-Spot photo rating value, if available -->
+    { if $img_rating[thumb] }
+     <br />
+     {section name="rating" loop=$img_rating[thumb] step=1}
+      <img src="{$web_path}/resources/star.png" />
+     {/section}
+    { /if }
    </div>
 
   {/if}
index c1d152c7e4c8a39070020796e9f90a8190c5e1ff..672bb357d36939718ede603a99428c46d759981c 100644 (file)
    <input type="image" class="submit" src="{$web_path}/resources/doit.png" alt="start search" title="start search" onclick="click(this);" />
   </td>
  </tr>
+ { if $has_rating }
+ <tr>
+  <td>Rating:</td>
+  <td class="nowarp">
+   { if ! $rate_search_enabled }
+    <input type="checkbox" class="checkbox" name="consider_rate" value="Y" />
+   { else }
+    <input type="checkbox" class="checkbox" name="consider_rate" value="Y" checked="checked" />
+   { /if }
+   consider rate-range
+  </td>
+  <td>&nbsp;</td>
+ </tr>
+ <tr>
+  <td>&nbsp;</td>
+  <td>
+   { $rate_search }
+  </td>
+  <td>
+   <input type="image" class="submit" src="{$web_path}/resources/doit.png" alt="start search" title="start search" onclick="click(this);" />
+  </td>
+ </tr>
+ { /if }
  <tr>
   <td>
    Sort-Order:&nbsp;
index 9b690ffbd7bba8638a24dfbe919eedf267ae647d..20b59f8d6c49f9a540e27e5742bb9797f0769672 100644 (file)
    {$ExifOrigResolution}px<br />
    { /if }
    <u>Size:</u>&nbsp;{$ExifFileSize}<br />
+   { if $image_rating }
+    <u><img src="{$web_path}/resources/rating.png" alt="rating" />&nbsp;Rating:</u><br />
+    {section name="rating" loop=$image_rating step=1}
+     <img src="{$web_path}/resources/star.png" />
+    {/section}
+    <br />
+   { /if }
    { if $tags }
     <br />
     <u><img src="{$web_path}/resources/small_available_tags.png" alt="available tags" />&nbsp;Tagged with:</u><br />