2013-03-10 06:00:24 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Name: Random List
|
|
|
|
* Author: Drudex Software <support@drudexsoftware.com>
|
|
|
|
* Link: http://www.drudexsoftware.com
|
|
|
|
* License: GPLv2
|
|
|
|
* Description: Allows displaying a page with random images
|
2013-03-10 07:43:50 +00:00
|
|
|
* Documentation:
|
|
|
|
* Random image list can be accessed through www.yoursite.com/random
|
|
|
|
* It is recommended that you create a link to this page so users know it exists.
|
2013-03-10 06:00:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class RandomList extends Extension {
|
|
|
|
public function onPageRequest(PageRequestEvent $event) {
|
2013-03-10 06:35:35 +00:00
|
|
|
global $config, $page;
|
2013-03-10 06:00:24 +00:00
|
|
|
|
2014-02-16 23:24:05 +00:00
|
|
|
if($event->page_matches("random")) {
|
2016-08-14 22:56:24 +00:00
|
|
|
if(isset($_GET['search'])) {
|
|
|
|
// implode(explode()) to resolve aliases and sanitise
|
|
|
|
$search = url_escape(Tag::implode(Tag::explode($_GET['search'], false)));
|
|
|
|
if(empty($search)) {
|
|
|
|
$page->set_mode("redirect");
|
|
|
|
$page->set_redirect(make_link("random"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$page->set_mode("redirect");
|
|
|
|
$page->set_redirect(make_link('random/'.$search));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($event->count_args() == 0) {
|
|
|
|
$search_terms = array();
|
|
|
|
}
|
|
|
|
else if($event->count_args() == 1) {
|
|
|
|
$search_terms = explode(' ', $event->get_arg(0));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new SCoreException("Error: too many arguments.");
|
|
|
|
}
|
|
|
|
|
2014-02-16 23:24:05 +00:00
|
|
|
// set vars
|
|
|
|
$images_per_page = $config->get_int("random_images_list_count", 12);
|
|
|
|
$random_images = array();
|
2013-03-10 06:00:24 +00:00
|
|
|
|
2014-02-16 23:24:05 +00:00
|
|
|
// generate random images
|
|
|
|
for ($i = 0; $i < $images_per_page; $i++)
|
2016-08-14 22:56:24 +00:00
|
|
|
array_push($random_images, Image::by_random($search_terms));
|
2014-02-16 23:24:05 +00:00
|
|
|
|
2016-08-14 22:56:24 +00:00
|
|
|
$this->theme->set_page($search_terms);
|
|
|
|
$this->theme->display_page($page, $random_images);
|
2013-03-10 06:35:35 +00:00
|
|
|
}
|
2013-03-10 06:00:24 +00:00
|
|
|
}
|
2014-02-16 23:24:05 +00:00
|
|
|
|
|
|
|
public function onInitExt(InitExtEvent $event) {
|
|
|
|
global $config;
|
|
|
|
$config->set_default_int("random_images_list_count", 12);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onSetupBuilding(SetupBuildingEvent $event) {
|
2013-03-10 07:43:50 +00:00
|
|
|
$sb = new SetupBlock("Random Images List");
|
2014-02-16 23:24:05 +00:00
|
|
|
|
|
|
|
// custom headers
|
2013-03-10 07:43:50 +00:00
|
|
|
$sb->add_int_option("random_images_list_count",
|
2014-02-16 23:24:05 +00:00
|
|
|
"Amount of Random images to display ");
|
2013-03-10 06:35:35 +00:00
|
|
|
|
2014-02-16 23:24:05 +00:00
|
|
|
$event->panel->add_block($sb);
|
2013-03-10 06:00:24 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-26 02:54:51 +00:00
|
|
|
|