2008-05-19 03:30:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: Random Image
|
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* License: GPLv2
|
|
|
|
* Description: Do things with a random image
|
2008-05-28 22:36:39 +00:00
|
|
|
* Link: http://trac.shishnet.org/shimmie2/wiki/Contrib/Extensions/RandomImage
|
2008-05-19 03:30:56 +00:00
|
|
|
*/
|
|
|
|
|
2008-08-23 12:08:19 +00:00
|
|
|
class RandomImage implements Extension {
|
|
|
|
public function receive_event(Event $event) {
|
2008-08-22 09:41:30 +00:00
|
|
|
if(($event instanceof PageRequestEvent) && ($event->page_name == "random_image")) {
|
2008-05-19 03:30:56 +00:00
|
|
|
global $database;
|
|
|
|
|
|
|
|
if($event->count_args() == 1) {
|
|
|
|
$action = $event->get_arg(0);
|
|
|
|
$search_terms = array();
|
|
|
|
}
|
|
|
|
else if($event->count_args() == 2) {
|
|
|
|
$action = $event->get_arg(0);
|
|
|
|
$search_terms = explode(' ', $event->get_arg(1));
|
|
|
|
}
|
|
|
|
$image = $database->get_random_image($search_terms);
|
|
|
|
|
|
|
|
if($event->get_arg(0) == "download") {
|
|
|
|
if(!is_null($image)) {
|
|
|
|
$event->page->set_mode("data");
|
|
|
|
$event->page->set_type("image/jpeg");
|
|
|
|
$event->page->set_data(file_get_contents($image->get_image_filename()));
|
|
|
|
}
|
|
|
|
}
|
2008-06-09 11:21:44 +00:00
|
|
|
if($event->get_arg(0) == "view") {
|
|
|
|
if(!is_null($image)) {
|
|
|
|
send_event(new DisplayingImageEvent($image, $event->page));
|
|
|
|
}
|
|
|
|
}
|
2008-05-19 03:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_event_listener(new RandomImage());
|
|
|
|
?>
|