issue61, theme support
[phpfspot.git] / phpfspot.class.php
index 25d144c2dcbe255b0cd7270b1090b13946d1c8a2..825f92d098d55a8e602ee8c16bd5cf027ac89b31 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();
@@ -145,6 +150,7 @@ class PHPFSPOT {
       $this->tmpl->assign('to_date', $this->get_calendar('to'));
       $this->tmpl->assign('sort_field', $this->get_sort_field());
       $this->tmpl->assign('content_page', 'welcome.tpl');
+      $this->tmpl->assign('template_path', 'themes/'. $this->cfg->theme_name);
       $this->tmpl->show("index.tpl");
 
 
@@ -361,6 +367,8 @@ class PHPFSPOT {
          $this->tmpl->assign('next_img', $next_img);
       }
       $this->tmpl->assign('mini_width', $this->cfg->mini_width);
+      $this->tmpl->assign('photo_number', $i);
+      $this->tmpl->assign('photo_count', count($all_photos));
 
       $this->tmpl->show("single_photo.tpl");
 
@@ -1680,6 +1688,34 @@ class PHPFSPOT {
       if(isset($_SESSION['slideshow_img']))
          unset($_SESSION['slideshow_img']);
    } // resetSlideShow()
+   
+   /***
+     * get random photo
+     *
+     * this function will get all photos from the fspot
+     * database and randomly return ONE entry
+     *
+     * saddly there is yet no sqlite3 function which returns
+     * the bulk result in array, so we have to fill up our
+     * own here.
+     */ 
+   public function get_random_photo()
+   {
+      $all = Array();
+
+      $result = $this->db->db_query("
+         SELECT id
+         FROM photos
+      ");
+      
+      while($row = $this->db->db_fetch_object($result)) {
+         array_push($all, $row[0]);
+      }
+
+      return array_rand($all);
+
+   } // get_random_photo()
+
 }
 
 ?>