Commit 574a2e47 authored by Dries's avatar Dries

- Patch #345866 by alexanderpas, justinrandell, Dave Reid: remove from hook_block().

parent 18d22419
......@@ -171,14 +171,14 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
);
// Module-specific block configurations.
if ($settings = module_invoke($module, 'block', 'configure', $delta)) {
if ($settings = module_invoke($module, 'block_configure', $delta)) {
foreach ($settings as $k => $v) {
$form['block_settings'][$k] = $v;
}
}
// Get the block subject for the page title.
$info = module_invoke($module, 'block', 'list');
$info = module_invoke($module, 'block_list');
if (isset($info[$delta])) {
drupal_set_title(t("'%name' block", array('%name' => $info[$delta]['info'])), PASS_THROUGH);
}
......@@ -285,7 +285,7 @@ function block_admin_configure_submit($form, &$form_state) {
foreach (array_filter($form_state['values']['roles']) as $rid) {
db_query("INSERT INTO {block_role} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $form_state['values']['delta']);
}
module_invoke($form_state['values']['module'], 'block', 'save', $form_state['values']['delta'], $form_state['values']);
module_invoke($form_state['values']['module'], 'block_save', $form_state['values']['delta'], $form_state['values']);
drupal_set_message(t('The block configuration has been saved.'));
cache_clear_all();
$form_state['redirect'] = 'admin/build/block';
......
This diff is collapsed.
......@@ -166,4 +166,11 @@ function block_schema() {
$schema['cache_block']['description'] = 'Cache table for the Block module to store already built blocks, identified by module, delta, and various contexts which may change the block, such as theme, locale, and caching mode defined for the block.';
return $schema;
}
\ No newline at end of file
}
/**
* Refresh the block cache.
*/
function block_update_7000() {
return array();
}
......@@ -15,7 +15,7 @@
* Constants defining cache granularity for blocks.
*
* Modules specify the caching patterns for their blocks using binary
* combinations of these constants in their hook_block(op 'list'):
* combinations of these constants in their hook_block_list():
* $block[delta]['cache'] = BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE;
* BLOCK_CACHE_PER_ROLE is used as a default when no caching pattern is
* specified.
......@@ -180,44 +180,51 @@ function _block_themes_access($theme) {
}
/**
* Implementation of hook_block().
*
* Generates the administrator-defined blocks for display.
* Implementation of hook_block_list().
*/
function block_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks = array();
$result = db_query('SELECT bid, info FROM {box} ORDER BY info');
while ($block = db_fetch_object($result)) {
$blocks[$block->bid]['info'] = $block->info;
// Not worth caching.
$blocks[$block->bid]['cache'] = BLOCK_NO_CACHE;
}
return $blocks;
case 'configure':
$box = array('format' => FILTER_FORMAT_DEFAULT);
if ($delta) {
$box = block_box_get($delta);
}
if (filter_access($box['format'])) {
return block_box_form($box);
}
break;
function block_block_list() {
$blocks = array();
case 'save':
block_box_save($edit, $delta);
break;
$result = db_query('SELECT bid, info FROM {box} ORDER BY info');
while ($block = db_fetch_object($result)) {
$blocks[$block->bid]['info'] = $block->info;
// Not worth caching.
$blocks[$block->bid]['cache'] = BLOCK_NO_CACHE;
}
return $blocks;
}
case 'view':
$block = db_fetch_object(db_query('SELECT body, format FROM {box} WHERE bid = %d', $delta));
$data['content'] = check_markup($block->body, $block->format, '', FALSE);
return $data;
/**
* Implementation of hook_block_configure().
*/
function block_block_configure($delta = 0, $edit = array()) {
$box = array('format' => FILTER_FORMAT_DEFAULT);
if ($delta) {
$box = block_box_get($delta);
}
if (filter_access($box['format'])) {
return block_box_form($box);
}
}
/**
* Implementation of hook_block_save().
*/
function block_block_save($delta = 0, $edit = array()) {
block_box_save($edit, $delta);
}
/**
* Implementation of hook_block_view().
*
* Generates the administrator-defined blocks for display.
*/
function block_block_view($delta = 0, $edit = array()) {
$block = db_fetch_object(db_query('SELECT body, format FROM {box} WHERE bid = %d', $delta));
$data['content'] = check_markup($block->body, $block->format, '', FALSE);
return $data;
}
/**
* Update the 'block' DB table with the blocks currently exported by modules.
*
......@@ -239,8 +246,8 @@ function _block_rehash() {
// Valid region names for the theme.
$regions = system_region_list($theme_key);
foreach (module_implements('block') as $module) {
$module_blocks = module_invoke($module, 'block', 'list');
foreach (module_implements('block_list') as $module) {
$module_blocks = module_invoke($module, 'block_list');
if ($module_blocks) {
foreach ($module_blocks as $delta => $block) {
if (empty($old_blocks[$module][$delta])) {
......@@ -349,7 +356,7 @@ function block_user_form(&$edit, &$account, $category = NULL) {
$result = db_query("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom != 0 AND (r.rid IN (" . db_placeholders($rids) . ") OR r.rid IS NULL) ORDER BY b.weight, b.module", $rids);
$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');
$data = module_invoke($block->module, 'block_list');
if ($data[$block->delta]['info']) {
$return = TRUE;
$form['block'][$block->module][$block->delta] = array('#type' => 'checkbox', '#title' => check_plain($data[$block->delta]['info']), '#default_value' => isset($account->block[$block->module][$block->delta]) ? $account->block[$block->module][$block->delta] : ($block->custom == 1));
......@@ -483,7 +490,7 @@ function _block_render_blocks($region_blocks) {
$array = $cache->data;
}
else {
$array = module_invoke($block->module, 'block', 'view', $block->delta);
$array = module_invoke($block->module, 'block_view', $block->delta);
if (isset($cid)) {
cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY);
}
......
......@@ -2,6 +2,8 @@
// $Id$
class BlockTestCase extends DrupalWebTestCase {
protected $regions;
function getInfo() {
return array(
'name' => t('Block functionality'),
......@@ -16,6 +18,14 @@ class BlockTestCase extends DrupalWebTestCase {
// Create and login user
$admin_user = $this->drupalCreateUser(array('administer blocks', 'administer filters'));
$this->drupalLogin($admin_user);
// Define the exising regions
$this->regions = array();
$this->regions[] = array('name' => 'header', 'id' => 'header-region');
$this->regions[] = array('name' => 'left', 'id' => 'sidebar-left');
$this->regions[] = array('name' => 'content', 'id' => 'center');
$this->regions[] = array('name' => 'right', 'id' => 'sidebar-right');
$this->regions[] = array('name' => 'footer');
}
/**
......@@ -36,17 +46,12 @@ class BlockTestCase extends DrupalWebTestCase {
// Check to see if the box was created by checking that it's in the database..
$this->assertNotNull($bid, t('Box found in database'));
// Set the created box to a specific region.
// TODO: Implement full region checking.
$edit = array();
$edit['block_' . $bid . '[region]'] = 'left';
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
// Confirm that the box was moved to the proper region.
$this->assertText(t('The block settings have been updated.'), t('Box successfully moved to left region.'));
// Confirm that the box is being displayed.
$this->assertText(t($box['title']), t('Box successfully being displayed on the page.'));
// Check if the block can be moved to all availble regions.
$box['module'] = 'block';
$box['delta'] = $bid;
foreach ($this->regions as $region) {
$this->moveBlockToRegion($box, $region);
}
// Delete the created box & verify that it's been deleted and no longer appearing on the page.
$this->drupalPost('admin/build/block/delete/' . $bid, array(), t('Delete'));
......@@ -94,17 +99,10 @@ class BlockTestCase extends DrupalWebTestCase {
// Check to see if the block was created by checking that it's in the database.
$this->assertNotNull($bid, t('Block found in database'));
// Set the created block to a specific region.
$edit = array();
$edit[$block['module'] . '_' . $block['delta'] . '[region]'] = 'left';
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
// Confirm that the block was moved to the proper region.
// TODO: Implement full region checking.
$this->assertText(t('The block settings have been updated.'), t('Block successfully moved to left region.'));
// Confirm that the block is being displayed.
$this->assertText(t($block['title']), t('Block successfully being displayed on the page.'));
// Check if the block can be moved to all availble regions.
foreach ($this->regions as $region) {
$this->moveBlockToRegion($block, $region);
}
// Set the block to the disabled region.
$edit = array();
......@@ -115,16 +113,41 @@ class BlockTestCase extends DrupalWebTestCase {
$this->assertText(t('The block settings have been updated.'), t('Block successfully move to disabled region.'));
$this->assertNoText(t($block['title']), t('Block no longer appears on page.'));
// Confirm that the regions xpath is not availble
$xpath = '//div[@id="block-block-' . $bid . '"]/*';
$this->assertNoFieldByXPath($xpath, FALSE, t('Box found in no regions. '));
// For convenience of developers, put the navigation block back.
$edit = array();
$edit[$block['module'] . '_' . $block['delta'] . '[region]'] = 'left';
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
$this->assertText(t('The block settings have been updated.'), t('Block successfully move to disabled region.'));
$this->assertText(t('The block settings have been updated.'), t('Block successfully move to left region.'));
$this->drupalPost('admin/build/block/configure/' . $block['module'] . '/' . $block['delta'], array('title' => 'Navigation'), t('Save block'));
$this->assertText(t('The block configuration has been saved.'), t('Block title set.'));
}
function moveBlockToRegion($block, $region) {
// If an id for an region hasn't been specified, we assume it's the same as the name.
if (!(isset($region['id']))) {
$region['id'] = $region['name'];
}
// Set the created block to a specific region.
$edit = array();
$edit[$block['module'] . '_' . $block['delta'] . '[region]'] = $region['name'];
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
// Confirm that the block was moved to the proper region.
$this->assertText(t('The block settings have been updated.'), t('Block successfully moved to %region_name region.', array( '%region_name'=> $region['name'])));
// Confirm that the block is being displayed.
$this->assertText(t($block['title']), t('Block successfully being displayed on the page.'));
// Confirm that the box was found at the proper region.
$xpath = '//div[@id="' . $region['id'] . '"]//div[@id="block-' . $block['module'] . '-' . $block['delta'] . '"]/*';
$this->assertFieldByXPath($xpath, FALSE, t('Box found in %region_name region.', array('%region_name' => $region['name'])));
}
}
class NonDefaultBlockAdmin extends DrupalWebTestCase {
......
......@@ -165,25 +165,28 @@ function _blog_post_exists($account) {
}
/**
* Implementation of hook_block().
* Implementation of hook_block_list().
*/
function blog_block_list() {
$block['recent']['info'] = t('Recent blog posts');
return $block;
}
/**
* Implementation of hook_block_view().
*
* Displays the most recent 10 blog titles.
*/
function blog_block($op = 'list', $delta = '') {
function blog_block_view($delta = '') {
global $user;
if ($op == 'list') {
$block['recent']['info'] = t('Recent blog posts');
return $block;
}
elseif ($op == 'view') {
if (user_access('access content')) {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10);
if ($node_title_list = node_title_list($result)) {
$block['content'] = $node_title_list;
$block['content'] .= theme('more_link', url('blog'), t('Read the latest blog entries.'));
$block['subject'] = t('Recent blog posts');
return $block;
}
if (user_access('access content')) {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10);
if ($node_title_list = node_title_list($result)) {
$block['content'] = $node_title_list;
$block['content'] .= theme('more_link', url('blog'), t('Read the latest blog entries.'));
$block['subject'] = t('Recent blog posts');
return $block;
}
}
}
......
......@@ -185,84 +185,95 @@ function book_init() {
}
/**
* Implementation of hook_block().
* Implementation of hook_block_list().
*/
function book_block_list() {
$block = array();
$block['navigation']['info'] = t('Book navigation');
$block['navigation']['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE;
return $block;
}
/**
* Implementation of hook_block_view().
*
* 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 = '', $edit = array()) {
function book_block_view($delta = '') {
$block = array();
switch ($op) {
case 'list':
$block['navigation']['info'] = t('Book navigation');
$block['navigation']['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE;
return $block;
case 'view':
$current_bid = 0;
if ($node = menu_get_object()) {
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
}
$current_bid = 0;
if ($node = menu_get_object()) {
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
}
if (variable_get('book_block_mode', 'all pages') == 'all pages') {
$block['subject'] = t('Book navigation');
$book_menus = array();
$pseudo_tree = array(0 => array('below' => FALSE));
foreach (book_get_books() as $book_id => $book) {
if ($book['bid'] == $current_bid) {
// If the current page is a node associated with a book, the menu
// needs to be retrieved.
$book_menus[$book_id] = menu_tree_output(menu_tree_all_data($node->book['menu_name'], $node->book));
}
else {
// Since we know we will only display a link to the top node, there
// is no reason to run an additional menu tree query for each book.
$book['in_active_trail'] = FALSE;
$pseudo_tree[0]['link'] = $book;
$book_menus[$book_id] = menu_tree_output($pseudo_tree);
}
}
$block['content'] = theme('book_all_books_block', $book_menus);
if (variable_get('book_block_mode', 'all pages') == 'all pages') {
$block['subject'] = t('Book navigation');
$book_menus = array();
$pseudo_tree = array(0 => array('below' => FALSE));
foreach (book_get_books() as $book_id => $book) {
if ($book['bid'] == $current_bid) {
// If the current page is a node associated with a book, the menu
// needs to be retrieved.
$book_menus[$book_id] = menu_tree_output(menu_tree_all_data($node->book['menu_name'], $node->book));
}
elseif ($current_bid) {
// Only display this block when the user is browsing a book.
$select = db_select('node');
$select->addField('node', 'title');
$select->condition('nid', $node->book['bid']);
$select->addTag('node_access');
$title = $select->execute()->fetchField();
// Only show the block if the user has view access for the top-level node.
if ($title) {
$tree = menu_tree_all_data($node->book['menu_name'], $node->book);
// There should only be one element at the top level.
$data = array_shift($tree);
$block['subject'] = theme('book_title_link', $data['link']);
$block['content'] = ($data['below']) ? menu_tree_output($data['below']) : '';
}
else {
// Since we know we will only display a link to the top node, there
// is no reason to run an additional menu tree query for each book.
$book['in_active_trail'] = FALSE;
$pseudo_tree[0]['link'] = $book;
$book_menus[$book_id] = menu_tree_output($pseudo_tree);
}
}
$block['content'] = theme('book_all_books_block', $book_menus);
}
elseif ($current_bid) {
// Only display this block when the user is browsing a book.
$select = db_select('node');
$select->addField('node', 'title');
$select->condition('nid', $node->book['bid']);
$select->addTag('node_access');
$title = $select->execute()->fetchField();
// Only show the block if the user has view access for the top-level node.
if ($title) {
$tree = menu_tree_all_data($node->book['menu_name'], $node->book);
// There should only be one element at the top level.
$data = array_shift($tree);
$block['subject'] = theme('book_title_link', $data['link']);
$block['content'] = ($data['below']) ? menu_tree_output($data['below']) : '';
}
}
return $block;
return $block;
}
case 'configure':
$options = array(
'all pages' => t('Show block on all pages'),
'book pages' => t('Show block only on book pages'),
);
$form['book_block_mode'] = array(
'#type' => 'radios',
'#title' => t('Book navigation block display'),
'#options' => $options,
'#default_value' => variable_get('book_block_mode', 'all pages'),
'#description' => t("If <em>Show block on all pages</em> is selected, the block will contain the automatically generated menus for all of the site's books. If <em>Show block only on book pages</em> is selected, the block will contain only the one menu corresponding to the current page's book. In this case, if the current page is not in a book, no block will be displayed. The <em>Page specific visibility settings</em> or other visibility settings can be used in addition to selectively display this block."),
);
/**
* Implementation of hook_block_configure().
*/
function book_block_configure($delta = '') {
$block = array();
$options = array(
'all pages' => t('Show block on all pages'),
'book pages' => t('Show block only on book pages'),
);
$form['book_block_mode'] = array(
'#type' => 'radios',
'#title' => t('Book navigation block display'),
'#options' => $options,
'#default_value' => variable_get('book_block_mode', 'all pages'),
'#description' => t("If <em>Show block on all pages</em> is selected, the block will contain the automatically generated menus for all of the site's books. If <em>Show block only on book pages</em> is selected, the block will contain only the one menu corresponding to the current page's book. In this case, if the current page is not in a book, no block will be displayed. The <em>Page specific visibility settings</em> or other visibility settings can be used in addition to selectively display this block."),
);
return $form;
return $form;
}
case 'save':
variable_set('book_block_mode', $edit['book_block_mode']);
break;
}
/**
* Implementation of hook_block_save().
*/
function book_block_save($delta = '', $edit = array()) {
$block = array();
variable_set('book_block_mode', $edit['book_block_mode']);
}
/**
......
......@@ -153,3 +153,33 @@ class BookTestCase extends DrupalWebTestCase {
return $node;
}
}
class BookBlockTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Block availability'),
'description' => t('Check if the book navigation block is available.'),
'group' => t('Book'),
);
}
function setUp() {
parent::setUp('book');
// Create and login user
$admin_user = $this->drupalCreateUser(array('administer blocks'));
$this->drupalLogin($admin_user);
}
function testBookNavigationBlock() {
// Set block title to confirm that the interface is availble.
$this->drupalPost('admin/build/block/configure/book/navigation', array('title' => $this->randomName(8)), t('Save block'));
$this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
// Set the block to a region to confirm block is availble.
$edit = array();
$edit['book_navigation[region]'] = 'footer';
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
$this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.'));
}
}
......@@ -261,39 +261,47 @@ function comment_perm() {
}
/**
* Implementation of hook_block().
*
* Generates a block with the most recent comments.
* Implementation of hook_block_list().
*/
function comment_block($op = 'list', $delta = '', $edit = array()) {
switch ($op) {
case 'list':
$blocks['recent']['info'] = t('Recent comments');
return $blocks;
case 'configure':
$form['comment_block_count'] = array(
'#type' => 'select',
'#title' => t('Number of recent comments'),
'#default_value' => variable_get('comment_block_count', 10),
'#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30)),
'#description' => t('Number of comments displayed in the <em>Recent comments</em> block.'),
);
function comment_block_list() {
$blocks['recent']['info'] = t('Recent comments');
return $form;
return $blocks;
}
case 'save':
variable_set('comment_block_count', (int)$edit['comment_block_count']);
break;
/**
* Implementation of hook_block_configure().
*/
function comment_block_configure($delta = '') {
$form['comment_block_count'] = array(
'#type' => 'select',
'#title' => t('Number of recent comments'),
'#default_value' => variable_get('comment_block_count', 10),
'#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30)),
'#description' => t('Number of comments displayed in the <em>Recent comments</em> block.'),
);
case 'view':
if (user_access('access comments')) {
$block['subject'] = t('Recent comments');
$block['content'] = theme('comment_block');
return $form;
}
return $block;
}
/**
* Implementation of hook_block_save().
*/
function comment_block_save($delta = '', $edit = array()) {
variable_set('comment_block_count', (int)$edit['comment_block_count']);
}
/**
* Implementation of hook_block_view().
*
* Generates a block with the most recent comments.
*/
function comment_block_view($delta = '') {
if (user_access('access comments')) {
$block['subject'] = t('Recent comments');
$block['content'] = theme('comment_block');
return $block;
}
}
......
......@@ -546,3 +546,33 @@ class CommentApprovalTest extends CommentHelperCase {
$this->assertTrue($this->commentExists($anonymous_comment4), t('Anonymous comment visible.'));
}
}
class CommentBlockTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Block availability'),
'description' => t('Check if the recent comments block is available.'),
'group' => t('Comment'),
);
}
function setUp() {
parent::setUp('comment');
// Create and login user
$admin_user = $this->drupalCreateUser(array('administer blocks'));
$this->drupalLogin($admin_user);
}
function testRecentCommentBlock() {
// Set block title to confirm that the interface is availble.
$this->drupalPost('admin/build/block/configure/comment/recent', array('title' => $this->randomName(8)), t('Save block'));
$this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
// Set the block to a region to confirm block is availble.
$edit = array();
$edit['comment_recent[region]'] = 'footer';
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
$this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.'));
}
}
......@@ -466,50 +466,58 @@ function forum_form_alter(&$form, $form_state, $form_id) {
}
/**
* Implementation of hook_block().
* Implementation of hook_block_list().
*/
function forum_block_list() {
$blocks['active']['info'] = t('Active forum topics');
$blocks['new']['info'] = t('New forum topics');
return $blocks;
}
/**
* Implementation of hook_block_configure().
*/
function forum_block_configure($delta = '') {
$form['forum_block_num_' . $delta] = array('#type' => 'select', '#title' => t('Number of topics'), '#default_value' => variable_get('forum_block_num_' . $delta, '5'), '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
return $form;
}
/**
* Implementation of hook_block_save().
*/
function forum_block_save($delta = '', $edit = array()) {
variable_set('forum_block_num_' . $delta, $edit['forum_block_num_' . $delta]);
}
/**
* Implementation of hook_block_view().
*
* Generates a block containing the currently active forum topics and the
* most recently added forum topics.
*/
function forum_block($op = 'list', $delta = '', $edit = array()) {
switch ($op) {
case 'list':
$blocks['active']['info'] = t('Active forum topics');
$blocks['new']['info'] = t('New forum topics');
return $blocks;
case 'configure':
$form['forum_block_num_' . $delta] = array('#type' => 'select', '#title' => t('Number of topics'), '#default_value' => variable_get('forum_block_num_' . $delta, '5'), '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
return $form;
case 'save':
variable_set('forum_block_num_' . $delta, $edit['forum_block_num_' . $delta]);
break;
function forum_block_view($delta = '') {
if (user_access('access content')) {
switch ($delta) {
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_active', '5'));
$content = node_title_list($result);
break;
case 'view':
if (user_access('access content')) {
switch ($delta) {
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_active', '5'));
$content = node_title_list($result);
break;
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_new', '5'));
$content = node_title_list($result);
break;
}
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_new', '5'));
$content = node_title_list($result);