issue6, first implementation of paged photo index view
authorAndreas Unterkircher <unki@netshadow.at>
Sat, 23 Jun 2007 08:40:48 +0000 (08:40 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Sat, 23 Jun 2007 08:40:48 +0000 (08:40 +0000)
use thumbnail width & height for <img> to avoid "flipping" when images are getting loaded
fixed issue when all selected tags are clicked away but photo index still stays, there are no matching photos

git-svn-id: file:///var/lib/svn/phpfspot/trunk@124 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php
phpfspot.js
phpfspot_cfg.php
rpc.php
templates/photo_index.tpl

index 0fa174016b5cd299c344c3a51adc680f588be8bb..525b5c1b0d4b8f8dc3d0858f53da994cc97909ef 100644 (file)
@@ -280,7 +280,7 @@ class PHPFSPOT {
       }
 
       /* return according the selected tags */
-      if(isset($_SESSION['selected_tags'])) {
+      if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
          $selected = "";
          foreach($_SESSION['selected_tags'] as $tag)
             $selected.= $tag .",";
@@ -354,18 +354,41 @@ class PHPFSPOT {
 
       $count = count($photos);
 
+      if(!$_SESSION['begin_with'] || $_SESSION['begin_with'] == 0)
+         $begin_with = 0;
+      else
+         $begin_with = $_SESSION['begin_with'];
+
+      if($this->cfg->rows_per_page == 0)
+         $end_with = $count;
+      else
+         $end_with = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
+
+   
       $rows = 0;
       $cols = 0;
       $images[$rows] = Array();
+      $img_height[$rows] = Array();
+      $img_width[$rows] = Array();
 
-      for($i = 0; $i < $count; $i++) {
+      for($i = $begin_with; $i < $end_with; $i++) {
 
          $images[$rows][$cols] = $photos[$i];
 
+         $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
+
+         if(file_exists($thumb_path)) {
+            $info = getimagesize($thumb_path); 
+            $img_width[$rows][$cols] = $info[0];
+            $img_height[$rows][$cols] = $info[1];
+         }
+
          if($cols == $this->cfg->thumbs_per_row-1) {
             $cols = 0;
             $rows++;
             $images[$rows] = Array();
+            $img_width[$rows] = Array();
+            $img_height[$rows] = Array();
          }
          else {
             $cols++;
@@ -378,9 +401,21 @@ class PHPFSPOT {
       if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '')
          $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
 
+      if($this->cfg->rows_per_page != 0) {
+         $previous_start = $begin_with - ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
+         $next_start = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
+
+         if($begin_with != 0) 
+            $this->tmpl->assign("previous_url", "javascript:showPhotoIndex(". $previous_start .");"); 
+         if($end_with < $count)
+            $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");"); 
+      }
+   
       $this->tmpl->assign('count', $count);
       $this->tmpl->assign('width', $this->cfg->thumb_width);
       $this->tmpl->assign('images', $images);
+      $this->tmpl->assign('img_width', $img_width);
+      $this->tmpl->assign('img_height', $img_height);
       $this->tmpl->assign('rows', $rows);
       $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
       $this->tmpl->show("photo_index.tpl");
index 4849295d0b311699f46974e4dd69a9c8644d0153..fcc5766a2506f9b304bfb86c8d8d588bc4d9f06e 100644 (file)
@@ -48,9 +48,12 @@ function refreshSelectedTags()
    selected_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_selected_tags'));
 }
 
-function showPhotoIndex()
+function showPhotoIndex(begin_with)
 {
-   HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index'));
+   if(begin_with == undefined)
+      HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index'));
+   else
+      HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index&begin_with=' + begin_with));
 }
 
 function showBubbleDetails(object, id, direction)
index a451544b9bb487507cc5debff9412e8f02dfb48d..ecb45ac931f113e5d69bb4c0b5e437f6e7a706d1 100644 (file)
@@ -7,17 +7,17 @@ class PHPFSPOT_CFG {
    var $product = "phpfspot";
    var $version = "0.1";
 
-   var $base_path = "/var/www/images.netshadow.at/htdocs/phpfspot";
+   var $base_path = "/var/www/images.netshadow.at/htdocs";
 
    var $web_path = "/phpfspot";
 
    /* it's enough if this database is readonly for the webserver */
-   var $fspot_db = "/var/www/images.netshadow.at/htdocs/phpfspot/photos.db";
+   var $fspot_db = "/var/www/images.netshadow.at/f-spot-dbs/photos.db";
 
    /* this database MUST be writeable for the webserver. Set the directory
       permissions correctly so phpfspot can create this database for you!!
    */
-   var $phpfspot_db = "/var/www/images.netshadow.at/htdocs/phpfspot/phpfspot.db";
+   var $phpfspot_db = "/var/www/images.netshadow.at/f-spot-dbs/phpfspot.db";
 
    /* don't touch if you haven't changed the base templates */
    var $thumb_width = "150";
@@ -27,12 +27,16 @@ class PHPFSPOT_CFG {
    /* how many columns in the photo index view */
    var $thumbs_per_row = 4;
 
+   /* how many rows should be displayed on the photo index view */
+   /* use 0 to display all matching photos on one page */
+   var $rows_per_page = 4;
+
    /* Usually the photo directory differs between your local F-Spot installation
       and your webserver. With this you can advice phpfspot to replace all paths
       (they are stored in F-Spot's sqlite3 database
    */
    var $path_replace_from = "/home/unki";
-   var $path_replace_to = "/var/www/images.netshadow.at/htdocs/phpfspot";
+   var $path_replace_to = "/var/www/images.netshadow.at";
 
    /* This is not really a security option - it only hides some present F-Spot
       tags from the available-tags-list
diff --git a/rpc.php b/rpc.php
index 0bdccc9fde733c14972b02f1d8eaab7ab64635cb..6775647ca6acd84a1b8564bee1c204051ac39e3c 100644 (file)
--- a/rpc.php
+++ b/rpc.php
@@ -80,6 +80,7 @@ class PHPFSPOT_RPC {
 
          case 'show_photo_index':
 
+            $_SESSION['begin_with'] = $_GET['begin_with'];
             $fspot->showPhotoIndex();
             break;
    
index 89d348e51a3c90e4c4cb8d0f11015c6a69093213..36d095575297b6d652cd03591a65971febda0201 100644 (file)
@@ -33,7 +33,7 @@
       <div id="outter">
       <div id="inner">
        <a href="javascript:showImage({$images[row][col]});" id="{$images[row][col]}" class="bubble">
-        <img class="thumb" id="{$images[row][col]}" src="phpfspot_img.php?idx={$images[row][col]}&amp;width={$width}" alt="thumb_{$images[row][col]}" />
+        <img class="thumb" id="{$images[row][col]}" src="phpfspot_img.php?idx={$images[row][col]}&amp;width={$width}" alt="thumb_{$images[row][col]}" width="{$img_width[row][col]}" height="{$img_height[row][col]}" />
        </a>
       </div>
       </div>
    </div>
   </td>
  </tr>
+ <tr>
+  <td style="text-align: left; width: 33%;">
+  { if $previous_url == "" }
+   &nbsp;
+  { else }
+   <a href="{$previous_url}">
+    <img src="resources/arrow_left.png" alt="previous photo" />
+   </a>
+  { /if }
+  </td>
+  <td style="text-align: right; width: 33%;">
+  { if $next_url == "" }
+   &nbsp;
+  { else }
+   <a href="{$next_url}">
+    <img src="resources/arrow_right.png" alt="next photo" />
+   </a>
+  { /if}
+  </td>
+ </tr>
 </table>
 <script type="text/javascript">
 <!--