Aleksander Machniak
2014-07-03 36d004e3d0ad9ff97b66b2e505f6b17fd6d23102
Added 'contact_search_name' option to define autocompletion entry format
5 files modified
71 ■■■■■ changed files
CHANGELOG 1 ●●●● patch | view | raw | blame | history
config/defaults.inc.php 5 ●●●●● patch | view | raw | blame | history
program/js/app.js 2 ●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_addressbook.php 53 ●●●●● patch | view | raw | blame | history
program/steps/mail/autocomplete.inc 10 ●●●● patch | view | raw | blame | history
CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================
- Added 'contact_search_name' option to define autocompletion entry format
- Display quota information for current folder not INBOX only (#1487993)
- Support images in HTML signatures (#1488676)
- Display full quota information in popup (#1485769, #1486604)
config/defaults.inc.php
@@ -877,6 +877,11 @@
// Note: For LDAP sources fuzzy_search must be enabled to use 'partial' or 'prefix' mode
$config['addressbook_search_mode'] = 0;
// Template of contact entry on the autocompletion list.
// You can use contact fields as: name, email, organization, department, etc.
// See program/steps/addressbook/func.inc for a list
$config['contact_search_name'] = '{name} <{email}>';
// ----------------------------------
// USER PREFERENCES
// ----------------------------------
program/js/app.js
@@ -4568,7 +4568,7 @@
    // add each result line to list
    if (results && (len = results.length)) {
      for (i=0; i < len && maxlen > 0; i++) {
        text = typeof results[i] === 'object' ? results[i].name : results[i];
        text = typeof results[i] === 'object' ? (results[i].display || results[i].name) : results[i];
        type = typeof results[i] === 'object' ? results[i].type : '';
        id = i + this.env.contacts.length;
        $('<li>').attr('id', 'rcmkSearchItem' + id)
program/lib/Roundcube/rcube_addressbook.php
@@ -557,6 +557,59 @@
    }
    /**
     * Build contact display name for autocomplete listing
     *
     * @param array  Hash array with contact data as key-value pairs
     * @param string Optional email address
     * @param string Optional name (self::compose_list_name() result)
     *
     * @return string Display name
     */
    public static function compose_search_name($contact, $email = null, $name = null)
    {
        static $template;
        if (!isset($template)) {  // cache this
            $template = rcube::get_instance()->config->get('contact_search_name');
            if (empty($template)) {
                $template = '{name} <{email}>';
            }
        }
        $result = $template;
        if (preg_match_all('/\{[a-z]+\}/', $result, $matches)) {
            foreach ($matches[0] as $key) {
                $key = trim($key, '{}');
                switch ($key) {
                case 'name':
                    $value = $name ?: self::compose_list_name($contact);
                    break;
                case 'email':
                    $value = $email;
                    break;
                }
                if (empty($value)) {
                    $value = strpos($key, ':') ? $contact[$key] : self::get_col_values($key, $contact, true);
                    if (is_array($value)) {
                        $value = $value[0];
                    }
                }
                $result = str_replace('{' . $key . '}', $value, $result);
            }
        }
        $result = preg_replace('/\s+/', ' ', $result);
        $result = trim($result);
        return $result;
    }
    /**
     * Create a unique key for sorting contacts
     */
    public static function compose_contact_key($contact, $sort_col)
program/steps/mail/autocomplete.inc
@@ -90,8 +90,14 @@
                    // skip duplicates
                    if (!in_array($contact, $contacts)) {
                        $contacts[]  = array('name' => $contact, 'type' => $sql_arr['_type']);
                        $sort_keys[] = sprintf('%s %03d', $sql_arr['name'] , $idx++);
                        $contact = array('name' => $contact, 'type' => $sql_arr['_type']);
                        if (($display = rcube_addressbook::compose_search_name($sql_arr, $email, $name)) && $display != $contact['name']) {
                            $contact['display'] = $display;
                        }
                        $contacts[]  = $contact;
                        $sort_keys[] = sprintf('%s %03d', $contact['display'] ?: $name, $idx++);
                        if (count($contacts) >= $MAXNUM) {
                            break 2;