From ac1af6d3daf377002fb9875c49dde0a0025a980a Mon Sep 17 00:00:00 2001 From: alec Date: Wed, 6 Jul 2011 17:59:12 +0000 Subject: Fix new_user_identity after some changes in rcube_ldap class (#1487758) git-svn-id: https://svn.roundcube.net/trunk@4915 208e9e7b-5314-0410-a742-e7e81cd9613c --- plugins/new_user_identity/new_user_identity.php | 46 ++++++++++++++++++++----- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'plugins') diff --git a/plugins/new_user_identity/new_user_identity.php b/plugins/new_user_identity/new_user_identity.php index 45750facd..a8894a299 100644 --- a/plugins/new_user_identity/new_user_identity.php +++ b/plugins/new_user_identity/new_user_identity.php @@ -15,7 +15,7 @@ * // user's full name in their new identity. (This should be an * // string, which refers to the $rcmail_config['ldap_public'] array.) * $rcmail_config['new_user_identity_addressbook'] = 'People'; - * + * * // When automatically setting a new users's full name in their * // new identity, match the user's login name against this field. * $rcmail_config['new_user_identity_match'] = 'uid'; @@ -24,6 +24,8 @@ class new_user_identity extends rcube_plugin { public $task = 'login'; + private $ldap; + function init() { $this->add_hook('user_create', array($this, 'lookup_user_name')); @@ -31,12 +33,8 @@ class new_user_identity extends rcube_plugin function lookup_user_name($args) { - $rcmail = rcmail::get_instance(); - if ($addressbook = $rcmail->config->get('new_user_identity_addressbook')) { - $match = $rcmail->config->get('new_user_identity_match'); - $ldap = $rcmail->get_address_book($addressbook); - $ldap->prop['search_fields'] = array($match); - $results = $ldap->search($match, $args['user'], TRUE); + if ($this->init_ldap()) { + $results = $this->ldap->search('*', $args['user'], TRUE); if (count($results->records) == 1) { $args['user_name'] = $results->records[0]['name']; if (!$args['user_email'] && strpos($results->records[0]['email'], '@')) { @@ -46,5 +44,37 @@ class new_user_identity extends rcube_plugin } return $args; } + + private function init_ldap() + { + if ($this->ldap) + return $this->ldap->ready; + + $rcmail = rcmail::get_instance(); + + $addressbook = $rcmail->config->get('new_user_identity_addressbook'); + $ldap_config = (array)$rcmail->config->get('ldap_public'); + $match = $rcmail->config->get('new_user_identity_match'); + + if (empty($addressbook) || empty($match) || empty($ldap_config[$addressbook])) { + return false; + } + + $this->ldap = new new_user_identity_ldap_backend( + $ldap_config[$addressbook], + $rcmail->config->get('ldap_debug'), + $rcmail->config->mail_domain($_SESSION['imap_host']), + $match); + + return $this->ldap->ready; + } +} + +class new_user_identity_ldap_backend extends rcube_ldap +{ + function __construct($p, $debug=false, $mail_domain=NULL, $search=null) + { + parent::__construct($p, $debug, $mail_domain); + $this->prop['search_fields'] = $search; + } } -?> -- cgit v1.2.3