issue27, on gallery export use links which will guide back the user into phpfspot...
[phpfspot.git] / phpfspot.class.php
index 3a6a59082a7c04e6943d18fb265fad8497f02fd2..5e25f21b81d446d3c1097b630a44b40ba7ae978c 100644 (file)
@@ -12,7 +12,6 @@ class PHPFSPOT {
    var $tmpl;
    var $tags;
    var $avail_tags;
-   var $current_tags;
 
    public function __construct()
    {
@@ -64,6 +63,19 @@ class PHPFSPOT {
                $_SESSION['selected_tags'] = split(',', $_GET['tags']);
             }
             break;
+         case 'showp':
+            if(isset($_GET['tags'])) {
+               $_SESSION['selected_tags'] = split(',', $_GET['tags']);
+            }
+            if(isset($_GET['id'])) {
+               $_SESSION['current_photo'] = $_GET['id'];
+            }
+            break;
+         case 'export':
+            $this->tmpl->show("export.tpl");
+            return;
+            break;
+
       }
 
       $this->tmpl->assign('content_page', 'welcome.tpl');
@@ -114,18 +126,14 @@ class PHPFSPOT {
 
    } // get_photo_details
 
-   public function getPhotoName($idx)
+   public function getPhotoName($idx, $limit = 0)
    {
       if($details = $this->get_photo_details($idx)) {
-
          $name = $details['name'];
-
-         if(strlen($name) > 15) {
-            $name = substr($name, 0, 10) ."...". substr($name, -10);
+         if($limit != 0 && strlen($name) > $limit) {
+            $name = substr($name, 0, $limit-5) ."...". substr($name, -($limit-5));
          }
-
          return $name;
-   
       }
 
    } // getPhotoName()
@@ -191,6 +199,14 @@ class PHPFSPOT {
       $meta_make = isset($meta['Make']) ? $meta['Make'] ." ". $meta['Model'] : "n/a";
       $meta_size = isset($meta['FileSize']) ? round($meta['FileSize']/1024, 1) ."kbyte" : "n/a";
 
+      $current_tags = $this->getCurrentTags();
+      $extern_link = "index.php?mode=showp&id=". $photo;
+      if($current_tags != "") {
+         $extern_link.= "&tags=". $current_tags;
+      }
+
+      $this->tmpl->assign('extern_link', $extern_link);
+
       if(file_exists($thumb_path)) {
 
          $info = getimagesize($thumb_path);
@@ -327,6 +343,12 @@ class PHPFSPOT {
 
    } // resetTags()
 
+   public function resetPhotoView()
+   {
+      unset($_SESSION['current_photo']);
+
+   } // resetPhotoView();
+
    public function resetTagSearch()
    {
       unset($_SESSION['searchfor']);
@@ -477,12 +499,14 @@ class PHPFSPOT {
       $img_width[$rows] = Array();
       $img_id[$rows] = Array();
       $img_name[$rows] = Array();
+      $img_title = Array();
 
       for($i = $begin_with; $i < $end_with; $i++) {
 
          $images[$rows][$cols] = $photos[$i];
          $img_id[$rows][$cols] = $i;
-         $img_name[$rows][$cols] = $this->getPhotoName($photos[$i]);
+         $img_name[$rows][$cols] = htmlspecialchars($this->getPhotoName($photos[$i], 15));
+         $img_title[$rows][$cols] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0));
 
          $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
 
@@ -582,19 +606,17 @@ class PHPFSPOT {
             $this->tmpl->assign('page_selector', $page_select);
       }
 
-      $current_tags = "";
-      if($_SESSION['selected_tags'] != "") {
-         foreach($_SESSION['selected_tags'] as $tag)
-            $current_tags.= $tag .",";
-         $current_tags = substr($current_tags, 0, strlen($current_tags)-1);
-      }
-
-      $extern_link = "http://". $_SERVER['SERVER_NAME'] ."/index.php?mode=showpi";
+      
+      $current_tags = $this->getCurrentTags();
+      $extern_link = "index.php?mode=showpi";
       if($current_tags != "") {
          $extern_link.= "&tags=". $current_tags;
       }
 
+      $export_link = "index.php?mode=export";
+
       $this->tmpl->assign('extern_link', $extern_link);
+      $this->tmpl->assign('export_link', $export_link);
       $this->tmpl->assign('count', $count);
       $this->tmpl->assign('width', $this->cfg->thumb_width);
       $this->tmpl->assign('images', $images);
@@ -602,6 +624,7 @@ class PHPFSPOT {
       $this->tmpl->assign('img_height', $img_height);
       $this->tmpl->assign('img_id', $img_id);
       $this->tmpl->assign('img_name', $img_name);
+      $this->tmpl->assign('img_title', $img_title);
       $this->tmpl->assign('rows', $rows);
       $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
 
@@ -1129,6 +1152,61 @@ class PHPFSPOT {
 
    } // get_calendar()
 
+   public function getExport($mode)
+   {
+      $pictures = $this->getPhotoSelection();
+      $current_tags = $this->getCurrentTags();  
+
+      if(!isset($_SERVER['HTTPS'])) $protocol = "http";
+      else $protocol = "https";
+
+      $server_name = $_SERVER['SERVER_NAME'];
+
+      foreach($pictures as $picture) {
+
+         $orig_url = $protocol ."://". $server_name . $this->cfg->web_path ."index.php?mode=showp&id=". $picture;
+         if($current_tags != "") {
+            $orig_url.= "&tags=". $current_tags;
+         } 
+
+         $thumb_url = $protocol ."://". $server_name . $this->cfg->web_path ."phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width;
+
+         switch($mode) {
+
+            case 'HTML':
+               // <a href="%pictureurl%"><img src="%thumbnailurl%" ></a>
+               print htmlspecialchars("<a href=\"". $orig_url ."\"><img src=\"". $thumb_url ."\" /></a>") ."<br />\n";
+               break;
+               
+            case 'MoinMoin':
+               // [%pictureurl% %thumbnailurl%]
+               print htmlspecialchars(" * [".$orig_url." ".$thumb_url."&fake=1.jpg]") ."<br />\n";
+               break;
+         }
+
+      }
+
+   } // getExport()
+
+   private function getCurrentTags()
+   {
+      $current_tags = "";
+      if($_SESSION['selected_tags'] != "") {
+         foreach($_SESSION['selected_tags'] as $tag)
+            $current_tags.= $tag .",";
+         $current_tags = substr($current_tags, 0, strlen($current_tags)-1);
+      }
+      return $current_tags;
+
+   } // getCurrentTags()
+
+   public function getCurrentPhoto()
+   {
+      if(isset($_SESSION['current_photo'])) {
+         print $_SESSION['current_photo'];
+      }
+   } // getCurrentPhoto()
+
 }
 
 ?>