Fixed folders discovery, fixed xml formatting in debug log
This commit is contained in:
parent
b74301fa2b
commit
f53ff8edec
2 changed files with 44 additions and 12 deletions
|
@ -120,7 +120,12 @@ class kolab_dav_client
|
||||||
*/
|
*/
|
||||||
public function discover($component = 'VEVENT')
|
public function discover($component = 'VEVENT')
|
||||||
{
|
{
|
||||||
/*
|
$roots = [
|
||||||
|
'VEVENT' => 'calendars',
|
||||||
|
'VTODO' => 'calendars',
|
||||||
|
'VCARD' => 'addressbooks',
|
||||||
|
];
|
||||||
|
|
||||||
$path = parse_url($this->url, PHP_URL_PATH);
|
$path = parse_url($this->url, PHP_URL_PATH);
|
||||||
|
|
||||||
$body = '<?xml version="1.0" encoding="utf-8"?>'
|
$body = '<?xml version="1.0" encoding="utf-8"?>'
|
||||||
|
@ -130,7 +135,7 @@ class kolab_dav_client
|
||||||
. '</d:prop>'
|
. '</d:prop>'
|
||||||
. '</d:propfind>';
|
. '</d:propfind>';
|
||||||
|
|
||||||
$response = $this->request('/calendars', 'PROPFIND', $body);
|
$response = $this->request('/' . $roots[$component], 'PROPFIND', $body);
|
||||||
|
|
||||||
$elements = $response->getElementsByTagName('response');
|
$elements = $response->getElementsByTagName('response');
|
||||||
|
|
||||||
|
@ -153,14 +158,25 @@ class kolab_dav_client
|
||||||
. '</d:propfind>';
|
. '</d:propfind>';
|
||||||
|
|
||||||
$response = $this->request($principal_href, 'PROPFIND', $body);
|
$response = $this->request($principal_href, 'PROPFIND', $body);
|
||||||
*/
|
|
||||||
$roots = [
|
|
||||||
'VEVENT' => 'calendars',
|
|
||||||
'VTODO' => 'calendars',
|
|
||||||
'VCARD' => 'addressbooks',
|
|
||||||
];
|
|
||||||
|
|
||||||
$principal_href = '/' . $roots[$component] . '/' . rawurlencode($this->user);
|
$elements = $response->getElementsByTagName('response');
|
||||||
|
|
||||||
|
foreach ($elements as $element) {
|
||||||
|
foreach ($element->getElementsByTagName('prop') as $prop) {
|
||||||
|
$root_href = $prop->nodeValue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($root_href)) {
|
||||||
|
if ($path && strpos($root_href, $path) === 0) {
|
||||||
|
$root_href = substr($root_href, strlen($path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Kolab iRony's calendar root
|
||||||
|
$root_href = '/' . $roots[$component] . '/' . rawurlencode($this->user);
|
||||||
|
}
|
||||||
|
|
||||||
$body = '<?xml version="1.0" encoding="utf-8"?>'
|
$body = '<?xml version="1.0" encoding="utf-8"?>'
|
||||||
. '<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:a="http://apple.com/ns/ical/">'
|
. '<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:a="http://apple.com/ns/ical/">'
|
||||||
|
@ -173,7 +189,7 @@ class kolab_dav_client
|
||||||
. '</d:prop>'
|
. '</d:prop>'
|
||||||
. '</d:propfind>';
|
. '</d:propfind>';
|
||||||
|
|
||||||
$response = $this->request($principal_href, 'PROPFIND', $body);
|
$response = $this->request($root_href, 'PROPFIND', $body);
|
||||||
|
|
||||||
if (empty($response)) {
|
if (empty($response)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -363,12 +379,13 @@ class kolab_dav_client
|
||||||
if (stripos($body, '<?xml') === 0) {
|
if (stripos($body, '<?xml') === 0) {
|
||||||
$doc = new DOMDocument('1.0', 'UTF-8');
|
$doc = new DOMDocument('1.0', 'UTF-8');
|
||||||
|
|
||||||
|
$doc->formatOutput = true;
|
||||||
|
$doc->preserveWhiteSpace = false;
|
||||||
|
|
||||||
if (!$doc->loadXML($body)) {
|
if (!$doc->loadXML($body)) {
|
||||||
throw new Exception("Failed to parse XML");
|
throw new Exception("Failed to parse XML");
|
||||||
}
|
}
|
||||||
|
|
||||||
$doc->formatOutput = true;
|
|
||||||
|
|
||||||
$body = $doc->saveXML();
|
$body = $doc->saveXML();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,12 +431,21 @@ class kolab_dav_client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$types = [];
|
||||||
|
if ($type_element = $element->getElementsByTagName('resourcetype')->item(0)) {
|
||||||
|
foreach ($type_element->childNodes as $node) {
|
||||||
|
$_type = explode(':', $node->nodeName);
|
||||||
|
$types[] = count($_type) > 1 ? $_type[1] : $_type[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'href' => $href,
|
'href' => $href,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'ctag' => $ctag,
|
'ctag' => $ctag,
|
||||||
'color' => $color,
|
'color' => $color,
|
||||||
'type' => $component,
|
'type' => $component,
|
||||||
|
'resource_type' => $types,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,12 @@ class kolab_storage_dav
|
||||||
|
|
||||||
if (is_array($folders)) {
|
if (is_array($folders)) {
|
||||||
foreach ($folders as $idx => $folder) {
|
foreach ($folders as $idx => $folder) {
|
||||||
|
// Exclude some special folders
|
||||||
|
if (in_array('schedule-inbox', $folder['resource_type']) || in_array('schedule-outbox', $folder['resource_type'])) {
|
||||||
|
unset($folders[$idx]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$folders[$idx] = new kolab_storage_dav_folder($this->dav, $folder, $type);
|
$folders[$idx] = new kolab_storage_dav_folder($this->dav, $folder, $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue