From 867cf65e5ec98f5be8529a584329385814543e4d Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sun, 4 May 2008 09:44:14 +0200 Subject: [PATCH 1/1] issue118, user-friendly-url to directly address a photo or a photo-view Signed-off-by: Andreas Unterkircher --- phpfspot.class.php | 91 +++++++++++++++++++---- phpfspot.js | 2 + rpc.php | 2 +- themes/default/templates/single_photo.tpl | 24 +++--- themes/default/templates/tags.tpl | 6 +- 5 files changed, 96 insertions(+), 29 deletions(-) diff --git a/phpfspot.class.php b/phpfspot.class.php index badc728..99b0d7b 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -245,7 +245,7 @@ class PHPFSPOT { $this->tmpl->assign('template_path', 'themes/'. $this->cfg->theme_name); /* parse URL */ - if(isset($this->cfg->user_friendly_url) && $this->cfg->user_friendly_url) { + if($this->is_user_friendly_url()) { $content = $this->parse_user_friendly_url($_SERVER['REQUEST_URI']); } @@ -619,12 +619,15 @@ class PHPFSPOT { $this->tmpl->assign('ExifOrigResolution', $meta_res); $this->tmpl->assign('ExifFileSize', $meta_size); - if(!isset($this->cfg->user_friendly_url) || !$this->cfg->user_friendly_url) - $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width); - else + if($this->is_user_friendly_url()) { $this->tmpl->assign('image_url', '/photo/'. $photo ."/". $this->cfg->photo_width); + $this->tmpl->assign('image_url_full', '/photo/'. $photo); + } + else { + $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&width=". $this->cfg->photo_width); + $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo); + } - $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo); $this->tmpl->assign('image_filename', $this->parse_uri($details['uri'], 'filename')); $this->tmpl->assign('tags', $this->get_photo_tags($photo)); @@ -1353,17 +1356,19 @@ class PHPFSPOT { $this->tmpl->assign('thumbs', $thumbs); $this->tmpl->assign('selected_tags', $this->getSelectedTags('img')); - $this->tmpl->show("photo_index.tpl"); + $result = $this->tmpl->fetch("photo_index.tpl"); /* if we are returning to photo index from an photo-view, scroll the window to the last shown photo-thumbnail. after this, unset the last_photo session variable. */ if(isset($_SESSION['last_photo'])) { - print "\n"; + $result.= "\n"; unset($_SESSION['last_photo']); } + return $result; + } // showPhotoIndex() /** @@ -2277,7 +2282,7 @@ class PHPFSPOT { foreach($pictures as $picture) { - $orig_url = $this->get_phpfspot_url() ."index.php?mode=showp&id=". $picture; + $orig_url = $this->get_phpfspot_url() ."/index.php?mode=showp&id=". $picture; if($current_tags != "") { $orig_url.= "&tags=". $current_tags; } @@ -2285,7 +2290,12 @@ class PHPFSPOT { $orig_url.= "&from_date=". $_SESSION['from_date'] ."&to_date=". $_SESSION['to_date']; } - $thumb_url = $this->get_phpfspot_url() ."phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width; + if($this->is_user_friendly_url()) { + $thumb_url = $this->get_phpfspot_url() ."/photo/". $picture ."/". $this->cfg->thumb_width; + } + else { + $thumb_url = $this->get_phpfspot_url() ."/phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width; + } switch($mode) { @@ -2334,7 +2344,7 @@ class PHPFSPOT { foreach($pictures as $picture) { - $orig_url = $this->get_phpfspot_url() ."index.php?mode=showp&id=". $picture; + $orig_url = $this->get_phpfspot_url() ."/index.php?mode=showp&id=". $picture; if($current_tags != "") { $orig_url.= "&tags=". $current_tags; } @@ -2344,7 +2354,13 @@ class PHPFSPOT { $details = $this->get_photo_details($picture); - $thumb_url = $this->get_phpfspot_url() ."phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width; + if($this->is_user_friendly_url()) { + $thumb_url = $this->get_phpfspot_url() ."/photo/". $picture ."/". $this->cfg->thumb_width; + } + else { + $thumb_url = $this->get_phpfspot_url() ."/phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width; + } + $thumb_html = htmlspecialchars("
@@ -2527,7 +2543,11 @@ class PHPFSPOT { else $_SESSION['slideshow_img']++; - return $this->get_phpfspot_url() ."phpfspot_img.php?idx=". $all_photos[$_SESSION['slideshow_img']] ."&width=". $this->cfg->photo_width; + if($this->is_user_friendly_url()) { + return $this->get_phpfspot_url() ."/photo/". $all_photos[$_SESSION['slideshow_img']] ."/". $this->cfg->photo_width; + } + + return $this->get_phpfspot_url() ."/phpfspot_img.php?idx=". $all_photos[$_SESSION['slideshow_img']] ."&width=". $this->cfg->photo_width; } // getNextSlideShowImage() @@ -2547,7 +2567,11 @@ class PHPFSPOT { else $_SESSION['slideshow_img']--; - return $this->get_phpfspot_url() ."phpfspot_img.php?idx=". $all_photos[$_SESSION['slideshow_img']] ."&width=". $this->cfg->photo_width; + if($this->is_user_friendly_url()) { + return $this->get_phpfspot_url() ."/photo/". $all_photos[$_SESSION['slideshow_img']] ."/". $this->cfg->photo_width; + } + + return $this->get_phpfspot_url() ."/phpfspot_img.php?idx=". $all_photos[$_SESSION['slideshow_img']] ."&width=". $this->cfg->photo_width; } // getPrevSlideShowImage() @@ -2747,7 +2771,16 @@ class PHPFSPOT { */ private function get_phpfspot_url() { - return $this->get_web_protocol() ."://". $this->get_server_name() . $this->cfg->web_path; + if($this->cfg->web_path == "/") + $web_path = ""; + /* remove trailing slash */ + elseif(preg_match('/\/$/', $this->cfg->web_path)) + $web_path = preg_replace('/\/$/', '', $this->cfg->web_path); + else + $web_path = $this->cfg->web_path; + + return $this->get_web_protocol() ."://". $this->get_server_name() . $web_path; + } // get_phpfspot_url() /** @@ -3062,7 +3095,10 @@ class PHPFSPOT { private function parse_user_friendly_url($request_uri) { - if(preg_match('/\/photoview\/|\/photo\//', $request_uri)) { + if(preg_match('/\/photoview\/|\/photo\/|\/tag\//', $request_uri)) { + + unset($_SESSION['start_action']); + unset($_SESSION['selected_tags']); $options = explode('/', $request_uri); @@ -3083,11 +3119,36 @@ class PHPFSPOT { } exit; break; + case 'tag': + if(is_numeric($options[2])) { + $_GET['mode'] = 'showpi'; + $_SESSION['selected_tags'] = Array($options[2]); + $this->tmpl->assign('preset_selected_tags', $this->getSelectedTags()); + $_GET['tags'] = $options[2]; + return $this->showPhotoIndex(); + } + break; } } } // parse_user_friendly_url() + /** + * check if user-friendly-urls are enabled + * + * this function will return true, if the config option + * $user_friendly_url has been set. Otherwise false. + * @return boolean + */ + private function is_user_friendly_url() + { + if(isset($this->cfg->user_friendly_url) && $this->cfg->user_friendly_url) + return true; + + return false; + + } // is_user_friendly_url() + } // class PHPFSPOT diff --git a/phpfspot.js b/phpfspot.js index 6c0054d..47ebe32 100644 --- a/phpfspot.js +++ b/phpfspot.js @@ -373,6 +373,8 @@ function init_phpfspot(mode) /* ask the server what we are currently displaying */ whattodo = AskServerWhatToDo(); + window.alert(whattodo); + if(whattodo == 'showpi' || whattodo == 'showpi_date') { showPhotoIndex(); } diff --git a/rpc.php b/rpc.php index 5ff334e..e2da768 100644 --- a/rpc.php +++ b/rpc.php @@ -117,7 +117,7 @@ class PHPFSPOT_RPC { if(isset($_GET['last_photo']) && is_numeric($_GET['last_photo'])) $_SESSION['last_photo'] = $_GET['last_photo']; - $phpfspot->showPhotoIndex(); + return $phpfspot->showPhotoIndex(); break; case 'showcredits': diff --git a/themes/default/templates/single_photo.tpl b/themes/default/templates/single_photo.tpl index 04a3502..8526053 100644 --- a/themes/default/templates/single_photo.tpl +++ b/themes/default/templates/single_photo.tpl @@ -15,14 +15,14 @@ {/if}
- - - + + +  Auto-Browse {if $extern_link }  External Link {/if} - original resolution Fullsize + original resolution Fullsize
@@ -45,19 +45,19 @@
available tags Tagged with:
{ foreach from=$tags key=id item=name } - {$name}
+ {$name}
{ /foreach } { /if }
{ if $prev_img } photo icon Previous:
- +
{ /if} { if $next_img } photo icon Next:
- +
{ /if} @@ -67,9 +67,9 @@
{ if $next_url == "" } - + { else } - + { /if } {$image_filename} @@ -81,17 +81,17 @@ { if $previous_url == "" } first photo reached { else } - + previous photo { /if } - + photo index { if $next_url == "" } last photo reached { else } - + next photo { /if} diff --git a/themes/default/templates/tags.tpl b/themes/default/templates/tags.tpl index 326c095..42a20ff 100644 --- a/themes/default/templates/tags.tpl +++ b/themes/default/templates/tags.tpl @@ -8,4 +8,8 @@   || && -
no tags selected
+{ if $preset_selected_tags } +
{ $preset_selected_tags }
+{ else } +
no tags selected
+{ /if } -- 2.17.1