You are here

function privatemsg_realname_privatemsg_name_lookup in Privatemsg 6.2

Same name and namespace in other branches
  1. 7.2 privatemsg_realname/privatemsg_realname.module \privatemsg_realname_privatemsg_name_lookup()
  2. 7 privatemsg_realname/privatemsg_realname.module \privatemsg_realname_privatemsg_name_lookup()

Implements hook_privatemsg_name_lookup().

File

privatemsg_realname/privatemsg_realname.module, line 6

Code

function privatemsg_realname_privatemsg_name_lookup($string) {

  // First, check the unique version.
  if (preg_match('/\\[user:(.+)\\]/', $string, $match)) {
    $account = user_load(array(
      variable_get('privatemsg_realname_unique_identifier', 'name') => trim($match[1]),
    ));
    $account->type = 'user';
    $account->recipient = $account->uid;
    return array(
      $account,
    );
  }

  // Then try to look it up with the real name.
  $result = db_query("SELECT r.uid FROM {realname} r WHERE r.realname = '%s'", $string);
  $accounts = array();
  while ($row = db_fetch_object($result)) {
    if ($account = user_load($row->uid)) {
      $account->type = 'user';
      $account->recipient = $account->uid;
      $accounts[] = $account;
    }
  }
  return $accounts;
}