Index: user_stats.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/user_stats/user_stats.module,v
retrieving revision 1.2.2.16.2.5
diff -b -u -p -r1.2.2.16.2.5 user_stats.module
--- user_stats.module	14 Oct 2008 12:14:11 -0000	1.2.2.16.2.5
+++ user_stats.module	22 Oct 2008 08:41:25 -0000
@@ -49,7 +49,7 @@ function user_stats_admin_settings() {
     '#type' => 'fieldset',
     '#title' => t('Post count options'),
     '#collapsible' => TRUE,
-    '#collapsed' => (variable_get('user_stats_count_posts', TRUE) ? FALSE : TRUE),
+    '#collapsed' => (variable_get('user_stats_count_posts', TRUE) || variable_get('user_stats_count_comments', TRUE) ? FALSE : TRUE),
   );
 
   $form['post_count_options']['user_stats_count_posts'] = array(
@@ -59,6 +59,13 @@ function user_stats_admin_settings() {
     '#default_value' => variable_get('user_stats_count_posts', TRUE),
   );
 
+  $form['post_count_options']['user_stats_count_comments'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Count comments'),
+    '#description' => t('If checked user comments counts will be included in the total user post count.'),
+    '#default_value' => variable_get('user_stats_count_comments', TRUE),
+  );
+
   foreach (node_get_types() as $types) {
     $options[$types->type] = $types->name;
   }
@@ -233,7 +240,7 @@ function user_stats_get_stats($type, $ui
       case 'login_days':
         return floor((time() - $user->access) / 86400);
       case 'post_count':
-        if (!variable_get('user_stats_count_posts', TRUE)) {
+        if (!variable_get('user_stats_count_posts', TRUE) && !variable_get('user_stats_count_comments', TRUE)) {
           return 'n/a';
         }
         // If the post count for this user hasn't been set then update it
@@ -380,11 +387,13 @@ function user_stats_comment(&$a1, $op) {
     return;
   }
 
+  // check to see if comments should be counted at all
+  if (variable_get('user_stats_count_comments', TRUE)) {
+
   $comment = (object)$a1;
   $postcount_content_types = variable_get('user_stats_included_content_types', array());
   $node = node_load(array('nid' => $comment->nid));
 
-
   if ((empty($postcount_content_types) ||
     in_array($node->type, $postcount_content_types)) &&
     variable_get('user_login_count', TRUE)) {
@@ -404,6 +413,7 @@ function user_stats_comment(&$a1, $op) {
         break;
     }
   }
+  }
 
   // Do IP address update
   global $user;
@@ -420,7 +430,7 @@ function user_stats_comment(&$a1, $op) {
  * updating them.
  */
 function user_stats_cron() {
-  if (variable_get('user_stats_rebuild_stats', TRUE) && variable_get('user_stats_count_posts', TRUE)) {
+  if (variable_get('user_stats_rebuild_stats', TRUE) && (variable_get('user_stats_count_posts', TRUE) || variable_get('user_stats_count_comments', TRUE))) {
     $sql = "SELECT fid FROM {profile_fields} WHERE name='%s'";
     $fid = db_result(db_query($sql, variable_get('user_stats_postcount_profile_field', 'user_post_count')));
 
@@ -787,10 +797,12 @@ function user_stats_post_count_update(&$
       break;
     case 'reset':
       static $fid;
+      $total_count = 0;
       if (!isset($fid)) {
         $sql = "SELECT fid FROM {profile_fields} WHERE name='%s'";
         $fid = db_result(db_query($sql, $post_count_profile_field));
       }
+      if (variable_get('user_stats_count_posts', TRUE)) {
       $sql  = "SELECT COUNT(*) FROM {node} WHERE uid=%d AND status=1";
       $postcount_content_types = variable_get('user_stats_included_content_types', array());
       if (!empty($postcount_content_types)) {
@@ -799,13 +811,17 @@ function user_stats_post_count_update(&$
         $sql .= $where;
       }
       $node_count = db_result(db_query($sql, $user->uid));
+        $total_count += $node_count;
+      }
+      if (variable_get('user_stats_count_comments', TRUE)) {
       $sql = "SELECT COUNT(*) FROM {comments} c INNER JOIN {node} n ON c.nid=n.nid WHERE c.uid=%d AND c.status=0 AND n.status=1";
       if (!empty($postcount_content_types)) {
         $where = ' AND n.type IN ('. $content_types .')';
         $sql .= $where;
       }
       $comments_count = db_result(db_query($sql, $user->uid));
-      $total_count = $node_count + $comments_count;
+        $total_count += $comments_count;
+      }
       $sql =  "DELETE FROM {profile_values} ";
       $sql .= "WHERE fid=%d AND uid=%d";
       db_query($sql, $fid, $user->uid);
