diff options
-rw-r--r-- | includes/theme.inc | 31 | ||||
-rw-r--r-- | modules/block.module | 33 | ||||
-rw-r--r-- | modules/block/block.module | 33 | ||||
-rw-r--r-- | themes/marvin/marvin.theme | 4 | ||||
-rw-r--r-- | themes/unconed/unconed.theme | 2 | ||||
-rw-r--r-- | themes/xtemplate/xtemplate.theme | 25 |
6 files changed, 84 insertions, 44 deletions
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 .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\"><tr><td style=\"vertical-align: top; width: 170px;\">"; $output .= theme("box", t("Navigation"), @implode("<br />", link_page())); - $output .= render_blocks("all"); + $output .= theme("blocks", "all"); $output .= "</td><td style=\"vertical-align: top;\">"; 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 == <i>module</i>_<i>delta</i> + $output .= theme('block', $block); } } return $output; diff --git a/modules/block.module b/modules/block.module index bd78a3295..381d31c78 100644 --- a/modules/block.module +++ b/modules/block.module @@ -346,4 +346,37 @@ function block_user($type, &$edit, &$user) { } } +/** + * Return blocks available for current $user at $region. + * + * @param $region main|left|right + * + * @return array of block objects, indexed with <i>module</i>_<i>delta</i> + * + * @see <a href="http://drupal.org/node/view/1042" target="_top">[feature] + * Generic template design difficult w/o block region "look-ahead"</a> + * @todo add a proper primary key (bid) to the blocks table so we don't have + * to mess around with this <i>module</i>_<i>delta</i> construct. currently, + * "blocks" has no primary key defined (bad)! + */ +function block_list($region) { + global $user; + static $blocks = array(); + + if (!isset($blocks[$region])) { + $blocks[$region] = array(); + $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); + + 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']) { + $blocks[$region]["$block[module]_$block[delta]"] = (object) $block; + } + } + } + } + return $blocks[$region]; +} + ?> diff --git a/modules/block/block.module b/modules/block/block.module index bd78a3295..381d31c78 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -346,4 +346,37 @@ function block_user($type, &$edit, &$user) { } } +/** + * Return blocks available for current $user at $region. + * + * @param $region main|left|right + * + * @return array of block objects, indexed with <i>module</i>_<i>delta</i> + * + * @see <a href="http://drupal.org/node/view/1042" target="_top">[feature] + * Generic template design difficult w/o block region "look-ahead"</a> + * @todo add a proper primary key (bid) to the blocks table so we don't have + * to mess around with this <i>module</i>_<i>delta</i> construct. currently, + * "blocks" has no primary key defined (bad)! + */ +function block_list($region) { + global $user; + static $blocks = array(); + + if (!isset($blocks[$region])) { + $blocks[$region] = array(); + $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); + + 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']) { + $blocks[$region]["$block[module]_$block[delta]"] = (object) $block; + } + } + } + } + return $blocks[$region]; +} + ?> diff --git a/themes/marvin/marvin.theme b/themes/marvin/marvin.theme index fdeefb118..ae31085fb 100644 --- a/themes/marvin/marvin.theme +++ b/themes/marvin/marvin.theme @@ -47,7 +47,7 @@ function marvin_header($title = "") { $output .= "<table border=\"0\" style=\"width: 100%\" cellpadding=\"8\" cellspacing=\"0\">\n"; $output .= " <tr>\n"; - $blocks = render_blocks("left"); + $blocks = theme("blocks", "left"); if ($blocks) { $output .= " <td style=\"width: 200px; vertical-align: top;\">\n"; $output .= $blocks; @@ -171,7 +171,7 @@ function marvin_links($links, $delimiter = " · ") { function marvin_footer() { $output = " </td>\n"; - $blocks = render_blocks("right"); + $blocks = theme("blocks", "right"); if ($blocks) { $output .= " <td style=\"width: 200px; vertical-align: top;\">\n"; $output .= $blocks; diff --git a/themes/unconed/unconed.theme b/themes/unconed/unconed.theme index df2e014ff..66cd24c08 100644 --- a/themes/unconed/unconed.theme +++ b/themes/unconed/unconed.theme @@ -274,7 +274,7 @@ function unconed_footer() { </td> <td valign="top" width="20%"> <?php - print render_blocks("all", $this); + print theme("blocks", "all"); ?> </td> </tr> diff --git a/themes/xtemplate/xtemplate.theme b/themes/xtemplate/xtemplate.theme index 799643d19..9bf714483 100644 --- a/themes/xtemplate/xtemplate.theme +++ b/themes/xtemplate/xtemplate.theme @@ -5,7 +5,6 @@ if (!class_exists("XTemplate")) { include_once("themes/xtemplate/xtemplate.inc"); } -$GLOBALS["xtemplate"]->sidebar = variable_get("xtemplate_sidebar", "right"); $GLOBALS["xtemplate"]->template = new XTemplate("themes/xtemplate/xtemplate.xtmpl"); $GLOBALS["xtemplate"]->template->SetNullBlock(" "); // "" doesnt work! @@ -113,17 +112,7 @@ function xtemplate_header($title = "") { $xtemplate->template->parse("header.message"); } - /* - if ($xtemplate->sidebar == "left") { - $blocks = render_blocks("all"); - } - else if ($xtemplate->sidebar == "both") { - $blocks = render_blocks("left"); - } - */ - $blocks = render_blocks("left"); - - if ($blocks) { + if ($blocks = theme("blocks", "left")) { $xtemplate->template->assign("blocks", $blocks); $xtemplate->template->parse("header.blocks"); } @@ -162,17 +151,7 @@ function xtemplate_box($title, $content, $region = "main") { function xtemplate_footer() { global $xtemplate; - /* - if ($xtemplate->sidebar == "right") { - print render_blocks("all"); - } - else if ($xtemplate->sidebar == "both") { - print render_blocks("right"); - } - */ - $blocks = render_blocks("right"); - - if ($blocks) { + if ($blocks = theme("blocks", "right")) { $xtemplate->template->assign("blocks", $blocks); $xtemplate->template->parse("footer.blocks"); } |