From 39a40e49a19f00baeeeefe375d67e915ccc7e09a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 29 Sep 2009 14:35:15 -0700 Subject: [PATCH] Refactor sidebar_blocks into a separate function and then call block_manager::get_html(site.sidebar). Convert image_block to use block management instead of theme::sidebar_blocks --- modules/gallery/libraries/Theme_View.php | 7 +++ ..._block_theme.php => image_block_block.php} | 51 ++++++++++++------- .../helpers/image_block_installer.php | 32 ++++++++++++ modules/image_block/module.info | 2 +- 4 files changed, 72 insertions(+), 20 deletions(-) rename modules/image_block/helpers/{image_block_theme.php => image_block_block.php} (53%) create mode 100644 modules/image_block/helpers/image_block_installer.php diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 728e8bf9..493bca16 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -153,6 +153,13 @@ class Theme_View_Core extends Gallery_View { return message::get(); } + /** + * Print out the sidebar. + */ + public function sidebar_blocks() { + return block_manager::get_html("site.sidebar"); + } + /** * Handle all theme functions that insert module content. */ diff --git a/modules/image_block/helpers/image_block_theme.php b/modules/image_block/helpers/image_block_block.php similarity index 53% rename from modules/image_block/helpers/image_block_theme.php rename to modules/image_block/helpers/image_block_block.php index 78138b23..f7aefc43 100644 --- a/modules/image_block/helpers/image_block_theme.php +++ b/modules/image_block/helpers/image_block_block.php @@ -17,34 +17,47 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class image_block_theme_Core { - static function sidebar_blocks($theme) { +class image_block_block_Core { + static function get_site_list() { + return array("random_image" => t("Random Image")); + } + + static function get($block_id) { $block = new Block(); - $block->css_id = "gImageBlock"; - $block->title = t("Random Image"); - $block->content = new View("image_block_block.html"); + switch ($block_id) { + case "random_image": + $block = new Block(); + $block->css_id = "gImageBlock"; + $block->title = t("Random Image"); + $block->content = new View("image_block_block.html"); - $random = ((float)mt_rand()) / (float)mt_getrandmax(); + $random = ((float)mt_rand()) / (float)mt_getrandmax(); - $items = ORM::factory("item") - ->viewable() - ->where("type !=", "album") - ->where("rand_key < ", $random) - ->orderby(array("rand_key" => "DESC")) - ->find_all(1); - - if ($items->count() == 0) { - // Try once more. If this fails, just ditch the block altogether $items = ORM::factory("item") ->viewable() ->where("type !=", "album") - ->where("rand_key >= ", $random) + ->where("rand_key < ", $random) ->orderby(array("rand_key" => "DESC")) ->find_all(1); + + if ($items->count() == 0) { + // Try once more. If this fails, just ditch the block altogether + $items = ORM::factory("item") + ->viewable() + ->where("type !=", "album") + ->where("rand_key >= ", $random) + ->orderby(array("rand_key" => "DESC")) + ->find_all(1); + } + + if ($items->count() > 0) { + $block->content->item = $items->current(); + } else { + $block = ""; + } + break; } - $block->content->item = $items->current(); - - return $items->count() == 0 ? "" : $block; + return $block; } } diff --git a/modules/image_block/helpers/image_block_installer.php b/modules/image_block/helpers/image_block_installer.php new file mode 100644 index 00000000..06668dc2 --- /dev/null +++ b/modules/image_block/helpers/image_block_installer.php @@ -0,0 +1,32 @@ +