X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=blobdiff_plain;f=phpfspot.class.php;h=f3944d1575ccbc231a38019a8494e7c63c94e69d;hp=980dc818a09ed510a3d62e6a2f0f727594b9788b;hb=179073f20df0b8ad23acf777ef7925f7516b4b3e;hpb=5d397db3e6ff4dc02bf989bb64945e990d2c9da2 diff --git a/phpfspot.class.php b/phpfspot.class.php index 980dc81..f3944d1 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -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)) { @@ -192,11 +217,14 @@ class PHPFSPOT { if($previous_img) { $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");"); + $this->tmpl->assign('prev_img', $previous_img); } if($next_img) { $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");"); + $this->tmpl->assign('next_img', $next_img); } + $this->tmpl->assign('mini_width', $this->cfg->mini_width); $this->tmpl->show("single_photo.tpl"); @@ -263,7 +291,7 @@ class PHPFSPOT { { // return all selected tags if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) { - print "". $this->tags[$tag] ." "; + print "". $this->tags[$tag] .", "; } } @@ -399,6 +427,9 @@ class PHPFSPOT { $count = count($photos); + if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "") + $anchor = $_SESSION['begin_with']; + if(!isset($this->cfg->rows_per_page) || $this->cfg->rows_per_page == 0) { $begin_with = 0; @@ -435,10 +466,14 @@ class PHPFSPOT { $images[$rows] = Array(); $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]); @@ -466,6 +501,7 @@ class PHPFSPOT { if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') $this->tmpl->assign('searchfor', $_SESSION['searchfor']); + /* do we have to display the page selector ? */ if($this->cfg->rows_per_page != 0) { /* calculate the page switchers */ @@ -477,19 +513,13 @@ class PHPFSPOT { if($end_with < $count) $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");"); - /* page selector */ $photo_per_page = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row; - - /* until 6 pages we show the selector from 1-6 - everything large will be - 1 ... 2 3 4 (5) 6 7 ... 9 - */ $last_page = ceil($count / $photo_per_page); + /* get the current selected page */ if($begin_with == 0) { $current_page = 1; - } - else { + } else { $current_page = 0; for($i = $begin_with; $i >= 0; $i-=$photo_per_page) { $current_page++; @@ -508,11 +538,34 @@ class PHPFSPOT { else $style = ""; - $page_select.= " "; + $select = " "; + + // until 9 pages we show the selector from 1-9 + if($last_page <= 9) { + $page_select.= $select; + continue; + } else { + if($i == 1 /* first page */ || + $i == $last_page /* last page */ || + $i == $current_page /* current page */ || + $i == ceil($last_page * 0.25) /* first quater */ || + $i == ceil($last_page * 0.5) /* half */ || + $i == ceil($last_page * 0.75) /* third quater */ || + (in_array($i, array(1,2,3,4,5,6)) && $current_page <= 4) /* the first 6 */ || + (in_array($i, array($last_page, $last_page-1, $last_page-2, $last_page-3, $last_page-4, $last_page-5)) && $current_page >= $last_page-4) /* the last 6 */ || + $i == $current_page-3 || $i == $current_page-2 || $i == $current_page-1 /* three before */ || + $i == $current_page+3 || $i == $current_page+2 || $i == $current_page+1 /* three after */) { + + $page_select.= $select; + continue; + } + } + + $page_select.= "."; } /* only show the page selector if we have more then one page */ @@ -527,7 +580,10 @@ class PHPFSPOT { $current_tags = substr($current_tags, 0, strlen($current_tags)-1); } - $extern_link = "http://". $_SERVER['SERVER_NAME'] ."/index.php?mode=showpi&tags=". $current_tags; + $extern_link = "http://". $_SERVER['SERVER_NAME'] ."/index.php?mode=showpi"; + if($current_tags != "") { + $extern_link.= "&tags=". $current_tags; + } $this->tmpl->assign('extern_link', $extern_link); $this->tmpl->assign('count', $count); @@ -535,10 +591,15 @@ class PHPFSPOT { $this->tmpl->assign('images', $images); $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); + $this->tmpl->show("photo_index.tpl"); + if(isset($anchor)) + print "\n"; } // showPhotoIndex() @@ -605,21 +666,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; } @@ -631,23 +692,55 @@ class PHPFSPOT { } /* grabs the height and width */ - $new_w = imagesx($src_img); - $new_h = imagesy($src_img); + $cur_width = imagesx($src_img); + $cur_height = imagesy($src_img); // If requested width is more then the actual image width, // do not generate a thumbnail - if($width >= $new_w) { + if($width >= $cur_width) { imagedestroy($src_img); 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 = $new_h / $new_w; + $aspect_ratio = $cur_height / $cur_width; /* sets new size */ - $new_w = $width; - $new_h = abs($new_w * $aspect_ratio); + if($aspect_ratio < 1) { + $new_w = $width; + $new_h = abs($new_w * $aspect_ratio); + } else { + /* 'virtually' rotate the image and calculate it's ratio */ + $tmp_w = $cur_height; + $tmp_h = $cur_width; + /* now get the ratio from the 'rotated' image */ + $tmp_ratio = $tmp_h/$tmp_w; + /* now calculate the new dimensions */ + $tmp_w = $width; + $tmp_h = abs($tmp_w * $tmp_ratio); + + // now that we know, how high they photo should be, if it + // 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 */ $dst_img = imagecreatetruecolor($new_w, $new_h); @@ -655,7 +748,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) { @@ -667,7 +760,7 @@ class PHPFSPOT { } if($rotate) { - print "(ROTATE)"; + $this->_debug("(ROTATE)"); $dst_img = $this->rotateImage($dst_img, $rotate); } @@ -726,6 +819,7 @@ class PHPFSPOT { $this->cfg->thumb_width, $this->cfg->bubble_width, $this->cfg->photo_width, + $this->cfg->mini_width, ); /* get details from F-Spot's database */ @@ -952,10 +1046,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
\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
\n"; + $missing = true; + } ini_restore('track_errors'); if(isset($missing)) @@ -989,6 +1088,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 = "\n"; + + $output.= "\n"; + + $output.= "\n"; + + return $output; + + } // get_calendar() + } ?>