This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/view/main.php

145 lines
3.6 KiB
PHP
Raw Normal View History

<?php
2010-01-05 10:11:53 +00:00
/*
* Name: Image Viewer
* Author: Shish
* Description: Allows users too see uploaded images
*/
/*
* 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;
public function __construct(Image $image) {
$this->image = $image;
}
public function get_image() {
return $this->image;
}
}
class ImageInfoBoxBuildingEvent extends Event {
var $parts = array();
var $image;
var $user;
public function ImageInfoBoxBuildingEvent(Image $image, User $user) {
$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;
2009-01-18 01:07:06 +00:00
public function ImageInfoSetEvent($image) {
$this->image = $image;
}
}
class ImageAdminBlockBuildingEvent extends Event {
var $parts = array();
var $image = null;
var $user = null;
public function ImageAdminBlockBuildingEvent(Image $image, User $user) {
$this->image = $image;
$this->user = $user;
}
public function add_part($html, $position=50) {
while(isset($this->parts[$position])) $position++;
$this->parts[$position] = $html;
}
}
2009-05-11 21:09:24 +00:00
class ViewImage implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(is_a($event, 'PageRequestEvent') && (
$event->page_matches("post/prev") ||
$event->page_matches("post/next")
)) {
$image_id = int_escape($event->get_arg(0));
if(isset($_GET['search'])) {
$search_terms = explode(' ', $_GET['search']);
$query = "search=".url_escape($_GET['search']);
}
else {
$search_terms = array();
$query = null;
}
$image = Image::by_id($image_id);
if($event->page_matches("post/next")) {
$image = $image->get_next($search_terms);
}
else {
$image = $image->get_prev($search_terms);
}
if(!is_null($image)) {
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/{$image->id}", $query));
}
else {
$this->theme->display_error($page, "Image not found", "No more images");
}
}
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
$image = Image::by_id($image_id);
if(!is_null($image)) {
send_event(new DisplayingImageEvent($image));
$iabbe = new ImageAdminBlockBuildingEvent($image, $user);
send_event($iabbe);
ksort($iabbe->parts);
$this->theme->display_admin_block($page, $iabbe->parts);
}
else {
$this->theme->display_error($page, "Image not found", "No image in the database has the ID #$image_id");
}
}
if(($event instanceof PageRequestEvent) && $event->page_matches("post/set")) {
$image_id = int_escape($_POST['image_id']);
send_event(new ImageInfoSetEvent(Image::by_id($image_id)));
2009-01-04 19:18:37 +00:00
$query = $_POST['query'];
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$image_id", $query));
}
if($event instanceof DisplayingImageEvent) {
$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
send_event($iibbe);
ksort($iibbe->parts);
$this->theme->display_page($page, $event->get_image(), $iibbe->parts);
}
}
}
add_event_listener(new ViewImage());
?>