3 require_once "phpfspot_cfg.php";
4 require_once "phpfspot_db.php";
5 require_once "phpfspot_tmpl.php";
16 public function __construct()
18 /* Check necessary requirements */
19 if(!$this->checkRequirements()) {
23 $this->cfg = new PHPFSPOT_CFG;
25 $this->db = new PHPFSPOT_DB(&$this, $this->cfg->fspot_db);
26 $this->cfg_db = new PHPFSPOT_DB(&$this, $this->cfg->phpfspot_db);
27 $this->check_config_table();
29 $this->tmpl = new PHPFSPOT_TMPL($this);
35 if(!isset($_SESSION['tag_condition']))
36 $_SESSION['tag_condition'] = 'or';
38 if(!isset($_SESSION['searchfor']))
39 $_SESSION['searchfor'] = '';
41 // if begin_with is still set but rows_per_page is now 0, unset it
42 if(isset($_SESSION['begin_with']) && $this->cfg->rows_per_page == 0)
43 unset($_SESSION['begin_with']);
47 public function __destruct()
52 public function show()
54 $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
55 $this->tmpl->assign('page_title', $this->cfg->page_title);
56 $this->tmpl->assign('current_condition', $_SESSION['tag_condition']);
57 $this->tmpl->assign('from_date', $this->get_calendar());
58 $this->tmpl->assign('to_date', $this->get_calendar());
60 switch($_GET['mode']) {
62 if(isset($_GET['tags'])) {
63 $_SESSION['selected_tags'] = split(',', $_GET['tags']);
67 if(isset($_GET['tags'])) {
68 $_SESSION['selected_tags'] = split(',', $_GET['tags']);
70 if(isset($_GET['id'])) {
71 $_SESSION['current_photo'] = $_GET['id'];
75 $this->tmpl->show("export.tpl");
81 $this->tmpl->assign('content_page', 'welcome.tpl');
82 $this->tmpl->show("index.tpl");
87 private function get_tags()
90 $this->avail_tags = Array();
93 $result = $this->db->db_query("
96 ORDER BY sort_priority ASC
99 while($row = $this->db->db_fetch_object($result)) {
101 $tag_id = $row['id'];
102 $tag_name = $row['name'];
104 /* check if config requests to ignore this tag */
105 if(in_array($row['name'], $this->cfg->hide_tags))
108 $this->tags[$tag_id] = $tag_name;
109 $this->avail_tags[$count] = $tag_id;
117 public function get_photo_details($idx)
119 $result = $this->db->db_query("
122 WHERE id='". $idx ."'
125 return $this->db->db_fetch_object($result);
127 } // get_photo_details
129 public function getPhotoName($idx, $limit = 0)
131 if($details = $this->get_photo_details($idx)) {
132 $name = $details['name'];
133 if($limit != 0 && strlen($name) > $limit) {
134 $name = substr($name, 0, $limit-5) ."...". substr($name, -($limit-5));
141 public function translate_path($path, $width = 0)
143 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
147 public function showPhoto($photo)
149 $all_photos = $this->getPhotoSelection();
150 $count = count($all_photos);
152 for($i = 0; $i < $count; $i++) {
155 $next_img = $all_photos[$i];
159 if($all_photos[$i] == $photo) {
163 $previous_img = $all_photos[$i];
166 if($photo == $all_photos[$i]) {
171 $details = $this->get_photo_details($photo);
172 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
173 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
175 if(!file_exists($orig_path)) {
176 $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
179 if(!is_readable($orig_path)) {
180 $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
183 /* If the thumbnail doesn't exist yet, try to create it */
184 if(!file_exists($thumb_path)) {
185 $this->gen_thumb($photo, true);
188 $meta = $this->get_meta_informations($orig_path);
190 /* If EXIF data are available, use them */
191 if(isset($meta['ExifImageWidth'])) {
192 $meta_res = $meta['ExifImageWidth'] ."x". $meta['ExifImageLength'];
194 $info = getimagesize($orig_path);
195 $meta_res = $info[0] ."x". $info[1];
198 $meta_date = isset($meta['FileDateTime']) ? strftime("%a %x %X", $meta['FileDateTime']) : "n/a";
199 $meta_make = isset($meta['Make']) ? $meta['Make'] ." ". $meta['Model'] : "n/a";
200 $meta_size = isset($meta['FileSize']) ? round($meta['FileSize']/1024, 1) ."kbyte" : "n/a";
202 $current_tags = $this->getCurrentTags();
203 $extern_link = "index.php?mode=showp&id=". $photo;
204 if($current_tags != "") {
205 $extern_link.= "&tags=". $current_tags;
208 $this->tmpl->assign('extern_link', $extern_link);
210 if(file_exists($thumb_path)) {
212 $info = getimagesize($thumb_path);
214 $this->tmpl->assign('description', $details['description']);
215 $this->tmpl->assign('image_name', $details['name']);
217 $this->tmpl->assign('width', $info[0]);
218 $this->tmpl->assign('height', $info[1]);
219 $this->tmpl->assign('ExifMadeOn', $meta_date);
220 $this->tmpl->assign('ExifMadeWith', $meta_make);
221 $this->tmpl->assign('ExifOrigResolution', $meta_res);
222 $this->tmpl->assign('ExifFileSize', $meta_size);
224 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
225 $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo);
227 $this->tmpl->assign('tags', $this->get_photo_tags($photo));
228 $this->tmpl->assign('current', $current);
231 $this->_warning("Can't open file ". $thumb_path ."\n");
235 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
236 $this->tmpl->assign('prev_img', $previous_img);
240 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
241 $this->tmpl->assign('next_img', $next_img);
243 $this->tmpl->assign('mini_width', $this->cfg->mini_width);
245 $this->tmpl->show("single_photo.tpl");
249 public function getAvailableTags()
251 $result = $this->db->db_query("
252 SELECT tag_id as id, count(tag_id) as quantity
262 while($row = $this->db->db_fetch_object($result)) {
263 $tags[$row['id']] = $row['quantity'];
266 // change these font sizes if you will
267 $max_size = 125; // max font size in %
268 $min_size = 75; // min font size in %
270 // get the largest and smallest array values
271 $max_qty = max(array_values($tags));
272 $min_qty = min(array_values($tags));
274 // find the range of values
275 $spread = $max_qty - $min_qty;
276 if (0 == $spread) { // we don't want to divide by zero
280 // determine the font-size increment
281 // this is the increase per tag quantity (times used)
282 $step = ($max_size - $min_size)/($spread);
284 // loop through our tag array
285 foreach ($tags as $key => $value) {
287 if(isset($_SESSION['selected_tags']) && in_array($key, $_SESSION['selected_tags']))
290 // calculate CSS font-size
291 // find the $value in excess of $min_qty
292 // multiply by the font-size increment ($size)
293 // and add the $min_size set above
294 $size = $min_size + (($value - $min_qty) * $step);
295 // uncomment if you want sizes in whole %:
298 print "<a href=\"javascript:Tags('add', ". $key .");\" class=\"tag\" style=\"font-size: ". $size ."%;\">". $this->tags[$key] ."</a>, ";
302 } // getAvailableTags()
304 public function getSelectedTags()
307 foreach($this->avail_tags as $tag)
309 // return all selected tags
310 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
311 $output.= "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a>, ";
315 $output = substr($output, 0, strlen($output)-2);
318 } // getSelectedTags()
320 public function addTag($tag)
322 if(!isset($_SESSION['selected_tags']))
323 $_SESSION['selected_tags'] = Array();
325 if(!in_array($tag, $_SESSION['selected_tags']))
326 array_push($_SESSION['selected_tags'], $tag);
330 public function delTag($tag)
332 if(isset($_SESSION['selected_tags'])) {
333 $key = array_search($tag, $_SESSION['selected_tags']);
334 unset($_SESSION['selected_tags'][$key]);
335 sort($_SESSION['selected_tags']);
340 public function resetTags()
342 unset($_SESSION['selected_tags']);
346 public function resetPhotoView()
348 unset($_SESSION['current_photo']);
350 } // resetPhotoView();
352 public function resetTagSearch()
354 unset($_SESSION['searchfor']);
356 } // resetTagSearch()
358 public function getPhotoSelection()
360 $tagged_photos = Array();
362 /* return a search result */
363 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
364 $result = $this->db->db_query("
365 SELECT DISTINCT photo_id
371 WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'
374 while($row = $this->db->db_fetch_object($result)) {
375 array_push($tagged_photos, $row['photo_id']);
377 return $tagged_photos;
380 /* return according the selected tags */
381 if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
383 foreach($_SESSION['selected_tags'] as $tag)
384 $selected.= $tag .",";
385 $selected = substr($selected, 0, strlen($selected)-1);
387 if($_SESSION['tag_condition'] == 'or') {
388 $result = $this->db->db_query("
389 SELECT DISTINCT photo_id
393 WHERE pt.tag_id IN (". $selected .")
397 elseif($_SESSION['tag_condition'] == 'and') {
399 if(count($_SESSION['selected_tags']) >= 32) {
400 print "A SQLite limit of 32 tables within a JOIN SELECT avoids to<br />\n";
401 print "evaluate your tag selection. Please remove some tags from your selection.\n";
405 /* Join together a table looking like
407 pt1.photo_id pt1.tag_id pt2.photo_id pt2.tag_id ...
409 so the query can quickly return all images matching the
410 selected tags in an AND condition
415 SELECT DISTINCT pt1.photo_id
419 for($i = 0; $i < count($_SESSION['selected_tags']); $i++) {
421 INNER JOIN photo_tags pt". ($i+2) ."
422 ON pt1.photo_id=pt". ($i+2) .".photo_id
425 $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0];
426 for($i = 1; $i < count($_SESSION['selected_tags']); $i++) {
428 AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ."
431 $result = $this->db->db_query($query_str);
434 while($row = $this->db->db_fetch_object($result)) {
435 array_push($tagged_photos, $row['photo_id']);
437 return $tagged_photos;
440 /* return all available photos */
441 $result = $this->db->db_query("
442 SELECT DISTINCT photo_id
448 while($row = $this->db->db_fetch_object($result)) {
449 array_push($tagged_photos, $row['photo_id']);
451 return $tagged_photos;
453 } // getPhotoSelection()
455 public function showPhotoIndex()
457 $photos = $this->getPhotoSelection();
459 $count = count($photos);
461 if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
462 $anchor = $_SESSION['begin_with'];
464 if(!isset($this->cfg->rows_per_page) || $this->cfg->rows_per_page == 0) {
470 elseif($this->cfg->rows_per_page > 0) {
472 if(!$_SESSION['begin_with'] || $_SESSION['begin_with'] == 0)
476 $begin_with = $_SESSION['begin_with'];
478 // verify $begin_with - perhaps the thumbs-per-rows or
479 // rows-per-page variables have changed or the jump back
480 // from a photo wasn't exact - so calculate the real new
482 $multiplicator = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
483 for($i = 0; $i <= $count; $i+=$multiplicator) {
484 if($begin_with >= $i && $begin_with < $i+$multiplicator) {
491 $end_with = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
497 $images[$rows] = Array();
498 $img_height[$rows] = Array();
499 $img_width[$rows] = Array();
500 $img_id[$rows] = Array();
501 $img_name[$rows] = Array();
502 $img_title = Array();
504 for($i = $begin_with; $i < $end_with; $i++) {
506 $images[$rows][$cols] = $photos[$i];
507 $img_id[$rows][$cols] = $i;
508 $img_name[$rows][$cols] = htmlspecialchars($this->getPhotoName($photos[$i], 15));
509 $img_title[$rows][$cols] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0));
511 $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]);
513 if(file_exists($thumb_path)) {
514 $info = getimagesize($thumb_path);
515 $img_width[$rows][$cols] = $info[0];
516 $img_height[$rows][$cols] = $info[1];
519 if($cols == $this->cfg->thumbs_per_row-1) {
522 $images[$rows] = Array();
523 $img_width[$rows] = Array();
524 $img_height[$rows] = Array();
531 // +1 for for smarty's selection iteration
534 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '')
535 $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
537 /* do we have to display the page selector ? */
538 if($this->cfg->rows_per_page != 0) {
540 /* calculate the page switchers */
541 $previous_start = $begin_with - ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
542 $next_start = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
545 $this->tmpl->assign("previous_url", "javascript:showPhotoIndex(". $previous_start .");");
546 if($end_with < $count)
547 $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");");
549 $photo_per_page = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
550 $last_page = ceil($count / $photo_per_page);
552 /* get the current selected page */
553 if($begin_with == 0) {
557 for($i = $begin_with; $i >= 0; $i-=$photo_per_page) {
562 for($i = 1; $i <= $last_page; $i++) {
564 if($current_page == $i)
565 $style = "style=\"font-size: 125%;\"";
566 elseif($current_page-1 == $i || $current_page+1 == $i)
567 $style = "style=\"font-size: 105%;\"";
568 elseif(($current_page-5 >= $i) && ($i != 1) ||
569 ($current_page+5 <= $i) && ($i != $last_page))
570 $style = "style=\"font-size: 75%;\"";
574 $select = "<a href=\"javascript:showPhotoIndex(". (($i*$photo_per_page)-$photo_per_page) .");\"";
577 $select.= ">". $i ."</a> ";
579 // until 9 pages we show the selector from 1-9
580 if($last_page <= 9) {
581 $page_select.= $select;
584 if($i == 1 /* first page */ ||
585 $i == $last_page /* last page */ ||
586 $i == $current_page /* current page */ ||
587 $i == ceil($last_page * 0.25) /* first quater */ ||
588 $i == ceil($last_page * 0.5) /* half */ ||
589 $i == ceil($last_page * 0.75) /* third quater */ ||
590 (in_array($i, array(1,2,3,4,5,6)) && $current_page <= 4) /* the first 6 */ ||
591 (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 */ ||
592 $i == $current_page-3 || $i == $current_page-2 || $i == $current_page-1 /* three before */ ||
593 $i == $current_page+3 || $i == $current_page+2 || $i == $current_page+1 /* three after */) {
595 $page_select.= $select;
604 /* only show the page selector if we have more then one page */
606 $this->tmpl->assign('page_selector', $page_select);
610 $current_tags = $this->getCurrentTags();
611 $extern_link = "index.php?mode=showpi";
612 if($current_tags != "") {
613 $extern_link.= "&tags=". $current_tags;
616 $export_link = "index.php?mode=export";
618 $this->tmpl->assign('extern_link', $extern_link);
619 $this->tmpl->assign('export_link', $export_link);
620 $this->tmpl->assign('count', $count);
621 $this->tmpl->assign('width', $this->cfg->thumb_width);
622 $this->tmpl->assign('images', $images);
623 $this->tmpl->assign('img_width', $img_width);
624 $this->tmpl->assign('img_height', $img_height);
625 $this->tmpl->assign('img_id', $img_id);
626 $this->tmpl->assign('img_name', $img_name);
627 $this->tmpl->assign('img_title', $img_title);
628 $this->tmpl->assign('rows', $rows);
629 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
631 $this->tmpl->show("photo_index.tpl");
634 print "<script language=\"JavaScript\">self.location.hash = '#image". $anchor ."';</script>\n";
636 } // showPhotoIndex()
638 public function showCredits()
640 $this->tmpl->assign('version', $this->cfg->version);
641 $this->tmpl->assign('product', $this->cfg->product);
642 $this->tmpl->show("credits.tpl");
646 public function create_thumbnail($orig_image, $thumb_image, $width)
648 if(!file_exists($orig_image))
651 $details = getimagesize($orig_image);
653 /* check if original photo is a support image type */
654 if(!$this->checkifImageSupported($details['mime']))
657 $meta = $this->get_meta_informations($orig_image);
662 switch($meta['Orientation']) {
664 case 1: /* top, left */
665 $rotate = 0; $flip = false; break;
666 case 2: /* top, right */
667 $rotate = 0; $flip = true; break;
668 case 3: /* bottom, left */
669 $rotate = 180; $flip = false; break;
670 case 4: /* bottom, right */
671 $rotate = 180; $flip = true; break;
672 case 5: /* left side, top */
673 $rotate = 90; $flip = true; break;
674 case 6: /* right side, top */
675 $rotate = 90; $flip = false; break;
676 case 7: /* left side, bottom */
677 $rotate = 270; $flip = true; break;
678 case 8: /* right side, bottom */
679 $rotate = 270; $flip = false; break;
682 $src_img = @imagecreatefromjpeg($orig_image);
685 print "Can't load image from ". $orig_image ."\n";
689 /* grabs the height and width */
690 $cur_width = imagesx($src_img);
691 $cur_height = imagesy($src_img);
693 // If requested width is more then the actual image width,
694 // do not generate a thumbnail
696 if($width >= $cur_width) {
697 imagedestroy($src_img);
701 // If the image will be rotate because EXIF orientation said so
702 // 'virtually rotate' the image for further calculations
703 if($rotate == 90 || $rotate == 270) {
705 $cur_width = $cur_height;
709 /* calculates aspect ratio */
710 $aspect_ratio = $cur_height / $cur_width;
713 if($aspect_ratio < 1) {
715 $new_h = abs($new_w * $aspect_ratio);
717 /* 'virtually' rotate the image and calculate it's ratio */
718 $tmp_w = $cur_height;
720 /* now get the ratio from the 'rotated' image */
721 $tmp_ratio = $tmp_h/$tmp_w;
722 /* now calculate the new dimensions */
724 $tmp_h = abs($tmp_w * $tmp_ratio);
726 // now that we know, how high they photo should be, if it
727 // gets rotated, use this high to scale the image
729 $new_w = abs($new_h / $aspect_ratio);
731 // If the image will be rotate because EXIF orientation said so
732 // now 'virtually rotate' back the image for the image manipulation
733 if($rotate == 90 || $rotate == 270) {
740 /* creates new image of that size */
741 $dst_img = imagecreatetruecolor($new_w, $new_h);
743 imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
745 /* copies resized portion of original image into new image */
746 imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
748 /* needs the image to be flipped horizontal? */
752 for($x = 0; $x < $new_w; $x++) {
753 imagecopy($dst_img, $image, $x, 0, $w - $x - 1, 0, 1, $h);
758 $this->_debug("(ROTATE)");
759 $dst_img = $this->rotateImage($dst_img, $rotate);
762 /* write down new generated file */
763 $result = imagejpeg($dst_img, $thumb_image, 75);
766 imagedestroy($dst_img);
767 imagedestroy($src_img);
769 if($result === false) {
770 print "Can't write thumbnail ". $thumb_image ."\n";
776 } // create_thumbnail()
778 public function get_meta_informations($file)
780 return exif_read_data($file);
782 } // get_meta_informations()
784 public function check_config_table()
786 // if the config table doesn't exist yet, create it
787 if(!$this->cfg_db->db_check_table_exists("images")) {
788 $this->cfg_db->db_exec("
789 CREATE TABLE images (
790 img_idx int primary key,
796 } // check_config_table
799 * Generates a thumbnail from photo idx
801 * This function will generate JPEG thumbnails from provided F-Spot photo
804 * 1. Check if all thumbnail generations (width) are already in place and
806 * 2. Check if the md5sum of the original file has changed
807 * 3. Generate the thumbnails if needed
809 public function gen_thumb($idx = 0, $force = 0)
813 $resolutions = Array(
814 $this->cfg->thumb_width,
815 $this->cfg->photo_width,
816 $this->cfg->mini_width,
819 /* get details from F-Spot's database */
820 $details = $this->get_photo_details($idx);
822 /* calculate file MD5 sum */
823 $full_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
825 if(!file_exists($full_path)) {
826 $this->_warning("File ". $full_path ." does not exist\n");
830 if(!is_readable($full_path)) {
831 $this->_warning("File ". $full_path ." is not readable for ". get_current_user() ."\n");
835 $file_md5 = md5_file($full_path);
837 $this->_debug("Image [". $idx ."] ". $details['name'] ." Thumbnails:");
839 foreach($resolutions as $resolution) {
841 $thumb_path = $this->cfg->base_path ."/thumbs/". $resolution ."_". $file_md5;
843 /* if the thumbnail file doesn't exist, create it */
844 if(!file_exists($thumb_path)) {
846 $this->_debug(" ". $resolution ."px");
847 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
851 /* if the file hasn't changed there is no need to regen the thumb */
852 elseif($file_md5 != $this->getMD5($idx) || $force) {
854 $this->_debug(" ". $resolution ."px");
855 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
861 /* set the new/changed MD5 sum for the current photo */
863 $this->setMD5($idx, $file_md5);
870 public function getMD5($idx)
872 $result = $this->cfg_db->db_query("
875 WHERE img_idx='". $idx ."'
881 $img = $this->cfg_db->db_fetch_object($result);
882 return $img['img_md5'];
886 private function setMD5($idx, $md5)
888 $result = $this->cfg_db->db_exec("
889 REPLACE INTO images (img_idx, img_md5)
890 VALUES ('". $idx ."', '". $md5 ."')
895 public function setTagCondition($mode)
897 $_SESSION['tag_condition'] = $mode;
899 } // setTagCondition()
901 public function startTagSearch($searchfor)
903 $_SESSION['searchfor'] = $searchfor;
904 $_SESSION['selected_tags'] = Array();
906 foreach($this->avail_tags as $tag) {
907 if(preg_match('/'. $searchfor .'/i', $this->tags[$tag]))
908 array_push($_SESSION['selected_tags'], $tag);
911 } // startTagSearch()
913 private function rotateImage($img, $degrees)
915 if(function_exists("imagerotate"))
916 $img = imagerotate($img, $degrees, 0);
919 function imagerotate($src_img, $angle)
921 $src_x = imagesx($src_img);
922 $src_y = imagesy($src_img);
927 elseif ($src_x <= $src_y) {
931 elseif ($src_x >= $src_y) {
936 $rotate=imagecreatetruecolor($dest_x,$dest_y);
937 imagealphablending($rotate, false);
942 for ($y = 0; $y < ($src_y); $y++) {
943 for ($x = 0; $x < ($src_x); $x++) {
944 $color = imagecolorat($src_img, $x, $y);
945 imagesetpixel($rotate, $dest_x - $y - 1, $x, $color);
951 for ($y = 0; $y < ($src_y); $y++) {
952 for ($x = 0; $x < ($src_x); $x++) {
953 $color = imagecolorat($src_img, $x, $y);
954 imagesetpixel($rotate, $y, $dest_y - $x - 1, $color);
960 for ($y = 0; $y < ($src_y); $y++) {
961 for ($x = 0; $x < ($src_x); $x++) {
962 $color = imagecolorat($src_img, $x, $y);
963 imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color);
968 default: $rotate = $src_img;
975 $img = imagerotate($img, $degrees);
983 private function get_photo_tags($idx)
985 $result = $this->db->db_query("
988 INNER JOIN photo_tags pt
990 WHERE pt.photo_id='". $idx ."'
995 while($row = $this->db->db_fetch_object($result))
996 $tags[$row['id']] = $row['name'];
1000 } // get_photo_tags()
1002 public function showTextImage($txt, $color=000000, $space=4, $font=4, $w=300)
1004 if (strlen($color) != 6)
1007 $int = hexdec($color);
1008 $h = imagefontheight($font);
1009 $fw = imagefontwidth($font);
1010 $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
1011 $lines = count($txt);
1012 $im = imagecreate($w, (($h * $lines) + ($lines * $space)));
1013 $bg = imagecolorallocate($im, 255, 255, 255);
1014 $color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
1017 foreach ($txt as $text) {
1018 $x = (($w - ($fw * strlen($text))) / 2);
1019 imagestring($im, $font, $x, $y, $text, $color);
1020 $y += ($h + $space);
1023 Header("Content-type: image/png");
1026 } // showTextImage()
1028 private function checkRequirements()
1030 if(!function_exists("imagecreatefromjpeg")) {
1031 print "PHP GD library extension is missing<br />\n";
1035 if(!function_exists("sqlite3_open")) {
1036 print "PHP SQLite3 library extension is missing<br />\n";
1040 /* Check for HTML_AJAX PEAR package, lent from Horde project */
1041 ini_set('track_errors', 1);
1042 @include_once 'HTML/AJAX/Server.php';
1043 if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
1044 print "PEAR HTML_AJAX package is missing<br />\n";
1047 @include_once 'Calendar/Calendar.php';
1048 if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
1049 print "PEAR Calendar package is missing<br />\n";
1052 ini_restore('track_errors');
1059 } // checkRequirements()
1061 private function _debug($text)
1063 if($this->fromcmd) {
1069 public function checkifImageSupported($mime)
1071 if(in_array($mime, Array("image/jpeg")))
1076 } // checkifImageSupported()
1078 public function _warning($text)
1080 print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";
1085 private function get_calendar()
1087 // require_once CALENDAR_ROOT.'Year.php';
1088 // require_once CALENDAR_ROOT.'Month.php';
1089 // require_once CALENDAR_ROOT.'Day.php';
1091 // $Year = new Calendar_Year();
1092 // $Month = new Calendar_Month();
1093 // $Day = new Calendar_Day();
1095 $output = "<select name=\"year\">\n";
1096 for($year = 1990; $year <= date("Y"); $year++) {
1097 $output.= "<option value=\"". $year ."\">". $year ."</option>\n";
1099 $output.= "</select>\n";
1101 $output.= "<select name=\"month\">\n";
1102 for($month = 1; $month <= 12; $month++) {
1103 $output.= "<option value=\"". $month ."\">". $month ."</option>\n";
1105 $output.= "</select>\n";
1107 $output.= "<select name=\"day\">\n";
1108 for($day = 1; $day <= 31; $day++) {
1109 $output.= "<option value=\"". $day ."\">". $day ."</option>\n";
1111 $output.= "</select>\n";
1117 public function getExport($mode)
1119 $pictures = $this->getPhotoSelection();
1120 $current_tags = $this->getCurrentTags();
1122 if(!isset($_SERVER['HTTPS'])) $protocol = "http";
1123 else $protocol = "https";
1125 $server_name = $_SERVER['SERVER_NAME'];
1127 foreach($pictures as $picture) {
1129 $orig_url = $protocol ."://". $server_name . $this->cfg->web_path ."index.php?mode=showp&id=". $picture;
1130 if($current_tags != "") {
1131 $orig_url.= "&tags=". $current_tags;
1134 $thumb_url = $protocol ."://". $server_name . $this->cfg->web_path ."phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width;
1139 // <a href="%pictureurl%"><img src="%thumbnailurl%" ></a>
1140 print htmlspecialchars("<a href=\"". $orig_url ."\"><img src=\"". $thumb_url ."\" /></a>") ."<br />\n";
1144 // [%pictureurl% %thumbnailurl%]
1145 print htmlspecialchars(" * [".$orig_url." ".$thumb_url."&fake=1.jpg]") ."<br />\n";
1153 private function getCurrentTags()
1156 if($_SESSION['selected_tags'] != "") {
1157 foreach($_SESSION['selected_tags'] as $tag)
1158 $current_tags.= $tag .",";
1159 $current_tags = substr($current_tags, 0, strlen($current_tags)-1);
1161 return $current_tags;
1163 } // getCurrentTags()
1165 public function getCurrentPhoto()
1167 if(isset($_SESSION['current_photo'])) {
1168 print $_SESSION['current_photo'];
1170 } // getCurrentPhoto()