issue118, user-friendly-url to directly address a photo or a photo-view
[phpfspot.git] / phpfspot.class.php
index badc728980262accbed01b66789e88c5b4b4aec8..99b0d7b9fe1c767837205385d901ed421d2e5d7d 100644 (file)
@@ -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 "<script language=\"JavaScript\">moveToThumb(". $_SESSION['last_photo'] .");</script>\n";
+         $result.= "<script language=\"JavaScript\">moveToThumb(". $_SESSION['last_photo'] .");</script>\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("
 <a href=\"". $orig_url ."\"><img src=\"". $thumb_url ."\" /></a>
 <br>
@@ -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