diff options
-rw-r--r-- | phpfspot.class.php | 78 | ||||
-rw-r--r-- | phpfspot_img.php | 86 | ||||
-rw-r--r-- | resources/underbar.png | bin | 0 -> 304 bytes | |||
-rw-r--r-- | themes/default/stylesheet.css | 7 | ||||
-rw-r--r-- | themes/default/templates/photo_index.tpl | 11 |
5 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.= "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a>, "; + + switch($type) { + default: + case 'link': + $output.= "<a href=\"javascript:Tags('del', ". $tag .");\" class=\"tag\">". $this->tags[$tag] ."</a>, "; + break; + case 'img': + $output.= " + <div style=\"display: table-cell;\"> + <div style=\"display: table-row; text-align: center;\"> + <a href=\"javascript:Tags('del', ". $tag .");\" title=\"". $this->tags[$tag] ."\"> + <img src=\"phpfspot_img.php?tagidx=". $tag ."\" /> + </a> + </div> + <div style=\"display: table-row; text-align: center;\"> + <a href=\"javascript:Tags('del', ". $tag .");\" title=\"". $this->tags[$tag] ."\"> + <img src=\"resources/underbar.png\" /> + </a> + </div> + </div> + "; + 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 */ @@ -2564,6 +2588,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 * * this function validates if the 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/resources/underbar.png b/resources/underbar.png Binary files differnew file mode 100644 index 0000000..013cf7b --- /dev/null +++ b/resources/underbar.png 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} </div> - <div style="text-align: right"> +<div style="text-align: right"> {if $slideshow_link } <a href="{$slideshow_link}" title="Slideshow" target="_blank"><img src="resources/slideshow.png" /></a> {/if} @@ -41,6 +41,15 @@ {/if} </div> </div> +{ if $tag_result } +<div style="height: 1px; background-color: #ffffff;"></div> +<div class="subheader"> + <div style="display: table-cell; vertical-align: middle;"> + Tags: + </div> + { $selected_tags } +</div> +{ /if } <div id="index"> |