=== modified file 'realname.admin.inc'
--- realname.admin.inc	2009-03-08 09:22:40 +0000
+++ realname.admin.inc	2009-03-08 09:23:15 +0000
@@ -19,6 +19,11 @@
 }
 
 function realname_admin_general() {
+  // Show rebuild warning
+  if (variable_get('realname_recalculate', FALSE)) {
+    drupal_set_message(t('In order to apply new settings you need to <a href="!rebuild">rebuild</a> your realnames', array('!rebuild' => url('admin/user/realname/recalc'))), 'warning');
+  }
+  
   $form = array();
 
   $form['realname_nodeapi'] = array(
@@ -28,6 +33,15 @@
     '#default_value' => variable_get('realname_nodeapi', FALSE),
     );
 
+  if ( module_exists('views') ) {  
+    $form['realname_view'] = array(
+      '#type' => 'checkbox',
+      '#title' => '<strong>'. t('Overwrite user fields in view to show realnames') .'</strong>',
+      '#description' => t('This option will overwrite default user name definition in Views in order to show realnames without the need to modify views. Remember to rebuild view cache after changing this option.'),
+      '#default_value' => variable_get('realname_view', FALSE),
+      );
+  }  
+  
   $form['theme'] = array(
     '#type' => 'fieldset',
     '#title' => t('Theme_username options'),
@@ -62,6 +76,10 @@
 }
 
 function realname_admin_bypass() {
+  // Show rebuild warning
+  if (variable_get('realname_recalculate', FALSE)) {
+    drupal_set_message(t('In order to apply new settings you need to <a href="!rebuild">rebuild</a> your realnames', array('!rebuild' => url('admin/user/realname/recalc'))), 'warning');
+  }
   $form = array();
 
   $current = variable_get('realname_bypass_forms', array(array('name' => 'comment_form', 'fields' => array('name'))));
@@ -106,10 +124,18 @@
     }
   }
   variable_set('realname_bypass_forms', $bypass_forms);
+  // mark form for realname recalculation
+  variable_set('realname_recalculate', TRUE);
+  
   drupal_set_message(t('Information saved for !count forms.', array('!count' => count($bypass_forms))), 'status');
 }
 
 function realname_admin_module($form_state) {
+  // Show rebuild warning
+  if (variable_get('realname_recalculate', FALSE)) {
+    drupal_set_message(t('In order to apply new settings you need to <a href="!rebuild">rebuild</a> your realnames', array('!rebuild' => url('admin/user/realname/recalc'))), 'warning');
+  }
+  
   $form = array();
   // Get the list of modules we support.
   include_once(drupal_get_path('module', 'realname') .'/realname_supported.inc');
@@ -183,6 +209,10 @@
       }
     }
   }
+  
+  // mark form for realname recalculation
+  variable_set('realname_recalculate', TRUE);
+  
   // We are done with types, so go pick fields.
   unset($form_state['storage']);
   $form_state['redirect'] = 'admin/user/realname/fields'; // Go get the fields now.
@@ -190,6 +220,11 @@
 }
 
 function realname_admin_fields() {
+  // Show rebuild warning
+  if (variable_get('realname_recalculate', FALSE)) {
+    drupal_set_message(t('In order to apply new settings you need to <a href="!rebuild">rebuild</a> your realnames', array('!rebuild' => url('admin/user/realname/recalc'))), 'warning');
+  }
+  
   $form = array();
   $current = variable_get('realname_fields', array());
   $module = variable_get('realname_profile_module', NULL);
@@ -325,6 +360,36 @@
   variable_set('realname_pattern', $form_state['values']['realname_pattern']);
   variable_set('realname_homepage', $form_state['values']['realname_homepage']);
   variable_set('realname_nofollow', $form_state['values']['realname_nofollow']);
-
+  
+  // mark realnames for recalculation
+  variable_set('realname_recalculate', TRUE);
+  
   drupal_set_message(t('Configuration has been updated.'), 'status');
 }
+
+/**
+ * Real names rebuild (in case of config change) handlers
+ */
+ 
+/**
+ * Menu callback: confirm rebuilding of realnames.
+ */
+function realname_rebuild_confirm() {
+  return confirm_form(array(), t('Are you sure you want to rebuild the realnames for all site users?'),
+                  'admin/user/realname', t('This action rebuilds realnames for all users , and may be a lengthy process. This action cannot be undone.'), t('Rebuild realnames'), t('Cancel'));
+}
+
+/**
+ * Handler for rebuild confirmation
+ */
+function realname_rebuild_confirm_submit($form, &$form_state) {
+  $batch = array(
+    'title' => t('Rebuilding realnames'),
+    'operations' => array(
+      array('_realname_rebuild_realnames', array()),
+    ),
+    'finished' => '_realname_rebuild_batch_finished'
+  );
+  batch_set($batch);
+}
+

=== modified file 'realname.install'
--- realname.install	2009-03-08 09:22:40 +0000
+++ realname.install	2009-03-08 09:23:15 +0000
@@ -11,6 +11,30 @@
 //********************************************************************
 //* Drupal Hooks
 //********************************************************************
+/**
+ * Implementation of hook_schema().
+ */
+function realname_schema() {
+  $schema['realname_calculated_realname'] = array(
+    'fields' => array(
+         'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+         'realname' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE),
+        ),
+    'primary key' => array('uid'),
+    'indexes' => array(
+         'realname' => array('realname')
+        ),
+  );
+  return $schema;
+}
+
+/**
+ * Implementation of hook_install().
+ */
+function realname_install() {
+  drupal_install_schema('realname');
+}
+
 
 /**
  * Implementation of hook_enable().
@@ -34,6 +58,8 @@
   variable_del('realname_profile_module');
   variable_del('realname_profile_type');
   variable_del('realname_theme');
+  
+  drupal_uninstall_schema('realname');
 }
 
 /**
@@ -71,3 +97,40 @@
 
   return $ret;
 }
+
+/**
+ * Implementation of hook_update_N().
+ */
+function realname_update_6102() {
+  $ret = array();
+  $table = array(
+    'fields' => array(
+         'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+         'realname' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE),
+        ),
+    'primary key' => array('uid'),        
+    'indexes' => array(
+         'realname' => array('realname')
+        ),
+  );
+  // 1. Create new table
+  db_create_table($ret, 'realname_calculated_realname', $table);
+  // 2. Populate table using current settings
+  // @TODO: User processing can take quite long. We probably need to use BATCH API
+  $module = variable_get('realname_profile_module' , null);
+  if ($module) {
+    include_once(drupal_get_path('module', 'realname') .'/realname.module');
+    $query = "SELECT u.uid, u.name, u.mail FROM {users} u";
+    $result = db_query($query);
+    while ($row = db_fetch_object($result)) {
+      $realname = _realname_make_name($row);
+      db_query("INSERT INTO {realname_calculated_realname} (uid, realname) VALUES(%d, '%s')", $row->uid, $realname);
+    }
+    $ret[] = array('success' => TRUE, 'query' => t('Realnames has been recalculated'));
+  }
+  else {
+    drupal_set_message(t('Realname module has been updated. In order to start using it you have to select profile module to be used'), 'warning');
+  }
+  
+  return $ret;
+}

=== modified file 'realname.module'
--- realname.module	2009-03-08 09:22:40 +0000
+++ realname.module	2009-03-08 09:23:15 +0000
@@ -18,7 +18,12 @@
 //********************************************************************
 //* Drupal Hooks
 //********************************************************************/
-
+/**
+ * Views API implementation
+ */
+function realname_views_api() {
+  return array('api' => 2.0);
+}
 /**
  * Implementation of hook_help().
  */
@@ -38,16 +43,16 @@
  * Implementation of hook_theme().
  */
 function realname_theme() {
-  return array(
-    'realname_admin_levels' => array(
-      'arguments' => array('form' => NULL),
-      'file' => 'realname.admin.inc',
-      ),
-    'realname_new_role' => array(
-      'arguments' => array('form' => NULL),
-      'file' => 'realname_theme.inc',
-      ),
-    );
+ return array(
+   'realname_admin_levels' => array(
+     'arguments' => array('form' => NULL),
+     'file' => 'realname.admin.inc',
+     ),
+   'realname_new_role' => array(
+     'arguments' => array('form' => NULL),
+     'file' => 'realname_theme.inc',
+     ),
+   );
 }
 
 /**
@@ -69,8 +74,8 @@
     'description' => "Configure which fields are used to create a user's RealName.",
     'access arguments' => array('administer users'),
     'page callback' => 'realname_admin_settings',
+    'file' => 'realname.admin.inc',
     'type' => MENU_NORMAL_ITEM,
-    'file' => 'realname.admin.inc',
     );
 
   $items['admin/user/realname/fields'] = array(
@@ -112,6 +117,25 @@
     'file' => 'realname.admin.inc',
     'weight' => 6,
     );
+    
+  $items['admin/user/realname/recalc'] = array(
+    'title' => 'Recalculate names',
+    'access arguments' => array('administer users'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('realname_rebuild_confirm'),
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'realname.admin.inc',
+    'weight' => 8,
+    );
+
+  // Path is not admin/build/views due to menu complications with the wildcards from
+  // the generic ajax callback.
+  $items['admin/user/realname/ajax/autocomplete/user'] = array(
+    'page callback' => 'realname_ajax_autocomplete_user',
+    'access callback' => 'user_access',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    );
 
   return $items;
 }
@@ -237,17 +261,16 @@
     $theme_registry['user_admin_new_role']['file'] = $path .'/realname_theme.inc';
     $theme_registry['user_admin_new_role']['theme path'] = $path;
     $theme_registry['user_admin_new_role']['theme paths'][0] = $path;
-
     $theme_registry['user_picture']['theme path'] = $path;
     $theme_registry['user_picture']['theme paths'][0] = $path;
     foreach ($theme_registry['user_picture']['preprocess functions'] as $key => $value) {
       if ($value == 'template_preprocess_user_picture') {
         $theme_registry['user_picture']['preprocess functions'][$key] = 'template_preprocess_user_picture_realname';
       }
-    }    
+    }
   }
 }
-
+ 	 
 /**
  * Process variables for user-picture.tpl.php (copied from user.module).
  */
@@ -261,7 +284,7 @@
     elseif (variable_get('user_picture_default', '')) {
       $picture = variable_get('user_picture_default', '');
     }
-
+	 	 
     if (isset($picture)) {
       $account->name = isset($account->realname) ? $account->realname : realname_make_name($account);
       $name = $account->name ? $account->name : variable_get('anonymous', t('Anonymous'));
@@ -271,7 +294,7 @@
         $attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
         $variables['picture'] = l($variables['picture'], "user/$account->uid", $attributes);
       }
-    }
+    }    
   }
 }
 
@@ -279,16 +302,29 @@
  * Implementation of hook_user().
  */
 function realname_user($op, &$edit, &$account, $category = NULL) {
-  if ($op == 'load') {
-    $account->realname = realname_make_name($account);
+  switch ($op) {
+    case 'load':
+      $account->realname = realname_make_name($account);
 
-    // If theme then replace name with realname.
-    if (variable_get('realname_theme', TRUE) && $account->realname) {
-      //Store it for places where it needed
-      if (!isset($account->realname_save) && is_object($account)) {
-        $account->realname_save = $account->name;
-      }
-    }
+      // If theme then replace name with realname.
+      if (variable_get('realname_theme', TRUE) && $account->realname) {
+        //Store it for places where it needed
+        if (!isset($account->realname_save) && is_object($account)) {
+          $account->realname_save = $account->name;
+        }
+      }
+      break;
+    case 'delete':
+      db_query("DELETE FROM {realname_calculated_realname} WHERE uid=%d", $account->uid);
+      break;
+    case 'insert':
+    case 'after_update':
+      $realname->uid = $account->uid;
+      $realname->realname = _realname_make_name($account);
+      // try to update, if fail - try to insert
+      if (!drupal_write_record('realname_calculated_realname', $realname, 'uid')) {
+        drupal_write_record('realname_calculated_realname', $realname);
+      }
   }
 }
 
@@ -302,6 +338,23 @@
     return;
   }
 
+  // NickSI: Yes, we will have another switch later but I would like to separate table update with other processing
+  if ( variable_get('realname_profile_module', NULL) == 'content_profile'  &&
+       is_content_profile($node->type)) { // do realnames table update if content_profile has been changed
+    switch ($op) {
+      case 'update':
+      case 'insert':
+      case 'delete':
+        $realname->uid = $account->uid;
+        $realname->realname = _realname_make_name($account);
+        // try to update, if fail - try to insert
+        if (!drupal_write_record('realname_calculated_realname', $realname,  'uid')) {
+          drupal_write_record('realname_calculated_realname', $realname);
+        }           
+    }
+  }
+  
+  
   if (!variable_get('realname_nodeapi', FALSE)) {
     return;
   }
@@ -359,7 +412,6 @@
         else {
           $users[$comment->uid] = $account = realname_get_user($comment->uid);
         }
-        
         $comment->homepage = isset($account->homepage) ? $account->homepage : NULL;
       }
       break;
@@ -390,7 +442,6 @@
   if (!user_access('use realname')) {
     return;
   }
-//  drupal_set_message($form_id);
 
   $bypass_forms = variable_get('realname_bypass_forms', array(array('name' => 'comment_form', 'fields' => array('name'))));
   foreach ($bypass_forms as $bypass) {
@@ -434,17 +485,17 @@
         '#default_value' => $pic,
         '#title' => t('User level image'),
         '#description' => t('This image will be shown when the user name is themed.
-          It can be used to show special attributes or user participation level.'),
+             It can be used to show special attributes or user participation level.'),
         '#field_suffix' => empty($pic) ? '' : '&nbsp;&nbsp;<img src="'. file_create_url($pic) .'" />',
         );
-
+   
       $form['submit']['#weight'] = 98;
       $form['delete']['#weight'] = 99;
       $form['#submit'][] = '_realname_role_submit';
       break;
 
 //    case 'user_admin_new_role':  // See http://drupal.org/node/392156
-//      drupal_set_message(show_array($form));
+//      drupal_set_message(show_array($form)); 
   }
 }
 
@@ -454,38 +505,62 @@
 function _realname_role_submit($form, &$form_state) {
   $rid = $form_state['values']['rid'];
   $pic = $form_state['values']['level'];
-// variable_set('realname_user_level_'. $rid, $pic);  
-  drupal_set_message("realname_user_level_$rid => '$pic'");  
+  variable_set('realname_user_level_'. $rid, $pic);
+  drupal_set_message("realname_user_level_$rid => '$pic'");
 }
 
 //********************************************************************
 //* Module Functions
 //********************************************************************
-
 /**
- * Using selected fields, build the "real name" field in the object.
+ * Retreive calculated user name. Try static cache first, DB next and on failure call
+ * helper function to calculate realname and populate DB
  *
  * @param
  *   $account - the user object to update.
  *
  * @return
- *   The constructed "real name" string.
- */
+ *   The retreived "real name" string. 
+ */ 
 function realname_make_name(&$account) {
-  static $fields, $pattern_saved, $homepage, $use_theme, $type, $module, $profile_privacy;
   static $users = array();
-  static $links = array();
-  static $edit = array();
-
   // Return anonymous user right away.
   if ($account->uid == 0) {
     return $account->name;
   }
-
+  
+  // Check static cache first  
   if (isset($users[$account->uid])) {
     $account->homepage = isset($links[$account->uid]) ? $links[$account->uid] : NULL;
     return $users[$account->uid];
   }
+  // Check DB next
+  $query = "SELECT realname from {realname_calculated_realname} WHERE uid=%d";
+  $result = db_result(db_query($query, $account->uid));
+  
+  if ($result) { // we've succeed
+    return $result;
+  }
+  
+  $result = _realname_make_name($account);
+  db_query("INSERT INTO {realname_calculated_realname} (uid, realname) VALUES(%d, '%s')", $account->uid, $result);
+  return $result;
+}
+
+/**
+ * Helper function for realname_make_name. Using selected fields, build the "real name" field in the object.
+ *
+ * @param
+ *   $account - the user object to update.
+ *
+ * @return
+ *   The constructed "real name" string.
+ */
+function _realname_make_name(&$account) {
+  static $fields, $pattern_saved, $homepage, $use_theme, $type, $module, $profile_privacy;
+  static $users = array();
+  static $links = array();
+  static $edit = array();
 
   // Get our controlling variables (static makes it once per page load).
   if (!isset($fields)) {
@@ -587,3 +662,76 @@
 
   return $ret;
 }
+
+/**
+* Page callback for user autocomplete
+*/
+function realname_ajax_autocomplete_user($string = '') {
+  // The user enters a comma-separated list of tags. We only autocomplete the last tag.
+  $array = drupal_explode_tags($string);
+
+  // Fetch last tag
+  $last_string = trim(array_pop($array));
+  $matches = array();
+  if ($last_string != '') {
+    $prefix = count($array) ? implode(', ', $array) . ', ' : '';
+
+    if (strpos('anonymous', strtolower($last_string)) !== FALSE) {
+      $matches[$prefix . 'Anonymous'] = 'Anonymous';
+    }
+    $result = db_query_range("SELECT realname FROM {realname_calculated_realname} WHERE LOWER(realname) LIKE LOWER('%s%%')", $last_string, 0, 10);
+
+    while ($account = db_fetch_object($result)) {
+      $n = $account->realname;
+      // Commas and quotes in terms are special cases, so encode 'em.
+      if (strpos($account->realname, ',') !== FALSE || strpos($account->realname, '"') !== FALSE) {
+        $n = '"' . str_replace('"', '""', $account->realname) . '"';
+      }
+      $matches[$prefix . $n] = check_plain($account->realname);
+    }
+  }
+
+  drupal_json($matches);
+}
+
+/**
+ * Batchable function used to rebuild realnames
+ * Batch API does not for some reason pick'em up in realname.admin.inc
+ */
+function _realname_rebuild_realnames(&$context) {
+  if (empty($context['sandbox'])) {
+    // Initiate multistep processing.
+    $context['sandbox']['progress'] = 0;
+    $context['sandbox']['current_user'] = 0;
+    $context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT uid) FROM {users}'));
+  }
+  // Process the next 20 users.
+  $limit = 20;
+  $result = db_query_range("SELECT u.uid, u.name, u.mail FROM {users} u WHERE uid >= %d ORDER BY uid ASC", $context['sandbox']['current_user'], 0, $limit);
+  while ($row = db_fetch_object($result)) {
+    $realname->uid = $row->uid;
+    $realname->realname = _realname_make_name($row);
+    // try to update, if fail - try to insert
+    if (!drupal_write_record('realname_calculated_realname', $realname,  'uid')) {
+      drupal_write_record('realname_calculated_realname', $realname);
+    }      
+    $context['sandbox']['progress']++;
+    $context['sandbox']['current_user'] = $row->uid;
+  }
+
+  // Multistep processing : report progress.
+  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
+    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
+  }
+}
+
+function _realname_rebuild_batch_finished($success, $results, $operations) {
+  if ($success) {
+    drupal_set_message(t('The realnames have been rebuilt.'));
+    variable_set('realname_recalculate', FALSE);
+    drupal_goto('admin/user/realname');
+  }
+  else {
+    drupal_set_message(t('The realanmes have not been properly rebuilt.'), 'error');
+  }
+}

=== added file 'realname.views.inc'
--- realname.views.inc	1970-01-01 00:00:00 +0000
+++ realname.views.inc	2009-03-08 09:23:15 +0000
@@ -0,0 +1,98 @@
+<?php
+// $Id: realname.views.inc,v 1.1.2.2 2008/11/03 20:10:34 nancyw Exp $
+/**
+ * @file
+ * Realname VIEW declarations.
+ */
+
+function realname_views_data_alter(&$data) {
+  if (variable_get('realname_view', FALSE)) {
+    // override username handling in order to use realname theme
+    $data['users']['name']['field']['handler'] = 'realname_handler_field_user_name_override';
+    $data['users']['uid']['filter']['handler'] = 'realname_handler_filter_user_name';
+    $data['users']['uid']['argument']['handler'] = 'realname_handler_argument_user_uid';
+  }
+}
+
+function realname_views_data() {
+  $tables['realname_calculated_realname'] =  array(
+    'table' => array(
+      'group' => t('Realname'),
+      'join' => array(
+        'users' => array (
+          'field' => 'uid',
+          'left_field' => 'uid'
+          )
+        ),
+      ),
+    'uid' => array(
+      'title' => t('Uid'),
+      'help' => t('The user ID'), // The help that appears on the UI,
+      'argument' => array(
+        'handler' => 'realname_handler_argument_user_uid',
+        ),
+      'filter' => array(
+        'title' => t('User Realname'),
+        'handler' => 'realname_handler_filter_user_name',
+        ),
+      'sort' => array(
+        'handler' => 'views_handler_sort',
+        ),
+      ),
+    'realname' => array(
+      'title' => t('Name'), // The item it appears as on the UI,
+      'help' => t('The user or author name.'), // The help that appears on the UI,
+      'field' => array(
+        'handler' => 'realname_handler_field_user_name',
+        'click sortable' => TRUE,
+        ),
+      'sort' => array(
+        'handler' => 'views_handler_sort',
+        ),
+      'argument' => array(
+        'handler' => 'views_handler_argument_string',
+        ),
+      ),
+  );
+
+  return $tables;
+}
+
+/**
+ * Implementation of hook_views_plugins
+ */
+function realname_views_plugins() {
+  return array(
+    'argument validator' => array(
+      'user_realname' => array(
+        'title' => t('User (realname)'),
+        'handler' => 'realname_plugin_argument_validate_user',
+        'parent' => 'user',
+      ),
+    ),
+  );
+}
+
+/**
+ * Define all realname views handlers
+ *
+ **/
+function realname_views_handlers() {
+  return array(
+    'info' => array(),
+    'handlers' => array(
+      'realname_handler_field_user_name' => array(
+        'parent' => 'views_handler_field_user_name',
+      ),
+      'realname_handler_argument_user_uid' => array(
+        'parent' => 'views_handler_argument_user_uid',
+      ),
+      'realname_handler_filter_user_name' => array(
+        'parent' => 'views_handler_filter_user_name',
+      ),
+      'realname_handler_field_user_name_override' => array(
+        'parent' => 'views_handler_field_user_name',
+      ),
+    )
+  );
+}
\ No newline at end of file

=== added file 'realname_handler_argument_user_uid.inc'
--- realname_handler_argument_user_uid.inc	1970-01-01 00:00:00 +0000
+++ realname_handler_argument_user_uid.inc	2009-03-08 09:23:15 +0000
@@ -0,0 +1,25 @@
+<?php
+// $Id:
+
+/**
+ * Argument handler for realnames
+ */
+class realname_handler_argument_user_uid extends views_handler_argument_user_uid {
+  /**
+   * Override the behavior of title(). Get the realname of the user.
+   */
+  function title_query() {
+    if (!$this->argument) {
+      return array(variable_get('anonymous', t('Anonymous')));
+    }
+    
+    $titles = array();
+    $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
+
+    $result = db_query("SELECT ru.realname FROM {users} u LEFT JOIN {realname_calculated_realname} ru ON u.uid = ru.uid WHERE u.uid IN ($placeholders)", $this->value);
+    while ($term = db_fetch_object($result)) {
+      $titles[] = check_plain($term->realname);
+    }
+    return $titles;
+  }
+}
\ No newline at end of file

=== added file 'realname_handler_field_user_name.inc'
--- realname_handler_field_user_name.inc	1970-01-01 00:00:00 +0000
+++ realname_handler_field_user_name.inc	2009-03-08 09:23:15 +0000
@@ -0,0 +1,30 @@
+<?php
+// $Id:
+
+/**
+ * Field handler for realnames
+ */
+class realname_handler_field_user_name extends views_handler_field_user_name {
+  function init(&$view, &$data) {
+    parent::init($view, $data);
+    $this->additional_fields['realname'] = 'realname';
+  }
+  
+  function render_link($data, $values) {
+    if (!empty($this->options['link_to_user']) || !empty($this->options['overwrite_anonymous'])) {
+      $account = new stdClass();
+      $account->uid = $values->{$this->aliases['uid']};
+      if (!empty($this->options['overwrite_anonymous']) && !$account->uid) {
+        // This is an anonymous user, and we're overriting the text.
+        return check_plain($this->options['anonymous_text']);
+      }
+      elseif (!empty($this->options['link_to_user'])) {
+        $account->name = $values->{$this->field_alias};
+        return theme('username', $account);
+      }
+    }
+    // Otherwise, there's no special handling, so return the data directly.
+    return $values->{$this->aliases['realname']};
+  }
+
+}
\ No newline at end of file

=== added file 'realname_handler_field_user_name_override.inc'
--- realname_handler_field_user_name_override.inc	1970-01-01 00:00:00 +0000
+++ realname_handler_field_user_name_override.inc	2009-03-08 09:23:15 +0000
@@ -0,0 +1,31 @@
+<?php
+// $Id:
+
+/**
+ * Field handler for realnames
+ */
+class realname_handler_field_user_name_override extends views_handler_field_user_name {
+  function init(&$view, &$data) {
+    parent::init($view, $data);
+    $this->additional_fields['uid'] = 'uid';
+  }
+  
+  function render_link($data, $values) {
+    $account = new stdClass();
+    $account->uid = $values->{$this->aliases['uid']};
+    $account->name = $values->{$this->field_alias};
+    
+    if (!empty($this->options['link_to_user']) || !empty($this->options['overwrite_anonymous'])) {
+      if (!empty($this->options['overwrite_anonymous']) && !$account->uid) {
+        // This is an anonymous user, and we're overriting the text.
+        return check_plain($this->options['anonymous_text']);
+      }
+      elseif (!empty($this->options['link_to_user'])) {
+        return theme('username', $account);
+      }
+    }
+    // Otherwise, there's no special handling, so return the data directly.
+    return realname_make_name($account);
+  }
+
+}
\ No newline at end of file

=== added file 'realname_handler_filter_user_name.inc'
--- realname_handler_filter_user_name.inc	1970-01-01 00:00:00 +0000
+++ realname_handler_filter_user_name.inc	2009-03-08 09:23:15 +0000
@@ -0,0 +1,96 @@
+<?php
+// $Id:
+
+/**
+ * Filter handler for usernames
+ */
+class realname_handler_filter_user_name extends views_handler_filter_user_name {
+  var $no_single = TRUE;
+
+  function value_form(&$form, &$form_state) {
+    $values = array();
+    if ($this->value) {
+      $result = db_query("SELECT u.*, ru.realname FROM {users} u LEFT JOIN {realname_calculated_realname} ru ON ru.uid=u.uid WHERE u.uid IN ("  . implode(', ', $this->value) . ")");
+      while ($account = db_fetch_object($result)) {
+        if ($account->uid) {
+          $values[] = $account->realname;
+        }
+        else {
+          $values[] = 'Anonymous'; // Intentionally NOT translated.
+        }
+      }
+    }
+
+    sort($values);
+    $default_value = implode(', ', $values);
+    $form['value'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Realnames'),
+      '#description' => t('Enter a comma separated list of user real names.'),
+      '#default_value' => $default_value,
+      '#autocomplete_path' => 'admin/user/realname/ajax/autocomplete/user',
+    );
+
+    if (!empty($form_state['exposed']) && !isset($form_state['input'][$this->options['expose']['identifier']])) {
+      $form_state['input'][$this->options['expose']['identifier']] = $default_value;
+    }
+  }
+
+  /**
+   * 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_user_strings(&$form, $values) {
+    $uids = array();
+    $placeholders = array();
+    $args = array();
+    $results = array();
+    foreach ($values as $value) {
+      if (strtolower($value) == 'anonymous') {
+        $uids[] = 0;
+      }
+      else {
+        $missing[strtolower($value)] = TRUE;
+        $args[] = $value;
+        $placeholders[] = "'%s'";
+      }
+    }
+
+    if (!$args) {
+      return $uids;
+    }
+
+    $result = db_query("SELECT u.*, ru.realname FROM {users} u LEFT JOIN {realname_calculated_realname} ru ON ru.uid=u.uid WHERE ru.realname IN (" . implode(', ', $placeholders) . ")", $args);
+    while ($account = db_fetch_object($result)) {
+      unset($missing[strtolower($account->realname)]);
+      $uids[] = $account->uid;
+    }
+
+    if ($missing) {
+      form_error($form, format_plural(count($missing), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', array_keys($missing)))));
+    }
+
+    return $uids;
+  }
+
+  function admin_summary() {
+    // set up $this->value_options for the parent summary
+    $this->value_options = array();
+
+    if ($this->value) {
+      $result = db_query("SELECT u.*, ru.realname FROM {users} u LEFT JOIN {realname_calculated_realname} ru ON ru.uid=u.uid WHERE u.uid IN ("  . implode(', ', $this->value) . ")");
+
+      while ($account = db_fetch_object($result)) {
+        if ($account->uid) {
+          $this->value_options[$account->uid] = $account->realname;
+        }
+        else {
+          $this->value_options[$account->uid] = 'Anonymous'; // Intentionally NOT translated.
+        }
+      }
+    }
+
+    return parent::admin_summary();
+  }
+}

=== added file 'realname_plugin_argument_validate_user.inc'
--- realname_plugin_argument_validate_user.inc	1970-01-01 00:00:00 +0000
+++ realname_plugin_argument_validate_user.inc	2009-03-08 09:23:15 +0000
@@ -0,0 +1,16 @@
+<?php
+// $Id: realname_plugin_argument_validate_user.inc
+
+/**
+ * Override of style plugin. Replaces username with realname
+ *
+ */
+class realname_plugin_argument_validate_user extends views_plugin_argument_validate_user {
+  
+  function validate_argument($argument) {
+    $result = parent::validate_argument($argument);
+    $this->argument->validated_title = realname_make_name($account);
+    return TRUE;
+  }
+}
+

