summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-03-03 12:53:05 +0100
committerThomas Bruederli <bruederli@kolabsys.com>2015-03-03 12:53:18 +0100
commit83eeec6c0665ff18881ba05743b7368f9fb1c2f7 (patch)
tree00ddee9129c7dd843e5a4fd8cc0dd77cf8dc9e2e /program/lib/Roundcube
parent9ad0fc489ff3c32face845989a8f5f311208b4f9 (diff)
Add utility function to compose a full-text-like LDAP search filter
Diffstat (limited to 'program/lib/Roundcube')
-rw-r--r--program/lib/Roundcube/rcube_ldap_generic.php42
1 files changed, 41 insertions, 1 deletions
diff --git a/program/lib/Roundcube/rcube_ldap_generic.php b/program/lib/Roundcube/rcube_ldap_generic.php
index a76ad6d06..40adbedbe 100644
--- a/program/lib/Roundcube/rcube_ldap_generic.php
+++ b/program/lib/Roundcube/rcube_ldap_generic.php
@@ -6,7 +6,7 @@
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2006-2014, The Roundcube Dev Team |
- | Copyright (C) 2012-2014, Kolab Systems AG |
+ | Copyright (C) 2012-2015, Kolab Systems AG |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -316,6 +316,46 @@ class rcube_ldap_generic extends Net_LDAP3
return $rec;
}
+
+ /**
+ * Compose an LDAP filter string matching all words from the search string
+ * in the given list of attributes.
+ *
+ * @param string $value Search value
+ * @param mixed $attrs List of LDAP attributes to search
+ * @param int $mode Matching mode:
+ * 0 - partial (*abc*),
+ * 1 - strict (=),
+ * 2 - prefix (abc*)
+ * @return string LDAP filter
+ */
+ public static function fulltext_search_filter($value, $attributes, $mode = 1)
+ {
+ if (empty($attributes)) {
+ $attributes = array('cn');
+ }
+
+ $groups = array();
+ $words = rcube_utils::tokenize_string($value, 1);
+
+ // set wildcards
+ $wp = $ws = '';
+ if ($mode != 1) {
+ $ws = '*';
+ $wp = !$mode ? '*' : '';
+ }
+
+ // search each word in all listed attributes
+ foreach ($words as $word) {
+ $parts = array();
+ foreach ($attributes as $attr) {
+ $parts[] = "($attr=$wp" . self::quote_string($word) . "$ws)";
+ }
+ $groups[] = '(|' . join('', $parts) . ')';
+ }
+
+ return empty($groups) ? '' : '(&' . join('', $groups) . ')';
+ }
}
// for backward compat.