Index: user_titles.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/user_titles/user_titles.module,v
retrieving revision 1.13
diff -u -r1.13 user_titles.module
--- user_titles.module	19 Nov 2007 00:46:36 -0000	1.13
+++ user_titles.module	5 Dec 2007 21:36:07 -0000
@@ -51,12 +51,24 @@
     $nodes[$type] = $info->name;
   }
 
+  $userpoints_exists = module_exists('userpoints');
+  $use_userpoints    = user_titles_use_userpoints();
+  
+  if ($userpoints_exists) {
+    $form['userpoints'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Use userpoints'),
+      '#description' => t('Use userpoint\'s point counts (note, these will be higher than post counts)'),
+      '#default_value' => $use_userpoints,
+    );
+  }
   $form['types'] = array(
     '#type' => 'checkboxes',
     '#title' => t('Counted node types'),
     '#description' => t('Only the checked node types will be counted'),
     '#options' => $nodes,
     '#default_value' => $types,
+    '#disabled' => $use_userpoints
   );
 
   $titles = user_titles_get_titles();
@@ -128,8 +140,12 @@
   drupal_add_js(array('userTitles' => array('imageURL' => base_path() ."misc/watchdog-error.png")), 'setting');
   drupal_add_js("$path/admin.js");
   drupal_add_css("$path/admin.css");
+  $countable = t('Posts');
+  if (user_titles_use_userpoints()) {
+    $countable = t('!Points', userpoints_translation());
+  }
   $header = array(
-    array('data' => t('Posts'), 'class' => 'num-posts'),
+    array('data' => $countable, 'class' => 'num-posts'),
     array('data' => t('Title'), 'class' => 'user-title'),
     '',
   );
@@ -159,6 +175,7 @@
   $output .= '</div>';
 
   $output .= '<div class="right">';
+  $output .= drupal_render($form['userpoints']);
   $output .= drupal_render($form['types']);
   $output .= '</div>';
 
@@ -208,7 +225,12 @@
     db_query("TRUNCATE {user_titles_posts}");
   }
 
-  user_titles_set_allowed_types(array_keys(array_filter($form_values['types'])));
+  if (!user_titles_use_userpoints() && $form_values['userpoints']) {
+    user_titles_set_allowed_types(array_keys(array_filter($form_values['types'])));
+  }
+  if (module_exists('userpoints')) {
+    variable_set('user_titles_use_userpoints', $form_values['userpoints']);
+  }
   drupal_set_message(t('The configuration has been updated.'));
 }
 
@@ -247,7 +269,12 @@
 function user_titles_get_posts($uid) {
   static $cache = array();
   if (!array_key_exists($uid, $cache)) {
-    $cache[$uid] = db_result(db_query("SELECT posts FROM {user_titles_posts} WHERE uid = %d", $uid));
+    $cache[$uid] = FALSE;
+    if (!user_titles_use_userpoints()) {
+      $cache[$uid] = db_result(db_query("SELECT posts FROM {user_titles_posts} WHERE uid = %d", $uid));
+    } else {
+      return userpoints_get_current_points($uid);
+    }
     if ($cache[$uid] === FALSE) {
       $cache[$uid] = user_titles_update_post_count($uid);
     }
@@ -435,3 +462,10 @@
     }
   }
 }
+
+/**
+ * Whether or not userpoints should be used instead of post counts
+ */
+function user_titles_use_userpoints() {
+  return variable_get('user_titles_use_userpoints', false) && module_exists('userpoints');
+}
