random image block
This commit is contained in:
parent
aca8a039e1
commit
8414082c8a
@ -8,7 +8,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class RandomImage implements Extension {
|
class RandomImage implements Extension {
|
||||||
|
var $theme;
|
||||||
|
|
||||||
public function receive_event(Event $event) {
|
public function receive_event(Event $event) {
|
||||||
|
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||||
|
|
||||||
if(($event instanceof PageRequestEvent) && $event->page_matches("random_image")) {
|
if(($event instanceof PageRequestEvent) && $event->page_matches("random_image")) {
|
||||||
global $config;
|
global $config;
|
||||||
global $database;
|
global $database;
|
||||||
@ -36,6 +40,22 @@ class RandomImage implements Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(($event instanceof SetupBuildingEvent)) {
|
||||||
|
$sb = new SetupBlock("Random Image");
|
||||||
|
$sb->add_bool_option("show_random_block", "Show Random Block: ");
|
||||||
|
$event->panel->add_block($sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($event instanceof PostListBuildingEvent) {
|
||||||
|
global $config, $database;
|
||||||
|
if($config->get_bool("show_random_block")) {
|
||||||
|
$image = Image::by_random($config, $database, $event->search_terms);
|
||||||
|
if(!is_null($image)) {
|
||||||
|
$this->theme->display_random($event->page, $image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_event_listener(new RandomImage());
|
add_event_listener(new RandomImage());
|
||||||
|
8
contrib/random_image/theme.php
Normal file
8
contrib/random_image/theme.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class RandomImageTheme extends Themelet {
|
||||||
|
public function display_random(Page $page, Image $image) {
|
||||||
|
$page->add_block(new Block("Random Image", $this->build_thumb_html($image), "left", 8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user