Index: forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v
retrieving revision 1.507
diff -u -r1.507 forum.module
--- forum.module	28 Jul 2009 10:41:20 -0000	1.507
+++ forum.module	9 Aug 2009 17:12:41 -0000
@@ -498,6 +498,7 @@
 function forum_block_list() {
   $blocks['active']['info'] = t('Active forum topics');
   $blocks['new']['info'] = t('New forum topics');
+  $blocks['statistics']['info'] = t('Forum statistics');
   return $blocks;
 }
 
@@ -505,15 +506,24 @@
  * Implement 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;
+  switch ($delta) {
+    case 'new':
+    case 'active':
+      $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;
+  }
 }
 
 /**
  * Implement hook_block_save().
  */
 function forum_block_save($delta = '', $edit = array()) {
-  variable_set('forum_block_num_' . $delta, $edit['forum_block_num_' . $delta]);
+  switch ($delta) {
+    case 'new':
+    case 'active':
+      variable_set('forum_block_num_' . $delta, $edit['forum_block_num_' . $delta]);
+    return $form;
+  }
 }
 
 /**
@@ -524,38 +534,60 @@
  */
 function forum_block_view($delta = '') {
   if (user_access('access content')) {
-    $query = db_select('node', 'n');
-    $query->join('taxonomy_term_node', 'tn', 'tn.vid = n.vid');
-    $query->join('taxonomy_term_data', 'td', 'td.tid = tn.tid');
-    $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');
-    $query
-      ->fields('n', array('nid', 'title'))
-      ->fields('ncs', array('comment_count', 'last_comment_timestamp'))
-      ->condition('n.status', 1)
-      ->condition('td.vid', variable_get('forum_nav_vocabulary', 0))
-      ->addTag('node_access');
-    switch ($delta) {
+  switch ($delta) {
       case 'active':
-        $title = t('Active forum topics');
-        $query
-          ->orderBy('ncs.last_comment_timestamp', 'DESC')
-          ->range(0, variable_get('forum_block_num_active', '5'));
-        break;
-
       case 'new':
-        $title = t('New forum topics');
+        $query = db_select('node', 'n');
+        $query->join('taxonomy_term_node', 'tn', 'tn.vid = n.vid');
+        $query->join('taxonomy_term_data', 'td', 'td.tid = tn.tid');
+        $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');
         $query
-          ->orderBy('n.nid', 'DESC')
-          ->range(0, variable_get('forum_block_num_new', '5'));
+          ->fields('n', array('nid', 'title'))
+          ->fields('ncs', array('comment_count', 'last_comment_timestamp'))
+          ->condition('n.status', 1)
+          ->condition('td.vid', variable_get('forum_nav_vocabulary', 0))
+          ->addTag('node_access');
+        switch ($delta) {
+          case 'active':
+            $title = t('Active forum topics');
+            $query
+              ->orderBy('ncs.last_comment_timestamp', 'DESC')
+              ->range(0, variable_get('forum_block_num_active', '5'));
+            break;
+
+          case 'new':
+            $title = t('New forum topics');
+            $query
+              ->orderBy('n.nid', 'DESC')
+              ->range(0, variable_get('forum_block_num_new', '5'));
+            break;
+        }
+
+        $result = $query->execute();
+        $content = node_title_list($result);
+        if ($content) {
+          $block['subject'] = $title;
+          $block['content'] = $content . theme('more_link', url('forum'), t('Read the latest forum topics.'));
+          return $block;
+        }
+
         break;
-    }
 
-    $result = $query->execute();
-    $content = node_title_list($result);
-    if (!empty($content)) {
-      $block['subject'] = $title;
-      $block['content'] = $content . theme('more_link', url('forum'), t('Read the latest forum topics.'));
-      return $block;
+      case 'statistics':
+        $comments = db_result(db_query('SELECT COUNT(cid) FROM {comment} c INNER JOIN {forum} f ON (f.nid = c.nid)'));
+        $topics = db_result(db_query('SELECT COUNT(DISTINCT(nid)) FROM {forum}'));
+        $posts = $comments + $topics;
+        $users = db_result(db_query('SELECT COUNT(uid) FROM {users} WHERE status = 1'));
+        $latest_user_object = db_fetch_object(db_query('SELECT uid, name FROM {users} WHERE status = 1 AND access > 0 ORDER BY created DESC'));
+        $latest_user = theme('username', $latest_user_object);
+        
+        $content = t('Topics: @topics, Posts: @posts, users: @users.<br />Please welcome our latest member !member', array('@topics' => $topics, '@posts' => $posts, '@users' => $users, '!member' => $latest_user));
+        
+        if ($content) {
+          $block['subject'] = 'Forum statistics';
+          $block['content'] = $content;
+          return $block;
+        }
     }
   }
 }

