From 2cd801f7d0e779c1518e296dfc2740707f0c0c2c Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 23 May 2012 14:34:08 +0200 Subject: [PATCH] Prepare to handle configuration objects --- .../Horde_Kolab_Format_XML_configuration.php | 76 +++++++++++++++++++ plugins/libkolab/lib/kolab_format.php | 3 +- plugins/libkolab/lib/kolab_storage_folder.php | 35 +++++---- 3 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 plugins/libkolab/lib/Horde_Kolab_Format_XML_configuration.php diff --git a/plugins/libkolab/lib/Horde_Kolab_Format_XML_configuration.php b/plugins/libkolab/lib/Horde_Kolab_Format_XML_configuration.php new file mode 100644 index 00000000..c80fbd3d --- /dev/null +++ b/plugins/libkolab/lib/Horde_Kolab_Format_XML_configuration.php @@ -0,0 +1,76 @@ + + * + * 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 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 . + */ +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']); + } +} diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php index b7ce0578..883eb7fd 100644 --- a/plugins/libkolab/lib/kolab_format.php +++ b/plugins/libkolab/lib/kolab_format.php @@ -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); } /** diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php index da0718a8..3d4c168e 100644 --- a/plugins/libkolab/lib/kolab_storage_folder.php +++ b/plugins/libkolab/lib/kolab_storage_folder.php @@ -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,17 +75,20 @@ 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; } - $this->name = $name; - $this->type_annotation = $type; - $this->type = reset(explode('.', $type)); - $this->resource_uri = null; + list($this->type, $suffix) = explode('.', $this->type_annotation); + $this->default = $suffix == 'default'; + $this->name = $name; + $this->resource_uri = null; $this->imap->set_folder($this->name); $this->cache->set_folder($this); @@ -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; }