From c6f0cc036df6a1306b03c987092197d8bab27111 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 22 Nov 2008 21:46:34 +0000 Subject: Move all block callbacks from View::block_type() to $theme->block_type() so that the themer has a consistent interface. Also added a bunch more callbacks and normalized the names so that the module author has plenty of options for where stuff gets put on the page. Especially renamed album/photo/sidebar to be album_blocks() photo_blocks() and sidebar_blocks() to make it clear that those are going to be larger content sections and not just basic insertion points. Used __call() to collapse all functions in the theme, which incidentally makes it trivially easy to add a new insertion point. --- core/libraries/MY_View.php | 54 --------------------------- core/libraries/Theme.php | 42 +++++++++++++++++++++ modules/carousel/helpers/carousel_block.php | 2 +- modules/gmaps/helpers/gmaps_block.php | 2 +- modules/info/helpers/info_block.php | 2 +- modules/slideshow/helpers/slideshow_block.php | 4 +- modules/tag/helpers/tag_block.php | 2 +- modules/user/helpers/user_block.php | 2 +- themes/default/views/album.html.php | 5 ++- themes/default/views/header.html.php | 4 +- themes/default/views/page.html.php | 6 ++- themes/default/views/photo.html.php | 4 +- themes/default/views/sidebar.html.php | 4 +- 13 files changed, 64 insertions(+), 69 deletions(-) diff --git a/core/libraries/MY_View.php b/core/libraries/MY_View.php index fe2ef12e..26326b5d 100644 --- a/core/libraries/MY_View.php +++ b/core/libraries/MY_View.php @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class View extends View_Core { - private static $block_helpers = null; - /** * Override View_Core::render so that we trap errors stemming from bad PHP includes and show a * visible stack trace to help developers. @@ -40,56 +38,4 @@ class View extends View_Core { return ""; } } - - public static function admin($theme) { - return self::_get_block_helpers("admin", $theme); - } - - public static function head($theme) { - return self::_get_block_helpers("head", $theme); - } - - public static function top($theme) { - return self::_get_block_helpers("top", $theme); - } - - public static function bottom($theme) { - return self::_get_block_helpers("bottom", $theme); - } - - public static function sidebar($theme) { - return self::_get_block_helpers("sidebar", $theme); - } - - public static function album($theme) { - return self::_get_block_helpers("album", $theme); - } - - public static function album_top($theme) { - return self::_get_block_helpers("album_top", $theme); - } - - public static function photo($theme) { - return self::_get_block_helpers("photo", $theme); - } - - private static function _get_block_helpers($method, $theme) { - if (empty(self::$block_helpers[$method])) { - foreach (module::get_list() as $module) { - $helper_path = MODPATH . "$module->name/helpers/{$module->name}_block.php"; - $helper_class = "{$module->name}_block"; - if (file_exists($helper_path) && method_exists($helper_class, $method)) { - self::$block_helpers[$method][] = "$helper_class"; - } - } - } - - $blocks = ""; - if (!empty(self::$block_helpers[$method])) { - foreach (self::$block_helpers[$method] as $helper_class) { - $blocks .= call_user_func_array(array($helper_class, $method), array($theme)) . "\n"; - } - } - return $blocks; - } } diff --git a/core/libraries/Theme.php b/core/libraries/Theme.php index f95ef569..d7790626 100644 --- a/core/libraries/Theme.php +++ b/core/libraries/Theme.php @@ -57,4 +57,46 @@ class Theme_Core { return new View("in_place_edit.html"); } + /** + * Handle all theme functions that insert module content. + */ + public function __call($function, $args) { + switch ($function) { + case "admin": + case "head": + case "page_top": + case "page_bottom": + case "header_top": + case "header_bottom": + case "sidebar_top": + case "sidebar_blocks": + case "sidebar_bottom": + case "album_top": + case "album_blocks": + case "album_bottom": + case "photo_top": + case "photo_blocks": + case "photo_bottom": + if (empty($this->block_helpers[$function])) { + foreach (module::get_list() as $module) { + $helper_path = MODPATH . "$module->name/helpers/{$module->name}_block.php"; + $helper_class = "{$module->name}_block"; + if (file_exists($helper_path) && method_exists($helper_class, $function)) { + $this->block_helpers[$function][] = "$helper_class"; + } + } + } + + $blocks = ""; + if (!empty($this->block_helpers[$function])) { + foreach ($this->block_helpers[$function] as $helper_class) { + $blocks .= call_user_func_array(array($helper_class, $function), array($this)) . "\n"; + } + } + return $blocks; + + default: + throw new Exception("@todo UNKNOWN_THEME_FUNCTION: $function"); + } + } } diff --git a/modules/carousel/helpers/carousel_block.php b/modules/carousel/helpers/carousel_block.php index f83a48da..a93cfef6 100644 --- a/modules/carousel/helpers/carousel_block.php +++ b/modules/carousel/helpers/carousel_block.php @@ -19,7 +19,7 @@ */ class carousel_block_Core { - public static function sidebar($theme) { + public static function sidebar_blocks($theme) { $block = new Block(); $block->id = "gCarousel"; $block->title = "Album: {$theme->item()->title_edit}"; diff --git a/modules/gmaps/helpers/gmaps_block.php b/modules/gmaps/helpers/gmaps_block.php index 1620e881..0d3155d1 100644 --- a/modules/gmaps/helpers/gmaps_block.php +++ b/modules/gmaps/helpers/gmaps_block.php @@ -19,7 +19,7 @@ */ class gmaps_block_Core { - public static function sidebar($theme) { + public static function sidebar_blocks($theme) { $block = new Block(); $block->id = "gMaps"; $block->title = _("Location"); diff --git a/modules/info/helpers/info_block.php b/modules/info/helpers/info_block.php index 65b60289..62c2919c 100644 --- a/modules/info/helpers/info_block.php +++ b/modules/info/helpers/info_block.php @@ -19,7 +19,7 @@ */ class info_block_Core { - public static function sidebar($theme) { + public static function sidebar_blocks($theme) { $block = new Block(); $block->id = "gMetadata"; $block->title = _("Item Info"); diff --git a/modules/slideshow/helpers/slideshow_block.php b/modules/slideshow/helpers/slideshow_block.php index 8272554f..3a089d22 100644 --- a/modules/slideshow/helpers/slideshow_block.php +++ b/modules/slideshow/helpers/slideshow_block.php @@ -23,11 +23,11 @@ class slideshow_block_Core { ""; } - public static function album_top() { + public static function album_top($theme) { return "Slideshow"; } - public static function photo() { + public static function photo_top($theme) { return "Slideshow"; } } diff --git a/modules/tag/helpers/tag_block.php b/modules/tag/helpers/tag_block.php index 63486435..0ade0acf 100644 --- a/modules/tag/helpers/tag_block.php +++ b/modules/tag/helpers/tag_block.php @@ -19,7 +19,7 @@ */ class tag_block_Core { - public static function sidebar($theme) { + public static function sidebar_blocks($theme) { $block = new Block(); $block->id = "gTag"; $block->title = _("Tags"); diff --git a/modules/user/helpers/user_block.php b/modules/user/helpers/user_block.php index 05767253..225ff82e 100644 --- a/modules/user/helpers/user_block.php +++ b/modules/user/helpers/user_block.php @@ -24,7 +24,7 @@ class user_block_Core { return empty($user) ? "" : ""; } - public static function top($theme) { + public static function header_top($theme) { $view = new View("login.html"); $view->user = Session::instance()->get('user', null); return $view->render(); diff --git a/themes/default/views/album.html.php b/themes/default/views/album.html.php index ff0b441f..f4869479 100644 --- a/themes/default/views/album.html.php +++ b/themes/default/views/album.html.php @@ -2,11 +2,11 @@

title_edit ?>

description_edit ?> - + album_top() ?>
+ album_bottom() ?> pager() ?> diff --git a/themes/default/views/header.html.php b/themes/default/views/header.html.php index 9dba9c71..c8eb2145 100644 --- a/themes/default/views/header.html.php +++ b/themes/default/views/header.html.php @@ -1,8 +1,7 @@ +header_top() ?> " src="url("images/logo.png") ?>" /> - -
+header_bottom() ?> diff --git a/themes/default/views/page.html.php b/themes/default/views/page.html.php index ca4a5688..8a93c9dc 100644 --- a/themes/default/views/page.html.php +++ b/themes/default/views/page.html.php @@ -20,11 +20,12 @@ - + head() ?> -
+ page_top() ?> +
display("header.html") ?> @@ -48,6 +49,7 @@
+ page_bottom() ?> in_place_edit(); ?> diff --git a/themes/default/views/photo.html.php b/themes/default/views/photo.html.php index 88ffedf9..2a5079b4 100644 --- a/themes/default/views/photo.html.php +++ b/themes/default/views/photo.html.php @@ -1,7 +1,7 @@
Full size (1024x768) - + photo_top() ?> photo + + photo_bottom() ?>
diff --git a/themes/default/views/sidebar.html.php b/themes/default/views/sidebar.html.php index fc47d72e..f05ee025 100644 --- a/themes/default/views/sidebar.html.php +++ b/themes/default/views/sidebar.html.php @@ -1,2 +1,4 @@ - +sidebar_top() ?> +sidebar_blocks() ?> +sidebar_bottom() ?> -- cgit v1.2.3