issue118, jumpin to a specific starting point in the photo-index
[phpfspot.git] / phpfspot.class.php
index 8305ba5ba7289cddcc112d70f28065f542ed2da7..0e2ea44b7cd9ae92fcd8cbc04d13f2fced4f0228 100644 (file)
@@ -311,13 +311,20 @@ class PHPFSPOT {
          $this->tmpl->assign('date_search_enabled', true);
 
       $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('search_from_date', $this->get_calendar('from'));
+      $this->tmpl->assign('search_to_date', $this->get_calendar('to'));
 
-      if(!isset($content))
-         $this->tmpl->assign('content_page', $this->tmpl->fetch('welcome.tpl'));
+      $this->tmpl->assign('preset_selected_tags', $this->getSelectedTags());
+      $this->tmpl->assign('preset_available_tags', $this->getAvailableTags());
+
+      if(!isset($content)) {
+         if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags']))
+            $this->tmpl->assign('initial_content', $this->showPhotoIndex());
+         else
+            $this->tmpl->assign('initial_content', $this->tmpl->fetch('welcome.tpl'));
+      }
       else
-         $this->tmpl->assign('content_page', $content);
+         $this->tmpl->assign('initial_content', $content);
 
       $this->tmpl->show("index.tpl");
 
@@ -727,13 +734,15 @@ class PHPFSPOT {
          $b = '88';
 
          if(isset($this->tags[$key])) {
-            $output.= "<a href=\"javascript:Tags('add', ". $key .");\" class=\"tag\" style=\"font-size: ". $size ."%; color: #". $r.$g.$b .";\">". $this->tags[$key] ."</a>, ";
+            if($this->is_user_friendly_url())
+               $output.= "<a href=\"". $this->cfg->web_path ."/tag/". $key ."\" onclick=\"Tags('add', ". $key ."); return false;\" class=\"tag\" style=\"font-size: ". $size ."%; color: #". $r.$g.$b .";\">". $this->tags[$key] ."</a>, ";
+            else
+               $output.= "<a href=\"". $this->cfg->web_path ."/index.php?mode=showpi\" onclick=\"Tags('add', ". $key ."); return false;\" class=\"tag\" style=\"font-size: ". $size ."%; color: #". $r.$g.$b .";\">". $this->tags[$key] ."</a>, ";
          }
-
       }
 
       $output = substr($output, 0, strlen($output)-2);
-      print $output;
+      return $output;
 
    } // getAvailableTags()
 
@@ -767,12 +776,12 @@ class PHPFSPOT {
                   <div style=\"display: table-cell;\">
                    <div style=\"display: table-row; text-align: center;\">
                     <a href=\"javascript:Tags('del', ". $tag .");\" title=\"". $this->tags[$tag] ."\">
-                     <img src=\"phpfspot_img.php?tagidx=". $tag ."\" />
+                     <img src=\"". $this->cfg->web_path ."/phpfspot_img.php?tagidx=". $tag ."\" />
                     </a>
                    </div>
                    <div style=\"display: table-row; text-align: center;\">
                     <a href=\"javascript:Tags('del', ". $tag .");\" title=\"". $this->tags[$tag] ."\">
-                     <img src=\"resources/underbar.png\" />
+                     <img src=\"". $this->cfg->web_path ."/resources/underbar.png\" />
                     </a>
                    </div>
                   </div>
@@ -1173,6 +1182,7 @@ class PHPFSPOT {
     *
     * this function provides all the necessary information
     * for the photo index template.
+    * @return string
     */
    public function showPhotoIndex()
    {
@@ -1284,7 +1294,16 @@ class PHPFSPOT {
             else
                $style = "";
 
-            $select = "<a href=\"javascript:showPhotoIndex(". (($i*$photo_per_page)-$photo_per_page) .");\"";
+            $start_with = ($i*$photo_per_page)-$photo_per_page;
+
+            if($this->is_user_friendly_url()) {
+               $select = "<a href=\"". $this->cfg->web_path ."/tag/205/". $start_with ."\"";
+            }
+            else {
+               $select = "<a href=\"". $this->cfg->web_path ."/index.php?mode=showpi&nbsp;tags=". $current_tags ."&nbsp;begin_with=". $begin_with ."\"";
+            }
+            $select.= " onclick=\"showPhotoIndex(". $start_with ."); return false;\"";
+
                if($style != "")
                   $select.= $style;
             $select.= ">". $i ."</a>&nbsp;";
@@ -1322,7 +1341,6 @@ class PHPFSPOT {
          if($last_page > 1)
             $this->tmpl->assign('page_selector', $page_select);
       }
-
       
       $current_tags = $this->getCurrentTags();
       $extern_link = "index.php?mode=showpi";
@@ -2701,7 +2719,9 @@ class PHPFSPOT {
     */
    private function ts2str($timestamp)
    {
-      return strftime("%Y-%m-%d", $timestamp);
+      if(!empty($timestamp) && is_numeric($timestamp))
+         return strftime("%Y-%m-%d", $timestamp);
+
    } // ts2str()
 
    /**
@@ -3119,10 +3139,11 @@ class PHPFSPOT {
                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());
+                  $this->session_cleanup();
                   $_GET['tags'] = $options[2];
+                  $_SESSION['selected_tags'] = Array($options[2]);
+                  if(isset($options[3]) && is_numeric($options[3]))
+                     $_SESSION['begin_with'] = $options[3];
                   return $this->showPhotoIndex();
                }
                break;
@@ -3147,6 +3168,21 @@ class PHPFSPOT {
 
    } // is_user_friendly_url()
 
+   /**
+    * session cleanup
+    *
+    * this function will cleanup user's session information
+    */
+   private function session_cleanup()
+   {
+      unset($_SESSION['begin_with']);
+      $this->resetDateSearch();
+      $this->resetPhotoView();
+      $this->resetTagSearch();
+      $this->resetNameSearch();
+      $this->resetDateSearch();
+
+   } // session_cleanup()
 
 } // class PHPFSPOT