Commit b3adcf05 authored by Dries's avatar Dries
Browse files

- Patch #11875 by Neil Drumm: block module configuration improvements.

The primary goal of this patch is to take the 'custom' and 'path' columns of the block overview page and make them into something understandable. As of Drupal 4.5 'custom' lacked an explanation which wasn't buried in help text and path required dealing with regular expressions.

Every block now has a configuration page to control these options. This gives more space to make form controls which do not require a lengthy explanation. This page also gives modules a chance to put their block configuration options in a place that makes sense using new operations in the block hook.

The only required changes to modules implementing hook_block() is to be careful about what is returned. Do not return anything if $op is not 'list' or 'view'. Once this change is made, modules will still be compatible with Drupal 4.5. Required changes to core modules are included in this path.

An additional optional change to modules is to implement the additional $op options added. 'configure' should return a string containing the configuration form for the block with the appropriate $delta. 'configure save' will come with an additional $edit argument, which will contain the submitted form data for saving. These changes to core modules are also included in this patch.
parent 8daed9cb
......@@ -121,9 +121,10 @@ CREATE TABLE blocks (
status tinyint(2) DEFAULT '0' NOT NULL,
weight tinyint(1) DEFAULT '0' NOT NULL,
region tinyint(1) DEFAULT '0' NOT NULL,
path varchar(255) DEFAULT '' NOT NULL,
custom tinyint(2) DEFAULT '0' NOT NULL,
throttle tinyint(1) DEFAULT '0' NOT NULL
throttle tinyint(1) DEFAULT '0' NOT NULL,
visibility tinyint(1) DEFAULT '0' NOT NULL,
pages text NOT NULL
) TYPE=MyISAM;
--
......
......@@ -86,7 +86,7 @@
"2004-09-17" => "update_107",
"2004-10-16" => "update_108",
"2004-10-18" => "update_109",
"2004-10-28: first update since Drupal 4.5.0 release" => "update_110"
"2004-10-31: first update since Drupal 4.5.0 release" => "update_110"
);
function update_32() {
......@@ -1927,6 +1927,10 @@ function update_110() {
// TODO: needs PGSQL version
if ($GLOBALS['db_type'] == 'mysql') {
/*
** Search
*/
$ret[] = update_sql('DROP TABLE {search_index}');
$ret[] = update_sql("CREATE TABLE {search_index} (
word varchar(50) NOT NULL default '',
......@@ -1946,8 +1950,18 @@ function update_110() {
) TYPE=MyISAM");
$ret[] = update_sql("DELETE FROM {variable} WHERE name = 'node_cron_last'");
/*
** Blocks
*/
$ret[] = update_sql('ALTER TABLE {blocks} DROP path');
$ret[] = update_sql('ALTER TABLE {blocks} ADD visibility tinyint(1) NOT NULL');
$ret[] = update_sql('ALTER TABLE {blocks} ADD pages text NOT NULL');
}
$ret[] = update_sql('UPDATE {blocks} SET status = 1, custom = 2 WHERE status = 0 AND custom = 1');
return $ret;
}
......
......@@ -231,7 +231,7 @@ function aggregator_block($op, $delta) {
$block['feed:'. $feed->fid]['info'] = t('%title feed latest items', array('%title' => $feed->title));
}
}
else {
else if ($op == 'view') {
list($type, $id) = split(':', $delta);
switch ($type) {
case 'feed':
......
......@@ -231,7 +231,7 @@ function aggregator_block($op, $delta) {
$block['feed:'. $feed->fid]['info'] = t('%title feed latest items', array('%title' => $feed->title));
}
}
else {
else if ($op == 'view') {
list($type, $id) = split(':', $delta);
switch ($type) {
case 'feed':
......
......@@ -182,7 +182,7 @@ function archive_block($op = 'list', $delta = 0) {
$blocks[0]['info'] = t('Calendar to browse archives');
return $blocks;
}
else if (user_access('access content')) {
else if ($op == 'view' && user_access('access content')) {
$block['subject'] = t('Browse archives');
$block['content'] = archive_calendar();
return $block;
......
......@@ -182,7 +182,7 @@ function archive_block($op = 'list', $delta = 0) {
$blocks[0]['info'] = t('Calendar to browse archives');
return $blocks;
}
else if (user_access('access content')) {
else if ($op == 'view' && user_access('access content')) {
$block['subject'] = t('Browse archives');
$block['content'] = archive_calendar();
return $block;
......
This diff is collapsed.
This diff is collapsed.
......@@ -291,7 +291,7 @@ function blog_block($op = 'list', $delta = 0) {
$block[0]['info'] = t('Recent blog posts');
return $block;
}
else {
else if ($op == 'view') {
if (user_access('access content')) {
$block['content'] = node_title_list(db_query_range('SELECT DISTINCT(n.nid), n.title, n.created FROM {node} n '. node_access_join_sql() ." WHERE n.type = 'blog' AND n.status = 1 AND ". node_access_where_sql() .' ORDER BY n.created DESC', 0, 10));
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
......
......@@ -291,7 +291,7 @@ function blog_block($op = 'list', $delta = 0) {
$block[0]['info'] = t('Recent blog posts');
return $block;
}
else {
else if ($op == 'view') {
if (user_access('access content')) {
$block['content'] = node_title_list(db_query_range('SELECT DISTINCT(n.nid), n.title, n.created FROM {node} n '. node_access_join_sql() ." WHERE n.type = 'blog' AND n.status = 1 AND ". node_access_where_sql() .' ORDER BY n.created DESC', 0, 10));
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
......
......@@ -135,8 +135,9 @@ function book_block($op = 'list', $delta = 0) {
$block = array();
if ($op == 'list') {
$block[0]['info'] = t('Book navigation');
return $block;
}
else {
else if ($op == 'view') {
// Only display this block when the user is browsing a book:
if (arg(0) == 'node' && is_numeric(arg(1))) {
$result = db_query('SELECT n.nid, n.title, b.parent FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND n.nid = %d', arg(1));
......@@ -155,9 +156,9 @@ function book_block($op = 'list', $delta = 0) {
$block['content'] = book_tree($expand[0], 5, $expand);
}
}
}
return $block;
return $block;
}
}
/**
......
......@@ -135,8 +135,9 @@ function book_block($op = 'list', $delta = 0) {
$block = array();
if ($op == 'list') {
$block[0]['info'] = t('Book navigation');
return $block;
}
else {
else if ($op == 'view') {
// Only display this block when the user is browsing a book:
if (arg(0) == 'node' && is_numeric(arg(1))) {
$result = db_query('SELECT n.nid, n.title, b.parent FROM {node} n '. node_access_join_sql() .' INNER JOIN {book} b ON n.nid = b.nid WHERE '. node_access_where_sql() .' AND n.nid = %d', arg(1));
......@@ -155,9 +156,9 @@ function book_block($op = 'list', $delta = 0) {
$block['content'] = book_tree($expand[0], 5, $expand);
}
}
}
return $block;
return $block;
}
}
/**
......
......@@ -156,7 +156,7 @@ function comment_block($op = 'list', $delta = 0) {
$blocks[0]['info'] = t('Recent comments');
return $blocks;
}
else if (user_access('access comments')) {
else if ($op == 'view' && user_access('access comments')) {
$result = db_query_range('SELECT * FROM {comments} WHERE status = 0 ORDER BY timestamp DESC', 0, 10);
$items = array();
while ($comment = db_fetch_object($result)) {
......
......@@ -156,7 +156,7 @@ function comment_block($op = 'list', $delta = 0) {
$blocks[0]['info'] = t('Recent comments');
return $blocks;
}
else if (user_access('access comments')) {
else if ($op == 'view' && user_access('access comments')) {
$result = db_query_range('SELECT * FROM {comments} WHERE status = 0 ORDER BY timestamp DESC', 0, 10);
$items = array();
while ($comment = db_fetch_object($result)) {
......
......@@ -78,9 +78,6 @@ function forum_settings() {
$group .= form_select(t('Topics per page'), 'forum_per_page', variable_get('forum_per_page', 25), drupal_map_assoc(array(10, 25, 50, 75, 100)), t('The default number of topics displayed per page; links to browse older messages are automatically being displayed.'));
$group .= form_radios(t('Default order'), 'forum_order', variable_get('forum_order', '1'), array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4=> t('Posts - least active first')), t('The default display order for topics.'));
$output .= form_group(t('Forum viewing options'), $group);
$group = form_select(t('Number of topics in block'), 'forum_block_num', variable_get('forum_block_num', '5'), drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)), t('The number of topics to show in the "Forum topics" block. To enable the block, go to the <a href="%block-administration">block administration</a> page.', array('%block-administration' => url('admin/block'))));
$output .= form_group(t('"Forum topic" block settings'), $group);
}
}
......@@ -114,27 +111,36 @@ 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) {
function forum_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Forum topics');
return $blocks;
case 'configure':
$output = form_select(t('Number of topics in block'), 'forum_block_num', variable_get('forum_block_num', '5'), drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
return $output;
case 'save':
variable_set('forum_block_num', $edit['forum_block_num']);
break;
if ($op == 'list') {
$blocks[0]['info'] = t('Forum topics');
}
else {
if (user_access('access content')) {
$content = node_title_list(db_query_range("SELECT n.nid, n.title, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ". node_access_join_sql() ." WHERE n.status = 1 AND n.type='forum' AND ". node_access_where_sql() ." ORDER BY l.last_comment_timestamp DESC", 0, variable_get('forum_block_num', '5')), t('Active forum topics:'));
case 'view':
if (user_access('access content')) {
$content = node_title_list(db_query_range("SELECT n.nid, n.title, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ". node_access_join_sql() ." WHERE n.status = 1 AND n.type='forum' AND ". node_access_where_sql() ." ORDER BY l.last_comment_timestamp DESC", 0, variable_get('forum_block_num', '5')), t('Active forum topics:'));
$content .= node_title_list(db_query_range("SELECT n.nid, n.title FROM {node} n ". node_access_join_sql() ." WHERE n.type = 'forum' AND n.status = 1 AND ". node_access_where_sql() ." ORDER BY n.nid DESC", 0, variable_get('forum_block_num', '5')), t('New forum topics:'));
$content .= node_title_list(db_query_range("SELECT n.nid, n.title FROM {node} n ". node_access_join_sql() ." WHERE n.type = 'forum' AND n.status = 1 AND ". node_access_where_sql() ." ORDER BY n.nid DESC", 0, variable_get('forum_block_num', '5')), t('New forum topics:'));
if ($content) {
$content .= '<div class="more-link">'. l(t('more'), 'forum', array('title' => t('Read the latest forum topics.'))) .'</div>';
}
if ($content) {
$content .= '<div class="more-link">'. l(t('more'), 'forum', array('title' => t('Read the latest forum topics.'))) .'</div>';
}
$blocks['subject'] = t('Forum topics');
$blocks['content'] = $content;
}
}
$block['subject'] = t('Forum topics');
$block['content'] = $content;
return $blocks;
return $block;
}
}
}
/**
......
......@@ -78,9 +78,6 @@ function forum_settings() {
$group .= form_select(t('Topics per page'), 'forum_per_page', variable_get('forum_per_page', 25), drupal_map_assoc(array(10, 25, 50, 75, 100)), t('The default number of topics displayed per page; links to browse older messages are automatically being displayed.'));
$group .= form_radios(t('Default order'), 'forum_order', variable_get('forum_order', '1'), array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4=> t('Posts - least active first')), t('The default display order for topics.'));
$output .= form_group(t('Forum viewing options'), $group);
$group = form_select(t('Number of topics in block'), 'forum_block_num', variable_get('forum_block_num', '5'), drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)), t('The number of topics to show in the "Forum topics" block. To enable the block, go to the <a href="%block-administration">block administration</a> page.', array('%block-administration' => url('admin/block'))));
$output .= form_group(t('"Forum topic" block settings'), $group);
}
}
......@@ -114,27 +111,36 @@ 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) {
function forum_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Forum topics');
return $blocks;
case 'configure':
$output = form_select(t('Number of topics in block'), 'forum_block_num', variable_get('forum_block_num', '5'), drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
return $output;
case 'save':
variable_set('forum_block_num', $edit['forum_block_num']);
break;
if ($op == 'list') {
$blocks[0]['info'] = t('Forum topics');
}
else {
if (user_access('access content')) {
$content = node_title_list(db_query_range("SELECT n.nid, n.title, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ". node_access_join_sql() ." WHERE n.status = 1 AND n.type='forum' AND ". node_access_where_sql() ." ORDER BY l.last_comment_timestamp DESC", 0, variable_get('forum_block_num', '5')), t('Active forum topics:'));
case 'view':
if (user_access('access content')) {
$content = node_title_list(db_query_range("SELECT n.nid, n.title, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ". node_access_join_sql() ." WHERE n.status = 1 AND n.type='forum' AND ". node_access_where_sql() ." ORDER BY l.last_comment_timestamp DESC", 0, variable_get('forum_block_num', '5')), t('Active forum topics:'));
$content .= node_title_list(db_query_range("SELECT n.nid, n.title FROM {node} n ". node_access_join_sql() ." WHERE n.type = 'forum' AND n.status = 1 AND ". node_access_where_sql() ." ORDER BY n.nid DESC", 0, variable_get('forum_block_num', '5')), t('New forum topics:'));
$content .= node_title_list(db_query_range("SELECT n.nid, n.title FROM {node} n ". node_access_join_sql() ." WHERE n.type = 'forum' AND n.status = 1 AND ". node_access_where_sql() ." ORDER BY n.nid DESC", 0, variable_get('forum_block_num', '5')), t('New forum topics:'));
if ($content) {
$content .= '<div class="more-link">'. l(t('more'), 'forum', array('title' => t('Read the latest forum topics.'))) .'</div>';
}
if ($content) {
$content .= '<div class="more-link">'. l(t('more'), 'forum', array('title' => t('Read the latest forum topics.'))) .'</div>';
}
$blocks['subject'] = t('Forum topics');
$blocks['content'] = $content;
}
}
$block['subject'] = t('Forum topics');
$block['content'] = $content;
return $blocks;
return $block;
}
}
}
/**
......
......@@ -84,7 +84,7 @@ function menu_block($op = 'list', $delta = 0) {
}
return $blocks;
}
else {
else if ($op == 'view') {
$data['subject'] = $menu['items'][$delta]['title'];
$data['content'] = '<div class="menu">'. theme('menu_tree', $delta) .'</div>' ;
return $data;
......
......@@ -84,7 +84,7 @@ function menu_block($op = 'list', $delta = 0) {
}
return $blocks;
}
else {
else if ($op == 'view') {
$data['subject'] = $menu['items'][$delta]['title'];
$data['content'] = '<div class="menu">'. theme('menu_tree', $delta) .'</div>' ;
return $data;
......
......@@ -968,7 +968,7 @@ function node_block($op = 'list', $delta = 0) {
$blocks[0]['info'] = t('Syndicate');
return $blocks;
}
else {
else if ($op == 'view') {
$block['subject'] = t('Syndicate');
$block['content'] = theme('xml_icon', url('node/feed'));
......
......@@ -968,7 +968,7 @@ function node_block($op = 'list', $delta = 0) {
$blocks[0]['info'] = t('Syndicate');
return $blocks;
}
else {
else if ($op == 'view') {
$block['subject'] = t('Syndicate');
$block['content'] = theme('xml_icon', url('node/feed'));
......
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