issue67, when called from an external link, also check the consider-date-search-box...
[phpfspot.git] / phpfspot.class.php
index ffb511d97361df9c475132a27bb0c9e4cc6d7f99..9d3f548a2f38e7d714687e9cbabf0c52375aa598 100644 (file)
@@ -58,8 +58,13 @@ class PHPFSPOT {
       }
          
       $this->cfg_db = new PHPFSPOT_DB(&$this, $this->cfg->phpfspot_db);
+      if(!is_writeable($this->cfg->phpfspot_db)) {
+         print $this->cfg->phpfspot_db ." is not writeable for user ". $this->getuid() ."\n";
+         exit(1);
+      }
       $this->check_config_table();
 
+
       $this->tmpl = new PHPFSPOT_TMPL($this);
 
       $this->get_tags();
@@ -100,6 +105,7 @@ class PHPFSPOT {
       $this->tmpl->assign('searchfor', $_SESSION['searchfor']);
       $this->tmpl->assign('page_title', $this->cfg->page_title);
       $this->tmpl->assign('current_condition', $_SESSION['tag_condition']);
+      $this->tmpl->assign('template_path', 'themes/'. $this->cfg->theme_name);
 
       $_SESSION['start_action'] = $_GET['mode'];
 
@@ -141,6 +147,9 @@ class PHPFSPOT {
             break;
       }
 
+      if(isset($_SESSION['from_date']) && isset($_SESSION['to_date']))
+       $this->tmpl->assign('date_search_enabled', true);
+
       $this->tmpl->assign('from_date', $this->get_calendar('from'));
       $this->tmpl->assign('to_date', $this->get_calendar('to'));
       $this->tmpl->assign('sort_field', $this->get_sort_field());
@@ -287,11 +296,11 @@ class PHPFSPOT {
       $thumb_path = $this->cfg->base_path ."/thumbs/". $this->cfg->photo_width ."_". $this->getMD5($photo);
 
       if(!file_exists($orig_path)) {
-         $this->_warning("Photo ". $orig_path ." does not exist!<br />\n");
+         $this->_error("Photo ". $orig_path ." does not exist!<br />\n");
       }
 
       if(!is_readable($orig_path)) {
-         $this->_warning("Photo ". $orig_path ." is not readable for user ". $this->getuid() ."<br />\n");
+         $this->_error("Photo ". $orig_path ." is not readable for user ". $this->getuid() ."<br />\n");
       }
 
       /* If the thumbnail doesn't exist yet, try to create it */
@@ -347,7 +356,7 @@ class PHPFSPOT {
          $this->tmpl->assign('current', $current);
       }
       else {
-         $this->_warning("Can't open file ". $thumb_path ."\n");
+         $this->_error("Can't open file ". $thumb_path ."\n");
          return;
       }
 
@@ -558,8 +567,8 @@ class PHPFSPOT {
       $matched_photos = Array();
 
       if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
-         $from_date = strtotime($_SESSION['from_date']);
-         $to_date = strtotime($_SESSION['to_date']);
+         $from_date = strtotime($_SESSION['from_date'] ." 00:00:00");
+         $to_date = strtotime($_SESSION['to_date'] ." 23:59:59");
          $additional_where_cond = "
                p.time>='". $from_date ."'
             AND
@@ -812,7 +821,7 @@ class PHPFSPOT {
          for($i = 1; $i <= $last_page; $i++) {
 
             if($current_page == $i)
-               $style = "style=\"font-size: 125%;\"";
+               $style = "style=\"font-size: 125%; text-decoration: underline;\"";
             elseif($current_page-1 == $i || $current_page+1 == $i)
                $style = "style=\"font-size: 105%;\"";
             elseif(($current_page-5 >= $i) && ($i != 1) ||
@@ -1106,12 +1115,12 @@ class PHPFSPOT {
       $full_path = $this->translate_path($details['directory_path'])  ."/". $details['name'];
 
       if(!file_exists($full_path)) {
-         $this->_warning("File ". $full_path ." does not exist\n");
+         $this->_error("File ". $full_path ." does not exist\n");
          return;
       }
 
       if(!is_readable($full_path)) {
-         $this->_warning("File ". $full_path ." is not readable for ". $this->getuid() ."\n");
+         $this->_error("File ". $full_path ." is not readable for ". $this->getuid() ."\n");
          return;
       }
 
@@ -1405,12 +1414,22 @@ class PHPFSPOT {
 
    } // checkifImageSupported()
 
-   public function _warning($text)
+   public function _error($text)
    {
-      print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";
-      print $text;
+      switch($this->cfg->logging) {
+         case 'display':
+            print "<img src=\"resources/green_info.png\" alt=\"warning\" />\n";
+            print $text;
+            break;
+         case 'errorlog':  
+            error_log($text);
+            break;
+         case 'logfile':
+            error_log($text, 3, $his->cfg->log_file);
+            break;
+      }
 
-   } // _warning()
+   } // _error()
 
    /**
     * output calendard input fields
@@ -1545,8 +1564,13 @@ class PHPFSPOT {
                break;
                
             case 'MoinMoin':
-               // [%pictureurl% %thumbnailurl%]
-               print htmlspecialchars(" * [".$orig_url." ".$thumb_url."&fake=1.jpg]") ."<br />\n";
+               // "[%pictureurl% %thumbnailurl%]"
+               print htmlspecialchars("[".$orig_url." ".$thumb_url."&fake=1.jpg]") ."<br />\n";
+               break;
+
+            case 'MoinMoinList':
+               // " * [%pictureurl% %thumbnailurl%]"
+               print "&nbsp;" . htmlspecialchars("* [".$orig_url." ".$thumb_url."&fake=1.jpg]") ."<br />\n";
                break;
          }
 
@@ -1660,6 +1684,12 @@ class PHPFSPOT {
 
    } // get_sort_order()
 
+   /***
+     * return the next to be shown slide show image
+     *
+     * this function returns the URL of the next image
+     * in the slideshow sequence.
+     */
    public function getNextSlideShowImage()
    {
       $all_photos = $this->getPhotoSelection();
@@ -1677,6 +1707,29 @@ class PHPFSPOT {
 
    } // getNextSlideShowImage()
 
+   /***
+     * return the previous to be shown slide show image
+     *
+     * this function returns the URL of the previous image
+     * in the slideshow sequence.
+     */
+   public function getPrevSlideShowImage()
+   {
+      $all_photos = $this->getPhotoSelection();
+
+      if(!isset($_SESSION['slideshow_img']) || $_SESSION['slideshow_img'] == 0)
+         $_SESSION['slideshow_img'] = 0;
+      else
+         $_SESSION['slideshow_img']--;
+
+      $server_name = $_SERVER['SERVER_NAME'];
+      if(!isset($_SERVER['HTTPS'])) $protocol = "http";
+      else $protocol = "https";
+
+      return $protocol ."://". $server_name . $this->cfg->web_path ."phpfspot_img.php?idx=". $all_photos[$_SESSION['slideshow_img']] ."&width=". $this->cfg->photo_width;
+
+   } // getPrevSlideShowImage()
+
    public function resetSlideShow()
    {
       if(isset($_SESSION['slideshow_img']))
@@ -1703,10 +1756,10 @@ class PHPFSPOT {
       ");
       
       while($row = $this->db->db_fetch_object($result)) {
-         array_push($all, $row[0]);
+         array_push($all, $row['id']);
       }
 
-      return array_rand($all);
+      return $all[array_rand($all)];
 
    } // get_random_photo()