You are here

function privatemsg_realname_privatemsg_name_lookup in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg_realname/privatemsg_realname.module \privatemsg_realname_privatemsg_name_lookup()
  2. 7.2 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_multiple(array(), array(
      variable_get('privatemsg_realname_unique_identifier', 'name') => trim($match[1]),
    ));
    $account = reset($account);
    if ($account && $account->uid) {
      $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 = :realname', array(
    ':realname' => $string,
  ));
  $accounts = array();
  foreach ($result as $row) {
    if ($account = user_load($row->uid)) {
      $account->type = 'user';
      $account->recipient = $account->uid;
      $accounts[] = $account;
    }
  }
  return $accounts;
}