Overview

Packages

  • Kronolith
  • None

Classes

  • Kronolith
  • Kronolith_Ajax_Application
  • Kronolith_Ajax_Imple_ContactAutoCompleter
  • Kronolith_Ajax_Imple_Embed
  • Kronolith_Ajax_Imple_TagActions
  • Kronolith_Ajax_Imple_TagAutoCompleter
  • Kronolith_Api
  • Kronolith_Calendar
  • Kronolith_Calendar_External
  • Kronolith_Calendar_External_Tasks
  • Kronolith_Calendar_Holiday
  • Kronolith_Calendar_Internal
  • Kronolith_Calendar_Remote
  • Kronolith_Calendar_Resource
  • Kronolith_Calendars_Base
  • Kronolith_Calendars_Default
  • Kronolith_Calendars_Kolab
  • Kronolith_Day
  • Kronolith_Driver
  • Kronolith_Driver_Holidays
  • Kronolith_Driver_Horde
  • Kronolith_Driver_Ical
  • Kronolith_Driver_Kolab
  • Kronolith_Driver_Mock
  • Kronolith_Driver_Resource
  • Kronolith_Driver_Sql
  • Kronolith_Event
  • Kronolith_Event_Holidays
  • Kronolith_Event_Horde
  • Kronolith_Event_Ical
  • Kronolith_Event_Kolab
  • Kronolith_Event_Resource
  • Kronolith_Event_Sql
  • Kronolith_Exception
  • Kronolith_Factory_Calendars
  • Kronolith_Factory_Geo
  • Kronolith_Form_CreateCalendar
  • Kronolith_Form_CreateResource
  • Kronolith_Form_CreateResourceGroup
  • Kronolith_Form_DeleteCalendar
  • Kronolith_Form_DeleteResource
  • Kronolith_Form_DeleteResourceGroup
  • Kronolith_Form_EditCalendar
  • Kronolith_Form_EditRemoteCalendar
  • Kronolith_Form_EditResource
  • Kronolith_Form_EditResourceGroup
  • Kronolith_Form_SubscribeRemoteCalendar
  • Kronolith_Form_UnsubscribeRemoteCalendar
  • Kronolith_FreeBusy
  • Kronolith_FreeBusy_View
  • Kronolith_FreeBusy_View_Day
  • Kronolith_FreeBusy_View_Month
  • Kronolith_FreeBusy_View_Week
  • Kronolith_FreeBusy_View_Workweek
  • Kronolith_Geo_Base
  • Kronolith_Geo_Mysql
  • Kronolith_Geo_Sql
  • Kronolith_LoginTasks_SystemTask_Upgrade
  • Kronolith_LoginTasks_Task_PurgeEvents
  • Kronolith_Notification_Listener_AjaxStatus
  • Kronolith_Resource
  • Kronolith_Resource_Base
  • Kronolith_Resource_Group
  • Kronolith_Resource_Single
  • Kronolith_Storage
  • Kronolith_Storage_Kolab
  • Kronolith_Storage_Sql
  • Kronolith_Tagger
  • Kronolith_Test
  • Kronolith_View_Day
  • Kronolith_View_DeleteEvent
  • Kronolith_View_EditEvent
  • Kronolith_View_Event
  • Kronolith_View_ExportEvent
  • Kronolith_View_Month
  • Kronolith_View_Week
  • Kronolith_View_WorkWeek
  • Kronolith_View_Year
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Attach the contact auto completer to a javascript element.
  4:  *
  5:  * Copyright 2005-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Michael Slusarz <slusarz@horde.org>
 11:  * @package Kronolith
 12:  */
 13: class Kronolith_Ajax_Imple_ContactAutoCompleter extends Horde_Core_Ajax_Imple_AutoCompleter
 14: {
 15:     /**
 16:      * Attach the Imple object to a javascript event.
 17:      *
 18:      * @param array $js_params  See
 19:      *                          Horde_Core_Ajax_Imple_AutoCompleter::_attach().
 20:      *
 21:      * @return array  See Horde_Core_Ajax_Imple_AutoCompleter::_attach().
 22:      */
 23:     protected function _attach($js_params)
 24:     {
 25:         $js_params['indicator'] = $this->_params['triggerId'] . '_loading_img';
 26: 
 27:         $ret = array('params' => $js_params,
 28:                      'raw_params' => array(
 29:                          'onSelect' => 'function (v) { if (!v.endsWith(";")) { v += ","; } return v + " "; }',
 30:                          'onType' => 'function (e) { return e.include("<") ? "" : e; }',
 31:                       ));
 32:         if (isset($this->_params['onAdd'])) {
 33:             $ret['raw_params']['onAdd'] = $this->_params['onAdd'];
 34:             $ret['raw_params']['onRemove'] = $this->_params['onRemove'];
 35:         }
 36:         if (empty($this->_params['pretty'])) {
 37:             $ret['ajax'] = 'ContactAutoCompleter';
 38:         } else {
 39:             $ret['pretty'] = 'ContactAutoCompleter';
 40:         }
 41: 
 42:         if (!empty($this->_params['var'])) {
 43:             $ret['var'] = $this->_params['var'];
 44:         }
 45: 
 46:         return $ret;
 47:     }
 48: 
 49:     /**
 50:      * TODO
 51:      *
 52:      * @param array $args  TODO
 53:      *
 54:      * @return string  TODO
 55:      */
 56:     public function handle($args, $post)
 57:     {
 58:         // Avoid errors if 'input' isn't set and short-circuit empty searches.
 59:         if (empty($args['input']) ||
 60:             !($input = Horde_Util::getFormData($args['input']))) {
 61:             return array();
 62:         }
 63: 
 64:         return $this->_getAddressList($input);
 65:     }
 66: 
 67:     /**
 68:      * Uses the Registry to expand names and return error information for
 69:      * any address that is either not valid or fails to expand.
 70:      *
 71:      * This function will not search if the address string is empty.
 72:      *
 73:      * @param string $addrString  The name(s) or address(es) to expand.
 74:      *
 75:      * @return array  All matching addresses.
 76:      */
 77:     protected function _getAddressList($addrString = '')
 78:     {
 79:         if (!preg_match('|[^\s]|', $addrString)) {
 80:             return array();
 81:         }
 82: 
 83:         $search = reset(array_filter(array_map('trim', Horde_Mime_Address::explode($addrString, ',;'))));
 84:         $searchpref = Kronolith::getAddressbookSearchParams();
 85: 
 86:         try {
 87:             $res = $GLOBALS['registry']->call('contacts/search', array($search, $searchpref['sources'], $searchpref['fields']));
 88:         } catch (Horde_Exception $e) {
 89:             Horde::logMessage($e, 'ERR');
 90:             return array();
 91:         }
 92: 
 93:         if (!count($res)) {
 94:             return array();
 95:         }
 96: 
 97:         /* The first key of the result will be the search term. The matching
 98:          * entries are stored underneath this key. */
 99:         $search = array();
100:         foreach (reset($res) as $val) {
101:             if (!empty($val['email'])) {
102:                 if (strpos($val['email'], ',') !== false) {
103:                     $search[] = Horde_Mime_Address::encode($val['name'], 'personal') . ': ' . $val['email'] . ';';
104:                 } else {
105:                     $mbox_host = explode('@', $val['email']);
106:                     if (isset($mbox_host[1])) {
107:                         $search[] = Horde_Mime_Address::writeAddress($mbox_host[0], $mbox_host[1], $val['name']);
108:                     }
109:                 }
110:             }
111:         }
112: 
113:         $sort_list = array();
114:         foreach ($search as $val) {
115:             $sort_list[$val] = levenshtein($addrString, $val);
116:         }
117:         asort($sort_list, SORT_NUMERIC);
118: 
119:         return array_keys($sort_list);
120:     }
121: }
122: 
API documentation generated by ApiGen