2011-10-13 09:38:10 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kolab configuration storage.
|
|
|
|
*
|
|
|
|
* Plugin to use Kolab server as a configuration storage. Provides an API to handle
|
|
|
|
* configuration according to http://wiki.kolab.org/KEP:9.
|
|
|
|
*
|
2011-11-18 15:55:08 +01:00
|
|
|
* @version @package_version@
|
2011-10-27 10:20:46 +02:00
|
|
|
* @author Machniak Aleksander <machniak@kolabsys.com>
|
2012-05-23 14:41:32 +02:00
|
|
|
* @author Thomas Bruederli <bruederli@kolabsys.com>
|
2011-10-13 09:38:10 +02:00
|
|
|
*
|
2012-05-23 14:41:32 +02:00
|
|
|
* Copyright (C) 2011-2012, Kolab Systems AG <contact@kolabsys.com>
|
2011-10-13 09:38:10 +02:00
|
|
|
*
|
2011-10-27 10:20:46 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2011-10-13 09:38:10 +02:00
|
|
|
*
|
2011-10-27 10:20:46 +02:00
|
|
|
* 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-10-13 09:38:10 +02:00
|
|
|
*/
|
2011-10-27 10:20:46 +02:00
|
|
|
|
2011-10-13 09:38:10 +02:00
|
|
|
class kolab_config extends rcube_plugin
|
|
|
|
{
|
|
|
|
public $task = 'utils';
|
|
|
|
|
|
|
|
private $enabled;
|
2012-05-23 14:41:32 +02:00
|
|
|
private $default;
|
|
|
|
private $folders;
|
|
|
|
private $dicts = array();
|
2011-10-13 09:38:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Required startup method of a Roundcube plugin
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
2012-10-17 11:54:25 +02:00
|
|
|
$rcmail = rcube::get_instance();
|
2011-10-13 09:38:10 +02:00
|
|
|
|
|
|
|
// Register spellchecker dictionary handlers
|
|
|
|
if (strtolower($rcmail->config->get('spellcheck_dictionary')) != 'shared') {
|
|
|
|
$this->add_hook('spell_dictionary_save', array($this, 'dictionary_save'));
|
|
|
|
$this->add_hook('spell_dictionary_get', array($this, 'dictionary_get'));
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
// Register addressbook saved searches handlers
|
|
|
|
$this->add_hook('saved_search_create', array($this, 'saved_search_create'));
|
|
|
|
$this->add_hook('saved_search_delete', array($this, 'saved_search_delete'));
|
|
|
|
$this->add_hook('saved_search_list', array($this, 'saved_search_list'));
|
|
|
|
$this->add_hook('saved_search_get', array($this, 'saved_search_get'));
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes config object and dependencies
|
|
|
|
*/
|
|
|
|
private function load()
|
|
|
|
{
|
2012-05-23 14:41:32 +02:00
|
|
|
// nothing to be done here
|
|
|
|
if (isset($this->folders))
|
2011-10-13 09:38:10 +02:00
|
|
|
return;
|
|
|
|
|
2012-05-09 17:20:39 +02:00
|
|
|
$this->require_plugin('libkolab');
|
2011-10-13 09:38:10 +02:00
|
|
|
|
2012-05-23 14:41:32 +02:00
|
|
|
$this->folders = kolab_storage::get_folders('configuration');
|
2013-05-07 12:16:11 +02:00
|
|
|
foreach ($this->folders as $folder) {
|
2012-05-23 14:41:32 +02:00
|
|
|
if ($folder->default) {
|
|
|
|
$this->default = $folder;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no folder is set as default, choose the first one
|
|
|
|
if (!$this->default)
|
2012-11-02 13:46:00 +01:00
|
|
|
$this->default = reset($this->folders);
|
2011-10-13 09:38:10 +02:00
|
|
|
|
|
|
|
// check if configuration folder exist
|
2012-05-23 14:41:32 +02:00
|
|
|
if ($this->default && $this->default->name) {
|
2011-10-13 09:38:10 +02:00
|
|
|
$this->enabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves spellcheck dictionary.
|
|
|
|
*
|
|
|
|
* @param array $args Hook arguments
|
|
|
|
*
|
|
|
|
* @return array Hook arguments
|
|
|
|
*/
|
|
|
|
public function dictionary_save($args)
|
|
|
|
{
|
|
|
|
$this->load();
|
|
|
|
|
|
|
|
if (!$this->enabled) {
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
|
|
|
$lang = $args['language'];
|
2012-05-23 14:41:32 +02:00
|
|
|
$dict = $this->read_dictionary($lang, true);
|
2012-06-06 10:45:06 +02:00
|
|
|
|
2011-10-13 09:38:10 +02:00
|
|
|
$dict['type'] = 'dictionary';
|
|
|
|
$dict['language'] = $args['language'];
|
|
|
|
$dict['e'] = $args['dictionary'];
|
|
|
|
|
|
|
|
if (empty($dict['e'])) {
|
|
|
|
// Delete the object
|
2012-05-23 14:41:32 +02:00
|
|
|
$this->default->delete($dict);
|
2011-10-13 09:38:10 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Update the object
|
2012-06-06 10:24:28 +02:00
|
|
|
$this->default->save($dict, 'configuration.dictionary', $dict['uid']);
|
2011-10-13 09:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$args['abort'] = true;
|
|
|
|
|
2012-05-23 14:41:32 +02:00
|
|
|
return $args;
|
2011-10-13 09:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns spellcheck dictionary.
|
|
|
|
*
|
|
|
|
* @param array $args Hook arguments
|
|
|
|
*
|
|
|
|
* @return array Hook arguments
|
|
|
|
*/
|
|
|
|
public function dictionary_get($args)
|
|
|
|
{
|
|
|
|
$this->load();
|
|
|
|
|
|
|
|
if (!$this->enabled) {
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
|
|
|
$lang = $args['language'];
|
2012-05-23 14:41:32 +02:00
|
|
|
$dict = $this->read_dictionary($lang);
|
2011-10-13 09:38:10 +02:00
|
|
|
|
2012-05-23 14:41:32 +02:00
|
|
|
if (!empty($dict)) {
|
|
|
|
$args['dictionary'] = (array)$dict['e'];
|
2011-10-13 09:38:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$args['abort'] = true;
|
|
|
|
|
2012-05-23 14:41:32 +02:00
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load dictionary config objects from Kolab storage
|
|
|
|
*
|
|
|
|
* @param string The language (2 chars) to load
|
|
|
|
* @param boolean Only load objects from default folder
|
|
|
|
* @return array Dictionary object as hash array
|
|
|
|
*/
|
|
|
|
private function read_dictionary($lang, $default = false)
|
|
|
|
{
|
|
|
|
if (isset($this->dicts[$lang]))
|
|
|
|
return $this->dicts[$lang];
|
|
|
|
|
2014-06-02 23:34:53 +02:00
|
|
|
$query = array(array('type','=','dictionary'), array('tags','=',$lang));
|
2012-05-23 14:41:32 +02:00
|
|
|
|
|
|
|
foreach ($this->folders as $folder) {
|
|
|
|
// we only want to read from default folder
|
|
|
|
if ($default && !$folder->default)
|
|
|
|
continue;
|
|
|
|
|
2014-02-06 17:30:40 +01:00
|
|
|
foreach ($folder->select($query) as $object) {
|
2012-05-23 15:41:13 +02:00
|
|
|
if ($object['type'] == 'dictionary' && ($object['language'] == $lang || $object['language'] == 'XX')) {
|
2012-05-23 14:41:32 +02:00
|
|
|
if (is_array($this->dicts[$lang]))
|
|
|
|
$this->dicts[$lang]['e'] = array_merge((array)$this->dicts[$lang]['e'], $object['e']);
|
|
|
|
else
|
|
|
|
$this->dicts[$lang] = $object;
|
|
|
|
|
|
|
|
// make sure the default object is cached
|
2012-05-23 15:41:13 +02:00
|
|
|
if ($folder->default && $object['language'] != 'XX') {
|
2012-05-23 14:41:32 +02:00
|
|
|
$object['e'] = $this->dicts[$lang]['e'];
|
|
|
|
$this->dicts[$lang] = $object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->dicts[$lang];
|
2011-10-13 09:38:10 +02:00
|
|
|
}
|
|
|
|
}
|