From 8db20b966f5bdf29b87a559acb115b3ec913f692 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sat, 20 Mar 2010 01:05:05 +1300 Subject: [PATCH] Handle resourcetypes regardless of XML format. --- inc/DAVResource.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/inc/DAVResource.php b/inc/DAVResource.php index d0b279b2..f2e67bf8 100644 --- a/inc/DAVResource.php +++ b/inc/DAVResource.php @@ -246,7 +246,7 @@ class DAVResource $this->resourcetypes = ''; } else if ( $this->_is_proxy_request ) { - $this->resourcetypes = sprintf('', $this->collection->proxy_type ); + $this->resourcetypes = $this->collection->resourcetypes; } if ( isset($this->collection->dav_displayname) ) $this->collection->displayname = $this->collection->dav_displayname; } @@ -456,7 +456,9 @@ EOSQL; $this->resourcetypes = $this->collection->resourcetypes; else { $this->resourcetypes = ''; - if ( $this->_is_principal ) $this->resourcetypes .= ''; + if ( $this->_is_principal ) $this->resourcetypes .= ''; + if ( $this->_is_addressbook ) $this->resourcetypes .= ''; + if ( $this->_is_calendar ) $this->resourcetypes .= ''; } } } @@ -1135,8 +1137,16 @@ EOQRY; case 'resourcetype': if ( isset($this->resourcetypes) ) { - $this->resourcetypes = preg_replace('{^<(.*)/>$}', '$1', $this->resourcetypes); - $type_list = explode('/><', $this->resourcetypes); + $this->resourcetypes = preg_replace('{^\s*<(.*)/>\s*$}', '$1', $this->resourcetypes); + $type_list = preg_split('{(/>\s*<|\n)}', $this->resourcetypes); + foreach( $type_list AS $k => $resourcetype ) { + if ( preg_match( '{^([^:]+):([^:]+) \s+ xmlns:([^=]+)="([^"]+)" \s* $}x', $resourcetype, $matches ) ) { + $type_list[$k] = $matches[4] .':' .$matches[2]; + } + else if ( preg_match( '{^([^:]+) \s+ xmlns="([^"]+)" \s* $}x', $resourcetype, $matches ) ) { + $type_list[$k] = $matches[2] .':' .$matches[1]; + } + } return $type_list; }