* add option to control photo path-substituion, resolves #180
[phpfspot.git] / phpfspot.class.php
index b82efa55d3c9c8711811be3e33588d5da3823fd1..a5b4a4da7cfc045c89c87fa354ca689c6e952801 100644 (file)
@@ -213,6 +213,7 @@ class PHPFSPOT {
       require_once "phpfspot_tmpl.php";
       $this->tmpl = new PHPFSPOT_TMPL();
 
       require_once "phpfspot_tmpl.php";
       $this->tmpl = new PHPFSPOT_TMPL();
 
+      /* pre-set some template variables */
       $this->tmpl->assign('web_path', $this->cfg->web_path);
 
       /* Starting with F-Spot 0.4.2, the rating-feature was available */
       $this->tmpl->assign('web_path', $this->cfg->web_path);
 
       /* Starting with F-Spot 0.4.2, the rating-feature was available */
@@ -702,8 +703,13 @@ class PHPFSPOT {
     * @return string
     */
    public function translate_path($path)
     * @return string
     */
    public function translate_path($path)
-   {  
-      return str_replace($this->cfg->path_replace_from, $this->cfg->path_replace_to, $path);
+   {
+      if($this->cfg->enable_replace_path == true)
+         return str_replace(
+            $this->cfg->path_replace_from,
+            $this->cfg->path_replace_to, $path);
+
+      return $path;
 
    } // translate_path
 
 
    } // translate_path
 
@@ -1471,40 +1477,45 @@ class PHPFSPOT {
       }
 
       $thumbs = 0;
       }
 
       $thumbs = 0;
-      $images[$thumbs] = Array();
-      $img_height[$thumbs] = Array();
-      $img_width[$thumbs] = Array();
-      $img_id[$thumbs] = Array();
-      $img_name[$thumbs] = Array();
-      $img_fullname[$thumbs] = Array();
-      $img_title = Array();
-      $img_rating = Array();
 
       for($i = $begin_with; $i < $end_with; $i++) {
 
 
       for($i = $begin_with; $i < $end_with; $i++) {
 
-         if(isset($photos[$i])) {
+         if(!isset($photos[$i]))
+            continue;
 
 
-            $images[$thumbs] = $photos[$i];
-            $img_id[$thumbs] = $i;
-            $img_name[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 15));
-            $img_fullname[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 0));
-            $img_title[$thumbs] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0));
-            $img_rating[$thumbs] = $this->get_photo_rating($photos[$i]);
+         /* on first run, initalize all used variables */
+         if($thumbs == 0) {
+            $images = Array();
+            $images[$thumbs]        = Array();
+            $img_height[$thumbs]    = Array();
+            $img_width[$thumbs]     = Array();
+            $img_id[$thumbs]        = Array();
+            $img_name[$thumbs]      = Array();
+            $img_fullname[$thumbs]  = Array();
+            $img_title              = Array();
+            $img_rating             = Array();
+         }
+
+         $images[$thumbs] = $photos[$i];
+         $img_id[$thumbs] = $i;
+         $img_name[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 15));
+         $img_fullname[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 0));
+         $img_title[$thumbs] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0));
+         $img_rating[$thumbs] = $this->get_photo_rating($photos[$i]);
 
 
-            $thumb_path = $this->get_thumb_path($this->cfg->thumb_width, $photos[$i], $this->get_latest_version($photos[$i]));
+         /* get local path of the thumbnail image to be displayed */
+         $thumb_path = $this->get_thumb_path($this->cfg->thumb_width, $photos[$i], $this->get_latest_version($photos[$i]));
 
 
-            if(file_exists($thumb_path)) {
-               $info = getimagesize($thumb_path); 
+         /* if the image exist and is readable, extract some details */
+         if(file_exists($thumb_path) && is_readable($thumb_path)) {
+            if($info = getimagesize($thumb_path) !== false) {
                $img_width[$thumbs] = $info[0];
                $img_height[$thumbs] = $info[1];
             }
                $img_width[$thumbs] = $info[0];
                $img_height[$thumbs] = $info[1];
             }
-            $thumbs++;
-         } 
+         }
+         $thumbs++;
       }
 
       }
 
-      // +1 for for smarty's selection iteration
-      $thumbs++;
-
       if(isset($_SESSION['searchfor_tag']) && $_SESSION['searchfor_tag'] != '')
          $this->tmpl->assign('searchfor_tag', $_SESSION['searchfor_tag']);
 
       if(isset($_SESSION['searchfor_tag']) && $_SESSION['searchfor_tag'] != '')
          $this->tmpl->assign('searchfor_tag', $_SESSION['searchfor_tag']);
 
@@ -1629,16 +1640,20 @@ class PHPFSPOT {
       $this->tmpl->assign('preview_width', $this->cfg->photo_width);
       $this->tmpl->assign('thumb_container_width', $this->cfg->thumb_width);
       $this->tmpl->assign('thumb_container_height', $this->cfg->thumb_height+20);
       $this->tmpl->assign('preview_width', $this->cfg->photo_width);
       $this->tmpl->assign('thumb_container_width', $this->cfg->thumb_width);
       $this->tmpl->assign('thumb_container_height', $this->cfg->thumb_height+20);
-      $this->tmpl->assign('images', $images);
-      $this->tmpl->assign('img_width', $img_width);
-      $this->tmpl->assign('img_height', $img_height);
-      $this->tmpl->assign('img_id', $img_id);
-      $this->tmpl->assign('img_name', $img_name);
-      $this->tmpl->assign('img_fullname', $img_fullname);
-      $this->tmpl->assign('img_title', $img_title);
-      $this->tmpl->assign('img_rating', $img_rating);
-      $this->tmpl->assign('thumbs', $thumbs);
       $this->tmpl->assign('selected_tags', $this->getSelectedTags('img'));
       $this->tmpl->assign('selected_tags', $this->getSelectedTags('img'));
+      // +1 for for smarty's selection iteration
+      $this->tmpl->assign('thumbs', $thumbs+1);
+
+      if($thumbs > 0) {
+         $this->tmpl->assign('images', $images);
+         $this->tmpl->assign('img_width', $img_width);
+         $this->tmpl->assign('img_height', $img_height);
+         $this->tmpl->assign('img_id', $img_id);
+         $this->tmpl->assign('img_name', $img_name);
+         $this->tmpl->assign('img_fullname', $img_fullname);
+         $this->tmpl->assign('img_title', $img_title);
+         $this->tmpl->assign('img_rating', $img_rating);
+      }
 
       $result = $this->tmpl->fetch("photo_index.tpl");
 
 
       $result = $this->tmpl->fetch("photo_index.tpl");
 
@@ -2534,6 +2549,13 @@ class PHPFSPOT {
          $missing = true;
       }
 
          $missing = true;
       }
 
+      if($this->cfg->db_access == "pdo") {
+         if(array_search("sqlite", PDO::getAvailableDrivers()) === false) {
+            print "PDO SQLite3 driver is missing<br />\n";
+            $missing = true;
+         }
+      }
+
       /* Check for HTML_AJAX PEAR package, lent from Horde project */
       ini_set('track_errors', 1);
       @include_once 'HTML/AJAX/Server.php';
       /* Check for HTML_AJAX PEAR package, lent from Horde project */
       ini_set('track_errors', 1);
       @include_once 'HTML/AJAX/Server.php';
@@ -2551,6 +2573,11 @@ class PHPFSPOT {
          print "PEAR Console_Getopt package is missing<br />\n";
          $missing = true;
       }
          print "PEAR Console_Getopt package is missing<br />\n";
          $missing = true;
       }
+      @include_once 'Date.php';
+      if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
+         print "PEAR Date package is missing<br />\n";
+         $missing = true;
+      }
       @include_once $this->cfg->smarty_path .'/libs/Smarty.class.php';
       if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
          print "Smarty template engine can not be found in ". $this->cfg->smarty_path ."/libs/Smarty.class.php<br />\n";
       @include_once $this->cfg->smarty_path .'/libs/Smarty.class.php';
       if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) {
          print "Smarty template engine can not be found in ". $this->cfg->smarty_path ."/libs/Smarty.class.php<br />\n";
@@ -2655,11 +2682,22 @@ class PHPFSPOT {
     * @param integer $month
     * @param integer $day
     */
     * @param integer $month
     * @param integer $day
     */
-   public function get_calendar_matrix($year = 0, $month = 0, $day = 0)
+   public function get_calendar_matrix($userdate)
    {
    {
-      if (!isset($year)) $year = date('Y');
-      if (!isset($month)) $month = date('m');
-      if (!isset($day)) $day = date('d');
+      if(($userdate = strtotime($userdate)) === false) {
+         $year = date('Y');
+         $month = date('m');
+         $day = date('d');
+      }
+      else {
+         $date = new Date();
+         $date->setDate($userdate);
+
+         $year  = $date->getYear();
+         $month = $date->getMonth();
+         $day   = $date->getDay();
+      }
+
       $rows = 1;
       $cols = 1;
       $matrix = Array();
       $rows = 1;
       $cols = 1;
       $matrix = Array();
@@ -2668,27 +2706,26 @@ class PHPFSPOT {
       require_once CALENDAR_ROOT.'Day.php';
 
       // Build the month
       require_once CALENDAR_ROOT.'Day.php';
 
       // Build the month
-      $month = new Calendar_Month_Weekdays($year,$month);
+      $month_cal = new Calendar_Month_Weekdays($year,$month);
 
       // Create links
 
       // Create links
-      $prevStamp = $month->prevMonth(true);
+      $prevStamp = $month_cal->prevMonth(true);
       $prev = "javascript:setMonth(". date('Y',$prevStamp) .", ". date('n',$prevStamp) .", ". date('j',$prevStamp) .");";
       $prev = "javascript:setMonth(". date('Y',$prevStamp) .", ". date('n',$prevStamp) .", ". date('j',$prevStamp) .");";
-      $nextStamp = $month->nextMonth(true);
+      $nextStamp = $month_cal->nextMonth(true);
       $next = "javascript:setMonth(". date('Y',$nextStamp) .", ". date('n',$nextStamp) .", ". date('j',$nextStamp) .");";
 
       $selectedDays = array (
          new Calendar_Day($year,$month,$day),
       $next = "javascript:setMonth(". date('Y',$nextStamp) .", ". date('n',$nextStamp) .", ". date('j',$nextStamp) .");";
 
       $selectedDays = array (
          new Calendar_Day($year,$month,$day),
-         new Calendar_Day($year,12,25),
       );
 
       // Build the days in the month
       );
 
       // Build the days in the month
-      $month->build($selectedDays);
+      $month_cal->build($selectedDays);
 
 
-      $this->tmpl->assign('current_month', date('F Y',$month->getTimeStamp()));
+      $this->tmpl->assign('current_month', date('F Y',$month_cal->getTimeStamp()));
       $this->tmpl->assign('prev_month', $prev);
       $this->tmpl->assign('next_month', $next);
 
       $this->tmpl->assign('prev_month', $prev);
       $this->tmpl->assign('next_month', $next);
 
-      while ( $day = $month->fetch() ) {
+      while ( $day = $month_cal->fetch() ) {
    
          if(!isset($matrix[$rows]))
             $matrix[$rows] = Array();
    
          if(!isset($matrix[$rows]))
             $matrix[$rows] = Array();
@@ -2696,7 +2733,13 @@ class PHPFSPOT {
          $string = "";
 
          $dayStamp = $day->thisDay(true);
          $string = "";
 
          $dayStamp = $day->thisDay(true);
-         $link = "javascript:setCalendarDate(". date('Y',$dayStamp) .", ". date('n',$dayStamp).", ". date('j',$dayStamp) .");";
+         $link = "javascript:setCalendarDate('"
+            . date('Y',$dayStamp)
+            . "-"
+            . date('m',$dayStamp)
+            . "-"
+            . date('d',$dayStamp)
+            ."');";
 
          // isFirst() to find start of week
          if ( $day->isFirst() )
 
          // isFirst() to find start of week
          if ( $day->isFirst() )
@@ -3482,11 +3525,16 @@ class PHPFSPOT {
       if(!isset($this->cfg->thumbs_per_page))
          $this->_error("Please set \$thumbs_per_page in phpfspot_cfg");
 
       if(!isset($this->cfg->thumbs_per_page))
          $this->_error("Please set \$thumbs_per_page in phpfspot_cfg");
 
-      if(!isset($this->cfg->path_replace_from) || $this->cfg->path_replace_from == "")
-         $this->_error("Please set \$path_replace_from in phpfspot_cfg");
+      if(!isset($this->cfg->enable_replace_path))
+         $this->_error("Please set \$enable_replace_path in phpfspot_cfg");
+
+      if($this->cfg->enable_replace_path == true) {
+         if(!isset($this->cfg->path_replace_from) || $this->cfg->path_replace_from == "")
+            $this->_error("Please set \$path_replace_from in phpfspot_cfg");
 
 
-      if(!isset($this->cfg->path_replace_to) || $this->cfg->path_replace_to == "")
-         $this->_error("Please set \$path_replace_to in phpfspot_cfg");
+         if(!isset($this->cfg->path_replace_to) || $this->cfg->path_replace_to == "")
+            $this->_error("Please set \$path_replace_to in phpfspot_cfg");
+      }
 
       if(!isset($this->cfg->hide_tags))
          $this->_error("Please set \$hide_tags in phpfspot_cfg");
 
       if(!isset($this->cfg->hide_tags))
          $this->_error("Please set \$hide_tags in phpfspot_cfg");