PSR-2. I'm not a huge fan, but ugly consistency beats no consistency...
This commit is contained in:
@ -20,60 +20,59 @@
|
||||
* <code>/random_image/download/size=1024x768+cute</code>
|
||||
*/
|
||||
|
||||
class RandomImage extends Extension {
|
||||
public function onPageRequest(PageRequestEvent $event) {
|
||||
global $page;
|
||||
class RandomImage extends Extension
|
||||
{
|
||||
public function onPageRequest(PageRequestEvent $event)
|
||||
{
|
||||
global $page;
|
||||
|
||||
if($event->page_matches("random_image")) {
|
||||
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));
|
||||
}
|
||||
else {
|
||||
throw new SCoreException("Error: too many arguments.");
|
||||
}
|
||||
$image = Image::by_random($search_terms);
|
||||
if ($event->page_matches("random_image")) {
|
||||
if ($event->count_args() == 1) {
|
||||
$action = $event->get_arg(0);
|
||||
$search_terms = [];
|
||||
} elseif ($event->count_args() == 2) {
|
||||
$action = $event->get_arg(0);
|
||||
$search_terms = explode(' ', $event->get_arg(1));
|
||||
} else {
|
||||
throw new SCoreException("Error: too many arguments.");
|
||||
}
|
||||
$image = Image::by_random($search_terms);
|
||||
|
||||
if($action === "download") {
|
||||
if(!is_null($image)) {
|
||||
$page->set_mode("data");
|
||||
$page->set_type($image->get_mime_type());
|
||||
$page->set_data(file_get_contents($image->get_image_filename()));
|
||||
}
|
||||
}
|
||||
else if($action === "view") {
|
||||
if(!is_null($image)) {
|
||||
send_event(new DisplayingImageEvent($image));
|
||||
}
|
||||
}
|
||||
else if($action === "widget") {
|
||||
if(!is_null($image)) {
|
||||
$page->set_mode("data");
|
||||
$page->set_type("text/html");
|
||||
$page->set_data($this->theme->build_thumb_html($image));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($action === "download") {
|
||||
if (!is_null($image)) {
|
||||
$page->set_mode("data");
|
||||
$page->set_type($image->get_mime_type());
|
||||
$page->set_data(file_get_contents($image->get_image_filename()));
|
||||
}
|
||||
} elseif ($action === "view") {
|
||||
if (!is_null($image)) {
|
||||
send_event(new DisplayingImageEvent($image));
|
||||
}
|
||||
} elseif ($action === "widget") {
|
||||
if (!is_null($image)) {
|
||||
$page->set_mode("data");
|
||||
$page->set_type("text/html");
|
||||
$page->set_data($this->theme->build_thumb_html($image));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function onSetupBuilding(SetupBuildingEvent $event) {
|
||||
$sb = new SetupBlock("Random Image");
|
||||
$sb->add_bool_option("show_random_block", "Show Random Block: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
public function onSetupBuilding(SetupBuildingEvent $event)
|
||||
{
|
||||
$sb = new SetupBlock("Random Image");
|
||||
$sb->add_bool_option("show_random_block", "Show Random Block: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onPostListBuilding(PostListBuildingEvent $event) {
|
||||
global $config, $page;
|
||||
if($config->get_bool("show_random_block")) {
|
||||
$image = Image::by_random($event->search_terms);
|
||||
if(!is_null($image)) {
|
||||
$this->theme->display_random($page, $image);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function onPostListBuilding(PostListBuildingEvent $event)
|
||||
{
|
||||
global $config, $page;
|
||||
if ($config->get_bool("show_random_block")) {
|
||||
$image = Image::by_random($event->search_terms);
|
||||
if (!is_null($image)) {
|
||||
$this->theme->display_random($page, $image);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user