function forum_block in Drupal 6
Same name and namespace in other branches
- 4 modules/forum.module \forum_block()
- 5 modules/forum/forum.module \forum_block()
Implementation of hook_block().
Generates a block containing the currently active forum topics and the most recently added forum topics.
File
- modules/
forum/ forum.module, line 405 - Enable threaded discussions about general topics.
Code
function forum_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Active forum topics');
$blocks[1]['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;
case 'view':
if (user_access('access content')) {
switch ($delta) {
case 0:
$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'));
$content = node_title_list($result);
break;
case 1:
$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'));
$content = node_title_list($result);
break;
}
if (!empty($content)) {
$block['subject'] = $title;
$block['content'] = $content . theme('more_link', url('forum'), t('Read the latest forum topics.'));
return $block;
}
}
}
}