Recent Image Patch for Random Block.

Sytone
Sytone's picture

Joined: 2002-11-11
Posts: 16
Posted: Wed, 2002-11-13 16:56

This now returns a random recent image :smile:

<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
function chooseAlbum() {
global $cache;

/*
* The odds that an album will be selected is proportional
* to the number of (visible) items in the album.
*/

$total = 0;
foreach ($cache as $name => $count) {
$album = new Album();
$album->load($name);
$time = $album->fields["last_mod_time"];
if ($time > $curdate &amp;&amp; rand(1,3) == 2) {
$choose = $name;
$curdate = $time;
}

}

if ($choose) {
$album = new Album();
$album->load($choose);
return $album;
} else {
return null;
}
}
</TD></TR></TABLE><!-- BBCode End -->