/
main.php
86 lines (70 loc) · 2.31 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
class ImageInfoBoxBuildingEvent extends Event {
var $parts = array();
var $image;
var $user;
public function ImageInfoBoxBuildingEvent($image, $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 {
var $image_id;
public function ImageInfoSetEvent($image_id) {
$this->image_id = int_escape($image_id);
}
}
class ImageAdminBlockBuildingEvent extends Event {
var $parts = array();
var $image = null;
var $user = null;
public function ImageAdminBlockBuildingEvent($image, $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 ViewImage extends Extension {
var $theme;
public function receive_event($event) {
if(is_null($this->theme)) $this->theme = get_theme_object("view", "ViewTheme");
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "post") && ($event->get_arg(0) == "view")) {
$image_id = int_escape($event->get_arg(1));
global $database;
$image = $database->get_image($image_id);
if(!is_null($image)) {
send_event(new DisplayingImageEvent($image, $event->page));
$iabbe = new ImageAdminBlockBuildingEvent($image, $event->user);
send_event($iabbe);
ksort($iabbe->parts);
$this->theme->display_admin_block($event->page, $iabbe->parts);
}
else {
$this->theme->display_error($event->page, "Image not found", "No image in the database has the ID #$image_id");
}
}
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "post") && ($event->get_arg(0) == "set")) {
$image_id = int_escape($_POST['image_id']);
send_event(new ImageInfoSetEvent($image_id));
$query = $_POST['query'];
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/$image_id", $query));
}
if(is_a($event, 'DisplayingImageEvent')) {
global $user;
$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
send_event($iibbe);
ksort($iibbe->parts);
$this->theme->display_page($event->page, $event->get_image(), $iibbe->parts);
}
}
}
add_event_listener(new ViewImage());
?>