mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-24 17:04:14 +01:00
fixed supported-report-set according to a calendarserver example and reorganized HTTP_WebDAV_Server to generally support hierachical properties
This commit is contained in:
parent
46f3d19e1c
commit
c1fa9f5cf4
@ -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:
|
||||
* <D:supported-report-set>
|
||||
* <supported-report>
|
||||
* <report>
|
||||
* <addressbook-query xmlns='urn:ietf:params:xml:ns:carddav'/>
|
||||
* </report>
|
||||
* </supported-report>
|
||||
* <supported-report>
|
||||
* <report>
|
||||
* <addressbook-multiget xmlns='urn:ietf:params:xml:ns:carddav'/>
|
||||
* </report>
|
||||
* </supported-report>
|
||||
* </D:supported-report-set>
|
||||
* @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;
|
||||
}
|
||||
|
@ -757,44 +757,6 @@ class HTTP_WebDAV_Server
|
||||
. gmdate("D, d M Y H:i:s ", $prop['val'])
|
||||
. "GMT</D:getlastmodified>\n";
|
||||
break;
|
||||
case "resourcetype":
|
||||
case "supported-report-set":
|
||||
if (!is_array($prop['val'])) {
|
||||
echo " <D:$prop[name]><D:$prop[val]/></D:$prop[name]>\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]</$ns_name$subprop[name]>";
|
||||
}
|
||||
}
|
||||
echo " <D:$prop[name]$extra_ns>$vals</D:$prop[name]>\n";
|
||||
//error_log(array2string($prop));
|
||||
//error_log("<D:$prop[name]$extra_ns>$vals</D:$prop[name]>");
|
||||
}
|
||||
break;
|
||||
case "supportedlock":
|
||||
echo " <D:supportedlock>$prop[val]</D:supportedlock>\n";
|
||||
break;
|
||||
@ -804,10 +766,11 @@ class HTTP_WebDAV_Server
|
||||
echo " </D:lockdiscovery>\n";
|
||||
break;
|
||||
default:
|
||||
if (is_array($prop['val'])) error_log($file['path'].': '.$prop['name'].'='.array2string($prop['val']));
|
||||
echo " <D:$prop[name]>"
|
||||
. $this->_prop_encode(htmlspecialchars($prop['val']))
|
||||
. "</D:$prop[name]>\n";
|
||||
echo " <D:$prop[name]>".
|
||||
(is_array($prop['val']) ?
|
||||
$this->_hierarchical_prop_encode($prop['val']) :
|
||||
$this->_prop_encode(htmlspecialchars($prop['val']))).
|
||||
"</D:$prop[name]>\n";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -2122,6 +2085,45 @@ class HTTP_WebDAV_Server
|
||||
return urldecode($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a hierarchical properties like:
|
||||
*
|
||||
* <D:supported-report-set>
|
||||
* <supported-report>
|
||||
* <report>
|
||||
* <addressbook-query xmlns='urn:ietf:params:xml:ns:carddav'/>
|
||||
* </report>
|
||||
* </supported-report>
|
||||
* <supported-report>
|
||||
* <report>
|
||||
* <addressbook-multiget xmlns='urn:ietf:params:xml:ns:carddav'/>
|
||||
* </report>
|
||||
* </supported-report>
|
||||
* </D:supported-report-set>
|
||||
*
|
||||
* @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'])).
|
||||
'</'.$prop['name'].'>');
|
||||
}
|
||||
//error_log(__METHOD__.'('.array2string($props).') = '.array2string($ret));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* UTF-8 encode property values if not already done so
|
||||
*
|
||||
|
@ -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 '<h3>'.lang('Collection listing').': '.htmlspecialchars($collection_props['DAV:displayname'])."</h3>\n";
|
||||
continue; // own entry --> displaying properies later
|
||||
}
|
||||
@ -398,7 +398,7 @@ class groupdav extends HTTP_WebDAV_Server
|
||||
echo "<table>\n\t<tr class='th'><th>#</th><th>".lang('Name')."</th><th>".lang('Size')."</th><th>".lang('Last modified')."</th><th>".
|
||||
lang('ETag')."</th><th>".lang('Content type')."</th><th>".lang('Resource type')."</th></tr>\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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user