From 8f252df2825d2647bd4e3aed7ac1f2badb914c0c Mon Sep 17 00:00:00 2001 From: shish Date: Sat, 14 Jun 2008 11:36:19 +0000 Subject: [PATCH] merge image admin buttons into a single block git-svn-id: file:///home/shish/svn/shimmie2/trunk@897 7f39781d-f577-437e-ae19-be835c7a54ca --- contrib/featured/main.php | 7 +++---- contrib/featured/theme.php | 5 ++--- contrib/regen_thumb/main.php | 7 +++---- contrib/regen_thumb/theme.php | 5 ++--- ext/admin/main.php | 7 +++---- ext/admin/theme.php | 4 ++-- ext/view/main.php | 19 +++++++++++++++++++ ext/view/theme.php | 6 ++++++ 8 files changed, 40 insertions(+), 20 deletions(-) diff --git a/contrib/featured/main.php b/contrib/featured/main.php index ac521a2d..a429393e 100644 --- a/contrib/featured/main.php +++ b/contrib/featured/main.php @@ -49,10 +49,9 @@ class Featured extends Extension { } */ - if(is_a($event, 'DisplayingImageEvent')) { - global $user; - if($user->is_admin()) { - $this->theme->display_buttons($event->page, $event->image->id); + if(is_a($event, 'ImageAdminBlockBuildingEvent')) { + if($event->user->is_admin()) { + $event->add_part($this->theme->get_buttons_html($event->image->id)); } } } diff --git a/contrib/featured/theme.php b/contrib/featured/theme.php index dda394c3..b6f532af 100644 --- a/contrib/featured/theme.php +++ b/contrib/featured/theme.php @@ -8,14 +8,13 @@ class FeaturedTheme extends Themelet { $page->add_block(new Block("Featured Image", $this->build_thumb_html($image), "left", 3)); } - public function display_buttons($page, $image_id) { - $html = " + public function get_buttons_html($image_id) { + return "
"; - $page->add_block(new Block("Featured Image", $html, "left")); } } ?> diff --git a/contrib/regen_thumb/main.php b/contrib/regen_thumb/main.php index 9e6ded78..28bb22d3 100644 --- a/contrib/regen_thumb/main.php +++ b/contrib/regen_thumb/main.php @@ -22,10 +22,9 @@ class RegenThumb extends Extension { } } - if(is_a($event, 'DisplayingImageEvent')) { - global $user; - if($user->is_admin()) { - $this->theme->display_buttons($event->page, $event->image->id); + if(is_a($event, 'ImageAdminBlockBuildingEvent')) { + if($event->user->is_admin()) { + $event->add_part($this->theme->get_buttons_html($event->image->id)); } } } diff --git a/contrib/regen_thumb/theme.php b/contrib/regen_thumb/theme.php index d5af9a72..03ade603 100644 --- a/contrib/regen_thumb/theme.php +++ b/contrib/regen_thumb/theme.php @@ -4,14 +4,13 @@ class RegenThumbTheme extends Themelet { /* * Show a form which offers to regenerate the thumb of an image with ID #$image_id */ - public function display_buttons($page, $image_id) { - $html = " + public function get_buttons_html($image_id) { + return "
"; - $page->add_block(new Block("Regen Thumb", $html, "left")); } /* diff --git a/ext/admin/main.php b/ext/admin/main.php index f322d40b..908e8434 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -70,10 +70,9 @@ class AdminPage extends Extension { } } - if(is_a($event, 'DisplayingImageEvent')) { - global $user; - if($user->is_admin()) { - $this->theme->display_deleter($event->page, $event->image->id); + if(is_a($event, 'ImageAdminBlockBuildingEvent')) { + if($event->user->is_admin()) { + $event->add_part($this->theme->get_deleter_html($event->image->id)); } } diff --git a/ext/admin/theme.php b/ext/admin/theme.php index 950cf4b5..adc68c93 100644 --- a/ext/admin/theme.php +++ b/ext/admin/theme.php @@ -15,7 +15,7 @@ class AdminPageTheme extends Themelet { * * $image_id = the image to delete */ - public function display_deleter($page, $image_id) { + public function get_deleter_html($image_id) { $i_image_id = int_escape($image_id); $html = "
@@ -23,7 +23,7 @@ class AdminPageTheme extends Themelet {
"; - $page->add_block(new Block("Admin", $html, "left")); + return $html; } /* diff --git a/ext/view/main.php b/ext/view/main.php index 8f66f92b..4dfa6ccc 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -24,6 +24,21 @@ class ImageInfoSetEvent extends Event { } } +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; @@ -38,6 +53,10 @@ class ViewImage extends Extension { 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"); diff --git a/ext/view/theme.php b/ext/view/theme.php index 53cbe9bb..ba381451 100644 --- a/ext/view/theme.php +++ b/ext/view/theme.php @@ -12,6 +12,12 @@ class ViewTheme extends Themelet { $page->add_block(new Block(null, $this->build_pin($image->id), "main", 11)); } + public function display_admin_block($page, $parts) { + if(count($parts) > 0) { + $page->add_block(new Block("Image Admin", join("
", $parts), "left", 50)); + } + } + var $pin = null;