Skip to content

Commit 40e077e

Browse files
author
Jack Bates
committed
* Depth: header support
* Committing current WebDAV library
1 parent dfc4ff9 commit 40e077e

File tree

5 files changed

+439
-357
lines changed

5 files changed

+439
-357
lines changed

caldav.php

+32-27
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ function move(&$options) {
148148
return true;
149149
}
150150

151-
// FIXME Handle depth
152151
// FIXME Use file_exists
153152
function propfind($options, &$files) {
154153
$files = array();
155-
$paths = array();
156-
$path = $options['path'];
157-
while (isset($path)) {
154+
$paths = array(array($options['path'], 0));
155+
while (!empty($paths)) {
156+
list ($path, $depth) = array_pop($paths);
157+
158158
$file = array();
159159
$file['path'] = $path;
160160

@@ -168,26 +168,28 @@ function propfind($options, &$files) {
168168
if (is_dir($absolutePath)) {
169169
$file['props'][] = $this->mkprop('resourcetype', 'collection');
170170

171-
$handle = opendir($absolutePath);
172-
if (!$handle) {
173-
return;
174-
}
171+
if ($depth < $options['depth']) {
172+
$handle = opendir($absolutePath);
173+
if (!$handle) {
174+
return;
175+
}
175176

176-
while (($pathComponent = readdir($handle)) !== false) {
177-
if ($pathComponent != '.' && $pathComponent != '..') {
178-
$paths[] = $path != '' ? "$path/$pathComponent" :
179-
$pathComponent;
177+
while (($pathComponent = readdir($handle)) !== false) {
178+
if ($pathComponent != '.' && $pathComponent != '..') {
179+
$paths[] = array($path != '' ?
180+
"$path/$pathComponent" : $pathComponent,
181+
$depth + 1);
182+
}
180183
}
184+
closedir($handle);
181185
}
182-
closedir($handle);
183186
} else {
184187
$file['props'][] = $this->mkprop('getcontentlength',
185188
$stat['size']);
186189
$file['props'][] = $this->mkprop('resourcetype', null);
187190
}
188191

189192
$files[] = $file;
190-
$path = array_pop($paths);
191193
}
192194

193195
return true;
@@ -211,9 +213,10 @@ function put(&$options) {
211213

212214
function report($options, &$files) {
213215
$files = array();
214-
$paths = array();
215-
$path = $options['path'];
216-
while (isset($path)) {
216+
$paths = array(array($options['path'], 0));
217+
while (!empty($paths)) {
218+
list ($path, $depth) = array_pop($paths);
219+
217220
$file = array();
218221
$file['path'] = $path;
219222

@@ -227,26 +230,28 @@ function report($options, &$files) {
227230
if (is_dir($absolutePath)) {
228231
$file['props'][] = $this->mkprop('resourcetype', 'collection');
229232

230-
$handle = opendir($absolutePath);
231-
if (!$handle) {
232-
return;
233-
}
233+
if ($depth < $options['depth']) {
234+
$handle = opendir($absolutePath);
235+
if (!$handle) {
236+
return;
237+
}
234238

235-
while (($pathComponent = readdir($handle)) !== false) {
236-
if ($pathComponent != '.' && $pathComponent != '..') {
237-
$paths[] = $path != '' ? "$path/$pathComponent" :
238-
$pathComponent;
239+
while (($pathComponent = readdir($handle)) !== false) {
240+
if ($pathComponent != '.' && $pathComponent != '..') {
241+
$paths[] = array($path != '' ?
242+
"$path/$pathComponent" : $pathComponent,
243+
$depth + 1);
244+
}
239245
}
246+
closedir($handle);
240247
}
241-
closedir($handle);
242248
} else {
243249
$file['props'][] = $this->mkprop('getcontentlength',
244250
$stat['size']);
245251
$file['props'][] = $this->mkprop('resourcetype', null);
246252
}
247253

248254
$files[] = $file;
249-
$path = array_pop($paths);
250255
}
251256

252257
return true;

0 commit comments

Comments
 (0)