X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=blobdiff_plain;f=phpfspot_img.php;h=b6952041dcedc69b0451baac8302aca8363eea62;hp=3599b2b3a89dbf30e7406e389973df148a5d516f;hb=ad8f72f790097776757dfcd3eda84272fb17d142;hpb=7e3758cb44cc14bb68c4724849e923741dc9982b diff --git a/phpfspot_img.php b/phpfspot_img.php index 3599b2b..b695204 100644 --- a/phpfspot_img.php +++ b/phpfspot_img.php @@ -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'])) { } - ?>