From: Andreas Unterkircher Date: Fri, 18 Jan 2008 19:26:23 +0000 (+0100) Subject: issue103, ensure showPhotoIndex() returns to the right page X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=commitdiff_plain;h=1b98418fc7f31d2d10364a60bc798ee85ef7add1;ds=sidebyside issue103, ensure showPhotoIndex() returns to the right page Signed-off-by: Andreas Unterkircher --- diff --git a/phpfspot.class.php b/phpfspot.class.php index cf0a60c..17ec450 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -503,7 +503,7 @@ class PHPFSPOT { $this->tmpl->assign('image_filename', $this->parse_uri($details['uri'], 'filename')); $this->tmpl->assign('tags', $this->get_photo_tags($photo)); - $this->tmpl->assign('current', $current); + $this->tmpl->assign('current', $this->getCurrentPage($current, $count)); if($previous_img) { $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");"); @@ -955,12 +955,12 @@ class PHPFSPOT { if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "") $anchor = $_SESSION['begin_with']; + /* if all thumbnails should be shown on one page */ if(!isset($this->cfg->thumbs_per_page) || $this->cfg->thumbs_per_page == 0) { - $begin_with = 0; $end_with = $count; - } + /* thumbnails should be splitted up in several pages */ elseif($this->cfg->thumbs_per_page > 0) { if(!isset($_SESSION['begin_with']) || $_SESSION['begin_with'] == 0) { @@ -2464,6 +2464,27 @@ class PHPFSPOT { } // cleanup_phpfspot_db() + /** + * return first image of the page, the $current photo + * lies in. + * + * this function is used to find out the first photo of the + * current page, in which the $current photo lies. this is + * used to display the correct photo, when calling showPhotoIndex() + * from showImage() + */ + private function getCurrentPage($current, $max) + { + if(isset($this->cfg->thumbs_per_page) && !empty($this->cfg->thumbs_per_page)) { + for($page_start = 0; $page_start <= $max; $page_start+=$this->cfg->thumbs_per_page) { + if($current >= $page_start && $current < ($page_start+$this->cfg->thumbs_per_page)) + return $page_start; + } + } + return 0; + + } // getCurrentPage() + } // class PHPFSPOT ?>