some code for issue24
[phpfspot.git] / phpfspot.class.php
index 204c8a7374f4c687ba88ebb2e96d149943f98c7e..92a0199a339bdbe89c949e6a2a6d4289a2a81121 100644 (file)
@@ -55,6 +55,8 @@ 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']);
+      $this->tmpl->assign('from_date', $this->get_calendar());
+      $this->tmpl->assign('to_date', $this->get_calendar());
 
       switch($_GET['mode']) {
          case 'showpi':
@@ -112,6 +114,22 @@ class PHPFSPOT {
 
    } // get_photo_details
 
+   public function getPhotoName($idx)
+   {
+      if($details = $this->get_photo_details($idx)) {
+
+         $name = $details['name'];
+
+         if(strlen($name) > 15) {
+            $name = substr($name, 0, 10) ."...". substr($name, -10);
+         }
+
+         return $name;
+   
+      }
+
+   } // getPhotoName()
+
    public function translate_path($path, $width = 0)
    {  
       return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
@@ -161,9 +179,16 @@ class PHPFSPOT {
 
       $meta = $this->get_meta_informations($orig_path);
 
+      /* If EXIF data are available, use them */
+      if(isset($meta['ExifImageWidth'])) {
+         $meta_res = $meta['ExifImageWidth'] ."x". $meta['ExifImageLength'];
+      } else {
+         $info = getimagesize($orig_path);
+         $meta_res = $info[0] ."x". $info[1]; 
+      }
+
       $meta_date = isset($meta['FileDateTime']) ? strftime("%a %x %X", $meta['FileDateTime']) : "n/a";
       $meta_make = isset($meta['Make']) ? $meta['Make'] ." ". $meta['Model'] : "n/a";
-      $meta_res  = isset($meta['ExifImageWidth']) ?  $meta['ExifImageWidth'] ."x". $meta['ExifImageLength'] : "n/a";
       $meta_size = isset($meta['FileSize']) ? round($meta['FileSize']/1024, 1) ."kbyte" : "n/a";
 
       if(file_exists($thumb_path)) {
@@ -439,11 +464,13 @@ class PHPFSPOT {
       $img_height[$rows] = Array();
       $img_width[$rows] = Array();
       $img_id[$rows] = Array();
+      $img_name[$rows] = 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]);
 
          $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
 
@@ -544,6 +571,7 @@ class PHPFSPOT {
       $this->tmpl->assign('img_width', $img_width);
       $this->tmpl->assign('img_height', $img_height);
       $this->tmpl->assign('img_id', $img_id);
+      $this->tmpl->assign('img_name', $img_name);
       $this->tmpl->assign('rows', $rows);
       $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
 
@@ -617,21 +645,21 @@ class PHPFSPOT {
 
       switch($meta['Orientation']) {
 
-         case 1:
+         case 1: /* top, left */
             $rotate = 0; $flip = false; break;
-         case 2:
+         case 2: /* top, right */
             $rotate = 0; $flip = true; break;
-         case 3:
+         case 3: /* bottom, left */
             $rotate = 180; $flip = false; break;
-         case 4:
+         case 4: /* bottom, right */
             $rotate = 180; $flip = true; break;
-         case 5:
+         case 5: /* left side, top */
             $rotate = 90; $flip = true; break;
-         case 6:
+         case 6: /* right side, top */
             $rotate = 90; $flip = false; break;
-         case 7:
+         case 7: /* left side, bottom */
             $rotate = 270; $flip = true; break;
-         case 8:
+         case 8: /* right side, bottom */
             $rotate = 270; $flip = false; break;
       }
 
@@ -654,6 +682,14 @@ class PHPFSPOT {
          return true;
       }
 
+      // If the image will be rotate because EXIF orientation said so
+      // 'virtually rotate' the image for further calculations
+      if($rotate == 90 || $rotate == 270) {
+         $tmp = $cur_width;
+         $cur_width = $cur_height;
+         $cur_height = $tmp;
+      }
+
       /* calculates aspect ratio */
       $aspect_ratio = $cur_height / $cur_width;
 
@@ -675,6 +711,14 @@ class PHPFSPOT {
          // gets rotated, use this high to scale the image
          $new_h = $tmp_h;
          $new_w = abs($new_h / $aspect_ratio);
+
+         // If the image will be rotate because EXIF orientation said so
+         // now 'virtually rotate' back the image for the image manipulation
+         if($rotate == 90 || $rotate == 270) {
+            $tmp = $new_w;
+            $new_w = $new_h;
+            $new_h = $tmp;
+         }
       }
 
       /* creates new image of that size */
@@ -683,7 +727,7 @@ class PHPFSPOT {
       imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
 
       /* copies resized portion of original image into new image */
-      imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
+      imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
 
       /* needs the image to be flipped horizontal? */
       if($flip) {
@@ -980,10 +1024,15 @@ class PHPFSPOT {
       /* Check for HTML_AJAX PEAR package, lent from Horde project */
       ini_set('track_errors', 1);
       @include_once 'HTML/AJAX/Server.php';
-      if(isset($php_errormsg)) {
+      if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
          print "PEAR HTML_AJAX package is missing<br />\n";
          $missing = true;
       }
+      @include_once 'Calendar/Calendar.php';
+      if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
+         print "PEAR Calendar package is missing<br />\n";
+         $missing = true;
+      }
       ini_restore('track_errors');
 
       if(isset($missing))
@@ -1017,6 +1066,38 @@ class PHPFSPOT {
 
    } // _warning()
 
+   private function get_calendar()
+   {
+//      require_once CALENDAR_ROOT.'Year.php';
+//      require_once CALENDAR_ROOT.'Month.php';
+//      require_once CALENDAR_ROOT.'Day.php';
+
+//      $Year = new Calendar_Year();
+//      $Month = new Calendar_Month();
+//      $Day = new Calendar_Day();
+
+      $output = "<select name=\"year\">\n";
+      for($year = 1990; $year <= date("Y"); $year++) {
+         $output.= "<option value=\"". $year ."\">". $year ."</option>\n";
+      }
+      $output.= "</select>\n";
+
+      $output.= "<select name=\"month\">\n";
+      for($month = 1; $month <= 12; $month++) {
+         $output.= "<option value=\"". $month ."\">". $month ."</option>\n";
+      }
+      $output.= "</select>\n";
+
+      $output.= "<select name=\"day\">\n";
+      for($day = 1; $day <= 31; $day++) {
+         $output.= "<option value=\"". $day ."\">". $day ."</option>\n";
+      }
+      $output.= "</select>\n";
+
+      return $output;
+
+   } // get_calendar()
+
 }
 
 ?>