1: <?php
2: /**
3: * Implementation for IMAP folder annotations in the Kolab XML format.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Format
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://www.horde.org/libraries/Horde_Kolab_Format
12: */
13:
14: /**
15: * Kolab XML handler for IMAP folder annotations.
16: *
17: * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you did not
20: * receive this file, see
21: * http://www.horde.org/licenses/lgpl21.
22: *
23: * @category Kolab
24: * @package Kolab_Format
25: * @author Gunnar Wrobel <wrobel@pardus.de>
26: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
27: * @link http://www.horde.org/libraries/Horde_Kolab_Format
28: */
29: class Horde_Kolab_Format_Xml_Annotation extends Horde_Kolab_Format_Xml
30: {
31: /**
32: * The name of the root element.
33: *
34: * @var string
35: */
36: protected $_root_name = 'annotations';
37:
38: /**
39: * Specific data fields for the prefs object
40: *
41: * @var Kolab
42: */
43: protected $_fields_specific = array(
44: 'annotation' => 'Horde_Kolab_Format_Xml_Type_Multiple_String',
45: );
46:
47: /**
48: * Load the groupware object based on the specifc XML values.
49: *
50: * @param array &$children An array of XML nodes.
51: *
52: * @return array Array with the object data
53: *
54: * @throws Horde_Kolab_Format_Exception If parsing the XML data failed.
55: */
56: protected function _load(&$children)
57: {
58: $object = $this->_loadArray($children, $this->_fields_specific);
59:
60: $result = array();
61: foreach ($object['annotation'] as $annotation) {
62: list($key, $value) = split('#', $annotation, 2);
63: $result[base64_decode($key)] = base64_decode($value);
64: }
65:
66: return $result;
67: }
68:
69: /**
70: * Save the specific XML values.
71: *
72: * @param array $root The XML document root.
73: * @param array $object The resulting data array.
74: *
75: * @return boolean True on success.
76: *
77: * @throws Horde_Kolab_Format_Exception If converting the data to XML failed.
78: */
79: protected function _save(&$root, $object)
80: {
81: $annotations = array();
82: foreach ($object as $key => $value) {
83: if ($key != 'uid') {
84: $annotations['annotation'][] = base64_encode($key) .
85: '#' . base64_encode($value);
86: }
87: }
88:
89: return $this->_saveArray($root, $annotations, $this->_fields_specific);
90: }
91: }
92: