X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=phpfspot.git;a=blobdiff_plain;f=phpfspot.class.php;h=ba94884fe4a215f8a9a282bdacc13381d6bd879a;hp=92a0199a339bdbe89c949e6a2a6d4289a2a81121;hb=22ac9327fb70b59796a6e5405e18788e89af4d69;hpb=873c2c27c91e4d64fd2ec3f07e3de47caf8e076b diff --git a/phpfspot.class.php b/phpfspot.class.php index 92a0199..ba94884 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -12,7 +12,6 @@ class PHPFSPOT { var $tmpl; var $tags; var $avail_tags; - var $current_tags; public function __construct() { @@ -24,6 +23,12 @@ class PHPFSPOT { $this->cfg = new PHPFSPOT_CFG; $this->db = new PHPFSPOT_DB(&$this, $this->cfg->fspot_db); + + if(!is_writeable(dirname($this->cfg->phpfspot_db))) { + print dirname($this->cfg->phpfspot_db) .": directory is not writeable!"; + exit(1); + } + $this->cfg_db = new PHPFSPOT_DB(&$this, $this->cfg->phpfspot_db); $this->check_config_table(); @@ -55,17 +60,46 @@ 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()); + + $_SESSION['start_action'] = $_GET['mode']; switch($_GET['mode']) { case 'showpi': if(isset($_GET['tags'])) { $_SESSION['selected_tags'] = split(',', $_GET['tags']); } + if(isset($_GET['from_date'])) { + $_SESSION['from_date'] = $_GET['from_date']; + } + if(isset($_GET['to_date'])) { + $_SESSION['to_date'] = $_GET['to_date']; + } break; + case 'showp': + if(isset($_GET['tags'])) { + $_SESSION['selected_tags'] = split(',', $_GET['tags']); + $_SESSION['start_action'] = 'showp'; + } + if(isset($_GET['id'])) { + $_SESSION['current_photo'] = $_GET['id']; + $_SESSION['start_action'] = 'showp'; + } + if(isset($_GET['from_date'])) { + $_SESSION['from_date'] = $_GET['from_date']; + } + if(isset($_GET['to_date'])) { + $_SESSION['to_date'] = $_GET['to_date']; + } + break; + case 'export': + $this->tmpl->show("export.tpl"); + return; + break; + } + $this->tmpl->assign('from_date', $this->get_calendar('from')); + $this->tmpl->assign('to_date', $this->get_calendar('to')); $this->tmpl->assign('content_page', 'welcome.tpl'); $this->tmpl->show("index.tpl"); @@ -114,18 +148,14 @@ class PHPFSPOT { } // get_photo_details - public function getPhotoName($idx) + public function getPhotoName($idx, $limit = 0) { if($details = $this->get_photo_details($idx)) { - $name = $details['name']; - - if(strlen($name) > 15) { - $name = substr($name, 0, 10) ."...". substr($name, -10); + if($limit != 0 && strlen($name) > $limit) { + $name = substr($name, 0, $limit-5) ."...". substr($name, -($limit-5)); } - return $name; - } } // getPhotoName() @@ -191,6 +221,17 @@ class PHPFSPOT { $meta_make = isset($meta['Make']) ? $meta['Make'] ." ". $meta['Model'] : "n/a"; $meta_size = isset($meta['FileSize']) ? round($meta['FileSize']/1024, 1) ."kbyte" : "n/a"; + $current_tags = $this->getCurrentTags(); + $extern_link = "index.php?mode=showp&id=". $photo; + if($current_tags != "") { + $extern_link.= "&tags=". $current_tags; + } + if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) { + $extern_link.= "&from_date=". $_SESSION['from_date'] ."&to_date=". $_SESSION['to_date']; + } + + $this->tmpl->assign('extern_link', $extern_link); + if(file_exists($thumb_path)) { $info = getimagesize($thumb_path); @@ -217,11 +258,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"); @@ -284,19 +328,25 @@ class PHPFSPOT { public function getSelectedTags() { + $output = ""; foreach($this->avail_tags as $tag) { // return all selected tags if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) { - print "". $this->tags[$tag] ." "; + $output.= "". $this->tags[$tag] .", "; } - } + $output = substr($output, 0, strlen($output)-2); + print $output; + } // getSelectedTags() public function addTag($tag) { + // if the result of a date search are displayed, reset them + $this->resetDateSearch(); + if(!isset($_SESSION['selected_tags'])) $_SESSION['selected_tags'] = Array(); @@ -317,19 +367,37 @@ class PHPFSPOT { public function resetTags() { - unset($_SESSION['selected_tags']); + if(isset($_SESSION['selected_tags'])) + unset($_SESSION['selected_tags']); } // resetTags() + public function resetPhotoView() + { + if(isset($_SESSION['current_photo'])) + unset($_SESSION['current_photo']); + + } // resetPhotoView(); + public function resetTagSearch() { - unset($_SESSION['searchfor']); + if(isset($_SESSION['searchfor'])) + unset($_SESSION['searchfor']); } // resetTagSearch() + public function resetDateSearch() + { + if(isset($_SESSION['from_date'])) + unset($_SESSION['from_date']); + if(isset($_SESSION['to_date'])) + unset($_SESSION['to_date']); + + } // resetDateSearch(); + public function getPhotoSelection() { - $tagged_photos = Array(); + $matched_photos = Array(); /* return a search result */ if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') { @@ -344,9 +412,9 @@ class PHPFSPOT { ORDER BY p.time ASC "); while($row = $this->db->db_fetch_object($result)) { - array_push($tagged_photos, $row['photo_id']); + array_push($matched_photos, $row['photo_id']); } - return $tagged_photos; + return $matched_photos; } /* return according the selected tags */ @@ -368,6 +436,12 @@ class PHPFSPOT { } elseif($_SESSION['tag_condition'] == 'and') { + if(count($_SESSION['selected_tags']) >= 32) { + print "A SQLite limit of 32 tables within a JOIN SELECT avoids to
\n"; + print "evaluate your tag selection. Please remove some tags from your selection.\n"; + return Array(); + } + /* Join together a table looking like pt1.photo_id pt1.tag_id pt2.photo_id pt2.tag_id ... @@ -398,11 +472,31 @@ class PHPFSPOT { } while($row = $this->db->db_fetch_object($result)) { - array_push($tagged_photos, $row['photo_id']); + array_push($matched_photos, $row['photo_id']); } - return $tagged_photos; + return $matched_photos; } + if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) { + $from_date = strtotime($_SESSION['from_date']); + $to_date = strtotime($_SESSION['to_date']); + $result = $this->db->db_query(" + SELECT DISTINCT photo_id + FROM photo_tags pt + INNER JOIN photos p + ON p.id=pt.photo_id + WHERE + time>='". $from_date ."' + AND + time<='". $to_date ."' + ORDER BY p.time ASC + "); + while($row = $this->db->db_fetch_object($result)) { + array_push($matched_photos, $row['photo_id']); + } + return $matched_photos; + } + /* return all available photos */ $result = $this->db->db_query(" SELECT DISTINCT photo_id @@ -412,9 +506,9 @@ class PHPFSPOT { ORDER BY p.time ASC "); while($row = $this->db->db_fetch_object($result)) { - array_push($tagged_photos, $row['photo_id']); + array_push($matched_photos, $row['photo_id']); } - return $tagged_photos; + return $matched_photos; } // getPhotoSelection() @@ -465,12 +559,14 @@ class PHPFSPOT { $img_width[$rows] = Array(); $img_id[$rows] = Array(); $img_name[$rows] = Array(); + $img_title = 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]); + $img_name[$rows][$cols] = htmlspecialchars($this->getPhotoName($photos[$i], 15)); + $img_title[$rows][$cols] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0)); $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->thumb_width ."_". $this->getMD5($photos[$i]); @@ -498,6 +594,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 */ @@ -509,19 +606,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++; @@ -540,11 +631,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 */ @@ -552,19 +666,20 @@ class PHPFSPOT { $this->tmpl->assign('page_selector', $page_select); } - $current_tags = ""; - if($_SESSION['selected_tags'] != "") { - foreach($_SESSION['selected_tags'] as $tag) - $current_tags.= $tag .","; - $current_tags = substr($current_tags, 0, strlen($current_tags)-1); - } - - $extern_link = "http://". $_SERVER['SERVER_NAME'] ."/index.php?mode=showpi"; + + $current_tags = $this->getCurrentTags(); + $extern_link = "index.php?mode=showpi"; if($current_tags != "") { $extern_link.= "&tags=". $current_tags; } + if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) { + $extern_link.= "&from_date=". $_SESSION['from_date'] ."&to_date=". $_SESSION['to_date']; + } + + $export_link = "index.php?mode=export"; $this->tmpl->assign('extern_link', $extern_link); + $this->tmpl->assign('export_link', $export_link); $this->tmpl->assign('count', $count); $this->tmpl->assign('width', $this->cfg->thumb_width); $this->tmpl->assign('images', $images); @@ -572,6 +687,7 @@ class PHPFSPOT { $this->tmpl->assign('img_height', $img_height); $this->tmpl->assign('img_id', $img_id); $this->tmpl->assign('img_name', $img_name); + $this->tmpl->assign('img_title', $img_title); $this->tmpl->assign('rows', $rows); $this->tmpl->assign('columns', $this->cfg->thumbs_per_row); @@ -582,43 +698,6 @@ class PHPFSPOT { } // showPhotoIndex() - public function showBubbleDetails($photo, $direction) - { - if($direction == "up") - $direction = "bubbleimg_up"; - else - $direction = "bubbleimg_down"; - - $details = $this->get_photo_details($photo); - $orig_path = $this->translate_path($details['directory_path']) ."/". $details['name']; - - $image_url = "phpfspot_img.php?idx=". $photo ."&width=". $this->cfg->bubble_width; - - $filesize = filesize($orig_path); - $filesize = rand($filesize/1024, 2); - - if(!file_exists($orig_path)) { - $this->_warning("Photo ". $orig_path ." does not exist!
\n"); - return; - } - - if(!is_readable($orig_path)) { - $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."
\n"); - return; - } - - $img = getimagesize($orig_path); - - $this->tmpl->assign('file_size', $filesize); - $this->tmpl->assign('width', $img[0]); - $this->tmpl->assign('height', $img[1]); - $this->tmpl->assign('file_name', $details['name']); - $this->tmpl->assign('image_id', $direction); - $this->tmpl->assign('image_url', $image_url); - $this->tmpl->show("bubble_details.tpl"); - - } // showBubbleDetails() - public function showCredits() { $this->tmpl->assign('version', $this->cfg->version); @@ -796,8 +875,8 @@ class PHPFSPOT { $resolutions = Array( $this->cfg->thumb_width, - $this->cfg->bubble_width, $this->cfg->photo_width, + $this->cfg->mini_width, ); /* get details from F-Spot's database */ @@ -892,8 +971,16 @@ class PHPFSPOT { array_push($_SESSION['selected_tags'], $tag); } + $this->resetDateSearch(); + } // startTagSearch() + public function startDateSearch($from, $to) + { + $_SESSION['from_date'] = $from; + $_SESSION['to_date'] = $to; + } + private function rotateImage($img, $degrees) { if(function_exists("imagerotate")) @@ -1066,37 +1153,171 @@ class PHPFSPOT { } // _warning() - private function get_calendar() + private function get_calendar($mode) { -// require_once CALENDAR_ROOT.'Year.php'; -// require_once CALENDAR_ROOT.'Month.php'; -// require_once CALENDAR_ROOT.'Day.php'; + $year = $_SESSION[$mode .'_date'] ? date("Y", strtotime($_SESSION[$mode .'_date'])) : date("Y"); + $month = $_SESSION[$mode .'_date'] ? date("m", strtotime($_SESSION[$mode .'_date'])) : date("m"); + $day = $_SESSION[$mode .'_date'] ? date("d", strtotime($_SESSION[$mode .'_date'])) : date("d"); + + $output = "\n"; + $output.= "\n"; + $output.= "\n"; + return $output; + + } // get_calendar() + + public function get_calendar_matrix($year = 0, $month = 0, $day = 0) + { + if (!isset($year)) $year = date('Y'); + if (!isset($month)) $month = date('m'); + if (!isset($day)) $day = date('d'); + $rows = 1; + $cols = 1; + $matrix = Array(); + + require_once CALENDAR_ROOT.'Month/Weekdays.php'; + require_once CALENDAR_ROOT.'Day.php'; -// $Year = new Calendar_Year(); -// $Month = new Calendar_Month(); -// $Day = new Calendar_Day(); - $output = "\n"; - $output.= "\n"; + } // getCurrentPhoto() - $output.= "\n"; - return $output; + return "nothing special"; - } // get_calendar() + } // whatToDo() }