diff --git a/includes/theme.inc b/includes/theme.inc index 46274ba8d12796448ec33c5d84ab1d1dea2a387b..79d39b8576699a90b428dfdc23e6c4d7bdc3178f 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;
diff --git a/modules/block.module b/modules/block.module
index bd78a3295dbae6424522f47dfa184103ed7a829e..381d31c784f767d3de5cdc5488d12151f35ffd5b 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 module_delta
+ *
+ * @see [feature]
+ * Generic template design difficult w/o block region "look-ahead"
+ * @todo add a proper primary key (bid) to the blocks table so we don't have
+ * to mess around with this module_delta 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 bd78a3295dbae6424522f47dfa184103ed7a829e..381d31c784f767d3de5cdc5488d12151f35ffd5b 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 module_delta
+ *
+ * @see [feature]
+ * Generic template design difficult w/o block region "look-ahead"
+ * @todo add a proper primary key (bid) to the blocks table so we don't have
+ * to mess around with this module_delta 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 fdeefb118b87ef690b02450d5b6a611954b8cc0d..ae31085fba3b979e96bbea6cc0d1bc5beee83502 100644
--- a/themes/marvin/marvin.theme
+++ b/themes/marvin/marvin.theme
@@ -47,7 +47,7 @@ function marvin_header($title = "") {
$output .= "
|