2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
2010-01-05 10:11:53 +00:00
|
|
|
/*
|
|
|
|
* Name: Image Viewer
|
|
|
|
* Author: Shish
|
2010-01-05 10:32:39 +00:00
|
|
|
* Description: Allows users to see uploaded images
|
2010-01-05 10:11:53 +00:00
|
|
|
*/
|
|
|
|
|
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-05-11 14:04:33 +00:00
|
|
|
public function __construct(Image $image) {
|
2009-01-03 21:00:09 +00:00
|
|
|
$this->image = $image;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2010-02-01 23:30:07 +00:00
|
|
|
public function ImageInfoSetEvent(Image $image) {
|
2009-01-18 01:07:06 +00:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2012-02-02 14:14:33 +00:00
|
|
|
public function add_part(/*string*/ $html, /*int*/ $position=50) {
|
2008-06-14 11:36:19 +00:00
|
|
|
while(isset($this->parts[$position])) $position++;
|
|
|
|
$this->parts[$position] = $html;
|
|
|
|
}
|
|
|
|
}
|
2009-05-11 21:09:24 +00:00
|
|
|
|
2012-02-08 12:07:01 +00:00
|
|
|
class ViewImage extends Extension {
|
2010-05-28 01:07:33 +00:00
|
|
|
public function onPageRequest(PageRequestEvent $event) {
|
2010-06-17 18:44:05 +00:00
|
|
|
global $page, $user;
|
2007-07-16 14:35:49 +00:00
|
|
|
|
2010-05-28 01:07:33 +00:00
|
|
|
if(
|
2009-04-21 22:02:23 +00:00
|
|
|
$event->page_matches("post/prev") ||
|
|
|
|
$event->page_matches("post/next")
|
2010-05-28 01:07:33 +00:00
|
|
|
) {
|
|
|
|
|
2009-04-21 22:02:23 +00:00
|
|
|
$image_id = int_escape($event->get_arg(0));
|
|
|
|
|
|
|
|
if(isset($_GET['search'])) {
|
|
|
|
$search_terms = explode(' ', $_GET['search']);
|
2010-02-09 10:08:08 +00:00
|
|
|
$query = "#search=".url_escape($_GET['search']);
|
2009-04-21 22:02:23 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$search_terms = array();
|
|
|
|
$query = null;
|
|
|
|
}
|
|
|
|
|
2009-05-11 14:04:33 +00:00
|
|
|
$image = Image::by_id($image_id);
|
2012-01-14 14:38:45 +00:00
|
|
|
if(is_null($image)) {
|
2012-02-16 15:37:05 +00:00
|
|
|
$this->theme->display_error(404, "Image not found", "Image $image_id could not be found");
|
2012-01-14 14:38:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-18 03:13:27 +00:00
|
|
|
|
2009-04-21 22:02:23 +00:00
|
|
|
if($event->page_matches("post/next")) {
|
|
|
|
$image = $image->get_next($search_terms);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$image = $image->get_prev($search_terms);
|
|
|
|
}
|
|
|
|
|
2012-01-18 03:13:27 +00:00
|
|
|
if(is_null($image)) {
|
2012-02-16 15:37:05 +00:00
|
|
|
$this->theme->display_error(404, "Image not found", "No more images");
|
2012-01-26 17:16:57 +00:00
|
|
|
return;
|
2009-04-21 22:02:23 +00:00
|
|
|
}
|
2012-01-18 03:13:27 +00:00
|
|
|
|
|
|
|
$page->set_mode("redirect");
|
|
|
|
$page->set_redirect(make_link("post/view/{$image->id}", $query));
|
2009-04-21 22:02:23 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 01:07:33 +00:00
|
|
|
if($event->page_matches("post/view")) {
|
2008-09-06 17:48:03 +00:00
|
|
|
$image_id = int_escape($event->get_arg(0));
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2009-05-11 14:04:33 +00:00
|
|
|
$image = Image::by_id($image_id);
|
2007-04-16 11:58:25 +00:00
|
|
|
|
|
|
|
if(!is_null($image)) {
|
2009-05-11 14:04:33 +00:00
|
|
|
send_event(new DisplayingImageEvent($image));
|
|
|
|
$iabbe = new ImageAdminBlockBuildingEvent($image, $user);
|
2008-06-14 11:36:19 +00:00
|
|
|
send_event($iabbe);
|
|
|
|
ksort($iabbe->parts);
|
2009-05-11 14:04:33 +00:00
|
|
|
$this->theme->display_admin_block($page, $iabbe->parts);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-02-16 15:37:05 +00:00
|
|
|
$this->theme->display_error(404, "Image not found", "No image in the database has the ID #$image_id");
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-28 01:07:33 +00:00
|
|
|
if($event->page_matches("post/set")) {
|
2012-01-26 15:16:52 +00:00
|
|
|
if(!isset($_POST['image_id'])) return;
|
|
|
|
|
2007-11-14 10:11:56 +00:00
|
|
|
$image_id = int_escape($_POST['image_id']);
|
|
|
|
|
2009-05-11 14:04:33 +00:00
|
|
|
send_event(new ImageInfoSetEvent(Image::by_id($image_id)));
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2009-05-11 14:04:33 +00:00
|
|
|
$page->set_mode("redirect");
|
2012-03-09 18:14:14 +00:00
|
|
|
$page->set_redirect(make_link("post/view/$image_id", url_escape(@$_POST['query'])));
|
2007-11-14 10:11:56 +00:00
|
|
|
}
|
2010-05-28 01:07:33 +00:00
|
|
|
}
|
2007-11-14 10:11:56 +00:00
|
|
|
|
2010-05-28 01:07:33 +00:00
|
|
|
public function onDisplayingImage(DisplayingImageEvent $event) {
|
2010-06-17 18:44:05 +00:00
|
|
|
global $user;
|
2010-05-28 01:07:33 +00:00
|
|
|
$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
|
|
|
|
send_event($iibbe);
|
|
|
|
ksort($iibbe->parts);
|
|
|
|
$this->theme->display_page($event->get_image(), $iibbe->parts);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|