2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
2009-01-03 21:00:09 +00:00
|
|
|
/*
|
|
|
|
* DisplayingImageEvent:
|
|
|
|
* $image -- the image being displayed
|
|
|
|
* $page -- the page to display on
|
|
|
|
*
|
|
|
|
* Sent when an image is ready to display. Extensions who
|
|
|
|
* wish to appear on the "view" page should listen for this,
|
|
|
|
* which only appears when an image actually exists.
|
|
|
|
*/
|
|
|
|
class DisplayingImageEvent extends Event {
|
2009-01-22 13:42:44 +00:00
|
|
|
var $image, $page, $context;
|
2009-01-03 21:00:09 +00:00
|
|
|
|
2009-01-22 13:42:44 +00:00
|
|
|
public function __construct(RequestContext $context, Image $image) {
|
|
|
|
parent::__construct($context);
|
2009-01-03 21:00:09 +00:00
|
|
|
$this->image = $image;
|
2009-01-22 13:42:44 +00:00
|
|
|
$this->page = $context->page;
|
2009-01-03 21:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function get_image() {
|
|
|
|
return $this->image;
|
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
|
2007-11-14 10:11:56 +00:00
|
|
|
class ImageInfoBoxBuildingEvent extends Event {
|
|
|
|
var $parts = array();
|
|
|
|
var $image;
|
|
|
|
var $user;
|
|
|
|
|
2008-09-18 02:48:12 +00:00
|
|
|
public function ImageInfoBoxBuildingEvent(Image $image, User $user) {
|
2007-11-14 10:11:56 +00:00
|
|
|
$this->image = $image;
|
|
|
|
$this->user = $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function add_part($html, $position=50) {
|
|
|
|
while(isset($this->parts[$position])) $position++;
|
|
|
|
$this->parts[$position] = $html;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ImageInfoSetEvent extends Event {
|
2009-01-18 01:07:06 +00:00
|
|
|
var $image;
|
2007-11-14 10:11:56 +00:00
|
|
|
|
2009-01-18 01:07:06 +00:00
|
|
|
public function ImageInfoSetEvent($image) {
|
|
|
|
$this->image = $image;
|
2007-11-14 10:11:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-14 11:36:19 +00:00
|
|
|
class ImageAdminBlockBuildingEvent extends Event {
|
|
|
|
var $parts = array();
|
|
|
|
var $image = null;
|
|
|
|
var $user = null;
|
|
|
|
|
2008-09-18 02:48:12 +00:00
|
|
|
public function ImageAdminBlockBuildingEvent(Image $image, User $user) {
|
2008-06-14 11:36:19 +00:00
|
|
|
$this->image = $image;
|
|
|
|
$this->user = $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function add_part($html, $position=50) {
|
|
|
|
while(isset($this->parts[$position])) $position++;
|
|
|
|
$this->parts[$position] = $html;
|
|
|
|
}
|
|
|
|
}
|
2008-08-23 12:08:19 +00:00
|
|
|
class ViewImage implements Extension {
|
2007-07-16 13:15:56 +00:00
|
|
|
var $theme;
|
2007-07-16 14:35:49 +00:00
|
|
|
|
2008-08-23 12:08:19 +00:00
|
|
|
public function receive_event(Event $event) {
|
2008-09-06 16:59:02 +00:00
|
|
|
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
2007-07-16 13:15:56 +00:00
|
|
|
|
2008-09-06 17:48:03 +00:00
|
|
|
if(($event instanceof PageRequestEvent) && $event->page_matches("post/view")) {
|
|
|
|
$image_id = int_escape($event->get_arg(0));
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
global $database;
|
2008-10-09 03:21:18 +00:00
|
|
|
global $config;
|
|
|
|
$image = Image::by_id($config, $database, $image_id);
|
2007-04-16 11:58:25 +00:00
|
|
|
|
|
|
|
if(!is_null($image)) {
|
2009-01-22 13:42:44 +00:00
|
|
|
send_event(new DisplayingImageEvent($event->context, $image));
|
2008-06-14 11:36:19 +00:00
|
|
|
$iabbe = new ImageAdminBlockBuildingEvent($image, $event->user);
|
|
|
|
send_event($iabbe);
|
|
|
|
ksort($iabbe->parts);
|
|
|
|
$this->theme->display_admin_block($event->page, $iabbe->parts);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-07-28 20:30:01 +00:00
|
|
|
$this->theme->display_error($event->page, "Image not found", "No image in the database has the ID #$image_id");
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-06 17:48:03 +00:00
|
|
|
if(($event instanceof PageRequestEvent) && $event->page_matches("post/set")) {
|
2009-01-18 01:07:06 +00:00
|
|
|
global $config, $database;
|
2007-11-14 10:11:56 +00:00
|
|
|
$image_id = int_escape($_POST['image_id']);
|
|
|
|
|
2009-01-18 01:07:06 +00:00
|
|
|
send_event(new ImageInfoSetEvent(Image::by_id($config, $database, $image_id)));
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2007-11-14 10:11:56 +00:00
|
|
|
$query = $_POST['query'];
|
|
|
|
$event->page->set_mode("redirect");
|
|
|
|
$event->page->set_redirect(make_link("post/view/$image_id", $query));
|
|
|
|
}
|
|
|
|
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof DisplayingImageEvent) {
|
2008-02-06 17:33:08 +00:00
|
|
|
global $user;
|
|
|
|
$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
|
2007-11-14 10:11:56 +00:00
|
|
|
send_event($iibbe);
|
|
|
|
ksort($iibbe->parts);
|
|
|
|
$this->theme->display_page($event->page, $event->get_image(), $iibbe->parts);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_event_listener(new ViewImage());
|
|
|
|
?>
|