Commit 79b016d9 authored by Dries's avatar Dries

- Patch #216072 by recidive, David Rothstein, ptalindstrom et al: switched...

- Patch #216072 by recidive, David Rothstein, ptalindstrom et al: switched from numeric block IDs to string IDs.

  The short explanation is that Drupal uses a lot of numeric deltas in the block system; blocks are identified by the 'module' and the 'delta'. In early Drupal, delta was numeric, but somewhere along the line it was changed to be possibly a string. In modern Drupal, block overrides are easily done via block-MODULE-DELTA.tpl.php.  The primary motivation to switch to string IDs everywhere is to make these deltas friendlier to themers:

    block-user-0.tpl.php --> block-user-navigation.tpl.php
    block-user-1.tpl.php --> block-user-login.tpl.php

  You get the picture.
parent ee08784f
......@@ -300,7 +300,7 @@ function aggregator_cron() {
*
* Generates blocks for the latest news items in each category and feed.
*/
function aggregator_block($op = 'list', $delta = 0, $edit = array()) {
function aggregator_block($op = 'list', $delta = '', $edit = array()) {
if (user_access('access news feeds')) {
if ($op == 'list') {
$result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title');
......
......@@ -172,10 +172,10 @@ function blog_menu() {
*
* Displays the most recent 10 blog titles.
*/
function blog_block($op = 'list', $delta = 0) {
function blog_block($op = 'list', $delta = '') {
global $user;
if ($op == 'list') {
$block[0]['info'] = t('Recent blog posts');
$block['recent']['info'] = t('Recent blog posts');
return $block;
}
else if ($op == 'view') {
......
......@@ -178,12 +178,12 @@ function book_init() {
* Displays the book table of contents in a block when the current page is a
* single-node view of a book node.
*/
function book_block($op = 'list', $delta = 0, $edit = array()) {
function book_block($op = 'list', $delta = '', $edit = array()) {
$block = array();
switch ($op) {
case 'list':
$block[0]['info'] = t('Book navigation');
$block[0]['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE;
$block['navigation']['info'] = t('Book navigation');
$block['navigation']['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE;
return $block;
case 'view':
$current_bid = 0;
......
......@@ -284,10 +284,10 @@ function comment_perm() {
*
* Generates a block with the most recent comments.
*/
function comment_block($op = 'list', $delta = 0, $edit = array()) {
function comment_block($op = 'list', $delta = '', $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Recent comments');
$blocks['recent']['info'] = t('Recent comments');
return $blocks;
case 'configure':
......
......@@ -57,8 +57,8 @@ function forum_uninstall() {
variable_del('forum_hot_topic');
variable_del('forum_per_page');
variable_del('forum_order');
variable_del('forum_block_num_0');
variable_del('forum_block_num_1');
variable_del('forum_block_num_active');
variable_del('forum_block_num_new');
}
/**
......
......@@ -401,11 +401,11 @@ function forum_load($node) {
* Generates a block containing the currently active forum topics and the
* most recently added forum topics.
*/
function forum_block($op = 'list', $delta = 0, $edit = array()) {
function forum_block($op = 'list', $delta = '', $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Active forum topics');
$blocks[1]['info'] = t('New forum topics');
$blocks['active']['info'] = t('Active forum topics');
$blocks['new']['info'] = t('New forum topics');
return $blocks;
case 'configure':
......@@ -419,17 +419,17 @@ function forum_block($op = 'list', $delta = 0, $edit = array()) {
case 'view':
if (user_access('access content')) {
switch ($delta) {
case 0:
case 'active':
$title = t('Active forum topics');
$sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid INNER JOIN {term_data} td ON td.tid = tn.tid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND td.vid = %d ORDER BY l.last_comment_timestamp DESC");
$result = db_query_range($sql, variable_get('forum_nav_vocabulary', ''), 0, variable_get('forum_block_num_0', '5'));
$result = db_query_range($sql, variable_get('forum_nav_vocabulary', ''), 0, variable_get('forum_block_num_active', '5'));
$content = node_title_list($result);
break;
case 1:
case 'new':
$title = t('New forum topics');
$sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid INNER JOIN {term_data} td ON td.tid = tn.tid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND td.vid = %d ORDER BY n.nid DESC");
$result = db_query_range($sql, variable_get('forum_nav_vocabulary', ''), 0, variable_get('forum_block_num_1', '5'));
$result = db_query_range($sql, variable_get('forum_nav_vocabulary', ''), 0, variable_get('forum_block_num_new', '5'));
$content = node_title_list($result);
break;
}
......
......@@ -556,11 +556,11 @@ function locale_update_js_files() {
* Implementation of hook_block().
* Displays a language switcher. Translation links may be provided by other modules.
*/
function locale_block($op = 'list', $delta = 0) {
function locale_block($op = 'list', $delta = '') {
if ($op == 'list') {
$block[0]['info'] = t('Language switcher');
$block['language-switcher']['info'] = t('Language switcher');
// Not worth caching.
$block[0]['cache'] = BLOCK_NO_CACHE;
$block['language-switcher']['cache'] = BLOCK_NO_CACHE;
return $block;
}
......
......@@ -260,7 +260,7 @@ function menu_reset_item($item) {
/**
* Implementation of hook_block().
*/
function menu_block($op = 'list', $delta = 0) {
function menu_block($op = 'list', $delta = '') {
$menus = menu_get_menus();
// The Navigation menu is handled by the user module.
unset($menus['navigation']);
......
......@@ -1607,11 +1607,11 @@ function node_revision_list($node) {
/**
* Implementation of hook_block().
*/
function node_block($op = 'list', $delta = 0) {
function node_block($op = 'list', $delta = '') {
if ($op == 'list') {
$blocks[0]['info'] = t('Syndicate');
$blocks['syndicate']['info'] = t('Syndicate');
// Not worth caching.
$blocks[0]['cache'] = BLOCK_NO_CACHE;
$blocks['syndicate']['cache'] = BLOCK_NO_CACHE;
return $blocks;
}
else if ($op == 'view') {
......
......@@ -134,10 +134,10 @@ function _poll_menu_access($node, $perm, $inspect_allowvotes) {
*
* Generates a block containing the latest poll.
*/
function poll_block($op = 'list', $delta = 0) {
function poll_block($op = 'list', $delta = '') {
if (user_access('access content')) {
if ($op == 'list') {
$blocks[0]['info'] = t('Most recent poll');
$blocks['recent']['info'] = t('Most recent poll');
return $blocks;
}
else if ($op == 'view') {
......
......@@ -131,14 +131,14 @@ function profile_menu() {
/**
* Implementation of hook_block().
*/
function profile_block($op = 'list', $delta = 0, $edit = array()) {
function profile_block($op = 'list', $delta = '', $edit = array()) {
if ($op == 'list') {
$blocks[0]['info'] = t('Author information');
$blocks[0]['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE;
$blocks['author-information']['info'] = t('Author information');
$blocks['author-information']['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE;
return $blocks;
}
else if ($op == 'configure' && $delta == 0) {
else if ($op == 'configure') {
// Compile a list of fields to show
$fields = array();
$result = db_query('SELECT name, title, weight, visibility FROM {profile_fields} WHERE visibility IN (%d, %d) ORDER BY weight', PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS);
......@@ -146,7 +146,8 @@ function profile_block($op = 'list', $delta = 0, $edit = array()) {
$fields[$record->name] = check_plain($record->title);
}
$fields['user_profile'] = t('Link to full user profile');
$form['profile_block_author_fields'] = array('#type' => 'checkboxes',
$form['profile_block_author_fields'] = array(
'#type' => 'checkboxes',
'#title' => t('Profile fields to display'),
'#default_value' => variable_get('profile_block_author_fields', NULL),
'#options' => $fields,
......@@ -154,7 +155,7 @@ function profile_block($op = 'list', $delta = 0, $edit = array()) {
);
return $form;
}
else if ($op == 'save' && $delta == 0) {
else if ($op == 'save') {
variable_set('profile_block_author_fields', $edit['profile_block_author_fields']);
}
else if ($op == 'view') {
......
......@@ -151,11 +151,11 @@ function search_perm() {
/**
* Implementation of hook_block().
*/
function search_block($op = 'list', $delta = 0) {
function search_block($op = 'list', $delta = '') {
if ($op == 'list') {
$blocks[0]['info'] = t('Search form');
$blocks['form']['info'] = t('Search form');
// Not worth caching.
$blocks[0]['cache'] = BLOCK_NO_CACHE;
$blocks['form']['cache'] = BLOCK_NO_CACHE;
return $blocks;
}
else if ($op == 'view' && user_access('search content')) {
......
......@@ -242,13 +242,13 @@ function statistics_get($nid) {
/**
* Implementation of hook_block().
*/
function statistics_block($op = 'list', $delta = 0, $edit = array()) {
function statistics_block($op = 'list', $delta = '', $edit = array()) {
switch ($op) {
case 'list':
if (variable_get('statistics_count_content_views', 0)) {
$blocks[0]['info'] = t('Popular content');
$blocks['popular']['info'] = t('Popular content');
// Too dynamic to cache.
$blocks[0]['cache'] = BLOCK_NO_CACHE;
$blocks['popular']['cache'] = BLOCK_NO_CACHE;
return $blocks;
}
break;
......
......@@ -10,7 +10,7 @@
* - $block->subject: Block title.
* - $block->content: Block content.
* - $block->module: Module that generated the block.
* - $block->delta: This is a numeric id connected to each module.
* - $block->delta: An ID for the block, unique within each module.
* - $block->region: The block region embedding the current block.
*
* Helper variables:
......
......@@ -374,9 +374,9 @@ function system_install() {
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'theme_default', 's:7:"garland";');
db_query("UPDATE {system} SET status = %d WHERE type = '%s' AND name = '%s'", 1, 'theme', 'garland');
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, pages, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s', %d)", 'user', '0', 'garland', 1, 0, 'left', '', -1);
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, pages, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s', %d)", 'user', '1', 'garland', 1, 0, 'left', '', -1);
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, pages, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s', %d)", 'system', '0', 'garland', 1, 10, 'footer', '', -1);
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, pages, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s', %d)", 'user', 'login', 'garland', 1, 0, 'left', '', -1);
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, pages, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s', %d)", 'user', 'navigation', 'garland', 1, 0, 'left', '', -1);
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, pages, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s', %d)", 'system', 'powered-by', 'garland', 1, 10, 'footer', '', -1);
db_query("INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, '%s', %d, %d, %d)", 0, 0, 'all', 1, 0, 0);
......@@ -2755,6 +2755,95 @@ function system_update_7003() {
return $ret;
}
/**
* Remove hardcoded numeric deltas from all blocks in core.
*/
function system_update_7004(&$sandbox) {
$ret = array();
// Get an array of the renamed block deltas, organized by module.
$renamed_deltas = array(
'blog' => array('0' => 'recent'),
'book' => array('0' => 'navigation'),
'comment' => array('0' => 'recent'),
'forum' => array(
'0' => 'active',
'1' => 'new',
),
'locale' => array('0' => 'language-switcher'),
'node' => array('0' => 'syndicate'),
'poll' => array('0' => 'recent'),
'profile' => array('0' => 'author-information'),
'search' => array('0' => 'form'),
'statistics' => array('0' => 'popular'),
'system' => array('0' => 'powered-by'),
'user' => array(
'0' => 'login',
'1' => 'navigation',
'2' => 'new',
'3' => 'online',
),
);
// Loop through each block and make changes to the core block tables.
// Only run this the first time through the batch update.
if (!isset($sandbox['progress'])) {
$block_tables = array('blocks', 'blocks_roles');
foreach ($block_tables as $table) {
foreach ($renamed_deltas as $module => $deltas) {
foreach ($deltas as $old_delta => $new_delta) {
// Only do the update if the old block actually exists.
if (db_result(db_query("SELECT COUNT(*) FROM {". $table ."} WHERE module = '%s' AND delta = '%s'", $module, $old_delta))) {
$ret[] = update_sql("UPDATE {". $table ."} SET delta = '". $new_delta ."' WHERE module = '". $module ."' AND delta = '". $old_delta ."'");
}
}
}
}
// Rename forum module's block variables.
$forum_block_num_0 = variable_get('forum_block_num_0', NULL);
if (isset($forum_block_num_0)) {
variable_set('forum_block_num_active', $forum_block_num_0);
variable_del('forum_block_num_0');
}
$forum_block_num_1 = variable_get('forum_block_num_1', NULL);
if (isset($forum_block_num_1)) {
variable_set('forum_block_num_new', $forum_block_num_1);
variable_del('forum_block_num_1');
}
// Initialize batch update information.
$sandbox['progress'] = 0;
$sandbox['last_user_processed'] = -1;
$sandbox['max'] = db_result(db_query("SELECT COUNT(*) FROM {users} WHERE data IS NOT NULL"));
}
// Now do the batch update of the user-specific block visibility settings.
$limit = 100;
$result = db_query_range("SELECT uid, data FROM {users} WHERE uid > %d AND data IS NOT NULL", $sandbox['last_user_processed'], 0, $limit);
while ($row = db_fetch_object($result)) {
$data = unserialize($row->data);
$user_needs_update = FALSE;
foreach ($renamed_deltas as $module => $deltas) {
foreach ($deltas as $old_delta => $new_delta) {
if (isset($data['block'][$module][$old_delta])) {
// Transfer the old block visibility settings to the newly-renamed
// block, and mark this user for a database update.
$data['block'][$module][$new_delta] = $data['block'][$module][$old_delta];
unset($data['block'][$module][$old_delta]);
$user_needs_update = TRUE;
}
}
}
// Update the current user.
if ($user_needs_update) {
db_query("UPDATE {users} SET data = '%s' WHERE uid = %d", serialize($data), $row->uid);
}
// Update our progress information for the batch update.
$sandbox['progress']++;
$sandbox['last_user_processed'] = $row->uid;
}
// Indicate our current progress to the batch update system.
if ($sandbox['progress'] < $sandbox['max']) {
$ret['#finished'] = $sandbox['progress'] / $sandbox['max'];
}
return $ret;
}
/**
* @} End of "defgroup updates-6.x-to-7.x"
......
......@@ -728,10 +728,10 @@ function system_user($type, $edit, &$user, $category = NULL) {
*
* Generate a block with a promotional link to Drupal.org.
*/
function system_block($op = 'list', $delta = 0, $edit = NULL) {
function system_block($op = 'list', $delta = '', $edit = NULL) {
switch ($op) {
case 'list':
$blocks[0] = array(
$blocks['powered-by'] = array(
'info' => t('Powered by Drupal'),
'weight' => '10',
// Not worth caching.
......
......@@ -635,27 +635,27 @@ function user_login_block() {
/**
* Implementation of hook_block().
*/
function user_block($op = 'list', $delta = 0, $edit = array()) {
function user_block($op = 'list', $delta = '', $edit = array()) {
global $user;
if ($op == 'list') {
$blocks[0]['info'] = t('User login');
$blocks['login']['info'] = t('User login');
// Not worth caching.
$blocks[0]['cache'] = BLOCK_NO_CACHE;
$blocks['login']['cache'] = BLOCK_NO_CACHE;
$blocks[1]['info'] = t('Navigation');
$blocks['navigation']['info'] = t('Navigation');
// Menu blocks can't be cached because each menu item can have
// a custom access callback. menu.inc manages its own caching.
$blocks[1]['cache'] = BLOCK_NO_CACHE;
$blocks['navigation']['cache'] = BLOCK_NO_CACHE;
$blocks[2]['info'] = t('Who\'s new');
$blocks['new']['info'] = t('Who\'s new');
// Too dynamic to cache.
$blocks[3]['info'] = t('Who\'s online');
$blocks[3]['cache'] = BLOCK_NO_CACHE;
$blocks['online']['info'] = t('Who\'s online');
$blocks['online']['cache'] = BLOCK_NO_CACHE;
return $blocks;
}
else if ($op == 'configure' && $delta == 2) {
else if ($op == 'configure' && $delta == 'new') {
$form['user_block_whois_new_count'] = array(
'#type' => 'select',
'#title' => t('Number of users to display'),
......@@ -664,17 +664,17 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
);
return $form;
}
else if ($op == 'configure' && $delta == 3) {
else if ($op == 'configure' && $delta == 'online') {
$period = drupal_map_assoc(array(30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 43200, 86400), 'format_interval');
$form['user_block_seconds_online'] = array('#type' => 'select', '#title' => t('User activity'), '#default_value' => variable_get('user_block_seconds_online', 900), '#options' => $period, '#description' => t('A user is considered online for this long after they have last viewed a page.'));
$form['user_block_max_list_count'] = array('#type' => 'select', '#title' => t('User list length'), '#default_value' => variable_get('user_block_max_list_count', 10), '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), '#description' => t('Maximum number of currently online users to display.'));
return $form;
}
else if ($op == 'save' && $delta == 2) {
else if ($op == 'save' && $delta == 'new') {
variable_set('user_block_whois_new_count', $edit['user_block_whois_new_count']);
}
else if ($op == 'save' && $delta == 3) {
else if ($op == 'save' && $delta == 'online') {
variable_set('user_block_seconds_online', $edit['user_block_seconds_online']);
variable_set('user_block_max_list_count', $edit['user_block_max_list_count']);
}
......@@ -682,7 +682,7 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
$block = array();
switch ($delta) {
case 0:
case 'login':
// For usability's sake, avoid showing two login forms on one page.
if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
......@@ -691,14 +691,14 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
}
return $block;
case 1:
case 'navigation':
if ($menu = menu_tree()) {
$block['subject'] = $user->uid ? check_plain($user->name) : t('Navigation');
$block['content'] = $menu;
}
return $block;
case 2:
case 'new':
if (user_access('access content')) {
// Retrieve a list of new users who have subsequently accessed the site successfully.
$result = db_query_range('SELECT uid, name FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC', 0, variable_get('user_block_whois_new_count', 5));
......@@ -712,7 +712,7 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
}
return $block;
case 3:
case 'online':
if (user_access('access content')) {
// Count users active within the defined period.
$interval = time() - variable_get('user_block_seconds_online', 900);
......
......@@ -220,17 +220,17 @@ html.js fieldset.collapsed legend a {
/**
* Syndication Block
*/
#block-node-0 h2 {
#block-node-syndicate h2 {
float: right;
padding-right: 0;
padding-left: 20px;
}
#block-node-0 img {
#block-node-syndicate img {
float: left;
}
#block-node-0 .content {
#block-node-syndicate .content {
clear: left;
}
......
......@@ -865,17 +865,17 @@ html.js fieldset.collapsed legend a {
/**
* Syndication icons and block
*/
#block-node-0 h2 {
#block-node-syndicate h2 {
float: left; /* LTR */
padding-right: 20px; /* LTR */
}
#block-node-0 img, .feed-icon {
#block-node-syndicate img, .feed-icon {
float: right; /* LTR */
padding-top: 4px;
}
#block-node-0 .content {
#block-node-syndicate .content {
clear: right; /* LTR */
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment