issue118, first code for friendly looking URLs and new config-option $user_friendly_url
authorAndreas Unterkircher <unki@netshadow.at>
Fri, 2 May 2008 17:38:53 +0000 (19:38 +0200)
committerAndreas Unterkircher <unki@netshadow.at>
Sun, 4 May 2008 19:52:22 +0000 (21:52 +0200)
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
phpfspot.class.php
phpfspot_cfg.php.dist
rpc.php
themes/default/templates/index.tpl

index 094746c0bef16097794697aed7675794b650cafd..badc728980262accbed01b66789e88c5b4b4aec8 100644 (file)
@@ -244,6 +244,11 @@ class PHPFSPOT {
       $this->tmpl->assign('current_condition', $_SESSION['tag_condition']);
       $this->tmpl->assign('template_path', 'themes/'. $this->cfg->theme_name);
 
+      /* parse URL */
+      if(isset($this->cfg->user_friendly_url) && $this->cfg->user_friendly_url) {
+         $content = $this->parse_user_friendly_url($_SERVER['REQUEST_URI']);
+      }
+
       if(isset($_GET['mode'])) {
 
          $_SESSION['start_action'] = $_GET['mode'];
@@ -306,7 +311,12 @@ class PHPFSPOT {
       $this->tmpl->register_function("sort_select_list", array(&$this, "smarty_sort_select_list"), false);
       $this->tmpl->assign('from_date', $this->get_calendar('from'));
       $this->tmpl->assign('to_date', $this->get_calendar('to'));
-      $this->tmpl->assign('content_page', 'welcome.tpl');
+
+      if(!isset($content))
+         $this->tmpl->assign('content_page', $this->tmpl->fetch('welcome.tpl'));
+      else
+         $this->tmpl->assign('content_page', $content);
+
       $this->tmpl->show("index.tpl");
 
    } // show()
@@ -609,7 +619,11 @@ class PHPFSPOT {
       $this->tmpl->assign('ExifOrigResolution', $meta_res);
       $this->tmpl->assign('ExifFileSize', $meta_size);
  
-      $this->tmpl->assign('image_url', 'phpfspot_img.php?idx='. $photo ."&amp;width=". $this->cfg->photo_width);
+      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
+         $this->tmpl->assign('image_url', '/photo/'. $photo ."/". $this->cfg->photo_width);
+
       $this->tmpl->assign('image_url_full', 'phpfspot_img.php?idx='. $photo);
       $this->tmpl->assign('image_filename', $this->parse_uri($details['uri'], 'filename'));
 
@@ -631,7 +645,7 @@ class PHPFSPOT {
       $this->tmpl->assign('photo_number', $i);
       $this->tmpl->assign('photo_count', count($all_photos));
 
-      $this->tmpl->show("single_photo.tpl");
+      return $this->tmpl->fetch("single_photo.tpl");
 
    } // showPhoto()
 
@@ -3045,6 +3059,36 @@ class PHPFSPOT {
       
    } // get_tag_name()
 
+
+   private function parse_user_friendly_url($request_uri)
+   {
+      if(preg_match('/\/photoview\/|\/photo\//', $request_uri)) {
+
+         $options = explode('/', $request_uri);
+
+         switch($options[1]) {
+            case 'photoview':
+               if(is_numeric($options[2])) {
+                  return $this->showPhoto($options[2]);
+               }
+               break;
+            case 'photo':
+               if(is_numeric($options[2])) {
+                  require_once "phpfspot_img.php";
+                  $img = new PHPFSPOT_IMG;
+                  if(isset($options[3]) && is_numeric($options[3]))
+                     $img->showImg($options[2], $options[3]);
+                  else
+                     $img->showImg($options[2]);
+               }
+               exit;
+               break;
+         }
+      }
+
+   } // parse_user_friendly_url()
+
+
 } // class PHPFSPOT
 
 ?>
index 4eb5894fe4de1d04809f813972379204b0279ee8..3793c541414d7da39735a62937a24e3a4090a2fa 100644 (file)
@@ -116,6 +116,9 @@ class PHPFSPOT_CFG {
    /* path to dcraw to decode Nikon's NEF format */
    // var $dcraw_bin = "/usr/bin/dcraw";
 
+   /* user friendly URLs */
+   var $user_friendly_url = false;
+
    public function __construct()
    {
 
diff --git a/rpc.php b/rpc.php
index bdb62069eb11d7d6605f97f463b0d07c510b24d4..5ff334e02995b72e6c9de2e2d1fa35d82184245c 100644 (file)
--- a/rpc.php
+++ b/rpc.php
@@ -65,7 +65,7 @@ class PHPFSPOT_RPC {
       switch($action) {
          case 'showphoto':
             if(isset($_GET['id']) && is_numeric($_GET['id'])) {
-               $phpfspot->showPhoto($_GET['id']);
+               print $phpfspot->showPhoto($_GET['id']);
             }
             break;
    
index 0bd7a7bbd042352a18c438b2dc1922eaef3d67a9..59b4b5639fcfed6b7e42dc11f3cc72b8d25ee7ce 100644 (file)
@@ -39,7 +39,7 @@
 
   <!-- content column -->
   <div id="content" class="content">
-   {include file="welcome.tpl"}
+   { $content_page }
   </div>
   </span>