Creates the output list for the 'email' autocomplete search.
public toAutocompleteArray ( integer $limit = null ) : array | ||
$limit | integer | Limit display to this many addresses. If null, shows all addresses. |
return | array | An array with the following keys for each result:
- g: (array) List of addresses in the group. - l: (string) Full label. - s: (string) Short display string. - v: (string) Value. |
/** * URL parameters: * - bcc: BCC addresses. * - bcc_json: JSON encoded addresses to send to. Overwrites 'bcc'. * - body: Message body text. * - cc: CC addresses. * - cc_json: JSON encoded addresses to send to. Overwrites 'cc'. * - identity: Force message to use this identity by default. * - popup_link: Compose window generated via a popup link. * - subject: Subject to use. * - type: redirect, reply, reply_auto, reply_all, reply_list, * forward_attach, forward_auto, forward_body, forward_both, * forward_redirect, resume, new, new_to, editasnew, template, * template_edit, template_new * - to: Addresses to send to. * - to_json: JSON encoded addresses to send to. Overwrites 'to'. */ protected function _init() { global $injector, $notification, $page_output, $prefs; $alist = $injector->getInstance('IMP_Dynamic_AddressList'); $clink = new IMP_Compose_Link($this->vars); $addr = array(); foreach (array('to', 'cc', 'bcc') as $val) { $var_name = $val . '_json'; if (isset($this->vars->{$var_name})) { /* Check for JSON encoded information. */ $addr[$val] = $alist->parseAddressList($this->vars->{$var_name}); } elseif (isset($clink->args[$val])) { /* Non-JSON encoded address information. */ $addr[$val] = IMP::parseAddressList($clink->args[$val]); } } $subject = isset($clink->args['subject']) ? $clink->args['subject'] : null; $identity = $injector->getInstance('IMP_Identity'); if (!$prefs->isLocked('default_identity') && isset($this->vars->identity)) { $identity->setDefault($this->vars->identity); } /* Init objects. */ $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create(); $compose_ajax = new IMP_Ajax_Application_Compose($imp_compose, $this->vars->type); $ajax_queue = $injector->getInstance('IMP_Ajax_Queue'); $ajax_queue->compose($imp_compose); $compose_opts = array('title' => _("New Message")); switch ($this->vars->type) { case 'reply': case 'reply_all': case 'reply_auto': case 'reply_list': try { $result = $imp_compose->replyMessage($compose_ajax->reply_map[$this->vars->type], $this->_getContents(), array('to' => isset($addr['to']) ? $addr['to'] : null)); } catch (IMP_Exception $e) { $notification->push($e, 'horde.error'); break; } $onload = $compose_ajax->getResponse($result); switch ($result['type']) { case IMP_Compose::REPLY_SENDER: $compose_opts['title'] = _("Reply"); break; case IMP_Compose::REPLY_ALL: $compose_opts['title'] = _("Reply to All"); break; case IMP_Compose::REPLY_LIST: $compose_opts['title'] = _("Reply to List"); break; } $compose_opts['title'] .= ': ' . $result['subject']; break; case 'forward_attach': case 'forward_auto': case 'forward_body': case 'forward_both': try { if (count($this->indices) > 1) { if (!in_array($this->vars->type, array('forward_attach', 'forward_auto'))) { $notification->push(_("Multiple messages can only be forwarded as attachments."), 'horde.warning'); } $result = $imp_compose->forwardMultipleMessages($this->indices); } else { $result = $imp_compose->forwardMessage($compose_ajax->forward_map[$this->vars->type], $this->_getContents()); } } catch (IMP_Exception $e) { $notification->push($e, 'horde.error'); break; } $onload = $compose_ajax->getResponse($result); $compose_opts['title'] = $result['title']; $ajax_queue->attachment($imp_compose, IMP_Compose::FORWARD_ATTACH); break; case 'forward_redirect': try { $imp_compose->redirectMessage($this->indices); $compose_opts['title'] = _("Redirect"); } catch (IMP_Compose_Exception $e) { $notification->push($e, 'horde.error'); } // Not used in JS $onload = new stdClass(); break; case 'editasnew': case 'resume': case 'template': case 'template_edit': try { switch ($this->vars->type) { case 'editasnew': $result = $imp_compose->editAsNew($this->indices); break; case 'resume': $result = $imp_compose->resumeDraft($this->indices); $compose_opts['resume'] = true; break; case 'template': $result = $imp_compose->useTemplate($this->indices); break; case 'template_edit': $result = $imp_compose->editTemplate($this->indices); $compose_opts['template'] = true; break; } $onload = $compose_ajax->getResponse($result); $ajax_queue->attachment($imp_compose, $result['type']); $show_editor = $result['format'] == 'html'; } catch (IMP_Compose_Exception $e) { $notification->push($e); } break; case 'new_to': $h = $this->_getContents()->getHeader(); $f = $h['reply-to'] ?: $h['from']; $addr['to'] = $f->getAddressList(true); // Fall-through // Fall-through case 'new': case 'template_new': default: $show_editor = $prefs->getValue('compose_html') && IMP_Compose::canHtmlCompose(); $onload = $compose_ajax->getBaseResponse(); $onload->body = isset($clink->args['body']) ? strval($clink->args['body']) : ''; if ($show_editor) { $onload->format = 'html'; } if ($this->vars->type == 'template_new') { $compose_opts['template'] = true; } break; } $compose_opts['redirect'] = $this->vars->type == 'forward_redirect'; if (isset($onload->addr) || !empty($addr)) { foreach (array('to', 'cc', 'bcc') as $val) { if (!isset($onload->addr[$val])) { $onload->addr[$val] = array(); } if (isset($addr[$val])) { $tmp = new IMP_Ajax_Addresses($addr[$val]); $onload->addr[$val] = array_merge($onload->addr[$val], $tmp->toAutocompleteArray()); } } } if (!is_null($subject)) { $onload->subject = $subject; } $this->title = $compose_opts['title']; $this->view->compose = $injector->getInstance('IMP_Dynamic_Compose_Common')->compose($this, $compose_opts); $page_output->addInlineJsVars(array('ImpCompose.popup_link' => intval($this->vars->popup_link), 'ImpCompose.onload_show' => $onload, 'ImpCompose.tasks' => $injector->getInstance('Horde_Core_Factory_Ajax')->create('imp', $this->vars)->getTasks())); Horde::startBuffer(); $notification->notify(array('listeners' => array('status', 'audio'))); $this->view->status = Horde::endBuffer(); $this->_pages[] = 'compose-base'; }
/** * AJAX Action: Do an autocomplete search. * * Variables used: * - limit: (integer) If set, limits to this many results. * - search: (string) Search string. * - type: (string) Autocomplete search type. * * @return object An object with a single property: 'results'. * The format of 'results' depends on the search type. * - type = 'email' * Results is an array with the following keys for each result: * - g: (array) List of addresses in the group (in same 'results' * format as type = 'email'). * - l: (string) Full label. * - s: (string) Short display string. * - v: (string) Value. */ public function autocompleteSearch() { $out = new stdClass(); $out->results = array(); switch ($this->vars->type) { case 'email': $addr = $GLOBALS['injector']->getInstance('IMP_Contacts')->searchEmail($this->vars->search, array('levenshtein' => true)); $ajax_addr = new IMP_Ajax_Addresses($addr); $out->results = $ajax_addr->toAutocompleteArray($this->vars->limit); break; } return $out; }
/** */ public function getBaseResponse($result = array()) { $ob = new stdClass(); $ob->body = ''; $ob->opts = new stdClass(); $ob->subject = isset($result['subject']) ? $result['subject'] : ''; $ob->type = $this->_type; if (isset($result['addr'])) { $ob->addr = array(); foreach (array('to', 'cc', 'bcc') as $val) { $addr = new IMP_Ajax_Addresses($result['addr'][$val]); $ob->addr[$val] = $addr->toAutocompleteArray(); } } return $ob; }