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. --- modules/block.module | 33 +++++++++++++++++++++++++++++++++ modules/block/block.module | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'modules') 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 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 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 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]; +} + ?> -- cgit v1.2.3