You are here

function realname_privatemsg_autocomplete in Real Name 5

Same name and namespace in other branches
  1. 6 realname.module \realname_privatemsg_autocomplete()

Intercept Privatemsg autocomplete results for usernames.

1 string reference to 'realname_privatemsg_autocomplete'
realname_menu in ./realname.module
Implementation of hook_menu().

File

./realname.module, line 271
The RealName module allows the admin to choose fields from the user profile that will be used to add a "realname" element (method) to a user object. Hook_user is used to automatically add this to any user object that is loaded.

Code

function realname_privatemsg_autocomplete($string) {
  $names = explode(',', $string);

  //  for ($i = 0; $i < count($names); $i++) {
  //    $names[$i] = trim($names[$i]);
  //  }
  $names = array_map('trim', $names);
  $search = array_pop($names);
  if ($search != '') {
    $sql = "SELECT uid, name FROM {users} u WHERE status <> 0 AND LOWER(name) LIKE LOWER('%s%%') AND ";
    $sql .= variable_get('privatemsg_default_allow', 1) ? '(data NOT LIKE \'%%:16:"privatemsg_allow";i:0%%\' OR data IS NULL)' : 'data LIKE \'%%:16:"privatemsg_allow";i:1%%\'';
    $sql .= ' ORDER BY name ASC';
    $result = db_query_range($sql, $search, 0, 10);
    $prefix = count($names) ? implode(', ', $names) . ', ' : '';
    $matches = array();
    while ($user = db_fetch_object($result)) {
      $account = user_load(array(
        'uid' => $user->uid,
      ));
      $matches[$prefix . $user->name] = realname_make_name($account);
    }
    print drupal_to_js($matches);
    exit;
  }
}