summaryrefslogtreecommitdiff
path: root/modules/block.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2003-11-19 16:13:07 +0000
committerDries Buytaert <dries@buytaert.net>2003-11-19 16:13:07 +0000
commit980637265c51416b57ba2145d7ab459f0c0eed02 (patch)
tree95a6f5d1678dee81ad4b2c7e3fcf4b31b9e1b305 /modules/block.module
parent3198d786a1ba6f4c32e76f6c6d3da9ac1e9811e1 (diff)
downloadbrdo-980637265c51416b57ba2145d7ab459f0c0eed02.tar.gz
brdo-980637265c51416b57ba2145d7ab459f0c0eed02.tar.bz2
- 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.
Diffstat (limited to 'modules/block.module')
-rw-r--r--modules/block.module33
1 files changed, 33 insertions, 0 deletions
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];
+}
+
?>