From b925062456f90ab0bc32a3f6063aca7295095bc6 Mon Sep 17 00:00:00 2001 From: jeroenrnl Date: Wed, 13 Apr 2016 22:57:43 +0200 Subject: [PATCH] Select a random photo from a configured album as logon background Issue #72 --- php/classes/album.inc.php | 13 +++++++++++++ php/classes/photo.inc.php | 13 +++++++++++++ php/image.php | 26 +++++++++++++++++--------- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/php/classes/album.inc.php b/php/classes/album.inc.php index 27c2445..647d759 100644 --- a/php/classes/album.inc.php +++ b/php/classes/album.inc.php @@ -284,6 +284,19 @@ public function getTotalPhotoCount() { return $qry->getCount(); } + /** + * Get the photos in this album + * Does NOT check user permissions! + */ + public function getPhotos() { + $qry=new select(array("pa" => "photo_albums")); + $qry->addFields(array("photo_id" => "pa.photo_id")); + $qry->where(new clause("pa.album_id = :alb_id")); + $qry->addParam(new param(":alb_id", $this->getId(), PDO::PARAM_INT)); + + return photo::getRecordsFromQuery($qry); + } + /** * Get array of fields/values to create an edit form * @return array fields/values diff --git a/php/classes/photo.inc.php b/php/classes/photo.inc.php index bd5ad2f..0cde9e9 100644 --- a/php/classes/photo.inc.php +++ b/php/classes/photo.inc.php @@ -137,6 +137,18 @@ public function lookup() { return $photo; } + /** + * Lookup a photo, ignoring access rights + */ + public function lookupAll() { + $qry = new select(array("p" => "photos")); + $qry->where(new clause("p.photo_id=:photoid")); + $qry->addParam(new param(":photoid", (int) $this->getId(), PDO::PARAM_INT)); + $photo = $this->lookupFromSQL($qry); + return $photo; + } + + /** * Lookup photographer of this photo */ @@ -1245,6 +1257,7 @@ public static function getByName($file, $path=null) { * @return string SHA1 hash */ private function getHashFromFile() { + $this->lookupAll(); $file=$this->getFilePath(); if (file_exists($file)) { return sha1_file($file); diff --git a/php/image.php b/php/image.php index 9154f2b..f0c88c1 100644 --- a/php/image.php +++ b/php/image.php @@ -75,15 +75,23 @@ $photo = new photo($photo_id); $found = $photo->lookup(); } else if ($type=="background") { - $templates=array( - conf::get("interface.template"), - "default" - ); - foreach ($templates as $template) { - $bgs=glob(settings::$php_loc . "/templates/" . $template . "/images/backgrounds/*.{jpg,JPG}", GLOB_BRACE); - if (sizeof($bgs) > 0) { - $image=$bgs[array_rand($bgs)]; - redirect("templates/" . $template . "/images/backgrounds/" . basename($image)); + if (conf::get("interface.logon.background.album")) { + $album=new album(conf::get("interface.logon.background.album")); + $photos=$album->getPhotos(); + $photo=$photos[array_rand($photos)]; + $photo->lookup(); + redirect("image.php?hash=" . $photo->getHash("full")); + } else { + $templates=array( + conf::get("interface.template"), + "default" + ); + foreach ($templates as $template) { + $bgs=glob(settings::$php_loc . "/templates/" . $template . "/images/backgrounds/*.{jpg,JPG}", GLOB_BRACE); + if (sizeof($bgs) > 0) { + $image=$bgs[array_rand($bgs)]; + redirect("templates/" . $template . "/images/backgrounds/" . basename($image)); + } } } exit;