function views_ajax_autocomplete_user
3.x ajax.inc | views_ajax_autocomplete_user($string = '') |
2.x ajax.inc | views_ajax_autocomplete_user($string = '') |
Page callback for views user autocomplete
Related topics
1 string reference to 'views_ajax_autocomplete_user'
- views_menu in ./
views.module - Implementation of hook_menu().
File
Code
function views_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 name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $last_string, 0, 10);
while ($account = db_fetch_object($result)) {
$n = $account->name;
// Commas and quotes in terms are special cases, so encode 'em.
if (strpos($account->name, ',') !== FALSE || strpos($account->name, '"') !== FALSE) {
$n = '"' . str_replace('"', '""', $account->name) . '"';
}
$matches[$prefix . $n] = check_plain($account->name);
}
}
drupal_json($matches);
}