Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.218 diff -u -r1.218 block.module --- modules/block/block.module 20 Aug 2006 06:49:15 -0000 1.218 +++ modules/block/block.module 20 Aug 2006 19:58:53 -0000 @@ -80,6 +80,11 @@ 'callback' => 'drupal_get_form', 'callback arguments' => array('block_admin_configure'), 'type' => MENU_CALLBACK); + $items[] = array('path' => 'admin/build/block/visibility/configure', 'title' => t('configure block'), + 'access' => user_access('administer blocks'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('block_admin_visibility'), + 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/build/block/delete', 'title' => t('delete block'), 'access' => user_access('administer blocks'), 'callback' => 'drupal_get_form', @@ -90,14 +95,24 @@ 'callback' => 'drupal_get_form', 'callback arguments' => array('block_box_form'), 'type' => MENU_LOCAL_TASK); + $items[] = array('path' => 'admin/build/block/placement', 'title' => t('block placement'), + 'access' => user_access('administer blocks'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('block_admin_placement_configure'), + 'type' => MENU_LOCAL_TASK); + $items[] = array('path' => 'admin/build/block/placement/remove', 'title' => t('remove block'), + 'access' => user_access('administer blocks'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('block_admin_placement_remove'), + 'type' => MENU_CALLBACK); foreach (list_themes() as $key => $theme) { if ($theme->status) { if ($key == variable_get('theme_default', 'bluemarine')) { - $items[] = array('path' => 'admin/build/block/list/' . $key, 'title' => t('%key settings', array('%key' => $key)), + $items[] = array('path' => 'admin/build/block/placement/' . $key, 'title' => t('@key settings', array('@key' => $key)), 'access' => user_access('administer blocks'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); } else { - $items[] = array('path' => 'admin/build/block/list/' . $key, 'title' => t('%key settings', array('%key' => $key)), + $items[] = array('path' => 'admin/build/block/placement/' . $key, 'title' => t('@key settings', array('@key' => $key)), 'access' => user_access('administer blocks'), 'type' => MENU_LOCAL_TASK); } } @@ -154,11 +169,8 @@ * Blocks currently exported by modules. */ function _block_rehash() { - global $theme_key; - - init_theme(); - $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $theme_key); + $result = db_query("SELECT * FROM {blocks}"); while ($old_block = db_fetch_object($result)) { $old_blocks[$old_block->module][$old_block->delta] = $old_block; } @@ -173,22 +185,20 @@ $block['delta'] = $delta; // If previously written to database, load values. if ($old_blocks[$module][$delta]) { + $block['block_id'] = $old_blocks[$module][$delta]->block_id; $block['status'] = $old_blocks[$module][$delta]->status; - $block['weight'] = $old_blocks[$module][$delta]->weight; - $block['region'] = $old_blocks[$module][$delta]->region; - $block['visibility'] = $old_blocks[$module][$delta]->visibility; - $block['pages'] = $old_blocks[$module][$delta]->pages; - $block['custom'] = $old_blocks[$module][$delta]->custom; $block['throttle'] = $old_blocks[$module][$delta]->throttle; } // Otherwise, use any set values, or else substitute defaults. else { - $properties = array('status' => 0, 'weight' => 0, 'region' => 'left', 'pages' => '', 'custom' => 0); + $properties = array('status' => 0, 'pages' => '', 'custom' => 0); foreach ($properties as $property => $default) { - if (!isset($block[$property])) { - $block[$property] = $default; - } + $block[$property] = $default; } + // Reinsert blocks into table + db_query("INSERT INTO {blocks} (module, delta, status, throttle) VALUES ('%s', '%s', %d, %d)", + $block['module'], $block['delta'], $block['status'], $block['throttle']); + $block['block_id'] = db_next_id('{blocks}_block_id'); } $blocks[] = $block; @@ -196,60 +206,39 @@ } } - db_lock_table('blocks'); - // Remove all blocks from table. - db_query("DELETE FROM {blocks} WHERE theme = '%s'", $theme_key); - - // Reinsert new set of blocks into table. - foreach ($blocks as $block) { - db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)", $block['module'], $block['delta'], $theme_key, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']); - } - db_unlock_tables(); - return $blocks; } + + /** * Generate main block administration form. */ -function block_admin_display($theme = NULL) { - global $theme_key, $custom_theme; - - // If non-default theme configuration has been selected, set the custom theme. - if ($theme) { - $custom_theme = $theme; - } - else { - $custom_theme = variable_get('theme_default', 'bluemarine'); - } - init_theme(); +function block_admin_display() { // Fetch and sort blocks $blocks = _block_rehash(); usort($blocks, '_block_compare'); $throttle = module_exists('throttle'); - $block_regions = system_region_list($theme_key); // Build form tree - $form['#action'] = arg(3) ? url('admin/build/block/list/' . $theme_key) : url('admin/build/block'); + $form['#action'] = url('admin/build/block'); $form['#tree'] = TRUE; foreach ($blocks as $i => $block) { + $form[$i]['block_id'] = array('#type' => 'value', '#value' => $block['block_id']); $form[$i]['module'] = array('#type' => 'value', '#value' => $block['module']); $form[$i]['delta'] = array('#type' => 'value', '#value' => $block['delta']); $form[$i]['info'] = array('#value' => $block['info']); $form[$i]['status'] = array('#type' => 'checkbox', '#default_value' => $block['status']); - $form[$i]['theme'] = array('#type' => 'hidden', '#value' => $theme_key); - $form[$i]['weight'] = array('#type' => 'weight', '#default_value' => $block['weight']); - $form[$i]['region'] = array('#type' => 'select', - '#default_value' => isset($block['region']) ? $block['region'] : system_default_region($theme_key), - '#options' => $block_regions, - ); if ($throttle) { $form[$i]['throttle'] = array('#type' => 'checkbox', '#default_value' => $block['throttle']); } - $form[$i]['configure'] = array('#value' => l(t('configure'), 'admin/build/block/configure/'. $block['module'] .'/'. $block['delta'])); + + if ($settings = module_invoke($block['module'], 'block', 'configure', $block['delta'])) + $form[$i]['configure'] = array('#value' => l(t('configure'), 'admin/build/block/configure/'. $block['block_id'])); + if ($block['module'] == 'block') { $form[$i]['delete'] = array('#value' => l(t('delete'), 'admin/build/block/delete/'. $block['delta'])); } @@ -262,7 +251,7 @@ /** * Helper function for sorting blocks on admin/build/block. * - * Active blocks are sorted by region, then by weight. + * Active blocks are sorted name. * Disabled blocks are sorted by name. */ function _block_compare($a, $b) { @@ -271,15 +260,8 @@ if ($status) { return $status; } - // Enabled blocks - if ($a['status']) { - $place = strcmp($a['region'], $b['region']); - return $place ? $place : ($a['weight'] - $b['weight']); - } - // Disabled blocks - else { - return strcmp($a['info'], $b['info']); - } + // sort alphabetically + return strcmp($a['info'], $b['info']); } /** @@ -287,71 +269,56 @@ */ function block_admin_display_submit($form_id, $form_values) { foreach ($form_values as $block) { - db_query("UPDATE {blocks} SET status = %d, weight = %d, region = '%s', throttle = %d WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['status'], $block['weight'], $block['region'], $block['throttle'], $block['module'], $block['delta'], $block['theme']); + db_query("UPDATE {blocks} SET status = %d, throttle = %d WHERE block_id = %d", $block['status'], $block['throttle'], $block['block_id']); } drupal_set_message(t('The block settings have been updated.')); cache_clear_all(); + return 'admin/build/block/'; } /** * Theme main block administration form submission. - * - * Note: the blocks are already sorted in the right order, - * grouped by status, region and weight. + * - here the user controls global block configuration: status, throttle and block-specific configuration */ function theme_block_admin_display($form) { global $theme_key; $throttle = module_exists('throttle'); - $block_regions = system_region_list($theme_key); - - // Highlight regions on page to provide visual reference. - foreach ($block_regions as $key => $value) { - drupal_set_content($key, '
TRUE (PHP-mode, experts only).');
- $description .= t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => ''));
+ $description .= t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => theme('placeholder', '')));
}
$form['page_vis_settings']['visibility'] = array(
'#type' => 'radios',
@@ -474,6 +673,50 @@
);
}
+ $form['submit'] = array('#type' => 'submit', '#value' => t('Save settings'));
+
+ return $form;
+}
+
+
+function block_admin_visibility_submit($form_id, $form_values) {
+ db_query("UPDATE {block_theme} SET visibility = %d, pages = '%s', custom = %d WHERE block_id = %d AND instance = %d", $form_values['visibility'], $form_values['pages'], $form_values['custom'], $form_values['block_id'], $form_values['instance']);
+ db_query("DELETE FROM {blocks_roles} WHERE block_id = %d", $form_values['block_id']);
+ foreach (array_filter($form_values['roles']) as $rid) {
+ db_query("INSERT INTO {blocks_roles} (rid, block_id) VALUES (%d, %d)", $rid, $form_values['block_id']);
+ }
+ drupal_set_message(t('The block configuration has been saved.'));
+ cache_clear_all();
+ return 'admin/build/block/placement';
+}
+
+
+/**
+ * Menu callback; displays the block configuration form.
+ */
+function block_admin_configure($block_id) {
+
+ $edit = db_fetch_array(db_query("SELECT * FROM {blocks} WHERE block_id = %d", $block_id));
+
+ $module = $edit['module'];
+ $delta = $edit['delta'];
+
+ $form['module'] = array('#type' => 'value', '#value' => $module);
+ $form['delta'] = array('#type' => 'value', '#value' => $delta);
+
+ // Module-specific block configurations.
+ if ($settings = module_invoke($module, 'block', 'configure', $delta)) {
+ $form['block_settings'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Block specific settings'),
+ '#collapsible' => TRUE,
+ );
+
+ foreach ($settings as $k => $v) {
+ $form['block_settings'][$k] = $v;
+ }
+ }
+
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save block'),
@@ -492,11 +735,6 @@
function block_admin_configure_submit($form_id, $form_values) {
if (!form_get_errors()) {
- db_query("UPDATE {blocks} SET visibility = %d, pages = '%s', custom = %d WHERE module = '%s' AND delta = '%s'", $form_values['visibility'], $form_values['pages'], $form_values['custom'], $form_values['module'], $form_values['delta']);
- db_query("DELETE FROM {blocks_roles} WHERE module = '%s' AND delta = '%s'", $form_values['module'], $form_values['delta']);
- foreach (array_filter($form_values['roles']) as $rid) {
- db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_values['module'], $form_values['delta']);
- }
module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values);
drupal_set_message(t('The block configuration has been saved.'));
cache_clear_all();
@@ -504,6 +742,7 @@
}
}
+
function block_box_form_validate($form_id, $form_values) {
if (empty($form_values['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $form_values['info']))) {
form_set_error('info', t('Please ensure that each block description is unique.'));
@@ -598,7 +837,7 @@
switch ($type) {
case 'form':
if ($category == 'account') {
- $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom != 0 AND (r.rid IN (%s) OR r.rid IS NULL) ORDER BY b.weight, b.module", implode(',', array_keys($user->roles)));
+ $result = db_query("SELECT DISTINCT b.*, bt.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON (b.block_id = r.block_id) LEFT JOIN {block_theme} bt ON (b.block_id = bt.block_id) WHERE b.status = 1 AND custom != 0 AND (r.rid IN (%s) OR r.rid IS NULL) ORDER BY bt.region, bt.weight, b.module", implode(',', array_keys($user->roles)));
$form['block'] = array('#type' => 'fieldset', '#title' => t('Block configuration'), '#weight' => 3, '#collapsible' => TRUE, '#tree' => TRUE);
while ($block = db_fetch_object($result)) {
$data = module_invoke($block->module, 'block', 'list');
@@ -645,7 +884,7 @@
static $blocks = array();
if (!count($blocks)) {
- $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN (%s) OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", $theme_key, implode(',', array_keys($user->roles)));
+ $result = db_query("SELECT DISTINCT b.*, bt.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON (b.block_id = r.block_id) LEFT JOIN {block_theme} bt ON (b.block_id = bt.block_id) WHERE bt.theme = '%s' AND b.status = 1 AND (r.rid IN (%s) OR r.rid IS NULL) ORDER BY bt.region, bt.weight, b.module", $theme_key, implode(',', array_keys($user->roles)));
while ($block = db_fetch_object($result)) {
if (!isset($blocks[$block->region])) {
$blocks[$block->region] = array();
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.9
diff -u -r1.9 system.install
--- modules/system/system.install 20 Aug 2006 06:38:50 -0000 1.9
+++ modules/system/system.install 20 Aug 2006 19:52:07 -0000
@@ -23,16 +23,22 @@
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {blocks} (
+ block_id INT(10) NOT NULL auto_increment PRIMARY KEY,
module varchar(64) DEFAULT '' NOT NULL,
delta varchar(32) NOT NULL default '0',
- theme varchar(255) NOT NULL default '',
status tinyint DEFAULT '0' NOT NULL,
- weight tinyint DEFAULT '0' NOT NULL,
+ throttle tinyint DEFAULT '0' NOT NULL
+ ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+
+ db_query("CREATE TABLE {block_theme} (
+ block_id INT(10) NOT NULL,
+ instance INT(10) DEFAULT '-1' NOT NULL,
+ theme varchar(255) NOT NULL default '',
+ weight smallint DEFAULT '0' NOT NULL,
region varchar(64) DEFAULT 'left' NOT NULL,
- custom tinyint DEFAULT '0' NOT NULL,
- throttle tinyint DEFAULT '0' NOT NULL,
- visibility tinyint DEFAULT '0' NOT NULL,
- pages text DEFAULT '' NOT NULL
+ custom smallint DEFAULT '0' NOT NULL,
+ visibility smallint DEFAULT '0' NOT NULL,
+ pages text DEFAULT ''
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {boxes} (
@@ -240,10 +246,9 @@
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {blocks_roles} (
- module varchar(64) NOT NULL,
- delta varchar(32) NOT NULL,
+ block_id INT(10) NOT NULL DEFAULT 0,
rid int unsigned NOT NULL,
- PRIMARY KEY (module, delta, rid)
+ PRIMARY KEY (block_id, rid)
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {sessions} (
@@ -818,8 +823,10 @@
db_query("INSERT INTO {variable} (name,value) VALUES('theme_default', 's:10:\"bluemarine\";')");
- db_query("INSERT INTO {blocks} (module,delta,theme,status) VALUES('user', 0, 'bluemarine', 1)");
- db_query("INSERT INTO {blocks} (module,delta,theme,status) VALUES('user', 1, 'bluemarine', 1)");
+ db_query("INSERT INTO {blocks} (module,delta,status) VALUES('user', 0, 1)");
+ db_query("INSERT INTO {blocks} (module,delta,status) VALUES('user', 1, 1)");
+ db_query("INSERT INTO {block_theme} (block_id,theme,region) VALUES(1, 'bluemarine', 'left')");
+ db_query("INSERT INTO {block_theme} (block_id,theme,region) VALUES(2, 'bluemarine', 'left')");
db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)");
@@ -3047,6 +3054,74 @@
return $ret;
}
+function system_update_1006() {
+ $ret = array();
+
+ switch ($GLOBALS['db_type']) {
+ case 'mysqli':
+ case 'mysql':
+ $ret[] = update_sql("CREATE TABLE {block_theme} (
+ block_id INT(10) NOT NULL,
+ instance INT(10) DEFAULT '-1' NOT NULL,
+ theme varchar(255) NOT NULL default '',
+ weight smallint DEFAULT '0' NOT NULL,
+ region varchar(64) DEFAULT 'left' NOT NULL,
+ custom smallint DEFAULT '0' NOT NULL,
+ visibility smallint DEFAULT '0' NOT NULL,
+ pages text DEFAULT ''
+ )");
+ break;
+ case 'pgsql':
+ break;
+ }
+
+ $blocks = array();
+ $query = db_query('SELECT * FROM {blocks}');
+ while ($block = db_fetch_array($query)) {
+ $query2 = db_query("SELECT rid FROM {blocks_roles} WHERE module = '%s' AND delta = %d", $block['module'], $block['delta']);
+ $block['roles'] = array();
+ while ($role = db_fetch_object($query2)) {
+ $block['roles'][] = $role->rid;
+ }
+ $blocks[] = $block;
+ }
+
+ switch ($GLOBALS['db_type']) {
+ case 'mysqli':
+ case 'mysql':
+ $ret[] = update_sql("DELETE FROM {blocks}");
+ $ret[] = update_sql("ALTER TABLE {blocks} DROP `pages`");
+ $ret[] = update_sql("ALTER TABLE {blocks} DROP `visibility`");
+ $ret[] = update_sql("ALTER TABLE {blocks} DROP `custom`");
+ $ret[] = update_sql("ALTER TABLE {blocks} DROP `region`");
+ $ret[] = update_sql("ALTER TABLE {blocks} DROP `weight`");
+ $ret[] = update_sql("ALTER TABLE {blocks} DROP `theme`");
+ $ret[] = update_sql("ALTER TABLE {blocks} ADD COLUMN block_id int(10) NOT NULL auto_increment PRIMARY KEY FIRST");
+ $ret[] = update_sql("DELETE FROM {blocks_roles}");
+ $ret[] = update_sql("ALTER TABLE {blocks_roles} ADD COLUMN block_id int(10) NOT NULL DEFAULT 0 FIRST");
+ $ret[] = update_sql("ALTER TABLE {blocks_roles} DROP `module`");
+ $ret[] = update_sql("ALTER TABLE {blocks_roles} DROP `delta`");
+ break;
+ case 'pgsql':
+ break;
+ }
+ foreach ($blocks as $block_id => $block) {
+ db_query("INSERT INTO {blocks} (module, delta, status, throttle) VALUES ('%s', %d, %d, %d)", $block['module'], $block['delta'], $block['status'], $block['throttle']);
+ if (count($block['roles']) > 0) {
+ foreach ($block['roles'] as $i => $rid) {
+ db_query("INSERT INTO {blocks_roles} (block_id, rid) VALUES (%d, %d)", $block_id, $rid);
+ }
+ }
+ if ($block['status']) {
+ $instance = db_next_id("{block_theme}_instance");
+ db_query("INSERT INTO {block_theme} (block_id, instance, theme, weight, region, visibility, pages, custom) VALUES (%d, %d, '%s', %d, '%s', %d, '%s', %d)",
+ $block_id+1, $instance, $block['theme'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom']);
+ }
+ }
+
+ return $ret;
+}
+
/**
* @} End of "defgroup updates-4.7-to-x.x"
* The next series of updates should start at 2000.
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.348
diff -u -r1.348 system.module
--- modules/system/system.module 20 Aug 2006 05:57:40 -0000 1.348
+++ modules/system/system.module 20 Aug 2006 19:38:58 -0000
@@ -392,7 +392,7 @@
function system_admin_theme_submit($form_id, $form_values) {
// If we're changing themes, make sure the theme has its blocks initialized.
if ($form_values['admin_theme'] != variable_get('admin_theme', 'bluemarine')) {
- $result = db_query("SELECT status FROM {blocks} WHERE theme = '%s'", $form_values['admin_theme']);
+ $result = db_query("SELECT block_id FROM {block_theme} WHERE theme = '%s'", $form_values['admin_theme']);
if (!db_num_rows($result)) {
system_initialize_theme_blocks($form_values['admin_theme']);
}
@@ -1034,17 +1034,17 @@
*/
function system_initialize_theme_blocks($theme) {
// Initialize theme's blocks if none already registered.
- if (!(db_num_rows(db_query("SELECT module FROM {blocks} WHERE theme = '%s'", $theme)))) {
+ if (!(db_num_rows(db_query("SELECT block_id FROM {block_theme} WHERE theme = '%s'", $theme)))) {
$default_theme = variable_get('theme_default', 'bluemarine');
$regions = system_region_list($theme);
- $result = db_query("SELECT * FROM {blocks} WHERE theme = '%s'", $default_theme);
+ $result = db_query("SELECT * FROM {block_theme} WHERE theme = '%s'", $default_theme);
while($block = db_fetch_array($result)) {
// If the region isn't supported by the theme, assign the block to the theme's default region.
if (!array_key_exists($block['region'], $regions)) {
$block['region'] = system_default_region($theme);
}
- db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)",
- $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle']);
+ db_query("INSERT INTO {block_theme} (block_id, theme, weight, region, visibility, pages, custom) VALUES (%d, '%s', %d, '%s', %d, '%s', %d)",
+ $block['block_id'], $theme, $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom']);
}
}
}