summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Unterkircher <unki@netshadow.at>2007-07-21 14:43:41 +0000
committerAndreas Unterkircher <unki@netshadow.at>2007-07-21 14:43:41 +0000
commit758887b79c875b31b86d427e27f515e2c3d2a257 (patch)
treef071048ed86b53d1e5383b6d312067351bfde14b
parent7cd411d39455615dbf2069cc7304ed68c8696636 (diff)
issue55, PHPFSPOT_IMG can now display a random selected photo
git-svn-id: file:///var/lib/svn/phpfspot/trunk@232 fa6a889d-dae6-447d-9e79-4ba9a3039384
-rw-r--r--phpfspot.class.php28
-rw-r--r--phpfspot_img.php5
2 files changed, 32 insertions, 1 deletions
diff --git a/phpfspot.class.php b/phpfspot.class.php
index 2df0250..ffb511d 100644
--- a/phpfspot.class.php
+++ b/phpfspot.class.php
@@ -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()
+
}
?>
diff --git a/phpfspot_img.php b/phpfspot_img.php
index 194b534..a96d5e6 100644
--- a/phpfspot_img.php
+++ b/phpfspot_img.php
@@ -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;