page == "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));
}
else {
global $page;
$page->set_title("Image not found");
$page->set_heading("Image not found");
$page->add_side_block(new NavBlock(), 0);
$page->add_main_block(new Block("Image not found",
"No image in the database has the ID #$image_id"), 0);
}
}
if(is_a($event, 'DisplayingImageEvent')) {
$image = $event->get_image();
global $page;
$page->set_title("Image {$image->id}: ".$image->get_tag_list());
$page->set_heading($image->get_tag_list());
$page->add_side_block(new Block("Navigation", $this->build_navigation($image->id)), 0);
$page->add_main_block(new Block("Image", $this->build_image_view($image)), 0);
$page->add_main_block(new Block(null, $this->build_info($image)), 10);
}
if(is_a($event, 'SetupBuildingEvent')) {
$sb = new SetupBlock("View Options");
$sb->add_text_option("image_ilink", "Long link ");
$sb->add_text_option("image_slink", "
Short link ");
$sb->add_text_option("image_tlink", "
Thumbnail link ");
$event->panel->add_main_block($sb, 30);
}
if(is_a($event, 'ConfigSaveEvent')) {
$event->config->set_string_from_post("image_ilink");
$event->config->set_string_from_post("image_slink");
$event->config->set_string_from_post("image_tlink");
}
}
// }}}
// HTML {{{
var $pin = null;
private function build_pin($image_id) {
if(!is_null($this->pin)) {
return $this->pin;
}
global $database;
// $next_img = $database->db->GetOne("SELECT id FROM images WHERE id < ? ORDER BY id DESC", array($image_id));
// $prev_img = $database->db->GetOne("SELECT id FROM images WHERE id > ? ORDER BY id ASC ", array($image_id));
if(isset($_GET['search'])) {
$search_terms = explode(' ', $_GET['search']);
$query = "search=".html_escape($_GET['search']);
}
else {
$search_terms = array();
$query = null;
}
$next = $database->get_next_image($image_id, $search_terms);
$prev = $database->get_prev_image($image_id, $search_terms);
$h_prev = (!is_null($prev) ? "Prev" : "Prev");
$h_index = "Index";
$h_next = (!is_null($next) ? "Next" : "Next");
$this->pin = "$h_prev | $h_index | $h_next";
return $this->pin;
}
private function build_navigation($image_id) {
$h_pin = $this->build_pin($image_id);
$h_search = "
Link: "; } $html .= "
Uploaded by $h_owner"; $html .= "
".$this->build_pin($image->id); return $html; } // }}} } add_event_listener(new ViewImage()); ?>