From 4552617dca9f593137d6785ccd67c6a421df232f Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sat, 26 Apr 2008 10:18:50 +0200 Subject: [PATCH] issue115, display tag-selection in photo-index Signed-off-by: Andreas Unterkircher --- phpfspot.class.php | 78 ++++++++++++++++++++- phpfspot_img.php | 86 ++++++++++++++++++++++-- themes/default/stylesheet.css | 7 ++ themes/default/templates/photo_index.tpl | 11 ++- 4 files changed, 174 insertions(+), 8 deletions(-) diff --git a/phpfspot.class.php b/phpfspot.class.php index bae4ae7..97deb96 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -726,7 +726,7 @@ class PHPFSPOT { * session-variable $_SESSION['selected_tags'] * @return string */ - public function getSelectedTags() + public function getSelectedTags($type = 'link') { /* retrive tags from database */ $this->get_tags(); @@ -737,7 +737,29 @@ class PHPFSPOT { { // return all selected tags if(isset($_SESSION['selected_tags']) && in_array($tag, $_SESSION['selected_tags'])) { - $output.= "". $this->tags[$tag] .", "; + + switch($type) { + default: + case 'link': + $output.= "". $this->tags[$tag] .", "; + break; + case 'img': + $output.= " +
+
+ tags[$tag] ."\"> + + +
+
+ tags[$tag] ."\"> + + +
+
+ "; + break; + } } } @@ -1315,6 +1337,7 @@ class PHPFSPOT { $this->tmpl->assign('img_fullname', $img_fullname); $this->tmpl->assign('img_title', $img_title); $this->tmpl->assign('thumbs', $thumbs); + $this->tmpl->assign('selected_tags', $this->getSelectedTags('img')); $this->tmpl->show("photo_index.tpl"); @@ -1634,6 +1657,7 @@ class PHPFSPOT { $this->cfg->thumb_width, $this->cfg->photo_width, $this->cfg->mini_width, + 30, ); /* get details from F-Spot's database */ @@ -2563,6 +2587,56 @@ class PHPFSPOT { } // get_random_photo() + /** + * get random photo tag photo + * + * this function will get all photos tagged with the requested + * tag from the fspot database and randomly return ONE entry + * + * saddly there is yet no sqlite3 function which returns + * the bulk result in array, so we have to fill up our + * own here. + * @return array + */ + public function get_random_tag_photo($tagidx) + { + $all = Array(); + + $query_str = " + SELECT p.id + FROM photos p + INNER JOIN photo_tags pt + ON p.id=pt.photo_id + "; + + if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) { + $query_str.= " + INNER JOIN tags t + ON pt.tag_id=t.id + "; + } + $query_str.= " + WHERE + pt.tag_id LIKE '". $tagidx ."' + "; + + if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) { + $query_str.= " + AND + t.name IN ('".implode("','",$this->cfg->show_tags)."') + "; + } + + $result = $this->db->db_query($query_str); + + while($row = $this->db->db_fetch_object($result)) { + array_push($all, $row['id']); + } + + return $all[array_rand($all)]; + + } // get_random_tag_photo() + /** * validates provided date * diff --git a/phpfspot_img.php b/phpfspot_img.php index bc8d3d1..3599b2b 100644 --- a/phpfspot_img.php +++ b/phpfspot_img.php @@ -64,7 +64,7 @@ class PHPFSPOT_IMG { * @param integer $idx * @param integer $width */ - public function show($idx, $width = 0) + public function showImg($idx, $width = 0) { if($idx == 'rand') $idx = $this->parent->get_random_photo(); @@ -118,12 +118,76 @@ class PHPFSPOT_IMG { Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); Header("Cache-Control: no-cache"); Header("Pragma: no-cache"); - + + $file = fopen($fullpath, "rb"); + fpassthru($file); + @fclose($file); + + } // showImg() + + /** + * sends a random photo of the requested tag to the browser + * + * this function will send a random photo to the client. + * It is selected out by the provided $tagidx. It also try's + * to create on-the-fly missing thumbnails via PHPFSPOT + * gen_thumbs function. + * @param integer $idx + */ + public function showTagImg($tagidx) + { + $idx = $this->parent->get_random_tag_photo($tagidx); + $width = 30; + + $details = $this->parent->get_photo_details($idx); + + if(!$details) { + $this->parent->showTextImage("The image (". $idx .") you requested is unknown"); + return; + } + + /* if no entry for this photo is yet in the database, create thumb */ + if(!$this->parent->getMD5($idx)) { + $this->parent->gen_thumb($idx); + } + $fullpath = $this->parent->get_thumb_path($width, $idx); + /* if the thumb file does not exist, create it */ + if(!file_exists($fullpath)) { + $this->parent->gen_thumb($idx); + } + + if(!file_exists($fullpath)) { + $this->parent->showTextImage("File ". basename($fullpath) ." does not exist"); + return; + } + if(!is_readable($fullpath)) { + $this->parent->showTextImage("File ". basename($fullpath) ." is not readable. Check the permissions"); + return; + } + + $mime = $this->parent->get_mime_info($fullpath); + + if(!$this->parent->checkifImageSupported($mime)) { + $this->parent->showTextImage("Unsupported Image Type"); + return; + } + + Header("Content-Type: ". $mime); + Header("Content-Length: ". filesize($fullpath)); + Header("Content-Transfer-Encoding: binary\n"); + Header("Content-Disposition: inline; filename=\"". $this->parent->parse_uri($details['uri'], 'filename') ."\""); + Header("Content-Description: ". $this->parent->parse_uri($details['uri'], 'filename')); + Header("Accept-Ranges: bytes"); + Header("Connection: close"); + Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); + Header("Cache-Control: no-cache"); + Header("Pragma: no-cache"); + $file = fopen($fullpath, "rb"); fpassthru($file); @fclose($file); - } // show() + } // showTagImg() } // PHPFSPOT_IMG() @@ -132,9 +196,21 @@ if(isset($_GET['idx']) && (is_numeric($_GET['idx']) || $_GET['idx'] == 'rand')) $img = new PHPFSPOT_IMG; if(isset($_GET['width']) && is_numeric($_GET['width'])) - $img->show($_GET['idx'], $_GET['width']); + $img->showImg($_GET['idx'], $_GET['width']); else - $img->show($_GET['idx']); + $img->showImg($_GET['idx']); + + exit(0); } +if(isset($_GET['tagidx']) && is_numeric($_GET['tagidx'])) { + + $img = new PHPFSPOT_IMG; + $img->showTagImg($_GET['tagidx']); + + exit(0); + +} + + ?> diff --git a/themes/default/stylesheet.css b/themes/default/stylesheet.css index e9a505c..7771736 100644 --- a/themes/default/stylesheet.css +++ b/themes/default/stylesheet.css @@ -83,6 +83,13 @@ div.header { white-space: nowrap; } +div.subheader { + background-color: #eeeeee; + padding: 5px 10px 5px 10px; + vertical-align: middle; + white-space: nowrap; +} + img { border: none; } diff --git a/themes/default/templates/photo_index.tpl b/themes/default/templates/photo_index.tpl index 82f4959..c01c6af 100644 --- a/themes/default/templates/photo_index.tpl +++ b/themes/default/templates/photo_index.tpl @@ -26,7 +26,7 @@ Results are limited to a date within {$from_date} to {$to_date}. {/if} -
+
{if $slideshow_link } {/if} @@ -41,6 +41,15 @@ {/if}
+{ if $tag_result } +
+
+
+ Tags: +
+ { $selected_tags } +
+{ /if }
-- 2.25.1