From 980637265c51416b57ba2145d7ab459f0c0eed02 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 19 Nov 2003 16:13:07 +0000 Subject: - Block and theme improvements. Patch by Ax. + block_list() (in block.module): returns an array of block objects for $region. + theme_blocks() (in theme.inc): uses block_list() and theme("block") to actually render them. Advantages: + Decouples blocks content and layout, allows block_list() to be used for non-output purposes (think "pull"). + Unifies naming in theme.inc: render_blocks()) didn't really fit there. + Puts block_list() in blocks.module where it logically belongs. - Removed some cruft from the Xtemplate theme. Patch by Ax. --- includes/theme.inc | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'includes/theme.inc') diff --git a/includes/theme.inc b/includes/theme.inc index 46274ba8d..79d39b857 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -37,7 +37,7 @@ function theme_header($title = "") { $output .= "
"; $output .= theme("box", t("Navigation"), @implode("
", link_page())); - $output .= render_blocks("all"); + $output .= theme("blocks", "all"); $output .= "
"; return $output; @@ -358,24 +358,19 @@ function theme_onload_attribute($theme_onloads = array()) { } /** - Render blocks available for (global) $user and $region calling $theme->block($block). - - @param $region main|left|right - - @return a string containing the \a blocks output. - **/ -function render_blocks($region) { - global $user; - - $result = db_query("SELECT * FROM {blocks} WHERE (status = '1' OR custom = '1') ". ($region != "all" ? "AND region = %d " : "") ."ORDER BY weight, module", $region == "left" ? 0 : 1); - + * Returns themed blocks available for current $user at $region. + * + * @param $region main|left|right + * + * @return a string containing the \a blocks output. + */ +function theme_blocks($region) { $output = ""; - while ($result && ($block = db_fetch_array($result))) { - if ((($block['status'] && (!$user->uid || !$block['custom'])) || ($block['custom'] && $user->block[$block['module']][$block['delta']])) && (!$block['path'] || preg_match($block['path'], str_replace("?q=", "", request_uri())))) { - $block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta'])); - if ($block['content']) { - $output .= theme('block', (object)$block); - } + + if ($list = module_invoke('block', 'list', $region)) { + foreach ($list as $key => $block) { + // $key == module_delta + $output .= theme('block', $block); } } return $output; -- cgit v1.2.3