diff -rupN user_titles/admin.css user_titles_new/admin.css
--- user_titles/admin.css	2009-01-07 12:35:55.000000000 +1100
+++ admin.css	1970-01-01 10:00:00.000000000 +1000
@@ -1,69 +0,0 @@
-/* $Id: admin.css,v 1.5.2.1 2009/01/07 01:35:55 agileware Exp $ */
-
-table#user-titles-settings {
-  width: auto;
-  margin-bottom: 0;
-  padding-bottom: 0;
-}
-
-table#user-titles-add {
-  width: auto;
-  margin-top: 10px;
-  padding-top: 0;
-}
-
-th.num-posts,
-td.num-posts {
-  padding-right: 3px; 
-  padding-left: 3px;
-  width: 3em;
-}
-
-td.user-title,
-th.user-title {
-  width: 10em;
-}
-
-div.top {
-  float: left;
-  width: 96%;
-  padding: 0 5px;
-  margin-bottom: 15px;
-}
-
-div.title-table {
-  float: right;
-  width: 56%;
-  padding: 0 5px;
-}
-
-div.settings {
-  width: 40%;
-  float: left;
-  padding: 0 5px;
-}
-
-div.right div.form-checkboxes div.form-item {
-  width: 10em;
-  float: left;
-  padding: 0 1px;
-  margin: 0 2px;
-}
-
-div.description {
-  clear: left;
-}
-
-div.clearer {
-  clear: both;
-  height: 0;
-}
-
-table#user-titles-settings img.title-delete {
-  cursor: pointer;
-  vertical-align: middle;
-}
-
-legend {
-  font-weight: bold;
-}
\ No newline at end of file
diff -rupN user_titles/API.txt user_titles_new/API.txt
--- user_titles/API.txt	2009-01-07 12:35:55.000000000 +1100
+++ API.txt	2010-01-28 22:15:27.000000000 +1100
@@ -1,10 +1,12 @@
+// $Id$
 
-User Titles defines a hook function other modules can define. It is:
-
-hook_user_titles($op, $uid = null)
-  Use this function to describe what point scheme your module defines
-  for User Titles.
-
+User Titles defines a hook function other modules can define. It is:
+For a live example check out the ut_userpoints module in the contrib directory.
+
+/**
+ * Use this function to describe what point scheme your module defines for User Titles.
+ */
+hook_user_titles($op, $uid = NULL) {
   $op: The operation to be acted upon
     'register'
       Return module name so that module can be called later
@@ -30,5 +32,6 @@ hook_user_titles($op, $uid = null)
         return "admin/help/donate";
 
     'get'
-      Return number of points for $uid
-
+      Return number of points for $uid
+}
+
diff -rupN user_titles/contrib/ut_userpoints/ut_userpoints.info user_titles_new/contrib/ut_userpoints/ut_userpoints.info
--- user_titles/contrib/ut_userpoints/ut_userpoints.info	1970-01-01 10:00:00.000000000 +1000
+++ contrib/ut_userpoints/ut_userpoints.info	2010-01-27 22:22:14.000000000 +1100
@@ -0,0 +1,7 @@
+; $Id$
+name = User titles userpoints
+description = Allows user titles to be based on a users userpoints
+dependencies[] = user_titles
+dependencies[] = userpoints
+core = 6.x
+
diff -rupN user_titles/contrib/ut_userpoints/ut_userpoints.module user_titles_new/contrib/ut_userpoints/ut_userpoints.module
--- user_titles/contrib/ut_userpoints/ut_userpoints.module	1970-01-01 10:00:00.000000000 +1000
+++ contrib/ut_userpoints/ut_userpoints.module	2010-01-28 00:38:52.000000000 +1100
@@ -0,0 +1,28 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Allows user titles to be based on a users userpoints.
+ */
+
+/**
+ * Implementation of hook_user_titles().
+ */
+function ut_userpoints_user_titles($op, $uid = NULL) {
+  switch ($op) {
+    case 'register':
+      return 'ut_userpoints';
+    case 'name':
+      return t('User points');
+    case 'description':
+      return t('Different points values are assigned to user actions');
+    case 'units':
+      return t('Points');
+    case 'url':
+      return 'admin/help/userpoints';
+    case 'get':
+      return userpoints_get_current_points($uid);
+  }
+}
+
diff -rupN user_titles/README.txt user_titles_new/README.txt
--- user_titles/README.txt	2009-01-07 12:35:55.000000000 +1100
+++ README.txt	2010-01-28 22:32:50.000000000 +1100
@@ -1,13 +1,80 @@
-When installing this module, it won't appear to do anything at first. This is
-because you need to modify your theme in order to place the output where
-you like.
+// $Id$
 
-The function you need to call to get the data is
-user_titles_get_user_title(). This module will automatically populate the
+---------------------DESCRIPTION-------------------------------------------
+
+This module allows the administrator to assign titles to users based upon
+their role and  the number of nodes they have created.
+It also has the ability to use other modules point schemes to assign titles.
+For example the userpoints module.
+Images can also be assigned to the titles.
+Titles and/or their images can be displayed anywhere in your theme using
+the supplied functions and node/comment template variables.
+
+---------------------INSTALLATION------------------------------------------
+
+1. Copy the user_titles directory to sites/all/modules
+2. On the modules page (admin/build/modules) enable the user titles module
+3. If you want to integrate with userpoints you now have to enable the user
+titles userpoints module also
+
+----------------------UPGRADING--------------------------------------------
+
+If you are upgrading from a pre-roles-based version you won't lose your
+existing titles.  They will be put under the authenticated user role and
+that role will be placed at the top of the role priority table.
+This means that your site will continue working the same after upgrading
+without you having to change any settings.
+
+NOTE: If you were previously using userpoints to calculate your titles
+you must now enable the user titles userpoints sub module.
+
+------------------------USAGE----------------------------------------------
+
+After the module is installed you need to set up your titles:
+1. Go to the user titles setttings page (admin/user/user-titles)
+---Settings:---
+* If you are using an another module to calculate points this is
+where you select the module to use.
+* Counted node types is only used if you are using user titles
+to calculate the points.
+* The images directory is a subdirectory of the file directory
+(sites/default/files) where you want user titles images stored.
+---Role priority:---
+User titles are based on roles.  This makes it possible to have different
+titles for each role (or no titles for a specific role) but it also
+makes things a bit more complicated.
+* If a user has one role (authenticated user) then they will get whatever
+titles are assigned to that role.
+* If a user has multiple roles, this is where you set which one gets used.
+The table is for weighting the roles.
+If a user has multiple roles these weights are checked against the user's
+roles and the role with the lightest weight is used.
+
+An example usage of this is:
+You have a moderator role and an administrator role and you want moderators
+to have different titles to regular authenticated users and admins to have
+no titles.
+Order the roles like this:
+  administrator
+  moderator
+  authenticated user
+Then set no titles for the administrator role and different titles for the
+moderator and authenticated user roles.
+
+You can then use the "Add title" tab (admin/user/user-titles/add/title) to
+add titles to your roles.
+And you can use the "Titles" tab (admin/user/user-titles/titles) to view
+your titles.
+
+After all this has been done the module still won't appear to do anything.
+This is because it assigns titles to users but doesn't print them.
+To print the user titles you need to add some code to your theme.
+
+This module will automatically populate the
 $user_title and $user_title_image variables into your nodes and comments.
 
-In your node.tpl.php and/or your comment.tpl.php, choose where you would like
-the user title to appear, and place this code:
+In your node.tpl.php and/or your comment.tpl.php, choose where you would
+like the user title to appear, and place this code:
 
   <?php if ($user_title): ?>
     <div class="user-title">
@@ -17,3 +84,13 @@ the user title to appear, and place this
       ?>
     </div>
   <?php endif; ?>
+
+
+If you need the user titles elsewhere you can get them using these functions:
+  user_titles_get_user_title($user) returns the user's title.
+  user_titles_get_user_image($user) returns the user's image.
+The $user parameter can be either a user object or uid integer.
+
+----------------------DEVELOPERS-------------------------------------------
+
+This module is developed and maintained by Agileware (www.agileware.net)
diff -rupN user_titles/user_titles.admin.inc user_titles_new/user_titles.admin.inc
--- user_titles/user_titles.admin.inc	1970-01-01 10:00:00.000000000 +1000
+++ user_titles.admin.inc	2010-01-28 21:36:57.000000000 +1100
@@ -0,0 +1,538 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Admin page callback file for the user_titles module.
+ */
+
+/**
+ * Form to determine titles and levels.
+ *
+ * @return
+ *   A form array.
+ */
+function user_titles_settings_form() {
+  $form = array();
+
+  $types = user_titles_get_allowed_types();
+
+  foreach (node_get_types() as $type => $info) {
+    $nodes[$type] = $info->name;
+  }
+
+  $hook_module = user_titles_get_hook_module();
+  $hook_modules = module_invoke_all('user_titles', 'register');
+
+
+  $form['settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Settings',
+  );
+  $form['settings']['hook_module'] = array(
+    '#type' => 'radios',
+    '#title' => 'Point scheme',
+    '#default_value' => $hook_module,
+    '#options' => array(),
+    '#attributes' => array('class' => 'user-titles-hook-module'),
+  );
+  foreach ($hook_modules as $module) {
+    $name = module_invoke($module, 'user_titles', 'name');
+    $form['settings']['hook_module']['#options'][$module] = array(
+      'name' => $name,
+      'description' => module_invoke($module, 'user_titles', 'description'),
+      'url' => module_invoke($module, 'user_titles', 'url'),
+    );
+    $name_index[$module] = $name;
+  }
+
+  array_multisort($name_index, SORT_ASC, SORT_STRING, $form['settings']['hook_module']['#options']);
+
+  // Implementation of user_titles' default behavior
+  $form['settings']['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' => $hook_module !== 'user_titles',
+    '#attributes' => array('class' => 'user-titles-types'),
+  );
+  $form['settings']['types_disabled'] = array(
+    '#type' => 'hidden',
+    '#default_value' => $hook_module !== 'user_titles',
+  );
+  // Directory to save images
+  $form['settings']['image_dir'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Image directory'),
+    '#description' => t('Subdirectory in the directory %dir where images will be stored.', array('%dir' => file_directory_path() .'/')),
+    '#default_value' => variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR),
+    '#size' => 35,
+    '#attributes' => array('class' => 'user-titles-image-dir'),
+  );
+
+  $form['roles-description'] = array(
+    '#type' => 'item',
+    '#value' => t('Set the priority of your roles here.  If a user has multiple roles they will get the titles of highest role in this list that they are a member of.  If the users highest role has no titles that user will not get titles.'),
+  );
+  $form['roles'] = array(
+    '#tree' => TRUE,
+  );
+
+  $result = db_query("SELECT r.name, ro.*
+                      FROM {role} r, {user_titles_roles} ro
+                      WHERE r.rid = ro.rid
+                      AND r.rid != 1
+                      ORDER BY ro.weight");
+  while ($role = db_fetch_array($result)) {
+    $form['roles'][$role['rid']]['name'] = array(
+      '#value' => check_plain($role['name']),
+    );
+    $form['roles'][$role['rid']]['weight'] = array(
+      '#type' => 'weight',
+      '#delta' => 30,
+      '#default_value' => $role['weight'],
+    );
+  }
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+  );
+
+  return $form;
+}
+
+/**
+ * Submit function for the user titles setting form.
+ */
+function user_titles_settings_form_submit($form, &$form_state) {
+  // If they change the allowed types, wipe the existing counts so each one will be fresh.
+  $types = user_titles_get_allowed_types();
+  if ($types != $form_values['types']) {
+    db_query("TRUNCATE TABLE {user_titles_posts}");
+  }
+
+  if (!$form_state['values']['types_disabled']) {
+    user_titles_set_allowed_types(array_keys(array_filter($form_state['values']['types'])));
+  }
+
+  user_titles_set_hook_module($form_state['values']['hook_module']);
+  variable_set('user_titles_image_dir', $form_state['values']['image_dir']);
+
+  $image_path = file_create_path(variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR));
+  file_check_directory($image_path, 1, 'image_dir');
+
+  // Role orders
+  foreach ($form_state['values']['roles'] as $rid => $role) {
+    db_query("UPDATE {user_titles_roles} SET weight = %d WHERE rid = %d", $role['weight'], $rid);
+    if (!db_affected_rows()) {
+      db_query("INSERT INTO {user_titles_roles} (rid, weight) VALUES (%d, %d)", $rid, $role['weight']);
+    }
+  }
+
+  drupal_set_message(t('The configuration has been updated.'));
+}
+
+/**
+ * Form that lists the user titles.
+ *
+ * @return
+ *   A form array.
+ */
+function user_titles_titles_form() {
+  $form = array();
+
+  $form['roles']['#tree'] = TRUE;
+
+  $result = db_query("SELECT r.name, ro.*
+                      FROM {role} r, {user_titles_roles} ro
+                      WHERE r.rid = ro.rid
+                      AND r.rid != 1
+                      ORDER BY ro.weight");
+  while ($role = db_fetch_array($result)) {
+    $titles = user_titles_get_titles_by_role($role['rid']);
+    
+    $form['roles'][$role['rid']]['name'] = array(
+      '#type' => 'markup',
+      '#value' => t($role['name']),
+    );
+    $form['roles'][$role['rid']]['add_title'] = array(
+      '#type' => 'item',
+      '#value' => l(t('Add another title'), 'admin/user/user-titles/add/title', array('query' => array('rid' => $role['rid']))),
+    );
+
+    if (!empty($titles)) {
+      foreach ($titles as $i => $title) {
+        $form['roles'][$role['rid']]['titles'][$i]['value'] = array(
+          '#type' => 'markup',
+          '#value' => $title->value,
+        );
+        $form['roles'][$role['rid']]['titles'][$i]['title'] = array(
+          '#type' => 'markup',
+          '#value' => $title->title,
+        );
+        $form['roles'][$role['rid']]['titles'][$i]['image'] = array(
+          '#type' => 'markup',
+          '#value' => theme('user_titles_image', $title->image, $title->image_title),
+        );
+        $form['roles'][$role['rid']]['titles'][$i]['tid'] = array(
+          '#type' => 'hidden',
+          '#value' => $title->tid,
+        );
+      }
+    }
+  }
+
+  return $form;
+}
+
+/**
+ * Form for adding/editing user titles.
+ *
+ * @param $title
+ *   A title object if editing.  NULL if adding a new title.
+ *
+ * @return
+ *   A form array.
+ */
+function user_titles_add_title_form(&$form_state, $title = NULL) {
+  $path = drupal_get_path('module', 'user_titles');
+  drupal_add_css("$path/admin.css");
+
+  // For file field to work.
+  $form['#attributes'] = array('enctype' => 'multipart/form-data');
+
+  $roles = user_titles_get_roles();
+  $rid = is_numeric($_GET['rid']) ? $_GET['rid'] : 0;
+  $default_role = $title->rid ? $title->rid : $rid;
+  $form['role'] = array(
+    '#type' => 'select',
+    '#title' => t('Role'),
+    '#required' => TRUE,
+    '#default_value' => $default_role,
+    '#options' => $roles,
+  );
+
+  $units = module_invoke(user_titles_get_hook_module(), 'user_titles', 'units');
+  $form['value'] = array(
+    '#type' => 'textfield',
+    '#title' => t($units),
+    '#size' => 5,
+    '#maxlength' => 10,
+    '#required' => TRUE,
+    '#default_value' => $title->value,
+  );
+
+  $form['title'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Title'),
+    '#size' => 40,
+    '#maxlength' => 128,
+    '#required' => TRUE,
+    '#default_value' => $title->title,
+  );
+
+  $form['image'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Image'),
+  );
+
+  $form['image']['image_display'] = array(
+    '#type' => 'item',
+    '#value' => theme('user_titles_image', $title->image, $title->image_title),
+  );
+
+  if ($title->image) {
+    $form['image']['remove_image'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Remove image'),
+      '#description' => t('If checked this image will be removed from this title on submit.'),
+    );
+  }
+
+  $form['image']['image_title'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Image title/alt text'),
+    '#size' => 40,
+    '#maxlength' => 255,
+    '#default_value' => $title->image_title,
+    '#description' => t('This text will be used as the title and alt text for the image when it is displayed.'),
+  );
+
+  $form['image']['image_upload'] = array(
+    '#type' => 'file',
+    '#title' => t('Upload new image'),
+    '#size' => 40,
+    '#description' => t('Upload an image that can be displayed with this user title.  This image will replace any existing image attached to this title.'),
+  );
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+  );
+
+  if ($title->tid) {
+    $form['delete'] = array(
+      '#type' => 'submit',
+      '#value' => t('Delete'),
+    );
+    $form['tid'] = array(
+      '#type' => 'value',
+      '#value' => $title->tid,
+    );
+  }
+
+  return $form;
+}
+
+/**
+ * Validate function for the add title form.
+ */
+function user_titles_add_title_form_validate($form, &$form_state) {
+  $existing_titles = user_titles_get_titles_by_role($form_state['values']['role']);
+
+  if (!is_numeric($form_state['values']['value'])) {
+    form_set_error('title', t('Number of posts must be a number!'));
+  }
+
+  foreach ($existing_titles as $title) {
+    if ($title->tid != $form_state['values']['tid']) {
+      if ($title->title == $form_state['values']['title']) {
+       form_set_error('title', t('This title already exists for the selected role.  Titles must be unique.'));
+      }
+      if ($title->value == $form_state['values']['value']) {
+        form_set_error('value', t('There is already a title for this number of posts for the selected role.  Posts must be unique.'));
+      }
+    }
+  }
+}
+
+/**
+ * Submit function for the add title form.
+ */
+function user_titles_add_title_form_submit($form, &$form_state) {
+  // Do file processing if a file has been added.
+  $image = '';
+
+  // Get directory
+  $dir = file_create_path(variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR));
+  file_check_directory($dir, 1, 'image_upload');
+
+  // Save file
+  $validators = array(
+    'file_validate_is_image' => array(),
+  );
+  if ($file = file_save_upload('image_upload', $validators, $dir, TRUE)) {
+    $image = $file->filepath;
+    drupal_set_message(t('The file: <strong>"' . $file->filename . '"</strong> is successfully uploaded'));
+  }
+ // else if ($file === 0) {
+  //  drupal_set_message(t('ERROR uploading the file to ' . $dir . '.  The user title has been created without an image.'), 'error');
+ // }
+
+  // Save title information
+  if ($form_state['values']['tid']) {
+    // Only update image information if an image was uploaded so images don't get lost.
+    if ($image != '') {
+      db_query("UPDATE {user_titles} SET title = '%s', value = %d, image = '%s', image_title = '%s', rid = %d WHERE tid = %d", $form_state['values']['title'], $form_state['values']['value'], $image, $form_state['values']['image_title'], $form_state['values']['role'], $form_state['values']['tid']);
+    }
+    elseif ($form_state['values']['remove_image']) {
+      db_query("UPDATE {user_titles} SET title = '%s', value = %d, image = '%s', image_title = '%s', rid = %d WHERE tid = %d", $form_state['values']['title'], $form_state['values']['value'], '', '', $form_state['values']['role'], $form_state['values']['tid']);
+    }
+    else {
+      db_query("UPDATE {user_titles} SET title = '%s', value = %d, image_title = '%s', rid = %d WHERE tid = %d", $form_state['values']['title'], $form_state['values']['value'], $form_state['values']['image_title'], $form_state['values']['role'], $form_state['values']['tid']);
+    }
+    drupal_set_message(t('Updated user title %title.', array('%title' => $form_state['values']['title'])));
+    $form_state['redirect'] = 'admin/user/user-titles/titles';
+  }
+  else {
+    db_query("INSERT INTO {user_titles} (title, value, image, image_title, rid) VALUES ('%s', %d, '%s', '%s', %d)", $form_state['values']['title'], $form_state['values']['value'], $image, $form_state['values']['image_title'], $form_state['values']['role']);
+    drupal_set_message(t('Created new user title %title.', array('%title' => $form_state['values']['title'])));
+    $form_state['redirect'] = 'admin/user/user-titles/add/title';
+  }
+
+  return;
+}
+
+/**
+ * Page to edit a user title.
+ * Redirects to either the add title form or the delete title form.
+ *
+ * @param $title
+ *   A title object to edit or delete.
+ */
+function user_titles_edit_title_form($title) {
+  if ($_POST['op'] == t('Delete') || $_POST['confirm']) {
+    return drupal_get_form('user_titles_delete_title_form', $title);
+  }
+  if ($title) {
+    return drupal_get_form('user_titles_add_title_form', $title);
+  }
+  return drupal_not_found();
+}
+
+/**
+ * Confirm deletion of user title form.
+ *
+ * @param $title
+ *   A title object to delete.
+ */
+function user_titles_delete_title_form(&$form_values, $title) {
+  $form = array();
+  $form['tid'] = array(
+    '#type' => 'hidden',
+    '#value' => $title->tid,
+  );
+
+  $form['title'] = array(
+    '#type' => 'hidden',
+    '#value' => $title->title,
+  );
+
+  $confirm_form = confirm_form($form,
+    t('Are you sure you want to delete the user title: %title?', array('%title' => $title->title)),
+    'admin/user/user-titles/titles',
+    t('This action cannot be undone.'),
+    t('Delete'),
+    t('Cancel'));
+
+  return $confirm_form;
+}
+
+/**
+ * Submit function for the delete user titles form.
+ */
+function user_titles_delete_title_form_submit($form, &$form_state) {
+  if ($form_state['values']['tid'] && is_numeric($form_state['values']['tid'])) {
+    $success = db_query("DELETE FROM {user_titles} WHERE tid = %d", $form_state['values']['tid']);
+  }
+
+  if ($success) {
+    drupal_set_message("User title '" . $form_state['values']['title'] . "' has been deleted successfully.", 'status');
+  }
+  else {
+    drupal_set_message("Deletion of user title '" . $form_state['values']['title'] . "' has failed.", 'error');
+  }
+
+  $form_state['redirect'] = 'admin/user/user-titles/titles';
+  return;
+}
+
+/**
+ * Theme function for the user title settings form.
+ *
+ * @param $form
+ *   The form array of the user titles settings form.
+ * 
+ * @return
+ *   A string containing the html output for the user titles settings form.
+ *
+ * @ingroup themeable
+ */
+function theme_user_titles_settings_form($form) {
+  // Properly format hook_module
+  foreach ($form['settings']['hook_module']['#options'] as $module => $info) {
+    if ($info['url']) {
+      $name = l($info['name'], $info['url']);
+    }
+    else {
+      $name = check_plain($info['name']);
+    }
+    // drupal_render uses this area, not the original
+    $form['settings']['hook_module'][$module]['#title'] = '<strong>' . $name . '</strong><div class="description">' . $info['description'] . '</div>';
+  }
+
+  $output .= '<div class="settings">';
+  $output .= drupal_render($form['settings']);
+  $output .= '</div>';
+
+  $rows = array();
+  foreach (element_children($form['roles']) as $key) {
+    if (isset($form['roles'][$key]['name'])) {
+      $role = &$form['roles'][$key];
+
+      $row = array();
+      $row[] = drupal_render($role['name']);
+      if (isset($role['weight'])) {
+        $role['weight']['#attributes']['class'] = 'role-weight';
+        $row[] = drupal_render($role['weight']);
+      }
+      $rows[] = array('data' => $row, 'class' => 'draggable');
+    }
+  }
+  if (empty($rows)) {
+    $rows[] = array(array('data' => t('No roles available.')));
+  }
+
+  $header = array(t('Role'), t('Weight'));
+  drupal_add_tabledrag('roles', 'order', 'sibling', 'role-weight');
+
+  $output .= '<fieldset class="roles-table">';
+  $output .= '<legend>' . t('Role priority') . '</legend>';
+  $output .= drupal_render($form['roles-description']);
+  $output .= theme('table', $header, $rows, array('id' => 'roles'));
+  $output .= '</fieldset>';
+
+  $output .= '<div class="clearer">&nbsp;</div>';
+  $output .= drupal_render($form);
+  return $output;
+}
+
+/**
+ * Theme function for the user title settings form.
+ *
+ * @param $form
+ *   The form array of the user titles titles form.
+ * 
+ * @return
+ *   A string containing the html output for the user titles titles form.
+ *
+ * @ingroup themeable
+ */
+function theme_user_titles_titles_form($form) {
+  drupal_add_js('misc/collapse.js');
+  $output = '';
+  $units = module_invoke(user_titles_get_hook_module(), 'user_titles', 'units');
+  $header = array(
+    array('data' => $units, 'class' => 'num-posts'),
+    array('data' => t('Title'), 'class' => 'user-title'),
+    array('data' => t('Image'), 'class' => 'user-title-image'),
+    array('data' => t('Operations'), 'colspan' => 2),
+  );
+
+  foreach (element_children($form['roles']) as $rid) {
+    $role = &$form['roles'][$rid];
+    $rows = array();
+    if (isset($role['titles'])) {
+      foreach (element_children($form['roles'][$rid]['titles']) as $key) {
+        // set a reference so that the drupal_render gets remembered.
+        unset($elem);
+        $elem = &$form['roles'][$rid]['titles'][$key];
+
+        $rows[] = array(
+          array('data' => drupal_render($elem['value']), 'class' => 'num-posts'),
+          array('data' => drupal_render($elem['title']), 'class' => 'user-title'),
+          array('data' => drupal_render($elem['image']), 'class' => 'user-title-image'),
+          'edit' => l(t('edit'), "admin/user/user-titles/edit/title/" . $elem['tid']['#value']),
+          'delete' => l(t('delete'), "admin/user/user-titles/delete/title/" . $elem['tid']['#value']),
+        );
+      }
+    }
+    if (empty($rows)) {
+      $rows[] = array(array('data' => t('No titles set.'), 'colspan' => '5'));
+    }
+
+    $output .= '<fieldset class="collapsible collapsed title-table ' . $role['name']['#value'] . '">';
+    $output .= '<legend>' . drupal_render($role['name']) . '</legend>';
+    $output .= theme('table', $header, $rows);
+    $output .= drupal_render($role['add_title']);
+    $output .= '</fieldset>';
+  }
+
+  $output .= '<div class="clearer">&nbsp;</div>';
+  $output .= drupal_render($form);
+  return $output;
+}
+
diff -rupN user_titles/user_titles.info user_titles_new/user_titles.info
--- user_titles/user_titles.info	2009-10-12 23:36:55.000000000 +1100
+++ user_titles.info	2009-11-15 06:09:42.000000000 +1100
@@ -3,10 +3,3 @@ name = User titles
 description = Allow users to have titles based upon how many posts they have.
 core = 6.x
 
-
-; Information added by drupal.org packaging script on 2009-10-12
-version = "6.x-1.x-dev"
-core = "6.x"
-project = "user_titles"
-datestamp = "1255351015"
-
diff -rupN user_titles/user_titles.install user_titles_new/user_titles.install
--- user_titles/user_titles.install	2009-01-07 12:35:55.000000000 +1100
+++ user_titles.install	2010-01-28 22:45:05.000000000 +1100
@@ -1,5 +1,6 @@
 <?php
 // $Id: user_titles.install,v 1.4.2.1 2009/01/07 01:35:55 agileware Exp $
+
 /**
  * @file user_titles.install
  * Installation file for user_titles module
@@ -37,6 +38,12 @@ function user_titles_schema() {
         'not null' => TRUE,
         'default' => '',
       ),
+      'rid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 2,
+      ),
     ),
     'primary key' => array('tid'),
   );
@@ -57,6 +64,22 @@ function user_titles_schema() {
     'primary key' => array('uid'),
   );
 
+  $schema['user_titles_roles'] = array(
+    'fields' => array(
+      'rid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+      ),
+      'weight' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array('rid'),
+  );
+
   return $schema;
 }
 
@@ -65,17 +88,24 @@ function user_titles_schema() {
  */
 function user_titles_install() {
   drupal_install_schema('user_titles');
+
+  db_query("INSERT INTO {user_titles_roles} (rid, weight) SELECT rid, 0 FROM {role} WHERE rid NOT IN (1, 2)");
+  db_query("INSERT INTO {user_titles_roles} (rid, weight) VALUES (2, -10)");
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function user_titles_uninstall() {
+  variable_del('user_titles_hook_module');
+  variable_del('user_titles_types');
+  variable_del('user_titles_image_dir');
+
   drupal_uninstall_schema('user_titles');
 }
 
 /**
- * Implementation of hook_update().
+ * Implementation of hook_update_N().
  */
 function user_titles_update_6100() {
   $ret = array();
@@ -87,4 +117,35 @@ function user_titles_update_6100() {
   db_add_field($ret, 'user_titles', 'image_title', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
 
   return $ret;
-}
\ No newline at end of file
+}
+
+/**
+ * Implementation of hook_update_N().
+ */
+function user_titles_update_6101() {
+  $ret = array();
+
+  db_add_field($ret, 'user_titles', 'rid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 2));
+
+  $schema['user_titles_roles'] = array(
+    'fields' => array(
+      'rid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'unsigned' => TRUE,
+      ),
+      'weight' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array('rid'),
+  );
+  db_create_table($ret, 'user_titles_roles', $schema['user_titles_roles']);
+
+  $ret[] = update_sql("INSERT INTO {user_titles_roles} (rid, weight) SELECT rid, 0 FROM {role} WHERE rid NOT IN (1, 2)");
+  $ret[] = update_sql("INSERT INTO {user_titles_roles} (rid, weight) VALUES (2, -10)");
+
+  return $ret;
+}
diff -rupN user_titles/user_titles.module user_titles_new/user_titles.module
--- user_titles/user_titles.module	2009-10-12 18:37:39.000000000 +1100
+++ user_titles.module	2010-01-28 22:00:58.000000000 +1100
@@ -1,5 +1,6 @@
 <?php
 // $Id: user_titles.module,v 1.14.2.5 2009/10/12 07:37:39 agileware Exp $
+
 /** 
  * @file user_titles.module
  * Allows assignment of titles to a user based upon the number of posts the 
@@ -14,7 +15,7 @@ define('DEFAULT_IMAGE_DIR', 'user-titles
 function user_titles_help($path, $arg) {
   switch ($path) {
     case 'admin/user/user-titles':
-      return t('Click "Save" to change settings or use the "Add title" tab to add a new title.');
+      return t('Click "Save" to save changes, use the "Add title" tab to add a new title or use the "Titles" tab to view current titles.');
   }
 }
 
@@ -35,33 +36,46 @@ function user_titles_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('user_titles_settings_form'),
     'access arguments' => array('administer user titles'),
+    'file' => 'user_titles.admin.inc',
   );
-  $items['admin/user/user-titles/list'] = array(
-    'title' => t('List'),
+  $items['admin/user/user-titles/settings'] = array(
+    'title' => t('Settings'),
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'weight' => -10
   );
+  $items['admin/user/user-titles/titles'] = array(
+    'title' => t('Titles'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('user_titles_titles_form'),
+    'access arguments' => array('administer user titles'),
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'user_titles.admin.inc',
+  );
   $items['admin/user/user-titles/add/title'] = array(
     'title' => t('Add title'),
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('user_titles_title_form'),
+    'page arguments' => array('user_titles_add_title_form'),
     'access arguments' => array('administer user titles'),
-    'type' => MENU_LOCAL_TASK
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'user_titles.admin.inc',
   );
   $items['admin/user/user-titles/edit/title/%title'] = array(
     'title' => t('Edit title'),
-    'page callback' => 'user_titles_edit_title',
+    'page callback' => 'user_titles_edit_title_form',
     'page arguments' => array(5),
     'access arguments' => array('administer user titles'),
-    'type' => MENU_CALLBACK
+    'type' => MENU_CALLBACK,
+    'file' => 'user_titles.admin.inc',
   );
   $items['admin/user/user-titles/delete/title/%title'] = array(
     'title' => t('Remove title'),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('user_titles_delete_title_form', 5),
     'access arguments' => array('administer user titles'),
-    'type' => MENU_CALLBACK
+    'type' => MENU_CALLBACK,
+    'file' => 'user_titles.admin.inc',
   );
+
   return $items;
 }
 
@@ -80,118 +94,6 @@ function title_load($tid) {
 }
 
 /**
- * Determines what the current hook module implementation is, or '' if
- * using built-in version. Ensures the module is loaded too.
- */
-function user_titles_hook_module() {
-  $module = variable_get('user_titles_hook_module', $default = 'user_titles');
-  if (module_exists($module)) {
-    return $module;
-  }
-  else {
-    return $default;
-  }
-}
-
-
-/**
- * Form to determine titles and levels.
- */
-function user_titles_settings_form(&$form_state) {
-  $form = array();
-
-  $types = user_titles_get_allowed_types();
-
-  foreach (node_get_types() as $type => $info) {
-    $nodes[$type] = $info->name;
-  }
-
-  $hook_module  = user_titles_hook_module();
-  $hook_modules = module_invoke_all('user_titles', 'register');
-
-
-  $form['settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Settings',
-  );
-
-  $form['settings']['hook_module'] = array(
-    '#type' => 'radios',
-    '#title' => 'Point scheme',
-    '#default_value' => $hook_module,
-    '#options' => array(),
-    '#attributes' => array('class' => 'user-titles-hook-module'),
-  );
-  foreach ($hook_modules as $module) {
-    $form['settings']['hook_module']['#options'][$module] = array(
-      'name'        => $name = module_invoke($module, 'user_titles', 'name'),
-      'description' => module_invoke($module, 'user_titles', 'description'),
-      'url'         => module_invoke($module, 'user_titles', 'url'),
-    );
-    $name_index[$module] = $name;
-  }
-
-  array_multisort($name_index, SORT_ASC, SORT_STRING, $form['settings']['hook_module']['#options']);
-
-  // Implementation of user_titles' default behavior
-  $form['settings']['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' => $hook_module !== 'user_titles',
-    '#attributes' => array('class' => 'user-titles-types'),
-  );
-  $form['settings']['types_disabled'] = array(
-    '#type' => 'hidden',
-    '#default_value' => $hook_module !== 'user_titles',
-  );
-
-  // Directory to save images
-  $form['settings']['image_dir'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Image directory'),
-    '#description' => t('Subdirectory in the directory %dir where images will be stored.', array('%dir' => file_directory_path() .'/')),
-    '#default_value' => variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR),
-    '#size' => 35,
-    '#attributes' => array('class' => 'user-titles-image-dir'),
-  );
-
-  $form['settings']['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save'),
-  );
-
-  $titles = user_titles_get_titles();
-
-  $form['titles'] = array('#tree' => TRUE);
-
-  foreach ($titles as $i => $title) {
-    $form['titles'][$i]['value'] = array(
-      '#type' => 'markup',
-      '#value' => $title['value'],
-    );
-    $form['titles'][$i]['title'] = array(
-      '#type' => 'markup',
-      '#value' => $title['title'],
-    );
-    $form['titles'][$i]['image'] = array(
-      '#type' => 'markup',
-      '#value' => theme('user_titles_image', $title['image'], $title['image_title']),
-    );
-    $form['titles'][$i]['tid'] = array(
-      '#type' => 'hidden',
-      '#value' => $title['tid'],
-    );
-  }
-
-  $form['#submit'] = array('user_titles_settings_form_submit_handler');
-
-  return $form;
-}
-
-/**
  * Implementation of hook_theme().
  */
 function user_titles_theme($existing, $type, $theme, $path) {
@@ -199,368 +101,273 @@ function user_titles_theme($existing, $t
     'user_titles_settings_form' => array(
       'arguments' => array('form' => NULL),
     ),
+    'user_titles_titles_form' => array(
+      'arguments' => array('form' => NULL),
+    ),
     'user_titles_image' => array(
       'arguments' => array('filepath' => NULL, 'alt' => NULL),
     ),
   );
 }
 
-
 /**
- * Theme function for the user title settings form.
+ * Implementation of hook_form_alter().
  */
-function theme_user_titles_settings_form($form) {
-  $path = drupal_get_path('module', 'user_titles');
-  drupal_add_css("$path/admin.css");
-
-  $units = module_invoke(user_titles_hook_module(), 'user_titles', 'units');
-  $header = array(
-    array('data' => $units, 'class' => 'num-posts'),
-    array('data' => t('Title'), 'class' => 'user-title'),
-    array('data' => t('Image'), 'class' => 'user-title-image'),
-    array('data' => t('Operations'), 'colspan' => 2),
-  );
-
-  $rows = array();
-  foreach (element_children($form['titles']) as $key) {
-    // set a reference so that the drupal_render gets remembered.
-    unset($elem);
-    $elem = &$form['titles'][$key];
-
-    $rows[] = array(
-      array('data' => drupal_render($elem['value']), 'class' => 'num-posts'),
-      array('data' => drupal_render($elem['title']), 'class' => 'user-title'),
-      array('data' => drupal_render($elem['image']), 'class' => 'user-title-image'),
-      drupal_render($elem['tid']),
-      'edit' => l(t('edit'), "admin/user/user-titles/edit/title/" . $elem['tid']['#value']),
-      'delete' => l(t('delete'), "admin/user/user-titles/delete/title/" . $elem['tid']['#value']),
-    );
+function user_titles_form_alter(&$form, $form_state, $form_id) {
+  if ($form_id == 'user_admin_new_role') {
+    $form['#submit'][] = 'user_titles_user_admin_new_role_submit';
   }
-
-  $output = '<div class="title-table">';
-  $output .= theme('table', $header, $rows, array('id' => 'user-titles-settings'));
-  $output .= '</div>';
-
-  // Properly format hook_module
-  foreach ($form['settings']['hook_module']['#options'] as $module => $info) {
-    if ($info['url']) {
-      $name = l($info['name'], $info['url']);
-    }
-    else {
-      $name = check_plain($info['name']); drupal_get_form('user_titles_title_form', $title);
-    }
-    // drupal_render uses this area, not the original
-    $form['settings']['hook_module'][$module]['#title'] = '<strong>'. $name .'</strong><div class="description">'. $info['description'] .'</div>';
+  elseif ($form_id == 'user_admin_role') {
+    $form['#submit'][] = 'user_titles_user_admin_role_submit';
   }
-
-  $output .= '<div class="settings">';
-  $output .= drupal_render($form['settings']);
-  $output .= '</div>';
-
-  $output .= '<div class="clearer">&nbsp;</div>';
-  $output .= drupal_render($form);
-  return $output;
 }
 
 /**
- * Submit the user titles setting form
+ * Implementation of hook_nodeapi().
  */
-function user_titles_settings_form_submit_handler($form, &$form_state) {
-  // If they change the allowed types, wipe the existing counts so each one will be fresh.
-  $types = user_titles_get_allowed_types();
-  if ($types != $form_values['types']) {
-    db_query("TRUNCATE {user_titles_posts}");
-  }
-
-  if (!$form_state['values']['types_disabled']) {
-    user_titles_set_allowed_types(array_keys(array_filter($form_state['values']['types'])));
+function user_titles_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+  if ($op == 'insert' || $op == 'delete') {
+    $allowed_types = user_titles_get_allowed_types();
+    if (in_array($node->type, $allowed_types)) {
+      $inc = ($op == 'insert') ? 1 : -1;
+      db_query("UPDATE {user_titles_posts} SET posts = %d WHERE uid = %d", user_titles_get_posts($node->uid) + $inc, $node->uid);
+      if (!db_affected_rows()) {
+        db_query("INSERT INTO {user_titles_posts} (uid, posts) VALUES (%d, %d)", $node->uid, user_titles_get_posts($node->uid) + $inc);
+      }
+    }
   }
-
-  variable_set('user_titles_hook_module', $form_state['values']['hook_module']);
-  variable_set('user_titles_image_dir', $form_state['values']['image_dir']);
-
-  $image_path = file_create_path(variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR));
-  file_check_directory($image_path, 1, 'image_dir');
-
-  drupal_set_message(t('The configuration has been updated.'));
 }
 
 /**
- * Form for adding/editing user titles.
+ * Extra submit handler for the user_admin_new_role form.
  */
-function user_titles_title_form(&$form_state, $edit = array()) {
-  $path = drupal_get_path('module', 'user_titles');
-  drupal_add_css("$path/admin.css");
-
-  // For file field to work.
-  $form['#attributes'] = array('enctype' => 'multipart/form-data');
-
-  $units = module_invoke(user_titles_hook_module(), 'user_titles', 'units');
-  $form['value'] = array(
-    '#type' => 'textfield',
-    '#title' => t($units),
-    '#size' => 5,
-    '#maxlength' => 10,
-    '#required' => TRUE,
-    '#default_value' => $edit['value'],
-  );
-
-  $form['title'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Title'),
-    '#size' => 40,
-    '#maxlength' => 128,
-    '#required' => TRUE,
-    '#default_value' => $edit['title'],
-  );
-
-  $form['image'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Image'),
-  );
-
-  $form['image']['image_display'] = array(
-    '#type' => 'item',
-    '#value' => theme('user_titles_image', $edit['image'], $edit['image_title']),
-  );
-
-  if ($edit['image']) {
-    $form['image']['remove_image'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Remove image'),
-      '#description' => t('If checked this image will be removed from this title on submit.'),
-    );
+function user_titles_user_admin_new_role_submit($form, &$form_state) {
+  if ($form_state['values']['op'] == t('Add role')) {
+    $max_weight = db_result(db_query("SELECT MAX(weight) FROM {user_titles_roles}"));
+    db_query("INSERT INTO {user_titles_roles} (rid, weight)
+              SELECT rid, %d FROM {role} WHERE name = '%s'", $max_weight + 1, $form_state['values']['name']);
   }
-
-  $form['image']['image_title'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Image title/alt text'),
-    '#size' => 40,
-    '#maxlength' => 255,
-    '#default_value' => $edit['image_title'],
-      '#description' => t('This text will be used as the title and alt text for the image when it is displayed.'),
-  );
-
-  $form['image']['image_upload'] = array(
-    '#type' => 'file',
-    '#title' => t('Upload new image'),
-    '#size' => 40,
-    '#description' => t('Upload an image that can be displayed with this user title.  This image will replace any existing image attached to this title.'),
-  );
-
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save'),
-  );
-
-  if ($edit['tid']) {
-    $form['delete'] = array(
-      '#type' => 'submit',
-      '#value' => t('Delete'));
-    $form['tid'] = array(
-      '#type' => 'value',
-      '#value' => $edit['tid'],
-    );
-  }
-
-  $form['#submit'] = array('user_titles_title_form_submit_handler');
-
-  return $form;
 }
 
 /**
- * Implementation of hook_validate().
- * Validate the add title form.
+ * Extra submit handler for the user_admin_role form.
  */
-function user_titles_title_form_validate($form, &$form_state) {
-  $existing_titles = user_titles_get_titles();
-
-  if (!is_numeric($form_state['values']['value'])) {
-    form_set_error('title', t('Number of posts must be a number!'));
+function user_titles_user_admin_role_submit($form, &$form_state) {
+  if ($form_state['values']['op'] == t('Delete role')) {
+    db_query("DELETE FROM {user_titles_roles} WHERE rid = %d", $form_state['values']['rid']);
   }
+}
 
-  foreach ($existing_titles as $title) {
-    if ($title['tid'] != $form_state['values']['tid']) {
-      if ($title['title'] == $form_state['values']['title']) {
-       form_set_error('title', t('This title already exists.  Titles must be unique.'));
-      }
-      if ($title['value'] == $form_state['values']['value']) {
-        form_set_error('value', t('There is already a title for this number of posts.  Posts must be unique.'));
+/**
+ * Implementation of hook_block().
+ */
+function user_titles_block($op = 'list', $delta = 0, $edit = array()) {
+  switch ($op) {
+    case 'list':
+      $blocks[0] = array(
+        'info' => t('User Titles: Users with my title'),
+        'cache' => BLOCK_CACHE_PER_USER,
+      );
+      return $blocks;
+    case 'view':
+      // If $op is "view", then we need to generate the block for display
+      // purposes. The $delta parameter tells us which block is being requested.
+      switch ($delta) {
+        case 0:
+          $block['subject'] = t('Users with your title');
+          $block['content'] = user_titles_matching_users_block();
+          break;
       }
-    }
+      return $block;
   }
+
 }
 
 /**
- * Submit the add title form.
+ * Creates the content for a block that lists users with your title.
+ * Displays 10 random users with the same title as you.
+ *
+ * @return
+ *   A string containing the html output for the matching users block.
  */
-function user_titles_title_form_submit_handler($form, &$form_state) {
-  // Do file processing if a file has been added.
-  $image = '';
-
-  // Get directory
-  $dir = file_create_path(variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR));
-  file_check_directory($dir, 1, 'image_upload');
-
-  // Save file
-  $validators = array(
-    'file_validate_is_image' => array(),
-  );
-  if ($file = file_save_upload('image_upload', $validators, $dir, TRUE)) {
-    $image = $file->filepath;
-    drupal_set_message(t('The file: <strong>"' . $file->filename . '"</strong> is successfully uploaded'));
-  }
- // else if ($file === 0) {
-  //  drupal_set_message(t('ERROR uploading the file to ' . $dir . '.  The user title has been created without an image.'), 'error');
- // }
-
-  // Save title information
-  if ($form_state['values']['tid']) {
-    // Only update image information if an image was uploaded so images don't get lost.
-    if ($image != '') {
-      db_query("UPDATE {user_titles} SET title = '%s', value = %d, image = '%s', image_title = '%s' WHERE tid = %d", $form_state['values']['title'], $form_state['values']['value'], $image, $form_state['values']['image_title'], $form_state['values']['tid']);
-    }
-    else if ($form_state['values']['remove_image']) {
-      db_query("UPDATE {user_titles} SET title = '%s', value = %d, image = '%s', image_title = '%s' WHERE tid = %d", $form_state['values']['title'], $form_state['values']['value'], '', '', $form_state['values']['tid']);
-    }
-    else {
-      db_query("UPDATE {user_titles} SET title = '%s', value = %d, image_title = '%s' WHERE tid = %d", $form_state['values']['title'], $form_state['values']['value'], $form_state['values']['image_title'], $form_state['values']['tid']);
+function user_titles_matching_users_block() {
+  global $user;
+  $users = user_titles_get_matching_users($user);
+  if (!empty($users)) {
+    shuffle($users);
+    $count = min(10, count($users));
+    $output = '<ul>';
+    for ($i = 0; $i < $count; $i++) {
+      $temp_user = user_load(array('uid' => $users[$i]));
+      $output .= '<li>' . l(t($temp_user->name), 'user/' . $temp_user->uid) . '</li>';
     }
-    drupal_set_message(t('Updated user title %title.', array('%title' => $form_state['values']['title'])));
-    $form_state['redirect'] = 'admin/user/user-titles';
+    $output .= '</ul>';
   }
   else {
-    db_query("INSERT INTO {user_titles} (title, value, image, image_title) VALUES ('%s', %d, '%s', '%s')", $form_state['values']['title'], $form_state['values']['value'], $image, $form_state['values']['image_title']);
-    drupal_set_message(t('Created new user title %title.', array('%title' => $form_state['values']['title'])));
-    $form_state['redirect'] = 'admin/user/user-titles/add/title';
+    $output .= '<span class="no-matches">' . t('There are no other uses with your title.') . '</span>';
   }
 
-  return;
+  return $output;
 }
 
 /**
- * Page to edit a user title.
+ * Implementation of hook_comment().
  */
-function user_titles_edit_title($title) {
-  if ($_POST['op'] == t('Delete') || $_POST['confirm']) {
-    return drupal_get_form('user_titles_delete_title_form', $title);
-  }
-  if ($title) {
-    return drupal_get_form('user_titles_title_form', $title);
+function user_titles_comment($a1, $op) {
+  if ($op == 'insert' || $op == 'delete') {
+    $a1 = (object)$a1; // sometimes an array is passed in
+    $node = node_load($a1->nid);
+    $types = user_titles_get_allowed_types();
+    if (in_array($node->type, $types)) {
+      $uid = $a1->uid;
+      $inc = ($op == 'insert') ? 1 : -1;
+      db_query("UPDATE {user_titles_posts} SET posts = %d WHERE uid = %d", user_titles_get_posts($uid) + $inc, $uid);
+      if (!db_affected_rows()) {
+        db_query("INSERT INTO {user_titles_posts} (uid, posts) VALUES (%d, %d)", $uid, user_titles_get_posts($uid) + $inc);
+      }
+    }
   }
-  return drupal_not_found();
 }
 
 /**
- * Confirm deletion of user title form.
+ * Implementation of hook_user().
+ *
+ * Add the 'edit user title' form to the edit user page.
  */
-function user_titles_delete_title_form(&$form_values, $title) {
-
-  $form = array();
-  $form['tid'] = array(
-    '#type' => 'hidden',
-    '#value' => $title['tid'],
-  );
+function user_titles_user($op, $edit, &$user, $category = NULL) {
+  switch ($op) {
+    case 'form':
+      if (user_access('administer user titles') && $category == 'account' && (isset($user->uid))) {
+        // when user tries to edit his own data
+        $form['user_titles'] = array(
+          '#type' => 'fieldset',
+          '#title' => t('User Title'),
+          '#collapsible' => TRUE,
+          '#weight' => 4,
+        );
+        $title_info = user_titles_get_user_title_info($user);
 
-  $form['title'] = array(
-    '#type' => 'hidden',
-    '#value' => $title['title'],
-  );
+        if (!isset($title_info->title)) {
+          $title = t('No title set');
+        }
+        else {
+          $title = $title_info->title;
+        }
 
-  $confirm_form = confirm_form($form,
-    t('Are you sure you want to delete the user title: %title?', array('%title' => $title['title'])),
-    'admin/user/user-titles',
-    t('This action cannot be undone.'),
-    t('Delete'),
-    t('Cancel'));
+        $form['user_titles']['current_title'] = array(
+          '#value' => '<div><strong>' . t('Current user title:') . ' </strong> ' . filter_xss_admin($title) . '</div>',
+        );
 
-  return $confirm_form;
-}
+        if (isset($title_info->title) && empty($title_info->tid)) {
+          $default_title_info = user_titles_get_title(user_titles_get_posts($uid));
+          if (!isset($default_title_info->title)) {
+            $default_title = t('No title set');
+          }
+          else {
+            $default_title = $default_title_info->title;
+          }
+          $form['user_titles']['default_title'] = array(
+            '#value' => '<div><strong>' . t('Default user title:') . ' </strong> ' . filter_xss_admin($default_title) . '</div>',
+          );
+        }
 
-/**
- * Implementation of hook_submit().
- * Submit the delete user titles form.
- */
-function user_titles_delete_title_form_submit($form, &$form_state) {
-  if ($form_state['values']['tid'] && is_numeric($form_state['values']['tid'])) {
-    $success = db_query("DELETE FROM {user_titles} WHERE tid = %d", $form_state['values']['tid']);
-  }
+        $form['user_titles']['user_title'] = array(
+          '#type' => 'textfield',
+          '#title' => t('Override title'),
+          '#description' => t('Enter a title here to give this user a manually overridden title. Leave blank to use the default title.'),
+          '#default_value' => isset($user->user_title) ? $user->user_title : '',
+        );
 
-  if ($success) {
-    drupal_set_message("User title '" . $form_state['values']['title'] . "' has been deleted successfully.", 'status');
-  }
-  else {
-    drupal_set_message("Deletion of user title '" . $form_state['values']['title'] . "' has failed.", 'error');
+        return $form;
+      }
+      break;
+    case 'delete':
+      db_query('DELETE FROM {user_titles_posts} WHERE uid = %d', $user->uid);
+      break;
+    case 'view':
+      $title = user_titles_get_user_title($user);
+      if ($title) {
+        $user->content['user_titles'] = array(
+          '#type' => 'user_profile_category',
+          '#title' => t('User title'),
+        );
+        $user->content['user_titles']['title'] = array(
+          '#type' => 'user_profile_item',
+          '#value' => filter_xss_admin($title),
+        );
+      }
+      break;
   }
-
-  $form_state['redirect'] = 'admin/user/user-titles';
-  return;
 }
 
 /**
- * Implementation of hook_nodeapi
+ * Get the currently used hook module.
+ *
+ * @return
+ *   A string containing the name of the module that is being used to calculate user titles.
  */
-function user_titles_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
-  if ($op == 'insert' || $op == 'delete') {
-    $allowed_types = user_titles_get_allowed_types();
-    if (in_array($node->type, $allowed_types)) {
-      $inc = ($op == 'insert') ? 1 : -1;
-      db_query("UPDATE {user_titles_posts} SET posts = %d WHERE uid = %d", user_titles_get_posts($node->uid) + $inc, $node->uid);
-      if (!db_affected_rows()) {
-        db_query("INSERT INTO {user_titles_posts} (uid, posts) VALUES (%d, %d)", $node->uid, user_titles_get_posts($node->uid) + $inc);
-      }
-    }
+function user_titles_get_hook_module() {
+  $default = 'user_titles';
+  $module = variable_get('user_titles_hook_module', $default);
+  if (module_exists($module)) {
+    return $module;
+  }
+  else {
+    return $default;
   }
 }
 
 /**
- * Implementation of hook_comment.
+ * Set the currently used hook module.
+ *
+ * @param
+*   A string containing the name of the module that is being used to calculate user titles.
  */
-function user_titles_comment($a1, $op) {
-  if ($op == 'insert' || $op == 'delete') {
-    $a1 = (object)$a1; // sometimes an array is passed in
-    $node = node_load($a1->nid);
-    $types = user_titles_get_allowed_types();
-    if (in_array($node->type, $types)) {
-      $uid = $a1->uid;
-      $inc = ($op == 'insert') ? 1 : -1;
-      db_query("UPDATE {user_titles_posts} SET posts = %d WHERE uid = %d", user_titles_get_posts($uid) + $inc, $uid);
-      if (!db_affected_rows()) {
-        db_query("INSERT INTO {user_titles_posts} (uid, posts) VALUES (%d, %d)", $uid, user_titles_get_posts($uid) + $inc);
-      }
-    }
-  }
+function user_titles_set_hook_module($module) {
+  variable_set('user_titles_hook_module', $module);
 }
 
 /**
- * Load the number of posts for a user. If we don't have a stored count
- * in the database, count and store that value.
+ * Get the number of posts for a user.
+ * If we don't have a stored count in the database, count and store that value.
  * 
- * @todo When porting to 7.x, rename to user_title_get_points
+ * @todo When porting to 7.x, rename to user_title_get_points.
  *
  * @param $uid
- *   The user to fetch the number of posts for.
+ *   An integer containing the uid of the user to fetch the number of posts for.
+ * 
+ * @return
+ *   An integer containing the number of posts for the user.
  */
 function user_titles_get_posts($uid) {
   static $cache = array();
   if (!isset($cache[$uid])) {
-    $module = user_titles_hook_module();
+    $module = user_titles_get_hook_module();
     $cache[$uid] = module_invoke($module, 'user_titles', 'get', $uid);
   }
   return $cache[$uid];
 }
 
 /**
- * Calculate a title based upon the number of posts.
+ * Calculate a title based upon the number of posts and user role.
  *
  * @param $posts
  *   The number of posts to find the title for.
+ * @param $rid
+ *   The role id to get the title for.
+ *   If $rid is NULL the default user titles role will be used.
+ *
+ * @return
+ *   A title object for the number of posts and role.
  */
-function user_titles_get_title($posts) {
-  $titles = user_titles_get_titles();
+function user_titles_get_title($posts, $rid = NULL) {
+  if (!$rid) {
+    $rid = user_titles_get_default_role();
+  }
+  $titles = user_titles_get_titles_by_role($rid);
   // This array will be sorted from highest to lowest prior to storing.
   foreach ($titles as $title) {
-    if ($posts >= $title['value']) {
+    if ($posts >= $title->value) {
       return $title;
     }
   }
@@ -569,39 +376,39 @@ function user_titles_get_title($posts) {
 /**
  * Fetch a title for the given user.
  * 
- * @param $account
- *   The user to fetch. May be a $user object or a $uid.
+ * @param $user
+ *   The user to fetch the title for. May be a $user object or a $uid.
  */
-function user_titles_get_user_title($account) {
-  $title = user_titles_get_user_title_info($account);
-  if (isset($title['title'])) {
-    return $title['title'];
+function user_titles_get_user_title($user) {
+  $title = user_titles_get_user_title_info($user);
+  if (isset($title->title)) {
+    return $title->title;
   }
 }
 
 /**
  * Fetch the user title image path for the given user.
  *
- * @param $account
- *   The user to fetch. May be a $user object or a $uid.
+ * @param $user
+ *   The user to fetch the image path for. May be a $user object or a $uid.
  */
-function user_titles_get_user_image_path($account) {
-  $title = user_titles_get_user_title_info($account);
-  if (isset($title['image'])) {
-    return $title['image'];
+function user_titles_get_user_image_path($user) {
+  $title = user_titles_get_user_title_info($user);
+  if (isset($title->image)) {
+    return $title->image;
   }
 }
 
 /**
  * Fetch the themed user title image for the given user.
  *
- * @param $account
- *   The user to fetch. May be a $user object or a $uid.
+ * @param $user
+ *   The user to fetch the image for. May be a $user object or a $uid.
  */
-function user_titles_get_user_image($account) {
-  $title = user_titles_get_user_title_info($account);
-  if (isset($title['image'])) {
-    return theme('user_titles_image', $title['image'], $title['image_title']);
+function user_titles_get_user_image($user) {
+  $title = user_titles_get_user_title_info($user);
+  if (isset($title->image)) {
+    return theme('user_titles_image', $title->image, $title->image_title);
   }
 }
 
@@ -611,48 +418,66 @@ function user_titles_get_user_image($acc
  * @param $uid
  *   The user to fetch. May be a $user object or a $uid.
  */
-function user_titles_get_user_title_info($account) {
-  if (is_numeric($account)) {
-    $account = user_load(array('uid' => $account));
+function user_titles_get_user_title_info($user) {
+  if (is_numeric($user)) {
+    $user = user_load(array('uid' => $user));
   }
-  if (!$account) {
+  if (!$user) {
     return;
   }
 
-  if (!empty($account->user_title)) {
-    return array('title' => $account->user_title);
+  if (!empty($user->user_title)) {
+    return array('title' => $user->user_title);
   }
-  return user_titles_get_title(user_titles_get_posts($account->uid));
+  $rid = user_titles_get_users_title_role($user->uid);
+
+  return user_titles_get_title(user_titles_get_posts($user->uid), $rid);
 }
 
 /**
  * Returns the next highest title from the given title
  */
-function user_titles_get_next_higher_title($tid) {
-  $title = db_fetch_array(db_query("SELECT * FROM {user_titles} WHERE value > (SELECT value FROM user_titles WHERE tid = %d) ORDER BY value LIMIT 1", $tid));
+function user_titles_get_next_higher_title($tid, $rid) {
+  $title = db_fetch_object(db_query_range("SELECT *
+                                           FROM {user_titles}
+                                           WHERE value > (SELECT value
+                                                          FROM user_titles
+                                                          WHERE tid = %d)
+                                           AND rid = %d
+                                           ORDER BY value", $tid, $rid, 0, 1));
   return $title;
 }
 
 /**
- * Get users (uids) that have a given title
+ * Get users (uids) that have a given title in a given role.
  * 
- * @param $uid
- *   The user to fetch. May be a $user object or a $uid.
+ * @param $user
+ *   The user object to fetch the matching users for.
  */
-function user_titles_get_matching_users($uid) {
-  $title = user_titles_get_user_title_info($uid);
-  $next_title = user_titles_get_next_higher_title($title['tid']);
+function user_titles_get_matching_users($user) {
+  $title = user_titles_get_user_title_info($user->uid);
+  $next_title = user_titles_get_next_higher_title($title->tid, $title->rid);
 
   if ($next_title !== FALSE) {
-    $result = db_query("SELECT uid FROM {user_titles_posts} WHERE posts >= %d AND posts < %d AND uid NOT IN (0, %d)", $title['value'], $next_title['value'], $uid);
+    $result = db_query("SELECT uid
+                        FROM {user_titles_posts}
+                        WHERE posts >= %d
+                        AND posts < %d
+                        AND uid NOT IN (0, %d)", $title->value, $next_title->value, $user->uid);
   }
   else {
-    $result = db_query("SELECT uid FROM {user_titles_posts} WHERE posts >= %d AND uid NOT IN (0, %d)", $title['value'], $uid);
+    $result = db_query("SELECT uid
+                        FROM {user_titles_posts}
+                        WHERE posts >= %d
+                        AND uid NOT IN (0, %d)", $title->value, $user->uid);
   }
 
   $users = array();
   while ($row = db_fetch_array($result)) {
-    $users[] = $row['uid'];
+    // Only return users in the same user titles role
+    if (user_titles_get_users_title_role($row['uid']) == $title->rid) {
+      $users[] = $row['uid'];
+    }
   }
 
   return $users;
@@ -666,29 +491,45 @@ function user_titles_get_matching_users(
  * @param $count
  *   The count to write. If not given, posts will be counted and that data 
  *   written.
+ *
+ * @return
+ *   The post count for the user.
  */
 function user_titles_update_post_count($uid, $count = NULL) {
   if (is_null($count)) {
-    // fetch count from the database
+    // Fetch count from the database
     $allowed_types = user_titles_get_allowed_types();
     if ($allowed_types) {
-      $types = implode("','", $allowed_types);
-      $count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE uid = %d AND type IN ('$types')", $uid));
+      $in = '';
+      $query_args = array($uid);
+      foreach ($allowed_types as $type) {
+        $query_args[] = $type;
+        $in .= $in ? ", '%s'" : "'%s'";
+      }
+      $count = db_result(db_query("SELECT COUNT(*)
+                                   FROM {node}
+                                   WHERE uid = %d
+                                   AND type IN ($in)", $query_args));
       if (module_exists('comment')) {
-        $count += db_result(db_query("SELECT COUNT(*) FROM {comments} WHERE uid = %d", $uid));
+        $count += db_result(db_query("SELECT COUNT(*)
+                                      FROM {comments}
+                                      WHERE uid = %d", $uid));
       }
     }
     else {
       $count = 0;
     }
   }
-  // mysql only query
+  // MySQL only query
   db_query("REPLACE INTO {user_titles_posts} (uid, posts) VALUES (%d, %d)", $uid, $count);
   return $count;
 }
 
 /**
  * Get allowed types from db.
+ *
+ * @return
+ *   An array of node types that count towards the post count.
  */
 function user_titles_get_allowed_types() {
   return variable_get('user_titles_types', array());
@@ -696,6 +537,9 @@ function user_titles_get_allowed_types()
 
 /**
  * Set allowed types from db
+ * 
+ * @param $types
+ *   An array of node types that count towards the post count.
  */
 function user_titles_set_allowed_types($types) {
   variable_set('user_titles_types', $types);
@@ -703,16 +547,23 @@ function user_titles_set_allowed_types($
 
 /**
  * Get titles from db
- * If tid is passed in only that title will be fetched, otherwise all titles will be fetched
+ * If tid is passed in only that title will be fetched, otherwise all titles will be fetched.
+ *
+ * @param $tid
+ *   The title id to retrieve.  If NULL then fetch all titles.
+ *
+ * @return
+ *   If $tid param is not NULL a title object is returned.
+ *   Otherwise an array of title objects is returned.
  */
 function user_titles_get_titles($tid = NULL) {
   if ($tid && is_numeric($tid)) {
-    $result = db_fetch_array(db_query("SELECT * FROM {user_titles} WHERE tid = %d", $tid));
+    $result = db_fetch_object(db_query("SELECT * FROM {user_titles} WHERE tid = %d", $tid));
   }
   else {
     $result = array();
     $query = db_query("SELECT * FROM {user_titles} ORDER BY value DESC");
-    while ($row = db_fetch_array($query)) {
+    while ($row = db_fetch_object($query)) {
       $result[] = $row;
     }
   }
@@ -721,77 +572,88 @@ function user_titles_get_titles($tid = N
 }
 
 /**
- * Implementation of hook_user()
+ * Get titles from db based on rid
+ * If rid is passed in only that roles titles will be fetched,
+ * otherwise all titles will be fetched and ordered by role then value
  *
- * Add the 'edit user title' form to the edit user page.
+ * @param $rid
+ *   The role id to get the titles for.  If NULL return all titles.
+ *
+ * @return
+ *   An array of title objects.
  */
-function user_titles_user($op, $edit, &$user, $category = NULL) {
-  switch ($op) {
-    case 'form':
-      if (user_access('administer user titles') && $category == 'account' && (isset($user->uid))) {
-        // when user tries to edit his own data
-        $form['user_titles'] = array(
-          '#type' => 'fieldset',
-          '#title' => t('User Title'),
-          '#collapsible' => TRUE,
-          '#weight' => 4);
-        $title_info = user_titles_get_user_title_info($user);
-
-        if (!isset($title_info['title'])) {
-          $title = t('No title set');
-        }
-        else {
-          $title = $title_info['title'];
-        }
-
-        $form['user_titles']['current_title'] = array(
-          '#value' => '<div><strong>'. t('Current user title:') .' </strong> '. filter_xss_admin($title) .'</div>',
-        );
+function user_titles_get_titles_by_role($rid = NULL) {
+  $result = array();
+  if ($rid) {
+    $query = db_query("SELECT * FROM {user_titles} WHERE rid = %d ORDER BY value DESC", $rid);
+  }
+  else {
+    $query = db_query("SELECT * FROM {user_titles} ORDER BY rid, value DESC");
+  }
+  while ($row = db_fetch_object($query)) {
+    $result[] = $row;
+  }
+  return $result;
+}
 
-        if (isset($title_info['title']) && empty($title_info['tid'])) {
-          $default_title_info = user_titles_get_title(user_titles_get_posts($uid));
-          if (!isset($default_title_info['title'])) {
-            $default_title = t('No title set');
-          }
-          else {
-            $default_title = $default_title_info['title'];
-          }
-          $form['user_titles']['default_title'] = array(
-            '#value' => '<div><strong>'. t('Default user title:') .' </strong> '. filter_xss_admin($default_title) .'</div>',
-          );
-        }
+/**
+ * Get an array of the roles available for user_titles ordered by weight.
+ *
+ * @return
+ *   An array of roles with role id as the key and role name as the value.
+ */
+function user_titles_get_roles() {
+  $roles = array();
+  $result = db_query("SELECT r.rid, r.name
+                      FROM {role} r, {user_titles_roles} ur
+                      WHERE r.rid = ur.rid
+                      ORDER BY ur.weight");
+  while ($row = db_fetch_array($result)) {
+    $roles[$row['rid']] = $row['name'];
+  }
+  return $roles;
+}
 
-        $form['user_titles']['user_title'] = array(
-          '#type' => 'textfield',
-          '#title' => t('Override title'),
-          '#description' => t('Enter a title here to give this user a manually overridden title. Leave blank to use the default title.'),
-          '#default_value' => isset($user->user_title) ? $user->user_title : '',
-        );
+/**
+ * Get the default role in case a role is not specified somewhere.
+ * The default role is the role with the least weight.
+ *
+ * @return
+ *   An integer containing a role id.
+ */
+function user_titles_get_default_role() {
+  $rid = db_result(db_query_range("SELECT rid FROM {user_titles_roles} ORDER BY weight", 0, 1));
+  return $rid;
+}
 
-        return $form;
-      }
-      break;
-    case 'delete':
-      db_query('DELETE FROM {user_titles_posts} WHERE uid = %d', $user->uid);
-      break;
-    case 'view':
-      $title = user_titles_get_user_title($user);
-      if ($title) {
-        $user->content['user_titles'] = array(
-          '#type' => 'user_profile_category',
-          '#title' => t('User title'),
-        );
-        $user->content['user_titles']['title'] = array(
-          '#type' => 'user_profile_item',
-          '#value' => filter_xss_admin($title),
-        );
-      }
-      break;
-  }
+/**
+ * Get the role that is to be used for a users titles.
+ *
+ * @return
+ *   An integer containing a role id.
+ */
+function user_titles_get_users_title_role($uid) {
+  $rid = db_result(db_query_range("SELECT rid
+                                   FROM {user_titles_roles}
+                                   WHERE rid IN (2, (SELECT rid
+                                                     FROM {users_roles}
+                                                     WHERE uid = %d))
+                                   ORDER BY weight", $uid, 0, 1));
+  return $rid;
 }
 
 /**
  * Theme function for user titles images.
+ * 
+ * @param $filepath
+ *   A string containing the filepath of the image
+ * @param $alt
+ *   A string containing the alt text for the image.  Also used for the image title.
+ *
+ * @return
+ *   A string containing the html output for the user titles image.
+ *
+ * @ingroup themeable
  */
 function theme_user_titles_image($filepath, $alt) {
   $image = theme('image', $filepath, $alt, $alt, '', FALSE);
@@ -804,6 +666,22 @@ function theme_user_titles_image($filepa
 }
 
 /**
+ * Implementation of template_preprocess_node().
+ */
+function user_titles_preprocess_node(&$variables) {
+  $variables['user_title'] = user_titles_get_user_title($variables['node']->uid);
+  $variables['user_title_image'] = user_titles_get_user_image($variables['node']->uid);
+}
+
+/**
+ * Implementation of template_preprocess_comment().
+ */
+function user_titles_preprocess_comment(&$variables) {
+  $variables['user_title'] = user_titles_get_user_title($variables['comment']->uid);
+  $variables['user_title_image'] = user_titles_get_user_image($variables['comment']->uid);
+}
+
+/**
  * Built-in hook implementation that counts nodes
  */
 function user_titles_user_titles($op, $uid = NULL) {
@@ -821,94 +699,10 @@ function user_titles_user_titles($op, $u
       return;
     case 'get':
       $res = db_result(db_query("SELECT posts FROM {user_titles_posts} WHERE uid = %d", $uid));
-      if ($res === FALSE) $res = user_titles_update_post_count($uid);
-      return $res;
-  }
-}
-
-/**
- * Sample hook implementation for userpoints; should be placed in userpoints
- */
-if (module_exists('userpoints') && !function_exists('userpoints_user_titles')) {
-  function userpoints_user_titles($op, $uid = NULL) {
-    switch ($op) {
-      case 'register':
-        return 'userpoints';
-      case 'name':
-        return t('User points');
-      case 'description':
-        return t('Different points values are assigned to user actions');
-      case 'units':
-        return t('Points');
-      case 'url':
-        return 'admin/help/userpoints';
-      case 'get':
-        return userpoints_get_current_points($uid);
-    }
-  }
-}
-
-/**
- * Implementation of hook_block().
- */
-function user_titles_block($op = 'list', $delta = 0, $edit = array()) {
-  switch ($op) {
-    case 'list':
-      $blocks[0] = array(
-        'info' => t('User Titles: Users with my title'),
-        'cache' => BLOCK_CACHE_PER_USER,
-      );
-      return $blocks;
-    case 'view':
-      // If $op is "view", then we need to generate the block for display
-      // purposes. The $delta parameter tells us which block is being requested.
-      switch ($delta) {
-        case 0:
-          $block['subject'] = t('Users with your title');
-          $block['content'] = user_titles_matching_users_block();
-          break;
+      if ($res === FALSE) {
+        $res = user_titles_update_post_count($uid);
       }
-      return $block;
-  }
-
-}
-
-/**
- * Creates the content for a block that lists users with your title
- * Displays 10 random users with the same title as you
- */
-function user_titles_matching_users_block() {
-  global $user;
-  $users = user_titles_get_matching_users($user->uid);
-  if (!empty($users)) {
-    shuffle($users);
-    $count = min(10, count($users));
-    $output = '<ul>';
-    for ($i = 0; $i < $count; $i++) {
-      $temp_user = user_load(array('uid' => $users[$i]));
-      $output .= '<li>' . l(t($temp_user->name), 'user/' . $temp_user->uid) . '</li>';
-    }
-    $output .= '</ul>';
-  }
-  else {
-    $output .= '<span class="no-matches">' . t('There are no other uses with your title.') . '</span>';
+      return $res;
   }
-
-  return $output;
-}
-
-/**
- * Implementation of template_preprocess_node().
- */
-function user_titles_preprocess_node(&$variables) {
-  $variables['user_title'] = user_titles_get_user_title($variables['node']->uid);
-  $variables['user_title_image'] = user_titles_get_user_image($variables['node']->uid);
 }
 
-/**
- * Implementation of template_preprocess_comment().
- */
-function user_titles_preprocess_comment(&$variables) {
-  $variables['user_title'] = user_titles_get_user_title($variables['comment']->uid);
-  $variables['user_title_image'] = user_titles_get_user_image($variables['comment']->uid);
-}
