issue118, first code for friendly looking URLs and new config-option $user_friendly_url
[phpfspot.git] / phpfspot.class.php
index 97deb968dacb5b6b98dd967d73a379480f4bf21d..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 ."&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 ."&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()
 
@@ -2620,12 +2634,12 @@ class PHPFSPOT {
             pt.tag_id LIKE '". $tagidx ."'
       ";
 
-      if(isset($this->cfg->show_tags) && !empty($this->cfg->show_tags)) {
+      /*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);
 
@@ -3004,7 +3018,7 @@ class PHPFSPOT {
     */
    public function get_mime_info($file)
    {
-      $details = getimagesize($orig_image);
+      $details = getimagesize($file);
 
       /* if getimagesize() returns empty, try at least to find out the
          mime type.
@@ -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
 
 ?>