shrink photo name also on generate-thumbnails-output
[phpfspot.git] / phpfspot.class.php
index e0a87a567e184ac83174bc222eee0745dc4ddc61..14ce0c7afa285d7f87af6050f10ed36327e19399 100644 (file)
@@ -115,10 +115,10 @@ class PHPFSPOT {
                $_SESSION['selected_tags'] = $this->extractTags($_GET['tags']);
             }
             if(isset($_GET['from_date']) && $this->isValidDate($_GET['from_date'])) {
-               $_SESSION['from_date'] = strtotime($_GET['from_date']);
+               $_SESSION['from_date'] = strtotime($_GET['from_date'] ." 00:00:00");
             }
             if(isset($_GET['to_date']) && $this->isValidDate($_GET['to_date'])) {
-               $_SESSION['to_date'] = strtotime($_GET['to_date']);
+               $_SESSION['to_date'] = strtotime($_GET['to_date'] ." 23:59:59");
             }
             break;
          case 'showp':
@@ -226,15 +226,29 @@ class PHPFSPOT {
    public function getPhotoName($idx, $limit = 0)
    {
       if($details = $this->get_photo_details($idx)) {
-         $name = $details['name'];
-         if($limit != 0 && strlen($name) > $limit) {
-            $name = substr($name, 0, $limit-5) ."...". substr($name, -($limit-5));
-         }
+         $name = $this->shrink_text($details['name'], $limit);
          return $name;
       }
 
    } // getPhotoName()
 
+   /**
+    * shrink text according provided limit
+    *
+    * If the length of the name exceeds $limit the
+    * text will be shortend and some content in between
+    * will be replaced with "..." 
+    */
+   private function shrink_text($text, $limit)
+   {
+      if($limit != 0 && strlen($text) > $limit) {
+         $text = substr($text, 0, $limit-5) ."...". substr($text, -($limit-5));
+      }
+
+      return $text;
+
+   } // shrink_text();
+
    /**
     * translate f-spoth photo path
     * 
@@ -292,7 +306,7 @@ 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);
+      $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo);
 
       if(!file_exists($orig_path)) {
          $this->_error("Photo ". $orig_path ." does not exist!<br />\n");
@@ -305,7 +319,7 @@ class PHPFSPOT {
       /* If the thumbnail doesn't exist yet, try to create it */
       if(!file_exists($thumb_path)) {
          $this->gen_thumb($photo, true);
-         $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
+         $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo);
       }
 
       /* get f-spot database meta information */
@@ -755,7 +769,7 @@ class PHPFSPOT {
          $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]);
+         $thumb_path = $this->get_thumb_path($this->cfg->thumb_width, $photos[$i]);
 
          if(file_exists($thumb_path)) {
             $info = getimagesize($thumb_path); 
@@ -1125,11 +1139,16 @@ class PHPFSPOT {
 
       $file_md5 = md5_file($full_path);
 
-      $this->_debug("Image [". $idx ."] ". $details['name'] ." Thumbnails:");
+      $this->_debug("Image [". $idx ."] ". $this->shrink_text($details['name'], 20) ." Thumbnails:");
 
       foreach($resolutions as $resolution) {
 
-         $thumb_path = $this->cfg->base_path ."/thumbs/". $resolution ."_". $file_md5;
+         $thumb_sub_path = substr($file_md5, 0, 2);
+         $thumb_path = $this->cfg->base_path ."/thumbs/". $thumb_sub_path ."/". $resolution ."_". $file_md5;
+
+         if(!file_exists(dirname($thumb_path))) {
+            mkdir(dirname($thumb_path), 0755);
+         }
 
          /* if the thumbnail file doesn't exist, create it */
          if(!file_exists($thumb_path)) {
@@ -1442,9 +1461,9 @@ class PHPFSPOT {
     */
    private function get_calendar($mode)
    {
-      $year = $_SESSION[$mode .'_date'] ? date("Y", strtotime($_SESSION[$mode .'_date'])) : date("Y");
-      $month = $_SESSION[$mode .'_date'] ? date("m", strtotime($_SESSION[$mode .'_date'])) : date("m");
-      $day = $_SESSION[$mode .'_date'] ? date("d", strtotime($_SESSION[$mode .'_date'])) : date("d");
+      $year = $_SESSION[$mode .'_date'] ? date("Y", $_SESSION[$mode .'_date']) : date("Y");
+      $month = $_SESSION[$mode .'_date'] ? date("m", $_SESSION[$mode .'_date']) : date("m");
+      $day = $_SESSION[$mode .'_date'] ? date("d", $_SESSION[$mode .'_date']) : date("d");
 
       $output = "<input type=\"text\" size=\"3\" id=\"". $mode ."year\" value=\"". $year ."\"";
       if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\"";
@@ -1623,9 +1642,8 @@ class PHPFSPOT {
       if(isset($_SESSION['current_photo']) && $_SESSION['start_action'] == 'showp') {
          return "show_photo";
       }
-      elseif((isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) ||
-         (isset($_SESSION['from_date']) && isset($_SESSION['to_date']))) {
-         return "showpi";
+      elseif(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
+         return "showpi_tags";
       }
       elseif(isset($_SESSION['start_action']) && $_SESSION['start_action'] == 'showpi') {
          return "showpi";
@@ -1809,6 +1827,22 @@ class PHPFSPOT {
    
    } // extractTags()
 
+   /**
+    * returns the full path to a thumbnail
+    */
+   public function get_thumb_path($width, $photo)
+   {
+      $sub_path = substr($this->getMD5($photo), 0, 2);
+      return $this->cfg->base_path
+         . "/thumbs/"
+         . $sub_path
+         . "/"
+         . $width
+         . "_"
+         . $this->getMD5($photo);
+
+   } // get_thumb_path()
+
 }
 
 ?>