Completed
Push — master ( aa44e9...fa84e5 )
by Ralf
90:14 queued 73:21
created
api/src/Vfs/Links/StreamWrapper.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -316,7 +316,7 @@
 block discarded – undo
316 316
 	 *
317 317
 	 * @param string $url URL that was passed to opendir() and that this object is expected to explore.
318 318
 	 * @param $options
319
-	 * @return booelan
319
+	 * @return boolean
320 320
 	 */
321 321
 	function dir_opendir ( $url, $options )
322 322
 	{
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -76,34 +76,34 @@  discard block
 block discarded – undo
76 76
 	 * @param int $check mode to check: one or more or'ed together of: 4 = read, 2 = write, 1 = executable
77 77
 	 * @return boolean
78 78
 	 */
79
-	static function check_extended_acl($url,$check)
79
+	static function check_extended_acl($url, $check)
80 80
 	{
81 81
 		if (Vfs::$is_root)
82 82
 		{
83 83
 			return true;
84 84
 		}
85
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
85
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
86 86
 
87
-		list(,$apps,$app,$id,$rel_path) = explode('/',$path,5);
87
+		list(,$apps, $app, $id, $rel_path) = explode('/', $path, 5);
88 88
 
89 89
 		if ($apps != 'apps')
90 90
 		{
91
-			$access = false;							// no access to anything, but /apps
91
+			$access = false; // no access to anything, but /apps
92 92
 			$what = '!= apps';
93 93
 		}
94 94
 		elseif (!$app)
95 95
 		{
96
-			$access = !($check & Vfs::WRITABLE);	// always grant read access to /apps
96
+			$access = !($check&Vfs::WRITABLE); // always grant read access to /apps
97 97
 			$what = '!$app';
98 98
 		}
99
-		elseif(!isset($GLOBALS['egw_info']['user']['apps'][$app]))
99
+		elseif (!isset($GLOBALS['egw_info']['user']['apps'][$app]))
100 100
 		{
101
-			$access = false;							// user has no access to the $app application
101
+			$access = false; // user has no access to the $app application
102 102
 			$what = 'no app-rights';
103 103
 		}
104 104
 		elseif (!$id)
105 105
 		{
106
-			$access = true;								// grant read&write access to /apps/$app
106
+			$access = true; // grant read&write access to /apps/$app
107 107
 			$what = 'app dir';
108 108
 		}
109 109
 		// allow applications to implement their own access control to the file storage
@@ -112,11 +112,11 @@  discard block
 block discarded – undo
112 112
 		else
113 113
 		{
114 114
 			// vfs & stream-wrapper use posix rights, Api\Link::file_access uses Api\Acl::{EDIT|READ}!
115
-			$required = $check & Vfs::WRITABLE ? Api\Acl::EDIT : Api\Acl::READ;
116
-			$access = Api\Link::file_access($app,$id,$required,$rel_path,Vfs::$user);
115
+			$required = $check&Vfs::WRITABLE ? Api\Acl::EDIT : Api\Acl::READ;
116
+			$access = Api\Link::file_access($app, $id, $required, $rel_path, Vfs::$user);
117 117
 			$what = "from Api\Link::file_access('$app',$id,$required,'$rel_path,".Vfs::$user.")";
118 118
 		}
119
-		if (self::DEBUG) error_log(__METHOD__."($url,$check) user=".Vfs::$user." ($what) ".($access?"access granted ($app:$id:$rel_path)":'no access!!!'));
119
+		if (self::DEBUG) error_log(__METHOD__."($url,$check) user=".Vfs::$user." ($what) ".($access ? "access granted ($app:$id:$rel_path)" : 'no access!!!'));
120 120
 		return $access;
121 121
 	}
122 122
 
@@ -137,19 +137,19 @@  discard block
 block discarded – undo
137 137
 	 *                          stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper!
138 138
 	 * @return array
139 139
 	 */
140
-	static function url_stat ( $url, $flags )
140
+	static function url_stat($url, $flags)
141 141
 	{
142
-		$eacl_check=self::check_extended_acl($url,Vfs::READABLE);
142
+		$eacl_check = self::check_extended_acl($url, Vfs::READABLE);
143 143
 
144 144
 		// return vCard as /.entry
145
-		if ( $eacl_check && substr($url,-7) == '/.entry' &&
146
-			(list($app) = array_slice(explode('/',$url),-3,1)) && $app === 'addressbook')
145
+		if ($eacl_check && substr($url, -7) == '/.entry' &&
146
+			(list($app) = array_slice(explode('/', $url), -3, 1)) && $app === 'addressbook')
147 147
 		{
148 148
 			$ret = array(
149 149
 				'ino'   => md5($url),
150 150
 				'name'  => '.entry',
151
-				'mode'  => self::MODE_FILE|Vfs::READABLE,	// required by the stream wrapper
152
-				'size'  => 1024,	// fmail does NOT attach files with size 0!
151
+				'mode'  => self::MODE_FILE|Vfs::READABLE, // required by the stream wrapper
152
+				'size'  => 1024, // fmail does NOT attach files with size 0!
153 153
 				'uid'   => 0,
154 154
 				'gid'   => 0,
155 155
 				'mtime' => time(),
@@ -160,15 +160,15 @@  discard block
 block discarded – undo
160 160
 			);
161 161
 		}
162 162
 		// if entry directory does not exist --> return fake directory
163
-		elseif (!($ret = parent::url_stat($url,$flags,$eacl_check)) && $eacl_check)
163
+		elseif (!($ret = parent::url_stat($url, $flags, $eacl_check)) && $eacl_check)
164 164
 		{
165
-			list(,/*$apps*/,/*$app*/,$id,$rel_path) = explode('/', Vfs::parse_url($url, PHP_URL_PATH), 5);
165
+			list(,/*$apps*/, /*$app*/, $id, $rel_path) = explode('/', Vfs::parse_url($url, PHP_URL_PATH), 5);
166 166
 			if ($id && !isset($rel_path))
167 167
 			{
168 168
 				$ret = array(
169 169
 					'ino'   => md5($url),
170 170
 					'name'  => $id,
171
-					'mode'  => self::MODE_DIR,	// required by the stream wrapper
171
+					'mode'  => self::MODE_DIR, // required by the stream wrapper
172 172
 					'size'  => 0,
173 173
 					'uid'   => 0,
174 174
 					'gid'   => 0,
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 	 * @param int $fs_id =null fs_id to use, to not query it again (eg. because it's already deleted)
196 196
 	 * @return boolean true if acl is set/deleted, false on error
197 197
 	 */
198
-	static function eacl($path,$rights=null,$owner=null,$fs_id=null)
198
+	static function eacl($path, $rights = null, $owner = null, $fs_id = null)
199 199
 	{
200
-		unset($path, $rights, $owner, $fs_id);	// not used, but required by function signature
200
+		unset($path, $rights, $owner, $fs_id); // not used, but required by function signature
201 201
 
202 202
 		return false;
203 203
 	}
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	static function get_eacl($path)
214 214
 	{
215
-		unset($path);	// not used, but required by function signature
215
+		unset($path); // not used, but required by function signature
216 216
 
217 217
 		return false;
218 218
 	}
@@ -232,25 +232,25 @@  discard block
 block discarded – undo
232 232
 	 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE, we allways use recursive!
233 233
 	 * @return boolean TRUE on success or FALSE on failure
234 234
 	 */
235
-	static function mkdir($path,$mode,$options)
235
+	static function mkdir($path, $mode, $options)
236 236
 	{
237
-		unset($mode);	// not used, but required by function signature
237
+		unset($mode); // not used, but required by function signature
238 238
 
239
-		if($path[0] != '/')
239
+		if ($path[0] != '/')
240 240
 		{
241
-			if (strpos($path,'?') !== false) $query = Vfs::parse_url($path,PHP_URL_QUERY);
242
-			$path = Vfs::parse_url($path,PHP_URL_PATH).($query ? '?'.$query : '');
241
+			if (strpos($path, '?') !== false) $query = Vfs::parse_url($path, PHP_URL_QUERY);
242
+			$path = Vfs::parse_url($path, PHP_URL_PATH).($query ? '?'.$query : '');
243 243
 		}
244
-		list(,$apps,$app,$id) = explode('/',$path);
244
+		list(,$apps, $app, $id) = explode('/', $path);
245 245
 
246 246
 		$ret = false;
247
-		if ($apps == 'apps' && $app && !$id || self::check_extended_acl($path,Vfs::WRITABLE))	// app directory itself is allways ok
247
+		if ($apps == 'apps' && $app && !$id || self::check_extended_acl($path, Vfs::WRITABLE))	// app directory itself is allways ok
248 248
 		{
249 249
 			$current_is_root = Vfs::$is_root; Vfs::$is_root = true;
250 250
 			$current_user = Vfs::$user; Vfs::$user = 0;
251 251
 
252
-			$ret = parent::mkdir($path,0,$options|STREAM_MKDIR_RECURSIVE);
253
-			if ($id) parent::chmod($path,0);	// no other rights
252
+			$ret = parent::mkdir($path, 0, $options|STREAM_MKDIR_RECURSIVE);
253
+			if ($id) parent::chmod($path, 0); // no other rights
254 254
 
255 255
 			Vfs::$user = $current_user;
256 256
 			Vfs::$is_root = $current_is_root;
@@ -274,23 +274,23 @@  discard block
 block discarded – undo
274 274
 	 * @param string $opened_path full path of the file/resource, if the open was successfull and STREAM_USE_PATH was set
275 275
 	 * @return boolean true if the ressource was opened successful, otherwise false
276 276
 	 */
277
-	function stream_open ( $url, $mode, $options, &$opened_path )
277
+	function stream_open($url, $mode, $options, &$opened_path)
278 278
 	{
279 279
 		// the following call is necessary to fill sqlfs_stream_wrapper::$stat_cache, WITH the extendes ACL!
280
-		$stat = self::url_stat($url,0);
280
+		$stat = self::url_stat($url, 0);
281 281
 		//error_log(__METHOD__."('$url', '$mode', $options) stat=".array2string($stat));
282 282
 
283 283
 		// return vCard as /.entry
284
-		if ($stat && $mode[0] == 'r' && substr($url,-7) === '/.entry' &&
285
-			(list($app) = array_slice(explode('/',$url),-3,1)) && $app === 'addressbook')
284
+		if ($stat && $mode[0] == 'r' && substr($url, -7) === '/.entry' &&
285
+			(list($app) = array_slice(explode('/', $url), -3, 1)) && $app === 'addressbook')
286 286
 		{
287
-			list($id) = array_slice(explode('/',$url),-2,1);
288
-			$ab_vcard = new addressbook_vcal('addressbook','text/vcard');
287
+			list($id) = array_slice(explode('/', $url), -2, 1);
288
+			$ab_vcard = new addressbook_vcal('addressbook', 'text/vcard');
289 289
 			if (!($charset = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset']))
290 290
 			{
291 291
 				$charset = 'utf-8';
292 292
 			}
293
-			if (!($vcard =& $ab_vcard->getVCard($id, $charset)))
293
+			if (!($vcard = & $ab_vcard->getVCard($id, $charset)))
294 294
 			{
295 295
 				error_log(__METHOD__."('$url', '$mode', $options) addressbook_vcal::getVCard($id) returned false!");
296 296
 				return false;
@@ -302,11 +302,11 @@  discard block
 block discarded – undo
302 302
 			return true;
303 303
 		}
304 304
 		// create not existing entry directories on the fly
305
-		if ($mode[0] != 'r' && !parent::url_stat($dir = Vfs::dirname($url),0) && self::check_extended_acl($dir,Vfs::WRITABLE))
305
+		if ($mode[0] != 'r' && !parent::url_stat($dir = Vfs::dirname($url), 0) && self::check_extended_acl($dir, Vfs::WRITABLE))
306 306
 		{
307
-			self::mkdir($dir,0,STREAM_MKDIR_RECURSIVE);
307
+			self::mkdir($dir, 0, STREAM_MKDIR_RECURSIVE);
308 308
 		}
309
-		return parent::stream_open($url,$mode,$options,$opened_path);
309
+		return parent::stream_open($url, $mode, $options, $opened_path);
310 310
 	}
311 311
 
312 312
 	/**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 	 * @param $options
319 319
 	 * @return booelan
320 320
 	 */
321
-	function dir_opendir ( $url, $options )
321
+	function dir_opendir($url, $options)
322 322
 	{
323 323
 		if (!parent::url_stat($url, STREAM_URL_STAT_QUIET) && self::url_stat($url, STREAM_URL_STAT_QUIET))
324 324
 		{
Please login to merge, or discard this patch.
Braces   +26 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,7 +26,9 @@  discard block
 block discarded – undo
26 26
  */
27 27
 if (!class_exists('EGroupware\\Api\\Vfs\\Links\\LinksParent', false))
28 28
 {
29
-	class LinksParent extends Vfs\Sqlfs\StreamWrapper {}
29
+	class LinksParent extends Vfs\Sqlfs\StreamWrapper
30
+	{
31
+}
30 32
 }
31 33
 
32 34
 /**
@@ -116,7 +118,10 @@  discard block
 block discarded – undo
116 118
 			$access = Api\Link::file_access($app,$id,$required,$rel_path,Vfs::$user);
117 119
 			$what = "from Api\Link::file_access('$app',$id,$required,'$rel_path,".Vfs::$user.")";
118 120
 		}
119
-		if (self::DEBUG) error_log(__METHOD__."($url,$check) user=".Vfs::$user." ($what) ".($access?"access granted ($app:$id:$rel_path)":'no access!!!'));
121
+		if (self::DEBUG)
122
+		{
123
+			error_log(__METHOD__."($url,$check) user=".Vfs::$user." ($what) ".($access?"access granted ($app:$id:$rel_path)":'no access!!!'));
124
+		}
120 125
 		return $access;
121 126
 	}
122 127
 
@@ -180,7 +185,10 @@  discard block
 block discarded – undo
180 185
 				);
181 186
 			}
182 187
 		}
183
-		if (self::DEBUG) error_log(__METHOD__."('$url', $flags) calling parent::url_stat(,,".array2string($eacl_check).') returning '.array2string($ret));
188
+		if (self::DEBUG)
189
+		{
190
+			error_log(__METHOD__."('$url', $flags) calling parent::url_stat(,,".array2string($eacl_check).') returning '.array2string($ret));
191
+		}
184 192
 		return $ret;
185 193
 	}
186 194
 
@@ -238,19 +246,30 @@  discard block
 block discarded – undo
238 246
 
239 247
 		if($path[0] != '/')
240 248
 		{
241
-			if (strpos($path,'?') !== false) $query = Vfs::parse_url($path,PHP_URL_QUERY);
249
+			if (strpos($path,'?') !== false)
250
+			{
251
+				$query = Vfs::parse_url($path,PHP_URL_QUERY);
252
+			}
242 253
 			$path = Vfs::parse_url($path,PHP_URL_PATH).($query ? '?'.$query : '');
243 254
 		}
244 255
 		list(,$apps,$app,$id) = explode('/',$path);
245 256
 
246 257
 		$ret = false;
247
-		if ($apps == 'apps' && $app && !$id || self::check_extended_acl($path,Vfs::WRITABLE))	// app directory itself is allways ok
258
+		if ($apps == 'apps' && $app && !$id || self::check_extended_acl($path,Vfs::WRITABLE))
259
+		{
260
+			// app directory itself is allways ok
248 261
 		{
249
-			$current_is_root = Vfs::$is_root; Vfs::$is_root = true;
262
+			$current_is_root = Vfs::$is_root;
263
+		}
264
+		Vfs::$is_root = true;
250 265
 			$current_user = Vfs::$user; Vfs::$user = 0;
251 266
 
252 267
 			$ret = parent::mkdir($path,0,$options|STREAM_MKDIR_RECURSIVE);
253
-			if ($id) parent::chmod($path,0);	// no other rights
268
+			if ($id)
269
+			{
270
+				parent::chmod($path,0);
271
+			}
272
+			// no other rights
254 273
 
255 274
 			Vfs::$user = $current_user;
256 275
 			Vfs::$is_root = $current_is_root;
Please login to merge, or discard this patch.
api/src/Vfs/Sharing.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -98,7 +98,6 @@  discard block
 block discarded – undo
98 98
 	/**
99 99
 	 * Protected constructor called via self::create_session
100 100
 	 *
101
-	 * @param string $token
102 101
 	 * @param array $share
103 102
 	 */
104 103
 	protected function __construct(array $share)
@@ -109,6 +108,7 @@  discard block
 block discarded – undo
109 108
 
110 109
 	/**
111 110
 	 * Get token from url
111
+	 * @return string
112 112
 	 */
113 113
 	public static function get_token()
114 114
 	{
Please login to merge, or discard this patch.
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
 	const WRITABLE = 'share_rw';
73 73
 
74 74
  	/**
75
-	 * Modes for sharing files
76
-	 *
77
-	 * @var array
78
-	 */
75
+ 	 * Modes for sharing files
76
+ 	 *
77
+ 	 * @var array
78
+ 	 */
79 79
 	static $modes = array(
80 80
 		self::ATTACH => array(
81 81
 			'label' => 'Attachment',
@@ -112,16 +112,16 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	public static function get_token()
114 114
 	{
115
-        // WebDAV has no concept of a query string and clients (including cadaver)
116
-        // seem to pass '?' unencoded, so we need to extract the path info out
117
-        // of the request URI ourselves
118
-        // if request URI contains a full url, remove schema and domain
115
+		// WebDAV has no concept of a query string and clients (including cadaver)
116
+		// seem to pass '?' unencoded, so we need to extract the path info out
117
+		// of the request URI ourselves
118
+		// if request URI contains a full url, remove schema and domain
119 119
 		$matches = null;
120
-        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$_SERVER['REQUEST_URI'], $matches))
121
-        {
122
-        	$path_info = $matches[1];
123
-        }
124
-        $path_info = substr($path_info, strlen($_SERVER['SCRIPT_NAME']));
120
+		if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$_SERVER['REQUEST_URI'], $matches))
121
+		{
122
+			$path_info = $matches[1];
123
+		}
124
+		$path_info = substr($path_info, strlen($_SERVER['SCRIPT_NAME']));
125 125
 		list(, $token/*, $path*/) = preg_split('|[/?]|', $path_info, 3);
126 126
 
127 127
 		return $token;
Please login to merge, or discard this patch.
Spacing   +26 added lines, -27 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         // of the request URI ourselves
118 118
         // if request URI contains a full url, remove schema and domain
119 119
 		$matches = null;
120
-        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$_SERVER['REQUEST_URI'], $matches))
120
+        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info = $_SERVER['REQUEST_URI'], $matches))
121 121
         {
122 122
         	$path_info = $matches[1];
123 123
         }
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @param boolean $keep_session =null null: create a new session, true: try mounting it into existing (already verified) session
156 156
 	 * @return string with sessionid, does NOT return if no session created
157 157
 	 */
158
-	public static function create_session($keep_session=null)
158
+	public static function create_session($keep_session = null)
159 159
 	{
160 160
 		self::$db = $GLOBALS['egw']->db;
161 161
 
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 		// need to reset fs_tab, as resolve_url does NOT work with just share mounted
209 209
 		if (count($GLOBALS['egw_info']['server']['vfs_fstab']) <= 1)
210 210
 		{
211
-			unset($GLOBALS['egw_info']['server']['vfs_fstab']);	// triggers reset of fstab in mount()
211
+			unset($GLOBALS['egw_info']['server']['vfs_fstab']); // triggers reset of fstab in mount()
212 212
 			$GLOBALS['egw_info']['server']['vfs_fstab'] = Vfs::mount();
213 213
 			Vfs::clearstatcache();
214 214
 		}
215
-		$share['resolve_url'] = Vfs::resolve_url($share['share_path'], true, true, true, true);	// true = fix evtl. contained url parameter
215
+		$share['resolve_url'] = Vfs::resolve_url($share['share_path'], true, true, true, true); // true = fix evtl. contained url parameter
216 216
 		// if share not writable append ro=1 to mount url to make it readonly
217 217
 		if (!self::$db->from_bool($share['share_writable']))
218 218
 		{
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 
258 258
 		// update accessed timestamp
259 259
 		self::$db->update(self::TABLE, array(
260
-			'share_last_accessed' => $share['share_last_accessed']=time(),
260
+			'share_last_accessed' => $share['share_last_accessed'] = time(),
261 261
 		), array(
262 262
 			'share_id' => $share['share_id'],
263 263
 		), __LINE__, __FILE__);
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 		if ($keep_session || $sessionid)
300 300
 		{
301 301
 			$_SESSION[Api\Session::EGW_INFO_CACHE] = $GLOBALS['egw_info'];
302
-			unset($_SESSION[Api\Session::EGW_INFO_CACHE]['flags']);	// dont save the flags, they change on each request
302
+			unset($_SESSION[Api\Session::EGW_INFO_CACHE]['flags']); // dont save the flags, they change on each request
303 303
 
304 304
 			$_SESSION[Api\Session::EGW_OBJECT_CACHE] = serialize($GLOBALS['egw']);
305 305
 		}
@@ -368,8 +368,7 @@  discard block
 block discarded – undo
368 368
 		// generate random token (using oppenssl if available otherwise mt_rand based Api\Auth::randomstring)
369 369
 		do {
370 370
 			$token = function_exists('openssl_random_pseudo_bytes') ?
371
-				base64_encode(openssl_random_pseudo_bytes(3*self::TOKEN_LENGTH/4)) :
372
-				Api\Auth::randomstring(self::TOKEN_LENGTH);
371
+				base64_encode(openssl_random_pseudo_bytes(3 * self::TOKEN_LENGTH / 4)) : Api\Auth::randomstring(self::TOKEN_LENGTH);
373 372
 			// base64 can contain chars not allowed in our vfs-urls eg. / or #
374 373
 		} while ($token != Vfs::encodePathComponent($token));
375 374
 
@@ -389,13 +388,13 @@  discard block
 block discarded – undo
389 388
 	 * @throw Api\Exception\AssertionFailed if user temp. directory does not exist and can not be created
390 389
 	 * @return array with share data, eg. value for key 'share_token'
391 390
 	 */
392
-	public static function create($path, $mode, $name, $recipients, $extra=array())
391
+	public static function create($path, $mode, $name, $recipients, $extra = array())
393 392
 	{
394 393
 		if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
395 394
 
396 395
 		if (empty($name)) $name = $path;
397 396
 
398
-		$path2tmp =& Api\Cache::getSession(__CLASS__, 'path2tmp');
397
+		$path2tmp = & Api\Cache::getSession(__CLASS__, 'path2tmp');
399 398
 
400 399
 		// allow filesystem path only for temp_dir
401 400
 		$temp_dir = $GLOBALS['egw_info']['server']['temp_dir'].'/';
@@ -406,7 +405,7 @@  discard block
 block discarded – undo
406 405
 		}
407 406
 		else
408 407
 		{
409
-			if(parse_url($path, PHP_URL_SCHEME) !== 'vfs')
408
+			if (parse_url($path, PHP_URL_SCHEME) !== 'vfs')
410 409
 			{
411 410
 				$path = 'vfs://default'.($path[0] == '/' ? '' : '/').$path;
412 411
 			}
@@ -420,7 +419,7 @@  discard block
 block discarded – undo
420 419
 		}
421 420
 		// check if file has been shared before, with identical attributes
422 421
 		if (($mode != self::LINK || isset($path2tmp[$path])) &&
423
-			($share = self::$db->select(self::TABLE, '*', $extra+array(
422
+			($share = self::$db->select(self::TABLE, '*', $extra + array(
424 423
 				'share_path' => $mode == 'link' ? $path2tmp[$path] : $vfs_path,
425 424
 				'share_owner' => $GLOBALS['egw_info']['user']['account_id'],
426 425
 				'share_expires' => null,
@@ -431,7 +430,7 @@  discard block
 block discarded – undo
431 430
 			// if yes, just add additional recipients
432 431
 			$share['share_with'] = $share['share_with'] ? explode(',', $share['share_with']) : array();
433 432
 			$need_save = false;
434
-			foreach((array)$recipients as $recipient)
433
+			foreach ((array)$recipients as $recipient)
435 434
 			{
436 435
 				if (!in_array($recipient, $share['share_with']))
437 436
 				{
@@ -461,9 +460,9 @@  discard block
 block discarded – undo
461 460
 				}
462 461
 				$n = 0;
463 462
 				do {
464
-					$tmp_file = Vfs::concat($user_tmp, ($n?$n.'.':'').Vfs::basename($name));
463
+					$tmp_file = Vfs::concat($user_tmp, ($n ? $n.'.' : '').Vfs::basename($name));
465 464
 				}
466
-				while(!(is_dir($path) && Vfs::mkdir($tmp_file, null, STREAM_MKDIR_RECURSIVE) ||
465
+				while (!(is_dir($path) && Vfs::mkdir($tmp_file, null, STREAM_MKDIR_RECURSIVE) ||
467 466
 					!is_dir($path) && (!Vfs::file_exists($tmp_file) && ($fp = Vfs::fopen($tmp_file, 'x')) ||
468 467
 						// do not copy identical files again to users tmp dir, just re-use them
469 468
 						Vfs::file_exists($tmp_file) && Vfs::compare(Vfs::PREFIX.$tmp_file, $path))) && $n++ < 100);
@@ -488,12 +487,12 @@  discard block
 block discarded – undo
488 487
 				$async = new Api\Asyncservice();
489 488
 				if (!$async->read('egw_sharing-tmp-cleanup'))
490 489
 				{
491
-					$async->set_timer(array('day' => 28),'egw_sharing-tmp_cleanup','egw_sharing::tmp_cleanup',null);
490
+					$async->set_timer(array('day' => 28), 'egw_sharing-tmp_cleanup', 'egw_sharing::tmp_cleanup', null);
492 491
 				}
493 492
 			}
494 493
 
495 494
 			$i = 0;
496
-			while(true)	// self::token() can return an existing value
495
+			while (true)	// self::token() can return an existing value
497 496
 			{
498 497
 				try {
499 498
 					self::$db->insert(self::TABLE, $share = array(
@@ -502,12 +501,12 @@  discard block
 block discarded – undo
502 501
 						'share_owner' => $GLOBALS['egw_info']['user']['account_id'],
503 502
 						'share_with' => implode(',', (array)$recipients),
504 503
 						'share_created' => time(),
505
-					)+$extra, false, __LINE__, __FILE__);
504
+					) + $extra, false, __LINE__, __FILE__);
506 505
 
507 506
 					$share['share_id'] = self::$db->get_last_insert_id(self::TABLE, 'share_id');
508 507
 					break;
509 508
 				}
510
-				catch(Api\Db\Exception $e) {
509
+				catch (Api\Db\Exception $e) {
511 510
 					if ($i++ > 3) throw $e;
512 511
 					unset($e);
513 512
 				}
@@ -550,8 +549,8 @@  discard block
 block discarded – undo
550 549
 
551 550
 		// get all temp. files, to be able to delete them
552 551
 		$tmp_paths = array();
553
-		foreach(self::$db->select(self::TABLE, 'share_path', array(
554
-			"share_path LIKE '/home/%/.tmp/%'")+$keys, __LINE__, __FILE__, false) as $row)
552
+		foreach (self::$db->select(self::TABLE, 'share_path', array(
553
+			"share_path LIKE '/home/%/.tmp/%'") + $keys, __LINE__, __FILE__, false) as $row)
555 554
 		{
556 555
 			$tmp_paths[] = $row['share_path'];
557 556
 		}
@@ -563,7 +562,7 @@  discard block
 block discarded – undo
563 562
 		// check if temp. files are used elsewhere
564 563
 		if ($tmp_paths)
565 564
 		{
566
-			foreach(self::$db->select(self::TABLE, 'share_path,COUNT(*) AS cnt', array(
565
+			foreach (self::$db->select(self::TABLE, 'share_path,COUNT(*) AS cnt', array(
567 566
 				'share_path' => $tmp_paths,
568 567
 			), __LINE__, __FILE__, false, 'GROUP BY share_path') as $row)
569 568
 			{
@@ -573,7 +572,7 @@  discard block
 block discarded – undo
573 572
 				}
574 573
 			}
575 574
 			// if not delete them
576
-			foreach($tmp_paths as $path)
575
+			foreach ($tmp_paths as $path)
577 576
 			{
578 577
 				Vfs::remove($path);
579 578
 			}
@@ -607,11 +606,11 @@  discard block
 block discarded – undo
607 606
 			// remove expired tmp-files unconditionally
608 607
 			$having = 'HAVING share_expires < '.self::$db->quote(self::$db->to_timestamp(time())).' OR '.
609 608
 				// remove without expiration date, when created over 100 days ago AND
610
-				'share_expires IS NULL AND share_created < '.self::$db->quote(self::$db->to_timestamp(time()-self::TMP_KEEP)). ' AND '.
609
+				'share_expires IS NULL AND share_created < '.self::$db->quote(self::$db->to_timestamp(time() - self::TMP_KEEP)).' AND '.
611 610
 					// (last accessed over 100 days ago OR never)
612
-					'(share_last_accessed IS NULL OR share_last_accessed < '.self::$db->quote(self::$db->to_timestamp(time()-self::TMP_KEEP)).')';
611
+					'(share_last_accessed IS NULL OR share_last_accessed < '.self::$db->quote(self::$db->to_timestamp(time() - self::TMP_KEEP)).')';
613 612
 
614
-			foreach(self::$db->select(self::TABLE, $cols, array(
613
+			foreach (self::$db->select(self::TABLE, $cols, array(
615 614
 				"share_path LIKE '/home/%/.tmp/%'",
616 615
 			), __LINE__, __FILE__, false, 'GROUP BY share_path '.$having) as $row)
617 616
 			{
@@ -624,7 +623,7 @@  discard block
 block discarded – undo
624 623
 				else
625 624
 				{
626 625
 					$share_ids = array();
627
-					foreach(self::$db->selec(self::TABLE, 'share_id', array(
626
+					foreach (self::$db->selec(self::TABLE, 'share_id', array(
628 627
 						'share_path' => $row['share_path'],
629 628
 					), __LINE__, __FILE__) as $id)
630 629
 					{
Please login to merge, or discard this patch.
Braces   +48 added lines, -12 removed lines patch added patch discarded remove patch
@@ -166,7 +166,10 @@  discard block
 block discarded – undo
166 166
 		if ($token && !$keep_session)
167 167
 		{
168 168
 			$_SERVER['PHP_AUTH_USER'] = $token;
169
-			if (!isset($_SERVER['PHP_AUTH_PW'])) $_SERVER['PHP_AUTH_PW'] = '';
169
+			if (!isset($_SERVER['PHP_AUTH_PW']))
170
+			{
171
+				$_SERVER['PHP_AUTH_PW'] = '';
172
+			}
170 173
 
171 174
 			unset($GLOBALS['egw_info']['flags']['autocreate_session_callback']);
172 175
 			if ($GLOBALS['egw']->session->verify() && isset($GLOBALS['egw']->sharing) &&
@@ -220,9 +223,12 @@  discard block
 block discarded – undo
220 223
 		}
221 224
 		//_debug_array($share);
222 225
 
223
-		if ($keep_session)	// add share to existing session
226
+		if ($keep_session)
227
+		{
228
+			// add share to existing session
224 229
 		{
225 230
 			$share['share_root'] = '/'.$share['share_token'];
231
+		}
226 232
 
227 233
 			// if current user is not the share owner, we cant just mount share
228 234
 			if (Vfs::$user != $share['share_owner'])
@@ -230,12 +236,15 @@  discard block
 block discarded – undo
230 236
 				$keep_session = false;
231 237
 			}
232 238
 		}
233
-		if (!$keep_session)	// do NOT change to else, as we might have set $keep_session=false!
239
+		if (!$keep_session)
240
+		{
241
+			// do NOT change to else, as we might have set $keep_session=false!
234 242
 		{
235 243
 			// only allow filemanager app
236 244
 			$GLOBALS['egw_info']['user']['apps'] = array(
237 245
 				'filemanager' => $GLOBALS['egw_info']['apps']['filemanager']
238 246
 			);
247
+		}
239 248
 
240 249
 			$share['share_root'] = '/';
241 250
 			Vfs::$user = $share['share_owner'];
@@ -391,9 +400,15 @@  discard block
 block discarded – undo
391 400
 	 */
392 401
 	public static function create($path, $mode, $name, $recipients, $extra=array())
393 402
 	{
394
-		if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
403
+		if (!isset(self::$db))
404
+		{
405
+			self::$db = $GLOBALS['egw']->db;
406
+		}
395 407
 
396
-		if (empty($name)) $name = $path;
408
+		if (empty($name))
409
+		{
410
+			$name = $path;
411
+		}
397 412
 
398 413
 		$path2tmp =& Api\Cache::getSession(__CLASS__, 'path2tmp');
399 414
 
@@ -472,7 +487,10 @@  discard block
 block discarded – undo
472 487
 				{
473 488
 					throw new Api\Exception\AssertionFailed("Could NOT create temp. file '$tmp_file'!");
474 489
 				}
475
-				if ($fp) fclose($fp);
490
+				if ($fp)
491
+				{
492
+					fclose($fp);
493
+				}
476 494
 
477 495
 				if (is_dir($path) && !Vfs::copy_files(array($path), $tmp_file) ||
478 496
 					!is_dir($path) && !copy($path, Vfs::PREFIX.$tmp_file))
@@ -493,7 +511,9 @@  discard block
 block discarded – undo
493 511
 			}
494 512
 
495 513
 			$i = 0;
496
-			while(true)	// self::token() can return an existing value
514
+			while(true)
515
+			{
516
+				// self::token() can return an existing value
497 517
 			{
498 518
 				try {
499 519
 					self::$db->insert(self::TABLE, $share = array(
@@ -503,12 +523,16 @@  discard block
 block discarded – undo
503 523
 						'share_with' => implode(',', (array)$recipients),
504 524
 						'share_created' => time(),
505 525
 					)+$extra, false, __LINE__, __FILE__);
526
+			}
506 527
 
507 528
 					$share['share_id'] = self::$db->get_last_insert_id(self::TABLE, 'share_id');
508 529
 					break;
509 530
 				}
510 531
 				catch(Api\Db\Exception $e) {
511
-					if ($i++ > 3) throw $e;
532
+					if ($i++ > 3)
533
+					{
534
+						throw $e;
535
+					}
512 536
 					unset($e);
513 537
 				}
514 538
 			}
@@ -546,7 +570,10 @@  discard block
 block discarded – undo
546 570
 	{
547 571
 		self::$db = $GLOBALS['egw']->db;
548 572
 
549
-		if (is_scalar($keys)) $keys = array('share_id' => $keys);
573
+		if (is_scalar($keys))
574
+		{
575
+			$keys = array('share_id' => $keys);
576
+		}
550 577
 
551 578
 		// get all temp. files, to be able to delete them
552 579
 		$tmp_paths = array();
@@ -593,7 +620,10 @@  discard block
 block discarded – undo
593 620
 	 */
594 621
 	public static function tmp_cleanup()
595 622
 	{
596
-		if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
623
+		if (!isset(self::$db))
624
+		{
625
+			self::$db = $GLOBALS['egw']->db;
626
+		}
597 627
 		Vfs::$is_root = true;
598 628
 
599 629
 		try {
@@ -603,7 +633,10 @@  discard block
 block discarded – undo
603 633
 				'MAX(share_created) AS share_created',
604 634
 				'MAX(share_last_accessed) AS share_last_accessed',
605 635
 			);
606
-			if (($group_concat = self::$db->group_concat('share_id'))) $cols[] = $group_concat.' AS share_id';
636
+			if (($group_concat = self::$db->group_concat('share_id')))
637
+			{
638
+				$cols[] = $group_concat.' AS share_id';
639
+			}
607 640
 			// remove expired tmp-files unconditionally
608 641
 			$having = 'HAVING share_expires < '.self::$db->quote(self::$db->to_timestamp(time())).' OR '.
609 642
 				// remove without expiration date, when created over 100 days ago AND
@@ -651,7 +684,10 @@  discard block
 block discarded – undo
651 684
 	 */
652 685
 	public static function share2link($share)
653 686
 	{
654
-		if (is_array($share)) $share = $share['share_token'];
687
+		if (is_array($share))
688
+		{
689
+			$share = $share['share_token'];
690
+		}
655 691
 
656 692
 		$link = Api\Framework::link('/share.php').'/'.$share;
657 693
 		if ($link[0] == '/')
Please login to merge, or discard this patch.
api/src/Vfs/Sqlfs/StreamWrapper.php 4 patches
Doc Comments   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 	 *
507 507
 	 * If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now.
508 508
 	 *
509
-	 * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
509
+	 * @return boolean TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
510 510
 	 */
511 511
 	function stream_flush ( )
512 512
 	{
@@ -547,6 +547,7 @@  discard block
 block discarded – undo
547 547
 	 * In order for the appropriate error message to be returned, do not define this method if your wrapper does not support unlinking!
548 548
 	 *
549 549
 	 * @param string $url
550
+	 * @param integer $parent_stat
550 551
 	 * @return boolean TRUE on success or FALSE on failure
551 552
 	 */
552 553
 	static function unlink ( $url, $parent_stat=null )
@@ -675,6 +676,8 @@  discard block
 block discarded – undo
675 676
 
676 677
 	/**
677 678
 	 * due to problems with recursive directory creation, we have our own here
679
+	 * @param false|string $pathname
680
+	 * @param integer $mode
678 681
 	 */
679 682
 	protected static function mkdir_recursive($pathname, $mode, $depth=0)
680 683
 	{
@@ -1005,7 +1008,7 @@  discard block
 block discarded – undo
1005 1008
 	 *
1006 1009
 	 * @param string $url URL that was passed to opendir() and that this object is expected to explore.
1007 1010
 	 * @param int $options
1008
-	 * @return booelan
1011
+	 * @return boolean
1009 1012
 	 */
1010 1013
 	function dir_opendir ( $url, $options )
1011 1014
 	{
@@ -1405,7 +1408,7 @@  discard block
 block discarded – undo
1405 1408
 	 *
1406 1409
 	 * @param string $path string with path
1407 1410
 	 * @param int $rights =null rights to set, or null to delete the entry
1408
-	 * @param int|boolean $owner =null owner for whom to set the rights, null for the current user, or false to delete all rights for $path
1411
+	 * @param boolean $owner =null owner for whom to set the rights, null for the current user, or false to delete all rights for $path
1409 1412
 	 * @param int $fs_id =null fs_id to use, to not query it again (eg. because it's already deleted)
1410 1413
 	 * @return boolean true if acl is set/deleted, false on error
1411 1414
 	 */
@@ -1707,7 +1710,7 @@  discard block
 block discarded – undo
1707 1710
 	/**
1708 1711
 	 * Just a little abstration 'til I know how to organise stuff like that with PDO
1709 1712
 	 *
1710
-	 * @param mixed $time
1713
+	 * @param integer $time
1711 1714
 	 * @return string Y-m-d H:i:s
1712 1715
 	 */
1713 1716
 	static protected function _pdo_timestamp($time)
@@ -1792,6 +1795,7 @@  discard block
 block discarded – undo
1792 1795
 	 * Replace the password of an url with '...' for error messages
1793 1796
 	 *
1794 1797
 	 * @param string &$url
1798
+	 * @param string $url
1795 1799
 	 */
1796 1800
 	static protected function _remove_password(&$url)
1797 1801
 	{
@@ -1807,7 +1811,7 @@  discard block
 block discarded – undo
1807 1811
 	/**
1808 1812
 	 * Get storage mode from url (get parameter 'storage', eg. ?storage=db)
1809 1813
 	 *
1810
-	 * @param string|array $url complete url or array of url-parts from parse_url
1814
+	 * @param string $url complete url or array of url-parts from parse_url
1811 1815
 	 * @return int self::STORE2FS or self::STORE2DB
1812 1816
 	 */
1813 1817
 	static function url2operation($url)
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -447,10 +447,10 @@  discard block
 block discarded – undo
447 447
  	 * Important: PHP 5.0 introduced a bug that wasn't fixed until 5.1: the return value has to be the oposite!
448 448
  	 *
449 449
  	 * if(version_compare(PHP_VERSION,'5.0','>=') && version_compare(PHP_VERSION,'5.1','<'))
450
-  	 * {
450
+ 	 * {
451 451
  	 * 		$eof = !$eof;
452 452
  	 * }
453
-  	 *
453
+ 	 *
454 454
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
455 455
  	 */
456 456
 	function stream_eof ( )
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
  	 * See fseek() for more information about these parameters.
486 486
  	 *
487 487
  	 * @param integer $offset
488
-  	 * @param integer $whence	SEEK_SET - 0 - Set position equal to offset bytes
488
+ 	 * @param integer $whence	SEEK_SET - 0 - Set position equal to offset bytes
489 489
  	 * 							SEEK_CUR - 1 - Set position to current location plus offset.
490 490
  	 * 							SEEK_END - 2 - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.)
491 491
  	 * @return boolean TRUE if the position was updated, FALSE otherwise.
@@ -681,8 +681,8 @@  discard block
 block discarded – undo
681 681
 		$maxdepth=10;
682 682
 		$depth2propagate = (int)$depth + 1;
683 683
 		if ($depth2propagate > $maxdepth) return is_dir($pathname);
684
-    	is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate);
685
-    	return is_dir($pathname) || @mkdir($pathname, $mode);
684
+		is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate);
685
+		return is_dir($pathname) || @mkdir($pathname, $mode);
686 686
 	}
687 687
 
688 688
 	/**
Please login to merge, or discard this patch.
Spacing   +234 added lines, -236 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	/**
68 68
 	 * mode-bits, which have to be set for directories
69 69
 	 */
70
-	const MODE_DIR =   040000;
70
+	const MODE_DIR = 040000;
71 71
 	/**
72 72
 	 * mode-bits, which have to be set for links
73 73
 	 */
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @param string $path ='/'
172 172
 	 */
173
-	public static function clearstatcache($path='/')
173
+	public static function clearstatcache($path = '/')
174 174
 	{
175 175
 		//error_log(__METHOD__."('$path')");
176
-		unset($path);	// not used
176
+		unset($path); // not used
177 177
 
178 178
 		self::$stat_cache = array();
179 179
 
@@ -193,32 +193,32 @@  discard block
 block discarded – undo
193 193
 	 * @param array $overwrite_new =null if set create new file with values overwriten by the given ones
194 194
 	 * @return boolean true if the ressource was opened successful, otherwise false
195 195
 	 */
196
-	function stream_open ( $url, $mode, $options, &$opened_path, array $overwrite_new=null )
196
+	function stream_open($url, $mode, $options, &$opened_path, array $overwrite_new = null)
197 197
 	{
198 198
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)");
199 199
 
200
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
200
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
201 201
 		$this->operation = self::url2operation($url);
202 202
 		$dir = Vfs::dirname($url);
203 203
 
204 204
 		$this->opened_path = $opened_path = $path;
205
-		$this->opened_mode = $mode = str_replace('b','',$mode);	// we are always binary, like every Linux system
205
+		$this->opened_mode = $mode = str_replace('b', '', $mode); // we are always binary, like every Linux system
206 206
 		$this->opened_stream = null;
207 207
 
208 208
 		parse_str(parse_url($url, PHP_URL_QUERY), $this->dir_url_params);
209 209
 
210
-		if (!is_null($overwrite_new) || !($stat = static::url_stat($path,STREAM_URL_STAT_QUIET)) || $mode[0] == 'x')	// file not found or file should NOT exist
210
+		if (!is_null($overwrite_new) || !($stat = static::url_stat($path, STREAM_URL_STAT_QUIET)) || $mode[0] == 'x')	// file not found or file should NOT exist
211 211
 		{
212
-			if ($mode[0] == 'r' ||	// does $mode require the file to exist (r,r+)
213
-				$mode[0] == 'x' && $stat ||	// or file should not exist, but does
214
-				!($dir_stat=static::url_stat($dir,STREAM_URL_STAT_QUIET)) ||	// or parent dir does not exist																																			create it
215
-				!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat))	// or we are not allowed to 																																			create it
212
+			if ($mode[0] == 'r' || // does $mode require the file to exist (r,r+)
213
+				$mode[0] == 'x' && $stat || // or file should not exist, but does
214
+				!($dir_stat = static::url_stat($dir, STREAM_URL_STAT_QUIET)) || // or parent dir does not exist																																			create it
215
+				!Vfs::check_access($dir, Vfs::WRITABLE, $dir_stat))	// or we are not allowed to 																																			create it
216 216
 			{
217 217
 				self::_remove_password($url);
218 218
 				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!");
219
-				if (($options & STREAM_REPORT_ERRORS))
219
+				if (($options&STREAM_REPORT_ERRORS))
220 220
 				{
221
-					trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING);
221
+					trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!", E_USER_WARNING);
222 222
 				}
223 223
 				$this->opened_stream = $this->opened_path = $this->opened_mode = null;
224 224
 				return false;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 				'fs_name' => self::limit_filename(Vfs::basename($path)),
234 234
 				'fs_dir'  => $dir_stat['ino'],
235 235
 				// we use the mode of the dir, so files in group dirs stay accessible by all members
236
-				'fs_mode' => $dir_stat['mode'] & 0666,
236
+				'fs_mode' => $dir_stat['mode']&0666,
237 237
 				// for the uid we use the uid of the dir if not 0=root or the current user otherwise
238 238
 				'fs_uid'  => $dir_stat['uid'] ? $dir_stat['uid'] : Vfs::$user,
239 239
 				// we allways use the group of the dir
@@ -241,11 +241,11 @@  discard block
 block discarded – undo
241 241
 				'fs_created'  => self::_pdo_timestamp(time()),
242 242
 				'fs_modified' => self::_pdo_timestamp(time()),
243 243
 				'fs_creator'  => Vfs::$user,
244
-				'fs_mime'     => 'application/octet-stream',	// required NOT NULL!
244
+				'fs_mime'     => 'application/octet-stream', // required NOT NULL!
245 245
 				'fs_size'     => 0,
246 246
 				'fs_active'   => self::_pdo_boolean(true),
247 247
 			);
248
-			if ($overwrite_new) $values = array_merge($values,$overwrite_new);
248
+			if ($overwrite_new) $values = array_merge($values, $overwrite_new);
249 249
 			if (!$stmt->execute($values) || !($this->opened_fs_id = self::$pdo->lastInsertId('egw_sqlfs_fs_id_seq')))
250 250
 			{
251 251
 				$this->opened_stream = $this->opened_path = $this->opened_mode = null;
@@ -258,35 +258,35 @@  discard block
 block discarded – undo
258 258
 				$this->opened_stream = tmpfile();
259 259
 			}
260 260
 			// create the hash-dirs, if they not yet exist
261
-			elseif(!file_exists($fs_dir=Vfs::dirname(self::_fs_path($this->opened_fs_id))))
261
+			elseif (!file_exists($fs_dir = Vfs::dirname(self::_fs_path($this->opened_fs_id))))
262 262
 			{
263 263
 				$umaskbefore = umask();
264 264
 				if (self::LOG_LEVEL > 1) error_log(__METHOD__." about to call mkdir for $fs_dir # Present UMASK:".decoct($umaskbefore)." called from:".function_backtrace());
265
-				self::mkdir_recursive($fs_dir,0700,true);
265
+				self::mkdir_recursive($fs_dir, 0700, true);
266 266
 			}
267 267
 		}
268 268
 		// check if opend file is a directory
269
-		elseif($stat && ($stat['mode'] & self::MODE_DIR) == self::MODE_DIR)
269
+		elseif ($stat && ($stat['mode']&self::MODE_DIR) == self::MODE_DIR)
270 270
 		{
271 271
 				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) Is a directory!");
272
-				if (($options & STREAM_REPORT_ERRORS))
272
+				if (($options&STREAM_REPORT_ERRORS))
273 273
 				{
274
-					trigger_error(__METHOD__."($url,$mode,$options) Is a directory!",E_USER_WARNING);
274
+					trigger_error(__METHOD__."($url,$mode,$options) Is a directory!", E_USER_WARNING);
275 275
 				}
276 276
 				$this->opened_stream = $this->opened_path = $this->opened_mode = null;
277 277
 				return false;
278 278
 		}
279 279
 		else
280 280
 		{
281
-			if ($mode == 'r' && !Vfs::check_access($url,Vfs::READABLE ,$stat) ||// we are not allowed to read
282
-				$mode != 'r' && !Vfs::check_access($url,Vfs::WRITABLE,$stat))	// or edit it
281
+			if ($mode == 'r' && !Vfs::check_access($url, Vfs::READABLE, $stat) || // we are not allowed to read
282
+				$mode != 'r' && !Vfs::check_access($url, Vfs::WRITABLE, $stat))	// or edit it
283 283
 			{
284 284
 				self::_remove_password($url);
285 285
 				$op = $mode == 'r' ? 'read' : 'edited';
286 286
 				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be $op!");
287
-				if (($options & STREAM_REPORT_ERRORS))
287
+				if (($options&STREAM_REPORT_ERRORS))
288 288
 				{
289
-					trigger_error(__METHOD__."($url,$mode,$options) file can not be $op!",E_USER_WARNING);
289
+					trigger_error(__METHOD__."($url,$mode,$options) file can not be $op!", E_USER_WARNING);
290 290
 				}
291 291
 				$this->opened_stream = $this->opened_path = $this->opened_mode = null;
292 292
 				return false;
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
 
296 296
 			if ($this->operation == self::STORE2DB)
297 297
 			{
298
-				$stmt = self::$pdo->prepare($sql='SELECT fs_content FROM '.self::TABLE.' WHERE fs_id=?');
298
+				$stmt = self::$pdo->prepare($sql = 'SELECT fs_content FROM '.self::TABLE.' WHERE fs_id=?');
299 299
 				$stmt->execute(array($stat['ino']));
300
-				$stmt->bindColumn(1,$this->opened_stream,\PDO::PARAM_LOB);
300
+				$stmt->bindColumn(1, $this->opened_stream, \PDO::PARAM_LOB);
301 301
 				$stmt->fetch(\PDO::FETCH_BOUND);
302 302
 				// hack to work around a current php bug (http://bugs.php.net/bug.php?id=40913)
303 303
 				// PDOStatement::bindColumn(,,\PDO::PARAM_LOB) is not working for MySQL, content is returned as string :-(
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		if ($this->operation == self::STORE2FS)
317 317
 		{
318 318
 			if (self::LOG_LEVEL > 1) error_log(__METHOD__." fopen (may create a directory? mkdir) ($this->opened_fs_id,$mode,$options)");
319
-			if (!($this->opened_stream = fopen(self::_fs_path($this->opened_fs_id),$mode)) && $new_file)
319
+			if (!($this->opened_stream = fopen(self::_fs_path($this->opened_fs_id), $mode)) && $new_file)
320 320
 			{
321 321
 				// delete db entry again, if we are not able to open a new(!) file
322 322
 				unset($stmt);
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 		}
327 327
 		if ($mode[0] == 'a')	// append modes: a, a+
328 328
 		{
329
-			$this->stream_seek(0,SEEK_END);
329
+			$this->stream_seek(0, SEEK_END);
330 330
 		}
331 331
 		if (!is_resource($this->opened_stream)) error_log(__METHOD__."($url,$mode,$options) NO stream, returning false!");
332 332
 
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 	 *
339 339
 	 * You must release any resources that were locked or allocated by the stream.
340 340
 	 */
341
-	function stream_close ( )
341
+	function stream_close( )
342 342
 	{
343 343
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
344 344
 
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 
350 350
 		if ($this->opened_mode != 'r')
351 351
 		{
352
-			$this->stream_seek(0,SEEK_END);
352
+			$this->stream_seek(0, SEEK_END);
353 353
 
354 354
 			// we need to update the mime-type, size and content (if STORE2DB)
355 355
 			$values = array(
@@ -372,10 +372,10 @@  discard block
 block discarded – undo
372 372
 			else
373 373
 			{
374 374
 				$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_size=:fs_size,fs_mime=:fs_mime,fs_modifier=:fs_modifier,fs_modified=:fs_modified,fs_content=:fs_content WHERE fs_id=:fs_id');
375
-				$this->stream_seek(0,SEEK_SET);	// rewind to the start
376
-				foreach($values as $name => &$value)
375
+				$this->stream_seek(0, SEEK_SET); // rewind to the start
376
+				foreach ($values as $name => &$value)
377 377
 				{
378
-					$stmt->bindParam($name,$value);
378
+					$stmt->bindParam($name, $value);
379 379
 				}
380 380
 				$stmt->bindParam('fs_content', $this->opened_stream, \PDO::PARAM_LOB);
381 381
 				if (!($ret = $stmt->execute()))
@@ -408,13 +408,13 @@  discard block
 block discarded – undo
408 408
 	 * @param int $count
409 409
 	 * @return string/false up to count bytes read or false on EOF
410 410
 	 */
411
-	function stream_read ( $count )
411
+	function stream_read($count)
412 412
 	{
413 413
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($count) pos=$this->opened_pos");
414 414
 
415 415
 		if (is_resource($this->opened_stream))
416 416
 		{
417
-			return fread($this->opened_stream,$count);
417
+			return fread($this->opened_stream, $count);
418 418
 		}
419 419
 		return false;
420 420
 	}
@@ -430,13 +430,13 @@  discard block
 block discarded – undo
430 430
 	 * @param string $data
431 431
 	 * @return integer
432 432
 	 */
433
-	function stream_write ( $data )
433
+	function stream_write($data)
434 434
 	{
435 435
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($data)");
436 436
 
437 437
 		if (is_resource($this->opened_stream))
438 438
 		{
439
-			return fwrite($this->opened_stream,$data);
439
+			return fwrite($this->opened_stream, $data);
440 440
 		}
441 441
 		return false;
442 442
 	}
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
   	 *
454 454
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
455 455
  	 */
456
-	function stream_eof ( )
456
+	function stream_eof( )
457 457
 	{
458 458
 		if (is_resource($this->opened_stream))
459 459
 		{
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	 *
468 468
 	 * @return integer current read/write position of the stream
469 469
 	 */
470
- 	function stream_tell ( )
470
+ 	function stream_tell( )
471 471
  	{
472 472
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
473 473
 
@@ -490,13 +490,13 @@  discard block
 block discarded – undo
490 490
  	 * 							SEEK_END - 2 - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.)
491 491
  	 * @return boolean TRUE if the position was updated, FALSE otherwise.
492 492
  	 */
493
-	function stream_seek ( $offset, $whence )
493
+	function stream_seek($offset, $whence)
494 494
 	{
495 495
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($offset,$whence)");
496 496
 
497 497
 		if (is_resource($this->opened_stream))
498 498
 		{
499
-			return !fseek($this->opened_stream,$offset,$whence);	// fseek returns 0 on success and -1 on failure
499
+			return !fseek($this->opened_stream, $offset, $whence); // fseek returns 0 on success and -1 on failure
500 500
 		}
501 501
 		return false;
502 502
 	}
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 	 *
509 509
 	 * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
510 510
 	 */
511
-	function stream_flush ( )
511
+	function stream_flush( )
512 512
 	{
513 513
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
514 514
 
@@ -533,11 +533,11 @@  discard block
 block discarded – undo
533 533
 	 *
534 534
 	 * @return array containing the same values as appropriate for the stream.
535 535
 	 */
536
-	function stream_stat ( )
536
+	function stream_stat( )
537 537
 	{
538 538
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($this->opened_path)");
539 539
 
540
-		return $this->url_stat($this->opened_path,0);
540
+		return $this->url_stat($this->opened_path, 0);
541 541
 	}
542 542
 
543 543
 	/**
@@ -549,27 +549,27 @@  discard block
 block discarded – undo
549 549
 	 * @param string $url
550 550
 	 * @return boolean TRUE on success or FALSE on failure
551 551
 	 */
552
-	static function unlink ( $url, $parent_stat=null )
552
+	static function unlink($url, $parent_stat = null)
553 553
 	{
554 554
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
555 555
 
556
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
556
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
557 557
 
558 558
 		// need to get parent stat from Sqlfs, not Vfs
559 559
 		if (!isset($parent_stat)) $parent_stat = static::url_stat(Vfs::dirname($path), STREAM_URL_STAT_LINK);
560 560
 
561
-		if (!$parent_stat || !($stat = self::url_stat($path,STREAM_URL_STAT_LINK)) ||
562
-			!Vfs::check_access(Vfs::dirname($path),Vfs::WRITABLE, $parent_stat))
561
+		if (!$parent_stat || !($stat = self::url_stat($path, STREAM_URL_STAT_LINK)) ||
562
+			!Vfs::check_access(Vfs::dirname($path), Vfs::WRITABLE, $parent_stat))
563 563
 		{
564 564
 			self::_remove_password($url);
565 565
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
566
-			return false;	// no permission or file does not exist
566
+			return false; // no permission or file does not exist
567 567
 		}
568 568
 		if ($stat['mime'] == self::DIR_MIME_TYPE)
569 569
 		{
570 570
 			self::_remove_password($url);
571 571
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url) is NO file!");
572
-			return false;	// no permission or file does not exist
572
+			return false; // no permission or file does not exist
573 573
 		}
574 574
 		$stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=:fs_id');
575 575
 		unset(self::$stat_cache[$path]);
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 		if (($ret = $stmt->execute(array('fs_id' => $stat['ino']))))
578 578
 		{
579 579
 			if (self::url2operation($url) == self::STORE2FS &&
580
-				($stat['mode'] & self::MODE_LINK) != self::MODE_LINK)
580
+				($stat['mode']&self::MODE_LINK) != self::MODE_LINK)
581 581
 			{
582 582
 				unlink(self::_fs_path($stat['ino']));
583 583
 			}
@@ -601,13 +601,13 @@  discard block
 block discarded – undo
601 601
 	 * @param string $url_to
602 602
 	 * @return boolean TRUE on success or FALSE on failure
603 603
 	 */
604
-	static function rename ( $url_from, $url_to)
604
+	static function rename($url_from, $url_to)
605 605
 	{
606 606
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url_from,$url_to)");
607 607
 
608
-		$path_from = Vfs::parse_url($url_from,PHP_URL_PATH);
608
+		$path_from = Vfs::parse_url($url_from, PHP_URL_PATH);
609 609
 		$from_dir = Vfs::dirname($path_from);
610
-		$path_to = Vfs::parse_url($url_to,PHP_URL_PATH);
610
+		$path_to = Vfs::parse_url($url_to, PHP_URL_PATH);
611 611
 		$to_dir = Vfs::dirname($path_to);
612 612
 		$operation = self::url2operation($url_from);
613 613
 
@@ -618,14 +618,14 @@  discard block
 block discarded – undo
618 618
 			self::_remove_password($url_from);
619 619
 			self::_remove_password($url_to);
620 620
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_from permission denied!");
621
-			return false;	// no permission or file does not exist
621
+			return false; // no permission or file does not exist
622 622
 		}
623 623
 		if (!Vfs::check_access($to_dir, Vfs::WRITABLE, $to_dir_stat = static::url_stat($to_dir, 0)))
624 624
 		{
625 625
 			self::_remove_password($url_from);
626 626
 			self::_remove_password($url_to);
627 627
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_to permission denied!");
628
-			return false;	// no permission or parent-dir does not exist
628
+			return false; // no permission or parent-dir does not exist
629 629
 		}
630 630
 		// the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems
631 631
 		// for our vfs too, we abort here with an error, like the filesystem one does
@@ -636,10 +636,10 @@  discard block
 block discarded – undo
636 636
 			self::_remove_password($url_to);
637 637
 			$is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no';
638 638
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $path_to is $is_dir directory!");
639
-			return false;	// no permission or file does not exist
639
+			return false; // no permission or file does not exist
640 640
 		}
641 641
 		// if destination file already exists, delete it
642
-		if ($to_stat && !static::unlink($url_to,$operation))
642
+		if ($to_stat && !static::unlink($url_to, $operation))
643 643
 		{
644 644
 			self::_remove_password($url_to);
645 645
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!");
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
 
661 661
 		// check if extension changed and update mime-type in that case (as we currently determine mime-type by it's extension!)
662 662
 		// fixes eg. problems with MsWord storing file with .tmp extension and then renaming to .doc
663
-		if ($ok && ($new_mime = Vfs::mime_content_type($url_to,true)) != Vfs::mime_content_type($url_to))
663
+		if ($ok && ($new_mime = Vfs::mime_content_type($url_to, true)) != Vfs::mime_content_type($url_to))
664 664
 		{
665 665
 			//echo "<p>Vfs::nime_content_type($url_to,true) = $new_mime</p>\n";
666 666
 			$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_mime=:fs_mime WHERE fs_id=:fs_id');
@@ -676,9 +676,9 @@  discard block
 block discarded – undo
676 676
 	/**
677 677
 	 * due to problems with recursive directory creation, we have our own here
678 678
 	 */
679
-	protected static function mkdir_recursive($pathname, $mode, $depth=0)
679
+	protected static function mkdir_recursive($pathname, $mode, $depth = 0)
680 680
 	{
681
-		$maxdepth=10;
681
+		$maxdepth = 10;
682 682
 		$depth2propagate = (int)$depth + 1;
683 683
 		if ($depth2propagate > $maxdepth) return is_dir($pathname);
684 684
     	is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate);
@@ -696,47 +696,47 @@  discard block
 block discarded – undo
696 696
 	 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
697 697
 	 * @return boolean TRUE on success or FALSE on failure
698 698
 	 */
699
-	static function mkdir ( $url, $mode, $options )
699
+	static function mkdir($url, $mode, $options)
700 700
 	{
701 701
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)");
702 702
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__." called from:".function_backtrace());
703
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
703
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
704 704
 
705
-		if (self::url_stat($path,STREAM_URL_STAT_QUIET))
705
+		if (self::url_stat($path, STREAM_URL_STAT_QUIET))
706 706
 		{
707 707
 			self::_remove_password($url);
708 708
 			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) already exist!");
709
-			if (!($options & STREAM_REPORT_ERRORS))
709
+			if (!($options&STREAM_REPORT_ERRORS))
710 710
 			{
711 711
 				//throw new Exception(__METHOD__."('$url',$mode,$options) already exist!");
712
-				trigger_error(__METHOD__."('$url',$mode,$options) already exist!",E_USER_WARNING);
712
+				trigger_error(__METHOD__."('$url',$mode,$options) already exist!", E_USER_WARNING);
713 713
 			}
714 714
 			return false;
715 715
 		}
716 716
 		$parent_path = Vfs::dirname($path);
717
-		if (($query = Vfs::parse_url($url,PHP_URL_QUERY))) $parent_path .= '?'.$query;
718
-		$parent = self::url_stat($parent_path,STREAM_URL_STAT_QUIET);
717
+		if (($query = Vfs::parse_url($url, PHP_URL_QUERY))) $parent_path .= '?'.$query;
718
+		$parent = self::url_stat($parent_path, STREAM_URL_STAT_QUIET);
719 719
 
720 720
 		// check if we should also create all non-existing path components and our parent does not exist,
721 721
 		// if yes call ourself recursive with the parent directory
722
-		if (($options & STREAM_MKDIR_RECURSIVE) && $parent_path != '/' && !$parent)
722
+		if (($options&STREAM_MKDIR_RECURSIVE) && $parent_path != '/' && !$parent)
723 723
 		{
724 724
 			if (self::LOG_LEVEL > 1) error_log(__METHOD__." creating parents: $parent_path, $mode");
725
-			if (!self::mkdir($parent_path,$mode,$options))
725
+			if (!self::mkdir($parent_path, $mode, $options))
726 726
 			{
727 727
 				return false;
728 728
 			}
729
-			$parent = self::url_stat($parent_path,0);
729
+			$parent = self::url_stat($parent_path, 0);
730 730
 		}
731
-		if (!$parent || !Vfs::check_access($parent_path,Vfs::WRITABLE,$parent))
731
+		if (!$parent || !Vfs::check_access($parent_path, Vfs::WRITABLE, $parent))
732 732
 		{
733 733
 			self::_remove_password($url);
734 734
 			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) permission denied!");
735
-			if (!($options & STREAM_REPORT_ERRORS))
735
+			if (!($options&STREAM_REPORT_ERRORS))
736 736
 			{
737
-				trigger_error(__METHOD__."('$url',$mode,$options) permission denied!",E_USER_WARNING);
737
+				trigger_error(__METHOD__."('$url',$mode,$options) permission denied!", E_USER_WARNING);
738 738
 			}
739
-			return false;	// no permission or file does not exist
739
+			return false; // no permission or file does not exist
740 740
 		}
741 741
 		unset(self::$stat_cache[$path]);
742 742
 		$stmt = self::$pdo->prepare('INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_size,fs_mime,fs_created,fs_modified,fs_creator'.
@@ -757,9 +757,9 @@  discard block
 block discarded – undo
757 757
 			// check if some other process created the directory parallel to us (sqlfs would gives SQL errors later!)
758 758
 			$new_fs_id = self::$pdo->lastInsertId('egw_sqlfs_fs_id_seq');
759 759
 
760
-			unset($stmt);	// free statement object, on some installs a new prepare fails otherwise!
760
+			unset($stmt); // free statement object, on some installs a new prepare fails otherwise!
761 761
 
762
-			$stmt = self::$pdo->prepare($q='SELECT COUNT(*) FROM '.self::TABLE.
762
+			$stmt = self::$pdo->prepare($q = 'SELECT COUNT(*) FROM '.self::TABLE.
763 763
 				' WHERE fs_dir=:fs_dir AND fs_active=:fs_active AND fs_name'.self::$case_sensitive_equal.':fs_name');
764 764
 			if ($stmt->execute(array(
765 765
 				'fs_dir'  => $parent['ino'],
@@ -783,25 +783,24 @@  discard block
 block discarded – undo
783 783
 	 * @param int $options Possible values include STREAM_REPORT_ERRORS.
784 784
 	 * @return boolean TRUE on success or FALSE on failure.
785 785
 	 */
786
-	static function rmdir ( $url, $options )
786
+	static function rmdir($url, $options)
787 787
 	{
788 788
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
789 789
 
790
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
790
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
791 791
 		$parent = Vfs::dirname($path);
792 792
 
793
-		if (!($stat = self::url_stat($path,0)) || $stat['mime'] != self::DIR_MIME_TYPE ||
794
-			!Vfs::check_access($parent, Vfs::WRITABLE, static::url_stat($parent,0)))
793
+		if (!($stat = self::url_stat($path, 0)) || $stat['mime'] != self::DIR_MIME_TYPE ||
794
+			!Vfs::check_access($parent, Vfs::WRITABLE, static::url_stat($parent, 0)))
795 795
 		{
796 796
 			self::_remove_password($url);
797
-			$err_msg = __METHOD__."($url,$options) ".(!$stat ? 'not found!' :
798
-				($stat['mime'] != self::DIR_MIME_TYPE ? 'not a directory!' : 'permission denied!'));
797
+			$err_msg = __METHOD__."($url,$options) ".(!$stat ? 'not found!' : ($stat['mime'] != self::DIR_MIME_TYPE ? 'not a directory!' : 'permission denied!'));
799 798
 			if (self::LOG_LEVEL) error_log($err_msg);
800
-			if (!($options & STREAM_REPORT_ERRORS))
799
+			if (!($options&STREAM_REPORT_ERRORS))
801 800
 			{
802
-				trigger_error($err_msg,E_USER_WARNING);
801
+				trigger_error($err_msg, E_USER_WARNING);
803 802
 			}
804
-			return false;	// no permission or file does not exist
803
+			return false; // no permission or file does not exist
805 804
 		}
806 805
 		$stmt = self::$pdo->prepare('SELECT COUNT(*) FROM '.self::TABLE.' WHERE fs_dir=?');
807 806
 		$stmt->execute(array($stat['ino']));
@@ -809,19 +808,19 @@  discard block
 block discarded – undo
809 808
 		{
810 809
 			self::_remove_password($url);
811 810
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$options) dir is not empty!");
812
-			if (!($options & STREAM_REPORT_ERRORS))
811
+			if (!($options&STREAM_REPORT_ERRORS))
813 812
 			{
814
-				trigger_error(__METHOD__."('$url',$options) dir is not empty!",E_USER_WARNING);
813
+				trigger_error(__METHOD__."('$url',$options) dir is not empty!", E_USER_WARNING);
815 814
 			}
816 815
 			return false;
817 816
 		}
818 817
 		unset(self::$stat_cache[$path]);
819
-		unset($stmt);	// free statement object, on some installs a new prepare fails otherwise!
818
+		unset($stmt); // free statement object, on some installs a new prepare fails otherwise!
820 819
 
821 820
 		$del_stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=?');
822 821
 		if (($ret = $del_stmt->execute(array($stat['ino']))))
823 822
 		{
824
-			self::eacl($path,null,false,$stat['ino']);	// remove all (=false) evtl. existing extended acl for that dir
823
+			self::eacl($path, null, false, $stat['ino']); // remove all (=false) evtl. existing extended acl for that dir
825 824
 			// delete props
826 825
 			unset($del_stmt);
827 826
 			$del_stmt = self::$pdo->prepare('DELETE FROM '.self::PROPS_TABLE.' WHERE fs_id=?');
@@ -837,25 +836,25 @@  discard block
 block discarded – undo
837 836
 	 * @param int $time =null modification time (unix timestamp), default null = current time
838 837
 	 * @param int $atime =null access time (unix timestamp), default null = current time, not implemented in the vfs!
839 838
 	 */
840
-	static function touch($url,$time=null,$atime=null)
839
+	static function touch($url, $time = null, $atime = null)
841 840
 	{
842
-		unset($atime);	// not used
841
+		unset($atime); // not used
843 842
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $time)");
844 843
 
845
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
844
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
846 845
 
847
-		if (!($stat = self::url_stat($path,STREAM_URL_STAT_QUIET)))
846
+		if (!($stat = self::url_stat($path, STREAM_URL_STAT_QUIET)))
848 847
 		{
849 848
 			// file does not exist --> create an empty one
850
-			if (!($f = fopen(self::SCHEME.'://default'.$path,'w')) || !fclose($f))
849
+			if (!($f = fopen(self::SCHEME.'://default'.$path, 'w')) || !fclose($f))
851 850
 			{
852 851
 				return false;
853 852
 			}
854 853
 			if (is_null($time))
855 854
 			{
856
-				return true;	// new (empty) file created with current mod time
855
+				return true; // new (empty) file created with current mod time
857 856
 			}
858
-			$stat = self::url_stat($path,0);
857
+			$stat = self::url_stat($path, 0);
859 858
 		}
860 859
 		unset(self::$stat_cache[$path]);
861 860
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_modified=:fs_modified,fs_modifier=:fs_modifier WHERE fs_id=:fs_id');
@@ -874,39 +873,39 @@  discard block
 block discarded – undo
874 873
 	 * @param int $owner
875 874
 	 * @return boolean
876 875
 	 */
877
-	static function chown($url,$owner)
876
+	static function chown($url, $owner)
878 877
 	{
879 878
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)");
880 879
 
881
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
880
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
882 881
 
883
-		if (!($stat = self::url_stat($path,0)))
882
+		if (!($stat = self::url_stat($path, 0)))
884 883
 		{
885 884
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!");
886
-			trigger_error("No such file or directory $url !",E_USER_WARNING);
885
+			trigger_error("No such file or directory $url !", E_USER_WARNING);
887 886
 			return false;
888 887
 		}
889 888
 		if (!Vfs::$is_root)
890 889
 		{
891 890
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only root can do that!");
892
-			trigger_error("Only root can do that!",E_USER_WARNING);
891
+			trigger_error("Only root can do that!", E_USER_WARNING);
893 892
 			return false;
894 893
 		}
895 894
 		if ($owner < 0 || $owner && !$GLOBALS['egw']->accounts->id2name($owner))	// not a user (0 == root)
896 895
 		{
897 896
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) user id!");
898
-			trigger_error(__METHOD__."($url,$owner) Unknown (numeric) user id!",E_USER_WARNING);
897
+			trigger_error(__METHOD__."($url,$owner) Unknown (numeric) user id!", E_USER_WARNING);
899 898
 			//throw new Exception(__METHOD__."($url,$owner) Unknown (numeric) user id!");
900 899
 			return false;
901 900
 		}
902 901
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_uid=:fs_uid WHERE fs_id=:fs_id');
903 902
 
904 903
 		// update stat-cache
905
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
904
+		if ($path != '/' && substr($path, -1) == '/') $path = substr($path, 0, -1);
906 905
 		self::$stat_cache[$path]['fs_uid'] = $owner;
907 906
 
908 907
 		return $stmt->execute(array(
909
-			'fs_uid' => (int) $owner,
908
+			'fs_uid' => (int)$owner,
910 909
 			'fs_id' => $stat['ino'],
911 910
 		));
912 911
 	}
@@ -918,36 +917,36 @@  discard block
 block discarded – undo
918 917
 	 * @param int $owner
919 918
 	 * @return boolean
920 919
 	 */
921
-	static function chgrp($url,$owner)
920
+	static function chgrp($url, $owner)
922 921
 	{
923 922
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)");
924 923
 
925
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
924
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
926 925
 
927
-		if (!($stat = self::url_stat($path,0)))
926
+		if (!($stat = self::url_stat($path, 0)))
928 927
 		{
929 928
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!");
930
-			trigger_error("No such file or directory $url !",E_USER_WARNING);
929
+			trigger_error("No such file or directory $url !", E_USER_WARNING);
931 930
 			return false;
932 931
 		}
933
-		if (!Vfs::has_owner_rights($path,$stat))
932
+		if (!Vfs::has_owner_rights($path, $stat))
934 933
 		{
935 934
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only owner or root can do that!");
936
-			trigger_error("Only owner or root can do that!",E_USER_WARNING);
935
+			trigger_error("Only owner or root can do that!", E_USER_WARNING);
937 936
 			return false;
938 937
 		}
939
-		if ($owner < 0) $owner = -$owner;	// sqlfs uses a positiv group id's!
938
+		if ($owner < 0) $owner = -$owner; // sqlfs uses a positiv group id's!
940 939
 
941 940
 		if ($owner && !$GLOBALS['egw']->accounts->id2name(-$owner))	// not a group
942 941
 		{
943 942
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) group id!");
944
-			trigger_error("Unknown (numeric) group id!",E_USER_WARNING);
943
+			trigger_error("Unknown (numeric) group id!", E_USER_WARNING);
945 944
 			return false;
946 945
 		}
947 946
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_gid=:fs_gid WHERE fs_id=:fs_id');
948 947
 
949 948
 		// update stat-cache
950
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
949
+		if ($path != '/' && substr($path, -1) == '/') $path = substr($path, 0, -1);
951 950
 		self::$stat_cache[$path]['fs_gid'] = $owner;
952 951
 
953 952
 		return $stmt->execute(array(
@@ -963,38 +962,38 @@  discard block
 block discarded – undo
963 962
 	 * @param int $mode
964 963
 	 * @return boolean
965 964
 	 */
966
-	static function chmod($url,$mode)
965
+	static function chmod($url, $mode)
967 966
 	{
968 967
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $mode)");
969 968
 
970
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
969
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
971 970
 
972
-		if (!($stat = self::url_stat($path,0)))
971
+		if (!($stat = self::url_stat($path, 0)))
973 972
 		{
974 973
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no such file or directory!");
975
-			trigger_error("No such file or directory $url !",E_USER_WARNING);
974
+			trigger_error("No such file or directory $url !", E_USER_WARNING);
976 975
 			return false;
977 976
 		}
978
-		if (!Vfs::has_owner_rights($path,$stat))
977
+		if (!Vfs::has_owner_rights($path, $stat))
979 978
 		{
980 979
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) only owner or root can do that!");
981
-			trigger_error("Only owner or root can do that!",E_USER_WARNING);
980
+			trigger_error("Only owner or root can do that!", E_USER_WARNING);
982 981
 			return false;
983 982
 		}
984 983
 		if (!is_numeric($mode))	// not a mode
985 984
 		{
986 985
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no (numeric) mode!");
987
-			trigger_error("No (numeric) mode!",E_USER_WARNING);
986
+			trigger_error("No (numeric) mode!", E_USER_WARNING);
988 987
 			return false;
989 988
 		}
990 989
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_mode=:fs_mode WHERE fs_id=:fs_id');
991 990
 
992 991
 		// update stat cache
993
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
994
-		self::$stat_cache[$path]['fs_mode'] = ((int) $mode) & 0777;
992
+		if ($path != '/' && substr($path, -1) == '/') $path = substr($path, 0, -1);
993
+		self::$stat_cache[$path]['fs_mode'] = ((int)$mode)&0777;
995 994
 
996 995
 		return $stmt->execute(array(
997
-			'fs_mode' => ((int) $mode) & 0777,		// we dont store the file and dir bits, give int overflow!
996
+			'fs_mode' => ((int)$mode)&0777, // we dont store the file and dir bits, give int overflow!
998 997
 			'fs_id' => $stat['ino'],
999 998
 		));
1000 999
 	}
@@ -1007,15 +1006,15 @@  discard block
 block discarded – undo
1007 1006
 	 * @param int $options
1008 1007
 	 * @return booelan
1009 1008
 	 */
1010
-	function dir_opendir ( $url, $options )
1009
+	function dir_opendir($url, $options)
1011 1010
 	{
1012 1011
 		$this->opened_dir = null;
1013 1012
 
1014
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
1013
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
1015 1014
 
1016
-		if (!($stat = self::url_stat($url,0)) || 		// dir not found
1017
-			$stat['mime'] != self::DIR_MIME_TYPE ||		// no dir
1018
-			!Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat))	// no access
1015
+		if (!($stat = self::url_stat($url, 0)) || // dir not found
1016
+			$stat['mime'] != self::DIR_MIME_TYPE || // no dir
1017
+			!Vfs::check_access($url, Vfs::EXECUTABLE|Vfs::READABLE, $stat))	// no access
1019 1018
 		{
1020 1019
 			self::_remove_password($url);
1021 1020
 			$msg = $stat['mime'] != self::DIR_MIME_TYPE ? "$url is no directory" : 'permission denied';
@@ -1034,13 +1033,13 @@  discard block
 block discarded – undo
1034 1033
 		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
1035 1034
 		if ($stmt->execute(array($stat['ino'])))
1036 1035
 		{
1037
-			foreach($stmt as $file)
1036
+			foreach ($stmt as $file)
1038 1037
 			{
1039 1038
 				$this->opened_dir[] = $file['fs_name'];
1040
-				self::$stat_cache[Vfs::concat($path,$file['fs_name'])] = $file;
1039
+				self::$stat_cache[Vfs::concat($path, $file['fs_name'])] = $file;
1041 1040
 			}
1042 1041
 		}
1043
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options): ".implode(', ',$this->opened_dir));
1042
+		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options): ".implode(', ', $this->opened_dir));
1044 1043
 		reset($this->opened_dir);
1045 1044
 
1046 1045
 		return true;
@@ -1073,26 +1072,26 @@  discard block
 block discarded – undo
1073 1072
 	 * @param boolean $eacl_access =null allows extending classes to pass the value of their check_extended_acl() method (no lsb!)
1074 1073
 	 * @return array
1075 1074
 	 */
1076
-	static function url_stat ( $url, $flags, $eacl_access=null )
1075
+	static function url_stat($url, $flags, $eacl_access = null)
1077 1076
 	{
1078
-		static $max_subquery_depth=null;
1077
+		static $max_subquery_depth = null;
1079 1078
 		if (is_null($max_subquery_depth))
1080 1079
 		{
1081 1080
 			$max_subquery_depth = $GLOBALS['egw_info']['server']['max_subquery_depth'];
1082
-			if (!$max_subquery_depth) $max_subquery_depth = 7;	// setting current default of 7, if nothing set
1081
+			if (!$max_subquery_depth) $max_subquery_depth = 7; // setting current default of 7, if nothing set
1083 1082
 		}
1084 1083
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$flags,$eacl_access)");
1085 1084
 
1086
-		$path = Vfs::parse_url($url,PHP_URL_PATH);
1085
+		$path = Vfs::parse_url($url, PHP_URL_PATH);
1087 1086
 
1088 1087
 		// webdav adds a trailing slash to dirs, which causes url_stat to NOT find the file otherwise
1089
-		if ($path != '/' && substr($path,-1) == '/')
1088
+		if ($path != '/' && substr($path, -1) == '/')
1090 1089
 		{
1091
-			$path = substr($path,0,-1);
1090
+			$path = substr($path, 0, -1);
1092 1091
 		}
1093 1092
 		if (empty($path))
1094 1093
 		{
1095
-			return false;	// is invalid and gives sql error
1094
+			return false; // is invalid and gives sql error
1096 1095
 		}
1097 1096
 		// check if we already have the info from the last dir_open call, as the old vfs reads it anyway from the db
1098 1097
 		if (self::$stat_cache && isset(self::$stat_cache[$path]) && (is_null($eacl_access) || self::$stat_cache[$path] !== false))
@@ -1107,28 +1106,28 @@  discard block
 block discarded – undo
1107 1106
 		$base_query = 'SELECT fs_id,fs_name,fs_mode,fs_uid,fs_gid,fs_size,fs_mime,fs_created,fs_modified'.self::$extra_columns.
1108 1107
 			' FROM '.self::TABLE.' WHERE fs_active='.self::_pdo_boolean(true).
1109 1108
 			' AND fs_name'.self::$case_sensitive_equal.'? AND fs_dir=';
1110
-		$parts = explode('/',$path);
1109
+		$parts = explode('/', $path);
1111 1110
 
1112 1111
 		// if we have extendes acl access to the url, we dont need and can NOT include the sql for the readable check
1113 1112
 		if (is_null($eacl_access))
1114 1113
 		{
1115
-			$eacl_access = self::check_extended_acl($path,Vfs::READABLE);	// should be static::check_extended_acl, but no lsb!
1114
+			$eacl_access = self::check_extended_acl($path, Vfs::READABLE); // should be static::check_extended_acl, but no lsb!
1116 1115
 		}
1117 1116
 
1118 1117
 		try {
1119
-			foreach($parts as $n => $name)
1118
+			foreach ($parts as $n => $name)
1120 1119
 			{
1121 1120
 				if ($n == 0)
1122 1121
 				{
1123
-					$query = (int) ($path != '/');	// / always has fs_id == 1, no need to query it ($path=='/' needs fs_dir=0!)
1122
+					$query = (int)($path != '/'); // / always has fs_id == 1, no need to query it ($path=='/' needs fs_dir=0!)
1124 1123
 				}
1125
-				elseif ($n < count($parts)-1)
1124
+				elseif ($n < count($parts) - 1)
1126 1125
 				{
1127 1126
 					// MySQL 5.0 has a nesting limit for subqueries
1128 1127
 					// --> we replace the so far cumulated subqueries with their result
1129 1128
 					// no idea about the other DBMS, but this does NOT hurt ...
1130 1129
 					// --> depth limit of subqueries is now dynamicly decremented in catch
1131
-					if ($n > 1 && !(($n-1) % $max_subquery_depth) && !($query = self::$pdo->query($query)->fetchColumn()))
1130
+					if ($n > 1 && !(($n - 1) % $max_subquery_depth) && !($query = self::$pdo->query($query)->fetchColumn()))
1132 1131
 					{
1133 1132
 						if (self::LOG_LEVEL > 1)
1134 1133
 						{
@@ -1155,7 +1154,7 @@  discard block
 block discarded – undo
1155 1154
 				}
1156 1155
 				else
1157 1156
 				{
1158
-					$query = str_replace('fs_name'.self::$case_sensitive_equal.'?','fs_name'.self::$case_sensitive_equal.self::$pdo->quote($name),$base_query).'('.$query.')';
1157
+					$query = str_replace('fs_name'.self::$case_sensitive_equal.'?', 'fs_name'.self::$case_sensitive_equal.self::$pdo->quote($name), $base_query).'('.$query.')';
1159 1158
 				}
1160 1159
 			}
1161 1160
 			if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__."($url,$flags,$eacl_access)".' */ '.$query;
@@ -1181,7 +1180,7 @@  discard block
 block discarded – undo
1181 1180
 			$GLOBALS['egw_info']['server']['max_subquery_depth'] = --$max_subquery_depth;
1182 1181
 			error_log(__METHOD__."() decremented max_subquery_depth to $max_subquery_depth");
1183 1182
 			Api\Config::save_value('max_subquery_depth', $max_subquery_depth, 'phpgwapi');
1184
-			if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache();
1183
+			if (method_exists($GLOBALS['egw'], 'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache();
1185 1184
 			return self::url_stat($url, $flags, $eacl_access);
1186 1185
 		}
1187 1186
 		self::$stat_cache[$path] = $info;
@@ -1197,18 +1196,18 @@  discard block
 block discarded – undo
1197 1196
 	 */
1198 1197
 	protected static function _sql_readable()
1199 1198
 	{
1200
-		static $sql_read_acl=null;
1199
+		static $sql_read_acl = null;
1201 1200
 
1202 1201
 		if (is_null($sql_read_acl))
1203 1202
 		{
1204
-			foreach($GLOBALS['egw']->accounts->memberships(Vfs::$user,true) as $gid)
1203
+			foreach ($GLOBALS['egw']->accounts->memberships(Vfs::$user, true) as $gid)
1205 1204
 			{
1206
-				$memberships[] = abs($gid);	// sqlfs stores the gid's positiv
1205
+				$memberships[] = abs($gid); // sqlfs stores the gid's positiv
1207 1206
 			}
1208 1207
 			// using octal numbers with mysql leads to funny results (select 384 & 0400 --> 384 not 256=0400)
1209 1208
 			// 256 = 0400, 32 = 040
1210 1209
 			$sql_read_acl = '((fs_mode & 4)=4 OR (fs_mode & 256)=256 AND fs_uid='.(int)Vfs::$user.
1211
-				($memberships ? ' OR (fs_mode & 32)=32 AND fs_gid IN('.implode(',',$memberships).')' : '').')';
1210
+				($memberships ? ' OR (fs_mode & 32)=32 AND fs_gid IN('.implode(',', $memberships).')' : '').')';
1212 1211
 			//error_log(__METHOD__."() Vfs::\$user=".array2string(Vfs::$user).' --> memberships='.array2string($memberships).' --> '.$sql_read_acl.($memberships?'':': '.function_backtrace()));
1213 1212
 		}
1214 1213
 		return $sql_read_acl;
@@ -1221,7 +1220,7 @@  discard block
 block discarded – undo
1221 1220
 	 *
1222 1221
 	 * @return string
1223 1222
 	 */
1224
-	function dir_readdir ( )
1223
+	function dir_readdir( )
1225 1224
 	{
1226 1225
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1227 1226
 
@@ -1240,7 +1239,7 @@  discard block
 block discarded – undo
1240 1239
 	 *
1241 1240
 	 * @return boolean
1242 1241
 	 */
1243
-	function dir_rewinddir ( )
1242
+	function dir_rewinddir( )
1244 1243
 	{
1245 1244
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1246 1245
 
@@ -1258,7 +1257,7 @@  discard block
 block discarded – undo
1258 1257
 	 *
1259 1258
 	 * @return boolean
1260 1259
 	 */
1261
-	function dir_closedir ( )
1260
+	function dir_closedir( )
1262 1261
 	{
1263 1262
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1264 1263
 
@@ -1279,7 +1278,7 @@  discard block
 block discarded – undo
1279 1278
 	 */
1280 1279
 	static function readlink($path)
1281 1280
 	{
1282
-		$link = !($lstat = self::url_stat($path,STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink'];
1281
+		$link = !($lstat = self::url_stat($path, STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink'];
1283 1282
 
1284 1283
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = $link");
1285 1284
 
@@ -1293,31 +1292,31 @@  discard block
 block discarded – undo
1293 1292
 	 * @param string $link
1294 1293
 	 * @return boolean true on success false on error
1295 1294
 	 */
1296
-	static function symlink($target,$link)
1295
+	static function symlink($target, $link)
1297 1296
 	{
1298 1297
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$target','$link')");
1299 1298
 
1300
-		if (self::url_stat($link,0))
1299
+		if (self::url_stat($link, 0))
1301 1300
 		{
1302 1301
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') $link exists, returning false!");
1303
-			return false;	// $link already exists
1302
+			return false; // $link already exists
1304 1303
 		}
1305 1304
 		if (!($dir = Vfs::dirname($link)) ||
1306
-			!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=static::url_stat($dir,0)))
1305
+			!Vfs::check_access($dir, Vfs::WRITABLE, $dir_stat = static::url_stat($dir, 0)))
1307 1306
 		{
1308 1307
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') returning false! (!is_writable('$dir'), dir_stat=".array2string($dir_stat).")");
1309
-			return false;	// parent dir does not exist or is not writable
1308
+			return false; // parent dir does not exist or is not writable
1310 1309
 		}
1311 1310
 		$query = 'INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_created,fs_modified,fs_creator,fs_mime,fs_size,fs_link'.
1312 1311
 			') VALUES (:fs_name,:fs_dir,:fs_mode,:fs_uid,:fs_gid,:fs_created,:fs_modified,:fs_creator,:fs_mime,:fs_size,:fs_link)';
1313 1312
 		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1314 1313
 		$stmt = self::$pdo->prepare($query);
1315
-		unset(self::$stat_cache[Vfs::parse_url($link,PHP_URL_PATH)]);
1314
+		unset(self::$stat_cache[Vfs::parse_url($link, PHP_URL_PATH)]);
1316 1315
 
1317 1316
 		return !!$stmt->execute(array(
1318 1317
 			'fs_name' => self::limit_filename(Vfs::basename($link)),
1319 1318
 			'fs_dir'  => $dir_stat['ino'],
1320
-			'fs_mode' => ($dir_stat['mode'] & 0666),
1319
+			'fs_mode' => ($dir_stat['mode']&0666),
1321 1320
 			'fs_uid'  => $dir_stat['uid'] ? $dir_stat['uid'] : Vfs::$user,
1322 1321
 			'fs_gid'  => $dir_stat['gid'],
1323 1322
 			'fs_created'  => self::_pdo_timestamp(time()),
@@ -1341,24 +1340,24 @@  discard block
 block discarded – undo
1341 1340
 	 * @param int $check mode to check: one or more or'ed together of: 4 = read, 2 = write, 1 = executable
1342 1341
 	 * @return boolean
1343 1342
 	 */
1344
-	static function check_extended_acl($url,$check)
1343
+	static function check_extended_acl($url, $check)
1345 1344
 	{
1346
-		$url_path = Vfs::parse_url($url,PHP_URL_PATH);
1345
+		$url_path = Vfs::parse_url($url, PHP_URL_PATH);
1347 1346
 
1348 1347
 		if (is_null(self::$extended_acl))
1349 1348
 		{
1350 1349
 			self::_read_extended_acl();
1351 1350
 		}
1352 1351
 		$access = false;
1353
-		foreach(self::$extended_acl as $path => $rights)
1352
+		foreach (self::$extended_acl as $path => $rights)
1354 1353
 		{
1355
-			if ($path == $url_path || substr($url_path,0,strlen($path)+1) == $path.'/')
1354
+			if ($path == $url_path || substr($url_path, 0, strlen($path) + 1) == $path.'/')
1356 1355
 			{
1357
-				$access = ($rights & $check) == $check;
1356
+				$access = ($rights&$check) == $check;
1358 1357
 				break;
1359 1358
 			}
1360 1359
 		}
1361
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$check) ".($access?"access granted by $path=$rights":'no access!!!'));
1360
+		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$check) ".($access ? "access granted by $path=$rights" : 'no access!!!'));
1362 1361
 		return $access;
1363 1362
 	}
1364 1363
 
@@ -1370,14 +1369,14 @@  discard block
 block discarded – undo
1370 1369
 	{
1371 1370
 		if ((self::$extended_acl = Api\Cache::getSession(self::EACL_APPNAME, 'extended_acl')))
1372 1371
 		{
1373
-			return;		// ext. ACL read from session.
1372
+			return; // ext. ACL read from session.
1374 1373
 		}
1375 1374
 		self::$extended_acl = array();
1376
-		if (($rights = $GLOBALS['egw']->acl->get_all_location_rights(Vfs::$user,self::EACL_APPNAME)))
1375
+		if (($rights = $GLOBALS['egw']->acl->get_all_location_rights(Vfs::$user, self::EACL_APPNAME)))
1377 1376
 		{
1378 1377
 			$pathes = self::id2path(array_keys($rights));
1379 1378
 		}
1380
-		foreach($rights as $fs_id => $right)
1379
+		foreach ($rights as $fs_id => $right)
1381 1380
 		{
1382 1381
 			$path = $pathes[$fs_id];
1383 1382
 			if (isset($path))
@@ -1386,8 +1385,8 @@  discard block
 block discarded – undo
1386 1385
 			}
1387 1386
 		}
1388 1387
 		// sort by length descending, to allow more specific pathes to have precedence
1389
-		uksort(self::$extended_acl, function($a,$b) {
1390
-			return strlen($b)-strlen($a);
1388
+		uksort(self::$extended_acl, function($a, $b) {
1389
+			return strlen($b) - strlen($a);
1391 1390
 		});
1392 1391
 		Api\Cache::setSession(self::EACL_APPNAME, 'extended_acl', self::$extended_acl);
1393 1392
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'() '.array2string(self::$extended_acl));
@@ -1409,23 +1408,23 @@  discard block
 block discarded – undo
1409 1408
 	 * @param int $fs_id =null fs_id to use, to not query it again (eg. because it's already deleted)
1410 1409
 	 * @return boolean true if acl is set/deleted, false on error
1411 1410
 	 */
1412
-	static function eacl($path,$rights=null,$owner=null,$fs_id=null)
1411
+	static function eacl($path, $rights = null, $owner = null, $fs_id = null)
1413 1412
 	{
1414 1413
 		if ($path[0] != '/')
1415 1414
 		{
1416
-			$path = Vfs::parse_url($path,PHP_URL_PATH);
1415
+			$path = Vfs::parse_url($path, PHP_URL_PATH);
1417 1416
 		}
1418 1417
 		if (is_null($fs_id))
1419 1418
 		{
1420
-			if (!($stat = self::url_stat($path,0)))
1419
+			if (!($stat = self::url_stat($path, 0)))
1421 1420
 			{
1422 1421
 				if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!");
1423
-				return false;	// $path not found
1422
+				return false; // $path not found
1424 1423
 			}
1425
-			if (!Vfs::has_owner_rights($path,$stat))		// not group dir and user is eGW admin
1424
+			if (!Vfs::has_owner_rights($path, $stat))		// not group dir and user is eGW admin
1426 1425
 			{
1427 1426
 				if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) permission denied!");
1428
-				return false;	// permission denied
1427
+				return false; // permission denied
1429 1428
 			}
1430 1429
 			$fs_id = $stat['ino'];
1431 1430
 		}
@@ -1437,21 +1436,21 @@  discard block
 block discarded – undo
1437 1436
 		{
1438 1437
 			// delete eacl
1439 1438
 			if (is_null($owner) || $owner == Vfs::$user ||
1440
-				$owner < 0 && Vfs::$user && in_array($owner,$GLOBALS['egw']->accounts->memberships(Vfs::$user,true)))
1439
+				$owner < 0 && Vfs::$user && in_array($owner, $GLOBALS['egw']->accounts->memberships(Vfs::$user, true)))
1441 1440
 			{
1442
-				self::$extended_acl = null;	// force new read of eACL, as there could be multiple eACL for that path
1441
+				self::$extended_acl = null; // force new read of eACL, as there could be multiple eACL for that path
1443 1442
 			}
1444
-			$ret = $GLOBALS['egw']->acl->delete_repository(self::EACL_APPNAME,$fs_id,(int)$owner);
1443
+			$ret = $GLOBALS['egw']->acl->delete_repository(self::EACL_APPNAME, $fs_id, (int)$owner);
1445 1444
 		}
1446 1445
 		else
1447 1446
 		{
1448 1447
 			if (isset(self::$extended_acl) && ($owner == Vfs::$user ||
1449
-				$owner < 0 && Vfs::$user && in_array($owner,$GLOBALS['egw']->accounts->memberships(Vfs::$user,true))))
1448
+				$owner < 0 && Vfs::$user && in_array($owner, $GLOBALS['egw']->accounts->memberships(Vfs::$user, true))))
1450 1449
 			{
1451 1450
 				// set rights for this class, if applicable
1452 1451
 				self::$extended_acl[$path] |= $rights;
1453 1452
 			}
1454
-			$ret = $GLOBALS['egw']->acl->add_repository(self::EACL_APPNAME,$fs_id,$owner,$rights);
1453
+			$ret = $GLOBALS['egw']->acl->add_repository(self::EACL_APPNAME, $fs_id, $owner, $rights);
1455 1454
 		}
1456 1455
 		if ($ret)
1457 1456
 		{
@@ -1474,10 +1473,10 @@  discard block
 block discarded – undo
1474 1473
 		if (!($stat = static::url_stat($path, STREAM_URL_STAT_QUIET)))
1475 1474
 		{
1476 1475
 			error_log(__METHOD__.__LINE__.' '.array2string($path).' not found!');
1477
-			return false;	// not found
1476
+			return false; // not found
1478 1477
 		}
1479 1478
 		$eacls = array();
1480
-		foreach($GLOBALS['egw']->acl->get_all_rights($stat['ino'],self::EACL_APPNAME) as $owner => $rights)
1479
+		foreach ($GLOBALS['egw']->acl->get_all_rights($stat['ino'], self::EACL_APPNAME) as $owner => $rights)
1481 1480
 		{
1482 1481
 			$eacls[] = array(
1483 1482
 				'path'   => $path,
@@ -1488,7 +1487,7 @@  discard block
 block discarded – undo
1488 1487
 		}
1489 1488
 		if (($path = Vfs::dirname($path)))
1490 1489
 		{
1491
-			$eacls = array_merge((array)self::get_eacl($path),$eacls);
1490
+			$eacls = array_merge((array)self::get_eacl($path), $eacls);
1492 1491
 		}
1493 1492
 		// sort by length descending, to show precedence
1494 1493
 		usort($eacls, function($a, $b) {
@@ -1513,9 +1512,9 @@  discard block
 block discarded – undo
1513 1512
 		$ids = (array)$fs_ids;
1514 1513
 		$pathes = array();
1515 1514
 		// first check our stat-cache for the ids
1516
-		foreach(self::$stat_cache as $path => $stat)
1515
+		foreach (self::$stat_cache as $path => $stat)
1517 1516
 		{
1518
-			if (($key = array_search($stat['fs_id'],$ids)) !== false)
1517
+			if (($key = array_search($stat['fs_id'], $ids)) !== false)
1519 1518
 			{
1520 1519
 				$pathes[$stat['fs_id']] = $path;
1521 1520
 				unset($ids[$key]);
@@ -1529,7 +1528,7 @@  discard block
 block discarded – undo
1529 1528
 		// now search via the database
1530 1529
 		if (count($ids) > 1) array_map(function(&$v) { $v = (int)$v; },$ids);
1531 1530
 		$query = 'SELECT fs_id,fs_dir,fs_name FROM '.self::TABLE.' WHERE fs_id'.
1532
-			(count($ids) == 1 ? '='.(int)$ids[0] : ' IN ('.implode(',',$ids).')');
1531
+			(count($ids) == 1 ? '='.(int)$ids[0] : ' IN ('.implode(',', $ids).')');
1533 1532
 		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1534 1533
 
1535 1534
 		if (!is_object(self::$pdo))
@@ -1540,12 +1539,12 @@  discard block
 block discarded – undo
1540 1539
 		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
1541 1540
 		if (!$stmt->execute())
1542 1541
 		{
1543
-			return false;	// not found
1542
+			return false; // not found
1544 1543
 		}
1545 1544
 		$parents = array();
1546
-		foreach($stmt as $row)
1545
+		foreach ($stmt as $row)
1547 1546
 		{
1548
-			if ($row['fs_dir'] > 1 && !in_array($row['fs_dir'],$parents))
1547
+			if ($row['fs_dir'] > 1 && !in_array($row['fs_dir'], $parents))
1549 1548
 			{
1550 1549
 				$parents[] = $row['fs_dir'];
1551 1550
 			}
@@ -1555,14 +1554,14 @@  discard block
 block discarded – undo
1555 1554
 
1556 1555
 		if ($parents && !($parents = self::id2path($parents)))
1557 1556
 		{
1558
-			return false;	// parent not found, should never happen ...
1557
+			return false; // parent not found, should never happen ...
1559 1558
 		}
1560
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__." trying foreach with:".print_r($rows,true)."#");
1561
-		foreach((array)$rows as $fs_id => $row)
1559
+		if (self::LOG_LEVEL > 1) error_log(__METHOD__." trying foreach with:".print_r($rows, true)."#");
1560
+		foreach ((array)$rows as $fs_id => $row)
1562 1561
 		{
1563 1562
 			$parent = $row['fs_dir'] > 1 ? $parents[$row['fs_dir']] : '';
1564 1563
 
1565
-			$pathes[$fs_id] = $parent . '/' . $row['fs_name'];
1564
+			$pathes[$fs_id] = $parent.'/'.$row['fs_name'];
1566 1565
 		}
1567 1566
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes));
1568 1567
 		return is_array($fs_ids) ? $pathes : array_shift($pathes);
@@ -1586,7 +1585,7 @@  discard block
 block discarded – undo
1586 1585
 			$parts = explode('.', $name);
1587 1586
 			if ($parts > 1 && mb_strlen($extension = '.'.array_pop($parts)) <= $fs_name_precision)
1588 1587
 			{
1589
-				$name = mb_substr(implode('.', $parts), 0, $fs_name_precision-mb_strlen($extension)).$extension;
1588
+				$name = mb_substr(implode('.', $parts), 0, $fs_name_precision - mb_strlen($extension)).$extension;
1590 1589
 			}
1591 1590
 			else
1592 1591
 			{
@@ -1607,9 +1606,8 @@  discard block
 block discarded – undo
1607 1606
 		$stat = array(
1608 1607
 			'ino'   => $info['fs_id'],
1609 1608
 			'name'  => $info['fs_name'],
1610
-			'mode'  => $info['fs_mode'] |
1611
-				($info['fs_mime'] == self::DIR_MIME_TYPE ? self::MODE_DIR :
1612
-				($info['fs_mime'] == self::SYMLINK_MIME_TYPE ? self::MODE_LINK : self::MODE_FILE)),	// required by the stream wrapper
1609
+			'mode'  => $info['fs_mode']|
1610
+				($info['fs_mime'] == self::DIR_MIME_TYPE ? self::MODE_DIR : ($info['fs_mime'] == self::SYMLINK_MIME_TYPE ? self::MODE_LINK : self::MODE_FILE)), // required by the stream wrapper
1613 1611
 			'size'  => $info['fs_size'],
1614 1612
 			'uid'   => $info['fs_uid'],
1615 1613
 			'gid'   => $info['fs_gid'],
@@ -1649,7 +1647,7 @@  discard block
 block discarded – undo
1649 1647
 	{
1650 1648
 		$egw_db = isset($GLOBALS['egw_setup']) ? $GLOBALS['egw_setup']->db : $GLOBALS['egw']->db;
1651 1649
 
1652
-		switch($egw_db->Type)
1650
+		switch ($egw_db->Type)
1653 1651
 		{
1654 1652
 			case 'mysqli':
1655 1653
 			case 'mysqlt':
@@ -1667,17 +1665,17 @@  discard block
 block discarded – undo
1667 1665
 
1668 1666
 		$dsn = self::$pdo_type.':dbname='.$egw_db->Database.($host ? ';host='.$host.($egw_db->Port ? ';port='.$egw_db->Port : '') : '');
1669 1667
 		// check once if pdo extension and DB specific driver is loaded or can be loaded
1670
-		static $pdo_available=null;
1668
+		static $pdo_available = null;
1671 1669
 		if (is_null($pdo_available))
1672 1670
 		{
1673
-			foreach(array('pdo','pdo_'.self::$pdo_type) as $ext)
1671
+			foreach (array('pdo', 'pdo_'.self::$pdo_type) as $ext)
1674 1672
 			{
1675
-				check_load_extension($ext,true);	// true = throw Exception
1673
+				check_load_extension($ext, true); // true = throw Exception
1676 1674
 			}
1677 1675
 			$pdo_available = true;
1678 1676
 		}
1679 1677
 		// set client charset of the connection
1680
-		switch(self::$pdo_type)
1678
+		switch (self::$pdo_type)
1681 1679
 		{
1682 1680
 			case 'mysql':
1683 1681
 				$dsn .= ';charset=utf8';
@@ -1687,15 +1685,15 @@  discard block
 block discarded – undo
1687 1685
 				break;
1688 1686
 		}
1689 1687
 		try {
1690
-			self::$pdo = new \PDO($dsn,$egw_db->User,$egw_db->Password,array(
1688
+			self::$pdo = new \PDO($dsn, $egw_db->User, $egw_db->Password, array(
1691 1689
 				\PDO::ATTR_ERRMODE=>\PDO::ERRMODE_EXCEPTION,
1692 1690
 			));
1693 1691
 		}
1694
-		catch(\PDOException $e)
1692
+		catch (\PDOException $e)
1695 1693
 		{
1696 1694
 			unset($e);
1697 1695
 			// Exception reveals password, so we ignore the exception and connect again without pw, to get the right exception without pw
1698
-			self::$pdo = new \PDO($dsn,$egw_db->User,'$egw_db->Password');
1696
+			self::$pdo = new \PDO($dsn, $egw_db->User, '$egw_db->Password');
1699 1697
 		}
1700 1698
 		if ($query)
1701 1699
 		{
@@ -1714,7 +1712,7 @@  discard block
 block discarded – undo
1714 1712
 	{
1715 1713
 		if (is_numeric($time))
1716 1714
 		{
1717
-			$time = date('Y-m-d H:i:s',$time);
1715
+			$time = date('Y-m-d H:i:s', $time);
1718 1716
 		}
1719 1717
 		return $time;
1720 1718
 	}
@@ -1764,10 +1762,10 @@  discard block
 block discarded – undo
1764 1762
 		{
1765 1763
 			if (is_object($GLOBALS['egw_setup']->db))	// if we run under setup, query the db for the files dir
1766 1764
 			{
1767
-				$GLOBALS['egw_info']['server']['files_dir'] = $GLOBALS['egw_setup']->db->select('egw_config','config_value',array(
1765
+				$GLOBALS['egw_info']['server']['files_dir'] = $GLOBALS['egw_setup']->db->select('egw_config', 'config_value', array(
1768 1766
 					'config_name' => 'files_dir',
1769 1767
 					'config_app' => 'phpgwapi',
1770
-				),__LINE__,__FILE__)->fetchColumn();
1768
+				), __LINE__, __FILE__)->fetchColumn();
1771 1769
 			}
1772 1770
 		}
1773 1771
 		if (!$GLOBALS['egw_info']['server']['files_dir'])
@@ -1776,14 +1774,14 @@  discard block
 block discarded – undo
1776 1774
 		}
1777 1775
 		$hash = array();
1778 1776
 		$n = $id;
1779
-		while(($n = (int) ($n / self::HASH_MAX)))
1777
+		while (($n = (int)($n / self::HASH_MAX)))
1780 1778
 		{
1781
-			$hash[] = sprintf('%02d',$n % self::HASH_MAX);
1779
+			$hash[] = sprintf('%02d', $n % self::HASH_MAX);
1782 1780
 		}
1783
-		if (!$hash) $hash[] = '00';		// we need at least one directory, to not conflict with the dir-names
1784
-		array_unshift($hash,$id);
1781
+		if (!$hash) $hash[] = '00'; // we need at least one directory, to not conflict with the dir-names
1782
+		array_unshift($hash, $id);
1785 1783
 
1786
-		$path = '/sqlfs/'.implode('/',array_reverse($hash));
1784
+		$path = '/sqlfs/'.implode('/', array_reverse($hash));
1787 1785
 		//error_log(__METHOD__."($id) = '$path'");
1788 1786
 		return $GLOBALS['egw_info']['server']['files_dir'].$path;
1789 1787
 	}
@@ -1799,7 +1797,7 @@  discard block
 block discarded – undo
1799 1797
 
1800 1798
 		if ($parts['pass'] || $parts['scheme'])
1801 1799
 		{
1802
-			$url = $parts['scheme'].'://'.($parts['user'] ? $parts['user'].($parts['pass']?':...':'').'@' : '').
1800
+			$url = $parts['scheme'].'://'.($parts['user'] ? $parts['user'].($parts['pass'] ? ':...' : '').'@' : '').
1803 1801
 				$parts['host'].$parts['path'];
1804 1802
 		}
1805 1803
 	}
@@ -1814,10 +1812,10 @@  discard block
 block discarded – undo
1814 1812
 	{
1815 1813
 		$operation = self::DEFAULT_OPERATION;
1816 1814
 
1817
-		if (strpos(is_array($url) ? $url['query'] : $url,'storage=') !== false)
1815
+		if (strpos(is_array($url) ? $url['query'] : $url, 'storage=') !== false)
1818 1816
 		{
1819 1817
 			$query = null;
1820
-			parse_str(is_array($url) ? $url['query'] : Vfs::parse_url($url,PHP_URL_QUERY), $query);
1818
+			parse_str(is_array($url) ? $url['query'] : Vfs::parse_url($url, PHP_URL_QUERY), $query);
1821 1819
 			switch ($query['storage'])
1822 1820
 			{
1823 1821
 				case 'db':
@@ -1840,27 +1838,27 @@  discard block
 block discarded – undo
1840 1838
 	 * @param array $props array of array with values for keys 'name', 'ns', 'val' (null to delete the prop)
1841 1839
 	 * @return boolean true if props are updated, false otherwise (eg. ressource not found)
1842 1840
 	 */
1843
-	static function proppatch($path,array $props)
1841
+	static function proppatch($path, array $props)
1844 1842
 	{
1845 1843
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."(".array2string($path).','.array2string($props));
1846 1844
 		if (!is_numeric($path))
1847 1845
 		{
1848
-			if (!($stat = self::url_stat($path,0)))
1846
+			if (!($stat = self::url_stat($path, 0)))
1849 1847
 			{
1850 1848
 				return false;
1851 1849
 			}
1852 1850
 			$id = $stat['ino'];
1853 1851
 		}
1854
-		elseif(!($path = self::id2path($id=$path)))
1852
+		elseif (!($path = self::id2path($id = $path)))
1855 1853
 		{
1856 1854
 			return false;
1857 1855
 		}
1858
-		if (!Vfs::check_access($path,Api\Acl::EDIT,$stat))
1856
+		if (!Vfs::check_access($path, Api\Acl::EDIT, $stat))
1859 1857
 		{
1860
-			return false;	// permission denied
1858
+			return false; // permission denied
1861 1859
 		}
1862 1860
 		$ins_stmt = $del_stmt = null;
1863
-		foreach($props as &$prop)
1861
+		foreach ($props as &$prop)
1864 1862
 		{
1865 1863
 			if (!isset($prop['ns'])) $prop['ns'] = Vfs::DEFAULT_PROP_NAMESPACE;
1866 1864
 
@@ -1905,14 +1903,14 @@  discard block
 block discarded – undo
1905 1903
 	 * @return array|boolean false on error ($path_ids does not exist), array with props (values for keys 'name', 'ns', 'value'), or
1906 1904
 	 * 	fs_id/path => array of props for $depth==1 or is_array($path_ids)
1907 1905
 	 */
1908
-	static function propfind($path_ids,$ns=Vfs::DEFAULT_PROP_NAMESPACE)
1906
+	static function propfind($path_ids, $ns = Vfs::DEFAULT_PROP_NAMESPACE)
1909 1907
 	{
1910 1908
 		$ids = is_array($path_ids) ? $path_ids : array($path_ids);
1911
-		foreach($ids as &$id)
1909
+		foreach ($ids as &$id)
1912 1910
 		{
1913 1911
 			if (!is_numeric($id))
1914 1912
 			{
1915
-				if (!($stat = self::url_stat($id,0)))
1913
+				if (!($stat = self::url_stat($id, 0)))
1916 1914
 				{
1917 1915
 					if (self::LOG_LEVEL) error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!");
1918 1916
 					return false;
@@ -1922,7 +1920,7 @@  discard block
 block discarded – undo
1922 1920
 		}
1923 1921
 		if (count($ids) >= 1) array_map(function(&$v) { $v = (int)$v; },$ids);
1924 1922
 		$query = 'SELECT * FROM '.self::PROPS_TABLE.' WHERE (fs_id'.
1925
-			(count($ids) == 1 ? '='.(int)implode('',$ids) : ' IN ('.implode(',',$ids).')').')'.
1923
+			(count($ids) == 1 ? '='.(int)implode('', $ids) : ' IN ('.implode(',', $ids).')').')'.
1926 1924
 			(!is_null($ns) ? ' AND prop_namespace=?' : '');
1927 1925
 		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1928 1926
 
@@ -1931,7 +1929,7 @@  discard block
 block discarded – undo
1931 1929
 		$stmt->execute(!is_null($ns) ? array($ns) : array());
1932 1930
 
1933 1931
 		$props = array();
1934
-		foreach($stmt as $row)
1932
+		foreach ($stmt as $row)
1935 1933
 		{
1936 1934
 			$props[$row['fs_id']][] = array(
1937 1935
 				'val'  => $row['prop_value'],
@@ -1941,19 +1939,19 @@  discard block
 block discarded – undo
1941 1939
 		}
1942 1940
 		if (!is_array($path_ids))
1943 1941
 		{
1944
-			$props = $props[$row['fs_id']] ? $props[$row['fs_id']] : array();	// return empty array for no props
1942
+			$props = $props[$row['fs_id']] ? $props[$row['fs_id']] : array(); // return empty array for no props
1945 1943
 		}
1946 1944
 		elseif ($props && isset($stat))	// need to map fs_id's to pathes
1947 1945
 		{
1948
-			foreach(self::id2path(array_keys($props)) as $id => $path)
1946
+			foreach (self::id2path(array_keys($props)) as $id => $path)
1949 1947
 			{
1950
-				$props[$path] =& $props[$id];
1948
+				$props[$path] = & $props[$id];
1951 1949
 				unset($props[$id]);
1952 1950
 			}
1953 1951
 		}
1954 1952
 		if (self::LOG_LEVEL > 1)
1955 1953
 		{
1956
-			foreach((array)$props as $k => $v)
1954
+			foreach ((array)$props as $k => $v)
1957 1955
 			{
1958 1956
 				error_log(__METHOD__."($path_ids,$ns) $k => ".array2string($v));
1959 1957
 			}
Please login to merge, or discard this patch.
Braces   +405 added lines, -101 removed lines patch added patch discarded remove patch
@@ -195,7 +195,10 @@  discard block
 block discarded – undo
195 195
 	 */
196 196
 	function stream_open ( $url, $mode, $options, &$opened_path, array $overwrite_new=null )
197 197
 	{
198
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)");
198
+		if (self::LOG_LEVEL > 1)
199
+		{
200
+			error_log(__METHOD__."($url,$mode,$options)");
201
+		}
199 202
 
200 203
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
201 204
 		$this->operation = self::url2operation($url);
@@ -207,7 +210,9 @@  discard block
 block discarded – undo
207 210
 
208 211
 		parse_str(parse_url($url, PHP_URL_QUERY), $this->dir_url_params);
209 212
 
210
-		if (!is_null($overwrite_new) || !($stat = static::url_stat($path,STREAM_URL_STAT_QUIET)) || $mode[0] == 'x')	// file not found or file should NOT exist
213
+		if (!is_null($overwrite_new) || !($stat = static::url_stat($path,STREAM_URL_STAT_QUIET)) || $mode[0] == 'x')
214
+		{
215
+			// file not found or file should NOT exist
211 216
 		{
212 217
 			if ($mode[0] == 'r' ||	// does $mode require the file to exist (r,r+)
213 218
 				$mode[0] == 'x' && $stat ||	// or file should not exist, but does
@@ -215,7 +220,11 @@  discard block
 block discarded – undo
215 220
 				!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat))	// or we are not allowed to 																																			create it
216 221
 			{
217 222
 				self::_remove_password($url);
218
-				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!");
223
+		}
224
+				if (self::LOG_LEVEL)
225
+				{
226
+					error_log(__METHOD__."($url,$mode,$options) file does not exist or can not be created!");
227
+				}
219 228
 				if (($options & STREAM_REPORT_ERRORS))
220 229
 				{
221 230
 					trigger_error(__METHOD__."($url,$mode,$options) file does not exist or can not be created!",E_USER_WARNING);
@@ -227,7 +236,10 @@  discard block
 block discarded – undo
227 236
 			$new_file = true;
228 237
 			$query = 'INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_created,fs_modified,fs_creator,fs_mime,fs_size,fs_active'.
229 238
 				') VALUES (:fs_name,:fs_dir,:fs_mode,:fs_uid,:fs_gid,:fs_created,:fs_modified,:fs_creator,:fs_mime,:fs_size,:fs_active)';
230
-			if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
239
+			if (self::LOG_LEVEL > 2)
240
+			{
241
+				$query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
242
+			}
231 243
 			$stmt = self::$pdo->prepare($query);
232 244
 			$values = array(
233 245
 				'fs_name' => self::limit_filename(Vfs::basename($path)),
@@ -245,11 +257,17 @@  discard block
 block discarded – undo
245 257
 				'fs_size'     => 0,
246 258
 				'fs_active'   => self::_pdo_boolean(true),
247 259
 			);
248
-			if ($overwrite_new) $values = array_merge($values,$overwrite_new);
260
+			if ($overwrite_new)
261
+			{
262
+				$values = array_merge($values,$overwrite_new);
263
+			}
249 264
 			if (!$stmt->execute($values) || !($this->opened_fs_id = self::$pdo->lastInsertId('egw_sqlfs_fs_id_seq')))
250 265
 			{
251 266
 				$this->opened_stream = $this->opened_path = $this->opened_mode = null;
252
-				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) execute() failed: ".self::$pdo->errorInfo());
267
+				if (self::LOG_LEVEL)
268
+				{
269
+					error_log(__METHOD__."($url,$mode,$options) execute() failed: ".self::$pdo->errorInfo());
270
+				}
253 271
 				return false;
254 272
 			}
255 273
 			if ($this->operation == self::STORE2DB)
@@ -261,14 +279,20 @@  discard block
 block discarded – undo
261 279
 			elseif(!file_exists($fs_dir=Vfs::dirname(self::_fs_path($this->opened_fs_id))))
262 280
 			{
263 281
 				$umaskbefore = umask();
264
-				if (self::LOG_LEVEL > 1) error_log(__METHOD__." about to call mkdir for $fs_dir # Present UMASK:".decoct($umaskbefore)." called from:".function_backtrace());
282
+				if (self::LOG_LEVEL > 1)
283
+				{
284
+					error_log(__METHOD__." about to call mkdir for $fs_dir # Present UMASK:".decoct($umaskbefore)." called from:".function_backtrace());
285
+				}
265 286
 				self::mkdir_recursive($fs_dir,0700,true);
266 287
 			}
267 288
 		}
268 289
 		// check if opend file is a directory
269 290
 		elseif($stat && ($stat['mode'] & self::MODE_DIR) == self::MODE_DIR)
270 291
 		{
271
-				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) Is a directory!");
292
+				if (self::LOG_LEVEL)
293
+				{
294
+					error_log(__METHOD__."($url,$mode,$options) Is a directory!");
295
+				}
272 296
 				if (($options & STREAM_REPORT_ERRORS))
273 297
 				{
274 298
 					trigger_error(__METHOD__."($url,$mode,$options) Is a directory!",E_USER_WARNING);
@@ -279,11 +303,17 @@  discard block
 block discarded – undo
279 303
 		else
280 304
 		{
281 305
 			if ($mode == 'r' && !Vfs::check_access($url,Vfs::READABLE ,$stat) ||// we are not allowed to read
282
-				$mode != 'r' && !Vfs::check_access($url,Vfs::WRITABLE,$stat))	// or edit it
306
+				$mode != 'r' && !Vfs::check_access($url,Vfs::WRITABLE,$stat))
307
+			{
308
+				// or edit it
283 309
 			{
284 310
 				self::_remove_password($url);
311
+			}
285 312
 				$op = $mode == 'r' ? 'read' : 'edited';
286
-				if (self::LOG_LEVEL) error_log(__METHOD__."($url,$mode,$options) file can not be $op!");
313
+				if (self::LOG_LEVEL)
314
+				{
315
+					error_log(__METHOD__."($url,$mode,$options) file can not be $op!");
316
+				}
287 317
 				if (($options & STREAM_REPORT_ERRORS))
288 318
 				{
289 319
 					trigger_error(__METHOD__."($url,$mode,$options) file can not be $op!",E_USER_WARNING);
@@ -315,7 +345,10 @@  discard block
 block discarded – undo
315 345
 		// do we operate directly on the filesystem --> open file from there
316 346
 		if ($this->operation == self::STORE2FS)
317 347
 		{
318
-			if (self::LOG_LEVEL > 1) error_log(__METHOD__." fopen (may create a directory? mkdir) ($this->opened_fs_id,$mode,$options)");
348
+			if (self::LOG_LEVEL > 1)
349
+			{
350
+				error_log(__METHOD__." fopen (may create a directory? mkdir) ($this->opened_fs_id,$mode,$options)");
351
+			}
319 352
 			if (!($this->opened_stream = fopen(self::_fs_path($this->opened_fs_id),$mode)) && $new_file)
320 353
 			{
321 354
 				// delete db entry again, if we are not able to open a new(!) file
@@ -324,11 +357,17 @@  discard block
 block discarded – undo
324 357
 				$stmt->execute(array('fs_id' => $this->opened_fs_id));
325 358
 			}
326 359
 		}
327
-		if ($mode[0] == 'a')	// append modes: a, a+
360
+		if ($mode[0] == 'a')
361
+		{
362
+			// append modes: a, a+
328 363
 		{
329 364
 			$this->stream_seek(0,SEEK_END);
330 365
 		}
331
-		if (!is_resource($this->opened_stream)) error_log(__METHOD__."($url,$mode,$options) NO stream, returning false!");
366
+		}
367
+		if (!is_resource($this->opened_stream))
368
+		{
369
+			error_log(__METHOD__."($url,$mode,$options) NO stream, returning false!");
370
+		}
332 371
 
333 372
 		return is_resource($this->opened_stream);
334 373
 	}
@@ -340,7 +379,10 @@  discard block
 block discarded – undo
340 379
 	 */
341 380
 	function stream_close ( )
342 381
 	{
343
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
382
+		if (self::LOG_LEVEL > 1)
383
+		{
384
+			error_log(__METHOD__."()");
385
+		}
344 386
 
345 387
 		if (is_null($this->opened_path) || !is_resource($this->opened_stream) || !$this->opened_fs_id)
346 388
 		{
@@ -410,7 +452,10 @@  discard block
 block discarded – undo
410 452
 	 */
411 453
 	function stream_read ( $count )
412 454
 	{
413
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($count) pos=$this->opened_pos");
455
+		if (self::LOG_LEVEL > 1)
456
+		{
457
+			error_log(__METHOD__."($count) pos=$this->opened_pos");
458
+		}
414 459
 
415 460
 		if (is_resource($this->opened_stream))
416 461
 		{
@@ -432,7 +477,10 @@  discard block
 block discarded – undo
432 477
 	 */
433 478
 	function stream_write ( $data )
434 479
 	{
435
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($data)");
480
+		if (self::LOG_LEVEL > 1)
481
+		{
482
+			error_log(__METHOD__."($data)");
483
+		}
436 484
 
437 485
 		if (is_resource($this->opened_stream))
438 486
 		{
@@ -469,7 +517,10 @@  discard block
 block discarded – undo
469 517
 	 */
470 518
  	function stream_tell ( )
471 519
  	{
472
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
520
+		if (self::LOG_LEVEL > 1)
521
+		{
522
+			error_log(__METHOD__."()");
523
+		}
473 524
 
474 525
 		if (is_resource($this->opened_stream))
475 526
 		{
@@ -492,7 +543,10 @@  discard block
 block discarded – undo
492 543
  	 */
493 544
 	function stream_seek ( $offset, $whence )
494 545
 	{
495
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($offset,$whence)");
546
+		if (self::LOG_LEVEL > 1)
547
+		{
548
+			error_log(__METHOD__."($offset,$whence)");
549
+		}
496 550
 
497 551
 		if (is_resource($this->opened_stream))
498 552
 		{
@@ -510,7 +564,10 @@  discard block
 block discarded – undo
510 564
 	 */
511 565
 	function stream_flush ( )
512 566
 	{
513
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."()");
567
+		if (self::LOG_LEVEL > 1)
568
+		{
569
+			error_log(__METHOD__."()");
570
+		}
514 571
 
515 572
 		if (is_resource($this->opened_stream))
516 573
 		{
@@ -535,7 +592,10 @@  discard block
 block discarded – undo
535 592
 	 */
536 593
 	function stream_stat ( )
537 594
 	{
538
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($this->opened_path)");
595
+		if (self::LOG_LEVEL > 1)
596
+		{
597
+			error_log(__METHOD__."($this->opened_path)");
598
+		}
539 599
 
540 600
 		return $this->url_stat($this->opened_path,0);
541 601
 	}
@@ -551,24 +611,36 @@  discard block
 block discarded – undo
551 611
 	 */
552 612
 	static function unlink ( $url, $parent_stat=null )
553 613
 	{
554
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
614
+		if (self::LOG_LEVEL > 1)
615
+		{
616
+			error_log(__METHOD__."($url)");
617
+		}
555 618
 
556 619
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
557 620
 
558 621
 		// need to get parent stat from Sqlfs, not Vfs
559
-		if (!isset($parent_stat)) $parent_stat = static::url_stat(Vfs::dirname($path), STREAM_URL_STAT_LINK);
622
+		if (!isset($parent_stat))
623
+		{
624
+			$parent_stat = static::url_stat(Vfs::dirname($path), STREAM_URL_STAT_LINK);
625
+		}
560 626
 
561 627
 		if (!$parent_stat || !($stat = self::url_stat($path,STREAM_URL_STAT_LINK)) ||
562 628
 			!Vfs::check_access(Vfs::dirname($path),Vfs::WRITABLE, $parent_stat))
563 629
 		{
564 630
 			self::_remove_password($url);
565
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url) permission denied!");
631
+			if (self::LOG_LEVEL)
632
+			{
633
+				error_log(__METHOD__."($url) permission denied!");
634
+			}
566 635
 			return false;	// no permission or file does not exist
567 636
 		}
568 637
 		if ($stat['mime'] == self::DIR_MIME_TYPE)
569 638
 		{
570 639
 			self::_remove_password($url);
571
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url) is NO file!");
640
+			if (self::LOG_LEVEL)
641
+			{
642
+				error_log(__METHOD__."($url) is NO file!");
643
+			}
572 644
 			return false;	// no permission or file does not exist
573 645
 		}
574 646
 		$stmt = self::$pdo->prepare('DELETE FROM '.self::TABLE.' WHERE fs_id=:fs_id');
@@ -603,7 +675,10 @@  discard block
 block discarded – undo
603 675
 	 */
604 676
 	static function rename ( $url_from, $url_to)
605 677
 	{
606
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url_from,$url_to)");
678
+		if (self::LOG_LEVEL > 1)
679
+		{
680
+			error_log(__METHOD__."($url_from,$url_to)");
681
+		}
607 682
 
608 683
 		$path_from = Vfs::parse_url($url_from,PHP_URL_PATH);
609 684
 		$from_dir = Vfs::dirname($path_from);
@@ -617,14 +692,20 @@  discard block
 block discarded – undo
617 692
 		{
618 693
 			self::_remove_password($url_from);
619 694
 			self::_remove_password($url_to);
620
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_from permission denied!");
695
+			if (self::LOG_LEVEL)
696
+			{
697
+				error_log(__METHOD__."($url_from,$url_to): $path_from permission denied!");
698
+			}
621 699
 			return false;	// no permission or file does not exist
622 700
 		}
623 701
 		if (!Vfs::check_access($to_dir, Vfs::WRITABLE, $to_dir_stat = static::url_stat($to_dir, 0)))
624 702
 		{
625 703
 			self::_remove_password($url_from);
626 704
 			self::_remove_password($url_to);
627
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_from,$url_to): $path_to permission denied!");
705
+			if (self::LOG_LEVEL)
706
+			{
707
+				error_log(__METHOD__."($url_from,$url_to): $path_to permission denied!");
708
+			}
628 709
 			return false;	// no permission or parent-dir does not exist
629 710
 		}
630 711
 		// the filesystem stream-wrapper does NOT allow to rename files to directories, as this makes problems
@@ -635,14 +716,20 @@  discard block
 block discarded – undo
635 716
 			self::_remove_password($url_from);
636 717
 			self::_remove_password($url_to);
637 718
 			$is_dir = $to_stat['mime'] === self::DIR_MIME_TYPE ? 'a' : 'no';
638
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) $path_to is $is_dir directory!");
719
+			if (self::LOG_LEVEL)
720
+			{
721
+				error_log(__METHOD__."($url_to,$url_from) $path_to is $is_dir directory!");
722
+			}
639 723
 			return false;	// no permission or file does not exist
640 724
 		}
641 725
 		// if destination file already exists, delete it
642 726
 		if ($to_stat && !static::unlink($url_to,$operation))
643 727
 		{
644 728
 			self::_remove_password($url_to);
645
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!");
729
+			if (self::LOG_LEVEL)
730
+			{
731
+				error_log(__METHOD__."($url_to,$url_from) can't unlink existing $url_to!");
732
+			}
646 733
 			return false;
647 734
 		}
648 735
 		unset(self::$stat_cache[$path_from]);
@@ -680,7 +767,10 @@  discard block
 block discarded – undo
680 767
 	{
681 768
 		$maxdepth=10;
682 769
 		$depth2propagate = (int)$depth + 1;
683
-		if ($depth2propagate > $maxdepth) return is_dir($pathname);
770
+		if ($depth2propagate > $maxdepth)
771
+		{
772
+			return is_dir($pathname);
773
+		}
684 774
     	is_dir(Vfs::dirname($pathname)) || self::mkdir_recursive(Vfs::dirname($pathname), $mode, $depth2propagate);
685 775
     	return is_dir($pathname) || @mkdir($pathname, $mode);
686 776
 	}
@@ -698,14 +788,23 @@  discard block
 block discarded – undo
698 788
 	 */
699 789
 	static function mkdir ( $url, $mode, $options )
700 790
 	{
701
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$mode,$options)");
702
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__." called from:".function_backtrace());
791
+		if (self::LOG_LEVEL > 1)
792
+		{
793
+			error_log(__METHOD__."($url,$mode,$options)");
794
+		}
795
+		if (self::LOG_LEVEL > 1)
796
+		{
797
+			error_log(__METHOD__." called from:".function_backtrace());
798
+		}
703 799
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
704 800
 
705 801
 		if (self::url_stat($path,STREAM_URL_STAT_QUIET))
706 802
 		{
707 803
 			self::_remove_password($url);
708
-			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) already exist!");
804
+			if (self::LOG_LEVEL)
805
+			{
806
+				error_log(__METHOD__."('$url',$mode,$options) already exist!");
807
+			}
709 808
 			if (!($options & STREAM_REPORT_ERRORS))
710 809
 			{
711 810
 				//throw new Exception(__METHOD__."('$url',$mode,$options) already exist!");
@@ -714,14 +813,20 @@  discard block
 block discarded – undo
714 813
 			return false;
715 814
 		}
716 815
 		$parent_path = Vfs::dirname($path);
717
-		if (($query = Vfs::parse_url($url,PHP_URL_QUERY))) $parent_path .= '?'.$query;
816
+		if (($query = Vfs::parse_url($url,PHP_URL_QUERY)))
817
+		{
818
+			$parent_path .= '?'.$query;
819
+		}
718 820
 		$parent = self::url_stat($parent_path,STREAM_URL_STAT_QUIET);
719 821
 
720 822
 		// check if we should also create all non-existing path components and our parent does not exist,
721 823
 		// if yes call ourself recursive with the parent directory
722 824
 		if (($options & STREAM_MKDIR_RECURSIVE) && $parent_path != '/' && !$parent)
723 825
 		{
724
-			if (self::LOG_LEVEL > 1) error_log(__METHOD__." creating parents: $parent_path, $mode");
826
+			if (self::LOG_LEVEL > 1)
827
+			{
828
+				error_log(__METHOD__." creating parents: $parent_path, $mode");
829
+			}
725 830
 			if (!self::mkdir($parent_path,$mode,$options))
726 831
 			{
727 832
 				return false;
@@ -731,7 +836,10 @@  discard block
 block discarded – undo
731 836
 		if (!$parent || !Vfs::check_access($parent_path,Vfs::WRITABLE,$parent))
732 837
 		{
733 838
 			self::_remove_password($url);
734
-			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$mode,$options) permission denied!");
839
+			if (self::LOG_LEVEL)
840
+			{
841
+				error_log(__METHOD__."('$url',$mode,$options) permission denied!");
842
+			}
735 843
 			if (!($options & STREAM_REPORT_ERRORS))
736 844
 			{
737 845
 				trigger_error(__METHOD__."('$url',$mode,$options) permission denied!",E_USER_WARNING);
@@ -765,10 +873,13 @@  discard block
 block discarded – undo
765 873
 				'fs_dir'  => $parent['ino'],
766 874
 				'fs_active' => self::_pdo_boolean(true),
767 875
 				'fs_name' => self::limit_filename(Vfs::basename($path)),
768
-			)) && $stmt->fetchColumn() > 1)	// if there's more then one --> remove our new dir
876
+			)) && $stmt->fetchColumn() > 1)
877
+			{
878
+				// if there's more then one --> remove our new dir
769 879
 			{
770 880
 				self::$pdo->query('DELETE FROM '.self::TABLE.' WHERE fs_id='.$new_fs_id);
771 881
 			}
882
+			}
772 883
 		}
773 884
 		return $ok;
774 885
 	}
@@ -785,7 +896,10 @@  discard block
 block discarded – undo
785 896
 	 */
786 897
 	static function rmdir ( $url, $options )
787 898
 	{
788
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url)");
899
+		if (self::LOG_LEVEL > 1)
900
+		{
901
+			error_log(__METHOD__."($url)");
902
+		}
789 903
 
790 904
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
791 905
 		$parent = Vfs::dirname($path);
@@ -796,7 +910,10 @@  discard block
 block discarded – undo
796 910
 			self::_remove_password($url);
797 911
 			$err_msg = __METHOD__."($url,$options) ".(!$stat ? 'not found!' :
798 912
 				($stat['mime'] != self::DIR_MIME_TYPE ? 'not a directory!' : 'permission denied!'));
799
-			if (self::LOG_LEVEL) error_log($err_msg);
913
+			if (self::LOG_LEVEL)
914
+			{
915
+				error_log($err_msg);
916
+			}
800 917
 			if (!($options & STREAM_REPORT_ERRORS))
801 918
 			{
802 919
 				trigger_error($err_msg,E_USER_WARNING);
@@ -808,7 +925,10 @@  discard block
 block discarded – undo
808 925
 		if ($stmt->fetchColumn())
809 926
 		{
810 927
 			self::_remove_password($url);
811
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$options) dir is not empty!");
928
+			if (self::LOG_LEVEL)
929
+			{
930
+				error_log(__METHOD__."($url,$options) dir is not empty!");
931
+			}
812 932
 			if (!($options & STREAM_REPORT_ERRORS))
813 933
 			{
814 934
 				trigger_error(__METHOD__."('$url',$options) dir is not empty!",E_USER_WARNING);
@@ -840,7 +960,10 @@  discard block
 block discarded – undo
840 960
 	static function touch($url,$time=null,$atime=null)
841 961
 	{
842 962
 		unset($atime);	// not used
843
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $time)");
963
+		if (self::LOG_LEVEL > 1)
964
+		{
965
+			error_log(__METHOD__."($url, $time)");
966
+		}
844 967
 
845 968
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
846 969
 
@@ -876,25 +999,37 @@  discard block
 block discarded – undo
876 999
 	 */
877 1000
 	static function chown($url,$owner)
878 1001
 	{
879
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)");
1002
+		if (self::LOG_LEVEL > 1)
1003
+		{
1004
+			error_log(__METHOD__."($url,$owner)");
1005
+		}
880 1006
 
881 1007
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
882 1008
 
883 1009
 		if (!($stat = self::url_stat($path,0)))
884 1010
 		{
885
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!");
1011
+			if (self::LOG_LEVEL)
1012
+			{
1013
+				error_log(__METHOD__."($url,$owner) no such file or directory!");
1014
+			}
886 1015
 			trigger_error("No such file or directory $url !",E_USER_WARNING);
887 1016
 			return false;
888 1017
 		}
889 1018
 		if (!Vfs::$is_root)
890 1019
 		{
891
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only root can do that!");
1020
+			if (self::LOG_LEVEL)
1021
+			{
1022
+				error_log(__METHOD__."($url,$owner) only root can do that!");
1023
+			}
892 1024
 			trigger_error("Only root can do that!",E_USER_WARNING);
893 1025
 			return false;
894 1026
 		}
895
-		if ($owner < 0 || $owner && !$GLOBALS['egw']->accounts->id2name($owner))	// not a user (0 == root)
1027
+		if ($owner < 0 || $owner && !$GLOBALS['egw']->accounts->id2name($owner))
1028
+		{
1029
+			// not a user (0 == root)
896 1030
 		{
897 1031
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) user id!");
1032
+		}
898 1033
 			trigger_error(__METHOD__."($url,$owner) Unknown (numeric) user id!",E_USER_WARNING);
899 1034
 			//throw new Exception(__METHOD__."($url,$owner) Unknown (numeric) user id!");
900 1035
 			return false;
@@ -902,7 +1037,10 @@  discard block
 block discarded – undo
902 1037
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_uid=:fs_uid WHERE fs_id=:fs_id');
903 1038
 
904 1039
 		// update stat-cache
905
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
1040
+		if ($path != '/' && substr($path,-1) == '/')
1041
+		{
1042
+			$path = substr($path, 0, -1);
1043
+		}
906 1044
 		self::$stat_cache[$path]['fs_uid'] = $owner;
907 1045
 
908 1046
 		return $stmt->execute(array(
@@ -920,34 +1058,53 @@  discard block
 block discarded – undo
920 1058
 	 */
921 1059
 	static function chgrp($url,$owner)
922 1060
 	{
923
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$owner)");
1061
+		if (self::LOG_LEVEL > 1)
1062
+		{
1063
+			error_log(__METHOD__."($url,$owner)");
1064
+		}
924 1065
 
925 1066
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
926 1067
 
927 1068
 		if (!($stat = self::url_stat($path,0)))
928 1069
 		{
929
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) no such file or directory!");
1070
+			if (self::LOG_LEVEL)
1071
+			{
1072
+				error_log(__METHOD__."($url,$owner) no such file or directory!");
1073
+			}
930 1074
 			trigger_error("No such file or directory $url !",E_USER_WARNING);
931 1075
 			return false;
932 1076
 		}
933 1077
 		if (!Vfs::has_owner_rights($path,$stat))
934 1078
 		{
935
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) only owner or root can do that!");
1079
+			if (self::LOG_LEVEL)
1080
+			{
1081
+				error_log(__METHOD__."($url,$owner) only owner or root can do that!");
1082
+			}
936 1083
 			trigger_error("Only owner or root can do that!",E_USER_WARNING);
937 1084
 			return false;
938 1085
 		}
939
-		if ($owner < 0) $owner = -$owner;	// sqlfs uses a positiv group id's!
1086
+		if ($owner < 0)
1087
+		{
1088
+			$owner = -$owner;
1089
+		}
1090
+		// sqlfs uses a positiv group id's!
940 1091
 
941
-		if ($owner && !$GLOBALS['egw']->accounts->id2name(-$owner))	// not a group
1092
+		if ($owner && !$GLOBALS['egw']->accounts->id2name(-$owner))
1093
+		{
1094
+			// not a group
942 1095
 		{
943 1096
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url,$owner) unknown (numeric) group id!");
1097
+		}
944 1098
 			trigger_error("Unknown (numeric) group id!",E_USER_WARNING);
945 1099
 			return false;
946 1100
 		}
947 1101
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_gid=:fs_gid WHERE fs_id=:fs_id');
948 1102
 
949 1103
 		// update stat-cache
950
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
1104
+		if ($path != '/' && substr($path,-1) == '/')
1105
+		{
1106
+			$path = substr($path, 0, -1);
1107
+		}
951 1108
 		self::$stat_cache[$path]['fs_gid'] = $owner;
952 1109
 
953 1110
 		return $stmt->execute(array(
@@ -965,32 +1122,47 @@  discard block
 block discarded – undo
965 1122
 	 */
966 1123
 	static function chmod($url,$mode)
967 1124
 	{
968
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url, $mode)");
1125
+		if (self::LOG_LEVEL > 1)
1126
+		{
1127
+			error_log(__METHOD__."($url, $mode)");
1128
+		}
969 1129
 
970 1130
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
971 1131
 
972 1132
 		if (!($stat = self::url_stat($path,0)))
973 1133
 		{
974
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no such file or directory!");
1134
+			if (self::LOG_LEVEL)
1135
+			{
1136
+				error_log(__METHOD__."($url, $mode) no such file or directory!");
1137
+			}
975 1138
 			trigger_error("No such file or directory $url !",E_USER_WARNING);
976 1139
 			return false;
977 1140
 		}
978 1141
 		if (!Vfs::has_owner_rights($path,$stat))
979 1142
 		{
980
-			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) only owner or root can do that!");
1143
+			if (self::LOG_LEVEL)
1144
+			{
1145
+				error_log(__METHOD__."($url, $mode) only owner or root can do that!");
1146
+			}
981 1147
 			trigger_error("Only owner or root can do that!",E_USER_WARNING);
982 1148
 			return false;
983 1149
 		}
984
-		if (!is_numeric($mode))	// not a mode
1150
+		if (!is_numeric($mode))
1151
+		{
1152
+			// not a mode
985 1153
 		{
986 1154
 			if (self::LOG_LEVEL) error_log(__METHOD__."($url, $mode) no (numeric) mode!");
1155
+		}
987 1156
 			trigger_error("No (numeric) mode!",E_USER_WARNING);
988 1157
 			return false;
989 1158
 		}
990 1159
 		$stmt = self::$pdo->prepare('UPDATE '.self::TABLE.' SET fs_mode=:fs_mode WHERE fs_id=:fs_id');
991 1160
 
992 1161
 		// update stat cache
993
-		if ($path != '/' && substr($path,-1) == '/') $path = substr($path, 0, -1);
1162
+		if ($path != '/' && substr($path,-1) == '/')
1163
+		{
1164
+			$path = substr($path, 0, -1);
1165
+		}
994 1166
 		self::$stat_cache[$path]['fs_mode'] = ((int) $mode) & 0777;
995 1167
 
996 1168
 		return $stmt->execute(array(
@@ -1015,11 +1187,17 @@  discard block
 block discarded – undo
1015 1187
 
1016 1188
 		if (!($stat = self::url_stat($url,0)) || 		// dir not found
1017 1189
 			$stat['mime'] != self::DIR_MIME_TYPE ||		// no dir
1018
-			!Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat))	// no access
1190
+			!Vfs::check_access($url,Vfs::EXECUTABLE|Vfs::READABLE,$stat))
1191
+		{
1192
+			// no access
1019 1193
 		{
1020 1194
 			self::_remove_password($url);
1195
+		}
1021 1196
 			$msg = $stat['mime'] != self::DIR_MIME_TYPE ? "$url is no directory" : 'permission denied';
1022
-			if (self::LOG_LEVEL) error_log(__METHOD__."('$url',$options) $msg!");
1197
+			if (self::LOG_LEVEL)
1198
+			{
1199
+				error_log(__METHOD__."('$url',$options) $msg!");
1200
+			}
1023 1201
 			$this->opened_dir = null;
1024 1202
 			return false;
1025 1203
 		}
@@ -1028,7 +1206,10 @@  discard block
 block discarded – undo
1028 1206
 			' FROM '.self::TABLE.' WHERE fs_dir=? AND fs_active='.self::_pdo_boolean(true).
1029 1207
 			" ORDER BY fs_mime='httpd/unix-directory' DESC, fs_name ASC";
1030 1208
 		//if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1031
-		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__."($url,$options)".' */ '.$query;
1209
+		if (self::LOG_LEVEL > 2)
1210
+		{
1211
+			$query = '/* '.__METHOD__."($url,$options)".' */ '.$query;
1212
+		}
1032 1213
 
1033 1214
 		$stmt = self::$pdo->prepare($query);
1034 1215
 		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
@@ -1040,7 +1221,10 @@  discard block
 block discarded – undo
1040 1221
 				self::$stat_cache[Vfs::concat($path,$file['fs_name'])] = $file;
1041 1222
 			}
1042 1223
 		}
1043
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$options): ".implode(', ',$this->opened_dir));
1224
+		if (self::LOG_LEVEL > 1)
1225
+		{
1226
+			error_log(__METHOD__."($url,$options): ".implode(', ',$this->opened_dir));
1227
+		}
1044 1228
 		reset($this->opened_dir);
1045 1229
 
1046 1230
 		return true;
@@ -1079,9 +1263,16 @@  discard block
 block discarded – undo
1079 1263
 		if (is_null($max_subquery_depth))
1080 1264
 		{
1081 1265
 			$max_subquery_depth = $GLOBALS['egw_info']['server']['max_subquery_depth'];
1082
-			if (!$max_subquery_depth) $max_subquery_depth = 7;	// setting current default of 7, if nothing set
1266
+			if (!$max_subquery_depth)
1267
+			{
1268
+				$max_subquery_depth = 7;
1269
+			}
1270
+			// setting current default of 7, if nothing set
1271
+		}
1272
+		if (self::LOG_LEVEL > 1)
1273
+		{
1274
+			error_log(__METHOD__."('$url',$flags,$eacl_access)");
1083 1275
 		}
1084
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$flags,$eacl_access)");
1085 1276
 
1086 1277
 		$path = Vfs::parse_url($url,PHP_URL_PATH);
1087 1278
 
@@ -1147,7 +1338,10 @@  discard block
 block discarded – undo
1147 1338
 						if (!Vfs::$user)
1148 1339
 						{
1149 1340
 							self::_remove_password($url);
1150
-							if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$url',$flags) permission denied, no user-id and not root!");
1341
+							if (self::LOG_LEVEL > 1)
1342
+							{
1343
+								error_log(__METHOD__."('$url',$flags) permission denied, no user-id and not root!");
1344
+							}
1151 1345
 							return false;
1152 1346
 						}
1153 1347
 						$query .= ' AND '.self::_sql_readable();
@@ -1158,7 +1352,10 @@  discard block
 block discarded – undo
1158 1352
 					$query = str_replace('fs_name'.self::$case_sensitive_equal.'?','fs_name'.self::$case_sensitive_equal.self::$pdo->quote($name),$base_query).'('.$query.')';
1159 1353
 				}
1160 1354
 			}
1161
-			if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__."($url,$flags,$eacl_access)".' */ '.$query;
1355
+			if (self::LOG_LEVEL > 2)
1356
+			{
1357
+				$query = '/* '.__METHOD__."($url,$flags,$eacl_access)".' */ '.$query;
1358
+			}
1162 1359
 			//if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1163 1360
 
1164 1361
 			if (!($result = self::$pdo->query($query)) || !($info = $result->fetch(\PDO::FETCH_ASSOC)))
@@ -1181,12 +1378,18 @@  discard block
 block discarded – undo
1181 1378
 			$GLOBALS['egw_info']['server']['max_subquery_depth'] = --$max_subquery_depth;
1182 1379
 			error_log(__METHOD__."() decremented max_subquery_depth to $max_subquery_depth");
1183 1380
 			Api\Config::save_value('max_subquery_depth', $max_subquery_depth, 'phpgwapi');
1184
-			if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) $GLOBALS['egw']->invalidate_session_cache();
1381
+			if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))
1382
+			{
1383
+				$GLOBALS['egw']->invalidate_session_cache();
1384
+			}
1185 1385
 			return self::url_stat($url, $flags, $eacl_access);
1186 1386
 		}
1187 1387
 		self::$stat_cache[$path] = $info;
1188 1388
 
1189
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$flags)=".array2string($info));
1389
+		if (self::LOG_LEVEL > 1)
1390
+		{
1391
+			error_log(__METHOD__."($url,$flags)=".array2string($info));
1392
+		}
1190 1393
 		return self::_vfsinfo2stat($info);
1191 1394
 	}
1192 1395
 
@@ -1223,9 +1426,15 @@  discard block
 block discarded – undo
1223 1426
 	 */
1224 1427
 	function dir_readdir ( )
1225 1428
 	{
1226
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1429
+		if (self::LOG_LEVEL > 1)
1430
+		{
1431
+			error_log(__METHOD__."( )");
1432
+		}
1227 1433
 
1228
-		if (!is_array($this->opened_dir)) return false;
1434
+		if (!is_array($this->opened_dir))
1435
+		{
1436
+			return false;
1437
+		}
1229 1438
 
1230 1439
 		$file = current($this->opened_dir); next($this->opened_dir);
1231 1440
 
@@ -1242,9 +1451,15 @@  discard block
 block discarded – undo
1242 1451
 	 */
1243 1452
 	function dir_rewinddir ( )
1244 1453
 	{
1245
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1454
+		if (self::LOG_LEVEL > 1)
1455
+		{
1456
+			error_log(__METHOD__."( )");
1457
+		}
1246 1458
 
1247
-		if (!is_array($this->opened_dir)) return false;
1459
+		if (!is_array($this->opened_dir))
1460
+		{
1461
+			return false;
1462
+		}
1248 1463
 
1249 1464
 		reset($this->opened_dir);
1250 1465
 
@@ -1260,9 +1475,15 @@  discard block
 block discarded – undo
1260 1475
 	 */
1261 1476
 	function dir_closedir ( )
1262 1477
 	{
1263
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( )");
1478
+		if (self::LOG_LEVEL > 1)
1479
+		{
1480
+			error_log(__METHOD__."( )");
1481
+		}
1264 1482
 
1265
-		if (!is_array($this->opened_dir)) return false;
1483
+		if (!is_array($this->opened_dir))
1484
+		{
1485
+			return false;
1486
+		}
1266 1487
 
1267 1488
 		$this->opened_dir = null;
1268 1489
 
@@ -1281,7 +1502,10 @@  discard block
 block discarded – undo
1281 1502
 	{
1282 1503
 		$link = !($lstat = self::url_stat($path,STREAM_URL_STAT_LINK)) || is_null($lstat['readlink']) ? false : $lstat['readlink'];
1283 1504
 
1284
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = $link");
1505
+		if (self::LOG_LEVEL > 1)
1506
+		{
1507
+			error_log(__METHOD__."('$path') = $link");
1508
+		}
1285 1509
 
1286 1510
 		return $link;
1287 1511
 	}
@@ -1295,22 +1519,34 @@  discard block
 block discarded – undo
1295 1519
 	 */
1296 1520
 	static function symlink($target,$link)
1297 1521
 	{
1298
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$target','$link')");
1522
+		if (self::LOG_LEVEL > 1)
1523
+		{
1524
+			error_log(__METHOD__."('$target','$link')");
1525
+		}
1299 1526
 
1300 1527
 		if (self::url_stat($link,0))
1301 1528
 		{
1302
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') $link exists, returning false!");
1529
+			if (self::LOG_LEVEL > 0)
1530
+			{
1531
+				error_log(__METHOD__."('$target','$link') $link exists, returning false!");
1532
+			}
1303 1533
 			return false;	// $link already exists
1304 1534
 		}
1305 1535
 		if (!($dir = Vfs::dirname($link)) ||
1306 1536
 			!Vfs::check_access($dir,Vfs::WRITABLE,$dir_stat=static::url_stat($dir,0)))
1307 1537
 		{
1308
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$target','$link') returning false! (!is_writable('$dir'), dir_stat=".array2string($dir_stat).")");
1538
+			if (self::LOG_LEVEL > 0)
1539
+			{
1540
+				error_log(__METHOD__."('$target','$link') returning false! (!is_writable('$dir'), dir_stat=".array2string($dir_stat).")");
1541
+			}
1309 1542
 			return false;	// parent dir does not exist or is not writable
1310 1543
 		}
1311 1544
 		$query = 'INSERT INTO '.self::TABLE.' (fs_name,fs_dir,fs_mode,fs_uid,fs_gid,fs_created,fs_modified,fs_creator,fs_mime,fs_size,fs_link'.
1312 1545
 			') VALUES (:fs_name,:fs_dir,:fs_mode,:fs_uid,:fs_gid,:fs_created,:fs_modified,:fs_creator,:fs_mime,:fs_size,:fs_link)';
1313
-		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1546
+		if (self::LOG_LEVEL > 2)
1547
+		{
1548
+			$query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1549
+		}
1314 1550
 		$stmt = self::$pdo->prepare($query);
1315 1551
 		unset(self::$stat_cache[Vfs::parse_url($link,PHP_URL_PATH)]);
1316 1552
 
@@ -1358,7 +1594,10 @@  discard block
 block discarded – undo
1358 1594
 				break;
1359 1595
 			}
1360 1596
 		}
1361
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$check) ".($access?"access granted by $path=$rights":'no access!!!'));
1597
+		if (self::LOG_LEVEL > 1)
1598
+		{
1599
+			error_log(__METHOD__."($url,$check) ".($access?"access granted by $path=$rights":'no access!!!'));
1600
+		}
1362 1601
 		return $access;
1363 1602
 	}
1364 1603
 
@@ -1386,11 +1625,15 @@  discard block
 block discarded – undo
1386 1625
 			}
1387 1626
 		}
1388 1627
 		// sort by length descending, to allow more specific pathes to have precedence
1389
-		uksort(self::$extended_acl, function($a,$b) {
1628
+		uksort(self::$extended_acl, function($a,$b)
1629
+		{
1390 1630
 			return strlen($b)-strlen($a);
1391 1631
 		});
1392 1632
 		Api\Cache::setSession(self::EACL_APPNAME, 'extended_acl', self::$extended_acl);
1393
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'() '.array2string(self::$extended_acl));
1633
+		if (self::LOG_LEVEL > 1)
1634
+		{
1635
+			error_log(__METHOD__.'() '.array2string(self::$extended_acl));
1636
+		}
1394 1637
 	}
1395 1638
 
1396 1639
 	/**
@@ -1419,12 +1662,18 @@  discard block
 block discarded – undo
1419 1662
 		{
1420 1663
 			if (!($stat = self::url_stat($path,0)))
1421 1664
 			{
1422
-				if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!");
1665
+				if (self::LOG_LEVEL)
1666
+				{
1667
+					error_log(__METHOD__."($path,$rights,$owner,$fs_id) no such file or directory!");
1668
+				}
1423 1669
 				return false;	// $path not found
1424 1670
 			}
1425
-			if (!Vfs::has_owner_rights($path,$stat))		// not group dir and user is eGW admin
1671
+			if (!Vfs::has_owner_rights($path,$stat))
1672
+			{
1673
+				// not group dir and user is eGW admin
1426 1674
 			{
1427 1675
 				if (self::LOG_LEVEL) error_log(__METHOD__."($path,$rights,$owner,$fs_id) permission denied!");
1676
+			}
1428 1677
 				return false;	// permission denied
1429 1678
 			}
1430 1679
 			$fs_id = $stat['ino'];
@@ -1457,7 +1706,10 @@  discard block
 block discarded – undo
1457 1706
 		{
1458 1707
 			Api\Cache::setSession(self::EACL_APPNAME, 'extended_acl', self::$extended_acl);
1459 1708
 		}
1460
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$rights,$owner,$fs_id)=".(int)$ret);
1709
+		if (self::LOG_LEVEL > 1)
1710
+		{
1711
+			error_log(__METHOD__."($path,$rights,$owner,$fs_id)=".(int)$ret);
1712
+		}
1461 1713
 		return $ret;
1462 1714
 	}
1463 1715
 
@@ -1491,7 +1743,8 @@  discard block
 block discarded – undo
1491 1743
 			$eacls = array_merge((array)self::get_eacl($path),$eacls);
1492 1744
 		}
1493 1745
 		// sort by length descending, to show precedence
1494
-		usort($eacls, function($a, $b) {
1746
+		usort($eacls, function($a, $b)
1747
+		{
1495 1748
 			return strlen($b['path']) - strlen($a['path']);
1496 1749
 		});
1497 1750
 		//error_log(__METHOD__."('$_path') returning ".array2string($eacls));
@@ -1509,7 +1762,10 @@  discard block
 block discarded – undo
1509 1762
 	 */
1510 1763
 	static function id2path($fs_ids)
1511 1764
 	{
1512
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')');
1765
+		if (self::LOG_LEVEL > 1)
1766
+		{
1767
+			error_log(__METHOD__.'('.array2string($fs_ids).')');
1768
+		}
1513 1769
 		$ids = (array)$fs_ids;
1514 1770
 		$pathes = array();
1515 1771
 		// first check our stat-cache for the ids
@@ -1521,16 +1777,26 @@  discard block
 block discarded – undo
1521 1777
 				unset($ids[$key]);
1522 1778
 				if (!$ids)
1523 1779
 				{
1524
-					if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes).' *from stat_cache*');
1780
+					if (self::LOG_LEVEL > 1)
1781
+					{
1782
+						error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes).' *from stat_cache*');
1783
+					}
1525 1784
 					return is_array($fs_ids) ? $pathes : array_shift($pathes);
1526 1785
 				}
1527 1786
 			}
1528 1787
 		}
1529 1788
 		// now search via the database
1530
-		if (count($ids) > 1) array_map(function(&$v) { $v = (int)$v; },$ids);
1789
+		if (count($ids) > 1)
1790
+		{
1791
+			array_map(function(&$v) { $v = (int)$v;
1792
+		}
1793
+		},$ids);
1531 1794
 		$query = 'SELECT fs_id,fs_dir,fs_name FROM '.self::TABLE.' WHERE fs_id'.
1532 1795
 			(count($ids) == 1 ? '='.(int)$ids[0] : ' IN ('.implode(',',$ids).')');
1533
-		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1796
+		if (self::LOG_LEVEL > 2)
1797
+		{
1798
+			$query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
1799
+		}
1534 1800
 
1535 1801
 		if (!is_object(self::$pdo))
1536 1802
 		{
@@ -1557,14 +1823,20 @@  discard block
 block discarded – undo
1557 1823
 		{
1558 1824
 			return false;	// parent not found, should never happen ...
1559 1825
 		}
1560
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__." trying foreach with:".print_r($rows,true)."#");
1826
+		if (self::LOG_LEVEL > 1)
1827
+		{
1828
+			error_log(__METHOD__." trying foreach with:".print_r($rows,true)."#");
1829
+		}
1561 1830
 		foreach((array)$rows as $fs_id => $row)
1562 1831
 		{
1563 1832
 			$parent = $row['fs_dir'] > 1 ? $parents[$row['fs_dir']] : '';
1564 1833
 
1565 1834
 			$pathes[$fs_id] = $parent . '/' . $row['fs_name'];
1566 1835
 		}
1567
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes));
1836
+		if (self::LOG_LEVEL > 1)
1837
+		{
1838
+			error_log(__METHOD__.'('.array2string($fs_ids).')='.array2string($pathes));
1839
+		}
1568 1840
 		return is_array($fs_ids) ? $pathes : array_shift($pathes);
1569 1841
 	}
1570 1842
 
@@ -1620,7 +1892,10 @@  discard block
 block discarded – undo
1620 1892
 			'mime'  => $info['fs_mime'],
1621 1893
 			'readlink' => $info['fs_link'],
1622 1894
 		);
1623
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($info[name]) = ".array2string($stat));
1895
+		if (self::LOG_LEVEL > 1)
1896
+		{
1897
+			error_log(__METHOD__."($info[name]) = ".array2string($stat));
1898
+		}
1624 1899
 		return $stat;
1625 1900
 	}
1626 1901
 
@@ -1762,13 +2037,16 @@  discard block
 block discarded – undo
1762 2037
 		}
1763 2038
 		if (!isset($GLOBALS['egw_info']['server']['files_dir']))
1764 2039
 		{
1765
-			if (is_object($GLOBALS['egw_setup']->db))	// if we run under setup, query the db for the files dir
2040
+			if (is_object($GLOBALS['egw_setup']->db))
2041
+			{
2042
+				// if we run under setup, query the db for the files dir
1766 2043
 			{
1767 2044
 				$GLOBALS['egw_info']['server']['files_dir'] = $GLOBALS['egw_setup']->db->select('egw_config','config_value',array(
1768 2045
 					'config_name' => 'files_dir',
1769 2046
 					'config_app' => 'phpgwapi',
1770 2047
 				),__LINE__,__FILE__)->fetchColumn();
1771 2048
 			}
2049
+			}
1772 2050
 		}
1773 2051
 		if (!$GLOBALS['egw_info']['server']['files_dir'])
1774 2052
 		{
@@ -1780,7 +2058,11 @@  discard block
 block discarded – undo
1780 2058
 		{
1781 2059
 			$hash[] = sprintf('%02d',$n % self::HASH_MAX);
1782 2060
 		}
1783
-		if (!$hash) $hash[] = '00';		// we need at least one directory, to not conflict with the dir-names
2061
+		if (!$hash)
2062
+		{
2063
+			$hash[] = '00';
2064
+		}
2065
+		// we need at least one directory, to not conflict with the dir-names
1784 2066
 		array_unshift($hash,$id);
1785 2067
 
1786 2068
 		$path = '/sqlfs/'.implode('/',array_reverse($hash));
@@ -1842,7 +2124,10 @@  discard block
 block discarded – undo
1842 2124
 	 */
1843 2125
 	static function proppatch($path,array $props)
1844 2126
 	{
1845
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."(".array2string($path).','.array2string($props));
2127
+		if (self::LOG_LEVEL > 1)
2128
+		{
2129
+			error_log(__METHOD__."(".array2string($path).','.array2string($props));
2130
+		}
1846 2131
 		if (!is_numeric($path))
1847 2132
 		{
1848 2133
 			if (!($stat = self::url_stat($path,0)))
@@ -1862,13 +2147,19 @@  discard block
 block discarded – undo
1862 2147
 		$ins_stmt = $del_stmt = null;
1863 2148
 		foreach($props as &$prop)
1864 2149
 		{
1865
-			if (!isset($prop['ns'])) $prop['ns'] = Vfs::DEFAULT_PROP_NAMESPACE;
2150
+			if (!isset($prop['ns']))
2151
+			{
2152
+				$prop['ns'] = Vfs::DEFAULT_PROP_NAMESPACE;
2153
+			}
1866 2154
 
1867
-			if (!isset($prop['val']) || self::$pdo_type != 'mysql')	// for non mysql, we have to delete the prop anyway, as there's no REPLACE!
2155
+			if (!isset($prop['val']) || self::$pdo_type != 'mysql')
2156
+			{
2157
+				// for non mysql, we have to delete the prop anyway, as there's no REPLACE!
1868 2158
 			{
1869 2159
 				if (!isset($del_stmt))
1870 2160
 				{
1871 2161
 					$del_stmt = self::$pdo->prepare('DELETE FROM '.self::PROPS_TABLE.' WHERE fs_id=:fs_id AND prop_namespace=:prop_namespace AND prop_name=:prop_name');
2162
+			}
1872 2163
 				}
1873 2164
 				$del_stmt->execute(array(
1874 2165
 					'fs_id'          => $id,
@@ -1914,17 +2205,27 @@  discard block
 block discarded – undo
1914 2205
 			{
1915 2206
 				if (!($stat = self::url_stat($id,0)))
1916 2207
 				{
1917
-					if (self::LOG_LEVEL) error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!");
2208
+					if (self::LOG_LEVEL)
2209
+					{
2210
+						error_log(__METHOD__."(".array2string($path_ids).",$ns) path '$id' not found!");
2211
+					}
1918 2212
 					return false;
1919 2213
 				}
1920 2214
 				$id = $stat['ino'];
1921 2215
 			}
1922 2216
 		}
1923
-		if (count($ids) >= 1) array_map(function(&$v) { $v = (int)$v; },$ids);
2217
+		if (count($ids) >= 1)
2218
+		{
2219
+			array_map(function(&$v) { $v = (int)$v;
2220
+		}
2221
+		},$ids);
1924 2222
 		$query = 'SELECT * FROM '.self::PROPS_TABLE.' WHERE (fs_id'.
1925 2223
 			(count($ids) == 1 ? '='.(int)implode('',$ids) : ' IN ('.implode(',',$ids).')').')'.
1926 2224
 			(!is_null($ns) ? ' AND prop_namespace=?' : '');
1927
-		if (self::LOG_LEVEL > 2) $query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
2225
+		if (self::LOG_LEVEL > 2)
2226
+		{
2227
+			$query = '/* '.__METHOD__.': '.__LINE__.' */ '.$query;
2228
+		}
1928 2229
 
1929 2230
 		$stmt = self::$pdo->prepare($query);
1930 2231
 		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
@@ -1943,11 +2244,14 @@  discard block
 block discarded – undo
1943 2244
 		{
1944 2245
 			$props = $props[$row['fs_id']] ? $props[$row['fs_id']] : array();	// return empty array for no props
1945 2246
 		}
1946
-		elseif ($props && isset($stat))	// need to map fs_id's to pathes
2247
+		elseif ($props && isset($stat))
2248
+		{
2249
+			// need to map fs_id's to pathes
1947 2250
 		{
1948 2251
 			foreach(self::id2path(array_keys($props)) as $id => $path)
1949 2252
 			{
1950 2253
 				$props[$path] =& $props[$id];
2254
+		}
1951 2255
 				unset($props[$id]);
1952 2256
 			}
1953 2257
 		}
Please login to merge, or discard this patch.
api/src/Vfs/StreamWrapper.php 4 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 	 *
455 455
 	 * If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now.
456 456
 	 *
457
-	 * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
457
+	 * @return boolean TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
458 458
 	 */
459 459
 	function stream_flush ( )
460 460
 	{
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
 	 * This method is called immediately when your stream object is created for examining directory contents with opendir().
857 857
 	 *
858 858
 	 * @param string $path URL that was passed to opendir() and that this object is expected to explore.
859
-	 * @return booelan
859
+	 * @return boolean
860 860
 	 */
861 861
 	function dir_opendir ( $path, $options )
862 862
 	{
@@ -1213,7 +1213,7 @@  discard block
 block discarded – undo
1213 1213
 	 * It should reset the output generated by dir_readdir(). i.e.:
1214 1214
 	 * The next call to dir_readdir() should return the first entry in the location returned by dir_opendir().
1215 1215
 	 *
1216
-	 * @return boolean
1216
+	 * @return boolean|null
1217 1217
 	 */
1218 1218
 	function dir_rewinddir ( )
1219 1219
 	{
@@ -1227,7 +1227,7 @@  discard block
 block discarded – undo
1227 1227
 	 *
1228 1228
 	 * You should release any resources which were locked or allocated during the opening and use of the directory stream.
1229 1229
 	 *
1230
-	 * @return boolean
1230
+	 * @return boolean|null
1231 1231
 	 */
1232 1232
 	function dir_closedir ( )
1233 1233
 	{
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -411,10 +411,10 @@  discard block
 block discarded – undo
411 411
  	 * Important: PHP 5.0 introduced a bug that wasn't fixed until 5.1: the return value has to be the oposite!
412 412
  	 *
413 413
  	 * if(version_compare(PHP_VERSION,'5.0','>=') && version_compare(PHP_VERSION,'5.1','<'))
414
-  	 * {
414
+ 	 * {
415 415
  	 * 		$eof = !$eof;
416 416
  	 * }
417
-  	 *
417
+ 	 *
418 418
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
419 419
  	 */
420 420
 	function stream_eof ( )
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url'): ".function_backtrace(1));
1054 1054
 
1055 1055
 		while (($rel_path = Vfs::basename($url).($rel_path ? '/'.$rel_path : '')) &&
1056
-		       ($url = Vfs::dirname($url)))
1056
+			   ($url = Vfs::dirname($url)))
1057 1057
 		{
1058 1058
 			if (($stat = self::url_stat($url,0,false,false)))
1059 1059
 			{
Please login to merge, or discard this patch.
Spacing   +149 added lines, -150 removed lines patch added patch discarded remove patch
@@ -157,14 +157,14 @@  discard block
 block discarded – undo
157 157
 	 * @param array|boolean &$stat=null on return: stat of existing file or false for non-existing files
158 158
 	 * @return string|boolean false if the url cant be resolved, should not happen if fstab has a root entry
159 159
 	 */
160
-	static function resolve_url_symlinks($_path,$file_exists=true,$resolve_last_symlink=true,&$stat=null)
160
+	static function resolve_url_symlinks($_path, $file_exists = true, $resolve_last_symlink = true, &$stat = null)
161 161
 	{
162 162
 		$path = self::get_path($_path);
163 163
 
164
-		if (!($stat = self::url_stat($path,$resolve_last_symlink?0:STREAM_URL_STAT_LINK)) && !$file_exists)
164
+		if (!($stat = self::url_stat($path, $resolve_last_symlink ? 0 : STREAM_URL_STAT_LINK)) && !$file_exists)
165 165
 		{
166 166
 			$url = null;
167
-			$stat = self::check_symlink_components($path,0,$url);
167
+			$stat = self::check_symlink_components($path, 0, $url);
168 168
 			if (self::LOG_LEVEL > 1) $log = " (check_symlink_components('$path',0,'$url') = $stat)";
169 169
 		}
170 170
 		else
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
 			$url = $stat['url'];
173 173
 		}
174 174
 		// if the url resolves to a symlink to the vfs, resolve this vfs:// url direct
175
-		if ($url && self::parse_url($url,PHP_URL_SCHEME) == self::SCHEME)
175
+		if ($url && self::parse_url($url, PHP_URL_SCHEME) == self::SCHEME)
176 176
 		{
177
-			$url = self::resolve_url(self::parse_url($url,PHP_URL_PATH));
177
+			$url = self::resolve_url(self::parse_url($url, PHP_URL_PATH));
178 178
 		}
179 179
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,file_exists=$file_exists,resolve_last_symlink=$resolve_last_symlink) = '$url'$log");
180 180
 		return $url;
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 * @param boolean $fix_url_query =false true append relativ path to url query parameter, default not
198 198
 	 * @return string|boolean false if the url cant be resolved, should not happen if fstab has a root entry
199 199
 	 */
200
-	static function resolve_url($_path,$do_symlink=true,$use_symlinkcache=true,$replace_user_pass_host=true,$fix_url_query=false)
200
+	static function resolve_url($_path, $do_symlink = true, $use_symlinkcache = true, $replace_user_pass_host = true, $fix_url_query = false)
201 201
 	{
202 202
 		$path = self::get_path($_path);
203 203
 
@@ -210,52 +210,52 @@  discard block
 block discarded – undo
210 210
 		// check if we can already resolve path (or a part of it) with a known symlinks
211 211
 		if ($use_symlinkcache)
212 212
 		{
213
-			$path = self::symlinkCache_resolve($path,$do_symlink);
213
+			$path = self::symlinkCache_resolve($path, $do_symlink);
214 214
 		}
215 215
 		// setting default user, passwd and domain, if it's not contained int the url
216
-		static $defaults=null;
216
+		static $defaults = null;
217 217
 		if (is_null($defaults))
218 218
 		{
219 219
 			$defaults = array(
220 220
 				'user' => $GLOBALS['egw_info']['user']['account_lid'],
221 221
 				'pass' => urlencode($GLOBALS['egw_info']['user']['passwd']),
222 222
 				'host' => $GLOBALS['egw_info']['user']['domain'],
223
-				'home' => str_replace(array('\\\\','\\'),array('','/'),$GLOBALS['egw_info']['user']['homedirectory']),
223
+				'home' => str_replace(array('\\\\', '\\'), array('', '/'), $GLOBALS['egw_info']['user']['homedirectory']),
224 224
 			);
225 225
 		}
226
-		$parts = array_merge(self::parse_url($path),$defaults);
227
-		if (!$parts['host']) $parts['host'] = 'default';	// otherwise we get an invalid url (scheme:///path/to/something)!
226
+		$parts = array_merge(self::parse_url($path), $defaults);
227
+		if (!$parts['host']) $parts['host'] = 'default'; // otherwise we get an invalid url (scheme:///path/to/something)!
228 228
 
229 229
 		if (!empty($parts['scheme']) && $parts['scheme'] != self::SCHEME)
230 230
 		{
231 231
 			if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = '$path' (path is already an url)");
232
-			return $path;	// path is already a non-vfs url --> nothing to do
232
+			return $path; // path is already a non-vfs url --> nothing to do
233 233
 		}
234 234
 		if (empty($parts['path'])) $parts['path'] = '/';
235 235
 
236
-		foreach(array_reverse(self::$fstab) as $mounted => $url)
236
+		foreach (array_reverse(self::$fstab) as $mounted => $url)
237 237
 		{
238
-			if ($mounted == '/' || $mounted == $parts['path'] || $mounted.'/' == substr($parts['path'],0,strlen($mounted)+1))
238
+			if ($mounted == '/' || $mounted == $parts['path'] || $mounted.'/' == substr($parts['path'], 0, strlen($mounted) + 1))
239 239
 			{
240
-				$scheme = self::parse_url($url,PHP_URL_SCHEME);
241
-				if (is_null(self::$wrappers) || !in_array($scheme,self::$wrappers))
240
+				$scheme = self::parse_url($url, PHP_URL_SCHEME);
241
+				if (is_null(self::$wrappers) || !in_array($scheme, self::$wrappers))
242 242
 				{
243 243
 					self::load_wrapper($scheme);
244 244
 				}
245
-				if (($relative = substr($parts['path'],strlen($mounted))))
245
+				if (($relative = substr($parts['path'], strlen($mounted))))
246 246
 				{
247
-					$url = Vfs::concat($url,$relative);
247
+					$url = Vfs::concat($url, $relative);
248 248
 				}
249 249
 				// if url contains url parameter, eg. from filesystem streamwrapper, we need to append relative path here too
250 250
 				$matches = null;
251 251
 				if ($fix_url_query && preg_match('|([?&]url=)([^&]+)|', $url, $matches))
252 252
 				{
253
-					$url = str_replace($matches[0], $matches[1].Vfs::concat($matches[2], substr($parts['path'],strlen($mounted))), $url);
253
+					$url = str_replace($matches[0], $matches[1].Vfs::concat($matches[2], substr($parts['path'], strlen($mounted))), $url);
254 254
 				}
255 255
 
256 256
 				if ($replace_user_pass_host)
257 257
 				{
258
-					$url = str_replace(array('$user','$pass','$host','$home'),array($parts['user'],$parts['pass'],$parts['host'],$parts['home']),$url);
258
+					$url = str_replace(array('$user', '$pass', '$host', '$home'), array($parts['user'], $parts['pass'], $parts['host'], $parts['home']), $url);
259 259
 				}
260 260
 				if ($parts['query']) $url .= '?'.$parts['query'];
261 261
 				if ($parts['fragment']) $url .= '#'.$parts['fragment'];
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 			}
269 269
 		}
270 270
 		if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$path') can't resolve path!\n");
271
-		trigger_error(__METHOD__."($path) can't resolve path!\n",E_USER_WARNING);
271
+		trigger_error(__METHOD__."($path) can't resolve path!\n", E_USER_WARNING);
272 272
 		return false;
273 273
 	}
274 274
 
@@ -280,10 +280,10 @@  discard block
 block discarded – undo
280 280
 	 */
281 281
 	static function mount_url($fullurl)
282 282
 	{
283
-		foreach(array_reverse(self::$fstab) as $url)
283
+		foreach (array_reverse(self::$fstab) as $url)
284 284
 		{
285
-			list($url_no_query) = explode('?',$url);
286
-			if (substr($fullurl,0,1+strlen($url_no_query)) === $url_no_query.'/')
285
+			list($url_no_query) = explode('?', $url);
286
+			if (substr($fullurl, 0, 1 + strlen($url_no_query)) === $url_no_query.'/')
287 287
 			{
288 288
 				return $url;
289 289
 			}
@@ -310,13 +310,13 @@  discard block
 block discarded – undo
310 310
 	 * @param string $opened_path full path of the file/resource, if the open was successfull and STREAM_USE_PATH was set
311 311
 	 * @return boolean true if the ressource was opened successful, otherwise false
312 312
 	 */
313
-	function stream_open ( $path, $mode, $options, &$opened_path )
313
+	function stream_open($path, $mode, $options, &$opened_path)
314 314
 	{
315
-		unset($options,$opened_path);	// not used but required by function signature
315
+		unset($options, $opened_path); // not used but required by function signature
316 316
 		$this->opened_stream = null;
317 317
 
318 318
 		$stat = null;
319
-		if (!($url = self::resolve_url_symlinks($path,$mode[0]=='r',true,$stat)))
319
+		if (!($url = self::resolve_url_symlinks($path, $mode[0] == 'r', true, $stat)))
320 320
 		{
321 321
 			return false;
322 322
 		}
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	 *
352 352
 	 * VFS calls either "vfs_read", "vfs_added" or "vfs_modified" hook
353 353
 	 */
354
-	function stream_close ( )
354
+	function stream_close( )
355 355
 	{
356 356
 		$ret = fclose($this->opened_stream);
357 357
 		// clear PHP's stat cache, it contains wrong size of just closed file,
@@ -361,12 +361,11 @@  discard block
 block discarded – undo
361 361
 		if (isset($GLOBALS['egw']) && isset($GLOBALS['egw']->hooks))
362 362
 		{
363 363
 			Api\Hooks::process(array(
364
-				'location' => str_replace('b','',$this->opened_stream_mode) == 'r' ? 'vfs_read' :
365
-					($this->opened_stream_is_new ? 'vfs_added' : 'vfs_modified'),
364
+				'location' => str_replace('b', '', $this->opened_stream_mode) == 'r' ? 'vfs_read' : ($this->opened_stream_is_new ? 'vfs_added' : 'vfs_modified'),
366 365
 				'path' => $this->opened_stream_path,
367 366
 				'mode' => $this->opened_stream_mode,
368 367
 				'url'  => $this->opened_stream_url,
369
-			),'',true);
368
+			), '', true);
370 369
 		}
371 370
 		$this->opened_stream = $this->opened_stream_mode = $this->opened_stream_path = $this->opened_stream_url = $this->opened_stream_is_new = null;
372 371
 
@@ -384,9 +383,9 @@  discard block
 block discarded – undo
384 383
 	 * @param int $count
385 384
 	 * @return string/false up to count bytes read or false on EOF
386 385
 	 */
387
-	function stream_read ( $count )
386
+	function stream_read($count)
388 387
 	{
389
-		return fread($this->opened_stream,$count);
388
+		return fread($this->opened_stream, $count);
390 389
 	}
391 390
 
392 391
 	/**
@@ -400,9 +399,9 @@  discard block
 block discarded – undo
400 399
 	 * @param string $data
401 400
 	 * @return integer
402 401
 	 */
403
-	function stream_write ( $data )
402
+	function stream_write($data)
404 403
 	{
405
-		return fwrite($this->opened_stream,$data);
404
+		return fwrite($this->opened_stream, $data);
406 405
 	}
407 406
 
408 407
  	/**
@@ -417,7 +416,7 @@  discard block
 block discarded – undo
417 416
   	 *
418 417
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
419 418
  	 */
420
-	function stream_eof ( )
419
+	function stream_eof( )
421 420
 	{
422 421
 		return feof($this->opened_stream);
423 422
 	}
@@ -427,7 +426,7 @@  discard block
 block discarded – undo
427 426
 	 *
428 427
 	 * @return integer current read/write position of the stream
429 428
 	 */
430
- 	function stream_tell ( )
429
+ 	function stream_tell( )
431 430
  	{
432 431
  		return ftell($this->opened_stream);
433 432
  	}
@@ -444,9 +443,9 @@  discard block
 block discarded – undo
444 443
  	 * 							SEEK_END - 2 - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.)
445 444
  	 * @return boolean TRUE if the position was updated, FALSE otherwise.
446 445
  	 */
447
-	function stream_seek ( $offset, $whence )
446
+	function stream_seek($offset, $whence)
448 447
 	{
449
-		return !fseek($this->opened_stream,$offset,$whence);	// fseek returns 0 on success and -1 on failure
448
+		return !fseek($this->opened_stream, $offset, $whence); // fseek returns 0 on success and -1 on failure
450 449
 	}
451 450
 
452 451
 	/**
@@ -456,7 +455,7 @@  discard block
 block discarded – undo
456 455
 	 *
457 456
 	 * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
458 457
 	 */
459
-	function stream_flush ( )
458
+	function stream_flush( )
460 459
 	{
461 460
 		return fflush($this->opened_stream);
462 461
 	}
@@ -475,7 +474,7 @@  discard block
 block discarded – undo
475 474
 	 *
476 475
 	 * @return array containing the same values as appropriate for the stream.
477 476
 	 */
478
-	function stream_stat ( )
477
+	function stream_stat( )
479 478
 	{
480 479
 		return fstat($this->opened_stream);
481 480
 	}
@@ -489,9 +488,9 @@  discard block
 block discarded – undo
489 488
 	 * @param string $path
490 489
 	 * @return boolean TRUE on success or FALSE on failure
491 490
 	 */
492
-	static function unlink ( $path )
491
+	static function unlink($path)
493 492
 	{
494
-		if (!($url = self::resolve_url_symlinks($path,true,false)))	// true,false file need to exist, but do not resolve last component
493
+		if (!($url = self::resolve_url_symlinks($path, true, false)))	// true,false file need to exist, but do not resolve last component
495 494
 		{
496 495
 			return false;
497 496
 		}
@@ -512,7 +511,7 @@  discard block
 block discarded – undo
512 511
 				'path' => $path[0] == '/' ? $path : self::parse_url($path, PHP_URL_PATH),
513 512
 				'url'  => $url,
514 513
 				'stat' => $stat,
515
-			),'',true);
514
+			), '', true);
516 515
 		}
517 516
 		return $ok;
518 517
 	}
@@ -529,22 +528,22 @@  discard block
 block discarded – undo
529 528
 	 * @param string $path_to
530 529
 	 * @return boolean TRUE on success or FALSE on failure
531 530
 	 */
532
-	static function rename ( $path_from, $path_to )
531
+	static function rename($path_from, $path_to)
533 532
 	{
534
-		if (!($url_from = self::resolve_url_symlinks($path_from,true,false)) ||
535
-			!($url_to = self::resolve_url_symlinks($path_to,false)))
533
+		if (!($url_from = self::resolve_url_symlinks($path_from, true, false)) ||
534
+			!($url_to = self::resolve_url_symlinks($path_to, false)))
536 535
 		{
537 536
 			return false;
538 537
 		}
539 538
 		// if file is moved from one filesystem / wrapper to an other --> copy it (rename fails cross wrappers)
540
-		if (self::parse_url($url_from,PHP_URL_SCHEME) == self::parse_url($url_to,PHP_URL_SCHEME))
539
+		if (self::parse_url($url_from, PHP_URL_SCHEME) == self::parse_url($url_to, PHP_URL_SCHEME))
541 540
 		{
542 541
 			self::symlinkCache_remove($path_from);
543
-			$ret = rename($url_from,$url_to);
542
+			$ret = rename($url_from, $url_to);
544 543
 		}
545
-		elseif (($from = fopen($url_from,'r')) && ($to = fopen($url_to,'w')))
544
+		elseif (($from = fopen($url_from, 'r')) && ($to = fopen($url_to, 'w')))
546 545
 		{
547
-			$ret = stream_copy_to_stream($from,$to) !== false;
546
+			$ret = stream_copy_to_stream($from, $to) !== false;
548 547
 			fclose($from);
549 548
 			fclose($to);
550 549
 			if ($ret) self::unlink($path_from);
@@ -566,7 +565,7 @@  discard block
 block discarded – undo
566 565
 				'to' => $path_to[0] == '/' ? $path_to : self::parse_url($path_to, PHP_URL_PATH),
567 566
 				'url_from' => $url_from,
568 567
 				'url_to' => $url_to,
569
-			),'',true);
568
+			), '', true);
570 569
 		}
571 570
 		return $ret;
572 571
 	}
@@ -582,13 +581,13 @@  discard block
 block discarded – undo
582 581
 	 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
583 582
 	 * @return boolean TRUE on success or FALSE on failure
584 583
 	 */
585
-	static function mkdir ( $path, $mode, $options )
584
+	static function mkdir($path, $mode, $options)
586 585
 	{
587
-		if (!($url = self::resolve_url_symlinks($path,false)))	// false = directory does not need to exists
586
+		if (!($url = self::resolve_url_symlinks($path, false)))	// false = directory does not need to exists
588 587
 		{
589 588
 			return false;
590 589
 		}
591
-		$ret = mkdir($url,$mode,$options);
590
+		$ret = mkdir($url, $mode, $options);
592 591
 
593 592
 		// call "vfs_mkdir" hook
594 593
 		if ($ret && isset($GLOBALS['egw']) && isset($GLOBALS['egw']->hooks))
@@ -597,7 +596,7 @@  discard block
 block discarded – undo
597 596
 				'location' => 'vfs_mkdir',
598 597
 				'path' => $path[0] == '/' ? $path : self::parse_url($path, PHP_URL_PATH),
599 598
 				'url' => $url,
600
-			),'',true);
599
+			), '', true);
601 600
 		}
602 601
 		return $ret;
603 602
 	}
@@ -612,9 +611,9 @@  discard block
 block discarded – undo
612 611
 	 * @param int $options Possible values include STREAM_REPORT_ERRORS.
613 612
 	 * @return boolean TRUE on success or FALSE on failure.
614 613
 	 */
615
-	static function rmdir ( $path, $options )
614
+	static function rmdir($path, $options)
616 615
 	{
617
-		unset($options);	// not uses but required by function signature
616
+		unset($options); // not uses but required by function signature
618 617
 		if (!($url = self::resolve_url_symlinks($path)))
619 618
 		{
620 619
 			return false;
@@ -636,7 +635,7 @@  discard block
 block discarded – undo
636 635
 				'path' => $path[0] == '/' ? $path : self::parse_url($path, PHP_URL_PATH),
637 636
 				'url' => $url,
638 637
 				'stat' => $stat,
639
-			),'',true);
638
+			), '', true);
640 639
 		}
641 640
 		return $ok;
642 641
 	}
@@ -653,60 +652,60 @@  discard block
 block discarded – undo
653 652
 	 * @param int $path_param_key =0 key in params containing the path, default 0
654 653
 	 * @return mixed return value of backend or false if function does not exist on backend
655 654
 	 */
656
-	static protected function _call_on_backend($name,$params,$fail_silent=false,$path_param_key=0)
655
+	static protected function _call_on_backend($name, $params, $fail_silent = false, $path_param_key = 0)
657 656
 	{
658 657
 		$pathes = $params[$path_param_key];
659 658
 
660 659
 		$scheme2urls = array();
661
-		foreach(is_array($pathes) ? $pathes : array($pathes) as $path)
660
+		foreach (is_array($pathes) ? $pathes : array($pathes) as $path)
662 661
 		{
663
-			if (!($url = self::resolve_url_symlinks($path,false,false)))
662
+			if (!($url = self::resolve_url_symlinks($path, false, false)))
664 663
 			{
665 664
 				return false;
666 665
 			}
667
-			$k=(string)self::parse_url($url,PHP_URL_SCHEME);
666
+			$k = (string)self::parse_url($url, PHP_URL_SCHEME);
668 667
 			if (!(is_array($scheme2urls[$k]))) $scheme2urls[$k] = array();
669 668
 			$scheme2urls[$k][$path] = $url;
670 669
 		}
671 670
 		$ret = array();
672
-		foreach($scheme2urls as $scheme => $urls)
671
+		foreach ($scheme2urls as $scheme => $urls)
673 672
 		{
674 673
 			if ($scheme)
675 674
 			{
676
-				if (!class_exists($class = self::scheme2class($scheme)) || !method_exists($class,$name))
675
+				if (!class_exists($class = self::scheme2class($scheme)) || !method_exists($class, $name))
677 676
 				{
678
-					if (!$fail_silent) trigger_error("Can't $name for scheme $scheme!\n",E_USER_WARNING);
677
+					if (!$fail_silent) trigger_error("Can't $name for scheme $scheme!\n", E_USER_WARNING);
679 678
 					return false;
680 679
 				}
681 680
 				if (!is_array($pathes))
682 681
 				{
683 682
 					$params[$path_param_key] = $url;
684 683
 
685
-					return call_user_func_array(array($class,$name),$params);
684
+					return call_user_func_array(array($class, $name), $params);
686 685
 				}
687 686
 				$params[$path_param_key] = $urls;
688
-				if (!is_array($r = call_user_func_array(array($class,$name),$params)))
687
+				if (!is_array($r = call_user_func_array(array($class, $name), $params)))
689 688
 				{
690 689
 					return $r;
691 690
 				}
692 691
 				// we need to re-translate the urls to pathes, as they can eg. contain symlinks
693
-				foreach($urls as $path => $url)
692
+				foreach ($urls as $path => $url)
694 693
 				{
695
-					if (isset($r[$url]) || isset($r[$url=self::parse_url($url,PHP_URL_PATH)]))
694
+					if (isset($r[$url]) || isset($r[$url = self::parse_url($url, PHP_URL_PATH)]))
696 695
 					{
697 696
 						$ret[$path] = $r[$url];
698 697
 					}
699 698
 				}
700 699
 			}
701 700
 			// call the filesystem specific function (dont allow to use arrays!)
702
-			elseif(!function_exists($name) || is_array($pathes))
701
+			elseif (!function_exists($name) || is_array($pathes))
703 702
 			{
704 703
 				return false;
705 704
 			}
706 705
 			else
707 706
 			{
708 707
 				$time = null;
709
-				return $name($url,$time);
708
+				return $name($url, $time);
710 709
 			}
711 710
 		}
712 711
 		return $ret;
@@ -720,9 +719,9 @@  discard block
 block discarded – undo
720 719
 	 * @param int $atime =null access time (unix timestamp), default null = current time, not implemented in the vfs!
721 720
 	 * @return boolean true on success, false otherwise
722 721
 	 */
723
-	static function touch($path,$time=null,$atime=null)
722
+	static function touch($path, $time = null, $atime = null)
724 723
 	{
725
-		return self::_call_on_backend('touch',array($path,$time,$atime));
724
+		return self::_call_on_backend('touch', array($path, $time, $atime));
726 725
 	}
727 726
 
728 727
 	/**
@@ -734,9 +733,9 @@  discard block
 block discarded – undo
734 733
 	 * @param string $mode mode string see Vfs::mode2int
735 734
 	 * @return boolean true on success, false otherwise
736 735
 	 */
737
-	static function chmod($path,$mode)
736
+	static function chmod($path, $mode)
738 737
 	{
739
-		return self::_call_on_backend('chmod',array($path,$mode));
738
+		return self::_call_on_backend('chmod', array($path, $mode));
740 739
 	}
741 740
 
742 741
 	/**
@@ -748,9 +747,9 @@  discard block
 block discarded – undo
748 747
 	 * @param int $owner numeric user id
749 748
 	 * @return boolean true on success, false otherwise
750 749
 	 */
751
-	static function chown($path,$owner)
750
+	static function chown($path, $owner)
752 751
 	{
753
-		return self::_call_on_backend('chown',array($path,$owner));
752
+		return self::_call_on_backend('chown', array($path, $owner));
754 753
 	}
755 754
 
756 755
 	/**
@@ -762,9 +761,9 @@  discard block
 block discarded – undo
762 761
 	 * @param int $group numeric group id
763 762
 	 * @return boolean true on success, false otherwise
764 763
 	 */
765
-	static function chgrp($path,$group)
764
+	static function chgrp($path, $group)
766 765
 	{
767
-		return self::_call_on_backend('chgrp',array($path,$group));
766
+		return self::_call_on_backend('chgrp', array($path, $group));
768 767
 	}
769 768
 
770 769
 	/**
@@ -777,7 +776,7 @@  discard block
 block discarded – undo
777 776
 	 */
778 777
 	static function readlink($path)
779 778
 	{
780
-		$ret = self::_call_on_backend('readlink',array($path),true);	// true = fail silent, if backend does not support readlink
779
+		$ret = self::_call_on_backend('readlink', array($path), true); // true = fail silent, if backend does not support readlink
781 780
 		//error_log(__METHOD__."('$path') returning ".array2string($ret).' '.function_backtrace());
782 781
 		return $ret;
783 782
 	}
@@ -791,9 +790,9 @@  discard block
 block discarded – undo
791 790
 	 * @param string $link path of the link to create
792 791
 	 * @return boolean true on success, false on error
793 792
 	 */
794
-	static function symlink($target,$link)
793
+	static function symlink($target, $link)
795 794
 	{
796
-		if (($ret = self::_call_on_backend('symlink',array($target,$link),false,1)))	// 1=path is in $link!
795
+		if (($ret = self::_call_on_backend('symlink', array($target, $link), false, 1)))	// 1=path is in $link!
797 796
 		{
798 797
 			self::symlinkCache_remove($link);
799 798
 		}
@@ -813,13 +812,13 @@  discard block
 block discarded – undo
813 812
 	 * @param boolean $recheck =false true = do a new check, false = rely on stored mime type (if existing)
814 813
 	 * @return string mime-type (self::DIR_MIME_TYPE for directories)
815 814
 	 */
816
-	static function mime_content_type($path,$recheck=false)
815
+	static function mime_content_type($path, $recheck = false)
817 816
 	{
818 817
 		if (!($url = self::resolve_url_symlinks($path)))
819 818
 		{
820 819
 			return false;
821 820
 		}
822
-		if (($scheme = self::parse_url($url,PHP_URL_SCHEME)) && !$recheck)
821
+		if (($scheme = self::parse_url($url, PHP_URL_SCHEME)) && !$recheck)
823 822
 		{
824 823
 			// check it it's an eGW stream wrapper returning mime-type via url_stat
825 824
 			// we need to first check if the constant is defined, as we get a fatal error in php5.3 otherwise
@@ -827,7 +826,7 @@  discard block
 block discarded – undo
827 826
 				defined($class.'::STAT_RETURN_MIME_TYPE') &&
828 827
 				($mime_attr = constant($class.'::STAT_RETURN_MIME_TYPE')))
829 828
 			{
830
-				$stat = call_user_func(array($class,'url_stat'),self::parse_url($url,PHP_URL_PATH),0);
829
+				$stat = call_user_func(array($class, 'url_stat'), self::parse_url($url, PHP_URL_PATH), 0);
831 830
 				if ($stat && $stat[$mime_attr])
832 831
 				{
833 832
 					$mime = $stat[$mime_attr];
@@ -846,7 +845,7 @@  discard block
 block discarded – undo
846 845
 		// using EGw's own mime magic (currently only checking the extension!)
847 846
 		if (!$mime)
848 847
 		{
849
-			$mime = Api\MimeMagic::filename2mime(self::parse_url($url,PHP_URL_PATH));
848
+			$mime = Api\MimeMagic::filename2mime(self::parse_url($url, PHP_URL_PATH));
850 849
 		}
851 850
 		//error_log(__METHOD__."($path,$recheck) mime=$mime");
852 851
 		return $mime;
@@ -858,7 +857,7 @@  discard block
 block discarded – undo
858 857
 	 * @param string $path URL that was passed to opendir() and that this object is expected to explore.
859 858
 	 * @return booelan
860 859
 	 */
861
-	function dir_opendir ( $path, $options )
860
+	function dir_opendir($path, $options)
862 861
 	{
863 862
 		$this->opened_dir = $this->extra_dirs = null;
864 863
 		$this->dir_url_params = array();
@@ -875,15 +874,15 @@  discard block
 block discarded – undo
875 874
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__."( $path,$options) opendir($this->opened_dir_url) failed!");
876 875
 			return false;
877 876
 		}
878
-		$this->opened_dir_writable = Vfs::check_access($this->opened_dir_url,Vfs::WRITABLE);
877
+		$this->opened_dir_writable = Vfs::check_access($this->opened_dir_url, Vfs::WRITABLE);
879 878
 		// check our fstab if we need to add some of the mountpoints
880
-		$basepath = self::parse_url($path,PHP_URL_PATH);
881
-		foreach(array_keys(self::$fstab) as $mounted)
879
+		$basepath = self::parse_url($path, PHP_URL_PATH);
880
+		foreach (array_keys(self::$fstab) as $mounted)
882 881
 		{
883 882
 			if (((Vfs::dirname($mounted) == $basepath || Vfs::dirname($mounted).'/' == $basepath) && $mounted != '/') &&
884 883
 				// only return children readable by the user, if dir is not writable
885 884
 				(!self::HIDE_UNREADABLES || $this->opened_dir_writable ||
886
-					Vfs::check_access($mounted,Vfs::READABLE)))
885
+					Vfs::check_access($mounted, Vfs::READABLE)))
887 886
 			{
888 887
 				$this->extra_dirs[] = basename($mounted);
889 888
 			}
@@ -922,24 +921,24 @@  discard block
 block discarded – undo
922 921
 	 * @param boolean $check_symlink_components =true check if path contains symlinks in path components other then the last one
923 922
 	 * @return array
924 923
 	 */
925
-	static function url_stat ( $path, $flags, $try_create_home=false, $check_symlink_components=true, $check_symlink_depth=self::MAX_SYMLINK_DEPTH, $try_reconnect=true )
924
+	static function url_stat($path, $flags, $try_create_home = false, $check_symlink_components = true, $check_symlink_depth = self::MAX_SYMLINK_DEPTH, $try_reconnect = true)
926 925
 	{
927
-		if (!($url = self::resolve_url($path,!($flags & STREAM_URL_STAT_LINK), $check_symlink_components)))
926
+		if (!($url = self::resolve_url($path, !($flags&STREAM_URL_STAT_LINK), $check_symlink_components)))
928 927
 		{
929 928
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$path',$flags) can NOT resolve path!");
930 929
 			return false;
931 930
 		}
932 931
 
933 932
 		try {
934
-			if ($flags & STREAM_URL_STAT_LINK)
933
+			if ($flags&STREAM_URL_STAT_LINK)
935 934
 			{
936
-				$stat = @lstat($url);	// suppressed the stat failed warnings
935
+				$stat = @lstat($url); // suppressed the stat failed warnings
937 936
 			}
938 937
 			else
939 938
 			{
940
-				$stat = @stat($url);	// suppressed the stat failed warnings
939
+				$stat = @stat($url); // suppressed the stat failed warnings
941 940
 
942
-				if ($stat && ($stat['mode'] & self::MODE_LINK))
941
+				if ($stat && ($stat['mode']&self::MODE_LINK))
943 942
 				{
944 943
 					if (!$check_symlink_depth)
945 944
 					{
@@ -950,25 +949,25 @@  discard block
 block discarded – undo
950 949
 					{
951 950
 						if ($lpath[0] != '/')	// concat relative path
952 951
 						{
953
-							$lpath = Vfs::concat(self::parse_url($path,PHP_URL_PATH),'../'.$lpath);
952
+							$lpath = Vfs::concat(self::parse_url($path, PHP_URL_PATH), '../'.$lpath);
954 953
 						}
955
-						$u_query = parse_url($url,PHP_URL_QUERY);
954
+						$u_query = parse_url($url, PHP_URL_QUERY);
956 955
 						$url = Vfs::PREFIX.$lpath;
957 956
 						if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$flags) symlif (substr($path,-1) == '/' && $path != '/') $path = substr($path,0,-1);	// remove trailing slash eg. added by WebDAVink found and resolved to $url");
958 957
 						// try reading the stat of the link
959
-						if (($stat = self::url_stat($lpath, STREAM_URL_STAT_QUIET, false, true, $check_symlink_depth-1)))
958
+						if (($stat = self::url_stat($lpath, STREAM_URL_STAT_QUIET, false, true, $check_symlink_depth - 1)))
960 959
 						{
961 960
 							$stat_query = parse_url($stat['url'], PHP_URL_QUERY);
962
-							if($u_query || $stat_query)
961
+							if ($u_query || $stat_query)
963 962
 							{
964 963
 								$stat_url = parse_url($stat['url']);
965
-								parse_str($stat_query,$stat_query);
964
+								parse_str($stat_query, $stat_query);
966 965
 								parse_str($u_query, $u_query);
967 966
 								$stat_query = http_build_query(array_merge($stat_query, $u_query));
968 967
 								$stat['url'] = $stat_url['scheme'].'://'.$stat_url['host'].$stat_url['path'].'?'.$stat_query;
969 968
 							}
970
-							if(isset($stat['url'])) $url = $stat['url'];	// if stat returns an url use that, as there might be more links ...
971
-							self::symlinkCache_add($path,$url);
969
+							if (isset($stat['url'])) $url = $stat['url']; // if stat returns an url use that, as there might be more links ...
970
+							self::symlinkCache_add($path, $url);
972 971
 						}
973 972
 					}
974 973
 				}
@@ -988,7 +987,7 @@  discard block
 block discarded – undo
988 987
 			throw $e;
989 988
 		}
990 989
 		// check if a failed url_stat was for a home dir, in that case silently create it
991
-		if (!$stat && $try_create_home && Vfs::dirname(self::parse_url($path,PHP_URL_PATH)) == '/home' &&
990
+		if (!$stat && $try_create_home && Vfs::dirname(self::parse_url($path, PHP_URL_PATH)) == '/home' &&
992 991
 			($id = $GLOBALS['egw']->accounts->name2id(basename($path))) &&
993 992
 			$GLOBALS['egw']->accounts->id2name($id) == basename($path))	// make sure path has the right case!
994 993
 		{
@@ -998,25 +997,25 @@  discard block
 block discarded – undo
998 997
 				'account_lid' => basename($path),
999 998
 				'account_name' => basename($path),
1000 999
 			);
1001
-			call_user_func(array(__NAMESPACE__.'\\Hooks',$hook_data['location']),$hook_data);
1000
+			call_user_func(array(__NAMESPACE__.'\\Hooks', $hook_data['location']), $hook_data);
1002 1001
 			unset($hook_data);
1003
-			$stat = self::url_stat($path,$flags,false);
1002
+			$stat = self::url_stat($path, $flags, false);
1004 1003
 		}
1005 1004
 		$query = parse_url($url, PHP_URL_QUERY);
1006 1005
 		if (!$stat && $check_symlink_components)	// check if there's a symlink somewhere inbetween the path
1007 1006
 		{
1008
-			$stat = self::check_symlink_components($path,$flags,$url);
1009
-			if ($stat && isset($stat['url']) && !$query) self::symlinkCache_add($path,$stat['url']);
1007
+			$stat = self::check_symlink_components($path, $flags, $url);
1008
+			if ($stat && isset($stat['url']) && !$query) self::symlinkCache_add($path, $stat['url']);
1010 1009
 		}
1011
-		elseif(is_array($stat) && !isset($stat['url']))
1010
+		elseif (is_array($stat) && !isset($stat['url']))
1012 1011
 		{
1013 1012
 			$stat['url'] = $url;
1014 1013
 		}
1015
-		if (($stat['mode'] & 0222) && self::url_is_readonly($stat['url']))
1014
+		if (($stat['mode']&0222) && self::url_is_readonly($stat['url']))
1016 1015
 		{
1017 1016
 			$stat['mode'] &= ~0222;
1018 1017
 		}
1019
-		if($stat['url'] && $query && strpos($stat['url'],'?'.$query)===false)
1018
+		if ($stat['url'] && $query && strpos($stat['url'], '?'.$query) === false)
1020 1019
 		{
1021 1020
 			$stat['url'] .= '?'.$query;
1022 1021
 		}
@@ -1043,7 +1042,7 @@  discard block
 block discarded – undo
1043 1042
 	 * @param string &$url=null already resolved path
1044 1043
 	 * @return array|boolean stat array or false if not found
1045 1044
 	 */
1046
-	static private function check_symlink_components($path,$flags=0,&$url=null)
1045
+	static private function check_symlink_components($path, $flags = 0, &$url = null)
1047 1046
 	{
1048 1047
 		if (is_null($url) && !($url = self::resolve_url($path)))
1049 1048
 		{
@@ -1055,7 +1054,7 @@  discard block
 block discarded – undo
1055 1054
 		while (($rel_path = Vfs::basename($url).($rel_path ? '/'.$rel_path : '')) &&
1056 1055
 		       ($url = Vfs::dirname($url)))
1057 1056
 		{
1058
-			if (($stat = self::url_stat($url,0,false,false)))
1057
+			if (($stat = self::url_stat($url, 0, false, false)))
1059 1058
 			{
1060 1059
 				if (is_link($url) && ($lpath = self::readlink($url)))
1061 1060
 				{
@@ -1063,20 +1062,20 @@  discard block
 block discarded – undo
1063 1062
 
1064 1063
 					if ($lpath[0] != '/')
1065 1064
 					{
1066
-						$lpath = Vfs::concat(self::parse_url($url,PHP_URL_PATH),'../'.$lpath);
1065
+						$lpath = Vfs::concat(self::parse_url($url, PHP_URL_PATH), '../'.$lpath);
1067 1066
 					}
1068 1067
 					//self::symlinkCache_add($path,Vfs::PREFIX.$lpath);
1069
-					$url = Vfs::PREFIX.Vfs::concat($lpath,$rel_path);
1068
+					$url = Vfs::PREFIX.Vfs::concat($lpath, $rel_path);
1070 1069
 					if (self::LOG_LEVEL > 1) error_log("$log --> lpath='$lpath', url='$url'");
1071
-					return self::url_stat($url,$flags);
1070
+					return self::url_stat($url, $flags);
1072 1071
 				}
1073
-				$url = Vfs::concat($url,$rel_path);
1072
+				$url = Vfs::concat($url, $rel_path);
1074 1073
 				if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning null");
1075 1074
 				return null;
1076 1075
 			}
1077 1076
 		}
1078 1077
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning false");
1079
-		return false;	// $path does not exist
1078
+		return false; // $path does not exist
1080 1079
 	}
1081 1080
 
1082 1081
 	/**
@@ -1092,13 +1091,13 @@  discard block
 block discarded – undo
1092 1091
 	 * @param string $_path vfs path
1093 1092
 	 * @param string $target target path
1094 1093
 	 */
1095
-	static protected function symlinkCache_add($_path,$target)
1094
+	static protected function symlinkCache_add($_path, $target)
1096 1095
 	{
1097 1096
 		$path = self::get_path($_path);
1098 1097
 
1099
-		if (isset(self::$symlink_cache[$path])) return;	// nothing to do
1098
+		if (isset(self::$symlink_cache[$path])) return; // nothing to do
1100 1099
 
1101
-		if ($target[0] != '/') $target = self::parse_url($target,PHP_URL_PATH);
1100
+		if ($target[0] != '/') $target = self::parse_url($target, PHP_URL_PATH);
1102 1101
 
1103 1102
 		self::$symlink_cache[$path] = $target;
1104 1103
 
@@ -1132,25 +1131,25 @@  discard block
 block discarded – undo
1132 1131
 	 * @param boolean $do_symlink =true is a direct match allowed, default yes (must be false for a lstat or readlink!)
1133 1132
 	 * @return string target or path, if path not found
1134 1133
 	 */
1135
-	static public function symlinkCache_resolve($_path,$do_symlink=true)
1134
+	static public function symlinkCache_resolve($_path, $do_symlink = true)
1136 1135
 	{
1137 1136
 		// remove vfs scheme, but no other schemes (eg. filesystem!)
1138 1137
 		$path = self::get_path($_path);
1139 1138
 
1140 1139
 		$strlen_path = strlen($path);
1141 1140
 
1142
-		foreach(self::$symlink_cache as $p => $t)
1141
+		foreach (self::$symlink_cache as $p => $t)
1143 1142
 		{
1144
-			if (($strlen_p = strlen($p)) > $strlen_path) continue;	// $path can NOT start with $p
1143
+			if (($strlen_p = strlen($p)) > $strlen_path) continue; // $path can NOT start with $p
1145 1144
 
1146 1145
 			if ($path == $p)
1147 1146
 			{
1148 1147
 				if ($do_symlink) $target = $t;
1149 1148
 				break;
1150 1149
 			}
1151
-			elseif (substr($path,0,$strlen_p+1) == $p.'/')
1150
+			elseif (substr($path, 0, $strlen_p + 1) == $p.'/')
1152 1151
 			{
1153
-				$target = $t . substr($path,$strlen_p);
1152
+				$target = $t.substr($path, $strlen_p);
1154 1153
 				break;
1155 1154
 			}
1156 1155
 		}
@@ -1168,7 +1167,7 @@  discard block
 block discarded – undo
1168 1167
 	 *
1169 1168
 	 * @param string $path ='/' path of backend, whos cache to clear
1170 1169
 	 */
1171
-	static function clearstatcache($path='/')
1170
+	static function clearstatcache($path = '/')
1172 1171
 	{
1173 1172
 		//error_log(__METHOD__."('$path')");
1174 1173
 		self::$symlink_cache = self::$resolve_url_cache = array();
@@ -1186,7 +1185,7 @@  discard block
 block discarded – undo
1186 1185
 	 *
1187 1186
 	 * @return string
1188 1187
 	 */
1189
-	function dir_readdir ( )
1188
+	function dir_readdir( )
1190 1189
 	{
1191 1190
 		if ($this->extra_dirs && count($this->extra_dirs) > $this->extra_dir_ptr)
1192 1191
 		{
@@ -1198,10 +1197,10 @@  discard block
 block discarded – undo
1198 1197
 			do {
1199 1198
 				$file = readdir($this->opened_dir);
1200 1199
 			}
1201
-			while($file !== false &&
1202
-				(is_array($this->extra_dirs) && in_array($file,$this->extra_dirs) || // do NOT return extra_dirs twice
1200
+			while ($file !== false &&
1201
+				(is_array($this->extra_dirs) && in_array($file, $this->extra_dirs) || // do NOT return extra_dirs twice
1203 1202
 				self::HIDE_UNREADABLES && !$this->opened_dir_writable &&
1204
-				!Vfs::check_access(Vfs::concat($this->opened_dir_url,$file),Vfs::READABLE)));
1203
+				!Vfs::check_access(Vfs::concat($this->opened_dir_url, $file), Vfs::READABLE)));
1205 1204
 		}
1206 1205
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( $this->opened_dir ) = '$file'");
1207 1206
 		return $file;
@@ -1215,7 +1214,7 @@  discard block
 block discarded – undo
1215 1214
 	 *
1216 1215
 	 * @return boolean
1217 1216
 	 */
1218
-	function dir_rewinddir ( )
1217
+	function dir_rewinddir( )
1219 1218
 	{
1220 1219
 		$this->extra_dir_ptr = 0;
1221 1220
 
@@ -1229,7 +1228,7 @@  discard block
 block discarded – undo
1229 1228
 	 *
1230 1229
 	 * @return boolean
1231 1230
 	 */
1232
-	function dir_closedir ( )
1231
+	function dir_closedir( )
1233 1232
 	{
1234 1233
 		$ret = closedir($this->opened_dir);
1235 1234
 
@@ -1246,9 +1245,9 @@  discard block
 block discarded – undo
1246 1245
 	 */
1247 1246
 	static function load_wrapper($scheme)
1248 1247
 	{
1249
-		if (!in_array($scheme,self::get_wrappers()))
1248
+		if (!in_array($scheme, self::get_wrappers()))
1250 1249
 		{
1251
-			switch($scheme)
1250
+			switch ($scheme)
1252 1251
 			{
1253 1252
 				case 'webdav':
1254 1253
 				case 'webdavs':
@@ -1256,16 +1255,16 @@  discard block
 block discarded – undo
1256 1255
 					self::$wrappers[] = $scheme;
1257 1256
 					break;
1258 1257
 				case '':
1259
-					break;	// default file, always loaded
1258
+					break; // default file, always loaded
1260 1259
 				default:
1261 1260
 					// check if scheme is buildin in php or one of our own stream wrappers
1262
-					if (in_array($scheme,stream_get_wrappers()) || class_exists(self::scheme2class($scheme)))
1261
+					if (in_array($scheme, stream_get_wrappers()) || class_exists(self::scheme2class($scheme)))
1263 1262
 					{
1264 1263
 						self::$wrappers[] = $scheme;
1265 1264
 					}
1266 1265
 					else
1267 1266
 					{
1268
-						trigger_error("Can't load stream-wrapper for scheme '$scheme'!",E_USER_WARNING);
1267
+						trigger_error("Can't load stream-wrapper for scheme '$scheme'!", E_USER_WARNING);
1269 1268
 						return false;
1270 1269
 					}
1271 1270
 			}
@@ -1299,10 +1298,10 @@  discard block
 block discarded – undo
1299 1298
 	static function scheme2class($scheme)
1300 1299
 	{
1301 1300
 		list($app, $app_scheme) = explode('.', $scheme);
1302
-		foreach(array(
1303
-			empty($app_scheme) ? 'EGroupware\\Api\\Vfs\\'.ucfirst($scheme).'\\StreamWrapper' :	// streamwrapper in Api\Vfs
1301
+		foreach (array(
1302
+			empty($app_scheme) ? 'EGroupware\\Api\\Vfs\\'.ucfirst($scheme).'\\StreamWrapper' : // streamwrapper in Api\Vfs
1304 1303
 				'EGroupware\\'.ucfirst($app).'\\Vfs\\'.ucfirst($app_scheme).'\\StreamWrapper', // streamwrapper in $app\Vfs
1305
-			str_replace('.','_',$scheme).'_stream_wrapper',	// old (flat) name
1304
+			str_replace('.', '_', $scheme).'_stream_wrapper', // old (flat) name
1306 1305
 		) as $class)
1307 1306
 		{
1308 1307
 			//error_log(__METHOD__."('$scheme') class_exists('$class')=".array2string(class_exists($class)));
@@ -1319,7 +1318,7 @@  discard block
 block discarded – undo
1319 1318
 	 * @param int $component =-1 PHP_URL_* constants
1320 1319
 	 * @return array|string|boolean on success array or string, if $component given, or false on failure
1321 1320
 	 */
1322
-	static function parse_url($url, $component=-1)
1321
+	static function parse_url($url, $component = -1)
1323 1322
 	{
1324 1323
 		static $component2str = array(
1325 1324
 			PHP_URL_SCHEME => 'scheme',
@@ -1331,9 +1330,9 @@  discard block
 block discarded – undo
1331 1330
 			PHP_URL_QUERY => 'query',
1332 1331
 			PHP_URL_FRAGMENT => 'fragment',
1333 1332
 		);
1334
-		static $cache = array();	// some caching
1333
+		static $cache = array(); // some caching
1335 1334
 
1336
-		$result =& $cache[$url];
1335
+		$result = & $cache[$url];
1337 1336
 
1338 1337
 		if (!isset($result))
1339 1338
 		{
@@ -1370,7 +1369,7 @@  discard block
 block discarded – undo
1370 1369
 	 * @param string $only_remove_scheme =self::SCHEME if given only that scheme get's removed
1371 1370
 	 * @return string path without training slash
1372 1371
 	 */
1373
-	static protected function get_path($path,$only_remove_scheme=self::SCHEME)
1372
+	static protected function get_path($path, $only_remove_scheme = self::SCHEME)
1374 1373
 	{
1375 1374
 		if ($path[0] != '/' && (!$only_remove_scheme || self::parse_url($path, PHP_URL_SCHEME) == $only_remove_scheme))
1376 1375
 		{
@@ -1381,7 +1380,7 @@  discard block
 block discarded – undo
1381 1380
 		{
1382 1381
 			while (mb_substr($path, -1) == '/' && $path != '/' && ($path[0] == '/' || self::parse_url($path, PHP_URL_PATH) != '/'))
1383 1382
 			{
1384
-				$path = mb_substr($path,0,-1);
1383
+				$path = mb_substr($path, 0, -1);
1385 1384
 			}
1386 1385
 		}
1387 1386
 		return $path;
@@ -1396,7 +1395,7 @@  discard block
 block discarded – undo
1396 1395
 	static function url_is_readonly($url)
1397 1396
 	{
1398 1397
 		static $cache = array();
1399
-		$ret =& $cache[$url];
1398
+		$ret = & $cache[$url];
1400 1399
 		if (!isset($ret))
1401 1400
 		{
1402 1401
 			$matches = null;
@@ -1411,7 +1410,7 @@  discard block
 block discarded – undo
1411 1410
 	 */
1412 1411
 	static function init_static()
1413 1412
 	{
1414
-		stream_register_wrapper(self::SCHEME,__CLASS__);
1413
+		stream_register_wrapper(self::SCHEME, __CLASS__);
1415 1414
 
1416 1415
 		if (($fstab = $GLOBALS['egw_info']['server']['vfs_fstab']) && is_array($fstab) && count($fstab))
1417 1416
 		{
Please login to merge, or discard this patch.
Braces   +184 added lines, -45 removed lines patch added patch discarded remove patch
@@ -165,7 +165,10 @@  discard block
 block discarded – undo
165 165
 		{
166 166
 			$url = null;
167 167
 			$stat = self::check_symlink_components($path,0,$url);
168
-			if (self::LOG_LEVEL > 1) $log = " (check_symlink_components('$path',0,'$url') = $stat)";
168
+			if (self::LOG_LEVEL > 1)
169
+			{
170
+				$log = " (check_symlink_components('$path',0,'$url') = $stat)";
171
+			}
169 172
 		}
170 173
 		else
171 174
 		{
@@ -176,7 +179,10 @@  discard block
 block discarded – undo
176 179
 		{
177 180
 			$url = self::resolve_url(self::parse_url($url,PHP_URL_PATH));
178 181
 		}
179
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,file_exists=$file_exists,resolve_last_symlink=$resolve_last_symlink) = '$url'$log");
182
+		if (self::LOG_LEVEL > 1)
183
+		{
184
+			error_log(__METHOD__."($path,file_exists=$file_exists,resolve_last_symlink=$resolve_last_symlink) = '$url'$log");
185
+		}
180 186
 		return $url;
181 187
 	}
182 188
 
@@ -204,7 +210,10 @@  discard block
 block discarded – undo
204 210
 		// we do some caching here
205 211
 		if (isset(self::$resolve_url_cache[$path]) && $replace_user_pass_host)
206 212
 		{
207
-			if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = '".self::$resolve_url_cache[$path]."' (from cache)");
213
+			if (self::LOG_LEVEL > 1)
214
+			{
215
+				error_log(__METHOD__."('$path') = '".self::$resolve_url_cache[$path]."' (from cache)");
216
+			}
208 217
 			return self::$resolve_url_cache[$path];
209 218
 		}
210 219
 		// check if we can already resolve path (or a part of it) with a known symlinks
@@ -224,14 +233,24 @@  discard block
 block discarded – undo
224 233
 			);
225 234
 		}
226 235
 		$parts = array_merge(self::parse_url($path),$defaults);
227
-		if (!$parts['host']) $parts['host'] = 'default';	// otherwise we get an invalid url (scheme:///path/to/something)!
236
+		if (!$parts['host'])
237
+		{
238
+			$parts['host'] = 'default';
239
+		}
240
+		// otherwise we get an invalid url (scheme:///path/to/something)!
228 241
 
229 242
 		if (!empty($parts['scheme']) && $parts['scheme'] != self::SCHEME)
230 243
 		{
231
-			if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = '$path' (path is already an url)");
244
+			if (self::LOG_LEVEL > 1)
245
+			{
246
+				error_log(__METHOD__."('$path') = '$path' (path is already an url)");
247
+			}
232 248
 			return $path;	// path is already a non-vfs url --> nothing to do
233 249
 		}
234
-		if (empty($parts['path'])) $parts['path'] = '/';
250
+		if (empty($parts['path']))
251
+		{
252
+			$parts['path'] = '/';
253
+		}
235 254
 
236 255
 		foreach(array_reverse(self::$fstab) as $mounted => $url)
237 256
 		{
@@ -257,17 +276,32 @@  discard block
 block discarded – undo
257 276
 				{
258 277
 					$url = str_replace(array('$user','$pass','$host','$home'),array($parts['user'],$parts['pass'],$parts['host'],$parts['home']),$url);
259 278
 				}
260
-				if ($parts['query']) $url .= '?'.$parts['query'];
261
-				if ($parts['fragment']) $url .= '#'.$parts['fragment'];
279
+				if ($parts['query'])
280
+				{
281
+					$url .= '?'.$parts['query'];
282
+				}
283
+				if ($parts['fragment'])
284
+				{
285
+					$url .= '#'.$parts['fragment'];
286
+				}
262 287
 
263
-				if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path') = '$url'");
288
+				if (self::LOG_LEVEL > 1)
289
+				{
290
+					error_log(__METHOD__."('$path') = '$url'");
291
+				}
264 292
 
265
-				if ($replace_user_pass_host) self::$resolve_url_cache[$path] = $url;
293
+				if ($replace_user_pass_host)
294
+				{
295
+					self::$resolve_url_cache[$path] = $url;
296
+				}
266 297
 
267 298
 				return $url;
268 299
 			}
269 300
 		}
270
-		if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$path') can't resolve path!\n");
301
+		if (self::LOG_LEVEL > 0)
302
+		{
303
+			error_log(__METHOD__."('$path') can't resolve path!\n");
304
+		}
271 305
 		trigger_error(__METHOD__."($path) can't resolve path!\n",E_USER_WARNING);
272 306
 		return false;
273 307
 	}
@@ -491,10 +525,13 @@  discard block
 block discarded – undo
491 525
 	 */
492 526
 	static function unlink ( $path )
493 527
 	{
494
-		if (!($url = self::resolve_url_symlinks($path,true,false)))	// true,false file need to exist, but do not resolve last component
528
+		if (!($url = self::resolve_url_symlinks($path,true,false)))
529
+		{
530
+			// true,false file need to exist, but do not resolve last component
495 531
 		{
496 532
 			return false;
497 533
 		}
534
+		}
498 535
 		if (self::url_is_readonly($url))
499 536
 		{
500 537
 			return false;
@@ -547,7 +584,10 @@  discard block
 block discarded – undo
547 584
 			$ret = stream_copy_to_stream($from,$to) !== false;
548 585
 			fclose($from);
549 586
 			fclose($to);
550
-			if ($ret) self::unlink($path_from);
587
+			if ($ret)
588
+			{
589
+				self::unlink($path_from);
590
+			}
551 591
 		}
552 592
 		else
553 593
 		{
@@ -584,10 +624,13 @@  discard block
 block discarded – undo
584 624
 	 */
585 625
 	static function mkdir ( $path, $mode, $options )
586 626
 	{
587
-		if (!($url = self::resolve_url_symlinks($path,false)))	// false = directory does not need to exists
627
+		if (!($url = self::resolve_url_symlinks($path,false)))
628
+		{
629
+			// false = directory does not need to exists
588 630
 		{
589 631
 			return false;
590 632
 		}
633
+		}
591 634
 		$ret = mkdir($url,$mode,$options);
592 635
 
593 636
 		// call "vfs_mkdir" hook
@@ -665,7 +708,10 @@  discard block
 block discarded – undo
665 708
 				return false;
666 709
 			}
667 710
 			$k=(string)self::parse_url($url,PHP_URL_SCHEME);
668
-			if (!(is_array($scheme2urls[$k]))) $scheme2urls[$k] = array();
711
+			if (!(is_array($scheme2urls[$k])))
712
+			{
713
+				$scheme2urls[$k] = array();
714
+			}
669 715
 			$scheme2urls[$k][$path] = $url;
670 716
 		}
671 717
 		$ret = array();
@@ -675,7 +721,10 @@  discard block
 block discarded – undo
675 721
 			{
676 722
 				if (!class_exists($class = self::scheme2class($scheme)) || !method_exists($class,$name))
677 723
 				{
678
-					if (!$fail_silent) trigger_error("Can't $name for scheme $scheme!\n",E_USER_WARNING);
724
+					if (!$fail_silent)
725
+					{
726
+						trigger_error("Can't $name for scheme $scheme!\n",E_USER_WARNING);
727
+					}
679 728
 					return false;
680 729
 				}
681 730
 				if (!is_array($pathes))
@@ -793,10 +842,13 @@  discard block
 block discarded – undo
793 842
 	 */
794 843
 	static function symlink($target,$link)
795 844
 	{
796
-		if (($ret = self::_call_on_backend('symlink',array($target,$link),false,1)))	// 1=path is in $link!
845
+		if (($ret = self::_call_on_backend('symlink',array($target,$link),false,1)))
846
+		{
847
+			// 1=path is in $link!
797 848
 		{
798 849
 			self::symlinkCache_remove($link);
799 850
 		}
851
+		}
800 852
 		return $ret;
801 853
 	}
802 854
 
@@ -866,13 +918,19 @@  discard block
 block discarded – undo
866 918
 
867 919
 		if (!($this->opened_dir_url = self::resolve_url_symlinks($path)))
868 920
 		{
869
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."( $path,$options) resolve_url_symlinks() failed!");
921
+			if (self::LOG_LEVEL > 0)
922
+			{
923
+				error_log(__METHOD__."( $path,$options) resolve_url_symlinks() failed!");
924
+			}
870 925
 			return false;
871 926
 		}
872 927
 		if (!($this->opened_dir = $this->context ?
873 928
 			opendir($this->opened_dir_url, $this->context) : opendir($this->opened_dir_url)))
874 929
 		{
875
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."( $path,$options) opendir($this->opened_dir_url) failed!");
930
+			if (self::LOG_LEVEL > 0)
931
+			{
932
+				error_log(__METHOD__."( $path,$options) opendir($this->opened_dir_url) failed!");
933
+			}
876 934
 			return false;
877 935
 		}
878 936
 		$this->opened_dir_writable = Vfs::check_access($this->opened_dir_url,Vfs::WRITABLE);
@@ -890,7 +948,10 @@  discard block
 block discarded – undo
890 948
 		}
891 949
 
892 950
 
893
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( $path,$options): opendir($this->opened_dir_url)=$this->opened_dir, extra_dirs=".array2string($this->extra_dirs).', '.function_backtrace());
951
+		if (self::LOG_LEVEL > 1)
952
+		{
953
+			error_log(__METHOD__."( $path,$options): opendir($this->opened_dir_url)=$this->opened_dir, extra_dirs=".array2string($this->extra_dirs).', '.function_backtrace());
954
+		}
894 955
 		return true;
895 956
 	}
896 957
 
@@ -926,7 +987,10 @@  discard block
 block discarded – undo
926 987
 	{
927 988
 		if (!($url = self::resolve_url($path,!($flags & STREAM_URL_STAT_LINK), $check_symlink_components)))
928 989
 		{
929
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$path',$flags) can NOT resolve path!");
990
+			if (self::LOG_LEVEL > 0)
991
+			{
992
+				error_log(__METHOD__."('$path',$flags) can NOT resolve path!");
993
+			}
930 994
 			return false;
931 995
 		}
932 996
 
@@ -943,18 +1007,27 @@  discard block
 block discarded – undo
943 1007
 				{
944 1008
 					if (!$check_symlink_depth)
945 1009
 					{
946
-						if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$path',$flags) maximum symlink depth exceeded, might be a circular symlink!");
1010
+						if (self::LOG_LEVEL > 0)
1011
+						{
1012
+							error_log(__METHOD__."('$path',$flags) maximum symlink depth exceeded, might be a circular symlink!");
1013
+						}
947 1014
 						$stat = false;
948 1015
 					}
949 1016
 					elseif (($lpath = self::readlink($url)))
950 1017
 					{
951
-						if ($lpath[0] != '/')	// concat relative path
1018
+						if ($lpath[0] != '/')
1019
+						{
1020
+							// concat relative path
952 1021
 						{
953 1022
 							$lpath = Vfs::concat(self::parse_url($path,PHP_URL_PATH),'../'.$lpath);
954 1023
 						}
1024
+						}
955 1025
 						$u_query = parse_url($url,PHP_URL_QUERY);
956 1026
 						$url = Vfs::PREFIX.$lpath;
957
-						if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$flags) symlif (substr($path,-1) == '/' && $path != '/') $path = substr($path,0,-1);	// remove trailing slash eg. added by WebDAVink found and resolved to $url");
1027
+						if (self::LOG_LEVEL > 1)
1028
+						{
1029
+							error_log(__METHOD__."($path,$flags) symlif (substr($path,-1) == '/' && $path != '/') $path = substr($path,0,-1);	// remove trailing slash eg. added by WebDAVink found and resolved to $url");
1030
+						}
958 1031
 						// try reading the stat of the link
959 1032
 						if (($stat = self::url_stat($lpath, STREAM_URL_STAT_QUIET, false, true, $check_symlink_depth-1)))
960 1033
 						{
@@ -967,7 +1040,11 @@  discard block
 block discarded – undo
967 1040
 								$stat_query = http_build_query(array_merge($stat_query, $u_query));
968 1041
 								$stat['url'] = $stat_url['scheme'].'://'.$stat_url['host'].$stat_url['path'].'?'.$stat_query;
969 1042
 							}
970
-							if(isset($stat['url'])) $url = $stat['url'];	// if stat returns an url use that, as there might be more links ...
1043
+							if(isset($stat['url']))
1044
+							{
1045
+								$url = $stat['url'];
1046
+							}
1047
+							// if stat returns an url use that, as there might be more links ...
971 1048
 							self::symlinkCache_add($path,$url);
972 1049
 						}
973 1050
 					}
@@ -990,7 +1067,9 @@  discard block
 block discarded – undo
990 1067
 		// check if a failed url_stat was for a home dir, in that case silently create it
991 1068
 		if (!$stat && $try_create_home && Vfs::dirname(self::parse_url($path,PHP_URL_PATH)) == '/home' &&
992 1069
 			($id = $GLOBALS['egw']->accounts->name2id(basename($path))) &&
993
-			$GLOBALS['egw']->accounts->id2name($id) == basename($path))	// make sure path has the right case!
1070
+			$GLOBALS['egw']->accounts->id2name($id) == basename($path))
1071
+		{
1072
+			// make sure path has the right case!
994 1073
 		{
995 1074
 			$hook_data = array(
996 1075
 				'location' => $GLOBALS['egw']->accounts->get_type($id) == 'g' ? 'addgroup' : 'addaccount',
@@ -998,15 +1077,22 @@  discard block
 block discarded – undo
998 1077
 				'account_lid' => basename($path),
999 1078
 				'account_name' => basename($path),
1000 1079
 			);
1080
+		}
1001 1081
 			call_user_func(array(__NAMESPACE__.'\\Hooks',$hook_data['location']),$hook_data);
1002 1082
 			unset($hook_data);
1003 1083
 			$stat = self::url_stat($path,$flags,false);
1004 1084
 		}
1005 1085
 		$query = parse_url($url, PHP_URL_QUERY);
1006
-		if (!$stat && $check_symlink_components)	// check if there's a symlink somewhere inbetween the path
1086
+		if (!$stat && $check_symlink_components)
1087
+		{
1088
+			// check if there's a symlink somewhere inbetween the path
1007 1089
 		{
1008 1090
 			$stat = self::check_symlink_components($path,$flags,$url);
1009
-			if ($stat && isset($stat['url']) && !$query) self::symlinkCache_add($path,$stat['url']);
1091
+		}
1092
+			if ($stat && isset($stat['url']) && !$query)
1093
+			{
1094
+				self::symlinkCache_add($path,$stat['url']);
1095
+			}
1010 1096
 		}
1011 1097
 		elseif(is_array($stat) && !isset($stat['url']))
1012 1098
 		{
@@ -1021,7 +1107,10 @@  discard block
 block discarded – undo
1021 1107
 			$stat['url'] .= '?'.$query;
1022 1108
 		}
1023 1109
 
1024
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,try_create_home=$try_create_home,check_symlink_components=$check_symlink_components) returning ".array2string($stat));
1110
+		if (self::LOG_LEVEL > 1)
1111
+		{
1112
+			error_log(__METHOD__."('$path',$flags,try_create_home=$try_create_home,check_symlink_components=$check_symlink_components) returning ".array2string($stat));
1113
+		}
1025 1114
 
1026 1115
 		return $stat;
1027 1116
 
@@ -1047,10 +1136,16 @@  discard block
 block discarded – undo
1047 1136
 	{
1048 1137
 		if (is_null($url) && !($url = self::resolve_url($path)))
1049 1138
 		{
1050
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$path',$flags,'$url') can NOT resolve path: ".function_backtrace(1));
1139
+			if (self::LOG_LEVEL > 0)
1140
+			{
1141
+				error_log(__METHOD__."('$path',$flags,'$url') can NOT resolve path: ".function_backtrace(1));
1142
+			}
1051 1143
 			return false;
1052 1144
 		}
1053
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url'): ".function_backtrace(1));
1145
+		if (self::LOG_LEVEL > 1)
1146
+		{
1147
+			error_log(__METHOD__."('$path',$flags,'$url'): ".function_backtrace(1));
1148
+		}
1054 1149
 
1055 1150
 		while (($rel_path = Vfs::basename($url).($rel_path ? '/'.$rel_path : '')) &&
1056 1151
 		       ($url = Vfs::dirname($url)))
@@ -1059,7 +1154,10 @@  discard block
 block discarded – undo
1059 1154
 			{
1060 1155
 				if (is_link($url) && ($lpath = self::readlink($url)))
1061 1156
 				{
1062
-					if (self::LOG_LEVEL > 1) $log = "rel_path='$rel_path', url='$url': lpath='$lpath'";
1157
+					if (self::LOG_LEVEL > 1)
1158
+					{
1159
+						$log = "rel_path='$rel_path', url='$url': lpath='$lpath'";
1160
+					}
1063 1161
 
1064 1162
 					if ($lpath[0] != '/')
1065 1163
 					{
@@ -1067,15 +1165,24 @@  discard block
 block discarded – undo
1067 1165
 					}
1068 1166
 					//self::symlinkCache_add($path,Vfs::PREFIX.$lpath);
1069 1167
 					$url = Vfs::PREFIX.Vfs::concat($lpath,$rel_path);
1070
-					if (self::LOG_LEVEL > 1) error_log("$log --> lpath='$lpath', url='$url'");
1168
+					if (self::LOG_LEVEL > 1)
1169
+					{
1170
+						error_log("$log --> lpath='$lpath', url='$url'");
1171
+					}
1071 1172
 					return self::url_stat($url,$flags);
1072 1173
 				}
1073 1174
 				$url = Vfs::concat($url,$rel_path);
1074
-				if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning null");
1175
+				if (self::LOG_LEVEL > 1)
1176
+				{
1177
+					error_log(__METHOD__."('$path',$flags,'$url') returning null");
1178
+				}
1075 1179
 				return null;
1076 1180
 			}
1077 1181
 		}
1078
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning false");
1182
+		if (self::LOG_LEVEL > 1)
1183
+		{
1184
+			error_log(__METHOD__."('$path',$flags,'$url') returning false");
1185
+		}
1079 1186
 		return false;	// $path does not exist
1080 1187
 	}
1081 1188
 
@@ -1096,9 +1203,16 @@  discard block
 block discarded – undo
1096 1203
 	{
1097 1204
 		$path = self::get_path($_path);
1098 1205
 
1099
-		if (isset(self::$symlink_cache[$path])) return;	// nothing to do
1206
+		if (isset(self::$symlink_cache[$path]))
1207
+		{
1208
+			return;
1209
+		}
1210
+		// nothing to do
1100 1211
 
1101
-		if ($target[0] != '/') $target = self::parse_url($target,PHP_URL_PATH);
1212
+		if ($target[0] != '/')
1213
+		{
1214
+			$target = self::parse_url($target,PHP_URL_PATH);
1215
+		}
1102 1216
 
1103 1217
 		self::$symlink_cache[$path] = $target;
1104 1218
 
@@ -1107,7 +1221,10 @@  discard block
 block discarded – undo
1107 1221
 		{
1108 1222
 			return strlen($a) - strlen($b);
1109 1223
 		});
1110
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$target) cache now ".array2string(self::$symlink_cache));
1224
+		if (self::LOG_LEVEL > 1)
1225
+		{
1226
+			error_log(__METHOD__."($path,$target) cache now ".array2string(self::$symlink_cache));
1227
+		}
1111 1228
 	}
1112 1229
 
1113 1230
 	/**
@@ -1120,7 +1237,10 @@  discard block
 block discarded – undo
1120 1237
 		$path = self::get_path($_path);
1121 1238
 
1122 1239
 		unset(self::$symlink_cache[$path]);
1123
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path) cache now ".array2string(self::$symlink_cache));
1240
+		if (self::LOG_LEVEL > 1)
1241
+		{
1242
+			error_log(__METHOD__."($path) cache now ".array2string(self::$symlink_cache));
1243
+		}
1124 1244
 	}
1125 1245
 
1126 1246
 	/**
@@ -1141,11 +1261,18 @@  discard block
 block discarded – undo
1141 1261
 
1142 1262
 		foreach(self::$symlink_cache as $p => $t)
1143 1263
 		{
1144
-			if (($strlen_p = strlen($p)) > $strlen_path) continue;	// $path can NOT start with $p
1264
+			if (($strlen_p = strlen($p)) > $strlen_path)
1265
+			{
1266
+				continue;
1267
+			}
1268
+			// $path can NOT start with $p
1145 1269
 
1146 1270
 			if ($path == $p)
1147 1271
 			{
1148
-				if ($do_symlink) $target = $t;
1272
+				if ($do_symlink)
1273
+				{
1274
+					$target = $t;
1275
+				}
1149 1276
 				break;
1150 1277
 			}
1151 1278
 			elseif (substr($path,0,$strlen_p+1) == $p.'/')
@@ -1154,7 +1281,10 @@  discard block
 block discarded – undo
1154 1281
 				break;
1155 1282
 			}
1156 1283
 		}
1157
-		if (self::LOG_LEVEL > 1 && isset($target)) error_log(__METHOD__."($path) = $target");
1284
+		if (self::LOG_LEVEL > 1 && isset($target))
1285
+		{
1286
+			error_log(__METHOD__."($path) = $target");
1287
+		}
1158 1288
 		return isset($target) ? $target : $path;
1159 1289
 	}
1160 1290
 
@@ -1203,7 +1333,10 @@  discard block
 block discarded – undo
1203 1333
 				self::HIDE_UNREADABLES && !$this->opened_dir_writable &&
1204 1334
 				!Vfs::check_access(Vfs::concat($this->opened_dir_url,$file),Vfs::READABLE)));
1205 1335
 		}
1206
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( $this->opened_dir ) = '$file'");
1336
+		if (self::LOG_LEVEL > 1)
1337
+		{
1338
+			error_log(__METHOD__."( $this->opened_dir ) = '$file'");
1339
+		}
1207 1340
 		return $file;
1208 1341
 	}
1209 1342
 
@@ -1306,7 +1439,10 @@  discard block
 block discarded – undo
1306 1439
 		) as $class)
1307 1440
 		{
1308 1441
 			//error_log(__METHOD__."('$scheme') class_exists('$class')=".array2string(class_exists($class)));
1309
-			if (class_exists($class))  return $class;
1442
+			if (class_exists($class))
1443
+			{
1444
+				return $class;
1445
+			}
1310 1446
 		}
1311 1447
 	}
1312 1448
 
@@ -1341,7 +1477,10 @@  discard block
 block discarded – undo
1341 1477
 			static $entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%24', '%2C', '%2F', '%3F', '%23', '%5B', '%5D');
1342 1478
 			static $replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "$", ",", "/", "?", "#", "[", "]");
1343 1479
 			static $str_replace = null;
1344
-			if (!isset($str_replace)) $str_replace = function_exists('mb_str_replace') ? 'mb_str_replace' : 'str_replace';
1480
+			if (!isset($str_replace))
1481
+			{
1482
+				$str_replace = function_exists('mb_str_replace') ? 'mb_str_replace' : 'str_replace';
1483
+			}
1345 1484
 
1346 1485
 			// Create encoded URL with special URL characters decoded so it can be parsed
1347 1486
 			// All other characters will be encoded
Please login to merge, or discard this patch.
api/src/Vfs/StreamWrapperIface.php 3 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -45,6 +45,7 @@  discard block
 block discarded – undo
45 45
 	 * This method is called when the stream is closed, using fclose().
46 46
 	 *
47 47
 	 * You must release any resources that were locked or allocated by the stream.
48
+	 * @return boolean
48 49
 	 */
49 50
 	function stream_close ( );
50 51
 
@@ -57,7 +58,7 @@  discard block
 block discarded – undo
57 58
 	 * You must also update the read/write position of the stream by the number of bytes that were successfully read.
58 59
 	 *
59 60
 	 * @param int $count
60
-	 * @return string/false up to count bytes read or false on EOF
61
+	 * @return string|false up to count bytes read or false on EOF
61 62
 	 */
62 63
 	function stream_read ( $count );
63 64
 
@@ -114,7 +115,7 @@  discard block
 block discarded – undo
114 115
 	 *
115 116
 	 * If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now.
116 117
 	 *
117
-	 * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
118
+	 * @return boolean TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
118 119
 	 */
119 120
 	function stream_flush ( );
120 121
 
@@ -188,7 +189,7 @@  discard block
 block discarded – undo
188 189
 	 * This method is called immediately when your stream object is created for examining directory contents with opendir().
189 190
 	 *
190 191
 	 * @param string $path URL that was passed to opendir() and that this object is expected to explore.
191
-	 * @return booelan
192
+	 * @return boolean
192 193
 	 */
193 194
 	function dir_opendir ( $path, $options );
194 195
 
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,10 +80,10 @@
 block discarded – undo
80 80
  	 * Important: PHP 5.0 introduced a bug that wasn't fixed until 5.1: the return value has to be the oposite!
81 81
  	 *
82 82
  	 * if(version_compare(PHP_VERSION,'5.0','>=') && version_compare(PHP_VERSION,'5.1','<'))
83
-  	 * {
83
+ 	 * {
84 84
  	 * 		$eof = !$eof;
85 85
  	 * }
86
-  	 *
86
+ 	 *
87 87
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
88 88
  	 */
89 89
 	function stream_eof ( );
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -39,14 +39,14 @@  discard block
 block discarded – undo
39 39
 	 * @param string $opened_path full path of the file/resource, if the open was successfull and STREAM_USE_PATH was set
40 40
 	 * @return boolean true if the ressource was opened successful, otherwise false
41 41
 	 */
42
-	function stream_open ( $path, $mode, $options, &$opened_path );
42
+	function stream_open($path, $mode, $options, &$opened_path);
43 43
 
44 44
 	/**
45 45
 	 * This method is called when the stream is closed, using fclose().
46 46
 	 *
47 47
 	 * You must release any resources that were locked or allocated by the stream.
48 48
 	 */
49
-	function stream_close ( );
49
+	function stream_close( );
50 50
 
51 51
 	/**
52 52
 	 * This method is called in response to fread() and fgets() calls on the stream.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 * @param int $count
60 60
 	 * @return string/false up to count bytes read or false on EOF
61 61
 	 */
62
-	function stream_read ( $count );
62
+	function stream_read($count);
63 63
 
64 64
 	/**
65 65
 	 * This method is called in response to fwrite() calls on the stream.
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * @param string $data
73 73
 	 * @return integer
74 74
 	 */
75
-	function stream_write ( $data );
75
+	function stream_write($data);
76 76
 
77 77
  	/**
78 78
  	 * This method is called in response to feof() calls on the stream.
@@ -86,14 +86,14 @@  discard block
 block discarded – undo
86 86
   	 *
87 87
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
88 88
  	 */
89
-	function stream_eof ( );
89
+	function stream_eof( );
90 90
 
91 91
 	/**
92 92
 	 * This method is called in response to ftell() calls on the stream.
93 93
 	 *
94 94
 	 * @return integer current read/write position of the stream
95 95
 	 */
96
- 	function stream_tell ( );
96
+ 	function stream_tell( );
97 97
 
98 98
  	/**
99 99
  	 * This method is called in response to fseek() calls on the stream.
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
  	 * 							SEEK_END - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.)
108 108
  	 * @return boolean TRUE if the position was updated, FALSE otherwise.
109 109
  	 */
110
-	function stream_seek ( $offset, $whence );
110
+	function stream_seek($offset, $whence);
111 111
 
112 112
 	/**
113 113
 	 * This method is called in response to fflush() calls on the stream.
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 *
117 117
 	 * @return booelan TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
118 118
 	 */
119
-	function stream_flush ( );
119
+	function stream_flush( );
120 120
 
121 121
 	/**
122 122
 	 * This method is called in response to fstat() calls on the stream.
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 *
133 133
 	 * @return array containing the same values as appropriate for the stream.
134 134
 	 */
135
-	function stream_stat ( );
135
+	function stream_stat( );
136 136
 
137 137
 	/**
138 138
 	 * This method is called in response to unlink() calls on URL paths associated with the wrapper.
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * @param string $path
144 144
 	 * @return boolean TRUE on success or FALSE on failure
145 145
 	 */
146
-	static function unlink ( $path );
146
+	static function unlink($path);
147 147
 
148 148
 	/**
149 149
 	 * This method is called in response to rename() calls on URL paths associated with the wrapper.
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 * @param string $path_to
158 158
 	 * @return boolean TRUE on success or FALSE on failure
159 159
 	 */
160
-	static function rename ( $path_from, $path_to );
160
+	static function rename($path_from, $path_to);
161 161
 
162 162
 	/**
163 163
 	 * This method is called in response to mkdir() calls on URL paths associated with the wrapper.
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
171 171
 	 * @return boolean TRUE on success or FALSE on failure
172 172
 	 */
173
-	static function mkdir ( $path, $mode, $options );
173
+	static function mkdir($path, $mode, $options);
174 174
 
175 175
 	/**
176 176
 	 * This method is called in response to rmdir() calls on URL paths associated with the wrapper.
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @param int $options Possible values include STREAM_REPORT_ERRORS.
183 183
 	 * @return boolean TRUE on success or FALSE on failure.
184 184
 	 */
185
-	static function rmdir ( $path, $options );
185
+	static function rmdir($path, $options);
186 186
 
187 187
 	/**
188 188
 	 * This method is called immediately when your stream object is created for examining directory contents with opendir().
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	 * @param string $path URL that was passed to opendir() and that this object is expected to explore.
191 191
 	 * @return booelan
192 192
 	 */
193
-	function dir_opendir ( $path, $options );
193
+	function dir_opendir($path, $options);
194 194
 
195 195
 	/**
196 196
 	 * This method is called in response to stat() calls on the URL paths associated with the wrapper.
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	 *                          stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper!
219 219
 	 * @return array
220 220
 	 */
221
-	static function url_stat ( $path, $flags );
221
+	static function url_stat($path, $flags);
222 222
 
223 223
 	/**
224 224
 	 * This method is called in response to readdir().
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 * @return string
229 229
 	 */
230
-	function dir_readdir ( );
230
+	function dir_readdir( );
231 231
 
232 232
 	/**
233 233
 	 * This method is called in response to rewinddir().
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	 *
238 238
 	 * @return boolean
239 239
 	 */
240
-	function dir_rewinddir ( );
240
+	function dir_rewinddir( );
241 241
 
242 242
 	/**
243 243
 	 * This method is called in response to closedir().
@@ -246,5 +246,5 @@  discard block
 block discarded – undo
246 246
 	 *
247 247
 	 * @return boolean
248 248
 	 */
249
-	function dir_closedir ( );
249
+	function dir_closedir( );
250 250
 }
Please login to merge, or discard this patch.
api/src/Vfs/WebDAV.php 5 patches
Doc Comments   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	* Reimplemented to not check our vfs base path with realpath and connect to mysql DB
58 58
 	*
59 59
 	* @access public
60
-    * @param  $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php
60
+    * @param  string $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php
61 61
 	*/
62 62
 	function ServeRequest($prefix=null)
63 63
 	{
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	* DELETE method handler
77 77
 	*
78 78
 	* @param  array  general parameter passing array
79
-	* @return bool   true on success
79
+	* @return string   true on success
80 80
 	*/
81 81
 	function DELETE($options)
82 82
 	{
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      * Reimplemented to NOT use dirname/basename, which has problems with utf-8 chars
117 117
      *
118 118
      * @param  array  general parameter passing array
119
-     * @return bool   true on success
119
+     * @return string   true on success
120 120
      */
121 121
     function MKCOL($options)
122 122
     {
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      * COPY method handler
152 152
      *
153 153
      * @param  array  general parameter passing array
154
-     * @return bool   true on success
154
+     * @return string   true on success
155 155
      */
156 156
     function COPY($options, $del=false)
157 157
     {
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * but in the regular vfs attributes.
478 478
 	 *
479 479
 	 * @param  array  general parameter passing array
480
-	 * @return bool   true on success
480
+	 * @return string   true on success
481 481
 	 */
482 482
 	function PROPPATCH(&$options)
483 483
 	{
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
 	 * LOCK method handler
558 558
 	 *
559 559
 	 * @param  array  general parameter passing array
560
-	 * @return bool   true on success
560
+	 * @return string|boolean   true on success
561 561
 	 */
562 562
 	function LOCK(&$options)
563 563
 	{
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 	 * UNLOCK method handler
584 584
 	 *
585 585
 	 * @param  array  general parameter passing array
586
-	 * @return bool   true on success
586
+	 * @return string   true on success
587 587
 	 */
588 588
 	function UNLOCK(&$options)
589 589
 	{
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 	 * Reimplement to add a Content-Disposition header, if ?download is appended to the REQUEST_URI
641 641
 	 *
642 642
 	 * @param  array  parameter passing array
643
-	 * @return bool   true on success
643
+	 * @return boolean|null   true on success
644 644
 	 */
645 645
 	function GET(&$options)
646 646
 	{
Please login to merge, or discard this patch.
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -52,13 +52,13 @@  discard block
 block discarded – undo
52 52
 	var $debug = 0;
53 53
 
54 54
 	/**
55
-	* Serve a webdav request
56
-	*
57
-	* Reimplemented to not check our vfs base path with realpath and connect to mysql DB
58
-	*
59
-	* @access public
60
-    * @param  $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php
61
-	*/
55
+	 * Serve a webdav request
56
+	 *
57
+	 * Reimplemented to not check our vfs base path with realpath and connect to mysql DB
58
+	 *
59
+	 * @access public
60
+	 * @param  $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php
61
+	 */
62 62
 	function ServeRequest($prefix=null)
63 63
 	{
64 64
 		// special treatment for litmus compliance test
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
 	}
74 74
 
75 75
 	/**
76
-	* DELETE method handler
77
-	*
78
-	* @param  array  general parameter passing array
79
-	* @return bool   true on success
80
-	*/
76
+	 * DELETE method handler
77
+	 *
78
+	 * @param  array  general parameter passing array
79
+	 * @return bool   true on success
80
+	 */
81 81
 	function DELETE($options)
82 82
 	{
83 83
 		$path = $this->base . $options['path'];
@@ -110,165 +110,165 @@  discard block
 block discarded – undo
110 110
 		return '204 No Content';
111 111
 	}
112 112
 
113
-    /**
114
-     * MKCOL method handler
115
-     *
116
-     * Reimplemented to NOT use dirname/basename, which has problems with utf-8 chars
117
-     *
118
-     * @param  array  general parameter passing array
119
-     * @return bool   true on success
120
-     */
121
-    function MKCOL($options)
122
-    {
123
-        $path   = $this->_unslashify($this->base .$options["path"]);
124
-        $parent = Vfs::dirname($path);
125
-
126
-        if (!file_exists($parent)) {
127
-            return "409 Conflict";
128
-        }
129
-
130
-        if (!is_dir($parent)) {
131
-            return "403 Forbidden";
132
-        }
133
-
134
-        if ( file_exists($path) ) {
135
-            return "405 Method not allowed";
136
-        }
137
-
138
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
139
-            return "415 Unsupported media type";
140
-        }
141
-
142
-        $stat = mkdir($path, 0777);
143
-        if (!$stat) {
144
-            return "403 Forbidden";
145
-        }
146
-
147
-        return ("201 Created");
148
-    }
113
+	/**
114
+	 * MKCOL method handler
115
+	 *
116
+	 * Reimplemented to NOT use dirname/basename, which has problems with utf-8 chars
117
+	 *
118
+	 * @param  array  general parameter passing array
119
+	 * @return bool   true on success
120
+	 */
121
+	function MKCOL($options)
122
+	{
123
+		$path   = $this->_unslashify($this->base .$options["path"]);
124
+		$parent = Vfs::dirname($path);
125
+
126
+		if (!file_exists($parent)) {
127
+			return "409 Conflict";
128
+		}
129
+
130
+		if (!is_dir($parent)) {
131
+			return "403 Forbidden";
132
+		}
133
+
134
+		if ( file_exists($path) ) {
135
+			return "405 Method not allowed";
136
+		}
137
+
138
+		if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
139
+			return "415 Unsupported media type";
140
+		}
141
+
142
+		$stat = mkdir($path, 0777);
143
+		if (!$stat) {
144
+			return "403 Forbidden";
145
+		}
146
+
147
+		return ("201 Created");
148
+	}
149 149
 
150 150
 	/**
151
-     * COPY method handler
152
-     *
153
-     * @param  array  general parameter passing array
154
-     * @return bool   true on success
155
-     */
156
-    function COPY($options, $del=false)
157
-    {
158
-        // TODO Property updates still broken (Litmus should detect this?)
159
-
160
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
161
-            return "415 Unsupported media type";
162
-        }
163
-
164
-        // no copying to different WebDAV Servers yet
165
-        if (isset($options["dest_url"])) {
166
-            return "502 bad gateway";
167
-        }
168
-
169
-        $source = $this->base .$options["path"];
170
-        if (!file_exists($source)) return "404 Not found";
171
-
172
-        if (is_dir($source)) { // resource is a collection
173
-            switch ($options["depth"]) {
174
-            case "infinity": // valid
175
-                break;
176
-            case "0": // valid for COPY only
177
-                if ($del) { // MOVE?
178
-                    return "400 Bad request";
179
-                }
180
-                break;
181
-            case "1": // invalid for both COPY and MOVE
182
-            default:
183
-                return "400 Bad request";
184
-            }
185
-        }
186
-
187
-        $dest         = $this->base . $options["dest"];
188
-        $destdir      = dirname($dest);
189
-
190
-        if (!file_exists($destdir) || !is_dir($destdir)) {
191
-            return "409 Conflict";
192
-        }
193
-
194
-        $new          = !file_exists($dest);
195
-        $existing_col = false;
196
-
197
-        if (!$new) {
198
-            if ($del && is_dir($dest)) {
199
-                if (!$options["overwrite"]) {
200
-                    return "412 precondition failed";
201
-                }
202
-                $dest .= basename($source);
203
-                if (file_exists($dest)) {
204
-                    $options["dest"] .= basename($source);
205
-                } else {
206
-                    $new          = true;
207
-                    $existing_col = true;
208
-                }
209
-            }
210
-        }
211
-
212
-        if (!$new) {
213
-            if ($options["overwrite"]) {
214
-                $stat = $this->DELETE(array("path" => $options["dest"]));
215
-                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
216
-                    return $stat;
217
-                }
218
-            } else {
219
-                return "412 precondition failed";
220
-            }
221
-        }
222
-
223
-        if ($del) {
224
-            if (!rename($source, $dest)) {
225
-                return "500 Internal server error";
226
-            }
227
-        } else {
228
-            if (is_dir($source) && $options['depth'] == 'infinity') {
229
-            	$files = Vfs::find($source,array('depth' => true,'url' => true));	// depth=true: return dirs first, url=true: allow urls!
230
-            } else {
231
-                $files = array($source);
232
-            }
233
-
234
-            if (!is_array($files) || empty($files)) {
235
-                return "500 Internal server error";
236
-            }
237
-
238
-
239
-            foreach ($files as $file) {
240
-                if (is_dir($file)) {
241
-                    $file = $this->_slashify($file);
242
-                }
243
-
244
-                $destfile = str_replace($source, $dest, $file);
245
-
246
-                if (is_dir($file)) {
247
-                    if (!is_dir($destfile)) {
248
-                        // TODO "mkdir -p" here? (only natively supported by PHP 5)
249
-                        if (!@mkdir($destfile)) {
250
-                            return "409 Conflict";
251
-                        }
252
-                    }
253
-                } else {
254
-                    if (!@copy($file, $destfile)) {
255
-                        return "409 Conflict";
256
-                    }
257
-                }
258
-            }
259
-        }
260
-        // adding Location header as shown in example in rfc2518 section 8.9.5
151
+	 * COPY method handler
152
+	 *
153
+	 * @param  array  general parameter passing array
154
+	 * @return bool   true on success
155
+	 */
156
+	function COPY($options, $del=false)
157
+	{
158
+		// TODO Property updates still broken (Litmus should detect this?)
159
+
160
+		if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
161
+			return "415 Unsupported media type";
162
+		}
163
+
164
+		// no copying to different WebDAV Servers yet
165
+		if (isset($options["dest_url"])) {
166
+			return "502 bad gateway";
167
+		}
168
+
169
+		$source = $this->base .$options["path"];
170
+		if (!file_exists($source)) return "404 Not found";
171
+
172
+		if (is_dir($source)) { // resource is a collection
173
+			switch ($options["depth"]) {
174
+			case "infinity": // valid
175
+				break;
176
+			case "0": // valid for COPY only
177
+				if ($del) { // MOVE?
178
+					return "400 Bad request";
179
+				}
180
+				break;
181
+			case "1": // invalid for both COPY and MOVE
182
+			default:
183
+				return "400 Bad request";
184
+			}
185
+		}
186
+
187
+		$dest         = $this->base . $options["dest"];
188
+		$destdir      = dirname($dest);
189
+
190
+		if (!file_exists($destdir) || !is_dir($destdir)) {
191
+			return "409 Conflict";
192
+		}
193
+
194
+		$new          = !file_exists($dest);
195
+		$existing_col = false;
196
+
197
+		if (!$new) {
198
+			if ($del && is_dir($dest)) {
199
+				if (!$options["overwrite"]) {
200
+					return "412 precondition failed";
201
+				}
202
+				$dest .= basename($source);
203
+				if (file_exists($dest)) {
204
+					$options["dest"] .= basename($source);
205
+				} else {
206
+					$new          = true;
207
+					$existing_col = true;
208
+				}
209
+			}
210
+		}
211
+
212
+		if (!$new) {
213
+			if ($options["overwrite"]) {
214
+				$stat = $this->DELETE(array("path" => $options["dest"]));
215
+				if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
216
+					return $stat;
217
+				}
218
+			} else {
219
+				return "412 precondition failed";
220
+			}
221
+		}
222
+
223
+		if ($del) {
224
+			if (!rename($source, $dest)) {
225
+				return "500 Internal server error";
226
+			}
227
+		} else {
228
+			if (is_dir($source) && $options['depth'] == 'infinity') {
229
+				$files = Vfs::find($source,array('depth' => true,'url' => true));	// depth=true: return dirs first, url=true: allow urls!
230
+			} else {
231
+				$files = array($source);
232
+			}
233
+
234
+			if (!is_array($files) || empty($files)) {
235
+				return "500 Internal server error";
236
+			}
237
+
238
+
239
+			foreach ($files as $file) {
240
+				if (is_dir($file)) {
241
+					$file = $this->_slashify($file);
242
+				}
243
+
244
+				$destfile = str_replace($source, $dest, $file);
245
+
246
+				if (is_dir($file)) {
247
+					if (!is_dir($destfile)) {
248
+						// TODO "mkdir -p" here? (only natively supported by PHP 5)
249
+						if (!@mkdir($destfile)) {
250
+							return "409 Conflict";
251
+						}
252
+					}
253
+				} else {
254
+					if (!@copy($file, $destfile)) {
255
+						return "409 Conflict";
256
+					}
257
+				}
258
+			}
259
+		}
260
+		// adding Location header as shown in example in rfc2518 section 8.9.5
261 261
 		header('Location: '.$this->base_uri.$options['dest']);
262 262
 
263
-        return ($new && !$existing_col) ? "201 Created" : "204 No Content";
264
-    }
263
+		return ($new && !$existing_col) ? "201 Created" : "204 No Content";
264
+	}
265 265
 
266
-    /**
267
-	* Get properties for a single file/resource
268
-	*
269
-	* @param  string  $_path resource path
270
-	* @return array   resource properties
271
-	*/
266
+	/**
267
+	 * Get properties for a single file/resource
268
+	 *
269
+	 * @param  string  $_path resource path
270
+	 * @return array   resource properties
271
+	 */
272 272
 	function fileinfo($_path)
273 273
 	{
274 274
 		// internally we require some url-encoding, as vfs_stream_wrapper uses URL's internally
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
 		$info['props'][] = self::mkprop	('creationdate',    filectime($fspath));
297 297
 		$info['props'][] = self::mkprop	('getlastmodified', filemtime($fspath));
298 298
 
299
-        // Microsoft extensions: last access time and 'hidden' status
300
-        $info["props"][] = self::mkprop("lastaccessed",    fileatime($fspath));
301
-        $info["props"][] = self::mkprop("ishidden",        Vfs::is_hidden($fspath));
299
+		// Microsoft extensions: last access time and 'hidden' status
300
+		$info["props"][] = self::mkprop("lastaccessed",    fileatime($fspath));
301
+		$info["props"][] = self::mkprop("ishidden",        Vfs::is_hidden($fspath));
302 302
 
303 303
 		// type and size (caller already made sure that path exists)
304 304
 		if (is_dir($fspath)) {
@@ -436,38 +436,38 @@  discard block
 block discarded – undo
436 436
 	}
437 437
 
438 438
  	/**
439
-	 * Used eg. by get
440
-	 *
441
-	 * @todo replace all calls to _mimetype with Vfs::mime_content_type()
442
-	 * @param string $path
443
-	 * @return string
444
-	 */
439
+ 	 * Used eg. by get
440
+ 	 *
441
+ 	 * @todo replace all calls to _mimetype with Vfs::mime_content_type()
442
+ 	 * @param string $path
443
+ 	 * @return string
444
+ 	 */
445 445
 	function _mimetype($path)
446 446
 	{
447 447
 		return Vfs::mime_content_type($path);
448 448
 	}
449 449
 
450
-    /**
451
-     * Check if path is readable by current user
452
-     *
453
-     * @param string $fspath
454
-     * @return boolean
455
-     */
456
-    function _is_readable($fspath)
457
-    {
458
-    	return Vfs::is_readable($fspath);
459
-    }
460
-
461
-    /**
462
-     * Check if path is writable by current user
463
-     *
464
-     * @param string $fspath
465
-     * @return boolean
466
-     */
467
-    function _is_writable($fspath)
468
-    {
469
-    	return Vfs::is_writable($fspath);
470
-    }
450
+	/**
451
+	 * Check if path is readable by current user
452
+	 *
453
+	 * @param string $fspath
454
+	 * @return boolean
455
+	 */
456
+	function _is_readable($fspath)
457
+	{
458
+		return Vfs::is_readable($fspath);
459
+	}
460
+
461
+	/**
462
+	 * Check if path is writable by current user
463
+	 *
464
+	 * @param string $fspath
465
+	 * @return boolean
466
+	 */
467
+	function _is_writable($fspath)
468
+	{
469
+		return Vfs::is_writable($fspath);
470
+	}
471 471
 
472 472
 	/**
473 473
 	 * PROPPATCH method handler
@@ -610,13 +610,13 @@  discard block
 block discarded – undo
610 610
 	 * @param  string  directory path
611 611
 	 * @return void    function has to handle HTTP response itself
612 612
 	 */
613
-    function GetDir($fspath, &$options)
614
-    {
613
+	function GetDir($fspath, &$options)
614
+	{
615 615
 		// add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv)
616 616
 		header('Content-type: text/html; charset='.Api\Translation::charset());
617 617
 
618 618
 		parent::GetDir($fspath, $options);
619
-    }
619
+	}
620 620
 
621 621
 	private $force_download = false;
622 622
 
Please login to merge, or discard this patch.
Switch Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -171,16 +171,16 @@
 block discarded – undo
171 171
 
172 172
         if (is_dir($source)) { // resource is a collection
173 173
             switch ($options["depth"]) {
174
-            case "infinity": // valid
175
-                break;
176
-            case "0": // valid for COPY only
177
-                if ($del) { // MOVE?
178
-                    return "400 Bad request";
179
-                }
180
-                break;
181
-            case "1": // invalid for both COPY and MOVE
182
-            default:
183
-                return "400 Bad request";
174
+            	case "infinity": // valid
175
+                	break;
176
+            	case "0": // valid for COPY only
177
+                	if ($del) { // MOVE?
178
+                    	return "400 Bad request";
179
+                	}
180
+                	break;
181
+            	case "1": // invalid for both COPY and MOVE
182
+            	default:
183
+                	return "400 Bad request";
184 184
             }
185 185
         }
186 186
 
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	* @access public
60 60
     * @param  $prefix =null prefix filesystem path with given path, eg. "/webdav" for owncloud 4.5 remote.php
61 61
 	*/
62
-	function ServeRequest($prefix=null)
62
+	function ServeRequest($prefix = null)
63 63
 	{
64 64
 		// special treatment for litmus compliance test
65 65
 		// reply on its identifier header
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	*/
81 81
 	function DELETE($options)
82 82
 	{
83
-		$path = $this->base . $options['path'];
83
+		$path = $this->base.$options['path'];
84 84
 
85 85
 		if (!file_exists($path))
86 86
 		{
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      */
121 121
     function MKCOL($options)
122 122
     {
123
-        $path   = $this->_unslashify($this->base .$options["path"]);
123
+        $path   = $this->_unslashify($this->base.$options["path"]);
124 124
         $parent = Vfs::dirname($path);
125 125
 
126 126
         if (!file_exists($parent)) {
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             return "403 Forbidden";
132 132
         }
133 133
 
134
-        if ( file_exists($path) ) {
134
+        if (file_exists($path)) {
135 135
             return "405 Method not allowed";
136 136
         }
137 137
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      * @param  array  general parameter passing array
154 154
      * @return bool   true on success
155 155
      */
156
-    function COPY($options, $del=false)
156
+    function COPY($options, $del = false)
157 157
     {
158 158
         // TODO Property updates still broken (Litmus should detect this?)
159 159
 
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
             return "502 bad gateway";
167 167
         }
168 168
 
169
-        $source = $this->base .$options["path"];
169
+        $source = $this->base.$options["path"];
170 170
         if (!file_exists($source)) return "404 Not found";
171 171
 
172 172
         if (is_dir($source)) { // resource is a collection
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
             }
185 185
         }
186 186
 
187
-        $dest         = $this->base . $options["dest"];
187
+        $dest         = $this->base.$options["dest"];
188 188
         $destdir      = dirname($dest);
189 189
 
190 190
         if (!file_exists($destdir) || !is_dir($destdir)) {
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
             }
227 227
         } else {
228 228
             if (is_dir($source) && $options['depth'] == 'infinity') {
229
-            	$files = Vfs::find($source,array('depth' => true,'url' => true));	// depth=true: return dirs first, url=true: allow urls!
229
+            	$files = Vfs::find($source, array('depth' => true, 'url' => true)); // depth=true: return dirs first, url=true: allow urls!
230 230
             } else {
231 231
                 $files = array($source);
232 232
             }
@@ -272,16 +272,16 @@  discard block
 block discarded – undo
272 272
 	function fileinfo($_path)
273 273
 	{
274 274
 		// internally we require some url-encoding, as vfs_stream_wrapper uses URL's internally
275
-		$path = str_replace(array('#','?'),array('%23','%3F'),$_path);
275
+		$path = str_replace(array('#', '?'), array('%23', '%3F'), $_path);
276 276
 
277 277
 		//error_log(__METHOD__."($path)");
278 278
 		// map URI path to filesystem path
279
-		$fspath = $this->base . $path;
279
+		$fspath = $this->base.$path;
280 280
 
281 281
 		// create result array
282 282
 		$info = array();
283 283
 		// TODO remove slash append code when base class is able to do it itself
284
-		$info['path']  = is_dir($fspath) ? $this->_slashify($path) : $path;
284
+		$info['path'] = is_dir($fspath) ? $this->_slashify($path) : $path;
285 285
 
286 286
 		// remove all urlencoding we need internally in EGw, HTTP_WebDAV_Server will add it's own!
287 287
 		// rawurldecode does NOT touch +
@@ -290,32 +290,32 @@  discard block
 block discarded – undo
290 290
 		$info['props'] = array();
291 291
 
292 292
 		// no special beautified displayname here ...
293
-		$info['props'][] = self::mkprop	('displayname', Vfs::basename(self::_unslashify($info['path'])));
293
+		$info['props'][] = self::mkprop('displayname', Vfs::basename(self::_unslashify($info['path'])));
294 294
 
295 295
 		// creation and modification time
296
-		$info['props'][] = self::mkprop	('creationdate',    filectime($fspath));
297
-		$info['props'][] = self::mkprop	('getlastmodified', filemtime($fspath));
296
+		$info['props'][] = self::mkprop('creationdate', filectime($fspath));
297
+		$info['props'][] = self::mkprop('getlastmodified', filemtime($fspath));
298 298
 
299 299
         // Microsoft extensions: last access time and 'hidden' status
300
-        $info["props"][] = self::mkprop("lastaccessed",    fileatime($fspath));
301
-        $info["props"][] = self::mkprop("ishidden",        Vfs::is_hidden($fspath));
300
+        $info["props"][] = self::mkprop("lastaccessed", fileatime($fspath));
301
+        $info["props"][] = self::mkprop("ishidden", Vfs::is_hidden($fspath));
302 302
 
303 303
 		// type and size (caller already made sure that path exists)
304 304
 		if (is_dir($fspath)) {
305 305
 			// directory (WebDAV collection)
306
-			$info['props'][] = self::mkprop	('resourcetype', array(
306
+			$info['props'][] = self::mkprop('resourcetype', array(
307 307
 			 	self::mkprop('collection', '')));
308
-			$info['props'][] = self::mkprop	('getcontenttype', 'httpd/unix-directory');
308
+			$info['props'][] = self::mkprop('getcontenttype', 'httpd/unix-directory');
309 309
 		} else {
310 310
 			// plain file (WebDAV resource)
311
-			$info['props'][] = self::mkprop	('resourcetype', '');
311
+			$info['props'][] = self::mkprop('resourcetype', '');
312 312
 			if (Vfs::is_readable($path)) {
313
-				$info['props'][] = self::mkprop	('getcontenttype', Vfs::mime_content_type($path));
313
+				$info['props'][] = self::mkprop('getcontenttype', Vfs::mime_content_type($path));
314 314
 			} else {
315 315
 				error_log(__METHOD__."($path) $fspath is not readable!");
316
-				$info['props'][] = self::mkprop	('getcontenttype', 'application/x-non-readable');
316
+				$info['props'][] = self::mkprop('getcontenttype', 'application/x-non-readable');
317 317
 			}
318
-			$info['props'][] = self::mkprop	('getcontentlength', filesize($fspath));
318
+			$info['props'][] = self::mkprop('getcontentlength', filesize($fspath));
319 319
 		}
320 320
 		// generate etag from inode (sqlfs: fs_id), modification time and size
321 321
 		$stat = stat($fspath);
@@ -369,21 +369,21 @@  discard block
 block discarded – undo
369 369
 	 */
370 370
 	function PROPFIND(&$options, &$files)
371 371
 	{
372
-		if (!parent::PROPFIND($options,$files))
372
+		if (!parent::PROPFIND($options, $files))
373 373
 		{
374 374
 			return false;
375 375
 		}
376 376
 		$path2n = array();
377
-		foreach($files['files'] as $n => $info)
377
+		foreach ($files['files'] as $n => $info)
378 378
 		{
379 379
 			// do NOT report /clientsync/.favorites/, as it fails
380
-			if (strpos($info['path'],'/clientsync/.favorites/') === 0)
380
+			if (strpos($info['path'], '/clientsync/.favorites/') === 0)
381 381
 			{
382 382
 				unset($files['files'][$n]);
383 383
 				continue;
384 384
 			}
385 385
 			$_path = $info['path'];
386
-			if (!$n && $info['path'] != '/' && substr($info['path'],-1) == '/') $_path = substr($info['path'],0,-1);
386
+			if (!$n && $info['path'] != '/' && substr($info['path'], -1) == '/') $_path = substr($info['path'], 0, -1);
387 387
 
388 388
 			// need to encode path again, as $info['path'] is NOT encoded, but Vfs::(stat|propfind) require it
389 389
 			// otherwise pathes containing url special chars like ? or # will not stat
@@ -393,21 +393,21 @@  discard block
 block discarded – undo
393 393
 			// adding some properties used instead of regular DAV times
394 394
 			if (($stat = Vfs::stat($path)))
395 395
 			{
396
-				$fileprops =& $files['files'][$path2n[$path]]['props'];
397
-				foreach(self::$auto_props as $attr => $props)
396
+				$fileprops = & $files['files'][$path2n[$path]]['props'];
397
+				foreach (self::$auto_props as $attr => $props)
398 398
 				{
399
-					switch($attr)
399
+					switch ($attr)
400 400
 					{
401 401
 						case 'ctime':
402 402
 						case 'mtime':
403 403
 						case 'atime':
404
-							$value = gmdate('D, d M Y H:i:s T',$stat[$attr]);
404
+							$value = gmdate('D, d M Y H:i:s T', $stat[$attr]);
405 405
 							break;
406 406
 
407 407
 						default:
408 408
 							continue 2;
409 409
 					}
410
-					foreach($props as $prop)
410
+					foreach ($props as $prop)
411 411
 					{
412 412
 						$prop['val'] = $value;
413 413
 						$fileprops[] = $prop;
@@ -415,17 +415,17 @@  discard block
 block discarded – undo
415 415
 				}
416 416
 			}
417 417
 		}
418
-		if ($path2n && ($path2props = Vfs::propfind(array_keys($path2n),null)))
418
+		if ($path2n && ($path2props = Vfs::propfind(array_keys($path2n), null)))
419 419
 		{
420
-			foreach($path2props as $path => $props)
420
+			foreach ($path2props as $path => $props)
421 421
 			{
422
-				$fileprops =& $files['files'][$path2n[$path]]['props'];
423
-				foreach($props as $prop)
422
+				$fileprops = & $files['files'][$path2n[$path]]['props'];
423
+				foreach ($props as $prop)
424 424
 				{
425 425
 					if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'][0] == '#')	// eGW's customfields
426 426
 					{
427 427
 						$prop['ns'] .= 'customfields/';
428
-						$prop['name'] = substr($prop['name'],1);
428
+						$prop['name'] = substr($prop['name'], 1);
429 429
 					}
430 430
 					$fileprops[] = $prop;
431 431
 				}
@@ -481,36 +481,36 @@  discard block
 block discarded – undo
481 481
 	 */
482 482
 	function PROPPATCH(&$options)
483 483
 	{
484
-		$path = Api\Translation::convert($options['path'],'utf-8');
484
+		$path = Api\Translation::convert($options['path'], 'utf-8');
485 485
 
486 486
 		foreach ($options['props'] as $key => $prop) {
487 487
 			$attributes = array();
488
-			switch($prop['ns'])
488
+			switch ($prop['ns'])
489 489
 			{
490 490
 				// allow Webdrive to set creation and modification time
491 491
 				case 'http://www.southrivertech.com/':
492
-					switch($prop['name'])
492
+					switch ($prop['name'])
493 493
 					{
494 494
 						case 'srt_modifiedtime':
495 495
 						case 'getlastmodified':
496
-							Vfs::touch($path,strtotime($prop['val']));
496
+							Vfs::touch($path, strtotime($prop['val']));
497 497
 							break;
498 498
 						//case 'srt_creationtime':
499 499
 							// no streamwrapper interface / php function to set the ctime currently
500 500
 							//$attributes['created'] = strtotime($prop['val']);
501 501
 							//break;
502 502
 						default:
503
-							if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
503
+							if (!Vfs::proppatch($path, array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
504 504
 							break;
505 505
 					}
506 506
 					break;
507 507
 
508 508
 				case 'DAV:':
509
-					switch($prop['name'])
509
+					switch ($prop['name'])
510 510
 					{
511 511
 						// allow netdrive to change the modification time
512 512
 						case 'getlastmodified':
513
-							Vfs::touch($path,strtotime($prop['val']));
513
+							Vfs::touch($path, strtotime($prop['val']));
514 514
 							break;
515 515
 						// not sure why, the filesystem example of the WebDAV class does it ...
516 516
 						default:
@@ -520,16 +520,16 @@  discard block
 block discarded – undo
520 520
 					break;
521 521
 
522 522
 				case 'urn:schemas-microsoft-com:':
523
-					switch($prop['name'])
523
+					switch ($prop['name'])
524 524
 					{
525 525
 						case 'Win32LastModifiedTime':
526
-							Vfs::touch($path,strtotime($prop['val']));
526
+							Vfs::touch($path, strtotime($prop['val']));
527 527
 							break;
528 528
 						case 'Win32CreationTime':	// eg. "Wed, 14 Sep 2011 15:48:26 GMT"
529 529
 						case 'Win32LastAccessTime':
530 530
 						case 'Win32FileAttributes':	// not sure what that is, it was always "00000000"
531 531
 						default:
532
-							if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
532
+							if (!Vfs::proppatch($path, array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
533 533
 							break;
534 534
 					}
535 535
 					break;
@@ -539,18 +539,18 @@  discard block
 block discarded – undo
539 539
 					$prop['name'] = '#'.$prop['name'];
540 540
 					// fall through
541 541
 				default:
542
-					if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
542
+					if (!Vfs::proppatch($path, array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
543 543
 					break;
544 544
 			}
545 545
 			if ($this->debug) $props[] = '('.$prop['ns'].')'.$prop['name'].'='.$prop['val'];
546 546
 		}
547 547
 		if ($this->debug)
548 548
 		{
549
-			error_log(__METHOD__.": path=$options[path], props=".implode(', ',$props));
550
-			if ($attributes) error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n",' ',print_r($attributes,true)));
549
+			error_log(__METHOD__.": path=$options[path], props=".implode(', ', $props));
550
+			if ($attributes) error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n", ' ', print_r($attributes, true)));
551 551
 		}
552 552
 
553
-		return '';	// this is as the filesystem example handler does it, no true or false ...
553
+		return ''; // this is as the filesystem example handler does it, no true or false ...
554 554
 	}
555 555
 
556 556
 	/**
@@ -561,18 +561,18 @@  discard block
 block discarded – undo
561 561
 	 */
562 562
 	function LOCK(&$options)
563 563
 	{
564
-		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
564
+		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n", '    '), '', print_r($options, true)).')');
565 565
 		// TODO recursive locks on directories not supported yet
566
-		if (is_dir($this->base . $options['path']) && !empty($options['depth']))
566
+		if (is_dir($this->base.$options['path']) && !empty($options['depth']))
567 567
 		{
568 568
 			return '409 Conflict';
569 569
 		}
570
-		$options['timeout'] = time()+300; // 5min. hardcoded
570
+		$options['timeout'] = time() + 300; // 5min. hardcoded
571 571
 
572 572
 		// dont know why, but HTTP_WebDAV_Server passes the owner in D:href tags, which get's passed unchanged to checkLock/PROPFIND
573 573
 		// that's wrong according to the standard and cadaver does not show it on discover --> strip_tags removes eventual tags
574
-		if (($ret = Vfs::lock($options['path'],$options['locktoken'],$options['timeout'],strip_tags($options['owner']),
575
-			$options['scope'],$options['type'],isset($options['update']))) && !isset($options['update']))
574
+		if (($ret = Vfs::lock($options['path'], $options['locktoken'], $options['timeout'], strip_tags($options['owner']),
575
+			$options['scope'], $options['type'], isset($options['update']))) && !isset($options['update']))
576 576
 		{
577 577
 			return $ret ? '200 OK' : '409 Conflict';
578 578
 		}
@@ -587,8 +587,8 @@  discard block
 block discarded – undo
587 587
 	 */
588 588
 	function UNLOCK(&$options)
589 589
 	{
590
-		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
591
-		return Vfs::unlock($options['path'],$options['token']) ? '204 No Content' : '409 Conflict';
590
+		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n", '    '), '', print_r($options, true)).')');
591
+		return Vfs::unlock($options['path'], $options['token']) ? '204 No Content' : '409 Conflict';
592 592
 	}
593 593
 
594 594
 	/**
@@ -627,9 +627,9 @@  discard block
 block discarded – undo
627 627
 	 */
628 628
 	function __construct()
629 629
 	{
630
-		if ($_SERVER['REQUEST_METHOD'] == 'GET' && (($this->force_download = strpos($_SERVER['REQUEST_URI'],'?download')) !== false))
630
+		if ($_SERVER['REQUEST_METHOD'] == 'GET' && (($this->force_download = strpos($_SERVER['REQUEST_URI'], '?download')) !== false))
631 631
 		{
632
-			$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'],0,$this->force_download);
632
+			$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $this->force_download);
633 633
 		}
634 634
 		parent::__construct();
635 635
 	}
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 	 */
645 645
 	function GET(&$options)
646 646
 	{
647
-		if (is_dir($this->base . $options["path"]))
647
+		if (is_dir($this->base.$options["path"]))
648 648
 		{
649 649
 			return $this->autoindex($options);
650 650
 		}
@@ -652,11 +652,11 @@  discard block
 block discarded – undo
652 652
 		{
653 653
 			// mitigate risks of serving javascript or css from our domain
654 654
 			Api\Header\Content::safe($options['stream'], $options['path'], $options['mimetype'], $options['size'], false,
655
-				$this->force_download, true);	// true = do not send content-type and content-length header, but modify values
655
+				$this->force_download, true); // true = do not send content-type and content-length header, but modify values
656 656
 
657 657
 			if (!is_resource($options['stream']))
658 658
 			{
659
-				$options['data'] =& $options['stream'];
659
+				$options['data'] = & $options['stream'];
660 660
 				unset($options['stream']);
661 661
 			}
662 662
 		}
@@ -675,9 +675,9 @@  discard block
 block discarded – undo
675 675
 			'depth' => 1,
676 676
 		);
677 677
 		$files = array();
678
-		if (($ret = $this->PROPFIND($propfind_options,$files)) !== true)
678
+		if (($ret = $this->PROPFIND($propfind_options, $files)) !== true)
679 679
 		{
680
-			return $ret;	// no collection
680
+			return $ret; // no collection
681 681
 		}
682 682
 		header('Content-type: text/html; charset='.Api\Translation::charset());
683 683
 		echo "<html>\n<head>\n\t<title>".'EGroupware WebDAV server '.htmlspecialchars($options['path'])."</title>\n";
@@ -689,10 +689,10 @@  discard block
 block discarded – undo
689 689
 		echo '<h1>WebDAV ';
690 690
 		list(,$base) = explode(parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH), $this->base_uri, 2);
691 691
 		$path = $base;
692
-		foreach(explode('/',$this->_unslashify($options['path'])) as $n => $name)
692
+		foreach (explode('/', $this->_unslashify($options['path'])) as $n => $name)
693 693
 		{
694 694
 			$path .= ($n != 1 ? '/' : '').$name;
695
-			echo Api\Html::a_href(htmlspecialchars($name.'/'),$path);
695
+			echo Api\Html::a_href(htmlspecialchars($name.'/'), $path);
696 696
 		}
697 697
 		echo "</h1>\n";
698 698
 
@@ -709,18 +709,18 @@  discard block
 block discarded – undo
709 709
 		);
710 710
 		$n = 0;
711 711
 		$collection_props = null;
712
-		foreach($files['files'] as $file)
712
+		foreach ($files['files'] as $file)
713 713
 		{
714 714
 			if (!isset($collection_props))
715 715
 			{
716 716
 				$collection_props = $this->props2array($file['props']);
717 717
 				echo '<h3>'.lang('Collection listing').': '.htmlspecialchars($collection_props['DAV:displayname'])."</h3>\n";
718
-				continue;	// own entry --> displaying properies later
718
+				continue; // own entry --> displaying properies later
719 719
 			}
720
-			if(!$n++)
720
+			if (!$n++)
721 721
 			{
722 722
 				echo "<table>\n\t<tr class='th'>\n\t\t<th>#</th>\n\t\t<th>".lang('Name')."</th>";
723
-				foreach($props2show as $label)
723
+				foreach ($props2show as $label)
724 724
 				{
725 725
 					echo "\t\t<th>".lang($label)."</th>\n";
726 726
 				}
@@ -730,9 +730,9 @@  discard block
 block discarded – undo
730 730
 			//echo $file['path']; _debug_array($props);
731 731
 			$class = $class == 'row_on' ? 'row_off' : 'row_on';
732 732
 
733
-			if (substr($file['path'],-1) == '/')
733
+			if (substr($file['path'], -1) == '/')
734 734
 			{
735
-				$name = basename(substr($file['path'],0,-1)).'/';
735
+				$name = basename(substr($file['path'], 0, -1)).'/';
736 736
 			}
737 737
 			else
738 738
 			{
@@ -740,14 +740,14 @@  discard block
 block discarded – undo
740 740
 			}
741 741
 
742 742
 			echo "\t<tr class='$class'>\n\t\t<td>$n</td>\n\t\t<td>".
743
-				Api\Html::a_href(htmlspecialchars($name),$base.strtr($file['path'], array(
743
+				Api\Html::a_href(htmlspecialchars($name), $base.strtr($file['path'], array(
744 744
 					'%' => '%25',
745 745
 					'#' => '%23',
746 746
 					'?' => '%3F',
747 747
 				)))."</td>\n";
748
-			foreach($props2show as $prop => $label)
748
+			foreach ($props2show as $prop => $label)
749 749
 			{
750
-				echo "\t\t<td>".($prop=='DAV:getlastmodified'&&!empty($props[$prop])?date('Y-m-d H:i:s',$props[$prop]):$props[$prop])."</td>\n";
750
+				echo "\t\t<td>".($prop == 'DAV:getlastmodified' && !empty($props[$prop]) ? date('Y-m-d H:i:s', $props[$prop]) : $props[$prop])."</td>\n";
751 751
 			}
752 752
 			echo "\t</tr>\n";
753 753
 		}
@@ -761,12 +761,12 @@  discard block
 block discarded – undo
761 761
 		}
762 762
 		echo '<h3>'.lang('Properties')."</h3>\n";
763 763
 		echo "<table>\n\t<tr class='th'><th>".lang('Namespace')."</th><th>".lang('Name')."</th><th>".lang('Value')."</th></tr>\n";
764
-		foreach($collection_props as $name => $value)
764
+		foreach ($collection_props as $name => $value)
765 765
 		{
766 766
 			$class = $class == 'row_on' ? 'row_off' : 'row_on';
767
-			$parts = explode(':',$name);
767
+			$parts = explode(':', $name);
768 768
 			$name = array_pop($parts);
769
-			$ns = implode(':',$parts);
769
+			$ns = implode(':', $parts);
770 770
 			echo "\t<tr class='$class'>\n\t\t<td>".htmlspecialchars($ns)."</td><td style='white-space: nowrap'>".htmlspecialchars($name)."</td>\n";
771 771
 			echo "\t\t<td>".$value."</td>\n\t</tr>\n";
772 772
 		}
@@ -809,11 +809,11 @@  discard block
 block discarded – undo
809 809
 				'wrap'            => 0,
810 810
 			));
811 811
 		}
812
-		if (($href=preg_match('/\<(D:)?href\>[^<]+\<\/(D:)?href\>/i',$value)))
812
+		if (($href = preg_match('/\<(D:)?href\>[^<]+\<\/(D:)?href\>/i', $value)))
813 813
 		{
814
-			$value = preg_replace('/\<(D:)?href\>('.preg_quote($this->base_uri.'/','/').')?([^<]+)\<\/(D:)?href\>/i','<\\1href><a href="\\2\\3">\\3</a></\\4href>',$value);
814
+			$value = preg_replace('/\<(D:)?href\>('.preg_quote($this->base_uri.'/', '/').')?([^<]+)\<\/(D:)?href\>/i', '<\\1href><a href="\\2\\3">\\3</a></\\4href>', $value);
815 815
 		}
816
-		$ret = $value[0] == '<'  || strpos($value, "\n") !== false ?
816
+		$ret = $value[0] == '<' || strpos($value, "\n") !== false ?
817 817
 			'<pre>'.htmlspecialchars($value).'</pre>' : htmlspecialchars($value);
818 818
 
819 819
 		if ($href)
@@ -833,10 +833,10 @@  discard block
 block discarded – undo
833 833
 	protected function props2array(array $props)
834 834
 	{
835 835
 		$arr = array();
836
-		foreach($props as $prop)
836
+		foreach ($props as $prop)
837 837
 		{
838 838
 			$ns_hash = array('DAV:' => 'D');
839
-			switch($prop['ns'])
839
+			switch ($prop['ns'])
840 840
 			{
841 841
 				case 'DAV:';
842 842
 					$ns = 'DAV';
@@ -846,10 +846,10 @@  discard block
 block discarded – undo
846 846
 			}
847 847
 			if (is_array($prop['val']))
848 848
 			{
849
-				$prop['val'] = $this->_hierarchical_prop_encode($prop['val'], $prop['ns'], $ns_defs='', $ns_hash);
849
+				$prop['val'] = $this->_hierarchical_prop_encode($prop['val'], $prop['ns'], $ns_defs = '', $ns_hash);
850 850
 				// hack to show real namespaces instead of not (visibly) defined shortcuts
851 851
 				unset($ns_hash['DAV:']);
852
-				$value = strtr($v=$this->prop_value($prop['val']),array_flip($ns_hash));
852
+				$value = strtr($v = $this->prop_value($prop['val']), array_flip($ns_hash));
853 853
 			}
854 854
 			else
855 855
 			{
Please login to merge, or discard this patch.
Braces   +133 added lines, -50 removed lines patch added patch discarded remove patch
@@ -64,7 +64,8 @@  discard block
 block discarded – undo
64 64
 		// special treatment for litmus compliance test
65 65
 		// reply on its identifier header
66 66
 		// not needed for the test itself but eases debugging
67
-		if (isset($this->_SERVER['HTTP_X_LITMUS'])) {
67
+		if (isset($this->_SERVER['HTTP_X_LITMUS']))
68
+		{
68 69
 			error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']);
69 70
 			header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']);
70 71
 		}
@@ -123,24 +124,30 @@  discard block
 block discarded – undo
123 124
         $path   = $this->_unslashify($this->base .$options["path"]);
124 125
         $parent = Vfs::dirname($path);
125 126
 
126
-        if (!file_exists($parent)) {
127
+        if (!file_exists($parent))
128
+        {
127 129
             return "409 Conflict";
128 130
         }
129 131
 
130
-        if (!is_dir($parent)) {
132
+        if (!is_dir($parent))
133
+        {
131 134
             return "403 Forbidden";
132 135
         }
133 136
 
134
-        if ( file_exists($path) ) {
137
+        if ( file_exists($path) )
138
+        {
135 139
             return "405 Method not allowed";
136 140
         }
137 141
 
138
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
142
+        if (!empty($this->_SERVER["CONTENT_LENGTH"]))
143
+        {
144
+// no body parsing yet
139 145
             return "415 Unsupported media type";
140 146
         }
141 147
 
142 148
         $stat = mkdir($path, 0777);
143
-        if (!$stat) {
149
+        if (!$stat)
150
+        {
144 151
             return "403 Forbidden";
145 152
         }
146 153
 
@@ -157,24 +164,35 @@  discard block
 block discarded – undo
157 164
     {
158 165
         // TODO Property updates still broken (Litmus should detect this?)
159 166
 
160
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
167
+        if (!empty($this->_SERVER["CONTENT_LENGTH"]))
168
+        {
169
+// no body parsing yet
161 170
             return "415 Unsupported media type";
162 171
         }
163 172
 
164 173
         // no copying to different WebDAV Servers yet
165
-        if (isset($options["dest_url"])) {
174
+        if (isset($options["dest_url"]))
175
+        {
166 176
             return "502 bad gateway";
167 177
         }
168 178
 
169 179
         $source = $this->base .$options["path"];
170
-        if (!file_exists($source)) return "404 Not found";
180
+        if (!file_exists($source))
181
+        {
182
+        	return "404 Not found";
183
+        }
171 184
 
172
-        if (is_dir($source)) { // resource is a collection
173
-            switch ($options["depth"]) {
185
+        if (is_dir($source))
186
+        {
187
+// resource is a collection
188
+            switch ($options["depth"])
189
+            {
174 190
             case "infinity": // valid
175 191
                 break;
176 192
             case "0": // valid for COPY only
177
-                if ($del) { // MOVE?
193
+                if ($del)
194
+                {
195
+// MOVE?
178 196
                     return "400 Bad request";
179 197
                 }
180 198
                 break;
@@ -187,71 +205,99 @@  discard block
 block discarded – undo
187 205
         $dest         = $this->base . $options["dest"];
188 206
         $destdir      = dirname($dest);
189 207
 
190
-        if (!file_exists($destdir) || !is_dir($destdir)) {
208
+        if (!file_exists($destdir) || !is_dir($destdir))
209
+        {
191 210
             return "409 Conflict";
192 211
         }
193 212
 
194 213
         $new          = !file_exists($dest);
195 214
         $existing_col = false;
196 215
 
197
-        if (!$new) {
198
-            if ($del && is_dir($dest)) {
199
-                if (!$options["overwrite"]) {
216
+        if (!$new)
217
+        {
218
+            if ($del && is_dir($dest))
219
+            {
220
+                if (!$options["overwrite"])
221
+                {
200 222
                     return "412 precondition failed";
201 223
                 }
202 224
                 $dest .= basename($source);
203
-                if (file_exists($dest)) {
225
+                if (file_exists($dest))
226
+                {
204 227
                     $options["dest"] .= basename($source);
205
-                } else {
228
+                }
229
+                else
230
+                {
206 231
                     $new          = true;
207 232
                     $existing_col = true;
208 233
                 }
209 234
             }
210 235
         }
211 236
 
212
-        if (!$new) {
213
-            if ($options["overwrite"]) {
237
+        if (!$new)
238
+        {
239
+            if ($options["overwrite"])
240
+            {
214 241
                 $stat = $this->DELETE(array("path" => $options["dest"]));
215
-                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
242
+                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404"))
243
+                {
216 244
                     return $stat;
217 245
                 }
218
-            } else {
246
+            }
247
+            else
248
+            {
219 249
                 return "412 precondition failed";
220 250
             }
221 251
         }
222 252
 
223
-        if ($del) {
224
-            if (!rename($source, $dest)) {
253
+        if ($del)
254
+        {
255
+            if (!rename($source, $dest))
256
+            {
225 257
                 return "500 Internal server error";
226 258
             }
227
-        } else {
228
-            if (is_dir($source) && $options['depth'] == 'infinity') {
259
+        }
260
+        else
261
+        {
262
+            if (is_dir($source) && $options['depth'] == 'infinity')
263
+            {
229 264
             	$files = Vfs::find($source,array('depth' => true,'url' => true));	// depth=true: return dirs first, url=true: allow urls!
230
-            } else {
265
+            }
266
+            else
267
+            {
231 268
                 $files = array($source);
232 269
             }
233 270
 
234
-            if (!is_array($files) || empty($files)) {
271
+            if (!is_array($files) || empty($files))
272
+            {
235 273
                 return "500 Internal server error";
236 274
             }
237 275
 
238 276
 
239
-            foreach ($files as $file) {
240
-                if (is_dir($file)) {
277
+            foreach ($files as $file)
278
+            {
279
+                if (is_dir($file))
280
+                {
241 281
                     $file = $this->_slashify($file);
242 282
                 }
243 283
 
244 284
                 $destfile = str_replace($source, $dest, $file);
245 285
 
246
-                if (is_dir($file)) {
247
-                    if (!is_dir($destfile)) {
286
+                if (is_dir($file))
287
+                {
288
+                    if (!is_dir($destfile))
289
+                    {
248 290
                         // TODO "mkdir -p" here? (only natively supported by PHP 5)
249
-                        if (!@mkdir($destfile)) {
291
+                        if (!@mkdir($destfile))
292
+                        {
250 293
                             return "409 Conflict";
251 294
                         }
252 295
                     }
253
-                } else {
254
-                    if (!@copy($file, $destfile)) {
296
+                }
297
+                else
298
+                {
299
+                    if (!@copy($file, $destfile))
300
+                    {
255 301
                         return "409 Conflict";
256 302
                     }
257 303
                 }
@@ -301,17 +347,23 @@  discard block
 block discarded – undo
301 347
         $info["props"][] = self::mkprop("ishidden",        Vfs::is_hidden($fspath));
302 348
 
303 349
 		// type and size (caller already made sure that path exists)
304
-		if (is_dir($fspath)) {
350
+		if (is_dir($fspath))
351
+		{
305 352
 			// directory (WebDAV collection)
306 353
 			$info['props'][] = self::mkprop	('resourcetype', array(
307 354
 			 	self::mkprop('collection', '')));
308 355
 			$info['props'][] = self::mkprop	('getcontenttype', 'httpd/unix-directory');
309
-		} else {
356
+		}
357
+		else
358
+		{
310 359
 			// plain file (WebDAV resource)
311 360
 			$info['props'][] = self::mkprop	('resourcetype', '');
312
-			if (Vfs::is_readable($path)) {
361
+			if (Vfs::is_readable($path))
362
+			{
313 363
 				$info['props'][] = self::mkprop	('getcontenttype', Vfs::mime_content_type($path));
314
-			} else {
364
+			}
365
+			else
366
+			{
315 367
 				error_log(__METHOD__."($path) $fspath is not readable!");
316 368
 				$info['props'][] = self::mkprop	('getcontenttype', 'application/x-non-readable');
317 369
 			}
@@ -383,7 +435,10 @@  discard block
 block discarded – undo
383 435
 				continue;
384 436
 			}
385 437
 			$_path = $info['path'];
386
-			if (!$n && $info['path'] != '/' && substr($info['path'],-1) == '/') $_path = substr($info['path'],0,-1);
438
+			if (!$n && $info['path'] != '/' && substr($info['path'],-1) == '/')
439
+			{
440
+				$_path = substr($info['path'],0,-1);
441
+			}
387 442
 
388 443
 			// need to encode path again, as $info['path'] is NOT encoded, but Vfs::(stat|propfind) require it
389 444
 			// otherwise pathes containing url special chars like ? or # will not stat
@@ -422,16 +477,22 @@  discard block
 block discarded – undo
422 477
 				$fileprops =& $files['files'][$path2n[$path]]['props'];
423 478
 				foreach($props as $prop)
424 479
 				{
425
-					if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'][0] == '#')	// eGW's customfields
480
+					if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'][0] == '#')
481
+					{
482
+						// eGW's customfields
426 483
 					{
427 484
 						$prop['ns'] .= 'customfields/';
485
+					}
428 486
 						$prop['name'] = substr($prop['name'],1);
429 487
 					}
430 488
 					$fileprops[] = $prop;
431 489
 				}
432 490
 			}
433 491
 		}
434
-		if ($this->debug) error_log(__METHOD__."() props=".array2string($files['files']));
492
+		if ($this->debug)
493
+		{
494
+			error_log(__METHOD__."() props=".array2string($files['files']));
495
+		}
435 496
 		return true;
436 497
 	}
437 498
 
@@ -483,7 +544,8 @@  discard block
 block discarded – undo
483 544
 	{
484 545
 		$path = Api\Translation::convert($options['path'],'utf-8');
485 546
 
486
-		foreach ($options['props'] as $key => $prop) {
547
+		foreach ($options['props'] as $key => $prop)
548
+		{
487 549
 			$attributes = array();
488 550
 			switch($prop['ns'])
489 551
 			{
@@ -500,7 +562,10 @@  discard block
 block discarded – undo
500 562
 							//$attributes['created'] = strtotime($prop['val']);
501 563
 							//break;
502 564
 						default:
503
-							if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
565
+							if (!Vfs::proppatch($path,array($prop)))
566
+							{
567
+								$options['props'][$key]['status'] = '403 Forbidden';
568
+							}
504 569
 							break;
505 570
 					}
506 571
 					break;
@@ -529,7 +594,10 @@  discard block
 block discarded – undo
529 594
 						case 'Win32LastAccessTime':
530 595
 						case 'Win32FileAttributes':	// not sure what that is, it was always "00000000"
531 596
 						default:
532
-							if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
597
+							if (!Vfs::proppatch($path,array($prop)))
598
+							{
599
+								$options['props'][$key]['status'] = '403 Forbidden';
600
+							}
533 601
 							break;
534 602
 					}
535 603
 					break;
@@ -539,15 +607,24 @@  discard block
 block discarded – undo
539 607
 					$prop['name'] = '#'.$prop['name'];
540 608
 					// fall through
541 609
 				default:
542
-					if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
610
+					if (!Vfs::proppatch($path,array($prop)))
611
+					{
612
+						$options['props'][$key]['status'] = '403 Forbidden';
613
+					}
543 614
 					break;
544 615
 			}
545
-			if ($this->debug) $props[] = '('.$prop['ns'].')'.$prop['name'].'='.$prop['val'];
616
+			if ($this->debug)
617
+			{
618
+				$props[] = '('.$prop['ns'].')'.$prop['name'].'='.$prop['val'];
619
+			}
546 620
 		}
547 621
 		if ($this->debug)
548 622
 		{
549 623
 			error_log(__METHOD__.": path=$options[path], props=".implode(', ',$props));
550
-			if ($attributes) error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n",' ',print_r($attributes,true)));
624
+			if ($attributes)
625
+			{
626
+				error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n",' ',print_r($attributes,true)));
627
+			}
551 628
 		}
552 629
 
553 630
 		return '';	// this is as the filesystem example handler does it, no true or false ...
@@ -561,7 +638,10 @@  discard block
 block discarded – undo
561 638
 	 */
562 639
 	function LOCK(&$options)
563 640
 	{
564
-		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
641
+		if ($this->debug)
642
+		{
643
+			error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
644
+		}
565 645
 		// TODO recursive locks on directories not supported yet
566 646
 		if (is_dir($this->base . $options['path']) && !empty($options['depth']))
567 647
 		{
@@ -587,7 +667,10 @@  discard block
 block discarded – undo
587 667
 	 */
588 668
 	function UNLOCK(&$options)
589 669
 	{
590
-		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
670
+		if ($this->debug)
671
+		{
672
+			error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
673
+		}
591 674
 		return Vfs::unlock($options['path'],$options['token']) ? '204 No Content' : '409 Conflict';
592 675
 	}
593 676
 
Please login to merge, or discard this patch.
api/src/WebDAV/Server.php 6 patches
Doc Comments   +9 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2170,6 +2170,9 @@  discard block
 block discarded – undo
2170 2170
 
2171 2171
     // {{{ _copymove()
2172 2172
 
2173
+    /**
2174
+     * @param string $what
2175
+     */
2173 2176
     function _copymove($what)
2174 2177
     {
2175 2178
         $options         = Array();
@@ -2509,7 +2512,7 @@  discard block
 block discarded – undo
2509 2512
      * defined in RFC 2518 section 9.4
2510 2513
      *
2511 2514
      * @param  void
2512
-     * @return void
2515
+     * @return boolean
2513 2516
      */
2514 2517
     function _check_if_header_conditions()
2515 2518
     {
@@ -2581,6 +2584,7 @@  discard block
 block discarded – undo
2581 2584
      *
2582 2585
      * @param  string  path of resource to check
2583 2586
      * @param  bool    exclusive lock?
2587
+     * @param string $path
2584 2588
      */
2585 2589
     function _check_lock_status($path, $exclusive_only = false)
2586 2590
     {
@@ -2733,6 +2737,7 @@  discard block
 block discarded – undo
2733 2737
      * not really needed but added for completenes
2734 2738
      *
2735 2739
      * @param  string  URL to decode
2740
+     * @param string $path
2736 2741
      * @return string  decoded URL
2737 2742
      */
2738 2743
     public static function _urldecode($path)
@@ -2835,6 +2840,7 @@  discard block
 block discarded – undo
2835 2840
      * UTF-8 encode property values if not already done so
2836 2841
      *
2837 2842
      * @param  string  text to encode
2843
+     * @param string $text
2838 2844
      * @return string  utf-8 encoded text
2839 2845
      */
2840 2846
     function _prop_encode($text)
@@ -2876,6 +2882,7 @@  discard block
 block discarded – undo
2876 2882
      *
2877 2883
      * @param   string directory path
2878 2884
      * @returns string directory path wihtout trailing slash
2885
+     * @return string
2879 2886
      */
2880 2887
     public static function _unslashify($path)
2881 2888
     {
@@ -2892,6 +2899,7 @@  discard block
 block discarded – undo
2892 2899
      *
2893 2900
      * @param  string  parent path
2894 2901
      * @param  string  child path
2902
+     * @param string $child
2895 2903
      * @return string  merged path
2896 2904
      */
2897 2905
     public static function _mergePaths($parent, $child)
Please login to merge, or discard this patch.
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("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("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("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("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("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("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.
Switch Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -816,34 +816,34 @@  discard block
 block discarded – undo
816 816
 	            	// this can happen if we have allprop and prop in one propfind:
817 817
 	            	// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
818 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;
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 847
 	                }
848 848
 
849 849
 	                // namespace handling
@@ -964,49 +964,49 @@  discard block
 block discarded – undo
964 964
                     } else if ($prop["ns"] == "DAV:") {
965 965
                         // some WebDAV properties need special treatment
966 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;
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 1010
                         }
1011 1011
                     } else {
1012 1012
                         // allow multiple values and attributes, required eg. for caldav:supported-calendar-component-set
@@ -1761,9 +1761,9 @@  discard block
 block discarded – undo
1761 1761
             foreach ($this->_SERVER as $key => $val) {
1762 1762
                 if (strncmp($key, "HTTP_CONTENT", 11)) continue;
1763 1763
                 switch ($key) {
1764
-                case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1765
-		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1766
-		        	{
1764
+                	case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1765
+		        		switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1766
+		        		{
1767 1767
 		        		case 'gzip':
1768 1768
 		        		case 'deflate':	//zlib
1769 1769
 		        			if (extension_loaded('zlib')) break;
@@ -1772,67 +1772,67 @@  discard block
 block discarded – undo
1772 1772
 					        $this->http_status('415 Unsupported Media Type');
1773 1773
 					        echo "The service does not support '$val' content encoding";
1774 1774
 					        return;
1775
-		        	}
1775
+		        		}
1776 1776
 		        	break;
1777 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;
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 1783
 
1784
-                case 'HTTP_CONTENT_LENGTH':
1785
-                    // defined on IIS and has the same value as CONTENT_LENGTH
1786
-                    break;
1784
+                	case 'HTTP_CONTENT_LENGTH':
1785
+                    	// defined on IIS and has the same value as CONTENT_LENGTH
1786
+                    	break;
1787 1787
 
1788
-                case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
1789
-                    /* The meaning of the Content-Location header in PUT
1788
+                	case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
1789
+                    	/* The meaning of the Content-Location header in PUT
1790 1790
                      or POST requests is undefined; servers are free
1791 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;
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 1836
                 }
1837 1837
             }
1838 1838
 
@@ -2390,34 +2390,34 @@  discard block
 block discarded – undo
2390 2390
 
2391 2391
         // now it depends on what we found
2392 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);
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 2421
         }
2422 2422
     }
2423 2423
 
@@ -2461,33 +2461,33 @@  discard block
 block discarded – undo
2461 2461
                     continue;
2462 2462
                 }
2463 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
-                    }
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 2475
                     break;
2476 2476
 
2477
-                case "URI":
2478
-                    $list[] = $not."<$token[1]>";
2479
-                    break;
2477
+                	case "URI":
2478
+                    	$list[] = $not."<$token[1]>";
2479
+                    	break;
2480 2480
 
2481
-                case "ETAG_WEAK":
2482
-                    $list[] = $not."[W/'$token[1]']>";
2483
-                    break;
2481
+                	case "ETAG_WEAK":
2482
+                    	$list[] = $not."[W/'$token[1]']>";
2483
+                    	break;
2484 2484
 
2485
-                case "ETAG_STRONG":
2486
-                    $list[] = $not."['$token[1]']>";
2487
-                    break;
2485
+                	case "ETAG_STRONG":
2486
+                    	$list[] = $not."['$token[1]']>";
2487
+                    	break;
2488 2488
 
2489
-                default:
2490
-                    return false;
2489
+                	default:
2490
+                    	return false;
2491 2491
                 }
2492 2492
                 $not = "";
2493 2493
             }
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("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("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("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("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.
Upper-Lower-Casing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -655,8 +655,8 @@  discard block
 block discarded – undo
655 655
      */
656 656
     function http_PROPFIND($handler='PROPFIND')
657 657
     {
658
-        $options = Array();
659
-        $files   = Array();
658
+        $options = array();
659
+        $files   = array();
660 660
 
661 661
         $options["path"] = $this->path;
662 662
 
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
     function http_PROPPATCH()
1165 1165
     {
1166 1166
         if ($this->_check_lock_status($this->path)) {
1167
-            $options = Array();
1167
+            $options = array();
1168 1168
 
1169 1169
             $options["path"] = $this->path;
1170 1170
 
@@ -1222,7 +1222,7 @@  discard block
 block discarded – undo
1222 1222
      */
1223 1223
     function http_MKCOL()
1224 1224
     {
1225
-        $options = Array();
1225
+        $options = array();
1226 1226
 
1227 1227
         $options["path"] = $this->path;
1228 1228
 
@@ -1269,7 +1269,7 @@  discard block
 block discarded – undo
1269 1269
     function http_GET()
1270 1270
     {
1271 1271
         // TODO check for invalid stream
1272
-        $options         = Array();
1272
+        $options         = array();
1273 1273
         $options["path"] = $this->path;
1274 1274
 
1275 1275
         $this->_get_ranges($options);
@@ -1478,7 +1478,7 @@  discard block
 block discarded – undo
1478 1478
     function http_HEAD()
1479 1479
     {
1480 1480
         $status          = false;
1481
-        $options         = Array();
1481
+        $options         = array();
1482 1482
         $options["path"] = $this->path;
1483 1483
 
1484 1484
         if (method_exists($this, "HEAD")) {
@@ -1524,7 +1524,7 @@  discard block
 block discarded – undo
1524 1524
     function http_POST()
1525 1525
     {
1526 1526
         $status          = '405 Method not allowed';
1527
-        $options         = Array();
1527
+        $options         = array();
1528 1528
         $options['path'] = $this->path;
1529 1529
 
1530 1530
         if (isset($this->_SERVER['CONTENT_LENGTH']))
@@ -1704,7 +1704,7 @@  discard block
 block discarded – undo
1704 1704
     function http_PUT()
1705 1705
     {
1706 1706
         if ($this->_check_lock_status($this->path)) {
1707
-            $options                   = Array();
1707
+            $options                   = array();
1708 1708
             $options["path"]           = $this->path;
1709 1709
 
1710 1710
             if (isset($this->_SERVER['CONTENT_LENGTH']))
@@ -1923,7 +1923,7 @@  discard block
 block discarded – undo
1923 1923
         // check lock status
1924 1924
         if ($this->_check_lock_status($this->path)) {
1925 1925
             // ok, proceed
1926
-            $options         = Array();
1926
+            $options         = array();
1927 1927
             $options["path"] = $this->path;
1928 1928
 
1929 1929
             $stat = $this->DELETE($options);
@@ -1985,7 +1985,7 @@  discard block
 block discarded – undo
1985 1985
      */
1986 1986
     function http_LOCK()
1987 1987
     {
1988
-        $options         = Array();
1988
+        $options         = array();
1989 1989
         $options["path"] = $this->path;
1990 1990
 
1991 1991
         if (isset($this->_SERVER['HTTP_DEPTH'])) {
@@ -2103,7 +2103,7 @@  discard block
 block discarded – undo
2103 2103
      */
2104 2104
     function http_UNLOCK()
2105 2105
     {
2106
-        $options         = Array();
2106
+        $options         = array();
2107 2107
         $options["path"] = $this->path;
2108 2108
 
2109 2109
         if (isset($this->_SERVER['HTTP_DEPTH'])) {
@@ -2133,7 +2133,7 @@  discard block
 block discarded – undo
2133 2133
      */
2134 2134
     function http_ACL()
2135 2135
     {
2136
-        $options         = Array();
2136
+        $options         = array();
2137 2137
         $options['path'] = $this->path;
2138 2138
         $options['errors'] = array();
2139 2139
 
@@ -2172,7 +2172,7 @@  discard block
 block discarded – undo
2172 2172
 
2173 2173
     function _copymove($what)
2174 2174
     {
2175
-        $options         = Array();
2175
+        $options         = array();
2176 2176
         $options["path"] = $this->path;
2177 2177
 
2178 2178
         if (isset($this->_SERVER["HTTP_DEPTH"])) {
Please login to merge, or discard this patch.
api/src/WebDAV/Server/Filesystem.php 6 patches
Doc Comments   +11 added lines, -9 removed lines patch added patch discarded remove patch
@@ -254,6 +254,7 @@  discard block
 block discarded – undo
254 254
      *
255 255
      * @param  string  program name
256 256
      * @param  string  optional search path, defaults to $PATH
257
+     * @param string $name
257 258
      * @return bool    true if executable program found in path
258 259
      */
259 260
     function _can_execute($name, $path = false)
@@ -319,6 +320,7 @@  discard block
 block discarded – undo
319 320
      * try to detect the mime type of a file
320 321
      *
321 322
      * @param  string  file path
323
+     * @param string $fspath
322 324
      * @return string  guessed mime type
323 325
      */
324 326
     function _mimetype($fspath)
@@ -416,7 +418,7 @@  discard block
 block discarded – undo
416 418
      * GET method handler
417 419
      *
418 420
      * @param  array  parameter passing array
419
-     * @return bool   true on success
421
+     * @return null|boolean   true on success
420 422
      */
421 423
     function GET(&$options)
422 424
     {
@@ -446,7 +448,7 @@  discard block
 block discarded – undo
446 448
      * See RFC 2518, Section 8.4 on GET/HEAD for collections
447 449
      *
448 450
      * @param  string  directory path
449
-     * @return void    function has to handle HTTP response itself
451
+     * @return null|false    function has to handle HTTP response itself
450 452
      */
451 453
     function GetDir($fspath, &$options)
452 454
     {
@@ -533,7 +535,7 @@  discard block
 block discarded – undo
533 535
      * MKCOL method handler
534 536
      *
535 537
      * @param  array  general parameter passing array
536
-     * @return bool   true on success
538
+     * @return string   true on success
537 539
      */
538 540
     function MKCOL($options)
539 541
     {
@@ -570,7 +572,7 @@  discard block
 block discarded – undo
570 572
      * DELETE method handler
571 573
      *
572 574
      * @param  array  general parameter passing array
573
-     * @return bool   true on success
575
+     * @return string   true on success
574 576
      */
575 577
     function DELETE($options)
576 578
     {
@@ -600,7 +602,7 @@  discard block
 block discarded – undo
600 602
      * MOVE method handler
601 603
      *
602 604
      * @param  array  general parameter passing array
603
-     * @return bool   true on success
605
+     * @return string   true on success
604 606
      */
605 607
     function MOVE($options)
606 608
     {
@@ -611,7 +613,7 @@  discard block
 block discarded – undo
611 613
      * COPY method handler
612 614
      *
613 615
      * @param  array  general parameter passing array
614
-     * @return bool   true on success
616
+     * @return string   true on success
615 617
      */
616 618
     function COPY($options, $del=false)
617 619
     {
@@ -751,7 +753,7 @@  discard block
 block discarded – undo
751 753
      * PROPPATCH method handler
752 754
      *
753 755
      * @param  array  general parameter passing array
754
-     * @return bool   true on success
756
+     * @return string   true on success
755 757
      */
756 758
     function PROPPATCH(&$options)
757 759
     {
@@ -790,7 +792,7 @@  discard block
 block discarded – undo
790 792
      * LOCK method handler
791 793
      *
792 794
      * @param  array  general parameter passing array
793
-     * @return bool   true on success
795
+     * @return string|boolean   true on success
794 796
      */
795 797
     function LOCK(&$options)
796 798
     {
@@ -848,7 +850,7 @@  discard block
 block discarded – undo
848 850
      * UNLOCK method handler
849 851
      *
850 852
      * @param  array  general parameter passing array
851
-     * @return bool   true on success
853
+     * @return string   true on success
852 854
      */
853 855
     function UNLOCK(&$options)
854 856
     {
Please login to merge, or discard this patch.
Indentation   +827 added lines, -827 removed lines patch added patch discarded remove patch
@@ -44,793 +44,793 @@  discard block
 block discarded – undo
44 44
  */
45 45
 class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server
46 46
 {
47
-    /**
48
-     * Root directory for WebDAV access
49
-     *
50
-     * Defaults to webserver document root (set by ServeRequest)
51
-     *
52
-     * @access private
53
-     * @var    string
54
-     */
55
-    var $base = "";
56
-
57
-    /**
58
-     * MySQL Host where property and locking information is stored
59
-     *
60
-     * @access private
61
-     * @var    string
62
-     */
63
-    var $db_host = "localhost";
64
-
65
-    /**
66
-     * MySQL database for property/locking information storage
67
-     *
68
-     * @access private
69
-     * @var    string
70
-     */
71
-    var $db_name = "webdav";
72
-
73
-    /**
74
-     * MySQL table name prefix
75
-     *
76
-     * @access private
77
-     * @var    string
78
-     */
79
-    var $db_prefix = "";
80
-
81
-    /**
82
-     * MySQL user for property/locking db access
83
-     *
84
-     * @access private
85
-     * @var    string
86
-     */
87
-    var $db_user = "root";
88
-
89
-    /**
90
-     * MySQL password for property/locking db access
91
-     *
92
-     * @access private
93
-     * @var    string
94
-     */
95
-    var $db_passwd = "";
96
-
97
-    /**
98
-     * Serve a webdav request
99
-     *
100
-     * @access public
101
-     * @param  string
102
-     */
103
-    function ServeRequest($base = false)
104
-    {
105
-        // special treatment for litmus compliance test
106
-        // reply on its identifier header
107
-        // not needed for the test itself but eases debugging
108
-        if (isset($this->_SERVER['HTTP_X_LITMUS'])) {
109
-            error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']);
110
-            header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']);
111
-        }
112
-
113
-        // set root directory, defaults to webserver document root if not set
114
-        if ($base) {
115
-            $this->base = realpath($base); // TODO throw if not a directory
116
-        } else if (!$this->base) {
117
-            $this->base = $this->_SERVER['DOCUMENT_ROOT'];
118
-        }
119
-
120
-        // establish connection to property/locking db
121
-        mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error());
122
-        mysql_select_db($this->db_name) or die(mysql_error());
123
-        // TODO throw on connection problems
124
-
125
-        // let the base class do all the work
126
-        parent::ServeRequest();
127
-    }
128
-
129
-    /**
130
-     * No authentication is needed here
131
-     *
132
-     * @access private
133
-     * @param  string  HTTP Authentication type (Basic, Digest, ...)
134
-     * @param  string  Username
135
-     * @param  string  Password
136
-     * @return bool    true on successful authentication
137
-     */
138
-    function check_auth($type, $user, $pass)
139
-    {
140
-        return true;
141
-    }
142
-
143
-
144
-    /**
145
-     * PROPFIND method handler
146
-     *
147
-     * @param  array  general parameter passing array
148
-     * @param  array  return array for file properties
149
-     * @return bool   true on success
150
-     */
151
-    function PROPFIND(&$options, &$files)
152
-    {
153
-        // get absolute fs path to requested resource
154
-        $fspath = $this->base . $options["path"];
155
-
156
-        // sanity check
157
-        if (!file_exists($fspath)) {
158
-            return false;
159
-        }
160
-
161
-        // prepare property array
162
-        $files["files"] = array();
163
-
164
-        // store information for the requested path itself
165
-        $files["files"][] = $this->fileinfo($options["path"]);
166
-
167
-        // information for contained resources requested?
168
-        if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) {
169
-
170
-            // make sure path ends with '/'
171
-            $options["path"] = $this->_slashify($options["path"]);
172
-
173
-            // try to open directory
174
-            $handle = opendir($fspath);
175
-
176
-            if ($handle) {
177
-                // ok, now get all its contents
178
-                while ($filename = readdir($handle)) {
179
-                    if ($filename != "." && $filename != "..") {
180
-                        $files["files"][] = $this->fileinfo($options["path"].$filename);
181
-                    }
182
-                }
183
-                // TODO recursion needed if "Depth: infinite"
184
-            	closedir($handle);
185
-            }
186
-        }
187
-
188
-        // ok, all done
189
-        return true;
190
-    }
191
-
192
-    /**
193
-     * Get properties for a single file/resource
194
-     *
195
-     * @param  string  resource path
196
-     * @return array   resource properties
197
-     */
198
-    function fileinfo($path)
199
-    {
200
-        // map URI path to filesystem path
201
-        $fspath = $this->base . $path;
202
-
203
-        // create result array
204
-        $info = array();
205
-        // TODO remove slash append code when base clase is able to do it itself
206
-        $info["path"]  = is_dir($fspath) ? $this->_slashify($path) : $path;
207
-        $info["props"] = array();
208
-
209
-        // no special beautified displayname here ...
210
-        $info["props"][] = $this->mkprop("displayname", strtoupper($path));
211
-
212
-        // creation and modification time
213
-        $info["props"][] = $this->mkprop("creationdate",    filectime($fspath));
214
-        $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath));
215
-
216
-        // Microsoft extensions: last access time and 'hidden' status
217
-        $info["props"][] = $this->mkprop("lastaccessed",    fileatime($fspath));
218
-        $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219
-
220
-        // type and size (caller already made sure that path exists)
221
-        if (is_dir($fspath)) {
222
-            // directory (WebDAV collection)
223
-            $info["props"][] = $this->mkprop("resourcetype", "collection");
224
-            $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
225
-        } else {
226
-            // plain file (WebDAV resource)
227
-            $info["props"][] = $this->mkprop("resourcetype", "");
228
-            if ($this->_is_readable($fspath)) {
229
-                $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
230
-            } else {
231
-                $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
232
-            }
233
-            $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath));
234
-        }
235
-
236
-        // get additional properties from database
237
-        $query = "SELECT ns, name, value
47
+	/**
48
+	 * Root directory for WebDAV access
49
+	 *
50
+	 * Defaults to webserver document root (set by ServeRequest)
51
+	 *
52
+	 * @access private
53
+	 * @var    string
54
+	 */
55
+	var $base = "";
56
+
57
+	/**
58
+	 * MySQL Host where property and locking information is stored
59
+	 *
60
+	 * @access private
61
+	 * @var    string
62
+	 */
63
+	var $db_host = "localhost";
64
+
65
+	/**
66
+	 * MySQL database for property/locking information storage
67
+	 *
68
+	 * @access private
69
+	 * @var    string
70
+	 */
71
+	var $db_name = "webdav";
72
+
73
+	/**
74
+	 * MySQL table name prefix
75
+	 *
76
+	 * @access private
77
+	 * @var    string
78
+	 */
79
+	var $db_prefix = "";
80
+
81
+	/**
82
+	 * MySQL user for property/locking db access
83
+	 *
84
+	 * @access private
85
+	 * @var    string
86
+	 */
87
+	var $db_user = "root";
88
+
89
+	/**
90
+	 * MySQL password for property/locking db access
91
+	 *
92
+	 * @access private
93
+	 * @var    string
94
+	 */
95
+	var $db_passwd = "";
96
+
97
+	/**
98
+	 * Serve a webdav request
99
+	 *
100
+	 * @access public
101
+	 * @param  string
102
+	 */
103
+	function ServeRequest($base = false)
104
+	{
105
+		// special treatment for litmus compliance test
106
+		// reply on its identifier header
107
+		// not needed for the test itself but eases debugging
108
+		if (isset($this->_SERVER['HTTP_X_LITMUS'])) {
109
+			error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']);
110
+			header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']);
111
+		}
112
+
113
+		// set root directory, defaults to webserver document root if not set
114
+		if ($base) {
115
+			$this->base = realpath($base); // TODO throw if not a directory
116
+		} else if (!$this->base) {
117
+			$this->base = $this->_SERVER['DOCUMENT_ROOT'];
118
+		}
119
+
120
+		// establish connection to property/locking db
121
+		mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error());
122
+		mysql_select_db($this->db_name) or die(mysql_error());
123
+		// TODO throw on connection problems
124
+
125
+		// let the base class do all the work
126
+		parent::ServeRequest();
127
+	}
128
+
129
+	/**
130
+	 * No authentication is needed here
131
+	 *
132
+	 * @access private
133
+	 * @param  string  HTTP Authentication type (Basic, Digest, ...)
134
+	 * @param  string  Username
135
+	 * @param  string  Password
136
+	 * @return bool    true on successful authentication
137
+	 */
138
+	function check_auth($type, $user, $pass)
139
+	{
140
+		return true;
141
+	}
142
+
143
+
144
+	/**
145
+	 * PROPFIND method handler
146
+	 *
147
+	 * @param  array  general parameter passing array
148
+	 * @param  array  return array for file properties
149
+	 * @return bool   true on success
150
+	 */
151
+	function PROPFIND(&$options, &$files)
152
+	{
153
+		// get absolute fs path to requested resource
154
+		$fspath = $this->base . $options["path"];
155
+
156
+		// sanity check
157
+		if (!file_exists($fspath)) {
158
+			return false;
159
+		}
160
+
161
+		// prepare property array
162
+		$files["files"] = array();
163
+
164
+		// store information for the requested path itself
165
+		$files["files"][] = $this->fileinfo($options["path"]);
166
+
167
+		// information for contained resources requested?
168
+		if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) {
169
+
170
+			// make sure path ends with '/'
171
+			$options["path"] = $this->_slashify($options["path"]);
172
+
173
+			// try to open directory
174
+			$handle = opendir($fspath);
175
+
176
+			if ($handle) {
177
+				// ok, now get all its contents
178
+				while ($filename = readdir($handle)) {
179
+					if ($filename != "." && $filename != "..") {
180
+						$files["files"][] = $this->fileinfo($options["path"].$filename);
181
+					}
182
+				}
183
+				// TODO recursion needed if "Depth: infinite"
184
+				closedir($handle);
185
+			}
186
+		}
187
+
188
+		// ok, all done
189
+		return true;
190
+	}
191
+
192
+	/**
193
+	 * Get properties for a single file/resource
194
+	 *
195
+	 * @param  string  resource path
196
+	 * @return array   resource properties
197
+	 */
198
+	function fileinfo($path)
199
+	{
200
+		// map URI path to filesystem path
201
+		$fspath = $this->base . $path;
202
+
203
+		// create result array
204
+		$info = array();
205
+		// TODO remove slash append code when base clase is able to do it itself
206
+		$info["path"]  = is_dir($fspath) ? $this->_slashify($path) : $path;
207
+		$info["props"] = array();
208
+
209
+		// no special beautified displayname here ...
210
+		$info["props"][] = $this->mkprop("displayname", strtoupper($path));
211
+
212
+		// creation and modification time
213
+		$info["props"][] = $this->mkprop("creationdate",    filectime($fspath));
214
+		$info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath));
215
+
216
+		// Microsoft extensions: last access time and 'hidden' status
217
+		$info["props"][] = $this->mkprop("lastaccessed",    fileatime($fspath));
218
+		$info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219
+
220
+		// type and size (caller already made sure that path exists)
221
+		if (is_dir($fspath)) {
222
+			// directory (WebDAV collection)
223
+			$info["props"][] = $this->mkprop("resourcetype", "collection");
224
+			$info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
225
+		} else {
226
+			// plain file (WebDAV resource)
227
+			$info["props"][] = $this->mkprop("resourcetype", "");
228
+			if ($this->_is_readable($fspath)) {
229
+				$info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
230
+			} else {
231
+				$info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
232
+			}
233
+			$info["props"][] = $this->mkprop("getcontentlength", filesize($fspath));
234
+		}
235
+
236
+		// get additional properties from database
237
+		$query = "SELECT ns, name, value
238 238
                         FROM {$this->db_prefix}properties
239 239
                        WHERE path = '$path'";
240
-        $res = mysql_query($query);
241
-        while ($row = mysql_fetch_assoc($res)) {
242
-            $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
243
-        }
244
-        mysql_free_result($res);
245
-
246
-        return $info;
247
-    }
248
-
249
-    /**
250
-     * detect if a given program is found in the search PATH
251
-     *
252
-     * helper function used by _mimetype() to detect if the
253
-     * external 'file' utility is available
254
-     *
255
-     * @param  string  program name
256
-     * @param  string  optional search path, defaults to $PATH
257
-     * @return bool    true if executable program found in path
258
-     */
259
-    function _can_execute($name, $path = false)
260
-    {
261
-        // path defaults to PATH from environment if not set
262
-        if ($path === false) {
263
-            $path = getenv("PATH");
264
-        }
265
-
266
-        // check method depends on operating system
267
-        if (!strncmp(PHP_OS, "WIN", 3)) {
268
-            // on Windows an appropriate COM or EXE file needs to exist
269
-            $exts     = array(".exe", ".com");
270
-            $check_fn = "file_exists";
271
-        } else {
272
-            // anywhere else we look for an executable file of that name
273
-            $exts     = array("");
274
-            $check_fn = "is_executable";
275
-        }
276
-
277
-        // now check the directories in the path for the program
278
-        foreach (explode(PATH_SEPARATOR, $path) as $dir) {
279
-            // skip invalid path entries
280
-            if (!file_exists($dir)) continue;
281
-            if (!is_dir($dir)) continue;
282
-
283
-            // and now look for the file
284
-            foreach ($exts as $ext) {
285
-                if ($check_fn("$dir/$name".$ext)) return true;
286
-            }
287
-        }
288
-
289
-        return false;
290
-    }
291
-
292
-    /**
293
-     * Check if path is readable by current user
294
-     *
295
-     * Allow extending classes to overwrite it
296
-     *
297
-     * @param string $fspath
298
-     * @return boolean
299
-     */
300
-    function _is_readable($fspath)
301
-    {
302
-    	return is_readable($fspath);
303
-    }
304
-
305
-    /**
306
-     * Check if path is writable by current user
307
-     *
308
-     * Allow extending classes to overwrite it
309
-     *
310
-     * @param string $fspath
311
-     * @return boolean
312
-     */
313
-    function _is_writable($fspath)
314
-    {
315
-    	return is_writable($fspath);
316
-    }
317
-
318
-    /**
319
-     * try to detect the mime type of a file
320
-     *
321
-     * @param  string  file path
322
-     * @return string  guessed mime type
323
-     */
324
-    function _mimetype($fspath)
325
-    {
326
-        if (is_dir($fspath)) {
327
-            // directories are easy
328
-            return "httpd/unix-directory";
329
-        } else if (function_exists("mime_content_type")) {
330
-            // use mime magic extension if available
331
-            $mime_type = mime_content_type($fspath);
332
-        } else if ($this->_can_execute("file")) {
333
-            // it looks like we have a 'file' command,
334
-            // lets see it it does have mime support
335
-            $fp    = popen("file -i '$fspath' 2>/dev/null", "r");
336
-            $reply = fgets($fp);
337
-            pclose($fp);
338
-
339
-            // popen will not return an error if the binary was not found
340
-            // and find may not have mime support using "-i"
341
-            // so we test the format of the returned string
342
-
343
-            // the reply begins with the requested filename
344
-            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
345
-                $reply = substr($reply, strlen($fspath)+2);
346
-                // followed by the mime type (maybe including options)
347
-                if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
348
-                    $mime_type = $matches[0];
349
-                }
350
-            }
351
-        }
352
-
353
-        if (empty($mime_type)) {
354
-            // Fallback solution: try to guess the type by the file extension
355
-            // TODO: add more ...
356
-            // TODO: it has been suggested to delegate mimetype detection
357
-            //       to apache but this has at least three issues:
358
-            //       - works only with apache
359
-            //       - needs file to be within the document tree
360
-            //       - requires apache mod_magic
361
-            // TODO: can we use the registry for this on Windows?
362
-            //       OTOH if the server is Windos the clients are likely to
363
-            //       be Windows, too, and tend do ignore the Content-Type
364
-            //       anyway (overriding it with information taken from
365
-            //       the registry)
366
-            // TODO: have a seperate PEAR class for mimetype detection?
367
-            switch (strtolower(strrchr(basename($fspath), "."))) {
368
-            case ".html":
369
-                $mime_type = "text/html";
370
-                break;
371
-            case ".gif":
372
-                $mime_type = "image/gif";
373
-                break;
374
-            case ".jpg":
375
-                $mime_type = "image/jpeg";
376
-                break;
377
-            default:
378
-                $mime_type = "application/octet-stream";
379
-                break;
380
-            }
381
-        }
382
-
383
-        return $mime_type;
384
-    }
385
-
386
-    /**
387
-     * HEAD method handler
388
-     *
389
-     * @param  array  parameter passing array
390
-     * @return bool   true on success
391
-     */
392
-    function HEAD(&$options)
393
-    {
394
-        // get absolute fs path to requested resource
395
-        $fspath = $this->base . $options["path"];
396
-
397
-        // sanity check
398
-        if (!file_exists($fspath)) return false;
399
-
400
-        // detect resource type
401
-        $options['mimetype'] = $this->_mimetype($fspath);
402
-
403
-        // detect modification time
404
-        // see rfc2518, section 13.7
405
-        // some clients seem to treat this as a reverse rule
406
-        // requiering a Last-Modified header if the getlastmodified header was set
407
-        $options['mtime'] = filemtime($fspath);
408
-
409
-        // detect resource size
410
-        $options['size'] = filesize($fspath);
411
-
412
-        return true;
413
-    }
414
-
415
-    /**
416
-     * GET method handler
417
-     *
418
-     * @param  array  parameter passing array
419
-     * @return bool   true on success
420
-     */
421
-    function GET(&$options)
422
-    {
423
-        // get absolute fs path to requested resource
424
-        $fspath = $this->base . $options["path"];
425
-
426
-        // is this a collection?
427
-        if (is_dir($fspath)) {
428
-            return $this->GetDir($fspath, $options);
429
-        }
430
-
431
-        // the header output is the same as for HEAD
432
-        if (!$this->HEAD($options)) {
433
-            return false;
434
-        }
435
-
436
-        // no need to check result here, it is handled by the base class
437
-        $options['stream'] = fopen($fspath, "r");
438
-
439
-        return true;
440
-    }
441
-
442
-    /**
443
-     * GET method handler for directories
444
-     *
445
-     * This is a very simple mod_index lookalike.
446
-     * See RFC 2518, Section 8.4 on GET/HEAD for collections
447
-     *
448
-     * @param  string  directory path
449
-     * @return void    function has to handle HTTP response itself
450
-     */
451
-    function GetDir($fspath, &$options)
452
-    {
453
-        $path = $this->_slashify($options["path"]);
454
-        if ($path != $options["path"]) {
455
-            header("Location: ".$this->base_uri.$path);
456
-            exit;
457
-        }
458
-
459
-        // fixed width directory column format
460
-        $format = "%15s  %-19s  %-s\n";
461
-
462
-        if (!$this->_is_readable($fspath)) {
463
-            return false;
464
-        }
465
-
466
-        $handle = opendir($fspath);
467
-        if (!$handle) {
468
-            return false;
469
-        }
470
-
471
-        echo "<html><head><title>Index of ".htmlspecialchars(urldecode($options['path']))."</title></head>\n";
472
-
473
-        echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n";
474
-
475
-        echo "<pre>";
476
-        printf($format, "Size", "Last modified", "Filename");
477
-        echo "<hr>";
478
-
479
-        while ($filename = readdir($handle)) {
480
-            if ($filename != "." && $filename != "..") {
481
-                $fullpath = $fspath.$filename;
482
-                $name     = htmlspecialchars($filename);
483
-                printf($format,
484
-                       number_format(filesize($fullpath)),
485
-                       strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)),
486
-                       '<a href="'.$name.'">'.urldecode($name).'</a>');
487
-            }
488
-        }
489
-
490
-        echo "</pre>";
491
-
492
-        closedir($handle);
493
-
494
-        echo "</html>\n";
495
-
496
-        exit;
497
-    }
498
-
499
-    /**
500
-     * PUT method handler
501
-     *
502
-     * @param  array  parameter passing array
503
-     * @return bool   true on success
504
-     */
505
-    function PUT(&$options)
506
-    {
507
-        $fspath = $this->base . $options["path"];
508
-
509
-        $dir = dirname($fspath);
510
-        if (!file_exists($dir) || !is_dir($dir)) {
511
-            return "409 Conflict"; // TODO right status code for both?
512
-        }
513
-
514
-        $options["new"] = ! file_exists($fspath);
515
-
516
-        if ($options["new"] && !$this->_is_writable($dir)) {
517
-            return "403 Forbidden";
518
-        }
519
-        if (!$options["new"] && !$this->_is_writable($fspath)) {
520
-            return "403 Forbidden";
521
-        }
522
-        if (!$options["new"] && is_dir($fspath)) {
523
-            return "403 Forbidden";
524
-        }
525
-
526
-        $fp = fopen($fspath, "w");
527
-
528
-        return $fp;
529
-    }
530
-
531
-
532
-    /**
533
-     * MKCOL method handler
534
-     *
535
-     * @param  array  general parameter passing array
536
-     * @return bool   true on success
537
-     */
538
-    function MKCOL($options)
539
-    {
540
-        $path   = $this->base .$options["path"];
541
-        $parent = dirname($path);
542
-        $name   = basename($path);
543
-
544
-        if (!file_exists($parent)) {
545
-            return "409 Conflict";
546
-        }
547
-
548
-        if (!is_dir($parent)) {
549
-            return "403 Forbidden";
550
-        }
551
-
552
-        if ( file_exists($parent."/".$name) ) {
553
-            return "405 Method not allowed";
554
-        }
555
-
556
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
557
-            return "415 Unsupported media type";
558
-        }
559
-
560
-        $stat = mkdir($parent."/".$name, 0777);
561
-        if (!$stat) {
562
-            return "403 Forbidden";
563
-        }
564
-
565
-        return ("201 Created");
566
-    }
567
-
568
-
569
-    /**
570
-     * DELETE method handler
571
-     *
572
-     * @param  array  general parameter passing array
573
-     * @return bool   true on success
574
-     */
575
-    function DELETE($options)
576
-    {
577
-        $path = $this->base . "/" .$options["path"];
578
-
579
-        if (!file_exists($path)) {
580
-            return "404 Not found";
581
-        }
582
-
583
-        if (is_dir($path)) {
584
-            $query = "DELETE FROM {$this->db_prefix}properties
240
+		$res = mysql_query($query);
241
+		while ($row = mysql_fetch_assoc($res)) {
242
+			$info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
243
+		}
244
+		mysql_free_result($res);
245
+
246
+		return $info;
247
+	}
248
+
249
+	/**
250
+	 * detect if a given program is found in the search PATH
251
+	 *
252
+	 * helper function used by _mimetype() to detect if the
253
+	 * external 'file' utility is available
254
+	 *
255
+	 * @param  string  program name
256
+	 * @param  string  optional search path, defaults to $PATH
257
+	 * @return bool    true if executable program found in path
258
+	 */
259
+	function _can_execute($name, $path = false)
260
+	{
261
+		// path defaults to PATH from environment if not set
262
+		if ($path === false) {
263
+			$path = getenv("PATH");
264
+		}
265
+
266
+		// check method depends on operating system
267
+		if (!strncmp(PHP_OS, "WIN", 3)) {
268
+			// on Windows an appropriate COM or EXE file needs to exist
269
+			$exts     = array(".exe", ".com");
270
+			$check_fn = "file_exists";
271
+		} else {
272
+			// anywhere else we look for an executable file of that name
273
+			$exts     = array("");
274
+			$check_fn = "is_executable";
275
+		}
276
+
277
+		// now check the directories in the path for the program
278
+		foreach (explode(PATH_SEPARATOR, $path) as $dir) {
279
+			// skip invalid path entries
280
+			if (!file_exists($dir)) continue;
281
+			if (!is_dir($dir)) continue;
282
+
283
+			// and now look for the file
284
+			foreach ($exts as $ext) {
285
+				if ($check_fn("$dir/$name".$ext)) return true;
286
+			}
287
+		}
288
+
289
+		return false;
290
+	}
291
+
292
+	/**
293
+	 * Check if path is readable by current user
294
+	 *
295
+	 * Allow extending classes to overwrite it
296
+	 *
297
+	 * @param string $fspath
298
+	 * @return boolean
299
+	 */
300
+	function _is_readable($fspath)
301
+	{
302
+		return is_readable($fspath);
303
+	}
304
+
305
+	/**
306
+	 * Check if path is writable by current user
307
+	 *
308
+	 * Allow extending classes to overwrite it
309
+	 *
310
+	 * @param string $fspath
311
+	 * @return boolean
312
+	 */
313
+	function _is_writable($fspath)
314
+	{
315
+		return is_writable($fspath);
316
+	}
317
+
318
+	/**
319
+	 * try to detect the mime type of a file
320
+	 *
321
+	 * @param  string  file path
322
+	 * @return string  guessed mime type
323
+	 */
324
+	function _mimetype($fspath)
325
+	{
326
+		if (is_dir($fspath)) {
327
+			// directories are easy
328
+			return "httpd/unix-directory";
329
+		} else if (function_exists("mime_content_type")) {
330
+			// use mime magic extension if available
331
+			$mime_type = mime_content_type($fspath);
332
+		} else if ($this->_can_execute("file")) {
333
+			// it looks like we have a 'file' command,
334
+			// lets see it it does have mime support
335
+			$fp    = popen("file -i '$fspath' 2>/dev/null", "r");
336
+			$reply = fgets($fp);
337
+			pclose($fp);
338
+
339
+			// popen will not return an error if the binary was not found
340
+			// and find may not have mime support using "-i"
341
+			// so we test the format of the returned string
342
+
343
+			// the reply begins with the requested filename
344
+			if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
345
+				$reply = substr($reply, strlen($fspath)+2);
346
+				// followed by the mime type (maybe including options)
347
+				if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
348
+					$mime_type = $matches[0];
349
+				}
350
+			}
351
+		}
352
+
353
+		if (empty($mime_type)) {
354
+			// Fallback solution: try to guess the type by the file extension
355
+			// TODO: add more ...
356
+			// TODO: it has been suggested to delegate mimetype detection
357
+			//       to apache but this has at least three issues:
358
+			//       - works only with apache
359
+			//       - needs file to be within the document tree
360
+			//       - requires apache mod_magic
361
+			// TODO: can we use the registry for this on Windows?
362
+			//       OTOH if the server is Windos the clients are likely to
363
+			//       be Windows, too, and tend do ignore the Content-Type
364
+			//       anyway (overriding it with information taken from
365
+			//       the registry)
366
+			// TODO: have a seperate PEAR class for mimetype detection?
367
+			switch (strtolower(strrchr(basename($fspath), "."))) {
368
+			case ".html":
369
+				$mime_type = "text/html";
370
+				break;
371
+			case ".gif":
372
+				$mime_type = "image/gif";
373
+				break;
374
+			case ".jpg":
375
+				$mime_type = "image/jpeg";
376
+				break;
377
+			default:
378
+				$mime_type = "application/octet-stream";
379
+				break;
380
+			}
381
+		}
382
+
383
+		return $mime_type;
384
+	}
385
+
386
+	/**
387
+	 * HEAD method handler
388
+	 *
389
+	 * @param  array  parameter passing array
390
+	 * @return bool   true on success
391
+	 */
392
+	function HEAD(&$options)
393
+	{
394
+		// get absolute fs path to requested resource
395
+		$fspath = $this->base . $options["path"];
396
+
397
+		// sanity check
398
+		if (!file_exists($fspath)) return false;
399
+
400
+		// detect resource type
401
+		$options['mimetype'] = $this->_mimetype($fspath);
402
+
403
+		// detect modification time
404
+		// see rfc2518, section 13.7
405
+		// some clients seem to treat this as a reverse rule
406
+		// requiering a Last-Modified header if the getlastmodified header was set
407
+		$options['mtime'] = filemtime($fspath);
408
+
409
+		// detect resource size
410
+		$options['size'] = filesize($fspath);
411
+
412
+		return true;
413
+	}
414
+
415
+	/**
416
+	 * GET method handler
417
+	 *
418
+	 * @param  array  parameter passing array
419
+	 * @return bool   true on success
420
+	 */
421
+	function GET(&$options)
422
+	{
423
+		// get absolute fs path to requested resource
424
+		$fspath = $this->base . $options["path"];
425
+
426
+		// is this a collection?
427
+		if (is_dir($fspath)) {
428
+			return $this->GetDir($fspath, $options);
429
+		}
430
+
431
+		// the header output is the same as for HEAD
432
+		if (!$this->HEAD($options)) {
433
+			return false;
434
+		}
435
+
436
+		// no need to check result here, it is handled by the base class
437
+		$options['stream'] = fopen($fspath, "r");
438
+
439
+		return true;
440
+	}
441
+
442
+	/**
443
+	 * GET method handler for directories
444
+	 *
445
+	 * This is a very simple mod_index lookalike.
446
+	 * See RFC 2518, Section 8.4 on GET/HEAD for collections
447
+	 *
448
+	 * @param  string  directory path
449
+	 * @return void    function has to handle HTTP response itself
450
+	 */
451
+	function GetDir($fspath, &$options)
452
+	{
453
+		$path = $this->_slashify($options["path"]);
454
+		if ($path != $options["path"]) {
455
+			header("Location: ".$this->base_uri.$path);
456
+			exit;
457
+		}
458
+
459
+		// fixed width directory column format
460
+		$format = "%15s  %-19s  %-s\n";
461
+
462
+		if (!$this->_is_readable($fspath)) {
463
+			return false;
464
+		}
465
+
466
+		$handle = opendir($fspath);
467
+		if (!$handle) {
468
+			return false;
469
+		}
470
+
471
+		echo "<html><head><title>Index of ".htmlspecialchars(urldecode($options['path']))."</title></head>\n";
472
+
473
+		echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n";
474
+
475
+		echo "<pre>";
476
+		printf($format, "Size", "Last modified", "Filename");
477
+		echo "<hr>";
478
+
479
+		while ($filename = readdir($handle)) {
480
+			if ($filename != "." && $filename != "..") {
481
+				$fullpath = $fspath.$filename;
482
+				$name     = htmlspecialchars($filename);
483
+				printf($format,
484
+					   number_format(filesize($fullpath)),
485
+					   strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)),
486
+					   '<a href="'.$name.'">'.urldecode($name).'</a>');
487
+			}
488
+		}
489
+
490
+		echo "</pre>";
491
+
492
+		closedir($handle);
493
+
494
+		echo "</html>\n";
495
+
496
+		exit;
497
+	}
498
+
499
+	/**
500
+	 * PUT method handler
501
+	 *
502
+	 * @param  array  parameter passing array
503
+	 * @return bool   true on success
504
+	 */
505
+	function PUT(&$options)
506
+	{
507
+		$fspath = $this->base . $options["path"];
508
+
509
+		$dir = dirname($fspath);
510
+		if (!file_exists($dir) || !is_dir($dir)) {
511
+			return "409 Conflict"; // TODO right status code for both?
512
+		}
513
+
514
+		$options["new"] = ! file_exists($fspath);
515
+
516
+		if ($options["new"] && !$this->_is_writable($dir)) {
517
+			return "403 Forbidden";
518
+		}
519
+		if (!$options["new"] && !$this->_is_writable($fspath)) {
520
+			return "403 Forbidden";
521
+		}
522
+		if (!$options["new"] && is_dir($fspath)) {
523
+			return "403 Forbidden";
524
+		}
525
+
526
+		$fp = fopen($fspath, "w");
527
+
528
+		return $fp;
529
+	}
530
+
531
+
532
+	/**
533
+	 * MKCOL method handler
534
+	 *
535
+	 * @param  array  general parameter passing array
536
+	 * @return bool   true on success
537
+	 */
538
+	function MKCOL($options)
539
+	{
540
+		$path   = $this->base .$options["path"];
541
+		$parent = dirname($path);
542
+		$name   = basename($path);
543
+
544
+		if (!file_exists($parent)) {
545
+			return "409 Conflict";
546
+		}
547
+
548
+		if (!is_dir($parent)) {
549
+			return "403 Forbidden";
550
+		}
551
+
552
+		if ( file_exists($parent."/".$name) ) {
553
+			return "405 Method not allowed";
554
+		}
555
+
556
+		if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
557
+			return "415 Unsupported media type";
558
+		}
559
+
560
+		$stat = mkdir($parent."/".$name, 0777);
561
+		if (!$stat) {
562
+			return "403 Forbidden";
563
+		}
564
+
565
+		return ("201 Created");
566
+	}
567
+
568
+
569
+	/**
570
+	 * DELETE method handler
571
+	 *
572
+	 * @param  array  general parameter passing array
573
+	 * @return bool   true on success
574
+	 */
575
+	function DELETE($options)
576
+	{
577
+		$path = $this->base . "/" .$options["path"];
578
+
579
+		if (!file_exists($path)) {
580
+			return "404 Not found";
581
+		}
582
+
583
+		if (is_dir($path)) {
584
+			$query = "DELETE FROM {$this->db_prefix}properties
585 585
                            WHERE path LIKE '".$this->_slashify($options["path"])."%'";
586
-            mysql_query($query);
587
-            System::rm(array("-rf", $path));
588
-        } else {
589
-            unlink($path);
590
-        }
591
-        $query = "DELETE FROM {$this->db_prefix}properties
586
+			mysql_query($query);
587
+			System::rm(array("-rf", $path));
588
+		} else {
589
+			unlink($path);
590
+		}
591
+		$query = "DELETE FROM {$this->db_prefix}properties
592 592
                        WHERE path = '$options[path]'";
593
-        mysql_query($query);
594
-
595
-        return "204 No Content";
596
-    }
597
-
598
-
599
-    /**
600
-     * MOVE method handler
601
-     *
602
-     * @param  array  general parameter passing array
603
-     * @return bool   true on success
604
-     */
605
-    function MOVE($options)
606
-    {
607
-        return $this->COPY($options, true);
608
-    }
609
-
610
-    /**
611
-     * COPY method handler
612
-     *
613
-     * @param  array  general parameter passing array
614
-     * @return bool   true on success
615
-     */
616
-    function COPY($options, $del=false)
617
-    {
618
-        // TODO Property updates still broken (Litmus should detect this?)
619
-
620
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
621
-            return "415 Unsupported media type";
622
-        }
623
-
624
-        // no copying to different WebDAV Servers yet
625
-        if (isset($options["dest_url"])) {
626
-            return "502 bad gateway";
627
-        }
628
-
629
-        $source = $this->base . $options["path"];
630
-        if (!file_exists($source)) {
631
-            return "404 Not found";
632
-        }
633
-
634
-        if (is_dir($source)) { // resource is a collection
635
-            switch ($options["depth"]) {
636
-            case "infinity": // valid
637
-                break;
638
-            case "0": // valid for COPY only
639
-                if ($del) { // MOVE?
640
-                    return "400 Bad request";
641
-                }
642
-                break;
643
-            case "1": // invalid for both COPY and MOVE
644
-            default:
645
-                return "400 Bad request";
646
-            }
647
-        }
648
-
649
-        $dest         = $this->base . $options["dest"];
650
-        $destdir      = dirname($dest);
651
-
652
-        if (!file_exists($destdir) || !is_dir($destdir)) {
653
-            return "409 Conflict";
654
-        }
655
-
656
-
657
-        $new          = !file_exists($dest);
658
-        $existing_col = false;
659
-
660
-        if (!$new) {
661
-            if ($del && is_dir($dest)) {
662
-                if (!$options["overwrite"]) {
663
-                    return "412 precondition failed";
664
-                }
665
-                $dest .= basename($source);
666
-                if (file_exists($dest)) {
667
-                    $options["dest"] .= basename($source);
668
-                } else {
669
-                    $new          = true;
670
-                    $existing_col = true;
671
-                }
672
-            }
673
-        }
674
-
675
-        if (!$new) {
676
-            if ($options["overwrite"]) {
677
-                $stat = $this->DELETE(array("path" => $options["dest"]));
678
-                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
679
-                    return $stat;
680
-                }
681
-            } else {
682
-                return "412 precondition failed";
683
-            }
684
-        }
685
-
686
-        if ($del) {
687
-            if (!rename($source, $dest)) {
688
-                return "500 Internal server error";
689
-            }
690
-            $destpath = $this->_unslashify($options["dest"]);
691
-            if (is_dir($source)) {
692
-                $query = "UPDATE {$this->db_prefix}properties
593
+		mysql_query($query);
594
+
595
+		return "204 No Content";
596
+	}
597
+
598
+
599
+	/**
600
+	 * MOVE method handler
601
+	 *
602
+	 * @param  array  general parameter passing array
603
+	 * @return bool   true on success
604
+	 */
605
+	function MOVE($options)
606
+	{
607
+		return $this->COPY($options, true);
608
+	}
609
+
610
+	/**
611
+	 * COPY method handler
612
+	 *
613
+	 * @param  array  general parameter passing array
614
+	 * @return bool   true on success
615
+	 */
616
+	function COPY($options, $del=false)
617
+	{
618
+		// TODO Property updates still broken (Litmus should detect this?)
619
+
620
+		if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
621
+			return "415 Unsupported media type";
622
+		}
623
+
624
+		// no copying to different WebDAV Servers yet
625
+		if (isset($options["dest_url"])) {
626
+			return "502 bad gateway";
627
+		}
628
+
629
+		$source = $this->base . $options["path"];
630
+		if (!file_exists($source)) {
631
+			return "404 Not found";
632
+		}
633
+
634
+		if (is_dir($source)) { // resource is a collection
635
+			switch ($options["depth"]) {
636
+			case "infinity": // valid
637
+				break;
638
+			case "0": // valid for COPY only
639
+				if ($del) { // MOVE?
640
+					return "400 Bad request";
641
+				}
642
+				break;
643
+			case "1": // invalid for both COPY and MOVE
644
+			default:
645
+				return "400 Bad request";
646
+			}
647
+		}
648
+
649
+		$dest         = $this->base . $options["dest"];
650
+		$destdir      = dirname($dest);
651
+
652
+		if (!file_exists($destdir) || !is_dir($destdir)) {
653
+			return "409 Conflict";
654
+		}
655
+
656
+
657
+		$new          = !file_exists($dest);
658
+		$existing_col = false;
659
+
660
+		if (!$new) {
661
+			if ($del && is_dir($dest)) {
662
+				if (!$options["overwrite"]) {
663
+					return "412 precondition failed";
664
+				}
665
+				$dest .= basename($source);
666
+				if (file_exists($dest)) {
667
+					$options["dest"] .= basename($source);
668
+				} else {
669
+					$new          = true;
670
+					$existing_col = true;
671
+				}
672
+			}
673
+		}
674
+
675
+		if (!$new) {
676
+			if ($options["overwrite"]) {
677
+				$stat = $this->DELETE(array("path" => $options["dest"]));
678
+				if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
679
+					return $stat;
680
+				}
681
+			} else {
682
+				return "412 precondition failed";
683
+			}
684
+		}
685
+
686
+		if ($del) {
687
+			if (!rename($source, $dest)) {
688
+				return "500 Internal server error";
689
+			}
690
+			$destpath = $this->_unslashify($options["dest"]);
691
+			if (is_dir($source)) {
692
+				$query = "UPDATE {$this->db_prefix}properties
693 693
                                  SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
694 694
                                WHERE path LIKE '".$this->_slashify($options["path"])."%'";
695
-                mysql_query($query);
696
-            }
695
+				mysql_query($query);
696
+			}
697 697
 
698
-            $query = "UPDATE {$this->db_prefix}properties
698
+			$query = "UPDATE {$this->db_prefix}properties
699 699
                              SET path = '".$destpath."'
700 700
                            WHERE path = '".$options["path"]."'";
701
-            mysql_query($query);
702
-        } else {
703
-            if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
704
-                $files = System::find($source);
705
-                $files = array_reverse($files);
706
-            } else {
707
-                $files = array($source);
708
-            }
709
-
710
-            if (!is_array($files) || empty($files)) {
711
-                return "500 Internal server error";
712
-            }
713
-
714
-
715
-            foreach ($files as $file) {
716
-                if (is_dir($file)) {
717
-                    $file = $this->_slashify($file);
718
-                }
719
-
720
-                $destfile = str_replace($source, $dest, $file);
721
-
722
-                if (is_dir($file)) {
723
-                    if (!file_exists($destfile)) {
724
-                        if (!$this->_is_writable(dirname($destfile))) {
725
-                            return "403 Forbidden";
726
-                        }
727
-                        if (!mkdir($destfile)) {
728
-                            return "409 Conflict";
729
-                        }
730
-                    } else if (!is_dir($destfile)) {
731
-                        return "409 Conflict";
732
-                    }
733
-                } else {
734
-
735
-                    if (!copy($file, $destfile)) {
736
-                        return "409 Conflict";
737
-                    }
738
-                }
739
-            }
740
-
741
-            $query = "INSERT INTO {$this->db_prefix}properties
701
+			mysql_query($query);
702
+		} else {
703
+			if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
704
+				$files = System::find($source);
705
+				$files = array_reverse($files);
706
+			} else {
707
+				$files = array($source);
708
+			}
709
+
710
+			if (!is_array($files) || empty($files)) {
711
+				return "500 Internal server error";
712
+			}
713
+
714
+
715
+			foreach ($files as $file) {
716
+				if (is_dir($file)) {
717
+					$file = $this->_slashify($file);
718
+				}
719
+
720
+				$destfile = str_replace($source, $dest, $file);
721
+
722
+				if (is_dir($file)) {
723
+					if (!file_exists($destfile)) {
724
+						if (!$this->_is_writable(dirname($destfile))) {
725
+							return "403 Forbidden";
726
+						}
727
+						if (!mkdir($destfile)) {
728
+							return "409 Conflict";
729
+						}
730
+					} else if (!is_dir($destfile)) {
731
+						return "409 Conflict";
732
+					}
733
+				} else {
734
+
735
+					if (!copy($file, $destfile)) {
736
+						return "409 Conflict";
737
+					}
738
+				}
739
+			}
740
+
741
+			$query = "INSERT INTO {$this->db_prefix}properties
742 742
                                SELECT *
743 743
                                  FROM {$this->db_prefix}properties
744 744
                                 WHERE path = '".$options['path']."'";
745
-        }
746
-
747
-        return ($new && !$existing_col) ? "201 Created" : "204 No Content";
748
-    }
749
-
750
-    /**
751
-     * PROPPATCH method handler
752
-     *
753
-     * @param  array  general parameter passing array
754
-     * @return bool   true on success
755
-     */
756
-    function PROPPATCH(&$options)
757
-    {
758
-        global $prefs, $tab;
759
-
760
-        $msg  = "";
761
-        $path = $options["path"];
762
-        $dir  = dirname($path)."/";
763
-        $base = basename($path);
764
-
765
-        foreach ($options["props"] as $key => $prop) {
766
-            if ($prop["ns"] == "DAV:") {
767
-                $options["props"][$key]['status'] = "403 Forbidden";
768
-            } else {
769
-                if (isset($prop["val"])) {
770
-                    $query = "REPLACE INTO {$this->db_prefix}properties
745
+		}
746
+
747
+		return ($new && !$existing_col) ? "201 Created" : "204 No Content";
748
+	}
749
+
750
+	/**
751
+	 * PROPPATCH method handler
752
+	 *
753
+	 * @param  array  general parameter passing array
754
+	 * @return bool   true on success
755
+	 */
756
+	function PROPPATCH(&$options)
757
+	{
758
+		global $prefs, $tab;
759
+
760
+		$msg  = "";
761
+		$path = $options["path"];
762
+		$dir  = dirname($path)."/";
763
+		$base = basename($path);
764
+
765
+		foreach ($options["props"] as $key => $prop) {
766
+			if ($prop["ns"] == "DAV:") {
767
+				$options["props"][$key]['status'] = "403 Forbidden";
768
+			} else {
769
+				if (isset($prop["val"])) {
770
+					$query = "REPLACE INTO {$this->db_prefix}properties
771 771
                                            SET path = '$options[path]'
772 772
                                              , name = '$prop[name]'
773 773
                                              , ns= '$prop[ns]'
774 774
                                              , value = '$prop[val]'";
775
-                } else {
776
-                    $query = "DELETE FROM {$this->db_prefix}properties
775
+				} else {
776
+					$query = "DELETE FROM {$this->db_prefix}properties
777 777
                                         WHERE path = '$options[path]'
778 778
                                           AND name = '$prop[name]'
779 779
                                           AND ns = '$prop[ns]'";
780
-                }
781
-                mysql_query($query);
782
-            }
783
-        }
784
-
785
-        return "";
786
-    }
787
-
788
-
789
-    /**
790
-     * LOCK method handler
791
-     *
792
-     * @param  array  general parameter passing array
793
-     * @return bool   true on success
794
-     */
795
-    function LOCK(&$options)
796
-    {
797
-        // get absolute fs path to requested resource
798
-        $fspath = $this->base . $options["path"];
799
-
800
-        // TODO recursive locks on directories not supported yet
801
-        // makes litmus test "32. lock_collection" fail
802
-        if (is_dir($fspath) && !empty($options["depth"])) {
803
-            return "409 Conflict";
804
-        }
805
-
806
-        $options["timeout"] = time()+300; // 5min. hardcoded
807
-
808
-        if (isset($options["update"])) { // Lock Update
809
-            $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
810
-
811
-            $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
812
-            $res   = mysql_query($query);
813
-            $row   = mysql_fetch_assoc($res);
814
-            mysql_free_result($res);
815
-
816
-            if (is_array($row)) {
817
-                $query = "UPDATE {$this->db_prefix}locks
780
+				}
781
+				mysql_query($query);
782
+			}
783
+		}
784
+
785
+		return "";
786
+	}
787
+
788
+
789
+	/**
790
+	 * LOCK method handler
791
+	 *
792
+	 * @param  array  general parameter passing array
793
+	 * @return bool   true on success
794
+	 */
795
+	function LOCK(&$options)
796
+	{
797
+		// get absolute fs path to requested resource
798
+		$fspath = $this->base . $options["path"];
799
+
800
+		// TODO recursive locks on directories not supported yet
801
+		// makes litmus test "32. lock_collection" fail
802
+		if (is_dir($fspath) && !empty($options["depth"])) {
803
+			return "409 Conflict";
804
+		}
805
+
806
+		$options["timeout"] = time()+300; // 5min. hardcoded
807
+
808
+		if (isset($options["update"])) { // Lock Update
809
+			$where = "WHERE path = '$options[path]' AND token = '$options[update]'";
810
+
811
+			$query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
812
+			$res   = mysql_query($query);
813
+			$row   = mysql_fetch_assoc($res);
814
+			mysql_free_result($res);
815
+
816
+			if (is_array($row)) {
817
+				$query = "UPDATE {$this->db_prefix}locks
818 818
                                  SET expires = '$options[timeout]'
819 819
                                    , modified = ".time()."
820 820
                               $where";
821
-                mysql_query($query);
821
+				mysql_query($query);
822 822
 
823
-                $options['owner'] = $row['owner'];
824
-                $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
825
-                $options['type']  = $row["exclusivelock"] ? "write"     : "read";
823
+				$options['owner'] = $row['owner'];
824
+				$options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
825
+				$options['type']  = $row["exclusivelock"] ? "write"     : "read";
826 826
 
827
-                return true;
828
-            } else {
829
-                return false;
830
-            }
831
-        }
827
+				return true;
828
+			} else {
829
+				return false;
830
+			}
831
+		}
832 832
 
833
-        $query = "INSERT INTO {$this->db_prefix}locks
833
+		$query = "INSERT INTO {$this->db_prefix}locks
834 834
                         SET token   = '$options[locktoken]'
835 835
                           , path    = '$options[path]'
836 836
                           , created = ".time()."
@@ -838,76 +838,76 @@  discard block
 block discarded – undo
838 838
                           , owner   = '$options[owner]'
839 839
                           , expires = '$options[timeout]'
840 840
                           , exclusivelock  = " .($options['scope'] === "exclusive" ? "1" : "0")
841
-            ;
842
-        mysql_query($query);
843
-
844
-        return mysql_affected_rows() ? "200 OK" : "409 Conflict";
845
-    }
846
-
847
-    /**
848
-     * UNLOCK method handler
849
-     *
850
-     * @param  array  general parameter passing array
851
-     * @return bool   true on success
852
-     */
853
-    function UNLOCK(&$options)
854
-    {
855
-        $query = "DELETE FROM {$this->db_prefix}locks
841
+			;
842
+		mysql_query($query);
843
+
844
+		return mysql_affected_rows() ? "200 OK" : "409 Conflict";
845
+	}
846
+
847
+	/**
848
+	 * UNLOCK method handler
849
+	 *
850
+	 * @param  array  general parameter passing array
851
+	 * @return bool   true on success
852
+	 */
853
+	function UNLOCK(&$options)
854
+	{
855
+		$query = "DELETE FROM {$this->db_prefix}locks
856 856
                       WHERE path = '$options[path]'
857 857
                         AND token = '$options[token]'";
858
-        mysql_query($query);
859
-
860
-        return mysql_affected_rows() ? "204 No Content" : "409 Conflict";
861
-    }
862
-
863
-    /**
864
-     * checkLock() helper
865
-     *
866
-     * @param  string resource path to check for locks
867
-     * @return bool   true on success
868
-     */
869
-    function checkLock($path)
870
-    {
871
-        $result = false;
872
-
873
-        $query = "SELECT owner, token, created, modified, expires, exclusivelock
858
+		mysql_query($query);
859
+
860
+		return mysql_affected_rows() ? "204 No Content" : "409 Conflict";
861
+	}
862
+
863
+	/**
864
+	 * checkLock() helper
865
+	 *
866
+	 * @param  string resource path to check for locks
867
+	 * @return bool   true on success
868
+	 */
869
+	function checkLock($path)
870
+	{
871
+		$result = false;
872
+
873
+		$query = "SELECT owner, token, created, modified, expires, exclusivelock
874 874
                   FROM {$this->db_prefix}locks
875 875
                  WHERE path = '$path'
876 876
                ";
877
-        $res = mysql_query($query);
878
-
879
-        if ($res) {
880
-            $row = mysql_fetch_array($res);
881
-            mysql_free_result($res);
882
-
883
-            if ($row) {
884
-                $result = array( "type"    => "write",
885
-                                 "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
886
-                                 "depth"   => 0,
887
-                                 "owner"   => $row['owner'],
888
-                                 "token"   => $row['token'],
889
-                                 "created" => $row['created'],
890
-                                 "modified" => $row['modified'],
891
-                                 "expires" => $row['expires']
892
-                                 );
893
-            }
894
-        }
895
-
896
-        return $result;
897
-    }
898
-
899
-
900
-    /**
901
-     * create database tables for property and lock storage
902
-     *
903
-     * @param  void
904
-     * @return bool   true on success
905
-     */
906
-    function create_database()
907
-    {
908
-        // TODO
909
-        return false;
910
-    }
877
+		$res = mysql_query($query);
878
+
879
+		if ($res) {
880
+			$row = mysql_fetch_array($res);
881
+			mysql_free_result($res);
882
+
883
+			if ($row) {
884
+				$result = array( "type"    => "write",
885
+								 "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
886
+								 "depth"   => 0,
887
+								 "owner"   => $row['owner'],
888
+								 "token"   => $row['token'],
889
+								 "created" => $row['created'],
890
+								 "modified" => $row['modified'],
891
+								 "expires" => $row['expires']
892
+								 );
893
+			}
894
+		}
895
+
896
+		return $result;
897
+	}
898
+
899
+
900
+	/**
901
+	 * create database tables for property and lock storage
902
+	 *
903
+	 * @param  void
904
+	 * @return bool   true on success
905
+	 */
906
+	function create_database()
907
+	{
908
+		// TODO
909
+		return false;
910
+	}
911 911
 }
912 912
 
913 913
 
Please login to merge, or discard this patch.
Switch Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -365,18 +365,18 @@  discard block
 block discarded – undo
365 365
             //       the registry)
366 366
             // TODO: have a seperate PEAR class for mimetype detection?
367 367
             switch (strtolower(strrchr(basename($fspath), "."))) {
368
-            case ".html":
369
-                $mime_type = "text/html";
370
-                break;
371
-            case ".gif":
372
-                $mime_type = "image/gif";
373
-                break;
374
-            case ".jpg":
375
-                $mime_type = "image/jpeg";
376
-                break;
377
-            default:
378
-                $mime_type = "application/octet-stream";
379
-                break;
368
+            	case ".html":
369
+                	$mime_type = "text/html";
370
+                	break;
371
+            	case ".gif":
372
+                	$mime_type = "image/gif";
373
+                	break;
374
+            	case ".jpg":
375
+                	$mime_type = "image/jpeg";
376
+                	break;
377
+            	default:
378
+                	$mime_type = "application/octet-stream";
379
+                	break;
380 380
             }
381 381
         }
382 382
 
@@ -633,16 +633,16 @@  discard block
 block discarded – undo
633 633
 
634 634
         if (is_dir($source)) { // resource is a collection
635 635
             switch ($options["depth"]) {
636
-            case "infinity": // valid
637
-                break;
638
-            case "0": // valid for COPY only
639
-                if ($del) { // MOVE?
640
-                    return "400 Bad request";
641
-                }
642
-                break;
643
-            case "1": // invalid for both COPY and MOVE
644
-            default:
645
-                return "400 Bad request";
636
+            	case "infinity": // valid
637
+                	break;
638
+            	case "0": // valid for COPY only
639
+                	if ($del) { // MOVE?
640
+                    	return "400 Bad request";
641
+                	}
642
+                	break;
643
+            	case "1": // invalid for both COPY and MOVE
644
+            	default:
645
+                	return "400 Bad request";
646 646
             }
647 647
         }
648 648
 
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     function PROPFIND(&$options, &$files)
152 152
     {
153 153
         // get absolute fs path to requested resource
154
-        $fspath = $this->base . $options["path"];
154
+        $fspath = $this->base.$options["path"];
155 155
 
156 156
         // sanity check
157 157
         if (!file_exists($fspath)) {
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
     function fileinfo($path)
199 199
     {
200 200
         // map URI path to filesystem path
201
-        $fspath = $this->base . $path;
201
+        $fspath = $this->base.$path;
202 202
 
203 203
         // create result array
204 204
         $info = array();
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
         $info["props"][] = $this->mkprop("displayname", strtoupper($path));
211 211
 
212 212
         // creation and modification time
213
-        $info["props"][] = $this->mkprop("creationdate",    filectime($fspath));
213
+        $info["props"][] = $this->mkprop("creationdate", filectime($fspath));
214 214
         $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath));
215 215
 
216 216
         // Microsoft extensions: last access time and 'hidden' status
217
-        $info["props"][] = $this->mkprop("lastaccessed",    fileatime($fspath));
217
+        $info["props"][] = $this->mkprop("lastaccessed", fileatime($fspath));
218 218
         $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219 219
 
220 220
         // type and size (caller already made sure that path exists)
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
             // so we test the format of the returned string
342 342
 
343 343
             // the reply begins with the requested filename
344
-            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
345
-                $reply = substr($reply, strlen($fspath)+2);
344
+            if (!strncmp($reply, "$fspath: ", strlen($fspath) + 2)) {
345
+                $reply = substr($reply, strlen($fspath) + 2);
346 346
                 // followed by the mime type (maybe including options)
347 347
                 if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
348 348
                     $mime_type = $matches[0];
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
     function HEAD(&$options)
393 393
     {
394 394
         // get absolute fs path to requested resource
395
-        $fspath = $this->base . $options["path"];
395
+        $fspath = $this->base.$options["path"];
396 396
 
397 397
         // sanity check
398 398
         if (!file_exists($fspath)) return false;
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
     function GET(&$options)
422 422
     {
423 423
         // get absolute fs path to requested resource
424
-        $fspath = $this->base . $options["path"];
424
+        $fspath = $this->base.$options["path"];
425 425
 
426 426
         // is this a collection?
427 427
         if (is_dir($fspath)) {
@@ -504,14 +504,14 @@  discard block
 block discarded – undo
504 504
      */
505 505
     function PUT(&$options)
506 506
     {
507
-        $fspath = $this->base . $options["path"];
507
+        $fspath = $this->base.$options["path"];
508 508
 
509 509
         $dir = dirname($fspath);
510 510
         if (!file_exists($dir) || !is_dir($dir)) {
511 511
             return "409 Conflict"; // TODO right status code for both?
512 512
         }
513 513
 
514
-        $options["new"] = ! file_exists($fspath);
514
+        $options["new"] = !file_exists($fspath);
515 515
 
516 516
         if ($options["new"] && !$this->_is_writable($dir)) {
517 517
             return "403 Forbidden";
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
      */
538 538
     function MKCOL($options)
539 539
     {
540
-        $path   = $this->base .$options["path"];
540
+        $path   = $this->base.$options["path"];
541 541
         $parent = dirname($path);
542 542
         $name   = basename($path);
543 543
 
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             return "403 Forbidden";
550 550
         }
551 551
 
552
-        if ( file_exists($parent."/".$name) ) {
552
+        if (file_exists($parent."/".$name)) {
553 553
             return "405 Method not allowed";
554 554
         }
555 555
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      */
575 575
     function DELETE($options)
576 576
     {
577
-        $path = $this->base . "/" .$options["path"];
577
+        $path = $this->base."/".$options["path"];
578 578
 
579 579
         if (!file_exists($path)) {
580 580
             return "404 Not found";
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
      * @param  array  general parameter passing array
614 614
      * @return bool   true on success
615 615
      */
616
-    function COPY($options, $del=false)
616
+    function COPY($options, $del = false)
617 617
     {
618 618
         // TODO Property updates still broken (Litmus should detect this?)
619 619
 
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
             return "502 bad gateway";
627 627
         }
628 628
 
629
-        $source = $this->base . $options["path"];
629
+        $source = $this->base.$options["path"];
630 630
         if (!file_exists($source)) {
631 631
             return "404 Not found";
632 632
         }
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
             }
647 647
         }
648 648
 
649
-        $dest         = $this->base . $options["dest"];
649
+        $dest         = $this->base.$options["dest"];
650 650
         $destdir      = dirname($dest);
651 651
 
652 652
         if (!file_exists($destdir) || !is_dir($destdir)) {
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
     function LOCK(&$options)
796 796
     {
797 797
         // get absolute fs path to requested resource
798
-        $fspath = $this->base . $options["path"];
798
+        $fspath = $this->base.$options["path"];
799 799
 
800 800
         // TODO recursive locks on directories not supported yet
801 801
         // makes litmus test "32. lock_collection" fail
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
             return "409 Conflict";
804 804
         }
805 805
 
806
-        $options["timeout"] = time()+300; // 5min. hardcoded
806
+        $options["timeout"] = time() + 300; // 5min. hardcoded
807 807
 
808 808
         if (isset($options["update"])) { // Lock Update
809 809
             $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
 
823 823
                 $options['owner'] = $row['owner'];
824 824
                 $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
825
-                $options['type']  = $row["exclusivelock"] ? "write"     : "read";
825
+                $options['type']  = $row["exclusivelock"] ? "write" : "read";
826 826
 
827 827
                 return true;
828 828
             } else {
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
                           , modified = ".time()."
838 838
                           , owner   = '$options[owner]'
839 839
                           , expires = '$options[timeout]'
840
-                          , exclusivelock  = " .($options['scope'] === "exclusive" ? "1" : "0")
840
+                          , exclusivelock  = ".($options['scope'] === "exclusive" ? "1" : "0")
841 841
             ;
842 842
         mysql_query($query);
843 843
 
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
             mysql_free_result($res);
882 882
 
883 883
             if ($row) {
884
-                $result = array( "type"    => "write",
884
+                $result = array("type"    => "write",
885 885
                                  "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
886 886
                                  "depth"   => 0,
887 887
                                  "owner"   => $row['owner'],
Please login to merge, or discard this patch.
Braces   +212 added lines, -91 removed lines patch added patch discarded remove patch
@@ -105,15 +105,19 @@  discard block
 block discarded – undo
105 105
         // special treatment for litmus compliance test
106 106
         // reply on its identifier header
107 107
         // not needed for the test itself but eases debugging
108
-        if (isset($this->_SERVER['HTTP_X_LITMUS'])) {
108
+        if (isset($this->_SERVER['HTTP_X_LITMUS']))
109
+        {
109 110
             error_log("Litmus test ".$this->_SERVER['HTTP_X_LITMUS']);
110 111
             header("X-Litmus-reply: ".$this->_SERVER['HTTP_X_LITMUS']);
111 112
         }
112 113
 
113 114
         // set root directory, defaults to webserver document root if not set
114
-        if ($base) {
115
+        if ($base)
116
+        {
115 117
             $this->base = realpath($base); // TODO throw if not a directory
116
-        } else if (!$this->base) {
118
+        }
119
+        else if (!$this->base)
120
+        {
117 121
             $this->base = $this->_SERVER['DOCUMENT_ROOT'];
118 122
         }
119 123
 
@@ -154,7 +158,8 @@  discard block
 block discarded – undo
154 158
         $fspath = $this->base . $options["path"];
155 159
 
156 160
         // sanity check
157
-        if (!file_exists($fspath)) {
161
+        if (!file_exists($fspath))
162
+        {
158 163
             return false;
159 164
         }
160 165
 
@@ -165,7 +170,8 @@  discard block
 block discarded – undo
165 170
         $files["files"][] = $this->fileinfo($options["path"]);
166 171
 
167 172
         // information for contained resources requested?
168
-        if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath)) {
173
+        if (!empty($options["depth"]) && is_dir($fspath) && $this->_is_readable($fspath))
174
+        {
169 175
 
170 176
             // make sure path ends with '/'
171 177
             $options["path"] = $this->_slashify($options["path"]);
@@ -173,10 +179,13 @@  discard block
 block discarded – undo
173 179
             // try to open directory
174 180
             $handle = opendir($fspath);
175 181
 
176
-            if ($handle) {
182
+            if ($handle)
183
+            {
177 184
                 // ok, now get all its contents
178
-                while ($filename = readdir($handle)) {
179
-                    if ($filename != "." && $filename != "..") {
185
+                while ($filename = readdir($handle))
186
+                {
187
+                    if ($filename != "." && $filename != "..")
188
+                    {
180 189
                         $files["files"][] = $this->fileinfo($options["path"].$filename);
181 190
                     }
182 191
                 }
@@ -218,16 +227,22 @@  discard block
 block discarded – undo
218 227
         $info["props"][] = $this->mkprop("ishidden", ('.' === substr(basename($fspath), 0, 1)));
219 228
 
220 229
         // type and size (caller already made sure that path exists)
221
-        if (is_dir($fspath)) {
230
+        if (is_dir($fspath))
231
+        {
222 232
             // directory (WebDAV collection)
223 233
             $info["props"][] = $this->mkprop("resourcetype", "collection");
224 234
             $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
225
-        } else {
235
+        }
236
+        else
237
+        {
226 238
             // plain file (WebDAV resource)
227 239
             $info["props"][] = $this->mkprop("resourcetype", "");
228
-            if ($this->_is_readable($fspath)) {
240
+            if ($this->_is_readable($fspath))
241
+            {
229 242
                 $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
230
-            } else {
243
+            }
244
+            else
245
+            {
231 246
                 $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable");
232 247
             }
233 248
             $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath));
@@ -238,7 +253,8 @@  discard block
 block discarded – undo
238 253
                         FROM {$this->db_prefix}properties
239 254
                        WHERE path = '$path'";
240 255
         $res = mysql_query($query);
241
-        while ($row = mysql_fetch_assoc($res)) {
256
+        while ($row = mysql_fetch_assoc($res))
257
+        {
242 258
             $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
243 259
         }
244 260
         mysql_free_result($res);
@@ -259,30 +275,45 @@  discard block
 block discarded – undo
259 275
     function _can_execute($name, $path = false)
260 276
     {
261 277
         // path defaults to PATH from environment if not set
262
-        if ($path === false) {
278
+        if ($path === false)
279
+        {
263 280
             $path = getenv("PATH");
264 281
         }
265 282
 
266 283
         // check method depends on operating system
267
-        if (!strncmp(PHP_OS, "WIN", 3)) {
284
+        if (!strncmp(PHP_OS, "WIN", 3))
285
+        {
268 286
             // on Windows an appropriate COM or EXE file needs to exist
269 287
             $exts     = array(".exe", ".com");
270 288
             $check_fn = "file_exists";
271
-        } else {
289
+        }
290
+        else
291
+        {
272 292
             // anywhere else we look for an executable file of that name
273 293
             $exts     = array("");
274 294
             $check_fn = "is_executable";
275 295
         }
276 296
 
277 297
         // now check the directories in the path for the program
278
-        foreach (explode(PATH_SEPARATOR, $path) as $dir) {
298
+        foreach (explode(PATH_SEPARATOR, $path) as $dir)
299
+        {
279 300
             // skip invalid path entries
280
-            if (!file_exists($dir)) continue;
281
-            if (!is_dir($dir)) continue;
301
+            if (!file_exists($dir))
302
+            {
303
+            	continue;
304
+            }
305
+            if (!is_dir($dir))
306
+            {
307
+            	continue;
308
+            }
282 309
 
283 310
             // and now look for the file
284
-            foreach ($exts as $ext) {
285
-                if ($check_fn("$dir/$name".$ext)) return true;
311
+            foreach ($exts as $ext)
312
+            {
313
+                if ($check_fn("$dir/$name".$ext))
314
+                {
315
+                	return true;
316
+                }
286 317
             }
287 318
         }
288 319
 
@@ -323,13 +354,18 @@  discard block
 block discarded – undo
323 354
      */
324 355
     function _mimetype($fspath)
325 356
     {
326
-        if (is_dir($fspath)) {
357
+        if (is_dir($fspath))
358
+        {
327 359
             // directories are easy
328 360
             return "httpd/unix-directory";
329
-        } else if (function_exists("mime_content_type")) {
361
+        }
362
+        else if (function_exists("mime_content_type"))
363
+        {
330 364
             // use mime magic extension if available
331 365
             $mime_type = mime_content_type($fspath);
332
-        } else if ($this->_can_execute("file")) {
366
+        }
367
+        else if ($this->_can_execute("file"))
368
+        {
333 369
             // it looks like we have a 'file' command,
334 370
             // lets see it it does have mime support
335 371
             $fp    = popen("file -i '$fspath' 2>/dev/null", "r");
@@ -341,16 +377,19 @@  discard block
 block discarded – undo
341 377
             // so we test the format of the returned string
342 378
 
343 379
             // the reply begins with the requested filename
344
-            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) {
380
+            if (!strncmp($reply, "$fspath: ", strlen($fspath)+2))
381
+            {
345 382
                 $reply = substr($reply, strlen($fspath)+2);
346 383
                 // followed by the mime type (maybe including options)
347
-                if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) {
384
+                if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches))
385
+                {
348 386
                     $mime_type = $matches[0];
349 387
                 }
350 388
             }
351 389
         }
352 390
 
353
-        if (empty($mime_type)) {
391
+        if (empty($mime_type))
392
+        {
354 393
             // Fallback solution: try to guess the type by the file extension
355 394
             // TODO: add more ...
356 395
             // TODO: it has been suggested to delegate mimetype detection
@@ -364,7 +403,8 @@  discard block
 block discarded – undo
364 403
             //       anyway (overriding it with information taken from
365 404
             //       the registry)
366 405
             // TODO: have a seperate PEAR class for mimetype detection?
367
-            switch (strtolower(strrchr(basename($fspath), "."))) {
406
+            switch (strtolower(strrchr(basename($fspath), ".")))
407
+            {
368 408
             case ".html":
369 409
                 $mime_type = "text/html";
370 410
                 break;
@@ -395,7 +435,10 @@  discard block
 block discarded – undo
395 435
         $fspath = $this->base . $options["path"];
396 436
 
397 437
         // sanity check
398
-        if (!file_exists($fspath)) return false;
438
+        if (!file_exists($fspath))
439
+        {
440
+        	return false;
441
+        }
399 442
 
400 443
         // detect resource type
401 444
         $options['mimetype'] = $this->_mimetype($fspath);
@@ -424,12 +467,14 @@  discard block
 block discarded – undo
424 467
         $fspath = $this->base . $options["path"];
425 468
 
426 469
         // is this a collection?
427
-        if (is_dir($fspath)) {
470
+        if (is_dir($fspath))
471
+        {
428 472
             return $this->GetDir($fspath, $options);
429 473
         }
430 474
 
431 475
         // the header output is the same as for HEAD
432
-        if (!$this->HEAD($options)) {
476
+        if (!$this->HEAD($options))
477
+        {
433 478
             return false;
434 479
         }
435 480
 
@@ -451,7 +496,8 @@  discard block
 block discarded – undo
451 496
     function GetDir($fspath, &$options)
452 497
     {
453 498
         $path = $this->_slashify($options["path"]);
454
-        if ($path != $options["path"]) {
499
+        if ($path != $options["path"])
500
+        {
455 501
             header("Location: ".$this->base_uri.$path);
456 502
             exit;
457 503
         }
@@ -459,12 +505,14 @@  discard block
 block discarded – undo
459 505
         // fixed width directory column format
460 506
         $format = "%15s  %-19s  %-s\n";
461 507
 
462
-        if (!$this->_is_readable($fspath)) {
508
+        if (!$this->_is_readable($fspath))
509
+        {
463 510
             return false;
464 511
         }
465 512
 
466 513
         $handle = opendir($fspath);
467
-        if (!$handle) {
514
+        if (!$handle)
515
+        {
468 516
             return false;
469 517
         }
470 518
 
@@ -476,8 +524,10 @@  discard block
 block discarded – undo
476 524
         printf($format, "Size", "Last modified", "Filename");
477 525
         echo "<hr>";
478 526
 
479
-        while ($filename = readdir($handle)) {
480
-            if ($filename != "." && $filename != "..") {
527
+        while ($filename = readdir($handle))
528
+        {
529
+            if ($filename != "." && $filename != "..")
530
+            {
481 531
                 $fullpath = $fspath.$filename;
482 532
                 $name     = htmlspecialchars($filename);
483 533
                 printf($format,
@@ -507,19 +557,23 @@  discard block
 block discarded – undo
507 557
         $fspath = $this->base . $options["path"];
508 558
 
509 559
         $dir = dirname($fspath);
510
-        if (!file_exists($dir) || !is_dir($dir)) {
560
+        if (!file_exists($dir) || !is_dir($dir))
561
+        {
511 562
             return "409 Conflict"; // TODO right status code for both?
512 563
         }
513 564
 
514 565
         $options["new"] = ! file_exists($fspath);
515 566
 
516
-        if ($options["new"] && !$this->_is_writable($dir)) {
567
+        if ($options["new"] && !$this->_is_writable($dir))
568
+        {
517 569
             return "403 Forbidden";
518 570
         }
519
-        if (!$options["new"] && !$this->_is_writable($fspath)) {
571
+        if (!$options["new"] && !$this->_is_writable($fspath))
572
+        {
520 573
             return "403 Forbidden";
521 574
         }
522
-        if (!$options["new"] && is_dir($fspath)) {
575
+        if (!$options["new"] && is_dir($fspath))
576
+        {
523 577
             return "403 Forbidden";
524 578
         }
525 579
 
@@ -541,24 +595,30 @@  discard block
 block discarded – undo
541 595
         $parent = dirname($path);
542 596
         $name   = basename($path);
543 597
 
544
-        if (!file_exists($parent)) {
598
+        if (!file_exists($parent))
599
+        {
545 600
             return "409 Conflict";
546 601
         }
547 602
 
548
-        if (!is_dir($parent)) {
603
+        if (!is_dir($parent))
604
+        {
549 605
             return "403 Forbidden";
550 606
         }
551 607
 
552
-        if ( file_exists($parent."/".$name) ) {
608
+        if ( file_exists($parent."/".$name) )
609
+        {
553 610
             return "405 Method not allowed";
554 611
         }
555 612
 
556
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
613
+        if (!empty($this->_SERVER["CONTENT_LENGTH"]))
614
+        {
615
+// no body parsing yet
557 616
             return "415 Unsupported media type";
558 617
         }
559 618
 
560 619
         $stat = mkdir($parent."/".$name, 0777);
561
-        if (!$stat) {
620
+        if (!$stat)
621
+        {
562 622
             return "403 Forbidden";
563 623
         }
564 624
 
@@ -576,16 +636,20 @@  discard block
 block discarded – undo
576 636
     {
577 637
         $path = $this->base . "/" .$options["path"];
578 638
 
579
-        if (!file_exists($path)) {
639
+        if (!file_exists($path))
640
+        {
580 641
             return "404 Not found";
581 642
         }
582 643
 
583
-        if (is_dir($path)) {
644
+        if (is_dir($path))
645
+        {
584 646
             $query = "DELETE FROM {$this->db_prefix}properties
585 647
                            WHERE path LIKE '".$this->_slashify($options["path"])."%'";
586 648
             mysql_query($query);
587 649
             System::rm(array("-rf", $path));
588
-        } else {
650
+        }
651
+        else
652
+        {
589 653
             unlink($path);
590 654
         }
591 655
         $query = "DELETE FROM {$this->db_prefix}properties
@@ -617,26 +681,35 @@  discard block
 block discarded – undo
617 681
     {
618 682
         // TODO Property updates still broken (Litmus should detect this?)
619 683
 
620
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
684
+        if (!empty($this->_SERVER["CONTENT_LENGTH"]))
685
+        {
686
+// no body parsing yet
621 687
             return "415 Unsupported media type";
622 688
         }
623 689
 
624 690
         // no copying to different WebDAV Servers yet
625
-        if (isset($options["dest_url"])) {
691
+        if (isset($options["dest_url"]))
692
+        {
626 693
             return "502 bad gateway";
627 694
         }
628 695
 
629 696
         $source = $this->base . $options["path"];
630
-        if (!file_exists($source)) {
697
+        if (!file_exists($source))
698
+        {
631 699
             return "404 Not found";
632 700
         }
633 701
 
634
-        if (is_dir($source)) { // resource is a collection
635
-            switch ($options["depth"]) {
702
+        if (is_dir($source))
703
+        {
704
+// resource is a collection
705
+            switch ($options["depth"])
706
+            {
636 707
             case "infinity": // valid
637 708
                 break;
638 709
             case "0": // valid for COPY only
639
-                if ($del) { // MOVE?
710
+                if ($del)
711
+                {
712
+// MOVE?
640 713
                     return "400 Bad request";
641 714
                 }
642 715
                 break;
@@ -649,7 +722,8 @@  discard block
 block discarded – undo
649 722
         $dest         = $this->base . $options["dest"];
650 723
         $destdir      = dirname($dest);
651 724
 
652
-        if (!file_exists($destdir) || !is_dir($destdir)) {
725
+        if (!file_exists($destdir) || !is_dir($destdir))
726
+        {
653 727
             return "409 Conflict";
654 728
         }
655 729
 
@@ -657,38 +731,52 @@  discard block
 block discarded – undo
657 731
         $new          = !file_exists($dest);
658 732
         $existing_col = false;
659 733
 
660
-        if (!$new) {
661
-            if ($del && is_dir($dest)) {
662
-                if (!$options["overwrite"]) {
734
+        if (!$new)
735
+        {
736
+            if ($del && is_dir($dest))
737
+            {
738
+                if (!$options["overwrite"])
739
+                {
663 740
                     return "412 precondition failed";
664 741
                 }
665 742
                 $dest .= basename($source);
666
-                if (file_exists($dest)) {
743
+                if (file_exists($dest))
744
+                {
667 745
                     $options["dest"] .= basename($source);
668
-                } else {
746
+                }
747
+                else
748
+                {
669 749
                     $new          = true;
670 750
                     $existing_col = true;
671 751
                 }
672 752
             }
673 753
         }
674 754
 
675
-        if (!$new) {
676
-            if ($options["overwrite"]) {
755
+        if (!$new)
756
+        {
757
+            if ($options["overwrite"])
758
+            {
677 759
                 $stat = $this->DELETE(array("path" => $options["dest"]));
678
-                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
760
+                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404"))
761
+                {
679 762
                     return $stat;
680 763
                 }
681
-            } else {
764
+            }
765
+            else
766
+            {
682 767
                 return "412 precondition failed";
683 768
             }
684 769
         }
685 770
 
686
-        if ($del) {
687
-            if (!rename($source, $dest)) {
771
+        if ($del)
772
+        {
773
+            if (!rename($source, $dest))
774
+            {
688 775
                 return "500 Internal server error";
689 776
             }
690 777
             $destpath = $this->_unslashify($options["dest"]);
691
-            if (is_dir($source)) {
778
+            if (is_dir($source))
779
+            {
692 780
                 $query = "UPDATE {$this->db_prefix}properties
693 781
                                  SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
694 782
                                WHERE path LIKE '".$this->_slashify($options["path"])."%'";
@@ -699,40 +787,58 @@  discard block
 block discarded – undo
699 787
                              SET path = '".$destpath."'
700 788
                            WHERE path = '".$options["path"]."'";
701 789
             mysql_query($query);
702
-        } else {
703
-            if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
790
+        }
791
+        else
792
+        {
793
+            if (is_dir($source) && $options["depth"] == "infinity")
794
+            {
795
+// no find for depth="0"
704 796
                 $files = System::find($source);
705 797
                 $files = array_reverse($files);
706
-            } else {
798
+            }
799
+            else
800
+            {
707 801
                 $files = array($source);
708 802
             }
709 803
 
710
-            if (!is_array($files) || empty($files)) {
804
+            if (!is_array($files) || empty($files))
805
+            {
711 806
                 return "500 Internal server error";
712 807
             }
713 808
 
714 809
 
715
-            foreach ($files as $file) {
716
-                if (is_dir($file)) {
810
+            foreach ($files as $file)
811
+            {
812
+                if (is_dir($file))
813
+                {
717 814
                     $file = $this->_slashify($file);
718 815
                 }
719 816
 
720 817
                 $destfile = str_replace($source, $dest, $file);
721 818
 
722
-                if (is_dir($file)) {
723
-                    if (!file_exists($destfile)) {
724
-                        if (!$this->_is_writable(dirname($destfile))) {
819
+                if (is_dir($file))
820
+                {
821
+                    if (!file_exists($destfile))
822
+                    {
823
+                        if (!$this->_is_writable(dirname($destfile)))
824
+                        {
725 825
                             return "403 Forbidden";
726 826
                         }
727
-                        if (!mkdir($destfile)) {
827
+                        if (!mkdir($destfile))
828
+                        {
728 829
                             return "409 Conflict";
729 830
                         }
730
-                    } else if (!is_dir($destfile)) {
831
+                    }
832
+                    else if (!is_dir($destfile))
833
+                    {
731 834
                         return "409 Conflict";
732 835
                     }
733
-                } else {
836
+                }
837
+                else
838
+                {
734 839
 
735
-                    if (!copy($file, $destfile)) {
840
+                    if (!copy($file, $destfile))
841
+                    {
736 842
                         return "409 Conflict";
737 843
                     }
738 844
                 }
@@ -762,17 +868,24 @@  discard block
 block discarded – undo
762 868
         $dir  = dirname($path)."/";
763 869
         $base = basename($path);
764 870
 
765
-        foreach ($options["props"] as $key => $prop) {
766
-            if ($prop["ns"] == "DAV:") {
871
+        foreach ($options["props"] as $key => $prop)
872
+        {
873
+            if ($prop["ns"] == "DAV:")
874
+            {
767 875
                 $options["props"][$key]['status'] = "403 Forbidden";
768
-            } else {
769
-                if (isset($prop["val"])) {
876
+            }
877
+            else
878
+            {
879
+                if (isset($prop["val"]))
880
+                {
770 881
                     $query = "REPLACE INTO {$this->db_prefix}properties
771 882
                                            SET path = '$options[path]'
772 883
                                              , name = '$prop[name]'
773 884
                                              , ns= '$prop[ns]'
774 885
                                              , value = '$prop[val]'";
775
-                } else {
886
+                }
887
+                else
888
+                {
776 889
                     $query = "DELETE FROM {$this->db_prefix}properties
777 890
                                         WHERE path = '$options[path]'
778 891
                                           AND name = '$prop[name]'
@@ -799,13 +912,16 @@  discard block
 block discarded – undo
799 912
 
800 913
         // TODO recursive locks on directories not supported yet
801 914
         // makes litmus test "32. lock_collection" fail
802
-        if (is_dir($fspath) && !empty($options["depth"])) {
915
+        if (is_dir($fspath) && !empty($options["depth"]))
916
+        {
803 917
             return "409 Conflict";
804 918
         }
805 919
 
806 920
         $options["timeout"] = time()+300; // 5min. hardcoded
807 921
 
808
-        if (isset($options["update"])) { // Lock Update
922
+        if (isset($options["update"]))
923
+        {
924
+// Lock Update
809 925
             $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
810 926
 
811 927
             $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
@@ -813,7 +929,8 @@  discard block
 block discarded – undo
813 929
             $row   = mysql_fetch_assoc($res);
814 930
             mysql_free_result($res);
815 931
 
816
-            if (is_array($row)) {
932
+            if (is_array($row))
933
+            {
817 934
                 $query = "UPDATE {$this->db_prefix}locks
818 935
                                  SET expires = '$options[timeout]'
819 936
                                    , modified = ".time()."
@@ -825,7 +942,9 @@  discard block
 block discarded – undo
825 942
                 $options['type']  = $row["exclusivelock"] ? "write"     : "read";
826 943
 
827 944
                 return true;
828
-            } else {
945
+            }
946
+            else
947
+            {
829 948
                 return false;
830 949
             }
831 950
         }
@@ -876,11 +995,13 @@  discard block
 block discarded – undo
876 995
                ";
877 996
         $res = mysql_query($query);
878 997
 
879
-        if ($res) {
998
+        if ($res)
999
+        {
880 1000
             $row = mysql_fetch_array($res);
881 1001
             mysql_free_result($res);
882 1002
 
883
-            if ($row) {
1003
+            if ($row)
1004
+            {
884 1005
                 $result = array( "type"    => "write",
885 1006
                                  "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
886 1007
                                  "depth"   => 0,
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -689,13 +689,13 @@  discard block
 block discarded – undo
689 689
             }
690 690
             $destpath = $this->_unslashify($options["dest"]);
691 691
             if (is_dir($source)) {
692
-                $query = "UPDATE {$this->db_prefix}properties
692
+                $query = "update {$this->db_prefix}properties
693 693
                                  SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
694 694
                                WHERE path LIKE '".$this->_slashify($options["path"])."%'";
695 695
                 mysql_query($query);
696 696
             }
697 697
 
698
-            $query = "UPDATE {$this->db_prefix}properties
698
+            $query = "update {$this->db_prefix}properties
699 699
                              SET path = '".$destpath."'
700 700
                            WHERE path = '".$options["path"]."'";
701 701
             mysql_query($query);
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
             mysql_free_result($res);
815 815
 
816 816
             if (is_array($row)) {
817
-                $query = "UPDATE {$this->db_prefix}locks
817
+                $query = "update {$this->db_prefix}locks
818 818
                                  SET expires = '$options[timeout]'
819 819
                                    , modified = ".time()."
820 820
                               $where";
Please login to merge, or discard this patch.
api/src/WebDAV/Tools/_parse_proppatch.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -95,6 +95,7 @@
 block discarded – undo
95 95
      *
96 96
      * @param  string  path of input stream
97 97
      * @param boolean $store_request =false if true whole request data will be made available in $this->request
98
+     * @param string $path
98 99
      * @access public
99 100
      */
100 101
     function __construct($path, $store_request=false)
Please login to merge, or discard this patch.
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -43,198 +43,198 @@
 block discarded – undo
43 43
  */
44 44
 class _parse_proppatch
45 45
 {
46
-    /**
47
-     *
48
-     *
49
-     * @var
50
-     * @access
51
-     */
52
-    var $success;
53
-
54
-    /**
55
-     *
56
-     *
57
-     * @var
58
-     * @access
59
-     */
60
-    var $props;
61
-
62
-    /**
63
-     *
64
-     *
65
-     * @var
66
-     * @access
67
-     */
68
-    var $depth;
69
-
70
-    /**
71
-     *
72
-     *
73
-     * @var
74
-     * @access
75
-     */
76
-    var $mode;
77
-
78
-    /**
79
-     *
80
-     *
81
-     * @var
82
-     * @access
83
-     */
84
-    var $current;
85
-
86
-    /**
87
-     * On return whole request, if $store_request == true was specified in constructor
88
-     *
89
-     * @var string
90
-     */
91
-    var $request;
92
-
93
-    /**
94
-     * constructor
95
-     *
96
-     * @param  string  path of input stream
97
-     * @param boolean $store_request =false if true whole request data will be made available in $this->request
98
-     * @access public
99
-     */
100
-    function __construct($path, $store_request=false)
101
-    {
102
-        $this->success = true;
103
-
104
-        $this->depth = 0;
105
-        $this->props = array();
106
-        $had_input = false;
107
-
108
-        $f_in = fopen($path, "r");
109
-        if (!$f_in) {
110
-            $this->success = false;
111
-            return;
112
-        }
113
-
114
-        $xml_parser = xml_parser_create_ns("UTF-8", " ");
115
-
116
-        xml_set_element_handler($xml_parser,
117
-                                array(&$this, "_startElement"),
118
-                                array(&$this, "_endElement"));
119
-
120
-        xml_set_character_data_handler($xml_parser,
121
-                                       array(&$this, "_data"));
122
-
123
-        xml_parser_set_option($xml_parser,
124
-                              XML_OPTION_CASE_FOLDING, false);
125
-
126
-        while($this->success && !feof($f_in)) {
127
-            $line = fgets($f_in);
128
-            if ($store_request) $this->request .= $line;
129
-            if (is_string($line)) {
130
-                $had_input = true;
131
-                $this->success &= xml_parse($xml_parser, $line, false);
132
-            }
133
-        }
134
-
135
-        if($had_input) {
136
-            $this->success &= xml_parse($xml_parser, "", true);
137
-        }
138
-
139
-        xml_parser_free($xml_parser);
140
-
141
-        fclose($f_in);
142
-    }
143
-
144
-    /**
145
-     * tag start handler
146
-     *
147
-     * @param  resource  parser
148
-     * @param  string    tag name
149
-     * @param  array     tag attributes
150
-     * @return void
151
-     * @access private
152
-     */
153
-    function _startElement($parser, $name, $attrs)
154
-    {
155
-        if (strstr($name, " ")) {
156
-            list($ns, $tag) = explode(" ", $name);
157
-            if ($ns == "")
158
-                $this->success = false;
159
-        } else {
160
-            $ns = "";
161
-            $tag = $name;
162
-        }
163
-
164
-        if ($this->depth == 1) {
165
-            $this->mode = $tag;
166
-        }
167
-
168
-        if ($this->depth == 3) {
169
-            $prop = array("name" => $tag);
170
-            $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171
-            if ($this->mode == "set") {
172
-                $this->current["val"] = "";     // default set val
173
-            }
174
-        }
175
-
176
-        if ($this->depth >= 4) {
177
-            $this->current["val"] .= "<$tag";
178
-            if (isset($attr)) {
179
-                foreach ($attr as $key => $val) {
180
-                    $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
181
-                }
182
-            }
183
-            $this->current["val"] .= ">";
184
-        }
185
-
186
-
187
-
188
-        $this->depth++;
189
-    }
190
-
191
-    /**
192
-     * tag end handler
193
-     *
194
-     * @param  resource  parser
195
-     * @param  string    tag name
196
-     * @return void
197
-     * @access private
198
-     */
199
-    function _endElement($parser, $name)
200
-    {
201
-        if (strstr($name, " ")) {
202
-            list($ns, $tag) = explode(" ", $name);
203
-            if ($ns == "")
204
-                $this->success = false;
205
-        } else {
206
-            $ns = "";
207
-            $tag = $name;
208
-        }
209
-
210
-        $this->depth--;
211
-
212
-        if ($this->depth >= 4) {
213
-            $this->current["val"] .= "</$tag>";
214
-        }
215
-
216
-        if ($this->depth == 3) {
217
-            if (isset($this->current)) {
218
-                $this->props[] = $this->current;
219
-                unset($this->current);
220
-            }
221
-        }
222
-    }
223
-
224
-    /**
225
-     * input data handler
226
-     *
227
-     * @param  resource  parser
228
-     * @param  string    data
229
-     * @return void
230
-     * @access private
231
-     */
232
-    function _data($parser, $data)
233
-    {
234
-        if (isset($this->current)) {
235
-            $this->current["val"] .= $data;
236
-        }
237
-    }
46
+	/**
47
+	 *
48
+	 *
49
+	 * @var
50
+	 * @access
51
+	 */
52
+	var $success;
53
+
54
+	/**
55
+	 *
56
+	 *
57
+	 * @var
58
+	 * @access
59
+	 */
60
+	var $props;
61
+
62
+	/**
63
+	 *
64
+	 *
65
+	 * @var
66
+	 * @access
67
+	 */
68
+	var $depth;
69
+
70
+	/**
71
+	 *
72
+	 *
73
+	 * @var
74
+	 * @access
75
+	 */
76
+	var $mode;
77
+
78
+	/**
79
+	 *
80
+	 *
81
+	 * @var
82
+	 * @access
83
+	 */
84
+	var $current;
85
+
86
+	/**
87
+	 * On return whole request, if $store_request == true was specified in constructor
88
+	 *
89
+	 * @var string
90
+	 */
91
+	var $request;
92
+
93
+	/**
94
+	 * constructor
95
+	 *
96
+	 * @param  string  path of input stream
97
+	 * @param boolean $store_request =false if true whole request data will be made available in $this->request
98
+	 * @access public
99
+	 */
100
+	function __construct($path, $store_request=false)
101
+	{
102
+		$this->success = true;
103
+
104
+		$this->depth = 0;
105
+		$this->props = array();
106
+		$had_input = false;
107
+
108
+		$f_in = fopen($path, "r");
109
+		if (!$f_in) {
110
+			$this->success = false;
111
+			return;
112
+		}
113
+
114
+		$xml_parser = xml_parser_create_ns("UTF-8", " ");
115
+
116
+		xml_set_element_handler($xml_parser,
117
+								array(&$this, "_startElement"),
118
+								array(&$this, "_endElement"));
119
+
120
+		xml_set_character_data_handler($xml_parser,
121
+									   array(&$this, "_data"));
122
+
123
+		xml_parser_set_option($xml_parser,
124
+							  XML_OPTION_CASE_FOLDING, false);
125
+
126
+		while($this->success && !feof($f_in)) {
127
+			$line = fgets($f_in);
128
+			if ($store_request) $this->request .= $line;
129
+			if (is_string($line)) {
130
+				$had_input = true;
131
+				$this->success &= xml_parse($xml_parser, $line, false);
132
+			}
133
+		}
134
+
135
+		if($had_input) {
136
+			$this->success &= xml_parse($xml_parser, "", true);
137
+		}
138
+
139
+		xml_parser_free($xml_parser);
140
+
141
+		fclose($f_in);
142
+	}
143
+
144
+	/**
145
+	 * tag start handler
146
+	 *
147
+	 * @param  resource  parser
148
+	 * @param  string    tag name
149
+	 * @param  array     tag attributes
150
+	 * @return void
151
+	 * @access private
152
+	 */
153
+	function _startElement($parser, $name, $attrs)
154
+	{
155
+		if (strstr($name, " ")) {
156
+			list($ns, $tag) = explode(" ", $name);
157
+			if ($ns == "")
158
+				$this->success = false;
159
+		} else {
160
+			$ns = "";
161
+			$tag = $name;
162
+		}
163
+
164
+		if ($this->depth == 1) {
165
+			$this->mode = $tag;
166
+		}
167
+
168
+		if ($this->depth == 3) {
169
+			$prop = array("name" => $tag);
170
+			$this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171
+			if ($this->mode == "set") {
172
+				$this->current["val"] = "";     // default set val
173
+			}
174
+		}
175
+
176
+		if ($this->depth >= 4) {
177
+			$this->current["val"] .= "<$tag";
178
+			if (isset($attr)) {
179
+				foreach ($attr as $key => $val) {
180
+					$this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
181
+				}
182
+			}
183
+			$this->current["val"] .= ">";
184
+		}
185
+
186
+
187
+
188
+		$this->depth++;
189
+	}
190
+
191
+	/**
192
+	 * tag end handler
193
+	 *
194
+	 * @param  resource  parser
195
+	 * @param  string    tag name
196
+	 * @return void
197
+	 * @access private
198
+	 */
199
+	function _endElement($parser, $name)
200
+	{
201
+		if (strstr($name, " ")) {
202
+			list($ns, $tag) = explode(" ", $name);
203
+			if ($ns == "")
204
+				$this->success = false;
205
+		} else {
206
+			$ns = "";
207
+			$tag = $name;
208
+		}
209
+
210
+		$this->depth--;
211
+
212
+		if ($this->depth >= 4) {
213
+			$this->current["val"] .= "</$tag>";
214
+		}
215
+
216
+		if ($this->depth == 3) {
217
+			if (isset($this->current)) {
218
+				$this->props[] = $this->current;
219
+				unset($this->current);
220
+			}
221
+		}
222
+	}
223
+
224
+	/**
225
+	 * input data handler
226
+	 *
227
+	 * @param  resource  parser
228
+	 * @param  string    data
229
+	 * @return void
230
+	 * @access private
231
+	 */
232
+	function _data($parser, $data)
233
+	{
234
+		if (isset($this->current)) {
235
+			$this->current["val"] .= $data;
236
+		}
237
+	}
238 238
 }
239 239
 
240 240
 /*
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      * @param boolean $store_request =false if true whole request data will be made available in $this->request
98 98
      * @access public
99 99
      */
100
-    function __construct($path, $store_request=false)
100
+    function __construct($path, $store_request = false)
101 101
     {
102 102
         $this->success = true;
103 103
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
         xml_parser_set_option($xml_parser,
124 124
                               XML_OPTION_CASE_FOLDING, false);
125 125
 
126
-        while($this->success && !feof($f_in)) {
126
+        while ($this->success && !feof($f_in)) {
127 127
             $line = fgets($f_in);
128 128
             if ($store_request) $this->request .= $line;
129 129
             if (is_string($line)) {
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             }
133 133
         }
134 134
 
135
-        if($had_input) {
135
+        if ($had_input) {
136 136
             $this->success &= xml_parse($xml_parser, "", true);
137 137
         }
138 138
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
             $prop = array("name" => $tag);
170 170
             $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171 171
             if ($this->mode == "set") {
172
-                $this->current["val"] = "";     // default set val
172
+                $this->current["val"] = ""; // default set val
173 173
             }
174 174
         }
175 175
 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
             $this->current["val"] .= "<$tag";
178 178
             if (isset($attr)) {
179 179
                 foreach ($attr as $key => $val) {
180
-                    $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
180
+                    $this->current["val"] .= ' '.$key.'="'.str_replace('"', '&quot;', $val).'"';
181 181
                 }
182 182
             }
183 183
             $this->current["val"] .= ">";
Please login to merge, or discard this patch.
Braces   +48 added lines, -21 removed lines patch added patch discarded remove patch
@@ -106,7 +106,8 @@  discard block
 block discarded – undo
106 106
         $had_input = false;
107 107
 
108 108
         $f_in = fopen($path, "r");
109
-        if (!$f_in) {
109
+        if (!$f_in)
110
+        {
110 111
             $this->success = false;
111 112
             return;
112 113
         }
@@ -123,16 +124,22 @@  discard block
 block discarded – undo
123 124
         xml_parser_set_option($xml_parser,
124 125
                               XML_OPTION_CASE_FOLDING, false);
125 126
 
126
-        while($this->success && !feof($f_in)) {
127
+        while($this->success && !feof($f_in))
128
+        {
127 129
             $line = fgets($f_in);
128
-            if ($store_request) $this->request .= $line;
129
-            if (is_string($line)) {
130
+            if ($store_request)
131
+            {
132
+            	$this->request .= $line;
133
+            }
134
+            if (is_string($line))
135
+            {
130 136
                 $had_input = true;
131 137
                 $this->success &= xml_parse($xml_parser, $line, false);
132 138
             }
133 139
         }
134 140
 
135
-        if($had_input) {
141
+        if($had_input)
142
+        {
136 143
             $this->success &= xml_parse($xml_parser, "", true);
137 144
         }
138 145
 
@@ -152,31 +159,42 @@  discard block
 block discarded – undo
152 159
      */
153 160
     function _startElement($parser, $name, $attrs)
154 161
     {
155
-        if (strstr($name, " ")) {
162
+        if (strstr($name, " "))
163
+        {
156 164
             list($ns, $tag) = explode(" ", $name);
157 165
             if ($ns == "")
158
-                $this->success = false;
159
-        } else {
166
+            {
167
+                            $this->success = false;
168
+            }
169
+        }
170
+        else
171
+        {
160 172
             $ns = "";
161 173
             $tag = $name;
162 174
         }
163 175
 
164
-        if ($this->depth == 1) {
176
+        if ($this->depth == 1)
177
+        {
165 178
             $this->mode = $tag;
166 179
         }
167 180
 
168
-        if ($this->depth == 3) {
181
+        if ($this->depth == 3)
182
+        {
169 183
             $prop = array("name" => $tag);
170 184
             $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
171
-            if ($this->mode == "set") {
185
+            if ($this->mode == "set")
186
+            {
172 187
                 $this->current["val"] = "";     // default set val
173 188
             }
174 189
         }
175 190
 
176
-        if ($this->depth >= 4) {
191
+        if ($this->depth >= 4)
192
+        {
177 193
             $this->current["val"] .= "<$tag";
178
-            if (isset($attr)) {
179
-                foreach ($attr as $key => $val) {
194
+            if (isset($attr))
195
+            {
196
+                foreach ($attr as $key => $val)
197
+                {
180 198
                     $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
181 199
                 }
182 200
             }
@@ -198,23 +216,31 @@  discard block
 block discarded – undo
198 216
      */
199 217
     function _endElement($parser, $name)
200 218
     {
201
-        if (strstr($name, " ")) {
219
+        if (strstr($name, " "))
220
+        {
202 221
             list($ns, $tag) = explode(" ", $name);
203 222
             if ($ns == "")
204
-                $this->success = false;
205
-        } else {
223
+            {
224
+                            $this->success = false;
225
+            }
226
+        }
227
+        else
228
+        {
206 229
             $ns = "";
207 230
             $tag = $name;
208 231
         }
209 232
 
210 233
         $this->depth--;
211 234
 
212
-        if ($this->depth >= 4) {
235
+        if ($this->depth >= 4)
236
+        {
213 237
             $this->current["val"] .= "</$tag>";
214 238
         }
215 239
 
216
-        if ($this->depth == 3) {
217
-            if (isset($this->current)) {
240
+        if ($this->depth == 3)
241
+        {
242
+            if (isset($this->current))
243
+            {
218 244
                 $this->props[] = $this->current;
219 245
                 unset($this->current);
220 246
             }
@@ -231,7 +257,8 @@  discard block
 block discarded – undo
231 257
      */
232 258
     function _data($parser, $data)
233 259
     {
234
-        if (isset($this->current)) {
260
+        if (isset($this->current))
261
+        {
235 262
             $this->current["val"] .= $data;
236 263
         }
237 264
     }
Please login to merge, or discard this patch.