fixed path problem (missing "/")
[phpfspot.git] / phpfspot_img.php
index 3599b2b3a89dbf30e7406e389973df148a5d516f..b6952041dcedc69b0451baac8302aca8363eea62 100644 (file)
@@ -64,13 +64,17 @@ class PHPFSPOT_IMG {
     * @param integer $idx
     * @param integer $width
     */
-   public function showImg($idx, $width = 0)
+   public function showImg($idx, $width = 0, $version = NULL)
    {
       if($idx == 'rand')
          $idx = $this->parent->get_random_photo();
 
-      $details = $this->parent->get_photo_details($idx);
-   
+      /* display the lastest available version, if a wrong version has been requested */
+      if(!isset($version) || !$this->parent->is_valid_version($idx, $version))
+         $version = $this->parent->get_latest_version($idx);
+
+      $details = $this->parent->get_photo_details($idx, $version);
+
       if(!$details) {
          $this->parent->showTextImage("The image (". $idx .") you requested is unknown");
          return;
@@ -82,11 +86,19 @@ class PHPFSPOT_IMG {
       }
       /* show thumbnail */
       else {
-         /* if no entry for this photo is yet in the database, create thumb */
+
+         if(!$this->parent->is_valid_width($width)) {
+            $this->parent->showTextImage("Requested width ". $width ."px is not valid!");
+            return;
+         }
+         /* check for an entry if we already handled this photo before. If not,
+            create a thumbnail for it.
+         */
          if(!$this->parent->getMD5($idx)) {
             $this->parent->gen_thumb($idx);
          }
-         $fullpath = $this->parent->get_thumb_path($width, $idx);
+         /* get the full filesystem path to the thumbnail */
+         $fullpath = $this->parent->get_thumb_path($width, $idx, $version);
          /* if the thumb file does not exist, create it */
          if(!file_exists($fullpath)) {
             $this->parent->gen_thumb($idx);
@@ -150,7 +162,10 @@ class PHPFSPOT_IMG {
       if(!$this->parent->getMD5($idx)) {
          $this->parent->gen_thumb($idx);
       }
-      $fullpath = $this->parent->get_thumb_path($width, $idx);
+
+      $version = $this->parent->get_latest_version($idx);
+
+      $fullpath = $this->parent->get_thumb_path($width, $idx, $version);
       /* if the thumb file does not exist, create it */
       if(!file_exists($fullpath)) {
          $this->parent->gen_thumb($idx);
@@ -196,9 +211,16 @@ if(isset($_GET['idx']) && (is_numeric($_GET['idx']) || $_GET['idx'] == 'rand'))
    $img = new PHPFSPOT_IMG;
 
    if(isset($_GET['width']) && is_numeric($_GET['width'])) 
-      $img->showImg($_GET['idx'], $_GET['width']);
+      $width = $_GET['width'];
+   else
+      $width = NULL;
+
+   if(isset($_GET['version']) && is_numeric($_GET['version']))
+      $version = $_GET['version'];
    else
-      $img->showImg($_GET['idx']);
+      $version = NULL;
+
+   $img->showImg($_GET['idx'], $width, $version);
 
    exit(0);
 }
@@ -212,5 +234,4 @@ if(isset($_GET['tagidx']) && is_numeric($_GET['tagidx'])) {
 
 }
 
-
 ?>