--- user_stats.module	2008-03-14 10:31:26.000000000 +0800
+++ user_stats.module	2008-03-15 00:20:52.000000000 +0800
@@ -64,6 +64,21 @@ function user_stats_admin_settings() {
     '#default_value' => variable_get('user_stats_count_posts', TRUE),
   );
 
+  $profile_fields = array('' => 'None');
+  $result = db_query("SELECT name, title FROM {profile_fields} ORDER BY fid");
+  while ($row = db_fetch_object($result)) {
+    $profile_fields[$row->name] = $row->title;
+  }
+
+  $form['post_count_options']['user_stats_postcount_profile_field'] = array(
+    '#type' => 'select',
+    '#title' => t('user stats postcount profile field'),
+    '#description' => t('This is the profile field that holds the postcount for a user. You must enable the profile module and create a new field for this.'),
+    '#options' => $profile_fields,
+    '#default_value' => variable_get('user_stats_postcount_profile_field', ''),
+    '#required' => TRUE,
+  );
+
   foreach(node_get_types() as $types) {
     $options[$types->type] = $types->name;
   }
@@ -226,10 +241,11 @@ function user_stats_get_stats($type, $ui
           return 'n/a';
         }
         // If the post count for this user hasn't been set then update it
-        if (!isset($user->user_post_count)) {
+        $post_count_profile_field = variable_get('user_stats_postcount_profile_field', '');
+        if (!isset($user->$post_count_profile_field)) {
           user_stats_post_count_update($user, 'reset');
         }
-        return $user->user_post_count;
+        return $user->$post_count_profile_field;
       case 'post_days':
         $last_post = _user_stats_last_post($user);
         if ($last_post !== FALSE) {
@@ -408,8 +424,8 @@ function user_stats_comment(&$a1, $op) {
  */
 function user_stats_cron() {
   if (variable_get('user_stats_rebuild_stats', TRUE) && variable_get('user_stats_count_posts', TRUE)) {
-    $sql = "SELECT fid FROM {profile_fields} WHERE name='user_post_count'";
-    $fid = db_result(db_query($sql));
+    $sql = "SELECT fid FROM {profile_fields} WHERE name='%s'";
+    $fid = db_result(db_query($sql, variable_get('user_stats_postcount_profile_field', '')));
 
     // Unfortunately this cannot be done with a JOIN because of the need to match on fid
     $sql  = "SELECT uid FROM {users} WHERE uid NOT IN ( ";
@@ -703,15 +719,16 @@ function user_stats_post_count_update(&$
   $sql  = "UPDATE {profile_values} SET value=%d ";
   $sql .= "WHERE fid = (SELECT fid FROM {profile_fields} ";
   $sql .= "WHERE name = '%s') AND uid=%d ";
+  $post_count_profile_field = variable_get('user_stats_postcount_profile_field', '');
 
   switch ($op) {
     case 'increment':
-      if (!isset($user->user_post_count)) {
+      if (!isset($user->$post_count_profile_field)) {
         $user = user_stats_post_count_update($user, 'reset');
       }
       else {
-        $user->user_post_count++;
-        db_query($sql, $user->user_post_count, 'user_post_count', $user->uid);
+        $user->$post_count_profile_field++;
+        db_query($sql, $user->$post_count_profile_field, $post_count_profile_field, $user->uid);
         // Flush user cache.
         _user_stats_user_cache($user->uid, TRUE);
         // Flush token cache
@@ -727,12 +744,12 @@ function user_stats_post_count_update(&$
       }
       break;
     case 'decrement':
-      if (!isset($user->user_post_count)) {
+      if (!isset($user->$post_count_profile_field)) {
         $user = user_stats_post_count_update($user, 'reset');
       }
       else {
-        $user->user_post_count--;
-        db_query($sql, $user->user_post_count, 'user_post_count', $user->uid);
+        $user->$post_count_profile_field--;
+        db_query($sql, $user->$post_count_profile_field, $post_count_profile_field, $user->uid);
         // Flush user cache.
         _user_stats_user_cache($user->uid, TRUE);
         // Flush token cache
@@ -749,8 +766,8 @@ function user_stats_post_count_update(&$
     case 'reset':
       static $fid;
       if (!isset($fid)) {
-        $sql = "SELECT fid FROM {profile_fields} WHERE name='user_post_count'";
-        $fid = db_result(db_query($sql));
+        $sql = "SELECT fid FROM {profile_fields} WHERE name='%s'";
+        $fid = db_result(db_query($sql, $post_count_profile_field));
       }
       $sql  = "SELECT COUNT(*) FROM {node} WHERE uid=%d AND status=1";
       $postcount_content_types = variable_get('user_stats_included_content_types', array());
@@ -851,7 +868,7 @@ function user_stats_user_load($uid) {
  *   This must be the name of the profile_fields field.
  */
 function user_stats_reset_counts($statistic = 'user_post_count') {
-  $fid = db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'", $statistic));
+  $fid = db_result(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'", variable_get('user_stats_postcount_profile_field', '')));
   if ($fid) {
     db_query('DELETE FROM {profile_values} WHERE fid = %d', $fid);
   }
