You are here

function realname_ajax_autocomplete_user in Real Name 6

Page callback for user autocomplete.

1 string reference to 'realname_ajax_autocomplete_user'
realname_menu in ./realname.module
Implements hook_menu().

File

./realname.module, line 954

Code

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} 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);
}