You are here

function forum_block in Drupal 4

Same name and namespace in other branches
  1. 5 modules/forum/forum.module \forum_block()
  2. 6 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.module, line 244
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 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;
      }
  }
}