forum_block
modules/forum/forum.module, строка 236
- Версии
- 5 – 6
forum_block($op = 'list', $delta = 0, $edit = array())
Реализация hook_block()
.
Generates a block containing the currently active forum topics and the most recently added forum topics.
Код
<?php
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 {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND n.type = 'forum' ORDER BY l.last_comment_timestamp DESC");
$result = db_query_range($sql, 0, variable_get('forum_block_num_0', '5'));
if (db_num_rows($result)) {
$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 {node_comment_statistics} l ON n.nid = l.nid WHERE n.type = 'forum' AND n.status = 1 ORDER BY n.nid DESC");
$result = db_query_range($sql, 0, variable_get('forum_block_num_1', '5'));
if (db_num_rows($result)) {
$content = node_title_list($result);
}
break;
}
if ($content) {
$content .= '<div class="more-link">'. l(t('more'), 'forum', array('title' => t('Read the latest forum topics.'))) .'</div>';
}
$block['subject'] = $title;
$block['content'] = $content;
return $block;
}
}
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии