@ -58,14 +58,14 @@ else {
$book_types = (array) $RCMAIL->config->get('autocomplete_addressbooks', 'sql');
$book_types = (array) $RCMAIL->config->get('autocomplete_addressbooks', 'sql');
}
}
$contacts = array();
if (!empty($book_types) & & strlen($search)) {
if (!empty($book_types) & & strlen($search)) {
$contacts = array();
$sort_keys = array();
$sort_keys = array();
$books_num = count($book_types);
$books_num = count($book_types);
$search_lc = mb_strtolower($search);
$search_lc = mb_strtolower($search);
foreach ($book_types as $id) {
foreach ($book_types as $abook_ id) {
$abook = $RCMAIL->get_address_book($id);
$abook = $RCMAIL->get_address_book($abook_ id);
$abook->set_pagesize($MAXNUM);
$abook->set_pagesize($MAXNUM);
if ($result = $abook->search($RCMAIL->config->get('contactlist_fields'), $search, $mode, true, true, 'email')) {
if ($result = $abook->search($RCMAIL->config->get('contactlist_fields'), $search, $mode, true, true, 'email')) {
@ -92,7 +92,12 @@ if (!empty($book_types) && strlen($search)) {
// skip duplicates
// skip duplicates
if (empty($contacts[$index])) {
if (empty($contacts[$index])) {
$contact = array('name' => $contact, 'type' => $sql_arr['_type']);
$contact = array(
'name' => $contact,
'type' => $sql_arr['_type'],
'id' => $sql_arr['contact_id'],
'source' => $abook_id,
);
if (($display = rcube_addressbook::compose_search_name($sql_arr, $email, $name)) & & $display != $contact['name']) {
if (($display = rcube_addressbook::compose_search_name($sql_arr, $email, $name)) & & $display != $contact['name']) {
$contact['display'] = $display;
$contact['display'] = $display;
@ -135,7 +140,7 @@ if (!empty($book_types) && strlen($search)) {
'email' => $email,
'email' => $email,
'type' => 'group',
'type' => 'group',
'id' => $group['ID'],
'id' => $group['ID'],
'source' => $id,
'source' => $abook_ id,
);
);
if (count($contacts) >= $MAXNUM) {
if (count($contacts) >= $MAXNUM) {
@ -152,7 +157,7 @@ if (!empty($book_types) && strlen($search)) {
'name' => $group['name'] . ' (' . intval($result->count) . ')',
'name' => $group['name'] . ' (' . intval($result->count) . ')',
'type' => 'group',
'type' => 'group',
'id' => $group['ID'],
'id' => $group['ID'],
'source' => $id
'source' => $abook_ id,
);
);
if (count($contacts) >= $MAXNUM) {
if (count($contacts) >= $MAXNUM) {
@ -175,5 +180,14 @@ if (!empty($book_types) && strlen($search)) {
}
}
}
}
// Allow autocomplete result optimization via plugin
$pluginResult = $RCMAIL->plugins->exec_hook('contacts_autocomplete_after', array(
'search' => $search,
'contacts' => $contacts, // Provide already-found contacts to plugin if they are required
));
$contacts = $pluginResult['contacts'];
$OUTPUT->command('ksearch_query_results', $contacts, $search, $reqid);
$OUTPUT->command('ksearch_query_results', $contacts, $search, $reqid);
$OUTPUT->send();
$OUTPUT->send();