From 40e077eb346693da15662632a90e5df0ff305046 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Fri, 14 Apr 2006 02:50:09 +0000 Subject: * Depth: header support * Committing current WebDAV library --- caldav.php | 59 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 27 deletions(-) (limited to 'caldav.php') diff --git a/caldav.php b/caldav.php index eb11ab7..d9c7ebc 100644 --- a/caldav.php +++ b/caldav.php @@ -148,13 +148,13 @@ class HTTP_CalDAV_Server_PHPiCalendar extends HTTP_CalDAV_Server { return true; } - // FIXME Handle depth // FIXME Use file_exists function propfind($options, &$files) { $files = array(); - $paths = array(); - $path = $options['path']; - while (isset($path)) { + $paths = array(array($options['path'], 0)); + while (!empty($paths)) { + list ($path, $depth) = array_pop($paths); + $file = array(); $file['path'] = $path; @@ -168,18 +168,21 @@ class HTTP_CalDAV_Server_PHPiCalendar extends HTTP_CalDAV_Server { if (is_dir($absolutePath)) { $file['props'][] = $this->mkprop('resourcetype', 'collection'); - $handle = opendir($absolutePath); - if (!$handle) { - return; - } + if ($depth < $options['depth']) { + $handle = opendir($absolutePath); + if (!$handle) { + return; + } - while (($pathComponent = readdir($handle)) !== false) { - if ($pathComponent != '.' && $pathComponent != '..') { - $paths[] = $path != '' ? "$path/$pathComponent" : - $pathComponent; + while (($pathComponent = readdir($handle)) !== false) { + if ($pathComponent != '.' && $pathComponent != '..') { + $paths[] = array($path != '' ? + "$path/$pathComponent" : $pathComponent, + $depth + 1); + } } + closedir($handle); } - closedir($handle); } else { $file['props'][] = $this->mkprop('getcontentlength', $stat['size']); @@ -187,7 +190,6 @@ class HTTP_CalDAV_Server_PHPiCalendar extends HTTP_CalDAV_Server { } $files[] = $file; - $path = array_pop($paths); } return true; @@ -211,9 +213,10 @@ class HTTP_CalDAV_Server_PHPiCalendar extends HTTP_CalDAV_Server { function report($options, &$files) { $files = array(); - $paths = array(); - $path = $options['path']; - while (isset($path)) { + $paths = array(array($options['path'], 0)); + while (!empty($paths)) { + list ($path, $depth) = array_pop($paths); + $file = array(); $file['path'] = $path; @@ -227,18 +230,21 @@ class HTTP_CalDAV_Server_PHPiCalendar extends HTTP_CalDAV_Server { if (is_dir($absolutePath)) { $file['props'][] = $this->mkprop('resourcetype', 'collection'); - $handle = opendir($absolutePath); - if (!$handle) { - return; - } + if ($depth < $options['depth']) { + $handle = opendir($absolutePath); + if (!$handle) { + return; + } - while (($pathComponent = readdir($handle)) !== false) { - if ($pathComponent != '.' && $pathComponent != '..') { - $paths[] = $path != '' ? "$path/$pathComponent" : - $pathComponent; + while (($pathComponent = readdir($handle)) !== false) { + if ($pathComponent != '.' && $pathComponent != '..') { + $paths[] = array($path != '' ? + "$path/$pathComponent" : $pathComponent, + $depth + 1); + } } + closedir($handle); } - closedir($handle); } else { $file['props'][] = $this->mkprop('getcontentlength', $stat['size']); @@ -246,7 +252,6 @@ class HTTP_CalDAV_Server_PHPiCalendar extends HTTP_CalDAV_Server { } $files[] = $file; - $path = array_pop($paths); } return true; -- cgit v1.2.3