Created
April 14, 2010 16:08
-
-
Save pifantastic/365996 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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')) { | |
| $block = cache_get(__FUNCTION__.$delta); | |
| if ($block !== 0) { | |
| return $block->data; | |
| } | |
| 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 = array(); | |
| $block['subject'] = $title; | |
| $block['content'] = $content . theme('more_link', url('forum'), t('Read the latest forum topics.')); | |
| cache_set(__FUNCTION__.$delta, $block, 'cache_block', time() + 300); | |
| return $block; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment