Merge branch 'master' of ssh://git.kolabsys.com/git/roundcube
This commit is contained in:
commit
2ff0adf9e8
4 changed files with 213 additions and 19 deletions
14
plugins/kolab_addressbook/config.inc.php.dist
Normal file
14
plugins/kolab_addressbook/config.inc.php.dist
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
This option allows to set addressbooks priority or to disable some
|
||||||
|
of them. Disabled addressbooks will be not shown in the UI. Default: 0.
|
||||||
|
|
||||||
|
0 - "Global address book(s) first". Use all address books, starting with the global (LDAP)
|
||||||
|
1 - "Personal address book(s) first". Use all address books, starting with the personal (Kolab)
|
||||||
|
2 - "Global address book(s) only". Use the global (LDAP) addressbook. Disable the personal.
|
||||||
|
3 - "Personal address book(s) only". Use the personal (Kolab) addressbook(s). Disable the global.
|
||||||
|
*/
|
||||||
|
$rcmail_config['kolab_addressbook_prio'] = 0;
|
||||||
|
|
||||||
|
?>
|
|
@ -9,57 +9,92 @@ require_once(dirname(__FILE__) . '/rcube_kolab_contacts.php');
|
||||||
* This is work-in-progress for the Roundcube+Kolab integration.
|
* This is work-in-progress for the Roundcube+Kolab integration.
|
||||||
*
|
*
|
||||||
* @author Thomas Bruederli <roundcube@gmail.com>
|
* @author Thomas Bruederli <roundcube@gmail.com>
|
||||||
|
* @author Aleksander Machniak <machniak@kolabsys.com>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2011, Kolab Systems AG
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
class kolab_addressbook extends rcube_plugin
|
class kolab_addressbook extends rcube_plugin
|
||||||
{
|
{
|
||||||
private $folders;
|
private $folders;
|
||||||
private $sources;
|
private $sources;
|
||||||
|
private $rc;
|
||||||
|
|
||||||
|
const GLOBAL_FIRST = 0;
|
||||||
|
const PERSONAL_FIRST = 1;
|
||||||
|
const GLOBAL_ONLY = 2;
|
||||||
|
const PERSONAL_ONLY = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required startup method of a Roundcube plugin
|
* Startup method of a Roundcube plugin
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
|
$this->rc = rcmail::get_instance();
|
||||||
|
|
||||||
// load required plugin
|
// load required plugin
|
||||||
$this->require_plugin('kolab_core');
|
$this->require_plugin('kolab_core');
|
||||||
|
|
||||||
// register hooks
|
// register hooks
|
||||||
$this->add_hook('addressbooks_list', array($this, 'address_sources'));
|
$this->add_hook('addressbooks_list', array($this, 'address_sources'));
|
||||||
$this->add_hook('addressbook_get', array($this, 'get_address_book'));
|
$this->add_hook('addressbook_get', array($this, 'get_address_book'));
|
||||||
$this->add_hook('contact_form', array($this, 'contact_form'));
|
|
||||||
|
|
||||||
$rcmail = rcmail::get_instance();
|
if ($this->rc->task == 'addressbook') {
|
||||||
|
|
||||||
if ($rcmail->task == 'addressbook') {
|
|
||||||
$this->add_texts('localization');
|
$this->add_texts('localization');
|
||||||
|
$this->add_hook('contact_form', array($this, 'contact_form'));
|
||||||
|
}
|
||||||
|
else if ($this->rc->task == 'settings') {
|
||||||
|
$this->add_texts('localization');
|
||||||
|
$this->add_hook('preferences_list', array($this, 'prefs_list'));
|
||||||
|
$this->add_hook('preferences_save', array($this, 'prefs_save'));
|
||||||
|
}
|
||||||
|
// extend list of address sources to be used for autocompletion
|
||||||
|
else if ($this->rc->task == 'mail' && $this->rc->action == 'autocomplete') {
|
||||||
|
$this->autocomplete_sources();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// extend list of address sources to be used for autocompletion
|
|
||||||
if ($rcmail->action == 'autocomplete' || $rcmail->action == 'group-expand') {
|
|
||||||
$sources = (array) $rcmail->config->get('autocomplete_addressbooks', array());
|
|
||||||
foreach ($this->_list_sources() as $abook_id => $abook) {
|
|
||||||
if (!in_array($abook_id, $sources))
|
|
||||||
$sources[] = $abook_id;
|
|
||||||
}
|
|
||||||
$rcmail->config->set('autocomplete_addressbooks', $sources);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the addressbooks_list hook.
|
* Handler for the addressbooks_list hook.
|
||||||
*
|
*
|
||||||
* This will add all instances of available Kolab-based address books
|
* This will add all instances of available Kolab-based address books
|
||||||
* to the list of address sources of Roundcube.
|
* to the list of address sources of Roundcube.
|
||||||
|
* This will also hide some addressbooks according to kolab_addressbook_prio setting.
|
||||||
|
*
|
||||||
|
* @param array $p Hash array with hook parameters
|
||||||
*
|
*
|
||||||
* @param array Hash array with hook parameters
|
|
||||||
* @return array Hash array with modified hook parameters
|
* @return array Hash array with modified hook parameters
|
||||||
*/
|
*/
|
||||||
public function address_sources($p)
|
public function address_sources($p)
|
||||||
{
|
{
|
||||||
|
// Load configuration
|
||||||
|
$this->load_config();
|
||||||
|
|
||||||
|
$abook_prio = (int) $this->rc->config->get('kolab_addressbook_prio');
|
||||||
|
|
||||||
|
// Disable all global address books
|
||||||
|
// Assumes that all non-kolab_addressbook sources are global
|
||||||
|
if ($abook_prio == self::PERSONAL_ONLY) {
|
||||||
|
$p['sources'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$sources = array();
|
||||||
foreach ($this->_list_sources() as $abook_id => $abook) {
|
foreach ($this->_list_sources() as $abook_id => $abook) {
|
||||||
// register this address source
|
// register this address source
|
||||||
$p['sources'][$abook_id] = array(
|
$sources[$abook_id] = array(
|
||||||
'id' => $abook_id,
|
'id' => $abook_id,
|
||||||
'name' => $abook->get_name(),
|
'name' => $abook->get_name(),
|
||||||
'readonly' => $abook->readonly,
|
'readonly' => $abook->readonly,
|
||||||
|
@ -67,12 +102,62 @@ class kolab_addressbook extends rcube_plugin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add personal address sources to the list
|
||||||
|
if ($abook_prio == self::PERSONAL_FIRST) {
|
||||||
|
$p['sources'] = array_merge($sources, $p['sources']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$p['sources'] = array_merge($p['sources'], $sources);
|
||||||
|
}
|
||||||
|
|
||||||
return $p;
|
return $p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setts autocomplete_addressbooks option according to
|
||||||
|
* kolab_addressbook_prio setting.
|
||||||
|
*/
|
||||||
|
public function autocomplete_sources()
|
||||||
|
{
|
||||||
|
// Load configuration
|
||||||
|
$this->load_config();
|
||||||
|
|
||||||
|
$abook_prio = (int) $this->rc->config->get('kolab_addressbook_prio');
|
||||||
|
$sources = (array) $this->rc->config->get('autocomplete_addressbooks', array());
|
||||||
|
|
||||||
|
// Disable all global address books
|
||||||
|
// Assumes that all non-kolab_addressbook sources are global
|
||||||
|
if ($abook_prio == self::PERSONAL_ONLY) {
|
||||||
|
$sources = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$kolab_sources = array();
|
||||||
|
foreach ($this->_list_sources() as $abook_id => $abook) {
|
||||||
|
if (!in_array($abook_id, $sources))
|
||||||
|
$kolab_sources[] = $abook_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add personal address sources to the list
|
||||||
|
if (!empty($kolab_sources)) {
|
||||||
|
if ($abook_prio == self::PERSONAL_FIRST) {
|
||||||
|
$sources = array_merge($kolab_sources, $sources);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$sources = array_merge($sources, $kolab_sources);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->rc->config->set('autocomplete_addressbooks', $sources);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for the rcube_addressbook instance
|
* Getter for the rcube_addressbook instance
|
||||||
|
*
|
||||||
|
* @param array $p Hash array with hook parameters
|
||||||
|
*
|
||||||
|
* @return array Hash array with modified hook parameters
|
||||||
*/
|
*/
|
||||||
public function get_address_book($p)
|
public function get_address_book($p)
|
||||||
{
|
{
|
||||||
|
@ -92,9 +177,20 @@ class kolab_addressbook extends rcube_plugin
|
||||||
if (isset($this->sources))
|
if (isset($this->sources))
|
||||||
return $this->sources;
|
return $this->sources;
|
||||||
|
|
||||||
|
$this->sources = array();
|
||||||
|
|
||||||
|
// Load configuration
|
||||||
|
$this->load_config();
|
||||||
|
|
||||||
|
$abook_prio = (int) $this->rc->config->get('kolab_addressbook_prio');
|
||||||
|
|
||||||
|
// Personal address source(s) disabled?
|
||||||
|
if ($abook_prio == self::GLOBAL_ONLY) {
|
||||||
|
return $this->sources;
|
||||||
|
}
|
||||||
|
|
||||||
// get all folders that have "contact" type
|
// get all folders that have "contact" type
|
||||||
$this->folders = rcube_kolab::get_folders('contact');
|
$this->folders = rcube_kolab::get_folders('contact');
|
||||||
$this->sources = array();
|
|
||||||
|
|
||||||
if (PEAR::isError($this->folders)) {
|
if (PEAR::isError($this->folders)) {
|
||||||
raise_error(array(
|
raise_error(array(
|
||||||
|
@ -118,6 +214,10 @@ class kolab_addressbook extends rcube_plugin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin hook called before rendering the contact form or detail view
|
* Plugin hook called before rendering the contact form or detail view
|
||||||
|
*
|
||||||
|
* @param array $p Hash array with hook parameters
|
||||||
|
*
|
||||||
|
* @return array Hash array with modified hook parameters
|
||||||
*/
|
*/
|
||||||
public function contact_form($p)
|
public function contact_form($p)
|
||||||
{
|
{
|
||||||
|
@ -165,4 +265,72 @@ class kolab_addressbook extends rcube_plugin
|
||||||
return $block;
|
return $block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for user preferences form (preferences_list hook)
|
||||||
|
*
|
||||||
|
* @param array $args Hash array with hook parameters
|
||||||
|
*
|
||||||
|
* @return array Hash array with modified hook parameters
|
||||||
|
*/
|
||||||
|
public function prefs_list($args)
|
||||||
|
{
|
||||||
|
if ($args['section'] != 'addressbook') {
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load configuration
|
||||||
|
$this->load_config();
|
||||||
|
|
||||||
|
// Load localization and configuration
|
||||||
|
$this->add_texts('localization');
|
||||||
|
|
||||||
|
// Check that configuration is not disabled
|
||||||
|
$dont_override = (array) $this->rc->config->get('dont_override', array());
|
||||||
|
|
||||||
|
if (!in_array('kolab_addressbook_prio', $dont_override)) {
|
||||||
|
$field_id = '_kolab_addressbook_prio';
|
||||||
|
$select = new html_select(array('name' => $field_id, 'id' => $field_id));
|
||||||
|
|
||||||
|
$select->add($this->gettext('globalfirst'), self::GLOBAL_FIRST);
|
||||||
|
$select->add($this->gettext('personalfirst'), self::PERSONAL_FIRST);
|
||||||
|
$select->add($this->gettext('globalonly'), self::GLOBAL_ONLY);
|
||||||
|
$select->add($this->gettext('personalonly'), self::PERSONAL_ONLY);
|
||||||
|
|
||||||
|
$args['blocks']['main']['options']['kolab_addressbook_prio'] = array(
|
||||||
|
'title' => html::label($field_id, Q($this->gettext('addressbookprio'))),
|
||||||
|
'content' => $select->show((int)$this->rc->config->get('kolab_addressbook_prio')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for user preferences save (preferences_save hook)
|
||||||
|
*
|
||||||
|
* @param array $args Hash array with hook parameters
|
||||||
|
*
|
||||||
|
* @return array Hash array with modified hook parameters
|
||||||
|
*/
|
||||||
|
public function prefs_save($args)
|
||||||
|
{
|
||||||
|
if ($args['section'] != 'addressbook') {
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load configuration
|
||||||
|
$this->load_config();
|
||||||
|
|
||||||
|
// Check that configuration is not disabled
|
||||||
|
$dont_override = (array) $this->rc->config->get('dont_override', array());
|
||||||
|
|
||||||
|
if (!in_array('kolab_addressbook_prio', $dont_override)) {
|
||||||
|
$key = 'kolab_addressbook_prio';
|
||||||
|
$args['prefs'][$key] = (int) get_input_value('_'.$key, RCUBE_INPUT_POST);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,4 +9,10 @@ $labels['pgppublickey'] = 'PGP publickey';
|
||||||
$labels['freebusyurl'] = 'Free-busy URL';
|
$labels['freebusyurl'] = 'Free-busy URL';
|
||||||
$labels['settings'] = 'Settings';
|
$labels['settings'] = 'Settings';
|
||||||
|
|
||||||
|
$labels['addressbookprio'] = 'Address book(s) selection/behaviour';
|
||||||
|
$labels['personalfirst'] = 'Personal address book(s) first';
|
||||||
|
$labels['globalfirst'] = 'Global address book(s) first';
|
||||||
|
$labels['personalonly'] = 'Personal address book(s) only';
|
||||||
|
$labels['globalonly'] = 'Global address book(s) only';
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -9,4 +9,10 @@ $labels['pgppublickey'] = 'Klucz publ. PGP';
|
||||||
$labels['freebusyurl'] = 'URL Free-busy';
|
$labels['freebusyurl'] = 'URL Free-busy';
|
||||||
$labels['settings'] = 'Ustawienia';
|
$labels['settings'] = 'Ustawienia';
|
||||||
|
|
||||||
|
$labels['addressbookprio'] = 'Wybór/zachowanie książek adresowych';
|
||||||
|
$labels['personalfirst'] = 'Najpierw osobiste książki adresowe';
|
||||||
|
$labels['globalfirst'] = 'Najpierw globalne książki adresowe';
|
||||||
|
$labels['personalonly'] = 'Tylko osobiste książki adresowe';
|
||||||
|
$labels['globalonly'] = 'Tylko globalne książki adresowe';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Reference in a new issue