* Link: http://www.drudexsoftware.com * License: GPLv2 * Description: Allows displaying a page with random images * Documentation: */ class RandomList extends Extension { public function onPageRequest(PageRequestEvent $event) { global $page; if($event->page_matches("random")) { $html = "Refresh the page to view more images
";
}
return $random_html;
}
/**
* Pick certain amount of random images random image out of a set
*
* @retval Image
*/
private function by_random($tags=array(), $amount=1) {
assert(is_array($tags));
$max = Image::count_images($tags);
if ($max < 1) return null; // From Issue #22 - opened by HungryFeline on May 30, 2011.
$rand = mt_rand(0, $max-1);
$set = Image::find_images($rand, $amount, $tags);
if(count($set) > 0)
{
if ($amount == 1) return $set[0]; // return as single image
else if ($amount > 1) return $set; // return as array
else return null;
}
else return null;
}
}
?>