| | |
| | | $this->mail_domain = $mail_domain; |
| | | |
| | | // initialize cache |
| | | $rcube = rcube::get_instance(); |
| | | $cache_type = $rcube->config->get('ldap_cache', 'db'); |
| | | $cache_ttl = $rcube->config->get('ldap_cache_ttl', '10m'); |
| | | $cache_name = 'LDAP.' . asciiwords($this->prop['name']); |
| | | $rcube = rcube::get_instance(); |
| | | if ($cache_type = $rcube->config->get('ldap_cache', 'db')) { |
| | | $cache_ttl = $rcube->config->get('ldap_cache_ttl', '10m'); |
| | | $cache_name = 'LDAP.' . asciiwords($this->prop['name']); |
| | | |
| | | $this->cache = $rcube->get_cache($cache_name, $cache_type, $cache_ttl); |
| | | $this->cache = $rcube->get_cache($cache_name, $cache_type, $cache_ttl); |
| | | } |
| | | |
| | | // determine which attributes to fetch |
| | | $this->prop['list_attributes'] = array_unique($fetch_attributes); |
| | |
| | | $cache_key = 'DN.' . md5("$host:$search_bind_dn:$search_base_dn:$search_filter:" |
| | | .$this->prop['search_bind_pw']); |
| | | |
| | | if ($dn = $this->cache->get($cache_key)) { |
| | | if ($this->cache && ($dn = $this->cache->get($cache_key))) { |
| | | $replaces['%dn'] = $dn; |
| | | } |
| | | else { |
| | |
| | | } |
| | | } |
| | | |
| | | if (!empty($replaces['%dn'])) { |
| | | if ($this->cache && !empty($replaces['%dn'])) { |
| | | $this->cache->set($cache_key, $replaces['%dn']); |
| | | } |
| | | } |
| | |
| | | return array(); |
| | | |
| | | // use cached list for searching |
| | | $this->cache->expunge(); |
| | | if (!$search || ($group_cache = $this->cache->get('groups')) === null) |
| | | if (!$this->cache || ($group_cache = $this->cache->get('groups')) === null) { |
| | | $group_cache = $this->_fetch_groups(); |
| | | } |
| | | |
| | | $groups = array(); |
| | | if ($search) { |
| | |
| | | array_multisort($group_sortnames, SORT_ASC, SORT_STRING, $groups); |
| | | |
| | | // cache this |
| | | $this->cache->set('groups', $groups); |
| | | if ($this->cache) { |
| | | $this->cache->set('groups', $groups); |
| | | } |
| | | |
| | | return $groups; |
| | | } |
| | |
| | | */ |
| | | private function get_group_entry($group_id) |
| | | { |
| | | if (($group_cache = $this->cache->get('groups')) === null) |
| | | if (!$this->cache || ($group_cache = $this->cache->get('groups')) === null) { |
| | | $group_cache = $this->_fetch_groups(); |
| | | } |
| | | |
| | | // add group record to cache if it isn't yet there |
| | | if (!isset($group_cache[$group_id])) { |
| | |
| | | $group_cache[$group_id] = false; |
| | | } |
| | | |
| | | $this->cache->set('groups', $group_cache); |
| | | if ($this->cache) { |
| | | $this->cache->set('groups', $group_cache); |
| | | } |
| | | } |
| | | |
| | | return $group_cache[$group_id]; |
| | |
| | | return false; |
| | | } |
| | | |
| | | $this->cache->remove('groups'); |
| | | if ($this->cache) { |
| | | $this->cache->remove('groups'); |
| | | } |
| | | |
| | | return array('id' => $new_gid, 'name' => $group_name); |
| | | } |
| | |
| | | */ |
| | | function delete_group($group_id) |
| | | { |
| | | if (($group_cache = $this->cache->get('groups')) === null) |
| | | if (!$this->cache || ($group_cache = $this->cache->get('groups')) === null) { |
| | | $group_cache = $this->_fetch_groups(); |
| | | } |
| | | |
| | | $del_dn = $group_cache[$group_id]['dn']; |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | unset($group_cache[$group_id]); |
| | | $this->cache->set('groups', $group_cache); |
| | | if ($this->cache) { |
| | | unset($group_cache[$group_id]); |
| | | $this->cache->set('groups', $group_cache); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | |
| | | */ |
| | | function rename_group($group_id, $new_name, &$new_gid) |
| | | { |
| | | if (($group_cache = $this->cache->get('groups')) === null) |
| | | if (!$this->cache || ($group_cache = $this->cache->get('groups')) === null) { |
| | | $group_cache = $this->_fetch_groups(); |
| | | } |
| | | |
| | | $old_dn = $group_cache[$group_id]['dn']; |
| | | $new_rdn = "cn=" . rcube_ldap_generic::quote_string($new_name, true); |
| | |
| | | return false; |
| | | } |
| | | |
| | | $this->cache->remove('groups'); |
| | | if ($this->cache) { |
| | | $this->cache->remove('groups'); |
| | | } |
| | | |
| | | return $new_name; |
| | | } |
| | |
| | | */ |
| | | function add_to_group($group_id, $contact_ids) |
| | | { |
| | | if (($group_cache = $this->cache->get('groups')) === null) |
| | | if (!$this->cache || ($group_cache = $this->cache->get('groups')) === null) { |
| | | $group_cache = $this->_fetch_groups(); |
| | | } |
| | | |
| | | if (!is_array($contact_ids)) |
| | | $contact_ids = explode(',', $contact_ids); |
| | |
| | | return 0; |
| | | } |
| | | |
| | | $this->cache->remove('groups'); |
| | | if ($this->cache) { |
| | | $this->cache->remove('groups'); |
| | | } |
| | | |
| | | return count($new_attrs[$member_attr]); |
| | | } |
| | |
| | | */ |
| | | function remove_from_group($group_id, $contact_ids) |
| | | { |
| | | if (($group_cache = $this->cache->get('groups')) === null) |
| | | if (!$this->cache || ($group_cache = $this->cache->get('groups')) === null) { |
| | | $group_cache = $this->_fetch_groups(); |
| | | } |
| | | |
| | | if (!is_array($contact_ids)) |
| | | $contact_ids = explode(',', $contact_ids); |
| | |
| | | return 0; |
| | | } |
| | | |
| | | $this->cache->remove('groups'); |
| | | if ($this->cache) { |
| | | $this->cache->remove('groups'); |
| | | } |
| | | |
| | | return count($del_attrs[$member_attr]); |
| | | } |