issue55, PHPFSPOT_IMG can now display a random selected photo
authorAndreas Unterkircher <unki@netshadow.at>
Sat, 21 Jul 2007 14:43:41 +0000 (14:43 +0000)
committerAndreas Unterkircher <unki@netshadow.at>
Sat, 21 Jul 2007 14:43:41 +0000 (14:43 +0000)
git-svn-id: file:///var/lib/svn/phpfspot/trunk@232 fa6a889d-dae6-447d-9e79-4ba9a3039384

phpfspot.class.php
phpfspot_img.php

index 2df02508df014e28fee09c55c70d92c8d29678f4..ffb511d97361df9c475132a27bb0c9e4cc6d7f99 100644 (file)
@@ -1682,6 +1682,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()
+
 }
 
 ?>
index 194b534ba63e61d9258ea0a1ce621d35673581f4..a96d5e6f41c1d4ed86dd46933c36bdb9faf441e2 100644 (file)
@@ -56,6 +56,9 @@ class PHPFSPOT_IMG {
     */
    public function show($idx, $width = 0)
    {
+      if($idx == 'rand')
+         $idx = $this->parent->get_random_photo();
+
       $details = $this->parent->get_photo_details($idx);
    
       if(!$details) {
@@ -112,7 +115,7 @@ class PHPFSPOT_IMG {
 
 }
 
-if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {
+if(isset($_GET['idx']) && (is_numeric($_GET['idx']) || $_GET['idx'] == 'rand')) {
 
    $img = new PHPFSPOT_IMG;