Amount of randoms displayed = images per page / 2
This commit is contained in:
parent
fccd5d249d
commit
8251133270
@ -10,66 +10,41 @@
|
|||||||
|
|
||||||
class RandomList extends Extension {
|
class RandomList extends Extension {
|
||||||
public function onPageRequest(PageRequestEvent $event) {
|
public function onPageRequest(PageRequestEvent $event) {
|
||||||
global $page;
|
global $config, $page;
|
||||||
|
|
||||||
|
if($event->page_matches("random")) {
|
||||||
|
// set vars
|
||||||
|
$images_per_page = $config->get_int("index_images") / 2;
|
||||||
|
$random_images = array();
|
||||||
|
$random_html = "<b>Refresh the page to view more images</b>
|
||||||
|
<div class='shm-image-list'>";
|
||||||
|
|
||||||
if($event->page_matches("random")) {
|
// generate random images
|
||||||
$html = "<b>Refresh the page to view more images</b>
|
for ($i = 0; $i < $images_per_page; $i++)
|
||||||
<div class='shm-image-list'>";
|
array_push($random_images, Image::by_random());
|
||||||
|
|
||||||
// create html to display images
|
// create html to display images
|
||||||
$html .= $this->build_random_html();
|
foreach ($random_images as $image)
|
||||||
|
$random_html .= $this->build_random_html($image);
|
||||||
// display it
|
|
||||||
$html .= "</div>";
|
// display it
|
||||||
$page->add_block(new Block("Random Images", $html));
|
$random_html .= "</div>";
|
||||||
}
|
$page->add_block(new Block("Random Images", $random_html));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function build_random_html() {
|
private function build_random_html(Image $image, $query=null) {
|
||||||
global $config;
|
|
||||||
|
|
||||||
$random_html = "";
|
|
||||||
$images_per_page = $config->get_int("index_images");
|
|
||||||
$random_images = $this->by_random(array(), $images_per_page);
|
|
||||||
|
|
||||||
var_dump($images_per_page);
|
|
||||||
var_dump($random_images);
|
|
||||||
|
|
||||||
foreach ($random_images as $image) {
|
|
||||||
$i_id = int_escape($image->id);
|
$i_id = int_escape($image->id);
|
||||||
$h_view_link = make_link("post/view/$i_id");
|
$h_view_link = make_link("post/view/$i_id", $query);
|
||||||
$h_thumb_link = $image->get_thumb_link();
|
$h_thumb_link = $image->get_thumb_link();
|
||||||
$h_tip = html_escape($image->get_tooltip());
|
$h_tip = html_escape($image->get_tooltip());
|
||||||
$tsize = get_thumbnail_size($image->width, $image->height);
|
$tsize = get_thumbnail_size($image->width, $image->height);
|
||||||
|
|
||||||
$random_html .= "
|
return "
|
||||||
<a href='$h_view_link' class='thumb shm-thumb' data-post-id='$i_id'>
|
<a href='$h_view_link' class='thumb shm-thumb' data-post-id='$i_id'>
|
||||||
<img id='thumb_$i_id' height='{$tsize[1]}' width='{$tsize[0]}' class='lazy' data-original='$h_thumb_link' src='/lib/static/grey.gif'><noscript>
|
<img id='thumb_$i_id' height='{$tsize[1]}' width='{$tsize[0]}' class='lazy' data-original='$h_thumb_link' src='/lib/static/grey.gif'><noscript>
|
||||||
<img id='thumb_$i_id' height='{$tsize[1]} width='{$tsize[0]} src='$h_thumb_link'></noscript></a>
|
<img id='thumb_$i_id' height='{$tsize[1]} width='{$tsize[0]} src='$h_thumb_link'></noscript></a>
|
||||||
";
|
";
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user