From 36d004e3d0ad9ff97b66b2e505f6b17fd6d23102 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 3 Jul 2014 14:25:19 +0200 Subject: Added 'contact_search_name' option to define autocompletion entry format --- program/lib/Roundcube/rcube_addressbook.php | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'program/lib/Roundcube/rcube_addressbook.php') diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php index 4d9fa3db1..7566d6546 100644 --- a/program/lib/Roundcube/rcube_addressbook.php +++ b/program/lib/Roundcube/rcube_addressbook.php @@ -556,6 +556,59 @@ abstract class rcube_addressbook return $fn; } + /** + * 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 */ -- cgit v1.2.3 From 83316e175dfb0aa4dde06a975600292be60dd132 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 23 Jul 2014 12:15:50 +0200 Subject: Reset $value in a loop --- program/lib/Roundcube/rcube_addressbook.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'program/lib/Roundcube/rcube_addressbook.php') diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php index 7566d6546..71d556234 100644 --- a/program/lib/Roundcube/rcube_addressbook.php +++ b/program/lib/Roundcube/rcube_addressbook.php @@ -580,7 +580,8 @@ abstract class rcube_addressbook if (preg_match_all('/\{[a-z]+\}/', $result, $matches)) { foreach ($matches[0] as $key) { - $key = trim($key, '{}'); + $key = trim($key, '{}'); + $value = ''; switch ($key) { case 'name': -- cgit v1.2.3 From 6a0a4a3a5230e823b812b98272c5e011d07aac35 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 18 Aug 2014 10:00:45 +0200 Subject: Remove empty brackets, slashes and spaces from contact search name --- program/lib/Roundcube/rcube_addressbook.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'program/lib/Roundcube/rcube_addressbook.php') diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php index 71d556234..5bc3edf2d 100644 --- a/program/lib/Roundcube/rcube_addressbook.php +++ b/program/lib/Roundcube/rcube_addressbook.php @@ -605,7 +605,8 @@ abstract class rcube_addressbook } $result = preg_replace('/\s+/', ' ', $result); - $result = trim($result); + $result = preg_replace('/\s*(<>|\(\)|\[\])/', '', $result); + $result = trim($result, '/ '); return $result; } -- cgit v1.2.3 From 25a9ec7bb7a1bea7238f400248599e74c4a93950 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 18 Aug 2014 14:16:20 +0200 Subject: Allow caller to supply the template for contact name composition --- program/lib/Roundcube/rcube_addressbook.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'program/lib/Roundcube/rcube_addressbook.php') diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php index 5bc3edf2d..69027b0e8 100644 --- a/program/lib/Roundcube/rcube_addressbook.php +++ b/program/lib/Roundcube/rcube_addressbook.php @@ -562,21 +562,22 @@ abstract class rcube_addressbook * @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) + * @param string Optional template to use (defaults to the 'contact_search_name' config option) * * @return string Display name */ - public static function compose_search_name($contact, $email = null, $name = null) + public static function compose_search_name($contact, $email = null, $name = null, $templ = null) { static $template; - if (!isset($template)) { // cache this + if (empty($templ) && !isset($template)) { // cache this $template = rcube::get_instance()->config->get('contact_search_name'); if (empty($template)) { $template = '{name} <{email}>'; } } - $result = $template; + $result = $templ ?: $template; if (preg_match_all('/\{[a-z]+\}/', $result, $matches)) { foreach ($matches[0] as $key) { -- cgit v1.2.3