diff --git a/addressbook/inc/class.addressbook_groupdav.inc.php b/addressbook/inc/class.addressbook_groupdav.inc.php index 01b03250ff..39f93fc189 100644 --- a/addressbook/inc/class.addressbook_groupdav.inc.php +++ b/addressbook/inc/class.addressbook_groupdav.inc.php @@ -328,6 +328,21 @@ class addressbook_groupdav extends groupdav_handler /** * Add extra properties for addressbook collections * + * Example for supported-report-set syntax from Apples Calendarserver: + * + * + * + * + * + * + * + * + * + * + * + * + * @link http://www.mail-archive.com/calendarserver-users@lists.macosforge.org/msg01156.html + * * @param array $props=array() regular props by the groupdav handler * @return array */ @@ -335,8 +350,12 @@ class addressbook_groupdav extends groupdav_handler { // supported reports (required property for CardDAV) $props[] = HTTP_WebDAV_Server::mkprop('supported-report-set',array( - HTTP_WebDAV_Server::mkprop('supported-report','addressbook-query'), - HTTP_WebDAV_Server::mkprop('supported-report','addressbook-multiget'), + HTTP_WebDAV_Server::mkprop('supported-report',array( + HTTP_WebDAV_Server::mkprop('report', + HTTP_WebDAV_Server::mkprop(groupdav::CARDDAV,'addressbook-query','')))), + HTTP_WebDAV_Server::mkprop('supported-report',array( + HTTP_WebDAV_Server::mkprop('report', + HTTP_WebDAV_Server::mkprop(groupdav::CARDDAV,'addressbook-multiget','')))), )); return $props; } diff --git a/egw-pear/HTTP/WebDAV/Server.php b/egw-pear/HTTP/WebDAV/Server.php index e68691c3cf..94dd2170a6 100644 --- a/egw-pear/HTTP/WebDAV/Server.php +++ b/egw-pear/HTTP/WebDAV/Server.php @@ -757,44 +757,6 @@ class HTTP_WebDAV_Server . gmdate("D, d M Y H:i:s ", $prop['val']) . "GMT\n"; break; - case "resourcetype": - case "supported-report-set": - if (!is_array($prop['val'])) { - echo " \n"; - } else { // multiple resourcetypes from different namespaces as required by GroupDAV - $vals = $extra_ns = ''; - foreach($prop['val'] as $subprop) - { - if ($subprop['ns'] && $subprop['ns'] != 'DAV:') { - // register property namespace if not known yet - if (!isset($ns_hash[$subprop['ns']])) { - $ns_name = "ns".(count($ns_hash) + 1); - $ns_hash[$subprop['ns']] = $ns_name; - } else { - $ns_name = $ns_hash[$subprop['ns']]; - } - if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) { - $extra_ns .= $extra; - } - $ns_name .= ':'; - } elseif ($subprop['ns'] == 'DAV:') { - $ns_name = 'D:'; - } else { - $ns_name = ''; - } - // check if $prop[val] should be returned as attribute or value - if ($subprop['name'] == $subprop['val'] || - $subprop['name'] == $prop['name']) { - $vals .= "<$ns_name$subprop[val]/>"; - } else { - $vals .= "<$ns_name$subprop[name]>$subprop[val]"; - } - } - echo " $vals\n"; - //error_log(array2string($prop)); - //error_log("$vals"); - } - break; case "supportedlock": echo " $prop[val]\n"; break; @@ -804,10 +766,11 @@ class HTTP_WebDAV_Server echo " \n"; break; default: - if (is_array($prop['val'])) error_log($file['path'].': '.$prop['name'].'='.array2string($prop['val'])); - echo " " - . $this->_prop_encode(htmlspecialchars($prop['val'])) - . "\n"; + echo " ". + (is_array($prop['val']) ? + $this->_hierarchical_prop_encode($prop['val']) : + $this->_prop_encode(htmlspecialchars($prop['val']))). + "\n"; break; } } else { @@ -2122,6 +2085,45 @@ class HTTP_WebDAV_Server return urldecode($path); } + /** + * Encode a hierarchical properties like: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * @param array $props + * @return string + */ + function _hierarchical_prop_encode(array $props) + { + //error_log(__METHOD__.'('.array2string($props).')'); + if (isset($props['name'])) $props = array($props); + + $ret = ''; + foreach($props as $prop) + { + $ret .= '<'.$prop['name']. + ($prop['ns'] != 'DAV:' ? ' xmlns="'.$prop['ns'].'"' : ''). + (empty($prop['val']) ? ' />' : '>'. + (is_array($prop['val']) ? + $this->_hierarchical_prop_encode($prop['val']) : + $this->_prop_encode($prop['val'])). + ''); + } + //error_log(__METHOD__.'('.array2string($props).') = '.array2string($ret)); + return $ret; + } + /** * UTF-8 encode property values if not already done so * diff --git a/phpgwapi/inc/class.groupdav.inc.php b/phpgwapi/inc/class.groupdav.inc.php index ddc2044b1f..f4fa71d256 100644 --- a/phpgwapi/inc/class.groupdav.inc.php +++ b/phpgwapi/inc/class.groupdav.inc.php @@ -275,13 +275,13 @@ class groupdav extends HTTP_WebDAV_Server if ($prop == 'resourcetype') { $resourcetype = array( - self::mkprop('collection','collection'), + self::mkprop('collection',''), ); if (!$no_extra_types) { foreach($this->root[$app]['resourcetype'] as $ns => $type) { - $resourcetype[] = self::mkprop($ns,'resourcetype', $type); + $resourcetype[] = self::mkprop($ns,$type,''); } } $props[] = self::mkprop('resourcetype',$resourcetype); @@ -389,7 +389,7 @@ class groupdav extends HTTP_WebDAV_Server { if (!isset($collection_props)) { - $collection_props = self::props2array($file['props']); + $collection_props = $this->props2array($file['props']); echo '

'.lang('Collection listing').': '.htmlspecialchars($collection_props['DAV:displayname'])."

\n"; continue; // own entry --> displaying properies later } @@ -398,7 +398,7 @@ class groupdav extends HTTP_WebDAV_Server echo "\n\t\n"; } - $props = self::props2array($file['props']); + $props = $this->props2array($file['props']); //echo $file['path']; _debug_array($props); $class = $class == 'row_on' ? 'row_off' : 'row_on'; if (substr($file['path'],-1) == '/') @@ -448,13 +448,13 @@ class groupdav extends HTTP_WebDAV_Server * @param mixed $value * @return string */ - protected static function prop_value($value) + protected function prop_value($value) { if (is_array($value)) { if (isset($value[0]['ns'])) { - $value = self::props2array($value); + $value = $this->_hierarchical_prop_encode($value); } $value = htmlspecialchars(array2string($value)); } @@ -475,7 +475,7 @@ class groupdav extends HTTP_WebDAV_Server * @param array $props * @return array */ - protected static function props2array(array $props) + protected function props2array(array $props) { $arr = array(); foreach($props as $prop) @@ -497,16 +497,8 @@ class groupdav extends HTTP_WebDAV_Server default: $ns = $prop['ns']; } - // allow multiple values for same name - if (isset($arr[$ns.':'.$prop['name']])) - { - $arr[$ns.':'.$prop['name']] = (array)$arr[$ns.':'.$prop['name']]; - $arr[$ns.':'.$prop['name']][] = $prop['val']; - } - else - { - $arr[$ns.':'.$prop['name']] = $prop['val']; - } + $arr[$ns.':'.$prop['name']] = is_array($prop['val']) ? + $this->_hierarchical_prop_encode($prop['val']) : $prop['val']; } return $arr; }
#".lang('Name')."".lang('Size')."".lang('Last modified')."". lang('ETag')."".lang('Content type')."".lang('Resource type')."