issue118, user-friendly-url to directly address a photo or a photo-view
authorAndreas Unterkircher <unki@netshadow.at>
Sun, 4 May 2008 07:44:14 +0000 (09:44 +0200)
committerAndreas Unterkircher <unki@netshadow.at>
Sun, 4 May 2008 19:52:25 +0000 (21:52 +0200)
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
phpfspot.class.php
phpfspot.js
rpc.php
themes/default/templates/single_photo.tpl
themes/default/templates/tags.tpl

index badc728980262accbed01b66789e88c5b4b4aec8..99b0d7b9fe1c767837205385d901ed421d2e5d7d 100644 (file)
@@ -245,7 +245,7 @@ class PHPFSPOT {
       $this->tmpl->assign('template_path', 'themes/'. $this->cfg->theme_name);
 
       /* parse URL */
       $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']);
       }
 
          $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);
  
       $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 ."&amp;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', '/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 ."&amp;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));
       $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->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'])) {
 
       /* 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 "<script language=\"JavaScript\">moveToThumb(". $_SESSION['last_photo'] .");</script>\n";
+         $result.= "<script language=\"JavaScript\">moveToThumb(". $_SESSION['last_photo'] .");</script>\n";
          unset($_SESSION['last_photo']);
       }
 
          unset($_SESSION['last_photo']);
       }
 
+      return $result;
+
    } // showPhotoIndex()
 
    /**
    } // showPhotoIndex()
 
    /**
@@ -2277,7 +2282,7 @@ class PHPFSPOT {
 
       foreach($pictures as $picture) {
 
 
       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;
          } 
          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'];
          }
 
             $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) {
 
 
          switch($mode) {
 
@@ -2334,7 +2344,7 @@ class PHPFSPOT {
 
       foreach($pictures as $picture) {
 
 
       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;
          } 
          if($current_tags != "") {
             $orig_url.= "&tags=". $current_tags;
          } 
@@ -2344,7 +2354,13 @@ class PHPFSPOT {
 
          $details = $this->get_photo_details($picture);
 
 
          $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("
 <a href=\"". $orig_url ."\"><img src=\"". $thumb_url ."\" /></a>
 <br>
          $thumb_html = htmlspecialchars("
 <a href=\"". $orig_url ."\"><img src=\"". $thumb_url ."\" /></a>
 <br>
@@ -2527,7 +2543,11 @@ class PHPFSPOT {
       else
          $_SESSION['slideshow_img']++;
 
       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()
 
 
    } // getNextSlideShowImage()
 
@@ -2547,7 +2567,11 @@ class PHPFSPOT {
       else
          $_SESSION['slideshow_img']--;
 
       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()
 
 
    } // getPrevSlideShowImage()
 
@@ -2747,7 +2771,16 @@ class PHPFSPOT {
     */
    private function get_phpfspot_url()
    {
     */
    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()
 
    /**
    } // get_phpfspot_url()
 
    /**
@@ -3062,7 +3095,10 @@ class PHPFSPOT {
 
    private function parse_user_friendly_url($request_uri)
    {
 
    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);
 
 
          $options = explode('/', $request_uri);
 
@@ -3083,11 +3119,36 @@ class PHPFSPOT {
                }
                exit;
                break;
                }
                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()
 
          }
       }
 
    } // 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
 
 
 } // class PHPFSPOT
 
index 6c0054dfe2f80cbd737f30b2be72a8a9b243f0d9..47ebe320d5e981b1990b0fb93269c9e0ad97ef1e 100644 (file)
@@ -373,6 +373,8 @@ function init_phpfspot(mode)
    /* ask the server what we are currently displaying */
    whattodo = AskServerWhatToDo();
 
    /* ask the server what we are currently displaying */
    whattodo = AskServerWhatToDo();
 
+   window.alert(whattodo);
+
    if(whattodo == 'showpi' || whattodo == 'showpi_date') {
       showPhotoIndex();
    }
    if(whattodo == 'showpi' || whattodo == 'showpi_date') {
       showPhotoIndex();
    }
diff --git a/rpc.php b/rpc.php
index 5ff334e02995b72e6c9de2e2d1fa35d82184245c..e2da768fc80751de41417aa854f953d66de4d9c9 100644 (file)
--- 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'];
 
             if(isset($_GET['last_photo']) && is_numeric($_GET['last_photo']))
                $_SESSION['last_photo'] = $_GET['last_photo'];
 
-            $phpfspot->showPhotoIndex();
+            return $phpfspot->showPhotoIndex();
             break;
    
          case 'showcredits':
             break;
    
          case 'showcredits':
index 04a35028c5b87ba62de84aebfed6b625f8dd1f62..85260536a5a63a67b5bc9b817f4ef5b30bf06339 100644 (file)
   {/if}
  </div>
  <div style="text-align: right;">
   {/if}
  </div>
  <div style="text-align: right;">
-  <a href="javascript:zoom(-10);" title="zoom_out" onclick="click(this);"><img src="resources/zoom-out.png" /></a>
-  <a href="javascript:zoom(0);" title="zoom_100" onclick="click(this);"><img src="resources/zoom-100.png" /></a>
-  <a href="javascript:zoom(10);" title="zoom_in" onclick="click(this);"><img src="resources/zoom-in.png" /></a>
+  <a href="javascript:zoom(-10);" title="zoom_out" onfocus="click(this);"><img src="resources/zoom-out.png" /></a>
+  <a href="javascript:zoom(0);" title="zoom_100" onfocus="click(this);"><img src="resources/zoom-100.png" /></a>
+  <a href="javascript:zoom(10);" title="zoom_in" onfocus="click(this);"><img src="resources/zoom-in.png" /></a>
  <a href="javascript:startAutoBrowse();" title="auto browsing"><img id="autobrowse_ico" src="resources/16_play.png" />&nbsp;Auto-Browse</a>
   {if $extern_link }
    <a href="{$extern_link}" title="Use this link to return to the current view"><img src="resources/link.png" />&nbsp;External Link</a>
   {/if}
  <a href="javascript:startAutoBrowse();" title="auto browsing"><img id="autobrowse_ico" src="resources/16_play.png" />&nbsp;Auto-Browse</a>
   {if $extern_link }
    <a href="{$extern_link}" title="Use this link to return to the current view"><img src="resources/link.png" />&nbsp;External Link</a>
   {/if}
-  <a href="{$image_url_full}" title="orig_image" target="_blank" onclick="click(this);"><img src="resources/original.png" alt="original resolution" />&nbsp;Fullsize</a>
+  <a href="{$image_url_full}" title="orig_image" target="_blank" onfocus="click(this);"><img src="resources/original.png" alt="original resolution" />&nbsp;Fullsize</a>
  </div>
 </div>
 
  </div>
 </div>
 
     <br />
     <u><img src="resources/small_available_tags.png" alt="available tags" />&nbsp;Tagged with:</u><br />
     { foreach from=$tags key=id item=name }
     <br />
     <u><img src="resources/small_available_tags.png" alt="available tags" />&nbsp;Tagged with:</u><br />
     { foreach from=$tags key=id item=name }
-    <a class="smalltag" href="javascript:Tags('add', '{$id}');" onclick="click(this);" onclick="click(this);">{$name}</a><br />
+    <a class="smalltag" href="javascript:Tags('add', '{$id}');" onfocus="click(this);">{$name}</a><br />
     { /foreach }
    { /if }
    <hr>
    { if $prev_img }
     <u><img src="resources/photo.png" alt="photo icon" />&nbsp;Previous:</u><br />
     { /foreach }
    { /if }
    <hr>
    { if $prev_img }
     <u><img src="resources/photo.png" alt="photo icon" />&nbsp;Previous:</u><br />
-    <a href="{$previous_url}" onclick="click(this);" id="prev_link">
+    <a href="{$previous_url}" onfocus="click(this);" id="prev_link">
      <img src="phpfspot_img.php?idx={$prev_img}&amp;width={$mini_width}" /><br />
     </a>
    { /if}
    { if $next_img }
     <u><img src="resources/photo.png" alt="photo icon" />&nbsp;Next:</u><br />
      <img src="phpfspot_img.php?idx={$prev_img}&amp;width={$mini_width}" /><br />
     </a>
    { /if}
    { if $next_img }
     <u><img src="resources/photo.png" alt="photo icon" />&nbsp;Next:</u><br />
-    <a href="{$next_url}" onclick="click(this);" id="next_link">
+    <a href="{$next_url}" onfocus="click(this);" id="next_link">
      <img src="phpfspot_img.php?idx={$next_img}&amp;width={$mini_width}" /><br />
     </a>
    { /if}
      <img src="phpfspot_img.php?idx={$next_img}&amp;width={$mini_width}" /><br />
     </a>
    { /if}
@@ -67,9 +67,9 @@
 
  <div style="text-align: left; margin-top: 20px; margin-left: 20px;">
  { if $next_url == "" }
 
  <div style="text-align: left; margin-top: 20px; margin-left: 20px;">
  { if $next_url == "" }
-  <a href="javascript:showPhotoIndex();" onclick="click(this);" name="photo">
+  <a href="{$image_url}" onclick="showPhotoIndex(); return false;" onfocus="click(this);" name="photo">
  { else }
  { else }
-  <a href="{$next_url}" onclick="click(this);" title="click for the next photo" name="photo">
+  <a href="{$image_url}" onclick="{$next_url}; return false;" onfocus="click(this);" title="click for the next photo" name="photo">
  { /if }
    <img src="{$image_url}" width="{$width}" height="{$height}" alt="{$image_filename}" name="photo" id="photo" />
   </a>
  { /if }
    <img src="{$image_url}" width="{$width}" height="{$height}" alt="{$image_filename}" name="photo" id="photo" />
   </a>
   { if $previous_url == "" }
    <img src="resources/arrow_left_gray.png" alt="first photo reached" />
   { else }
   { if $previous_url == "" }
    <img src="resources/arrow_left_gray.png" alt="first photo reached" />
   { else }
-   <a href="{$previous_url}" onclick="click(this);" title="click for the previous photo (left cursor)">
+   <a href="{$previous_url}" onfocus="click(this);" title="click for the previous photo (left cursor)">
     <img src="resources/arrow_left.png" alt="previous photo" />
    </a>
   { /if }
     <img src="resources/arrow_left.png" alt="previous photo" />
    </a>
   { /if }
-   <a href="javascript:showPhotoIndex({$current_page}, {$current_img});" onclick="click(this);" title="click to go back to the index">
+   <a href="javascript:showPhotoIndex({$current_page}, {$current_img});" onfocus="click(this);" title="click to go back to the index">
     <img src="resources/arrow_up.png" alt="photo index" />
    </a>
   { if $next_url == "" }
    <img src="resources/arrow_right_gray.png" alt="last photo reached" />
   { else }
     <img src="resources/arrow_up.png" alt="photo index" />
    </a>
   { if $next_url == "" }
    <img src="resources/arrow_right_gray.png" alt="last photo reached" />
   { else }
-   <a href="{$next_url}" onclick="click(this);" title="click for the next photo (right cursor)"> 
+   <a href="{$next_url}" onfocus="click(this);" title="click for the next photo (right cursor)">
     <img src="resources/arrow_right.png" alt="next photo" />
    </a>
   { /if}
     <img src="resources/arrow_right.png" alt="next photo" />
    </a>
   { /if}
index 326c09531449f650458da5aeb4414790801d24df..42a20ffb64a8a9c20090869a771e552e1668d90e 100644 (file)
@@ -8,4 +8,8 @@
  &nbsp;
  <input type="radio" name="condition" value="or" onclick="Tags('condition', this);" {if $current_condition == "or" } checked="checked" { /if } title="OR condition" />||
  <input type="radio" name="condition" value="and" onclick="Tags('condition', this);" {if $current_condition == "and" } checked="checked" { /if } title="AND condition" />&amp;&amp;
  &nbsp;
  <input type="radio" name="condition" value="or" onclick="Tags('condition', this);" {if $current_condition == "or" } checked="checked" { /if } title="OR condition" />||
  <input type="radio" name="condition" value="and" onclick="Tags('condition', this);" {if $current_condition == "and" } checked="checked" { /if } title="AND condition" />&amp;&amp;
-<div id="selected_tags">no tags selected</div>
+{ if $preset_selected_tags }
+ <div id="selected_tags">{ $preset_selected_tags }</div>
+{ else }
+ <div id="selected_tags">no tags selected</div>
+{ /if }