diff -ruN user_titles/API.txt user_titles.diff/API.txt
--- user_titles/API.txt	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/API.txt	2010-02-02 15:20:16.000000000 -0500
@@ -1,3 +1,4 @@
+// $Id: API.txt,v 1.1.4.3 2010/02/02 11:20:15 agileware Exp $
 
 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.
diff -ruN user_titles/README.txt user_titles.diff/README.txt
--- user_titles/README.txt	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/README.txt	2010-02-02 15:20:16.000000000 -0500
@@ -1,3 +1,4 @@
+// $Id: README.txt,v 1.5.2.2 2010/02/02 11:20:15 agileware Exp $
 
 ---------------------DESCRIPTION-------------------------------------------
 
@@ -13,13 +14,8 @@
 
 1. Copy the user_titles directory to sites/all/modules
 2. On the modules page (admin/build/modules) enable the user titles module
-3. You will also need to enable one of the sub-modules that handle the point
-schemes used to determin user titles.  The default one that this module
-provides is user titles basic. If you want to integrate with another module
-such as userpoints you have to enable it's sub-module, in that case the user
-titles userpoints module.
-4. If you want to use user titles data in views you must enable the user
-titles views module.
+3. If you want to integrate with userpoints you now have to enable the user
+titles userpoints module also
 
 ----------------------UPGRADING--------------------------------------------
 
@@ -32,20 +28,15 @@
 NOTE: If you were previously using userpoints to calculate your titles
 you must now enable the user titles userpoints sub module.
 
-If you are updating from 6.x-1.x-beta5 or before the user titles basic
-sub-module will be automatically enabled due to it's functionality
-previously being in the main 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:---
-* Here you can select which module's point scheme will be used to calculate
-user titles. If you choose the basic user titles module you can administer
-its point scheme at admin/user/user-titles/ut-basic
-* If you choose the basic user titles module you can administer
-its point scheme at admin/user/user-titles/ut-basic
+* 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:---
@@ -75,14 +66,6 @@
 And you can use the "Titles" tab (admin/user/user-titles/titles) to view
 your titles.
 
----Display---
-Here you can set whether or not the user title is displayed on users'
-profile page.
-
----Recalculate---
-By clicking this button all users titles in the database will be deleted
-and recalculated.  Try this if you notice user titles that are incorrect.
-
 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.
diff -ruN user_titles/contrib/ut_basic/ut_basic.admin.inc user_titles.diff/contrib/ut_basic/ut_basic.admin.inc
--- user_titles/contrib/ut_basic/ut_basic.admin.inc	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/contrib/ut_basic/ut_basic.admin.inc	1969-12-31 19:00:00.000000000 -0500
@@ -1,87 +0,0 @@
-<?php
-
-/**
- * @file
- * Admin page callback file for the user_titles module.
- */
-
-/**
- * Form to set which node types are counted to work out user titles.
- *
- * @return
- *   A form array.
- */
-function ut_basic_settings_form() {
-  $form = array();
-
-  $types = array();
-  foreach (node_get_types() as $type => $info) {
-    $types[$type] = $info->name;
-  }
-
-  $form['nodes'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Nodes'),
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-  );
-  $form['nodes']['ut_basic_node_types'] = array(
-    '#type' => 'checkboxes',
-    '#title' => t('Counted node types'),
-    '#description' => t('Only the checked node types will be counted'),
-    '#options' => $types,
-    '#default_value' => variable_get('ut_basic_node_types', array()),
-  );
-
-  $form['comments'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Comments'),
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-  );
-  $form['comments']['ut_basic_comment_types'] = array(
-    '#type' => 'checkboxes',
-    '#title' => t('Counted node type comments'),
-    '#description' => t('Only comments on the checked node types will be counted'),
-    '#options' => $types,
-    '#default_value' => variable_get('ut_basic_comment_types', array()),
-  );
-
-  $form['recalculate'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Recalculate'),
-    '#description' => t('This will clear all user post counts and recalculate them based on the types selected above. Titles will be automatically recalculated when the above type options are changed.'),
-  );
-  $form['recalculate']['recalculate_posts'] = array(
-    '#type' => 'submit',
-    '#value' => t('Recalculate all user post counts'),
-  );
-
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Submit'),
-  );
-
-  return $form;
-}
-
-/**
- * Submit handler for ut_basic_settings_form.
- */
-function ut_basic_settings_form_submit($form, &$form_state) {
-  if ($form_state['values']['op'] == t('Recalculate all user post counts')) {
-    ut_basic_update_all_post_counts();
-    $form_state['redirect'] = FALSE;
-    return;
-  }
-
-  $old_comment = variable_get('ut_basic_comment_types', array());
-  $old_node = variable_get('ut_basic_node_types', array());
-  variable_set('ut_basic_comment_types', $form_state['values']['ut_basic_comment_types']);
-  variable_set('ut_basic_node_types', $form_state['values']['ut_basic_node_types']);
-
-  if (!array_diff($old_comment, $form_state['values']['ut_basic_comment_types']) ||
-      !array_diff($old_node, $form_state['values']['ut_basic_node_types'])) {
-    ut_basic_update_all_post_counts();
-  }
-}
\ No newline at end of file
diff -ruN user_titles/contrib/ut_basic/ut_basic.info user_titles.diff/contrib/ut_basic/ut_basic.info
--- user_titles/contrib/ut_basic/ut_basic.info	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/contrib/ut_basic/ut_basic.info	1969-12-31 19:00:00.000000000 -0500
@@ -1,5 +0,0 @@
-name = User titles basic
-description = Allows user titles to be based on a basic node and comment post count
-dependencies[] = user_titles
-core = 6.x
-package = User titles
diff -ruN user_titles/contrib/ut_basic/ut_basic.install user_titles.diff/contrib/ut_basic/ut_basic.install
--- user_titles/contrib/ut_basic/ut_basic.install	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/contrib/ut_basic/ut_basic.install	1969-12-31 19:00:00.000000000 -0500
@@ -1,49 +0,0 @@
-<?php
-
-/**
- * @file ut_basic.install
- * Installation file for ut_basic module
- */
-
-/**
- * Implementation of hook_schema().
- */
-function ut_basic_schema() {
-  $schema['user_titles_posts'] = array(
-    'fields' => array(
-      'uid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'disp-width' => '10',
-      ),
-      'posts' => array(
-        'type' => 'int',
-        'not null' => FALSE,
-        'disp-width' => '11',
-      ),
-    ),
-    'primary key' => array('uid'),
-  );
-
-  return $schema;
-}
-
-/**
- * Implementation of hook_install().
- */
-function ut_basic_install() {
-  // This table used to be part of the user_titles module so check if it is already there.
-  if (!db_table_exists('user_titles_posts')) {
-    drupal_install_schema('ut_basic');
-  }
-}
-
-/**
- * Implementation of hook_uninstall().
- */
-function ut_basic_uninstall() {
-  drupal_uninstall_schema('ut_basic');
-
-  variable_del('ut_basic_node_types');
-  variable_del('ut_basic_comment_types');
-}
diff -ruN user_titles/contrib/ut_basic/ut_basic.module user_titles.diff/contrib/ut_basic/ut_basic.module
--- user_titles/contrib/ut_basic/ut_basic.module	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/contrib/ut_basic/ut_basic.module	1969-12-31 19:00:00.000000000 -0500
@@ -1,178 +0,0 @@
-<?php
-
-/**
- * @file
- * Allows user titles to be based on a users userpoints.
- */
-
-/**
- * Implementation of hook_menu().
- */
-function ut_basic_menu() {
-  $items['admin/user/user-titles/ut-basic'] = array(
-    'title' => t('UT basic'),
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('ut_basic_settings_form'),
-    'access arguments' => array('administer user titles'),
-    'type' => MENU_LOCAL_TASK,
-    'file' => 'ut_basic.admin.inc',
-  );
-
-  return $items;
-}
-
-/**
- * Implementation of hook_nodeapi().
- */
-function ut_basic_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
-  if (variable_get('user_titles_hook_module', 'ut_basic') == 'ut_basic') {
-    if ($op == 'insert' || $op == 'delete') {
-      // Update the users post count
-      $allowed_types = variable_get('ut_basic_node_types', array());
-      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);
-        }
-      }
-
-      // Update the users title
-      user_titles_set_user_title($a1->uid);
-    }
-  }
-}
-
-/**
- * Implementation of hook_comment().
- */
-function ut_basic_comment($a1, $op) {
-  // Only run this if this module is controlling user titles
-  if (variable_get('user_titles_hook_module', 'ut_basic') == 'ut_basic') {
-    if ($op == 'insert' || $op == 'delete') {
-      // Update the users post count
-      $a1 = (object) $a1; // sometimes an array is passed in
-      $node = node_load($a1->nid);
-      $types = variable_get('ut_basic_comment_types', array());
-      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);
-        }
-      }
-
-      // Update the users title
-      user_titles_set_user_title($a1->uid);
-    }
-  }
-}
-
-/**
- * Implementation of hook_user().
- *
- * Add the 'edit user title' form to the edit user page.
- */
-function ut_basic_user($op, $edit, &$user, $category = NULL) {
-  switch ($op) {
-    case 'delete':
-      db_query('DELETE FROM {user_titles_posts} WHERE uid = %d', $user->uid);
-      break;
-  }
-}
-
-/**
- * Update the post count for a given user.
- *
- * @param $uid
- *   The user id to update.
- * @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 ut_basic_update_post_count($uid, $count = NULL) {
-  if (is_null($count)) {
-    $count = 0;
-    // Fetch count from the database
-    $allowed_node_types = variable_get('ut_basic_node_types', array());
-    $allowed_comment_types = variable_get('ut_basic_comment_types', array());
-    if ($allowed_types) {
-      $in = '';
-      $query_args = array($uid);
-      foreach ($allowed_node_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')) {
-        $in = '';
-        $query_args = array($uid);
-        foreach ($allowed_node_types as $type) {
-          $query_args[] = $type;
-          $in .= $in ? ", '%s'" : "'%s'";
-        }
-        $count += db_result(db_query("SELECT COUNT(*)
-                                      FROM {comments}
-                                      WHERE uid = %d
-                                      AND nid IN (SELECT nid
-                                                  FROM {node}
-                                                  WHERE type IN ($in)", $query_args));
-      }
-    }
-  }
-
-  db_query("UPDATE {user_titles_posts} SET posts = %d WHERE uid = %d", $count, $uid);
-  if (!db_affected_rows()) {
-    db_query("INSERT INTO {user_titles_posts} (uid, posts) VALUES (%d, %d)", $uid, $count);
-  }
-  return $count;
-}
-
-/**
- * Reset post count for all users.
- */
-function ut_basic_update_all_post_counts() {
-  // Just in case. This could take a little while...
-  set_time_limit(600);
-
-  db_query('TRUNCATE TABLE {user_titles_posts}');
-  $result = db_query('SELECT uid FROM {users}');
-  $uids = array();
-  while ($row = db_fetch_array($result)) {
-    $uids[] = $row['uid'];
-  }
-  foreach ($uids as $uid) {
-    ut_basic_update_post_count($uid);
-  }
-}
-
-/**
- * Built-in hook implementation that counts nodes
- */
-function ut_basic_user_titles($op, $uid = NULL) {
-  switch ($op) {
-    case 'register':
-      return 'ut_basic';
-    case 'name':
-      return t('Basic post count');
-    case 'description':
-      return t('Built-in, see below');
-    case 'units':
-      return t('Posts');
-    case 'url':
-      return 'admin/user/user-titles/ut-basic';
-    case 'get':
-      $res = db_result(db_query("SELECT posts FROM {user_titles_posts} WHERE uid = %d", $uid));
-      if ($res === FALSE) {
-        $res = ut_basic_update_post_count($uid);
-      }
-      return $res;
-  }
-}
diff -ruN user_titles/contrib/ut_user_karma/ut_user_karma.info user_titles.diff/contrib/ut_user_karma/ut_user_karma.info
--- user_titles/contrib/ut_user_karma/ut_user_karma.info	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/contrib/ut_user_karma/ut_user_karma.info	1969-12-31 19:00:00.000000000 -0500
@@ -1,7 +0,0 @@
-name = User titles user karma
-description = Allows user titles to be based on a users user karma
-dependencies[] = user_titles
-dependencies[] = user_karma
-core = 6.x
-package = User titles
-
diff -ruN user_titles/contrib/ut_user_karma/ut_user_karma.module user_titles.diff/contrib/ut_user_karma/ut_user_karma.module
--- user_titles/contrib/ut_user_karma/ut_user_karma.module	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/contrib/ut_user_karma/ut_user_karma.module	1969-12-31 19:00:00.000000000 -0500
@@ -1,51 +0,0 @@
-<?php
-
-/**
- * @file
- * Allows user titles to be based on a users karma.
- */
-
-/**
- * Implementation of hook_user_karma_vote_cast().
- *
- * We use this to make sure the user titles are up to date.
- */
-function ut_user_karma_user_karma_vote_cast($op, $v, $value) {
-  // Only run this if this module is controlling user titles
-  if (variable_get('user_titles_hook_module', 'ut_basic') == 'ut_user_karma') {
-    switch ($op) {
-      case 'insert':
-      case 'delete':
-        if ($v[0]['content_type'] == 'node') {
-          $node = node_load($v[0]['content_id']);
-          user_titles_set_user_title($node->uid);
-        }
-        if ($v[0]['content_type'] == 'comment') {
-          $comment = _comment_load($v[0]['content_id']);
-          user_titles_set_user_title($comment->uid);
-        }
-        break;
-    }
-  }
-}
-
-/**
- * Implementation of hook_user_titles().
- */
-function ut_user_karma_user_titles($op, $uid = NULL) {
-  switch ($op) {
-    case 'register':
-      return 'ut_user_karma';
-    case 'name':
-      return t('User karma');
-    case 'description':
-      return t('Different karma values are assigned to user actions and votes of user content');
-    case 'units':
-      return t('Karma');
-    case 'url':
-      return 'admin/settings/user_karma';
-    case 'get':
-      return user_karma_user_karma($uid);
-  }
-}
-
diff -ruN user_titles/contrib/ut_user_stats/ut_user_stats.info user_titles.diff/contrib/ut_user_stats/ut_user_stats.info
--- user_titles/contrib/ut_user_stats/ut_user_stats.info	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/contrib/ut_user_stats/ut_user_stats.info	1969-12-31 19:00:00.000000000 -0500
@@ -1,7 +0,0 @@
-name = User titles user stats
-description = Allows user titles to be based on a users user stats
-dependencies[] = user_titles
-dependencies[] = user_stats
-core = 6.x
-package = User titles
-
diff -ruN user_titles/contrib/ut_user_stats/ut_user_stats.module user_titles.diff/contrib/ut_user_stats/ut_user_stats.module
--- user_titles/contrib/ut_user_stats/ut_user_stats.module	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/contrib/ut_user_stats/ut_user_stats.module	1969-12-31 19:00:00.000000000 -0500
@@ -1,43 +0,0 @@
-<?php
-
-/**
- * @file
- * Allows user titles to be based on a users user stats.
- */
-
-/**
- * Implementation of hook_user_stats().
- *
- * We use this to make sure the user titles are up to date.
- */
-function ut_user_stats_user_stats($type, $op, $uid, $value) {
-  // Only run this if this module is controlling user titles
-  if (variable_get('user_titles_hook_module', 'ut_basic') == 'ut_user_stats') {
-    switch ($op) {
-      case 'post_count':
-        user_titles_set_user_title($uid);
-        break;
-    }
-  }
-}
-
-/**
- * Implementation of hook_user_titles().
- */
-function ut_user_stats_user_titles($op, $uid = NULL) {
-  switch ($op) {
-    case 'register':
-      return 'ut_user_stats';
-    case 'name':
-      return t('User Stats');
-    case 'description':
-      return t('Count of post and/or comments');
-    case 'units':
-      return t('Posts');
-    case 'url':
-      return 'admin/settings/user_stats';
-    case 'get':
-      return user_stats_get_stats('post_count', $uid);
-  }
-}
-
diff -ruN user_titles/contrib/ut_userpoints/ut_userpoints.info user_titles.diff/contrib/ut_userpoints/ut_userpoints.info
--- user_titles/contrib/ut_userpoints/ut_userpoints.info	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/contrib/ut_userpoints/ut_userpoints.info	2011-10-14 16:22:00.000000000 -0500
@@ -1,7 +1,9 @@
+; 
 name = User titles userpoints
-description = Allows user titles to be based on a users userpoints
+description = Allows user titles to be based on a users userpoints. 7.x temporary port by boran on d.o
 dependencies[] = user_titles
 dependencies[] = userpoints
-core = 6.x
+core = 7.x
 package = User titles
 
+
diff -ruN user_titles/contrib/ut_userpoints/ut_userpoints.module user_titles.diff/contrib/ut_userpoints/ut_userpoints.module
--- user_titles/contrib/ut_userpoints/ut_userpoints.module	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/contrib/ut_userpoints/ut_userpoints.module	2011-10-14 16:10:22.000000000 -0500
@@ -1,4 +1,5 @@
 <?php
+// 
 
 /**
  * @file
@@ -15,7 +16,13 @@
   if (variable_get('user_titles_hook_module', 'ut_basic') == 'ut_userpoints') {
     switch ($op) {
       case 'points after':
-        user_titles_set_user_title($params->uid);
+        if ($params['uid'] >0) {
+          //watchdog('ut_userpoints', 'points after: call user_titles_set_user_title for uid ' . $params['uid']);
+          user_titles_set_user_title($params['uid']);   // http://drupal.org/node/1293230
+        }
+        else {
+          //watchdog('ut_userpoints', 'points after: params[uid] invalid');
+        }
         break;
     }
   }
@@ -35,8 +42,8 @@
     case 'units':
       return t('Points');
     case 'url':
-      return 'admin/settings/userpoints';
+      return 'admin/user/user-titles/userpoints';
     case 'get':
-      return userpoints_get_current_points($uid);
+      return userpoints_get_current_points($uid, 'all'); // http://drupal.org/node/881184
   }
 }
diff -ruN user_titles/user_titles.admin.inc user_titles.diff/user_titles.admin.inc
--- user_titles/user_titles.admin.inc	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/user_titles.admin.inc	2011-10-17 17:34:44.000000000 -0500
@@ -1,4 +1,5 @@
 <?php
+// $Id: user_titles.admin.inc,v 1.1.2.1 2010/02/02 11:20:15 agileware Exp $
 
 /**
  * @file
@@ -14,27 +15,30 @@
 function user_titles_settings_form() {
   $form = array();
 
-  $hook_module = variable_get('user_titles_hook_module', 'ut_basic');
-  $hook_modules = module_invoke_all('user_titles', 'register');
+  $types = user_titles_get_allowed_types();
 
-  if (empty($hook_modules)) {
-    drupal_set_message(t('There are no point scheme modules currently enabled.  Without one this module will do nothing.  You can enable one on the <a href="@modules-page">modules page</a>.', array('@modules-page' => url('admin/build/modules'))));
+  foreach (node_type_get_types() as $type => $info) {
+    $nodes[$type] = $info->name;
   }
 
-  $form['points'] = array(
+  $hook_module = user_titles_get_hook_module();
+  $hook_modules = module_invoke_all('user_titles', 'register');
+
+
+  $form['settings'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Point calculation'),
+    '#title' => 'Settings',
   );
-  $form['points']['hook_module'] = array(
+  $form['settings']['hook_module'] = array(
     '#type' => 'radios',
-    '#title' => t('Point scheme'),
+    '#title' => 'Point scheme',
     '#default_value' => $hook_module,
     '#options' => array(),
-    '#attributes' => array('class' => 'user-titles-hook-module'),
+    '#attributes' => array('class' => array('user-titles-hook-module')),
   );
   foreach ($hook_modules as $module) {
     $name = module_invoke($module, 'user_titles', 'name');
-    $form['points']['hook_module']['#options'][$module] = array(
+    $form['settings']['hook_module']['#options'][$module] = array(
       'name' => $name,
       'description' => module_invoke($module, 'user_titles', 'description'),
       'url' => module_invoke($module, 'user_titles', 'url'),
@@ -42,38 +46,50 @@
     $name_index[$module] = $name;
   }
 
-  array_multisort($name_index, SORT_ASC, SORT_STRING, $form['points']['hook_module']['#options']);
+  array_multisort($name_index, SORT_ASC, SORT_STRING, $form['settings']['hook_module']['#options']);
 
-  $form['images'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Images'),
+  // 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' => array('user-titles-types')),
+  );
+  $form['settings']['types_disabled'] = array(
+    '#type' => 'hidden',
+    '#default_value' => $hook_module !== 'user_titles',
   );
   // Directory to save images
-  $form['images']['image_dir'] = array(
+  $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() .'/')),
+    '#description' => t('Subdirectory in the directory %dir where images will be stored.', array('%dir' => variable_get('file_public_path', conf_path() . '/files') .'/')),
     '#default_value' => variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR),
     '#size' => 35,
-    '#attributes' => array('class' => 'user-titles-image-dir'),
+    '#attributes' => array('class' => array('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.'),
+    '#markup' => 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)) {
+  $query = db_select('role', 'r');
+  $query->join('user_titles_roles', 'ro', 'r.rid = ro.rid');
+  $query->addField('r', 'name');
+  $query->fields('ro'); //all fields from user_titles_roles
+  $query->condition('r.rid', 1, '!=');
+  $query->orderBy('ro.weight');
+  $result = $query->execute();
+  while ($role = $result->fetchAssoc()) {
     $form['roles'][$role['rid']]['name'] = array(
-      '#value' => check_plain($role['name']),
+      '#markup' => check_plain($role['name']),
     );
     $form['roles'][$role['rid']]['weight'] = array(
       '#type' => 'weight',
@@ -93,16 +109,6 @@
     '#description' => t("If checked, the user's title will be displayed on their profile page."),
   );
 
-  $form['recalculate'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Recalculate'),
-    '#description' => t('This will clear all users titles and recalculate them based on the points scheme selected above. Titles will be automatically recalculated when the points scheme is changed.'),
-  );
-  $form['recalculate']['recalculate_titles'] = array(
-    '#type' => 'submit',
-    '#value' => t('Recalculate all users titles'),
-  );
-
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
@@ -115,34 +121,44 @@
  * Submit function for the user titles setting form.
  */
 function user_titles_settings_form_submit($form, &$form_state) {
-  if ($form_state['values']['op'] == t('Recalculate all users titles')) {
-    user_titles_reset_titles();
-    $form_state['redirect'] = FALSE;
-    return;
+  // 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_truncate('user_titles_posts')->execute();
   }
 
-  $old_hook_module = variable_get('user_titles_hook_module', '');
-  variable_set('user_titles_hook_module', $form_state['values']['hook_module']);
+  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']);
   variable_set('user_titles_display_on_profile', $form_state['values']['display_on_profile']);
 
-  $image_path = file_create_path(variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR));
-  file_check_directory($image_path, 1, 'image_dir');
+  $created = file_prepare_directory(variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR), FILE_CREATE_DIRECTORY);
+  if (!$created) {
+  	form_set_error('image_dir', t('Error creating directory'));
+  }
 
   // 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']);
+  	$updated = db_update('user_titles_roles')
+      ->fields(array(
+        'weight' => $role['weight'],
+      )
+    )
+    ->condition('rid', $rid)
+    ->execute();
+    if (!$updated) {
+      db_insert('user_titles_roles')
+        ->fields(array(
+          'rid' => $rid,
+          'weight' => $role['weight'],
+        )
+      )
+      ->execute();
     }
   }
-
-  // If the hook module changes reset titles
-
-  if ($old_hook_module != $form_state['values']['hook_module']) {
-    user_titles_reset_titles();
-  }
-
   drupal_set_message(t('The configuration has been updated.'));
 }
 
@@ -156,41 +172,45 @@
   $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)) {
+  
+  $query = db_select('role', 'r');
+  $query->addField('r', 'name');
+  $query->join('user_titles_roles', 'ro', 'r.rid = ro.rid');
+  $query->fields('ro');
+  $query->condition('r.rid', 1, '!=');
+  $query->orderBy('ro.weight');
+  $rows = $query->execute();
+  while ($role = $rows->fetchAssoc()) {
     $titles = user_titles_get_titles_by_role($role['rid']);
     
     $form['roles'][$role['rid']]['name'] = array(
       '#type' => 'markup',
-      '#value' => t($role['name']),
+      '#markup' => 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']))),
+      '#markup' => l(t('Add another title'), 'admin/config/people/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,
+          '#markup' => isset($title['value']) ? $title['value'] : '',
         );
         $form['roles'][$role['rid']]['titles'][$i]['title'] = array(
           '#type' => 'markup',
-          '#value' => $title->title,
+          '#markup' => isset($title['title']) ? $title['title'] : '',
         );
+        $image = isset($title['image']) ? $title['image'] : '';
+        $alt = isset($title['image_title']) ? $title['image_title'] : '';
         $form['roles'][$role['rid']]['titles'][$i]['image'] = array(
           '#type' => 'markup',
-          '#value' => theme('user_titles_image', $title->image, $title->image_title),
+          '#markup' => theme('user_titles_image', array('filepath' => $image, 'alt' => $alt)),
         );
         $form['roles'][$role['rid']]['titles'][$i]['tid'] = array(
           '#type' => 'hidden',
-          '#value' => $title->tid,
+          '#markup' => isset($title['tid']) ? $title['tid'] : '',
         );
       }
     }
@@ -208,7 +228,7 @@
  * @return
  *   A form array.
  */
-function user_titles_add_title_form(&$form_state, $title = NULL) {
+function user_titles_add_title_form($form, &$form_state, $title = NULL) {
   $path = drupal_get_path('module', 'user_titles');
   drupal_add_css("$path/admin.css");
 
@@ -216,8 +236,8 @@
   $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;
+  $rid = is_numeric(isset($_GET['rid'])) ? $_GET['rid'] : 0;
+  $default_role = (isset($title->rid)) ? $title->rid : $rid;
   $form['role'] = array(
     '#type' => 'select',
     '#title' => t('Role'),
@@ -226,14 +246,14 @@
     '#options' => $roles,
   );
 
-  $units = module_invoke(variable_get('user_titles_hook_module', 'ut_basic'), 'user_titles', 'units');
+  $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,
+    '#default_value' => (isset($title->value)) ? $title->value : '',
   );
 
   $form['title'] = array(
@@ -242,7 +262,7 @@
     '#size' => 40,
     '#maxlength' => 128,
     '#required' => TRUE,
-    '#default_value' => $title->title,
+    '#default_value' => (isset($title->title)) ? $title->title : '',
   );
 
   $form['image'] = array(
@@ -250,12 +270,16 @@
     '#title' => t('Image'),
   );
 
+  $img_vars = array(
+    'filepath' => (isset($title->image)) ? $title->image : '',
+    'alt' => (isset($title->image_title)) ? $title->image_title : '',
+  );
   $form['image']['image_display'] = array(
     '#type' => 'item',
-    '#value' => theme('user_titles_image', $title->image, $title->image_title),
+    '#markup' => theme('user_titles_image', $img_vars),
   );
 
-  if ($title->image) {
+  if (isset($title->image)) {
     $form['image']['remove_image'] = array(
       '#type' => 'checkbox',
       '#title' => t('Remove image'),
@@ -268,7 +292,7 @@
     '#title' => t('Image title/alt text'),
     '#size' => 40,
     '#maxlength' => 255,
-    '#default_value' => $title->image_title,
+    '#default_value' => isset($title->image_title) ? $title->image_title : '',
     '#description' => t('This text will be used as the title and alt text for the image when it is displayed.'),
   );
 
@@ -284,15 +308,17 @@
     '#value' => t('Save'),
   );
 
-  if ($title->tid) {
-    $form['delete'] = array(
-      '#type' => 'submit',
-      '#value' => t('Delete'),
-    );
-    $form['tid'] = array(
-      '#type' => 'value',
-      '#value' => $title->tid,
-    );
+  if (isset($title->tid)) {
+  	if ($title->tid) {
+      $form['delete'] = array(
+        '#type' => 'submit',
+        '#value' => t('Delete'),
+      );
+      $form['tid'] = array(
+        '#type' => 'value',
+        '#value' => $title->tid,
+      );
+  	}
   }
 
   return $form;
@@ -305,7 +331,7 @@
   $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!'));
+    form_set_error('value', t('Number of posts must be a number!'));
   }
 
   foreach ($existing_titles as $title) {
@@ -328,43 +354,89 @@
   $image = '';
 
   // Get directory
-  $dir = file_create_path(variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR));
-  file_check_directory($dir, 1, 'image_upload');
-
+  $dir = variable_get('user_titles_image_dir', DEFAULT_IMAGE_DIR);
+  $created = file_prepare_directory($dir, FILE_CREATE_DIRECTORY);
+  if (!$created) {
+  	form_set_error('image_upload', t('Directory error'));
+  }
+  
   // Save file
   $validators = array(
     'file_validate_is_image' => array(),
   );
   if ($file = file_save_upload('image_upload', $validators, $dir, TRUE)) {
-    file_set_status($file, FILE_STATUS_PERMANENT);
+  	$file->status = FILE_STATUS_PERMANENT;
+  	file_save($file);
     $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']) {
+  if (isset($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']);
+      db_update('user_titles')
+        ->fields(
+          array(
+            'title' => $form_state['values']['title'],
+            'value' => $form_state['values']['value'],
+            'image' => $image,
+            'image_title' => $form_state['values']['image_title'],
+            'rid' => $form_state['values']['role'],
+          )
+        )
+        ->condition('tid', $form_state['values']['tid'])
+        ->execute();
     }
     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']);
+      db_update('user_titles')
+        ->fields(
+          array(
+            'title' => $form_state['values']['title'],
+            'value' => $form_state['values']['value'],
+            'image' => '',
+            'image_title' => '',
+            'rid' => $form_state['values']['role'],
+          )
+        )
+        ->condition('tid', $form_state['values']['tid'])
+        ->execute();
     }
     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']);
+      db_update('user_titles')
+        ->fields(
+          array(
+            'title' => $form_state['values']['title'],
+            'value' => $form_state['values']['value'],
+            'image_title' => $form_state['values']['image_title'],
+            'rid' => $form_state['values']['role'],
+          )
+        )
+        ->condition('tid', $form_state['values']['tid'])
+        ->execute();	
     }
     drupal_set_message(t('Updated user title %title.', array('%title' => $form_state['values']['title'])));
-    $form_state['redirect'] = 'admin/user/user-titles/titles';
+    $form_state['redirect'] = 'admin/config/people/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']);
+  	db_insert('user_titles')
+        ->fields(
+          array(
+            'title' => $form_state['values']['title'],
+            'value' => $form_state['values']['value'],
+            'image' => $image,
+            'image_title' => $form_state['values']['image_title'],
+            'rid' => $form_state['values']['role'],
+          )
+        )
+        ->execute();
     drupal_set_message(t('Created new user title %title.', array('%title' => $form_state['values']['title'])));
-    $form_state['redirect'] = 'admin/user/user-titles/add/title';
+    $form_state['redirect'] = 'admin/config/people/user-titles/add/title';
   }
-
+  
   return;
 }
 
@@ -376,8 +448,10 @@
  *   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 (isset($_POST)) {
+    if (isset($_POST['op']) && $_POST['op'] == t('Delete') || (isset($_POST['confirm']) && $_POST['confirm'])) {
+      return drupal_get_form('user_titles_delete_title_form', $title);
+    }
   }
   if ($title) {
     return drupal_get_form('user_titles_add_title_form', $title);
@@ -391,7 +465,7 @@
  * @param $title
  *   A title object to delete.
  */
-function user_titles_delete_title_form(&$form_values, $title) {
+function user_titles_delete_title_form($form, &$form_state, $title) {
   $form = array();
   $form['tid'] = array(
     '#type' => 'hidden',
@@ -405,7 +479,7 @@
 
   $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',
+    'admin/config/people/user-titles/titles',
     t('This action cannot be undone.'),
     t('Delete'),
     t('Cancel'));
@@ -418,34 +492,33 @@
  */
 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']);
+  	db_delete('user_titles')
+  	  ->condition('tid', $form_state['values']['tid'])
+  	  ->execute();
   }
 
-  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');
-  }
+  drupal_set_message("User title '" . $form_state['values']['title'] . "' has been deleted successfully.", 'status');
 
-  $form_state['redirect'] = 'admin/user/user-titles/titles';
+  $form_state['redirect'] = 'admin/config/people/user-titles/titles';
   return;
 }
 
 /**
  * Theme function for the user title settings form.
  *
- * @param $form
- *   The form array of the user titles settings form.
+ * @param $variables
+ *   $variables['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) {
+function theme_user_titles_settings_form($variables) {
+  $form = $variables['form'];
+  $output = '';
   // Properly format hook_module
-  foreach ($form['points']['hook_module']['#options'] as $module => $info) {
+  foreach ($form['settings']['hook_module']['#options'] as $module => $info) {
     if ($info['url']) {
       $name = l($info['name'], $info['url']);
     }
@@ -453,29 +526,25 @@
       $name = check_plain($info['name']);
     }
     // drupal_render uses this area, not the original
-    $form['points']['hook_module'][$module]['#title'] = '<strong>' . $name . '</strong><div class="description">' . $info['description'] . '</div>';
+    $form['settings']['hook_module'][$module]['#title'] = '<strong>' . $name . '</strong><div class="description">' . $info['description'] . '</div>';
   }
 
-  $output .= '<div class="points">';
-  $output .= drupal_render($form['points']);
-  $output .= '</div>';
-
-  $output .= '<div class="images">';
-  $output .= drupal_render($form['images']);
+  $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';
+        $role['weight']['#attributes']['class'] = array('role-weight');
         $row[] = drupal_render($role['weight']);
       }
-      $rows[] = array('data' => $row, 'class' => 'draggable');
+      $rows[] = array('data' => $row, 'class' => array('draggable'));
     }
   }
   if (empty($rows)) {
@@ -488,32 +557,38 @@
   $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 .= theme('table', array(
+    'header' => $header, 
+    'rows' => $rows, 
+    'attributes' => array('id' => 'roles'),
+  ));
   $output .= '</fieldset>';
 
-  $output .= drupal_render($form);
+  $output .= '<div class="clearer">&nbsp;</div>';
+  $output .= drupal_render_children($form);
   return $output;
 }
 
 /**
  * Theme function for the user title settings form.
  *
- * @param $form
- *   The form array of the user titles titles form.
+ * @param $variables
+ *   $variables['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) {
+function theme_user_titles_titles_form($variables) {
+  $form = $variables['form'];
   drupal_add_js('misc/collapse.js');
   $output = '';
-  $units = module_invoke(variable_get('user_titles_hook_module', 'ut_basic'), 'user_titles', 'units');
+  $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' => $units, 'class' => array('num-posts')),
+    array('data' => t('Title'), 'class' => array('user-title')),
+    array('data' => t('Image'), 'class' => array('user-title-image')),
     array('data' => t('Operations'), 'colspan' => 2),
   );
 
@@ -527,11 +602,11 @@
         $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']),
+          array('data' => drupal_render($elem['value']), 'class' => array('num-posts')),
+          array('data' => drupal_render($elem['title']), 'class' => array('user-title')),
+          array('data' => drupal_render($elem['image']), 'class' => array('user-title-image')),
+          'edit' => l(t('edit'), "admin/config/people/user-titles/edit/title/" . $elem['tid']['#markup']),
+          'delete' => l(t('delete'), "admin/config/people/user-titles/delete/title/" . $elem['tid']['#markup']),
         );
       }
     }
@@ -539,15 +614,14 @@
       $rows[] = array(array('data' => t('No titles set.'), 'colspan' => '5'));
     }
 
-    $output .= '<fieldset class="collapsible collapsed title-table ' . $role['name']['#value'] . '">';
+    $output .= '<fieldset class="collapsible collapsed title-table ' . $role['name']['#markup'] . '">';
     $output .= '<legend>' . drupal_render($role['name']) . '</legend>';
-    $output .= theme('table', $header, $rows);
+    $output .= theme('table', array('header' => $header, 'rows' => $rows));
     $output .= drupal_render($role['add_title']);
     $output .= '</fieldset>';
   }
 
   $output .= '<div class="clearer">&nbsp;</div>';
-  $output .= drupal_render($form);
+  $output .= drupal_render_children($form);
   return $output;
 }
-
diff -ruN user_titles/user_titles.css user_titles.diff/user_titles.css
--- user_titles/user_titles.css	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/user_titles.css	2010-02-02 15:20:16.000000000 -0500
@@ -1,3 +1,4 @@
+/* $Id: user_titles.css,v 1.1.2.1 2010/02/02 11:20:15 agileware Exp $ */
 
 /**
  * My title block
diff -ruN user_titles/user_titles.info user_titles.diff/user_titles.info
--- user_titles/user_titles.info	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/user_titles.info	2011-08-22 21:44:00.000000000 -0500
@@ -1,4 +1,6 @@
 name = User titles
 description = Allow users to have titles based upon how many posts they have.
-core = 6.x
-package = User titles
+core = 7.x
+package = "User titles"
+version = "7.x-1.0-dev"
+stylesheets[all][] = user_titles.css
diff -ruN user_titles/user_titles.install user_titles.diff/user_titles.install
--- user_titles/user_titles.install	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/user_titles.install	2011-10-13 17:12:06.000000000 -0500
@@ -1,4 +1,5 @@
 <?php
+// $Id: user_titles.install,v 1.4.2.3 2010/02/02 11:24:27 agileware Exp $
 
 /**
  * @file user_titles.install
@@ -47,39 +48,36 @@
     'primary key' => array('tid'),
   );
 
-  $schema['user_titles_roles'] = array(
+  $schema['user_titles_posts'] = array(
     'fields' => array(
-      'rid' => array(
+      'uid' => array(
         'type' => 'int',
         'not null' => TRUE,
-        'unsigned' => TRUE,
+        'disp-width' => '10',
       ),
-      'weight' => array(
+      'posts' => array(
         'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
+        'not null' => FALSE,
+        'disp-width' => '11',
       ),
     ),
-    'primary key' => array('rid'),
+    'primary key' => array('uid'),
   );
 
-  $schema['user_titles_users'] = array(
+  $schema['user_titles_roles'] = array(
     'fields' => array(
-      'uid' => array(
+      'rid' => array(
         'type' => 'int',
         'not null' => TRUE,
         'unsigned' => TRUE,
       ),
-      'tid' => array(
+      'weight' => array(
         'type' => 'int',
         'not null' => TRUE,
-        'unsigned' => TRUE,
+        'default' => 0,
       ),
     ),
-    'primary key' => array('uid'),
-    'indexes' => array(
-      'tid' => array('tid'),
-    ),
+    'primary key' => array('rid'),
   );
 
   return $schema;
@@ -89,14 +87,28 @@
  * Implementation of hook_install().
  */
 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)");
-
-  // Change the weight.
-  // The module must run after all the contrib modules to give accurate titles.
-  db_query("UPDATE {system} SET weight = 1 WHERE name = 'user_titles'");
+  //inserting fields for existing roles into {user_titles_roles}
+  $query = db_select('role', 'r');
+  $query->addField('r', 'rid');
+  $query->condition('rid', array(1,2), 'NOT IN');
+  $roles = $query->execute();
+  $values = array();
+  foreach ($roles as $record) {
+  	$values[] = array(
+  	  'rid' => $record->rid,
+  	  'weight' => 0,
+  	);
+  }
+  $values[] = array(
+    'rid' => 2, 
+    'weight' => -10,
+  );
+  
+  $query = db_insert('user_titles_roles')->fields(array('rid', 'weight'));
+  foreach ($values as $record) {
+    $query->values($record);
+  }
+  $query->execute();
 }
 
 /**
@@ -108,90 +120,4 @@
   variable_del('user_titles_image_dir');
   variable_del('user_titles_block_number_users');
   variable_del('user_titles_block_display_fields');
-
-  drupal_uninstall_schema('user_titles');
-}
-
-/**
- * Implementation of hook_update_N().
- */
-function user_titles_update_6100() {
-  $ret = array();
-
-  db_drop_primary_key($ret, 'user_titles');
-  db_change_field($ret, 'user_titles', 'tid', 'tid', array('type' => 'serial', 'not null' => TRUE), array('primary key' => array('tid')));
-
-  db_add_field($ret, 'user_titles', 'image', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
-  db_add_field($ret, 'user_titles', 'image_title', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
-
-  return $ret;
-}
-
-/**
- * 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;
-}
-
-/**
- * Implementation of hook_update_N().
- */
-function user_titles_update_6102() {
-  $ret = array();
-
-  // Install ut_basic because it's functionality was previously in user_titles
-  drupal_install_modules(array('ut_basic'));
-
-  $schema['user_titles_users'] = array(
-    'fields' => array(
-      'uid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'unsigned' => TRUE,
-      ),
-      'tid' => array(
-        'type' => 'int',
-        'not null' => TRUE,
-        'unsigned' => TRUE,
-      ),
-    ),
-    'primary key' => array('uid'),
-    'indexes' => array(
-      'tid' => array('tid'),
-    ),
-  );
-  db_create_table($ret, 'user_titles_users', $schema['user_titles_users']);
-
-  // Change the weight.
-  // The module must run after all the contrib modules to give accurate titles.
-  $ret[] = update_sql("UPDATE {system} SET weight = 1 WHERE name = 'user_titles'");
-
-  variable_del('user_titles_types');
-
-  return $ret;
 }
diff -ruN user_titles/user_titles.module user_titles.diff/user_titles.module
--- user_titles/user_titles.module	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/user_titles.module	2011-10-17 17:36:18.000000000 -0500
@@ -1,4 +1,5 @@
 <?php
+// $Id: user_titles.module,v 1.14.2.8 2010/03/10 10:23:33 agileware Exp $
 
 /** 
  * @file user_titles.module
@@ -13,23 +14,29 @@
  */
 function user_titles_help($path, $arg) {
   switch ($path) {
-    case 'admin/user/user-titles':
+    case 'admin/config/people/user-titles':
       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.');
   }
 }
 
 /**
- * Implementation of hook_perm().
+ * Implementation of hook_permission().
  */
-function user_titles_perm() {
-  return array('administer user titles');
+function user_titles_permission() {
+  return array(
+    'administer user titles' => array(
+      'title' => t('Administer user titles'),
+      'description' => t('Set up User Titles module.'),
+      'restrict access' => TRUE,
+    ),
+  );
 }
 
 /**
  * Implementation of hook_menu().
  */
 function user_titles_menu() {
-  $items['admin/user/user-titles'] = array(
+  $items['admin/config/people/user-titles'] = array(
     'title' => t('User titles'),
     'description' => 'Configure user titles and number of posts required',
     'page callback' => 'drupal_get_form',
@@ -37,12 +44,12 @@
     'access arguments' => array('administer user titles'),
     'file' => 'user_titles.admin.inc',
   );
-  $items['admin/user/user-titles/settings'] = array(
+  $items['admin/config/people/user-titles/settings'] = array(
     'title' => t('Settings'),
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'weight' => -10
   );
-  $items['admin/user/user-titles/titles'] = array(
+  $items['admin/config/people/user-titles/titles'] = array(
     'title' => t('Titles'),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('user_titles_titles_form'),
@@ -50,7 +57,7 @@
     'type' => MENU_LOCAL_TASK,
     'file' => 'user_titles.admin.inc',
   );
-  $items['admin/user/user-titles/add/title'] = array(
+  $items['admin/config/people/user-titles/add/title'] = array(
     'title' => t('Add title'),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('user_titles_add_title_form'),
@@ -58,30 +65,23 @@
     'type' => MENU_LOCAL_TASK,
     'file' => 'user_titles.admin.inc',
   );
-  $items['admin/user/user-titles/edit/title/%title'] = array(
+  $items['admin/config/people/user-titles/edit/title/%title'] = array(
     'title' => t('Edit title'),
     'page callback' => 'user_titles_edit_title_form',
-    'page arguments' => array(5),
+    'page arguments' => array(6),
     'access arguments' => array('administer user titles'),
     'type' => MENU_CALLBACK,
     'file' => 'user_titles.admin.inc',
   );
-  $items['admin/user/user-titles/delete/title/%title'] = array(
+  $items['admin/config/people/user-titles/delete/title/%title'] = array(
     'title' => t('Remove title'),
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('user_titles_delete_title_form', 5),
+    'page arguments' => array('user_titles_delete_title_form', 6),
     'access arguments' => array('administer user titles'),
     'type' => MENU_CALLBACK,
     'file' => 'user_titles.admin.inc',
   );
 
-  $items['user-titles/autocomplete'] = array(
-    'title' => 'Autocomplete user titles',
-    'page callback' => 'user_titles_autocomplete',
-    'access arguments' => array('access content'),
-    'type' => MENU_CALLBACK,
-  );
-
   return $items;
 }
 
@@ -100,33 +100,29 @@
 }
 
 /**
- * Implementation of hook_theme().
+ * Implementation of hook_theme()
  */
 function user_titles_theme($existing, $type, $theme, $path) {
   return array(
     'user_titles_settings_form' => array(
-      'arguments' => array(
-        'form' => array(),
-      ),
+      'render element' => 'form',
     ),
     'user_titles_titles_form' => array(
-      'arguments' => array(
-        'form' => array(),
-      ),
+      'render element' => 'form',
     ),
     'user_titles_image' => array(
-      'arguments' => array(
+      'variables' => array(
         'filepath' => NULL,
         'alt' => NULL,
       ),
     ),
     'user_titles_matching_users_block' => array(
-      'arguments' => array(
+      'variables' => array(
         'users' => array(),
       ),
     ),
     'user_titles_my_title_block' => array(
-      'arguments' => array(
+      'variables' => array(
         'name' => NULL,
         'posts' => NULL,
         'units' => NULL,
@@ -149,13 +145,86 @@
 }
 
 /**
+ * Implementatin of hook_node_insert
+ * 
+ * @param object $node
+ */
+function user_titles_node_insert($node) {
+  $allowed_types = user_titles_get_allowed_types();
+  if (in_array($node->type, $allowed_types)) {
+    //updating {user_titles_posts}
+    $updated = db_update('user_titles_posts')
+      ->fields(array(
+        'posts' => user_titles_get_posts($node->uid) + 1,
+      )
+    )
+    ->condition('uid', $node->uid)
+    ->execute();
+    if (!$updated) {
+      //if no entries were updated, insert new entry
+      db_insert('user_titles_posts')
+        ->fields(array(
+          'uid' => $node->uid,
+          'posts' => user_titles_get_posts($node->uid) + 1,
+        )
+      )
+      ->execute();
+    }
+  }
+}
+
+/**
+ * Implementatin of hooke_node_delete
+ * 
+ * @param object $node
+ */
+function user_titles_node_delete($node) {
+  $allowed_types = user_titles_get_allowed_types();
+  if (in_array($node->type, $allowed_types)) {
+  //updating {user_titles_posts}
+    $updated = db_update('user_titles_posts')
+      ->fields(array(
+        'posts' => user_titles_get_posts($node->uid) - 1,
+      )
+    )
+    ->condition('uid', $node->uid)
+    ->execute();
+    if (!$updated) {
+      //if no entries were updated, insert new entry
+      db_insert('user_titles_posts')
+        ->fields(array(
+          'uid' => $node->uid,
+          'posts' => user_titles_get_posts($node->uid) - 1,
+        )
+      )
+      ->execute();
+    }
+  }
+}
+
+/**
  * Extra submit handler for the user_admin_new_role form.
  */
 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']);
+    $query = db_select('user_titles_roles', 'u');
+    $query->addField('u', 'MAX(weight)');
+    $result = $query->execute();
+    $max_weight = $result->fetchField();
+    
+    //get role id
+    $query = db_select('role', 'r');
+    $query->addField('r', 'rid');
+    $query->condition('name', $form_state['values']['name']);
+    $rid = $query->execute()->fetchField();
+    //insert entry for this new role  
+    db_insert('user_titles_roles')
+      ->fields(array(
+        'rid' => $rid,
+        'weight' => $max_weight + 1,
+      )
+    )
+    ->execute();
   }
 }
 
@@ -164,80 +233,109 @@
  */
 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']);
+    db_delete('user_titles_roles')
+      ->condition('rid', $form_state['values']['rid'])
+      ->execute();
   }
 }
 
 /**
- * Implementation of hook_block().
+ * Implementation of hook_block_info
  */
-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,
+function user_titles_block_info() {
+  $blocks = array();
+  
+  $blocks['users_with_my_title'] = array(
+    'info' => t('User Titles: Users with my title'),
+    'cache' => BLOCK_CACHE_PER_USER,
+  );
+  
+  $blocks['my_title'] = array(
+    'info' => t('User Titles: My title'),
+    'cache' => BLOCK_CACHE_PER_USER,
+  );
+  
+  return $blocks; 
+}
+
+/**
+ * 
+ * Implementation of hook_block_view
+ * 
+ * @param $delta - to choose block
+ * 
+ * @return block content
+ */
+function user_titles_block_view($delta = '') {
+  switch ($delta) {
+    case 'users_with_my_title':
+      $block['subject'] = t('Users with your title');
+      $block['content'] = user_titles_matching_users_block();
+      break;
+    case 'my_title':
+      $block['subject'] = t('My title');
+      $block['content'] = user_titles_my_title_block();
+      break;
+  }
+  return $block;  
+}
+
+/**
+ * 
+ * Implementation of hook_block_configure
+ * 
+ * @param $delta - to choose block
+ * 
+ * @return block configure form
+ */
+function user_titles_block_configure($delta = '') {
+  $form = array();
+  switch ($delta) {
+    case 'users_with_my_title':
+      $options = array();
+      for ($i = 1; $i <= 25; $i++) {
+        $options[$i] = $i;
+      }
+      $form['number_users'] = array(
+        '#type' => 'select',
+        '#title' => t('Max number of users to display'),
+        '#default_value' => variable_get('user_titles_block_number_users', 10),
+        '#options' => $options,
       );
-      $blocks[1] = array(
-        'info' => t('User Titles: My title'),
-        'cache' => BLOCK_CACHE_PER_USER,
+      break;
+    case 'my_title':
+      $form['display_fields'] = array(
+        '#type' => 'select',
+        '#title' => t('Fields to display'),
+        '#default_value' => variable_get('user_titles_block_display_fields', array('name', 'posts', 'title')),
+        '#options' => array(
+          'name' => t('Name'),
+          'posts' => t('Posts'),
+          'title' => t('Title'),
+        ),
+        '#multiple' => TRUE,
+        '#required' => TRUE,
       );
-      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;
-        case 1:
-          $block['subject'] = t('My title');
-          $block['content'] = user_titles_my_title_block();
-          break;
-      } // End delta switch
-      return $block;
-    case 'configure':
-      $form = array();
-      switch ($delta) {
-        case 0:
-          $options = array();
-          for ($i = 1; $i <= 25; $i++) {
-            $options[$i] = $i;
-          }
-          $form['number_users'] = array(
-            '#type' => 'select',
-            '#title' => t('Max number of users to display'),
-            '#default_value' => variable_get('user_titles_block_number_users', 10),
-            '#options' => $options,
-          );
-          break;
-        case 1:
-          $form['display_fields'] = array(
-            '#type' => 'select',
-            '#title' => t('Fields to display'),
-            '#default_value' => variable_get('user_titles_block_display_fields', array('name', 'posts', 'title')),
-            '#options' => array(
-              'name' => t('Name'),
-              'posts' => t('Posts'),
-              'title' => t('Title'),
-            ),
-            '#multiple' => TRUE,
-            '#required' => TRUE,
-          );
-          break;
-      } // End delta switch
-      return $form;
-    case 'save':
-      switch ($delta) {
-        case 0:
-          variable_set('user_titles_block_number_users', $edit['number_users']);
-          break;
-        case 1:
-          variable_set('user_titles_block_display_fields', $edit['display_fields']);
-          break;
-      } // End delta switch
-  } // End op switch
+      break;
+  } // End delta switch
+  return $form;
+}
+
+/**
+ * 
+ * Implementation of hook_block_save
+ * 
+ * @param $delta - to choose block
+ */
+function user_titles_block_save($delta = '') {
+  switch ($delta) {
+    case 'users_with_my_title':
+      variable_set('user_titles_block_number_users', $edit['number_users']);
+      break;
+    case 'my_title':
+      variable_set('user_titles_block_display_fields', $edit['display_fields']);
+      break;
+    }
 }
 
 /**
@@ -259,7 +357,7 @@
     }
   }
 
-  return theme('user_titles_matching_users_block', $users);
+  return theme('user_titles_matching_users_block', array('users' => $users));
 }
 
 /**
@@ -275,88 +373,200 @@
   $display_fields = variable_get('user_titles_block_display_fields', array('name', 'posts', 'title'));
   $name = isset($display_fields['name']) ? $user->name : NULL;
   $posts = isset($display_fields['posts']) ? user_titles_get_posts($user->uid) : NULL;
-  $units = isset($display_fields['posts']) ? module_invoke(variable_get('user_titles_hook_module', 'ut_basic'), 'user_titles', 'units') : NULL;
+  $units = isset($display_fields['posts']) ? module_invoke(user_titles_get_hook_module(), 'user_titles', 'units') : NULL;
   $title = isset($display_fields['title']) ? user_titles_get_user_title($user) : NULL;
  
-  return theme('user_titles_my_title_block', $name, $posts, $units, $title);
+  return theme('user_titles_my_title_block', array('name' => $name, 'posts' => $posts, 'units' => $units, 'title' => $title));
 }
 
 /**
- * Implementation of hook_user().
+ * Implementation of hook_comment_insert().
+ */
+function user_titles_comment_insert($comment) {
+  $node = node_load($comment->nid);
+  $types = user_titles_get_allowed_types();
+  if (in_array($node->type, $types)) {
+    $uid = $comment->uid;
+    $updated = db_update('user_titles_posts')
+      ->fields(array(
+        'posts' => user_titles_get_posts($uid) + 1,
+      )
+    )
+    ->condition('uid', $uid)
+    ->execute();
+    if (!$updated) {
+      //if no entries were updated, insert new entry
+      db_insert('user_titles_posts')
+        ->fields(array(
+          'uid' => $uid,
+          'posts' => user_titles_get_posts($uid) + 1,
+        )
+      )
+      ->execute();
+    }
+  }
+}
+
+/**
+ * Implementation of hook_comment_delete().
+ */
+function user_titles_comment_delete($comment) {
+  $node = node_load($comment->nid);
+  $types = user_titles_get_allowed_types();
+  if (in_array($node->type, $types)) {
+    $uid = $comment->uid;
+    $updated = db_update('user_titles_posts')
+      ->fields(array(
+        'posts' => user_titles_get_posts($uid) - 1,
+      )
+    )
+    ->condition('uid', $uid)
+    ->execute();
+    if (!$updated) {
+      //if no entries were updated, insert new entry
+      db_insert('user_titles_posts')
+        ->fields(array(
+          'uid' => $uid,
+          'posts' => user_titles_get_posts($uid) - 1,
+        )
+      )
+      ->execute();
+    }
+  }
+}
+
+
+/**
+ * Implementation of hook_FORM_ID_form_alter
+ * Alters profile form to add user titles fields
  *
- * Add the 'edit user title' form to the edit user page.
+ * @param array $form
+ * @param array $form_state
  */
-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>',
-        );
-
-        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>',
-          );
-        }
-
-        $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 : '',
-        );
+function user_titles_form_user_profile_form_alter(&$form, &$form_state) {
+  if ($form['#user_category'] == 'account') {
+    $user = $form['#user'];
+    if (!user_access('administer user titles') || (!isset($user->uid))) {
+      return;
+    }
+    // when user tries to edit his own data
+    $form['user_titles'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('User Title'),
+      '#tree' => FALSE,
+      '#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;
+    }
 
-        return $form;
-      }
-      break;
-    case 'view':
-      if (variable_get('user_titles_display_on_profile', TRUE)) {
-        $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),
-          );
-        }
+    $form['user_titles']['current_title'] = array(
+      '#value' => '<div><strong>' . t('Current user title:') . ' </strong> ' . filter_xss_admin($title) . '</div>',
+    );
+
+    if (isset($title_info->title) && empty($title_info->tid)) {
+      $default_title_info = user_titles_get_title(user_titles_get_posts($user->uid));
+      if (!isset($default_title_info->title)) {
+        $default_title = t('No title set');
+      } else {
+        $default_title = $default_title_info->title;
       }
-      break;
+      $form['user_titles']['default_title'] = array(
+        '#value' => '<div><strong>' . t('Default user title:') . ' </strong> ' . filter_xss_admin($default_title) . '</div>',
+      );
+    }
+
+    $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->data['user_title']) ? $user->data['user_title'] : '',
+    );
+  }
+}
+
+
+/**
+ * hook_user_presave implementation
+ *
+ */
+function user_titles_user_presave(&$edit, $account, $category) {
+  if ($category == 'account') {
+    $edit['data']['user_title'] = $edit['user_title'];
   }
 }
 
+
+/**
+ * Implementation of hook_user_delete
+ *
+ * @param object $account
+ */
+function user_titles_user_delete($account) {
+  db_delete('user_titles_posts')
+    ->condition('uid', $account->uid)
+    ->execute();
+}
+
+
+/**
+ * Implementation of hook_user_view()
+ *
+ * @param object $user
+ */
+function user_titles_user_view($user) {
+  if (variable_get('user_titles_display_on_profile', TRUE)) {
+    $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',
+        '#title' => t('User title'),
+        '#markup' => filter_xss_admin($title),
+      );
+    }
+  }
+}
+
+/**
+ * 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_get_hook_module() {
+  $default = 'user_titles';
+  $module = variable_get('user_titles_hook_module', $default);
+  if (module_exists($module)) {
+    return $module;
+  }
+  else {
+    return $default;
+  }
+}
+
+/**
+ * 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_set_hook_module($module) {
+  variable_set('user_titles_hook_module', $module);
+}
+
 /**
  * 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.
- *
  * @param $uid
  *   An integer containing the uid of the user to fetch the number of posts for.
  * 
@@ -366,7 +576,7 @@
 function user_titles_get_posts($uid) {
   static $cache = array();
   if (!isset($cache[$uid])) {
-    $module = variable_get('user_titles_hook_module', 'ut_basic');
+    $module = user_titles_get_hook_module();
     $cache[$uid] = module_invoke($module, 'user_titles', 'get', $uid);
   }
   return $cache[$uid];
@@ -382,7 +592,7 @@
  *   If $rid is NULL the default user titles role will be used.
  *
  * @return
- *   A title object for the number of posts and role.
+ *   A title array for the number of posts and role.
  */
 function user_titles_get_title($posts, $rid = NULL) {
   if (!$rid) {
@@ -391,10 +601,12 @@
   $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) {
-      return $title;
+    if ($posts >= $title['value']) {
+      return (object)$title;
     }
   }
+  //to make code analyzer's warnings get off me
+  return NULL;
 }
 
 /**
@@ -407,6 +619,8 @@
   $title = user_titles_get_user_title_info($user);
   if (isset($title->title)) {
     return $title->title;
+  } else {
+    return '';
   }
 }
 
@@ -432,54 +646,46 @@
 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);
+    return theme('user_titles_image', array('filepath' => $title->image, 'alt' => $title->image_title));
   }
 }
 
 /**
  * Fetch full title info for a given user.
  * 
- * @param $user
+ * @param $uid
  *   The user to fetch. May be a $user object or a $uid.
- *
- * @return
- *   The title object for the user.
  */
 function user_titles_get_user_title_info($user) {
   if (is_numeric($user)) {
-    $user = user_load(array('uid' => $user));
+    $user = user_load($user);
   }
   if (!$user) {
     return;
   }
-
-  // Return override title if set.
-  if (!empty($user->user_title)) {
+  
+  if ((!empty($user->data['user_title'])) && ($user->data['user_title'] != '')) {
     $title = new stdClass;
-    $title->title = $user->user_title;
+    $title->title = $user->data['user_title'];
     return $title;
   }
+  $rid = user_titles_get_users_title_role($user->uid);
 
-  $tid = db_query("SELECT tid FROM {user_titles_users} WHERE uid = %d", $user->uid);
-  $title = user_titles_get_titles($tid);
-
-  return $title;
+  return user_titles_get_title(user_titles_get_posts($user->uid), $rid);
 }
 
 /**
- * Get the title id for the given user.
- *
- * @param $uid
- *   The user id to get the tid for.
- *
- * @return
- *   The tid of the users title.
+ * Returns the next highest title from the given title
  */
-function user_titles_get_user_tid($uid) {
-  $rid = user_titles_get_user_title_role($uid);
-  $title = user_titles_get_title(user_titles_get_posts($uid), $rid);
-
-  return $title->tid ? $title->tid : 0;
+function user_titles_get_next_higher_title($tid, $rid) {
+  $result = db_query_range("SELECT *
+                                  FROM {user_titles}
+                                  WHERE value > (SELECT value
+                                                  FROM {user_titles}
+                                                  WHERE tid = %d)
+                                       AND rid = %d
+                                  ORDER BY value", 0, 1, array($tid, $rid));
+  return $result->fetchField();
 }
 
 /**
@@ -492,12 +698,29 @@
  *   An array of user ids
  */
 function user_titles_get_matching_users($user) {
-  $users = array();
   $title = user_titles_get_user_title_info($user->uid);
+  $next_title = user_titles_get_next_higher_title($title->tid, $title->rid);
 
-  if ($title->tid) {
-    $result = db_query("SELECT uid FROM {user_titles_users} WHERE tid = %d AND uid != %d", $title->tid, $user->uid);
-    while ($row = db_fetch_array($result)) {
+  if ($next_title !== FALSE) {
+  	$query = db_select('user_titles_posts', 'u');
+    $query->addField('u', 'uid');
+    $query->condition('posts', $title->value, '>=');
+    $query->condition('posts', $next_title->value, '<=');
+    $query->condition('uid', array(0, $user->uid), 'NOT IN');
+    $result = $query->execute();
+  }
+  else {
+  	$query = db_select('user_titles_posts', 'u');
+    $query->addField('u', 'uid');
+    $query->condition('posts', $title->value, '>=');
+    $query->condition('uid', array(0, $user->uid), 'NOT IN');
+    $result = $query->execute();
+  }
+
+  $users = array();
+  while ($row = $result->fetchAssoc()) {
+    // Only return users in the same user titles role
+    if (user_titles_get_users_title_role($row['uid']) == $title->rid) {
       $users[] = $row['uid'];
     }
   }
@@ -506,6 +729,72 @@
 }
 
 /**
+ * Update the post count for a given user.
+ *
+ * @param $uid
+ *   The user id to update.
+ * @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
+    $allowed_types = user_titles_get_allowed_types();
+    if ($allowed_types) {
+      $query = db_select('node', 'n');
+      $query->addField('n', 'nid');
+      $query->condition('uid', $uid);
+      $query->condition('type', $allowed_types, 'IN');    
+      $count = $query->countQuery()->execute()->fetchField();
+      if (module_exists('comment')) {
+      	$query = db_select('comment', 'c');
+        $query->addField('c', 'nid');
+        $query->condition('uid', $uid);  
+        $count += $query->countQuery()->execute()->fetchField();
+      }
+    }
+    else {
+      $count = 0;
+    }
+  }
+  
+  //here there was "mysql only" REPLACE query. i haven't figured what was the meaning of it,
+  //but replaced it with db_update call 
+  db_update('user_titles_posts')
+    ->fields(array(
+        'posts' => $count,
+      )
+    )
+    ->condition('uid', $uid)
+    ->execute();
+  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());
+}
+
+/**
+ * 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);
+}
+
+/**
  * Get titles from db
  * If tid is passed in only that title will be fetched, otherwise all titles will be fetched.
  *
@@ -517,15 +806,22 @@
  *   Otherwise an array of title objects is returned.
  */
 function user_titles_get_titles($tid = NULL) {
+  $result = array();
   if ($tid && is_numeric($tid)) {
-    $result = db_fetch_object(db_query("SELECT * FROM {user_titles} WHERE tid = %d", $tid));
+  	$query = db_select('user_titles', 'u');
+    $query->fields('u');
+    $query->condition('tid', $tid); 
+    $rows = $query->execute();
+    return $rows->fetchObject();
   }
   else {
-    $result = array();
-    $query = db_query("SELECT * FROM {user_titles} ORDER BY value DESC");
-    while ($row = db_fetch_object($query)) {
-      $result[] = $row;
-    }
+    $query = db_select('user_titles', 'u');
+    $query->fields('u');
+    $query->orderBy('value', 'DESC'); 
+    $rows = $query->execute();
+  }
+  while ($row = $rows->fetchAssoc()) {
+    $result[] = $row;
   }
 
   return $result;
@@ -545,13 +841,13 @@
 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);
+    $rows = db_query('SELECT * FROM {user_titles} WHERE rid=:rid ORDER BY value DESC', array(':rid' => $rid));
   }
   else {
-    $query = db_query("SELECT * FROM {user_titles} ORDER BY rid, value DESC");
+    $rows = db_query('SELECT * FROM {user_titles} ORDER BY rid DESC, value DESC');
   }
-  while ($row = db_fetch_object($query)) {
-    $result[] = $row;
+  foreach ($rows as $row) {
+    $result[] = (array) $row;
   }
   return $result;
 }
@@ -564,11 +860,12 @@
  */
 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)) {
+  $query = db_select('role', 'r');
+  $query->join('user_titles_roles', 'ur', 'r.rid = ur.rid');
+  $query->fields('r', array('rid', 'name'));
+  $query->orderBy('ur.weight');
+  $result = $query->execute();
+  while ($row = $result->fetchAssoc()) {
     $roles[$row['rid']] = $row['name'];
   }
   return $roles;
@@ -582,8 +879,8 @@
  *   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;
+  $result = db_query_range("SELECT rid FROM {user_titles_roles} ORDER BY weight", 0, 1);
+  return $result->fetchField();
 }
 
 /**
@@ -592,47 +889,15 @@
  * @return
  *   An integer containing a role id.
  */
-function user_titles_get_user_title_role($uid) {
-  $rid = db_result(db_query_range("SELECT rid
-                                   FROM {user_titles_roles}
-                                   WHERE rid IN (SELECT rid
-                                                 FROM {users_roles}
-                                                 WHERE uid = %d)
-                                   OR rid = 2
-                                   ORDER BY weight", $uid, 0, 1));
-  return $rid;
-}
-
-/**
- * Set the given users title
- *
- * @param $uid
- *   The user id to set the title for.
- */
-function user_titles_set_user_title($uid) {
-  $tid = user_titles_get_user_tid($uid);
-  db_query("UPDATE {user_titles_users} SET tid = %d WHERE uid = %d", $tid, $uid);
-  if (!db_affected_rows()) {
-    db_query("INSERT INTO {user_titles_users} (uid, tid) VALUES (%d, %d)", $uid, $tid);
-  }
-}
-
-/**
- * Reset all user titles
- */
-function user_titles_reset_titles() {
-  // Just in case. This could take a little while...
-  set_time_limit(600);
-
-  db_query('TRUNCATE TABLE {user_titles_users}');
-  $result = db_query('SELECT uid FROM {users}');
-  $uids = array();
-  while ($row = db_fetch_array($result)) {
-    $uids[] = $row['uid'];
-  }
-  foreach ($uids as $uid) {
-    user_titles_set_user_title($uid);
-  }
+function user_titles_get_users_title_role($uid) {
+  $result = db_query_range("SELECT rid
+                            FROM {user_titles_roles}
+                            WHERE rid IN (SELECT rid
+                                            FROM {users_roles}
+                                            WHERE uid = :uid)
+                            OR rid = 2
+                            ORDER BY weight", 0, 1, array(':uid' => $uid));
+  return $result->fetchField();
 }
 
 /**
@@ -648,8 +913,8 @@
  *
  * @ingroup themeable
  */
-function theme_user_titles_image($filepath, $alt) {
-  $image = theme('image', $filepath, $alt, $alt, '', FALSE);
+function theme_user_titles_image($variables) {
+  $image = theme('image', array('path' => $variables['filepath'], 'alt' => $variables['alt'], 'title' => $variables['alt']));
 
   $output = '<div class="user-titles-image">';
   $output .= $image;
@@ -696,7 +961,11 @@
  *
  * @ingroup themeable
  */
-function theme_user_titles_my_title_block($name = NULL, $posts = NULL, $units = NULL, $title = NULL) {
+function theme_user_titles_my_title_block($variables) {
+  $name = $variables['name'];
+  $posts = $variables['posts'];
+  $units = $variables['units'];
+  $title = $variables['title'];
   $output = '';
   if (!is_null($name) || !is_null($posts) || !is_null($title)) {
     $label_class = 'label';
@@ -747,40 +1016,30 @@
 }
 
 /**
- * Helper function for autocompletion
+ * Built-in hook implementation that counts nodes
  */
-function user_titles_autocomplete($rids, $string = '') {
-  // The user enters a comma-separated list of titles. We only autocomplete the last title.
-  $array = drupal_explode_tags($string);
-
-  $rids = explode(',', $rids);
-  foreach ($rids as $rid) {
-    $in .= $in ? ', %d' : '%d';
-    $query_vars[] = $rid;
-  }
-
-  // Fetch last tag
-  $last_string = trim(array_pop($array));
-  $query_vars[] = $last_string;
-
-  $matches = array();
-  if ($last_string != '') {
-    $result = db_query_range("SELECT tid, title
-                              FROM {user_titles}
-                              WHERE rid IN ($in)
-                              AND LOWER(title) LIKE LOWER('%%%s%%')", $query_vars, 0, 10);
-
-    $prefix = count($array) ? implode(', ', $array) . ', ' : '';
-
-    while ($title = db_fetch_object($result)) {
-      $t = $title->title;
-      // Commas and quotes in terms are special cases, so encode 'em.
-      if (strpos($title->title, ',') !== FALSE || strpos($title->title, '"') !== FALSE) {
-        $t = '"' . str_replace('"', '""', $title->title) . '"';
+function user_titles_user_titles($op, $uid = NULL) {
+  switch ($op) {
+    case 'register':
+      return 'user_titles';
+    case 'name':
+      return t('Post count');
+    case 'description':
+      return t('Built-in, see below');
+    case 'units':
+      return t('Posts');
+    case 'url':
+      // No url implemented
+      return;
+    case 'get':
+      $query = db_select('user_titles_posts', 'u');
+      $query->addField('u', 'posts');
+      $query->condition('uid', $uid);
+      $res = $query->execute()->fetchField();
+      if ($res === FALSE) {
+        $res = user_titles_update_post_count($uid);
       }
-      $matches[$prefix . $t] = check_plain($title->title);
-    }
+      return $res;
   }
-
-  drupal_json($matches);
 }
+
diff -ruN user_titles/ut_views/ut_views.info user_titles.diff/ut_views/ut_views.info
--- user_titles/ut_views/ut_views.info	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/ut_views/ut_views.info	1969-12-31 19:00:00.000000000 -0500
@@ -1,6 +0,0 @@
-name = User titles views
-description = Adds views support to user titles
-core = 6.x
-dependencies[] = user_titles
-dependencies[] = views
-package = User titles
diff -ruN user_titles/ut_views/ut_views.module user_titles.diff/ut_views/ut_views.module
--- user_titles/ut_views/ut_views.module	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/ut_views/ut_views.module	1969-12-31 19:00:00.000000000 -0500
@@ -1,16 +0,0 @@
-<?php
-
-/** 
- * @file ut_views.module
- * Adds views support to user titles
- */
-
-/**
- *  Implement hook_views_api().
- */
-function ut_views_views_api() {
-  return array(
-    'api' => 2.0,
-    'path' => drupal_get_path('module', 'ut_views'),
-  );
-}
diff -ruN user_titles/ut_views/ut_views.views.inc user_titles.diff/ut_views/ut_views.views.inc
--- user_titles/ut_views/ut_views.views.inc	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/ut_views/ut_views.views.inc	1969-12-31 19:00:00.000000000 -0500
@@ -1,147 +0,0 @@
-<?php
-
-/**
- *  @file
- *  This defines views hooks for the user_titles module.
- *  It will be loaded automatically as needed by the Views module.
- */
-
-/**
- * Implementation of hook_views_data()
- */
-function user_titles_views_data() {
-  $data['user_titles']['table']['group'] = t('User titles');
-
-  $data['user_titles']['table']['join'] = array(
-    // user_titles links to node through user_titles_users via tid.
-    'node' => array(
-      'left_table' => 'user_titles_users',
-      'left_field' => 'tid',
-      'field' => 'tid',
-    ),
-    // user_titles links to node_revisions through user_titles_users via tid.
-    'node_revisions' => array(
-      'left_table' => 'user_titles_users',
-      'left_field' => 'tid',
-      'field' => 'tid',
-    ),
-    // user_titles links to users through user_titles_users via tid.
-    'users' => array(
-      'left_table' => 'user_titles_users',
-      'left_field' => 'tid',
-      'field' => 'tid',
-    ),
-  );
-
-  $data['user_titles_users']['table']['group'] = t('User titles');
-
-  $data['user_titles_users']['table']['join'] = array(
-    'user_titles' => array(
-      'left_field' => 'tid',
-      'field' => 'tid',
-    ),
-    'users' => array(
-      'left_field' => 'uid',
-      'field' => 'uid',
-    ),
-    'node' => array(
-      'left_field' => 'uid',
-      'field' => 'uid',
-    ),
-    'node_revisions' => array(
-      'left_field' => 'uid',
-      'field' => 'uid',
-    ),
-  );
-
-  // Describe the title column of the user_titles table.
-  $data['user_titles']['title'] = array(
-    'title' => t('Title'),
-    'help' => t("A user's current title."),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-      'help' => t('User title.'),
-//       'many to one' => TRUE,
-      'empty field name' => t('No title'),
-    ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-  );
-
-  $data['user_titles']['tid'] = array(
-    'title' => t('Title'),
-    'help' => t("A user's current title ID."),
-    'filter' => array(
-      'title' => t('Title'),
-      'handler' => 'views_handler_filter_user_title_tid',
-      'numeric' => TRUE,
-      'allow empty' => TRUE,
-    ),
-  );
-
-  // Describe the image column of the user_titles table.
-  $data['user_titles']['image'] = array(
-    'title' => t('Title image'),
-    'help' => t("A user's current title image."), // The help that appears on the UI,
-    'field' => array(
-      'handler' => 'views_handler_field_user_titles_image',
-      'click sortable' => TRUE,
-    ),
-/*
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-*/
-    'sort' => array(
-      'handler' => 'views_handler_sort_user_titles_image',
-    ),
-  );
-
-  return $data;
-}
-
-/**
- * Implementation of hook_views_handlers()
- */
-function user_titles_views_handlers() {
-  return array(
-    'info' => array(
-      'path' => drupal_get_path('module', 'ut_views'),
-    ),
-    'handlers' => array(
-      // field handlers
-      'views_handler_field_user_title_image' => array(
-        'parent' => 'views_handler_field',
-      ),
-      // filter handlers
-      'views_handler_filter_user_title_tid' => array(
-        'parent' => 'views_handler_filter_many_to_one',
-      ),
-      // sort handlers
-      'views_handler_sort_user_title_image' => array(
-        'parent' => 'views_handler_sort',
-      ),
-    ),
-  );
-}
-
-/**
- * Implementation of hook_views_plugins()
- */
-function user_titles_views_plugins() {
-  return array(
-    'module' => 'ut_views',
-    'argument validator' => array(
-      'user_title' => array(
-        'title' => t('User title'),
-        'handler' => 'views_plugin_argument_validate_user_title',
-        'path' => drupal_get_path('module', 'ut_views'),
-      ),
-    ),
-  );
-}
diff -ruN user_titles/ut_views/views_handler_field_user_title_image.inc user_titles.diff/ut_views/views_handler_field_user_title_image.inc
--- user_titles/ut_views/views_handler_field_user_title_image.inc	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/ut_views/views_handler_field_user_title_image.inc	1969-12-31 19:00:00.000000000 -0500
@@ -1,27 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains the user title image field handler.
- */
-
-/**
- * Field handler to provide simple renderer that allows using a themed user title image
- */
-class views_handler_field_user_title_image extends views_handler_field {
-  function construct() {
-    parent::construct();
-    $this->additional_fields['image_title'] = 'image_title';
-  }
-
-  function element_type() {
-    return 'div';
-  }
-
-  function render($values) {
-    $title = $values->{$this->aliases['image_title']};
-    $src = $values->{$this->field_alias};
-
-    return theme('image', $src, $title, $title);
-  }
-}
diff -ruN user_titles/ut_views/views_handler_filter_user_title_tid.inc user_titles.diff/ut_views/views_handler_filter_user_title_tid.inc
--- user_titles/ut_views/views_handler_filter_user_title_tid.inc	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/ut_views/views_handler_filter_user_title_tid.inc	1969-12-31 19:00:00.000000000 -0500
@@ -1,298 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains the user title tid filter handler.
- */
-
-/**
- * Filter by title id
- */
-class views_handler_filter_user_title_tid extends views_handler_filter_many_to_one {
-  function has_extra_options() { return TRUE; }
-
-  function get_value_options() { /* don't overwrite the value options */ }
-
-  function option_definition() {
-    $options = parent::option_definition();
-
-    $options['type'] = array('default' => 'textfield');
-    $options['rids'] = array('default' => array());
-
-    return $options;
-  }
-
-  function extra_options_form(&$form, &$form_state) {
-    $roles = user_titles_get_roles();
-    foreach ($roles as $rid => $role) {
-      $options[$rid] = check_plain($role);
-    }
-
-    $form['rids'] = array(
-      '#prefix' => '<div class="views-left-40">',
-      '#suffix' => '</div>',
-      '#type' => 'checkboxes',
-      '#title' => t('Roles'),
-      '#options' => $options,
-      '#description' => t('Select which roles to show terms for in the regular options.'),
-      '#default_value' => $this->options['rids'],
-    );
-
-    $form['markup_start'] = array(
-      '#value' => '<div class="views-left-40">',
-    );
-
-    $form['type'] = array(
-      '#type' => 'radios',
-      '#title' => t('Selection type'),
-      '#options' => array('select' => t('Dropdown'), 'textfield' => t('Autocomplete')),
-      '#default_value' => $this->options['type'],
-    );
-
-    $form['markup_end'] = array(
-      '#value' => '</div>',
-    );
-  }
-
-  function value_form(&$form, &$form_state) {
-    $all_roles = user_titles_get_roles();
-    $selection = array_filter($this->options['rids']);
-    $roles = empty($selection) ? array_keys($all_roles) : $selection;
-    $role_names = '';
-    $rids = '';
-    $in = '';
-    $query_vars = array();
-    foreach ($roles as $rid) {
-      $role_names .= $role_names ? ', ' . $all_roles[$rid] : $all_roles[$rid];
-      $rids .= $rids ? ",$rid" : $rid;
-      $in .= $in ? ', %d' : '%d';
-      $query_vars[] = $rid;
-    }
-
-    if ($this->options['type'] == 'textfield') {
-      $default = '';
-      if ($this->value) {
-        if (is_array($this->value)) {
-          foreach ($this->value as $tid) {
-            $in .= $in ? ', %d' : '%d';
-          }
-          $result = db_query("SELECT * FROM {user_titles} ut WHERE ut.tid IN ($in)", $this->value);
-        }
-        else {
-          $result = db_query("SELECT * FROM {user_titles} ut WHERE ut.tid = %d", $this->value);
-        }
-
-        while ($title = db_fetch_object($result)) {
-          $default .= $default ? ", {$title->title}" : $title->title;
-        }
-      }
-
-      $form['value'] = array(
-        '#title' => !empty($selection) ? format_plural(count($selection), 'Select titles from role: @role_names', 'Select titles from roles: @role_names', array('@role_names' => $role_names)) : t('Select titles'),
-        '#type' => 'textfield',
-        '#default_value' => $default,
-      );
-
-      $form['value']['#autocomplete_path'] = 'user-titles/autocomplete/' . $rids;
-    }
-    else {
-      $options = array();
-      $result = db_query("SELECT * FROM {user_titles} WHERE rid IN ($in) ORDER BY value", $query_vars);
-      while ($title = db_fetch_object($result)) {
-        $options[$title->tid] = $title->title;
-      }
-
-      $default_value = (array) $this->value;
-
-      if (!empty($form_state['exposed'])) {
-        $identifier = $this->options['expose']['identifier'];
-
-        if (!empty($this->options['expose']['reduce'])) {
-          $options = $this->reduce_value_options($options);
-
-          if (empty($this->options['expose']['single']) && !empty($this->options['expose']['optional'])) {
-            $default_value = array();
-          }
-        }
-
-        if (!empty($this->options['expose']['single'])) {
-          if (!empty($this->options['expose']['optional']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) {
-            $default_value = 'All';
-          }
-          else if (empty($default_value)) {
-            $keys = array_keys($options);
-            $default_value = array_shift($keys);
-          }
-          else {
-            $copy = $default_value;
-            $default_value = array_shift($copy);
-          }
-        }
-      }
-      $form['value'] = array(
-        '#type' => 'select',
-        '#title' => !empty($selection) ? format_plural(count($selection), 'Select titles from role: @role_names', 'Select titles from roles: @role_names', array('@role_names' => $role_names)) : t('Select titles'),
-        '#multiple' => TRUE,
-        '#options' => $options,
-        '#size' => min(9, count($options)),
-        '#default_value' => $default_value,
-      );
-
-      if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
-        $form_state['input'][$identifier] = $default_value;
-      }
-    }
-
-    if (empty($form_state['exposed'])) {
-      // Retain the helper option
-      $this->helper->options_form($form, $form_state);
-    }
-  }
-
-  function value_validate(&$form, &$form_state) {
-    // We only validate if they've chosen the text field style.
-    if ($this->options['type'] != 'textfield') {
-      return;
-    }
-
-    $values = drupal_explode_tags($form_state['values']['options']['value']);
-    $tids = $this->validate_title_strings($form['value'], $values);
-
-    if ($tids) {
-      $form_state['values']['options']['value'] = $tids;
-    }
-  }
-
-  function accept_exposed_input($input) {
-    if (empty($this->options['exposed'])) {
-      return TRUE;
-    }
-
-    // If it's optional and there's no value don't bother filtering.
-    if ($this->options['expose']['optional'] && empty($this->validated_exposed_input)) {
-      return FALSE;
-    }
-
-    $rc = parent::accept_exposed_input($input);
-    if ($rc) {
-      // If we have previously validated input, override.
-      if (isset($this->validated_exposed_input)) {
-        $this->value = $this->validated_exposed_input;
-      }
-    }
-
-    return $rc;
-  }
-
-  function exposed_validate(&$form, &$form_state) {
-    if (empty($this->options['exposed'])) {
-      return;
-    }
-
-    $identifier = $this->options['expose']['identifier'];
-
-    // We only validate if they've chosen the text field style.
-    if ($this->options['type'] != 'textfield') {
-      if ($form_state['values'][$identifier] != 'All')  {
-        $this->validated_exposed_input = (array) $form_state['values'][$identifier];
-      }
-      return;
-    }
-
-    if (empty($this->options['expose']['identifier'])) {
-      return;
-    }
-
-    $values = drupal_explode_tags($form_state['values'][$identifier]);
-
-    $tids = $this->validate_title_strings($form[$identifier], $values);
-    if ($tids) {
-      $this->validated_exposed_input = $tids;
-    }
-  }
-
-  /**
-   * Validate the user string. Since this can come from either the form
-   * or the exposed filter, this is abstracted out a bit so it can
-   * handle the multiple input sources.
-   */
-  function validate_title_strings(&$form, $values) {
-    if (empty($values)) {
-      return array();
-    }
-
-    $tids = array();
-    $placeholders = array();
-    $query_args = array();
-    $results = array();
-    $title_in = '';
-    foreach ($values as $value) {
-      $missing[strtolower($value)] = TRUE;
-      $query_args[] = $value;
-      $title_in .= $title_in ? ", '%s'" : "'%s'";
-    }
-
-    if (!$query_args) {
-      return;
-    }
-
-    // add the taxonomy vid to the argument list.
-    $rid_in = '';
-    foreach ($this->options['rids'] as $rid => $value) {
-      if ($value) {
-        $query_args[] = $rid;
-        $rid_in .= $rid_in ? ", %d" : "%d";
-      }
-    }
-
-    if ($rid_in) {
-      $result = db_query("SELECT * FROM {user_titles} WHERE title IN ($title_in) AND rid IN ($rid_in)", $query_args);
-    }
-    else {
-      $result = db_query("SELECT * FROM {user_titles} WHERE title IN ($title_in)", $query_args);
-    }
-    while ($title = db_fetch_object($result)) {
-      unset($missing[strtolower($title->title)]);
-      $tids[] = $title->tid;
-    }
-
-    if ($missing) {
-      form_error($form, format_plural(count($missing), 'Unable to find title: @titles', 'Unable to find titles: @titles', array('@titles' => implode(', ', array_keys($missing)))));
-    }
-
-    return $tids;
-  }
-
-  function value_submit($form, &$form_state) {
-    // prevent array_filter from messing up our arrays in parent submit.
-  }
-
-  function expose_form_right(&$form, &$form_state) {
-    parent::expose_form_right($form, $form_state);
-    if ($this->options['type'] != 'select') {
-      unset($form['expose']['reduce']);
-    }
-  }
-
-  function admin_summary() {
-    // set up $this->value_options for the parent summary
-    $this->value_options = array();
-
-    if ($this->value) {
-      if (is_array($this->value)) {
-        foreach ($this->value as $tid) {
-          $in .= $in ? ', %d' : '%d';
-        }
-        $result = db_query("SELECT * FROM {user_titles} ut WHERE ut.tid IN ($in)", $this->value);
-      }
-      else {
-        $result = db_query("SELECT * FROM {user_titles} ut WHERE ut.tid = %d", $this->value);
-      }
-
-      while ($title = db_fetch_object($result)) {
-        $this->value_options[$title->tid] = $title->title;
-      }
-    }
-    return parent::admin_summary();
-  }
-}
diff -ruN user_titles/ut_views/views_handler_sort_user_title_image.inc user_titles.diff/ut_views/views_handler_sort_user_title_image.inc
--- user_titles/ut_views/views_handler_sort_user_title_image.inc	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/ut_views/views_handler_sort_user_title_image.inc	1969-12-31 19:00:00.000000000 -0500
@@ -1,55 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains the user title image sort handler.
- */
-
-/**
- * Sort handler for user title images.
- *
- * This handler enables the user to select from a couple of different sort options.
- *
- * @ingroup views_sort_handlers
- */
-class views_handler_sort_user_title_image extends views_handler_sort {
-  function option_definition() {
-    $options = parent::option_definition();
-
-    $options['sort_by'] = array('default' => 'has_image');
-
-    return $options;
-  }
-
-  function options_form(&$form, &$form_state) {
-    parent::options_form($form, $form_state);
-
-    $form['sort_by'] = array(
-      '#type' => 'radios',
-      '#title' => t('Sort by'),
-      '#options' => array(
-        'has_image' => t('Has image?'),
-        'file_path' => t('File path'),
-      ),
-      '#description' => t('How to sort. Either by whether or not there is a file or by the file name.'),
-      '#default_value' => $this->options['sort_by'],
-    );
-  }
-
-  /**
-   * Called to add the sort to a query.
-   */
-  function query() {
-    $this->ensure_my_table();
-    switch ($this->options['sort_by']) {
-      case 'has_image':
-      default:
-        $formula = "IF(CHAR_LENGTH($this->table_alias.$this->real_field) > 0, 1, 0)";
-        $this->query->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field . '_' . $this->options['sort_by']);
-        return;
-      case 'file_path':
-        $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
-        return;
-    }
-  }
-}
diff -ruN user_titles/ut_views/views_plugin_argument_validate_user_title.inc user_titles.diff/ut_views/views_plugin_argument_validate_user_title.inc
--- user_titles/ut_views/views_plugin_argument_validate_user_title.inc	2011-10-17 14:36:10.000000000 -0500
+++ user_titles.diff/ut_views/views_plugin_argument_validate_user_title.inc	1969-12-31 19:00:00.000000000 -0500
@@ -1,55 +0,0 @@
-<?php
-/**
- * @file
- * Contains the 'user title' argument validator plugin.
- */
-
-/**
- * Validate whether an argument is an acceptable node.
- */
-class views_plugin_argument_validate_user_title extends views_plugin_argument_validate {
-  function validate_form(&$form, &$form_state) {
-    $roles = user_titles_get_roles();
-    $options = array();
-    foreach ($roles as $rid => $role) {
-      $options[$rid] = check_plain($role);
-    }
-
-    $form['validate_argument_role'] = array(
-      '#type' => 'checkboxes',
-      '#prefix' => '<div id="edit-options-validate-argument-role-wrapper">',
-      '#suffix' => '</div>',
-      '#title' => t('Roles'),
-      '#options' => $options,
-      '#default_value' => isset($this->argument->options['validate_argument_role']) ? $this->argument->options['validate_argument_role'] : array(),
-      '#description' => t('If you wish to validate for specific roles, check them; if none are checked, all titles will pass.'),
-    );
-
-    $form['validate_argument_transform'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Transform dashes in URL to spaces in title arguments'),
-      '#default_value' => isset($this->argument->options['validate_argument_transform']) ? $this->argument->options['validate_argument_transform'] : FALSE,
-    );
-  }
-
-  function validate_argument($argument) {
-    $rids = isset($this->argument->options['validate_argument_role']) ? array_filter($this->argument->options['validate_argument_role']) : array();
-    $transform = isset($this->argument->options['validate_argument_transform']) ? $this->argument->options['validate_argument_transform'] : FALSE;
-
-    $and = '';
-    if (!empty($rids)) {
-      $and = " AND rid IN(" . implode(', ', $rids) . ')';
-    }
-    if ($transform) {
-      $result = db_fetch_object(db_query("SELECT * FROM {user_titles} WHERE replace(title, ' ', '-') = '%s'$and", $argument));
-    }
-    else {
-      $result = db_fetch_object(db_query("SELECT * FROM {user_titles} WHERE title = '%s'$and", $argument));
-    }
-    if (!$result) {
-      return FALSE;
-    }
-
-    return TRUE;
-  }
-}
