Prepare to handle configuration objects
This commit is contained in:
parent
de40ba8950
commit
2cd801f7d0
3 changed files with 100 additions and 14 deletions
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Kolab XML handler for configuration (KEP:9).
|
||||
*
|
||||
* @author Aleksander Machniak <machniak@kolabsys.com>
|
||||
*
|
||||
* Copyright (C) 2011, Kolab Systems AG <contact@kolabsys.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
class Horde_Kolab_Format_XML_configuration extends Horde_Kolab_Format_XML {
|
||||
/**
|
||||
* Specific data fields for the configuration object
|
||||
*
|
||||
* @var Kolab
|
||||
*/
|
||||
var $_fields_specific;
|
||||
|
||||
var $_root_version = 2.1;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function Horde_Kolab_Format_XML_configuration($params = array())
|
||||
{
|
||||
$this->_root_name = 'configuration';
|
||||
|
||||
// Specific configuration fields, in kolab format specification order
|
||||
$this->_fields_specific = array(
|
||||
'application' => array (
|
||||
'type' => HORDE_KOLAB_XML_TYPE_STRING,
|
||||
'value' => HORDE_KOLAB_XML_VALUE_MAYBE_MISSING,
|
||||
),
|
||||
'type' => array(
|
||||
'type' => HORDE_KOLAB_XML_TYPE_STRING,
|
||||
'value' => HORDE_KOLAB_XML_VALUE_NOT_EMPTY,
|
||||
),
|
||||
);
|
||||
|
||||
// Dictionary fields
|
||||
if (!empty($params['subtype']) && preg_match('/^dictionary.*/', $params['subtype'])) {
|
||||
$this->_fields_specific = array_merge($this->_fields_specific, array(
|
||||
'language' => array (
|
||||
'type' => HORDE_KOLAB_XML_TYPE_STRING,
|
||||
'value' => HORDE_KOLAB_XML_VALUE_NOT_EMPTY,
|
||||
),
|
||||
'e' => array(
|
||||
'type' => HORDE_KOLAB_XML_TYPE_MULTIPLE,
|
||||
'value' => HORDE_KOLAB_XML_VALUE_NOT_EMPTY,
|
||||
'array' => array(
|
||||
'type' => HORDE_KOLAB_XML_TYPE_STRING,
|
||||
'value' => HORDE_KOLAB_XML_VALUE_NOT_EMPTY,
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
parent::Horde_Kolab_Format_XML($params);
|
||||
|
||||
unset($this->_fields_basic['body']);
|
||||
unset($this->_fields_basic['categories']);
|
||||
unset($this->_fields_basic['sensitivity']);
|
||||
}
|
||||
}
|
|
@ -51,12 +51,13 @@ abstract class kolab_format
|
|||
if (!isset(self::$timezone))
|
||||
self::$timezone = new DateTimeZone('UTC');
|
||||
|
||||
$type = preg_replace('/configuration\.[a-z.]+$/', 'configuration', $type);
|
||||
$suffix = preg_replace('/[^a-z]+/', '', $type);
|
||||
$classname = 'kolab_format_' . $suffix;
|
||||
if (class_exists($classname))
|
||||
return new $classname($xmldata);
|
||||
|
||||
return PEAR::raiseError(sprintf("Failed to load Kolab Format wrapper for type %s", $type));
|
||||
return PEAR::raiseError("Failed to load Kolab Format wrapper for type " . $type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,8 +38,14 @@ class kolab_storage_folder
|
|||
public $type;
|
||||
|
||||
/**
|
||||
* The attached cache object
|
||||
* @var kolab_storage_cache
|
||||
* Is this folder set to be the default for its type
|
||||
* @var boolean
|
||||
*/
|
||||
public $default = false;
|
||||
|
||||
/**
|
||||
* Is this folder set to be default
|
||||
* @var boolean
|
||||
*/
|
||||
public $cache;
|
||||
|
||||
|
@ -69,16 +75,19 @@ class kolab_storage_folder
|
|||
* @param string The folder name/path
|
||||
* @param string Optional folder type if known
|
||||
*/
|
||||
public function set_folder($name, $type = null)
|
||||
public function set_folder($name, $ftype = null)
|
||||
{
|
||||
if (!$type) {
|
||||
if (!$ftype) {
|
||||
$metadata = $this->imap->get_metadata($name, array(kolab_storage::CTYPE_KEY));
|
||||
$type = $metadata[$name][kolab_storage::CTYPE_KEY];
|
||||
$this->type_annotation = $metadata[$name][kolab_storage::CTYPE_KEY];
|
||||
}
|
||||
else {
|
||||
$this->type_annotation = $ftype;
|
||||
}
|
||||
|
||||
list($this->type, $suffix) = explode('.', $this->type_annotation);
|
||||
$this->default = $suffix == 'default';
|
||||
$this->name = $name;
|
||||
$this->type_annotation = $type;
|
||||
$this->type = reset(explode('.', $type));
|
||||
$this->resource_uri = null;
|
||||
|
||||
$this->imap->set_folder($this->name);
|
||||
|
@ -216,7 +225,6 @@ class kolab_storage_folder
|
|||
return $this->resource_uri;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check subscription status of this folder
|
||||
*
|
||||
|
@ -388,7 +396,7 @@ class kolab_storage_folder
|
|||
$this->imap->set_folder($folder);
|
||||
|
||||
$headers = $this->imap->get_message_headers($msguid);
|
||||
$object_type = substr($headers->others['x-kolab-type'], strlen(self::KTYPE_PREFIX));
|
||||
$object_type = preg_replace('/dictionary.[a-z]+$/', 'dictionary', substr($headers->others['x-kolab-type'], strlen(self::KTYPE_PREFIX)));
|
||||
$content_type = self::KTYPE_PREFIX . $object_type;
|
||||
|
||||
// check object type header and abort on mismatch
|
||||
|
@ -430,9 +438,10 @@ class kolab_storage_folder
|
|||
return false;
|
||||
|
||||
// check kolab format version
|
||||
if (strpos($xml, '<' . $object_type) !== false) {
|
||||
list($xmltype, $subtype) = explode('.', $object_type);
|
||||
if (strpos($xml, '<' . $xmltype) !== false) {
|
||||
// old Kolab 2.0 format detected
|
||||
$handler = class_exists('Horde_Kolab_Format') ? Horde_Kolab_Format::factory('XML', $object_type) : null;
|
||||
$handler = class_exists('Horde_Kolab_Format') ? Horde_Kolab_Format::factory('XML', $xmltype, array('subtype' => $subtype)) : null;
|
||||
if (!is_object($handler) || is_a($handler, 'PEAR_Error')) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue