some style improvements on photo view
[phpfspot.git] / phpfspot.class.php
index 525b5c1b0d4b8f8dc3d0858f53da994cc97909ef..191e06627f9e8dfc9f13e27877eb2387763d7bbe 100644 (file)
@@ -47,8 +47,19 @@ class PHPFSPOT {
       $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
       $this->tmpl->assign('page_title', $this->cfg->page_title);
       $this->tmpl->assign('current_condition', $_SESSION['tag_condition']);
+
+      switch($_GET['mode']) {
+         case 'showpi':
+            if(isset($_GET['tags'])) {
+               $_SESSION['selected_tags'] = split(',', $_GET['tags']);
+            }
+            break;
+      }
+
+      $this->tmpl->assign('content_page', 'welcome.tpl');
       $this->tmpl->show("index.tpl");
 
+
    } // show()
 
    private function get_tags()
@@ -121,6 +132,14 @@ class PHPFSPOT {
       $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
       $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
 
+      if(!file_exists($orig_path)) {
+         print "Photo ". $orig_path ." does not exist!<br />\n";
+      }
+
+      if(!is_readable($orig_path)) {
+         print "Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n";
+      }
+
       /* If the thumbnail doesn't exist yet, try to create it */
       if(!file_exists($thumb_path)) {
          $this->gen_thumb($photo, 0, 1);
@@ -410,7 +429,14 @@ class PHPFSPOT {
          if($end_with < $count)
             $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");"); 
       }
-   
+
+      $current_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&tags=". $current_tags;
+
+      $this->tmpl->assign('extern_link', $extern_link);
       $this->tmpl->assign('count', $count);
       $this->tmpl->assign('width', $this->cfg->thumb_width);
       $this->tmpl->assign('images', $images);
@@ -431,13 +457,24 @@ class PHPFSPOT {
          $direction = "bubbleimg_down";
 
       $details = $this->get_photo_details($photo);
+      $orig_path = $this->translate_path($details['directory_path'])  ."/". $details['name'];
 
       $image_url = "phpfspot_img.php?idx=". $photo ."&amp;width=". $this->cfg->bubble_width;
 
-      $filesize = filesize($this->translate_path($details['directory_path'])  ."/". $details['name']);
+      $filesize = filesize($orig_path);
       $filesize = rand($filesize/1024, 2);
 
-      $img = getimagesize($this->translate_path($details['directory_path'])  ."/". $details['name']);
+      if(!file_exists($orig_path)) {
+         print "Photo ". $orig_path ." does not exist!<br />\n";
+         return;
+      }
+      
+      if(!is_readable($orig_path)) {
+         print "Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n";
+         return;
+      }
+
+      $img = getimagesize($orig_path);
 
       $this->tmpl->assign('file_size', $filesize);
       $this->tmpl->assign('width', $img[0]);
@@ -660,11 +697,17 @@ class PHPFSPOT {
 
    } // setTagCondition()
 
-   public function startSearch($searchfor)
+   public function startTagSearch($searchfor)
    {
       $_SESSION['searchfor'] = $searchfor;
+      $_SESSION['selected_tags'] = Array();
+
+      foreach($this->avail_tags as $tag) {
+         if(preg_match('/'. $searchfor .'/i', $this->tags[$tag]))
+            array_push($_SESSION['selected_tags'], $tag);
+      }
 
-   } // startSearch()
+   } // startTagSearch()
 
    private function rotateImage($img, $degrees)
    {
@@ -755,6 +798,32 @@ class PHPFSPOT {
 
    } // get_photo_tags()
 
+   function showTextImage($txt, $color=000000, $space=4, $font=4, $w=300)
+   {
+      if (strlen($color) != 6) 
+         $color = 000000;
+
+      $int = hexdec($color);
+      $h = imagefontheight($font);
+      $fw = imagefontwidth($font);
+      $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
+      $lines = count($txt);
+      $im = imagecreate($w, (($h * $lines) + ($lines * $space)));
+      $bg = imagecolorallocate($im, 255, 255, 255);
+      $color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
+      $y = 0;
+
+      foreach ($txt as $text) {
+         $x = (($w - ($fw * strlen($text))) / 2);
+         imagestring($im, $font, $x, $y, $text, $color);
+         $y += ($h + $space);
+      }
+
+      Header("Content-type: image/png");
+      ImagePng($im);
+
+   } // showTextImage()
+
 }
 
 ?>