Passed
Push — 16.1 ( 9bf934...3870d9 )
by Nathan
16:16
created
api/src/WebDAV/Server.php 3 patches
Indentation   +2524 added lines, -2524 removed lines patch added patch discarded remove patch
@@ -48,632 +48,632 @@  discard block
 block discarded – undo
48 48
  */
49 49
 class HTTP_WebDAV_Server
50 50
 {
51
-    // {{{ Member Variables
51
+	// {{{ Member Variables
52 52
 
53
-    /**
54
-     * complete URI for this request
55
-     *
56
-     * @var string
57
-     */
58
-    var $uri;
53
+	/**
54
+	 * complete URI for this request
55
+	 *
56
+	 * @var string
57
+	 */
58
+	var $uri;
59 59
 
60
-    /**
61
-     * base URI for this request
62
-     *
63
-     * @var string
64
-     */
65
-    var $base_uri;
60
+	/**
61
+	 * base URI for this request
62
+	 *
63
+	 * @var string
64
+	 */
65
+	var $base_uri;
66 66
 
67
-    /**
68
-     * Set if client requires <D:href> to be a url (true) or a path (false).
69
-     * RFC 4918 allows both: http://www.webdav.org/specs/rfc4918.html#ELEMENT_href
70
-     * But some clients can NOT deal with one or the other!
71
-     *
72
-     * @var boolean
73
-     */
74
-    var $client_require_href_as_url;
75
-
76
-     /**
77
-     * Set if client requires or does not allow namespace redundacy.
78
-     * The XML Namespace specification does allow both
79
-     * But some clients can NOT deal with one or the other!
80
-     *
81
-     * $this->crrnd === false:
82
-     * <D:multistatus xmlns:D="DAV:">
83
-     *  <D:response xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
84
-     *   <D:href>/egroupware/webdav.php/home/ralf/</D:href>
85
-     *    <D:propstat>
86
-     *     <D:prop>
87
-     *      <D:resourcetype><D:collection /></D:resourcetype>
88
-     *     </D:prop>
89
-     *    <D:status>HTTP/1.1 200 OK</D:status>
90
-     *   </D:propstat>
91
-     *  </D:response>
92
-     * </D:multistatus>
93
-     *
94
-     * $this->crrnd === true:
95
-     * <multistatus xmlns="DAV:">
96
-     *  <response xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
97
-     *   <href>/egroupware/webdav.php/home/ralf/</href>
98
-     *    <propstat>
99
-     *     <prop>
100
-     *      <resourcetype><collection /></resourcetype>
101
-     *     </prop>
102
-     *    <status>HTTP/1.1 200 OK</status>
103
-     *   </propstat>
104
-     *  </response>
105
-     * </multistatus>
106
-     *
107
-     * @var boolean (client_refuses_redundand_namespace_declarations)
108
-     */
109
-    var $crrnd = false;
67
+	/**
68
+	 * Set if client requires <D:href> to be a url (true) or a path (false).
69
+	 * RFC 4918 allows both: http://www.webdav.org/specs/rfc4918.html#ELEMENT_href
70
+	 * But some clients can NOT deal with one or the other!
71
+	 *
72
+	 * @var boolean
73
+	 */
74
+	var $client_require_href_as_url;
75
+
76
+	 /**
77
+	  * Set if client requires or does not allow namespace redundacy.
78
+	  * The XML Namespace specification does allow both
79
+	  * But some clients can NOT deal with one or the other!
80
+	  *
81
+	  * $this->crrnd === false:
82
+	  * <D:multistatus xmlns:D="DAV:">
83
+	  *  <D:response xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
84
+	  *   <D:href>/egroupware/webdav.php/home/ralf/</D:href>
85
+	  *    <D:propstat>
86
+	  *     <D:prop>
87
+	  *      <D:resourcetype><D:collection /></D:resourcetype>
88
+	  *     </D:prop>
89
+	  *    <D:status>HTTP/1.1 200 OK</D:status>
90
+	  *   </D:propstat>
91
+	  *  </D:response>
92
+	  * </D:multistatus>
93
+	  *
94
+	  * $this->crrnd === true:
95
+	  * <multistatus xmlns="DAV:">
96
+	  *  <response xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/">
97
+	  *   <href>/egroupware/webdav.php/home/ralf/</href>
98
+	  *    <propstat>
99
+	  *     <prop>
100
+	  *      <resourcetype><collection /></resourcetype>
101
+	  *     </prop>
102
+	  *    <status>HTTP/1.1 200 OK</status>
103
+	  *   </propstat>
104
+	  *  </response>
105
+	  * </multistatus>
106
+	  *
107
+	  * @var boolean (client_refuses_redundand_namespace_declarations)
108
+	  */
109
+	var $crrnd = false;
110 110
 
111
-    /**
111
+	/**
112 112
 
113 113
 
114 114
     /**
115
-     * URI path for this request
116
-     *
117
-     * @var string
118
-     */
119
-    var $path;
115
+	 * URI path for this request
116
+	 *
117
+	 * @var string
118
+	 */
119
+	var $path;
120 120
 
121
-    /**
122
-     * Realm string to be used in authentification popups
123
-     *
124
-     * @var string
125
-     */
126
-    var $http_auth_realm = "PHP WebDAV";
121
+	/**
122
+	 * Realm string to be used in authentification popups
123
+	 *
124
+	 * @var string
125
+	 */
126
+	var $http_auth_realm = "PHP WebDAV";
127 127
 
128
-    /**
129
-     * String to be used in "X-Dav-Powered-By" header
130
-     *
131
-     * @var string
132
-     */
133
-    var $dav_powered_by = "";
128
+	/**
129
+	 * String to be used in "X-Dav-Powered-By" header
130
+	 *
131
+	 * @var string
132
+	 */
133
+	var $dav_powered_by = "";
134 134
 
135
-    /**
136
-     * Remember parsed If: (RFC2518/9.4) header conditions
137
-     *
138
-     * @var array
139
-     */
140
-    var $_if_header_uris = array();
135
+	/**
136
+	 * Remember parsed If: (RFC2518/9.4) header conditions
137
+	 *
138
+	 * @var array
139
+	 */
140
+	var $_if_header_uris = array();
141 141
 
142
-    /**
143
-     * HTTP response status/message
144
-     *
145
-     * @var string
146
-     */
147
-    var $_http_status = "200 OK";
142
+	/**
143
+	 * HTTP response status/message
144
+	 *
145
+	 * @var string
146
+	 */
147
+	var $_http_status = "200 OK";
148 148
 
149
-    /**
150
-     * encoding of property values passed in
151
-     *
152
-     * @var string
153
-     */
154
-    var $_prop_encoding = "utf-8";
149
+	/**
150
+	 * encoding of property values passed in
151
+	 *
152
+	 * @var string
153
+	 */
154
+	var $_prop_encoding = "utf-8";
155 155
 
156
-    /**
157
-     * Copy of $_SERVER superglobal array
158
-     *
159
-     * Derived classes may extend the constructor to
160
-     * modify its contents
161
-     *
162
-     * @var array
163
-     */
164
-    var $_SERVER;
156
+	/**
157
+	 * Copy of $_SERVER superglobal array
158
+	 *
159
+	 * Derived classes may extend the constructor to
160
+	 * modify its contents
161
+	 *
162
+	 * @var array
163
+	 */
164
+	var $_SERVER;
165 165
 
166
-    // }}}
166
+	// }}}
167 167
 
168
-    // {{{ Constructor
168
+	// {{{ Constructor
169 169
 
170
-    /**
171
-     * Constructor
172
-     *
173
-     * @param void
174
-     */
175
-    function __construct()
176
-    {
177
-        // PHP messages destroy XML output -> switch them off
178
-        ini_set("display_errors", 0);
179
-
180
-        // copy $_SERVER variables to local _SERVER array
181
-        // so that derived classes can simply modify these
182
-        $this->_SERVER = $_SERVER;
183
-    }
184
-
185
-    // }}}
186
-
187
-    // {{{ ServeRequest()
188
-    /**
189
-     * Serve WebDAV HTTP request
190
-     *
191
-     * dispatch WebDAV HTTP request to the apropriate method handler
192
-     *
193
-     * @param  $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php
194
-     * @return void
195
-     */
196
-    function ServeRequest($prefix=null)
197
-    {
198
-        // prevent warning in litmus check 'delete_fragment'
199
-        if (strstr($this->_SERVER["REQUEST_URI"], '#')) {
200
-            $this->http_status("400 Bad Request");
201
-            return;
202
-        }
203
-
204
-        // default is currently to use just the path, extending class can set $this->client_require_href_as_url depending on user-agent
205
-        if ($this->client_require_href_as_url)
206
-        {
207
-	        // default uri is the complete request uri
208
-	        $uri = (@$this->_SERVER["HTTPS"] === "on" ? "https:" : "http:") . '//'.$this->_SERVER['HTTP_HOST'];
209
-        }
210
-        $uri .= $this->_SERVER["SCRIPT_NAME"];
211
-
212
-        // WebDAV has no concept of a query string and clients (including cadaver)
213
-        // seem to pass '?' unencoded, so we need to extract the path info out
214
-        // of the request URI ourselves
215
-        // if request URI contains a full url, remove schema and domain
170
+	/**
171
+	 * Constructor
172
+	 *
173
+	 * @param void
174
+	 */
175
+	function __construct()
176
+	{
177
+		// PHP messages destroy XML output -> switch them off
178
+		ini_set("display_errors", 0);
179
+
180
+		// copy $_SERVER variables to local _SERVER array
181
+		// so that derived classes can simply modify these
182
+		$this->_SERVER = $_SERVER;
183
+	}
184
+
185
+	// }}}
186
+
187
+	// {{{ ServeRequest()
188
+	/**
189
+	 * Serve WebDAV HTTP request
190
+	 *
191
+	 * dispatch WebDAV HTTP request to the apropriate method handler
192
+	 *
193
+	 * @param  $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php
194
+	 * @return void
195
+	 */
196
+	function ServeRequest($prefix=null)
197
+	{
198
+		// prevent warning in litmus check 'delete_fragment'
199
+		if (strstr($this->_SERVER["REQUEST_URI"], '#')) {
200
+			$this->http_status("400 Bad Request");
201
+			return;
202
+		}
203
+
204
+		// default is currently to use just the path, extending class can set $this->client_require_href_as_url depending on user-agent
205
+		if ($this->client_require_href_as_url)
206
+		{
207
+			// default uri is the complete request uri
208
+			$uri = (@$this->_SERVER["HTTPS"] === "on" ? "https:" : "http:") . '//'.$this->_SERVER['HTTP_HOST'];
209
+		}
210
+		$uri .= $this->_SERVER["SCRIPT_NAME"];
211
+
212
+		// WebDAV has no concept of a query string and clients (including cadaver)
213
+		// seem to pass '?' unencoded, so we need to extract the path info out
214
+		// of the request URI ourselves
215
+		// if request URI contains a full url, remove schema and domain
216 216
 		$matches = null;
217
-        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$this->_SERVER["REQUEST_URI"], $matches))
218
-        {
219
-        	$path_info = $matches[1];
220
-        }
221
-        $path_info_raw = substr($path_info, strlen($this->_SERVER["SCRIPT_NAME"]));
222
-
223
-        // just in case the path came in empty ...
224
-        if (empty($path_info_raw)) {
225
-            $path_info_raw = "/";
226
-        }
227
-
228
-        $path_info = self::_urldecode($path_info_raw);
229
-
230
-        if ($prefix && strpos($path_info, $prefix) === 0)
231
-        {
232
-        	$uri .= $prefix;
233
-        	list(,$path_info) = explode($prefix, $path_info, 2);
234
-        }
235
-
236
-        $this->base_uri = $uri;
237
-        $this->uri      = $uri . $path_info;
238
-
239
-        // set path
240
-        // $_SERVER['PATH_INFO'] is already urldecoded
241
-        //$this->path = self::_urldecode($path_info);
242
-        // quote '#' (e.g. OpenOffice uses this for lock-files)
243
-        $this->path = strtr($path_info,array(
244
-        	'%' => '%25',
245
-        	'#' => '%23',
246
-        	'?' => '%3F',
247
-        ));
248
-        if (!strlen($this->path)) {
249
-            if ($this->_SERVER["REQUEST_METHOD"] == "GET") {
250
-                // redirect clients that try to GET a collection
251
-                // WebDAV clients should never try this while
252
-                // regular HTTP clients might ...
253
-                header("Location: ".$this->base_uri."/");
254
-                return;
255
-            } else {
256
-                // if a WebDAV client didn't give a path we just assume '/'
257
-                $this->path = "/";
258
-            }
259
-        }
260
-
261
-        if (ini_get("magic_quotes_gpc")) {
262
-            $this->path = stripslashes($this->path);
263
-        }
264
-
265
-
266
-        // identify ourselves
267
-        if (empty($this->dav_powered_by)) {
268
-            header("X-Dav-Powered-By: PHP class: ".get_class($this));
269
-        } else {
270
-            header("X-Dav-Powered-By: ".$this->dav_powered_by);
271
-        }
272
-
273
-        // check authentication
274
-        // for the motivation for not checking OPTIONS requests on / see
275
-        // http://pear.php.net/bugs/bug.php?id=5363
276
-        if ( (   !(($this->_SERVER['REQUEST_METHOD'] == 'OPTIONS') && ($this->path == "/")))
277
-             && (!$this->_check_auth())) {
278
-            // RFC2518 says we must use Digest instead of Basic
279
-            // but Microsoft Clients do not support Digest
280
-            // and we don't support NTLM and Kerberos
281
-            // so we are stuck with Basic here
282
-            header('WWW-Authenticate: Basic realm="'.($this->http_auth_realm).'"');
283
-
284
-            // Windows seems to require this being the last header sent
285
-            // (changed according to PECL bug #3138)
286
-            $this->http_status('401 Unauthorized');
287
-
288
-            return;
289
-        }
290
-
291
-        // check
292
-        if (! $this->_check_if_header_conditions()) {
293
-            return;
294
-        }
295
-
296
-        // detect requested method names
297
-        $method  = strtolower($this->_SERVER["REQUEST_METHOD"]);
298
-        $wrapper = "http_".$method;
299
-
300
-        // activate HEAD emulation by GET if no HEAD method found
301
-        if ($method == "head" && !method_exists($this, "head")) {
302
-            $method = "get";
303
-        }
304
-
305
-        if (method_exists($this, $wrapper) && ($method == "options" || method_exists($this, $method))) {
306
-            $this->$wrapper();  // call method by name
307
-        } else { // method not found/implemented
308
-            if ($this->_SERVER["REQUEST_METHOD"] == "LOCK") {
309
-            	$error = '412 Precondition failed';
310
-            } else {
311
-                $error = '405 Method not allowed';
312
-                header("Allow: ".join(", ", $this->_allow()));  // tell client what's allowed
313
-            }
314
-            $this->http_status($error);
315
-            echo "<html><head><title>Error $error</title></head>\n";
316
-            echo "<body><h1>$error</h1>\n";
317
-            echo "The requested could not by handled by this server.\n";
318
-            echo '(URI ' . $this->_SERVER['REQUEST_URI'] . ")<br>\n<br>\n";
319
-            echo "</body></html>\n";
320
-        }
321
-    }
322
-
323
-    // }}}
324
-
325
-    // {{{ abstract WebDAV methods
326
-
327
-    // {{{ GET()
328
-    /**
329
-     * GET implementation
330
-     *
331
-     * overload this method to retrieve resources from your server
332
-     * <br>
333
-     *
334
-     *
335
-     * @abstract
336
-     * @param array &$params Array of input and output parameters
337
-     * <br><b>input</b><ul>
338
-     * <li> path -
339
-     * </ul>
340
-     * <br><b>output</b><ul>
341
-     * <li> size -
342
-     * </ul>
343
-     * @returns int HTTP-Statuscode
344
-     */
345
-
346
-    /* abstract
217
+		if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$this->_SERVER["REQUEST_URI"], $matches))
218
+		{
219
+			$path_info = $matches[1];
220
+		}
221
+		$path_info_raw = substr($path_info, strlen($this->_SERVER["SCRIPT_NAME"]));
222
+
223
+		// just in case the path came in empty ...
224
+		if (empty($path_info_raw)) {
225
+			$path_info_raw = "/";
226
+		}
227
+
228
+		$path_info = self::_urldecode($path_info_raw);
229
+
230
+		if ($prefix && strpos($path_info, $prefix) === 0)
231
+		{
232
+			$uri .= $prefix;
233
+			list(,$path_info) = explode($prefix, $path_info, 2);
234
+		}
235
+
236
+		$this->base_uri = $uri;
237
+		$this->uri      = $uri . $path_info;
238
+
239
+		// set path
240
+		// $_SERVER['PATH_INFO'] is already urldecoded
241
+		//$this->path = self::_urldecode($path_info);
242
+		// quote '#' (e.g. OpenOffice uses this for lock-files)
243
+		$this->path = strtr($path_info,array(
244
+			'%' => '%25',
245
+			'#' => '%23',
246
+			'?' => '%3F',
247
+		));
248
+		if (!strlen($this->path)) {
249
+			if ($this->_SERVER["REQUEST_METHOD"] == "GET") {
250
+				// redirect clients that try to GET a collection
251
+				// WebDAV clients should never try this while
252
+				// regular HTTP clients might ...
253
+				header("Location: ".$this->base_uri."/");
254
+				return;
255
+			} else {
256
+				// if a WebDAV client didn't give a path we just assume '/'
257
+				$this->path = "/";
258
+			}
259
+		}
260
+
261
+		if (ini_get("magic_quotes_gpc")) {
262
+			$this->path = stripslashes($this->path);
263
+		}
264
+
265
+
266
+		// identify ourselves
267
+		if (empty($this->dav_powered_by)) {
268
+			header("X-Dav-Powered-By: PHP class: ".get_class($this));
269
+		} else {
270
+			header("X-Dav-Powered-By: ".$this->dav_powered_by);
271
+		}
272
+
273
+		// check authentication
274
+		// for the motivation for not checking OPTIONS requests on / see
275
+		// http://pear.php.net/bugs/bug.php?id=5363
276
+		if ( (   !(($this->_SERVER['REQUEST_METHOD'] == 'OPTIONS') && ($this->path == "/")))
277
+			 && (!$this->_check_auth())) {
278
+			// RFC2518 says we must use Digest instead of Basic
279
+			// but Microsoft Clients do not support Digest
280
+			// and we don't support NTLM and Kerberos
281
+			// so we are stuck with Basic here
282
+			header('WWW-Authenticate: Basic realm="'.($this->http_auth_realm).'"');
283
+
284
+			// Windows seems to require this being the last header sent
285
+			// (changed according to PECL bug #3138)
286
+			$this->http_status('401 Unauthorized');
287
+
288
+			return;
289
+		}
290
+
291
+		// check
292
+		if (! $this->_check_if_header_conditions()) {
293
+			return;
294
+		}
295
+
296
+		// detect requested method names
297
+		$method  = strtolower($this->_SERVER["REQUEST_METHOD"]);
298
+		$wrapper = "http_".$method;
299
+
300
+		// activate HEAD emulation by GET if no HEAD method found
301
+		if ($method == "head" && !method_exists($this, "head")) {
302
+			$method = "get";
303
+		}
304
+
305
+		if (method_exists($this, $wrapper) && ($method == "options" || method_exists($this, $method))) {
306
+			$this->$wrapper();  // call method by name
307
+		} else { // method not found/implemented
308
+			if ($this->_SERVER["REQUEST_METHOD"] == "LOCK") {
309
+				$error = '412 Precondition failed';
310
+			} else {
311
+				$error = '405 Method not allowed';
312
+				header("Allow: ".join(", ", $this->_allow()));  // tell client what's allowed
313
+			}
314
+			$this->http_status($error);
315
+			echo "<html><head><title>Error $error</title></head>\n";
316
+			echo "<body><h1>$error</h1>\n";
317
+			echo "The requested could not by handled by this server.\n";
318
+			echo '(URI ' . $this->_SERVER['REQUEST_URI'] . ")<br>\n<br>\n";
319
+			echo "</body></html>\n";
320
+		}
321
+	}
322
+
323
+	// }}}
324
+
325
+	// {{{ abstract WebDAV methods
326
+
327
+	// {{{ GET()
328
+	/**
329
+	 * GET implementation
330
+	 *
331
+	 * overload this method to retrieve resources from your server
332
+	 * <br>
333
+	 *
334
+	 *
335
+	 * @abstract
336
+	 * @param array &$params Array of input and output parameters
337
+	 * <br><b>input</b><ul>
338
+	 * <li> path -
339
+	 * </ul>
340
+	 * <br><b>output</b><ul>
341
+	 * <li> size -
342
+	 * </ul>
343
+	 * @returns int HTTP-Statuscode
344
+	 */
345
+
346
+	/* abstract
347 347
      function GET(&$params)
348 348
      {
349 349
      // dummy entry for PHPDoc
350 350
      }
351 351
     */
352 352
 
353
-    // }}}
353
+	// }}}
354 354
 
355
-    // {{{ PUT()
356
-    /**
357
-     * PUT implementation
358
-     *
359
-     * PUT implementation
360
-     *
361
-     * @abstract
362
-     * @param array &$params
363
-     * @returns int HTTP-Statuscode
364
-     */
365
-
366
-    /* abstract
355
+	// {{{ PUT()
356
+	/**
357
+	 * PUT implementation
358
+	 *
359
+	 * PUT implementation
360
+	 *
361
+	 * @abstract
362
+	 * @param array &$params
363
+	 * @returns int HTTP-Statuscode
364
+	 */
365
+
366
+	/* abstract
367 367
      function PUT()
368 368
      {
369 369
      // dummy entry for PHPDoc
370 370
      }
371 371
     */
372 372
 
373
-    // }}}
373
+	// }}}
374 374
 
375
-    // {{{ COPY()
375
+	// {{{ COPY()
376 376
 
377
-    /**
378
-     * COPY implementation
379
-     *
380
-     * COPY implementation
381
-     *
382
-     * @abstract
383
-     * @param array &$params
384
-     * @returns int HTTP-Statuscode
385
-     */
386
-
387
-    /* abstract
377
+	/**
378
+	 * COPY implementation
379
+	 *
380
+	 * COPY implementation
381
+	 *
382
+	 * @abstract
383
+	 * @param array &$params
384
+	 * @returns int HTTP-Statuscode
385
+	 */
386
+
387
+	/* abstract
388 388
      function COPY()
389 389
      {
390 390
      // dummy entry for PHPDoc
391 391
      }
392 392
     */
393 393
 
394
-    // }}}
394
+	// }}}
395 395
 
396
-    // {{{ MOVE()
396
+	// {{{ MOVE()
397 397
 
398
-    /**
399
-     * MOVE implementation
400
-     *
401
-     * MOVE implementation
402
-     *
403
-     * @abstract
404
-     * @param array &$params
405
-     * @returns int HTTP-Statuscode
406
-     */
407
-
408
-    /* abstract
398
+	/**
399
+	 * MOVE implementation
400
+	 *
401
+	 * MOVE implementation
402
+	 *
403
+	 * @abstract
404
+	 * @param array &$params
405
+	 * @returns int HTTP-Statuscode
406
+	 */
407
+
408
+	/* abstract
409 409
      function MOVE()
410 410
      {
411 411
      // dummy entry for PHPDoc
412 412
      }
413 413
     */
414 414
 
415
-    // }}}
415
+	// }}}
416 416
 
417
-    // {{{ DELETE()
417
+	// {{{ DELETE()
418 418
 
419
-    /**
420
-     * DELETE implementation
421
-     *
422
-     * DELETE implementation
423
-     *
424
-     * @abstract
425
-     * @param array &$params
426
-     * @returns int HTTP-Statuscode
427
-     */
428
-
429
-    /* abstract
419
+	/**
420
+	 * DELETE implementation
421
+	 *
422
+	 * DELETE implementation
423
+	 *
424
+	 * @abstract
425
+	 * @param array &$params
426
+	 * @returns int HTTP-Statuscode
427
+	 */
428
+
429
+	/* abstract
430 430
      function DELETE()
431 431
      {
432 432
      // dummy entry for PHPDoc
433 433
      }
434 434
     */
435
-    // }}}
435
+	// }}}
436 436
 
437
-    // {{{ PROPFIND()
437
+	// {{{ PROPFIND()
438 438
 
439
-    /**
440
-     * PROPFIND implementation
441
-     *
442
-     * PROPFIND implementation
443
-     *
444
-     * @abstract
445
-     * @param array &$params
446
-     * @returns int HTTP-Statuscode
447
-     */
448
-
449
-    /* abstract
439
+	/**
440
+	 * PROPFIND implementation
441
+	 *
442
+	 * PROPFIND implementation
443
+	 *
444
+	 * @abstract
445
+	 * @param array &$params
446
+	 * @returns int HTTP-Statuscode
447
+	 */
448
+
449
+	/* abstract
450 450
      function PROPFIND()
451 451
      {
452 452
      // dummy entry for PHPDoc
453 453
      }
454 454
     */
455 455
 
456
-    // }}}
456
+	// }}}
457 457
 
458
-    // {{{ PROPPATCH()
458
+	// {{{ PROPPATCH()
459 459
 
460
-    /**
461
-     * PROPPATCH implementation
462
-     *
463
-     * PROPPATCH implementation
464
-     *
465
-     * @abstract
466
-     * @param array &$params
467
-     * @returns int HTTP-Statuscode
468
-     */
469
-
470
-    /* abstract
460
+	/**
461
+	 * PROPPATCH implementation
462
+	 *
463
+	 * PROPPATCH implementation
464
+	 *
465
+	 * @abstract
466
+	 * @param array &$params
467
+	 * @returns int HTTP-Statuscode
468
+	 */
469
+
470
+	/* abstract
471 471
      function PROPPATCH()
472 472
      {
473 473
      // dummy entry for PHPDoc
474 474
      }
475 475
     */
476
-    // }}}
476
+	// }}}
477 477
 
478
-    // {{{ LOCK()
478
+	// {{{ LOCK()
479 479
 
480
-    /**
481
-     * LOCK implementation
482
-     *
483
-     * LOCK implementation
484
-     *
485
-     * @abstract
486
-     * @param array &$params
487
-     * @returns int HTTP-Statuscode
488
-     */
489
-
490
-    /* abstract
480
+	/**
481
+	 * LOCK implementation
482
+	 *
483
+	 * LOCK implementation
484
+	 *
485
+	 * @abstract
486
+	 * @param array &$params
487
+	 * @returns int HTTP-Statuscode
488
+	 */
489
+
490
+	/* abstract
491 491
      function LOCK()
492 492
      {
493 493
      // dummy entry for PHPDoc
494 494
      }
495 495
     */
496
-    // }}}
496
+	// }}}
497 497
 
498
-    // {{{ UNLOCK()
498
+	// {{{ UNLOCK()
499 499
 
500
-    /**
501
-     * UNLOCK implementation
502
-     *
503
-     * UNLOCK implementation
504
-     *
505
-     * @abstract
506
-     * @param array &$params
507
-     * @returns int HTTP-Statuscode
508
-     */
509
-
510
-    /* abstract
500
+	/**
501
+	 * UNLOCK implementation
502
+	 *
503
+	 * UNLOCK implementation
504
+	 *
505
+	 * @abstract
506
+	 * @param array &$params
507
+	 * @returns int HTTP-Statuscode
508
+	 */
509
+
510
+	/* abstract
511 511
      function UNLOCK()
512 512
      {
513 513
      // dummy entry for PHPDoc
514 514
      }
515 515
     */
516
-    // }}}
516
+	// }}}
517 517
 
518
-    // {{{ ACL()
518
+	// {{{ ACL()
519 519
 
520
-    /**
521
-     * ACL implementation
522
-     *
523
-     * ACL implementation
524
-     *
525
-     * @abstract
526
-     * @param array &$params
527
-     * @returns int HTTP-Statuscode
528
-     */
529
-
530
-    /* abstract
520
+	/**
521
+	 * ACL implementation
522
+	 *
523
+	 * ACL implementation
524
+	 *
525
+	 * @abstract
526
+	 * @param array &$params
527
+	 * @returns int HTTP-Statuscode
528
+	 */
529
+
530
+	/* abstract
531 531
      function ACL()
532 532
      {
533 533
      // dummy entry for PHPDoc
534 534
      }
535 535
     */
536
-    // }}}
536
+	// }}}
537 537
 
538
-    // }}}
538
+	// }}}
539 539
 
540
-    // {{{ other abstract methods
540
+	// {{{ other abstract methods
541 541
 
542
-    // {{{ check_auth()
542
+	// {{{ check_auth()
543 543
 
544
-    /**
545
-     * check authentication
546
-     *
547
-     * overload this method to retrieve and confirm authentication information
548
-     *
549
-     * @abstract
550
-     * @param string type Authentication type, e.g. "basic" or "digest"
551
-     * @param string username Transmitted username
552
-     * @param string passwort Transmitted password
553
-     * @returns bool Authentication status
554
-     */
555
-
556
-    /* abstract
544
+	/**
545
+	 * check authentication
546
+	 *
547
+	 * overload this method to retrieve and confirm authentication information
548
+	 *
549
+	 * @abstract
550
+	 * @param string type Authentication type, e.g. "basic" or "digest"
551
+	 * @param string username Transmitted username
552
+	 * @param string passwort Transmitted password
553
+	 * @returns bool Authentication status
554
+	 */
555
+
556
+	/* abstract
557 557
      function checkAuth($type, $username, $password)
558 558
      {
559 559
      // dummy entry for PHPDoc
560 560
      }
561 561
     */
562 562
 
563
-    // }}}
563
+	// }}}
564 564
 
565
-    // {{{ checklock()
565
+	// {{{ checklock()
566 566
 
567
-    /**
568
-     * check lock status for a resource
569
-     *
570
-     * overload this method to return shared and exclusive locks
571
-     * active for this resource
572
-     *
573
-     * @abstract
574
-     * @param string resource Resource path to check
575
-     * @returns array An array of lock entries each consisting
576
-     *                of 'type' ('shared'/'exclusive'), 'token' and 'timeout'
577
-     */
578
-
579
-    /* abstract
567
+	/**
568
+	 * check lock status for a resource
569
+	 *
570
+	 * overload this method to return shared and exclusive locks
571
+	 * active for this resource
572
+	 *
573
+	 * @abstract
574
+	 * @param string resource Resource path to check
575
+	 * @returns array An array of lock entries each consisting
576
+	 *                of 'type' ('shared'/'exclusive'), 'token' and 'timeout'
577
+	 */
578
+
579
+	/* abstract
580 580
      function checklock($resource)
581 581
      {
582 582
      // dummy entry for PHPDoc
583 583
      }
584 584
     */
585 585
 
586
-    // }}}
586
+	// }}}
587 587
 
588
-    // }}}
588
+	// }}}
589 589
 
590
-    // {{{ WebDAV HTTP method wrappers
590
+	// {{{ WebDAV HTTP method wrappers
591 591
 
592
-    // {{{ http_OPTIONS()
592
+	// {{{ http_OPTIONS()
593 593
 
594
-    /**
595
-     * OPTIONS method handler
596
-     *
597
-     * The OPTIONS method handler creates a valid OPTIONS reply
598
-     * including Dav: and Allowed: headers
599
-     * based on the implemented methods found in the actual instance
600
-     *
601
-     * @param  void
602
-     * @return void
603
-     */
604
-    function http_OPTIONS()
605
-    {
606
-        // Microsoft clients default to the Frontpage protocol
607
-        // unless we tell them to use WebDAV
608
-        header("MS-Author-Via: DAV");
609
-
610
-        // get allowed methods
611
-        $allow = $this->_allow();
612
-
613
-        // dav header
614
-        $dav = array(1);        // assume we are always dav class 1 compliant
615
-        if (isset($allow['LOCK'])) {
616
-            $dav[] = 2;         // dav class 2 requires that locking is supported
617
-        }
618
-
619
-        // allow extending class to modify DAV and Allow headers
594
+	/**
595
+	 * OPTIONS method handler
596
+	 *
597
+	 * The OPTIONS method handler creates a valid OPTIONS reply
598
+	 * including Dav: and Allowed: headers
599
+	 * based on the implemented methods found in the actual instance
600
+	 *
601
+	 * @param  void
602
+	 * @return void
603
+	 */
604
+	function http_OPTIONS()
605
+	{
606
+		// Microsoft clients default to the Frontpage protocol
607
+		// unless we tell them to use WebDAV
608
+		header("MS-Author-Via: DAV");
609
+
610
+		// get allowed methods
611
+		$allow = $this->_allow();
612
+
613
+		// dav header
614
+		$dav = array(1);        // assume we are always dav class 1 compliant
615
+		if (isset($allow['LOCK'])) {
616
+			$dav[] = 2;         // dav class 2 requires that locking is supported
617
+		}
618
+
619
+		// allow extending class to modify DAV and Allow headers
620 620
 		if (method_exists($this,'OPTIONS')) {
621 621
 			$this->OPTIONS($this->path,$dav,$allow);
622 622
 		}
623 623
 
624
-        // tell clients what we found
625
-        $this->http_status("200 OK");
626
-        header("DAV: "  .join(", ", $dav));
627
-        header("Allow: ".join(", ", $allow));
624
+		// tell clients what we found
625
+		$this->http_status("200 OK");
626
+		header("DAV: "  .join(", ", $dav));
627
+		header("Allow: ".join(", ", $allow));
628 628
 
629
-        header("Content-length: 0");
630
-    }
629
+		header("Content-length: 0");
630
+	}
631 631
 
632
-    // }}}
632
+	// }}}
633 633
 
634 634
 
635
-    // {{{ http_PROPFIND()
635
+	// {{{ http_PROPFIND()
636 636
 
637
-    /**
638
-     * Should the whole PROPFIND request (xml) be stored
639
-     *
640
-     * @var boolean
641
-     */
642
-    var $store_request = false;
643
-    /**
644
-     * Content of (last) PROPFIND request
645
-     *
646
-     * @var string
647
-     */
648
-    var $request;
637
+	/**
638
+	 * Should the whole PROPFIND request (xml) be stored
639
+	 *
640
+	 * @var boolean
641
+	 */
642
+	var $store_request = false;
643
+	/**
644
+	 * Content of (last) PROPFIND request
645
+	 *
646
+	 * @var string
647
+	 */
648
+	var $request;
649 649
 
650
-    /**
651
-     * PROPFIND method handler
652
-     *
653
-     * @param  string $handler ='PROPFIND' allows to use method eg. for CalDAV REPORT
654
-     * @return void
655
-     */
656
-    function http_PROPFIND($handler='PROPFIND')
657
-    {
658
-        $options = Array();
659
-        $files   = Array();
660
-
661
-        $options["path"] = $this->path;
662
-
663
-        // search depth from header (default is "infinity)
664
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
665
-            $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
666
-        } else {
667
-            $options["depth"] = "infinity";
668
-        }
669
-
670
-        // analyze request payload
671
-        $propinfo = new _parse_propfind("php://input", $this->store_request);
672
-        if ($this->store_request) $this->request = $propinfo->request;
673
-        if (!$propinfo->success) {
674
-            $this->http_status("400 Error");
675
-            return;
676
-        }
650
+	/**
651
+	 * PROPFIND method handler
652
+	 *
653
+	 * @param  string $handler ='PROPFIND' allows to use method eg. for CalDAV REPORT
654
+	 * @return void
655
+	 */
656
+	function http_PROPFIND($handler='PROPFIND')
657
+	{
658
+		$options = Array();
659
+		$files   = Array();
660
+
661
+		$options["path"] = $this->path;
662
+
663
+		// search depth from header (default is "infinity)
664
+		if (isset($this->_SERVER['HTTP_DEPTH'])) {
665
+			$options["depth"] = $this->_SERVER["HTTP_DEPTH"];
666
+		} else {
667
+			$options["depth"] = "infinity";
668
+		}
669
+
670
+		// analyze request payload
671
+		$propinfo = new _parse_propfind("php://input", $this->store_request);
672
+		if ($this->store_request) $this->request = $propinfo->request;
673
+		if (!$propinfo->success) {
674
+			$this->http_status("400 Error");
675
+			return;
676
+		}
677 677
 		$options['root'] = $propinfo->root;
678 678
 		$options['props'] = $propinfo->props;
679 679
 		if ($propinfo->filters)
@@ -681,34 +681,34 @@  discard block
 block discarded – undo
681 681
 		if ($propinfo->other)
682 682
 			$options['other'] = $propinfo->other;
683 683
 
684
-        // call user handler
685
-        if (!($retval =$this->$handler($options, $files))) {
686
-            $files = array("files" => array());
687
-            if (method_exists($this, "checkLock")) {
688
-                // is locked?
689
-                $lock = $this->checkLock($this->path);
690
-
691
-                if (is_array($lock) && count($lock)) {
692
-                    $created          = isset($lock['created'])  ? $lock['created']  : time();
693
-                    $modified         = isset($lock['modified']) ? $lock['modified'] : time();
694
-                    $files['files'][] = array("path"  => self::_slashify($this->path),
695
-                                              "props" => array($this->mkprop("displayname",      $this->path),
696
-                                                               $this->mkprop("creationdate",     $created),
697
-                                                               $this->mkprop("getlastmodified",  $modified),
698
-                                                               $this->mkprop("resourcetype",     ""),
699
-                                                               $this->mkprop("getcontenttype",   ""),
700
-                                                               $this->mkprop("getcontentlength", 0))
701
-                                              );
702
-                }
703
-            }
704
-
705
-            if (empty($files['files'])) {
706
-                $this->http_status("404 Not Found");
707
-                return;
708
-            }
709
-        }
710
-
711
-        // now we generate the reply header ...
684
+		// call user handler
685
+		if (!($retval =$this->$handler($options, $files))) {
686
+			$files = array("files" => array());
687
+			if (method_exists($this, "checkLock")) {
688
+				// is locked?
689
+				$lock = $this->checkLock($this->path);
690
+
691
+				if (is_array($lock) && count($lock)) {
692
+					$created          = isset($lock['created'])  ? $lock['created']  : time();
693
+					$modified         = isset($lock['modified']) ? $lock['modified'] : time();
694
+					$files['files'][] = array("path"  => self::_slashify($this->path),
695
+											  "props" => array($this->mkprop("displayname",      $this->path),
696
+															   $this->mkprop("creationdate",     $created),
697
+															   $this->mkprop("getlastmodified",  $modified),
698
+															   $this->mkprop("resourcetype",     ""),
699
+															   $this->mkprop("getcontenttype",   ""),
700
+															   $this->mkprop("getcontentlength", 0))
701
+											  );
702
+				}
703
+			}
704
+
705
+			if (empty($files['files'])) {
706
+				$this->http_status("404 Not Found");
707
+				return;
708
+			}
709
+		}
710
+
711
+		// now we generate the reply header ...
712 712
 		if ($retval === true)
713 713
 		{
714 714
 			$this->http_status('207 Multi-Status');
@@ -732,506 +732,506 @@  discard block
 block discarded – undo
732 732
 			return;
733 733
 		}
734 734
 		// dav header
735
-        $dav = array(1);        // assume we are always dav class 1 compliant
736
-        $allow = false;
735
+		$dav = array(1);        // assume we are always dav class 1 compliant
736
+		$allow = false;
737 737
 
738
-        // allow extending class to modify DAV
738
+		// allow extending class to modify DAV
739 739
 		if (method_exists($this,'OPTIONS')) {
740 740
 			$this->OPTIONS($this->path,$dav,$allow);
741 741
 		}
742
-        header("DAV: "  .join(", ", $dav));
743
-        header('Content-Type: text/xml; charset="utf-8"');
742
+		header("DAV: "  .join(", ", $dav));
743
+		header('Content-Type: text/xml; charset="utf-8"');
744 744
 
745
-        // add Vary and Preference-Applied header for Prefer: return=minimal
746
-        if (isset($this->_SERVER['HTTP_PREFER']) && in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER'])))
747
-        {
748
-        	header("Preference-Applied: return=minimal");
749
-        	header("Vary: Prefer");
750
-        }
751
-
752
-        // ... and payload
753
-        echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
754
-        echo $this->crrnd ? "<multistatus xmlns=\"DAV:\">\n" : "<D:multistatus xmlns:D=\"DAV:\">\n";
755
-
756
-        $this->multistatus_responses($files['files'], $options['props']);
757
-
758
-        // WebDAV sync report sync-token, can be either the sync-token or a callback (called with params in $files['sync-token-params'])
759
-        if (isset($files['sync-token']))
760
-        {
761
-            echo ($this->crrnd ? " <" : " <D:")."sync-token>".
762
-            	htmlspecialchars(!is_callable($files['sync-token']) ? $files['sync-token'] :
763
-            		call_user_func_array($files['sync-token'], (array)$files['sync-token-params'])).
764
-            	($this->crrnd ? "</" : "</D:")."sync-token>\n";
765
-        }
766
-
767
-        echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
768
-    }
769
-
770
-    /**
771
-     * Render (echo) XML for given multistatus responses
772
-     *
773
-     * @param array|Iterator $files
774
-     * @param array|string $props
775
-     */
776
-    function multistatus_responses(&$files, $props, $initial_ns_hash=null, $initial_ns_defs=null)
777
-    {
778
-    	if (!isset($initial_ns_hash)) $initial_ns_hash = array('DAV:' => 'D');
779
-    	if (!isset($initial_ns_defs)) $initial_ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';
780
-
781
-    	// using an ArrayIterator to prevent foreach from copying the array,
782
-        // as we cant loop by reference, when an iterator is given in $files
783
-        if (is_array($files))
784
-        {
785
-        	$files = new ArrayIterator($files);
786
-        }
787
-        // support for "Prefer: depth-noroot" header on PROPFIND
788
-        $skip_root = $this->_SERVER['REQUEST_METHOD'] == 'PROPFIND' &&
789
-        	!isset($initial_ns_hash) &&	// multistatus_response calls itself, do NOT apply skip in that case
790
-        	isset($this->_SERVER['HTTP_PREFER']) && in_array('depth-noroot', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER']));
791
-
792
-        // now we loop over all returned file entries
793
-        foreach ($files as $file) {
794
-
795
-        	// skip first element (root), if requested by Prefer: depth-noroot
796
-        	if ($skip_root) {
797
-        		$skip_root = false;
798
-        		continue;
799
-        	}
800
-
801
-	        // collect namespaces here
802
-	        $ns_hash = $initial_ns_hash;
803
-
804
-	        // Microsoft Clients need this special namespace for date and time values
805
-	        $ns_defs = $initial_ns_defs;
806
-
807
-            // nothing to do if no properties were returend for a file
808
-			if (isset($file["props"]) && is_array($file["props"])) {
809
-
810
-	            // now loop over all returned properties
811
-	            foreach ($file["props"] as &$prop) {
812
-	                // as a convenience feature we do not require that user handlers
813
-	                // restrict returned properties to the requested ones
814
-	                // here we strip all unrequested entries out of the response
815
-
816
-	            	// this can happen if we have allprop and prop in one propfind:
817
-	            	// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
818
-	                switch(is_array($props) ? $props[0] : $props) {
819
-	                case "all":
820
-	                    // nothing to remove
821
-	                    break;
822
-
823
-	                case "names":
824
-	                    // only the names of all existing properties were requested
825
-	                    // so we remove all values
826
-	                    unset($prop["val"]);
827
-	                    break;
828
-
829
-	                default:
830
-	                    $found = false;
831
-
832
-	                    // search property name in requested properties
833
-	                    foreach ((array)$props as $reqprop) {
834
-	                        if (   $reqprop["name"]  == $prop["name"]
835
-	                               && @$reqprop["xmlns"] == $prop["ns"]) {
836
-	                            $found = true;
837
-	                            break;
838
-	                        }
839
-	                    }
840
-
841
-	                    // unset property and continue with next one if not found/requested
842
-	                    if (!$found) {
843
-	                        $prop="";
844
-	                        continue(2);
845
-	                    }
846
-	                    break;
847
-	                }
848
-
849
-	                // namespace handling
850
-	                if (empty($prop["ns"])) continue; // no namespace
851
-	                $ns = $prop["ns"];
852
-	                //if ($ns == "DAV:") continue; // default namespace
853
-	                if (isset($ns_hash[$ns])) continue; // already known
854
-
855
-	                // register namespace
856
-	                $ns_name = "ns".(count($ns_hash) + 1);
857
-	                $ns_hash[$ns] = $ns_name;
858
-	                $ns_defs .= " xmlns:$ns_name=\"$ns\"";
859
-	            }
860
-
861
-	            // we also need to add empty entries for properties that were requested
862
-	            // but for which no values where returned by the user handler
863
-	            if (is_array($props)) {
864
-	                foreach ($props as $reqprop) {
865
-	                    if (!is_array($reqprop) || $reqprop['name']=="") continue; // skip empty entries, or 'all' if <allprop /> used together with <prop>
866
-
867
-	                    $found = false;
868
-
869
-	                    // check if property exists in result
870
-	                    foreach ($file["props"] as &$prop) {
871
-	                        if (is_array($prop) && $reqprop["name"] == $prop["name"]
872
-	                               && @$reqprop["xmlns"] == $prop["ns"]) {
873
-	                            $found = true;
874
-	                            break;
875
-	                        }
876
-	                    }
877
-
878
-	                    if (!$found) {
879
-	                        if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") {
880
-	                            // lockdiscovery is handled by the base class
881
-	                            $file["props"][]
882
-	                                = $this->mkprop("DAV:",
883
-	                                                "lockdiscovery",
884
-	                                                $this->lockdiscovery($file['path']));
885
-	                        // only collect $file['noprops'] if we have NO Brief: t and NO Prefer: return=minimal HTTP Header
886
-	                        } elseif ((!isset($this->_SERVER['HTTP_BRIEF']) || $this->_SERVER['HTTP_BRIEF'] != 't') &&
887
-	                        	(!isset($this->_SERVER['HTTP_PREFER']) || !in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER'])))) {
888
-	                            // add empty value for this property
889
-	                            $file["noprops"][] =
890
-	                                $this->mkprop($reqprop["xmlns"], $reqprop["name"], "");
891
-
892
-	                            // register property namespace if not known yet
893
-	                            if ($reqprop["xmlns"] != "DAV:" && !isset($ns_hash[$reqprop["xmlns"]])) {
894
-	                                $ns_name = "ns".(count($ns_hash) + 1);
895
-	                                $ns_hash[$reqprop["xmlns"]] = $ns_name;
896
-	                                $ns_defs .= " xmlns:$ns_name=\"$reqprop[xmlns]\"";
897
-	                            }
898
-	                        }
899
-	                    }
900
-	                }
901
-	            }
902
-	        }
903
-            // ignore empty or incomplete entries
904
-            if (!is_array($file) || empty($file) || !isset($file["path"])) continue;
905
-            $path = $file['path'];
906
-            if (!is_string($path) || $path==="") continue;
907
-
908
-            if ($this->crrnd)
909
-            {
910
-            	echo " <response $ns_defs>\n";
911
-            }
912
-            else
913
-            {
914
-            	echo " <D:response $ns_defs>\n";
915
-            }
916
-
917
-            /* TODO right now the user implementation has to make sure
918
-             collections end in a slash, this should be done in here
919
-             by checking the resource attribute */
920
-            $href_raw = $this->_mergePaths($this->base_uri, $path);
921
-
922
-            /* minimal urlencoding is needed for the resource path */
923
-            $href = $this->_urlencode($href_raw);
924
-
925
-            if ($this->crrnd)
926
-            {
927
-            	echo "  <href>$href</href>\n";
928
-            }
929
-            else
930
-            {
931
-            	echo "  <D:href>$href</D:href>\n";
932
-            }
933
-
934
-            // report all found properties and their values (if any)
935
-            if (isset($file["props"]) && is_array($file["props"])) {
936
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
937
-                echo '    <'.($this->crrnd?'':'D:')."prop>\n";
938
-
939
-                foreach ($file["props"] as &$prop) {
940
-
941
-                    if (!is_array($prop)) continue;
942
-                    if (!isset($prop["name"])) continue;
943
-
944
-                    if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) {
945
-                        // empty properties (cannot use empty() for check as "0" is a legal value here)
946
-                        if ($prop["ns"]=="DAV:") {
947
-                            echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
948
-                        } else if (!empty($prop["ns"])) {
949
-                            echo "     <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
950
-                        } else {
951
-                            echo "     <$prop[name] xmlns=\"\"/>";
952
-                        }
953
-                    }
954
-                    // multiple level of responses required for expand-property reports
955
-                    elseif(isset($prop['props']) && is_array($prop['val']))
956
-                    {
957
-                        if ($prop['ns'] && !isset($ns_hash[$prop['ns']])) {
958
-                            $ns_name = "ns".(count($ns_hash) + 1);
959
-                            $ns_hash[$prop['ns']] = $ns_name;
960
-                        }
961
-                    	echo '     <'.$ns_hash[$prop['ns']].":$prop[name]>\n";
962
-                        $this->multistatus_responses($prop['val'], $prop['props'], $ns_hash, '');
963
-                    	echo '     </'.$ns_hash[$prop['ns']].":$prop[name]>\n";
964
-                    } else if ($prop["ns"] == "DAV:") {
965
-                        // some WebDAV properties need special treatment
966
-                        switch ($prop["name"]) {
967
-                        case "creationdate":
968
-                            echo '     <'.($this->crrnd?'':'D:')."creationdate ns0:dt=\"dateTime.tz\">"
969
-                                . gmdate("Y-m-d\\TH:i:s\\Z", $prop['val'])
970
-                                . '</'.($this->crrnd?'':'D:')."creationdate>\n";
971
-                            break;
972
-                        case "getlastmodified":
973
-                            echo '     <'.($this->crrnd?'':'D:')."getlastmodified ns0:dt=\"dateTime.rfc1123\">"
974
-                                . gmdate("D, d M Y H:i:s ", $prop['val'])
975
-                                . "GMT</".($this->crrnd?'':'D:')."getlastmodified>\n";
976
-                            break;
977
-                        case "supportedlock":
978
-                            echo '     <'.($this->crrnd?'':'D:')."supportedlock>$prop[val]</".($this->crrnd?'':'D:')."supportedlock>\n";
979
-                            break;
980
-                        case "lockdiscovery":
981
-                            echo '     <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
982
-                            echo $prop["val"];
983
-                            echo '     </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
984
-                            break;
985
-                        // the following are non-standard Microsoft extensions to the DAV namespace
986
-                        case "lastaccessed":
987
-                            echo '     <'.($this->crrnd?'':'D:')."lastaccessed ns0:dt=\"dateTime.rfc1123\">"
988
-                                . gmdate("D, d M Y H:i:s ", $prop['val'])
989
-                                . 'GMT</'.($this->crrnd?'':'D:')."lastaccessed>\n";
990
-                            break;
991
-                        case "ishidden":
992
-                            echo '     <'.($this->crrnd?'':'D:')."ishidden>"
993
-                                . is_string($prop['val']) ? $prop['val'] : ($prop['val'] ? 'true' : 'false')
994
-                                . '</'.($this->crrnd?'':'D:')."</D:ishidden>\n";
995
-                            break;
996
-                        default:
997
-                        	$ns_defs = '';
998
-                            if (is_array($prop['val']))
999
-                            {
1000
-                            	$hns_hash = $ns_hash;
1001
-                            	$val = $this->_hierarchical_prop_encode($prop['val'], 'DAV:', $ns_defs, $hns_hash);
1002
-                            } elseif (isset($prop['raw'])) {
1003
-                            	$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
1004
-                            } else {
1005
-	                    		$val = $this->_prop_encode(htmlspecialchars($prop['val'], ENT_NOQUOTES, 'utf-8'));
1006
-                            }
1007
-	                        echo '     <'.($this->crrnd?'':'D:')."$prop[name]$ns_defs>$val".
1008
-	                        	'</'.($this->crrnd?'':'D:')."$prop[name]>\n";
1009
-                            break;
1010
-                        }
1011
-                    } else {
1012
-                        // allow multiple values and attributes, required eg. for caldav:supported-calendar-component-set
1013
-                        if ($prop['ns'] && is_array($prop['val'])) {
1014
-                    		if (!isset($ns_hash[$prop['ns']])) {
1015
-                                $ns_name = "ns".(count($ns_hash) + 1);
1016
-                                $ns_hash[$prop['ns']] = $ns_name;
1017
-                    		}
1018
-                  			$vals = $extra_ns = '';
1019
-                    		foreach($prop['val'] as $subprop)
1020
-                    		{
1021
-                    			if ($subprop['ns'] && $subprop['ns'] != 'DAV:') {
1022
-		                    		// register property namespace if not known yet
1023
-		                    		if (!isset($ns_hash[$subprop['ns']])) {
1024
-			                    		$ns_name = "ns".(count($ns_hash) + 1);
1025
-			                    		$ns_hash[$subprop['ns']] = $ns_name;
1026
-		                    		} else {
1027
-			                    		$ns_name = $ns_hash[$subprop['ns']];
1028
-		                    		}
1029
-		                    		if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) {
1030
-			                    		$extra_ns .= $extra;
1031
-		                    		}
1032
-		                    		$ns_name .= ':';
1033
-	                    		} elseif ($subprop['ns'] == 'DAV:') {
1034
-		                    		$ns_name = 'D:';
1035
-	                    		} else {
1036
-		                    		$ns_name = '';
1037
-	                    		}
1038
-	                    		$vals .= "<$ns_name$subprop[name]";
1039
-	                    		if (is_array($subprop['val']))
1040
-	                    		{
1041
-	                    			if (isset($subprop['val'][0]))
1042
-	                    			{
1043
-		                    			$vals .= '>';
1044
-		                    			$vals .= $this->_hierarchical_prop_encode($subprop['val'], $subprop['ns'], $ns_defs, $ns_hash);
1045
-			                    		$vals .= "</$ns_name$subprop[name]>";
1046
-	                    			}
1047
-	                    			else	// val contains only attributes, no value
1048
-	                    			{
1049
-			                    		foreach($subprop['val'] as $attr => $val)
1050
-										{
1051
-				                    		$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES, 'utf-8').'"';
1052
-										}
1053
-			                    		$vals .= '/>';
1054
-	                    			}
1055
-	                    		}
1056
-	                    		else
1057
-	                    		{
1058
-	                    			$vals .= '>';
1059
-	                    			if (isset($subprop['raw'])) {
1060
-	                    				$vals .= '<![CDATA['.$subprop['val'].']]>';
1061
-	                    			} else {
1062
-	                    				if($subprop['name'] == 'href') $subprop['val'] = $this->_urlencode($subprop['val']);
1063
-		                    			$vals .= htmlspecialchars($subprop['val'], ENT_NOQUOTES, 'utf-8');
1064
-	                    			}
1065
-	                    			$vals .= "</$ns_name$subprop[name]>";
1066
-	                    		}
1067
-                    		}
1068
-                    		echo '     <'.$ns_hash[$prop['ns']].":$prop[name]$extra_ns>$vals</".$ns_hash[$prop['ns']].":$prop[name]>\n";
1069
-                        } else {
1070
-                        	if ($prop['raw'])
1071
-                        	{
1072
-                        		$val = '<![CDATA['.$prop['val'].']]>';
1073
-                        	} else {
1074
-                        		$val = htmlspecialchars($prop['val'], ENT_NOQUOTES, 'utf-8');
1075
-                        	}
1076
-                        	$val = $this->_prop_encode($val);
1077
-	                        // properties from namespaces != "DAV:" or without any namespace
1078
-	                        if ($prop['ns']) {
1079
-		                        if ($this->crrnd) {
1080
-			                        echo "     <$prop[name] xmlns=".'"'.$prop["ns"].'">'
1081
-									. $val . "</$prop[name]>\n";
1082
-		                        } else {
1083
-			                        echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]>"
1084
-									. $val . '</'.$ns_hash[$prop['ns']].":$prop[name]>\n";
1085
-		                        }
1086
-	                        } else {
1087
-		                        echo "     <$prop[name] xmlns=\"\">$val</$prop[name]>\n";
1088
-	                        }
1089
-                        }
1090
-                    }
1091
-                }
1092
-
1093
-                if ($this->crrnd)
1094
-                {
1095
-	                echo "    </prop>\n";
1096
-	                echo "   <status>HTTP/1.1 200 OK</status>\n";
1097
-	                echo "  </propstat>\n";
1098
-                }
1099
-                else
1100
-                {
1101
-	                echo "    </D:prop>\n";
1102
-	                echo "   <D:status>HTTP/1.1 200 OK</D:status>\n";
1103
-	                echo "  </D:propstat>\n";
1104
-                }
1105
-            }
1106
-
1107
-            // now report all properties requested but not found
1108
-            if (isset($file["noprops"])) {
1109
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1110
-                echo '    <'.($this->crrnd?'':'D:')."prop>\n";
1111
-
1112
-                foreach ($file["noprops"] as &$prop) {
1113
-                    if ($prop["ns"] == "DAV:") {
1114
-                        echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
1115
-                    } else if ($prop["ns"] == "") {
1116
-                        echo "     <$prop[name] xmlns=\"\"/>\n";
1117
-                    } else {
1118
-                        echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]/>\n";
1119
-                    }
1120
-                }
1121
-
1122
-                if ($this->crrnd)
1123
-                {
1124
-	                echo "   </prop>\n";
1125
-	                echo "   <status>HTTP/1.1 404 Not Found</status>\n";
1126
-	                echo "  </propstat>\n";
1127
-                }
1128
-                else
1129
-                {
1130
-	                echo "   </D:prop>\n";
1131
-	                echo "   <D:status>HTTP/1.1 404 Not Found</D:status>\n";
1132
-	                echo "  </D:propstat>\n";
1133
-                }
1134
-            }
1135
-
1136
-            // 404 Not Found status element for WebDAV sync report
1137
-            if (!isset($file['props']) && !isset($file['noprops']))
1138
-            {
1139
-                if ($this->crrnd)
1140
-                {
1141
-	                echo "  <status>HTTP/1.1 404 Not Found</status>\n";
1142
-                }
1143
-                else
1144
-                {
1145
-	                echo "  <D:status>HTTP/1.1 404 Not Found</D:status>\n";
1146
-                }
1147
-            }
1148
-
1149
-            echo ' </'.($this->crrnd?'':'D:')."response>\n";
1150
-        }
1151
-    }
1152
-
1153
-
1154
-    // }}}
1155
-
1156
-    // {{{ http_PROPPATCH()
745
+		// add Vary and Preference-Applied header for Prefer: return=minimal
746
+		if (isset($this->_SERVER['HTTP_PREFER']) && in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER'])))
747
+		{
748
+			header("Preference-Applied: return=minimal");
749
+			header("Vary: Prefer");
750
+		}
1157 751
 
1158
-    /**
1159
-     * PROPPATCH method handler
1160
-     *
1161
-     * @param  void
1162
-     * @return void
1163
-     */
1164
-    function http_PROPPATCH()
1165
-    {
1166
-        if ($this->_check_lock_status($this->path)) {
1167
-            $options = Array();
752
+		// ... and payload
753
+		echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
754
+		echo $this->crrnd ? "<multistatus xmlns=\"DAV:\">\n" : "<D:multistatus xmlns:D=\"DAV:\">\n";
1168 755
 
1169
-            $options["path"] = $this->path;
756
+		$this->multistatus_responses($files['files'], $options['props']);
1170 757
 
1171
-            $propinfo = new _parse_proppatch("php://input", $this->store_request);
1172
-            if ($this->store_request) $this->request = $propinfo->request;
758
+		// WebDAV sync report sync-token, can be either the sync-token or a callback (called with params in $files['sync-token-params'])
759
+		if (isset($files['sync-token']))
760
+		{
761
+			echo ($this->crrnd ? " <" : " <D:")."sync-token>".
762
+				htmlspecialchars(!is_callable($files['sync-token']) ? $files['sync-token'] :
763
+					call_user_func_array($files['sync-token'], (array)$files['sync-token-params'])).
764
+				($this->crrnd ? "</" : "</D:")."sync-token>\n";
765
+		}
1173 766
 
1174
-            if (!$propinfo->success) {
1175
-                $this->http_status("400 Error");
1176
-                return;
1177
-            }
767
+		echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
768
+	}
1178 769
 
1179
-            $options['props'] = $propinfo->props;
770
+	/**
771
+	 * Render (echo) XML for given multistatus responses
772
+	 *
773
+	 * @param array|Iterator $files
774
+	 * @param array|string $props
775
+	 */
776
+	function multistatus_responses(&$files, $props, $initial_ns_hash=null, $initial_ns_defs=null)
777
+	{
778
+		if (!isset($initial_ns_hash)) $initial_ns_hash = array('DAV:' => 'D');
779
+		if (!isset($initial_ns_defs)) $initial_ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';
1180 780
 
1181
-            $responsedescr = $this->PROPPATCH($options);
781
+		// using an ArrayIterator to prevent foreach from copying the array,
782
+		// as we cant loop by reference, when an iterator is given in $files
783
+		if (is_array($files))
784
+		{
785
+			$files = new ArrayIterator($files);
786
+		}
787
+		// support for "Prefer: depth-noroot" header on PROPFIND
788
+		$skip_root = $this->_SERVER['REQUEST_METHOD'] == 'PROPFIND' &&
789
+			!isset($initial_ns_hash) &&	// multistatus_response calls itself, do NOT apply skip in that case
790
+			isset($this->_SERVER['HTTP_PREFER']) && in_array('depth-noroot', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER']));
791
+
792
+		// now we loop over all returned file entries
793
+		foreach ($files as $file) {
794
+
795
+			// skip first element (root), if requested by Prefer: depth-noroot
796
+			if ($skip_root) {
797
+				$skip_root = false;
798
+				continue;
799
+			}
1182 800
 
1183
-            $this->http_status("207 Multi-Status");
1184
-            header('Content-Type: text/xml; charset="utf-8"');
801
+			// collect namespaces here
802
+			$ns_hash = $initial_ns_hash;
1185 803
 
1186
-            echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
804
+			// Microsoft Clients need this special namespace for date and time values
805
+			$ns_defs = $initial_ns_defs;
1187 806
 
1188
-            echo "<D:multistatus xmlns:D=\"DAV:\">\n";
1189
-            echo ' <'.($this->crrnd?'':'D:')."response>\n";
1190
-            echo '  <'.($this->crrnd?'':'D:')."href>".$this->_urlencode($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)).'</'.($this->crrnd?'':'D:')."href>\n";
807
+			// nothing to do if no properties were returend for a file
808
+			if (isset($file["props"]) && is_array($file["props"])) {
1191 809
 
1192
-            foreach ($options["props"] as $prop) {
1193
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1194
-                echo '    <'.($this->crrnd?'':'D:')."prop><$prop[name] xmlns=\"$prop[ns]\"/></".($this->crrnd?'':'D:')."prop>\n";
1195
-                echo '    <'.($this->crrnd?'':'D:')."status>HTTP/1.1 $prop[status]</".($this->crrnd?'':'D:')."status>\n";
1196
-                echo '   </'.($this->crrnd?'':'D:')."propstat>\n";
1197
-            }
810
+				// now loop over all returned properties
811
+				foreach ($file["props"] as &$prop) {
812
+					// as a convenience feature we do not require that user handlers
813
+					// restrict returned properties to the requested ones
814
+					// here we strip all unrequested entries out of the response
815
+
816
+					// this can happen if we have allprop and prop in one propfind:
817
+					// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
818
+					switch(is_array($props) ? $props[0] : $props) {
819
+					case "all":
820
+						// nothing to remove
821
+						break;
822
+
823
+					case "names":
824
+						// only the names of all existing properties were requested
825
+						// so we remove all values
826
+						unset($prop["val"]);
827
+						break;
828
+
829
+					default:
830
+						$found = false;
831
+
832
+						// search property name in requested properties
833
+						foreach ((array)$props as $reqprop) {
834
+							if (   $reqprop["name"]  == $prop["name"]
835
+								   && @$reqprop["xmlns"] == $prop["ns"]) {
836
+								$found = true;
837
+								break;
838
+							}
839
+						}
1198 840
 
1199
-            if ($responsedescr) {
1200
-                echo '  <'.($this->crrnd?'':'D:')."responsedescription>".
1201
-                    $this->_prop_encode(htmlspecialchars($responsedescr, ENT_NOQUOTES, 'utf-8')).
1202
-                    '</'.($this->crrnd?'':'D:')."responsedescription>\n";
1203
-            }
841
+						// unset property and continue with next one if not found/requested
842
+						if (!$found) {
843
+							$prop="";
844
+							continue(2);
845
+						}
846
+						break;
847
+					}
1204 848
 
1205
-            echo ' </'.($this->crrnd?'':'D:')."response>\n";
1206
-            echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
1207
-        } else {
1208
-            $this->http_status("423 Locked");
1209
-        }
1210
-    }
849
+					// namespace handling
850
+					if (empty($prop["ns"])) continue; // no namespace
851
+					$ns = $prop["ns"];
852
+					//if ($ns == "DAV:") continue; // default namespace
853
+					if (isset($ns_hash[$ns])) continue; // already known
1211 854
 
1212
-    // }}}
855
+					// register namespace
856
+					$ns_name = "ns".(count($ns_hash) + 1);
857
+					$ns_hash[$ns] = $ns_name;
858
+					$ns_defs .= " xmlns:$ns_name=\"$ns\"";
859
+				}
1213 860
 
861
+				// we also need to add empty entries for properties that were requested
862
+				// but for which no values where returned by the user handler
863
+				if (is_array($props)) {
864
+					foreach ($props as $reqprop) {
865
+						if (!is_array($reqprop) || $reqprop['name']=="") continue; // skip empty entries, or 'all' if <allprop /> used together with <prop>
866
+
867
+						$found = false;
868
+
869
+						// check if property exists in result
870
+						foreach ($file["props"] as &$prop) {
871
+							if (is_array($prop) && $reqprop["name"] == $prop["name"]
872
+								   && @$reqprop["xmlns"] == $prop["ns"]) {
873
+								$found = true;
874
+								break;
875
+							}
876
+						}
1214 877
 
1215
-    // {{{ http_MKCOL()
878
+						if (!$found) {
879
+							if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") {
880
+								// lockdiscovery is handled by the base class
881
+								$file["props"][]
882
+									= $this->mkprop("DAV:",
883
+													"lockdiscovery",
884
+													$this->lockdiscovery($file['path']));
885
+							// only collect $file['noprops'] if we have NO Brief: t and NO Prefer: return=minimal HTTP Header
886
+							} elseif ((!isset($this->_SERVER['HTTP_BRIEF']) || $this->_SERVER['HTTP_BRIEF'] != 't') &&
887
+								(!isset($this->_SERVER['HTTP_PREFER']) || !in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER'])))) {
888
+								// add empty value for this property
889
+								$file["noprops"][] =
890
+									$this->mkprop($reqprop["xmlns"], $reqprop["name"], "");
891
+
892
+								// register property namespace if not known yet
893
+								if ($reqprop["xmlns"] != "DAV:" && !isset($ns_hash[$reqprop["xmlns"]])) {
894
+									$ns_name = "ns".(count($ns_hash) + 1);
895
+									$ns_hash[$reqprop["xmlns"]] = $ns_name;
896
+									$ns_defs .= " xmlns:$ns_name=\"$reqprop[xmlns]\"";
897
+								}
898
+							}
899
+						}
900
+					}
901
+				}
902
+			}
903
+			// ignore empty or incomplete entries
904
+			if (!is_array($file) || empty($file) || !isset($file["path"])) continue;
905
+			$path = $file['path'];
906
+			if (!is_string($path) || $path==="") continue;
1216 907
 
1217
-    /**
1218
-     * MKCOL method handler
1219
-     *
1220
-     * @param  void
1221
-     * @return void
1222
-     */
1223
-    function http_MKCOL()
1224
-    {
1225
-        $options = Array();
908
+			if ($this->crrnd)
909
+			{
910
+				echo " <response $ns_defs>\n";
911
+			}
912
+			else
913
+			{
914
+				echo " <D:response $ns_defs>\n";
915
+			}
1226 916
 
1227
-        $options["path"] = $this->path;
917
+			/* TODO right now the user implementation has to make sure
918
+             collections end in a slash, this should be done in here
919
+             by checking the resource attribute */
920
+			$href_raw = $this->_mergePaths($this->base_uri, $path);
1228 921
 
1229
-        $stat = $this->MKCOL($options);
922
+			/* minimal urlencoding is needed for the resource path */
923
+			$href = $this->_urlencode($href_raw);
1230 924
 
1231
-        $this->http_status($stat);
1232
-    }
925
+			if ($this->crrnd)
926
+			{
927
+				echo "  <href>$href</href>\n";
928
+			}
929
+			else
930
+			{
931
+				echo "  <D:href>$href</D:href>\n";
932
+			}
1233 933
 
1234
-    // }}}
934
+			// report all found properties and their values (if any)
935
+			if (isset($file["props"]) && is_array($file["props"])) {
936
+				echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
937
+				echo '    <'.($this->crrnd?'':'D:')."prop>\n";
938
+
939
+				foreach ($file["props"] as &$prop) {
940
+
941
+					if (!is_array($prop)) continue;
942
+					if (!isset($prop["name"])) continue;
943
+
944
+					if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) {
945
+						// empty properties (cannot use empty() for check as "0" is a legal value here)
946
+						if ($prop["ns"]=="DAV:") {
947
+							echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
948
+						} else if (!empty($prop["ns"])) {
949
+							echo "     <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
950
+						} else {
951
+							echo "     <$prop[name] xmlns=\"\"/>";
952
+						}
953
+					}
954
+					// multiple level of responses required for expand-property reports
955
+					elseif(isset($prop['props']) && is_array($prop['val']))
956
+					{
957
+						if ($prop['ns'] && !isset($ns_hash[$prop['ns']])) {
958
+							$ns_name = "ns".(count($ns_hash) + 1);
959
+							$ns_hash[$prop['ns']] = $ns_name;
960
+						}
961
+						echo '     <'.$ns_hash[$prop['ns']].":$prop[name]>\n";
962
+						$this->multistatus_responses($prop['val'], $prop['props'], $ns_hash, '');
963
+						echo '     </'.$ns_hash[$prop['ns']].":$prop[name]>\n";
964
+					} else if ($prop["ns"] == "DAV:") {
965
+						// some WebDAV properties need special treatment
966
+						switch ($prop["name"]) {
967
+						case "creationdate":
968
+							echo '     <'.($this->crrnd?'':'D:')."creationdate ns0:dt=\"dateTime.tz\">"
969
+								. gmdate("Y-m-d\\TH:i:s\\Z", $prop['val'])
970
+								. '</'.($this->crrnd?'':'D:')."creationdate>\n";
971
+							break;
972
+						case "getlastmodified":
973
+							echo '     <'.($this->crrnd?'':'D:')."getlastmodified ns0:dt=\"dateTime.rfc1123\">"
974
+								. gmdate("D, d M Y H:i:s ", $prop['val'])
975
+								. "GMT</".($this->crrnd?'':'D:')."getlastmodified>\n";
976
+							break;
977
+						case "supportedlock":
978
+							echo '     <'.($this->crrnd?'':'D:')."supportedlock>$prop[val]</".($this->crrnd?'':'D:')."supportedlock>\n";
979
+							break;
980
+						case "lockdiscovery":
981
+							echo '     <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
982
+							echo $prop["val"];
983
+							echo '     </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
984
+							break;
985
+						// the following are non-standard Microsoft extensions to the DAV namespace
986
+						case "lastaccessed":
987
+							echo '     <'.($this->crrnd?'':'D:')."lastaccessed ns0:dt=\"dateTime.rfc1123\">"
988
+								. gmdate("D, d M Y H:i:s ", $prop['val'])
989
+								. 'GMT</'.($this->crrnd?'':'D:')."lastaccessed>\n";
990
+							break;
991
+						case "ishidden":
992
+							echo '     <'.($this->crrnd?'':'D:')."ishidden>"
993
+								. is_string($prop['val']) ? $prop['val'] : ($prop['val'] ? 'true' : 'false')
994
+								. '</'.($this->crrnd?'':'D:')."</D:ishidden>\n";
995
+							break;
996
+						default:
997
+							$ns_defs = '';
998
+							if (is_array($prop['val']))
999
+							{
1000
+								$hns_hash = $ns_hash;
1001
+								$val = $this->_hierarchical_prop_encode($prop['val'], 'DAV:', $ns_defs, $hns_hash);
1002
+							} elseif (isset($prop['raw'])) {
1003
+								$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
1004
+							} else {
1005
+								$val = $this->_prop_encode(htmlspecialchars($prop['val'], ENT_NOQUOTES, 'utf-8'));
1006
+							}
1007
+							echo '     <'.($this->crrnd?'':'D:')."$prop[name]$ns_defs>$val".
1008
+								'</'.($this->crrnd?'':'D:')."$prop[name]>\n";
1009
+							break;
1010
+						}
1011
+					} else {
1012
+						// allow multiple values and attributes, required eg. for caldav:supported-calendar-component-set
1013
+						if ($prop['ns'] && is_array($prop['val'])) {
1014
+							if (!isset($ns_hash[$prop['ns']])) {
1015
+								$ns_name = "ns".(count($ns_hash) + 1);
1016
+								$ns_hash[$prop['ns']] = $ns_name;
1017
+							}
1018
+				  			$vals = $extra_ns = '';
1019
+							foreach($prop['val'] as $subprop)
1020
+							{
1021
+								if ($subprop['ns'] && $subprop['ns'] != 'DAV:') {
1022
+									// register property namespace if not known yet
1023
+									if (!isset($ns_hash[$subprop['ns']])) {
1024
+										$ns_name = "ns".(count($ns_hash) + 1);
1025
+										$ns_hash[$subprop['ns']] = $ns_name;
1026
+									} else {
1027
+										$ns_name = $ns_hash[$subprop['ns']];
1028
+									}
1029
+									if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) {
1030
+										$extra_ns .= $extra;
1031
+									}
1032
+									$ns_name .= ':';
1033
+								} elseif ($subprop['ns'] == 'DAV:') {
1034
+									$ns_name = 'D:';
1035
+								} else {
1036
+									$ns_name = '';
1037
+								}
1038
+								$vals .= "<$ns_name$subprop[name]";
1039
+								if (is_array($subprop['val']))
1040
+								{
1041
+									if (isset($subprop['val'][0]))
1042
+									{
1043
+										$vals .= '>';
1044
+										$vals .= $this->_hierarchical_prop_encode($subprop['val'], $subprop['ns'], $ns_defs, $ns_hash);
1045
+										$vals .= "</$ns_name$subprop[name]>";
1046
+									}
1047
+									else	// val contains only attributes, no value
1048
+									{
1049
+										foreach($subprop['val'] as $attr => $val)
1050
+										{
1051
+											$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES, 'utf-8').'"';
1052
+										}
1053
+										$vals .= '/>';
1054
+									}
1055
+								}
1056
+								else
1057
+								{
1058
+									$vals .= '>';
1059
+									if (isset($subprop['raw'])) {
1060
+										$vals .= '<![CDATA['.$subprop['val'].']]>';
1061
+									} else {
1062
+										if($subprop['name'] == 'href') $subprop['val'] = $this->_urlencode($subprop['val']);
1063
+										$vals .= htmlspecialchars($subprop['val'], ENT_NOQUOTES, 'utf-8');
1064
+									}
1065
+									$vals .= "</$ns_name$subprop[name]>";
1066
+								}
1067
+							}
1068
+							echo '     <'.$ns_hash[$prop['ns']].":$prop[name]$extra_ns>$vals</".$ns_hash[$prop['ns']].":$prop[name]>\n";
1069
+						} else {
1070
+							if ($prop['raw'])
1071
+							{
1072
+								$val = '<![CDATA['.$prop['val'].']]>';
1073
+							} else {
1074
+								$val = htmlspecialchars($prop['val'], ENT_NOQUOTES, 'utf-8');
1075
+							}
1076
+							$val = $this->_prop_encode($val);
1077
+							// properties from namespaces != "DAV:" or without any namespace
1078
+							if ($prop['ns']) {
1079
+								if ($this->crrnd) {
1080
+									echo "     <$prop[name] xmlns=".'"'.$prop["ns"].'">'
1081
+									. $val . "</$prop[name]>\n";
1082
+								} else {
1083
+									echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]>"
1084
+									. $val . '</'.$ns_hash[$prop['ns']].":$prop[name]>\n";
1085
+								}
1086
+							} else {
1087
+								echo "     <$prop[name] xmlns=\"\">$val</$prop[name]>\n";
1088
+							}
1089
+						}
1090
+					}
1091
+				}
1092
+
1093
+				if ($this->crrnd)
1094
+				{
1095
+					echo "    </prop>\n";
1096
+					echo "   <status>HTTP/1.1 200 OK</status>\n";
1097
+					echo "  </propstat>\n";
1098
+				}
1099
+				else
1100
+				{
1101
+					echo "    </D:prop>\n";
1102
+					echo "   <D:status>HTTP/1.1 200 OK</D:status>\n";
1103
+					echo "  </D:propstat>\n";
1104
+				}
1105
+			}
1106
+
1107
+			// now report all properties requested but not found
1108
+			if (isset($file["noprops"])) {
1109
+				echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1110
+				echo '    <'.($this->crrnd?'':'D:')."prop>\n";
1111
+
1112
+				foreach ($file["noprops"] as &$prop) {
1113
+					if ($prop["ns"] == "DAV:") {
1114
+						echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
1115
+					} else if ($prop["ns"] == "") {
1116
+						echo "     <$prop[name] xmlns=\"\"/>\n";
1117
+					} else {
1118
+						echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]/>\n";
1119
+					}
1120
+				}
1121
+
1122
+				if ($this->crrnd)
1123
+				{
1124
+					echo "   </prop>\n";
1125
+					echo "   <status>HTTP/1.1 404 Not Found</status>\n";
1126
+					echo "  </propstat>\n";
1127
+				}
1128
+				else
1129
+				{
1130
+					echo "   </D:prop>\n";
1131
+					echo "   <D:status>HTTP/1.1 404 Not Found</D:status>\n";
1132
+					echo "  </D:propstat>\n";
1133
+				}
1134
+			}
1135
+
1136
+			// 404 Not Found status element for WebDAV sync report
1137
+			if (!isset($file['props']) && !isset($file['noprops']))
1138
+			{
1139
+				if ($this->crrnd)
1140
+				{
1141
+					echo "  <status>HTTP/1.1 404 Not Found</status>\n";
1142
+				}
1143
+				else
1144
+				{
1145
+					echo "  <D:status>HTTP/1.1 404 Not Found</D:status>\n";
1146
+				}
1147
+			}
1148
+
1149
+			echo ' </'.($this->crrnd?'':'D:')."response>\n";
1150
+		}
1151
+	}
1152
+
1153
+
1154
+	// }}}
1155
+
1156
+	// {{{ http_PROPPATCH()
1157
+
1158
+	/**
1159
+	 * PROPPATCH method handler
1160
+	 *
1161
+	 * @param  void
1162
+	 * @return void
1163
+	 */
1164
+	function http_PROPPATCH()
1165
+	{
1166
+		if ($this->_check_lock_status($this->path)) {
1167
+			$options = Array();
1168
+
1169
+			$options["path"] = $this->path;
1170
+
1171
+			$propinfo = new _parse_proppatch("php://input", $this->store_request);
1172
+			if ($this->store_request) $this->request = $propinfo->request;
1173
+
1174
+			if (!$propinfo->success) {
1175
+				$this->http_status("400 Error");
1176
+				return;
1177
+			}
1178
+
1179
+			$options['props'] = $propinfo->props;
1180
+
1181
+			$responsedescr = $this->PROPPATCH($options);
1182
+
1183
+			$this->http_status("207 Multi-Status");
1184
+			header('Content-Type: text/xml; charset="utf-8"');
1185
+
1186
+			echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
1187
+
1188
+			echo "<D:multistatus xmlns:D=\"DAV:\">\n";
1189
+			echo ' <'.($this->crrnd?'':'D:')."response>\n";
1190
+			echo '  <'.($this->crrnd?'':'D:')."href>".$this->_urlencode($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)).'</'.($this->crrnd?'':'D:')."href>\n";
1191
+
1192
+			foreach ($options["props"] as $prop) {
1193
+				echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1194
+				echo '    <'.($this->crrnd?'':'D:')."prop><$prop[name] xmlns=\"$prop[ns]\"/></".($this->crrnd?'':'D:')."prop>\n";
1195
+				echo '    <'.($this->crrnd?'':'D:')."status>HTTP/1.1 $prop[status]</".($this->crrnd?'':'D:')."status>\n";
1196
+				echo '   </'.($this->crrnd?'':'D:')."propstat>\n";
1197
+			}
1198
+
1199
+			if ($responsedescr) {
1200
+				echo '  <'.($this->crrnd?'':'D:')."responsedescription>".
1201
+					$this->_prop_encode(htmlspecialchars($responsedescr, ENT_NOQUOTES, 'utf-8')).
1202
+					'</'.($this->crrnd?'':'D:')."responsedescription>\n";
1203
+			}
1204
+
1205
+			echo ' </'.($this->crrnd?'':'D:')."response>\n";
1206
+			echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
1207
+		} else {
1208
+			$this->http_status("423 Locked");
1209
+		}
1210
+	}
1211
+
1212
+	// }}}
1213
+
1214
+
1215
+	// {{{ http_MKCOL()
1216
+
1217
+	/**
1218
+	 * MKCOL method handler
1219
+	 *
1220
+	 * @param  void
1221
+	 * @return void
1222
+	 */
1223
+	function http_MKCOL()
1224
+	{
1225
+		$options = Array();
1226
+
1227
+		$options["path"] = $this->path;
1228
+
1229
+		$stat = $this->MKCOL($options);
1230
+
1231
+		$this->http_status($stat);
1232
+	}
1233
+
1234
+	// }}}
1235 1235
 
1236 1236
 	/**
1237 1237
 	 * Check or set if we want ot use compression as transfer encoding
@@ -1258,1387 +1258,1387 @@  discard block
 block discarded – undo
1258 1258
 		return $compression;
1259 1259
 	}
1260 1260
 
1261
-    // {{{ http_GET()
1261
+	// {{{ http_GET()
1262 1262
 
1263
-    /**
1264
-     * GET method handler
1265
-     *
1266
-     * @param void
1267
-     * @return void
1268
-     */
1269
-    function http_GET()
1270
-    {
1271
-        // TODO check for invalid stream
1272
-        $options         = Array();
1273
-        $options["path"] = $this->path;
1274
-
1275
-        $this->_get_ranges($options);
1276
-
1277
-        if (true === ($status = $this->GET($options))) {
1278
-            if (!headers_sent()) {
1279
-                $status = "200 OK";
1280
-
1281
-                if (!isset($options['mimetype'])) {
1282
-                    $options['mimetype'] = "application/octet-stream";
1283
-                }
1284
-                // switching off zlib.output_compression for everything but text files,
1285
-                // as the double compression of zip files makes problems eg. with lighttpd
1286
-                // and anyway little sense with with other content like pictures
1287
-                if (substr($options['mimetype'],0,5) != 'text/')
1288
-                {
1263
+	/**
1264
+	 * GET method handler
1265
+	 *
1266
+	 * @param void
1267
+	 * @return void
1268
+	 */
1269
+	function http_GET()
1270
+	{
1271
+		// TODO check for invalid stream
1272
+		$options         = Array();
1273
+		$options["path"] = $this->path;
1274
+
1275
+		$this->_get_ranges($options);
1276
+
1277
+		if (true === ($status = $this->GET($options))) {
1278
+			if (!headers_sent()) {
1279
+				$status = "200 OK";
1280
+
1281
+				if (!isset($options['mimetype'])) {
1282
+					$options['mimetype'] = "application/octet-stream";
1283
+				}
1284
+				// switching off zlib.output_compression for everything but text files,
1285
+				// as the double compression of zip files makes problems eg. with lighttpd
1286
+				// and anyway little sense with with other content like pictures
1287
+				if (substr($options['mimetype'],0,5) != 'text/')
1288
+				{
1289 1289
 					self::use_compression(false);
1290
-                }
1291
-                header("Content-type: $options[mimetype]");
1292
-
1293
-                if (isset($options['mtime'])) {
1294
-                    header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1295
-                }
1296
-                // fix for IE and https, thanks to [email protected]
1297
-                // see http://us3.php.net/manual/en/function.header.php#83219
1298
-                // and http://support.microsoft.com/kb/812935
1290
+				}
1291
+				header("Content-type: $options[mimetype]");
1292
+
1293
+				if (isset($options['mtime'])) {
1294
+					header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1295
+				}
1296
+				// fix for IE and https, thanks to [email protected]
1297
+				// see http://us3.php.net/manual/en/function.header.php#83219
1298
+				// and http://support.microsoft.com/kb/812935
1299 1299
 				header("Cache-Control: maxage=1"); //In seconds
1300 1300
 				header("Pragma: public");
1301 1301
 
1302
-                if (isset($options['stream'])) {
1303
-                    // GET handler returned a stream
1304
-                    if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET))) {
1305
-                        // partial request and stream is seekable
1306
-
1307
-                        if (count($options['ranges']) === 1) {
1308
-                            $range = $options['ranges'][0];
1309
-
1310
-                            if (isset($range['start'])) {
1311
-                                fseek($options['stream'], $range['start'], SEEK_SET);
1312
-                                if (feof($options['stream'])) {
1313
-                                    $this->http_status($status = "416 Requested range not satisfiable");
1314
-                                    return;
1315
-                                }
1316
-
1317
-                                if (!empty($range['end'])) {
1318
-                                    $size = $range['end']-$range['start']+1;
1319
-                                    $this->http_status($status = "206 Partial content");
1320
-                                    if (!self::use_compression()) header("Content-Length: $size");
1321
-                                    header("Content-Range: bytes $range[start]-$range[end]/"
1322
-                                           . (isset($options['size']) ? $options['size'] : "*"));
1323
-                                    while ($size > 0 && !feof($options['stream'])) {
1324
-                                        $buffer = fread($options['stream'], $size < 8192 ? $size : 8192);
1325
-                                        $size  -= self::bytes($buffer);
1326
-                                        echo $buffer;
1327
-                                    }
1328
-                                } else {
1329
-                                    $this->http_status($status = "206 Partial content");
1330
-                                    if (isset($options['size'])) {
1331
-                                        if (!self::use_compression()) header("Content-Length: ".($options['size'] - $range['start']));
1332
-                                        header("Content-Range: bytes ".$range['start']."-".
1302
+				if (isset($options['stream'])) {
1303
+					// GET handler returned a stream
1304
+					if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET))) {
1305
+						// partial request and stream is seekable
1306
+
1307
+						if (count($options['ranges']) === 1) {
1308
+							$range = $options['ranges'][0];
1309
+
1310
+							if (isset($range['start'])) {
1311
+								fseek($options['stream'], $range['start'], SEEK_SET);
1312
+								if (feof($options['stream'])) {
1313
+									$this->http_status($status = "416 Requested range not satisfiable");
1314
+									return;
1315
+								}
1316
+
1317
+								if (!empty($range['end'])) {
1318
+									$size = $range['end']-$range['start']+1;
1319
+									$this->http_status($status = "206 Partial content");
1320
+									if (!self::use_compression()) header("Content-Length: $size");
1321
+									header("Content-Range: bytes $range[start]-$range[end]/"
1322
+										   . (isset($options['size']) ? $options['size'] : "*"));
1323
+									while ($size > 0 && !feof($options['stream'])) {
1324
+										$buffer = fread($options['stream'], $size < 8192 ? $size : 8192);
1325
+										$size  -= self::bytes($buffer);
1326
+										echo $buffer;
1327
+									}
1328
+								} else {
1329
+									$this->http_status($status = "206 Partial content");
1330
+									if (isset($options['size'])) {
1331
+										if (!self::use_compression()) header("Content-Length: ".($options['size'] - $range['start']));
1332
+										header("Content-Range: bytes ".$range['start']."-".
1333 1333
 											(isset($options['size']) ? $options['size']-1 : "")."/"
1334 1334
 										   . (isset($options['size']) ? $options['size'] : "*"));
1335
-                                    }
1336
-                                    fpassthru($options['stream']);
1337
-                                }
1338
-                            } else {
1339
-                                if (!self::use_compression()) header("Content-length: ".$range['last']);
1340
-                                fseek($options['stream'], -$range['last'], SEEK_END);
1341
-                                fpassthru($options['stream']);
1342
-                            }
1343
-                        } else {
1344
-                            $this->_multipart_byterange_header(); // init multipart
1345
-                            foreach ($options['ranges'] as $range) {
1346
-                                // TODO what if size unknown? 500?
1347
-                                if (isset($range['start'])) {
1348
-                                    $from = $range['start'];
1349
-                                    $to   = !empty($range['end']) ? $range['end'] : $options['size']-1;
1350
-                                } else {
1351
-                                    $from = $options['size'] - $range['last']-1;
1352
-                                    $to   = $options['size'] -1;
1353
-                                }
1354
-                                $total = isset($options['size']) ? $options['size'] : "*";
1355
-                                $size  = $to - $from + 1;
1356
-                                $this->_multipart_byterange_header($options['mimetype'], $from, $to, $total);
1357
-
1358
-
1359
-                                fseek($options['stream'], $from, SEEK_SET);
1360
-                                while ($size && !feof($options['stream'])) {
1361
-                                    $buffer = fread($options['stream'], 4096);
1362
-                                    $size  -= self::bytes($buffer);
1363
-                                    echo $buffer;
1364
-                                }
1365
-                            }
1366
-                            $this->_multipart_byterange_header(); // end multipart
1367
-                        }
1368
-                    } else {
1369
-                        // normal request or stream isn't seekable, return full content
1370
-                        if (isset($options['size']) && !self::use_compression()) {
1371
-                            header("Content-Length: ".$options['size']);
1372
-                        }
1373
-                        fpassthru($options['stream']);
1374
-                        return; // no more headers
1375
-                    }
1376
-                } elseif (isset($options['data'])) {
1377
-                    if (is_array($options['data'])) {
1378
-                        // reply to partial request
1379
-                    } else {
1380
-                        if (!self::use_compression()) header("Content-Length: ".self::bytes($options['data']));
1381
-                        echo $options['data'];
1382
-                    }
1383
-                }
1384
-            }
1385
-        }
1386
-
1387
-        if (!headers_sent()) {
1388
-            if (false === $status) {
1389
-                $this->http_status("404 not found");
1390
-            } else {
1391
-                // TODO: check setting of headers in various code paths above
1392
-                $this->http_status("$status");
1393
-            }
1394
-        }
1395
-    }
1335
+									}
1336
+									fpassthru($options['stream']);
1337
+								}
1338
+							} else {
1339
+								if (!self::use_compression()) header("Content-length: ".$range['last']);
1340
+								fseek($options['stream'], -$range['last'], SEEK_END);
1341
+								fpassthru($options['stream']);
1342
+							}
1343
+						} else {
1344
+							$this->_multipart_byterange_header(); // init multipart
1345
+							foreach ($options['ranges'] as $range) {
1346
+								// TODO what if size unknown? 500?
1347
+								if (isset($range['start'])) {
1348
+									$from = $range['start'];
1349
+									$to   = !empty($range['end']) ? $range['end'] : $options['size']-1;
1350
+								} else {
1351
+									$from = $options['size'] - $range['last']-1;
1352
+									$to   = $options['size'] -1;
1353
+								}
1354
+								$total = isset($options['size']) ? $options['size'] : "*";
1355
+								$size  = $to - $from + 1;
1356
+								$this->_multipart_byterange_header($options['mimetype'], $from, $to, $total);
1357
+
1358
+
1359
+								fseek($options['stream'], $from, SEEK_SET);
1360
+								while ($size && !feof($options['stream'])) {
1361
+									$buffer = fread($options['stream'], 4096);
1362
+									$size  -= self::bytes($buffer);
1363
+									echo $buffer;
1364
+								}
1365
+							}
1366
+							$this->_multipart_byterange_header(); // end multipart
1367
+						}
1368
+					} else {
1369
+						// normal request or stream isn't seekable, return full content
1370
+						if (isset($options['size']) && !self::use_compression()) {
1371
+							header("Content-Length: ".$options['size']);
1372
+						}
1373
+						fpassthru($options['stream']);
1374
+						return; // no more headers
1375
+					}
1376
+				} elseif (isset($options['data'])) {
1377
+					if (is_array($options['data'])) {
1378
+						// reply to partial request
1379
+					} else {
1380
+						if (!self::use_compression()) header("Content-Length: ".self::bytes($options['data']));
1381
+						echo $options['data'];
1382
+					}
1383
+				}
1384
+			}
1385
+		}
1386
+
1387
+		if (!headers_sent()) {
1388
+			if (false === $status) {
1389
+				$this->http_status("404 not found");
1390
+			} else {
1391
+				// TODO: check setting of headers in various code paths above
1392
+				$this->http_status("$status");
1393
+			}
1394
+		}
1395
+	}
1396
+
1397
+
1398
+	/**
1399
+	 * parse HTTP Range: header
1400
+	 *
1401
+	 * @param  array options array to store result in
1402
+	 * @return void
1403
+	 */
1404
+	function _get_ranges(&$options)
1405
+	{
1406
+		// process Range: header if present
1407
+		if (isset($this->_SERVER['HTTP_RANGE'])) {
1408
+
1409
+			// we only support standard "bytes" range specifications for now
1410
+			$matches = null;
1411
+			if (preg_match('/bytes\s*=\s*(.+)/', $this->_SERVER['HTTP_RANGE'], $matches)) {
1412
+				$options["ranges"] = array();
1413
+
1414
+				// ranges are comma separated
1415
+				foreach (explode(",", $matches[1]) as $range) {
1416
+					// ranges are either from-to pairs or just end positions
1417
+					list($start, $end) = explode("-", $range);
1418
+					$options["ranges"][] = ($start==="")
1419
+						? array("last"=>$end)
1420
+						: array("start"=>$start, "end"=>$end);
1421
+				}
1422
+			}
1423
+		}
1424
+	}
1425
+
1426
+	/**
1427
+	 * generate separator headers for multipart response
1428
+	 *
1429
+	 * first and last call happen without parameters to generate
1430
+	 * the initial header and closing sequence, all calls inbetween
1431
+	 * require content mimetype, start and end byte position and
1432
+	 * optionaly the total byte length of the requested resource
1433
+	 *
1434
+	 * @param  string  mimetype
1435
+	 * @param  int     start byte position
1436
+	 * @param  int     end   byte position
1437
+	 * @param  int     total resource byte size
1438
+	 */
1439
+	function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false)
1440
+	{
1441
+		if ($mimetype === false) {
1442
+			if (!isset($this->multipart_separator)) {
1443
+				// initial
1444
+
1445
+				// a little naive, this sequence *might* be part of the content
1446
+				// but it's really not likely and rather expensive to check
1447
+				$this->multipart_separator = "SEPARATOR_".md5(microtime());
1448
+
1449
+				// generate HTTP header
1450
+				header("Content-type: multipart/byteranges; boundary=".$this->multipart_separator);
1451
+			} else {
1452
+				// final
1453
+
1454
+				// generate closing multipart sequence
1455
+				echo "\n--{$this->multipart_separator}--";
1456
+			}
1457
+		} else {
1458
+			// generate separator and header for next part
1459
+			echo "\n--{$this->multipart_separator}\n";
1460
+			echo "Content-type: $mimetype\n";
1461
+			echo "Content-range: $from-$to/". ($total === false ? "*" : $total);
1462
+			echo "\n\n";
1463
+		}
1464
+	}
1465
+
1466
+
1467
+
1468
+	// }}}
1469
+
1470
+	// {{{ http_HEAD()
1471
+
1472
+	/**
1473
+	 * HEAD method handler
1474
+	 *
1475
+	 * @param  void
1476
+	 * @return void
1477
+	 */
1478
+	function http_HEAD()
1479
+	{
1480
+		$status          = false;
1481
+		$options         = Array();
1482
+		$options["path"] = $this->path;
1483
+
1484
+		if (method_exists($this, "HEAD")) {
1485
+			$status = $this->head($options);
1486
+		} else if (method_exists($this, "GET")) {
1487
+			ob_start();
1488
+			$status = $this->GET($options);
1489
+			if (!isset($options['size'])) {
1490
+				$options['size'] = ob_get_length();
1491
+			}
1492
+			ob_end_clean();
1493
+		}
1494
+
1495
+		if (!isset($options['mimetype'])) {
1496
+			$options['mimetype'] = "application/octet-stream";
1497
+		}
1498
+		header("Content-type: $options[mimetype]");
1499
+
1500
+		if (isset($options['mtime'])) {
1501
+			header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1502
+		}
1503
+
1504
+		if (isset($options['size'])) {
1505
+			header("Content-Length: ".$options['size']);
1506
+		}
1507
+
1508
+		if ($status === true)  $status = "200 OK";
1509
+		if ($status === false) $status = "404 Not found";
1510
+
1511
+		$this->http_status($status);
1512
+	}
1513
+
1514
+	// }}}
1515
+
1516
+	// {{{ http_POST()
1517
+
1518
+	/**
1519
+	 * POST method handler
1520
+	 *
1521
+	 * @param  void
1522
+	 * @return void
1523
+	 */
1524
+	function http_POST()
1525
+	{
1526
+		$status          = '405 Method not allowed';
1527
+		$options         = Array();
1528
+		$options['path'] = $this->path;
1529
+
1530
+		if (isset($this->_SERVER['CONTENT_LENGTH']))
1531
+		{
1532
+			$options['content_length'] = $this->_SERVER['CONTENT_LENGTH'];
1533
+		}
1534
+		elseif (isset($this->_SERVER['X-Expected-Entity-Length']))
1535
+		{
1536
+			// MacOS gives us that hint
1537
+			$options['content_length'] = $this->_SERVER['X-Expected-Entity-Length'];
1538
+		}
1539
+
1540
+		// get the Content-type
1541
+		if (isset($this->_SERVER["CONTENT_TYPE"])) {
1542
+			// for now we do not support any sort of multipart requests
1543
+			if (!strncmp($this->_SERVER["CONTENT_TYPE"], 'multipart/', 10)) {
1544
+				$this->http_status('501 not implemented');
1545
+				echo 'The service does not support mulipart POST requests';
1546
+				return;
1547
+			}
1548
+			$options['content_type'] = $this->_SERVER['CONTENT_TYPE'];
1549
+		} else {
1550
+			// default content type if none given
1551
+			$options['content_type'] = 'application/octet-stream';
1552
+		}
1553
+
1554
+		$options['stream'] = fopen('php://input', 'r');
1555
+		switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1556
+		{
1557
+			case 'gzip':
1558
+			case 'deflate':	//zlib
1559
+				if (extension_loaded('zlib'))
1560
+	 			{
1561
+	  				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1562
+	   			}
1563
+		}
1564
+		// store request in $this->request, if requested via $this->store_request
1565
+		if ($this->store_request)
1566
+		{
1567
+			$options['content'] = '';
1568
+			while(!feof($options['stream']))
1569
+			{
1570
+				$options['content'] .= fread($options['stream'],8192);
1571
+			}
1572
+			$this->request =& $options['content'];
1573
+			unset($options['stream']);
1574
+		}
1575
+
1576
+		/* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
1577
+         ignore any Content-* (e.g. Content-Range) headers that it
1578
+         does not understand or implement and MUST return a 501
1579
+         (Not Implemented) response in such cases."
1580
+         */
1581
+		foreach ($this->_SERVER as $key => $val) {
1582
+			if (strncmp($key, 'HTTP_CONTENT', 11)) continue;
1583
+			switch ($key) {
1584
+				case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1585
+					switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1586
+					{
1587
+						case 'gzip':
1588
+						case 'deflate':	//zlib
1589
+							if (extension_loaded('zlib')) break;
1590
+							// fall through for no zlib support
1591
+						default:
1592
+							$this->http_status('415 Unsupported Media Type');
1593
+							echo "The service does not support '$val' content encoding";
1594
+							return;
1595
+					}
1596
+					break;
1597
+
1598
+				case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12
1599
+					// we assume it is not critical if this one is ignored
1600
+					// in the actual POST implementation ...
1601
+					$options['content_language'] = $val;
1602
+					break;
1603
+
1604
+				case 'HTTP_CONTENT_LENGTH':
1605
+					// defined on IIS and has the same value as CONTENT_LENGTH
1606
+					break;
1607
+
1608
+				case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
1609
+					/* The meaning of the Content-Location header in PUT
1610
+			         or POST requests is undefined; servers are free
1611
+			         to ignore it in those cases. */
1612
+					break;
1613
+
1614
+				case 'HTTP_CONTENT_RANGE':    // RFC 2616 14.16
1615
+					// single byte range requests are supported
1616
+					// the header format is also specified in RFC 2616 14.16
1617
+					// TODO we have to ensure that implementations support this or send 501 instead
1618
+					$matches = null;
1619
+					if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
1620
+						$this->http_status('400 bad request');
1621
+						echo 'The service does only support single byte ranges';
1622
+						return;
1623
+					}
1624
+
1625
+					$range = array('start'=>$matches[1], 'end'=>$matches[2]);
1626
+					if (is_numeric($matches[3])) {
1627
+						$range['total_length'] = $matches[3];
1628
+					}
1629
+					$options['ranges'][] = $range;
1630
+
1631
+					// TODO make sure the implementation supports partial POST
1632
+					// this has to be done in advance to avoid data being overwritten
1633
+					// on implementations that do not support this ...
1634
+					break;
1635
+
1636
+				case 'HTTP_CONTENT_TYPE':
1637
+					// defined on IIS and has the same value as CONTENT_TYPE
1638
+					break;
1639
+
1640
+				case 'HTTP_CONTENT_MD5':      // RFC 2616 14.15
1641
+					// TODO: maybe we can just pretend here?
1642
+					$this->http_status('501 not implemented');
1643
+					echo 'The service does not support content MD5 checksum verification';
1644
+					return;
1645
+
1646
+				case 'HTTP_CONTENT_DISPOSITION':
1647
+					// do NOT care about Content-Disposition in POST requests required by CalDAV managed attachments
1648
+					break;
1649
+
1650
+				default:
1651
+					// any other unknown Content-* headers
1652
+					$this->http_status('501 not implemented');
1653
+				echo "The service does not support '$key'";
1654
+				return;
1655
+			}
1656
+		}
1657
+
1658
+		if (method_exists($this, 'POST')) {
1659
+			$status = $this->POST($options);
1660
+
1661
+			if ($status === false) {
1662
+				$status = '400 Something went wrong';
1663
+			} else if ($status === true) {
1664
+				$status = '200 OK';
1665
+			} else if (is_resource($status) && get_resource_type($status) == 'stream') {
1666
+				$stream = $status;
1667
+
1668
+				$status = empty($options['new']) ? '200 OK' : '201 Created';
1669
+
1670
+				if (!empty($options['ranges'])) {
1671
+					// TODO multipart support is missing (see also above)
1672
+					if (0 == fseek($stream, $range[0]['start'], SEEK_SET)) {
1673
+						$length = $range[0]['end']-$range[0]['start']+1;
1674
+						if (!fwrite($stream, fread($options['stream'], $length))) {
1675
+							$status = '403 Forbidden';
1676
+						}
1677
+					} else {
1678
+						$status = '403 Forbidden';
1679
+					}
1680
+				} else {
1681
+					while (!feof($options['stream'])) {
1682
+						if (false === fwrite($stream, fread($options['stream'], 4096))) {
1683
+							$status = '403 Forbidden';
1684
+							break;
1685
+						}
1686
+					}
1687
+				}
1688
+				fclose($stream);
1689
+			}
1690
+		}
1691
+		$this->http_status($status);
1692
+	}
1693
+
1694
+	// }}}
1695
+
1696
+	// {{{ http_PUT()
1697
+
1698
+	/**
1699
+	 * PUT method handler
1700
+	 *
1701
+	 * @param  void
1702
+	 * @return void
1703
+	 */
1704
+	function http_PUT()
1705
+	{
1706
+		if ($this->_check_lock_status($this->path)) {
1707
+			$options                   = Array();
1708
+			$options["path"]           = $this->path;
1709
+
1710
+			if (isset($this->_SERVER['CONTENT_LENGTH']))
1711
+			{
1712
+				$options['content_length'] = $this->_SERVER['CONTENT_LENGTH'];
1713
+			}
1714
+			elseif (isset($this->_SERVER['X-Expected-Entity-Length']))
1715
+			{
1716
+				// MacOS gives us that hint
1717
+				$options['content_length'] = $this->_SERVER['X-Expected-Entity-Length'];
1718
+			}
1719
+
1720
+			// get the Content-type
1721
+			if (isset($this->_SERVER["CONTENT_TYPE"])) {
1722
+				// for now we do not support any sort of multipart requests
1723
+				if (!strncmp($this->_SERVER["CONTENT_TYPE"], "multipart/", 10)) {
1724
+					$this->http_status("501 not implemented");
1725
+					echo "The service does not support multipart PUT requests";
1726
+					return;
1727
+				}
1728
+				$options["content_type"] = $this->_SERVER["CONTENT_TYPE"];
1729
+			} else {
1730
+				// default content type if none given
1731
+				$options["content_type"] = "application/octet-stream";
1732
+			}
1733
+
1734
+			$options["stream"] = fopen("php://input", "r");
1735
+			switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1736
+			{
1737
+				case 'gzip':
1738
+				case 'deflate':	//zlib
1739
+					if (extension_loaded('zlib'))
1740
+		 			{
1741
+		  				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1742
+		   			}
1743
+			}
1744
+			// store request in $this->request, if requested via $this->store_request
1745
+			if ($this->store_request)
1746
+			{
1747
+				$options['content'] = '';
1748
+				while(!feof($options['stream']))
1749
+				{
1750
+					$options['content'] .= fread($options['stream'],8192);
1751
+				}
1752
+				$this->request =& $options['content'];
1753
+				unset($options['stream']);
1754
+			}
1755
+
1756
+			/* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
1757
+             ignore any Content-* (e.g. Content-Range) headers that it
1758
+             does not understand or implement and MUST return a 501
1759
+             (Not Implemented) response in such cases."
1760
+            */
1761
+			foreach ($this->_SERVER as $key => $val) {
1762
+				if (strncmp($key, "HTTP_CONTENT", 11)) continue;
1763
+				switch ($key) {
1764
+				case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1765
+					switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1766
+					{
1767
+						case 'gzip':
1768
+						case 'deflate':	//zlib
1769
+							if (extension_loaded('zlib')) break;
1770
+							// fall through for no zlib support
1771
+						default:
1772
+							$this->http_status('415 Unsupported Media Type');
1773
+							echo "The service does not support '$val' content encoding";
1774
+							return;
1775
+					}
1776
+					break;
1777
+
1778
+				case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12
1779
+					// we assume it is not critical if this one is ignored
1780
+					// in the actual PUT implementation ...
1781
+					$options["content_language"] = $val;
1782
+					break;
1783
+
1784
+				case 'HTTP_CONTENT_LENGTH':
1785
+					// defined on IIS and has the same value as CONTENT_LENGTH
1786
+					break;
1787
+
1788
+				case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
1789
+					/* The meaning of the Content-Location header in PUT
1790
+                     or POST requests is undefined; servers are free
1791
+                     to ignore it in those cases. */
1792
+					break;
1793
+
1794
+				case 'HTTP_CONTENT_RANGE':    // RFC 2616 14.16
1795
+					// single byte range requests are supported
1796
+					// the header format is also specified in RFC 2616 14.16
1797
+					// TODO we have to ensure that implementations support this or send 501 instead
1798
+					$matches = null;
1799
+					if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
1800
+						$this->http_status("400 bad request");
1801
+						echo "The service does only support single byte ranges";
1802
+						return;
1803
+					}
1804
+
1805
+					$range = array("start" => $matches[1], "end" => $matches[2]);
1806
+					if (is_numeric($matches[3])) {
1807
+						$range["total_length"] = $matches[3];
1808
+					}
1809
+
1810
+					if (!isset($options['ranges'])) {
1811
+						$options['ranges'] = array();
1812
+					}
1813
+
1814
+					$options["ranges"][] = $range;
1815
+
1816
+					// TODO make sure the implementation supports partial PUT
1817
+					// this has to be done in advance to avoid data being overwritten
1818
+					// on implementations that do not support this ...
1819
+					break;
1820
+
1821
+				case 'HTTP_CONTENT_TYPE':
1822
+					// defined on IIS and has the same value as CONTENT_TYPE
1823
+					break;
1824
+
1825
+				case 'HTTP_CONTENT_MD5':      // RFC 2616 14.15
1826
+					// TODO: maybe we can just pretend here?
1827
+					$this->http_status("501 not implemented");
1828
+					echo "The service does not support content MD5 checksum verification";
1829
+					return;
1830
+
1831
+				default:
1832
+					// any other unknown Content-* headers
1833
+					$this->http_status("501 not implemented");
1834
+					echo "The service does not support '$key'";
1835
+					return;
1836
+				}
1837
+			}
1838
+
1839
+			$stat = $this->PUT($options);
1840
+
1841
+			if ($stat === false) {
1842
+				$stat = "403 Forbidden";
1843
+			} else if (is_resource($stat) && get_resource_type($stat) == "stream") {
1844
+				$stream = $stat;
1845
+
1846
+				$stat = $options["new"] ? "201 Created" : "204 No Content";
1847
+
1848
+				if (!empty($options["ranges"])) {
1849
+					// TODO multipart support is missing (see also above)
1850
+					if (0 == fseek($stream, $options['ranges'][0]["start"], SEEK_SET)) {
1851
+						$length = $options['ranges'][0]["end"] - $options['ranges'][0]["start"]+1;
1852
+
1853
+						while (!feof($options['stream'])) {
1854
+							if ($length <= 0) {
1855
+							   break;
1856
+							}
1857
+
1858
+							if ($length <= 8192) {
1859
+								$data = fread($options['stream'], $length);
1860
+							} else {
1861
+								$data = fread($options['stream'], 8192);
1862
+							}
1863
+
1864
+							if ($data === false) {
1865
+								$stat = "400 Bad request";
1866
+							} elseif (strlen($data)) {
1867
+								if (false === fwrite($stream, $data)) {
1868
+									$stat = "403 Forbidden";
1869
+									break;
1870
+								}
1871
+								$length -= strlen($data);
1872
+							}
1873
+						}
1874
+					} else {
1875
+						$stat = "403 Forbidden";
1876
+					}
1877
+				} else {
1878
+					while (!feof($options["stream"])) {
1879
+						if (false === fwrite($stream, fread($options["stream"], 8192))) {
1880
+							$stat = "403 Forbidden";
1881
+							break;
1882
+						}
1883
+					}
1884
+				}
1885
+
1886
+				fclose($stream);
1887
+			}
1888
+
1889
+			$this->http_status($stat);
1890
+		} else {
1891
+			$this->http_status("423 Locked");
1892
+		}
1893
+	}
1894
+
1895
+	// }}}
1896
+
1897
+
1898
+	// {{{ http_DELETE()
1899
+
1900
+	/**
1901
+	 * DELETE method handler
1902
+	 *
1903
+	 * @param  void
1904
+	 * @return void
1905
+	 */
1906
+	function http_DELETE()
1907
+	{
1908
+		// check RFC 2518 Section 9.2, last paragraph
1909
+		if (isset($this->_SERVER["HTTP_DEPTH"])) {
1910
+			if ($this->_SERVER["HTTP_DEPTH"] != "infinity") {
1911
+				if (stripos($_SERVER['HTTP_USER_AGENT'],'webdrive') !== false)
1912
+				{
1913
+					// pretend we didnt see it, as webdrive does not handle the depth parameter correctly while deleting collections
1914
+				}
1915
+				else
1916
+				{
1917
+					$this->http_status("400 Bad Request");
1918
+					return;
1919
+				}
1920
+			}
1921
+		}
1922
+
1923
+		// check lock status
1924
+		if ($this->_check_lock_status($this->path)) {
1925
+			// ok, proceed
1926
+			$options         = Array();
1927
+			$options["path"] = $this->path;
1928
+
1929
+			$stat = $this->DELETE($options);
1930
+
1931
+			$this->http_status($stat);
1932
+		} else {
1933
+			// sorry, its locked
1934
+			$this->http_status("423 Locked");
1935
+		}
1936
+	}
1937
+
1938
+	// }}}
1939
+
1940
+	// {{{ http_COPY()
1941
+
1942
+	/**
1943
+	 * COPY method handler
1944
+	 *
1945
+	 * @param  void
1946
+	 * @return void
1947
+	 */
1948
+	function http_COPY()
1949
+	{
1950
+		// no need to check source lock status here
1951
+		// destination lock status is always checked by the helper method
1952
+		$this->_copymove("copy");
1953
+	}
1954
+
1955
+	// }}}
1956
+
1957
+	// {{{ http_MOVE()
1958
+
1959
+	/**
1960
+	 * MOVE method handler
1961
+	 *
1962
+	 * @param  void
1963
+	 * @return void
1964
+	 */
1965
+	function http_MOVE()
1966
+	{
1967
+		if ($this->_check_lock_status($this->path)) {
1968
+			// destination lock status is always checked by the helper method
1969
+			$this->_copymove("move");
1970
+		} else {
1971
+			$this->http_status("423 Locked");
1972
+		}
1973
+	}
1974
+
1975
+	// }}}
1976
+
1977
+
1978
+	// {{{ http_LOCK()
1979
+
1980
+	/**
1981
+	 * LOCK method handler
1982
+	 *
1983
+	 * @param  void
1984
+	 * @return void
1985
+	 */
1986
+	function http_LOCK()
1987
+	{
1988
+		$options         = Array();
1989
+		$options["path"] = $this->path;
1990
+
1991
+		if (isset($this->_SERVER['HTTP_DEPTH'])) {
1992
+			$options["depth"] = $this->_SERVER["HTTP_DEPTH"];
1993
+		} else {
1994
+			$options["depth"] = "infinity";
1995
+		}
1996
+
1997
+		if (isset($this->_SERVER["HTTP_TIMEOUT"])) {
1998
+			$options["timeout"] = explode(",", $this->_SERVER["HTTP_TIMEOUT"]);
1999
+		}
2000
+
2001
+		if (empty($this->_SERVER['CONTENT_LENGTH']) && !empty($this->_SERVER['HTTP_IF'])) {
2002
+			// check if locking is possible
2003
+			if (!$this->_check_lock_status($this->path)) {
2004
+				$this->http_status("423 Locked");
2005
+				return;
2006
+			}
2007
+
2008
+			// refresh lock
2009
+			$options["locktoken"] = substr($this->_SERVER['HTTP_IF'], 2, -2);
2010
+			$options["update"]    = $options["locktoken"];
2011
+
2012
+			// setting defaults for required fields, LOCK() SHOULD overwrite these
2013
+			$options['owner']     = "unknown";
2014
+			$options['scope']     = "exclusive";
2015
+			$options['type']      = "write";
2016
+
2017
+
2018
+			$stat = $this->LOCK($options);
2019
+		} else {
2020
+			// extract lock request information from request XML payload
2021
+			$lockinfo = new _parse_lockinfo("php://input");
2022
+			if (!$lockinfo->success) {
2023
+				$this->http_status("400 bad request");
2024
+			}
2025
+
2026
+			// check if locking is possible
2027
+			if (!$this->_check_lock_status($this->path, $lockinfo->lockscope === "shared")) {
2028
+				$this->http_status("423 Locked");
2029
+				return;
2030
+			}
2031
+
2032
+			// new lock
2033
+			$options["scope"]     = $lockinfo->lockscope;
2034
+			$options["type"]      = $lockinfo->locktype;
2035
+			// Todo: lockinfo::owner still contains D:href opening and closing tags, maybe they should be removed here with strip_tags
2036
+			$options["owner"]     = $lockinfo->owner;
2037
+			$options["locktoken"] = $this->_new_locktoken();
2038
+
2039
+			$stat = $this->LOCK($options);
2040
+		}
2041
+
2042
+		if (is_bool($stat)) {
2043
+			$http_stat = $stat ? "200 OK" : "423 Locked";
2044
+		} else {
2045
+			$http_stat = (string)$stat;
2046
+		}
2047
+		$this->http_status($http_stat);
2048
+
2049
+		if ($http_stat{0} == 2) { // 2xx states are ok
2050
+			if ($options["timeout"]) {
2051
+				// if multiple timeout values were given we take the first only
2052
+				if (is_array($options["timeout"])) {
2053
+					reset($options["timeout"]);
2054
+					$options["timeout"] = current($options["timeout"]);
2055
+				}
2056
+				// if the timeout is numeric only we need to reformat it
2057
+				if (is_numeric($options["timeout"])) {
2058
+					// more than a million is considered an absolute timestamp
2059
+					// less is more likely a relative value
2060
+					if ($options["timeout"]>1000000) {
2061
+						$timeout = "Second-".($options['timeout']-time());
2062
+					} else {
2063
+						$timeout = "Second-$options[timeout]";
2064
+					}
2065
+				} else {
2066
+					// non-numeric values are passed on verbatim,
2067
+					// no error checking is performed here in this case
2068
+					// TODO: send "Infinite" on invalid timeout strings?
2069
+					$timeout = $options["timeout"];
2070
+				}
2071
+			} else {
2072
+				$timeout = "Infinite";
2073
+			}
2074
+
2075
+			header('Content-Type: text/xml; charset="utf-8"');
2076
+			header("Lock-Token: <$options[locktoken]>");
2077
+			echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2078
+			echo "<D:prop xmlns:D=\"DAV:\">\n";
2079
+			echo ' <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2080
+			echo '  <'.($this->crrnd?'':'D:')."activelock>\n";
2081
+			echo '   <'.($this->crrnd?'':'D:')."lockscope><D:$options[scope]/></".($this->crrnd?'':'D:')."lockscope>\n";
2082
+			echo '   <'.($this->crrnd?'':'D:')."locktype><D:$options[type]/></".($this->crrnd?'':'D:')."locktype>\n";
2083
+			echo '   <'.($this->crrnd?'':'D:')."depth>$options[depth]</".($this->crrnd?'':'D:')."depth>\n";
2084
+			echo '   <'.($this->crrnd?'':'D:')."owner>$options[owner]</".($this->crrnd?'':'D:')."owner>\n";
2085
+			echo '   <'.($this->crrnd?'':'D:')."timeout>$timeout</".($this->crrnd?'':'D:')."timeout>\n";
2086
+			echo '   <'.($this->crrnd?'':'D:')."locktoken><D:href>$options[locktoken]</D:href></".($this->crrnd?'':'D:')."locktoken>\n";
2087
+			echo '  </'.($this->crrnd?'':'D:')."activelock>\n";
2088
+			echo ' </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2089
+			echo '</'.($this->crrnd?'':'D:')."prop>\n\n";
2090
+		}
2091
+	}
2092
+
2093
+
2094
+	// }}}
2095
+
2096
+	// {{{ http_UNLOCK()
2097
+
2098
+	/**
2099
+	 * UNLOCK method handler
2100
+	 *
2101
+	 * @param  void
2102
+	 * @return void
2103
+	 */
2104
+	function http_UNLOCK()
2105
+	{
2106
+		$options         = Array();
2107
+		$options["path"] = $this->path;
2108
+
2109
+		if (isset($this->_SERVER['HTTP_DEPTH'])) {
2110
+			$options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2111
+		} else {
2112
+			$options["depth"] = "infinity";
2113
+		}
2114
+
2115
+		// strip surrounding <>
2116
+		$options["token"] = substr(trim($this->_SERVER["HTTP_LOCK_TOKEN"]), 1, -1);
2117
+
2118
+		// call user method
2119
+		$stat = $this->UNLOCK($options);
2120
+
2121
+		$this->http_status($stat);
2122
+	}
2123
+
2124
+	// }}}
2125
+
2126
+	// {{{ http_ACL()
2127
+
2128
+	/**
2129
+	 * ACL method handler
2130
+	 *
2131
+	 * @param  void
2132
+	 * @return void
2133
+	 */
2134
+	function http_ACL()
2135
+	{
2136
+		$options         = Array();
2137
+		$options['path'] = $this->path;
2138
+		$options['errors'] = array();
2139
+
2140
+		if (isset($this->_SERVER['HTTP_DEPTH'])) {
2141
+			$options['depth'] = $this->_SERVER['HTTP_DEPTH'];
2142
+		} else {
2143
+			$options['depth'] = 'infinity';
2144
+		}
2145
+
2146
+		// call user method
2147
+		$status = $this->ACL($options);
2148
+
2149
+		// now we generate the reply header ...
2150
+		$this->http_status($status);
2151
+		$content = '';
2152
+
2153
+		if (is_array($options['errors']) && count($options['errors'])) {
2154
+			header('Content-Type: text/xml; charset="utf-8"');
2155
+			// ... and payload
2156
+			$content .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2157
+			$content .= "<D:error xmlns:D=\"DAV:\"> \n";
2158
+			foreach ($options['errors'] as $violation) {
2159
+				$content .= '<'.($this->crrnd?'':'D:')."$violation/>\n";
2160
+			}
2161
+			$content .=  '</'.($this->crrnd?'':'D:')."error>\n";
2162
+		}
2163
+		if (!self::use_compression()) header("Content-Length: ".self::bytes($content));
2164
+		if ($content) echo $options['content'];
2165
+	}
2166
+
2167
+	// }}}
2168
+
2169
+	// }}}
2170
+
2171
+	// {{{ _copymove()
2172
+
2173
+	function _copymove($what)
2174
+	{
2175
+		$options         = Array();
2176
+		$options["path"] = $this->path;
2177
+
2178
+		if (isset($this->_SERVER["HTTP_DEPTH"])) {
2179
+			$options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2180
+		} else {
2181
+			$options["depth"] = "infinity";
2182
+		}
2183
+
2184
+		$http_header_host = preg_replace("/:80$/", "", $this->_SERVER["HTTP_HOST"]);
2185
+
2186
+		$url  = parse_url($this->_SERVER["HTTP_DESTINATION"]);
2187
+		$path = urldecode($url["path"]);
2188
+
2189
+		if (isset($url["host"])) {
2190
+			// TODO check url scheme, too
2191
+			$http_host = $url["host"];
2192
+			if (isset($url["port"]) && $url["port"] != 80)
2193
+				$http_host.= ":".$url["port"];
2194
+		} else {
2195
+			// only path given, set host to self
2196
+			$http_host = $http_header_host;
2197
+		}
2198
+
2199
+		if ($http_host == $http_header_host &&
2200
+			!strncmp($this->_SERVER["SCRIPT_NAME"], $path,
2201
+					 strlen($this->_SERVER["SCRIPT_NAME"]))) {
2202
+			$options["dest"] = substr($path, strlen($this->_SERVER["SCRIPT_NAME"]));
2203
+			if (!$this->_check_lock_status($options["dest"])) {
2204
+				$this->http_status("423 Locked");
2205
+				return;
2206
+			}
2207
+
2208
+		} else {
2209
+			$options["dest_url"] = $this->_SERVER["HTTP_DESTINATION"];
2210
+		}
2211
+
2212
+		// see RFC 2518 Sections 9.6, 8.8.4 and 8.9.3
2213
+		if (isset($this->_SERVER["HTTP_OVERWRITE"])) {
2214
+			$options["overwrite"] = $this->_SERVER["HTTP_OVERWRITE"] == "T";
2215
+		} else {
2216
+			$options["overwrite"] = true;
2217
+		}
2218
+
2219
+		$stat = $this->$what($options);
2220
+		$this->http_status($stat);
2221
+	}
2222
+
2223
+	// }}}
2224
+
2225
+	// {{{ _allow()
2226
+
2227
+	/**
2228
+	 * check for implemented HTTP methods
2229
+	 *
2230
+	 * @param  void
2231
+	 * @return array something
2232
+	 */
2233
+	function _allow()
2234
+	{
2235
+		// OPTIONS is always there
2236
+		$allow = array("OPTIONS" =>"OPTIONS");
2237
+
2238
+		// all other METHODS need both a http_method() wrapper
2239
+		// and a method() implementation
2240
+		// the base class supplies wrappers only
2241
+		foreach (get_class_methods($this) as $method) {
2242
+			if (!strncmp("http_", $method, 5)) {
2243
+				$method = strtoupper(substr($method, 5));
2244
+				if (method_exists($this, $method)) {
2245
+					$allow[$method] = $method;
2246
+				}
2247
+			}
2248
+		}
1396 2249
 
2250
+		// we can emulate a missing HEAD implemetation using GET
2251
+		if (isset($allow["GET"]))
2252
+			$allow["HEAD"] = "HEAD";
1397 2253
 
1398
-    /**
1399
-     * parse HTTP Range: header
1400
-     *
1401
-     * @param  array options array to store result in
1402
-     * @return void
1403
-     */
1404
-    function _get_ranges(&$options)
1405
-    {
1406
-        // process Range: header if present
1407
-        if (isset($this->_SERVER['HTTP_RANGE'])) {
1408
-
1409
-            // we only support standard "bytes" range specifications for now
1410
-			$matches = null;
1411
-            if (preg_match('/bytes\s*=\s*(.+)/', $this->_SERVER['HTTP_RANGE'], $matches)) {
1412
-                $options["ranges"] = array();
1413
-
1414
-                // ranges are comma separated
1415
-                foreach (explode(",", $matches[1]) as $range) {
1416
-                    // ranges are either from-to pairs or just end positions
1417
-                    list($start, $end) = explode("-", $range);
1418
-                    $options["ranges"][] = ($start==="")
1419
-                        ? array("last"=>$end)
1420
-                        : array("start"=>$start, "end"=>$end);
1421
-                }
1422
-            }
1423
-        }
1424
-    }
2254
+		// no LOCK without checklok()
2255
+		if (!method_exists($this, "checklock")) {
2256
+			unset($allow["LOCK"]);
2257
+			unset($allow["UNLOCK"]);
2258
+		}
1425 2259
 
1426
-    /**
1427
-     * generate separator headers for multipart response
1428
-     *
1429
-     * first and last call happen without parameters to generate
1430
-     * the initial header and closing sequence, all calls inbetween
1431
-     * require content mimetype, start and end byte position and
1432
-     * optionaly the total byte length of the requested resource
1433
-     *
1434
-     * @param  string  mimetype
1435
-     * @param  int     start byte position
1436
-     * @param  int     end   byte position
1437
-     * @param  int     total resource byte size
1438
-     */
1439
-    function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false)
1440
-    {
1441
-        if ($mimetype === false) {
1442
-            if (!isset($this->multipart_separator)) {
1443
-                // initial
1444
-
1445
-                // a little naive, this sequence *might* be part of the content
1446
-                // but it's really not likely and rather expensive to check
1447
-                $this->multipart_separator = "SEPARATOR_".md5(microtime());
1448
-
1449
-                // generate HTTP header
1450
-                header("Content-type: multipart/byteranges; boundary=".$this->multipart_separator);
1451
-            } else {
1452
-                // final
1453
-
1454
-                // generate closing multipart sequence
1455
-                echo "\n--{$this->multipart_separator}--";
1456
-            }
1457
-        } else {
1458
-            // generate separator and header for next part
1459
-            echo "\n--{$this->multipart_separator}\n";
1460
-            echo "Content-type: $mimetype\n";
1461
-            echo "Content-range: $from-$to/". ($total === false ? "*" : $total);
1462
-            echo "\n\n";
1463
-        }
1464
-    }
1465
-
1466
-
1467
-
1468
-    // }}}
1469
-
1470
-    // {{{ http_HEAD()
2260
+		return $allow;
2261
+	}
1471 2262
 
1472
-    /**
1473
-     * HEAD method handler
1474
-     *
1475
-     * @param  void
1476
-     * @return void
1477
-     */
1478
-    function http_HEAD()
1479
-    {
1480
-        $status          = false;
1481
-        $options         = Array();
1482
-        $options["path"] = $this->path;
1483
-
1484
-        if (method_exists($this, "HEAD")) {
1485
-            $status = $this->head($options);
1486
-        } else if (method_exists($this, "GET")) {
1487
-            ob_start();
1488
-            $status = $this->GET($options);
1489
-            if (!isset($options['size'])) {
1490
-                $options['size'] = ob_get_length();
1491
-            }
1492
-            ob_end_clean();
1493
-        }
1494
-
1495
-        if (!isset($options['mimetype'])) {
1496
-            $options['mimetype'] = "application/octet-stream";
1497
-        }
1498
-        header("Content-type: $options[mimetype]");
1499
-
1500
-        if (isset($options['mtime'])) {
1501
-            header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1502
-        }
1503
-
1504
-        if (isset($options['size'])) {
1505
-            header("Content-Length: ".$options['size']);
1506
-        }
1507
-
1508
-        if ($status === true)  $status = "200 OK";
1509
-        if ($status === false) $status = "404 Not found";
1510
-
1511
-        $this->http_status($status);
1512
-    }
1513
-
1514
-    // }}}
1515
-
1516
-    // {{{ http_POST()
2263
+	// }}}
1517 2264
 
1518
-    /**
1519
-     * POST method handler
1520
-     *
1521
-     * @param  void
1522
-     * @return void
1523
-     */
1524
-    function http_POST()
1525
-    {
1526
-        $status          = '405 Method not allowed';
1527
-        $options         = Array();
1528
-        $options['path'] = $this->path;
1529
-
1530
-        if (isset($this->_SERVER['CONTENT_LENGTH']))
1531
-        {
1532
-	        $options['content_length'] = $this->_SERVER['CONTENT_LENGTH'];
1533
-        }
1534
-        elseif (isset($this->_SERVER['X-Expected-Entity-Length']))
1535
-		{
1536
-	        // MacOS gives us that hint
1537
-	        $options['content_length'] = $this->_SERVER['X-Expected-Entity-Length'];
1538
-		}
1539
-
1540
-        // get the Content-type
1541
-        if (isset($this->_SERVER["CONTENT_TYPE"])) {
1542
-	        // for now we do not support any sort of multipart requests
1543
-	        if (!strncmp($this->_SERVER["CONTENT_TYPE"], 'multipart/', 10)) {
1544
-		        $this->http_status('501 not implemented');
1545
-		        echo 'The service does not support mulipart POST requests';
1546
-		        return;
1547
-	        }
1548
-	        $options['content_type'] = $this->_SERVER['CONTENT_TYPE'];
1549
-        } else {
1550
-	        // default content type if none given
1551
-	        $options['content_type'] = 'application/octet-stream';
1552
-        }
1553
-
1554
-        $options['stream'] = fopen('php://input', 'r');
1555
-    	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1556
-    	{
1557
-    		case 'gzip':
1558
-    		case 'deflate':	//zlib
1559
-    			if (extension_loaded('zlib'))
1560
-     			{
1561
-      				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1562
-       			}
1563
-    	}
1564
-		// store request in $this->request, if requested via $this->store_request
1565
-		if ($this->store_request)
1566
-		{
1567
-			$options['content'] = '';
1568
-			while(!feof($options['stream']))
1569
-			{
1570
-				$options['content'] .= fread($options['stream'],8192);
1571
-			}
1572
-			$this->request =& $options['content'];
1573
-			unset($options['stream']);
2265
+	/**
2266
+	 * helper for property element creation
2267
+	 *
2268
+	 * @param  string  XML namespace (optional)
2269
+	 * @param  string  property name
2270
+	 * @param  string  property value
2271
+	 * @praram boolen  property raw-flag
2272
+	 * @return array   property array
2273
+	 */
2274
+	public static function mkprop()
2275
+	{
2276
+		$args = func_get_args();
2277
+		switch (count($args)) {
2278
+			case 4:
2279
+				return array('ns'   => $args[0],
2280
+					'name' => $args[1],
2281
+					'val'  => $args[2],
2282
+					'raw'	=> true);
2283
+			case 3:
2284
+				return array('ns'   => $args[0],
2285
+					'name' => $args[1],
2286
+					'val'  => $args[2]);
2287
+			default:
2288
+				return array('ns'   => 'DAV:',
2289
+					'name' => $args[0],
2290
+					'val'  => $args[1]);
1574 2291
 		}
2292
+	}
1575 2293
 
1576
-        /* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
1577
-         ignore any Content-* (e.g. Content-Range) headers that it
1578
-         does not understand or implement and MUST return a 501
1579
-         (Not Implemented) response in such cases."
1580
-         */
1581
-        foreach ($this->_SERVER as $key => $val) {
1582
-	        if (strncmp($key, 'HTTP_CONTENT', 11)) continue;
1583
-	        switch ($key) {
1584
-		        case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1585
-		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1586
-		        	{
1587
-		        		case 'gzip':
1588
-		        		case 'deflate':	//zlib
1589
-		        			if (extension_loaded('zlib')) break;
1590
-		        			// fall through for no zlib support
1591
-		        		default:
1592
-					        $this->http_status('415 Unsupported Media Type');
1593
-					        echo "The service does not support '$val' content encoding";
1594
-					        return;
1595
-		        	}
1596
-		        	break;
1597
-
1598
-		        case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12
1599
-			        // we assume it is not critical if this one is ignored
1600
-			        // in the actual POST implementation ...
1601
-			        $options['content_language'] = $val;
1602
-			        break;
1603
-
1604
-		        case 'HTTP_CONTENT_LENGTH':
1605
-			        // defined on IIS and has the same value as CONTENT_LENGTH
1606
-			        break;
1607
-
1608
-		        case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
1609
-			        /* The meaning of the Content-Location header in PUT
1610
-			         or POST requests is undefined; servers are free
1611
-			         to ignore it in those cases. */
1612
-			        break;
2294
+	// {{{ _check_auth
1613 2295
 
1614
-		        case 'HTTP_CONTENT_RANGE':    // RFC 2616 14.16
1615
-			        // single byte range requests are supported
1616
-			        // the header format is also specified in RFC 2616 14.16
1617
-			        // TODO we have to ensure that implementations support this or send 501 instead
1618
-					$matches = null;
1619
-			        if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
1620
-				        $this->http_status('400 bad request');
1621
-				        echo 'The service does only support single byte ranges';
1622
-				        return;
1623
-			        }
1624
-
1625
-			        $range = array('start'=>$matches[1], 'end'=>$matches[2]);
1626
-			        if (is_numeric($matches[3])) {
1627
-				        $range['total_length'] = $matches[3];
1628
-			        }
1629
-			        $options['ranges'][] = $range;
1630
-
1631
-			        // TODO make sure the implementation supports partial POST
1632
-			        // this has to be done in advance to avoid data being overwritten
1633
-			        // on implementations that do not support this ...
1634
-			        break;
1635
-
1636
-		        case 'HTTP_CONTENT_TYPE':
1637
-			        // defined on IIS and has the same value as CONTENT_TYPE
1638
-			        break;
1639
-
1640
-		        case 'HTTP_CONTENT_MD5':      // RFC 2616 14.15
1641
-			        // TODO: maybe we can just pretend here?
1642
-			        $this->http_status('501 not implemented');
1643
-			        echo 'The service does not support content MD5 checksum verification';
1644
-			        return;
1645
-
1646
-		        case 'HTTP_CONTENT_DISPOSITION':
1647
-		        	// do NOT care about Content-Disposition in POST requests required by CalDAV managed attachments
1648
-		        	break;
1649
-
1650
-		        default:
1651
-			        // any other unknown Content-* headers
1652
-			        $this->http_status('501 not implemented');
1653
-		        echo "The service does not support '$key'";
1654
-		        return;
1655
-	        }
1656
-        }
1657
-
1658
-        if (method_exists($this, 'POST')) {
1659
-	        $status = $this->POST($options);
1660
-
1661
-	        if ($status === false) {
1662
-		        $status = '400 Something went wrong';
1663
-	        } else if ($status === true) {
1664
-	        	$status = '200 OK';
1665
-	        } else if (is_resource($status) && get_resource_type($status) == 'stream') {
1666
-		        $stream = $status;
1667
-
1668
-		        $status = empty($options['new']) ? '200 OK' : '201 Created';
1669
-
1670
-		        if (!empty($options['ranges'])) {
1671
-			        // TODO multipart support is missing (see also above)
1672
-			        if (0 == fseek($stream, $range[0]['start'], SEEK_SET)) {
1673
-				        $length = $range[0]['end']-$range[0]['start']+1;
1674
-				        if (!fwrite($stream, fread($options['stream'], $length))) {
1675
-					        $status = '403 Forbidden';
1676
-				        }
1677
-			        } else {
1678
-				        $status = '403 Forbidden';
1679
-			        }
1680
-		        } else {
1681
-			        while (!feof($options['stream'])) {
1682
-				        if (false === fwrite($stream, fread($options['stream'], 4096))) {
1683
-					        $status = '403 Forbidden';
1684
-					        break;
1685
-				        }
1686
-			        }
1687
-		        }
1688
-		        fclose($stream);
1689
-	        }
1690
-        }
1691
-        $this->http_status($status);
1692
-    }
1693
-
1694
-    // }}}
1695
-
1696
-    // {{{ http_PUT()
2296
+	/**
2297
+	 * check authentication if check is implemented
2298
+	 *
2299
+	 * @param  void
2300
+	 * @return bool  true if authentication succeded or not necessary
2301
+	 */
2302
+	function _check_auth()
2303
+	{
2304
+		if (method_exists($this, "checkAuth")) {
2305
+			// PEAR style method name
2306
+			return $this->checkAuth(@$this->_SERVER["AUTH_TYPE"],
2307
+									@$this->_SERVER["PHP_AUTH_USER"],
2308
+									@$this->_SERVER["PHP_AUTH_PW"]);
2309
+		} else if (method_exists($this, "check_auth")) {
2310
+			// old (pre 1.0) method name
2311
+			return $this->check_auth(@$this->_SERVER["AUTH_TYPE"],
2312
+									 @$this->_SERVER["PHP_AUTH_USER"],
2313
+									 @$this->_SERVER["PHP_AUTH_PW"]);
2314
+		} else {
2315
+			// no method found -> no authentication required
2316
+			return true;
2317
+		}
2318
+	}
1697 2319
 
1698
-    /**
1699
-     * PUT method handler
1700
-     *
1701
-     * @param  void
1702
-     * @return void
1703
-     */
1704
-    function http_PUT()
1705
-    {
1706
-        if ($this->_check_lock_status($this->path)) {
1707
-            $options                   = Array();
1708
-            $options["path"]           = $this->path;
1709
-
1710
-            if (isset($this->_SERVER['CONTENT_LENGTH']))
1711
-            {
1712
-            	$options['content_length'] = $this->_SERVER['CONTENT_LENGTH'];
1713
-            }
1714
-            elseif (isset($this->_SERVER['X-Expected-Entity-Length']))
1715
-            {
1716
-            	// MacOS gives us that hint
1717
-            	$options['content_length'] = $this->_SERVER['X-Expected-Entity-Length'];
1718
-            }
1719
-
1720
-            // get the Content-type
1721
-            if (isset($this->_SERVER["CONTENT_TYPE"])) {
1722
-                // for now we do not support any sort of multipart requests
1723
-                if (!strncmp($this->_SERVER["CONTENT_TYPE"], "multipart/", 10)) {
1724
-                    $this->http_status("501 not implemented");
1725
-                    echo "The service does not support multipart PUT requests";
1726
-                    return;
1727
-                }
1728
-                $options["content_type"] = $this->_SERVER["CONTENT_TYPE"];
1729
-            } else {
1730
-                // default content type if none given
1731
-                $options["content_type"] = "application/octet-stream";
1732
-            }
1733
-
1734
-            $options["stream"] = fopen("php://input", "r");
1735
-	    	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1736
-	    	{
1737
-	    		case 'gzip':
1738
-	    		case 'deflate':	//zlib
1739
-	    			if (extension_loaded('zlib'))
1740
-	     			{
1741
-	      				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1742
-	       			}
1743
-	    	}
1744
-			// store request in $this->request, if requested via $this->store_request
1745
-			if ($this->store_request)
1746
-			{
1747
-				$options['content'] = '';
1748
-				while(!feof($options['stream']))
1749
-				{
1750
-					$options['content'] .= fread($options['stream'],8192);
1751
-				}
1752
-				$this->request =& $options['content'];
1753
-				unset($options['stream']);
1754
-			}
2320
+	// }}}
1755 2321
 
1756
-            /* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
1757
-             ignore any Content-* (e.g. Content-Range) headers that it
1758
-             does not understand or implement and MUST return a 501
1759
-             (Not Implemented) response in such cases."
1760
-            */
1761
-            foreach ($this->_SERVER as $key => $val) {
1762
-                if (strncmp($key, "HTTP_CONTENT", 11)) continue;
1763
-                switch ($key) {
1764
-                case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1765
-		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1766
-		        	{
1767
-		        		case 'gzip':
1768
-		        		case 'deflate':	//zlib
1769
-		        			if (extension_loaded('zlib')) break;
1770
-		        			// fall through for no zlib support
1771
-		        		default:
1772
-					        $this->http_status('415 Unsupported Media Type');
1773
-					        echo "The service does not support '$val' content encoding";
1774
-					        return;
1775
-		        	}
1776
-		        	break;
1777
-
1778
-                case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12
1779
-                    // we assume it is not critical if this one is ignored
1780
-                    // in the actual PUT implementation ...
1781
-                    $options["content_language"] = $val;
1782
-                    break;
1783
-
1784
-                case 'HTTP_CONTENT_LENGTH':
1785
-                    // defined on IIS and has the same value as CONTENT_LENGTH
1786
-                    break;
1787
-
1788
-                case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
1789
-                    /* The meaning of the Content-Location header in PUT
1790
-                     or POST requests is undefined; servers are free
1791
-                     to ignore it in those cases. */
1792
-                    break;
2322
+	// {{{ UUID stuff
1793 2323
 
1794
-                case 'HTTP_CONTENT_RANGE':    // RFC 2616 14.16
1795
-                    // single byte range requests are supported
1796
-                    // the header format is also specified in RFC 2616 14.16
1797
-                    // TODO we have to ensure that implementations support this or send 501 instead
1798
-					$matches = null;
1799
-                    if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
1800
-                        $this->http_status("400 bad request");
1801
-                        echo "The service does only support single byte ranges";
1802
-                        return;
1803
-                    }
1804
-
1805
-                    $range = array("start" => $matches[1], "end" => $matches[2]);
1806
-                    if (is_numeric($matches[3])) {
1807
-                        $range["total_length"] = $matches[3];
1808
-                    }
1809
-
1810
-                    if (!isset($options['ranges'])) {
1811
-                        $options['ranges'] = array();
1812
-                    }
1813
-
1814
-                    $options["ranges"][] = $range;
1815
-
1816
-                    // TODO make sure the implementation supports partial PUT
1817
-                    // this has to be done in advance to avoid data being overwritten
1818
-                    // on implementations that do not support this ...
1819
-                    break;
1820
-
1821
-                case 'HTTP_CONTENT_TYPE':
1822
-                    // defined on IIS and has the same value as CONTENT_TYPE
1823
-                    break;
1824
-
1825
-                case 'HTTP_CONTENT_MD5':      // RFC 2616 14.15
1826
-                    // TODO: maybe we can just pretend here?
1827
-                    $this->http_status("501 not implemented");
1828
-                    echo "The service does not support content MD5 checksum verification";
1829
-                    return;
1830
-
1831
-                default:
1832
-                    // any other unknown Content-* headers
1833
-                    $this->http_status("501 not implemented");
1834
-                    echo "The service does not support '$key'";
1835
-                    return;
1836
-                }
1837
-            }
1838
-
1839
-            $stat = $this->PUT($options);
1840
-
1841
-            if ($stat === false) {
1842
-                $stat = "403 Forbidden";
1843
-            } else if (is_resource($stat) && get_resource_type($stat) == "stream") {
1844
-                $stream = $stat;
1845
-
1846
-                $stat = $options["new"] ? "201 Created" : "204 No Content";
1847
-
1848
-                if (!empty($options["ranges"])) {
1849
-                    // TODO multipart support is missing (see also above)
1850
-                    if (0 == fseek($stream, $options['ranges'][0]["start"], SEEK_SET)) {
1851
-                        $length = $options['ranges'][0]["end"] - $options['ranges'][0]["start"]+1;
1852
-
1853
-                        while (!feof($options['stream'])) {
1854
-                            if ($length <= 0) {
1855
-                               break;
1856
-                            }
1857
-
1858
-                            if ($length <= 8192) {
1859
-                                $data = fread($options['stream'], $length);
1860
-                            } else {
1861
-                                $data = fread($options['stream'], 8192);
1862
-                            }
1863
-
1864
-                            if ($data === false) {
1865
-                                $stat = "400 Bad request";
1866
-                            } elseif (strlen($data)) {
1867
-                                if (false === fwrite($stream, $data)) {
1868
-                                    $stat = "403 Forbidden";
1869
-                                    break;
1870
-                                }
1871
-                                $length -= strlen($data);
1872
-                            }
1873
-                        }
1874
-                    } else {
1875
-                        $stat = "403 Forbidden";
1876
-                    }
1877
-                } else {
1878
-                    while (!feof($options["stream"])) {
1879
-                        if (false === fwrite($stream, fread($options["stream"], 8192))) {
1880
-                            $stat = "403 Forbidden";
1881
-                            break;
1882
-                        }
1883
-                    }
1884
-                }
1885
-
1886
-                fclose($stream);
1887
-            }
1888
-
1889
-            $this->http_status($stat);
1890
-        } else {
1891
-            $this->http_status("423 Locked");
1892
-        }
1893
-    }
1894
-
1895
-    // }}}
1896
-
1897
-
1898
-    // {{{ http_DELETE()
2324
+	/**
2325
+	 * generate Unique Universal IDentifier for lock token
2326
+	 *
2327
+	 * @param  void
2328
+	 * @return string  a new UUID
2329
+	 */
2330
+	public static function _new_uuid()
2331
+	{
2332
+		// use uuid extension from PECL if available
2333
+		if (function_exists("uuid_create")) {
2334
+			return uuid_create();
2335
+		}
1899 2336
 
1900
-    /**
1901
-     * DELETE method handler
1902
-     *
1903
-     * @param  void
1904
-     * @return void
1905
-     */
1906
-    function http_DELETE()
1907
-    {
1908
-        // check RFC 2518 Section 9.2, last paragraph
1909
-        if (isset($this->_SERVER["HTTP_DEPTH"])) {
1910
-            if ($this->_SERVER["HTTP_DEPTH"] != "infinity") {
1911
-				if (stripos($_SERVER['HTTP_USER_AGENT'],'webdrive') !== false)
1912
-				{
1913
-					// pretend we didnt see it, as webdrive does not handle the depth parameter correctly while deleting collections
1914
-				}
1915
-				else
1916
-				{
1917
-                	$this->http_status("400 Bad Request");
1918
-                	return;
1919
-				}
1920
-            }
1921
-        }
2337
+		// fallback
2338
+		$uuid = md5(microtime().getmypid());    // this should be random enough for now
2339
+
2340
+		// set variant and version fields for 'true' random uuid
2341
+		$uuid{12} = "4";
2342
+		$n = 8 + (ord($uuid{16}) & 3);
2343
+		$hex = "0123456789abcdef";
2344
+		$uuid{16} = $hex{$n};
2345
+
2346
+		// return formated uuid
2347
+		return substr($uuid,  0, 8)."-"
2348
+			.  substr($uuid,  8, 4)."-"
2349
+			.  substr($uuid, 12, 4)."-"
2350
+			.  substr($uuid, 16, 4)."-"
2351
+			.  substr($uuid, 20);
2352
+	}
1922 2353
 
1923
-        // check lock status
1924
-        if ($this->_check_lock_status($this->path)) {
1925
-            // ok, proceed
1926
-            $options         = Array();
1927
-            $options["path"] = $this->path;
2354
+	/**
2355
+	 * create a new opaque lock token as defined in RFC2518
2356
+	 *
2357
+	 * @param  void
2358
+	 * @return string  new RFC2518 opaque lock token
2359
+	 */
2360
+	public static function _new_locktoken()
2361
+	{
2362
+		return "opaquelocktoken:".self::_new_uuid();
2363
+	}
1928 2364
 
1929
-            $stat = $this->DELETE($options);
2365
+	// }}}
1930 2366
 
1931
-            $this->http_status($stat);
1932
-        } else {
1933
-            // sorry, its locked
1934
-            $this->http_status("423 Locked");
1935
-        }
1936
-    }
2367
+	// {{{ WebDAV If: header parsing
1937 2368
 
1938
-    // }}}
2369
+	/**
2370
+	 *
2371
+	 *
2372
+	 * @param  string  header string to parse
2373
+	 * @param  int     current parsing position
2374
+	 * @return array   next token (type and value)
2375
+	 */
2376
+	function _if_header_lexer($string, &$pos)
2377
+	{
2378
+		// skip whitespace
2379
+		while (ctype_space($string{$pos})) {
2380
+			++$pos;
2381
+		}
1939 2382
 
1940
-    // {{{ http_COPY()
2383
+		// already at end of string?
2384
+		if (strlen($string) <= $pos) {
2385
+			return false;
2386
+		}
1941 2387
 
1942
-    /**
1943
-     * COPY method handler
1944
-     *
1945
-     * @param  void
1946
-     * @return void
1947
-     */
1948
-    function http_COPY()
1949
-    {
1950
-        // no need to check source lock status here
1951
-        // destination lock status is always checked by the helper method
1952
-        $this->_copymove("copy");
1953
-    }
1954
-
1955
-    // }}}
1956
-
1957
-    // {{{ http_MOVE()
2388
+		// get next character
2389
+		$c = $string{$pos++};
2390
+
2391
+		// now it depends on what we found
2392
+		switch ($c) {
2393
+		case "<":
2394
+			// URIs are enclosed in <...>
2395
+			$pos2 = strpos($string, ">", $pos);
2396
+			$uri  = substr($string, $pos, $pos2 - $pos);
2397
+			$pos  = $pos2 + 1;
2398
+			return array("URI", $uri);
2399
+
2400
+		case "[":
2401
+			//Etags are enclosed in [...]
2402
+			if ($string{$pos} == "W") {
2403
+				$type = "ETAG_WEAK";
2404
+				$pos += 2;
2405
+			} else {
2406
+				$type = "ETAG_STRONG";
2407
+			}
2408
+			$pos2 = strpos($string, "]", $pos);
2409
+			$etag = substr($string, $pos + 1, $pos2 - $pos - 2);
2410
+			$pos  = $pos2 + 1;
2411
+			return array($type, $etag);
2412
+
2413
+		case "N":
2414
+			// "N" indicates negation
2415
+			$pos += 2;
2416
+			return array("NOT", "Not");
2417
+
2418
+		default:
2419
+			// anything else is passed verbatim char by char
2420
+			return array("CHAR", $c);
2421
+		}
2422
+	}
1958 2423
 
1959
-    /**
1960
-     * MOVE method handler
1961
-     *
1962
-     * @param  void
1963
-     * @return void
1964
-     */
1965
-    function http_MOVE()
1966
-    {
1967
-        if ($this->_check_lock_status($this->path)) {
1968
-            // destination lock status is always checked by the helper method
1969
-            $this->_copymove("move");
1970
-        } else {
1971
-            $this->http_status("423 Locked");
1972
-        }
1973
-    }
1974
-
1975
-    // }}}
1976
-
1977
-
1978
-    // {{{ http_LOCK()
2424
+	/**
2425
+	 * parse If: header
2426
+	 *
2427
+	 * @param  string  header string
2428
+	 * @return array   URIs and their conditions
2429
+	 */
2430
+	function _if_header_parser($str)
2431
+	{
2432
+		$pos  = 0;
2433
+		$len  = strlen($str);
2434
+		$uris = array();
2435
+
2436
+		// parser loop
2437
+		while ($pos < $len) {
2438
+			// get next token
2439
+			$token = $this->_if_header_lexer($str, $pos);
2440
+
2441
+			// check for URI
2442
+			if ($token[0] == "URI") {
2443
+				$uri   = $token[1]; // remember URI
2444
+				$token = $this->_if_header_lexer($str, $pos); // get next token
2445
+			} else {
2446
+				$uri = "";
2447
+			}
1979 2448
 
1980
-    /**
1981
-     * LOCK method handler
1982
-     *
1983
-     * @param  void
1984
-     * @return void
1985
-     */
1986
-    function http_LOCK()
1987
-    {
1988
-        $options         = Array();
1989
-        $options["path"] = $this->path;
1990
-
1991
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
1992
-            $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
1993
-        } else {
1994
-            $options["depth"] = "infinity";
1995
-        }
1996
-
1997
-        if (isset($this->_SERVER["HTTP_TIMEOUT"])) {
1998
-            $options["timeout"] = explode(",", $this->_SERVER["HTTP_TIMEOUT"]);
1999
-        }
2000
-
2001
-        if (empty($this->_SERVER['CONTENT_LENGTH']) && !empty($this->_SERVER['HTTP_IF'])) {
2002
-            // check if locking is possible
2003
-            if (!$this->_check_lock_status($this->path)) {
2004
-                $this->http_status("423 Locked");
2005
-                return;
2006
-            }
2007
-
2008
-            // refresh lock
2009
-            $options["locktoken"] = substr($this->_SERVER['HTTP_IF'], 2, -2);
2010
-            $options["update"]    = $options["locktoken"];
2011
-
2012
-            // setting defaults for required fields, LOCK() SHOULD overwrite these
2013
-            $options['owner']     = "unknown";
2014
-            $options['scope']     = "exclusive";
2015
-            $options['type']      = "write";
2016
-
2017
-
2018
-            $stat = $this->LOCK($options);
2019
-        } else {
2020
-            // extract lock request information from request XML payload
2021
-            $lockinfo = new _parse_lockinfo("php://input");
2022
-            if (!$lockinfo->success) {
2023
-                $this->http_status("400 bad request");
2024
-            }
2025
-
2026
-            // check if locking is possible
2027
-            if (!$this->_check_lock_status($this->path, $lockinfo->lockscope === "shared")) {
2028
-                $this->http_status("423 Locked");
2029
-                return;
2030
-            }
2031
-
2032
-            // new lock
2033
-            $options["scope"]     = $lockinfo->lockscope;
2034
-            $options["type"]      = $lockinfo->locktype;
2035
-            // Todo: lockinfo::owner still contains D:href opening and closing tags, maybe they should be removed here with strip_tags
2036
-            $options["owner"]     = $lockinfo->owner;
2037
-            $options["locktoken"] = $this->_new_locktoken();
2038
-
2039
-            $stat = $this->LOCK($options);
2040
-        }
2041
-
2042
-        if (is_bool($stat)) {
2043
-            $http_stat = $stat ? "200 OK" : "423 Locked";
2044
-        } else {
2045
-            $http_stat = (string)$stat;
2046
-        }
2047
-        $this->http_status($http_stat);
2048
-
2049
-        if ($http_stat{0} == 2) { // 2xx states are ok
2050
-            if ($options["timeout"]) {
2051
-                // if multiple timeout values were given we take the first only
2052
-                if (is_array($options["timeout"])) {
2053
-                    reset($options["timeout"]);
2054
-                    $options["timeout"] = current($options["timeout"]);
2055
-                }
2056
-                // if the timeout is numeric only we need to reformat it
2057
-                if (is_numeric($options["timeout"])) {
2058
-                    // more than a million is considered an absolute timestamp
2059
-                    // less is more likely a relative value
2060
-                    if ($options["timeout"]>1000000) {
2061
-                        $timeout = "Second-".($options['timeout']-time());
2062
-                    } else {
2063
-                        $timeout = "Second-$options[timeout]";
2064
-                    }
2065
-                } else {
2066
-                    // non-numeric values are passed on verbatim,
2067
-                    // no error checking is performed here in this case
2068
-                    // TODO: send "Infinite" on invalid timeout strings?
2069
-                    $timeout = $options["timeout"];
2070
-                }
2071
-            } else {
2072
-                $timeout = "Infinite";
2073
-            }
2074
-
2075
-            header('Content-Type: text/xml; charset="utf-8"');
2076
-            header("Lock-Token: <$options[locktoken]>");
2077
-            echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2078
-            echo "<D:prop xmlns:D=\"DAV:\">\n";
2079
-            echo ' <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2080
-            echo '  <'.($this->crrnd?'':'D:')."activelock>\n";
2081
-            echo '   <'.($this->crrnd?'':'D:')."lockscope><D:$options[scope]/></".($this->crrnd?'':'D:')."lockscope>\n";
2082
-            echo '   <'.($this->crrnd?'':'D:')."locktype><D:$options[type]/></".($this->crrnd?'':'D:')."locktype>\n";
2083
-            echo '   <'.($this->crrnd?'':'D:')."depth>$options[depth]</".($this->crrnd?'':'D:')."depth>\n";
2084
-            echo '   <'.($this->crrnd?'':'D:')."owner>$options[owner]</".($this->crrnd?'':'D:')."owner>\n";
2085
-            echo '   <'.($this->crrnd?'':'D:')."timeout>$timeout</".($this->crrnd?'':'D:')."timeout>\n";
2086
-            echo '   <'.($this->crrnd?'':'D:')."locktoken><D:href>$options[locktoken]</D:href></".($this->crrnd?'':'D:')."locktoken>\n";
2087
-            echo '  </'.($this->crrnd?'':'D:')."activelock>\n";
2088
-            echo ' </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2089
-            echo '</'.($this->crrnd?'':'D:')."prop>\n\n";
2090
-        }
2091
-    }
2092
-
2093
-
2094
-    // }}}
2095
-
2096
-    // {{{ http_UNLOCK()
2449
+			// sanity check
2450
+			if ($token[0] != "CHAR" || $token[1] != "(") {
2451
+				return false;
2452
+			}
2097 2453
 
2098
-    /**
2099
-     * UNLOCK method handler
2100
-     *
2101
-     * @param  void
2102
-     * @return void
2103
-     */
2104
-    function http_UNLOCK()
2105
-    {
2106
-        $options         = Array();
2107
-        $options["path"] = $this->path;
2108
-
2109
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
2110
-            $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2111
-        } else {
2112
-            $options["depth"] = "infinity";
2113
-        }
2114
-
2115
-        // strip surrounding <>
2116
-        $options["token"] = substr(trim($this->_SERVER["HTTP_LOCK_TOKEN"]), 1, -1);
2117
-
2118
-        // call user method
2119
-        $stat = $this->UNLOCK($options);
2120
-
2121
-        $this->http_status($stat);
2122
-    }
2123
-
2124
-    // }}}
2125
-
2126
-    // {{{ http_ACL()
2127
-
2128
-	/**
2129
-     * ACL method handler
2130
-     *
2131
-     * @param  void
2132
-     * @return void
2133
-     */
2134
-    function http_ACL()
2135
-    {
2136
-        $options         = Array();
2137
-        $options['path'] = $this->path;
2138
-        $options['errors'] = array();
2139
-
2140
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
2141
-            $options['depth'] = $this->_SERVER['HTTP_DEPTH'];
2142
-        } else {
2143
-            $options['depth'] = 'infinity';
2144
-        }
2145
-
2146
-        // call user method
2147
-        $status = $this->ACL($options);
2454
+			$list  = array();
2455
+			$level = 1;
2456
+			$not   = "";
2457
+			while ($level) {
2458
+				$token = $this->_if_header_lexer($str, $pos);
2459
+				if ($token[0] == "NOT") {
2460
+					$not = "!";
2461
+					continue;
2462
+				}
2463
+				switch ($token[0]) {
2464
+				case "CHAR":
2465
+					switch ($token[1]) {
2466
+					case "(":
2467
+						$level++;
2468
+						break;
2469
+					case ")":
2470
+						$level--;
2471
+						break;
2472
+					default:
2473
+						return false;
2474
+					}
2475
+					break;
2148 2476
 
2149
-		// now we generate the reply header ...
2150
-		$this->http_status($status);
2151
-		$content = '';
2477
+				case "URI":
2478
+					$list[] = $not."<$token[1]>";
2479
+					break;
2152 2480
 
2153
-        if (is_array($options['errors']) && count($options['errors'])) {
2154
-	        header('Content-Type: text/xml; charset="utf-8"');
2155
-	        // ... and payload
2156
-	        $content .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2157
-	        $content .= "<D:error xmlns:D=\"DAV:\"> \n";
2158
-	        foreach ($options['errors'] as $violation) {
2159
-	        	$content .= '<'.($this->crrnd?'':'D:')."$violation/>\n";
2160
-	        }
2161
-	        $content .=  '</'.($this->crrnd?'':'D:')."error>\n";
2162
-        }
2163
-        if (!self::use_compression()) header("Content-Length: ".self::bytes($content));
2164
-        if ($content) echo $options['content'];
2165
-    }
2166
-
2167
-    // }}}
2168
-
2169
-    // }}}
2170
-
2171
-    // {{{ _copymove()
2172
-
2173
-    function _copymove($what)
2174
-    {
2175
-        $options         = Array();
2176
-        $options["path"] = $this->path;
2177
-
2178
-        if (isset($this->_SERVER["HTTP_DEPTH"])) {
2179
-            $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2180
-        } else {
2181
-            $options["depth"] = "infinity";
2182
-        }
2183
-
2184
-        $http_header_host = preg_replace("/:80$/", "", $this->_SERVER["HTTP_HOST"]);
2185
-
2186
-        $url  = parse_url($this->_SERVER["HTTP_DESTINATION"]);
2187
-        $path = urldecode($url["path"]);
2188
-
2189
-        if (isset($url["host"])) {
2190
-            // TODO check url scheme, too
2191
-            $http_host = $url["host"];
2192
-            if (isset($url["port"]) && $url["port"] != 80)
2193
-                $http_host.= ":".$url["port"];
2194
-        } else {
2195
-            // only path given, set host to self
2196
-            $http_host = $http_header_host;
2197
-        }
2198
-
2199
-        if ($http_host == $http_header_host &&
2200
-            !strncmp($this->_SERVER["SCRIPT_NAME"], $path,
2201
-                     strlen($this->_SERVER["SCRIPT_NAME"]))) {
2202
-            $options["dest"] = substr($path, strlen($this->_SERVER["SCRIPT_NAME"]));
2203
-            if (!$this->_check_lock_status($options["dest"])) {
2204
-                $this->http_status("423 Locked");
2205
-                return;
2206
-            }
2207
-
2208
-        } else {
2209
-            $options["dest_url"] = $this->_SERVER["HTTP_DESTINATION"];
2210
-        }
2211
-
2212
-        // see RFC 2518 Sections 9.6, 8.8.4 and 8.9.3
2213
-        if (isset($this->_SERVER["HTTP_OVERWRITE"])) {
2214
-            $options["overwrite"] = $this->_SERVER["HTTP_OVERWRITE"] == "T";
2215
-        } else {
2216
-            $options["overwrite"] = true;
2217
-        }
2218
-
2219
-        $stat = $this->$what($options);
2220
-        $this->http_status($stat);
2221
-    }
2222
-
2223
-    // }}}
2224
-
2225
-    // {{{ _allow()
2481
+				case "ETAG_WEAK":
2482
+					$list[] = $not."[W/'$token[1]']>";
2483
+					break;
2226 2484
 
2227
-    /**
2228
-     * check for implemented HTTP methods
2229
-     *
2230
-     * @param  void
2231
-     * @return array something
2232
-     */
2233
-    function _allow()
2234
-    {
2235
-        // OPTIONS is always there
2236
-        $allow = array("OPTIONS" =>"OPTIONS");
2237
-
2238
-        // all other METHODS need both a http_method() wrapper
2239
-        // and a method() implementation
2240
-        // the base class supplies wrappers only
2241
-        foreach (get_class_methods($this) as $method) {
2242
-            if (!strncmp("http_", $method, 5)) {
2243
-                $method = strtoupper(substr($method, 5));
2244
-                if (method_exists($this, $method)) {
2245
-                    $allow[$method] = $method;
2246
-                }
2247
-            }
2248
-        }
2249
-
2250
-        // we can emulate a missing HEAD implemetation using GET
2251
-        if (isset($allow["GET"]))
2252
-            $allow["HEAD"] = "HEAD";
2253
-
2254
-        // no LOCK without checklok()
2255
-        if (!method_exists($this, "checklock")) {
2256
-            unset($allow["LOCK"]);
2257
-            unset($allow["UNLOCK"]);
2258
-        }
2259
-
2260
-        return $allow;
2261
-    }
2262
-
2263
-    // }}}
2485
+				case "ETAG_STRONG":
2486
+					$list[] = $not."['$token[1]']>";
2487
+					break;
2264 2488
 
2265
-    /**
2266
-     * helper for property element creation
2267
-     *
2268
-     * @param  string  XML namespace (optional)
2269
-     * @param  string  property name
2270
-     * @param  string  property value
2271
-     * @praram boolen  property raw-flag
2272
-     * @return array   property array
2273
-     */
2274
-    public static function mkprop()
2275
-    {
2276
-	    $args = func_get_args();
2277
-	    switch (count($args)) {
2278
-		    case 4:
2279
-			    return array('ns'   => $args[0],
2280
-				    'name' => $args[1],
2281
-					'val'  => $args[2],
2282
-					'raw'	=> true);
2283
-		    case 3:
2284
-			    return array('ns'   => $args[0],
2285
-				    'name' => $args[1],
2286
-					'val'  => $args[2]);
2287
-		    default:
2288
-			    return array('ns'   => 'DAV:',
2289
-				    'name' => $args[0],
2290
-					'val'  => $args[1]);
2291
-	    }
2292
-    }
2489
+				default:
2490
+					return false;
2491
+				}
2492
+				$not = "";
2493
+			}
2293 2494
 
2294
-    // {{{ _check_auth
2495
+			if (@is_array($uris[$uri])) {
2496
+				$uris[$uri] = array_merge($uris[$uri], $list);
2497
+			} else {
2498
+				$uris[$uri] = $list;
2499
+			}
2500
+		}
2295 2501
 
2296
-    /**
2297
-     * check authentication if check is implemented
2298
-     *
2299
-     * @param  void
2300
-     * @return bool  true if authentication succeded or not necessary
2301
-     */
2302
-    function _check_auth()
2303
-    {
2304
-        if (method_exists($this, "checkAuth")) {
2305
-            // PEAR style method name
2306
-            return $this->checkAuth(@$this->_SERVER["AUTH_TYPE"],
2307
-                                    @$this->_SERVER["PHP_AUTH_USER"],
2308
-                                    @$this->_SERVER["PHP_AUTH_PW"]);
2309
-        } else if (method_exists($this, "check_auth")) {
2310
-            // old (pre 1.0) method name
2311
-            return $this->check_auth(@$this->_SERVER["AUTH_TYPE"],
2312
-                                     @$this->_SERVER["PHP_AUTH_USER"],
2313
-                                     @$this->_SERVER["PHP_AUTH_PW"]);
2314
-        } else {
2315
-            // no method found -> no authentication required
2316
-            return true;
2317
-        }
2318
-    }
2319
-
2320
-    // }}}
2321
-
2322
-    // {{{ UUID stuff
2502
+		return $uris;
2503
+	}
2323 2504
 
2324
-    /**
2325
-     * generate Unique Universal IDentifier for lock token
2326
-     *
2327
-     * @param  void
2328
-     * @return string  a new UUID
2329
-     */
2330
-    public static function _new_uuid()
2331
-    {
2332
-        // use uuid extension from PECL if available
2333
-        if (function_exists("uuid_create")) {
2334
-            return uuid_create();
2335
-        }
2336
-
2337
-        // fallback
2338
-        $uuid = md5(microtime().getmypid());    // this should be random enough for now
2339
-
2340
-        // set variant and version fields for 'true' random uuid
2341
-        $uuid{12} = "4";
2342
-        $n = 8 + (ord($uuid{16}) & 3);
2343
-        $hex = "0123456789abcdef";
2344
-        $uuid{16} = $hex{$n};
2345
-
2346
-        // return formated uuid
2347
-        return substr($uuid,  0, 8)."-"
2348
-            .  substr($uuid,  8, 4)."-"
2349
-            .  substr($uuid, 12, 4)."-"
2350
-            .  substr($uuid, 16, 4)."-"
2351
-            .  substr($uuid, 20);
2352
-    }
2505
+	/**
2506
+	 * check if conditions from "If:" headers are meat
2507
+	 *
2508
+	 * the "If:" header is an extension to HTTP/1.1
2509
+	 * defined in RFC 2518 section 9.4
2510
+	 *
2511
+	 * @param  void
2512
+	 * @return void
2513
+	 */
2514
+	function _check_if_header_conditions()
2515
+	{
2516
+		if (isset($this->_SERVER["HTTP_IF"])) {
2517
+			$this->_if_header_uris =
2518
+				$this->_if_header_parser($this->_SERVER["HTTP_IF"]);
2353 2519
 
2354
-    /**
2355
-     * create a new opaque lock token as defined in RFC2518
2356
-     *
2357
-     * @param  void
2358
-     * @return string  new RFC2518 opaque lock token
2359
-     */
2360
-    public static function _new_locktoken()
2361
-    {
2362
-        return "opaquelocktoken:".self::_new_uuid();
2363
-    }
2520
+			foreach ($this->_if_header_uris as $uri => $conditions) {
2521
+				if ($uri == "") {
2522
+					$uri = $this->uri;
2523
+				}
2524
+				// all must match
2525
+				$state = true;
2526
+				foreach ($conditions as $condition) {
2527
+					// lock tokens may be free form (RFC2518 6.3)
2528
+					// but if opaquelocktokens are used (RFC2518 6.4)
2529
+					// we have to check the format (litmus tests this)
2530
+					if (!strncmp($condition, "<opaquelocktoken:", strlen("<opaquelocktoken"))) {
2531
+						if (!preg_match('/^<opaquelocktoken:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}>$/', $condition)) {
2532
+							$this->http_status("423 Locked");
2533
+							return false;
2534
+						}
2535
+					}
2536
+					if (!$this->_check_uri_condition($uri, $condition)) {
2537
+						$this->http_status("412 Precondition failed");
2538
+						$state = false;
2539
+						break;
2540
+					}
2541
+				}
2364 2542
 
2365
-    // }}}
2543
+				// any match is ok
2544
+				if ($state == true) {
2545
+					return true;
2546
+				}
2547
+			}
2548
+			return false;
2549
+		}
2550
+		return true;
2551
+	}
2366 2552
 
2367
-    // {{{ WebDAV If: header parsing
2553
+	/**
2554
+	 * Check a single URI condition parsed from an if-header
2555
+	 *
2556
+	 * Check a single URI condition parsed from an if-header
2557
+	 *
2558
+	 * @abstract
2559
+	 * @param string $uri URI to check
2560
+	 * @param string $condition Condition to check for this URI
2561
+	 * @returns bool Condition check result
2562
+	 */
2563
+	function _check_uri_condition($uri, $condition)
2564
+	{
2565
+		unset($uri);	// not used, but required by function signature
2566
+		// not really implemented here,
2567
+		// implementations must override
2368 2568
 
2369
-    /**
2370
-     *
2371
-     *
2372
-     * @param  string  header string to parse
2373
-     * @param  int     current parsing position
2374
-     * @return array   next token (type and value)
2375
-     */
2376
-    function _if_header_lexer($string, &$pos)
2377
-    {
2378
-        // skip whitespace
2379
-        while (ctype_space($string{$pos})) {
2380
-            ++$pos;
2381
-        }
2382
-
2383
-        // already at end of string?
2384
-        if (strlen($string) <= $pos) {
2385
-            return false;
2386
-        }
2387
-
2388
-        // get next character
2389
-        $c = $string{$pos++};
2390
-
2391
-        // now it depends on what we found
2392
-        switch ($c) {
2393
-        case "<":
2394
-            // URIs are enclosed in <...>
2395
-            $pos2 = strpos($string, ">", $pos);
2396
-            $uri  = substr($string, $pos, $pos2 - $pos);
2397
-            $pos  = $pos2 + 1;
2398
-            return array("URI", $uri);
2399
-
2400
-        case "[":
2401
-            //Etags are enclosed in [...]
2402
-            if ($string{$pos} == "W") {
2403
-                $type = "ETAG_WEAK";
2404
-                $pos += 2;
2405
-            } else {
2406
-                $type = "ETAG_STRONG";
2407
-            }
2408
-            $pos2 = strpos($string, "]", $pos);
2409
-            $etag = substr($string, $pos + 1, $pos2 - $pos - 2);
2410
-            $pos  = $pos2 + 1;
2411
-            return array($type, $etag);
2412
-
2413
-        case "N":
2414
-            // "N" indicates negation
2415
-            $pos += 2;
2416
-            return array("NOT", "Not");
2417
-
2418
-        default:
2419
-            // anything else is passed verbatim char by char
2420
-            return array("CHAR", $c);
2421
-        }
2422
-    }
2569
+		// a lock token can never be from the DAV: scheme
2570
+		// litmus uses DAV:no-lock in some tests
2571
+		if (!strncmp("<DAV:", $condition, 5)) {
2572
+			return false;
2573
+		}
2423 2574
 
2424
-    /**
2425
-     * parse If: header
2426
-     *
2427
-     * @param  string  header string
2428
-     * @return array   URIs and their conditions
2429
-     */
2430
-    function _if_header_parser($str)
2431
-    {
2432
-        $pos  = 0;
2433
-        $len  = strlen($str);
2434
-        $uris = array();
2435
-
2436
-        // parser loop
2437
-        while ($pos < $len) {
2438
-            // get next token
2439
-            $token = $this->_if_header_lexer($str, $pos);
2440
-
2441
-            // check for URI
2442
-            if ($token[0] == "URI") {
2443
-                $uri   = $token[1]; // remember URI
2444
-                $token = $this->_if_header_lexer($str, $pos); // get next token
2445
-            } else {
2446
-                $uri = "";
2447
-            }
2448
-
2449
-            // sanity check
2450
-            if ($token[0] != "CHAR" || $token[1] != "(") {
2451
-                return false;
2452
-            }
2453
-
2454
-            $list  = array();
2455
-            $level = 1;
2456
-            $not   = "";
2457
-            while ($level) {
2458
-                $token = $this->_if_header_lexer($str, $pos);
2459
-                if ($token[0] == "NOT") {
2460
-                    $not = "!";
2461
-                    continue;
2462
-                }
2463
-                switch ($token[0]) {
2464
-                case "CHAR":
2465
-                    switch ($token[1]) {
2466
-                    case "(":
2467
-                        $level++;
2468
-                        break;
2469
-                    case ")":
2470
-                        $level--;
2471
-                        break;
2472
-                    default:
2473
-                        return false;
2474
-                    }
2475
-                    break;
2476
-
2477
-                case "URI":
2478
-                    $list[] = $not."<$token[1]>";
2479
-                    break;
2480
-
2481
-                case "ETAG_WEAK":
2482
-                    $list[] = $not."[W/'$token[1]']>";
2483
-                    break;
2484
-
2485
-                case "ETAG_STRONG":
2486
-                    $list[] = $not."['$token[1]']>";
2487
-                    break;
2488
-
2489
-                default:
2490
-                    return false;
2491
-                }
2492
-                $not = "";
2493
-            }
2494
-
2495
-            if (@is_array($uris[$uri])) {
2496
-                $uris[$uri] = array_merge($uris[$uri], $list);
2497
-            } else {
2498
-                $uris[$uri] = $list;
2499
-            }
2500
-        }
2501
-
2502
-        return $uris;
2503
-    }
2575
+		return true;
2576
+	}
2504 2577
 
2505
-    /**
2506
-     * check if conditions from "If:" headers are meat
2507
-     *
2508
-     * the "If:" header is an extension to HTTP/1.1
2509
-     * defined in RFC 2518 section 9.4
2510
-     *
2511
-     * @param  void
2512
-     * @return void
2513
-     */
2514
-    function _check_if_header_conditions()
2515
-    {
2516
-        if (isset($this->_SERVER["HTTP_IF"])) {
2517
-            $this->_if_header_uris =
2518
-                $this->_if_header_parser($this->_SERVER["HTTP_IF"]);
2519
-
2520
-            foreach ($this->_if_header_uris as $uri => $conditions) {
2521
-                if ($uri == "") {
2522
-                    $uri = $this->uri;
2523
-                }
2524
-                // all must match
2525
-                $state = true;
2526
-                foreach ($conditions as $condition) {
2527
-                    // lock tokens may be free form (RFC2518 6.3)
2528
-                    // but if opaquelocktokens are used (RFC2518 6.4)
2529
-                    // we have to check the format (litmus tests this)
2530
-                    if (!strncmp($condition, "<opaquelocktoken:", strlen("<opaquelocktoken"))) {
2531
-                        if (!preg_match('/^<opaquelocktoken:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}>$/', $condition)) {
2532
-                            $this->http_status("423 Locked");
2533
-                            return false;
2534
-                        }
2535
-                    }
2536
-                    if (!$this->_check_uri_condition($uri, $condition)) {
2537
-                        $this->http_status("412 Precondition failed");
2538
-                        $state = false;
2539
-                        break;
2540
-                    }
2541
-                }
2542
-
2543
-                // any match is ok
2544
-                if ($state == true) {
2545
-                    return true;
2546
-                }
2547
-            }
2548
-            return false;
2549
-        }
2550
-        return true;
2551
-    }
2552 2578
 
2553
-    /**
2554
-     * Check a single URI condition parsed from an if-header
2555
-     *
2556
-     * Check a single URI condition parsed from an if-header
2557
-     *
2558
-     * @abstract
2559
-     * @param string $uri URI to check
2560
-     * @param string $condition Condition to check for this URI
2561
-     * @returns bool Condition check result
2562
-     */
2563
-    function _check_uri_condition($uri, $condition)
2564
-    {
2565
-		unset($uri);	// not used, but required by function signature
2566
-        // not really implemented here,
2567
-        // implementations must override
2579
+	/**
2580
+	 *
2581
+	 *
2582
+	 * @param  string  path of resource to check
2583
+	 * @param  bool    exclusive lock?
2584
+	 */
2585
+	function _check_lock_status($path, $exclusive_only = false)
2586
+	{
2587
+		// FIXME depth -> ignored for now
2588
+		if (method_exists($this, "checkLock")) {
2589
+			// is locked?
2590
+			$lock = $this->checkLock($path);
2591
+
2592
+			// ... and lock is not owned?
2593
+			if (is_array($lock) && count($lock)) {
2594
+				// FIXME doesn't check uri restrictions yet
2595
+				if (!isset($this->_SERVER["HTTP_IF"]) || !strstr($this->_SERVER["HTTP_IF"], $lock["token"])) {
2596
+					if (!$exclusive_only || ($lock["scope"] !== "shared"))
2597
+						return false;
2598
+				}
2599
+			}
2600
+		}
2601
+		return true;
2602
+	}
2568 2603
 
2569
-        // a lock token can never be from the DAV: scheme
2570
-        // litmus uses DAV:no-lock in some tests
2571
-        if (!strncmp("<DAV:", $condition, 5)) {
2572
-            return false;
2573
-        }
2574 2604
 
2575
-        return true;
2576
-    }
2605
+	// }}}
2577 2606
 
2578 2607
 
2579
-    /**
2580
-     *
2581
-     *
2582
-     * @param  string  path of resource to check
2583
-     * @param  bool    exclusive lock?
2584
-     */
2585
-    function _check_lock_status($path, $exclusive_only = false)
2586
-    {
2587
-        // FIXME depth -> ignored for now
2588
-        if (method_exists($this, "checkLock")) {
2589
-            // is locked?
2590
-            $lock = $this->checkLock($path);
2591
-
2592
-            // ... and lock is not owned?
2593
-            if (is_array($lock) && count($lock)) {
2594
-                // FIXME doesn't check uri restrictions yet
2595
-                if (!isset($this->_SERVER["HTTP_IF"]) || !strstr($this->_SERVER["HTTP_IF"], $lock["token"])) {
2596
-                    if (!$exclusive_only || ($lock["scope"] !== "shared"))
2597
-                        return false;
2598
-                }
2599
-            }
2600
-        }
2601
-        return true;
2602
-    }
2603
-
2604
-
2605
-    // }}}
2608
+	/**
2609
+	 * Generate lockdiscovery reply from checklock() result
2610
+	 *
2611
+	 * @param   string  resource path to check
2612
+	 * @return  string  lockdiscovery response
2613
+	 */
2614
+	function lockdiscovery($path)
2615
+	{
2616
+		// no lock support without checklock() method
2617
+		if (!method_exists($this, "checklock")) {
2618
+			return "";
2619
+		}
2606 2620
 
2621
+		// collect response here
2622
+		$activelocks = "";
2623
+
2624
+		// get checklock() reply
2625
+		$lock = $this->checklock($path);
2626
+
2627
+		// generate <activelock> block for returned data
2628
+		if (is_array($lock) && count($lock)) {
2629
+			// check for 'timeout' or 'expires'
2630
+			if (!empty($lock["expires"])) {
2631
+				$timeout = "Second-".($lock["expires"] - time());
2632
+			} else if (!empty($lock["timeout"])) {
2633
+				$timeout = "Second-$lock[timeout]";
2634
+			} else {
2635
+				$timeout = "Infinite";
2636
+			}
2607 2637
 
2608
-    /**
2609
-     * Generate lockdiscovery reply from checklock() result
2610
-     *
2611
-     * @param   string  resource path to check
2612
-     * @return  string  lockdiscovery response
2613
-     */
2614
-    function lockdiscovery($path)
2615
-    {
2616
-        // no lock support without checklock() method
2617
-        if (!method_exists($this, "checklock")) {
2618
-            return "";
2619
-        }
2620
-
2621
-        // collect response here
2622
-        $activelocks = "";
2623
-
2624
-        // get checklock() reply
2625
-        $lock = $this->checklock($path);
2626
-
2627
-        // generate <activelock> block for returned data
2628
-        if (is_array($lock) && count($lock)) {
2629
-            // check for 'timeout' or 'expires'
2630
-            if (!empty($lock["expires"])) {
2631
-                $timeout = "Second-".($lock["expires"] - time());
2632
-            } else if (!empty($lock["timeout"])) {
2633
-                $timeout = "Second-$lock[timeout]";
2634
-            } else {
2635
-                $timeout = "Infinite";
2636
-            }
2637
-
2638
-            // genreate response block
2639
-            if ($this->crrnd)
2640
-            {
2641
-	            $activelocks.= "
2638
+			// genreate response block
2639
+			if ($this->crrnd)
2640
+			{
2641
+				$activelocks.= "
2642 2642
 		            <activelock>
2643 2643
 		            <lockscope><$lock[scope]/></lockscope>
2644 2644
 		            <locktype><$lock[type]/></locktype>
@@ -2648,10 +2648,10 @@  discard block
 block discarded – undo
2648 2648
 		            <locktoken><href>$lock[token]</href></locktoken>
2649 2649
 		            </activelock>
2650 2650
 		            ";
2651
-            }
2652
-            else
2653
-            {
2654
-	            $activelocks.= "
2651
+			}
2652
+			else
2653
+			{
2654
+				$activelocks.= "
2655 2655
 		            <D:activelock>
2656 2656
 		            <D:lockscope><D:$lock[scope]/></D:lockscope>
2657 2657
 		            <D:locktype><D:$lock[type]/></D:locktype>
@@ -2661,47 +2661,47 @@  discard block
 block discarded – undo
2661 2661
 		            <D:locktoken><D:href>$lock[token]</D:href></D:locktoken>
2662 2662
 		            </D:activelock>
2663 2663
 		            ";
2664
-            }
2665
-        }
2664
+			}
2665
+		}
2666 2666
 
2667
-        // return generated response
2668
-        //error_log(__METHOD__."\n".print_r($activelocks,true));
2667
+		// return generated response
2668
+		//error_log(__METHOD__."\n".print_r($activelocks,true));
2669 2669
 		return $activelocks;
2670
-    }
2670
+	}
2671 2671
 
2672
-    /**
2673
-     * set HTTP return status and mirror it in a private header
2674
-     *
2675
-     * @param  string  status code and message
2676
-     * @return void
2677
-     */
2678
-    function http_status($status)
2679
-    {
2680
-        // simplified success case
2681
-        if ($status === true) {
2682
-            $status = "200 OK";
2683
-        }
2684
-
2685
-        // remember status
2686
-        $this->_http_status = $status;
2687
-
2688
-        // generate HTTP status response
2689
-        header("HTTP/1.1 $status");
2690
-        header("X-WebDAV-Status: $status", true);
2691
-    }
2672
+	/**
2673
+	 * set HTTP return status and mirror it in a private header
2674
+	 *
2675
+	 * @param  string  status code and message
2676
+	 * @return void
2677
+	 */
2678
+	function http_status($status)
2679
+	{
2680
+		// simplified success case
2681
+		if ($status === true) {
2682
+			$status = "200 OK";
2683
+		}
2692 2684
 
2693
-    /**
2694
-     * private minimalistic version of PHP urlencode()
2695
-     *
2696
-     * only blanks, percent and XML special chars must be encoded here
2697
-     * full urlencode() encoding confuses some clients ...
2698
-     *
2699
-     * @param  string  URL to encode
2700
-     * @return string  encoded URL
2701
-     * @todo check if other not explicitly named user-agents are happy with full url-encoding too and we can make it the default
2702
-     */
2703
-    public static function _urlencode($url)
2704
-    {
2685
+		// remember status
2686
+		$this->_http_status = $status;
2687
+
2688
+		// generate HTTP status response
2689
+		header("HTTP/1.1 $status");
2690
+		header("X-WebDAV-Status: $status", true);
2691
+	}
2692
+
2693
+	/**
2694
+	 * private minimalistic version of PHP urlencode()
2695
+	 *
2696
+	 * only blanks, percent and XML special chars must be encoded here
2697
+	 * full urlencode() encoding confuses some clients ...
2698
+	 *
2699
+	 * @param  string  URL to encode
2700
+	 * @return string  encoded URL
2701
+	 * @todo check if other not explicitly named user-agents are happy with full url-encoding too and we can make it the default
2702
+	 */
2703
+	public static function _urlencode($url)
2704
+	{
2705 2705
 		// cadaver (and probably all neon using agents) need a more complete url encoding
2706 2706
 		// otherwise special chars like "$,()'" in filenames do NOT work
2707 2707
 		if (strpos($_SERVER['HTTP_USER_AGENT'],'neon') !== false ||
@@ -2719,31 +2719,31 @@  discard block
 block discarded – undo
2719 2719
 		}
2720 2720
 		//error_log( __METHOD__."\n" .print_r($url,true));
2721 2721
 		return strtr($url, array(' '	=>	'%20',
2722
-                                 '%'	=>	'%25',
2723
-                                 '&'	=>	'%26',
2724
-                                 '<'	=>	'%3C',
2725
-                                 '>'	=>	'%3E',
2726
-                                 '+'	=>	'%2B',
2727
-                                 ));
2728
-    }
2722
+								 '%'	=>	'%25',
2723
+								 '&'	=>	'%26',
2724
+								 '<'	=>	'%3C',
2725
+								 '>'	=>	'%3E',
2726
+								 '+'	=>	'%2B',
2727
+								 ));
2728
+	}
2729 2729
 
2730
-    /**
2731
-     * private version of PHP urldecode
2732
-     *
2733
-     * not really needed but added for completenes
2734
-     *
2735
-     * @param  string  URL to decode
2736
-     * @return string  decoded URL
2737
-     */
2738
-    public static function _urldecode($path)
2739
-    {
2740
-        return rawurldecode($path);
2741
-    }
2730
+	/**
2731
+	 * private version of PHP urldecode
2732
+	 *
2733
+	 * not really needed but added for completenes
2734
+	 *
2735
+	 * @param  string  URL to decode
2736
+	 * @return string  decoded URL
2737
+	 */
2738
+	public static function _urldecode($path)
2739
+	{
2740
+		return rawurldecode($path);
2741
+	}
2742 2742
 
2743
-    /**
2744
-     * Encode a hierarchical properties like:
2745
-     *
2746
- 	 * <D:supported-report-set>
2743
+	/**
2744
+	 * Encode a hierarchical properties like:
2745
+	 *
2746
+	 * <D:supported-report-set>
2747 2747
 	 *    <supported-report>
2748 2748
 	 *       <report>
2749 2749
 	 *          <addressbook-query xmlns='urn:ietf:params:xml:ns:carddav'/>
@@ -2755,60 +2755,60 @@  discard block
 block discarded – undo
2755 2755
 	 *       </report>
2756 2756
 	 *    </supported-report>
2757 2757
 	 * </D:supported-report-set>
2758
-     *
2759
-     * @param array $props
2760
-     * @param string $ns
2761
-     * @param strin $ns_defs
2762
-     * @param array $ns_hash
2763
-     * @return string
2764
-     */
2758
+	 *
2759
+	 * @param array $props
2760
+	 * @param string $ns
2761
+	 * @param strin $ns_defs
2762
+	 * @param array $ns_hash
2763
+	 * @return string
2764
+	 */
2765 2765
 	function _hierarchical_prop_encode(array $props, $ns, &$ns_defs, array &$ns_hash)
2766
-    {
2767
-    	$ret = '';
2766
+	{
2767
+		$ret = '';
2768 2768
 
2769
-    	//error_log(__METHOD__.'('.array2string($props).')');
2770
-    	if (isset($props['name'])) $props = array($props);
2769
+		//error_log(__METHOD__.'('.array2string($props).')');
2770
+		if (isset($props['name'])) $props = array($props);
2771 2771
 
2772
-    	foreach($props as $prop)
2772
+		foreach($props as $prop)
2773 2773
 		{
2774
-	    	if (!isset($ns_hash[$prop['ns']])) // unknown namespace
2775
-	    	{
2776
-		    	// register namespace
2777
-		    	$ns_name = 'ns'.(count($ns_hash) + 1);
2778
-		    	$ns_hash[$prop['ns']] = $ns_name;
2779
-		    	$ns_defs .= ' xmlns:'.$ns_name.'="'.$prop['ns'].'"';
2780
-	    	}
2781
-	    	if (is_array($prop['val']))
2782
-	    	{
2783
-	    		$subprop = $prop['val'];
2784
-		    	if (isset($subprop['ns']) || isset($subprop[0]['ns']))
2785
-		    	{
2786
-			    	$ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2774
+			if (!isset($ns_hash[$prop['ns']])) // unknown namespace
2775
+			{
2776
+				// register namespace
2777
+				$ns_name = 'ns'.(count($ns_hash) + 1);
2778
+				$ns_hash[$prop['ns']] = $ns_name;
2779
+				$ns_defs .= ' xmlns:'.$ns_name.'="'.$prop['ns'].'"';
2780
+			}
2781
+			if (is_array($prop['val']))
2782
+			{
2783
+				$subprop = $prop['val'];
2784
+				if (isset($subprop['ns']) || isset($subprop[0]['ns']))
2785
+				{
2786
+					$ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2787 2787
 						(empty($prop['val']) ? '/>' : '>'.$this->_hierarchical_prop_encode($prop['val'], $prop['ns'], $ns_defs, $ns_hash).
2788 2788
 						'</'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : ($this->crrnd ? '' : $ns_hash[$prop['ns']].':')).$prop['name'].'>');
2789
-		    	}
2790
-		    	else // val contains only attributes, no value
2791
-		    	{
2792
-			    	$vals = '';
2789
+				}
2790
+				else // val contains only attributes, no value
2791
+				{
2792
+					$vals = '';
2793 2793
 
2794
-			    	foreach($subprop as $attr => $val)
2794
+					foreach($subprop as $attr => $val)
2795 2795
 					{
2796
-				    	$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES, 'utf-8').'"';
2796
+						$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES, 'utf-8').'"';
2797 2797
 					}
2798 2798
 
2799
-		             $ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2800
-				    	$vals .'/>';
2801
-		    	}
2802
-	    	}
2803
-	    	else
2804
-	    	{
2805
-		    	if (empty($prop['val']))
2806
-		    	{
2807
-			    	$val = '';
2808
-		    	}
2809
-		    	else
2810
-		    	{
2811
-			    	if(isset($prop['raw']))
2799
+					 $ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2800
+						$vals .'/>';
2801
+				}
2802
+			}
2803
+			else
2804
+			{
2805
+				if (empty($prop['val']))
2806
+				{
2807
+					$val = '';
2808
+				}
2809
+				else
2810
+				{
2811
+					if(isset($prop['raw']))
2812 2812
 					{
2813 2813
 						$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
2814 2814
 					} else {
@@ -2819,32 +2819,32 @@  discard block
 block discarded – undo
2819 2819
 							$val = $this->_urlencode($val);
2820 2820
 						}
2821 2821
 					}
2822
-		    	}
2822
+				}
2823 2823
 
2824
-		    	$ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2825
-			    	(empty($prop['val']) ? ' />' : '>'.$val.'</'.
2826
-			    	($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : ($this->crrnd ? '' : $ns_hash[$prop['ns']].':')).$prop['name'].'>');
2827
-	    	}
2824
+				$ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2825
+					(empty($prop['val']) ? ' />' : '>'.$val.'</'.
2826
+					($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : ($this->crrnd ? '' : $ns_hash[$prop['ns']].':')).$prop['name'].'>');
2827
+			}
2828 2828
 		}
2829 2829
 
2830
-    	//error_log(__METHOD__.'('.array2string($props).") crrnd=$this->crrnd returning ".array2string($ret));
2831
-    	return $ret;
2832
-    }
2830
+		//error_log(__METHOD__.'('.array2string($props).") crrnd=$this->crrnd returning ".array2string($ret));
2831
+		return $ret;
2832
+	}
2833 2833
 
2834
-    /**
2835
-     * UTF-8 encode property values if not already done so
2836
-     *
2837
-     * @param  string  text to encode
2838
-     * @return string  utf-8 encoded text
2839
-     */
2840
-    function _prop_encode($text)
2841
-    {
2834
+	/**
2835
+	 * UTF-8 encode property values if not already done so
2836
+	 *
2837
+	 * @param  string  text to encode
2838
+	 * @return string  utf-8 encoded text
2839
+	 */
2840
+	function _prop_encode($text)
2841
+	{
2842 2842
 		//error_log( __METHOD__."\n" .print_r($text,true));
2843 2843
 		//error_log("prop-encode:" . print_r($this->_prop_encoding,true));
2844 2844
 
2845 2845
 		switch (strtolower($this->_prop_encoding)) {
2846 2846
 			case "utf-8":
2847
-       			//error_log( __METHOD__."allready encoded\n" .print_r($text,true));
2847
+	   			//error_log( __METHOD__."allready encoded\n" .print_r($text,true));
2848 2848
 				return $text;
2849 2849
 			case "iso-8859-1":
2850 2850
 			case "iso-8859-15":
@@ -2852,75 +2852,75 @@  discard block
 block discarded – undo
2852 2852
 			default:
2853 2853
 				error_log( __METHOD__."utf8 encode\n" .print_r(utf8_encode($text),true));
2854 2854
 				return utf8_encode($text);
2855
-        }
2856
-    }
2855
+		}
2856
+	}
2857 2857
 
2858
-    /**
2859
-     * Slashify - make sure path ends in a slash
2860
-     *
2861
-     * @param   string directory path
2862
-     * @returns string directory path wiht trailing slash
2863
-     */
2864
-    public static function _slashify($path)
2865
-    {
2858
+	/**
2859
+	 * Slashify - make sure path ends in a slash
2860
+	 *
2861
+	 * @param   string directory path
2862
+	 * @returns string directory path wiht trailing slash
2863
+	 */
2864
+	public static function _slashify($path)
2865
+	{
2866 2866
 		//error_log(__METHOD__." called with $path");
2867 2867
 		if ($path[self::bytes($path)-1] != '/') {
2868 2868
 			//error_log(__METHOD__." added slash at the end of path");
2869 2869
 			$path = $path."/";
2870 2870
 		}
2871 2871
 		return $path;
2872
-    }
2872
+	}
2873 2873
 
2874
-    /**
2875
-     * Unslashify - make sure path doesn't in a slash
2876
-     *
2877
-     * @param   string directory path
2878
-     * @returns string directory path wihtout trailing slash
2879
-     */
2880
-    public static function _unslashify($path)
2881
-    {
2882
-        //error_log(__METHOD__." called with $path");
2883
-        if ($path[self::bytes($path)-1] == '/') {
2884
-            $path = substr($path, 0, -1);
2874
+	/**
2875
+	 * Unslashify - make sure path doesn't in a slash
2876
+	 *
2877
+	 * @param   string directory path
2878
+	 * @returns string directory path wihtout trailing slash
2879
+	 */
2880
+	public static function _unslashify($path)
2881
+	{
2882
+		//error_log(__METHOD__." called with $path");
2883
+		if ($path[self::bytes($path)-1] == '/') {
2884
+			$path = substr($path, 0, -1);
2885 2885
 			//error_log(__METHOD__." removed slash at the end of path");
2886
-        }
2887
-        return $path;
2888
-    }
2886
+		}
2887
+		return $path;
2888
+	}
2889 2889
 
2890
-    /**
2891
-     * Merge two paths, make sure there is exactly one slash between them
2892
-     *
2893
-     * @param  string  parent path
2894
-     * @param  string  child path
2895
-     * @return string  merged path
2896
-     */
2897
-    public static function _mergePaths($parent, $child)
2898
-    {
2899
-        //error_log("merge called :\n$parent \n$child\n" . function_backtrace());
2900
-        //error_log("merge :\n".print_r($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)true));
2901
-        if ($child{0} == '/') {
2902
-            return self::_unslashify($parent).$child;
2903
-        } else {
2904
-            return self::_slashify($parent).$child;
2905
-        }
2906
-    }
2890
+	/**
2891
+	 * Merge two paths, make sure there is exactly one slash between them
2892
+	 *
2893
+	 * @param  string  parent path
2894
+	 * @param  string  child path
2895
+	 * @return string  merged path
2896
+	 */
2897
+	public static function _mergePaths($parent, $child)
2898
+	{
2899
+		//error_log("merge called :\n$parent \n$child\n" . function_backtrace());
2900
+		//error_log("merge :\n".print_r($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)true));
2901
+		if ($child{0} == '/') {
2902
+			return self::_unslashify($parent).$child;
2903
+		} else {
2904
+			return self::_slashify($parent).$child;
2905
+		}
2906
+	}
2907 2907
 
2908
-    /**
2909
-     * mbstring.func_overload save strlen version: counting the bytes not the chars
2910
-     *
2911
-     * @param string $str
2912
-     * @return int
2913
-     */
2914
-    public static function bytes($str)
2915
-    {
2916
-    	static $func_overload=null;
2917
-
2918
-    	if (is_null($func_overload))
2919
-    	{
2920
-    		$func_overload = @extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
2921
-    	}
2922
-    	return $func_overload & 2 ? mb_strlen($str,'ascii') : strlen($str);
2923
-    }
2908
+	/**
2909
+	 * mbstring.func_overload save strlen version: counting the bytes not the chars
2910
+	 *
2911
+	 * @param string $str
2912
+	 * @return int
2913
+	 */
2914
+	public static function bytes($str)
2915
+	{
2916
+		static $func_overload=null;
2917
+
2918
+		if (is_null($func_overload))
2919
+		{
2920
+			$func_overload = @extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
2921
+		}
2922
+		return $func_overload & 2 ? mb_strlen($str,'ascii') : strlen($str);
2923
+	}
2924 2924
 }
2925 2925
 
2926 2926
 /*
Please login to merge, or discard this patch.
Spacing   +141 added lines, -143 removed lines patch added patch discarded remove patch
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      * @param  $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php
194 194
      * @return void
195 195
      */
196
-    function ServeRequest($prefix=null)
196
+    function ServeRequest($prefix = null)
197 197
     {
198 198
         // prevent warning in litmus check 'delete_fragment'
199 199
         if (strstr($this->_SERVER["REQUEST_URI"], '#')) {
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         if ($this->client_require_href_as_url)
206 206
         {
207 207
 	        // default uri is the complete request uri
208
-	        $uri = (@$this->_SERVER["HTTPS"] === "on" ? "https:" : "http:") . '//'.$this->_SERVER['HTTP_HOST'];
208
+	        $uri = (@$this->_SERVER["HTTPS"] === "on" ? "https:" : "http:").'//'.$this->_SERVER['HTTP_HOST'];
209 209
         }
210 210
         $uri .= $this->_SERVER["SCRIPT_NAME"];
211 211
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
         // of the request URI ourselves
215 215
         // if request URI contains a full url, remove schema and domain
216 216
 		$matches = null;
217
-        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$this->_SERVER["REQUEST_URI"], $matches))
217
+        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info = $this->_SERVER["REQUEST_URI"], $matches))
218 218
         {
219 219
         	$path_info = $matches[1];
220 220
         }
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
         }
235 235
 
236 236
         $this->base_uri = $uri;
237
-        $this->uri      = $uri . $path_info;
237
+        $this->uri      = $uri.$path_info;
238 238
 
239 239
         // set path
240 240
         // $_SERVER['PATH_INFO'] is already urldecoded
241 241
         //$this->path = self::_urldecode($path_info);
242 242
         // quote '#' (e.g. OpenOffice uses this for lock-files)
243
-        $this->path = strtr($path_info,array(
243
+        $this->path = strtr($path_info, array(
244 244
         	'%' => '%25',
245 245
         	'#' => '%23',
246 246
         	'?' => '%3F',
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
         // check authentication
274 274
         // for the motivation for not checking OPTIONS requests on / see
275 275
         // http://pear.php.net/bugs/bug.php?id=5363
276
-        if ( (   !(($this->_SERVER['REQUEST_METHOD'] == 'OPTIONS') && ($this->path == "/")))
276
+        if ((!(($this->_SERVER['REQUEST_METHOD'] == 'OPTIONS') && ($this->path == "/")))
277 277
              && (!$this->_check_auth())) {
278 278
             // RFC2518 says we must use Digest instead of Basic
279 279
             // but Microsoft Clients do not support Digest
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
         }
290 290
 
291 291
         // check
292
-        if (! $this->_check_if_header_conditions()) {
292
+        if (!$this->_check_if_header_conditions()) {
293 293
             return;
294 294
         }
295 295
 
@@ -303,19 +303,19 @@  discard block
 block discarded – undo
303 303
         }
304 304
 
305 305
         if (method_exists($this, $wrapper) && ($method == "options" || method_exists($this, $method))) {
306
-            $this->$wrapper();  // call method by name
306
+            $this->$wrapper(); // call method by name
307 307
         } else { // method not found/implemented
308 308
             if ($this->_SERVER["REQUEST_METHOD"] == "LOCK") {
309 309
             	$error = '412 Precondition failed';
310 310
             } else {
311 311
                 $error = '405 Method not allowed';
312
-                header("Allow: ".join(", ", $this->_allow()));  // tell client what's allowed
312
+                header("Allow: ".join(", ", $this->_allow())); // tell client what's allowed
313 313
             }
314 314
             $this->http_status($error);
315 315
             echo "<html><head><title>Error $error</title></head>\n";
316 316
             echo "<body><h1>$error</h1>\n";
317 317
             echo "The requested could not by handled by this server.\n";
318
-            echo '(URI ' . $this->_SERVER['REQUEST_URI'] . ")<br>\n<br>\n";
318
+            echo '(URI '.$this->_SERVER['REQUEST_URI'].")<br>\n<br>\n";
319 319
             echo "</body></html>\n";
320 320
         }
321 321
     }
@@ -611,19 +611,19 @@  discard block
 block discarded – undo
611 611
         $allow = $this->_allow();
612 612
 
613 613
         // dav header
614
-        $dav = array(1);        // assume we are always dav class 1 compliant
614
+        $dav = array(1); // assume we are always dav class 1 compliant
615 615
         if (isset($allow['LOCK'])) {
616
-            $dav[] = 2;         // dav class 2 requires that locking is supported
616
+            $dav[] = 2; // dav class 2 requires that locking is supported
617 617
         }
618 618
 
619 619
         // allow extending class to modify DAV and Allow headers
620
-		if (method_exists($this,'OPTIONS')) {
621
-			$this->OPTIONS($this->path,$dav,$allow);
620
+		if (method_exists($this, 'OPTIONS')) {
621
+			$this->OPTIONS($this->path, $dav, $allow);
622 622
 		}
623 623
 
624 624
         // tell clients what we found
625 625
         $this->http_status("200 OK");
626
-        header("DAV: "  .join(", ", $dav));
626
+        header("DAV: ".join(", ", $dav));
627 627
         header("Allow: ".join(", ", $allow));
628 628
 
629 629
         header("Content-length: 0");
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
      * @param  string $handler ='PROPFIND' allows to use method eg. for CalDAV REPORT
654 654
      * @return void
655 655
      */
656
-    function http_PROPFIND($handler='PROPFIND')
656
+    function http_PROPFIND($handler = 'PROPFIND')
657 657
     {
658 658
         $options = Array();
659 659
         $files   = Array();
@@ -682,21 +682,21 @@  discard block
 block discarded – undo
682 682
 			$options['other'] = $propinfo->other;
683 683
 
684 684
         // call user handler
685
-        if (!($retval =$this->$handler($options, $files))) {
685
+        if (!($retval = $this->$handler($options, $files))) {
686 686
             $files = array("files" => array());
687 687
             if (method_exists($this, "checkLock")) {
688 688
                 // is locked?
689 689
                 $lock = $this->checkLock($this->path);
690 690
 
691 691
                 if (is_array($lock) && count($lock)) {
692
-                    $created          = isset($lock['created'])  ? $lock['created']  : time();
692
+                    $created          = isset($lock['created']) ? $lock['created'] : time();
693 693
                     $modified         = isset($lock['modified']) ? $lock['modified'] : time();
694 694
                     $files['files'][] = array("path"  => self::_slashify($this->path),
695
-                                              "props" => array($this->mkprop("displayname",      $this->path),
696
-                                                               $this->mkprop("creationdate",     $created),
697
-                                                               $this->mkprop("getlastmodified",  $modified),
698
-                                                               $this->mkprop("resourcetype",     ""),
699
-                                                               $this->mkprop("getcontenttype",   ""),
695
+                                              "props" => array($this->mkprop("displayname", $this->path),
696
+                                                               $this->mkprop("creationdate", $created),
697
+                                                               $this->mkprop("getlastmodified", $modified),
698
+                                                               $this->mkprop("resourcetype", ""),
699
+                                                               $this->mkprop("getcontenttype", ""),
700 700
                                                                $this->mkprop("getcontentlength", 0))
701 701
                                               );
702 702
                 }
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 			header('Content-Type: text/html');
720 720
 			echo "<html><head><title>Error $retval</title></head>\n";
721 721
 			echo "<body><h1>$retval</h1>\n";
722
-			switch (substr($retval, 0 ,3))
722
+			switch (substr($retval, 0, 3))
723 723
 			{
724 724
 				case '501': // Not Implemented
725 725
 					echo "The requested feature is not (yet) supported by this server.\n";
@@ -727,19 +727,19 @@  discard block
 block discarded – undo
727 727
 				default:
728 728
 					echo "The request could not be handled by this server.\n";
729 729
 			}
730
-			echo '(URI ' . $this->_SERVER['REQUEST_URI'] . ")<br>\n<br>\n";
730
+			echo '(URI '.$this->_SERVER['REQUEST_URI'].")<br>\n<br>\n";
731 731
 			echo "</body></html>\n";
732 732
 			return;
733 733
 		}
734 734
 		// dav header
735
-        $dav = array(1);        // assume we are always dav class 1 compliant
735
+        $dav = array(1); // assume we are always dav class 1 compliant
736 736
         $allow = false;
737 737
 
738 738
         // allow extending class to modify DAV
739
-		if (method_exists($this,'OPTIONS')) {
740
-			$this->OPTIONS($this->path,$dav,$allow);
739
+		if (method_exists($this, 'OPTIONS')) {
740
+			$this->OPTIONS($this->path, $dav, $allow);
741 741
 		}
742
-        header("DAV: "  .join(", ", $dav));
742
+        header("DAV: ".join(", ", $dav));
743 743
         header('Content-Type: text/xml; charset="utf-8"');
744 744
 
745 745
         // add Vary and Preference-Applied header for Prefer: return=minimal
@@ -759,12 +759,11 @@  discard block
 block discarded – undo
759 759
         if (isset($files['sync-token']))
760 760
         {
761 761
             echo ($this->crrnd ? " <" : " <D:")."sync-token>".
762
-            	htmlspecialchars(!is_callable($files['sync-token']) ? $files['sync-token'] :
763
-            		call_user_func_array($files['sync-token'], (array)$files['sync-token-params'])).
762
+            	htmlspecialchars(!is_callable($files['sync-token']) ? $files['sync-token'] : call_user_func_array($files['sync-token'], (array)$files['sync-token-params'])).
764 763
             	($this->crrnd ? "</" : "</D:")."sync-token>\n";
765 764
         }
766 765
 
767
-        echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
766
+        echo '</'.($this->crrnd ? '' : 'D:')."multistatus>\n";
768 767
     }
769 768
 
770 769
     /**
@@ -773,7 +772,7 @@  discard block
 block discarded – undo
773 772
      * @param array|Iterator $files
774 773
      * @param array|string $props
775 774
      */
776
-    function multistatus_responses(&$files, $props, $initial_ns_hash=null, $initial_ns_defs=null)
775
+    function multistatus_responses(&$files, $props, $initial_ns_hash = null, $initial_ns_defs = null)
777 776
     {
778 777
     	if (!isset($initial_ns_hash)) $initial_ns_hash = array('DAV:' => 'D');
779 778
     	if (!isset($initial_ns_defs)) $initial_ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';
@@ -786,7 +785,7 @@  discard block
 block discarded – undo
786 785
         }
787 786
         // support for "Prefer: depth-noroot" header on PROPFIND
788 787
         $skip_root = $this->_SERVER['REQUEST_METHOD'] == 'PROPFIND' &&
789
-        	!isset($initial_ns_hash) &&	// multistatus_response calls itself, do NOT apply skip in that case
788
+        	!isset($initial_ns_hash) && // multistatus_response calls itself, do NOT apply skip in that case
790 789
         	isset($this->_SERVER['HTTP_PREFER']) && in_array('depth-noroot', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER']));
791 790
 
792 791
         // now we loop over all returned file entries
@@ -815,9 +814,8 @@  discard block
 block discarded – undo
815 814
 
816 815
 	            	// this can happen if we have allprop and prop in one propfind:
817 816
 	            	// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
818
-	                switch(is_array($props) ? $props[0] : $props) {
819
-	                case "all":
820
-	                    // nothing to remove
817
+	                switch (is_array($props) ? $props[0] : $props) {
818
+	                case "all" : // nothing to remove
821 819
 	                    break;
822 820
 
823 821
 	                case "names":
@@ -831,7 +829,7 @@  discard block
 block discarded – undo
831 829
 
832 830
 	                    // search property name in requested properties
833 831
 	                    foreach ((array)$props as $reqprop) {
834
-	                        if (   $reqprop["name"]  == $prop["name"]
832
+	                        if ($reqprop["name"] == $prop["name"]
835 833
 	                               && @$reqprop["xmlns"] == $prop["ns"]) {
836 834
 	                            $found = true;
837 835
 	                            break;
@@ -840,7 +838,7 @@  discard block
 block discarded – undo
840 838
 
841 839
 	                    // unset property and continue with next one if not found/requested
842 840
 	                    if (!$found) {
843
-	                        $prop="";
841
+	                        $prop = "";
844 842
 	                        continue(2);
845 843
 	                    }
846 844
 	                    break;
@@ -862,7 +860,7 @@  discard block
 block discarded – undo
862 860
 	            // but for which no values where returned by the user handler
863 861
 	            if (is_array($props)) {
864 862
 	                foreach ($props as $reqprop) {
865
-	                    if (!is_array($reqprop) || $reqprop['name']=="") continue; // skip empty entries, or 'all' if <allprop /> used together with <prop>
863
+	                    if (!is_array($reqprop) || $reqprop['name'] == "") continue; // skip empty entries, or 'all' if <allprop /> used together with <prop>
866 864
 
867 865
 	                    $found = false;
868 866
 
@@ -876,7 +874,7 @@  discard block
 block discarded – undo
876 874
 	                    }
877 875
 
878 876
 	                    if (!$found) {
879
-	                        if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") {
877
+	                        if ($reqprop["xmlns"] === "DAV:" && $reqprop["name"] === "lockdiscovery") {
880 878
 	                            // lockdiscovery is handled by the base class
881 879
 	                            $file["props"][]
882 880
 	                                = $this->mkprop("DAV:",
@@ -903,7 +901,7 @@  discard block
 block discarded – undo
903 901
             // ignore empty or incomplete entries
904 902
             if (!is_array($file) || empty($file) || !isset($file["path"])) continue;
905 903
             $path = $file['path'];
906
-            if (!is_string($path) || $path==="") continue;
904
+            if (!is_string($path) || $path === "") continue;
907 905
 
908 906
             if ($this->crrnd)
909 907
             {
@@ -933,8 +931,8 @@  discard block
 block discarded – undo
933 931
 
934 932
             // report all found properties and their values (if any)
935 933
             if (isset($file["props"]) && is_array($file["props"])) {
936
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
937
-                echo '    <'.($this->crrnd?'':'D:')."prop>\n";
934
+                echo '   <'.($this->crrnd ? '' : 'D:')."propstat>\n";
935
+                echo '    <'.($this->crrnd ? '' : 'D:')."prop>\n";
938 936
 
939 937
                 foreach ($file["props"] as &$prop) {
940 938
 
@@ -943,8 +941,8 @@  discard block
 block discarded – undo
943 941
 
944 942
                     if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) {
945 943
                         // empty properties (cannot use empty() for check as "0" is a legal value here)
946
-                        if ($prop["ns"]=="DAV:") {
947
-                            echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
944
+                        if ($prop["ns"] == "DAV:") {
945
+                            echo '     <'.($this->crrnd ? '' : 'D:')."$prop[name]/>\n";
948 946
                         } else if (!empty($prop["ns"])) {
949 947
                             echo "     <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
950 948
                         } else {
@@ -952,7 +950,7 @@  discard block
 block discarded – undo
952 950
                         }
953 951
                     }
954 952
                     // multiple level of responses required for expand-property reports
955
-                    elseif(isset($prop['props']) && is_array($prop['val']))
953
+                    elseif (isset($prop['props']) && is_array($prop['val']))
956 954
                     {
957 955
                         if ($prop['ns'] && !isset($ns_hash[$prop['ns']])) {
958 956
                             $ns_name = "ns".(count($ns_hash) + 1);
@@ -965,33 +963,33 @@  discard block
 block discarded – undo
965 963
                         // some WebDAV properties need special treatment
966 964
                         switch ($prop["name"]) {
967 965
                         case "creationdate":
968
-                            echo '     <'.($this->crrnd?'':'D:')."creationdate ns0:dt=\"dateTime.tz\">"
966
+                            echo '     <'.($this->crrnd ? '' : 'D:')."creationdate ns0:dt=\"dateTime.tz\">"
969 967
                                 . gmdate("Y-m-d\\TH:i:s\\Z", $prop['val'])
970
-                                . '</'.($this->crrnd?'':'D:')."creationdate>\n";
968
+                                . '</'.($this->crrnd ? '' : 'D:')."creationdate>\n";
971 969
                             break;
972 970
                         case "getlastmodified":
973
-                            echo '     <'.($this->crrnd?'':'D:')."getlastmodified ns0:dt=\"dateTime.rfc1123\">"
971
+                            echo '     <'.($this->crrnd ? '' : 'D:')."getlastmodified ns0:dt=\"dateTime.rfc1123\">"
974 972
                                 . gmdate("D, d M Y H:i:s ", $prop['val'])
975
-                                . "GMT</".($this->crrnd?'':'D:')."getlastmodified>\n";
973
+                                . "GMT</".($this->crrnd ? '' : 'D:')."getlastmodified>\n";
976 974
                             break;
977 975
                         case "supportedlock":
978
-                            echo '     <'.($this->crrnd?'':'D:')."supportedlock>$prop[val]</".($this->crrnd?'':'D:')."supportedlock>\n";
976
+                            echo '     <'.($this->crrnd ? '' : 'D:')."supportedlock>$prop[val]</".($this->crrnd ? '' : 'D:')."supportedlock>\n";
979 977
                             break;
980 978
                         case "lockdiscovery":
981
-                            echo '     <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
979
+                            echo '     <'.($this->crrnd ? '' : 'D:')."lockdiscovery>\n";
982 980
                             echo $prop["val"];
983
-                            echo '     </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
981
+                            echo '     </'.($this->crrnd ? '' : 'D:')."lockdiscovery>\n";
984 982
                             break;
985 983
                         // the following are non-standard Microsoft extensions to the DAV namespace
986 984
                         case "lastaccessed":
987
-                            echo '     <'.($this->crrnd?'':'D:')."lastaccessed ns0:dt=\"dateTime.rfc1123\">"
985
+                            echo '     <'.($this->crrnd ? '' : 'D:')."lastaccessed ns0:dt=\"dateTime.rfc1123\">"
988 986
                                 . gmdate("D, d M Y H:i:s ", $prop['val'])
989
-                                . 'GMT</'.($this->crrnd?'':'D:')."lastaccessed>\n";
987
+                                . 'GMT</'.($this->crrnd ? '' : 'D:')."lastaccessed>\n";
990 988
                             break;
991 989
                         case "ishidden":
992
-                            echo '     <'.($this->crrnd?'':'D:')."ishidden>"
990
+                            echo '     <'.($this->crrnd ? '' : 'D:')."ishidden>"
993 991
                                 . is_string($prop['val']) ? $prop['val'] : ($prop['val'] ? 'true' : 'false')
994
-                                . '</'.($this->crrnd?'':'D:')."</D:ishidden>\n";
992
+                                . '</'.($this->crrnd ? '' : 'D:')."</D:ishidden>\n";
995 993
                             break;
996 994
                         default:
997 995
                         	$ns_defs = '';
@@ -1004,8 +1002,8 @@  discard block
 block discarded – undo
1004 1002
                             } else {
1005 1003
 	                    		$val = $this->_prop_encode(htmlspecialchars($prop['val'], ENT_NOQUOTES, 'utf-8'));
1006 1004
                             }
1007
-	                        echo '     <'.($this->crrnd?'':'D:')."$prop[name]$ns_defs>$val".
1008
-	                        	'</'.($this->crrnd?'':'D:')."$prop[name]>\n";
1005
+	                        echo '     <'.($this->crrnd ? '' : 'D:')."$prop[name]$ns_defs>$val".
1006
+	                        	'</'.($this->crrnd ? '' : 'D:')."$prop[name]>\n";
1009 1007
                             break;
1010 1008
                         }
1011 1009
                     } else {
@@ -1016,7 +1014,7 @@  discard block
 block discarded – undo
1016 1014
                                 $ns_hash[$prop['ns']] = $ns_name;
1017 1015
                     		}
1018 1016
                   			$vals = $extra_ns = '';
1019
-                    		foreach($prop['val'] as $subprop)
1017
+                    		foreach ($prop['val'] as $subprop)
1020 1018
                     		{
1021 1019
                     			if ($subprop['ns'] && $subprop['ns'] != 'DAV:') {
1022 1020
 		                    		// register property namespace if not known yet
@@ -1026,7 +1024,7 @@  discard block
 block discarded – undo
1026 1024
 		                    		} else {
1027 1025
 			                    		$ns_name = $ns_hash[$subprop['ns']];
1028 1026
 		                    		}
1029
-		                    		if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) {
1027
+		                    		if (strchr($extra_ns, $extra = ' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) {
1030 1028
 			                    		$extra_ns .= $extra;
1031 1029
 		                    		}
1032 1030
 		                    		$ns_name .= ':';
@@ -1046,7 +1044,7 @@  discard block
 block discarded – undo
1046 1044
 	                    			}
1047 1045
 	                    			else	// val contains only attributes, no value
1048 1046
 	                    			{
1049
-			                    		foreach($subprop['val'] as $attr => $val)
1047
+			                    		foreach ($subprop['val'] as $attr => $val)
1050 1048
 										{
1051 1049
 				                    		$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES, 'utf-8').'"';
1052 1050
 										}
@@ -1059,7 +1057,7 @@  discard block
 block discarded – undo
1059 1057
 	                    			if (isset($subprop['raw'])) {
1060 1058
 	                    				$vals .= '<![CDATA['.$subprop['val'].']]>';
1061 1059
 	                    			} else {
1062
-	                    				if($subprop['name'] == 'href') $subprop['val'] = $this->_urlencode($subprop['val']);
1060
+	                    				if ($subprop['name'] == 'href') $subprop['val'] = $this->_urlencode($subprop['val']);
1063 1061
 		                    			$vals .= htmlspecialchars($subprop['val'], ENT_NOQUOTES, 'utf-8');
1064 1062
 	                    			}
1065 1063
 	                    			$vals .= "</$ns_name$subprop[name]>";
@@ -1078,10 +1076,10 @@  discard block
 block discarded – undo
1078 1076
 	                        if ($prop['ns']) {
1079 1077
 		                        if ($this->crrnd) {
1080 1078
 			                        echo "     <$prop[name] xmlns=".'"'.$prop["ns"].'">'
1081
-									. $val . "</$prop[name]>\n";
1079
+									. $val."</$prop[name]>\n";
1082 1080
 		                        } else {
1083
-			                        echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]>"
1084
-									. $val . '</'.$ns_hash[$prop['ns']].":$prop[name]>\n";
1081
+			                        echo "     <".$ns_hash[$prop["ns"]].":$prop[name]>"
1082
+									. $val.'</'.$ns_hash[$prop['ns']].":$prop[name]>\n";
1085 1083
 		                        }
1086 1084
 	                        } else {
1087 1085
 		                        echo "     <$prop[name] xmlns=\"\">$val</$prop[name]>\n";
@@ -1106,16 +1104,16 @@  discard block
 block discarded – undo
1106 1104
 
1107 1105
             // now report all properties requested but not found
1108 1106
             if (isset($file["noprops"])) {
1109
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1110
-                echo '    <'.($this->crrnd?'':'D:')."prop>\n";
1107
+                echo '   <'.($this->crrnd ? '' : 'D:')."propstat>\n";
1108
+                echo '    <'.($this->crrnd ? '' : 'D:')."prop>\n";
1111 1109
 
1112 1110
                 foreach ($file["noprops"] as &$prop) {
1113 1111
                     if ($prop["ns"] == "DAV:") {
1114
-                        echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
1112
+                        echo '     <'.($this->crrnd ? '' : 'D:')."$prop[name]/>\n";
1115 1113
                     } else if ($prop["ns"] == "") {
1116 1114
                         echo "     <$prop[name] xmlns=\"\"/>\n";
1117 1115
                     } else {
1118
-                        echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]/>\n";
1116
+                        echo "     <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
1119 1117
                     }
1120 1118
                 }
1121 1119
 
@@ -1146,7 +1144,7 @@  discard block
 block discarded – undo
1146 1144
                 }
1147 1145
             }
1148 1146
 
1149
-            echo ' </'.($this->crrnd?'':'D:')."response>\n";
1147
+            echo ' </'.($this->crrnd ? '' : 'D:')."response>\n";
1150 1148
         }
1151 1149
     }
1152 1150
 
@@ -1186,24 +1184,24 @@  discard block
 block discarded – undo
1186 1184
             echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
1187 1185
 
1188 1186
             echo "<D:multistatus xmlns:D=\"DAV:\">\n";
1189
-            echo ' <'.($this->crrnd?'':'D:')."response>\n";
1190
-            echo '  <'.($this->crrnd?'':'D:')."href>".$this->_urlencode($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)).'</'.($this->crrnd?'':'D:')."href>\n";
1187
+            echo ' <'.($this->crrnd ? '' : 'D:')."response>\n";
1188
+            echo '  <'.($this->crrnd ? '' : 'D:')."href>".$this->_urlencode($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)).'</'.($this->crrnd ? '' : 'D:')."href>\n";
1191 1189
 
1192 1190
             foreach ($options["props"] as $prop) {
1193
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1194
-                echo '    <'.($this->crrnd?'':'D:')."prop><$prop[name] xmlns=\"$prop[ns]\"/></".($this->crrnd?'':'D:')."prop>\n";
1195
-                echo '    <'.($this->crrnd?'':'D:')."status>HTTP/1.1 $prop[status]</".($this->crrnd?'':'D:')."status>\n";
1196
-                echo '   </'.($this->crrnd?'':'D:')."propstat>\n";
1191
+                echo '   <'.($this->crrnd ? '' : 'D:')."propstat>\n";
1192
+                echo '    <'.($this->crrnd ? '' : 'D:')."prop><$prop[name] xmlns=\"$prop[ns]\"/></".($this->crrnd ? '' : 'D:')."prop>\n";
1193
+                echo '    <'.($this->crrnd ? '' : 'D:')."status>HTTP/1.1 $prop[status]</".($this->crrnd ? '' : 'D:')."status>\n";
1194
+                echo '   </'.($this->crrnd ? '' : 'D:')."propstat>\n";
1197 1195
             }
1198 1196
 
1199 1197
             if ($responsedescr) {
1200
-                echo '  <'.($this->crrnd?'':'D:')."responsedescription>".
1198
+                echo '  <'.($this->crrnd ? '' : 'D:')."responsedescription>".
1201 1199
                     $this->_prop_encode(htmlspecialchars($responsedescr, ENT_NOQUOTES, 'utf-8')).
1202
-                    '</'.($this->crrnd?'':'D:')."responsedescription>\n";
1200
+                    '</'.($this->crrnd ? '' : 'D:')."responsedescription>\n";
1203 1201
             }
1204 1202
 
1205
-            echo ' </'.($this->crrnd?'':'D:')."response>\n";
1206
-            echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
1203
+            echo ' </'.($this->crrnd ? '' : 'D:')."response>\n";
1204
+            echo '</'.($this->crrnd ? '' : 'D:')."multistatus>\n";
1207 1205
         } else {
1208 1206
             $this->http_status("423 Locked");
1209 1207
         }
@@ -1243,12 +1241,12 @@  discard block
 block discarded – undo
1243 1241
 	 * @param boolean $set =null
1244 1242
 	 * @return boolean true if we use compression, false otherwise
1245 1243
 	 */
1246
-	public static function use_compression($set=null)
1244
+	public static function use_compression($set = null)
1247 1245
 	{
1248 1246
 		static $compression = null;
1249 1247
 		if (isset($set))
1250 1248
 		{
1251
-			ini_set('zlib.output_compression', $compression=(boolean)$set);
1249
+			ini_set('zlib.output_compression', $compression = (boolean)$set);
1252 1250
 		}
1253 1251
 		elseif (!isset($compression))
1254 1252
 		{
@@ -1284,7 +1282,7 @@  discard block
 block discarded – undo
1284 1282
                 // switching off zlib.output_compression for everything but text files,
1285 1283
                 // as the double compression of zip files makes problems eg. with lighttpd
1286 1284
                 // and anyway little sense with with other content like pictures
1287
-                if (substr($options['mimetype'],0,5) != 'text/')
1285
+                if (substr($options['mimetype'], 0, 5) != 'text/')
1288 1286
                 {
1289 1287
 					self::use_compression(false);
1290 1288
                 }
@@ -1301,7 +1299,7 @@  discard block
 block discarded – undo
1301 1299
 
1302 1300
                 if (isset($options['stream'])) {
1303 1301
                     // GET handler returned a stream
1304
-                    if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET))) {
1302
+                    if (!empty($options['ranges']) && (0 === fseek($options['stream'], 0, SEEK_SET))) {
1305 1303
                         // partial request and stream is seekable
1306 1304
 
1307 1305
                         if (count($options['ranges']) === 1) {
@@ -1315,7 +1313,7 @@  discard block
 block discarded – undo
1315 1313
                                 }
1316 1314
 
1317 1315
                                 if (!empty($range['end'])) {
1318
-                                    $size = $range['end']-$range['start']+1;
1316
+                                    $size = $range['end'] - $range['start'] + 1;
1319 1317
                                     $this->http_status($status = "206 Partial content");
1320 1318
                                     if (!self::use_compression()) header("Content-Length: $size");
1321 1319
                                     header("Content-Range: bytes $range[start]-$range[end]/"
@@ -1330,7 +1328,7 @@  discard block
 block discarded – undo
1330 1328
                                     if (isset($options['size'])) {
1331 1329
                                         if (!self::use_compression()) header("Content-Length: ".($options['size'] - $range['start']));
1332 1330
                                         header("Content-Range: bytes ".$range['start']."-".
1333
-											(isset($options['size']) ? $options['size']-1 : "")."/"
1331
+											(isset($options['size']) ? $options['size'] - 1 : "")."/"
1334 1332
 										   . (isset($options['size']) ? $options['size'] : "*"));
1335 1333
                                     }
1336 1334
                                     fpassthru($options['stream']);
@@ -1346,10 +1344,10 @@  discard block
 block discarded – undo
1346 1344
                                 // TODO what if size unknown? 500?
1347 1345
                                 if (isset($range['start'])) {
1348 1346
                                     $from = $range['start'];
1349
-                                    $to   = !empty($range['end']) ? $range['end'] : $options['size']-1;
1347
+                                    $to   = !empty($range['end']) ? $range['end'] : $options['size'] - 1;
1350 1348
                                 } else {
1351
-                                    $from = $options['size'] - $range['last']-1;
1352
-                                    $to   = $options['size'] -1;
1349
+                                    $from = $options['size'] - $range['last'] - 1;
1350
+                                    $to   = $options['size'] - 1;
1353 1351
                                 }
1354 1352
                                 $total = isset($options['size']) ? $options['size'] : "*";
1355 1353
                                 $size  = $to - $from + 1;
@@ -1415,7 +1413,7 @@  discard block
 block discarded – undo
1415 1413
                 foreach (explode(",", $matches[1]) as $range) {
1416 1414
                     // ranges are either from-to pairs or just end positions
1417 1415
                     list($start, $end) = explode("-", $range);
1418
-                    $options["ranges"][] = ($start==="")
1416
+                    $options["ranges"][] = ($start === "")
1419 1417
                         ? array("last"=>$end)
1420 1418
                         : array("start"=>$start, "end"=>$end);
1421 1419
                 }
@@ -1436,7 +1434,7 @@  discard block
 block discarded – undo
1436 1434
      * @param  int     end   byte position
1437 1435
      * @param  int     total resource byte size
1438 1436
      */
1439
-    function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false)
1437
+    function _multipart_byterange_header($mimetype = false, $from = false, $to = false, $total = false)
1440 1438
     {
1441 1439
         if ($mimetype === false) {
1442 1440
             if (!isset($this->multipart_separator)) {
@@ -1458,7 +1456,7 @@  discard block
 block discarded – undo
1458 1456
             // generate separator and header for next part
1459 1457
             echo "\n--{$this->multipart_separator}\n";
1460 1458
             echo "Content-type: $mimetype\n";
1461
-            echo "Content-range: $from-$to/". ($total === false ? "*" : $total);
1459
+            echo "Content-range: $from-$to/".($total === false ? "*" : $total);
1462 1460
             echo "\n\n";
1463 1461
         }
1464 1462
     }
@@ -1552,7 +1550,7 @@  discard block
 block discarded – undo
1552 1550
         }
1553 1551
 
1554 1552
         $options['stream'] = fopen('php://input', 'r');
1555
-    	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1553
+    	switch ($this->_SERVER['HTTP_CONTENT_ENCODING'])
1556 1554
     	{
1557 1555
     		case 'gzip':
1558 1556
     		case 'deflate':	//zlib
@@ -1565,11 +1563,11 @@  discard block
 block discarded – undo
1565 1563
 		if ($this->store_request)
1566 1564
 		{
1567 1565
 			$options['content'] = '';
1568
-			while(!feof($options['stream']))
1566
+			while (!feof($options['stream']))
1569 1567
 			{
1570
-				$options['content'] .= fread($options['stream'],8192);
1568
+				$options['content'] .= fread($options['stream'], 8192);
1571 1569
 			}
1572
-			$this->request =& $options['content'];
1570
+			$this->request = & $options['content'];
1573 1571
 			unset($options['stream']);
1574 1572
 		}
1575 1573
 
@@ -1582,7 +1580,7 @@  discard block
 block discarded – undo
1582 1580
 	        if (strncmp($key, 'HTTP_CONTENT', 11)) continue;
1583 1581
 	        switch ($key) {
1584 1582
 		        case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1585
-		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1583
+		        	switch ($this->_SERVER['HTTP_CONTENT_ENCODING'])
1586 1584
 		        	{
1587 1585
 		        		case 'gzip':
1588 1586
 		        		case 'deflate':	//zlib
@@ -1670,7 +1668,7 @@  discard block
 block discarded – undo
1670 1668
 		        if (!empty($options['ranges'])) {
1671 1669
 			        // TODO multipart support is missing (see also above)
1672 1670
 			        if (0 == fseek($stream, $range[0]['start'], SEEK_SET)) {
1673
-				        $length = $range[0]['end']-$range[0]['start']+1;
1671
+				        $length = $range[0]['end'] - $range[0]['start'] + 1;
1674 1672
 				        if (!fwrite($stream, fread($options['stream'], $length))) {
1675 1673
 					        $status = '403 Forbidden';
1676 1674
 				        }
@@ -1732,7 +1730,7 @@  discard block
 block discarded – undo
1732 1730
             }
1733 1731
 
1734 1732
             $options["stream"] = fopen("php://input", "r");
1735
-	    	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1733
+	    	switch ($this->_SERVER['HTTP_CONTENT_ENCODING'])
1736 1734
 	    	{
1737 1735
 	    		case 'gzip':
1738 1736
 	    		case 'deflate':	//zlib
@@ -1745,11 +1743,11 @@  discard block
 block discarded – undo
1745 1743
 			if ($this->store_request)
1746 1744
 			{
1747 1745
 				$options['content'] = '';
1748
-				while(!feof($options['stream']))
1746
+				while (!feof($options['stream']))
1749 1747
 				{
1750
-					$options['content'] .= fread($options['stream'],8192);
1748
+					$options['content'] .= fread($options['stream'], 8192);
1751 1749
 				}
1752
-				$this->request =& $options['content'];
1750
+				$this->request = & $options['content'];
1753 1751
 				unset($options['stream']);
1754 1752
 			}
1755 1753
 
@@ -1762,7 +1760,7 @@  discard block
 block discarded – undo
1762 1760
                 if (strncmp($key, "HTTP_CONTENT", 11)) continue;
1763 1761
                 switch ($key) {
1764 1762
                 case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1765
-		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1763
+		        	switch ($this->_SERVER['HTTP_CONTENT_ENCODING'])
1766 1764
 		        	{
1767 1765
 		        		case 'gzip':
1768 1766
 		        		case 'deflate':	//zlib
@@ -1848,7 +1846,7 @@  discard block
 block discarded – undo
1848 1846
                 if (!empty($options["ranges"])) {
1849 1847
                     // TODO multipart support is missing (see also above)
1850 1848
                     if (0 == fseek($stream, $options['ranges'][0]["start"], SEEK_SET)) {
1851
-                        $length = $options['ranges'][0]["end"] - $options['ranges'][0]["start"]+1;
1849
+                        $length = $options['ranges'][0]["end"] - $options['ranges'][0]["start"] + 1;
1852 1850
 
1853 1851
                         while (!feof($options['stream'])) {
1854 1852
                             if ($length <= 0) {
@@ -1908,7 +1906,7 @@  discard block
 block discarded – undo
1908 1906
         // check RFC 2518 Section 9.2, last paragraph
1909 1907
         if (isset($this->_SERVER["HTTP_DEPTH"])) {
1910 1908
             if ($this->_SERVER["HTTP_DEPTH"] != "infinity") {
1911
-				if (stripos($_SERVER['HTTP_USER_AGENT'],'webdrive') !== false)
1909
+				if (stripos($_SERVER['HTTP_USER_AGENT'], 'webdrive') !== false)
1912 1910
 				{
1913 1911
 					// pretend we didnt see it, as webdrive does not handle the depth parameter correctly while deleting collections
1914 1912
 				}
@@ -2057,8 +2055,8 @@  discard block
 block discarded – undo
2057 2055
                 if (is_numeric($options["timeout"])) {
2058 2056
                     // more than a million is considered an absolute timestamp
2059 2057
                     // less is more likely a relative value
2060
-                    if ($options["timeout"]>1000000) {
2061
-                        $timeout = "Second-".($options['timeout']-time());
2058
+                    if ($options["timeout"] > 1000000) {
2059
+                        $timeout = "Second-".($options['timeout'] - time());
2062 2060
                     } else {
2063 2061
                         $timeout = "Second-$options[timeout]";
2064 2062
                     }
@@ -2076,17 +2074,17 @@  discard block
 block discarded – undo
2076 2074
             header("Lock-Token: <$options[locktoken]>");
2077 2075
             echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2078 2076
             echo "<D:prop xmlns:D=\"DAV:\">\n";
2079
-            echo ' <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2080
-            echo '  <'.($this->crrnd?'':'D:')."activelock>\n";
2081
-            echo '   <'.($this->crrnd?'':'D:')."lockscope><D:$options[scope]/></".($this->crrnd?'':'D:')."lockscope>\n";
2082
-            echo '   <'.($this->crrnd?'':'D:')."locktype><D:$options[type]/></".($this->crrnd?'':'D:')."locktype>\n";
2083
-            echo '   <'.($this->crrnd?'':'D:')."depth>$options[depth]</".($this->crrnd?'':'D:')."depth>\n";
2084
-            echo '   <'.($this->crrnd?'':'D:')."owner>$options[owner]</".($this->crrnd?'':'D:')."owner>\n";
2085
-            echo '   <'.($this->crrnd?'':'D:')."timeout>$timeout</".($this->crrnd?'':'D:')."timeout>\n";
2086
-            echo '   <'.($this->crrnd?'':'D:')."locktoken><D:href>$options[locktoken]</D:href></".($this->crrnd?'':'D:')."locktoken>\n";
2087
-            echo '  </'.($this->crrnd?'':'D:')."activelock>\n";
2088
-            echo ' </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2089
-            echo '</'.($this->crrnd?'':'D:')."prop>\n\n";
2077
+            echo ' <'.($this->crrnd ? '' : 'D:')."lockdiscovery>\n";
2078
+            echo '  <'.($this->crrnd ? '' : 'D:')."activelock>\n";
2079
+            echo '   <'.($this->crrnd ? '' : 'D:')."lockscope><D:$options[scope]/></".($this->crrnd ? '' : 'D:')."lockscope>\n";
2080
+            echo '   <'.($this->crrnd ? '' : 'D:')."locktype><D:$options[type]/></".($this->crrnd ? '' : 'D:')."locktype>\n";
2081
+            echo '   <'.($this->crrnd ? '' : 'D:')."depth>$options[depth]</".($this->crrnd ? '' : 'D:')."depth>\n";
2082
+            echo '   <'.($this->crrnd ? '' : 'D:')."owner>$options[owner]</".($this->crrnd ? '' : 'D:')."owner>\n";
2083
+            echo '   <'.($this->crrnd ? '' : 'D:')."timeout>$timeout</".($this->crrnd ? '' : 'D:')."timeout>\n";
2084
+            echo '   <'.($this->crrnd ? '' : 'D:')."locktoken><D:href>$options[locktoken]</D:href></".($this->crrnd ? '' : 'D:')."locktoken>\n";
2085
+            echo '  </'.($this->crrnd ? '' : 'D:')."activelock>\n";
2086
+            echo ' </'.($this->crrnd ? '' : 'D:')."lockdiscovery>\n";
2087
+            echo '</'.($this->crrnd ? '' : 'D:')."prop>\n\n";
2090 2088
         }
2091 2089
     }
2092 2090
 
@@ -2156,9 +2154,9 @@  discard block
 block discarded – undo
2156 2154
 	        $content .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2157 2155
 	        $content .= "<D:error xmlns:D=\"DAV:\"> \n";
2158 2156
 	        foreach ($options['errors'] as $violation) {
2159
-	        	$content .= '<'.($this->crrnd?'':'D:')."$violation/>\n";
2157
+	        	$content .= '<'.($this->crrnd ? '' : 'D:')."$violation/>\n";
2160 2158
 	        }
2161
-	        $content .=  '</'.($this->crrnd?'':'D:')."error>\n";
2159
+	        $content .= '</'.($this->crrnd ? '' : 'D:')."error>\n";
2162 2160
         }
2163 2161
         if (!self::use_compression()) header("Content-Length: ".self::bytes($content));
2164 2162
         if ($content) echo $options['content'];
@@ -2190,7 +2188,7 @@  discard block
 block discarded – undo
2190 2188
             // TODO check url scheme, too
2191 2189
             $http_host = $url["host"];
2192 2190
             if (isset($url["port"]) && $url["port"] != 80)
2193
-                $http_host.= ":".$url["port"];
2191
+                $http_host .= ":".$url["port"];
2194 2192
         } else {
2195 2193
             // only path given, set host to self
2196 2194
             $http_host = $http_header_host;
@@ -2335,17 +2333,17 @@  discard block
 block discarded – undo
2335 2333
         }
2336 2334
 
2337 2335
         // fallback
2338
-        $uuid = md5(microtime().getmypid());    // this should be random enough for now
2336
+        $uuid = md5(microtime().getmypid()); // this should be random enough for now
2339 2337
 
2340 2338
         // set variant and version fields for 'true' random uuid
2341 2339
         $uuid{12} = "4";
2342
-        $n = 8 + (ord($uuid{16}) & 3);
2340
+        $n = 8 + (ord($uuid{16})&3);
2343 2341
         $hex = "0123456789abcdef";
2344 2342
         $uuid{16} = $hex{$n};
2345 2343
 
2346 2344
         // return formated uuid
2347
-        return substr($uuid,  0, 8)."-"
2348
-            .  substr($uuid,  8, 4)."-"
2345
+        return substr($uuid, 0, 8)."-"
2346
+            .  substr($uuid, 8, 4)."-"
2349 2347
             .  substr($uuid, 12, 4)."-"
2350 2348
             .  substr($uuid, 16, 4)."-"
2351 2349
             .  substr($uuid, 20);
@@ -2562,7 +2560,7 @@  discard block
 block discarded – undo
2562 2560
      */
2563 2561
     function _check_uri_condition($uri, $condition)
2564 2562
     {
2565
-		unset($uri);	// not used, but required by function signature
2563
+		unset($uri); // not used, but required by function signature
2566 2564
         // not really implemented here,
2567 2565
         // implementations must override
2568 2566
 
@@ -2638,7 +2636,7 @@  discard block
 block discarded – undo
2638 2636
             // genreate response block
2639 2637
             if ($this->crrnd)
2640 2638
             {
2641
-	            $activelocks.= "
2639
+	            $activelocks .= "
2642 2640
 		            <activelock>
2643 2641
 		            <lockscope><$lock[scope]/></lockscope>
2644 2642
 		            <locktype><$lock[type]/></locktype>
@@ -2651,7 +2649,7 @@  discard block
 block discarded – undo
2651 2649
             }
2652 2650
             else
2653 2651
             {
2654
-	            $activelocks.= "
2652
+	            $activelocks .= "
2655 2653
 		            <D:activelock>
2656 2654
 		            <D:lockscope><D:$lock[scope]/></D:lockscope>
2657 2655
 		            <D:locktype><D:$lock[type]/></D:locktype>
@@ -2704,15 +2702,15 @@  discard block
 block discarded – undo
2704 2702
     {
2705 2703
 		// cadaver (and probably all neon using agents) need a more complete url encoding
2706 2704
 		// otherwise special chars like "$,()'" in filenames do NOT work
2707
-		if (strpos($_SERVER['HTTP_USER_AGENT'],'neon') !== false ||
2705
+		if (strpos($_SERVER['HTTP_USER_AGENT'], 'neon') !== false ||
2708 2706
 			// old netdrive does NOT use a User-Agent, but requires full urlencoding for non-ascii chars (eg. German Umlauts)
2709 2707
 			!isset($_SERVER['HTTP_USER_AGENT']) ||
2710 2708
 			// current netdrive uses "NetDrive 2.5.8" as user-agent
2711
-			stripos($_SERVER['HTTP_USER_AGENT'],'NetDrive') !== false ||
2709
+			stripos($_SERVER['HTTP_USER_AGENT'], 'NetDrive') !== false ||
2712 2710
 			// OS X Finder (WebDAVFS/3.0.0 (03008000) Darwin/14.3.0 (x86_64))
2713
-			stripos($_SERVER['HTTP_USER_AGENT'],'WebDAVFS') !== false && stripos($_SERVER['HTTP_USER_AGENT'],'Darwin'))
2711
+			stripos($_SERVER['HTTP_USER_AGENT'], 'WebDAVFS') !== false && stripos($_SERVER['HTTP_USER_AGENT'], 'Darwin'))
2714 2712
 		{
2715
-			return strtr(rawurlencode($url),array(
2713
+			return strtr(rawurlencode($url), array(
2716 2714
 				'%2F' => '/',
2717 2715
 				'%3A' => ':',
2718 2716
 			));
@@ -2769,7 +2767,7 @@  discard block
 block discarded – undo
2769 2767
     	//error_log(__METHOD__.'('.array2string($props).')');
2770 2768
     	if (isset($props['name'])) $props = array($props);
2771 2769
 
2772
-    	foreach($props as $prop)
2770
+    	foreach ($props as $prop)
2773 2771
 		{
2774 2772
 	    	if (!isset($ns_hash[$prop['ns']])) // unknown namespace
2775 2773
 	    	{
@@ -2791,13 +2789,13 @@  discard block
 block discarded – undo
2791 2789
 		    	{
2792 2790
 			    	$vals = '';
2793 2791
 
2794
-			    	foreach($subprop as $attr => $val)
2792
+			    	foreach ($subprop as $attr => $val)
2795 2793
 					{
2796 2794
 				    	$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES, 'utf-8').'"';
2797 2795
 					}
2798 2796
 
2799 2797
 		             $ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2800
-				    	$vals .'/>';
2798
+				    	$vals.'/>';
2801 2799
 		    	}
2802 2800
 	    	}
2803 2801
 	    	else
@@ -2808,7 +2806,7 @@  discard block
 block discarded – undo
2808 2806
 		    	}
2809 2807
 		    	else
2810 2808
 		    	{
2811
-			    	if(isset($prop['raw']))
2809
+			    	if (isset($prop['raw']))
2812 2810
 					{
2813 2811
 						$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
2814 2812
 					} else {
@@ -2850,7 +2848,7 @@  discard block
 block discarded – undo
2850 2848
 			case "iso-8859-15":
2851 2849
 			case "latin-1":
2852 2850
 			default:
2853
-				error_log( __METHOD__."utf8 encode\n" .print_r(utf8_encode($text),true));
2851
+				error_log(__METHOD__."utf8 encode\n".print_r(utf8_encode($text), true));
2854 2852
 				return utf8_encode($text);
2855 2853
         }
2856 2854
     }
@@ -2864,7 +2862,7 @@  discard block
 block discarded – undo
2864 2862
     public static function _slashify($path)
2865 2863
     {
2866 2864
 		//error_log(__METHOD__." called with $path");
2867
-		if ($path[self::bytes($path)-1] != '/') {
2865
+		if ($path[self::bytes($path) - 1] != '/') {
2868 2866
 			//error_log(__METHOD__." added slash at the end of path");
2869 2867
 			$path = $path."/";
2870 2868
 		}
@@ -2880,7 +2878,7 @@  discard block
 block discarded – undo
2880 2878
     public static function _unslashify($path)
2881 2879
     {
2882 2880
         //error_log(__METHOD__." called with $path");
2883
-        if ($path[self::bytes($path)-1] == '/') {
2881
+        if ($path[self::bytes($path) - 1] == '/') {
2884 2882
             $path = substr($path, 0, -1);
2885 2883
 			//error_log(__METHOD__." removed slash at the end of path");
2886 2884
         }
@@ -2913,13 +2911,13 @@  discard block
 block discarded – undo
2913 2911
      */
2914 2912
     public static function bytes($str)
2915 2913
     {
2916
-    	static $func_overload=null;
2914
+    	static $func_overload = null;
2917 2915
 
2918 2916
     	if (is_null($func_overload))
2919 2917
     	{
2920 2918
     		$func_overload = @extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
2921 2919
     	}
2922
-    	return $func_overload & 2 ? mb_strlen($str,'ascii') : strlen($str);
2920
+    	return $func_overload&2 ? mb_strlen($str, 'ascii') : strlen($str);
2923 2921
     }
2924 2922
 }
2925 2923
 
Please login to merge, or discard this patch.
Braces   +700 added lines, -289 removed lines patch added patch discarded remove patch
@@ -196,7 +196,8 @@  discard block
 block discarded – undo
196 196
     function ServeRequest($prefix=null)
197 197
     {
198 198
         // prevent warning in litmus check 'delete_fragment'
199
-        if (strstr($this->_SERVER["REQUEST_URI"], '#')) {
199
+        if (strstr($this->_SERVER["REQUEST_URI"], '#'))
200
+        {
200 201
             $this->http_status("400 Bad Request");
201 202
             return;
202 203
         }
@@ -221,7 +222,8 @@  discard block
 block discarded – undo
221 222
         $path_info_raw = substr($path_info, strlen($this->_SERVER["SCRIPT_NAME"]));
222 223
 
223 224
         // just in case the path came in empty ...
224
-        if (empty($path_info_raw)) {
225
+        if (empty($path_info_raw))
226
+        {
225 227
             $path_info_raw = "/";
226 228
         }
227 229
 
@@ -245,28 +247,36 @@  discard block
 block discarded – undo
245 247
         	'#' => '%23',
246 248
         	'?' => '%3F',
247 249
         ));
248
-        if (!strlen($this->path)) {
249
-            if ($this->_SERVER["REQUEST_METHOD"] == "GET") {
250
+        if (!strlen($this->path))
251
+        {
252
+            if ($this->_SERVER["REQUEST_METHOD"] == "GET")
253
+            {
250 254
                 // redirect clients that try to GET a collection
251 255
                 // WebDAV clients should never try this while
252 256
                 // regular HTTP clients might ...
253 257
                 header("Location: ".$this->base_uri."/");
254 258
                 return;
255
-            } else {
259
+            }
260
+            else
261
+            {
256 262
                 // if a WebDAV client didn't give a path we just assume '/'
257 263
                 $this->path = "/";
258 264
             }
259 265
         }
260 266
 
261
-        if (ini_get("magic_quotes_gpc")) {
267
+        if (ini_get("magic_quotes_gpc"))
268
+        {
262 269
             $this->path = stripslashes($this->path);
263 270
         }
264 271
 
265 272
 
266 273
         // identify ourselves
267
-        if (empty($this->dav_powered_by)) {
274
+        if (empty($this->dav_powered_by))
275
+        {
268 276
             header("X-Dav-Powered-By: PHP class: ".get_class($this));
269
-        } else {
277
+        }
278
+        else
279
+        {
270 280
             header("X-Dav-Powered-By: ".$this->dav_powered_by);
271 281
         }
272 282
 
@@ -274,7 +284,8 @@  discard block
 block discarded – undo
274 284
         // for the motivation for not checking OPTIONS requests on / see
275 285
         // http://pear.php.net/bugs/bug.php?id=5363
276 286
         if ( (   !(($this->_SERVER['REQUEST_METHOD'] == 'OPTIONS') && ($this->path == "/")))
277
-             && (!$this->_check_auth())) {
287
+             && (!$this->_check_auth()))
288
+        {
278 289
             // RFC2518 says we must use Digest instead of Basic
279 290
             // but Microsoft Clients do not support Digest
280 291
             // and we don't support NTLM and Kerberos
@@ -289,7 +300,8 @@  discard block
 block discarded – undo
289 300
         }
290 301
 
291 302
         // check
292
-        if (! $this->_check_if_header_conditions()) {
303
+        if (! $this->_check_if_header_conditions())
304
+        {
293 305
             return;
294 306
         }
295 307
 
@@ -298,16 +310,24 @@  discard block
 block discarded – undo
298 310
         $wrapper = "http_".$method;
299 311
 
300 312
         // activate HEAD emulation by GET if no HEAD method found
301
-        if ($method == "head" && !method_exists($this, "head")) {
313
+        if ($method == "head" && !method_exists($this, "head"))
314
+        {
302 315
             $method = "get";
303 316
         }
304 317
 
305
-        if (method_exists($this, $wrapper) && ($method == "options" || method_exists($this, $method))) {
318
+        if (method_exists($this, $wrapper) && ($method == "options" || method_exists($this, $method)))
319
+        {
306 320
             $this->$wrapper();  // call method by name
307
-        } else { // method not found/implemented
308
-            if ($this->_SERVER["REQUEST_METHOD"] == "LOCK") {
321
+        }
322
+        else
323
+        {
324
+// method not found/implemented
325
+            if ($this->_SERVER["REQUEST_METHOD"] == "LOCK")
326
+            {
309 327
             	$error = '412 Precondition failed';
310
-            } else {
328
+            }
329
+            else
330
+            {
311 331
                 $error = '405 Method not allowed';
312 332
                 header("Allow: ".join(", ", $this->_allow()));  // tell client what's allowed
313 333
             }
@@ -612,12 +632,14 @@  discard block
 block discarded – undo
612 632
 
613 633
         // dav header
614 634
         $dav = array(1);        // assume we are always dav class 1 compliant
615
-        if (isset($allow['LOCK'])) {
635
+        if (isset($allow['LOCK']))
636
+        {
616 637
             $dav[] = 2;         // dav class 2 requires that locking is supported
617 638
         }
618 639
 
619 640
         // allow extending class to modify DAV and Allow headers
620
-		if (method_exists($this,'OPTIONS')) {
641
+		if (method_exists($this,'OPTIONS'))
642
+		{
621 643
 			$this->OPTIONS($this->path,$dav,$allow);
622 644
 		}
623 645
 
@@ -661,34 +683,48 @@  discard block
 block discarded – undo
661 683
         $options["path"] = $this->path;
662 684
 
663 685
         // search depth from header (default is "infinity)
664
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
686
+        if (isset($this->_SERVER['HTTP_DEPTH']))
687
+        {
665 688
             $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
666
-        } else {
689
+        }
690
+        else
691
+        {
667 692
             $options["depth"] = "infinity";
668 693
         }
669 694
 
670 695
         // analyze request payload
671 696
         $propinfo = new _parse_propfind("php://input", $this->store_request);
672
-        if ($this->store_request) $this->request = $propinfo->request;
673
-        if (!$propinfo->success) {
697
+        if ($this->store_request)
698
+        {
699
+        	$this->request = $propinfo->request;
700
+        }
701
+        if (!$propinfo->success)
702
+        {
674 703
             $this->http_status("400 Error");
675 704
             return;
676 705
         }
677 706
 		$options['root'] = $propinfo->root;
678 707
 		$options['props'] = $propinfo->props;
679 708
 		if ($propinfo->filters)
680
-			$options['filters'] = $propinfo->filters;
709
+		{
710
+					$options['filters'] = $propinfo->filters;
711
+		}
681 712
 		if ($propinfo->other)
682
-			$options['other'] = $propinfo->other;
713
+		{
714
+					$options['other'] = $propinfo->other;
715
+		}
683 716
 
684 717
         // call user handler
685
-        if (!($retval =$this->$handler($options, $files))) {
718
+        if (!($retval =$this->$handler($options, $files)))
719
+        {
686 720
             $files = array("files" => array());
687
-            if (method_exists($this, "checkLock")) {
721
+            if (method_exists($this, "checkLock"))
722
+            {
688 723
                 // is locked?
689 724
                 $lock = $this->checkLock($this->path);
690 725
 
691
-                if (is_array($lock) && count($lock)) {
726
+                if (is_array($lock) && count($lock))
727
+                {
692 728
                     $created          = isset($lock['created'])  ? $lock['created']  : time();
693 729
                     $modified         = isset($lock['modified']) ? $lock['modified'] : time();
694 730
                     $files['files'][] = array("path"  => self::_slashify($this->path),
@@ -702,7 +738,8 @@  discard block
 block discarded – undo
702 738
                 }
703 739
             }
704 740
 
705
-            if (empty($files['files'])) {
741
+            if (empty($files['files']))
742
+            {
706 743
                 $this->http_status("404 Not Found");
707 744
                 return;
708 745
             }
@@ -736,7 +773,8 @@  discard block
 block discarded – undo
736 773
         $allow = false;
737 774
 
738 775
         // allow extending class to modify DAV
739
-		if (method_exists($this,'OPTIONS')) {
776
+		if (method_exists($this,'OPTIONS'))
777
+		{
740 778
 			$this->OPTIONS($this->path,$dav,$allow);
741 779
 		}
742 780
         header("DAV: "  .join(", ", $dav));
@@ -775,8 +813,14 @@  discard block
 block discarded – undo
775 813
      */
776 814
     function multistatus_responses(&$files, $props, $initial_ns_hash=null, $initial_ns_defs=null)
777 815
     {
778
-    	if (!isset($initial_ns_hash)) $initial_ns_hash = array('DAV:' => 'D');
779
-    	if (!isset($initial_ns_defs)) $initial_ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';
816
+    	if (!isset($initial_ns_hash))
817
+    	{
818
+    		$initial_ns_hash = array('DAV:' => 'D');
819
+    	}
820
+    	if (!isset($initial_ns_defs))
821
+    	{
822
+    		$initial_ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';
823
+    	}
780 824
 
781 825
     	// using an ArrayIterator to prevent foreach from copying the array,
782 826
         // as we cant loop by reference, when an iterator is given in $files
@@ -790,10 +834,12 @@  discard block
 block discarded – undo
790 834
         	isset($this->_SERVER['HTTP_PREFER']) && in_array('depth-noroot', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER']));
791 835
 
792 836
         // now we loop over all returned file entries
793
-        foreach ($files as $file) {
837
+        foreach ($files as $file)
838
+        {
794 839
 
795 840
         	// skip first element (root), if requested by Prefer: depth-noroot
796
-        	if ($skip_root) {
841
+        	if ($skip_root)
842
+        	{
797 843
         		$skip_root = false;
798 844
         		continue;
799 845
         	}
@@ -805,17 +851,20 @@  discard block
 block discarded – undo
805 851
 	        $ns_defs = $initial_ns_defs;
806 852
 
807 853
             // nothing to do if no properties were returend for a file
808
-			if (isset($file["props"]) && is_array($file["props"])) {
854
+			if (isset($file["props"]) && is_array($file["props"]))
855
+			{
809 856
 
810 857
 	            // now loop over all returned properties
811
-	            foreach ($file["props"] as &$prop) {
858
+	            foreach ($file["props"] as &$prop)
859
+	            {
812 860
 	                // as a convenience feature we do not require that user handlers
813 861
 	                // restrict returned properties to the requested ones
814 862
 	                // here we strip all unrequested entries out of the response
815 863
 
816 864
 	            	// this can happen if we have allprop and prop in one propfind:
817 865
 	            	// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
818
-	                switch(is_array($props) ? $props[0] : $props) {
866
+	                switch(is_array($props) ? $props[0] : $props)
867
+	                {
819 868
 	                case "all":
820 869
 	                    // nothing to remove
821 870
 	                    break;
@@ -830,16 +879,19 @@  discard block
 block discarded – undo
830 879
 	                    $found = false;
831 880
 
832 881
 	                    // search property name in requested properties
833
-	                    foreach ((array)$props as $reqprop) {
882
+	                    foreach ((array)$props as $reqprop)
883
+	                    {
834 884
 	                        if (   $reqprop["name"]  == $prop["name"]
835
-	                               && @$reqprop["xmlns"] == $prop["ns"]) {
885
+	                               && @$reqprop["xmlns"] == $prop["ns"])
886
+	                        {
836 887
 	                            $found = true;
837 888
 	                            break;
838 889
 	                        }
839 890
 	                    }
840 891
 
841 892
 	                    // unset property and continue with next one if not found/requested
842
-	                    if (!$found) {
893
+	                    if (!$found)
894
+	                    {
843 895
 	                        $prop="";
844 896
 	                        continue(2);
845 897
 	                    }
@@ -847,10 +899,18 @@  discard block
 block discarded – undo
847 899
 	                }
848 900
 
849 901
 	                // namespace handling
850
-	                if (empty($prop["ns"])) continue; // no namespace
902
+	                if (empty($prop["ns"]))
903
+	                {
904
+	                	continue;
905
+	                }
906
+	                // no namespace
851 907
 	                $ns = $prop["ns"];
852 908
 	                //if ($ns == "DAV:") continue; // default namespace
853
-	                if (isset($ns_hash[$ns])) continue; // already known
909
+	                if (isset($ns_hash[$ns]))
910
+	                {
911
+	                	continue;
912
+	                }
913
+	                // already known
854 914
 
855 915
 	                // register namespace
856 916
 	                $ns_name = "ns".(count($ns_hash) + 1);
@@ -860,37 +920,50 @@  discard block
 block discarded – undo
860 920
 
861 921
 	            // we also need to add empty entries for properties that were requested
862 922
 	            // but for which no values where returned by the user handler
863
-	            if (is_array($props)) {
864
-	                foreach ($props as $reqprop) {
865
-	                    if (!is_array($reqprop) || $reqprop['name']=="") continue; // skip empty entries, or 'all' if <allprop /> used together with <prop>
923
+	            if (is_array($props))
924
+	            {
925
+	                foreach ($props as $reqprop)
926
+	                {
927
+	                    if (!is_array($reqprop) || $reqprop['name']=="")
928
+	                    {
929
+	                    	continue;
930
+	                    }
931
+	                    // skip empty entries, or 'all' if <allprop /> used together with <prop>
866 932
 
867 933
 	                    $found = false;
868 934
 
869 935
 	                    // check if property exists in result
870
-	                    foreach ($file["props"] as &$prop) {
936
+	                    foreach ($file["props"] as &$prop)
937
+	                    {
871 938
 	                        if (is_array($prop) && $reqprop["name"] == $prop["name"]
872
-	                               && @$reqprop["xmlns"] == $prop["ns"]) {
939
+	                               && @$reqprop["xmlns"] == $prop["ns"])
940
+	                        {
873 941
 	                            $found = true;
874 942
 	                            break;
875 943
 	                        }
876 944
 	                    }
877 945
 
878
-	                    if (!$found) {
879
-	                        if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") {
946
+	                    if (!$found)
947
+	                    {
948
+	                        if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery")
949
+	                        {
880 950
 	                            // lockdiscovery is handled by the base class
881 951
 	                            $file["props"][]
882 952
 	                                = $this->mkprop("DAV:",
883 953
 	                                                "lockdiscovery",
884 954
 	                                                $this->lockdiscovery($file['path']));
885 955
 	                        // only collect $file['noprops'] if we have NO Brief: t and NO Prefer: return=minimal HTTP Header
886
-	                        } elseif ((!isset($this->_SERVER['HTTP_BRIEF']) || $this->_SERVER['HTTP_BRIEF'] != 't') &&
887
-	                        	(!isset($this->_SERVER['HTTP_PREFER']) || !in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER'])))) {
956
+	                        }
957
+	                        elseif ((!isset($this->_SERVER['HTTP_BRIEF']) || $this->_SERVER['HTTP_BRIEF'] != 't') &&
958
+	                        	(!isset($this->_SERVER['HTTP_PREFER']) || !in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER']))))
959
+	                        {
888 960
 	                            // add empty value for this property
889 961
 	                            $file["noprops"][] =
890 962
 	                                $this->mkprop($reqprop["xmlns"], $reqprop["name"], "");
891 963
 
892 964
 	                            // register property namespace if not known yet
893
-	                            if ($reqprop["xmlns"] != "DAV:" && !isset($ns_hash[$reqprop["xmlns"]])) {
965
+	                            if ($reqprop["xmlns"] != "DAV:" && !isset($ns_hash[$reqprop["xmlns"]]))
966
+	                            {
894 967
 	                                $ns_name = "ns".(count($ns_hash) + 1);
895 968
 	                                $ns_hash[$reqprop["xmlns"]] = $ns_name;
896 969
 	                                $ns_defs .= " xmlns:$ns_name=\"$reqprop[xmlns]\"";
@@ -901,9 +974,15 @@  discard block
 block discarded – undo
901 974
 	            }
902 975
 	        }
903 976
             // ignore empty or incomplete entries
904
-            if (!is_array($file) || empty($file) || !isset($file["path"])) continue;
977
+            if (!is_array($file) || empty($file) || !isset($file["path"]))
978
+            {
979
+            	continue;
980
+            }
905 981
             $path = $file['path'];
906
-            if (!is_string($path) || $path==="") continue;
982
+            if (!is_string($path) || $path==="")
983
+            {
984
+            	continue;
985
+            }
907 986
 
908 987
             if ($this->crrnd)
909 988
             {
@@ -932,38 +1011,56 @@  discard block
 block discarded – undo
932 1011
             }
933 1012
 
934 1013
             // report all found properties and their values (if any)
935
-            if (isset($file["props"]) && is_array($file["props"])) {
1014
+            if (isset($file["props"]) && is_array($file["props"]))
1015
+            {
936 1016
                 echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
937 1017
                 echo '    <'.($this->crrnd?'':'D:')."prop>\n";
938 1018
 
939
-                foreach ($file["props"] as &$prop) {
1019
+                foreach ($file["props"] as &$prop)
1020
+                {
940 1021
 
941
-                    if (!is_array($prop)) continue;
942
-                    if (!isset($prop["name"])) continue;
1022
+                    if (!is_array($prop))
1023
+                    {
1024
+                    	continue;
1025
+                    }
1026
+                    if (!isset($prop["name"]))
1027
+                    {
1028
+                    	continue;
1029
+                    }
943 1030
 
944
-                    if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) {
1031
+                    if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false)
1032
+                    {
945 1033
                         // empty properties (cannot use empty() for check as "0" is a legal value here)
946
-                        if ($prop["ns"]=="DAV:") {
1034
+                        if ($prop["ns"]=="DAV:")
1035
+                        {
947 1036
                             echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
948
-                        } else if (!empty($prop["ns"])) {
1037
+                        }
1038
+                        else if (!empty($prop["ns"]))
1039
+                        {
949 1040
                             echo "     <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
950
-                        } else {
1041
+                        }
1042
+                        else
1043
+                        {
951 1044
                             echo "     <$prop[name] xmlns=\"\"/>";
952 1045
                         }
953 1046
                     }
954 1047
                     // multiple level of responses required for expand-property reports
955 1048
                     elseif(isset($prop['props']) && is_array($prop['val']))
956 1049
                     {
957
-                        if ($prop['ns'] && !isset($ns_hash[$prop['ns']])) {
1050
+                        if ($prop['ns'] && !isset($ns_hash[$prop['ns']]))
1051
+                        {
958 1052
                             $ns_name = "ns".(count($ns_hash) + 1);
959 1053
                             $ns_hash[$prop['ns']] = $ns_name;
960 1054
                         }
961 1055
                     	echo '     <'.$ns_hash[$prop['ns']].":$prop[name]>\n";
962 1056
                         $this->multistatus_responses($prop['val'], $prop['props'], $ns_hash, '');
963 1057
                     	echo '     </'.$ns_hash[$prop['ns']].":$prop[name]>\n";
964
-                    } else if ($prop["ns"] == "DAV:") {
1058
+                    }
1059
+                    else if ($prop["ns"] == "DAV:")
1060
+                    {
965 1061
                         // some WebDAV properties need special treatment
966
-                        switch ($prop["name"]) {
1062
+                        switch ($prop["name"])
1063
+                        {
967 1064
                         case "creationdate":
968 1065
                             echo '     <'.($this->crrnd?'':'D:')."creationdate ns0:dt=\"dateTime.tz\">"
969 1066
                                 . gmdate("Y-m-d\\TH:i:s\\Z", $prop['val'])
@@ -999,40 +1096,57 @@  discard block
 block discarded – undo
999 1096
                             {
1000 1097
                             	$hns_hash = $ns_hash;
1001 1098
                             	$val = $this->_hierarchical_prop_encode($prop['val'], 'DAV:', $ns_defs, $hns_hash);
1002
-                            } elseif (isset($prop['raw'])) {
1099
+                            }
1100
+                            elseif (isset($prop['raw']))
1101
+                            {
1003 1102
                             	$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
1004
-                            } else {
1103
+                            }
1104
+                            else
1105
+                            {
1005 1106
 	                    		$val = $this->_prop_encode(htmlspecialchars($prop['val'], ENT_NOQUOTES, 'utf-8'));
1006 1107
                             }
1007 1108
 	                        echo '     <'.($this->crrnd?'':'D:')."$prop[name]$ns_defs>$val".
1008 1109
 	                        	'</'.($this->crrnd?'':'D:')."$prop[name]>\n";
1009 1110
                             break;
1010 1111
                         }
1011
-                    } else {
1112
+                    }
1113
+                    else
1114
+                    {
1012 1115
                         // allow multiple values and attributes, required eg. for caldav:supported-calendar-component-set
1013
-                        if ($prop['ns'] && is_array($prop['val'])) {
1014
-                    		if (!isset($ns_hash[$prop['ns']])) {
1116
+                        if ($prop['ns'] && is_array($prop['val']))
1117
+                        {
1118
+                    		if (!isset($ns_hash[$prop['ns']]))
1119
+                    		{
1015 1120
                                 $ns_name = "ns".(count($ns_hash) + 1);
1016 1121
                                 $ns_hash[$prop['ns']] = $ns_name;
1017 1122
                     		}
1018 1123
                   			$vals = $extra_ns = '';
1019 1124
                     		foreach($prop['val'] as $subprop)
1020 1125
                     		{
1021
-                    			if ($subprop['ns'] && $subprop['ns'] != 'DAV:') {
1126
+                    			if ($subprop['ns'] && $subprop['ns'] != 'DAV:')
1127
+                    			{
1022 1128
 		                    		// register property namespace if not known yet
1023
-		                    		if (!isset($ns_hash[$subprop['ns']])) {
1129
+		                    		if (!isset($ns_hash[$subprop['ns']]))
1130
+		                    		{
1024 1131
 			                    		$ns_name = "ns".(count($ns_hash) + 1);
1025 1132
 			                    		$ns_hash[$subprop['ns']] = $ns_name;
1026
-		                    		} else {
1133
+		                    		}
1134
+		                    		else
1135
+		                    		{
1027 1136
 			                    		$ns_name = $ns_hash[$subprop['ns']];
1028 1137
 		                    		}
1029
-		                    		if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) {
1138
+		                    		if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false)
1139
+		                    		{
1030 1140
 			                    		$extra_ns .= $extra;
1031 1141
 		                    		}
1032 1142
 		                    		$ns_name .= ':';
1033
-	                    		} elseif ($subprop['ns'] == 'DAV:') {
1143
+	                    		}
1144
+	                    		elseif ($subprop['ns'] == 'DAV:')
1145
+	                    		{
1034 1146
 		                    		$ns_name = 'D:';
1035
-	                    		} else {
1147
+	                    		}
1148
+	                    		else
1149
+	                    		{
1036 1150
 		                    		$ns_name = '';
1037 1151
 	                    		}
1038 1152
 	                    		$vals .= "<$ns_name$subprop[name]";
@@ -1047,7 +1161,7 @@  discard block
 block discarded – undo
1047 1161
 	                    			else	// val contains only attributes, no value
1048 1162
 	                    			{
1049 1163
 			                    		foreach($subprop['val'] as $attr => $val)
1050
-										{
1164
+			                    		{
1051 1165
 				                    		$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES, 'utf-8').'"';
1052 1166
 										}
1053 1167
 			                    		$vals .= '/>';
@@ -1056,34 +1170,50 @@  discard block
 block discarded – undo
1056 1170
 	                    		else
1057 1171
 	                    		{
1058 1172
 	                    			$vals .= '>';
1059
-	                    			if (isset($subprop['raw'])) {
1173
+	                    			if (isset($subprop['raw']))
1174
+	                    			{
1060 1175
 	                    				$vals .= '<![CDATA['.$subprop['val'].']]>';
1061
-	                    			} else {
1062
-	                    				if($subprop['name'] == 'href') $subprop['val'] = $this->_urlencode($subprop['val']);
1176
+	                    			}
1177
+	                    			else
1178
+	                    			{
1179
+	                    				if($subprop['name'] == 'href')
1180
+	                    				{
1181
+	                    					$subprop['val'] = $this->_urlencode($subprop['val']);
1182
+	                    				}
1063 1183
 		                    			$vals .= htmlspecialchars($subprop['val'], ENT_NOQUOTES, 'utf-8');
1064 1184
 	                    			}
1065 1185
 	                    			$vals .= "</$ns_name$subprop[name]>";
1066 1186
 	                    		}
1067 1187
                     		}
1068 1188
                     		echo '     <'.$ns_hash[$prop['ns']].":$prop[name]$extra_ns>$vals</".$ns_hash[$prop['ns']].":$prop[name]>\n";
1069
-                        } else {
1189
+                        }
1190
+                        else
1191
+                        {
1070 1192
                         	if ($prop['raw'])
1071 1193
                         	{
1072 1194
                         		$val = '<![CDATA['.$prop['val'].']]>';
1073
-                        	} else {
1195
+                        	}
1196
+                        	else
1197
+                        	{
1074 1198
                         		$val = htmlspecialchars($prop['val'], ENT_NOQUOTES, 'utf-8');
1075 1199
                         	}
1076 1200
                         	$val = $this->_prop_encode($val);
1077 1201
 	                        // properties from namespaces != "DAV:" or without any namespace
1078
-	                        if ($prop['ns']) {
1079
-		                        if ($this->crrnd) {
1202
+	                        if ($prop['ns'])
1203
+	                        {
1204
+		                        if ($this->crrnd)
1205
+		                        {
1080 1206
 			                        echo "     <$prop[name] xmlns=".'"'.$prop["ns"].'">'
1081 1207
 									. $val . "</$prop[name]>\n";
1082
-		                        } else {
1208
+		                        }
1209
+		                        else
1210
+		                        {
1083 1211
 			                        echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]>"
1084 1212
 									. $val . '</'.$ns_hash[$prop['ns']].":$prop[name]>\n";
1085 1213
 		                        }
1086
-	                        } else {
1214
+	                        }
1215
+	                        else
1216
+	                        {
1087 1217
 		                        echo "     <$prop[name] xmlns=\"\">$val</$prop[name]>\n";
1088 1218
 	                        }
1089 1219
                         }
@@ -1105,16 +1235,23 @@  discard block
 block discarded – undo
1105 1235
             }
1106 1236
 
1107 1237
             // now report all properties requested but not found
1108
-            if (isset($file["noprops"])) {
1238
+            if (isset($file["noprops"]))
1239
+            {
1109 1240
                 echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1110 1241
                 echo '    <'.($this->crrnd?'':'D:')."prop>\n";
1111 1242
 
1112
-                foreach ($file["noprops"] as &$prop) {
1113
-                    if ($prop["ns"] == "DAV:") {
1243
+                foreach ($file["noprops"] as &$prop)
1244
+                {
1245
+                    if ($prop["ns"] == "DAV:")
1246
+                    {
1114 1247
                         echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
1115
-                    } else if ($prop["ns"] == "") {
1248
+                    }
1249
+                    else if ($prop["ns"] == "")
1250
+                    {
1116 1251
                         echo "     <$prop[name] xmlns=\"\"/>\n";
1117
-                    } else {
1252
+                    }
1253
+                    else
1254
+                    {
1118 1255
                         echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]/>\n";
1119 1256
                     }
1120 1257
                 }
@@ -1163,15 +1300,20 @@  discard block
 block discarded – undo
1163 1300
      */
1164 1301
     function http_PROPPATCH()
1165 1302
     {
1166
-        if ($this->_check_lock_status($this->path)) {
1303
+        if ($this->_check_lock_status($this->path))
1304
+        {
1167 1305
             $options = Array();
1168 1306
 
1169 1307
             $options["path"] = $this->path;
1170 1308
 
1171 1309
             $propinfo = new _parse_proppatch("php://input", $this->store_request);
1172
-            if ($this->store_request) $this->request = $propinfo->request;
1310
+            if ($this->store_request)
1311
+            {
1312
+            	$this->request = $propinfo->request;
1313
+            }
1173 1314
 
1174
-            if (!$propinfo->success) {
1315
+            if (!$propinfo->success)
1316
+            {
1175 1317
                 $this->http_status("400 Error");
1176 1318
                 return;
1177 1319
             }
@@ -1189,14 +1331,16 @@  discard block
 block discarded – undo
1189 1331
             echo ' <'.($this->crrnd?'':'D:')."response>\n";
1190 1332
             echo '  <'.($this->crrnd?'':'D:')."href>".$this->_urlencode($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)).'</'.($this->crrnd?'':'D:')."href>\n";
1191 1333
 
1192
-            foreach ($options["props"] as $prop) {
1334
+            foreach ($options["props"] as $prop)
1335
+            {
1193 1336
                 echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1194 1337
                 echo '    <'.($this->crrnd?'':'D:')."prop><$prop[name] xmlns=\"$prop[ns]\"/></".($this->crrnd?'':'D:')."prop>\n";
1195 1338
                 echo '    <'.($this->crrnd?'':'D:')."status>HTTP/1.1 $prop[status]</".($this->crrnd?'':'D:')."status>\n";
1196 1339
                 echo '   </'.($this->crrnd?'':'D:')."propstat>\n";
1197 1340
             }
1198 1341
 
1199
-            if ($responsedescr) {
1342
+            if ($responsedescr)
1343
+            {
1200 1344
                 echo '  <'.($this->crrnd?'':'D:')."responsedescription>".
1201 1345
                     $this->_prop_encode(htmlspecialchars($responsedescr, ENT_NOQUOTES, 'utf-8')).
1202 1346
                     '</'.($this->crrnd?'':'D:')."responsedescription>\n";
@@ -1204,7 +1348,9 @@  discard block
 block discarded – undo
1204 1348
 
1205 1349
             echo ' </'.($this->crrnd?'':'D:')."response>\n";
1206 1350
             echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
1207
-        } else {
1351
+        }
1352
+        else
1353
+        {
1208 1354
             $this->http_status("423 Locked");
1209 1355
         }
1210 1356
     }
@@ -1274,11 +1420,14 @@  discard block
 block discarded – undo
1274 1420
 
1275 1421
         $this->_get_ranges($options);
1276 1422
 
1277
-        if (true === ($status = $this->GET($options))) {
1278
-            if (!headers_sent()) {
1423
+        if (true === ($status = $this->GET($options)))
1424
+        {
1425
+            if (!headers_sent())
1426
+            {
1279 1427
                 $status = "200 OK";
1280 1428
 
1281
-                if (!isset($options['mimetype'])) {
1429
+                if (!isset($options['mimetype']))
1430
+                {
1282 1431
                     $options['mimetype'] = "application/octet-stream";
1283 1432
                 }
1284 1433
                 // switching off zlib.output_compression for everything but text files,
@@ -1290,7 +1439,8 @@  discard block
 block discarded – undo
1290 1439
                 }
1291 1440
                 header("Content-type: $options[mimetype]");
1292 1441
 
1293
-                if (isset($options['mtime'])) {
1442
+                if (isset($options['mtime']))
1443
+                {
1294 1444
                     header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1295 1445
                 }
1296 1446
                 // fix for IE and https, thanks to [email protected]
@@ -1299,55 +1449,82 @@  discard block
 block discarded – undo
1299 1449
 				header("Cache-Control: maxage=1"); //In seconds
1300 1450
 				header("Pragma: public");
1301 1451
 
1302
-                if (isset($options['stream'])) {
1452
+                if (isset($options['stream']))
1453
+                {
1303 1454
                     // GET handler returned a stream
1304
-                    if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET))) {
1455
+                    if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET)))
1456
+                    {
1305 1457
                         // partial request and stream is seekable
1306 1458
 
1307
-                        if (count($options['ranges']) === 1) {
1459
+                        if (count($options['ranges']) === 1)
1460
+                        {
1308 1461
                             $range = $options['ranges'][0];
1309 1462
 
1310
-                            if (isset($range['start'])) {
1463
+                            if (isset($range['start']))
1464
+                            {
1311 1465
                                 fseek($options['stream'], $range['start'], SEEK_SET);
1312
-                                if (feof($options['stream'])) {
1466
+                                if (feof($options['stream']))
1467
+                                {
1313 1468
                                     $this->http_status($status = "416 Requested range not satisfiable");
1314 1469
                                     return;
1315 1470
                                 }
1316 1471
 
1317
-                                if (!empty($range['end'])) {
1472
+                                if (!empty($range['end']))
1473
+                                {
1318 1474
                                     $size = $range['end']-$range['start']+1;
1319 1475
                                     $this->http_status($status = "206 Partial content");
1320
-                                    if (!self::use_compression()) header("Content-Length: $size");
1476
+                                    if (!self::use_compression())
1477
+                                    {
1478
+                                    	header("Content-Length: $size");
1479
+                                    }
1321 1480
                                     header("Content-Range: bytes $range[start]-$range[end]/"
1322 1481
                                            . (isset($options['size']) ? $options['size'] : "*"));
1323
-                                    while ($size > 0 && !feof($options['stream'])) {
1482
+                                    while ($size > 0 && !feof($options['stream']))
1483
+                                    {
1324 1484
                                         $buffer = fread($options['stream'], $size < 8192 ? $size : 8192);
1325 1485
                                         $size  -= self::bytes($buffer);
1326 1486
                                         echo $buffer;
1327 1487
                                     }
1328
-                                } else {
1488
+                                }
1489
+                                else
1490
+                                {
1329 1491
                                     $this->http_status($status = "206 Partial content");
1330
-                                    if (isset($options['size'])) {
1331
-                                        if (!self::use_compression()) header("Content-Length: ".($options['size'] - $range['start']));
1492
+                                    if (isset($options['size']))
1493
+                                    {
1494
+                                        if (!self::use_compression())
1495
+                                        {
1496
+                                        	header("Content-Length: ".($options['size'] - $range['start']));
1497
+                                        }
1332 1498
                                         header("Content-Range: bytes ".$range['start']."-".
1333 1499
 											(isset($options['size']) ? $options['size']-1 : "")."/"
1334 1500
 										   . (isset($options['size']) ? $options['size'] : "*"));
1335 1501
                                     }
1336 1502
                                     fpassthru($options['stream']);
1337 1503
                                 }
1338
-                            } else {
1339
-                                if (!self::use_compression()) header("Content-length: ".$range['last']);
1504
+                            }
1505
+                            else
1506
+                            {
1507
+                                if (!self::use_compression())
1508
+                                {
1509
+                                	header("Content-length: ".$range['last']);
1510
+                                }
1340 1511
                                 fseek($options['stream'], -$range['last'], SEEK_END);
1341 1512
                                 fpassthru($options['stream']);
1342 1513
                             }
1343
-                        } else {
1514
+                        }
1515
+                        else
1516
+                        {
1344 1517
                             $this->_multipart_byterange_header(); // init multipart
1345
-                            foreach ($options['ranges'] as $range) {
1518
+                            foreach ($options['ranges'] as $range)
1519
+                            {
1346 1520
                                 // TODO what if size unknown? 500?
1347
-                                if (isset($range['start'])) {
1521
+                                if (isset($range['start']))
1522
+                                {
1348 1523
                                     $from = $range['start'];
1349 1524
                                     $to   = !empty($range['end']) ? $range['end'] : $options['size']-1;
1350
-                                } else {
1525
+                                }
1526
+                                else
1527
+                                {
1351 1528
                                     $from = $options['size'] - $range['last']-1;
1352 1529
                                     $to   = $options['size'] -1;
1353 1530
                                 }
@@ -1357,7 +1534,8 @@  discard block
 block discarded – undo
1357 1534
 
1358 1535
 
1359 1536
                                 fseek($options['stream'], $from, SEEK_SET);
1360
-                                while ($size && !feof($options['stream'])) {
1537
+                                while ($size && !feof($options['stream']))
1538
+                                {
1361 1539
                                     $buffer = fread($options['stream'], 4096);
1362 1540
                                     $size  -= self::bytes($buffer);
1363 1541
                                     echo $buffer;
@@ -1365,29 +1543,44 @@  discard block
 block discarded – undo
1365 1543
                             }
1366 1544
                             $this->_multipart_byterange_header(); // end multipart
1367 1545
                         }
1368
-                    } else {
1546
+                    }
1547
+                    else
1548
+                    {
1369 1549
                         // normal request or stream isn't seekable, return full content
1370
-                        if (isset($options['size']) && !self::use_compression()) {
1550
+                        if (isset($options['size']) && !self::use_compression())
1551
+                        {
1371 1552
                             header("Content-Length: ".$options['size']);
1372 1553
                         }
1373 1554
                         fpassthru($options['stream']);
1374 1555
                         return; // no more headers
1375 1556
                     }
1376
-                } elseif (isset($options['data'])) {
1377
-                    if (is_array($options['data'])) {
1557
+                }
1558
+                elseif (isset($options['data']))
1559
+                {
1560
+                    if (is_array($options['data']))
1561
+                    {
1378 1562
                         // reply to partial request
1379
-                    } else {
1380
-                        if (!self::use_compression()) header("Content-Length: ".self::bytes($options['data']));
1563
+                    }
1564
+                    else
1565
+                    {
1566
+                        if (!self::use_compression())
1567
+                        {
1568
+                        	header("Content-Length: ".self::bytes($options['data']));
1569
+                        }
1381 1570
                         echo $options['data'];
1382 1571
                     }
1383 1572
                 }
1384 1573
             }
1385 1574
         }
1386 1575
 
1387
-        if (!headers_sent()) {
1388
-            if (false === $status) {
1576
+        if (!headers_sent())
1577
+        {
1578
+            if (false === $status)
1579
+            {
1389 1580
                 $this->http_status("404 not found");
1390
-            } else {
1581
+            }
1582
+            else
1583
+            {
1391 1584
                 // TODO: check setting of headers in various code paths above
1392 1585
                 $this->http_status("$status");
1393 1586
             }
@@ -1404,15 +1597,18 @@  discard block
 block discarded – undo
1404 1597
     function _get_ranges(&$options)
1405 1598
     {
1406 1599
         // process Range: header if present
1407
-        if (isset($this->_SERVER['HTTP_RANGE'])) {
1600
+        if (isset($this->_SERVER['HTTP_RANGE']))
1601
+        {
1408 1602
 
1409 1603
             // we only support standard "bytes" range specifications for now
1410 1604
 			$matches = null;
1411
-            if (preg_match('/bytes\s*=\s*(.+)/', $this->_SERVER['HTTP_RANGE'], $matches)) {
1605
+            if (preg_match('/bytes\s*=\s*(.+)/', $this->_SERVER['HTTP_RANGE'], $matches))
1606
+            {
1412 1607
                 $options["ranges"] = array();
1413 1608
 
1414 1609
                 // ranges are comma separated
1415
-                foreach (explode(",", $matches[1]) as $range) {
1610
+                foreach (explode(",", $matches[1]) as $range)
1611
+                {
1416 1612
                     // ranges are either from-to pairs or just end positions
1417 1613
                     list($start, $end) = explode("-", $range);
1418 1614
                     $options["ranges"][] = ($start==="")
@@ -1438,8 +1634,10 @@  discard block
 block discarded – undo
1438 1634
      */
1439 1635
     function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false)
1440 1636
     {
1441
-        if ($mimetype === false) {
1442
-            if (!isset($this->multipart_separator)) {
1637
+        if ($mimetype === false)
1638
+        {
1639
+            if (!isset($this->multipart_separator))
1640
+            {
1443 1641
                 // initial
1444 1642
 
1445 1643
                 // a little naive, this sequence *might* be part of the content
@@ -1448,13 +1646,17 @@  discard block
 block discarded – undo
1448 1646
 
1449 1647
                 // generate HTTP header
1450 1648
                 header("Content-type: multipart/byteranges; boundary=".$this->multipart_separator);
1451
-            } else {
1649
+            }
1650
+            else
1651
+            {
1452 1652
                 // final
1453 1653
 
1454 1654
                 // generate closing multipart sequence
1455 1655
                 echo "\n--{$this->multipart_separator}--";
1456 1656
             }
1457
-        } else {
1657
+        }
1658
+        else
1659
+        {
1458 1660
             // generate separator and header for next part
1459 1661
             echo "\n--{$this->multipart_separator}\n";
1460 1662
             echo "Content-type: $mimetype\n";
@@ -1481,32 +1683,45 @@  discard block
 block discarded – undo
1481 1683
         $options         = Array();
1482 1684
         $options["path"] = $this->path;
1483 1685
 
1484
-        if (method_exists($this, "HEAD")) {
1686
+        if (method_exists($this, "HEAD"))
1687
+        {
1485 1688
             $status = $this->head($options);
1486
-        } else if (method_exists($this, "GET")) {
1689
+        }
1690
+        else if (method_exists($this, "GET"))
1691
+        {
1487 1692
             ob_start();
1488 1693
             $status = $this->GET($options);
1489
-            if (!isset($options['size'])) {
1694
+            if (!isset($options['size']))
1695
+            {
1490 1696
                 $options['size'] = ob_get_length();
1491 1697
             }
1492 1698
             ob_end_clean();
1493 1699
         }
1494 1700
 
1495
-        if (!isset($options['mimetype'])) {
1701
+        if (!isset($options['mimetype']))
1702
+        {
1496 1703
             $options['mimetype'] = "application/octet-stream";
1497 1704
         }
1498 1705
         header("Content-type: $options[mimetype]");
1499 1706
 
1500
-        if (isset($options['mtime'])) {
1707
+        if (isset($options['mtime']))
1708
+        {
1501 1709
             header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1502 1710
         }
1503 1711
 
1504
-        if (isset($options['size'])) {
1712
+        if (isset($options['size']))
1713
+        {
1505 1714
             header("Content-Length: ".$options['size']);
1506 1715
         }
1507 1716
 
1508
-        if ($status === true)  $status = "200 OK";
1509
-        if ($status === false) $status = "404 Not found";
1717
+        if ($status === true)
1718
+        {
1719
+        	$status = "200 OK";
1720
+        }
1721
+        if ($status === false)
1722
+        {
1723
+        	$status = "404 Not found";
1724
+        }
1510 1725
 
1511 1726
         $this->http_status($status);
1512 1727
     }
@@ -1532,21 +1747,25 @@  discard block
 block discarded – undo
1532 1747
 	        $options['content_length'] = $this->_SERVER['CONTENT_LENGTH'];
1533 1748
         }
1534 1749
         elseif (isset($this->_SERVER['X-Expected-Entity-Length']))
1535
-		{
1750
+        {
1536 1751
 	        // MacOS gives us that hint
1537 1752
 	        $options['content_length'] = $this->_SERVER['X-Expected-Entity-Length'];
1538 1753
 		}
1539 1754
 
1540 1755
         // get the Content-type
1541
-        if (isset($this->_SERVER["CONTENT_TYPE"])) {
1756
+        if (isset($this->_SERVER["CONTENT_TYPE"]))
1757
+        {
1542 1758
 	        // for now we do not support any sort of multipart requests
1543
-	        if (!strncmp($this->_SERVER["CONTENT_TYPE"], 'multipart/', 10)) {
1759
+	        if (!strncmp($this->_SERVER["CONTENT_TYPE"], 'multipart/', 10))
1760
+	        {
1544 1761
 		        $this->http_status('501 not implemented');
1545 1762
 		        echo 'The service does not support mulipart POST requests';
1546 1763
 		        return;
1547 1764
 	        }
1548 1765
 	        $options['content_type'] = $this->_SERVER['CONTENT_TYPE'];
1549
-        } else {
1766
+        }
1767
+        else
1768
+        {
1550 1769
 	        // default content type if none given
1551 1770
 	        $options['content_type'] = 'application/octet-stream';
1552 1771
         }
@@ -1557,7 +1776,7 @@  discard block
 block discarded – undo
1557 1776
     		case 'gzip':
1558 1777
     		case 'deflate':	//zlib
1559 1778
     			if (extension_loaded('zlib'))
1560
-     			{
1779
+    			{
1561 1780
       				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1562 1781
        			}
1563 1782
     	}
@@ -1578,15 +1797,23 @@  discard block
 block discarded – undo
1578 1797
          does not understand or implement and MUST return a 501
1579 1798
          (Not Implemented) response in such cases."
1580 1799
          */
1581
-        foreach ($this->_SERVER as $key => $val) {
1582
-	        if (strncmp($key, 'HTTP_CONTENT', 11)) continue;
1583
-	        switch ($key) {
1800
+        foreach ($this->_SERVER as $key => $val)
1801
+        {
1802
+	        if (strncmp($key, 'HTTP_CONTENT', 11))
1803
+	        {
1804
+	        	continue;
1805
+	        }
1806
+	        switch ($key)
1807
+	        {
1584 1808
 		        case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1585 1809
 		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1586 1810
 		        	{
1587 1811
 		        		case 'gzip':
1588 1812
 		        		case 'deflate':	//zlib
1589
-		        			if (extension_loaded('zlib')) break;
1813
+		        			if (extension_loaded('zlib'))
1814
+		        			{
1815
+		        				break;
1816
+		        			}
1590 1817
 		        			// fall through for no zlib support
1591 1818
 		        		default:
1592 1819
 					        $this->http_status('415 Unsupported Media Type');
@@ -1616,14 +1843,16 @@  discard block
 block discarded – undo
1616 1843
 			        // the header format is also specified in RFC 2616 14.16
1617 1844
 			        // TODO we have to ensure that implementations support this or send 501 instead
1618 1845
 					$matches = null;
1619
-			        if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
1846
+			        if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches))
1847
+			        {
1620 1848
 				        $this->http_status('400 bad request');
1621 1849
 				        echo 'The service does only support single byte ranges';
1622 1850
 				        return;
1623 1851
 			        }
1624 1852
 
1625 1853
 			        $range = array('start'=>$matches[1], 'end'=>$matches[2]);
1626
-			        if (is_numeric($matches[3])) {
1854
+			        if (is_numeric($matches[3]))
1855
+			        {
1627 1856
 				        $range['total_length'] = $matches[3];
1628 1857
 			        }
1629 1858
 			        $options['ranges'][] = $range;
@@ -1655,31 +1884,46 @@  discard block
 block discarded – undo
1655 1884
 	        }
1656 1885
         }
1657 1886
 
1658
-        if (method_exists($this, 'POST')) {
1887
+        if (method_exists($this, 'POST'))
1888
+        {
1659 1889
 	        $status = $this->POST($options);
1660 1890
 
1661
-	        if ($status === false) {
1891
+	        if ($status === false)
1892
+	        {
1662 1893
 		        $status = '400 Something went wrong';
1663
-	        } else if ($status === true) {
1894
+	        }
1895
+	        else if ($status === true)
1896
+	        {
1664 1897
 	        	$status = '200 OK';
1665
-	        } else if (is_resource($status) && get_resource_type($status) == 'stream') {
1898
+	        }
1899
+	        else if (is_resource($status) && get_resource_type($status) == 'stream')
1900
+	        {
1666 1901
 		        $stream = $status;
1667 1902
 
1668 1903
 		        $status = empty($options['new']) ? '200 OK' : '201 Created';
1669 1904
 
1670
-		        if (!empty($options['ranges'])) {
1905
+		        if (!empty($options['ranges']))
1906
+		        {
1671 1907
 			        // TODO multipart support is missing (see also above)
1672
-			        if (0 == fseek($stream, $range[0]['start'], SEEK_SET)) {
1908
+			        if (0 == fseek($stream, $range[0]['start'], SEEK_SET))
1909
+			        {
1673 1910
 				        $length = $range[0]['end']-$range[0]['start']+1;
1674
-				        if (!fwrite($stream, fread($options['stream'], $length))) {
1911
+				        if (!fwrite($stream, fread($options['stream'], $length)))
1912
+				        {
1675 1913
 					        $status = '403 Forbidden';
1676 1914
 				        }
1677
-			        } else {
1915
+			        }
1916
+			        else
1917
+			        {
1678 1918
 				        $status = '403 Forbidden';
1679 1919
 			        }
1680
-		        } else {
1681
-			        while (!feof($options['stream'])) {
1682
-				        if (false === fwrite($stream, fread($options['stream'], 4096))) {
1920
+		        }
1921
+		        else
1922
+		        {
1923
+			        while (!feof($options['stream']))
1924
+			        {
1925
+				        if (false === fwrite($stream, fread($options['stream'], 4096)))
1926
+				        {
1683 1927
 					        $status = '403 Forbidden';
1684 1928
 					        break;
1685 1929
 				        }
@@ -1703,7 +1947,8 @@  discard block
 block discarded – undo
1703 1947
      */
1704 1948
     function http_PUT()
1705 1949
     {
1706
-        if ($this->_check_lock_status($this->path)) {
1950
+        if ($this->_check_lock_status($this->path))
1951
+        {
1707 1952
             $options                   = Array();
1708 1953
             $options["path"]           = $this->path;
1709 1954
 
@@ -1718,15 +1963,19 @@  discard block
 block discarded – undo
1718 1963
             }
1719 1964
 
1720 1965
             // get the Content-type
1721
-            if (isset($this->_SERVER["CONTENT_TYPE"])) {
1966
+            if (isset($this->_SERVER["CONTENT_TYPE"]))
1967
+            {
1722 1968
                 // for now we do not support any sort of multipart requests
1723
-                if (!strncmp($this->_SERVER["CONTENT_TYPE"], "multipart/", 10)) {
1969
+                if (!strncmp($this->_SERVER["CONTENT_TYPE"], "multipart/", 10))
1970
+                {
1724 1971
                     $this->http_status("501 not implemented");
1725 1972
                     echo "The service does not support multipart PUT requests";
1726 1973
                     return;
1727 1974
                 }
1728 1975
                 $options["content_type"] = $this->_SERVER["CONTENT_TYPE"];
1729
-            } else {
1976
+            }
1977
+            else
1978
+            {
1730 1979
                 // default content type if none given
1731 1980
                 $options["content_type"] = "application/octet-stream";
1732 1981
             }
@@ -1737,7 +1986,7 @@  discard block
 block discarded – undo
1737 1986
 	    		case 'gzip':
1738 1987
 	    		case 'deflate':	//zlib
1739 1988
 	    			if (extension_loaded('zlib'))
1740
-	     			{
1989
+	    			{
1741 1990
 	      				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1742 1991
 	       			}
1743 1992
 	    	}
@@ -1758,15 +2007,23 @@  discard block
 block discarded – undo
1758 2007
              does not understand or implement and MUST return a 501
1759 2008
              (Not Implemented) response in such cases."
1760 2009
             */
1761
-            foreach ($this->_SERVER as $key => $val) {
1762
-                if (strncmp($key, "HTTP_CONTENT", 11)) continue;
1763
-                switch ($key) {
2010
+            foreach ($this->_SERVER as $key => $val)
2011
+            {
2012
+                if (strncmp($key, "HTTP_CONTENT", 11))
2013
+                {
2014
+                	continue;
2015
+                }
2016
+                switch ($key)
2017
+                {
1764 2018
                 case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1765 2019
 		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1766 2020
 		        	{
1767 2021
 		        		case 'gzip':
1768 2022
 		        		case 'deflate':	//zlib
1769
-		        			if (extension_loaded('zlib')) break;
2023
+		        			if (extension_loaded('zlib'))
2024
+		        			{
2025
+		        				break;
2026
+		        			}
1770 2027
 		        			// fall through for no zlib support
1771 2028
 		        		default:
1772 2029
 					        $this->http_status('415 Unsupported Media Type');
@@ -1796,18 +2053,21 @@  discard block
 block discarded – undo
1796 2053
                     // the header format is also specified in RFC 2616 14.16
1797 2054
                     // TODO we have to ensure that implementations support this or send 501 instead
1798 2055
 					$matches = null;
1799
-                    if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
2056
+                    if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches))
2057
+                    {
1800 2058
                         $this->http_status("400 bad request");
1801 2059
                         echo "The service does only support single byte ranges";
1802 2060
                         return;
1803 2061
                     }
1804 2062
 
1805 2063
                     $range = array("start" => $matches[1], "end" => $matches[2]);
1806
-                    if (is_numeric($matches[3])) {
2064
+                    if (is_numeric($matches[3]))
2065
+                    {
1807 2066
                         $range["total_length"] = $matches[3];
1808 2067
                     }
1809 2068
 
1810
-                    if (!isset($options['ranges'])) {
2069
+                    if (!isset($options['ranges']))
2070
+                    {
1811 2071
                         $options['ranges'] = array();
1812 2072
                     }
1813 2073
 
@@ -1838,45 +2098,65 @@  discard block
 block discarded – undo
1838 2098
 
1839 2099
             $stat = $this->PUT($options);
1840 2100
 
1841
-            if ($stat === false) {
2101
+            if ($stat === false)
2102
+            {
1842 2103
                 $stat = "403 Forbidden";
1843
-            } else if (is_resource($stat) && get_resource_type($stat) == "stream") {
2104
+            }
2105
+            else if (is_resource($stat) && get_resource_type($stat) == "stream")
2106
+            {
1844 2107
                 $stream = $stat;
1845 2108
 
1846 2109
                 $stat = $options["new"] ? "201 Created" : "204 No Content";
1847 2110
 
1848
-                if (!empty($options["ranges"])) {
2111
+                if (!empty($options["ranges"]))
2112
+                {
1849 2113
                     // TODO multipart support is missing (see also above)
1850
-                    if (0 == fseek($stream, $options['ranges'][0]["start"], SEEK_SET)) {
2114
+                    if (0 == fseek($stream, $options['ranges'][0]["start"], SEEK_SET))
2115
+                    {
1851 2116
                         $length = $options['ranges'][0]["end"] - $options['ranges'][0]["start"]+1;
1852 2117
 
1853
-                        while (!feof($options['stream'])) {
1854
-                            if ($length <= 0) {
2118
+                        while (!feof($options['stream']))
2119
+                        {
2120
+                            if ($length <= 0)
2121
+                            {
1855 2122
                                break;
1856 2123
                             }
1857 2124
 
1858
-                            if ($length <= 8192) {
2125
+                            if ($length <= 8192)
2126
+                            {
1859 2127
                                 $data = fread($options['stream'], $length);
1860
-                            } else {
2128
+                            }
2129
+                            else
2130
+                            {
1861 2131
                                 $data = fread($options['stream'], 8192);
1862 2132
                             }
1863 2133
 
1864
-                            if ($data === false) {
2134
+                            if ($data === false)
2135
+                            {
1865 2136
                                 $stat = "400 Bad request";
1866
-                            } elseif (strlen($data)) {
1867
-                                if (false === fwrite($stream, $data)) {
2137
+                            }
2138
+                            elseif (strlen($data))
2139
+                            {
2140
+                                if (false === fwrite($stream, $data))
2141
+                                {
1868 2142
                                     $stat = "403 Forbidden";
1869 2143
                                     break;
1870 2144
                                 }
1871 2145
                                 $length -= strlen($data);
1872 2146
                             }
1873 2147
                         }
1874
-                    } else {
2148
+                    }
2149
+                    else
2150
+                    {
1875 2151
                         $stat = "403 Forbidden";
1876 2152
                     }
1877
-                } else {
1878
-                    while (!feof($options["stream"])) {
1879
-                        if (false === fwrite($stream, fread($options["stream"], 8192))) {
2153
+                }
2154
+                else
2155
+                {
2156
+                    while (!feof($options["stream"]))
2157
+                    {
2158
+                        if (false === fwrite($stream, fread($options["stream"], 8192)))
2159
+                        {
1880 2160
                             $stat = "403 Forbidden";
1881 2161
                             break;
1882 2162
                         }
@@ -1887,7 +2167,9 @@  discard block
 block discarded – undo
1887 2167
             }
1888 2168
 
1889 2169
             $this->http_status($stat);
1890
-        } else {
2170
+        }
2171
+        else
2172
+        {
1891 2173
             $this->http_status("423 Locked");
1892 2174
         }
1893 2175
     }
@@ -1906,8 +2188,10 @@  discard block
 block discarded – undo
1906 2188
     function http_DELETE()
1907 2189
     {
1908 2190
         // check RFC 2518 Section 9.2, last paragraph
1909
-        if (isset($this->_SERVER["HTTP_DEPTH"])) {
1910
-            if ($this->_SERVER["HTTP_DEPTH"] != "infinity") {
2191
+        if (isset($this->_SERVER["HTTP_DEPTH"]))
2192
+        {
2193
+            if ($this->_SERVER["HTTP_DEPTH"] != "infinity")
2194
+            {
1911 2195
 				if (stripos($_SERVER['HTTP_USER_AGENT'],'webdrive') !== false)
1912 2196
 				{
1913 2197
 					// pretend we didnt see it, as webdrive does not handle the depth parameter correctly while deleting collections
@@ -1921,7 +2205,8 @@  discard block
 block discarded – undo
1921 2205
         }
1922 2206
 
1923 2207
         // check lock status
1924
-        if ($this->_check_lock_status($this->path)) {
2208
+        if ($this->_check_lock_status($this->path))
2209
+        {
1925 2210
             // ok, proceed
1926 2211
             $options         = Array();
1927 2212
             $options["path"] = $this->path;
@@ -1929,7 +2214,9 @@  discard block
 block discarded – undo
1929 2214
             $stat = $this->DELETE($options);
1930 2215
 
1931 2216
             $this->http_status($stat);
1932
-        } else {
2217
+        }
2218
+        else
2219
+        {
1933 2220
             // sorry, its locked
1934 2221
             $this->http_status("423 Locked");
1935 2222
         }
@@ -1964,10 +2251,13 @@  discard block
 block discarded – undo
1964 2251
      */
1965 2252
     function http_MOVE()
1966 2253
     {
1967
-        if ($this->_check_lock_status($this->path)) {
2254
+        if ($this->_check_lock_status($this->path))
2255
+        {
1968 2256
             // destination lock status is always checked by the helper method
1969 2257
             $this->_copymove("move");
1970
-        } else {
2258
+        }
2259
+        else
2260
+        {
1971 2261
             $this->http_status("423 Locked");
1972 2262
         }
1973 2263
     }
@@ -1988,19 +2278,25 @@  discard block
 block discarded – undo
1988 2278
         $options         = Array();
1989 2279
         $options["path"] = $this->path;
1990 2280
 
1991
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
2281
+        if (isset($this->_SERVER['HTTP_DEPTH']))
2282
+        {
1992 2283
             $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
1993
-        } else {
2284
+        }
2285
+        else
2286
+        {
1994 2287
             $options["depth"] = "infinity";
1995 2288
         }
1996 2289
 
1997
-        if (isset($this->_SERVER["HTTP_TIMEOUT"])) {
2290
+        if (isset($this->_SERVER["HTTP_TIMEOUT"]))
2291
+        {
1998 2292
             $options["timeout"] = explode(",", $this->_SERVER["HTTP_TIMEOUT"]);
1999 2293
         }
2000 2294
 
2001
-        if (empty($this->_SERVER['CONTENT_LENGTH']) && !empty($this->_SERVER['HTTP_IF'])) {
2295
+        if (empty($this->_SERVER['CONTENT_LENGTH']) && !empty($this->_SERVER['HTTP_IF']))
2296
+        {
2002 2297
             // check if locking is possible
2003
-            if (!$this->_check_lock_status($this->path)) {
2298
+            if (!$this->_check_lock_status($this->path))
2299
+            {
2004 2300
                 $this->http_status("423 Locked");
2005 2301
                 return;
2006 2302
             }
@@ -2016,15 +2312,19 @@  discard block
 block discarded – undo
2016 2312
 
2017 2313
 
2018 2314
             $stat = $this->LOCK($options);
2019
-        } else {
2315
+        }
2316
+        else
2317
+        {
2020 2318
             // extract lock request information from request XML payload
2021 2319
             $lockinfo = new _parse_lockinfo("php://input");
2022
-            if (!$lockinfo->success) {
2320
+            if (!$lockinfo->success)
2321
+            {
2023 2322
                 $this->http_status("400 bad request");
2024 2323
             }
2025 2324
 
2026 2325
             // check if locking is possible
2027
-            if (!$this->_check_lock_status($this->path, $lockinfo->lockscope === "shared")) {
2326
+            if (!$this->_check_lock_status($this->path, $lockinfo->lockscope === "shared"))
2327
+            {
2028 2328
                 $this->http_status("423 Locked");
2029 2329
                 return;
2030 2330
             }
@@ -2039,36 +2339,51 @@  discard block
 block discarded – undo
2039 2339
             $stat = $this->LOCK($options);
2040 2340
         }
2041 2341
 
2042
-        if (is_bool($stat)) {
2342
+        if (is_bool($stat))
2343
+        {
2043 2344
             $http_stat = $stat ? "200 OK" : "423 Locked";
2044
-        } else {
2345
+        }
2346
+        else
2347
+        {
2045 2348
             $http_stat = (string)$stat;
2046 2349
         }
2047 2350
         $this->http_status($http_stat);
2048 2351
 
2049
-        if ($http_stat{0} == 2) { // 2xx states are ok
2050
-            if ($options["timeout"]) {
2352
+        if ($http_stat{0} == 2)
2353
+        {
2354
+// 2xx states are ok
2355
+            if ($options["timeout"])
2356
+            {
2051 2357
                 // if multiple timeout values were given we take the first only
2052
-                if (is_array($options["timeout"])) {
2358
+                if (is_array($options["timeout"]))
2359
+                {
2053 2360
                     reset($options["timeout"]);
2054 2361
                     $options["timeout"] = current($options["timeout"]);
2055 2362
                 }
2056 2363
                 // if the timeout is numeric only we need to reformat it
2057
-                if (is_numeric($options["timeout"])) {
2364
+                if (is_numeric($options["timeout"]))
2365
+                {
2058 2366
                     // more than a million is considered an absolute timestamp
2059 2367
                     // less is more likely a relative value
2060
-                    if ($options["timeout"]>1000000) {
2368
+                    if ($options["timeout"]>1000000)
2369
+                    {
2061 2370
                         $timeout = "Second-".($options['timeout']-time());
2062
-                    } else {
2371
+                    }
2372
+                    else
2373
+                    {
2063 2374
                         $timeout = "Second-$options[timeout]";
2064 2375
                     }
2065
-                } else {
2376
+                }
2377
+                else
2378
+                {
2066 2379
                     // non-numeric values are passed on verbatim,
2067 2380
                     // no error checking is performed here in this case
2068 2381
                     // TODO: send "Infinite" on invalid timeout strings?
2069 2382
                     $timeout = $options["timeout"];
2070 2383
                 }
2071
-            } else {
2384
+            }
2385
+            else
2386
+            {
2072 2387
                 $timeout = "Infinite";
2073 2388
             }
2074 2389
 
@@ -2106,9 +2421,12 @@  discard block
 block discarded – undo
2106 2421
         $options         = Array();
2107 2422
         $options["path"] = $this->path;
2108 2423
 
2109
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
2424
+        if (isset($this->_SERVER['HTTP_DEPTH']))
2425
+        {
2110 2426
             $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2111
-        } else {
2427
+        }
2428
+        else
2429
+        {
2112 2430
             $options["depth"] = "infinity";
2113 2431
         }
2114 2432
 
@@ -2137,9 +2455,12 @@  discard block
 block discarded – undo
2137 2455
         $options['path'] = $this->path;
2138 2456
         $options['errors'] = array();
2139 2457
 
2140
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
2458
+        if (isset($this->_SERVER['HTTP_DEPTH']))
2459
+        {
2141 2460
             $options['depth'] = $this->_SERVER['HTTP_DEPTH'];
2142
-        } else {
2461
+        }
2462
+        else
2463
+        {
2143 2464
             $options['depth'] = 'infinity';
2144 2465
         }
2145 2466
 
@@ -2150,18 +2471,26 @@  discard block
 block discarded – undo
2150 2471
 		$this->http_status($status);
2151 2472
 		$content = '';
2152 2473
 
2153
-        if (is_array($options['errors']) && count($options['errors'])) {
2474
+        if (is_array($options['errors']) && count($options['errors']))
2475
+        {
2154 2476
 	        header('Content-Type: text/xml; charset="utf-8"');
2155 2477
 	        // ... and payload
2156 2478
 	        $content .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2157 2479
 	        $content .= "<D:error xmlns:D=\"DAV:\"> \n";
2158
-	        foreach ($options['errors'] as $violation) {
2480
+	        foreach ($options['errors'] as $violation)
2481
+	        {
2159 2482
 	        	$content .= '<'.($this->crrnd?'':'D:')."$violation/>\n";
2160 2483
 	        }
2161 2484
 	        $content .=  '</'.($this->crrnd?'':'D:')."error>\n";
2162 2485
         }
2163
-        if (!self::use_compression()) header("Content-Length: ".self::bytes($content));
2164
-        if ($content) echo $options['content'];
2486
+        if (!self::use_compression())
2487
+        {
2488
+        	header("Content-Length: ".self::bytes($content));
2489
+        }
2490
+        if ($content)
2491
+        {
2492
+        	echo $options['content'];
2493
+        }
2165 2494
     }
2166 2495
 
2167 2496
     // }}}
@@ -2175,9 +2504,12 @@  discard block
 block discarded – undo
2175 2504
         $options         = Array();
2176 2505
         $options["path"] = $this->path;
2177 2506
 
2178
-        if (isset($this->_SERVER["HTTP_DEPTH"])) {
2507
+        if (isset($this->_SERVER["HTTP_DEPTH"]))
2508
+        {
2179 2509
             $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2180
-        } else {
2510
+        }
2511
+        else
2512
+        {
2181 2513
             $options["depth"] = "infinity";
2182 2514
         }
2183 2515
 
@@ -2186,33 +2518,45 @@  discard block
 block discarded – undo
2186 2518
         $url  = parse_url($this->_SERVER["HTTP_DESTINATION"]);
2187 2519
         $path = urldecode($url["path"]);
2188 2520
 
2189
-        if (isset($url["host"])) {
2521
+        if (isset($url["host"]))
2522
+        {
2190 2523
             // TODO check url scheme, too
2191 2524
             $http_host = $url["host"];
2192 2525
             if (isset($url["port"]) && $url["port"] != 80)
2193
-                $http_host.= ":".$url["port"];
2194
-        } else {
2526
+            {
2527
+                            $http_host.= ":".$url["port"];
2528
+            }
2529
+        }
2530
+        else
2531
+        {
2195 2532
             // only path given, set host to self
2196 2533
             $http_host = $http_header_host;
2197 2534
         }
2198 2535
 
2199 2536
         if ($http_host == $http_header_host &&
2200 2537
             !strncmp($this->_SERVER["SCRIPT_NAME"], $path,
2201
-                     strlen($this->_SERVER["SCRIPT_NAME"]))) {
2538
+                     strlen($this->_SERVER["SCRIPT_NAME"])))
2539
+        {
2202 2540
             $options["dest"] = substr($path, strlen($this->_SERVER["SCRIPT_NAME"]));
2203
-            if (!$this->_check_lock_status($options["dest"])) {
2541
+            if (!$this->_check_lock_status($options["dest"]))
2542
+            {
2204 2543
                 $this->http_status("423 Locked");
2205 2544
                 return;
2206 2545
             }
2207 2546
 
2208
-        } else {
2547
+        }
2548
+        else
2549
+        {
2209 2550
             $options["dest_url"] = $this->_SERVER["HTTP_DESTINATION"];
2210 2551
         }
2211 2552
 
2212 2553
         // see RFC 2518 Sections 9.6, 8.8.4 and 8.9.3
2213
-        if (isset($this->_SERVER["HTTP_OVERWRITE"])) {
2554
+        if (isset($this->_SERVER["HTTP_OVERWRITE"]))
2555
+        {
2214 2556
             $options["overwrite"] = $this->_SERVER["HTTP_OVERWRITE"] == "T";
2215
-        } else {
2557
+        }
2558
+        else
2559
+        {
2216 2560
             $options["overwrite"] = true;
2217 2561
         }
2218 2562
 
@@ -2238,10 +2582,13 @@  discard block
 block discarded – undo
2238 2582
         // all other METHODS need both a http_method() wrapper
2239 2583
         // and a method() implementation
2240 2584
         // the base class supplies wrappers only
2241
-        foreach (get_class_methods($this) as $method) {
2242
-            if (!strncmp("http_", $method, 5)) {
2585
+        foreach (get_class_methods($this) as $method)
2586
+        {
2587
+            if (!strncmp("http_", $method, 5))
2588
+            {
2243 2589
                 $method = strtoupper(substr($method, 5));
2244
-                if (method_exists($this, $method)) {
2590
+                if (method_exists($this, $method))
2591
+                {
2245 2592
                     $allow[$method] = $method;
2246 2593
                 }
2247 2594
             }
@@ -2249,10 +2596,13 @@  discard block
 block discarded – undo
2249 2596
 
2250 2597
         // we can emulate a missing HEAD implemetation using GET
2251 2598
         if (isset($allow["GET"]))
2252
-            $allow["HEAD"] = "HEAD";
2599
+        {
2600
+                    $allow["HEAD"] = "HEAD";
2601
+        }
2253 2602
 
2254 2603
         // no LOCK without checklok()
2255
-        if (!method_exists($this, "checklock")) {
2604
+        if (!method_exists($this, "checklock"))
2605
+        {
2256 2606
             unset($allow["LOCK"]);
2257 2607
             unset($allow["UNLOCK"]);
2258 2608
         }
@@ -2274,7 +2624,8 @@  discard block
 block discarded – undo
2274 2624
     public static function mkprop()
2275 2625
     {
2276 2626
 	    $args = func_get_args();
2277
-	    switch (count($args)) {
2627
+	    switch (count($args))
2628
+	    {
2278 2629
 		    case 4:
2279 2630
 			    return array('ns'   => $args[0],
2280 2631
 				    'name' => $args[1],
@@ -2301,17 +2652,22 @@  discard block
 block discarded – undo
2301 2652
      */
2302 2653
     function _check_auth()
2303 2654
     {
2304
-        if (method_exists($this, "checkAuth")) {
2655
+        if (method_exists($this, "checkAuth"))
2656
+        {
2305 2657
             // PEAR style method name
2306 2658
             return $this->checkAuth(@$this->_SERVER["AUTH_TYPE"],
2307 2659
                                     @$this->_SERVER["PHP_AUTH_USER"],
2308 2660
                                     @$this->_SERVER["PHP_AUTH_PW"]);
2309
-        } else if (method_exists($this, "check_auth")) {
2661
+        }
2662
+        else if (method_exists($this, "check_auth"))
2663
+        {
2310 2664
             // old (pre 1.0) method name
2311 2665
             return $this->check_auth(@$this->_SERVER["AUTH_TYPE"],
2312 2666
                                      @$this->_SERVER["PHP_AUTH_USER"],
2313 2667
                                      @$this->_SERVER["PHP_AUTH_PW"]);
2314
-        } else {
2668
+        }
2669
+        else
2670
+        {
2315 2671
             // no method found -> no authentication required
2316 2672
             return true;
2317 2673
         }
@@ -2330,7 +2686,8 @@  discard block
 block discarded – undo
2330 2686
     public static function _new_uuid()
2331 2687
     {
2332 2688
         // use uuid extension from PECL if available
2333
-        if (function_exists("uuid_create")) {
2689
+        if (function_exists("uuid_create"))
2690
+        {
2334 2691
             return uuid_create();
2335 2692
         }
2336 2693
 
@@ -2376,12 +2733,14 @@  discard block
 block discarded – undo
2376 2733
     function _if_header_lexer($string, &$pos)
2377 2734
     {
2378 2735
         // skip whitespace
2379
-        while (ctype_space($string{$pos})) {
2736
+        while (ctype_space($string{$pos}))
2737
+        {
2380 2738
             ++$pos;
2381 2739
         }
2382 2740
 
2383 2741
         // already at end of string?
2384
-        if (strlen($string) <= $pos) {
2742
+        if (strlen($string) <= $pos)
2743
+        {
2385 2744
             return false;
2386 2745
         }
2387 2746
 
@@ -2389,7 +2748,8 @@  discard block
 block discarded – undo
2389 2748
         $c = $string{$pos++};
2390 2749
 
2391 2750
         // now it depends on what we found
2392
-        switch ($c) {
2751
+        switch ($c)
2752
+        {
2393 2753
         case "<":
2394 2754
             // URIs are enclosed in <...>
2395 2755
             $pos2 = strpos($string, ">", $pos);
@@ -2399,10 +2759,13 @@  discard block
 block discarded – undo
2399 2759
 
2400 2760
         case "[":
2401 2761
             //Etags are enclosed in [...]
2402
-            if ($string{$pos} == "W") {
2762
+            if ($string{$pos} == "W")
2763
+            {
2403 2764
                 $type = "ETAG_WEAK";
2404 2765
                 $pos += 2;
2405
-            } else {
2766
+            }
2767
+            else
2768
+            {
2406 2769
                 $type = "ETAG_STRONG";
2407 2770
             }
2408 2771
             $pos2 = strpos($string, "]", $pos);
@@ -2434,35 +2797,44 @@  discard block
 block discarded – undo
2434 2797
         $uris = array();
2435 2798
 
2436 2799
         // parser loop
2437
-        while ($pos < $len) {
2800
+        while ($pos < $len)
2801
+        {
2438 2802
             // get next token
2439 2803
             $token = $this->_if_header_lexer($str, $pos);
2440 2804
 
2441 2805
             // check for URI
2442
-            if ($token[0] == "URI") {
2806
+            if ($token[0] == "URI")
2807
+            {
2443 2808
                 $uri   = $token[1]; // remember URI
2444 2809
                 $token = $this->_if_header_lexer($str, $pos); // get next token
2445
-            } else {
2810
+            }
2811
+            else
2812
+            {
2446 2813
                 $uri = "";
2447 2814
             }
2448 2815
 
2449 2816
             // sanity check
2450
-            if ($token[0] != "CHAR" || $token[1] != "(") {
2817
+            if ($token[0] != "CHAR" || $token[1] != "(")
2818
+            {
2451 2819
                 return false;
2452 2820
             }
2453 2821
 
2454 2822
             $list  = array();
2455 2823
             $level = 1;
2456 2824
             $not   = "";
2457
-            while ($level) {
2825
+            while ($level)
2826
+            {
2458 2827
                 $token = $this->_if_header_lexer($str, $pos);
2459
-                if ($token[0] == "NOT") {
2828
+                if ($token[0] == "NOT")
2829
+                {
2460 2830
                     $not = "!";
2461 2831
                     continue;
2462 2832
                 }
2463
-                switch ($token[0]) {
2833
+                switch ($token[0])
2834
+                {
2464 2835
                 case "CHAR":
2465
-                    switch ($token[1]) {
2836
+                    switch ($token[1])
2837
+                    {
2466 2838
                     case "(":
2467 2839
                         $level++;
2468 2840
                         break;
@@ -2492,9 +2864,12 @@  discard block
 block discarded – undo
2492 2864
                 $not = "";
2493 2865
             }
2494 2866
 
2495
-            if (@is_array($uris[$uri])) {
2867
+            if (@is_array($uris[$uri]))
2868
+            {
2496 2869
                 $uris[$uri] = array_merge($uris[$uri], $list);
2497
-            } else {
2870
+            }
2871
+            else
2872
+            {
2498 2873
                 $uris[$uri] = $list;
2499 2874
             }
2500 2875
         }
@@ -2513,27 +2888,34 @@  discard block
 block discarded – undo
2513 2888
      */
2514 2889
     function _check_if_header_conditions()
2515 2890
     {
2516
-        if (isset($this->_SERVER["HTTP_IF"])) {
2891
+        if (isset($this->_SERVER["HTTP_IF"]))
2892
+        {
2517 2893
             $this->_if_header_uris =
2518 2894
                 $this->_if_header_parser($this->_SERVER["HTTP_IF"]);
2519 2895
 
2520
-            foreach ($this->_if_header_uris as $uri => $conditions) {
2521
-                if ($uri == "") {
2896
+            foreach ($this->_if_header_uris as $uri => $conditions)
2897
+            {
2898
+                if ($uri == "")
2899
+                {
2522 2900
                     $uri = $this->uri;
2523 2901
                 }
2524 2902
                 // all must match
2525 2903
                 $state = true;
2526
-                foreach ($conditions as $condition) {
2904
+                foreach ($conditions as $condition)
2905
+                {
2527 2906
                     // lock tokens may be free form (RFC2518 6.3)
2528 2907
                     // but if opaquelocktokens are used (RFC2518 6.4)
2529 2908
                     // we have to check the format (litmus tests this)
2530
-                    if (!strncmp($condition, "<opaquelocktoken:", strlen("<opaquelocktoken"))) {
2531
-                        if (!preg_match('/^<opaquelocktoken:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}>$/', $condition)) {
2909
+                    if (!strncmp($condition, "<opaquelocktoken:", strlen("<opaquelocktoken")))
2910
+                    {
2911
+                        if (!preg_match('/^<opaquelocktoken:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}>$/', $condition))
2912
+                        {
2532 2913
                             $this->http_status("423 Locked");
2533 2914
                             return false;
2534 2915
                         }
2535 2916
                     }
2536
-                    if (!$this->_check_uri_condition($uri, $condition)) {
2917
+                    if (!$this->_check_uri_condition($uri, $condition))
2918
+                    {
2537 2919
                         $this->http_status("412 Precondition failed");
2538 2920
                         $state = false;
2539 2921
                         break;
@@ -2541,7 +2923,8 @@  discard block
 block discarded – undo
2541 2923
                 }
2542 2924
 
2543 2925
                 // any match is ok
2544
-                if ($state == true) {
2926
+                if ($state == true)
2927
+                {
2545 2928
                     return true;
2546 2929
                 }
2547 2930
             }
@@ -2568,7 +2951,8 @@  discard block
 block discarded – undo
2568 2951
 
2569 2952
         // a lock token can never be from the DAV: scheme
2570 2953
         // litmus uses DAV:no-lock in some tests
2571
-        if (!strncmp("<DAV:", $condition, 5)) {
2954
+        if (!strncmp("<DAV:", $condition, 5))
2955
+        {
2572 2956
             return false;
2573 2957
         }
2574 2958
 
@@ -2585,16 +2969,21 @@  discard block
 block discarded – undo
2585 2969
     function _check_lock_status($path, $exclusive_only = false)
2586 2970
     {
2587 2971
         // FIXME depth -> ignored for now
2588
-        if (method_exists($this, "checkLock")) {
2972
+        if (method_exists($this, "checkLock"))
2973
+        {
2589 2974
             // is locked?
2590 2975
             $lock = $this->checkLock($path);
2591 2976
 
2592 2977
             // ... and lock is not owned?
2593
-            if (is_array($lock) && count($lock)) {
2978
+            if (is_array($lock) && count($lock))
2979
+            {
2594 2980
                 // FIXME doesn't check uri restrictions yet
2595
-                if (!isset($this->_SERVER["HTTP_IF"]) || !strstr($this->_SERVER["HTTP_IF"], $lock["token"])) {
2981
+                if (!isset($this->_SERVER["HTTP_IF"]) || !strstr($this->_SERVER["HTTP_IF"], $lock["token"]))
2982
+                {
2596 2983
                     if (!$exclusive_only || ($lock["scope"] !== "shared"))
2597
-                        return false;
2984
+                    {
2985
+                                            return false;
2986
+                    }
2598 2987
                 }
2599 2988
             }
2600 2989
         }
@@ -2614,7 +3003,8 @@  discard block
 block discarded – undo
2614 3003
     function lockdiscovery($path)
2615 3004
     {
2616 3005
         // no lock support without checklock() method
2617
-        if (!method_exists($this, "checklock")) {
3006
+        if (!method_exists($this, "checklock"))
3007
+        {
2618 3008
             return "";
2619 3009
         }
2620 3010
 
@@ -2625,13 +3015,19 @@  discard block
 block discarded – undo
2625 3015
         $lock = $this->checklock($path);
2626 3016
 
2627 3017
         // generate <activelock> block for returned data
2628
-        if (is_array($lock) && count($lock)) {
3018
+        if (is_array($lock) && count($lock))
3019
+        {
2629 3020
             // check for 'timeout' or 'expires'
2630
-            if (!empty($lock["expires"])) {
3021
+            if (!empty($lock["expires"]))
3022
+            {
2631 3023
                 $timeout = "Second-".($lock["expires"] - time());
2632
-            } else if (!empty($lock["timeout"])) {
3024
+            }
3025
+            else if (!empty($lock["timeout"]))
3026
+            {
2633 3027
                 $timeout = "Second-$lock[timeout]";
2634
-            } else {
3028
+            }
3029
+            else
3030
+            {
2635 3031
                 $timeout = "Infinite";
2636 3032
             }
2637 3033
 
@@ -2678,7 +3074,8 @@  discard block
 block discarded – undo
2678 3074
     function http_status($status)
2679 3075
     {
2680 3076
         // simplified success case
2681
-        if ($status === true) {
3077
+        if ($status === true)
3078
+        {
2682 3079
             $status = "200 OK";
2683 3080
         }
2684 3081
 
@@ -2763,18 +3160,24 @@  discard block
 block discarded – undo
2763 3160
      * @return string
2764 3161
      */
2765 3162
 	function _hierarchical_prop_encode(array $props, $ns, &$ns_defs, array &$ns_hash)
2766
-    {
3163
+	{
2767 3164
     	$ret = '';
2768 3165
 
2769 3166
     	//error_log(__METHOD__.'('.array2string($props).')');
2770
-    	if (isset($props['name'])) $props = array($props);
3167
+    	if (isset($props['name']))
3168
+    	{
3169
+    		$props = array($props);
3170
+    	}
2771 3171
 
2772 3172
     	foreach($props as $prop)
2773
-		{
2774
-	    	if (!isset($ns_hash[$prop['ns']])) // unknown namespace
3173
+    	{
3174
+	    	if (!isset($ns_hash[$prop['ns']]))
3175
+	    	{
3176
+	    		// unknown namespace
2775 3177
 	    	{
2776 3178
 		    	// register namespace
2777 3179
 		    	$ns_name = 'ns'.(count($ns_hash) + 1);
3180
+	    	}
2778 3181
 		    	$ns_hash[$prop['ns']] = $ns_name;
2779 3182
 		    	$ns_defs .= ' xmlns:'.$ns_name.'="'.$prop['ns'].'"';
2780 3183
 	    	}
@@ -2792,7 +3195,7 @@  discard block
 block discarded – undo
2792 3195
 			    	$vals = '';
2793 3196
 
2794 3197
 			    	foreach($subprop as $attr => $val)
2795
-					{
3198
+			    	{
2796 3199
 				    	$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES, 'utf-8').'"';
2797 3200
 					}
2798 3201
 
@@ -2809,9 +3212,11 @@  discard block
 block discarded – undo
2809 3212
 		    	else
2810 3213
 		    	{
2811 3214
 			    	if(isset($prop['raw']))
2812
-					{
3215
+			    	{
2813 3216
 						$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
2814
-					} else {
3217
+					}
3218
+					else
3219
+					{
2815 3220
 						$val = $this->_prop_encode(htmlspecialchars($prop['val'], ENT_NOQUOTES, 'utf-8'));
2816 3221
 						// for href properties we need (minimalistic) urlencoding, eg. space
2817 3222
 						if ($prop['name'] == 'href')
@@ -2842,7 +3247,8 @@  discard block
 block discarded – undo
2842 3247
 		//error_log( __METHOD__."\n" .print_r($text,true));
2843 3248
 		//error_log("prop-encode:" . print_r($this->_prop_encoding,true));
2844 3249
 
2845
-		switch (strtolower($this->_prop_encoding)) {
3250
+		switch (strtolower($this->_prop_encoding))
3251
+		{
2846 3252
 			case "utf-8":
2847 3253
        			//error_log( __METHOD__."allready encoded\n" .print_r($text,true));
2848 3254
 				return $text;
@@ -2864,7 +3270,8 @@  discard block
 block discarded – undo
2864 3270
     public static function _slashify($path)
2865 3271
     {
2866 3272
 		//error_log(__METHOD__." called with $path");
2867
-		if ($path[self::bytes($path)-1] != '/') {
3273
+		if ($path[self::bytes($path)-1] != '/')
3274
+		{
2868 3275
 			//error_log(__METHOD__." added slash at the end of path");
2869 3276
 			$path = $path."/";
2870 3277
 		}
@@ -2880,7 +3287,8 @@  discard block
 block discarded – undo
2880 3287
     public static function _unslashify($path)
2881 3288
     {
2882 3289
         //error_log(__METHOD__." called with $path");
2883
-        if ($path[self::bytes($path)-1] == '/') {
3290
+        if ($path[self::bytes($path)-1] == '/')
3291
+        {
2884 3292
             $path = substr($path, 0, -1);
2885 3293
 			//error_log(__METHOD__." removed slash at the end of path");
2886 3294
         }
@@ -2898,9 +3306,12 @@  discard block
 block discarded – undo
2898 3306
     {
2899 3307
         //error_log("merge called :\n$parent \n$child\n" . function_backtrace());
2900 3308
         //error_log("merge :\n".print_r($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)true));
2901
-        if ($child{0} == '/') {
3309
+        if ($child{0} == '/')
3310
+        {
2902 3311
             return self::_unslashify($parent).$child;
2903
-        } else {
3312
+        }
3313
+        else
3314
+        {
2904 3315
             return self::_slashify($parent).$child;
2905 3316
         }
2906 3317
     }
Please login to merge, or discard this patch.