summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-04-04 12:27:05 +0000
committerDries Buytaert <dries@buytaert.net>2005-04-04 12:27:05 +0000
commitc7c33cc1747561c1f36569dbfe411b385cbb281b (patch)
tree600c49cbe59ef1c1e192f921e182d726972866b9
parent9660db2c4e6b1a86c39e53c5969e9f52baf0dd9e (diff)
downloadbrdo-c7c33cc1747561c1f36569dbfe411b385cbb281b.tar.gz
brdo-c7c33cc1747561c1f36569dbfe411b385cbb281b.tar.bz2
- Modified patch #19694 by chx: makes sure that block.module deals by default only with regions 0 and 1 as it does now but lets you use block_list with any region you define. This opens many possibilites. You may do a multi region module, with your admin UI using the blocks table as storage and the block_list matcher. Or you may do a sections module using the block matcher without cluttering the current blocks list.
-rw-r--r--modules/block.module50
-rw-r--r--modules/block/block.module50
2 files changed, 62 insertions, 38 deletions
diff --git a/modules/block.module b/modules/block.module
index caeee3691..4248f9bb4 100644
--- a/modules/block.module
+++ b/modules/block.module
@@ -215,11 +215,11 @@ function block_admin_display() {
if ($block['region'] == 0) {
$left[] = $row;
}
- else {
+ if ($block['region'] == 1) {
$right[] = $row;
}
}
- else {
+ else if ($block['region'] <= 1) {
$disabled[] = $row;
}
}
@@ -420,28 +420,40 @@ function block_user($type, $edit, &$user, $category = NULL) {
}
}
-/**
- * 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/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) {
+ /**
+ * Return all blocks in the specied region for the current user. You may
+ * use this function to implement variable block regions. The default
+ * regions are 'left', 'right' and 'all', where 'all' means both left and
+ * right.
+ *
+ * @param $region
+ * This is a string which describes in a human readable form which region
+ * you need.
+ *
+ * @param $regions
+ * This is an optional array and contains map(s) from the string $region to
+ * the numerical region value(s) in the blocks table. See default value for
+ * examples.
+ *
+ * @return
+ * An array of block objects, indexed with <i>module</i>_<i>delta</i>.
+ * If you are displaying your blocks in one or two sidebars, you may check
+ * whether this array is empty to see how many columns are going to be
+ * displayed.
+ *
+ * @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, the blocks table has no primary key defined!
+ */
+function block_list($region, $regions = array('left' => 0, 'right' => 1, 'all' => '0, 1')) {
global $user;
static $blocks = array();
if (!isset($blocks[$region])) {
$blocks[$region] = array();
- $result = db_query('SELECT * FROM {blocks} WHERE status = 1 '. ($region != 'all' ? 'AND region = %d ' : '') .'ORDER BY weight, module', $region == 'left' ? 0 : 1);
-
- while ($result && ($block = db_fetch_array($result))) {
+ $result = db_query("SELECT * FROM {blocks} WHERE status = 1 AND region IN ('%s') ORDER BY weight, module", $regions[$region]);
+ while ($block = db_fetch_array($result)) {
// Use the user's block visibility setting, if necessary
if ($block['custom'] != 0) {
if ($user->uid && isset($user->block[$block['module']][$block['delta']])) {
diff --git a/modules/block/block.module b/modules/block/block.module
index caeee3691..4248f9bb4 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -215,11 +215,11 @@ function block_admin_display() {
if ($block['region'] == 0) {
$left[] = $row;
}
- else {
+ if ($block['region'] == 1) {
$right[] = $row;
}
}
- else {
+ else if ($block['region'] <= 1) {
$disabled[] = $row;
}
}
@@ -420,28 +420,40 @@ function block_user($type, $edit, &$user, $category = NULL) {
}
}
-/**
- * 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/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) {
+ /**
+ * Return all blocks in the specied region for the current user. You may
+ * use this function to implement variable block regions. The default
+ * regions are 'left', 'right' and 'all', where 'all' means both left and
+ * right.
+ *
+ * @param $region
+ * This is a string which describes in a human readable form which region
+ * you need.
+ *
+ * @param $regions
+ * This is an optional array and contains map(s) from the string $region to
+ * the numerical region value(s) in the blocks table. See default value for
+ * examples.
+ *
+ * @return
+ * An array of block objects, indexed with <i>module</i>_<i>delta</i>.
+ * If you are displaying your blocks in one or two sidebars, you may check
+ * whether this array is empty to see how many columns are going to be
+ * displayed.
+ *
+ * @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, the blocks table has no primary key defined!
+ */
+function block_list($region, $regions = array('left' => 0, 'right' => 1, 'all' => '0, 1')) {
global $user;
static $blocks = array();
if (!isset($blocks[$region])) {
$blocks[$region] = array();
- $result = db_query('SELECT * FROM {blocks} WHERE status = 1 '. ($region != 'all' ? 'AND region = %d ' : '') .'ORDER BY weight, module', $region == 'left' ? 0 : 1);
-
- while ($result && ($block = db_fetch_array($result))) {
+ $result = db_query("SELECT * FROM {blocks} WHERE status = 1 AND region IN ('%s') ORDER BY weight, module", $regions[$region]);
+ while ($block = db_fetch_array($result)) {
// Use the user's block visibility setting, if necessary
if ($block['custom'] != 0) {
if ($user->uid && isset($user->block[$block['module']][$block['delta']])) {