display photo index as matrix
authorAndreas Unterkircher <unki@netshadow.at>
Wed, 6 Jun 2007 19:41:44 +0000 (19:41 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Wed, 6 Jun 2007 19:41:44 +0000 (19:41 +0000)
show a larger pic when user clicks on it

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

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

index 628cfeacba8adec7b5e6e4eabc09f0cc5833c294..dbefee8b37f52ec13bd2bb61cf7529df3fa3d8cf 100644 (file)
@@ -39,7 +39,6 @@ class PHPFSPOT {
    public function show()
    {
 
-      $this->prepare_single_photo($this->current_photo);
       $this->tmpl->assign('tags', $this->tags);
       $this->tmpl->show("index.tpl");
 
@@ -117,21 +116,23 @@ class PHPFSPOT {
 
    } // translate_path
 
-   public function prepare_single_photo($photo)
+   public function showPhoto($photo)
    {
       if(isset($photo)) {
-         $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $this->avail_photos[$photo] ."&amp;width=". $this->cfg->photo_width);
+         $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&amp;width=". $this->cfg->photo_width);
       }
 
       if($photo > 0) {
          $this->tmpl->assign('previous_url', "javascript:showImage(". ($photo-1) .");");
       }
 
-      if($photo < count($this->avail_photos)) {
+      if($photo < count($this->photos)) {
          $this->tmpl->assign('next_url', "javascript:showImage(". ($photo+1) .");");
       }
 
-   } // prepare_single_photo()
+      $this->tmpl->show("single_photo.tpl");
+
+   } // showPhoto()
 
    public function getAvailableTags()
    {
@@ -212,19 +213,43 @@ class PHPFSPOT {
          array_push($tagged_photos, $row['photo_id']);
       }
 
-
       return $tagged_photos;
 
    } // getAllTagPhotos()
 
    public function showPhotoIndex()
    {
-      foreach($this->getAllTagPhotos() as $photo)
-      {
-         $images.= "<img src=\"phpfspot_img.php?idx=". $photo ."&amp;width=". $this->cfg->thumb_width ."\" /><br />\n";
-      }
+      $photos = $this->getAllTagPhotos();
+      $count = count($photos);
+
+      $rows = 0;
+      $cols = 0;
+      $images[$rows] = Array();
+
+      for($i = 0; $i < $count; $i++) {
+
+         $images[$rows][$cols] = $photos[$i];
+
+         if($cols == $this->cfg->thumbs_per_row-1) {
+            $cols = 0;
+            $rows++;
+            $images[$rows] = Array();
+         }
+         else {
+            $cols++;
+         }
+      } 
+
+      // +1 for for smarty's selection iteration
+      $rows++;
+
+         //$images.= "<img src=\"phpfspot_img.php?idx=". $photo ."&amp;width=". $this->cfg->thumb_width ."\" /><br />\n";
 
-      $this->tmpl->assign('image_matrix', $images);
+      $this->tmpl->assign('count', $count);
+      $this->tmpl->assign('width', $this->cfg->thumb_width);
+      $this->tmpl->assign('images', $images);
+      $this->tmpl->assign('rows', $rows);
+      $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
       $this->tmpl->show("photo_index.tpl");
 
 
index b833b99940654134a3bb1a90e00f3acc0e80e796..955a6ffda25a54d38067e25a7a48cdf7057e34b0 100644 (file)
@@ -17,6 +17,8 @@ class PHPFSPOT_CFG {
    var $path_replace_from = "/home/unki";
    var $path_replace_to = "/var/www/images.netshadow.at/htdocs/phpfspot";
 
+   var $thumbs_per_row = 3;
+
 }
 
 ?>
diff --git a/rpc.php b/rpc.php
index c81a7aed35aa1c52a3946433f24f2e20259b5ff7..cffb4edaa6f48addba713962afb7c114a9adede2 100644 (file)
--- a/rpc.php
+++ b/rpc.php
@@ -45,9 +45,7 @@ class PHPFSPOT_RPC {
       switch($_GET['action']) {
          case 'showphoto':
 
-            $fspot->prepare_single_photo($_GET['id']);
-            $fspot->tmpl->show("body.tpl");
-
+            $fspot->showPhoto($_GET['id']);
             break;
    
          case 'show_available_tags':
index f917364fcb589ea3bf32be4cfedd87bfdf80f2e1..7f3af463864b9a14723a83dcae17469af3464d44 100644 (file)
@@ -1 +1,20 @@
-{$image_matrix}
+<!-- Image Matrix -->
+<table>
+ <tr>
+  <td colspan="{$columns}">
+   {$count} images have been found for the selected tags
+  </td>
+ </tr>
+{section name="row" loop=$rows step=1}
+ <tr>
+ {section name="col" loop=$columns step=1}
+  <td>
+   <a href="javascript:showImage({$images[row][col]});">
+    <img src="phpfspot_img.php?idx={$images[row][col]}&amp;width={$width}" />
+   </a>
+  </td>
+ {/section}
+ </tr>
+{/section} 
+</table>
+<!-- /Image Matrix -->