Skip to content

Commit

Permalink
Select a random photo from a configured album as logon background
Browse files Browse the repository at this point in the history
Issue #72
  • Loading branch information
jeroenrnl committed Apr 13, 2016
1 parent 512d81d commit b925062
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
13 changes: 13 additions & 0 deletions php/classes/album.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions php/classes/photo.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 17 additions & 9 deletions php/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b925062

Please sign in to comment.