3 /***************************************************************************
5 * Copyright (c) by Andreas Unterkircher, unki@netshadow.at
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 ***************************************************************************/
24 require_once "phpfspot_cfg.php";
25 require_once "phpfspot_db.php";
39 * this function will be called on class construct
40 * and will check requirements, loads configuration,
41 * open databases and start the user session
43 public function __construct()
45 /* Check necessary requirements */
46 if(!$this->checkRequirements()) {
50 $this->cfg = new PHPFSPOT_CFG;
52 $this->db = new PHPFSPOT_DB($this, $this->cfg->fspot_db);
54 if(!is_writeable(dirname($this->cfg->phpfspot_db))) {
55 print dirname($this->cfg->phpfspot_db) .": directory is not writeable!";
59 $this->cfg_db = new PHPFSPOT_DB($this, $this->cfg->phpfspot_db);
60 if(!is_writeable($this->cfg->phpfspot_db)) {
61 print $this->cfg->phpfspot_db ." is not writeable for user ". $this->getuid() ."\n";
64 $this->check_config_table();
66 /* include Smarty template engine */
67 require $this->cfg->smarty_path .'/libs/Smarty.class.php';
68 /* overload Smarty class if our own template handler */
69 require_once "phpfspot_tmpl.php";
70 $this->tmpl = new PHPFSPOT_TMPL($this);
76 if(!isset($_SESSION['tag_condition']))
77 $_SESSION['tag_condition'] = 'or';
79 if(!isset($_SESSION['sort_order']))
80 $_SESSION['sort_order'] = 'date_asc';
82 if(!isset($_SESSION['searchfor']))
83 $_SESSION['searchfor'] = '';
85 // if begin_with is still set but rows_per_page is now 0, unset it
86 if(isset($_SESSION['begin_with']) && $this->cfg->rows_per_page == 0)
87 unset($_SESSION['begin_with']);
91 public function __destruct()
97 * show - generate html output
99 * this function can be called after the constructor has
100 * prepared everyhing. it will load the index.tpl smarty
101 * template. if necessary it will registere pre-selects
102 * (photo index, photo, tag search, date search) into
105 public function show()
107 $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
108 $this->tmpl->assign('page_title', $this->cfg->page_title);
109 $this->tmpl->assign('current_condition', $_SESSION['tag_condition']);
110 $this->tmpl->assign('template_path', 'themes/'. $this->cfg->theme_name);
112 $_SESSION['start_action'] = $_GET['mode'];
114 switch($_GET['mode']) {
116 if(isset($_GET['tags'])) {
117 $_SESSION['selected_tags'] = $this->extractTags($_GET['tags']);
119 if(isset($_GET['from_date']) && $this->isValidDate($_GET['from_date'])) {
120 $_SESSION['from_date'] = strtotime($_GET['from_date'] ." 00:00:00");
122 if(isset($_GET['to_date']) && $this->isValidDate($_GET['to_date'])) {
123 $_SESSION['to_date'] = strtotime($_GET['to_date'] ." 23:59:59");
127 if(isset($_GET['tags'])) {
128 $_SESSION['selected_tags'] = $this->extractTags($_GET['tags']);
129 $_SESSION['start_action'] = 'showp';
131 if(isset($_GET['id']) && is_numeric($_GET['id'])) {
132 $_SESSION['current_photo'] = $_GET['id'];
133 $_SESSION['start_action'] = 'showp';
135 if(isset($_GET['from_date']) && $this->isValidDate($_GET['from_date'])) {
136 $_SESSION['from_date'] = strtotime($_GET['from_date']);
138 if(isset($_GET['to_date']) && $this->isValidDate($_GET['to_date'])) {
139 $_SESSION['to_date'] = strtotime($_GET['to_date']);
143 $this->tmpl->show("export.tpl");
147 $this->tmpl->show("slideshow.tpl");
151 if(isset($_GET['tags'])) {
152 $_SESSION['selected_tags'] = $this->extractTags($_GET['tags']);
154 if(isset($_GET['from_date']) && $this->isValidDate($_GET['from_date'])) {
155 $_SESSION['from_date'] = strtotime($_GET['from_date'] ." 00:00:00");
157 if(isset($_GET['to_date']) && $this->isValidDate($_GET['to_date'])) {
158 $_SESSION['to_date'] = strtotime($_GET['to_date'] ." 23:59:59");
165 if(isset($_SESSION['from_date']) && isset($_SESSION['to_date']))
166 $this->tmpl->assign('date_search_enabled', true);
168 $this->tmpl->assign('from_date', $this->get_calendar('from'));
169 $this->tmpl->assign('to_date', $this->get_calendar('to'));
170 $this->tmpl->assign('sort_field', $this->get_sort_field());
171 $this->tmpl->assign('content_page', 'welcome.tpl');
172 $this->tmpl->show("index.tpl");
177 * get_tags - grab all tags of f-spot's database
179 * this function will get all available tags from
180 * the f-spot database and store them within two
181 * arrays within this clase for later usage. in
182 * fact, if the user requests (hide_tags) it will
183 * opt-out some of them.
185 * this function is getting called once by show()
187 private function get_tags()
189 $this->avail_tags = Array();
192 $result = $this->db->db_query("
195 ORDER BY sort_priority ASC
198 while($row = $this->db->db_fetch_object($result)) {
200 $tag_id = $row['id'];
201 $tag_name = $row['name'];
203 /* check if config requests to ignore this tag */
204 if(in_array($row['name'], $this->cfg->hide_tags))
207 $this->tags[$tag_id] = $tag_name;
208 $this->avail_tags[$count] = $tag_id;
217 * extract all photo details
219 * retrieve all available details from f-spot's
220 * database and return them as object
222 public function get_photo_details($idx)
224 $result = $this->db->db_query("
227 WHERE id='". $idx ."'
230 return $this->db->db_fetch_object($result);
232 } // get_photo_details
235 * returns aligned photo names
237 * this function returns aligned (length) names for
238 * an specific photo. If the length of the name exceeds
239 * $limit the name will be shrinked (...)
241 public function getPhotoName($idx, $limit = 0)
243 if($details = $this->get_photo_details($idx)) {
244 $name = $this->shrink_text($details['name'], $limit);
251 * shrink text according provided limit
253 * If the length of the name exceeds $limit the
254 * text will be shortend and some content in between
255 * will be replaced with "..."
257 private function shrink_text($text, $limit)
259 if($limit != 0 && strlen($text) > $limit) {
260 $text = substr($text, 0, $limit-5) ."...". substr($text, -($limit-5));
268 * translate f-spoth photo path
270 * as the full-qualified path recorded in the f-spot database
271 * is usally not the same as on the webserver, this function
272 * will replace the path with that one specified in the cfg
274 public function translate_path($path, $width = 0)
276 return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
281 * control HTML ouput for a single photo
283 * this function provides all the necessary information
284 * for the single photo template.
286 public function showPhoto($photo)
288 /* get all photos from the current photo selection */
289 $all_photos = $this->getPhotoSelection();
290 $count = count($all_photos);
292 for($i = 0; $i < $count; $i++) {
294 // $get_next will be set, when the photo which has to
295 // be displayed has been found - this means that the
296 // next available is in fact the NEXT image (for the
298 if(isset($get_next)) {
299 $next_img = $all_photos[$i];
303 /* the next photo is our NEXT photo */
304 if($all_photos[$i] == $photo) {
308 $previous_img = $all_photos[$i];
311 if($photo == $all_photos[$i]) {
316 $details = $this->get_photo_details($photo);
323 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
324 $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo);
326 if(!file_exists($orig_path)) {
327 $this->_error("Photo ". $orig_path ." does not exist!<br />\n");
330 if(!is_readable($orig_path)) {
331 $this->_error("Photo ". $orig_path ." is not readable for user ". $this->getuid() ."<br />\n");
334 /* If the thumbnail doesn't exist yet, try to create it */
335 if(!file_exists($thumb_path)) {
336 $this->gen_thumb($photo, true);
337 $thumb_path = $this->get_thumb_path($this->cfg->photo_width, $photo);
340 /* get f-spot database meta information */
341 $meta = $this->get_meta_informations($orig_path);
343 /* If EXIF data are available, use them */
344 if(isset($meta['ExifImageWidth'])) {
345 $meta_res = $meta['ExifImageWidth'] ."x". $meta['ExifImageLength'];
347 $info = getimagesize($orig_path);
348 $meta_res = $info[0] ."x". $info[1];
351 $meta_date = isset($meta['FileDateTime']) ? strftime("%a %x %X", $meta['FileDateTime']) : "n/a";
352 $meta_make = isset($meta['Make']) ? $meta['Make'] ." / ". $meta['Model'] : "n/a";
353 $meta_size = isset($meta['FileSize']) ? round($meta['FileSize']/1024, 1) ."kbyte" : "n/a";
355 $extern_link = "index.php?mode=showp&id=". $photo;
356 $current_tags = $this->getCurrentTags();
357 if($current_tags != "") {
358 $extern_link.= "&tags=". $current_tags;
360 if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
361 $extern_link.= "&from_date=". $this->ts2str($_SESSION['from_date']) ."&to_date=". $this->ts2str($_SESSION['to_date']);
364 $this->tmpl->assign('extern_link', $extern_link);
366 if(file_exists($thumb_path)) {
368 $info = getimagesize($thumb_path);
370 $this->tmpl->assign('description', $details['description']);
371 $this->tmpl->assign('image_name', $details['name']);
373 $this->tmpl->assign('width', $info[0]);
374 $this->tmpl->assign('height', $info[1]);
375 $this->tmpl->assign('ExifMadeOn', $meta_date);
376 $this->tmpl->assign('ExifMadeWith', $meta_make);
377 $this->tmpl->assign('ExifOrigResolution', $meta_res);
378 $this->tmpl->assign('ExifFileSize', $meta_size);
380 $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width);
381 $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo);
383 $this->tmpl->assign('tags', $this->get_photo_tags($photo));
384 $this->tmpl->assign('current', $current);
387 $this->_error("Can't open file ". $thumb_path ."\n");
392 $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
393 $this->tmpl->assign('prev_img', $previous_img);
397 $this->tmpl->assign('next_url', "javascript:showImage(". $next_img .");");
398 $this->tmpl->assign('next_img', $next_img);
400 $this->tmpl->assign('mini_width', $this->cfg->mini_width);
401 $this->tmpl->assign('photo_number', $i);
402 $this->tmpl->assign('photo_count', count($all_photos));
404 $this->tmpl->show("single_photo.tpl");
409 * all available tags and tag cloud
411 * this function outputs all available tags (time ordered)
412 * and in addition output them as tag cloud (tags which have
413 * many photos will appears more then others)
415 public function getAvailableTags()
419 $result = $this->db->db_query("
420 SELECT tag_id as id, count(tag_id) as quantity
430 while($row = $this->db->db_fetch_object($result)) {
431 $tags[$row['id']] = $row['quantity'];
434 // change these font sizes if you will
435 $max_size = 125; // max font size in %
436 $min_size = 75; // min font size in %
438 // get the largest and smallest array values
439 $max_qty = max(array_values($tags));
440 $min_qty = min(array_values($tags));
442 // find the range of values
443 $spread = $max_qty - $min_qty;
444 if (0 == $spread) { // we don't want to divide by zero
448 // determine the font-size increment
449 // this is the increase per tag quantity (times used)
450 $step = ($max_size - $min_size)/($spread);
452 // loop through our tag array
453 foreach ($tags as $key => $value) {
455 if(isset($_SESSION['selected_tags']) && in_array($key, $_SESSION['selected_tags']))
458 // calculate CSS font-size
459 // find the $value in excess of $min_qty
460 // multiply by the font-size increment ($size)
461 // and add the $min_size set above
462 $size = $min_size + (($value - $min_qty) * $step);
463 // uncomment if you want sizes in whole %:
466 $output.= "<a href=\"javascript:Tags('add', ". $key .");\" class=\"tag\" style=\"font-size: ". $size ."%;\">". $this->tags[$key] ."</a>, ";
470 $output = substr($output, 0, strlen($output)-2);
473 } // getAvailableTags()
476 * output all selected tags
478 * this function output all tags which have been selected
479 * by the user. the selected tags are stored in the
480 * session-variable $_SESSION['selected_tags']
482 public function getSelectedTags()
485 foreach($this->avail_tags as $tag)
487 // return all selected tags
488 if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) {
489 $output.= "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a>, ";
493 $output = substr($output, 0, strlen($output)-2);
496 } // getSelectedTags()
499 * add tag to users session variable
501 * this function will add the specified to users current
502 * tag selection. if a date search has been made before
503 * it will be now cleared
505 public function addTag($tag)
507 if(!isset($_SESSION['selected_tags']))
508 $_SESSION['selected_tags'] = Array();
510 if(!in_array($tag, $_SESSION['selected_tags']))
511 array_push($_SESSION['selected_tags'], $tag);
516 * remove tag to users session variable
518 * this function removes the specified tag from
519 * users current tag selection
521 public function delTag($tag)
523 if(isset($_SESSION['selected_tags'])) {
524 $key = array_search($tag, $_SESSION['selected_tags']);
525 unset($_SESSION['selected_tags'][$key]);
526 sort($_SESSION['selected_tags']);
532 * reset tag selection
534 * if there is any tag selection, it will be
537 public function resetTags()
539 if(isset($_SESSION['selected_tags']))
540 unset($_SESSION['selected_tags']);
547 * if a specific photo was requested (external link)
548 * unset the session variable now
550 public function resetPhotoView()
552 if(isset($_SESSION['current_photo']))
553 unset($_SESSION['current_photo']);
555 } // resetPhotoView();
560 * if any tag search has taken place, reset
563 public function resetTagSearch()
565 if(isset($_SESSION['searchfor']))
566 unset($_SESSION['searchfor']);
568 } // resetTagSearch()
573 * if any date search has taken place, reset
576 public function resetDateSearch()
578 if(isset($_SESSION['from_date']))
579 unset($_SESSION['from_date']);
580 if(isset($_SESSION['to_date']))
581 unset($_SESSION['to_date']);
583 } // resetDateSearch();
586 * return all photo according selection
588 * this function returns all photos based on
589 * the tag-selection, tag- or date-search.
590 * the tag-search also has to take care of AND
591 * and OR conjunctions
593 public function getPhotoSelection()
595 $matched_photos = Array();
597 if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
598 $from_date = $_SESSION['from_date'];
599 $to_date = $_SESSION['to_date'];
600 $additional_where_cond = "
601 p.time>='". $from_date ."'
603 p.time<='". $to_date ."'
607 if(isset($_SESSION['sort_order'])) {
608 $order_str = $this->get_sort_order();
611 /* return a search result */
612 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
614 SELECT DISTINCT photo_id
620 WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'";
622 if(isset($additional_where_cond))
623 $query_str.= "AND ". $additional_where_cond ." ";
624 if(isset($order_str))
625 $query_str.= $order_str;
627 $result = $this->db->db_query($query_str);
628 while($row = $this->db->db_fetch_object($result)) {
629 array_push($matched_photos, $row['photo_id']);
631 return $matched_photos;
634 /* return according the selected tags */
635 if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
637 foreach($_SESSION['selected_tags'] as $tag)
638 $selected.= $tag .",";
639 $selected = substr($selected, 0, strlen($selected)-1);
641 if($_SESSION['tag_condition'] == 'or') {
643 SELECT DISTINCT photo_id
647 WHERE pt.tag_id IN (". $selected .")
649 if(isset($additional_where_cond))
650 $query_str.= "AND ". $additional_where_cond ." ";
651 if(isset($order_str))
652 $query_str.= $order_str;
654 elseif($_SESSION['tag_condition'] == 'and') {
656 if(count($_SESSION['selected_tags']) >= 32) {
657 print "A SQLite limit of 32 tables within a JOIN SELECT avoids to<br />\n";
658 print "evaluate your tag selection. Please remove some tags from your selection.\n";
662 /* Join together a table looking like
664 pt1.photo_id pt1.tag_id pt2.photo_id pt2.tag_id ...
666 so the query can quickly return all images matching the
667 selected tags in an AND condition
672 SELECT DISTINCT pt1.photo_id
676 for($i = 0; $i < count($_SESSION['selected_tags']); $i++) {
678 INNER JOIN photo_tags pt". ($i+2) ."
679 ON pt1.photo_id=pt". ($i+2) .".photo_id
686 $query_str.= "WHERE pt1.tag_id=". $_SESSION['selected_tags'][0];
687 for($i = 1; $i < count($_SESSION['selected_tags']); $i++) {
689 AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ."
692 if(isset($additional_where_cond))
693 $query_str.= "AND ". $additional_where_cond;
694 if(isset($order_str))
695 $query_str.= $order_str;
698 $result = $this->db->db_query($query_str);
699 while($row = $this->db->db_fetch_object($result)) {
700 array_push($matched_photos, $row['photo_id']);
702 return $matched_photos;
705 /* return all available photos */
707 SELECT DISTINCT photo_id
712 if(isset($additional_where_cond))
713 $query_str.= "WHERE ". $additional_where_cond ." ";
714 if(isset($order_str))
715 $query_str.= $order_str;
717 $result = $this->db->db_query($query_str);
718 while($row = $this->db->db_fetch_object($result)) {
719 array_push($matched_photos, $row['photo_id']);
721 return $matched_photos;
723 } // getPhotoSelection()
726 * control HTML ouput for photo index
728 * this function provides all the necessary information
729 * for the photo index template.
731 public function showPhotoIndex()
733 $photos = $this->getPhotoSelection();
735 $count = count($photos);
737 if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
738 $anchor = $_SESSION['begin_with'];
740 if(!isset($this->cfg->rows_per_page) || $this->cfg->rows_per_page == 0) {
746 elseif($this->cfg->rows_per_page > 0) {
748 if(!$_SESSION['begin_with'] || $_SESSION['begin_with'] == 0)
752 $begin_with = $_SESSION['begin_with'];
754 // verify $begin_with - perhaps the thumbs-per-rows or
755 // rows-per-page variables have changed or the jump back
756 // from a photo wasn't exact - so calculate the real new
758 $multiplicator = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
759 for($i = 0; $i <= $count; $i+=$multiplicator) {
760 if($begin_with >= $i && $begin_with < $i+$multiplicator) {
767 $end_with = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
773 $images[$rows] = Array();
774 $img_height[$rows] = Array();
775 $img_width[$rows] = Array();
776 $img_id[$rows] = Array();
777 $img_name[$rows] = Array();
778 $img_title = Array();
780 for($i = $begin_with; $i < $end_with; $i++) {
782 $images[$rows][$cols] = $photos[$i];
783 $img_id[$rows][$cols] = $i;
784 $img_name[$rows][$cols] = htmlspecialchars($this->getPhotoName($photos[$i], 15));
785 $img_title[$rows][$cols] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0));
787 $thumb_path = $this->get_thumb_path($this->cfg->thumb_width, $photos[$i]);
789 if(file_exists($thumb_path)) {
790 $info = getimagesize($thumb_path);
791 $img_width[$rows][$cols] = $info[0];
792 $img_height[$rows][$cols] = $info[1];
795 if($cols == $this->cfg->thumbs_per_row-1) {
798 $images[$rows] = Array();
799 $img_width[$rows] = Array();
800 $img_height[$rows] = Array();
807 // +1 for for smarty's selection iteration
810 if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '')
811 $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
813 if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
814 $this->tmpl->assign('from_date', $this->ts2str($_SESSION['from_date']));
815 $this->tmpl->assign('to_date', $this->ts2str($_SESSION['to_date']));
818 if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
819 $this->tmpl->assign('tag_result', 1);
822 /* do we have to display the page selector ? */
823 if($this->cfg->rows_per_page != 0) {
825 /* calculate the page switchers */
826 $previous_start = $begin_with - ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
827 $next_start = $begin_with + ($this->cfg->rows_per_page * $this->cfg->thumbs_per_row);
830 $this->tmpl->assign("previous_url", "javascript:showPhotoIndex(". $previous_start .");");
831 if($end_with < $count)
832 $this->tmpl->assign("next_url", "javascript:showPhotoIndex(". $next_start .");");
834 $photo_per_page = $this->cfg->rows_per_page * $this->cfg->thumbs_per_row;
835 $last_page = ceil($count / $photo_per_page);
837 /* get the current selected page */
838 if($begin_with == 0) {
842 for($i = $begin_with; $i >= 0; $i-=$photo_per_page) {
849 for($i = 1; $i <= $last_page; $i++) {
851 if($current_page == $i)
852 $style = "style=\"font-size: 125%; text-decoration: underline;\"";
853 elseif($current_page-1 == $i || $current_page+1 == $i)
854 $style = "style=\"font-size: 105%;\"";
855 elseif(($current_page-5 >= $i) && ($i != 1) ||
856 ($current_page+5 <= $i) && ($i != $last_page))
857 $style = "style=\"font-size: 75%;\"";
861 $select = "<a href=\"javascript:showPhotoIndex(". (($i*$photo_per_page)-$photo_per_page) .");\"";
864 $select.= ">". $i ."</a> ";
866 // until 9 pages we show the selector from 1-9
867 if($last_page <= 9) {
868 $page_select.= $select;
871 if($i == 1 /* first page */ ||
872 $i == $last_page /* last page */ ||
873 $i == $current_page /* current page */ ||
874 $i == ceil($last_page * 0.25) /* first quater */ ||
875 $i == ceil($last_page * 0.5) /* half */ ||
876 $i == ceil($last_page * 0.75) /* third quater */ ||
877 (in_array($i, array(1,2,3,4,5,6)) && $current_page <= 4) /* the first 6 */ ||
878 (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 */ ||
879 $i == $current_page-3 || $i == $current_page-2 || $i == $current_page-1 /* three before */ ||
880 $i == $current_page+3 || $i == $current_page+2 || $i == $current_page+1 /* three after */) {
882 $page_select.= $select;
890 $page_select.= "......... ";
895 /* only show the page selector if we have more then one page */
897 $this->tmpl->assign('page_selector', $page_select);
901 $current_tags = $this->getCurrentTags();
902 $extern_link = "index.php?mode=showpi";
903 $rss_link = "index.php?mode=rss";
904 if($current_tags != "") {
905 $extern_link.= "&tags=". $current_tags;
906 $rss_link.= "&tags=". $current_tags;
908 if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
909 $extern_link.= "&from_date=". $this->ts2str($_SESSION['from_date']) ."&to_date=". $this->ts2str($_SESSION['to_date']);
910 $rss_link.= "&from_date=". $this->ts2str($_SESSION['from_date']) ."&to_date=". $this->ts2str($_SESSION['to_date']);
913 $export_link = "index.php?mode=export";
914 $slideshow_link = "index.php?mode=slideshow";
916 $this->tmpl->assign('extern_link', $extern_link);
917 $this->tmpl->assign('slideshow_link', $slideshow_link);
918 $this->tmpl->assign('export_link', $export_link);
919 $this->tmpl->assign('rss_link', $rss_link);
920 $this->tmpl->assign('count', $count);
921 $this->tmpl->assign('width', $this->cfg->thumb_width);
922 $this->tmpl->assign('images', $images);
923 $this->tmpl->assign('img_width', $img_width);
924 $this->tmpl->assign('img_height', $img_height);
925 $this->tmpl->assign('img_id', $img_id);
926 $this->tmpl->assign('img_name', $img_name);
927 $this->tmpl->assign('img_title', $img_title);
928 $this->tmpl->assign('rows', $rows);
929 $this->tmpl->assign('columns', $this->cfg->thumbs_per_row);
931 $this->tmpl->show("photo_index.tpl");
934 print "<script language=\"JavaScript\">self.location.hash = '#image". $anchor ."';</script>\n";
936 } // showPhotoIndex()
939 * show credit template
941 public function showCredits()
943 $this->tmpl->assign('version', $this->cfg->version);
944 $this->tmpl->assign('product', $this->cfg->product);
945 $this->tmpl->show("credits.tpl");
950 * create_thumbnails for the requested width
952 * this function creates image thumbnails of $orig_image
953 * stored as $thumb_image. It will check if the image is
954 * in a supported format, if necessary rotate the image
955 * (based on EXIF orientation meta headers) and re-sizing.
957 public function create_thumbnail($orig_image, $thumb_image, $width)
959 if(!file_exists($orig_image)) {
963 $details = getimagesize($orig_image);
965 /* check if original photo is a support image type */
966 if(!$this->checkifImageSupported($details['mime']))
969 $meta = $this->get_meta_informations($orig_image);
974 switch($meta['Orientation']) {
976 case 1: /* top, left */
977 $rotate = 0; $flip = false; break;
978 case 2: /* top, right */
979 $rotate = 0; $flip = true; break;
980 case 3: /* bottom, left */
981 $rotate = 180; $flip = false; break;
982 case 4: /* bottom, right */
983 $rotate = 180; $flip = true; break;
984 case 5: /* left side, top */
985 $rotate = 90; $flip = true; break;
986 case 6: /* right side, top */
987 $rotate = 90; $flip = false; break;
988 case 7: /* left side, bottom */
989 $rotate = 270; $flip = true; break;
990 case 8: /* right side, bottom */
991 $rotate = 270; $flip = false; break;
994 $src_img = @imagecreatefromjpeg($orig_image);
997 print "Can't load image from ". $orig_image ."\n";
1001 /* grabs the height and width */
1002 $cur_width = imagesx($src_img);
1003 $cur_height = imagesy($src_img);
1005 // If requested width is more then the actual image width,
1006 // do not generate a thumbnail, instead safe the original
1007 // as thumbnail but with lower quality
1009 if($width >= $cur_width) {
1010 $result = imagejpeg($src_img, $thumb_image, 75);
1011 imagedestroy($src_img);
1015 // If the image will be rotate because EXIF orientation said so
1016 // 'virtually rotate' the image for further calculations
1017 if($rotate == 90 || $rotate == 270) {
1019 $cur_width = $cur_height;
1023 /* calculates aspect ratio */
1024 $aspect_ratio = $cur_height / $cur_width;
1027 if($aspect_ratio < 1) {
1029 $new_h = abs($new_w * $aspect_ratio);
1031 /* 'virtually' rotate the image and calculate it's ratio */
1032 $tmp_w = $cur_height;
1033 $tmp_h = $cur_width;
1034 /* now get the ratio from the 'rotated' image */
1035 $tmp_ratio = $tmp_h/$tmp_w;
1036 /* now calculate the new dimensions */
1038 $tmp_h = abs($tmp_w * $tmp_ratio);
1040 // now that we know, how high they photo should be, if it
1041 // gets rotated, use this high to scale the image
1043 $new_w = abs($new_h / $aspect_ratio);
1045 // If the image will be rotate because EXIF orientation said so
1046 // now 'virtually rotate' back the image for the image manipulation
1047 if($rotate == 90 || $rotate == 270) {
1054 /* creates new image of that size */
1055 $dst_img = imagecreatetruecolor($new_w, $new_h);
1057 imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
1059 /* copies resized portion of original image into new image */
1060 imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
1062 /* needs the image to be flipped horizontal? */
1066 for($x = 0; $x < $new_w; $x++) {
1067 imagecopy($dst_img, $image, $x, 0, $w - $x - 1, 0, 1, $h);
1072 $this->_debug("(ROTATE)");
1073 $dst_img = $this->rotateImage($dst_img, $rotate);
1076 /* write down new generated file */
1077 $result = imagejpeg($dst_img, $thumb_image, 75);
1079 /* free your mind */
1080 imagedestroy($dst_img);
1081 imagedestroy($src_img);
1083 if($result === false) {
1084 print "Can't write thumbnail ". $thumb_image ."\n";
1090 } // create_thumbnail()
1093 * return all exif meta data from the file
1095 public function get_meta_informations($file)
1097 return exif_read_data($file);
1099 } // get_meta_informations()
1102 * create phpfspot own sqlite database
1104 * this function creates phpfspots own sqlite database
1105 * if it does not exist yet. this own is used to store
1106 * some necessary informations (md5 sum's, ...).
1108 public function check_config_table()
1110 // if the config table doesn't exist yet, create it
1111 if(!$this->cfg_db->db_check_table_exists("images")) {
1112 $this->cfg_db->db_exec("
1113 CREATE TABLE images (
1114 img_idx int primary key,
1120 } // check_config_table
1123 * Generates a thumbnail from photo idx
1125 * This function will generate JPEG thumbnails from provided F-Spot photo
1128 * 1. Check if all thumbnail generations (width) are already in place and
1130 * 2. Check if the md5sum of the original file has changed
1131 * 3. Generate the thumbnails if needed
1133 public function gen_thumb($idx = 0, $force = 0)
1137 $resolutions = Array(
1138 $this->cfg->thumb_width,
1139 $this->cfg->photo_width,
1140 $this->cfg->mini_width,
1143 /* get details from F-Spot's database */
1144 $details = $this->get_photo_details($idx);
1146 /* calculate file MD5 sum */
1147 $full_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
1149 if(!file_exists($full_path)) {
1150 $this->_error("File ". $full_path ." does not exist\n");
1154 if(!is_readable($full_path)) {
1155 $this->_error("File ". $full_path ." is not readable for ". $this->getuid() ."\n");
1159 $file_md5 = md5_file($full_path);
1161 $this->_debug("Image [". $idx ."] ". $this->shrink_text($details['name'], 20) ." Thumbnails:");
1163 foreach($resolutions as $resolution) {
1165 $thumb_sub_path = substr($file_md5, 0, 2);
1166 $thumb_path = $this->cfg->base_path ."/thumbs/". $thumb_sub_path ."/". $resolution ."_". $file_md5;
1168 if(!file_exists(dirname($thumb_path))) {
1169 mkdir(dirname($thumb_path), 0755);
1172 /* if the thumbnail file doesn't exist, create it */
1173 if(!file_exists($thumb_path)) {
1175 $this->_debug(" ". $resolution ."px");
1176 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
1179 /* if the file hasn't changed there is no need to regen the thumb */
1180 elseif($file_md5 != $this->getMD5($idx) || $force) {
1182 $this->_debug(" ". $resolution ."px");
1183 if(!$this->create_thumbnail($full_path, $thumb_path, $resolution))
1189 /* set the new/changed MD5 sum for the current photo */
1191 $this->setMD5($idx, $file_md5);
1194 $this->_debug("\n");
1199 * returns stored md5 sum for a specific photo
1201 * this function queries the phpfspot database for a
1202 * stored MD5 checksum of the specified photo
1204 public function getMD5($idx)
1206 $result = $this->cfg_db->db_query("
1209 WHERE img_idx='". $idx ."'
1215 $img = $this->cfg_db->db_fetch_object($result);
1216 return $img['img_md5'];
1221 * set MD5 sum for the specific photo
1223 private function setMD5($idx, $md5)
1225 $result = $this->cfg_db->db_exec("
1226 REPLACE INTO images (img_idx, img_md5)
1227 VALUES ('". $idx ."', '". $md5 ."')
1233 * store current tag condition
1235 * this function stores the current tag condition
1236 * (AND or OR) in the users session variables
1238 public function setTagCondition($mode)
1240 $_SESSION['tag_condition'] = $mode;
1242 } // setTagCondition()
1245 * invoke tag & date search
1247 * this function will return all matching tags and store
1248 * them in the session variable selected_tags. furthermore
1249 * it also handles the date search.
1250 * getPhotoSelection() will then only return the matching
1253 public function startSearch($searchfor, $sort_order, $from = 0, $to = 0)
1255 $_SESSION['searchfor'] = $searchfor;
1256 $_SESSION['sort_order'] = $sort_order;
1258 $_SESSION['from_date'] = strtotime($from);
1260 unset($_SESSION['from_date']);
1262 $_SESSION['to_date'] = strtotime($to);
1264 unset($_SESSION['to_date']);
1266 if($searchfor != "") {
1267 /* new search, reset the current selected tags */
1268 $_SESSION['selected_tags'] = Array();
1269 foreach($this->avail_tags as $tag) {
1270 if(preg_match('/'. $searchfor .'/i', $this->tags[$tag]))
1271 array_push($_SESSION['selected_tags'], $tag);
1280 * this function rotates the image according the
1283 private function rotateImage($img, $degrees)
1285 if(function_exists("imagerotate")) {
1286 $img = imagerotate($img, $degrees, 0);
1288 function imagerotate($src_img, $angle)
1290 $src_x = imagesx($src_img);
1291 $src_y = imagesy($src_img);
1292 if ($angle == 180) {
1296 elseif ($src_x <= $src_y) {
1300 elseif ($src_x >= $src_y) {
1305 $rotate=imagecreatetruecolor($dest_x,$dest_y);
1306 imagealphablending($rotate, false);
1311 for ($y = 0; $y < ($src_y); $y++) {
1312 for ($x = 0; $x < ($src_x); $x++) {
1313 $color = imagecolorat($src_img, $x, $y);
1314 imagesetpixel($rotate, $dest_x - $y - 1, $x, $color);
1320 for ($y = 0; $y < ($src_y); $y++) {
1321 for ($x = 0; $x < ($src_x); $x++) {
1322 $color = imagecolorat($src_img, $x, $y);
1323 imagesetpixel($rotate, $y, $dest_y - $x - 1, $color);
1329 for ($y = 0; $y < ($src_y); $y++) {
1330 for ($x = 0; $x < ($src_x); $x++) {
1331 $color = imagecolorat($src_img, $x, $y);
1332 imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color);
1346 $img = imagerotate($img, $degrees);
1355 * return all assigned tags for the specified photo
1357 private function get_photo_tags($idx)
1359 $result = $this->db->db_query("
1362 INNER JOIN photo_tags pt
1364 WHERE pt.photo_id='". $idx ."'
1369 while($row = $this->db->db_fetch_object($result))
1370 $tags[$row['id']] = $row['name'];
1374 } // get_photo_tags()
1377 * create on-the-fly images with text within
1379 public function showTextImage($txt, $color=000000, $space=4, $font=4, $w=300)
1381 if (strlen($color) != 6)
1384 $int = hexdec($color);
1385 $h = imagefontheight($font);
1386 $fw = imagefontwidth($font);
1387 $txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
1388 $lines = count($txt);
1389 $im = imagecreate($w, (($h * $lines) + ($lines * $space)));
1390 $bg = imagecolorallocate($im, 255, 255, 255);
1391 $color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
1394 foreach ($txt as $text) {
1395 $x = (($w - ($fw * strlen($text))) / 2);
1396 imagestring($im, $font, $x, $y, $text, $color);
1397 $y += ($h + $space);
1400 Header("Content-type: image/png");
1403 } // showTextImage()
1406 * check if all requirements are met
1408 private function checkRequirements()
1410 if(!function_exists("imagecreatefromjpeg")) {
1411 print "PHP GD library extension is missing<br />\n";
1415 if($this->cfg->db_access == "native" && !function_exists("sqlite3_open")) {
1416 print "PHP SQLite3 library extension is missing<br />\n";
1420 /* Check for HTML_AJAX PEAR package, lent from Horde project */
1421 ini_set('track_errors', 1);
1422 @include_once 'HTML/AJAX/Server.php';
1423 if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
1424 print "PEAR HTML_AJAX package is missing<br />\n";
1427 @include_once 'Calendar/Calendar.php';
1428 if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
1429 print "PEAR Calendar package is missing<br />\n";
1432 ini_restore('track_errors');
1439 } // checkRequirements()
1441 private function _debug($text)
1443 if($this->fromcmd) {
1450 * check if specified MIME type is supported
1452 public function checkifImageSupported($mime)
1454 if(in_array($mime, Array("image/jpeg")))
1459 } // checkifImageSupported()
1461 public function _error($text)
1463 switch($this->cfg->logging) {
1465 print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";
1472 error_log($text, 3, $his->cfg->log_file);
1479 * output calendard input fields
1481 private function get_calendar($mode)
1483 $year = $_SESSION[$mode .'_date'] ? date("Y", $_SESSION[$mode .'_date']) : date("Y");
1484 $month = $_SESSION[$mode .'_date'] ? date("m", $_SESSION[$mode .'_date']) : date("m");
1485 $day = $_SESSION[$mode .'_date'] ? date("d", $_SESSION[$mode .'_date']) : date("d");
1487 $output = "<input type=\"text\" size=\"3\" id=\"". $mode ."year\" value=\"". $year ."\"";
1488 if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\"";
1490 $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."month\" value=\"". $month ."\"";
1491 if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\"";
1493 $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."day\" value=\"". $day ."\"";
1494 if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\"";
1501 * output calendar matrix
1503 public function get_calendar_matrix($year = 0, $month = 0, $day = 0)
1505 if (!isset($year)) $year = date('Y');
1506 if (!isset($month)) $month = date('m');
1507 if (!isset($day)) $day = date('d');
1512 require_once CALENDAR_ROOT.'Month/Weekdays.php';
1513 require_once CALENDAR_ROOT.'Day.php';
1516 $month = new Calendar_Month_Weekdays($year,$month);
1519 $prevStamp = $month->prevMonth(true);
1520 $prev = "javascript:setMonth(". date('Y',$prevStamp) .", ". date('n',$prevStamp) .", ". date('j',$prevStamp) .");";
1521 $nextStamp = $month->nextMonth(true);
1522 $next = "javascript:setMonth(". date('Y',$nextStamp) .", ". date('n',$nextStamp) .", ". date('j',$nextStamp) .");";
1524 $selectedDays = array (
1525 new Calendar_Day($year,$month,$day),
1526 new Calendar_Day($year,12,25),
1529 // Build the days in the month
1530 $month->build($selectedDays);
1532 $this->tmpl->assign('current_month', date('F Y',$month->getTimeStamp()));
1533 $this->tmpl->assign('prev_month', $prev);
1534 $this->tmpl->assign('next_month', $next);
1536 while ( $day = $month->fetch() ) {
1538 if(!isset($matrix[$rows]))
1539 $matrix[$rows] = Array();
1543 $dayStamp = $day->thisDay(true);
1544 $link = "javascript:setCalendarDate(". date('Y',$dayStamp) .", ". date('n',$dayStamp).", ". date('j',$dayStamp) .");";
1546 // isFirst() to find start of week
1547 if ( $day->isFirst() )
1550 if ( $day->isSelected() ) {
1551 $string.= "<td class=\"selected\">".$day->thisDay()."</td>\n";
1552 } else if ( $day->isEmpty() ) {
1553 $string.= "<td> </td>\n";
1555 $string.= "<td><a class=\"calendar\" href=\"".$link."\">".$day->thisDay()."</a></td>\n";
1558 // isLast() to find end of week
1559 if ( $day->isLast() )
1560 $string.= "</tr>\n";
1562 $matrix[$rows][$cols] = $string;
1572 $this->tmpl->assign('matrix', $matrix);
1573 $this->tmpl->assign('rows', $rows);
1574 $this->tmpl->show("calendar.tpl");
1576 } // get_calendar_matrix()
1579 * output export page
1581 public function getExport($mode)
1583 $pictures = $this->getPhotoSelection();
1584 $current_tags = $this->getCurrentTags();
1586 foreach($pictures as $picture) {
1588 $orig_url = $this->get_phpfspot_url() ."index.php?mode=showp&id=". $picture;
1589 if($current_tags != "") {
1590 $orig_url.= "&tags=". $current_tags;
1592 if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
1593 $orig_url.= "&from_date=". $_SESSION['from_date'] ."&to_date=". $_SESSION['to_date'];
1596 $thumb_url = $this->get_phpfspot_url() ."phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width;
1601 // <a href="%pictureurl%"><img src="%thumbnailurl%" ></a>
1602 print htmlspecialchars("<a href=\"". $orig_url ."\"><img src=\"". $thumb_url ."\" /></a>") ."<br />\n";
1606 // "[%pictureurl% %thumbnailurl%]"
1607 print htmlspecialchars("[".$orig_url." ".$thumb_url."&fake=1.jpg]") ."<br />\n";
1610 case 'MoinMoinList':
1611 // " * [%pictureurl% %thumbnailurl%]"
1612 print " " . htmlspecialchars("* [".$orig_url." ".$thumb_url."&fake=1.jpg]") ."<br />\n";
1623 public function getRSSFeed()
1625 Header("Content-type: text/xml; charset=utf-8");
1626 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
1629 xmlns:media="http://search.yahoo.com/mrss/"
1630 xmlns:dc="http://purl.org/dc/elements/1.1/"
1633 <title>phpfspot</title>
1634 <description>phpfspot RSS feed</description>
1635 <link><?php print htmlspecialchars($this->get_phpfspot_url()); ?></link>
1636 <pubDate><?php print strftime("%a, %d %b %Y %T %z"); ?></pubDate>
1637 <generator>phpfspot</generator>
1640 $pictures = $this->getPhotoSelection();
1641 $current_tags = $this->getCurrentTags();
1643 foreach($pictures as $picture) {
1645 $orig_url = $this->get_phpfspot_url() ."index.php?mode=showp&id=". $picture;
1646 if($current_tags != "") {
1647 $orig_url.= "&tags=". $current_tags;
1649 if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
1650 $orig_url.= "&from_date=". $_SESSION['from_date'] ."&to_date=". $_SESSION['to_date'];
1653 $details = $this->get_photo_details($picture);
1655 $thumb_url = $this->get_phpfspot_url() ."phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width;
1656 $thumb_html = htmlspecialchars("
1657 <a href=\"". $orig_url ."\"><img src=\"". $thumb_url ."\" /></a>
1659 ". $details['description']);
1661 $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name'];
1662 $meta = $this->get_meta_informations($orig_path);
1663 $meta_date = isset($meta['FileDateTime']) ? $meta['FileDateTime'] : filemtime($orig_path);
1667 <title><?php print htmlspecialchars($details['name']); ?></title>
1668 <link><?php print htmlspecialchars($orig_url); ?></link>
1669 <guid><?php print htmlspecialchars($orig_url); ?></guid>
1670 <dc:date.Taken><?php print strftime("%Y-%m-%dT%H:%M:%S+00:00", $meta_date); ?></dc:date.Taken>
1672 <?php print $thumb_html; ?>
1674 <pubDate><?php print strftime("%a, %d %b %Y %T %z"); ?></pubDate>
1689 * return all selected tags as one string
1691 private function getCurrentTags()
1694 if($_SESSION['selected_tags'] != "") {
1695 foreach($_SESSION['selected_tags'] as $tag)
1696 $current_tags.= $tag .",";
1697 $current_tags = substr($current_tags, 0, strlen($current_tags)-1);
1699 return $current_tags;
1701 } // getCurrentTags()
1704 * return the current photo
1706 public function getCurrentPhoto()
1708 if(isset($_SESSION['current_photo'])) {
1709 print $_SESSION['current_photo'];
1711 } // getCurrentPhoto()
1714 * tells the client browser what to do
1716 * this function is getting called via AJAX by the
1717 * client browsers. it will tell them what they have
1718 * to do next. This is necessary for directly jumping
1719 * into photo index or single photo view when the are
1720 * requested with specific URLs
1722 public function whatToDo()
1724 if(isset($_SESSION['current_photo']) && $_SESSION['start_action'] == 'showp') {
1725 return "show_photo";
1727 elseif(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
1728 return "showpi_tags";
1730 elseif(isset($_SESSION['start_action']) && $_SESSION['start_action'] == 'showpi') {
1734 return "nothing special";
1739 * return the current process-user
1741 private function getuid()
1743 if($uid = posix_getuid()) {
1744 if($user = posix_getpwuid($uid)) {
1745 return $user['name'];
1754 * returns a select-dropdown box to select photo index sort parameters
1756 private function get_sort_field()
1758 $output = "<select name=\"sort_order\">";
1759 foreach(array('date_asc', 'date_desc', 'name_asc', 'name_desc') as $sort_order) {
1760 $output.= "<option value=\"". $sort_order ."\"";
1761 if($sort_order == $_SESSION['sort_order']) {
1762 $output.= " selected=\"selected\"";
1764 $output.= ">". $sort_order ."</option>";
1766 $output.= "</select>";
1769 } // get_sort_field()
1772 * returns the currently selected sort order
1774 private function get_sort_order()
1776 switch($_SESSION['sort_order']) {
1778 return " ORDER BY p.time ASC";
1781 return " ORDER BY p.time DESC";
1784 return " ORDER BY p.name ASC";
1787 return " ORDER BY p.name DESC";
1791 } // get_sort_order()
1794 * return the next to be shown slide show image
1796 * this function returns the URL of the next image
1797 * in the slideshow sequence.
1799 public function getNextSlideShowImage()
1801 $all_photos = $this->getPhotoSelection();
1803 if(!isset($_SESSION['slideshow_img']) || $_SESSION['slideshow_img'] == count($all_photos)-1)
1804 $_SESSION['slideshow_img'] = 0;
1806 $_SESSION['slideshow_img']++;
1808 return $this->get_phpfspot_url() ."phpfspot_img.php?idx=". $all_photos[$_SESSION['slideshow_img']] ."&width=". $this->cfg->photo_width;
1810 } // getNextSlideShowImage()
1813 * return the previous to be shown slide show image
1815 * this function returns the URL of the previous image
1816 * in the slideshow sequence.
1818 public function getPrevSlideShowImage()
1820 $all_photos = $this->getPhotoSelection();
1822 if(!isset($_SESSION['slideshow_img']) || $_SESSION['slideshow_img'] == 0)
1823 $_SESSION['slideshow_img'] = 0;
1825 $_SESSION['slideshow_img']--;
1827 return $this->get_phpfspot_url() ."phpfspot_img.php?idx=". $all_photos[$_SESSION['slideshow_img']] ."&width=". $this->cfg->photo_width;
1829 } // getPrevSlideShowImage()
1831 public function resetSlideShow()
1833 if(isset($_SESSION['slideshow_img']))
1834 unset($_SESSION['slideshow_img']);
1835 } // resetSlideShow()
1840 * this function will get all photos from the fspot
1841 * database and randomly return ONE entry
1843 * saddly there is yet no sqlite3 function which returns
1844 * the bulk result in array, so we have to fill up our
1847 public function get_random_photo()
1851 $result = $this->db->db_query("
1856 while($row = $this->db->db_fetch_object($result)) {
1857 array_push($all, $row['id']);
1860 return $all[array_rand($all)];
1862 } // get_random_photo()
1865 * validates provided date
1867 * this function validates if the provided date
1868 * contains a valid date and will return true
1871 public function isValidDate($date_str)
1873 $timestamp = strtotime($date_str);
1875 if(is_numeric($timestamp))
1883 * timestamp to string conversion
1885 private function ts2str($timestamp)
1887 return strftime("%Y-%m-%d", $timestamp);
1890 private function extractTags($tags_str)
1892 $not_validated = split(',', $_GET['tags']);
1893 $validated = array();
1895 foreach($not_validated as $tag) {
1896 if(is_numeric($tag))
1897 array_push($validated, $tag);
1905 * returns the full path to a thumbnail
1907 public function get_thumb_path($width, $photo)
1909 $sub_path = substr($this->getMD5($photo), 0, 2);
1910 return $this->cfg->base_path
1916 . $this->getMD5($photo);
1918 } // get_thumb_path()
1921 * returns server's virtual host name
1923 private function get_server_name()
1925 return $_SERVER['SERVER_NAME'];
1926 } // get_server_name()
1929 * returns type of webprotocol which is
1932 private function get_web_protocol()
1934 if(!isset($_SERVER['HTTPS']))
1938 } // get_web_protocol()
1941 * return url to this phpfspot installation
1943 private function get_phpfspot_url()
1945 return $this->get_web_protocol() ."://". $this->get_server_name() . $this->cfg->web_path;
1946 } // get_phpfspot_url()