summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-11-22 21:46:34 +0000
committerBharat Mediratta <bharat@menalto.com>2008-11-22 21:46:34 +0000
commitc6f0cc036df6a1306b03c987092197d8bab27111 (patch)
tree57181842685c5e3cb58e4c77a3b7114b43b6aadb
parentac9df35d8aed2ed5dcf9da2b319bf8da1f246ab3 (diff)
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.
-rw-r--r--core/libraries/MY_View.php54
-rw-r--r--core/libraries/Theme.php42
-rw-r--r--modules/carousel/helpers/carousel_block.php2
-rw-r--r--modules/gmaps/helpers/gmaps_block.php2
-rw-r--r--modules/info/helpers/info_block.php2
-rw-r--r--modules/slideshow/helpers/slideshow_block.php4
-rw-r--r--modules/tag/helpers/tag_block.php2
-rw-r--r--modules/user/helpers/user_block.php2
-rw-r--r--themes/default/views/album.html.php5
-rw-r--r--themes/default/views/header.html.php4
-rw-r--r--themes/default/views/page.html.php6
-rw-r--r--themes/default/views/photo.html.php4
-rw-r--r--themes/default/views/sidebar.html.php4
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: <a href=#>{$theme->item()->title_edit}</a>";
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 {
"</script>";
}
- public static function album_top() {
+ public static function album_top($theme) {
return "<a href=\"javascript:PicLensLite.start()\" id=\"gSlideshowLink\" class=\"gButtonLink\">Slideshow</a>";
}
- public static function photo() {
+ public static function photo_top($theme) {
return "<a href=\"javascript:PicLensLite.start()\" id=\"gSlideshowLink\" class=\"gButtonLink\">Slideshow</a>";
}
}
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) ? "" : "<script src=\"$url\" type=\"text/javascript\"></script>";
}
- 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 @@
<div id="gAlbumHeader">
<h1><?= $item->title_edit ?></h1>
<span class="gUnderState"><?= $item->description_edit ?></span>
- <?= View::album_top($theme) ?>
+ <?= $theme->album_top() ?>
</div>
<ul id="gAlbumGrid">
- <? foreach ($children as $i => $child): ?>
+<? foreach ($children as $i => $child): ?>
<? $album_class = ""; ?>
<? if ($child->is_album()): ?>
<? $album_class = "gAlbum "; ?>
@@ -27,6 +27,7 @@
</ul>
</li>
<? endforeach ?>
+ <?= $theme->album_bottom() ?>
</ul>
<?= $theme->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 @@
<? defined("SYSPATH") or die("No direct script access."); ?>
+<?= $theme->header_top() ?>
<img id="gLogo" alt="<?= _("Logo") ?>" src="<?= $theme->url("images/logo.png") ?>" />
-<?= View::top($theme) ?>
-
<div id="gSiteMenu" class="gClearFix">
<ul class="ui-tabs-nav">
<li><a href="<?= url::base() ?>"><?= _("HOME") ?></a></li>
@@ -26,3 +25,4 @@
<? endforeach ?>
<li class="active"><?= $item->title_edit ?></li>
</ul>
+<?= $theme->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 @@
<script src="<?= $theme->url("jquery/jquery.ui.tabs.js") ?>" type="text/javascript"></script>
<!--script src="<?= $theme->url("jquery/jquery.ui.accordion.js") ?>" type="text/javascript"></script-->
<!--script src="<?= $theme->url("jquery/jquery.ui.init.js") ?>" type="text/javascript"></script-->
- <?= View::head($theme) ?>
+ <?= $theme->head() ?>
</head>
<body>
- <div id="doc4" class="yui-t5 gView">
+ <?= $theme->page_top() ?>
+ <div id="doc4" class="yui-t5 gView">
<div id="hd">
<div id="gHeader">
<?= $theme->display("header.html") ?>
@@ -48,6 +49,7 @@
</div>
</div>
</div>
+ <?= $theme->page_bottom() ?>
<? if ($user): ?>
<?= $theme->in_place_edit(); ?>
<? endif; ?>
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 @@
<? defined("SYSPATH") or die("No direct script access."); ?>
<div id="gItem">
<a href="" class="gButtonLink">Full size (1024x768)</a>
- <?= View::photo($theme) ?>
+ <?= $theme->photo_top() ?>
<img id="gPhotoID-<?= $item->id ?>" alt="photo" src="<?= $item->resize_url() ?>"
width="<?= $item->resize_width ?>"
@@ -12,4 +12,6 @@
<? if (module::is_installed("comment")): ?>
<?= comment::block($theme, true); ?>
<? endif ?>
+
+ <?= $theme->photo_bottom() ?>
</div>
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 @@
<? defined("SYSPATH") or die("No direct script access."); ?>
-<?= View::sidebar($theme) ?>
+<?= $theme->sidebar_top() ?>
+<?= $theme->sidebar_blocks() ?>
+<?= $theme->sidebar_bottom() ?>