Completed
Push — 17.1 ( 8c3b94...29ee37 )
by Ralf
20:39 queued 11:58
created
api/src/Vfs/Hooks.php 3 patches
Doc Comments   -15 removed lines patch added patch discarded remove patch
@@ -37,8 +37,6 @@  discard block
 block discarded – undo
37 37
 	 * Hook called after new accounts have been added
38 38
 	 *
39 39
 	 * @param array $data
40
-	 * @param int $data['account_id'] numerical id
41
-	 * @param string $data['account_lid'] account-name
42 40
 	 */
43 41
 	static function addAccount($data)
44 42
 	{
@@ -58,9 +56,6 @@  discard block
 block discarded – undo
58 56
 	 * Hook called after accounts has been modified
59 57
 	 *
60 58
 	 * @param array $data
61
-	 * @param int $data['account_id'] numerical id
62
-	 * @param string $data['account_lid'] new account-name
63
-	 * @param string $data['old_loginid'] old account-name
64 59
 	 */
65 60
 	static function editAccount($data)
66 61
 	{
@@ -79,9 +74,6 @@  discard block
 block discarded – undo
79 74
 	 * Hook called before an account get deleted
80 75
 	 *
81 76
 	 * @param array $data
82
-	 * @param int $data['account_id'] numerical id
83
-	 * @param string $data['account_lid'] account-name
84
-	 * @param int $data['new_owner'] account-id of new owner, or false if data should get deleted
85 77
 	 */
86 78
 	static function deleteAccount($data)
87 79
 	{
@@ -114,8 +106,6 @@  discard block
 block discarded – undo
114 106
 	 * Hook called after new groups have been added
115 107
 	 *
116 108
 	 * @param array $data
117
-	 * @param int $data['account_id'] numerical id
118
-	 * @param string $data['account_lid'] group-name
119 109
 	 */
120 110
 	static function addGroup($data)
121 111
 	{
@@ -140,9 +130,6 @@  discard block
 block discarded – undo
140 130
 	 * or if the group directory exists and creates it if not.
141 131
 	 *
142 132
 	 * @param array $data
143
-	 * @param int $data['account_id'] numerical id
144
-	 * @param string $data['account_lid'] new group-name
145
-	 * @param string $data['old_name'] old account-name
146 133
 	 */
147 134
 	static function editGroup($data)
148 135
 	{
@@ -170,8 +157,6 @@  discard block
 block discarded – undo
170 157
 	 * Hook called before a group get deleted
171 158
 	 *
172 159
 	 * @param array $data
173
-	 * @param int $data['account_id'] numerical id
174
-	 * @param string $data['account_lid'] account-name
175 160
 	 */
176 161
 	static function deleteGroup($data)
177 162
 	{
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
 		if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
46 46
 		// create a user-dir
47 47
 		Api\Vfs::$is_root = true;
48
-		if (Api\Vfs::file_exists($dir='/home/'.$data['account_lid']) || Api\Vfs::mkdir($dir, 0700, 0))
48
+		if (Api\Vfs::file_exists($dir = '/home/'.$data['account_lid']) || Api\Vfs::mkdir($dir, 0700, 0))
49 49
 		{
50
-			Api\Vfs::chown($dir,(int)$data['account_id']);
51
-			Api\Vfs::chgrp($dir,0);
52
-			Api\Vfs::chmod($dir,0700);	// only user has access
50
+			Api\Vfs::chown($dir, (int)$data['account_id']);
51
+			Api\Vfs::chgrp($dir, 0);
52
+			Api\Vfs::chmod($dir, 0700); // only user has access
53 53
 		}
54 54
 		Api\Vfs::$is_root = false;
55 55
 	}
@@ -67,11 +67,11 @@  discard block
 block discarded – undo
67 67
 		if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
68 68
 		if (empty($data['account_lid']) || empty($data['old_loginid']) || $data['account_lid'] == $data['old_loginid'])
69 69
 		{
70
-			return;	// nothing to do here
70
+			return; // nothing to do here
71 71
 		}
72 72
 		// rename the user-dir
73 73
 		Api\Vfs::$is_root = true;
74
-		Api\Vfs::rename('/home/'.$data['old_loginid'],'/home/'.$data['account_lid']);
74
+		Api\Vfs::rename('/home/'.$data['old_loginid'], '/home/'.$data['account_lid']);
75 75
 		Api\Vfs::$is_root = false;
76 76
 	}
77 77
 
@@ -90,15 +90,15 @@  discard block
 block discarded – undo
90 90
 		if ($data['new_owner'] && ($new_lid = $GLOBALS['egw']->accounts->id2name($data['new_owner'])))
91 91
 		{
92 92
 			// copy content of user-dir to new owner's user-dir as old-home-$name
93
-			for ($i=''; file_exists(Api\Vfs::PREFIX.($new_dir = '/home/'.$new_lid.'/old-home-'.$data['account_lid'].$i)); $i++)
93
+			for ($i = ''; file_exists(Api\Vfs::PREFIX.($new_dir = '/home/'.$new_lid.'/old-home-'.$data['account_lid'].$i)); $i++)
94 94
 			{
95 95
 
96 96
 			}
97
-			Api\Vfs::rename('/home/'.$data['account_lid'],$new_dir);
97
+			Api\Vfs::rename('/home/'.$data['account_lid'], $new_dir);
98 98
 			// make the new owner the owner of the dir and it's content
99 99
 			Api\Vfs::find($new_dir, array(), 'EGroupware\Api\Vfs::chown', $data['new_owner']);
100 100
 		}
101
-		elseif(!empty($data['account_lid']) && $data['account_lid'] != '/')
101
+		elseif (!empty($data['account_lid']) && $data['account_lid'] != '/')
102 102
 		{
103 103
 			// delete the user-directory
104 104
 			Api\Vfs::remove('/home/'.$data['account_lid']);
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
 
125 125
 		// create a group-dir
126 126
 		Api\Vfs::$is_root = true;
127
-		if (Api\Vfs::file_exists($dir='/home/'.$data['account_lid']) || Api\Vfs::mkdir($dir, 0070, 0))
127
+		if (Api\Vfs::file_exists($dir = '/home/'.$data['account_lid']) || Api\Vfs::mkdir($dir, 0070, 0))
128 128
 		{
129
-			Api\Vfs::chown($dir,0);
130
-			Api\Vfs::chgrp($dir,abs($data['account_id']));	// gid in Vfs is positiv!
131
-			Api\Vfs::chmod($dir,0070);	// only group has access
129
+			Api\Vfs::chown($dir, 0);
130
+			Api\Vfs::chgrp($dir, abs($data['account_id'])); // gid in Vfs is positiv!
131
+			Api\Vfs::chmod($dir, 0070); // only group has access
132 132
 		}
133 133
 		Api\Vfs::$is_root = false;
134 134
 	}
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 		{
162 162
 			// rename the group-dir
163 163
 			Api\Vfs::$is_root = true;
164
-			Api\Vfs::rename('/home/'.$data['old_name'],'/home/'.$data['account_lid']);
164
+			Api\Vfs::rename('/home/'.$data['old_name'], '/home/'.$data['account_lid']);
165 165
 			Api\Vfs::$is_root = false;
166 166
 		}
167 167
 	}
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	{
178 178
 		if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
179 179
 
180
-		if(empty($data['account_lid']) || $data['account_lid'] == '/')
180
+		if (empty($data['account_lid']) || $data['account_lid'] == '/')
181 181
 		{
182 182
 			throw new Api\Exception\AssertionFailed(__METHOD__.'('.array2string($data).') account_lid NOT set!');
183 183
 		}
Please login to merge, or discard this patch.
Braces   +32 added lines, -8 removed lines patch added patch discarded remove patch
@@ -42,7 +42,10 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	static function addAccount($data)
44 44
 	{
45
-		if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
45
+		if (self::LOG_LEVEL > 0)
46
+		{
47
+			error_log(__METHOD__.'('.array2string($data).')');
48
+		}
46 49
 		// create a user-dir
47 50
 		Api\Vfs::$is_root = true;
48 51
 		if (Api\Vfs::file_exists($dir='/home/'.$data['account_lid']) || Api\Vfs::mkdir($dir, 0700, 0))
@@ -64,7 +67,10 @@  discard block
 block discarded – undo
64 67
 	 */
65 68
 	static function editAccount($data)
66 69
 	{
67
-		if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
70
+		if (self::LOG_LEVEL > 0)
71
+		{
72
+			error_log(__METHOD__.'('.array2string($data).')');
73
+		}
68 74
 		if (empty($data['account_lid']) || empty($data['old_loginid']) || $data['account_lid'] == $data['old_loginid'])
69 75
 		{
70 76
 			return;	// nothing to do here
@@ -85,7 +91,10 @@  discard block
 block discarded – undo
85 91
 	 */
86 92
 	static function deleteAccount($data)
87 93
 	{
88
-		if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
94
+		if (self::LOG_LEVEL > 0)
95
+		{
96
+			error_log(__METHOD__.'('.array2string($data).')');
97
+		}
89 98
 		Api\Vfs::$is_root = true;
90 99
 		if ($data['new_owner'] && ($new_lid = $GLOBALS['egw']->accounts->id2name($data['new_owner'])))
91 100
 		{
@@ -119,8 +128,14 @@  discard block
 block discarded – undo
119 128
 	 */
120 129
 	static function addGroup($data)
121 130
 	{
122
-		if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
123
-		if (empty($data['account_lid'])) throw new Api\Exception\WrongParameter('account_lid must not be empty!');
131
+		if (self::LOG_LEVEL > 0)
132
+		{
133
+			error_log(__METHOD__.'('.array2string($data).')');
134
+		}
135
+		if (empty($data['account_lid']))
136
+		{
137
+			throw new Api\Exception\WrongParameter('account_lid must not be empty!');
138
+		}
124 139
 
125 140
 		// create a group-dir
126 141
 		Api\Vfs::$is_root = true;
@@ -146,8 +161,14 @@  discard block
 block discarded – undo
146 161
 	 */
147 162
 	static function editGroup($data)
148 163
 	{
149
-		if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
150
-		if (empty($data['account_lid']) || empty($data['old_name'])) throw new Api\Exception\WrongParameter('account_lid and old_name must not be empty!');
164
+		if (self::LOG_LEVEL > 0)
165
+		{
166
+			error_log(__METHOD__.'('.array2string($data).')');
167
+		}
168
+		if (empty($data['account_lid']) || empty($data['old_name']))
169
+		{
170
+			throw new Api\Exception\WrongParameter('account_lid and old_name must not be empty!');
171
+		}
151 172
 
152 173
 		if ($data['account_lid'] == $data['old_name'])
153 174
 		{
@@ -175,7 +196,10 @@  discard block
 block discarded – undo
175 196
 	 */
176 197
 	static function deleteGroup($data)
177 198
 	{
178
-		if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($data).')');
199
+		if (self::LOG_LEVEL > 0)
200
+		{
201
+			error_log(__METHOD__.'('.array2string($data).')');
202
+		}
179 203
 
180 204
 		if(empty($data['account_lid']) || $data['account_lid'] == '/')
181 205
 		{
Please login to merge, or discard this patch.
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.
Braces   +35 added lines, -10 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
 
@@ -200,7 +205,10 @@  discard block
 block discarded – undo
200 205
 				);
201 206
 			}
202 207
 		}
203
-		if (self::DEBUG) error_log(__METHOD__."('$url', $flags) calling parent::url_stat(,,".array2string($eacl_check).') returning '.array2string($ret));
208
+		if (self::DEBUG)
209
+		{
210
+			error_log(__METHOD__."('$url', $flags) calling parent::url_stat(,,".array2string($eacl_check).') returning '.array2string($ret));
211
+		}
204 212
 		return $ret;
205 213
 	}
206 214
 
@@ -258,20 +266,31 @@  discard block
 block discarded – undo
258 266
 
259 267
 		if($path[0] != '/')
260 268
 		{
261
-			if (strpos($path,'?') !== false) $query = Vfs::parse_url($path,PHP_URL_QUERY);
269
+			if (strpos($path,'?') !== false)
270
+			{
271
+				$query = Vfs::parse_url($path,PHP_URL_QUERY);
272
+			}
262 273
 			$path = Vfs::parse_url($path,PHP_URL_PATH).($query ? '?'.$query : '');
263 274
 		}
264 275
 		list(,$apps,$app,$id) = explode('/',$path);
265 276
 
266 277
 		$ret = false;
267
-		if ($apps == 'apps' && $app && !$id || self::check_extended_acl($path,Vfs::WRITABLE))	// app directory itself is allways ok
278
+		if ($apps == 'apps' && $app && !$id || self::check_extended_acl($path,Vfs::WRITABLE))
279
+		{
280
+			// app directory itself is allways ok
268 281
 		{
269
-			$current_is_root = Vfs::$is_root; Vfs::$is_root = true;
282
+			$current_is_root = Vfs::$is_root;
283
+		}
284
+		Vfs::$is_root = true;
270 285
 			$current_user = Vfs::$user; Vfs::$user = 0;
271 286
 
272 287
 			$sqlfs = new parent();
273 288
 			$ret = $sqlfs->mkdir($path,0,$options|STREAM_MKDIR_RECURSIVE);
274
-			if ($id) $sqlfs->chmod($path,0);	// no other rights
289
+			if ($id)
290
+			{
291
+				$sqlfs->chmod($path,0);
292
+			}
293
+			// no other rights
275 294
 
276 295
 			Vfs::$user = $current_user;
277 296
 			Vfs::$is_root = $current_is_root;
@@ -383,10 +402,13 @@  discard block
 block discarded – undo
383 402
 	 */
384 403
 	protected function touch($url,$time=null,$atime=null)
385 404
 	{
386
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$time,$atime)");
405
+		if (self::LOG_LEVEL > 1)
406
+		{
407
+			error_log(__METHOD__."($url,$time,$atime)");
408
+		}
387 409
 
388 410
  		if (!($stat = $this->url_stat($url,STREAM_URL_STAT_QUIET)))
389
-		{
411
+ 		{
390 412
 			// file does not exist --> create an empty one
391 413
 			if (!($f = fopen(self::SCHEME.'://default'.Vfs::parse_url($url,PHP_URL_PATH),'w')) || !fclose($f))
392 414
 			{
@@ -408,7 +430,10 @@  discard block
 block discarded – undo
408 430
 	 */
409 431
 	function rename ( $path_from, $path_to )
410 432
 	{
411
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path_from,$path_to)");
433
+		if (self::LOG_LEVEL > 1)
434
+		{
435
+			error_log(__METHOD__."($path_from,$path_to)");
436
+		}
412 437
 
413 438
 		// Check to make sure target _really_ exists, not just fake dir from Links/StreamWrapper
414 439
 		$path = Vfs::parse_url($path_to, PHP_URL_PATH);
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 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) = array_pad(explode('/',$path,5), 5, null);
87
+		list(,$apps, $app, $id, $rel_path) = array_pad(explode('/', $path, 5), 5, null);
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 99
 		elseif (!self::check_app_rights($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
 
@@ -157,19 +157,19 @@  discard block
 block discarded – undo
157 157
 	 *                          stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper!
158 158
 	 * @return array
159 159
 	 */
160
-	function url_stat ( $url, $flags )
160
+	function url_stat($url, $flags)
161 161
 	{
162
-		$eacl_check=self::check_extended_acl($url,Vfs::READABLE);
162
+		$eacl_check = self::check_extended_acl($url, Vfs::READABLE);
163 163
 
164 164
 		// return vCard as /.entry
165
-		if ( $eacl_check && substr($url,-7) == '/.entry' &&
166
-			(list($app) = array_slice(explode('/',$url),-3,1)) && $app === 'addressbook')
165
+		if ($eacl_check && substr($url, -7) == '/.entry' &&
166
+			(list($app) = array_slice(explode('/', $url), -3, 1)) && $app === 'addressbook')
167 167
 		{
168 168
 			$ret = array(
169 169
 				'ino'   => '#'.md5($url),
170 170
 				'name'  => '.entry',
171
-				'mode'  => self::MODE_FILE|Vfs::READABLE,	// required by the stream wrapper
172
-				'size'  => 1024,	// fmail does NOT attach files with size 0!
171
+				'mode'  => self::MODE_FILE|Vfs::READABLE, // required by the stream wrapper
172
+				'size'  => 1024, // fmail does NOT attach files with size 0!
173 173
 				'uid'   => 0,
174 174
 				'gid'   => 0,
175 175
 				'mtime' => time(),
@@ -180,15 +180,15 @@  discard block
 block discarded – undo
180 180
 			);
181 181
 		}
182 182
 		// if entry directory does not exist --> return fake directory
183
-		elseif (!($ret = parent::url_stat($url,$flags)) && $eacl_check)
183
+		elseif (!($ret = parent::url_stat($url, $flags)) && $eacl_check)
184 184
 		{
185
-			list(,/*$apps*/,/*$app*/,$id,$rel_path) = array_pad(explode('/', Vfs::parse_url($url, PHP_URL_PATH), 5),5,null);
185
+			list(,/*$apps*/, /*$app*/, $id, $rel_path) = array_pad(explode('/', Vfs::parse_url($url, PHP_URL_PATH), 5), 5, null);
186 186
 			if ($id && !isset($rel_path))
187 187
 			{
188 188
 				$ret = array(
189 189
 					'ino'   => '#'.md5($url),
190 190
 					'name'  => $id,
191
-					'mode'  => self::MODE_DIR,	// required by the stream wrapper
191
+					'mode'  => self::MODE_DIR, // required by the stream wrapper
192 192
 					'size'  => 0,
193 193
 					'uid'   => 0,
194 194
 					'gid'   => 0,
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
 	 * @param int $fs_id =null fs_id to use, to not query it again (eg. because it's already deleted)
216 216
 	 * @return boolean true if acl is set/deleted, false on error
217 217
 	 */
218
-	static function eacl($path,$rights=null,$owner=null,$fs_id=null)
218
+	static function eacl($path, $rights = null, $owner = null, $fs_id = null)
219 219
 	{
220
-		unset($path, $rights, $owner, $fs_id);	// not used, but required by function signature
220
+		unset($path, $rights, $owner, $fs_id); // not used, but required by function signature
221 221
 
222 222
 		return false;
223 223
 	}
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	 */
233 233
 	static function get_eacl($path)
234 234
 	{
235
-		unset($path);	// not used, but required by function signature
235
+		unset($path); // not used, but required by function signature
236 236
 
237 237
 		return false;
238 238
 	}
@@ -252,26 +252,26 @@  discard block
 block discarded – undo
252 252
 	 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE, we allways use recursive!
253 253
 	 * @return boolean TRUE on success or FALSE on failure
254 254
 	 */
255
-	function mkdir($path,$mode,$options)
255
+	function mkdir($path, $mode, $options)
256 256
 	{
257
-		unset($mode);	// not used, but required by function signature
257
+		unset($mode); // not used, but required by function signature
258 258
 
259
-		if($path[0] != '/')
259
+		if ($path[0] != '/')
260 260
 		{
261
-			if (strpos($path,'?') !== false) $query = Vfs::parse_url($path,PHP_URL_QUERY);
262
-			$path = Vfs::parse_url($path,PHP_URL_PATH).($query ? '?'.$query : '');
261
+			if (strpos($path, '?') !== false) $query = Vfs::parse_url($path, PHP_URL_QUERY);
262
+			$path = Vfs::parse_url($path, PHP_URL_PATH).($query ? '?'.$query : '');
263 263
 		}
264
-		list(,$apps,$app,$id) = explode('/',$path);
264
+		list(,$apps, $app, $id) = explode('/', $path);
265 265
 
266 266
 		$ret = false;
267
-		if ($apps == 'apps' && $app && !$id || self::check_extended_acl($path,Vfs::WRITABLE))	// app directory itself is allways ok
267
+		if ($apps == 'apps' && $app && !$id || self::check_extended_acl($path, Vfs::WRITABLE))	// app directory itself is allways ok
268 268
 		{
269 269
 			$current_is_root = Vfs::$is_root; Vfs::$is_root = true;
270 270
 			$current_user = Vfs::$user; Vfs::$user = 0;
271 271
 
272 272
 			$sqlfs = new parent();
273
-			$ret = $sqlfs->mkdir($path,0,$options|STREAM_MKDIR_RECURSIVE);
274
-			if ($id) $sqlfs->chmod($path,0);	// no other rights
273
+			$ret = $sqlfs->mkdir($path, 0, $options|STREAM_MKDIR_RECURSIVE);
274
+			if ($id) $sqlfs->chmod($path, 0); // no other rights
275 275
 
276 276
 			Vfs::$user = $current_user;
277 277
 			Vfs::$is_root = $current_is_root;
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
 	 * @param int $options Possible values include STREAM_REPORT_ERRORS.
291 291
 	 * @return boolean TRUE on success or FALSE on failure.
292 292
 	 */
293
-	function rmdir ( $url, $options )
293
+	function rmdir($url, $options)
294 294
 	{
295
-		$path = $url != '/' ? Vfs::parse_url($url,PHP_URL_PATH) : $url;
295
+		$path = $url != '/' ? Vfs::parse_url($url, PHP_URL_PATH) : $url;
296 296
 
297
-		list(,/*$apps*/,/*$app*/,/*$id*/,$rest) = explode('/',$path);
297
+		list(,/*$apps*/, /*$app*/, /*$id*/, $rest) = explode('/', $path);
298 298
 
299 299
 		// never delete entry-dir, as it makes attic inaccessible
300 300
 		if (empty($rest))
301 301
 		{
302 302
 			return true;
303 303
 		}
304
-		return parent::rmdir( $path, $options );
304
+		return parent::rmdir($path, $options);
305 305
 	}
306 306
 
307 307
 	/**
@@ -319,23 +319,23 @@  discard block
 block discarded – undo
319 319
 	 * @param string $opened_path full path of the file/resource, if the open was successfull and STREAM_USE_PATH was set
320 320
 	 * @return boolean true if the ressource was opened successful, otherwise false
321 321
 	 */
322
-	function stream_open ( $url, $mode, $options, &$opened_path )
322
+	function stream_open($url, $mode, $options, &$opened_path)
323 323
 	{
324 324
 		// the following call is necessary to fill sqlfs_stream_wrapper::$stat_cache, WITH the extendes ACL!
325
-		$stat = $this->url_stat($url,0);
325
+		$stat = $this->url_stat($url, 0);
326 326
 		//error_log(__METHOD__."('$url', '$mode', $options) stat=".array2string($stat));
327 327
 
328 328
 		// return vCard as /.entry
329
-		if ($stat && $mode[0] == 'r' && substr($url,-7) === '/.entry' &&
330
-			(list($app) = array_slice(explode('/',$url),-3,1)) && $app === 'addressbook')
329
+		if ($stat && $mode[0] == 'r' && substr($url, -7) === '/.entry' &&
330
+			(list($app) = array_slice(explode('/', $url), -3, 1)) && $app === 'addressbook')
331 331
 		{
332
-			list($id) = array_slice(explode('/',$url),-2,1);
333
-			$ab_vcard = new addressbook_vcal('addressbook','text/vcard');
332
+			list($id) = array_slice(explode('/', $url), -2, 1);
333
+			$ab_vcard = new addressbook_vcal('addressbook', 'text/vcard');
334 334
 			if (!($charset = $GLOBALS['egw_info']['user']['preferences']['addressbook']['vcard_charset']))
335 335
 			{
336 336
 				$charset = 'utf-8';
337 337
 			}
338
-			if (!($vcard =& $ab_vcard->getVCard($id, $charset)))
338
+			if (!($vcard = & $ab_vcard->getVCard($id, $charset)))
339 339
 			{
340 340
 				error_log(__METHOD__."('$url', '$mode', $options) addressbook_vcal::getVCard($id) returned false!");
341 341
 				return false;
@@ -350,9 +350,9 @@  discard block
 block discarded – undo
350 350
 		if ($mode[0] != 'r' && ($dir = Vfs::dirname($url)) &&
351 351
 			!parent::url_stat($dir, 0) && self::check_extended_acl($dir, Vfs::WRITABLE))
352 352
 		{
353
-			$this->mkdir($dir,0,STREAM_MKDIR_RECURSIVE);
353
+			$this->mkdir($dir, 0, STREAM_MKDIR_RECURSIVE);
354 354
 		}
355
-		return parent::stream_open($url,$mode,$options,$opened_path);
355
+		return parent::stream_open($url, $mode, $options, $opened_path);
356 356
 	}
357 357
 
358 358
 	/**
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 	 * @param $options
365 365
 	 * @return booelan
366 366
 	 */
367
-	function dir_opendir ( $url, $options )
367
+	function dir_opendir($url, $options)
368 368
 	{
369 369
 		if (!parent::url_stat($url, STREAM_URL_STAT_QUIET) && $this->url_stat($url, STREAM_URL_STAT_QUIET))
370 370
 		{
@@ -381,20 +381,20 @@  discard block
 block discarded – undo
381 381
 	 * @param int $time =null modification time (unix timestamp), default null = current time
382 382
 	 * @param int $atime =null access time (unix timestamp), default null = current time, not implemented in the vfs!
383 383
 	 */
384
-	protected function touch($url,$time=null,$atime=null)
384
+	protected function touch($url, $time = null, $atime = null)
385 385
 	{
386 386
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($url,$time,$atime)");
387 387
 
388
- 		if (!($stat = $this->url_stat($url,STREAM_URL_STAT_QUIET)))
388
+ 		if (!($stat = $this->url_stat($url, STREAM_URL_STAT_QUIET)))
389 389
 		{
390 390
 			// file does not exist --> create an empty one
391
-			if (!($f = fopen(self::SCHEME.'://default'.Vfs::parse_url($url,PHP_URL_PATH),'w')) || !fclose($f))
391
+			if (!($f = fopen(self::SCHEME.'://default'.Vfs::parse_url($url, PHP_URL_PATH), 'w')) || !fclose($f))
392 392
 			{
393 393
 				return false;
394 394
 			}
395 395
 		}
396 396
 
397
-		return is_null($time) ? true : parent::touch($url,$time,$atime);
397
+		return is_null($time) ? true : parent::touch($url, $time, $atime);
398 398
 	}
399 399
 
400 400
 	/**
@@ -406,20 +406,20 @@  discard block
 block discarded – undo
406 406
 	 * @param string $path_to
407 407
 	 * @return boolean TRUE on success or FALSE on failure
408 408
 	 */
409
-	function rename ( $path_from, $path_to )
409
+	function rename($path_from, $path_to)
410 410
 	{
411 411
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path_from,$path_to)");
412 412
 
413 413
 		// Check to make sure target _really_ exists, not just fake dir from Links/StreamWrapper
414 414
 		$path = Vfs::parse_url($path_to, PHP_URL_PATH);
415
-		list(,/*$apps*/,/*$app*/,$id) = explode('/', $path);
415
+		list(,/*$apps*/, /*$app*/, $id) = explode('/', $path);
416 416
 
417
-		if($id && !parent::url_stat(Vfs::dirname($path_to),STREAM_URL_STAT_QUIET))
417
+		if ($id && !parent::url_stat(Vfs::dirname($path_to), STREAM_URL_STAT_QUIET))
418 418
 		{
419
-			$this->mkdir(Vfs::dirname($path), 0, STREAM_MKDIR_RECURSIVE );
419
+			$this->mkdir(Vfs::dirname($path), 0, STREAM_MKDIR_RECURSIVE);
420 420
 		}
421 421
 
422
-		return parent::rename($path_from,$path_to);
422
+		return parent::rename($path_from, $path_to);
423 423
 	}
424 424
 
425 425
 	/**
@@ -431,14 +431,14 @@  discard block
 block discarded – undo
431 431
 	 * @param string $link
432 432
 	 * @return boolean true on success false on error
433 433
 	 */
434
-	static function symlink($target,$link)
434
+	static function symlink($target, $link)
435 435
 	{
436 436
 		$parent = new \EGroupware\Api\Vfs\Links\LinksParent();
437
-		if (!$parent->url_stat($dir = Vfs::dirname($link),0) && self::check_extended_acl($dir,Vfs::WRITABLE))
437
+		if (!$parent->url_stat($dir = Vfs::dirname($link), 0) && self::check_extended_acl($dir, Vfs::WRITABLE))
438 438
 		{
439
-			$parent->mkdir($dir,0,STREAM_MKDIR_RECURSIVE);
439
+			$parent->mkdir($dir, 0, STREAM_MKDIR_RECURSIVE);
440 440
 		}
441
-		return parent::symlink($target,$link);
441
+		return parent::symlink($target, $link);
442 442
 	}
443 443
 
444 444
 	/**
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   +33 added lines, -34 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         // of the request URI ourselves
119 119
         // if request URI contains a full url, remove schema and domain
120 120
 		$matches = null;
121
-        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info=$_SERVER['REQUEST_URI'], $matches))
121
+        if (preg_match('|^https?://[^/]+(/.*)$|', $path_info = $_SERVER['REQUEST_URI'], $matches))
122 122
         {
123 123
         	$path_info = $matches[1];
124 124
         }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	 * @param boolean $keep_session =null null: create a new session, true: try mounting it into existing (already verified) session
157 157
 	 * @return string with sessionid, does NOT return if no session created
158 158
 	 */
159
-	public static function create_session($keep_session=null)
159
+	public static function create_session($keep_session = null)
160 160
 	{
161 161
 		self::$db = $GLOBALS['egw']->db;
162 162
 
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
 		// need to reset fs_tab, as resolve_url does NOT work with just share mounted
210 210
 		if (count($GLOBALS['egw_info']['server']['vfs_fstab']) <= 1)
211 211
 		{
212
-			unset($GLOBALS['egw_info']['server']['vfs_fstab']);	// triggers reset of fstab in mount()
212
+			unset($GLOBALS['egw_info']['server']['vfs_fstab']); // triggers reset of fstab in mount()
213 213
 			$GLOBALS['egw_info']['server']['vfs_fstab'] = Vfs::mount();
214 214
 			Vfs::clearstatcache();
215 215
 		}
216
-		$share['resolve_url'] = Vfs::resolve_url($share['share_path'], true, true, true, true);	// true = fix evtl. contained url parameter
216
+		$share['resolve_url'] = Vfs::resolve_url($share['share_path'], true, true, true, true); // true = fix evtl. contained url parameter
217 217
 		// if share not writable append ro=1 to mount url to make it readonly
218
-		if (!($share['share_writable'] & 1))
218
+		if (!($share['share_writable']&1))
219 219
 		{
220 220
 			$share['resolve_url'] .= (strpos($share['resolve_url'], '?') ? '&' : '?').'ro=1';
221 221
 		}
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
 
244 244
 			// Need to re-init stream wrapper, as some of them look at
245 245
 			// preferences or permissions
246
-			$scheme = Vfs\StreamWrapper::scheme2class(Vfs::parse_url($share['resolve_url'],PHP_URL_SCHEME));
247
-			if($scheme && method_exists($scheme, 'init_static'))
246
+			$scheme = Vfs\StreamWrapper::scheme2class(Vfs::parse_url($share['resolve_url'], PHP_URL_SCHEME));
247
+			if ($scheme && method_exists($scheme, 'init_static'))
248 248
 			{
249 249
 				$scheme::init_static();
250 250
 			}
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 
269 269
 		// update accessed timestamp
270 270
 		self::$db->update(self::TABLE, array(
271
-			'share_last_accessed' => $share['share_last_accessed']=time(),
271
+			'share_last_accessed' => $share['share_last_accessed'] = time(),
272 272
 		), array(
273 273
 			'share_id' => $share['share_id'],
274 274
 		), __LINE__, __FILE__);
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		if ($keep_session || $sessionid)
317 317
 		{
318 318
 			$_SESSION[Api\Session::EGW_INFO_CACHE] = $GLOBALS['egw_info'];
319
-			unset($_SESSION[Api\Session::EGW_INFO_CACHE]['flags']);	// dont save the flags, they change on each request
319
+			unset($_SESSION[Api\Session::EGW_INFO_CACHE]['flags']); // dont save the flags, they change on each request
320 320
 
321 321
 			$_SESSION[Api\Session::EGW_OBJECT_CACHE] = serialize($GLOBALS['egw']);
322 322
 		}
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 		}
355 355
 
356 356
 		// No extended ACL for readonly shares, disable eacl by setting session cache
357
-		if(!($this->share['share_writable'] & 1))
357
+		if (!($this->share['share_writable']&1))
358 358
 		{
359 359
 			Api\Cache::setSession(Api\Vfs\Sqlfs\StreamWrapper::EACL_APPNAME, 'extended_acl', array(
360 360
 				'/' => 1,
@@ -394,8 +394,7 @@  discard block
 block discarded – undo
394 394
 		// generate random token (using oppenssl if available otherwise mt_rand based Api\Auth::randomstring)
395 395
 		do {
396 396
 			$token = function_exists('openssl_random_pseudo_bytes') ?
397
-				base64_encode(openssl_random_pseudo_bytes(3*self::TOKEN_LENGTH/4)) :
398
-				Api\Auth::randomstring(self::TOKEN_LENGTH);
397
+				base64_encode(openssl_random_pseudo_bytes(3 * self::TOKEN_LENGTH / 4)) : Api\Auth::randomstring(self::TOKEN_LENGTH);
399 398
 			// base64 can contain chars not allowed in our vfs-urls eg. / or #
400 399
 		} while ($token != urlencode($token));
401 400
 
@@ -420,13 +419,13 @@  discard block
 block discarded – undo
420 419
 	 * @throw Api\Exception\AssertionFailed if user temp. directory does not exist and can not be created
421 420
 	 * @return array with share data, eg. value for key 'share_token'
422 421
 	 */
423
-	public static function create($path, $mode, $name, $recipients, $extra=array())
422
+	public static function create($path, $mode, $name, $recipients, $extra = array())
424 423
 	{
425 424
 		if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
426 425
 
427 426
 		if (empty($name)) $name = $path;
428 427
 
429
-		$path2tmp =& Api\Cache::getSession(__CLASS__, 'path2tmp');
428
+		$path2tmp = & Api\Cache::getSession(__CLASS__, 'path2tmp');
430 429
 
431 430
 		// allow filesystem path only for temp_dir
432 431
 		$temp_dir = $GLOBALS['egw_info']['server']['temp_dir'].'/';
@@ -437,7 +436,7 @@  discard block
 block discarded – undo
437 436
 		}
438 437
 		else
439 438
 		{
440
-			if(parse_url($path, PHP_URL_SCHEME) !== 'vfs')
439
+			if (parse_url($path, PHP_URL_SCHEME) !== 'vfs')
441 440
 			{
442 441
 				$path = 'vfs://default'.($path[0] == '/' ? '' : '/').$path;
443 442
 			}
@@ -454,7 +453,7 @@  discard block
 block discarded – undo
454 453
 		}
455 454
 		// check if file has been shared before, with identical attributes
456 455
 		if (($mode != self::LINK || isset($path2tmp[$path])) &&
457
-			($share = self::$db->select(self::TABLE, '*', $extra+array(
456
+			($share = self::$db->select(self::TABLE, '*', $extra + array(
458 457
 				'share_path' => $mode == 'link' ? $path2tmp[$path] : $vfs_path,
459 458
 				'share_owner' => Vfs::$user,
460 459
 				'share_expires' => null,
@@ -465,7 +464,7 @@  discard block
 block discarded – undo
465 464
 			// if yes, just add additional recipients
466 465
 			$share['share_with'] = $share['share_with'] ? explode(',', $share['share_with']) : array();
467 466
 			$need_save = false;
468
-			foreach((array)$recipients as $recipient)
467
+			foreach ((array)$recipients as $recipient)
469 468
 			{
470 469
 				if (!in_array($recipient, $share['share_with']))
471 470
 				{
@@ -495,9 +494,9 @@  discard block
 block discarded – undo
495 494
 				}
496 495
 				$n = 0;
497 496
 				do {
498
-					$tmp_file = Vfs::concat($user_tmp, ($n?$n.'.':'').Vfs::basename($name));
497
+					$tmp_file = Vfs::concat($user_tmp, ($n ? $n.'.' : '').Vfs::basename($name));
499 498
 				}
500
-				while(!(is_dir($path) && Vfs::mkdir($tmp_file, null, STREAM_MKDIR_RECURSIVE) ||
499
+				while (!(is_dir($path) && Vfs::mkdir($tmp_file, null, STREAM_MKDIR_RECURSIVE) ||
501 500
 					!is_dir($path) && (!Vfs::file_exists($tmp_file) && ($fp = Vfs::fopen($tmp_file, 'x')) ||
502 501
 						// do not copy identical files again to users tmp dir, just re-use them
503 502
 						Vfs::file_exists($tmp_file) && Vfs::compare(Vfs::PREFIX.$tmp_file, $path))) && $n++ < 100);
@@ -520,7 +519,7 @@  discard block
 block discarded – undo
520 519
 			}
521 520
 
522 521
 			$i = 0;
523
-			while(true)	// self::token() can return an existing value
522
+			while (true)	// self::token() can return an existing value
524 523
 			{
525 524
 				try {
526 525
 					self::$db->insert(self::TABLE, $share = array(
@@ -529,12 +528,12 @@  discard block
 block discarded – undo
529 528
 						'share_owner' => Vfs::$user,
530 529
 						'share_with' => implode(',', (array)$recipients),
531 530
 						'share_created' => time(),
532
-					)+$extra, false, __LINE__, __FILE__);
531
+					) + $extra, false, __LINE__, __FILE__);
533 532
 
534 533
 					$share['share_id'] = self::$db->get_last_insert_id(self::TABLE, 'share_id');
535 534
 					break;
536 535
 				}
537
-				catch(Api\Db\Exception $e) {
536
+				catch (Api\Db\Exception $e) {
538 537
 					if ($i++ > 3) throw $e;
539 538
 					unset($e);
540 539
 				}
@@ -545,9 +544,9 @@  discard block
 block discarded – undo
545 544
 		$async = new Api\Asyncservice();
546 545
 		if (!($job = $async->read(self::ASYNC_JOB_ID)) || $job[self::ASYNC_JOB_ID]['method'] === 'egw_sharing::tmp_cleanup')
547 546
 		{
548
-			if ($job) $async->delete(self::ASYNC_JOB_ID);	// update not working old class-name
547
+			if ($job) $async->delete(self::ASYNC_JOB_ID); // update not working old class-name
549 548
 
550
-			$async->set_timer(array('day' => 28), self::ASYNC_JOB_ID, 'EGroupware\\Api\\Vfs\\Sharing::tmp_cleanup',null);
549
+			$async->set_timer(array('day' => 28), self::ASYNC_JOB_ID, 'EGroupware\\Api\\Vfs\\Sharing::tmp_cleanup', null);
551 550
 		}
552 551
 
553 552
 		return $share;
@@ -587,8 +586,8 @@  discard block
 block discarded – undo
587 586
 
588 587
 		// get all temp. files, to be able to delete them
589 588
 		$tmp_paths = array();
590
-		foreach(self::$db->select(self::TABLE, 'share_path', array(
591
-			"share_path LIKE '/home/%/.tmp/%'")+$keys, __LINE__, __FILE__, false) as $row)
589
+		foreach (self::$db->select(self::TABLE, 'share_path', array(
590
+			"share_path LIKE '/home/%/.tmp/%'") + $keys, __LINE__, __FILE__, false) as $row)
592 591
 		{
593 592
 			$tmp_paths[] = $row['share_path'];
594 593
 		}
@@ -600,7 +599,7 @@  discard block
 block discarded – undo
600 599
 		// check if temp. files are used elsewhere
601 600
 		if ($tmp_paths)
602 601
 		{
603
-			foreach(self::$db->select(self::TABLE, 'share_path,COUNT(*) AS cnt', array(
602
+			foreach (self::$db->select(self::TABLE, 'share_path,COUNT(*) AS cnt', array(
604 603
 				'share_path' => $tmp_paths,
605 604
 			), __LINE__, __FILE__, false, 'GROUP BY share_path') as $row)
606 605
 			{
@@ -610,7 +609,7 @@  discard block
 block discarded – undo
610 609
 				}
611 610
 			}
612 611
 			// if not delete them
613
-			foreach($tmp_paths as $path)
612
+			foreach ($tmp_paths as $path)
614 613
 			{
615 614
 				Vfs::remove($path);
616 615
 			}
@@ -648,11 +647,11 @@  discard block
 block discarded – undo
648 647
 			// remove expired tmp-files unconditionally
649 648
 			$having = 'HAVING MAX(share_expires) < '.self::$db->quote(self::$db->to_timestamp(time())).' OR '.
650 649
 				// remove without expiration date, when created over 100 days ago AND
651
-				'MAX(share_expires) IS NULL AND MAX(share_created) < '.self::$db->quote(self::$db->to_timestamp(time()-self::TMP_KEEP)). ' AND '.
650
+				'MAX(share_expires) IS NULL AND MAX(share_created) < '.self::$db->quote(self::$db->to_timestamp(time() - self::TMP_KEEP)).' AND '.
652 651
 					// (last accessed over 100 days ago OR never)
653
-					'(MAX(share_last_accessed) IS NULL OR MAX(share_last_accessed) < '.self::$db->quote(self::$db->to_timestamp(time()-self::TMP_KEEP)).')';
652
+					'(MAX(share_last_accessed) IS NULL OR MAX(share_last_accessed) < '.self::$db->quote(self::$db->to_timestamp(time() - self::TMP_KEEP)).')';
654 653
 
655
-			foreach(self::$db->select(self::TABLE, $cols, array(
654
+			foreach (self::$db->select(self::TABLE, $cols, array(
656 655
 				"share_path LIKE '/home/%/.tmp/%'",
657 656
 			), __LINE__, __FILE__, false, 'GROUP BY share_path '.$having) as $row)
658 657
 			{
@@ -665,7 +664,7 @@  discard block
 block discarded – undo
665 664
 				else
666 665
 				{
667 666
 					$share_ids = array();
668
-					foreach(self::$db->selec(self::TABLE, 'share_id', array(
667
+					foreach (self::$db->selec(self::TABLE, 'share_id', array(
669 668
 						'share_path' => $row['share_path'],
670 669
 					), __LINE__, __FILE__) as $id)
671 670
 					{
@@ -732,11 +731,11 @@  discard block
 block discarded – undo
732 731
 		{
733 732
 			$actions = parent::get_actions();
734 733
 			$group = 1;
735
-			if(Vfs::is_writable($GLOBALS['egw']->sharing->get_root()))
734
+			if (Vfs::is_writable($GLOBALS['egw']->sharing->get_root()))
736 735
 			{
737 736
 				return $actions;
738 737
 			}
739
-			$actions+= array(
738
+			$actions += array(
740 739
 				'egw_copy' => array(
741 740
 					'enabled' => false,
742 741
 					'group' => $group + 0.5,
Please login to merge, or discard this patch.
Braces   +53 added lines, -13 removed lines patch added patch discarded remove patch
@@ -167,7 +167,10 @@  discard block
 block discarded – undo
167 167
 		if ($token && !$keep_session)
168 168
 		{
169 169
 			$_SERVER['PHP_AUTH_USER'] = $token;
170
-			if (!isset($_SERVER['PHP_AUTH_PW'])) $_SERVER['PHP_AUTH_PW'] = '';
170
+			if (!isset($_SERVER['PHP_AUTH_PW']))
171
+			{
172
+				$_SERVER['PHP_AUTH_PW'] = '';
173
+			}
171 174
 
172 175
 			unset($GLOBALS['egw_info']['flags']['autocreate_session_callback']);
173 176
 			if (isset($GLOBALS['egw']->session) && $GLOBALS['egw']->session->verify()
@@ -221,9 +224,12 @@  discard block
 block discarded – undo
221 224
 		}
222 225
 		//_debug_array($share);
223 226
 
224
-		if ($keep_session)	// add share to existing session
227
+		if ($keep_session)
228
+		{
229
+			// add share to existing session
225 230
 		{
226 231
 			$share['share_root'] = '/'.$share['share_token'];
232
+		}
227 233
 
228 234
 			// if current user is not the share owner, we cant just mount share
229 235
 			if (Vfs::$user != $share['share_owner'])
@@ -231,12 +237,15 @@  discard block
 block discarded – undo
231 237
 				$keep_session = false;
232 238
 			}
233 239
 		}
234
-		if (!$keep_session)	// do NOT change to else, as we might have set $keep_session=false!
240
+		if (!$keep_session)
241
+		{
242
+			// do NOT change to else, as we might have set $keep_session=false!
235 243
 		{
236 244
 			// only allow filemanager app
237 245
 			$GLOBALS['egw_info']['user']['apps'] = array(
238 246
 				'filemanager' => $GLOBALS['egw_info']['apps']['filemanager']
239 247
 			);
248
+		}
240 249
 
241 250
 			$share['share_root'] = '/';
242 251
 			Vfs::$user = $share['share_owner'];
@@ -422,9 +431,15 @@  discard block
 block discarded – undo
422 431
 	 */
423 432
 	public static function create($path, $mode, $name, $recipients, $extra=array())
424 433
 	{
425
-		if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
434
+		if (!isset(self::$db))
435
+		{
436
+			self::$db = $GLOBALS['egw']->db;
437
+		}
426 438
 
427
-		if (empty($name)) $name = $path;
439
+		if (empty($name))
440
+		{
441
+			$name = $path;
442
+		}
428 443
 
429 444
 		$path2tmp =& Api\Cache::getSession(__CLASS__, 'path2tmp');
430 445
 
@@ -506,7 +521,10 @@  discard block
 block discarded – undo
506 521
 				{
507 522
 					throw new Api\Exception\AssertionFailed("Could NOT create temp. file '$tmp_file'!");
508 523
 				}
509
-				if ($fp) fclose($fp);
524
+				if ($fp)
525
+				{
526
+					fclose($fp);
527
+				}
510 528
 
511 529
 				if (is_dir($path) && !Vfs::copy_files(array($path), $tmp_file) ||
512 530
 					!is_dir($path) && !copy($path, Vfs::PREFIX.$tmp_file))
@@ -520,7 +538,9 @@  discard block
 block discarded – undo
520 538
 			}
521 539
 
522 540
 			$i = 0;
523
-			while(true)	// self::token() can return an existing value
541
+			while(true)
542
+			{
543
+				// self::token() can return an existing value
524 544
 			{
525 545
 				try {
526 546
 					self::$db->insert(self::TABLE, $share = array(
@@ -530,12 +550,16 @@  discard block
 block discarded – undo
530 550
 						'share_with' => implode(',', (array)$recipients),
531 551
 						'share_created' => time(),
532 552
 					)+$extra, false, __LINE__, __FILE__);
553
+			}
533 554
 
534 555
 					$share['share_id'] = self::$db->get_last_insert_id(self::TABLE, 'share_id');
535 556
 					break;
536 557
 				}
537 558
 				catch(Api\Db\Exception $e) {
538
-					if ($i++ > 3) throw $e;
559
+					if ($i++ > 3)
560
+					{
561
+						throw $e;
562
+					}
539 563
 					unset($e);
540 564
 				}
541 565
 			}
@@ -545,7 +569,11 @@  discard block
 block discarded – undo
545 569
 		$async = new Api\Asyncservice();
546 570
 		if (!($job = $async->read(self::ASYNC_JOB_ID)) || $job[self::ASYNC_JOB_ID]['method'] === 'egw_sharing::tmp_cleanup')
547 571
 		{
548
-			if ($job) $async->delete(self::ASYNC_JOB_ID);	// update not working old class-name
572
+			if ($job)
573
+			{
574
+				$async->delete(self::ASYNC_JOB_ID);
575
+			}
576
+			// update not working old class-name
549 577
 
550 578
 			$async->set_timer(array('day' => 28), self::ASYNC_JOB_ID, 'EGroupware\\Api\\Vfs\\Sharing::tmp_cleanup',null);
551 579
 		}
@@ -583,7 +611,10 @@  discard block
 block discarded – undo
583 611
 	{
584 612
 		self::$db = $GLOBALS['egw']->db;
585 613
 
586
-		if (is_scalar($keys)) $keys = array('share_id' => $keys);
614
+		if (is_scalar($keys))
615
+		{
616
+			$keys = array('share_id' => $keys);
617
+		}
587 618
 
588 619
 		// get all temp. files, to be able to delete them
589 620
 		$tmp_paths = array();
@@ -634,7 +665,10 @@  discard block
 block discarded – undo
634 665
 	 */
635 666
 	public static function tmp_cleanup()
636 667
 	{
637
-		if (!isset(self::$db)) self::$db = $GLOBALS['egw']->db;
668
+		if (!isset(self::$db))
669
+		{
670
+			self::$db = $GLOBALS['egw']->db;
671
+		}
638 672
 		Vfs::$is_root = true;
639 673
 
640 674
 		try {
@@ -644,7 +678,10 @@  discard block
 block discarded – undo
644 678
 				'MAX(share_created) AS share_created',
645 679
 				'MAX(share_last_accessed) AS share_last_accessed',
646 680
 			);
647
-			if (($group_concat = self::$db->group_concat('share_id'))) $cols[] = $group_concat.' AS share_id';
681
+			if (($group_concat = self::$db->group_concat('share_id')))
682
+			{
683
+				$cols[] = $group_concat.' AS share_id';
684
+			}
648 685
 			// remove expired tmp-files unconditionally
649 686
 			$having = 'HAVING MAX(share_expires) < '.self::$db->quote(self::$db->to_timestamp(time())).' OR '.
650 687
 				// remove without expiration date, when created over 100 days ago AND
@@ -701,7 +738,10 @@  discard block
 block discarded – undo
701 738
 	 */
702 739
 	public static function share2link($share)
703 740
 	{
704
-		if (is_array($share)) $share = $share['share_token'];
741
+		if (is_array($share))
742
+		{
743
+			$share = $share['share_token'];
744
+		}
705 745
 
706 746
 		return Api\Framework::getUrl(Api\Framework::link('/share.php')).'/'.$share;
707 747
 	}
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
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
  	 * Important: PHP 5.0 introduced a bug that wasn't fixed until 5.1: the return value has to be the oposite!
406 406
  	 *
407 407
  	 * if(version_compare(PHP_VERSION,'5.0','>=') && version_compare(PHP_VERSION,'5.1','<'))
408
-  	 * {
408
+ 	 * {
409 409
  	 * 		$eof = !$eof;
410 410
  	 * }
411
-  	 *
411
+ 	 *
412 412
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
413 413
  	 */
414 414
 	function stream_eof ( )
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url'): ".function_backtrace(1));
917 917
 
918 918
 		while (($rel_path = Vfs::basename($url).($rel_path ? '/'.$rel_path : '')) &&
919
-		       ($url = Vfs::dirname($url)))
919
+			   ($url = Vfs::dirname($url)))
920 920
 		{
921 921
 			if (($stat = $this->url_stat($url, 0, false, false)))
922 922
 			{
Please login to merge, or discard this patch.
Spacing   +133 added lines, -134 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
-	function resolve_url_symlinks($_path,$file_exists=true,$resolve_last_symlink=true,&$stat=null)
160
+	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 = $this->url_stat($path,$resolve_last_symlink?0:STREAM_URL_STAT_LINK)) && !$file_exists)
164
+		if (!($stat = $this->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 && Vfs::parse_url($url,PHP_URL_SCHEME) == self::SCHEME)
175
+		if ($url && Vfs::parse_url($url, PHP_URL_SCHEME) == self::SCHEME)
176 176
 		{
177
-			$url = self::resolve_url(Vfs::parse_url($url,PHP_URL_PATH));
177
+			$url = self::resolve_url(Vfs::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(Vfs::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(Vfs::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 = Vfs::parse_url($url,PHP_URL_SCHEME);
241
-				if (is_null(self::$wrappers) || !in_array($scheme,self::$wrappers))
240
+				$scheme = Vfs::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
 			}
@@ -303,13 +303,13 @@  discard block
 block discarded – undo
303 303
 	 * @param string $opened_path full path of the file/resource, if the open was successfull and STREAM_USE_PATH was set
304 304
 	 * @return boolean true if the ressource was opened successful, otherwise false
305 305
 	 */
306
-	function stream_open ( $path, $mode, $options, &$opened_path )
306
+	function stream_open($path, $mode, $options, &$opened_path)
307 307
 	{
308
-		unset($options,$opened_path);	// not used but required by function signature
308
+		unset($options, $opened_path); // not used but required by function signature
309 309
 		$this->opened_stream = null;
310 310
 
311 311
 		$stat = null;
312
-		if (!($url = $this->resolve_url_symlinks($path,$mode[0]=='r',true,$stat)))
312
+		if (!($url = $this->resolve_url_symlinks($path, $mode[0] == 'r', true, $stat)))
313 313
 		{
314 314
 			return false;
315 315
 		}
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	 *
346 346
 	 * VFS calls either "vfs_read", "vfs_added" or "vfs_modified" hook
347 347
 	 */
348
-	function stream_close ( )
348
+	function stream_close( )
349 349
 	{
350 350
 		$ret = fclose($this->opened_stream);
351 351
 		// clear PHP's stat cache, it contains wrong size of just closed file,
@@ -355,12 +355,11 @@  discard block
 block discarded – undo
355 355
 		if (!class_exists('setup_process', false))
356 356
 		{
357 357
 			Api\Hooks::process(array(
358
-				'location' => str_replace('b','',$this->opened_stream_mode) == 'r' ? 'vfs_read' :
359
-					($this->opened_stream_is_new ? 'vfs_added' : 'vfs_modified'),
358
+				'location' => str_replace('b', '', $this->opened_stream_mode) == 'r' ? 'vfs_read' : ($this->opened_stream_is_new ? 'vfs_added' : 'vfs_modified'),
360 359
 				'path' => $this->opened_stream_path,
361 360
 				'mode' => $this->opened_stream_mode,
362 361
 				'url'  => $this->opened_stream_url,
363
-			),'',true);
362
+			), '', true);
364 363
 		}
365 364
 		$this->opened_stream = $this->opened_stream_mode = $this->opened_stream_path = $this->opened_stream_url = $this->opened_stream_is_new = null;
366 365
 
@@ -378,9 +377,9 @@  discard block
 block discarded – undo
378 377
 	 * @param int $count
379 378
 	 * @return string/false up to count bytes read or false on EOF
380 379
 	 */
381
-	function stream_read ( $count )
380
+	function stream_read($count)
382 381
 	{
383
-		return fread($this->opened_stream,$count);
382
+		return fread($this->opened_stream, $count);
384 383
 	}
385 384
 
386 385
 	/**
@@ -394,9 +393,9 @@  discard block
 block discarded – undo
394 393
 	 * @param string $data
395 394
 	 * @return integer
396 395
 	 */
397
-	function stream_write ( $data )
396
+	function stream_write($data)
398 397
 	{
399
-		return fwrite($this->opened_stream,$data);
398
+		return fwrite($this->opened_stream, $data);
400 399
 	}
401 400
 
402 401
  	/**
@@ -411,7 +410,7 @@  discard block
 block discarded – undo
411 410
   	 *
412 411
  	 * @return boolean true if the read/write position is at the end of the stream and no more data availible, false otherwise
413 412
  	 */
414
-	function stream_eof ( )
413
+	function stream_eof( )
415 414
 	{
416 415
 		return feof($this->opened_stream);
417 416
 	}
@@ -421,7 +420,7 @@  discard block
 block discarded – undo
421 420
 	 *
422 421
 	 * @return integer current read/write position of the stream
423 422
 	 */
424
- 	function stream_tell ( )
423
+ 	function stream_tell( )
425 424
  	{
426 425
  		return ftell($this->opened_stream);
427 426
  	}
@@ -438,9 +437,9 @@  discard block
 block discarded – undo
438 437
  	 * 							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.)
439 438
  	 * @return boolean TRUE if the position was updated, FALSE otherwise.
440 439
  	 */
441
-	function stream_seek ( $offset, $whence )
440
+	function stream_seek($offset, $whence)
442 441
 	{
443
-		return !fseek($this->opened_stream,$offset,$whence);	// fseek returns 0 on success and -1 on failure
442
+		return !fseek($this->opened_stream, $offset, $whence); // fseek returns 0 on success and -1 on failure
444 443
 	}
445 444
 
446 445
 	/**
@@ -450,7 +449,7 @@  discard block
 block discarded – undo
450 449
 	 *
451 450
 	 * @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.
452 451
 	 */
453
-	function stream_flush ( )
452
+	function stream_flush( )
454 453
 	{
455 454
 		return fflush($this->opened_stream);
456 455
 	}
@@ -469,7 +468,7 @@  discard block
 block discarded – undo
469 468
 	 *
470 469
 	 * @return array containing the same values as appropriate for the stream.
471 470
 	 */
472
-	function stream_stat ( )
471
+	function stream_stat( )
473 472
 	{
474 473
 		return fstat($this->opened_stream);
475 474
 	}
@@ -498,10 +497,10 @@  discard block
 block discarded – undo
498 497
 		}
499 498
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path', $option, ".array2string($value).") url=$url");
500 499
 
501
-		switch($option)
500
+		switch ($option)
502 501
 		{
503 502
 			case STREAM_META_TOUCH:
504
-				return touch($url, $value[0]);	// atime is not supported
503
+				return touch($url, $value[0]); // atime is not supported
505 504
 
506 505
 			case STREAM_META_ACCESS:
507 506
 				return chmod($url, $value);
@@ -532,9 +531,9 @@  discard block
 block discarded – undo
532 531
 	 * @param string $path
533 532
 	 * @return boolean TRUE on success or FALSE on failure
534 533
 	 */
535
-	function unlink ( $path )
534
+	function unlink($path)
536 535
 	{
537
-		if (!($url = $this->resolve_url_symlinks($path,true,false)))	// true,false file need to exist, but do not resolve last component
536
+		if (!($url = $this->resolve_url_symlinks($path, true, false)))	// true,false file need to exist, but do not resolve last component
538 537
 		{
539 538
 			return false;
540 539
 		}
@@ -555,7 +554,7 @@  discard block
 block discarded – undo
555 554
 				'path' => $path[0] == '/' ? $path : Vfs::parse_url($path, PHP_URL_PATH),
556 555
 				'url'  => $url,
557 556
 				'stat' => $stat,
558
-			),'',true);
557
+			), '', true);
559 558
 		}
560 559
 		return $ok;
561 560
 	}
@@ -573,14 +572,14 @@  discard block
 block discarded – undo
573 572
 	 * @return boolean TRUE on success or FALSE on failure
574 573
 	 * @throws Exception\ProtectedDirectory if trying to delete a protected directory, see Vfs::isProtected()
575 574
 	 */
576
-	function rename ( $path_from, $path_to )
575
+	function rename($path_from, $path_to)
577 576
 	{
578 577
 		if (Vfs::isProtectedDir($path_from))
579 578
 		{
580 579
 			throw new Exception\ProtectedDirectory("Renaming protected directory '$path_from' rejected!");
581 580
 		}
582
-		if (!($url_from = $this->resolve_url_symlinks($path_from,true,false)) ||
583
-			!($url_to = $this->resolve_url_symlinks($path_to,false)))
581
+		if (!($url_from = $this->resolve_url_symlinks($path_from, true, false)) ||
582
+			!($url_to = $this->resolve_url_symlinks($path_to, false)))
584 583
 		{
585 584
 			return false;
586 585
 		}
@@ -590,14 +589,14 @@  discard block
 block discarded – undo
590 589
 			return false;
591 590
 		}
592 591
 		// if file is moved from one filesystem / wrapper to an other --> copy it (rename fails cross wrappers)
593
-		if (Vfs::parse_url($url_from,PHP_URL_SCHEME) == Vfs::parse_url($url_to,PHP_URL_SCHEME))
592
+		if (Vfs::parse_url($url_from, PHP_URL_SCHEME) == Vfs::parse_url($url_to, PHP_URL_SCHEME))
594 593
 		{
595 594
 			self::symlinkCache_remove($path_from);
596
-			$ret = rename($url_from,$url_to);
595
+			$ret = rename($url_from, $url_to);
597 596
 		}
598
-		elseif (($from = fopen($url_from,'r')) && ($to = fopen($url_to,'w')))
597
+		elseif (($from = fopen($url_from, 'r')) && ($to = fopen($url_to, 'w')))
599 598
 		{
600
-			$ret = stream_copy_to_stream($from,$to) !== false;
599
+			$ret = stream_copy_to_stream($from, $to) !== false;
601 600
 			fclose($from);
602 601
 			fclose($to);
603 602
 			if ($ret) $this->unlink($path_from);
@@ -619,7 +618,7 @@  discard block
 block discarded – undo
619 618
 				'to' => $path_to[0] == '/' ? $path_to : Vfs::parse_url($path_to, PHP_URL_PATH),
620 619
 				'url_from' => $url_from,
621 620
 				'url_to' => $url_to,
622
-			),'',true);
621
+			), '', true);
623 622
 		}
624 623
 		return $ret;
625 624
 	}
@@ -635,9 +634,9 @@  discard block
 block discarded – undo
635 634
 	 * @param int $options Posible values include STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE
636 635
 	 * @return boolean TRUE on success or FALSE on failure
637 636
 	 */
638
-	function mkdir ( $path, $mode, $options )
637
+	function mkdir($path, $mode, $options)
639 638
 	{
640
-		if (!($url = $this->resolve_url_symlinks($path,false)))	// false = directory does not need to exists
639
+		if (!($url = $this->resolve_url_symlinks($path, false)))	// false = directory does not need to exists
641 640
 		{
642 641
 			return false;
643 642
 		}
@@ -647,7 +646,7 @@  discard block
 block discarded – undo
647 646
 			return false;
648 647
 		}
649 648
 		// check if recursive option is set and needed
650
-		if (($options & STREAM_MKDIR_RECURSIVE) &&
649
+		if (($options&STREAM_MKDIR_RECURSIVE) &&
651 650
 			($parent_url = Vfs::dirname($url)) &&
652 651
 			!($this->url_stat($parent_url, STREAM_URL_STAT_QUIET)) &&
653 652
 			Vfs::parse_url($parent_url, PHP_URL_PATH) !== '/')
@@ -657,14 +656,14 @@  discard block
 block discarded – undo
657 656
 		// unset it now, as it was handled above
658 657
 		if (strpos($url, 'smb://') === 0)
659 658
 		{
660
-			$options = 0;	// smbclient php extension treats every bit as recursive
659
+			$options = 0; // smbclient php extension treats every bit as recursive
661 660
 		}
662 661
 		else
663 662
 		{
664 663
 			$options &= ~STREAM_MKDIR_RECURSIVE;
665 664
 		}
666 665
 
667
-		$ret = mkdir($url,$mode,$options);
666
+		$ret = mkdir($url, $mode, $options);
668 667
 
669 668
 		// call "vfs_mkdir" hook
670 669
 		if ($ret && !class_exists('setup_process', false))
@@ -673,7 +672,7 @@  discard block
 block discarded – undo
673 672
 				'location' => 'vfs_mkdir',
674 673
 				'path' => $path[0] == '/' ? $path : Vfs::parse_url($path, PHP_URL_PATH),
675 674
 				'url' => $url,
676
-			),'',true);
675
+			), '', true);
677 676
 		}
678 677
 		return $ret;
679 678
 	}
@@ -689,13 +688,13 @@  discard block
 block discarded – undo
689 688
 	 * @return boolean TRUE on success or FALSE on failure.
690 689
 	 * @throws Exception\ProtectedDirectory if trying to delete a protected directory, see Vfs::isProtected()
691 690
 	 */
692
-	function rmdir ( $path, $options )
691
+	function rmdir($path, $options)
693 692
 	{
694 693
 		if (Vfs::isProtectedDir($path))
695 694
 		{
696 695
 			throw new Exception\ProtectedDirectory("Deleting protected directory '$path' rejected!");
697 696
 		}
698
-		unset($options);	// not uses but required by function signature
697
+		unset($options); // not uses but required by function signature
699 698
 		if (!($url = $this->resolve_url_symlinks($path)))
700 699
 		{
701 700
 			return false;
@@ -717,7 +716,7 @@  discard block
 block discarded – undo
717 716
 				'path' => $path[0] == '/' ? $path : Vfs::parse_url($path, PHP_URL_PATH),
718 717
 				'url' => $url,
719 718
 				'stat' => $stat,
720
-			),'',true);
719
+			), '', true);
721 720
 		}
722 721
 		return $ok;
723 722
 	}
@@ -728,7 +727,7 @@  discard block
 block discarded – undo
728 727
 	 * @param string $path URL that was passed to opendir() and that this object is expected to explore.
729 728
 	 * @return booelan
730 729
 	 */
731
-	function dir_opendir ( $path, $options )
730
+	function dir_opendir($path, $options)
732 731
 	{
733 732
 		$this->opened_dir = $this->extra_dirs = null;
734 733
 		$this->dir_url_params = array();
@@ -745,15 +744,15 @@  discard block
 block discarded – undo
745 744
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__."( $path,$options) opendir($this->opened_dir_url) failed!");
746 745
 			return false;
747 746
 		}
748
-		$this->opened_dir_writable = Vfs::check_access($this->opened_dir_url,Vfs::WRITABLE);
747
+		$this->opened_dir_writable = Vfs::check_access($this->opened_dir_url, Vfs::WRITABLE);
749 748
 		// check our fstab if we need to add some of the mountpoints
750
-		$basepath = Vfs::parse_url($path,PHP_URL_PATH);
751
-		foreach(array_keys(self::$fstab) as $mounted)
749
+		$basepath = Vfs::parse_url($path, PHP_URL_PATH);
750
+		foreach (array_keys(self::$fstab) as $mounted)
752 751
 		{
753 752
 			if (((Vfs::dirname($mounted) == $basepath || Vfs::dirname($mounted).'/' == $basepath) && $mounted != '/') &&
754 753
 				// only return children readable by the user, if dir is not writable
755 754
 				(!self::HIDE_UNREADABLES || $this->opened_dir_writable ||
756
-					Vfs::check_access($mounted,Vfs::READABLE)))
755
+					Vfs::check_access($mounted, Vfs::READABLE)))
757 756
 			{
758 757
 				$this->extra_dirs[] = Vfs::basename($mounted);
759 758
 			}
@@ -792,24 +791,24 @@  discard block
 block discarded – undo
792 791
 	 * @param boolean $check_symlink_components =true check if path contains symlinks in path components other then the last one
793 792
 	 * @return array
794 793
 	 */
795
-	function url_stat ( $path, $flags, $try_create_home=false, $check_symlink_components=true, $check_symlink_depth=self::MAX_SYMLINK_DEPTH, $try_reconnect=true )
794
+	function url_stat($path, $flags, $try_create_home = false, $check_symlink_components = true, $check_symlink_depth = self::MAX_SYMLINK_DEPTH, $try_reconnect = true)
796 795
 	{
797
-		if (!($url = self::resolve_url($path,!($flags & STREAM_URL_STAT_LINK), $check_symlink_components)))
796
+		if (!($url = self::resolve_url($path, !($flags&STREAM_URL_STAT_LINK), $check_symlink_components)))
798 797
 		{
799 798
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$path',$flags) can NOT resolve path!");
800 799
 			return false;
801 800
 		}
802 801
 
803 802
 		try {
804
-			if ($flags & STREAM_URL_STAT_LINK)
803
+			if ($flags&STREAM_URL_STAT_LINK)
805 804
 			{
806
-				$stat = @lstat($url);	// suppressed the stat failed warnings
805
+				$stat = @lstat($url); // suppressed the stat failed warnings
807 806
 			}
808 807
 			else
809 808
 			{
810
-				$stat = @stat($url);	// suppressed the stat failed warnings
809
+				$stat = @stat($url); // suppressed the stat failed warnings
811 810
 
812
-				if ($stat && ($stat['mode'] & self::MODE_LINK))
811
+				if ($stat && ($stat['mode']&self::MODE_LINK))
813 812
 				{
814 813
 					if (!$check_symlink_depth)
815 814
 					{
@@ -820,25 +819,25 @@  discard block
 block discarded – undo
820 819
 					{
821 820
 						if ($lpath[0] != '/')	// concat relative path
822 821
 						{
823
-							$lpath = Vfs::concat(Vfs::parse_url($path,PHP_URL_PATH),'../'.$lpath);
822
+							$lpath = Vfs::concat(Vfs::parse_url($path, PHP_URL_PATH), '../'.$lpath);
824 823
 						}
825
-						$u_query = parse_url($url,PHP_URL_QUERY);
824
+						$u_query = parse_url($url, PHP_URL_QUERY);
826 825
 						$url = Vfs::PREFIX.$lpath;
827 826
 						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");
828 827
 						// try reading the stat of the link
829
-						if (($stat = $this->url_stat($lpath, STREAM_URL_STAT_QUIET, false, true, $check_symlink_depth-1)))
828
+						if (($stat = $this->url_stat($lpath, STREAM_URL_STAT_QUIET, false, true, $check_symlink_depth - 1)))
830 829
 						{
831 830
 							$stat_query = parse_url($stat['url'], PHP_URL_QUERY);
832
-							if($u_query || $stat_query)
831
+							if ($u_query || $stat_query)
833 832
 							{
834 833
 								$stat_url = parse_url($stat['url']);
835
-								parse_str($stat_query,$stat_query);
834
+								parse_str($stat_query, $stat_query);
836 835
 								parse_str($u_query, $u_query);
837 836
 								$stat_query = http_build_query(array_merge($stat_query, $u_query));
838 837
 								$stat['url'] = $stat_url['scheme'].'://'.$stat_url['host'].$stat_url['path'].'?'.$stat_query;
839 838
 							}
840
-							if(isset($stat['url'])) $url = $stat['url'];	// if stat returns an url use that, as there might be more links ...
841
-							self::symlinkCache_add($path,$url);
839
+							if (isset($stat['url'])) $url = $stat['url']; // if stat returns an url use that, as there might be more links ...
840
+							self::symlinkCache_add($path, $url);
842 841
 						}
843 842
 					}
844 843
 				}
@@ -858,7 +857,7 @@  discard block
 block discarded – undo
858 857
 			throw $e;
859 858
 		}
860 859
 		// check if a failed url_stat was for a home dir, in that case silently create it
861
-		if (!$stat && $try_create_home && Vfs::dirname(Vfs::parse_url($path,PHP_URL_PATH)) == '/home' &&
860
+		if (!$stat && $try_create_home && Vfs::dirname(Vfs::parse_url($path, PHP_URL_PATH)) == '/home' &&
862 861
 			($id = $GLOBALS['egw']->accounts->name2id(Vfs::basename($path))) &&
863 862
 			$GLOBALS['egw']->accounts->id2name($id) == Vfs::basename($path))	// make sure path has the right case!
864 863
 		{
@@ -868,25 +867,25 @@  discard block
 block discarded – undo
868 867
 				'account_lid' => Vfs::basename($path),
869 868
 				'account_name' => Vfs::basename($path),
870 869
 			);
871
-			call_user_func(array(__NAMESPACE__.'\\Hooks',$hook_data['location']),$hook_data);
870
+			call_user_func(array(__NAMESPACE__.'\\Hooks', $hook_data['location']), $hook_data);
872 871
 			unset($hook_data);
873
-			$stat = $this->url_stat($path,$flags,false);
872
+			$stat = $this->url_stat($path, $flags, false);
874 873
 		}
875 874
 		$query = parse_url($url, PHP_URL_QUERY);
876 875
 		if (!$stat && $check_symlink_components)	// check if there's a symlink somewhere inbetween the path
877 876
 		{
878
-			$stat = self::check_symlink_components($path,$flags,$url);
879
-			if ($stat && isset($stat['url']) && !$query) self::symlinkCache_add($path,$stat['url']);
877
+			$stat = self::check_symlink_components($path, $flags, $url);
878
+			if ($stat && isset($stat['url']) && !$query) self::symlinkCache_add($path, $stat['url']);
880 879
 		}
881
-		elseif(is_array($stat) && !isset($stat['url']))
880
+		elseif (is_array($stat) && !isset($stat['url']))
882 881
 		{
883 882
 			$stat['url'] = $url;
884 883
 		}
885
-		if (($stat['mode'] & 0222) && self::url_is_readonly($stat['url']))
884
+		if (($stat['mode']&0222) && self::url_is_readonly($stat['url']))
886 885
 		{
887 886
 			$stat['mode'] &= ~0222;
888 887
 		}
889
-		if($stat['url'] && $query && strpos($stat['url'],'?'.$query)===false)
888
+		if ($stat['url'] && $query && strpos($stat['url'], '?'.$query) === false)
890 889
 		{
891 890
 			$stat['url'] .= '?'.$query;
892 891
 		}
@@ -913,7 +912,7 @@  discard block
 block discarded – undo
913 912
 	 * @param string &$url=null already resolved path
914 913
 	 * @return array|boolean stat array or false if not found
915 914
 	 */
916
-	private function check_symlink_components($path,$flags=0,&$url=null)
915
+	private function check_symlink_components($path, $flags = 0, &$url = null)
917 916
 	{
918 917
 		if (is_null($url) && !($url = self::resolve_url($path)))
919 918
 		{
@@ -933,20 +932,20 @@  discard block
 block discarded – undo
933 932
 
934 933
 					if ($lpath[0] != '/')
935 934
 					{
936
-						$lpath = Vfs::concat(Vfs::parse_url($url,PHP_URL_PATH),'../'.$lpath);
935
+						$lpath = Vfs::concat(Vfs::parse_url($url, PHP_URL_PATH), '../'.$lpath);
937 936
 					}
938 937
 					//self::symlinkCache_add($path,Vfs::PREFIX.$lpath);
939
-					$url = Vfs::PREFIX.Vfs::concat($lpath,$rel_path);
938
+					$url = Vfs::PREFIX.Vfs::concat($lpath, $rel_path);
940 939
 					if (self::LOG_LEVEL > 1) error_log("$log --> lpath='$lpath', url='$url'");
941
-					return $this->url_stat($url,$flags);
940
+					return $this->url_stat($url, $flags);
942 941
 				}
943
-				$url = Vfs::concat($url,$rel_path);
942
+				$url = Vfs::concat($url, $rel_path);
944 943
 				if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning null");
945 944
 				return null;
946 945
 			}
947 946
 		}
948 947
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning false");
949
-		return false;	// $path does not exist
948
+		return false; // $path does not exist
950 949
 	}
951 950
 
952 951
 	/**
@@ -962,13 +961,13 @@  discard block
 block discarded – undo
962 961
 	 * @param string $_path vfs path
963 962
 	 * @param string $target target path
964 963
 	 */
965
-	static protected function symlinkCache_add($_path,$target)
964
+	static protected function symlinkCache_add($_path, $target)
966 965
 	{
967 966
 		$path = self::get_path($_path);
968 967
 
969
-		if (isset(self::$symlink_cache[$path])) return;	// nothing to do
968
+		if (isset(self::$symlink_cache[$path])) return; // nothing to do
970 969
 
971
-		if ($target[0] != '/') $target = Vfs::parse_url($target,PHP_URL_PATH);
970
+		if ($target[0] != '/') $target = Vfs::parse_url($target, PHP_URL_PATH);
972 971
 
973 972
 		self::$symlink_cache[$path] = $target;
974 973
 
@@ -1002,25 +1001,25 @@  discard block
 block discarded – undo
1002 1001
 	 * @param boolean $do_symlink =true is a direct match allowed, default yes (must be false for a lstat or readlink!)
1003 1002
 	 * @return string target or path, if path not found
1004 1003
 	 */
1005
-	static public function symlinkCache_resolve($_path,$do_symlink=true)
1004
+	static public function symlinkCache_resolve($_path, $do_symlink = true)
1006 1005
 	{
1007 1006
 		// remove vfs scheme, but no other schemes (eg. filesystem!)
1008 1007
 		$path = self::get_path($_path);
1009 1008
 
1010 1009
 		$strlen_path = strlen($path);
1011 1010
 
1012
-		foreach(self::$symlink_cache as $p => $t)
1011
+		foreach (self::$symlink_cache as $p => $t)
1013 1012
 		{
1014
-			if (($strlen_p = strlen($p)) > $strlen_path) continue;	// $path can NOT start with $p
1013
+			if (($strlen_p = strlen($p)) > $strlen_path) continue; // $path can NOT start with $p
1015 1014
 
1016 1015
 			if ($path == $p)
1017 1016
 			{
1018 1017
 				if ($do_symlink) $target = $t;
1019 1018
 				break;
1020 1019
 			}
1021
-			elseif (substr($path,0,$strlen_p+1) == $p.'/')
1020
+			elseif (substr($path, 0, $strlen_p + 1) == $p.'/')
1022 1021
 			{
1023
-				$target = $t . substr($path,$strlen_p);
1022
+				$target = $t.substr($path, $strlen_p);
1024 1023
 				break;
1025 1024
 			}
1026 1025
 		}
@@ -1048,7 +1047,7 @@  discard block
 block discarded – undo
1048 1047
 	 *
1049 1048
 	 * @return string
1050 1049
 	 */
1051
-	function dir_readdir ( )
1050
+	function dir_readdir( )
1052 1051
 	{
1053 1052
 		if ($this->extra_dirs && count($this->extra_dirs) > $this->extra_dir_ptr)
1054 1053
 		{
@@ -1060,10 +1059,10 @@  discard block
 block discarded – undo
1060 1059
 			do {
1061 1060
 				$file = readdir($this->opened_dir);
1062 1061
 			}
1063
-			while($file !== false &&
1064
-				(is_array($this->extra_dirs) && in_array($file,$this->extra_dirs) || // do NOT return extra_dirs twice
1062
+			while ($file !== false &&
1063
+				(is_array($this->extra_dirs) && in_array($file, $this->extra_dirs) || // do NOT return extra_dirs twice
1065 1064
 				self::HIDE_UNREADABLES && !$this->opened_dir_writable &&
1066
-				!Vfs::check_access(Vfs::concat($this->opened_dir_url,$file),Vfs::READABLE)));
1065
+				!Vfs::check_access(Vfs::concat($this->opened_dir_url, $file), Vfs::READABLE)));
1067 1066
 		}
1068 1067
 		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( $this->opened_dir ) = '$file'");
1069 1068
 		return $file;
@@ -1077,7 +1076,7 @@  discard block
 block discarded – undo
1077 1076
 	 *
1078 1077
 	 * @return boolean
1079 1078
 	 */
1080
-	function dir_rewinddir ( )
1079
+	function dir_rewinddir( )
1081 1080
 	{
1082 1081
 		$this->extra_dir_ptr = 0;
1083 1082
 
@@ -1091,7 +1090,7 @@  discard block
 block discarded – undo
1091 1090
 	 *
1092 1091
 	 * @return boolean
1093 1092
 	 */
1094
-	function dir_closedir ( )
1093
+	function dir_closedir( )
1095 1094
 	{
1096 1095
 		$ret = closedir($this->opened_dir);
1097 1096
 
@@ -1108,9 +1107,9 @@  discard block
 block discarded – undo
1108 1107
 	 */
1109 1108
 	static function load_wrapper($scheme)
1110 1109
 	{
1111
-		if (!in_array($scheme,self::get_wrappers()))
1110
+		if (!in_array($scheme, self::get_wrappers()))
1112 1111
 		{
1113
-			switch($scheme)
1112
+			switch ($scheme)
1114 1113
 			{
1115 1114
 				case 'webdav':
1116 1115
 				case 'webdavs':
@@ -1118,16 +1117,16 @@  discard block
 block discarded – undo
1118 1117
 					self::$wrappers[] = $scheme;
1119 1118
 					break;
1120 1119
 				case '':
1121
-					break;	// default file, always loaded
1120
+					break; // default file, always loaded
1122 1121
 				default:
1123 1122
 					// check if scheme is buildin in php or one of our own stream wrappers
1124
-					if (in_array($scheme,stream_get_wrappers()) || class_exists(self::scheme2class($scheme)))
1123
+					if (in_array($scheme, stream_get_wrappers()) || class_exists(self::scheme2class($scheme)))
1125 1124
 					{
1126 1125
 						self::$wrappers[] = $scheme;
1127 1126
 					}
1128 1127
 					else
1129 1128
 					{
1130
-						trigger_error("Can't load stream-wrapper for scheme '$scheme'!",E_USER_WARNING);
1129
+						trigger_error("Can't load stream-wrapper for scheme '$scheme'!", E_USER_WARNING);
1131 1130
 						return false;
1132 1131
 					}
1133 1132
 			}
@@ -1161,10 +1160,10 @@  discard block
 block discarded – undo
1161 1160
 	static function scheme2class($scheme)
1162 1161
 	{
1163 1162
 		list($app, $app_scheme) = explode('.', $scheme);
1164
-		foreach(array(
1165
-			empty($app_scheme) ? 'EGroupware\\Api\\Vfs\\'.ucfirst($scheme).'\\StreamWrapper' :	// streamwrapper in Api\Vfs
1163
+		foreach (array(
1164
+			empty($app_scheme) ? 'EGroupware\\Api\\Vfs\\'.ucfirst($scheme).'\\StreamWrapper' : // streamwrapper in Api\Vfs
1166 1165
 				'EGroupware\\'.ucfirst($app).'\\Vfs\\'.ucfirst($app_scheme).'\\StreamWrapper', // streamwrapper in $app\Vfs
1167
-			str_replace('.','_',$scheme).'_stream_wrapper',	// old (flat) name
1166
+			str_replace('.', '_', $scheme).'_stream_wrapper', // old (flat) name
1168 1167
 		) as $class)
1169 1168
 		{
1170 1169
 			//error_log(__METHOD__."('$scheme') class_exists('$class')=".array2string(class_exists($class)));
@@ -1179,7 +1178,7 @@  discard block
 block discarded – undo
1179 1178
 	 * @param string $only_remove_scheme =self::SCHEME if given only that scheme get's removed
1180 1179
 	 * @return string path without training slash
1181 1180
 	 */
1182
-	static protected function get_path($path,$only_remove_scheme=self::SCHEME)
1181
+	static protected function get_path($path, $only_remove_scheme = self::SCHEME)
1183 1182
 	{
1184 1183
 		if ($path[0] != '/' && (!$only_remove_scheme || Vfs::parse_url($path, PHP_URL_SCHEME) == $only_remove_scheme))
1185 1184
 		{
@@ -1190,7 +1189,7 @@  discard block
 block discarded – undo
1190 1189
 		{
1191 1190
 			while (mb_substr($path, -1) == '/' && $path != '/' && ($path[0] == '/' || Vfs::parse_url($path, PHP_URL_PATH) != '/'))
1192 1191
 			{
1193
-				$path = mb_substr($path,0,-1);
1192
+				$path = mb_substr($path, 0, -1);
1194 1193
 			}
1195 1194
 		}
1196 1195
 		return $path;
@@ -1205,7 +1204,7 @@  discard block
 block discarded – undo
1205 1204
 	static function url_is_readonly($url)
1206 1205
 	{
1207 1206
 		static $cache = array();
1208
-		$ret =& $cache[$url];
1207
+		$ret = & $cache[$url];
1209 1208
 		if (!isset($ret))
1210 1209
 		{
1211 1210
 			$matches = null;
@@ -1227,9 +1226,9 @@  discard block
 block discarded – undo
1227 1226
 	 * @param boolean $clear_fstab =false true clear current fstab, false (default) only add given mount
1228 1227
 	 * @return array|boolean array with fstab, if called without parameter or true on successful mount
1229 1228
 	 */
1230
-	static function mount($url=null,$path=null,$check_url=null,$persitent_mount=true,$clear_fstab=false)
1229
+	static function mount($url = null, $path = null, $check_url = null, $persitent_mount = true, $clear_fstab = false)
1231 1230
 	{
1232
-		if (is_null($check_url)) $check_url = strpos($url,'$') === false;
1231
+		if (is_null($check_url)) $check_url = strpos($url, '$') === false;
1233 1232
 
1234 1233
 		if (!isset($GLOBALS['egw_info']['server']['vfs_fstab']))	// happens eg. in setup
1235 1234
 		{
@@ -1255,7 +1254,7 @@  discard block
 block discarded – undo
1255 1254
 		if (!Vfs::$is_root)
1256 1255
 		{
1257 1256
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') permission denied, you are NOT root!');
1258
-			return false;	// only root can mount
1257
+			return false; // only root can mount
1259 1258
 		}
1260 1259
 		if ($clear_fstab)
1261 1260
 		{
@@ -1264,14 +1263,14 @@  discard block
 block discarded – undo
1264 1263
 		if (isset(self::$fstab[$path]) && self::$fstab[$path] === $url)
1265 1264
 		{
1266 1265
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') already mounted.');
1267
-			return true;	// already mounted
1266
+			return true; // already mounted
1268 1267
 		}
1269
-		self::load_wrapper(Vfs::parse_url($url,PHP_URL_SCHEME));
1268
+		self::load_wrapper(Vfs::parse_url($url, PHP_URL_SCHEME));
1270 1269
 
1271 1270
 		if ($check_url && (!file_exists($url) || opendir($url) === false))
1272 1271
 		{
1273 1272
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') url does NOT exist!');
1274
-			return false;	// url does not exist
1273
+			return false; // url does not exist
1275 1274
 		}
1276 1275
 		self::$fstab[$path] = $url;
1277 1276
 
@@ -1282,10 +1281,10 @@  discard block
 block discarded – undo
1282 1281
 
1283 1282
 		if ($persitent_mount)
1284 1283
 		{
1285
-			Api\Config::save_value('vfs_fstab',self::$fstab,'phpgwapi');
1284
+			Api\Config::save_value('vfs_fstab', self::$fstab, 'phpgwapi');
1286 1285
 			$GLOBALS['egw_info']['server']['vfs_fstab'] = self::$fstab;
1287 1286
 			// invalidate session cache
1288
-			if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
1287
+			if (method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
1289 1288
 			{
1290 1289
 				$GLOBALS['egw']->invalidate_session_cache();
1291 1290
 			}
@@ -1304,19 +1303,19 @@  discard block
 block discarded – undo
1304 1303
 		if (!Vfs::$is_root)
1305 1304
 		{
1306 1305
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($path).','.array2string($path).') permission denied, you are NOT root!');
1307
-			return false;	// only root can mount
1306
+			return false; // only root can mount
1308 1307
 		}
1309
-		if (!isset(self::$fstab[$path]) && ($path = array_search($path,self::$fstab)) === false)
1308
+		if (!isset(self::$fstab[$path]) && ($path = array_search($path, self::$fstab)) === false)
1310 1309
 		{
1311 1310
 			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($path).') NOT mounted!');
1312
-			return false;	// $path not mounted
1311
+			return false; // $path not mounted
1313 1312
 		}
1314 1313
 		unset(self::$fstab[$path]);
1315 1314
 
1316
-		Api\Config::save_value('vfs_fstab',self::$fstab,'phpgwapi');
1315
+		Api\Config::save_value('vfs_fstab', self::$fstab, 'phpgwapi');
1317 1316
 		$GLOBALS['egw_info']['server']['vfs_fstab'] = self::$fstab;
1318 1317
 		// invalidate session cache
1319
-		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
1318
+		if (method_exists($GLOBALS['egw'], 'invalidate_session_cache'))	// egw object in setup is limited
1320 1319
 		{
1321 1320
 			$GLOBALS['egw']->invalidate_session_cache();
1322 1321
 		}
@@ -1330,7 +1329,7 @@  discard block
 block discarded – undo
1330 1329
 	 */
1331 1330
 	static function init_static()
1332 1331
 	{
1333
-		stream_register_wrapper(self::SCHEME,__CLASS__);
1332
+		stream_register_wrapper(self::SCHEME, __CLASS__);
1334 1333
 
1335 1334
 		if (($fstab = $GLOBALS['egw_info']['server']['vfs_fstab']) && is_array($fstab) && count($fstab))
1336 1335
 		{
Please login to merge, or discard this patch.
Braces   +234 added lines, -58 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(Vfs::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(Vfs::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
 	}
@@ -488,15 +522,21 @@  discard block
 block discarded – undo
488 522
 	 */
489 523
 	function stream_metadata($path, $option, $value)
490 524
 	{
491
-		if (!($url = $this->resolve_url_symlinks($path, $option != STREAM_META_TOUCH, false)))	// true,false file need to exist, but do not resolve last component
525
+		if (!($url = $this->resolve_url_symlinks($path, $option != STREAM_META_TOUCH, false)))
526
+		{
527
+			// true,false file need to exist, but do not resolve last component
492 528
 		{
493 529
 			return false;
494 530
 		}
531
+		}
495 532
 		if (self::url_is_readonly($url))
496 533
 		{
497 534
 			return false;
498 535
 		}
499
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path', $option, ".array2string($value).") url=$url");
536
+		if (self::LOG_LEVEL > 1)
537
+		{
538
+			error_log(__METHOD__."('$path', $option, ".array2string($value).") url=$url");
539
+		}
500 540
 
501 541
 		switch($option)
502 542
 		{
@@ -508,14 +548,18 @@  discard block
 block discarded – undo
508 548
 
509 549
 			case STREAM_META_OWNER_NAME:
510 550
 				if (($value = $GLOBALS['egw']->accounts->name2id($value, 'account_lid', 'u')) === false)
511
-					return false;
551
+				{
552
+									return false;
553
+				}
512 554
 				// fall through
513 555
 			case STREAM_META_OWNER:
514 556
 				return chown($url, $value);
515 557
 
516 558
 			case STREAM_META_GROUP_NAME:
517 559
 				if (($value = $GLOBALS['egw']->accounts->name2id($value, 'account_lid', 'g')) === false)
518
-					return false;
560
+				{
561
+									return false;
562
+				}
519 563
 				// fall through
520 564
 			case STREAM_META_GROUP:
521 565
 				return chgrp($url, $value);
@@ -534,10 +578,13 @@  discard block
 block discarded – undo
534 578
 	 */
535 579
 	function unlink ( $path )
536 580
 	{
537
-		if (!($url = $this->resolve_url_symlinks($path,true,false)))	// true,false file need to exist, but do not resolve last component
581
+		if (!($url = $this->resolve_url_symlinks($path,true,false)))
582
+		{
583
+			// true,false file need to exist, but do not resolve last component
538 584
 		{
539 585
 			return false;
540 586
 		}
587
+		}
541 588
 		if (self::url_is_readonly($url))
542 589
 		{
543 590
 			return false;
@@ -600,7 +647,10 @@  discard block
 block discarded – undo
600 647
 			$ret = stream_copy_to_stream($from,$to) !== false;
601 648
 			fclose($from);
602 649
 			fclose($to);
603
-			if ($ret) $this->unlink($path_from);
650
+			if ($ret)
651
+			{
652
+				$this->unlink($path_from);
653
+			}
604 654
 		}
605 655
 		else
606 656
 		{
@@ -637,10 +687,13 @@  discard block
 block discarded – undo
637 687
 	 */
638 688
 	function mkdir ( $path, $mode, $options )
639 689
 	{
640
-		if (!($url = $this->resolve_url_symlinks($path,false)))	// false = directory does not need to exists
690
+		if (!($url = $this->resolve_url_symlinks($path,false)))
691
+		{
692
+			// false = directory does not need to exists
641 693
 		{
642 694
 			return false;
643 695
 		}
696
+		}
644 697
 		// refuse to modify readonly target (eg. readonly share)
645 698
 		if (self::url_is_readonly($url))
646 699
 		{
@@ -652,7 +705,10 @@  discard block
 block discarded – undo
652 705
 			!($this->url_stat($parent_url, STREAM_URL_STAT_QUIET)) &&
653 706
 			Vfs::parse_url($parent_url, PHP_URL_PATH) !== '/')
654 707
 		{
655
-			if (!self::mkdir(Vfs::dirname($path), $mode, $options)) return false;
708
+			if (!self::mkdir(Vfs::dirname($path), $mode, $options))
709
+			{
710
+				return false;
711
+			}
656 712
 		}
657 713
 		// unset it now, as it was handled above
658 714
 		if (strpos($url, 'smb://') === 0)
@@ -736,13 +792,19 @@  discard block
 block discarded – undo
736 792
 
737 793
 		if (!($this->opened_dir_url = $this->resolve_url_symlinks($path)))
738 794
 		{
739
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."( $path,$options) resolve_url_symlinks() failed!");
795
+			if (self::LOG_LEVEL > 0)
796
+			{
797
+				error_log(__METHOD__."( $path,$options) resolve_url_symlinks() failed!");
798
+			}
740 799
 			return false;
741 800
 		}
742 801
 		if (!($this->opened_dir = $this->context ?
743 802
 			opendir($this->opened_dir_url, $this->context) : opendir($this->opened_dir_url)))
744 803
 		{
745
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."( $path,$options) opendir($this->opened_dir_url) failed!");
804
+			if (self::LOG_LEVEL > 0)
805
+			{
806
+				error_log(__METHOD__."( $path,$options) opendir($this->opened_dir_url) failed!");
807
+			}
746 808
 			return false;
747 809
 		}
748 810
 		$this->opened_dir_writable = Vfs::check_access($this->opened_dir_url,Vfs::WRITABLE);
@@ -760,7 +822,10 @@  discard block
 block discarded – undo
760 822
 		}
761 823
 
762 824
 
763
-		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());
825
+		if (self::LOG_LEVEL > 1)
826
+		{
827
+			error_log(__METHOD__."( $path,$options): opendir($this->opened_dir_url)=$this->opened_dir, extra_dirs=".array2string($this->extra_dirs).', '.function_backtrace());
828
+		}
764 829
 		return true;
765 830
 	}
766 831
 
@@ -796,7 +861,10 @@  discard block
 block discarded – undo
796 861
 	{
797 862
 		if (!($url = self::resolve_url($path,!($flags & STREAM_URL_STAT_LINK), $check_symlink_components)))
798 863
 		{
799
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$path',$flags) can NOT resolve path!");
864
+			if (self::LOG_LEVEL > 0)
865
+			{
866
+				error_log(__METHOD__."('$path',$flags) can NOT resolve path!");
867
+			}
800 868
 			return false;
801 869
 		}
802 870
 
@@ -813,18 +881,27 @@  discard block
 block discarded – undo
813 881
 				{
814 882
 					if (!$check_symlink_depth)
815 883
 					{
816
-						if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$path',$flags) maximum symlink depth exceeded, might be a circular symlink!");
884
+						if (self::LOG_LEVEL > 0)
885
+						{
886
+							error_log(__METHOD__."('$path',$flags) maximum symlink depth exceeded, might be a circular symlink!");
887
+						}
817 888
 						$stat = false;
818 889
 					}
819 890
 					elseif (($lpath = Vfs::readlink($url)))
820 891
 					{
821
-						if ($lpath[0] != '/')	// concat relative path
892
+						if ($lpath[0] != '/')
893
+						{
894
+							// concat relative path
822 895
 						{
823 896
 							$lpath = Vfs::concat(Vfs::parse_url($path,PHP_URL_PATH),'../'.$lpath);
824 897
 						}
898
+						}
825 899
 						$u_query = parse_url($url,PHP_URL_QUERY);
826 900
 						$url = Vfs::PREFIX.$lpath;
827
-						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");
901
+						if (self::LOG_LEVEL > 1)
902
+						{
903
+							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");
904
+						}
828 905
 						// try reading the stat of the link
829 906
 						if (($stat = $this->url_stat($lpath, STREAM_URL_STAT_QUIET, false, true, $check_symlink_depth-1)))
830 907
 						{
@@ -837,7 +914,11 @@  discard block
 block discarded – undo
837 914
 								$stat_query = http_build_query(array_merge($stat_query, $u_query));
838 915
 								$stat['url'] = $stat_url['scheme'].'://'.$stat_url['host'].$stat_url['path'].'?'.$stat_query;
839 916
 							}
840
-							if(isset($stat['url'])) $url = $stat['url'];	// if stat returns an url use that, as there might be more links ...
917
+							if(isset($stat['url']))
918
+							{
919
+								$url = $stat['url'];
920
+							}
921
+							// if stat returns an url use that, as there might be more links ...
841 922
 							self::symlinkCache_add($path,$url);
842 923
 						}
843 924
 					}
@@ -860,7 +941,9 @@  discard block
 block discarded – undo
860 941
 		// check if a failed url_stat was for a home dir, in that case silently create it
861 942
 		if (!$stat && $try_create_home && Vfs::dirname(Vfs::parse_url($path,PHP_URL_PATH)) == '/home' &&
862 943
 			($id = $GLOBALS['egw']->accounts->name2id(Vfs::basename($path))) &&
863
-			$GLOBALS['egw']->accounts->id2name($id) == Vfs::basename($path))	// make sure path has the right case!
944
+			$GLOBALS['egw']->accounts->id2name($id) == Vfs::basename($path))
945
+		{
946
+			// make sure path has the right case!
864 947
 		{
865 948
 			$hook_data = array(
866 949
 				'location' => $GLOBALS['egw']->accounts->get_type($id) == 'g' ? 'addgroup' : 'addaccount',
@@ -868,15 +951,22 @@  discard block
 block discarded – undo
868 951
 				'account_lid' => Vfs::basename($path),
869 952
 				'account_name' => Vfs::basename($path),
870 953
 			);
954
+		}
871 955
 			call_user_func(array(__NAMESPACE__.'\\Hooks',$hook_data['location']),$hook_data);
872 956
 			unset($hook_data);
873 957
 			$stat = $this->url_stat($path,$flags,false);
874 958
 		}
875 959
 		$query = parse_url($url, PHP_URL_QUERY);
876
-		if (!$stat && $check_symlink_components)	// check if there's a symlink somewhere inbetween the path
960
+		if (!$stat && $check_symlink_components)
961
+		{
962
+			// check if there's a symlink somewhere inbetween the path
877 963
 		{
878 964
 			$stat = self::check_symlink_components($path,$flags,$url);
879
-			if ($stat && isset($stat['url']) && !$query) self::symlinkCache_add($path,$stat['url']);
965
+		}
966
+			if ($stat && isset($stat['url']) && !$query)
967
+			{
968
+				self::symlinkCache_add($path,$stat['url']);
969
+			}
880 970
 		}
881 971
 		elseif(is_array($stat) && !isset($stat['url']))
882 972
 		{
@@ -891,7 +981,10 @@  discard block
 block discarded – undo
891 981
 			$stat['url'] .= '?'.$query;
892 982
 		}
893 983
 
894
-		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));
984
+		if (self::LOG_LEVEL > 1)
985
+		{
986
+			error_log(__METHOD__."('$path',$flags,try_create_home=$try_create_home,check_symlink_components=$check_symlink_components) returning ".array2string($stat));
987
+		}
895 988
 
896 989
 		return $stat;
897 990
 
@@ -917,10 +1010,16 @@  discard block
 block discarded – undo
917 1010
 	{
918 1011
 		if (is_null($url) && !($url = self::resolve_url($path)))
919 1012
 		{
920
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__."('$path',$flags,'$url') can NOT resolve path: ".function_backtrace(1));
1013
+			if (self::LOG_LEVEL > 0)
1014
+			{
1015
+				error_log(__METHOD__."('$path',$flags,'$url') can NOT resolve path: ".function_backtrace(1));
1016
+			}
921 1017
 			return false;
922 1018
 		}
923
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url'): ".function_backtrace(1));
1019
+		if (self::LOG_LEVEL > 1)
1020
+		{
1021
+			error_log(__METHOD__."('$path',$flags,'$url'): ".function_backtrace(1));
1022
+		}
924 1023
 
925 1024
 		while (($rel_path = Vfs::basename($url).($rel_path ? '/'.$rel_path : '')) &&
926 1025
 		       ($url = Vfs::dirname($url)))
@@ -929,7 +1028,10 @@  discard block
 block discarded – undo
929 1028
 			{
930 1029
 				if (is_link($url) && ($lpath = Vfs::readlink($url)))
931 1030
 				{
932
-					if (self::LOG_LEVEL > 1) $log = "rel_path='$rel_path', url='$url': lpath='$lpath'";
1031
+					if (self::LOG_LEVEL > 1)
1032
+					{
1033
+						$log = "rel_path='$rel_path', url='$url': lpath='$lpath'";
1034
+					}
933 1035
 
934 1036
 					if ($lpath[0] != '/')
935 1037
 					{
@@ -937,15 +1039,24 @@  discard block
 block discarded – undo
937 1039
 					}
938 1040
 					//self::symlinkCache_add($path,Vfs::PREFIX.$lpath);
939 1041
 					$url = Vfs::PREFIX.Vfs::concat($lpath,$rel_path);
940
-					if (self::LOG_LEVEL > 1) error_log("$log --> lpath='$lpath', url='$url'");
1042
+					if (self::LOG_LEVEL > 1)
1043
+					{
1044
+						error_log("$log --> lpath='$lpath', url='$url'");
1045
+					}
941 1046
 					return $this->url_stat($url,$flags);
942 1047
 				}
943 1048
 				$url = Vfs::concat($url,$rel_path);
944
-				if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning null");
1049
+				if (self::LOG_LEVEL > 1)
1050
+				{
1051
+					error_log(__METHOD__."('$path',$flags,'$url') returning null");
1052
+				}
945 1053
 				return null;
946 1054
 			}
947 1055
 		}
948
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."('$path',$flags,'$url') returning false");
1056
+		if (self::LOG_LEVEL > 1)
1057
+		{
1058
+			error_log(__METHOD__."('$path',$flags,'$url') returning false");
1059
+		}
949 1060
 		return false;	// $path does not exist
950 1061
 	}
951 1062
 
@@ -966,9 +1077,16 @@  discard block
 block discarded – undo
966 1077
 	{
967 1078
 		$path = self::get_path($_path);
968 1079
 
969
-		if (isset(self::$symlink_cache[$path])) return;	// nothing to do
1080
+		if (isset(self::$symlink_cache[$path]))
1081
+		{
1082
+			return;
1083
+		}
1084
+		// nothing to do
970 1085
 
971
-		if ($target[0] != '/') $target = Vfs::parse_url($target,PHP_URL_PATH);
1086
+		if ($target[0] != '/')
1087
+		{
1088
+			$target = Vfs::parse_url($target,PHP_URL_PATH);
1089
+		}
972 1090
 
973 1091
 		self::$symlink_cache[$path] = $target;
974 1092
 
@@ -977,7 +1095,10 @@  discard block
 block discarded – undo
977 1095
 		{
978 1096
 			return strlen($a) - strlen($b);
979 1097
 		});
980
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path,$target) cache now ".array2string(self::$symlink_cache));
1098
+		if (self::LOG_LEVEL > 1)
1099
+		{
1100
+			error_log(__METHOD__."($path,$target) cache now ".array2string(self::$symlink_cache));
1101
+		}
981 1102
 	}
982 1103
 
983 1104
 	/**
@@ -990,7 +1111,10 @@  discard block
 block discarded – undo
990 1111
 		$path = self::get_path($_path);
991 1112
 
992 1113
 		unset(self::$symlink_cache[$path]);
993
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."($path) cache now ".array2string(self::$symlink_cache));
1114
+		if (self::LOG_LEVEL > 1)
1115
+		{
1116
+			error_log(__METHOD__."($path) cache now ".array2string(self::$symlink_cache));
1117
+		}
994 1118
 	}
995 1119
 
996 1120
 	/**
@@ -1011,11 +1135,18 @@  discard block
 block discarded – undo
1011 1135
 
1012 1136
 		foreach(self::$symlink_cache as $p => $t)
1013 1137
 		{
1014
-			if (($strlen_p = strlen($p)) > $strlen_path) continue;	// $path can NOT start with $p
1138
+			if (($strlen_p = strlen($p)) > $strlen_path)
1139
+			{
1140
+				continue;
1141
+			}
1142
+			// $path can NOT start with $p
1015 1143
 
1016 1144
 			if ($path == $p)
1017 1145
 			{
1018
-				if ($do_symlink) $target = $t;
1146
+				if ($do_symlink)
1147
+				{
1148
+					$target = $t;
1149
+				}
1019 1150
 				break;
1020 1151
 			}
1021 1152
 			elseif (substr($path,0,$strlen_p+1) == $p.'/')
@@ -1024,7 +1155,10 @@  discard block
 block discarded – undo
1024 1155
 				break;
1025 1156
 			}
1026 1157
 		}
1027
-		if (self::LOG_LEVEL > 1 && isset($target)) error_log(__METHOD__."($path) = $target");
1158
+		if (self::LOG_LEVEL > 1 && isset($target))
1159
+		{
1160
+			error_log(__METHOD__."($path) = $target");
1161
+		}
1028 1162
 		return isset($target) ? $target : $path;
1029 1163
 	}
1030 1164
 
@@ -1065,7 +1199,10 @@  discard block
 block discarded – undo
1065 1199
 				self::HIDE_UNREADABLES && !$this->opened_dir_writable &&
1066 1200
 				!Vfs::check_access(Vfs::concat($this->opened_dir_url,$file),Vfs::READABLE)));
1067 1201
 		}
1068
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__."( $this->opened_dir ) = '$file'");
1202
+		if (self::LOG_LEVEL > 1)
1203
+		{
1204
+			error_log(__METHOD__."( $this->opened_dir ) = '$file'");
1205
+		}
1069 1206
 		return $file;
1070 1207
 	}
1071 1208
 
@@ -1168,7 +1305,10 @@  discard block
 block discarded – undo
1168 1305
 		) as $class)
1169 1306
 		{
1170 1307
 			//error_log(__METHOD__."('$scheme') class_exists('$class')=".array2string(class_exists($class)));
1171
-			if (class_exists($class))  return $class;
1308
+			if (class_exists($class))
1309
+			{
1310
+				return $class;
1311
+			}
1172 1312
 		}
1173 1313
 	}
1174 1314
 
@@ -1229,11 +1369,17 @@  discard block
 block discarded – undo
1229 1369
 	 */
1230 1370
 	static function mount($url=null,$path=null,$check_url=null,$persitent_mount=true,$clear_fstab=false)
1231 1371
 	{
1232
-		if (is_null($check_url)) $check_url = strpos($url,'$') === false;
1372
+		if (is_null($check_url))
1373
+		{
1374
+			$check_url = strpos($url,'$') === false;
1375
+		}
1233 1376
 
1234
-		if (!isset($GLOBALS['egw_info']['server']['vfs_fstab']))	// happens eg. in setup
1377
+		if (!isset($GLOBALS['egw_info']['server']['vfs_fstab']))
1378
+		{
1379
+			// happens eg. in setup
1235 1380
 		{
1236 1381
 			$api_config = Api\Config::read('phpgwapi');
1382
+		}
1237 1383
 			if (isset($api_config['vfs_fstab']) && is_array($api_config['vfs_fstab']))
1238 1384
 			{
1239 1385
 				self::$fstab = $api_config['vfs_fstab'];
@@ -1249,12 +1395,18 @@  discard block
 block discarded – undo
1249 1395
 		}
1250 1396
 		if (is_null($url) || is_null($path))
1251 1397
 		{
1252
-			if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') returns '.array2string(self::$fstab));
1398
+			if (self::LOG_LEVEL > 1)
1399
+			{
1400
+				error_log(__METHOD__.'('.array2string($url).','.array2string($path).') returns '.array2string(self::$fstab));
1401
+			}
1253 1402
 			return self::$fstab;
1254 1403
 		}
1255 1404
 		if (!Vfs::$is_root)
1256 1405
 		{
1257
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') permission denied, you are NOT root!');
1406
+			if (self::LOG_LEVEL > 0)
1407
+			{
1408
+				error_log(__METHOD__.'('.array2string($url).','.array2string($path).') permission denied, you are NOT root!');
1409
+			}
1258 1410
 			return false;	// only root can mount
1259 1411
 		}
1260 1412
 		if ($clear_fstab)
@@ -1263,14 +1415,20 @@  discard block
 block discarded – undo
1263 1415
 		}
1264 1416
 		if (isset(self::$fstab[$path]) && self::$fstab[$path] === $url)
1265 1417
 		{
1266
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') already mounted.');
1418
+			if (self::LOG_LEVEL > 0)
1419
+			{
1420
+				error_log(__METHOD__.'('.array2string($url).','.array2string($path).') already mounted.');
1421
+			}
1267 1422
 			return true;	// already mounted
1268 1423
 		}
1269 1424
 		self::load_wrapper(Vfs::parse_url($url,PHP_URL_SCHEME));
1270 1425
 
1271 1426
 		if ($check_url && (!file_exists($url) || opendir($url) === false))
1272 1427
 		{
1273
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') url does NOT exist!');
1428
+			if (self::LOG_LEVEL > 0)
1429
+			{
1430
+				error_log(__METHOD__.'('.array2string($url).','.array2string($path).') url does NOT exist!');
1431
+			}
1274 1432
 			return false;	// url does not exist
1275 1433
 		}
1276 1434
 		self::$fstab[$path] = $url;
@@ -1285,12 +1443,18 @@  discard block
 block discarded – undo
1285 1443
 			Api\Config::save_value('vfs_fstab',self::$fstab,'phpgwapi');
1286 1444
 			$GLOBALS['egw_info']['server']['vfs_fstab'] = self::$fstab;
1287 1445
 			// invalidate session cache
1288
-			if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
1446
+			if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))
1447
+			{
1448
+				// egw object in setup is limited
1289 1449
 			{
1290 1450
 				$GLOBALS['egw']->invalidate_session_cache();
1291 1451
 			}
1452
+			}
1453
+		}
1454
+		if (self::LOG_LEVEL > 1)
1455
+		{
1456
+			error_log(__METHOD__.'('.array2string($url).','.array2string($path).') returns true (successful new mount).');
1292 1457
 		}
1293
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($url).','.array2string($path).') returns true (successful new mount).');
1294 1458
 		return true;
1295 1459
 	}
1296 1460
 
@@ -1303,12 +1467,18 @@  discard block
 block discarded – undo
1303 1467
 	{
1304 1468
 		if (!Vfs::$is_root)
1305 1469
 		{
1306
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($path).','.array2string($path).') permission denied, you are NOT root!');
1470
+			if (self::LOG_LEVEL > 0)
1471
+			{
1472
+				error_log(__METHOD__.'('.array2string($path).','.array2string($path).') permission denied, you are NOT root!');
1473
+			}
1307 1474
 			return false;	// only root can mount
1308 1475
 		}
1309 1476
 		if (!isset(self::$fstab[$path]) && ($path = array_search($path,self::$fstab)) === false)
1310 1477
 		{
1311
-			if (self::LOG_LEVEL > 0) error_log(__METHOD__.'('.array2string($path).') NOT mounted!');
1478
+			if (self::LOG_LEVEL > 0)
1479
+			{
1480
+				error_log(__METHOD__.'('.array2string($path).') NOT mounted!');
1481
+			}
1312 1482
 			return false;	// $path not mounted
1313 1483
 		}
1314 1484
 		unset(self::$fstab[$path]);
@@ -1316,11 +1486,17 @@  discard block
 block discarded – undo
1316 1486
 		Api\Config::save_value('vfs_fstab',self::$fstab,'phpgwapi');
1317 1487
 		$GLOBALS['egw_info']['server']['vfs_fstab'] = self::$fstab;
1318 1488
 		// invalidate session cache
1319
-		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))	// egw object in setup is limited
1489
+		if (method_exists($GLOBALS['egw'],'invalidate_session_cache'))
1490
+		{
1491
+			// egw object in setup is limited
1320 1492
 		{
1321 1493
 			$GLOBALS['egw']->invalidate_session_cache();
1322 1494
 		}
1323
-		if (self::LOG_LEVEL > 1) error_log(__METHOD__.'('.array2string($path).') returns true (successful unmount).');
1495
+		}
1496
+		if (self::LOG_LEVEL > 1)
1497
+		{
1498
+			error_log(__METHOD__.'('.array2string($path).') returns true (successful unmount).');
1499
+		}
1324 1500
 		return true;
1325 1501
 	}
1326 1502
 
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
-	function unlink ( $path );
146
+	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
-	function rename ( $path_from, $path_to );
160
+	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
-	function mkdir ( $path, $mode, $options );
173
+	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
-	function rmdir ( $path, $options );
185
+	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
-	function url_stat ( $path, $flags );
221
+	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.
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.
Indentation   +196 added lines, -196 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,117 +110,117 @@  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 .= Vfs::basename($source);
203
-                if (file_exists($dest)) {
204
-                    $options["dest"] .= Vfs::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) {
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 .= Vfs::basename($source);
203
+				if (file_exists($dest)) {
204
+					$options["dest"] .= Vfs::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 224
 			try {
225 225
 				if (!rename($source, $dest)) {
226 226
 					return "500 Internal server error";
@@ -229,51 +229,51 @@  discard block
 block discarded – undo
229 229
 			catch (Exception\ProtectedDirectory $e) {
230 230
 				return "403 Forbidden: ".$e->getMessage();
231 231
 			}
232
-        } else {
233
-            if (is_dir($source) && $options['depth'] == 'infinity') {
234
-            	$files = Vfs::find($source,array('depth' => true,'url' => true));	// depth=true: return dirs first, url=true: allow urls!
235
-            } else {
236
-                $files = array($source);
237
-            }
238
-
239
-            if (!is_array($files) || empty($files)) {
240
-                return "500 Internal server error";
241
-            }
242
-
243
-
244
-            foreach ($files as $file) {
245
-                if (is_dir($file)) {
246
-                    $file = $this->_slashify($file);
247
-                }
248
-
249
-                $destfile = str_replace($source, $dest, $file);
250
-
251
-                if (is_dir($file)) {
252
-                    if (!is_dir($destfile)) {
253
-                        // TODO "mkdir -p" here? (only natively supported by PHP 5)
254
-                        if (!@mkdir($destfile)) {
255
-                            return "409 Conflict";
256
-                        }
257
-                    }
258
-                } else {
259
-                    if (!@copy($file, $destfile)) {
260
-                        return "409 Conflict";
261
-                    }
262
-                }
263
-            }
264
-        }
265
-        // adding Location header as shown in example in rfc2518 section 8.9.5
232
+		} else {
233
+			if (is_dir($source) && $options['depth'] == 'infinity') {
234
+				$files = Vfs::find($source,array('depth' => true,'url' => true));	// depth=true: return dirs first, url=true: allow urls!
235
+			} else {
236
+				$files = array($source);
237
+			}
238
+
239
+			if (!is_array($files) || empty($files)) {
240
+				return "500 Internal server error";
241
+			}
242
+
243
+
244
+			foreach ($files as $file) {
245
+				if (is_dir($file)) {
246
+					$file = $this->_slashify($file);
247
+				}
248
+
249
+				$destfile = str_replace($source, $dest, $file);
250
+
251
+				if (is_dir($file)) {
252
+					if (!is_dir($destfile)) {
253
+						// TODO "mkdir -p" here? (only natively supported by PHP 5)
254
+						if (!@mkdir($destfile)) {
255
+							return "409 Conflict";
256
+						}
257
+					}
258
+				} else {
259
+					if (!@copy($file, $destfile)) {
260
+						return "409 Conflict";
261
+					}
262
+				}
263
+			}
264
+		}
265
+		// adding Location header as shown in example in rfc2518 section 8.9.5
266 266
 		header('Location: '.$this->base_uri.$options['dest']);
267 267
 
268
-        return ($new && !$existing_col) ? "201 Created" : "204 No Content";
269
-    }
268
+		return ($new && !$existing_col) ? "201 Created" : "204 No Content";
269
+	}
270 270
 
271
-    /**
272
-	* Get properties for a single file/resource
273
-	*
274
-	* @param  string  $_path resource path
275
-	* @return array   resource properties
276
-	*/
271
+	/**
272
+	 * Get properties for a single file/resource
273
+	 *
274
+	 * @param  string  $_path resource path
275
+	 * @return array   resource properties
276
+	 */
277 277
 	function fileinfo($_path)
278 278
 	{
279 279
 		// internally we require some url-encoding, as vfs_stream_wrapper uses URL's internally
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
 		$info['props'][] = self::mkprop	('creationdate',    filectime($fspath));
302 302
 		$info['props'][] = self::mkprop	('getlastmodified', filemtime($fspath));
303 303
 
304
-        // Microsoft extensions: last access time and 'hidden' status
305
-        $info["props"][] = self::mkprop("lastaccessed",    fileatime($fspath));
306
-        $info["props"][] = self::mkprop("ishidden",        Vfs::is_hidden($fspath));
304
+		// Microsoft extensions: last access time and 'hidden' status
305
+		$info["props"][] = self::mkprop("lastaccessed",    fileatime($fspath));
306
+		$info["props"][] = self::mkprop("ishidden",        Vfs::is_hidden($fspath));
307 307
 
308 308
 		// type and size (caller already made sure that path exists)
309 309
 		if (is_dir($fspath)) {
@@ -441,38 +441,38 @@  discard block
 block discarded – undo
441 441
 	}
442 442
 
443 443
  	/**
444
-	 * Used eg. by get
445
-	 *
446
-	 * @todo replace all calls to _mimetype with Vfs::mime_content_type()
447
-	 * @param string $path
448
-	 * @return string
449
-	 */
444
+ 	 * Used eg. by get
445
+ 	 *
446
+ 	 * @todo replace all calls to _mimetype with Vfs::mime_content_type()
447
+ 	 * @param string $path
448
+ 	 * @return string
449
+ 	 */
450 450
 	function _mimetype($path)
451 451
 	{
452 452
 		return Vfs::mime_content_type($path);
453 453
 	}
454 454
 
455
-    /**
456
-     * Check if path is readable by current user
457
-     *
458
-     * @param string $fspath
459
-     * @return boolean
460
-     */
461
-    function _is_readable($fspath)
462
-    {
463
-    	return Vfs::is_readable($fspath);
464
-    }
465
-
466
-    /**
467
-     * Check if path is writable by current user
468
-     *
469
-     * @param string $fspath
470
-     * @return boolean
471
-     */
472
-    function _is_writable($fspath)
473
-    {
474
-    	return Vfs::is_writable($fspath);
475
-    }
455
+	/**
456
+	 * Check if path is readable by current user
457
+	 *
458
+	 * @param string $fspath
459
+	 * @return boolean
460
+	 */
461
+	function _is_readable($fspath)
462
+	{
463
+		return Vfs::is_readable($fspath);
464
+	}
465
+
466
+	/**
467
+	 * Check if path is writable by current user
468
+	 *
469
+	 * @param string $fspath
470
+	 * @return boolean
471
+	 */
472
+	function _is_writable($fspath)
473
+	{
474
+		return Vfs::is_writable($fspath);
475
+	}
476 476
 
477 477
 	/**
478 478
 	 * PROPPATCH method handler
@@ -615,13 +615,13 @@  discard block
 block discarded – undo
615 615
 	 * @param  string  directory path
616 616
 	 * @return void    function has to handle HTTP response itself
617 617
 	 */
618
-    function GetDir($fspath, &$options)
619
-    {
618
+	function GetDir($fspath, &$options)
619
+	{
620 620
 		// add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv)
621 621
 		header('Content-type: text/html; charset='.Api\Translation::charset());
622 622
 
623 623
 		parent::GetDir($fspath, $options);
624
-    }
624
+	}
625 625
 
626 626
 	private $force_download = false;
627 627
 
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)) {
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 			}
232 232
         } else {
233 233
             if (is_dir($source) && $options['depth'] == 'infinity') {
234
-            	$files = Vfs::find($source,array('depth' => true,'url' => true));	// depth=true: return dirs first, url=true: allow urls!
234
+            	$files = Vfs::find($source, array('depth' => true, 'url' => true)); // depth=true: return dirs first, url=true: allow urls!
235 235
             } else {
236 236
                 $files = array($source);
237 237
             }
@@ -277,16 +277,16 @@  discard block
 block discarded – undo
277 277
 	function fileinfo($_path)
278 278
 	{
279 279
 		// internally we require some url-encoding, as vfs_stream_wrapper uses URL's internally
280
-		$path = str_replace(array('#','?'),array('%23','%3F'),$_path);
280
+		$path = str_replace(array('#', '?'), array('%23', '%3F'), $_path);
281 281
 
282 282
 		//error_log(__METHOD__."($path)");
283 283
 		// map URI path to filesystem path
284
-		$fspath = $this->base . $path;
284
+		$fspath = $this->base.$path;
285 285
 
286 286
 		// create result array
287 287
 		$info = array();
288 288
 		// TODO remove slash append code when base class is able to do it itself
289
-		$info['path']  = is_dir($fspath) ? $this->_slashify($path) : $path;
289
+		$info['path'] = is_dir($fspath) ? $this->_slashify($path) : $path;
290 290
 
291 291
 		// remove all urlencoding we need internally in EGw, HTTP_WebDAV_Server will add it's own!
292 292
 		// rawurldecode does NOT touch +
@@ -295,32 +295,32 @@  discard block
 block discarded – undo
295 295
 		$info['props'] = array();
296 296
 
297 297
 		// no special beautified displayname here ...
298
-		$info['props'][] = self::mkprop	('displayname', Vfs::basename(self::_unslashify($info['path'])));
298
+		$info['props'][] = self::mkprop('displayname', Vfs::basename(self::_unslashify($info['path'])));
299 299
 
300 300
 		// creation and modification time
301
-		$info['props'][] = self::mkprop	('creationdate',    filectime($fspath));
302
-		$info['props'][] = self::mkprop	('getlastmodified', filemtime($fspath));
301
+		$info['props'][] = self::mkprop('creationdate', filectime($fspath));
302
+		$info['props'][] = self::mkprop('getlastmodified', filemtime($fspath));
303 303
 
304 304
         // Microsoft extensions: last access time and 'hidden' status
305
-        $info["props"][] = self::mkprop("lastaccessed",    fileatime($fspath));
306
-        $info["props"][] = self::mkprop("ishidden",        Vfs::is_hidden($fspath));
305
+        $info["props"][] = self::mkprop("lastaccessed", fileatime($fspath));
306
+        $info["props"][] = self::mkprop("ishidden", Vfs::is_hidden($fspath));
307 307
 
308 308
 		// type and size (caller already made sure that path exists)
309 309
 		if (is_dir($fspath)) {
310 310
 			// directory (WebDAV collection)
311
-			$info['props'][] = self::mkprop	('resourcetype', array(
311
+			$info['props'][] = self::mkprop('resourcetype', array(
312 312
 			 	self::mkprop('collection', '')));
313
-			$info['props'][] = self::mkprop	('getcontenttype', 'httpd/unix-directory');
313
+			$info['props'][] = self::mkprop('getcontenttype', 'httpd/unix-directory');
314 314
 		} else {
315 315
 			// plain file (WebDAV resource)
316
-			$info['props'][] = self::mkprop	('resourcetype', '');
316
+			$info['props'][] = self::mkprop('resourcetype', '');
317 317
 			if (Vfs::is_readable($path)) {
318
-				$info['props'][] = self::mkprop	('getcontenttype', Vfs::mime_content_type($path));
318
+				$info['props'][] = self::mkprop('getcontenttype', Vfs::mime_content_type($path));
319 319
 			} else {
320 320
 				error_log(__METHOD__."($path) $fspath is not readable!");
321
-				$info['props'][] = self::mkprop	('getcontenttype', 'application/x-non-readable');
321
+				$info['props'][] = self::mkprop('getcontenttype', 'application/x-non-readable');
322 322
 			}
323
-			$info['props'][] = self::mkprop	('getcontentlength', filesize($fspath));
323
+			$info['props'][] = self::mkprop('getcontentlength', filesize($fspath));
324 324
 		}
325 325
 		// generate etag from inode (sqlfs: fs_id), modification time and size
326 326
 		$stat = stat($fspath);
@@ -374,21 +374,21 @@  discard block
 block discarded – undo
374 374
 	 */
375 375
 	function PROPFIND(&$options, &$files)
376 376
 	{
377
-		if (!parent::PROPFIND($options,$files))
377
+		if (!parent::PROPFIND($options, $files))
378 378
 		{
379 379
 			return false;
380 380
 		}
381 381
 		$path2n = array();
382
-		foreach($files['files'] as $n => $info)
382
+		foreach ($files['files'] as $n => $info)
383 383
 		{
384 384
 			// do NOT report /clientsync/.favorites/, as it fails
385
-			if (strpos($info['path'],'/clientsync/.favorites/') === 0)
385
+			if (strpos($info['path'], '/clientsync/.favorites/') === 0)
386 386
 			{
387 387
 				unset($files['files'][$n]);
388 388
 				continue;
389 389
 			}
390 390
 			$_path = $info['path'];
391
-			if (!$n && $info['path'] != '/' && substr($info['path'],-1) == '/') $_path = substr($info['path'],0,-1);
391
+			if (!$n && $info['path'] != '/' && substr($info['path'], -1) == '/') $_path = substr($info['path'], 0, -1);
392 392
 
393 393
 			// need to encode path again, as $info['path'] is NOT encoded, but Vfs::(stat|propfind) require it
394 394
 			// otherwise pathes containing url special chars like ? or # will not stat
@@ -398,21 +398,21 @@  discard block
 block discarded – undo
398 398
 			// adding some properties used instead of regular DAV times
399 399
 			if (($stat = Vfs::stat($path)))
400 400
 			{
401
-				$fileprops =& $files['files'][$path2n[$path]]['props'];
402
-				foreach(self::$auto_props as $attr => $props)
401
+				$fileprops = & $files['files'][$path2n[$path]]['props'];
402
+				foreach (self::$auto_props as $attr => $props)
403 403
 				{
404
-					switch($attr)
404
+					switch ($attr)
405 405
 					{
406 406
 						case 'ctime':
407 407
 						case 'mtime':
408 408
 						case 'atime':
409
-							$value = gmdate('D, d M Y H:i:s T',$stat[$attr]);
409
+							$value = gmdate('D, d M Y H:i:s T', $stat[$attr]);
410 410
 							break;
411 411
 
412 412
 						default:
413 413
 							continue 2;
414 414
 					}
415
-					foreach($props as $prop)
415
+					foreach ($props as $prop)
416 416
 					{
417 417
 						$prop['val'] = $value;
418 418
 						$fileprops[] = $prop;
@@ -420,17 +420,17 @@  discard block
 block discarded – undo
420 420
 				}
421 421
 			}
422 422
 		}
423
-		if ($path2n && ($path2props = Vfs::propfind(array_keys($path2n),null)))
423
+		if ($path2n && ($path2props = Vfs::propfind(array_keys($path2n), null)))
424 424
 		{
425
-			foreach($path2props as $path => $props)
425
+			foreach ($path2props as $path => $props)
426 426
 			{
427
-				$fileprops =& $files['files'][$path2n[$path]]['props'];
428
-				foreach($props as $prop)
427
+				$fileprops = & $files['files'][$path2n[$path]]['props'];
428
+				foreach ($props as $prop)
429 429
 				{
430 430
 					if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'][0] == '#')	// eGW's customfields
431 431
 					{
432 432
 						$prop['ns'] .= 'customfields/';
433
-						$prop['name'] = substr($prop['name'],1);
433
+						$prop['name'] = substr($prop['name'], 1);
434 434
 					}
435 435
 					$fileprops[] = $prop;
436 436
 				}
@@ -486,36 +486,36 @@  discard block
 block discarded – undo
486 486
 	 */
487 487
 	function PROPPATCH(&$options)
488 488
 	{
489
-		$path = Api\Translation::convert($options['path'],'utf-8');
489
+		$path = Api\Translation::convert($options['path'], 'utf-8');
490 490
 
491 491
 		foreach ($options['props'] as $key => $prop) {
492 492
 			$attributes = array();
493
-			switch($prop['ns'])
493
+			switch ($prop['ns'])
494 494
 			{
495 495
 				// allow Webdrive to set creation and modification time
496 496
 				case 'http://www.southrivertech.com/':
497
-					switch($prop['name'])
497
+					switch ($prop['name'])
498 498
 					{
499 499
 						case 'srt_modifiedtime':
500 500
 						case 'getlastmodified':
501
-							Vfs::touch($path,strtotime($prop['val']));
501
+							Vfs::touch($path, strtotime($prop['val']));
502 502
 							break;
503 503
 						//case 'srt_creationtime':
504 504
 							// no streamwrapper interface / php function to set the ctime currently
505 505
 							//$attributes['created'] = strtotime($prop['val']);
506 506
 							//break;
507 507
 						default:
508
-							if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
508
+							if (!Vfs::proppatch($path, array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
509 509
 							break;
510 510
 					}
511 511
 					break;
512 512
 
513 513
 				case 'DAV:':
514
-					switch($prop['name'])
514
+					switch ($prop['name'])
515 515
 					{
516 516
 						// allow netdrive to change the modification time
517 517
 						case 'getlastmodified':
518
-							Vfs::touch($path,strtotime($prop['val']));
518
+							Vfs::touch($path, strtotime($prop['val']));
519 519
 							break;
520 520
 						// not sure why, the filesystem example of the WebDAV class does it ...
521 521
 						default:
@@ -525,16 +525,16 @@  discard block
 block discarded – undo
525 525
 					break;
526 526
 
527 527
 				case 'urn:schemas-microsoft-com:':
528
-					switch($prop['name'])
528
+					switch ($prop['name'])
529 529
 					{
530 530
 						case 'Win32LastModifiedTime':
531
-							Vfs::touch($path,strtotime($prop['val']));
531
+							Vfs::touch($path, strtotime($prop['val']));
532 532
 							break;
533 533
 						case 'Win32CreationTime':	// eg. "Wed, 14 Sep 2011 15:48:26 GMT"
534 534
 						case 'Win32LastAccessTime':
535 535
 						case 'Win32FileAttributes':	// not sure what that is, it was always "00000000"
536 536
 						default:
537
-							if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
537
+							if (!Vfs::proppatch($path, array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
538 538
 							break;
539 539
 					}
540 540
 					break;
@@ -544,18 +544,18 @@  discard block
 block discarded – undo
544 544
 					$prop['name'] = '#'.$prop['name'];
545 545
 					// fall through
546 546
 				default:
547
-					if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
547
+					if (!Vfs::proppatch($path, array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
548 548
 					break;
549 549
 			}
550 550
 			if ($this->debug) $props[] = '('.$prop['ns'].')'.$prop['name'].'='.$prop['val'];
551 551
 		}
552 552
 		if ($this->debug)
553 553
 		{
554
-			error_log(__METHOD__.": path=$options[path], props=".implode(', ',$props));
555
-			if ($attributes) error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n",' ',print_r($attributes,true)));
554
+			error_log(__METHOD__.": path=$options[path], props=".implode(', ', $props));
555
+			if ($attributes) error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n", ' ', print_r($attributes, true)));
556 556
 		}
557 557
 
558
-		return '';	// this is as the filesystem example handler does it, no true or false ...
558
+		return ''; // this is as the filesystem example handler does it, no true or false ...
559 559
 	}
560 560
 
561 561
 	/**
@@ -566,18 +566,18 @@  discard block
 block discarded – undo
566 566
 	 */
567 567
 	function LOCK(&$options)
568 568
 	{
569
-		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
569
+		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n", '    '), '', print_r($options, true)).')');
570 570
 		// TODO recursive locks on directories not supported yet
571
-		if (is_dir($this->base . $options['path']) && !empty($options['depth']))
571
+		if (is_dir($this->base.$options['path']) && !empty($options['depth']))
572 572
 		{
573 573
 			return '409 Conflict';
574 574
 		}
575
-		$options['timeout'] = time()+300; // 5min. hardcoded
575
+		$options['timeout'] = time() + 300; // 5min. hardcoded
576 576
 
577 577
 		// dont know why, but HTTP_WebDAV_Server passes the owner in D:href tags, which get's passed unchanged to checkLock/PROPFIND
578 578
 		// that's wrong according to the standard and cadaver does not show it on discover --> strip_tags removes eventual tags
579
-		if (($ret = Vfs::lock($options['path'],$options['locktoken'],$options['timeout'],strip_tags($options['owner']),
580
-			$options['scope'],$options['type'],isset($options['update']))) && !isset($options['update']))
579
+		if (($ret = Vfs::lock($options['path'], $options['locktoken'], $options['timeout'], strip_tags($options['owner']),
580
+			$options['scope'], $options['type'], isset($options['update']))) && !isset($options['update']))
581 581
 		{
582 582
 			return $ret ? '200 OK' : '409 Conflict';
583 583
 		}
@@ -592,8 +592,8 @@  discard block
 block discarded – undo
592 592
 	 */
593 593
 	function UNLOCK(&$options)
594 594
 	{
595
-		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
596
-		return Vfs::unlock($options['path'],$options['token']) ? '204 No Content' : '409 Conflict';
595
+		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n", '    '), '', print_r($options, true)).')');
596
+		return Vfs::unlock($options['path'], $options['token']) ? '204 No Content' : '409 Conflict';
597 597
 	}
598 598
 
599 599
 	/**
@@ -632,9 +632,9 @@  discard block
 block discarded – undo
632 632
 	 */
633 633
 	function __construct()
634 634
 	{
635
-		if ($_SERVER['REQUEST_METHOD'] == 'GET' && (($this->force_download = strpos($_SERVER['REQUEST_URI'],'?download')) !== false))
635
+		if ($_SERVER['REQUEST_METHOD'] == 'GET' && (($this->force_download = strpos($_SERVER['REQUEST_URI'], '?download')) !== false))
636 636
 		{
637
-			$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'],0,$this->force_download);
637
+			$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $this->force_download);
638 638
 		}
639 639
 		parent::__construct();
640 640
 	}
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 	 */
650 650
 	function GET(&$options)
651 651
 	{
652
-		if (is_dir($this->base . $options["path"]))
652
+		if (is_dir($this->base.$options["path"]))
653 653
 		{
654 654
 			return $this->autoindex($options);
655 655
 		}
@@ -657,11 +657,11 @@  discard block
 block discarded – undo
657 657
 		{
658 658
 			// mitigate risks of serving javascript or css from our domain
659 659
 			Api\Header\Content::safe($options['stream'], $options['path'], $options['mimetype'], $options['size'], false,
660
-				$this->force_download, true);	// true = do not send content-type and content-length header, but modify values
660
+				$this->force_download, true); // true = do not send content-type and content-length header, but modify values
661 661
 
662 662
 			if (!is_resource($options['stream']))
663 663
 			{
664
-				$options['data'] =& $options['stream'];
664
+				$options['data'] = & $options['stream'];
665 665
 				unset($options['stream']);
666 666
 			}
667 667
 		}
@@ -680,9 +680,9 @@  discard block
 block discarded – undo
680 680
 			'depth' => 1,
681 681
 		);
682 682
 		$files = array();
683
-		if (($ret = $this->PROPFIND($propfind_options,$files)) !== true)
683
+		if (($ret = $this->PROPFIND($propfind_options, $files)) !== true)
684 684
 		{
685
-			return $ret;	// no collection
685
+			return $ret; // no collection
686 686
 		}
687 687
 		header('Content-type: text/html; charset='.Api\Translation::charset());
688 688
 		echo "<html>\n<head>\n\t<title>".'EGroupware WebDAV server '.htmlspecialchars($options['path'])."</title>\n";
@@ -694,10 +694,10 @@  discard block
 block discarded – undo
694 694
 		echo '<h1>WebDAV ';
695 695
 		list(,$base) = explode(parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH), $this->base_uri, 2);
696 696
 		$path = $base;
697
-		foreach(explode('/',$this->_unslashify($options['path'])) as $n => $name)
697
+		foreach (explode('/', $this->_unslashify($options['path'])) as $n => $name)
698 698
 		{
699 699
 			$path .= ($n != 1 ? '/' : '').$name;
700
-			echo Api\Html::a_href(htmlspecialchars($name.'/'),$path);
700
+			echo Api\Html::a_href(htmlspecialchars($name.'/'), $path);
701 701
 		}
702 702
 		echo "</h1>\n";
703 703
 
@@ -714,18 +714,18 @@  discard block
 block discarded – undo
714 714
 		);
715 715
 		$n = 0;
716 716
 		$collection_props = null;
717
-		foreach($files['files'] as $file)
717
+		foreach ($files['files'] as $file)
718 718
 		{
719 719
 			if (!isset($collection_props))
720 720
 			{
721 721
 				$collection_props = $this->props2array($file['props']);
722 722
 				echo '<h3>'.lang('Collection listing').': '.htmlspecialchars($collection_props['DAV:displayname'])."</h3>\n";
723
-				continue;	// own entry --> displaying properies later
723
+				continue; // own entry --> displaying properies later
724 724
 			}
725
-			if(!$n++)
725
+			if (!$n++)
726 726
 			{
727 727
 				echo "<table>\n\t<tr class='th'>\n\t\t<th>#</th>\n\t\t<th>".lang('Name')."</th>";
728
-				foreach($props2show as $label)
728
+				foreach ($props2show as $label)
729 729
 				{
730 730
 					echo "\t\t<th>".lang($label)."</th>\n";
731 731
 				}
@@ -735,9 +735,9 @@  discard block
 block discarded – undo
735 735
 			//echo $file['path']; _debug_array($props);
736 736
 			$class = $class == 'row_on' ? 'row_off' : 'row_on';
737 737
 
738
-			if (substr($file['path'],-1) == '/')
738
+			if (substr($file['path'], -1) == '/')
739 739
 			{
740
-				$name = Vfs::basename(substr($file['path'],0,-1)).'/';
740
+				$name = Vfs::basename(substr($file['path'], 0, -1)).'/';
741 741
 			}
742 742
 			else
743 743
 			{
@@ -745,14 +745,14 @@  discard block
 block discarded – undo
745 745
 			}
746 746
 
747 747
 			echo "\t<tr class='$class'>\n\t\t<td>$n</td>\n\t\t<td>".
748
-				Api\Html::a_href(htmlspecialchars($name),$base.strtr($file['path'], array(
748
+				Api\Html::a_href(htmlspecialchars($name), $base.strtr($file['path'], array(
749 749
 					'%' => '%25',
750 750
 					'#' => '%23',
751 751
 					'?' => '%3F',
752 752
 				)))."</td>\n";
753
-			foreach($props2show as $prop => $label)
753
+			foreach ($props2show as $prop => $label)
754 754
 			{
755
-				echo "\t\t<td>".($prop=='DAV:getlastmodified'&&!empty($props[$prop])?date('Y-m-d H:i:s',$props[$prop]):$props[$prop])."</td>\n";
755
+				echo "\t\t<td>".($prop == 'DAV:getlastmodified' && !empty($props[$prop]) ?date('Y-m-d H:i:s', $props[$prop]) : $props[$prop])."</td>\n";
756 756
 			}
757 757
 			echo "\t</tr>\n";
758 758
 		}
@@ -766,12 +766,12 @@  discard block
 block discarded – undo
766 766
 		}
767 767
 		echo '<h3>'.lang('Properties')."</h3>\n";
768 768
 		echo "<table>\n\t<tr class='th'><th>".lang('Namespace')."</th><th>".lang('Name')."</th><th>".lang('Value')."</th></tr>\n";
769
-		foreach($collection_props as $name => $value)
769
+		foreach ($collection_props as $name => $value)
770 770
 		{
771 771
 			$class = $class == 'row_on' ? 'row_off' : 'row_on';
772
-			$parts = explode(':',$name);
772
+			$parts = explode(':', $name);
773 773
 			$name = array_pop($parts);
774
-			$ns = implode(':',$parts);
774
+			$ns = implode(':', $parts);
775 775
 			echo "\t<tr class='$class'>\n\t\t<td>".htmlspecialchars($ns)."</td><td style='white-space: nowrap'>".htmlspecialchars($name)."</td>\n";
776 776
 			echo "\t\t<td>".$value."</td>\n\t</tr>\n";
777 777
 		}
@@ -814,11 +814,11 @@  discard block
 block discarded – undo
814 814
 				'wrap'            => 0,
815 815
 			));
816 816
 		}
817
-		if (($href=preg_match('/\<(D:)?href\>[^<]+\<\/(D:)?href\>/i',$value)))
817
+		if (($href = preg_match('/\<(D:)?href\>[^<]+\<\/(D:)?href\>/i', $value)))
818 818
 		{
819
-			$value = preg_replace('/\<(D:)?href\>('.preg_quote($this->base_uri.'/','/').')?([^<]+)\<\/(D:)?href\>/i','<\\1href><a href="\\2\\3">\\3</a></\\4href>',$value);
819
+			$value = preg_replace('/\<(D:)?href\>('.preg_quote($this->base_uri.'/', '/').')?([^<]+)\<\/(D:)?href\>/i', '<\\1href><a href="\\2\\3">\\3</a></\\4href>', $value);
820 820
 		}
821
-		$ret = $value[0] == '<'  || strpos($value, "\n") !== false ?
821
+		$ret = $value[0] == '<' || strpos($value, "\n") !== false ?
822 822
 			'<pre>'.htmlspecialchars($value).'</pre>' : htmlspecialchars($value);
823 823
 
824 824
 		if ($href)
@@ -838,10 +838,10 @@  discard block
 block discarded – undo
838 838
 	protected function props2array(array $props)
839 839
 	{
840 840
 		$arr = array();
841
-		foreach($props as $prop)
841
+		foreach ($props as $prop)
842 842
 		{
843 843
 			$ns_hash = array('DAV:' => 'D');
844
-			switch($prop['ns'])
844
+			switch ($prop['ns'])
845 845
 			{
846 846
 				case 'DAV:';
847 847
 					$ns = 'DAV';
@@ -851,10 +851,10 @@  discard block
 block discarded – undo
851 851
 			}
852 852
 			if (is_array($prop['val']))
853 853
 			{
854
-				$prop['val'] = $this->_hierarchical_prop_encode($prop['val'], $prop['ns'], $ns_defs='', $ns_hash);
854
+				$prop['val'] = $this->_hierarchical_prop_encode($prop['val'], $prop['ns'], $ns_defs = '', $ns_hash);
855 855
 				// hack to show real namespaces instead of not (visibly) defined shortcuts
856 856
 				unset($ns_hash['DAV:']);
857
-				$value = strtr($v=$this->prop_value($prop['val']),array_flip($ns_hash));
857
+				$value = strtr($v = $this->prop_value($prop['val']), array_flip($ns_hash));
858 858
 			}
859 859
 			else
860 860
 			{
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,76 +205,104 @@  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 .= Vfs::basename($source);
203
-                if (file_exists($dest)) {
225
+                if (file_exists($dest))
226
+                {
204 227
                     $options["dest"] .= Vfs::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) {
253
+        if ($del)
254
+        {
224 255
 			try {
225
-				if (!rename($source, $dest)) {
256
+				if (!rename($source, $dest))
257
+				{
226 258
 					return "500 Internal server error";
227 259
 				}
228 260
 			}
229 261
 			catch (Exception\ProtectedDirectory $e) {
230 262
 				return "403 Forbidden: ".$e->getMessage();
231 263
 			}
232
-        } else {
233
-            if (is_dir($source) && $options['depth'] == 'infinity') {
264
+        }
265
+        else
266
+        {
267
+            if (is_dir($source) && $options['depth'] == 'infinity')
268
+            {
234 269
             	$files = Vfs::find($source,array('depth' => true,'url' => true));	// depth=true: return dirs first, url=true: allow urls!
235
-            } else {
270
+            }
271
+            else
272
+            {
236 273
                 $files = array($source);
237 274
             }
238 275
 
239
-            if (!is_array($files) || empty($files)) {
276
+            if (!is_array($files) || empty($files))
277
+            {
240 278
                 return "500 Internal server error";
241 279
             }
242 280
 
243 281
 
244
-            foreach ($files as $file) {
245
-                if (is_dir($file)) {
282
+            foreach ($files as $file)
283
+            {
284
+                if (is_dir($file))
285
+                {
246 286
                     $file = $this->_slashify($file);
247 287
                 }
248 288
 
249 289
                 $destfile = str_replace($source, $dest, $file);
250 290
 
251
-                if (is_dir($file)) {
252
-                    if (!is_dir($destfile)) {
291
+                if (is_dir($file))
292
+                {
293
+                    if (!is_dir($destfile))
294
+                    {
253 295
                         // TODO "mkdir -p" here? (only natively supported by PHP 5)
254
-                        if (!@mkdir($destfile)) {
296
+                        if (!@mkdir($destfile))
297
+                        {
255 298
                             return "409 Conflict";
256 299
                         }
257 300
                     }
258
-                } else {
259
-                    if (!@copy($file, $destfile)) {
301
+                }
302
+                else
303
+                {
304
+                    if (!@copy($file, $destfile))
305
+                    {
260 306
                         return "409 Conflict";
261 307
                     }
262 308
                 }
@@ -306,17 +352,23 @@  discard block
 block discarded – undo
306 352
         $info["props"][] = self::mkprop("ishidden",        Vfs::is_hidden($fspath));
307 353
 
308 354
 		// type and size (caller already made sure that path exists)
309
-		if (is_dir($fspath)) {
355
+		if (is_dir($fspath))
356
+		{
310 357
 			// directory (WebDAV collection)
311 358
 			$info['props'][] = self::mkprop	('resourcetype', array(
312 359
 			 	self::mkprop('collection', '')));
313 360
 			$info['props'][] = self::mkprop	('getcontenttype', 'httpd/unix-directory');
314
-		} else {
361
+		}
362
+		else
363
+		{
315 364
 			// plain file (WebDAV resource)
316 365
 			$info['props'][] = self::mkprop	('resourcetype', '');
317
-			if (Vfs::is_readable($path)) {
366
+			if (Vfs::is_readable($path))
367
+			{
318 368
 				$info['props'][] = self::mkprop	('getcontenttype', Vfs::mime_content_type($path));
319
-			} else {
369
+			}
370
+			else
371
+			{
320 372
 				error_log(__METHOD__."($path) $fspath is not readable!");
321 373
 				$info['props'][] = self::mkprop	('getcontenttype', 'application/x-non-readable');
322 374
 			}
@@ -388,7 +440,10 @@  discard block
 block discarded – undo
388 440
 				continue;
389 441
 			}
390 442
 			$_path = $info['path'];
391
-			if (!$n && $info['path'] != '/' && substr($info['path'],-1) == '/') $_path = substr($info['path'],0,-1);
443
+			if (!$n && $info['path'] != '/' && substr($info['path'],-1) == '/')
444
+			{
445
+				$_path = substr($info['path'],0,-1);
446
+			}
392 447
 
393 448
 			// need to encode path again, as $info['path'] is NOT encoded, but Vfs::(stat|propfind) require it
394 449
 			// otherwise pathes containing url special chars like ? or # will not stat
@@ -427,16 +482,22 @@  discard block
 block discarded – undo
427 482
 				$fileprops =& $files['files'][$path2n[$path]]['props'];
428 483
 				foreach($props as $prop)
429 484
 				{
430
-					if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'][0] == '#')	// eGW's customfields
485
+					if ($prop['ns'] == Vfs::DEFAULT_PROP_NAMESPACE && $prop['name'][0] == '#')
486
+					{
487
+						// eGW's customfields
431 488
 					{
432 489
 						$prop['ns'] .= 'customfields/';
490
+					}
433 491
 						$prop['name'] = substr($prop['name'],1);
434 492
 					}
435 493
 					$fileprops[] = $prop;
436 494
 				}
437 495
 			}
438 496
 		}
439
-		if ($this->debug) error_log(__METHOD__."() props=".array2string($files['files']));
497
+		if ($this->debug)
498
+		{
499
+			error_log(__METHOD__."() props=".array2string($files['files']));
500
+		}
440 501
 		return true;
441 502
 	}
442 503
 
@@ -488,7 +549,8 @@  discard block
 block discarded – undo
488 549
 	{
489 550
 		$path = Api\Translation::convert($options['path'],'utf-8');
490 551
 
491
-		foreach ($options['props'] as $key => $prop) {
552
+		foreach ($options['props'] as $key => $prop)
553
+		{
492 554
 			$attributes = array();
493 555
 			switch($prop['ns'])
494 556
 			{
@@ -505,7 +567,10 @@  discard block
 block discarded – undo
505 567
 							//$attributes['created'] = strtotime($prop['val']);
506 568
 							//break;
507 569
 						default:
508
-							if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
570
+							if (!Vfs::proppatch($path,array($prop)))
571
+							{
572
+								$options['props'][$key]['status'] = '403 Forbidden';
573
+							}
509 574
 							break;
510 575
 					}
511 576
 					break;
@@ -534,7 +599,10 @@  discard block
 block discarded – undo
534 599
 						case 'Win32LastAccessTime':
535 600
 						case 'Win32FileAttributes':	// not sure what that is, it was always "00000000"
536 601
 						default:
537
-							if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
602
+							if (!Vfs::proppatch($path,array($prop)))
603
+							{
604
+								$options['props'][$key]['status'] = '403 Forbidden';
605
+							}
538 606
 							break;
539 607
 					}
540 608
 					break;
@@ -544,15 +612,24 @@  discard block
 block discarded – undo
544 612
 					$prop['name'] = '#'.$prop['name'];
545 613
 					// fall through
546 614
 				default:
547
-					if (!Vfs::proppatch($path,array($prop))) $options['props'][$key]['status'] = '403 Forbidden';
615
+					if (!Vfs::proppatch($path,array($prop)))
616
+					{
617
+						$options['props'][$key]['status'] = '403 Forbidden';
618
+					}
548 619
 					break;
549 620
 			}
550
-			if ($this->debug) $props[] = '('.$prop['ns'].')'.$prop['name'].'='.$prop['val'];
621
+			if ($this->debug)
622
+			{
623
+				$props[] = '('.$prop['ns'].')'.$prop['name'].'='.$prop['val'];
624
+			}
551 625
 		}
552 626
 		if ($this->debug)
553 627
 		{
554 628
 			error_log(__METHOD__.": path=$options[path], props=".implode(', ',$props));
555
-			if ($attributes) error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n",' ',print_r($attributes,true)));
629
+			if ($attributes)
630
+			{
631
+				error_log(__METHOD__.": path=$options[path], set attributes=".str_replace("\n",' ',print_r($attributes,true)));
632
+			}
556 633
 		}
557 634
 
558 635
 		return '';	// this is as the filesystem example handler does it, no true or false ...
@@ -566,7 +643,10 @@  discard block
 block discarded – undo
566 643
 	 */
567 644
 	function LOCK(&$options)
568 645
 	{
569
-		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
646
+		if ($this->debug)
647
+		{
648
+			error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
649
+		}
570 650
 		// TODO recursive locks on directories not supported yet
571 651
 		if (is_dir($this->base . $options['path']) && !empty($options['depth']))
572 652
 		{
@@ -592,7 +672,10 @@  discard block
 block discarded – undo
592 672
 	 */
593 673
 	function UNLOCK(&$options)
594 674
 	{
595
-		if ($this->debug) error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
675
+		if ($this->debug)
676
+		{
677
+			error_log(__METHOD__.'('.str_replace(array("\n",'    '),'',print_r($options,true)).')');
678
+		}
596 679
 		return Vfs::unlock($options['path'],$options['token']) ? '204 No Content' : '409 Conflict';
597 680
 	}
598 681
 
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.
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.
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|ENT_XML1|ENT_DISALLOWED, '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|ENT_XML1|ENT_DISALLOWED, '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.
Indentation   +2524 added lines, -2524 removed lines patch added patch discarded remove patch
@@ -48,633 +48,633 @@  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, $handler);
672
-        if ($this->store_request) $this->request = $propinfo->request;
673
-        if ($propinfo->error) {
674
-            $this->http_status("400 Bad Request");
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, $handler);
672
+		if ($this->store_request) $this->request = $propinfo->request;
673
+		if ($propinfo->error) {
674
+			$this->http_status("400 Bad Request");
675 675
 			if (method_exists($this, 'log')) $this->log('Error parsing propfind: '.$propinfo->error);
676
-            return;
677
-        }
676
+			return;
677
+		}
678 678
 		$options['root'] = $propinfo->root;
679 679
 		$options['props'] = $propinfo->props;
680 680
 		if ($propinfo->filters)
@@ -682,34 +682,34 @@  discard block
 block discarded – undo
682 682
 		if ($propinfo->other)
683 683
 			$options['other'] = $propinfo->other;
684 684
 
685
-        // call user handler
686
-        if (!($retval =$this->$handler($options, $files))) {
687
-            $files = array("files" => array());
688
-            if (method_exists($this, "checkLock")) {
689
-                // is locked?
690
-                $lock = $this->checkLock($this->path);
691
-
692
-                if (is_array($lock) && count($lock)) {
693
-                    $created          = isset($lock['created'])  ? $lock['created']  : time();
694
-                    $modified         = isset($lock['modified']) ? $lock['modified'] : time();
695
-                    $files['files'][] = array("path"  => self::_slashify($this->path),
696
-                                              "props" => array($this->mkprop("displayname",      $this->path),
697
-                                                               $this->mkprop("creationdate",     $created),
698
-                                                               $this->mkprop("getlastmodified",  $modified),
699
-                                                               $this->mkprop("resourcetype",     ""),
700
-                                                               $this->mkprop("getcontenttype",   ""),
701
-                                                               $this->mkprop("getcontentlength", 0))
702
-                                              );
703
-                }
704
-            }
705
-
706
-            if (empty($files['files'])) {
707
-                $this->http_status("404 Not Found");
708
-                return;
709
-            }
710
-        }
711
-
712
-        // now we generate the reply header ...
685
+		// call user handler
686
+		if (!($retval =$this->$handler($options, $files))) {
687
+			$files = array("files" => array());
688
+			if (method_exists($this, "checkLock")) {
689
+				// is locked?
690
+				$lock = $this->checkLock($this->path);
691
+
692
+				if (is_array($lock) && count($lock)) {
693
+					$created          = isset($lock['created'])  ? $lock['created']  : time();
694
+					$modified         = isset($lock['modified']) ? $lock['modified'] : time();
695
+					$files['files'][] = array("path"  => self::_slashify($this->path),
696
+											  "props" => array($this->mkprop("displayname",      $this->path),
697
+															   $this->mkprop("creationdate",     $created),
698
+															   $this->mkprop("getlastmodified",  $modified),
699
+															   $this->mkprop("resourcetype",     ""),
700
+															   $this->mkprop("getcontenttype",   ""),
701
+															   $this->mkprop("getcontentlength", 0))
702
+											  );
703
+				}
704
+			}
705
+
706
+			if (empty($files['files'])) {
707
+				$this->http_status("404 Not Found");
708
+				return;
709
+			}
710
+		}
711
+
712
+		// now we generate the reply header ...
713 713
 		if ($retval === true)
714 714
 		{
715 715
 			$this->http_status('207 Multi-Status');
@@ -733,506 +733,506 @@  discard block
 block discarded – undo
733 733
 			return;
734 734
 		}
735 735
 		// dav header
736
-        $dav = array(1);        // assume we are always dav class 1 compliant
737
-        $allow = false;
736
+		$dav = array(1);        // assume we are always dav class 1 compliant
737
+		$allow = false;
738 738
 
739
-        // allow extending class to modify DAV
739
+		// allow extending class to modify DAV
740 740
 		if (method_exists($this,'OPTIONS')) {
741 741
 			$this->OPTIONS($this->path,$dav,$allow);
742 742
 		}
743
-        header("DAV: "  .join(", ", $dav));
744
-        header('Content-Type: text/xml; charset="utf-8"');
743
+		header("DAV: "  .join(", ", $dav));
744
+		header('Content-Type: text/xml; charset="utf-8"');
745 745
 
746
-        // add Vary and Preference-Applied header for Prefer: return=minimal
747
-        if (isset($this->_SERVER['HTTP_PREFER']) && in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER'])))
748
-        {
749
-        	header("Preference-Applied: return=minimal");
750
-        	header("Vary: Prefer");
751
-        }
752
-
753
-        // ... and payload
754
-        echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
755
-        echo $this->crrnd ? "<multistatus xmlns=\"DAV:\">\n" : "<D:multistatus xmlns:D=\"DAV:\">\n";
756
-
757
-        $this->multistatus_responses($files['files'], $options['props']);
758
-
759
-        // WebDAV sync report sync-token, can be either the sync-token or a callback (called with params in $files['sync-token-params'])
760
-        if (isset($files['sync-token']))
761
-        {
762
-            echo ($this->crrnd ? " <" : " <D:")."sync-token>".
763
-            	htmlspecialchars(!is_callable($files['sync-token']) ? $files['sync-token'] :
764
-            		call_user_func_array($files['sync-token'], (array)$files['sync-token-params'])).
765
-            	($this->crrnd ? "</" : "</D:")."sync-token>\n";
766
-        }
767
-
768
-        echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
769
-    }
770
-
771
-    /**
772
-     * Render (echo) XML for given multistatus responses
773
-     *
774
-     * @param array|Iterator $files
775
-     * @param array|string $props
776
-     */
777
-    function multistatus_responses(&$files, $props, $initial_ns_hash=null, $initial_ns_defs=null)
778
-    {
779
-    	if (!isset($initial_ns_hash)) $initial_ns_hash = array('DAV:' => 'D');
780
-    	if (!isset($initial_ns_defs)) $initial_ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';
781
-
782
-    	// using an ArrayIterator to prevent foreach from copying the array,
783
-        // as we cant loop by reference, when an iterator is given in $files
784
-        if (is_array($files))
785
-        {
786
-        	$files = new ArrayIterator($files);
787
-        }
788
-        // support for "Prefer: depth-noroot" header on PROPFIND
789
-        $skip_root = $this->_SERVER['REQUEST_METHOD'] == 'PROPFIND' &&
790
-        	!isset($initial_ns_hash) &&	// multistatus_response calls itself, do NOT apply skip in that case
791
-        	isset($this->_SERVER['HTTP_PREFER']) && in_array('depth-noroot', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER']));
792
-
793
-        // now we loop over all returned file entries
794
-        foreach ($files as $file) {
795
-
796
-        	// skip first element (root), if requested by Prefer: depth-noroot
797
-        	if ($skip_root) {
798
-        		$skip_root = false;
799
-        		continue;
800
-        	}
801
-
802
-	        // collect namespaces here
803
-	        $ns_hash = $initial_ns_hash;
804
-
805
-	        // Microsoft Clients need this special namespace for date and time values
806
-	        $ns_defs = $initial_ns_defs;
807
-
808
-            // nothing to do if no properties were returend for a file
809
-			if (isset($file["props"]) && is_array($file["props"])) {
810
-
811
-	            // now loop over all returned properties
812
-	            foreach ($file["props"] as &$prop) {
813
-	                // as a convenience feature we do not require that user handlers
814
-	                // restrict returned properties to the requested ones
815
-	                // here we strip all unrequested entries out of the response
816
-
817
-	            	// this can happen if we have allprop and prop in one propfind:
818
-	            	// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
819
-	                switch(is_array($props) ? $props[0] : $props) {
820
-	                case "all":
821
-	                    // nothing to remove
822
-	                    break;
823
-
824
-	                case "names":
825
-	                    // only the names of all existing properties were requested
826
-	                    // so we remove all values
827
-	                    unset($prop["val"]);
828
-	                    break;
829
-
830
-	                default:
831
-	                    $found = false;
832
-
833
-	                    // search property name in requested properties
834
-	                    foreach ((array)$props as $reqprop) {
835
-	                        if (   $reqprop["name"]  == $prop["name"]
836
-	                               && @$reqprop["xmlns"] == $prop["ns"]) {
837
-	                            $found = true;
838
-	                            break;
839
-	                        }
840
-	                    }
841
-
842
-	                    // unset property and continue with next one if not found/requested
843
-	                    if (!$found) {
844
-	                        $prop="";
845
-	                        continue(2);
846
-	                    }
847
-	                    break;
848
-	                }
849
-
850
-	                // namespace handling
851
-	                if (empty($prop["ns"])) continue; // no namespace
852
-	                $ns = $prop["ns"];
853
-	                //if ($ns == "DAV:") continue; // default namespace
854
-	                if (isset($ns_hash[$ns])) continue; // already known
855
-
856
-	                // register namespace
857
-	                $ns_name = "ns".(count($ns_hash) + 1);
858
-	                $ns_hash[$ns] = $ns_name;
859
-	                $ns_defs .= " xmlns:$ns_name=\"$ns\"";
860
-	            }
861
-
862
-	            // we also need to add empty entries for properties that were requested
863
-	            // but for which no values where returned by the user handler
864
-	            if (is_array($props)) {
865
-	                foreach ($props as $reqprop) {
866
-	                    if (!is_array($reqprop) || $reqprop['name']=="") continue; // skip empty entries, or 'all' if <allprop /> used together with <prop>
867
-
868
-	                    $found = false;
869
-
870
-	                    // check if property exists in result
871
-	                    foreach ($file["props"] as &$prop) {
872
-	                        if (is_array($prop) && $reqprop["name"] == $prop["name"]
873
-	                               && @$reqprop["xmlns"] == $prop["ns"]) {
874
-	                            $found = true;
875
-	                            break;
876
-	                        }
877
-	                    }
878
-
879
-	                    if (!$found) {
880
-	                        if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") {
881
-	                            // lockdiscovery is handled by the base class
882
-	                            $file["props"][]
883
-	                                = $this->mkprop("DAV:",
884
-	                                                "lockdiscovery",
885
-	                                                $this->lockdiscovery($file['path']));
886
-	                        // only collect $file['noprops'] if we have NO Brief: t and NO Prefer: return=minimal HTTP Header
887
-	                        } elseif ((!isset($this->_SERVER['HTTP_BRIEF']) || $this->_SERVER['HTTP_BRIEF'] != 't') &&
888
-	                        	(!isset($this->_SERVER['HTTP_PREFER']) || !in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER'])))) {
889
-	                            // add empty value for this property
890
-	                            $file["noprops"][] =
891
-	                                $this->mkprop($reqprop["xmlns"], $reqprop["name"], "");
892
-
893
-	                            // register property namespace if not known yet
894
-	                            if ($reqprop["xmlns"] != "DAV:" && !isset($ns_hash[$reqprop["xmlns"]])) {
895
-	                                $ns_name = "ns".(count($ns_hash) + 1);
896
-	                                $ns_hash[$reqprop["xmlns"]] = $ns_name;
897
-	                                $ns_defs .= " xmlns:$ns_name=\"$reqprop[xmlns]\"";
898
-	                            }
899
-	                        }
900
-	                    }
901
-	                }
902
-	            }
903
-	        }
904
-            // ignore empty or incomplete entries
905
-            if (!is_array($file) || empty($file) || !isset($file["path"])) continue;
906
-            $path = $file['path'];
907
-            if (!is_string($path) || $path==="") continue;
908
-
909
-            if ($this->crrnd)
910
-            {
911
-            	echo " <response $ns_defs>\n";
912
-            }
913
-            else
914
-            {
915
-            	echo " <D:response $ns_defs>\n";
916
-            }
917
-
918
-            /* TODO right now the user implementation has to make sure
919
-             collections end in a slash, this should be done in here
920
-             by checking the resource attribute */
921
-            $href_raw = $this->_mergePaths($this->base_uri, $path);
922
-
923
-            /* minimal urlencoding is needed for the resource path */
924
-            $href = $this->_urlencode($href_raw);
925
-
926
-            if ($this->crrnd)
927
-            {
928
-            	echo "  <href>$href</href>\n";
929
-            }
930
-            else
931
-            {
932
-            	echo "  <D:href>$href</D:href>\n";
933
-            }
934
-
935
-            // report all found properties and their values (if any)
936
-            if (isset($file["props"]) && is_array($file["props"])) {
937
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
938
-                echo '    <'.($this->crrnd?'':'D:')."prop>\n";
939
-
940
-                foreach ($file["props"] as &$prop) {
941
-
942
-                    if (!is_array($prop)) continue;
943
-                    if (!isset($prop["name"])) continue;
944
-
945
-                    if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) {
946
-                        // empty properties (cannot use empty() for check as "0" is a legal value here)
947
-                        if ($prop["ns"]=="DAV:") {
948
-                            echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
949
-                        } else if (!empty($prop["ns"])) {
950
-                            echo "     <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
951
-                        } else {
952
-                            echo "     <$prop[name] xmlns=\"\"/>";
953
-                        }
954
-                    }
955
-                    // multiple level of responses required for expand-property reports
956
-                    elseif(isset($prop['props']) && is_array($prop['val']))
957
-                    {
958
-                        if ($prop['ns'] && !isset($ns_hash[$prop['ns']])) {
959
-                            $ns_name = "ns".(count($ns_hash) + 1);
960
-                            $ns_hash[$prop['ns']] = $ns_name;
961
-                        }
962
-                    	echo '     <'.$ns_hash[$prop['ns']].":$prop[name]>\n";
963
-                        $this->multistatus_responses($prop['val'], $prop['props'], $ns_hash, '');
964
-                    	echo '     </'.$ns_hash[$prop['ns']].":$prop[name]>\n";
965
-                    } else if ($prop["ns"] == "DAV:") {
966
-                        // some WebDAV properties need special treatment
967
-                        switch ($prop["name"]) {
968
-                        case "creationdate":
969
-                            echo '     <'.($this->crrnd?'':'D:')."creationdate ns0:dt=\"dateTime.tz\">"
970
-                                . gmdate("Y-m-d\\TH:i:s\\Z", $prop['val'])
971
-                                . '</'.($this->crrnd?'':'D:')."creationdate>\n";
972
-                            break;
973
-                        case "getlastmodified":
974
-                            echo '     <'.($this->crrnd?'':'D:')."getlastmodified ns0:dt=\"dateTime.rfc1123\">"
975
-                                . gmdate("D, d M Y H:i:s ", $prop['val'])
976
-                                . "GMT</".($this->crrnd?'':'D:')."getlastmodified>\n";
977
-                            break;
978
-                        case "supportedlock":
979
-                            echo '     <'.($this->crrnd?'':'D:')."supportedlock>$prop[val]</".($this->crrnd?'':'D:')."supportedlock>\n";
980
-                            break;
981
-                        case "lockdiscovery":
982
-                            echo '     <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
983
-                            echo $prop["val"];
984
-                            echo '     </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
985
-                            break;
986
-                        // the following are non-standard Microsoft extensions to the DAV namespace
987
-                        case "lastaccessed":
988
-                            echo '     <'.($this->crrnd?'':'D:')."lastaccessed ns0:dt=\"dateTime.rfc1123\">"
989
-                                . gmdate("D, d M Y H:i:s ", $prop['val'])
990
-                                . 'GMT</'.($this->crrnd?'':'D:')."lastaccessed>\n";
991
-                            break;
992
-                        case "ishidden":
993
-                            echo '     <'.($this->crrnd?'':'D:')."ishidden>"
994
-                                . is_string($prop['val']) ? $prop['val'] : ($prop['val'] ? 'true' : 'false')
995
-                                . '</'.($this->crrnd?'':'D:')."</D:ishidden>\n";
996
-                            break;
997
-                        default:
998
-                        	$ns_defs = '';
999
-                            if (is_array($prop['val']))
1000
-                            {
1001
-                            	$hns_hash = $ns_hash;
1002
-                            	$val = $this->_hierarchical_prop_encode($prop['val'], 'DAV:', $ns_defs, $hns_hash);
1003
-                            } elseif (isset($prop['raw'])) {
1004
-                            	$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
1005
-                            } else {
1006
-	                    		$val = $this->_prop_encode(htmlspecialchars($prop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8'));
1007
-                            }
1008
-	                        echo '     <'.($this->crrnd?'':'D:')."$prop[name]$ns_defs>$val".
1009
-	                        	'</'.($this->crrnd?'':'D:')."$prop[name]>\n";
1010
-                            break;
1011
-                        }
1012
-                    } else {
1013
-                        // allow multiple values and attributes, required eg. for caldav:supported-calendar-component-set
1014
-                        if ($prop['ns'] && is_array($prop['val'])) {
1015
-                    		if (!isset($ns_hash[$prop['ns']])) {
1016
-                                $ns_name = "ns".(count($ns_hash) + 1);
1017
-                                $ns_hash[$prop['ns']] = $ns_name;
1018
-                    		}
1019
-                  			$vals = $extra_ns = '';
1020
-                    		foreach($prop['val'] as $subprop)
1021
-                    		{
1022
-                    			if ($subprop['ns'] && $subprop['ns'] != 'DAV:') {
1023
-		                    		// register property namespace if not known yet
1024
-		                    		if (!isset($ns_hash[$subprop['ns']])) {
1025
-			                    		$ns_name = "ns".(count($ns_hash) + 1);
1026
-			                    		$ns_hash[$subprop['ns']] = $ns_name;
1027
-		                    		} else {
1028
-			                    		$ns_name = $ns_hash[$subprop['ns']];
1029
-		                    		}
1030
-		                    		if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) {
1031
-			                    		$extra_ns .= $extra;
1032
-		                    		}
1033
-		                    		$ns_name .= ':';
1034
-	                    		} elseif ($subprop['ns'] == 'DAV:') {
1035
-		                    		$ns_name = 'D:';
1036
-	                    		} else {
1037
-		                    		$ns_name = '';
1038
-	                    		}
1039
-	                    		$vals .= "<$ns_name$subprop[name]";
1040
-	                    		if (is_array($subprop['val']))
1041
-	                    		{
1042
-	                    			if (isset($subprop['val'][0]))
1043
-	                    			{
1044
-		                    			$vals .= '>';
1045
-		                    			$vals .= $this->_hierarchical_prop_encode($subprop['val'], $subprop['ns'], $ns_defs, $ns_hash);
1046
-			                    		$vals .= "</$ns_name$subprop[name]>";
1047
-	                    			}
1048
-	                    			else	// val contains only attributes, no value
1049
-	                    			{
1050
-			                    		foreach($subprop['val'] as $attr => $val)
1051
-										{
1052
-				                    		$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8').'"';
1053
-										}
1054
-			                    		$vals .= '/>';
1055
-	                    			}
1056
-	                    		}
1057
-	                    		else
1058
-	                    		{
1059
-	                    			$vals .= '>';
1060
-	                    			if (isset($subprop['raw'])) {
1061
-	                    				$vals .= '<![CDATA['.$subprop['val'].']]>';
1062
-	                    			} else {
1063
-	                    				if($subprop['name'] == 'href') $subprop['val'] = $this->_urlencode($subprop['val']);
1064
-		                    			$vals .= htmlspecialchars($subprop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8');
1065
-	                    			}
1066
-	                    			$vals .= "</$ns_name$subprop[name]>";
1067
-	                    		}
1068
-                    		}
1069
-                    		echo '     <'.$ns_hash[$prop['ns']].":$prop[name]$extra_ns>$vals</".$ns_hash[$prop['ns']].":$prop[name]>\n";
1070
-                        } else {
1071
-                        	if ($prop['raw'])
1072
-                        	{
1073
-                        		$val = '<![CDATA['.$prop['val'].']]>';
1074
-                        	} else {
1075
-                        		$val = htmlspecialchars($prop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8');
1076
-                        	}
1077
-                        	$val = $this->_prop_encode($val);
1078
-	                        // properties from namespaces != "DAV:" or without any namespace
1079
-	                        if ($prop['ns']) {
1080
-		                        if ($this->crrnd) {
1081
-			                        echo "     <$prop[name] xmlns=".'"'.$prop["ns"].'">'
1082
-									. $val . "</$prop[name]>\n";
1083
-		                        } else {
1084
-			                        echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]>"
1085
-									. $val . '</'.$ns_hash[$prop['ns']].":$prop[name]>\n";
1086
-		                        }
1087
-	                        } else {
1088
-		                        echo "     <$prop[name] xmlns=\"\">$val</$prop[name]>\n";
1089
-	                        }
1090
-                        }
1091
-                    }
1092
-                }
1093
-
1094
-                if ($this->crrnd)
1095
-                {
1096
-	                echo "    </prop>\n";
1097
-	                echo "   <status>HTTP/1.1 200 OK</status>\n";
1098
-	                echo "  </propstat>\n";
1099
-                }
1100
-                else
1101
-                {
1102
-	                echo "    </D:prop>\n";
1103
-	                echo "   <D:status>HTTP/1.1 200 OK</D:status>\n";
1104
-	                echo "  </D:propstat>\n";
1105
-                }
1106
-            }
1107
-
1108
-            // now report all properties requested but not found
1109
-            if (isset($file["noprops"])) {
1110
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1111
-                echo '    <'.($this->crrnd?'':'D:')."prop>\n";
1112
-
1113
-                foreach ($file["noprops"] as &$prop) {
1114
-                    if ($prop["ns"] == "DAV:") {
1115
-                        echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
1116
-                    } else if ($prop["ns"] == "") {
1117
-                        echo "     <$prop[name] xmlns=\"\"/>\n";
1118
-                    } else {
1119
-                        echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]/>\n";
1120
-                    }
1121
-                }
1122
-
1123
-                if ($this->crrnd)
1124
-                {
1125
-	                echo "   </prop>\n";
1126
-	                echo "   <status>HTTP/1.1 404 Not Found</status>\n";
1127
-	                echo "  </propstat>\n";
1128
-                }
1129
-                else
1130
-                {
1131
-	                echo "   </D:prop>\n";
1132
-	                echo "   <D:status>HTTP/1.1 404 Not Found</D:status>\n";
1133
-	                echo "  </D:propstat>\n";
1134
-                }
1135
-            }
1136
-
1137
-            // 404 Not Found status element for WebDAV sync report
1138
-            if (!isset($file['props']) && !isset($file['noprops']))
1139
-            {
1140
-                if ($this->crrnd)
1141
-                {
1142
-	                echo "  <status>HTTP/1.1 404 Not Found</status>\n";
1143
-                }
1144
-                else
1145
-                {
1146
-	                echo "  <D:status>HTTP/1.1 404 Not Found</D:status>\n";
1147
-                }
1148
-            }
1149
-
1150
-            echo ' </'.($this->crrnd?'':'D:')."response>\n";
1151
-        }
1152
-    }
1153
-
1154
-
1155
-    // }}}
1156
-
1157
-    // {{{ http_PROPPATCH()
746
+		// add Vary and Preference-Applied header for Prefer: return=minimal
747
+		if (isset($this->_SERVER['HTTP_PREFER']) && in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER'])))
748
+		{
749
+			header("Preference-Applied: return=minimal");
750
+			header("Vary: Prefer");
751
+		}
1158 752
 
1159
-    /**
1160
-     * PROPPATCH method handler
1161
-     *
1162
-     * @param  void
1163
-     * @return void
1164
-     */
1165
-    function http_PROPPATCH()
1166
-    {
1167
-        if ($this->_check_lock_status($this->path)) {
1168
-            $options = Array();
753
+		// ... and payload
754
+		echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
755
+		echo $this->crrnd ? "<multistatus xmlns=\"DAV:\">\n" : "<D:multistatus xmlns:D=\"DAV:\">\n";
1169 756
 
1170
-            $options["path"] = $this->path;
757
+		$this->multistatus_responses($files['files'], $options['props']);
1171 758
 
1172
-            $propinfo = new _parse_proppatch("php://input", $this->store_request);
1173
-            if ($this->store_request) $this->request = $propinfo->request;
759
+		// WebDAV sync report sync-token, can be either the sync-token or a callback (called with params in $files['sync-token-params'])
760
+		if (isset($files['sync-token']))
761
+		{
762
+			echo ($this->crrnd ? " <" : " <D:")."sync-token>".
763
+				htmlspecialchars(!is_callable($files['sync-token']) ? $files['sync-token'] :
764
+					call_user_func_array($files['sync-token'], (array)$files['sync-token-params'])).
765
+				($this->crrnd ? "</" : "</D:")."sync-token>\n";
766
+		}
1174 767
 
1175
-            if (!$propinfo->success) {
1176
-                $this->http_status("400 Error");
1177
-                return;
1178
-            }
768
+		echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
769
+	}
1179 770
 
1180
-            $options['props'] = $propinfo->props;
771
+	/**
772
+	 * Render (echo) XML for given multistatus responses
773
+	 *
774
+	 * @param array|Iterator $files
775
+	 * @param array|string $props
776
+	 */
777
+	function multistatus_responses(&$files, $props, $initial_ns_hash=null, $initial_ns_defs=null)
778
+	{
779
+		if (!isset($initial_ns_hash)) $initial_ns_hash = array('DAV:' => 'D');
780
+		if (!isset($initial_ns_defs)) $initial_ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';
1181 781
 
1182
-            $responsedescr = $this->PROPPATCH($options);
782
+		// using an ArrayIterator to prevent foreach from copying the array,
783
+		// as we cant loop by reference, when an iterator is given in $files
784
+		if (is_array($files))
785
+		{
786
+			$files = new ArrayIterator($files);
787
+		}
788
+		// support for "Prefer: depth-noroot" header on PROPFIND
789
+		$skip_root = $this->_SERVER['REQUEST_METHOD'] == 'PROPFIND' &&
790
+			!isset($initial_ns_hash) &&	// multistatus_response calls itself, do NOT apply skip in that case
791
+			isset($this->_SERVER['HTTP_PREFER']) && in_array('depth-noroot', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER']));
792
+
793
+		// now we loop over all returned file entries
794
+		foreach ($files as $file) {
795
+
796
+			// skip first element (root), if requested by Prefer: depth-noroot
797
+			if ($skip_root) {
798
+				$skip_root = false;
799
+				continue;
800
+			}
1183 801
 
1184
-            $this->http_status("207 Multi-Status");
1185
-            header('Content-Type: text/xml; charset="utf-8"');
802
+			// collect namespaces here
803
+			$ns_hash = $initial_ns_hash;
1186 804
 
1187
-            echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
805
+			// Microsoft Clients need this special namespace for date and time values
806
+			$ns_defs = $initial_ns_defs;
1188 807
 
1189
-            echo "<D:multistatus xmlns:D=\"DAV:\">\n";
1190
-            echo ' <'.($this->crrnd?'':'D:')."response>\n";
1191
-            echo '  <'.($this->crrnd?'':'D:')."href>".$this->_urlencode($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)).'</'.($this->crrnd?'':'D:')."href>\n";
808
+			// nothing to do if no properties were returend for a file
809
+			if (isset($file["props"]) && is_array($file["props"])) {
1192 810
 
1193
-            foreach ($options["props"] as $prop) {
1194
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1195
-                echo '    <'.($this->crrnd?'':'D:')."prop><$prop[name] xmlns=\"$prop[ns]\"/></".($this->crrnd?'':'D:')."prop>\n";
1196
-                echo '    <'.($this->crrnd?'':'D:')."status>HTTP/1.1 $prop[status]</".($this->crrnd?'':'D:')."status>\n";
1197
-                echo '   </'.($this->crrnd?'':'D:')."propstat>\n";
1198
-            }
811
+				// now loop over all returned properties
812
+				foreach ($file["props"] as &$prop) {
813
+					// as a convenience feature we do not require that user handlers
814
+					// restrict returned properties to the requested ones
815
+					// here we strip all unrequested entries out of the response
816
+
817
+					// this can happen if we have allprop and prop in one propfind:
818
+					// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
819
+					switch(is_array($props) ? $props[0] : $props) {
820
+					case "all":
821
+						// nothing to remove
822
+						break;
823
+
824
+					case "names":
825
+						// only the names of all existing properties were requested
826
+						// so we remove all values
827
+						unset($prop["val"]);
828
+						break;
829
+
830
+					default:
831
+						$found = false;
832
+
833
+						// search property name in requested properties
834
+						foreach ((array)$props as $reqprop) {
835
+							if (   $reqprop["name"]  == $prop["name"]
836
+								   && @$reqprop["xmlns"] == $prop["ns"]) {
837
+								$found = true;
838
+								break;
839
+							}
840
+						}
1199 841
 
1200
-            if ($responsedescr) {
1201
-                echo '  <'.($this->crrnd?'':'D:')."responsedescription>".
1202
-                    $this->_prop_encode(htmlspecialchars($responsedescr, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8')).
1203
-                    '</'.($this->crrnd?'':'D:')."responsedescription>\n";
1204
-            }
842
+						// unset property and continue with next one if not found/requested
843
+						if (!$found) {
844
+							$prop="";
845
+							continue(2);
846
+						}
847
+						break;
848
+					}
1205 849
 
1206
-            echo ' </'.($this->crrnd?'':'D:')."response>\n";
1207
-            echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
1208
-        } else {
1209
-            $this->http_status("423 Locked");
1210
-        }
1211
-    }
850
+					// namespace handling
851
+					if (empty($prop["ns"])) continue; // no namespace
852
+					$ns = $prop["ns"];
853
+					//if ($ns == "DAV:") continue; // default namespace
854
+					if (isset($ns_hash[$ns])) continue; // already known
1212 855
 
1213
-    // }}}
856
+					// register namespace
857
+					$ns_name = "ns".(count($ns_hash) + 1);
858
+					$ns_hash[$ns] = $ns_name;
859
+					$ns_defs .= " xmlns:$ns_name=\"$ns\"";
860
+				}
1214 861
 
862
+				// we also need to add empty entries for properties that were requested
863
+				// but for which no values where returned by the user handler
864
+				if (is_array($props)) {
865
+					foreach ($props as $reqprop) {
866
+						if (!is_array($reqprop) || $reqprop['name']=="") continue; // skip empty entries, or 'all' if <allprop /> used together with <prop>
867
+
868
+						$found = false;
869
+
870
+						// check if property exists in result
871
+						foreach ($file["props"] as &$prop) {
872
+							if (is_array($prop) && $reqprop["name"] == $prop["name"]
873
+								   && @$reqprop["xmlns"] == $prop["ns"]) {
874
+								$found = true;
875
+								break;
876
+							}
877
+						}
1215 878
 
1216
-    // {{{ http_MKCOL()
879
+						if (!$found) {
880
+							if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") {
881
+								// lockdiscovery is handled by the base class
882
+								$file["props"][]
883
+									= $this->mkprop("DAV:",
884
+													"lockdiscovery",
885
+													$this->lockdiscovery($file['path']));
886
+							// only collect $file['noprops'] if we have NO Brief: t and NO Prefer: return=minimal HTTP Header
887
+							} elseif ((!isset($this->_SERVER['HTTP_BRIEF']) || $this->_SERVER['HTTP_BRIEF'] != 't') &&
888
+								(!isset($this->_SERVER['HTTP_PREFER']) || !in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER'])))) {
889
+								// add empty value for this property
890
+								$file["noprops"][] =
891
+									$this->mkprop($reqprop["xmlns"], $reqprop["name"], "");
892
+
893
+								// register property namespace if not known yet
894
+								if ($reqprop["xmlns"] != "DAV:" && !isset($ns_hash[$reqprop["xmlns"]])) {
895
+									$ns_name = "ns".(count($ns_hash) + 1);
896
+									$ns_hash[$reqprop["xmlns"]] = $ns_name;
897
+									$ns_defs .= " xmlns:$ns_name=\"$reqprop[xmlns]\"";
898
+								}
899
+							}
900
+						}
901
+					}
902
+				}
903
+			}
904
+			// ignore empty or incomplete entries
905
+			if (!is_array($file) || empty($file) || !isset($file["path"])) continue;
906
+			$path = $file['path'];
907
+			if (!is_string($path) || $path==="") continue;
1217 908
 
1218
-    /**
1219
-     * MKCOL method handler
1220
-     *
1221
-     * @param  void
1222
-     * @return void
1223
-     */
1224
-    function http_MKCOL()
1225
-    {
1226
-        $options = Array();
909
+			if ($this->crrnd)
910
+			{
911
+				echo " <response $ns_defs>\n";
912
+			}
913
+			else
914
+			{
915
+				echo " <D:response $ns_defs>\n";
916
+			}
1227 917
 
1228
-        $options["path"] = $this->path;
918
+			/* TODO right now the user implementation has to make sure
919
+             collections end in a slash, this should be done in here
920
+             by checking the resource attribute */
921
+			$href_raw = $this->_mergePaths($this->base_uri, $path);
1229 922
 
1230
-        $stat = $this->MKCOL($options);
923
+			/* minimal urlencoding is needed for the resource path */
924
+			$href = $this->_urlencode($href_raw);
1231 925
 
1232
-        $this->http_status($stat);
1233
-    }
926
+			if ($this->crrnd)
927
+			{
928
+				echo "  <href>$href</href>\n";
929
+			}
930
+			else
931
+			{
932
+				echo "  <D:href>$href</D:href>\n";
933
+			}
1234 934
 
1235
-    // }}}
935
+			// report all found properties and their values (if any)
936
+			if (isset($file["props"]) && is_array($file["props"])) {
937
+				echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
938
+				echo '    <'.($this->crrnd?'':'D:')."prop>\n";
939
+
940
+				foreach ($file["props"] as &$prop) {
941
+
942
+					if (!is_array($prop)) continue;
943
+					if (!isset($prop["name"])) continue;
944
+
945
+					if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) {
946
+						// empty properties (cannot use empty() for check as "0" is a legal value here)
947
+						if ($prop["ns"]=="DAV:") {
948
+							echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
949
+						} else if (!empty($prop["ns"])) {
950
+							echo "     <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
951
+						} else {
952
+							echo "     <$prop[name] xmlns=\"\"/>";
953
+						}
954
+					}
955
+					// multiple level of responses required for expand-property reports
956
+					elseif(isset($prop['props']) && is_array($prop['val']))
957
+					{
958
+						if ($prop['ns'] && !isset($ns_hash[$prop['ns']])) {
959
+							$ns_name = "ns".(count($ns_hash) + 1);
960
+							$ns_hash[$prop['ns']] = $ns_name;
961
+						}
962
+						echo '     <'.$ns_hash[$prop['ns']].":$prop[name]>\n";
963
+						$this->multistatus_responses($prop['val'], $prop['props'], $ns_hash, '');
964
+						echo '     </'.$ns_hash[$prop['ns']].":$prop[name]>\n";
965
+					} else if ($prop["ns"] == "DAV:") {
966
+						// some WebDAV properties need special treatment
967
+						switch ($prop["name"]) {
968
+						case "creationdate":
969
+							echo '     <'.($this->crrnd?'':'D:')."creationdate ns0:dt=\"dateTime.tz\">"
970
+								. gmdate("Y-m-d\\TH:i:s\\Z", $prop['val'])
971
+								. '</'.($this->crrnd?'':'D:')."creationdate>\n";
972
+							break;
973
+						case "getlastmodified":
974
+							echo '     <'.($this->crrnd?'':'D:')."getlastmodified ns0:dt=\"dateTime.rfc1123\">"
975
+								. gmdate("D, d M Y H:i:s ", $prop['val'])
976
+								. "GMT</".($this->crrnd?'':'D:')."getlastmodified>\n";
977
+							break;
978
+						case "supportedlock":
979
+							echo '     <'.($this->crrnd?'':'D:')."supportedlock>$prop[val]</".($this->crrnd?'':'D:')."supportedlock>\n";
980
+							break;
981
+						case "lockdiscovery":
982
+							echo '     <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
983
+							echo $prop["val"];
984
+							echo '     </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
985
+							break;
986
+						// the following are non-standard Microsoft extensions to the DAV namespace
987
+						case "lastaccessed":
988
+							echo '     <'.($this->crrnd?'':'D:')."lastaccessed ns0:dt=\"dateTime.rfc1123\">"
989
+								. gmdate("D, d M Y H:i:s ", $prop['val'])
990
+								. 'GMT</'.($this->crrnd?'':'D:')."lastaccessed>\n";
991
+							break;
992
+						case "ishidden":
993
+							echo '     <'.($this->crrnd?'':'D:')."ishidden>"
994
+								. is_string($prop['val']) ? $prop['val'] : ($prop['val'] ? 'true' : 'false')
995
+								. '</'.($this->crrnd?'':'D:')."</D:ishidden>\n";
996
+							break;
997
+						default:
998
+							$ns_defs = '';
999
+							if (is_array($prop['val']))
1000
+							{
1001
+								$hns_hash = $ns_hash;
1002
+								$val = $this->_hierarchical_prop_encode($prop['val'], 'DAV:', $ns_defs, $hns_hash);
1003
+							} elseif (isset($prop['raw'])) {
1004
+								$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
1005
+							} else {
1006
+								$val = $this->_prop_encode(htmlspecialchars($prop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8'));
1007
+							}
1008
+							echo '     <'.($this->crrnd?'':'D:')."$prop[name]$ns_defs>$val".
1009
+								'</'.($this->crrnd?'':'D:')."$prop[name]>\n";
1010
+							break;
1011
+						}
1012
+					} else {
1013
+						// allow multiple values and attributes, required eg. for caldav:supported-calendar-component-set
1014
+						if ($prop['ns'] && is_array($prop['val'])) {
1015
+							if (!isset($ns_hash[$prop['ns']])) {
1016
+								$ns_name = "ns".(count($ns_hash) + 1);
1017
+								$ns_hash[$prop['ns']] = $ns_name;
1018
+							}
1019
+				  			$vals = $extra_ns = '';
1020
+							foreach($prop['val'] as $subprop)
1021
+							{
1022
+								if ($subprop['ns'] && $subprop['ns'] != 'DAV:') {
1023
+									// register property namespace if not known yet
1024
+									if (!isset($ns_hash[$subprop['ns']])) {
1025
+										$ns_name = "ns".(count($ns_hash) + 1);
1026
+										$ns_hash[$subprop['ns']] = $ns_name;
1027
+									} else {
1028
+										$ns_name = $ns_hash[$subprop['ns']];
1029
+									}
1030
+									if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) {
1031
+										$extra_ns .= $extra;
1032
+									}
1033
+									$ns_name .= ':';
1034
+								} elseif ($subprop['ns'] == 'DAV:') {
1035
+									$ns_name = 'D:';
1036
+								} else {
1037
+									$ns_name = '';
1038
+								}
1039
+								$vals .= "<$ns_name$subprop[name]";
1040
+								if (is_array($subprop['val']))
1041
+								{
1042
+									if (isset($subprop['val'][0]))
1043
+									{
1044
+										$vals .= '>';
1045
+										$vals .= $this->_hierarchical_prop_encode($subprop['val'], $subprop['ns'], $ns_defs, $ns_hash);
1046
+										$vals .= "</$ns_name$subprop[name]>";
1047
+									}
1048
+									else	// val contains only attributes, no value
1049
+									{
1050
+										foreach($subprop['val'] as $attr => $val)
1051
+										{
1052
+											$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8').'"';
1053
+										}
1054
+										$vals .= '/>';
1055
+									}
1056
+								}
1057
+								else
1058
+								{
1059
+									$vals .= '>';
1060
+									if (isset($subprop['raw'])) {
1061
+										$vals .= '<![CDATA['.$subprop['val'].']]>';
1062
+									} else {
1063
+										if($subprop['name'] == 'href') $subprop['val'] = $this->_urlencode($subprop['val']);
1064
+										$vals .= htmlspecialchars($subprop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8');
1065
+									}
1066
+									$vals .= "</$ns_name$subprop[name]>";
1067
+								}
1068
+							}
1069
+							echo '     <'.$ns_hash[$prop['ns']].":$prop[name]$extra_ns>$vals</".$ns_hash[$prop['ns']].":$prop[name]>\n";
1070
+						} else {
1071
+							if ($prop['raw'])
1072
+							{
1073
+								$val = '<![CDATA['.$prop['val'].']]>';
1074
+							} else {
1075
+								$val = htmlspecialchars($prop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8');
1076
+							}
1077
+							$val = $this->_prop_encode($val);
1078
+							// properties from namespaces != "DAV:" or without any namespace
1079
+							if ($prop['ns']) {
1080
+								if ($this->crrnd) {
1081
+									echo "     <$prop[name] xmlns=".'"'.$prop["ns"].'">'
1082
+									. $val . "</$prop[name]>\n";
1083
+								} else {
1084
+									echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]>"
1085
+									. $val . '</'.$ns_hash[$prop['ns']].":$prop[name]>\n";
1086
+								}
1087
+							} else {
1088
+								echo "     <$prop[name] xmlns=\"\">$val</$prop[name]>\n";
1089
+							}
1090
+						}
1091
+					}
1092
+				}
1093
+
1094
+				if ($this->crrnd)
1095
+				{
1096
+					echo "    </prop>\n";
1097
+					echo "   <status>HTTP/1.1 200 OK</status>\n";
1098
+					echo "  </propstat>\n";
1099
+				}
1100
+				else
1101
+				{
1102
+					echo "    </D:prop>\n";
1103
+					echo "   <D:status>HTTP/1.1 200 OK</D:status>\n";
1104
+					echo "  </D:propstat>\n";
1105
+				}
1106
+			}
1107
+
1108
+			// now report all properties requested but not found
1109
+			if (isset($file["noprops"])) {
1110
+				echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1111
+				echo '    <'.($this->crrnd?'':'D:')."prop>\n";
1112
+
1113
+				foreach ($file["noprops"] as &$prop) {
1114
+					if ($prop["ns"] == "DAV:") {
1115
+						echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
1116
+					} else if ($prop["ns"] == "") {
1117
+						echo "     <$prop[name] xmlns=\"\"/>\n";
1118
+					} else {
1119
+						echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]/>\n";
1120
+					}
1121
+				}
1122
+
1123
+				if ($this->crrnd)
1124
+				{
1125
+					echo "   </prop>\n";
1126
+					echo "   <status>HTTP/1.1 404 Not Found</status>\n";
1127
+					echo "  </propstat>\n";
1128
+				}
1129
+				else
1130
+				{
1131
+					echo "   </D:prop>\n";
1132
+					echo "   <D:status>HTTP/1.1 404 Not Found</D:status>\n";
1133
+					echo "  </D:propstat>\n";
1134
+				}
1135
+			}
1136
+
1137
+			// 404 Not Found status element for WebDAV sync report
1138
+			if (!isset($file['props']) && !isset($file['noprops']))
1139
+			{
1140
+				if ($this->crrnd)
1141
+				{
1142
+					echo "  <status>HTTP/1.1 404 Not Found</status>\n";
1143
+				}
1144
+				else
1145
+				{
1146
+					echo "  <D:status>HTTP/1.1 404 Not Found</D:status>\n";
1147
+				}
1148
+			}
1149
+
1150
+			echo ' </'.($this->crrnd?'':'D:')."response>\n";
1151
+		}
1152
+	}
1153
+
1154
+
1155
+	// }}}
1156
+
1157
+	// {{{ http_PROPPATCH()
1158
+
1159
+	/**
1160
+	 * PROPPATCH method handler
1161
+	 *
1162
+	 * @param  void
1163
+	 * @return void
1164
+	 */
1165
+	function http_PROPPATCH()
1166
+	{
1167
+		if ($this->_check_lock_status($this->path)) {
1168
+			$options = Array();
1169
+
1170
+			$options["path"] = $this->path;
1171
+
1172
+			$propinfo = new _parse_proppatch("php://input", $this->store_request);
1173
+			if ($this->store_request) $this->request = $propinfo->request;
1174
+
1175
+			if (!$propinfo->success) {
1176
+				$this->http_status("400 Error");
1177
+				return;
1178
+			}
1179
+
1180
+			$options['props'] = $propinfo->props;
1181
+
1182
+			$responsedescr = $this->PROPPATCH($options);
1183
+
1184
+			$this->http_status("207 Multi-Status");
1185
+			header('Content-Type: text/xml; charset="utf-8"');
1186
+
1187
+			echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
1188
+
1189
+			echo "<D:multistatus xmlns:D=\"DAV:\">\n";
1190
+			echo ' <'.($this->crrnd?'':'D:')."response>\n";
1191
+			echo '  <'.($this->crrnd?'':'D:')."href>".$this->_urlencode($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)).'</'.($this->crrnd?'':'D:')."href>\n";
1192
+
1193
+			foreach ($options["props"] as $prop) {
1194
+				echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1195
+				echo '    <'.($this->crrnd?'':'D:')."prop><$prop[name] xmlns=\"$prop[ns]\"/></".($this->crrnd?'':'D:')."prop>\n";
1196
+				echo '    <'.($this->crrnd?'':'D:')."status>HTTP/1.1 $prop[status]</".($this->crrnd?'':'D:')."status>\n";
1197
+				echo '   </'.($this->crrnd?'':'D:')."propstat>\n";
1198
+			}
1199
+
1200
+			if ($responsedescr) {
1201
+				echo '  <'.($this->crrnd?'':'D:')."responsedescription>".
1202
+					$this->_prop_encode(htmlspecialchars($responsedescr, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8')).
1203
+					'</'.($this->crrnd?'':'D:')."responsedescription>\n";
1204
+			}
1205
+
1206
+			echo ' </'.($this->crrnd?'':'D:')."response>\n";
1207
+			echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
1208
+		} else {
1209
+			$this->http_status("423 Locked");
1210
+		}
1211
+	}
1212
+
1213
+	// }}}
1214
+
1215
+
1216
+	// {{{ http_MKCOL()
1217
+
1218
+	/**
1219
+	 * MKCOL method handler
1220
+	 *
1221
+	 * @param  void
1222
+	 * @return void
1223
+	 */
1224
+	function http_MKCOL()
1225
+	{
1226
+		$options = Array();
1227
+
1228
+		$options["path"] = $this->path;
1229
+
1230
+		$stat = $this->MKCOL($options);
1231
+
1232
+		$this->http_status($stat);
1233
+	}
1234
+
1235
+	// }}}
1236 1236
 
1237 1237
 	/**
1238 1238
 	 * Check or set if we want ot use compression as transfer encoding
@@ -1259,1387 +1259,1387 @@  discard block
 block discarded – undo
1259 1259
 		return $compression;
1260 1260
 	}
1261 1261
 
1262
-    // {{{ http_GET()
1262
+	// {{{ http_GET()
1263 1263
 
1264
-    /**
1265
-     * GET method handler
1266
-     *
1267
-     * @param void
1268
-     * @return void
1269
-     */
1270
-    function http_GET()
1271
-    {
1272
-        // TODO check for invalid stream
1273
-        $options         = Array();
1274
-        $options["path"] = $this->path;
1275
-
1276
-        $this->_get_ranges($options);
1277
-
1278
-        if (true === ($status = $this->GET($options))) {
1279
-            if (!headers_sent()) {
1280
-                $status = "200 OK";
1281
-
1282
-                if (!isset($options['mimetype'])) {
1283
-                    $options['mimetype'] = "application/octet-stream";
1284
-                }
1285
-                // switching off zlib.output_compression for everything but text files,
1286
-                // as the double compression of zip files makes problems eg. with lighttpd
1287
-                // and anyway little sense with with other content like pictures
1288
-                if (substr($options['mimetype'],0,5) != 'text/')
1289
-                {
1264
+	/**
1265
+	 * GET method handler
1266
+	 *
1267
+	 * @param void
1268
+	 * @return void
1269
+	 */
1270
+	function http_GET()
1271
+	{
1272
+		// TODO check for invalid stream
1273
+		$options         = Array();
1274
+		$options["path"] = $this->path;
1275
+
1276
+		$this->_get_ranges($options);
1277
+
1278
+		if (true === ($status = $this->GET($options))) {
1279
+			if (!headers_sent()) {
1280
+				$status = "200 OK";
1281
+
1282
+				if (!isset($options['mimetype'])) {
1283
+					$options['mimetype'] = "application/octet-stream";
1284
+				}
1285
+				// switching off zlib.output_compression for everything but text files,
1286
+				// as the double compression of zip files makes problems eg. with lighttpd
1287
+				// and anyway little sense with with other content like pictures
1288
+				if (substr($options['mimetype'],0,5) != 'text/')
1289
+				{
1290 1290
 					self::use_compression(false);
1291
-                }
1292
-                header("Content-type: $options[mimetype]");
1293
-
1294
-                if (isset($options['mtime'])) {
1295
-                    header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1296
-                }
1297
-                // fix for IE and https, thanks to [email protected]
1298
-                // see http://us3.php.net/manual/en/function.header.php#83219
1299
-                // and http://support.microsoft.com/kb/812935
1291
+				}
1292
+				header("Content-type: $options[mimetype]");
1293
+
1294
+				if (isset($options['mtime'])) {
1295
+					header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1296
+				}
1297
+				// fix for IE and https, thanks to [email protected]
1298
+				// see http://us3.php.net/manual/en/function.header.php#83219
1299
+				// and http://support.microsoft.com/kb/812935
1300 1300
 				header("Cache-Control: maxage=1"); //In seconds
1301 1301
 				header("Pragma: public");
1302 1302
 
1303
-                if (isset($options['stream'])) {
1304
-                    // GET handler returned a stream
1305
-                    if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET))) {
1306
-                        // partial request and stream is seekable
1307
-
1308
-                        if (count($options['ranges']) === 1) {
1309
-                            $range = $options['ranges'][0];
1310
-
1311
-                            if (isset($range['start'])) {
1312
-                                fseek($options['stream'], $range['start'], SEEK_SET);
1313
-                                if (feof($options['stream'])) {
1314
-                                    $this->http_status($status = "416 Requested range not satisfiable");
1315
-                                    return;
1316
-                                }
1317
-
1318
-                                if (!empty($range['end'])) {
1319
-                                    $size = $range['end']-$range['start']+1;
1320
-                                    $this->http_status($status = "206 Partial content");
1321
-                                    if (!self::use_compression()) header("Content-Length: $size");
1322
-                                    header("Content-Range: bytes $range[start]-$range[end]/"
1323
-                                           . (isset($options['size']) ? $options['size'] : "*"));
1324
-                                    while ($size > 0 && !feof($options['stream'])) {
1325
-                                        $buffer = fread($options['stream'], $size < 8192 ? $size : 8192);
1326
-                                        $size  -= self::bytes($buffer);
1327
-                                        echo $buffer;
1328
-                                    }
1329
-                                } else {
1330
-                                    $this->http_status($status = "206 Partial content");
1331
-                                    if (isset($options['size'])) {
1332
-                                        if (!self::use_compression()) header("Content-Length: ".($options['size'] - $range['start']));
1333
-                                        header("Content-Range: bytes ".$range['start']."-".
1303
+				if (isset($options['stream'])) {
1304
+					// GET handler returned a stream
1305
+					if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET))) {
1306
+						// partial request and stream is seekable
1307
+
1308
+						if (count($options['ranges']) === 1) {
1309
+							$range = $options['ranges'][0];
1310
+
1311
+							if (isset($range['start'])) {
1312
+								fseek($options['stream'], $range['start'], SEEK_SET);
1313
+								if (feof($options['stream'])) {
1314
+									$this->http_status($status = "416 Requested range not satisfiable");
1315
+									return;
1316
+								}
1317
+
1318
+								if (!empty($range['end'])) {
1319
+									$size = $range['end']-$range['start']+1;
1320
+									$this->http_status($status = "206 Partial content");
1321
+									if (!self::use_compression()) header("Content-Length: $size");
1322
+									header("Content-Range: bytes $range[start]-$range[end]/"
1323
+										   . (isset($options['size']) ? $options['size'] : "*"));
1324
+									while ($size > 0 && !feof($options['stream'])) {
1325
+										$buffer = fread($options['stream'], $size < 8192 ? $size : 8192);
1326
+										$size  -= self::bytes($buffer);
1327
+										echo $buffer;
1328
+									}
1329
+								} else {
1330
+									$this->http_status($status = "206 Partial content");
1331
+									if (isset($options['size'])) {
1332
+										if (!self::use_compression()) header("Content-Length: ".($options['size'] - $range['start']));
1333
+										header("Content-Range: bytes ".$range['start']."-".
1334 1334
 											(isset($options['size']) ? $options['size']-1 : "")."/"
1335 1335
 										   . (isset($options['size']) ? $options['size'] : "*"));
1336
-                                    }
1337
-                                    fpassthru($options['stream']);
1338
-                                }
1339
-                            } else {
1340
-                                if (!self::use_compression()) header("Content-length: ".$range['last']);
1341
-                                fseek($options['stream'], -$range['last'], SEEK_END);
1342
-                                fpassthru($options['stream']);
1343
-                            }
1344
-                        } else {
1345
-                            $this->_multipart_byterange_header(); // init multipart
1346
-                            foreach ($options['ranges'] as $range) {
1347
-                                // TODO what if size unknown? 500?
1348
-                                if (isset($range['start'])) {
1349
-                                    $from = $range['start'];
1350
-                                    $to   = !empty($range['end']) ? $range['end'] : $options['size']-1;
1351
-                                } else {
1352
-                                    $from = $options['size'] - $range['last']-1;
1353
-                                    $to   = $options['size'] -1;
1354
-                                }
1355
-                                $total = isset($options['size']) ? $options['size'] : "*";
1356
-                                $size  = $to - $from + 1;
1357
-                                $this->_multipart_byterange_header($options['mimetype'], $from, $to, $total);
1358
-
1359
-
1360
-                                fseek($options['stream'], $from, SEEK_SET);
1361
-                                while ($size && !feof($options['stream'])) {
1362
-                                    $buffer = fread($options['stream'], 4096);
1363
-                                    $size  -= self::bytes($buffer);
1364
-                                    echo $buffer;
1365
-                                }
1366
-                            }
1367
-                            $this->_multipart_byterange_header(); // end multipart
1368
-                        }
1369
-                    } else {
1370
-                        // normal request or stream isn't seekable, return full content
1371
-                        if (isset($options['size']) && !self::use_compression()) {
1372
-                            header("Content-Length: ".$options['size']);
1373
-                        }
1374
-                        fpassthru($options['stream']);
1375
-                        return; // no more headers
1376
-                    }
1377
-                } elseif (isset($options['data'])) {
1378
-                    if (is_array($options['data'])) {
1379
-                        // reply to partial request
1380
-                    } else {
1381
-                        if (!self::use_compression()) header("Content-Length: ".self::bytes($options['data']));
1382
-                        echo $options['data'];
1383
-                    }
1384
-                }
1385
-            }
1386
-        }
1387
-
1388
-        if (!headers_sent()) {
1389
-            if (false === $status) {
1390
-                $this->http_status("404 not found");
1391
-            } else {
1392
-                // TODO: check setting of headers in various code paths above
1393
-                $this->http_status("$status");
1394
-            }
1395
-        }
1396
-    }
1336
+									}
1337
+									fpassthru($options['stream']);
1338
+								}
1339
+							} else {
1340
+								if (!self::use_compression()) header("Content-length: ".$range['last']);
1341
+								fseek($options['stream'], -$range['last'], SEEK_END);
1342
+								fpassthru($options['stream']);
1343
+							}
1344
+						} else {
1345
+							$this->_multipart_byterange_header(); // init multipart
1346
+							foreach ($options['ranges'] as $range) {
1347
+								// TODO what if size unknown? 500?
1348
+								if (isset($range['start'])) {
1349
+									$from = $range['start'];
1350
+									$to   = !empty($range['end']) ? $range['end'] : $options['size']-1;
1351
+								} else {
1352
+									$from = $options['size'] - $range['last']-1;
1353
+									$to   = $options['size'] -1;
1354
+								}
1355
+								$total = isset($options['size']) ? $options['size'] : "*";
1356
+								$size  = $to - $from + 1;
1357
+								$this->_multipart_byterange_header($options['mimetype'], $from, $to, $total);
1358
+
1359
+
1360
+								fseek($options['stream'], $from, SEEK_SET);
1361
+								while ($size && !feof($options['stream'])) {
1362
+									$buffer = fread($options['stream'], 4096);
1363
+									$size  -= self::bytes($buffer);
1364
+									echo $buffer;
1365
+								}
1366
+							}
1367
+							$this->_multipart_byterange_header(); // end multipart
1368
+						}
1369
+					} else {
1370
+						// normal request or stream isn't seekable, return full content
1371
+						if (isset($options['size']) && !self::use_compression()) {
1372
+							header("Content-Length: ".$options['size']);
1373
+						}
1374
+						fpassthru($options['stream']);
1375
+						return; // no more headers
1376
+					}
1377
+				} elseif (isset($options['data'])) {
1378
+					if (is_array($options['data'])) {
1379
+						// reply to partial request
1380
+					} else {
1381
+						if (!self::use_compression()) header("Content-Length: ".self::bytes($options['data']));
1382
+						echo $options['data'];
1383
+					}
1384
+				}
1385
+			}
1386
+		}
1387
+
1388
+		if (!headers_sent()) {
1389
+			if (false === $status) {
1390
+				$this->http_status("404 not found");
1391
+			} else {
1392
+				// TODO: check setting of headers in various code paths above
1393
+				$this->http_status("$status");
1394
+			}
1395
+		}
1396
+	}
1397
+
1398
+
1399
+	/**
1400
+	 * parse HTTP Range: header
1401
+	 *
1402
+	 * @param  array options array to store result in
1403
+	 * @return void
1404
+	 */
1405
+	function _get_ranges(&$options)
1406
+	{
1407
+		// process Range: header if present
1408
+		if (isset($this->_SERVER['HTTP_RANGE'])) {
1409
+
1410
+			// we only support standard "bytes" range specifications for now
1411
+			$matches = null;
1412
+			if (preg_match('/bytes\s*=\s*(.+)/', $this->_SERVER['HTTP_RANGE'], $matches)) {
1413
+				$options["ranges"] = array();
1414
+
1415
+				// ranges are comma separated
1416
+				foreach (explode(",", $matches[1]) as $range) {
1417
+					// ranges are either from-to pairs or just end positions
1418
+					list($start, $end) = explode("-", $range);
1419
+					$options["ranges"][] = ($start==="")
1420
+						? array("last"=>$end)
1421
+						: array("start"=>$start, "end"=>$end);
1422
+				}
1423
+			}
1424
+		}
1425
+	}
1426
+
1427
+	/**
1428
+	 * generate separator headers for multipart response
1429
+	 *
1430
+	 * first and last call happen without parameters to generate
1431
+	 * the initial header and closing sequence, all calls inbetween
1432
+	 * require content mimetype, start and end byte position and
1433
+	 * optionaly the total byte length of the requested resource
1434
+	 *
1435
+	 * @param  string  mimetype
1436
+	 * @param  int     start byte position
1437
+	 * @param  int     end   byte position
1438
+	 * @param  int     total resource byte size
1439
+	 */
1440
+	function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false)
1441
+	{
1442
+		if ($mimetype === false) {
1443
+			if (!isset($this->multipart_separator)) {
1444
+				// initial
1445
+
1446
+				// a little naive, this sequence *might* be part of the content
1447
+				// but it's really not likely and rather expensive to check
1448
+				$this->multipart_separator = "SEPARATOR_".md5(microtime());
1449
+
1450
+				// generate HTTP header
1451
+				header("Content-type: multipart/byteranges; boundary=".$this->multipart_separator);
1452
+			} else {
1453
+				// final
1454
+
1455
+				// generate closing multipart sequence
1456
+				echo "\n--{$this->multipart_separator}--";
1457
+			}
1458
+		} else {
1459
+			// generate separator and header for next part
1460
+			echo "\n--{$this->multipart_separator}\n";
1461
+			echo "Content-type: $mimetype\n";
1462
+			echo "Content-range: $from-$to/". ($total === false ? "*" : $total);
1463
+			echo "\n\n";
1464
+		}
1465
+	}
1466
+
1467
+
1468
+
1469
+	// }}}
1470
+
1471
+	// {{{ http_HEAD()
1472
+
1473
+	/**
1474
+	 * HEAD method handler
1475
+	 *
1476
+	 * @param  void
1477
+	 * @return void
1478
+	 */
1479
+	function http_HEAD()
1480
+	{
1481
+		$status          = false;
1482
+		$options         = Array();
1483
+		$options["path"] = $this->path;
1484
+
1485
+		if (method_exists($this, "HEAD")) {
1486
+			$status = $this->head($options);
1487
+		} else if (method_exists($this, "GET")) {
1488
+			ob_start();
1489
+			$status = $this->GET($options);
1490
+			if (!isset($options['size'])) {
1491
+				$options['size'] = ob_get_length();
1492
+			}
1493
+			ob_end_clean();
1494
+		}
1495
+
1496
+		if (!isset($options['mimetype'])) {
1497
+			$options['mimetype'] = "application/octet-stream";
1498
+		}
1499
+		header("Content-type: $options[mimetype]");
1500
+
1501
+		if (isset($options['mtime'])) {
1502
+			header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1503
+		}
1504
+
1505
+		if (isset($options['size'])) {
1506
+			header("Content-Length: ".$options['size']);
1507
+		}
1508
+
1509
+		if ($status === true)  $status = "200 OK";
1510
+		if ($status === false) $status = "404 Not found";
1511
+
1512
+		$this->http_status($status);
1513
+	}
1514
+
1515
+	// }}}
1516
+
1517
+	// {{{ http_POST()
1518
+
1519
+	/**
1520
+	 * POST method handler
1521
+	 *
1522
+	 * @param  void
1523
+	 * @return void
1524
+	 */
1525
+	function http_POST()
1526
+	{
1527
+		$status          = '405 Method not allowed';
1528
+		$options         = Array();
1529
+		$options['path'] = $this->path;
1530
+
1531
+		if (isset($this->_SERVER['CONTENT_LENGTH']))
1532
+		{
1533
+			$options['content_length'] = $this->_SERVER['CONTENT_LENGTH'];
1534
+		}
1535
+		elseif (isset($this->_SERVER['X-Expected-Entity-Length']))
1536
+		{
1537
+			// MacOS gives us that hint
1538
+			$options['content_length'] = $this->_SERVER['X-Expected-Entity-Length'];
1539
+		}
1540
+
1541
+		// get the Content-type
1542
+		if (isset($this->_SERVER["CONTENT_TYPE"])) {
1543
+			// for now we do not support any sort of multipart requests
1544
+			if (!strncmp($this->_SERVER["CONTENT_TYPE"], 'multipart/', 10)) {
1545
+				$this->http_status('501 not implemented');
1546
+				echo 'The service does not support mulipart POST requests';
1547
+				return;
1548
+			}
1549
+			$options['content_type'] = $this->_SERVER['CONTENT_TYPE'];
1550
+		} else {
1551
+			// default content type if none given
1552
+			$options['content_type'] = 'application/octet-stream';
1553
+		}
1554
+
1555
+		$options['stream'] = fopen('php://input', 'r');
1556
+		switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1557
+		{
1558
+			case 'gzip':
1559
+			case 'deflate':	//zlib
1560
+				if (extension_loaded('zlib'))
1561
+	 			{
1562
+	  				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1563
+	   			}
1564
+		}
1565
+		// store request in $this->request, if requested via $this->store_request
1566
+		if ($this->store_request)
1567
+		{
1568
+			$options['content'] = '';
1569
+			while(!feof($options['stream']))
1570
+			{
1571
+				$options['content'] .= fread($options['stream'],8192);
1572
+			}
1573
+			$this->request =& $options['content'];
1574
+			unset($options['stream']);
1575
+		}
1576
+
1577
+		/* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
1578
+         ignore any Content-* (e.g. Content-Range) headers that it
1579
+         does not understand or implement and MUST return a 501
1580
+         (Not Implemented) response in such cases."
1581
+         */
1582
+		foreach ($this->_SERVER as $key => $val) {
1583
+			if (strncmp($key, 'HTTP_CONTENT', 11)) continue;
1584
+			switch ($key) {
1585
+				case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1586
+					switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1587
+					{
1588
+						case 'gzip':
1589
+						case 'deflate':	//zlib
1590
+							if (extension_loaded('zlib')) break;
1591
+							// fall through for no zlib support
1592
+						default:
1593
+							$this->http_status('415 Unsupported Media Type');
1594
+							echo "The service does not support '$val' content encoding";
1595
+							return;
1596
+					}
1597
+					break;
1598
+
1599
+				case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12
1600
+					// we assume it is not critical if this one is ignored
1601
+					// in the actual POST implementation ...
1602
+					$options['content_language'] = $val;
1603
+					break;
1604
+
1605
+				case 'HTTP_CONTENT_LENGTH':
1606
+					// defined on IIS and has the same value as CONTENT_LENGTH
1607
+					break;
1608
+
1609
+				case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
1610
+					/* The meaning of the Content-Location header in PUT
1611
+			         or POST requests is undefined; servers are free
1612
+			         to ignore it in those cases. */
1613
+					break;
1614
+
1615
+				case 'HTTP_CONTENT_RANGE':    // RFC 2616 14.16
1616
+					// single byte range requests are supported
1617
+					// the header format is also specified in RFC 2616 14.16
1618
+					// TODO we have to ensure that implementations support this or send 501 instead
1619
+					$matches = null;
1620
+					if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
1621
+						$this->http_status('400 bad request');
1622
+						echo 'The service does only support single byte ranges';
1623
+						return;
1624
+					}
1625
+
1626
+					$range = array('start'=>$matches[1], 'end'=>$matches[2]);
1627
+					if (is_numeric($matches[3])) {
1628
+						$range['total_length'] = $matches[3];
1629
+					}
1630
+					$options['ranges'][] = $range;
1631
+
1632
+					// TODO make sure the implementation supports partial POST
1633
+					// this has to be done in advance to avoid data being overwritten
1634
+					// on implementations that do not support this ...
1635
+					break;
1636
+
1637
+				case 'HTTP_CONTENT_TYPE':
1638
+					// defined on IIS and has the same value as CONTENT_TYPE
1639
+					break;
1640
+
1641
+				case 'HTTP_CONTENT_MD5':      // RFC 2616 14.15
1642
+					// TODO: maybe we can just pretend here?
1643
+					$this->http_status('501 not implemented');
1644
+					echo 'The service does not support content MD5 checksum verification';
1645
+					return;
1646
+
1647
+				case 'HTTP_CONTENT_DISPOSITION':
1648
+					// do NOT care about Content-Disposition in POST requests required by CalDAV managed attachments
1649
+					break;
1650
+
1651
+				default:
1652
+					// any other unknown Content-* headers
1653
+					$this->http_status('501 not implemented');
1654
+				echo "The service does not support '$key'";
1655
+				return;
1656
+			}
1657
+		}
1658
+
1659
+		if (method_exists($this, 'POST')) {
1660
+			$status = $this->POST($options);
1661
+
1662
+			if ($status === false) {
1663
+				$status = '400 Something went wrong';
1664
+			} else if ($status === true) {
1665
+				$status = '200 OK';
1666
+			} else if (is_resource($status) && get_resource_type($status) == 'stream') {
1667
+				$stream = $status;
1668
+
1669
+				$status = empty($options['new']) ? '200 OK' : '201 Created';
1670
+
1671
+				if (!empty($options['ranges'])) {
1672
+					// TODO multipart support is missing (see also above)
1673
+					if (0 == fseek($stream, $range[0]['start'], SEEK_SET)) {
1674
+						$length = $range[0]['end']-$range[0]['start']+1;
1675
+						if (!fwrite($stream, fread($options['stream'], $length))) {
1676
+							$status = '403 Forbidden';
1677
+						}
1678
+					} else {
1679
+						$status = '403 Forbidden';
1680
+					}
1681
+				} else {
1682
+					while (!feof($options['stream'])) {
1683
+						if (false === fwrite($stream, fread($options['stream'], 4096))) {
1684
+							$status = '403 Forbidden';
1685
+							break;
1686
+						}
1687
+					}
1688
+				}
1689
+				fclose($stream);
1690
+			}
1691
+		}
1692
+		$this->http_status($status);
1693
+	}
1694
+
1695
+	// }}}
1696
+
1697
+	// {{{ http_PUT()
1698
+
1699
+	/**
1700
+	 * PUT method handler
1701
+	 *
1702
+	 * @param  void
1703
+	 * @return void
1704
+	 */
1705
+	function http_PUT()
1706
+	{
1707
+		if ($this->_check_lock_status($this->path)) {
1708
+			$options                   = Array();
1709
+			$options["path"]           = $this->path;
1710
+
1711
+			if (isset($this->_SERVER['CONTENT_LENGTH']))
1712
+			{
1713
+				$options['content_length'] = $this->_SERVER['CONTENT_LENGTH'];
1714
+			}
1715
+			elseif (isset($this->_SERVER['X-Expected-Entity-Length']))
1716
+			{
1717
+				// MacOS gives us that hint
1718
+				$options['content_length'] = $this->_SERVER['X-Expected-Entity-Length'];
1719
+			}
1720
+
1721
+			// get the Content-type
1722
+			if (isset($this->_SERVER["CONTENT_TYPE"])) {
1723
+				// for now we do not support any sort of multipart requests
1724
+				if (!strncmp($this->_SERVER["CONTENT_TYPE"], "multipart/", 10)) {
1725
+					$this->http_status("501 not implemented");
1726
+					echo "The service does not support multipart PUT requests";
1727
+					return;
1728
+				}
1729
+				$options["content_type"] = $this->_SERVER["CONTENT_TYPE"];
1730
+			} else {
1731
+				// default content type if none given
1732
+				$options["content_type"] = "application/octet-stream";
1733
+			}
1734
+
1735
+			$options["stream"] = fopen("php://input", "r");
1736
+			switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1737
+			{
1738
+				case 'gzip':
1739
+				case 'deflate':	//zlib
1740
+					if (extension_loaded('zlib'))
1741
+		 			{
1742
+		  				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1743
+		   			}
1744
+			}
1745
+			// store request in $this->request, if requested via $this->store_request
1746
+			if ($this->store_request)
1747
+			{
1748
+				$options['content'] = '';
1749
+				while(!feof($options['stream']))
1750
+				{
1751
+					$options['content'] .= fread($options['stream'],8192);
1752
+				}
1753
+				$this->request =& $options['content'];
1754
+				unset($options['stream']);
1755
+			}
1756
+
1757
+			/* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
1758
+             ignore any Content-* (e.g. Content-Range) headers that it
1759
+             does not understand or implement and MUST return a 501
1760
+             (Not Implemented) response in such cases."
1761
+            */
1762
+			foreach ($this->_SERVER as $key => $val) {
1763
+				if (strncmp($key, "HTTP_CONTENT", 11)) continue;
1764
+				switch ($key) {
1765
+				case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1766
+					switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1767
+					{
1768
+						case 'gzip':
1769
+						case 'deflate':	//zlib
1770
+							if (extension_loaded('zlib')) break;
1771
+							// fall through for no zlib support
1772
+						default:
1773
+							$this->http_status('415 Unsupported Media Type');
1774
+							echo "The service does not support '$val' content encoding";
1775
+							return;
1776
+					}
1777
+					break;
1778
+
1779
+				case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12
1780
+					// we assume it is not critical if this one is ignored
1781
+					// in the actual PUT implementation ...
1782
+					$options["content_language"] = $val;
1783
+					break;
1784
+
1785
+				case 'HTTP_CONTENT_LENGTH':
1786
+					// defined on IIS and has the same value as CONTENT_LENGTH
1787
+					break;
1788
+
1789
+				case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
1790
+					/* The meaning of the Content-Location header in PUT
1791
+                     or POST requests is undefined; servers are free
1792
+                     to ignore it in those cases. */
1793
+					break;
1794
+
1795
+				case 'HTTP_CONTENT_RANGE':    // RFC 2616 14.16
1796
+					// single byte range requests are supported
1797
+					// the header format is also specified in RFC 2616 14.16
1798
+					// TODO we have to ensure that implementations support this or send 501 instead
1799
+					$matches = null;
1800
+					if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
1801
+						$this->http_status("400 bad request");
1802
+						echo "The service does only support single byte ranges";
1803
+						return;
1804
+					}
1805
+
1806
+					$range = array("start" => $matches[1], "end" => $matches[2]);
1807
+					if (is_numeric($matches[3])) {
1808
+						$range["total_length"] = $matches[3];
1809
+					}
1810
+
1811
+					if (!isset($options['ranges'])) {
1812
+						$options['ranges'] = array();
1813
+					}
1814
+
1815
+					$options["ranges"][] = $range;
1816
+
1817
+					// TODO make sure the implementation supports partial PUT
1818
+					// this has to be done in advance to avoid data being overwritten
1819
+					// on implementations that do not support this ...
1820
+					break;
1821
+
1822
+				case 'HTTP_CONTENT_TYPE':
1823
+					// defined on IIS and has the same value as CONTENT_TYPE
1824
+					break;
1825
+
1826
+				case 'HTTP_CONTENT_MD5':      // RFC 2616 14.15
1827
+					// TODO: maybe we can just pretend here?
1828
+					$this->http_status("501 not implemented");
1829
+					echo "The service does not support content MD5 checksum verification";
1830
+					return;
1831
+
1832
+				default:
1833
+					// any other unknown Content-* headers
1834
+					$this->http_status("501 not implemented");
1835
+					echo "The service does not support '$key'";
1836
+					return;
1837
+				}
1838
+			}
1839
+
1840
+			$stat = $this->PUT($options);
1841
+
1842
+			if ($stat === false) {
1843
+				$stat = "403 Forbidden";
1844
+			} else if (is_resource($stat) && get_resource_type($stat) == "stream") {
1845
+				$stream = $stat;
1846
+
1847
+				$stat = $options["new"] ? "201 Created" : "204 No Content";
1848
+
1849
+				if (!empty($options["ranges"])) {
1850
+					// TODO multipart support is missing (see also above)
1851
+					if (0 == fseek($stream, $options['ranges'][0]["start"], SEEK_SET)) {
1852
+						$length = $options['ranges'][0]["end"] - $options['ranges'][0]["start"]+1;
1853
+
1854
+						while (!feof($options['stream'])) {
1855
+							if ($length <= 0) {
1856
+							   break;
1857
+							}
1858
+
1859
+							if ($length <= 8192) {
1860
+								$data = fread($options['stream'], $length);
1861
+							} else {
1862
+								$data = fread($options['stream'], 8192);
1863
+							}
1864
+
1865
+							if ($data === false) {
1866
+								$stat = "400 Bad request";
1867
+							} elseif (strlen($data)) {
1868
+								if (false === fwrite($stream, $data)) {
1869
+									$stat = "403 Forbidden";
1870
+									break;
1871
+								}
1872
+								$length -= strlen($data);
1873
+							}
1874
+						}
1875
+					} else {
1876
+						$stat = "403 Forbidden";
1877
+					}
1878
+				} else {
1879
+					while (!feof($options["stream"])) {
1880
+						if (false === fwrite($stream, fread($options["stream"], 8192))) {
1881
+							$stat = "403 Forbidden";
1882
+							break;
1883
+						}
1884
+					}
1885
+				}
1886
+
1887
+				fclose($stream);
1888
+			}
1889
+
1890
+			$this->http_status($stat);
1891
+		} else {
1892
+			$this->http_status("423 Locked");
1893
+		}
1894
+	}
1895
+
1896
+	// }}}
1897
+
1898
+
1899
+	// {{{ http_DELETE()
1900
+
1901
+	/**
1902
+	 * DELETE method handler
1903
+	 *
1904
+	 * @param  void
1905
+	 * @return void
1906
+	 */
1907
+	function http_DELETE()
1908
+	{
1909
+		// check RFC 2518 Section 9.2, last paragraph
1910
+		if (isset($this->_SERVER["HTTP_DEPTH"])) {
1911
+			if ($this->_SERVER["HTTP_DEPTH"] != "infinity") {
1912
+				if (stripos($_SERVER['HTTP_USER_AGENT'],'webdrive') !== false)
1913
+				{
1914
+					// pretend we didnt see it, as webdrive does not handle the depth parameter correctly while deleting collections
1915
+				}
1916
+				else
1917
+				{
1918
+					$this->http_status("400 Bad Request");
1919
+					return;
1920
+				}
1921
+			}
1922
+		}
1923
+
1924
+		// check lock status
1925
+		if ($this->_check_lock_status($this->path)) {
1926
+			// ok, proceed
1927
+			$options         = Array();
1928
+			$options["path"] = $this->path;
1929
+
1930
+			$stat = $this->DELETE($options);
1931
+
1932
+			$this->http_status($stat);
1933
+		} else {
1934
+			// sorry, its locked
1935
+			$this->http_status("423 Locked");
1936
+		}
1937
+	}
1938
+
1939
+	// }}}
1940
+
1941
+	// {{{ http_COPY()
1942
+
1943
+	/**
1944
+	 * COPY method handler
1945
+	 *
1946
+	 * @param  void
1947
+	 * @return void
1948
+	 */
1949
+	function http_COPY()
1950
+	{
1951
+		// no need to check source lock status here
1952
+		// destination lock status is always checked by the helper method
1953
+		$this->_copymove("copy");
1954
+	}
1955
+
1956
+	// }}}
1957
+
1958
+	// {{{ http_MOVE()
1959
+
1960
+	/**
1961
+	 * MOVE method handler
1962
+	 *
1963
+	 * @param  void
1964
+	 * @return void
1965
+	 */
1966
+	function http_MOVE()
1967
+	{
1968
+		if ($this->_check_lock_status($this->path)) {
1969
+			// destination lock status is always checked by the helper method
1970
+			$this->_copymove("move");
1971
+		} else {
1972
+			$this->http_status("423 Locked");
1973
+		}
1974
+	}
1975
+
1976
+	// }}}
1977
+
1978
+
1979
+	// {{{ http_LOCK()
1980
+
1981
+	/**
1982
+	 * LOCK method handler
1983
+	 *
1984
+	 * @param  void
1985
+	 * @return void
1986
+	 */
1987
+	function http_LOCK()
1988
+	{
1989
+		$options         = Array();
1990
+		$options["path"] = $this->path;
1991
+
1992
+		if (isset($this->_SERVER['HTTP_DEPTH'])) {
1993
+			$options["depth"] = $this->_SERVER["HTTP_DEPTH"];
1994
+		} else {
1995
+			$options["depth"] = "infinity";
1996
+		}
1997
+
1998
+		if (isset($this->_SERVER["HTTP_TIMEOUT"])) {
1999
+			$options["timeout"] = explode(",", $this->_SERVER["HTTP_TIMEOUT"]);
2000
+		}
2001
+
2002
+		if (empty($this->_SERVER['CONTENT_LENGTH']) && !empty($this->_SERVER['HTTP_IF'])) {
2003
+			// check if locking is possible
2004
+			if (!$this->_check_lock_status($this->path)) {
2005
+				$this->http_status("423 Locked");
2006
+				return;
2007
+			}
2008
+
2009
+			// refresh lock
2010
+			$options["locktoken"] = substr($this->_SERVER['HTTP_IF'], 2, -2);
2011
+			$options["update"]    = $options["locktoken"];
2012
+
2013
+			// setting defaults for required fields, LOCK() SHOULD overwrite these
2014
+			$options['owner']     = "unknown";
2015
+			$options['scope']     = "exclusive";
2016
+			$options['type']      = "write";
2017
+
2018
+
2019
+			$stat = $this->LOCK($options);
2020
+		} else {
2021
+			// extract lock request information from request XML payload
2022
+			$lockinfo = new _parse_lockinfo("php://input");
2023
+			if (!$lockinfo->success) {
2024
+				$this->http_status("400 bad request");
2025
+			}
2026
+
2027
+			// check if locking is possible
2028
+			if (!$this->_check_lock_status($this->path, $lockinfo->lockscope === "shared")) {
2029
+				$this->http_status("423 Locked");
2030
+				return;
2031
+			}
2032
+
2033
+			// new lock
2034
+			$options["scope"]     = $lockinfo->lockscope;
2035
+			$options["type"]      = $lockinfo->locktype;
2036
+			// Todo: lockinfo::owner still contains D:href opening and closing tags, maybe they should be removed here with strip_tags
2037
+			$options["owner"]     = $lockinfo->owner;
2038
+			$options["locktoken"] = $this->_new_locktoken();
2039
+
2040
+			$stat = $this->LOCK($options);
2041
+		}
2042
+
2043
+		if (is_bool($stat)) {
2044
+			$http_stat = $stat ? "200 OK" : "423 Locked";
2045
+		} else {
2046
+			$http_stat = (string)$stat;
2047
+		}
2048
+		$this->http_status($http_stat);
2049
+
2050
+		if ($http_stat{0} == 2) { // 2xx states are ok
2051
+			if ($options["timeout"]) {
2052
+				// if multiple timeout values were given we take the first only
2053
+				if (is_array($options["timeout"])) {
2054
+					reset($options["timeout"]);
2055
+					$options["timeout"] = current($options["timeout"]);
2056
+				}
2057
+				// if the timeout is numeric only we need to reformat it
2058
+				if (is_numeric($options["timeout"])) {
2059
+					// more than a million is considered an absolute timestamp
2060
+					// less is more likely a relative value
2061
+					if ($options["timeout"]>1000000) {
2062
+						$timeout = "Second-".($options['timeout']-time());
2063
+					} else {
2064
+						$timeout = "Second-$options[timeout]";
2065
+					}
2066
+				} else {
2067
+					// non-numeric values are passed on verbatim,
2068
+					// no error checking is performed here in this case
2069
+					// TODO: send "Infinite" on invalid timeout strings?
2070
+					$timeout = $options["timeout"];
2071
+				}
2072
+			} else {
2073
+				$timeout = "Infinite";
2074
+			}
2075
+
2076
+			header('Content-Type: text/xml; charset="utf-8"');
2077
+			header("Lock-Token: <$options[locktoken]>");
2078
+			echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2079
+			echo "<D:prop xmlns:D=\"DAV:\">\n";
2080
+			echo ' <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2081
+			echo '  <'.($this->crrnd?'':'D:')."activelock>\n";
2082
+			echo '   <'.($this->crrnd?'':'D:')."lockscope><D:$options[scope]/></".($this->crrnd?'':'D:')."lockscope>\n";
2083
+			echo '   <'.($this->crrnd?'':'D:')."locktype><D:$options[type]/></".($this->crrnd?'':'D:')."locktype>\n";
2084
+			echo '   <'.($this->crrnd?'':'D:')."depth>$options[depth]</".($this->crrnd?'':'D:')."depth>\n";
2085
+			echo '   <'.($this->crrnd?'':'D:')."owner>$options[owner]</".($this->crrnd?'':'D:')."owner>\n";
2086
+			echo '   <'.($this->crrnd?'':'D:')."timeout>$timeout</".($this->crrnd?'':'D:')."timeout>\n";
2087
+			echo '   <'.($this->crrnd?'':'D:')."locktoken><D:href>$options[locktoken]</D:href></".($this->crrnd?'':'D:')."locktoken>\n";
2088
+			echo '  </'.($this->crrnd?'':'D:')."activelock>\n";
2089
+			echo ' </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2090
+			echo '</'.($this->crrnd?'':'D:')."prop>\n\n";
2091
+		}
2092
+	}
2093
+
2094
+
2095
+	// }}}
2096
+
2097
+	// {{{ http_UNLOCK()
2098
+
2099
+	/**
2100
+	 * UNLOCK method handler
2101
+	 *
2102
+	 * @param  void
2103
+	 * @return void
2104
+	 */
2105
+	function http_UNLOCK()
2106
+	{
2107
+		$options         = Array();
2108
+		$options["path"] = $this->path;
2109
+
2110
+		if (isset($this->_SERVER['HTTP_DEPTH'])) {
2111
+			$options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2112
+		} else {
2113
+			$options["depth"] = "infinity";
2114
+		}
2115
+
2116
+		// strip surrounding <>
2117
+		$options["token"] = substr(trim($this->_SERVER["HTTP_LOCK_TOKEN"]), 1, -1);
2118
+
2119
+		// call user method
2120
+		$stat = $this->UNLOCK($options);
2121
+
2122
+		$this->http_status($stat);
2123
+	}
2124
+
2125
+	// }}}
2126
+
2127
+	// {{{ http_ACL()
2128
+
2129
+	/**
2130
+	 * ACL method handler
2131
+	 *
2132
+	 * @param  void
2133
+	 * @return void
2134
+	 */
2135
+	function http_ACL()
2136
+	{
2137
+		$options         = Array();
2138
+		$options['path'] = $this->path;
2139
+		$options['errors'] = array();
2140
+
2141
+		if (isset($this->_SERVER['HTTP_DEPTH'])) {
2142
+			$options['depth'] = $this->_SERVER['HTTP_DEPTH'];
2143
+		} else {
2144
+			$options['depth'] = 'infinity';
2145
+		}
2146
+
2147
+		// call user method
2148
+		$status = $this->ACL($options);
2149
+
2150
+		// now we generate the reply header ...
2151
+		$this->http_status($status);
2152
+		$content = '';
2153
+
2154
+		if (is_array($options['errors']) && count($options['errors'])) {
2155
+			header('Content-Type: text/xml; charset="utf-8"');
2156
+			// ... and payload
2157
+			$content .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2158
+			$content .= "<D:error xmlns:D=\"DAV:\"> \n";
2159
+			foreach ($options['errors'] as $violation) {
2160
+				$content .= '<'.($this->crrnd?'':'D:')."$violation/>\n";
2161
+			}
2162
+			$content .=  '</'.($this->crrnd?'':'D:')."error>\n";
2163
+		}
2164
+		if (!self::use_compression()) header("Content-Length: ".self::bytes($content));
2165
+		if ($content) echo $options['content'];
2166
+	}
2167
+
2168
+	// }}}
2169
+
2170
+	// }}}
2171
+
2172
+	// {{{ _copymove()
2173
+
2174
+	function _copymove($what)
2175
+	{
2176
+		$options         = Array();
2177
+		$options["path"] = $this->path;
2178
+
2179
+		if (isset($this->_SERVER["HTTP_DEPTH"])) {
2180
+			$options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2181
+		} else {
2182
+			$options["depth"] = "infinity";
2183
+		}
2184
+
2185
+		$http_header_host = preg_replace("/:80$/", "", $this->_SERVER["HTTP_HOST"]);
2186
+
2187
+		$url  = parse_url($this->_SERVER["HTTP_DESTINATION"]);
2188
+		$path = urldecode($url["path"]);
2189
+
2190
+		if (isset($url["host"])) {
2191
+			// TODO check url scheme, too
2192
+			$http_host = $url["host"];
2193
+			if (isset($url["port"]) && $url["port"] != 80)
2194
+				$http_host.= ":".$url["port"];
2195
+		} else {
2196
+			// only path given, set host to self
2197
+			$http_host = $http_header_host;
2198
+		}
2199
+
2200
+		if ($http_host == $http_header_host &&
2201
+			!strncmp($this->_SERVER["SCRIPT_NAME"], $path,
2202
+					 strlen($this->_SERVER["SCRIPT_NAME"]))) {
2203
+			$options["dest"] = substr($path, strlen($this->_SERVER["SCRIPT_NAME"]));
2204
+			if (!$this->_check_lock_status($options["dest"])) {
2205
+				$this->http_status("423 Locked");
2206
+				return;
2207
+			}
2208
+
2209
+		} else {
2210
+			$options["dest_url"] = $this->_SERVER["HTTP_DESTINATION"];
2211
+		}
2212
+
2213
+		// see RFC 2518 Sections 9.6, 8.8.4 and 8.9.3
2214
+		if (isset($this->_SERVER["HTTP_OVERWRITE"])) {
2215
+			$options["overwrite"] = $this->_SERVER["HTTP_OVERWRITE"] == "T";
2216
+		} else {
2217
+			$options["overwrite"] = true;
2218
+		}
2219
+
2220
+		$stat = $this->$what($options);
2221
+		$this->http_status($stat);
2222
+	}
2223
+
2224
+	// }}}
2225
+
2226
+	// {{{ _allow()
2227
+
2228
+	/**
2229
+	 * check for implemented HTTP methods
2230
+	 *
2231
+	 * @param  void
2232
+	 * @return array something
2233
+	 */
2234
+	function _allow()
2235
+	{
2236
+		// OPTIONS is always there
2237
+		$allow = array("OPTIONS" =>"OPTIONS");
2238
+
2239
+		// all other METHODS need both a http_method() wrapper
2240
+		// and a method() implementation
2241
+		// the base class supplies wrappers only
2242
+		foreach (get_class_methods($this) as $method) {
2243
+			if (!strncmp("http_", $method, 5)) {
2244
+				$method = strtoupper(substr($method, 5));
2245
+				if (method_exists($this, $method)) {
2246
+					$allow[$method] = $method;
2247
+				}
2248
+			}
2249
+		}
1397 2250
 
2251
+		// we can emulate a missing HEAD implemetation using GET
2252
+		if (isset($allow["GET"]))
2253
+			$allow["HEAD"] = "HEAD";
1398 2254
 
1399
-    /**
1400
-     * parse HTTP Range: header
1401
-     *
1402
-     * @param  array options array to store result in
1403
-     * @return void
1404
-     */
1405
-    function _get_ranges(&$options)
1406
-    {
1407
-        // process Range: header if present
1408
-        if (isset($this->_SERVER['HTTP_RANGE'])) {
1409
-
1410
-            // we only support standard "bytes" range specifications for now
1411
-			$matches = null;
1412
-            if (preg_match('/bytes\s*=\s*(.+)/', $this->_SERVER['HTTP_RANGE'], $matches)) {
1413
-                $options["ranges"] = array();
1414
-
1415
-                // ranges are comma separated
1416
-                foreach (explode(",", $matches[1]) as $range) {
1417
-                    // ranges are either from-to pairs or just end positions
1418
-                    list($start, $end) = explode("-", $range);
1419
-                    $options["ranges"][] = ($start==="")
1420
-                        ? array("last"=>$end)
1421
-                        : array("start"=>$start, "end"=>$end);
1422
-                }
1423
-            }
1424
-        }
1425
-    }
2255
+		// no LOCK without checklok()
2256
+		if (!method_exists($this, "checklock")) {
2257
+			unset($allow["LOCK"]);
2258
+			unset($allow["UNLOCK"]);
2259
+		}
1426 2260
 
1427
-    /**
1428
-     * generate separator headers for multipart response
1429
-     *
1430
-     * first and last call happen without parameters to generate
1431
-     * the initial header and closing sequence, all calls inbetween
1432
-     * require content mimetype, start and end byte position and
1433
-     * optionaly the total byte length of the requested resource
1434
-     *
1435
-     * @param  string  mimetype
1436
-     * @param  int     start byte position
1437
-     * @param  int     end   byte position
1438
-     * @param  int     total resource byte size
1439
-     */
1440
-    function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false)
1441
-    {
1442
-        if ($mimetype === false) {
1443
-            if (!isset($this->multipart_separator)) {
1444
-                // initial
1445
-
1446
-                // a little naive, this sequence *might* be part of the content
1447
-                // but it's really not likely and rather expensive to check
1448
-                $this->multipart_separator = "SEPARATOR_".md5(microtime());
1449
-
1450
-                // generate HTTP header
1451
-                header("Content-type: multipart/byteranges; boundary=".$this->multipart_separator);
1452
-            } else {
1453
-                // final
1454
-
1455
-                // generate closing multipart sequence
1456
-                echo "\n--{$this->multipart_separator}--";
1457
-            }
1458
-        } else {
1459
-            // generate separator and header for next part
1460
-            echo "\n--{$this->multipart_separator}\n";
1461
-            echo "Content-type: $mimetype\n";
1462
-            echo "Content-range: $from-$to/". ($total === false ? "*" : $total);
1463
-            echo "\n\n";
1464
-        }
1465
-    }
1466
-
1467
-
1468
-
1469
-    // }}}
1470
-
1471
-    // {{{ http_HEAD()
2261
+		return $allow;
2262
+	}
1472 2263
 
1473
-    /**
1474
-     * HEAD method handler
1475
-     *
1476
-     * @param  void
1477
-     * @return void
1478
-     */
1479
-    function http_HEAD()
1480
-    {
1481
-        $status          = false;
1482
-        $options         = Array();
1483
-        $options["path"] = $this->path;
1484
-
1485
-        if (method_exists($this, "HEAD")) {
1486
-            $status = $this->head($options);
1487
-        } else if (method_exists($this, "GET")) {
1488
-            ob_start();
1489
-            $status = $this->GET($options);
1490
-            if (!isset($options['size'])) {
1491
-                $options['size'] = ob_get_length();
1492
-            }
1493
-            ob_end_clean();
1494
-        }
1495
-
1496
-        if (!isset($options['mimetype'])) {
1497
-            $options['mimetype'] = "application/octet-stream";
1498
-        }
1499
-        header("Content-type: $options[mimetype]");
1500
-
1501
-        if (isset($options['mtime'])) {
1502
-            header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1503
-        }
1504
-
1505
-        if (isset($options['size'])) {
1506
-            header("Content-Length: ".$options['size']);
1507
-        }
1508
-
1509
-        if ($status === true)  $status = "200 OK";
1510
-        if ($status === false) $status = "404 Not found";
1511
-
1512
-        $this->http_status($status);
1513
-    }
1514
-
1515
-    // }}}
1516
-
1517
-    // {{{ http_POST()
2264
+	// }}}
1518 2265
 
1519
-    /**
1520
-     * POST method handler
1521
-     *
1522
-     * @param  void
1523
-     * @return void
1524
-     */
1525
-    function http_POST()
1526
-    {
1527
-        $status          = '405 Method not allowed';
1528
-        $options         = Array();
1529
-        $options['path'] = $this->path;
1530
-
1531
-        if (isset($this->_SERVER['CONTENT_LENGTH']))
1532
-        {
1533
-	        $options['content_length'] = $this->_SERVER['CONTENT_LENGTH'];
1534
-        }
1535
-        elseif (isset($this->_SERVER['X-Expected-Entity-Length']))
1536
-		{
1537
-	        // MacOS gives us that hint
1538
-	        $options['content_length'] = $this->_SERVER['X-Expected-Entity-Length'];
1539
-		}
1540
-
1541
-        // get the Content-type
1542
-        if (isset($this->_SERVER["CONTENT_TYPE"])) {
1543
-	        // for now we do not support any sort of multipart requests
1544
-	        if (!strncmp($this->_SERVER["CONTENT_TYPE"], 'multipart/', 10)) {
1545
-		        $this->http_status('501 not implemented');
1546
-		        echo 'The service does not support mulipart POST requests';
1547
-		        return;
1548
-	        }
1549
-	        $options['content_type'] = $this->_SERVER['CONTENT_TYPE'];
1550
-        } else {
1551
-	        // default content type if none given
1552
-	        $options['content_type'] = 'application/octet-stream';
1553
-        }
1554
-
1555
-        $options['stream'] = fopen('php://input', 'r');
1556
-    	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1557
-    	{
1558
-    		case 'gzip':
1559
-    		case 'deflate':	//zlib
1560
-    			if (extension_loaded('zlib'))
1561
-     			{
1562
-      				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1563
-       			}
1564
-    	}
1565
-		// store request in $this->request, if requested via $this->store_request
1566
-		if ($this->store_request)
1567
-		{
1568
-			$options['content'] = '';
1569
-			while(!feof($options['stream']))
1570
-			{
1571
-				$options['content'] .= fread($options['stream'],8192);
1572
-			}
1573
-			$this->request =& $options['content'];
1574
-			unset($options['stream']);
2266
+	/**
2267
+	 * helper for property element creation
2268
+	 *
2269
+	 * @param  string  XML namespace (optional)
2270
+	 * @param  string  property name
2271
+	 * @param  string  property value
2272
+	 * @praram boolen  property raw-flag
2273
+	 * @return array   property array
2274
+	 */
2275
+	public static function mkprop()
2276
+	{
2277
+		$args = func_get_args();
2278
+		switch (count($args)) {
2279
+			case 4:
2280
+				return array('ns'   => $args[0],
2281
+					'name' => $args[1],
2282
+					'val'  => $args[2],
2283
+					'raw'	=> true);
2284
+			case 3:
2285
+				return array('ns'   => $args[0],
2286
+					'name' => $args[1],
2287
+					'val'  => $args[2]);
2288
+			default:
2289
+				return array('ns'   => 'DAV:',
2290
+					'name' => $args[0],
2291
+					'val'  => $args[1]);
1575 2292
 		}
2293
+	}
1576 2294
 
1577
-        /* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
1578
-         ignore any Content-* (e.g. Content-Range) headers that it
1579
-         does not understand or implement and MUST return a 501
1580
-         (Not Implemented) response in such cases."
1581
-         */
1582
-        foreach ($this->_SERVER as $key => $val) {
1583
-	        if (strncmp($key, 'HTTP_CONTENT', 11)) continue;
1584
-	        switch ($key) {
1585
-		        case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1586
-		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1587
-		        	{
1588
-		        		case 'gzip':
1589
-		        		case 'deflate':	//zlib
1590
-		        			if (extension_loaded('zlib')) break;
1591
-		        			// fall through for no zlib support
1592
-		        		default:
1593
-					        $this->http_status('415 Unsupported Media Type');
1594
-					        echo "The service does not support '$val' content encoding";
1595
-					        return;
1596
-		        	}
1597
-		        	break;
1598
-
1599
-		        case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12
1600
-			        // we assume it is not critical if this one is ignored
1601
-			        // in the actual POST implementation ...
1602
-			        $options['content_language'] = $val;
1603
-			        break;
1604
-
1605
-		        case 'HTTP_CONTENT_LENGTH':
1606
-			        // defined on IIS and has the same value as CONTENT_LENGTH
1607
-			        break;
1608
-
1609
-		        case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
1610
-			        /* The meaning of the Content-Location header in PUT
1611
-			         or POST requests is undefined; servers are free
1612
-			         to ignore it in those cases. */
1613
-			        break;
2295
+	// {{{ _check_auth
1614 2296
 
1615
-		        case 'HTTP_CONTENT_RANGE':    // RFC 2616 14.16
1616
-			        // single byte range requests are supported
1617
-			        // the header format is also specified in RFC 2616 14.16
1618
-			        // TODO we have to ensure that implementations support this or send 501 instead
1619
-					$matches = null;
1620
-			        if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
1621
-				        $this->http_status('400 bad request');
1622
-				        echo 'The service does only support single byte ranges';
1623
-				        return;
1624
-			        }
1625
-
1626
-			        $range = array('start'=>$matches[1], 'end'=>$matches[2]);
1627
-			        if (is_numeric($matches[3])) {
1628
-				        $range['total_length'] = $matches[3];
1629
-			        }
1630
-			        $options['ranges'][] = $range;
1631
-
1632
-			        // TODO make sure the implementation supports partial POST
1633
-			        // this has to be done in advance to avoid data being overwritten
1634
-			        // on implementations that do not support this ...
1635
-			        break;
1636
-
1637
-		        case 'HTTP_CONTENT_TYPE':
1638
-			        // defined on IIS and has the same value as CONTENT_TYPE
1639
-			        break;
1640
-
1641
-		        case 'HTTP_CONTENT_MD5':      // RFC 2616 14.15
1642
-			        // TODO: maybe we can just pretend here?
1643
-			        $this->http_status('501 not implemented');
1644
-			        echo 'The service does not support content MD5 checksum verification';
1645
-			        return;
1646
-
1647
-		        case 'HTTP_CONTENT_DISPOSITION':
1648
-		        	// do NOT care about Content-Disposition in POST requests required by CalDAV managed attachments
1649
-		        	break;
1650
-
1651
-		        default:
1652
-			        // any other unknown Content-* headers
1653
-			        $this->http_status('501 not implemented');
1654
-		        echo "The service does not support '$key'";
1655
-		        return;
1656
-	        }
1657
-        }
1658
-
1659
-        if (method_exists($this, 'POST')) {
1660
-	        $status = $this->POST($options);
1661
-
1662
-	        if ($status === false) {
1663
-		        $status = '400 Something went wrong';
1664
-	        } else if ($status === true) {
1665
-	        	$status = '200 OK';
1666
-	        } else if (is_resource($status) && get_resource_type($status) == 'stream') {
1667
-		        $stream = $status;
1668
-
1669
-		        $status = empty($options['new']) ? '200 OK' : '201 Created';
1670
-
1671
-		        if (!empty($options['ranges'])) {
1672
-			        // TODO multipart support is missing (see also above)
1673
-			        if (0 == fseek($stream, $range[0]['start'], SEEK_SET)) {
1674
-				        $length = $range[0]['end']-$range[0]['start']+1;
1675
-				        if (!fwrite($stream, fread($options['stream'], $length))) {
1676
-					        $status = '403 Forbidden';
1677
-				        }
1678
-			        } else {
1679
-				        $status = '403 Forbidden';
1680
-			        }
1681
-		        } else {
1682
-			        while (!feof($options['stream'])) {
1683
-				        if (false === fwrite($stream, fread($options['stream'], 4096))) {
1684
-					        $status = '403 Forbidden';
1685
-					        break;
1686
-				        }
1687
-			        }
1688
-		        }
1689
-		        fclose($stream);
1690
-	        }
1691
-        }
1692
-        $this->http_status($status);
1693
-    }
1694
-
1695
-    // }}}
1696
-
1697
-    // {{{ http_PUT()
2297
+	/**
2298
+	 * check authentication if check is implemented
2299
+	 *
2300
+	 * @param  void
2301
+	 * @return bool  true if authentication succeded or not necessary
2302
+	 */
2303
+	function _check_auth()
2304
+	{
2305
+		if (method_exists($this, "checkAuth")) {
2306
+			// PEAR style method name
2307
+			return $this->checkAuth(@$this->_SERVER["AUTH_TYPE"],
2308
+									@$this->_SERVER["PHP_AUTH_USER"],
2309
+									@$this->_SERVER["PHP_AUTH_PW"]);
2310
+		} else if (method_exists($this, "check_auth")) {
2311
+			// old (pre 1.0) method name
2312
+			return $this->check_auth(@$this->_SERVER["AUTH_TYPE"],
2313
+									 @$this->_SERVER["PHP_AUTH_USER"],
2314
+									 @$this->_SERVER["PHP_AUTH_PW"]);
2315
+		} else {
2316
+			// no method found -> no authentication required
2317
+			return true;
2318
+		}
2319
+	}
1698 2320
 
1699
-    /**
1700
-     * PUT method handler
1701
-     *
1702
-     * @param  void
1703
-     * @return void
1704
-     */
1705
-    function http_PUT()
1706
-    {
1707
-        if ($this->_check_lock_status($this->path)) {
1708
-            $options                   = Array();
1709
-            $options["path"]           = $this->path;
1710
-
1711
-            if (isset($this->_SERVER['CONTENT_LENGTH']))
1712
-            {
1713
-            	$options['content_length'] = $this->_SERVER['CONTENT_LENGTH'];
1714
-            }
1715
-            elseif (isset($this->_SERVER['X-Expected-Entity-Length']))
1716
-            {
1717
-            	// MacOS gives us that hint
1718
-            	$options['content_length'] = $this->_SERVER['X-Expected-Entity-Length'];
1719
-            }
1720
-
1721
-            // get the Content-type
1722
-            if (isset($this->_SERVER["CONTENT_TYPE"])) {
1723
-                // for now we do not support any sort of multipart requests
1724
-                if (!strncmp($this->_SERVER["CONTENT_TYPE"], "multipart/", 10)) {
1725
-                    $this->http_status("501 not implemented");
1726
-                    echo "The service does not support multipart PUT requests";
1727
-                    return;
1728
-                }
1729
-                $options["content_type"] = $this->_SERVER["CONTENT_TYPE"];
1730
-            } else {
1731
-                // default content type if none given
1732
-                $options["content_type"] = "application/octet-stream";
1733
-            }
1734
-
1735
-            $options["stream"] = fopen("php://input", "r");
1736
-	    	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1737
-	    	{
1738
-	    		case 'gzip':
1739
-	    		case 'deflate':	//zlib
1740
-	    			if (extension_loaded('zlib'))
1741
-	     			{
1742
-	      				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1743
-	       			}
1744
-	    	}
1745
-			// store request in $this->request, if requested via $this->store_request
1746
-			if ($this->store_request)
1747
-			{
1748
-				$options['content'] = '';
1749
-				while(!feof($options['stream']))
1750
-				{
1751
-					$options['content'] .= fread($options['stream'],8192);
1752
-				}
1753
-				$this->request =& $options['content'];
1754
-				unset($options['stream']);
1755
-			}
2321
+	// }}}
1756 2322
 
1757
-            /* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
1758
-             ignore any Content-* (e.g. Content-Range) headers that it
1759
-             does not understand or implement and MUST return a 501
1760
-             (Not Implemented) response in such cases."
1761
-            */
1762
-            foreach ($this->_SERVER as $key => $val) {
1763
-                if (strncmp($key, "HTTP_CONTENT", 11)) continue;
1764
-                switch ($key) {
1765
-                case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1766
-		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1767
-		        	{
1768
-		        		case 'gzip':
1769
-		        		case 'deflate':	//zlib
1770
-		        			if (extension_loaded('zlib')) break;
1771
-		        			// fall through for no zlib support
1772
-		        		default:
1773
-					        $this->http_status('415 Unsupported Media Type');
1774
-					        echo "The service does not support '$val' content encoding";
1775
-					        return;
1776
-		        	}
1777
-		        	break;
1778
-
1779
-                case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12
1780
-                    // we assume it is not critical if this one is ignored
1781
-                    // in the actual PUT implementation ...
1782
-                    $options["content_language"] = $val;
1783
-                    break;
1784
-
1785
-                case 'HTTP_CONTENT_LENGTH':
1786
-                    // defined on IIS and has the same value as CONTENT_LENGTH
1787
-                    break;
1788
-
1789
-                case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
1790
-                    /* The meaning of the Content-Location header in PUT
1791
-                     or POST requests is undefined; servers are free
1792
-                     to ignore it in those cases. */
1793
-                    break;
2323
+	// {{{ UUID stuff
1794 2324
 
1795
-                case 'HTTP_CONTENT_RANGE':    // RFC 2616 14.16
1796
-                    // single byte range requests are supported
1797
-                    // the header format is also specified in RFC 2616 14.16
1798
-                    // TODO we have to ensure that implementations support this or send 501 instead
1799
-					$matches = null;
1800
-                    if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
1801
-                        $this->http_status("400 bad request");
1802
-                        echo "The service does only support single byte ranges";
1803
-                        return;
1804
-                    }
1805
-
1806
-                    $range = array("start" => $matches[1], "end" => $matches[2]);
1807
-                    if (is_numeric($matches[3])) {
1808
-                        $range["total_length"] = $matches[3];
1809
-                    }
1810
-
1811
-                    if (!isset($options['ranges'])) {
1812
-                        $options['ranges'] = array();
1813
-                    }
1814
-
1815
-                    $options["ranges"][] = $range;
1816
-
1817
-                    // TODO make sure the implementation supports partial PUT
1818
-                    // this has to be done in advance to avoid data being overwritten
1819
-                    // on implementations that do not support this ...
1820
-                    break;
1821
-
1822
-                case 'HTTP_CONTENT_TYPE':
1823
-                    // defined on IIS and has the same value as CONTENT_TYPE
1824
-                    break;
1825
-
1826
-                case 'HTTP_CONTENT_MD5':      // RFC 2616 14.15
1827
-                    // TODO: maybe we can just pretend here?
1828
-                    $this->http_status("501 not implemented");
1829
-                    echo "The service does not support content MD5 checksum verification";
1830
-                    return;
1831
-
1832
-                default:
1833
-                    // any other unknown Content-* headers
1834
-                    $this->http_status("501 not implemented");
1835
-                    echo "The service does not support '$key'";
1836
-                    return;
1837
-                }
1838
-            }
1839
-
1840
-            $stat = $this->PUT($options);
1841
-
1842
-            if ($stat === false) {
1843
-                $stat = "403 Forbidden";
1844
-            } else if (is_resource($stat) && get_resource_type($stat) == "stream") {
1845
-                $stream = $stat;
1846
-
1847
-                $stat = $options["new"] ? "201 Created" : "204 No Content";
1848
-
1849
-                if (!empty($options["ranges"])) {
1850
-                    // TODO multipart support is missing (see also above)
1851
-                    if (0 == fseek($stream, $options['ranges'][0]["start"], SEEK_SET)) {
1852
-                        $length = $options['ranges'][0]["end"] - $options['ranges'][0]["start"]+1;
1853
-
1854
-                        while (!feof($options['stream'])) {
1855
-                            if ($length <= 0) {
1856
-                               break;
1857
-                            }
1858
-
1859
-                            if ($length <= 8192) {
1860
-                                $data = fread($options['stream'], $length);
1861
-                            } else {
1862
-                                $data = fread($options['stream'], 8192);
1863
-                            }
1864
-
1865
-                            if ($data === false) {
1866
-                                $stat = "400 Bad request";
1867
-                            } elseif (strlen($data)) {
1868
-                                if (false === fwrite($stream, $data)) {
1869
-                                    $stat = "403 Forbidden";
1870
-                                    break;
1871
-                                }
1872
-                                $length -= strlen($data);
1873
-                            }
1874
-                        }
1875
-                    } else {
1876
-                        $stat = "403 Forbidden";
1877
-                    }
1878
-                } else {
1879
-                    while (!feof($options["stream"])) {
1880
-                        if (false === fwrite($stream, fread($options["stream"], 8192))) {
1881
-                            $stat = "403 Forbidden";
1882
-                            break;
1883
-                        }
1884
-                    }
1885
-                }
1886
-
1887
-                fclose($stream);
1888
-            }
1889
-
1890
-            $this->http_status($stat);
1891
-        } else {
1892
-            $this->http_status("423 Locked");
1893
-        }
1894
-    }
1895
-
1896
-    // }}}
1897
-
1898
-
1899
-    // {{{ http_DELETE()
2325
+	/**
2326
+	 * generate Unique Universal IDentifier for lock token
2327
+	 *
2328
+	 * @param  void
2329
+	 * @return string  a new UUID
2330
+	 */
2331
+	public static function _new_uuid()
2332
+	{
2333
+		// use uuid extension from PECL if available
2334
+		if (function_exists("uuid_create")) {
2335
+			return uuid_create();
2336
+		}
1900 2337
 
1901
-    /**
1902
-     * DELETE method handler
1903
-     *
1904
-     * @param  void
1905
-     * @return void
1906
-     */
1907
-    function http_DELETE()
1908
-    {
1909
-        // check RFC 2518 Section 9.2, last paragraph
1910
-        if (isset($this->_SERVER["HTTP_DEPTH"])) {
1911
-            if ($this->_SERVER["HTTP_DEPTH"] != "infinity") {
1912
-				if (stripos($_SERVER['HTTP_USER_AGENT'],'webdrive') !== false)
1913
-				{
1914
-					// pretend we didnt see it, as webdrive does not handle the depth parameter correctly while deleting collections
1915
-				}
1916
-				else
1917
-				{
1918
-                	$this->http_status("400 Bad Request");
1919
-                	return;
1920
-				}
1921
-            }
1922
-        }
2338
+		// fallback
2339
+		$uuid = md5(microtime().getmypid());    // this should be random enough for now
2340
+
2341
+		// set variant and version fields for 'true' random uuid
2342
+		$uuid{12} = "4";
2343
+		$n = 8 + (ord($uuid{16}) & 3);
2344
+		$hex = "0123456789abcdef";
2345
+		$uuid{16} = $hex{$n};
2346
+
2347
+		// return formated uuid
2348
+		return substr($uuid,  0, 8)."-"
2349
+			.  substr($uuid,  8, 4)."-"
2350
+			.  substr($uuid, 12, 4)."-"
2351
+			.  substr($uuid, 16, 4)."-"
2352
+			.  substr($uuid, 20);
2353
+	}
1923 2354
 
1924
-        // check lock status
1925
-        if ($this->_check_lock_status($this->path)) {
1926
-            // ok, proceed
1927
-            $options         = Array();
1928
-            $options["path"] = $this->path;
2355
+	/**
2356
+	 * create a new opaque lock token as defined in RFC2518
2357
+	 *
2358
+	 * @param  void
2359
+	 * @return string  new RFC2518 opaque lock token
2360
+	 */
2361
+	public static function _new_locktoken()
2362
+	{
2363
+		return "opaquelocktoken:".self::_new_uuid();
2364
+	}
1929 2365
 
1930
-            $stat = $this->DELETE($options);
2366
+	// }}}
1931 2367
 
1932
-            $this->http_status($stat);
1933
-        } else {
1934
-            // sorry, its locked
1935
-            $this->http_status("423 Locked");
1936
-        }
1937
-    }
2368
+	// {{{ WebDAV If: header parsing
1938 2369
 
1939
-    // }}}
2370
+	/**
2371
+	 *
2372
+	 *
2373
+	 * @param  string  header string to parse
2374
+	 * @param  int     current parsing position
2375
+	 * @return array   next token (type and value)
2376
+	 */
2377
+	function _if_header_lexer($string, &$pos)
2378
+	{
2379
+		// skip whitespace
2380
+		while (ctype_space($string{$pos})) {
2381
+			++$pos;
2382
+		}
1940 2383
 
1941
-    // {{{ http_COPY()
2384
+		// already at end of string?
2385
+		if (strlen($string) <= $pos) {
2386
+			return false;
2387
+		}
1942 2388
 
1943
-    /**
1944
-     * COPY method handler
1945
-     *
1946
-     * @param  void
1947
-     * @return void
1948
-     */
1949
-    function http_COPY()
1950
-    {
1951
-        // no need to check source lock status here
1952
-        // destination lock status is always checked by the helper method
1953
-        $this->_copymove("copy");
1954
-    }
1955
-
1956
-    // }}}
1957
-
1958
-    // {{{ http_MOVE()
2389
+		// get next character
2390
+		$c = $string{$pos++};
2391
+
2392
+		// now it depends on what we found
2393
+		switch ($c) {
2394
+		case "<":
2395
+			// URIs are enclosed in <...>
2396
+			$pos2 = strpos($string, ">", $pos);
2397
+			$uri  = substr($string, $pos, $pos2 - $pos);
2398
+			$pos  = $pos2 + 1;
2399
+			return array("URI", $uri);
2400
+
2401
+		case "[":
2402
+			//Etags are enclosed in [...]
2403
+			if ($string{$pos} == "W") {
2404
+				$type = "ETAG_WEAK";
2405
+				$pos += 2;
2406
+			} else {
2407
+				$type = "ETAG_STRONG";
2408
+			}
2409
+			$pos2 = strpos($string, "]", $pos);
2410
+			$etag = substr($string, $pos + 1, $pos2 - $pos - 2);
2411
+			$pos  = $pos2 + 1;
2412
+			return array($type, $etag);
2413
+
2414
+		case "N":
2415
+			// "N" indicates negation
2416
+			$pos += 2;
2417
+			return array("NOT", "Not");
2418
+
2419
+		default:
2420
+			// anything else is passed verbatim char by char
2421
+			return array("CHAR", $c);
2422
+		}
2423
+	}
1959 2424
 
1960
-    /**
1961
-     * MOVE method handler
1962
-     *
1963
-     * @param  void
1964
-     * @return void
1965
-     */
1966
-    function http_MOVE()
1967
-    {
1968
-        if ($this->_check_lock_status($this->path)) {
1969
-            // destination lock status is always checked by the helper method
1970
-            $this->_copymove("move");
1971
-        } else {
1972
-            $this->http_status("423 Locked");
1973
-        }
1974
-    }
1975
-
1976
-    // }}}
1977
-
1978
-
1979
-    // {{{ http_LOCK()
2425
+	/**
2426
+	 * parse If: header
2427
+	 *
2428
+	 * @param  string  header string
2429
+	 * @return array   URIs and their conditions
2430
+	 */
2431
+	function _if_header_parser($str)
2432
+	{
2433
+		$pos  = 0;
2434
+		$len  = strlen($str);
2435
+		$uris = array();
2436
+
2437
+		// parser loop
2438
+		while ($pos < $len) {
2439
+			// get next token
2440
+			$token = $this->_if_header_lexer($str, $pos);
2441
+
2442
+			// check for URI
2443
+			if ($token[0] == "URI") {
2444
+				$uri   = $token[1]; // remember URI
2445
+				$token = $this->_if_header_lexer($str, $pos); // get next token
2446
+			} else {
2447
+				$uri = "";
2448
+			}
1980 2449
 
1981
-    /**
1982
-     * LOCK method handler
1983
-     *
1984
-     * @param  void
1985
-     * @return void
1986
-     */
1987
-    function http_LOCK()
1988
-    {
1989
-        $options         = Array();
1990
-        $options["path"] = $this->path;
1991
-
1992
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
1993
-            $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
1994
-        } else {
1995
-            $options["depth"] = "infinity";
1996
-        }
1997
-
1998
-        if (isset($this->_SERVER["HTTP_TIMEOUT"])) {
1999
-            $options["timeout"] = explode(",", $this->_SERVER["HTTP_TIMEOUT"]);
2000
-        }
2001
-
2002
-        if (empty($this->_SERVER['CONTENT_LENGTH']) && !empty($this->_SERVER['HTTP_IF'])) {
2003
-            // check if locking is possible
2004
-            if (!$this->_check_lock_status($this->path)) {
2005
-                $this->http_status("423 Locked");
2006
-                return;
2007
-            }
2008
-
2009
-            // refresh lock
2010
-            $options["locktoken"] = substr($this->_SERVER['HTTP_IF'], 2, -2);
2011
-            $options["update"]    = $options["locktoken"];
2012
-
2013
-            // setting defaults for required fields, LOCK() SHOULD overwrite these
2014
-            $options['owner']     = "unknown";
2015
-            $options['scope']     = "exclusive";
2016
-            $options['type']      = "write";
2017
-
2018
-
2019
-            $stat = $this->LOCK($options);
2020
-        } else {
2021
-            // extract lock request information from request XML payload
2022
-            $lockinfo = new _parse_lockinfo("php://input");
2023
-            if (!$lockinfo->success) {
2024
-                $this->http_status("400 bad request");
2025
-            }
2026
-
2027
-            // check if locking is possible
2028
-            if (!$this->_check_lock_status($this->path, $lockinfo->lockscope === "shared")) {
2029
-                $this->http_status("423 Locked");
2030
-                return;
2031
-            }
2032
-
2033
-            // new lock
2034
-            $options["scope"]     = $lockinfo->lockscope;
2035
-            $options["type"]      = $lockinfo->locktype;
2036
-            // Todo: lockinfo::owner still contains D:href opening and closing tags, maybe they should be removed here with strip_tags
2037
-            $options["owner"]     = $lockinfo->owner;
2038
-            $options["locktoken"] = $this->_new_locktoken();
2039
-
2040
-            $stat = $this->LOCK($options);
2041
-        }
2042
-
2043
-        if (is_bool($stat)) {
2044
-            $http_stat = $stat ? "200 OK" : "423 Locked";
2045
-        } else {
2046
-            $http_stat = (string)$stat;
2047
-        }
2048
-        $this->http_status($http_stat);
2049
-
2050
-        if ($http_stat{0} == 2) { // 2xx states are ok
2051
-            if ($options["timeout"]) {
2052
-                // if multiple timeout values were given we take the first only
2053
-                if (is_array($options["timeout"])) {
2054
-                    reset($options["timeout"]);
2055
-                    $options["timeout"] = current($options["timeout"]);
2056
-                }
2057
-                // if the timeout is numeric only we need to reformat it
2058
-                if (is_numeric($options["timeout"])) {
2059
-                    // more than a million is considered an absolute timestamp
2060
-                    // less is more likely a relative value
2061
-                    if ($options["timeout"]>1000000) {
2062
-                        $timeout = "Second-".($options['timeout']-time());
2063
-                    } else {
2064
-                        $timeout = "Second-$options[timeout]";
2065
-                    }
2066
-                } else {
2067
-                    // non-numeric values are passed on verbatim,
2068
-                    // no error checking is performed here in this case
2069
-                    // TODO: send "Infinite" on invalid timeout strings?
2070
-                    $timeout = $options["timeout"];
2071
-                }
2072
-            } else {
2073
-                $timeout = "Infinite";
2074
-            }
2075
-
2076
-            header('Content-Type: text/xml; charset="utf-8"');
2077
-            header("Lock-Token: <$options[locktoken]>");
2078
-            echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2079
-            echo "<D:prop xmlns:D=\"DAV:\">\n";
2080
-            echo ' <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2081
-            echo '  <'.($this->crrnd?'':'D:')."activelock>\n";
2082
-            echo '   <'.($this->crrnd?'':'D:')."lockscope><D:$options[scope]/></".($this->crrnd?'':'D:')."lockscope>\n";
2083
-            echo '   <'.($this->crrnd?'':'D:')."locktype><D:$options[type]/></".($this->crrnd?'':'D:')."locktype>\n";
2084
-            echo '   <'.($this->crrnd?'':'D:')."depth>$options[depth]</".($this->crrnd?'':'D:')."depth>\n";
2085
-            echo '   <'.($this->crrnd?'':'D:')."owner>$options[owner]</".($this->crrnd?'':'D:')."owner>\n";
2086
-            echo '   <'.($this->crrnd?'':'D:')."timeout>$timeout</".($this->crrnd?'':'D:')."timeout>\n";
2087
-            echo '   <'.($this->crrnd?'':'D:')."locktoken><D:href>$options[locktoken]</D:href></".($this->crrnd?'':'D:')."locktoken>\n";
2088
-            echo '  </'.($this->crrnd?'':'D:')."activelock>\n";
2089
-            echo ' </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2090
-            echo '</'.($this->crrnd?'':'D:')."prop>\n\n";
2091
-        }
2092
-    }
2093
-
2094
-
2095
-    // }}}
2096
-
2097
-    // {{{ http_UNLOCK()
2450
+			// sanity check
2451
+			if ($token[0] != "CHAR" || $token[1] != "(") {
2452
+				return false;
2453
+			}
2098 2454
 
2099
-    /**
2100
-     * UNLOCK method handler
2101
-     *
2102
-     * @param  void
2103
-     * @return void
2104
-     */
2105
-    function http_UNLOCK()
2106
-    {
2107
-        $options         = Array();
2108
-        $options["path"] = $this->path;
2109
-
2110
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
2111
-            $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2112
-        } else {
2113
-            $options["depth"] = "infinity";
2114
-        }
2115
-
2116
-        // strip surrounding <>
2117
-        $options["token"] = substr(trim($this->_SERVER["HTTP_LOCK_TOKEN"]), 1, -1);
2118
-
2119
-        // call user method
2120
-        $stat = $this->UNLOCK($options);
2121
-
2122
-        $this->http_status($stat);
2123
-    }
2124
-
2125
-    // }}}
2126
-
2127
-    // {{{ http_ACL()
2128
-
2129
-	/**
2130
-     * ACL method handler
2131
-     *
2132
-     * @param  void
2133
-     * @return void
2134
-     */
2135
-    function http_ACL()
2136
-    {
2137
-        $options         = Array();
2138
-        $options['path'] = $this->path;
2139
-        $options['errors'] = array();
2140
-
2141
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
2142
-            $options['depth'] = $this->_SERVER['HTTP_DEPTH'];
2143
-        } else {
2144
-            $options['depth'] = 'infinity';
2145
-        }
2146
-
2147
-        // call user method
2148
-        $status = $this->ACL($options);
2455
+			$list  = array();
2456
+			$level = 1;
2457
+			$not   = "";
2458
+			while ($level) {
2459
+				$token = $this->_if_header_lexer($str, $pos);
2460
+				if ($token[0] == "NOT") {
2461
+					$not = "!";
2462
+					continue;
2463
+				}
2464
+				switch ($token[0]) {
2465
+				case "CHAR":
2466
+					switch ($token[1]) {
2467
+					case "(":
2468
+						$level++;
2469
+						break;
2470
+					case ")":
2471
+						$level--;
2472
+						break;
2473
+					default:
2474
+						return false;
2475
+					}
2476
+					break;
2149 2477
 
2150
-		// now we generate the reply header ...
2151
-		$this->http_status($status);
2152
-		$content = '';
2478
+				case "URI":
2479
+					$list[] = $not."<$token[1]>";
2480
+					break;
2153 2481
 
2154
-        if (is_array($options['errors']) && count($options['errors'])) {
2155
-	        header('Content-Type: text/xml; charset="utf-8"');
2156
-	        // ... and payload
2157
-	        $content .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2158
-	        $content .= "<D:error xmlns:D=\"DAV:\"> \n";
2159
-	        foreach ($options['errors'] as $violation) {
2160
-	        	$content .= '<'.($this->crrnd?'':'D:')."$violation/>\n";
2161
-	        }
2162
-	        $content .=  '</'.($this->crrnd?'':'D:')."error>\n";
2163
-        }
2164
-        if (!self::use_compression()) header("Content-Length: ".self::bytes($content));
2165
-        if ($content) echo $options['content'];
2166
-    }
2167
-
2168
-    // }}}
2169
-
2170
-    // }}}
2171
-
2172
-    // {{{ _copymove()
2173
-
2174
-    function _copymove($what)
2175
-    {
2176
-        $options         = Array();
2177
-        $options["path"] = $this->path;
2178
-
2179
-        if (isset($this->_SERVER["HTTP_DEPTH"])) {
2180
-            $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2181
-        } else {
2182
-            $options["depth"] = "infinity";
2183
-        }
2184
-
2185
-        $http_header_host = preg_replace("/:80$/", "", $this->_SERVER["HTTP_HOST"]);
2186
-
2187
-        $url  = parse_url($this->_SERVER["HTTP_DESTINATION"]);
2188
-        $path = urldecode($url["path"]);
2189
-
2190
-        if (isset($url["host"])) {
2191
-            // TODO check url scheme, too
2192
-            $http_host = $url["host"];
2193
-            if (isset($url["port"]) && $url["port"] != 80)
2194
-                $http_host.= ":".$url["port"];
2195
-        } else {
2196
-            // only path given, set host to self
2197
-            $http_host = $http_header_host;
2198
-        }
2199
-
2200
-        if ($http_host == $http_header_host &&
2201
-            !strncmp($this->_SERVER["SCRIPT_NAME"], $path,
2202
-                     strlen($this->_SERVER["SCRIPT_NAME"]))) {
2203
-            $options["dest"] = substr($path, strlen($this->_SERVER["SCRIPT_NAME"]));
2204
-            if (!$this->_check_lock_status($options["dest"])) {
2205
-                $this->http_status("423 Locked");
2206
-                return;
2207
-            }
2208
-
2209
-        } else {
2210
-            $options["dest_url"] = $this->_SERVER["HTTP_DESTINATION"];
2211
-        }
2212
-
2213
-        // see RFC 2518 Sections 9.6, 8.8.4 and 8.9.3
2214
-        if (isset($this->_SERVER["HTTP_OVERWRITE"])) {
2215
-            $options["overwrite"] = $this->_SERVER["HTTP_OVERWRITE"] == "T";
2216
-        } else {
2217
-            $options["overwrite"] = true;
2218
-        }
2219
-
2220
-        $stat = $this->$what($options);
2221
-        $this->http_status($stat);
2222
-    }
2223
-
2224
-    // }}}
2225
-
2226
-    // {{{ _allow()
2482
+				case "ETAG_WEAK":
2483
+					$list[] = $not."[W/'$token[1]']>";
2484
+					break;
2227 2485
 
2228
-    /**
2229
-     * check for implemented HTTP methods
2230
-     *
2231
-     * @param  void
2232
-     * @return array something
2233
-     */
2234
-    function _allow()
2235
-    {
2236
-        // OPTIONS is always there
2237
-        $allow = array("OPTIONS" =>"OPTIONS");
2238
-
2239
-        // all other METHODS need both a http_method() wrapper
2240
-        // and a method() implementation
2241
-        // the base class supplies wrappers only
2242
-        foreach (get_class_methods($this) as $method) {
2243
-            if (!strncmp("http_", $method, 5)) {
2244
-                $method = strtoupper(substr($method, 5));
2245
-                if (method_exists($this, $method)) {
2246
-                    $allow[$method] = $method;
2247
-                }
2248
-            }
2249
-        }
2250
-
2251
-        // we can emulate a missing HEAD implemetation using GET
2252
-        if (isset($allow["GET"]))
2253
-            $allow["HEAD"] = "HEAD";
2254
-
2255
-        // no LOCK without checklok()
2256
-        if (!method_exists($this, "checklock")) {
2257
-            unset($allow["LOCK"]);
2258
-            unset($allow["UNLOCK"]);
2259
-        }
2260
-
2261
-        return $allow;
2262
-    }
2263
-
2264
-    // }}}
2486
+				case "ETAG_STRONG":
2487
+					$list[] = $not."['$token[1]']>";
2488
+					break;
2265 2489
 
2266
-    /**
2267
-     * helper for property element creation
2268
-     *
2269
-     * @param  string  XML namespace (optional)
2270
-     * @param  string  property name
2271
-     * @param  string  property value
2272
-     * @praram boolen  property raw-flag
2273
-     * @return array   property array
2274
-     */
2275
-    public static function mkprop()
2276
-    {
2277
-	    $args = func_get_args();
2278
-	    switch (count($args)) {
2279
-		    case 4:
2280
-			    return array('ns'   => $args[0],
2281
-				    'name' => $args[1],
2282
-					'val'  => $args[2],
2283
-					'raw'	=> true);
2284
-		    case 3:
2285
-			    return array('ns'   => $args[0],
2286
-				    'name' => $args[1],
2287
-					'val'  => $args[2]);
2288
-		    default:
2289
-			    return array('ns'   => 'DAV:',
2290
-				    'name' => $args[0],
2291
-					'val'  => $args[1]);
2292
-	    }
2293
-    }
2490
+				default:
2491
+					return false;
2492
+				}
2493
+				$not = "";
2494
+			}
2294 2495
 
2295
-    // {{{ _check_auth
2496
+			if (@is_array($uris[$uri])) {
2497
+				$uris[$uri] = array_merge($uris[$uri], $list);
2498
+			} else {
2499
+				$uris[$uri] = $list;
2500
+			}
2501
+		}
2296 2502
 
2297
-    /**
2298
-     * check authentication if check is implemented
2299
-     *
2300
-     * @param  void
2301
-     * @return bool  true if authentication succeded or not necessary
2302
-     */
2303
-    function _check_auth()
2304
-    {
2305
-        if (method_exists($this, "checkAuth")) {
2306
-            // PEAR style method name
2307
-            return $this->checkAuth(@$this->_SERVER["AUTH_TYPE"],
2308
-                                    @$this->_SERVER["PHP_AUTH_USER"],
2309
-                                    @$this->_SERVER["PHP_AUTH_PW"]);
2310
-        } else if (method_exists($this, "check_auth")) {
2311
-            // old (pre 1.0) method name
2312
-            return $this->check_auth(@$this->_SERVER["AUTH_TYPE"],
2313
-                                     @$this->_SERVER["PHP_AUTH_USER"],
2314
-                                     @$this->_SERVER["PHP_AUTH_PW"]);
2315
-        } else {
2316
-            // no method found -> no authentication required
2317
-            return true;
2318
-        }
2319
-    }
2320
-
2321
-    // }}}
2322
-
2323
-    // {{{ UUID stuff
2503
+		return $uris;
2504
+	}
2324 2505
 
2325
-    /**
2326
-     * generate Unique Universal IDentifier for lock token
2327
-     *
2328
-     * @param  void
2329
-     * @return string  a new UUID
2330
-     */
2331
-    public static function _new_uuid()
2332
-    {
2333
-        // use uuid extension from PECL if available
2334
-        if (function_exists("uuid_create")) {
2335
-            return uuid_create();
2336
-        }
2337
-
2338
-        // fallback
2339
-        $uuid = md5(microtime().getmypid());    // this should be random enough for now
2340
-
2341
-        // set variant and version fields for 'true' random uuid
2342
-        $uuid{12} = "4";
2343
-        $n = 8 + (ord($uuid{16}) & 3);
2344
-        $hex = "0123456789abcdef";
2345
-        $uuid{16} = $hex{$n};
2346
-
2347
-        // return formated uuid
2348
-        return substr($uuid,  0, 8)."-"
2349
-            .  substr($uuid,  8, 4)."-"
2350
-            .  substr($uuid, 12, 4)."-"
2351
-            .  substr($uuid, 16, 4)."-"
2352
-            .  substr($uuid, 20);
2353
-    }
2506
+	/**
2507
+	 * check if conditions from "If:" headers are meat
2508
+	 *
2509
+	 * the "If:" header is an extension to HTTP/1.1
2510
+	 * defined in RFC 2518 section 9.4
2511
+	 *
2512
+	 * @param  void
2513
+	 * @return void
2514
+	 */
2515
+	function _check_if_header_conditions()
2516
+	{
2517
+		if (isset($this->_SERVER["HTTP_IF"])) {
2518
+			$this->_if_header_uris =
2519
+				$this->_if_header_parser($this->_SERVER["HTTP_IF"]);
2354 2520
 
2355
-    /**
2356
-     * create a new opaque lock token as defined in RFC2518
2357
-     *
2358
-     * @param  void
2359
-     * @return string  new RFC2518 opaque lock token
2360
-     */
2361
-    public static function _new_locktoken()
2362
-    {
2363
-        return "opaquelocktoken:".self::_new_uuid();
2364
-    }
2521
+			foreach ($this->_if_header_uris as $uri => $conditions) {
2522
+				if ($uri == "") {
2523
+					$uri = $this->uri;
2524
+				}
2525
+				// all must match
2526
+				$state = true;
2527
+				foreach ($conditions as $condition) {
2528
+					// lock tokens may be free form (RFC2518 6.3)
2529
+					// but if opaquelocktokens are used (RFC2518 6.4)
2530
+					// we have to check the format (litmus tests this)
2531
+					if (!strncmp($condition, "<opaquelocktoken:", strlen("<opaquelocktoken"))) {
2532
+						if (!preg_match('/^<opaquelocktoken:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}>$/', $condition)) {
2533
+							$this->http_status("423 Locked");
2534
+							return false;
2535
+						}
2536
+					}
2537
+					if (!$this->_check_uri_condition($uri, $condition)) {
2538
+						$this->http_status("412 Precondition failed");
2539
+						$state = false;
2540
+						break;
2541
+					}
2542
+				}
2365 2543
 
2366
-    // }}}
2544
+				// any match is ok
2545
+				if ($state == true) {
2546
+					return true;
2547
+				}
2548
+			}
2549
+			return false;
2550
+		}
2551
+		return true;
2552
+	}
2367 2553
 
2368
-    // {{{ WebDAV If: header parsing
2554
+	/**
2555
+	 * Check a single URI condition parsed from an if-header
2556
+	 *
2557
+	 * Check a single URI condition parsed from an if-header
2558
+	 *
2559
+	 * @abstract
2560
+	 * @param string $uri URI to check
2561
+	 * @param string $condition Condition to check for this URI
2562
+	 * @returns bool Condition check result
2563
+	 */
2564
+	function _check_uri_condition($uri, $condition)
2565
+	{
2566
+		unset($uri);	// not used, but required by function signature
2567
+		// not really implemented here,
2568
+		// implementations must override
2369 2569
 
2370
-    /**
2371
-     *
2372
-     *
2373
-     * @param  string  header string to parse
2374
-     * @param  int     current parsing position
2375
-     * @return array   next token (type and value)
2376
-     */
2377
-    function _if_header_lexer($string, &$pos)
2378
-    {
2379
-        // skip whitespace
2380
-        while (ctype_space($string{$pos})) {
2381
-            ++$pos;
2382
-        }
2383
-
2384
-        // already at end of string?
2385
-        if (strlen($string) <= $pos) {
2386
-            return false;
2387
-        }
2388
-
2389
-        // get next character
2390
-        $c = $string{$pos++};
2391
-
2392
-        // now it depends on what we found
2393
-        switch ($c) {
2394
-        case "<":
2395
-            // URIs are enclosed in <...>
2396
-            $pos2 = strpos($string, ">", $pos);
2397
-            $uri  = substr($string, $pos, $pos2 - $pos);
2398
-            $pos  = $pos2 + 1;
2399
-            return array("URI", $uri);
2400
-
2401
-        case "[":
2402
-            //Etags are enclosed in [...]
2403
-            if ($string{$pos} == "W") {
2404
-                $type = "ETAG_WEAK";
2405
-                $pos += 2;
2406
-            } else {
2407
-                $type = "ETAG_STRONG";
2408
-            }
2409
-            $pos2 = strpos($string, "]", $pos);
2410
-            $etag = substr($string, $pos + 1, $pos2 - $pos - 2);
2411
-            $pos  = $pos2 + 1;
2412
-            return array($type, $etag);
2413
-
2414
-        case "N":
2415
-            // "N" indicates negation
2416
-            $pos += 2;
2417
-            return array("NOT", "Not");
2418
-
2419
-        default:
2420
-            // anything else is passed verbatim char by char
2421
-            return array("CHAR", $c);
2422
-        }
2423
-    }
2570
+		// a lock token can never be from the DAV: scheme
2571
+		// litmus uses DAV:no-lock in some tests
2572
+		if (!strncmp("<DAV:", $condition, 5)) {
2573
+			return false;
2574
+		}
2424 2575
 
2425
-    /**
2426
-     * parse If: header
2427
-     *
2428
-     * @param  string  header string
2429
-     * @return array   URIs and their conditions
2430
-     */
2431
-    function _if_header_parser($str)
2432
-    {
2433
-        $pos  = 0;
2434
-        $len  = strlen($str);
2435
-        $uris = array();
2436
-
2437
-        // parser loop
2438
-        while ($pos < $len) {
2439
-            // get next token
2440
-            $token = $this->_if_header_lexer($str, $pos);
2441
-
2442
-            // check for URI
2443
-            if ($token[0] == "URI") {
2444
-                $uri   = $token[1]; // remember URI
2445
-                $token = $this->_if_header_lexer($str, $pos); // get next token
2446
-            } else {
2447
-                $uri = "";
2448
-            }
2449
-
2450
-            // sanity check
2451
-            if ($token[0] != "CHAR" || $token[1] != "(") {
2452
-                return false;
2453
-            }
2454
-
2455
-            $list  = array();
2456
-            $level = 1;
2457
-            $not   = "";
2458
-            while ($level) {
2459
-                $token = $this->_if_header_lexer($str, $pos);
2460
-                if ($token[0] == "NOT") {
2461
-                    $not = "!";
2462
-                    continue;
2463
-                }
2464
-                switch ($token[0]) {
2465
-                case "CHAR":
2466
-                    switch ($token[1]) {
2467
-                    case "(":
2468
-                        $level++;
2469
-                        break;
2470
-                    case ")":
2471
-                        $level--;
2472
-                        break;
2473
-                    default:
2474
-                        return false;
2475
-                    }
2476
-                    break;
2477
-
2478
-                case "URI":
2479
-                    $list[] = $not."<$token[1]>";
2480
-                    break;
2481
-
2482
-                case "ETAG_WEAK":
2483
-                    $list[] = $not."[W/'$token[1]']>";
2484
-                    break;
2485
-
2486
-                case "ETAG_STRONG":
2487
-                    $list[] = $not."['$token[1]']>";
2488
-                    break;
2489
-
2490
-                default:
2491
-                    return false;
2492
-                }
2493
-                $not = "";
2494
-            }
2495
-
2496
-            if (@is_array($uris[$uri])) {
2497
-                $uris[$uri] = array_merge($uris[$uri], $list);
2498
-            } else {
2499
-                $uris[$uri] = $list;
2500
-            }
2501
-        }
2502
-
2503
-        return $uris;
2504
-    }
2576
+		return true;
2577
+	}
2505 2578
 
2506
-    /**
2507
-     * check if conditions from "If:" headers are meat
2508
-     *
2509
-     * the "If:" header is an extension to HTTP/1.1
2510
-     * defined in RFC 2518 section 9.4
2511
-     *
2512
-     * @param  void
2513
-     * @return void
2514
-     */
2515
-    function _check_if_header_conditions()
2516
-    {
2517
-        if (isset($this->_SERVER["HTTP_IF"])) {
2518
-            $this->_if_header_uris =
2519
-                $this->_if_header_parser($this->_SERVER["HTTP_IF"]);
2520
-
2521
-            foreach ($this->_if_header_uris as $uri => $conditions) {
2522
-                if ($uri == "") {
2523
-                    $uri = $this->uri;
2524
-                }
2525
-                // all must match
2526
-                $state = true;
2527
-                foreach ($conditions as $condition) {
2528
-                    // lock tokens may be free form (RFC2518 6.3)
2529
-                    // but if opaquelocktokens are used (RFC2518 6.4)
2530
-                    // we have to check the format (litmus tests this)
2531
-                    if (!strncmp($condition, "<opaquelocktoken:", strlen("<opaquelocktoken"))) {
2532
-                        if (!preg_match('/^<opaquelocktoken:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}>$/', $condition)) {
2533
-                            $this->http_status("423 Locked");
2534
-                            return false;
2535
-                        }
2536
-                    }
2537
-                    if (!$this->_check_uri_condition($uri, $condition)) {
2538
-                        $this->http_status("412 Precondition failed");
2539
-                        $state = false;
2540
-                        break;
2541
-                    }
2542
-                }
2543
-
2544
-                // any match is ok
2545
-                if ($state == true) {
2546
-                    return true;
2547
-                }
2548
-            }
2549
-            return false;
2550
-        }
2551
-        return true;
2552
-    }
2553 2579
 
2554
-    /**
2555
-     * Check a single URI condition parsed from an if-header
2556
-     *
2557
-     * Check a single URI condition parsed from an if-header
2558
-     *
2559
-     * @abstract
2560
-     * @param string $uri URI to check
2561
-     * @param string $condition Condition to check for this URI
2562
-     * @returns bool Condition check result
2563
-     */
2564
-    function _check_uri_condition($uri, $condition)
2565
-    {
2566
-		unset($uri);	// not used, but required by function signature
2567
-        // not really implemented here,
2568
-        // implementations must override
2580
+	/**
2581
+	 *
2582
+	 *
2583
+	 * @param  string  path of resource to check
2584
+	 * @param  bool    exclusive lock?
2585
+	 */
2586
+	function _check_lock_status($path, $exclusive_only = false)
2587
+	{
2588
+		// FIXME depth -> ignored for now
2589
+		if (method_exists($this, "checkLock")) {
2590
+			// is locked?
2591
+			$lock = $this->checkLock($path);
2592
+
2593
+			// ... and lock is not owned?
2594
+			if (is_array($lock) && count($lock)) {
2595
+				// FIXME doesn't check uri restrictions yet
2596
+				if (!isset($this->_SERVER["HTTP_IF"]) || !strstr($this->_SERVER["HTTP_IF"], $lock["token"])) {
2597
+					if (!$exclusive_only || ($lock["scope"] !== "shared"))
2598
+						return false;
2599
+				}
2600
+			}
2601
+		}
2602
+		return true;
2603
+	}
2569 2604
 
2570
-        // a lock token can never be from the DAV: scheme
2571
-        // litmus uses DAV:no-lock in some tests
2572
-        if (!strncmp("<DAV:", $condition, 5)) {
2573
-            return false;
2574
-        }
2575 2605
 
2576
-        return true;
2577
-    }
2606
+	// }}}
2578 2607
 
2579 2608
 
2580
-    /**
2581
-     *
2582
-     *
2583
-     * @param  string  path of resource to check
2584
-     * @param  bool    exclusive lock?
2585
-     */
2586
-    function _check_lock_status($path, $exclusive_only = false)
2587
-    {
2588
-        // FIXME depth -> ignored for now
2589
-        if (method_exists($this, "checkLock")) {
2590
-            // is locked?
2591
-            $lock = $this->checkLock($path);
2592
-
2593
-            // ... and lock is not owned?
2594
-            if (is_array($lock) && count($lock)) {
2595
-                // FIXME doesn't check uri restrictions yet
2596
-                if (!isset($this->_SERVER["HTTP_IF"]) || !strstr($this->_SERVER["HTTP_IF"], $lock["token"])) {
2597
-                    if (!$exclusive_only || ($lock["scope"] !== "shared"))
2598
-                        return false;
2599
-                }
2600
-            }
2601
-        }
2602
-        return true;
2603
-    }
2604
-
2605
-
2606
-    // }}}
2609
+	/**
2610
+	 * Generate lockdiscovery reply from checklock() result
2611
+	 *
2612
+	 * @param   string  resource path to check
2613
+	 * @return  string  lockdiscovery response
2614
+	 */
2615
+	function lockdiscovery($path)
2616
+	{
2617
+		// no lock support without checklock() method
2618
+		if (!method_exists($this, "checklock")) {
2619
+			return "";
2620
+		}
2607 2621
 
2622
+		// collect response here
2623
+		$activelocks = "";
2624
+
2625
+		// get checklock() reply
2626
+		$lock = $this->checklock($path);
2627
+
2628
+		// generate <activelock> block for returned data
2629
+		if (is_array($lock) && count($lock)) {
2630
+			// check for 'timeout' or 'expires'
2631
+			if (!empty($lock["expires"])) {
2632
+				$timeout = "Second-".($lock["expires"] - time());
2633
+			} else if (!empty($lock["timeout"])) {
2634
+				$timeout = "Second-$lock[timeout]";
2635
+			} else {
2636
+				$timeout = "Infinite";
2637
+			}
2608 2638
 
2609
-    /**
2610
-     * Generate lockdiscovery reply from checklock() result
2611
-     *
2612
-     * @param   string  resource path to check
2613
-     * @return  string  lockdiscovery response
2614
-     */
2615
-    function lockdiscovery($path)
2616
-    {
2617
-        // no lock support without checklock() method
2618
-        if (!method_exists($this, "checklock")) {
2619
-            return "";
2620
-        }
2621
-
2622
-        // collect response here
2623
-        $activelocks = "";
2624
-
2625
-        // get checklock() reply
2626
-        $lock = $this->checklock($path);
2627
-
2628
-        // generate <activelock> block for returned data
2629
-        if (is_array($lock) && count($lock)) {
2630
-            // check for 'timeout' or 'expires'
2631
-            if (!empty($lock["expires"])) {
2632
-                $timeout = "Second-".($lock["expires"] - time());
2633
-            } else if (!empty($lock["timeout"])) {
2634
-                $timeout = "Second-$lock[timeout]";
2635
-            } else {
2636
-                $timeout = "Infinite";
2637
-            }
2638
-
2639
-            // genreate response block
2640
-            if ($this->crrnd)
2641
-            {
2642
-	            $activelocks.= "
2639
+			// genreate response block
2640
+			if ($this->crrnd)
2641
+			{
2642
+				$activelocks.= "
2643 2643
 		            <activelock>
2644 2644
 		            <lockscope><$lock[scope]/></lockscope>
2645 2645
 		            <locktype><$lock[type]/></locktype>
@@ -2649,10 +2649,10 @@  discard block
 block discarded – undo
2649 2649
 		            <locktoken><href>$lock[token]</href></locktoken>
2650 2650
 		            </activelock>
2651 2651
 		            ";
2652
-            }
2653
-            else
2654
-            {
2655
-	            $activelocks.= "
2652
+			}
2653
+			else
2654
+			{
2655
+				$activelocks.= "
2656 2656
 		            <D:activelock>
2657 2657
 		            <D:lockscope><D:$lock[scope]/></D:lockscope>
2658 2658
 		            <D:locktype><D:$lock[type]/></D:locktype>
@@ -2662,47 +2662,47 @@  discard block
 block discarded – undo
2662 2662
 		            <D:locktoken><D:href>$lock[token]</D:href></D:locktoken>
2663 2663
 		            </D:activelock>
2664 2664
 		            ";
2665
-            }
2666
-        }
2665
+			}
2666
+		}
2667 2667
 
2668
-        // return generated response
2669
-        //error_log(__METHOD__."\n".print_r($activelocks,true));
2668
+		// return generated response
2669
+		//error_log(__METHOD__."\n".print_r($activelocks,true));
2670 2670
 		return $activelocks;
2671
-    }
2671
+	}
2672 2672
 
2673
-    /**
2674
-     * set HTTP return status and mirror it in a private header
2675
-     *
2676
-     * @param  string  status code and message
2677
-     * @return void
2678
-     */
2679
-    function http_status($status)
2680
-    {
2681
-        // simplified success case
2682
-        if ($status === true) {
2683
-            $status = "200 OK";
2684
-        }
2685
-
2686
-        // remember status
2687
-        $this->_http_status = $status;
2688
-
2689
-        // generate HTTP status response
2690
-        header("HTTP/1.1 $status");
2691
-        header("X-WebDAV-Status: $status", true);
2692
-    }
2673
+	/**
2674
+	 * set HTTP return status and mirror it in a private header
2675
+	 *
2676
+	 * @param  string  status code and message
2677
+	 * @return void
2678
+	 */
2679
+	function http_status($status)
2680
+	{
2681
+		// simplified success case
2682
+		if ($status === true) {
2683
+			$status = "200 OK";
2684
+		}
2693 2685
 
2694
-    /**
2695
-     * private minimalistic version of PHP urlencode()
2696
-     *
2697
-     * only blanks, percent and XML special chars must be encoded here
2698
-     * full urlencode() encoding confuses some clients ...
2699
-     *
2700
-     * @param  string  URL to encode
2701
-     * @return string  encoded URL
2702
-     * @todo check if other not explicitly named user-agents are happy with full url-encoding too and we can make it the default
2703
-     */
2704
-    public static function _urlencode($url)
2705
-    {
2686
+		// remember status
2687
+		$this->_http_status = $status;
2688
+
2689
+		// generate HTTP status response
2690
+		header("HTTP/1.1 $status");
2691
+		header("X-WebDAV-Status: $status", true);
2692
+	}
2693
+
2694
+	/**
2695
+	 * private minimalistic version of PHP urlencode()
2696
+	 *
2697
+	 * only blanks, percent and XML special chars must be encoded here
2698
+	 * full urlencode() encoding confuses some clients ...
2699
+	 *
2700
+	 * @param  string  URL to encode
2701
+	 * @return string  encoded URL
2702
+	 * @todo check if other not explicitly named user-agents are happy with full url-encoding too and we can make it the default
2703
+	 */
2704
+	public static function _urlencode($url)
2705
+	{
2706 2706
 		// cadaver (and probably all neon using agents) need a more complete url encoding
2707 2707
 		// otherwise special chars like "$,()'" in filenames do NOT work
2708 2708
 		if (strpos($_SERVER['HTTP_USER_AGENT'],'neon') !== false ||
@@ -2720,31 +2720,31 @@  discard block
 block discarded – undo
2720 2720
 		}
2721 2721
 		//error_log( __METHOD__."\n" .print_r($url,true));
2722 2722
 		return strtr($url, array(' '	=>	'%20',
2723
-                                 '%'	=>	'%25',
2724
-                                 '&'	=>	'%26',
2725
-                                 '<'	=>	'%3C',
2726
-                                 '>'	=>	'%3E',
2727
-                                 '+'	=>	'%2B',
2728
-                                 ));
2729
-    }
2723
+								 '%'	=>	'%25',
2724
+								 '&'	=>	'%26',
2725
+								 '<'	=>	'%3C',
2726
+								 '>'	=>	'%3E',
2727
+								 '+'	=>	'%2B',
2728
+								 ));
2729
+	}
2730 2730
 
2731
-    /**
2732
-     * private version of PHP urldecode
2733
-     *
2734
-     * not really needed but added for completenes
2735
-     *
2736
-     * @param  string  URL to decode
2737
-     * @return string  decoded URL
2738
-     */
2739
-    public static function _urldecode($path)
2740
-    {
2741
-        return rawurldecode($path);
2742
-    }
2731
+	/**
2732
+	 * private version of PHP urldecode
2733
+	 *
2734
+	 * not really needed but added for completenes
2735
+	 *
2736
+	 * @param  string  URL to decode
2737
+	 * @return string  decoded URL
2738
+	 */
2739
+	public static function _urldecode($path)
2740
+	{
2741
+		return rawurldecode($path);
2742
+	}
2743 2743
 
2744
-    /**
2745
-     * Encode a hierarchical properties like:
2746
-     *
2747
- 	 * <D:supported-report-set>
2744
+	/**
2745
+	 * Encode a hierarchical properties like:
2746
+	 *
2747
+	 * <D:supported-report-set>
2748 2748
 	 *    <supported-report>
2749 2749
 	 *       <report>
2750 2750
 	 *          <addressbook-query xmlns='urn:ietf:params:xml:ns:carddav'/>
@@ -2756,60 +2756,60 @@  discard block
 block discarded – undo
2756 2756
 	 *       </report>
2757 2757
 	 *    </supported-report>
2758 2758
 	 * </D:supported-report-set>
2759
-     *
2760
-     * @param array $props
2761
-     * @param string $ns
2762
-     * @param strin $ns_defs
2763
-     * @param array $ns_hash
2764
-     * @return string
2765
-     */
2759
+	 *
2760
+	 * @param array $props
2761
+	 * @param string $ns
2762
+	 * @param strin $ns_defs
2763
+	 * @param array $ns_hash
2764
+	 * @return string
2765
+	 */
2766 2766
 	function _hierarchical_prop_encode(array $props, $ns, &$ns_defs, array &$ns_hash)
2767
-    {
2768
-    	$ret = '';
2767
+	{
2768
+		$ret = '';
2769 2769
 
2770
-    	//error_log(__METHOD__.'('.array2string($props).')');
2771
-    	if (isset($props['name'])) $props = array($props);
2770
+		//error_log(__METHOD__.'('.array2string($props).')');
2771
+		if (isset($props['name'])) $props = array($props);
2772 2772
 
2773
-    	foreach($props as $prop)
2773
+		foreach($props as $prop)
2774 2774
 		{
2775
-	    	if (!isset($ns_hash[$prop['ns']])) // unknown namespace
2776
-	    	{
2777
-		    	// register namespace
2778
-		    	$ns_name = 'ns'.(count($ns_hash) + 1);
2779
-		    	$ns_hash[$prop['ns']] = $ns_name;
2780
-		    	$ns_defs .= ' xmlns:'.$ns_name.'="'.$prop['ns'].'"';
2781
-	    	}
2782
-	    	if (is_array($prop['val']))
2783
-	    	{
2784
-	    		$subprop = $prop['val'];
2785
-		    	if (isset($subprop['ns']) || isset($subprop[0]['ns']))
2786
-		    	{
2787
-			    	$ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2775
+			if (!isset($ns_hash[$prop['ns']])) // unknown namespace
2776
+			{
2777
+				// register namespace
2778
+				$ns_name = 'ns'.(count($ns_hash) + 1);
2779
+				$ns_hash[$prop['ns']] = $ns_name;
2780
+				$ns_defs .= ' xmlns:'.$ns_name.'="'.$prop['ns'].'"';
2781
+			}
2782
+			if (is_array($prop['val']))
2783
+			{
2784
+				$subprop = $prop['val'];
2785
+				if (isset($subprop['ns']) || isset($subprop[0]['ns']))
2786
+				{
2787
+					$ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2788 2788
 						(empty($prop['val']) ? '/>' : '>'.$this->_hierarchical_prop_encode($prop['val'], $prop['ns'], $ns_defs, $ns_hash).
2789 2789
 						'</'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : ($this->crrnd ? '' : $ns_hash[$prop['ns']].':')).$prop['name'].'>');
2790
-		    	}
2791
-		    	else // val contains only attributes, no value
2792
-		    	{
2793
-			    	$vals = '';
2790
+				}
2791
+				else // val contains only attributes, no value
2792
+				{
2793
+					$vals = '';
2794 2794
 
2795
-			    	foreach($subprop as $attr => $val)
2795
+					foreach($subprop as $attr => $val)
2796 2796
 					{
2797
-				    	$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8').'"';
2797
+						$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8').'"';
2798 2798
 					}
2799 2799
 
2800
-		             $ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2801
-				    	$vals .'/>';
2802
-		    	}
2803
-	    	}
2804
-	    	else
2805
-	    	{
2806
-		    	if (empty($prop['val']))
2807
-		    	{
2808
-			    	$val = '';
2809
-		    	}
2810
-		    	else
2811
-		    	{
2812
-			    	if(isset($prop['raw']))
2800
+					 $ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2801
+						$vals .'/>';
2802
+				}
2803
+			}
2804
+			else
2805
+			{
2806
+				if (empty($prop['val']))
2807
+				{
2808
+					$val = '';
2809
+				}
2810
+				else
2811
+				{
2812
+					if(isset($prop['raw']))
2813 2813
 					{
2814 2814
 						$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
2815 2815
 					} else {
@@ -2820,32 +2820,32 @@  discard block
 block discarded – undo
2820 2820
 							$val = $this->_urlencode($val);
2821 2821
 						}
2822 2822
 					}
2823
-		    	}
2823
+				}
2824 2824
 
2825
-		    	$ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2826
-			    	(empty($prop['val']) ? ' />' : '>'.$val.'</'.
2827
-			    	($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : ($this->crrnd ? '' : $ns_hash[$prop['ns']].':')).$prop['name'].'>');
2828
-	    	}
2825
+				$ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2826
+					(empty($prop['val']) ? ' />' : '>'.$val.'</'.
2827
+					($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : ($this->crrnd ? '' : $ns_hash[$prop['ns']].':')).$prop['name'].'>');
2828
+			}
2829 2829
 		}
2830 2830
 
2831
-    	//error_log(__METHOD__.'('.array2string($props).") crrnd=$this->crrnd returning ".array2string($ret));
2832
-    	return $ret;
2833
-    }
2831
+		//error_log(__METHOD__.'('.array2string($props).") crrnd=$this->crrnd returning ".array2string($ret));
2832
+		return $ret;
2833
+	}
2834 2834
 
2835
-    /**
2836
-     * UTF-8 encode property values if not already done so
2837
-     *
2838
-     * @param  string  text to encode
2839
-     * @return string  utf-8 encoded text
2840
-     */
2841
-    function _prop_encode($text)
2842
-    {
2835
+	/**
2836
+	 * UTF-8 encode property values if not already done so
2837
+	 *
2838
+	 * @param  string  text to encode
2839
+	 * @return string  utf-8 encoded text
2840
+	 */
2841
+	function _prop_encode($text)
2842
+	{
2843 2843
 		//error_log( __METHOD__."\n" .print_r($text,true));
2844 2844
 		//error_log("prop-encode:" . print_r($this->_prop_encoding,true));
2845 2845
 
2846 2846
 		switch (strtolower($this->_prop_encoding)) {
2847 2847
 			case "utf-8":
2848
-       			//error_log( __METHOD__."allready encoded\n" .print_r($text,true));
2848
+	   			//error_log( __METHOD__."allready encoded\n" .print_r($text,true));
2849 2849
 				return $text;
2850 2850
 			case "iso-8859-1":
2851 2851
 			case "iso-8859-15":
@@ -2853,75 +2853,75 @@  discard block
 block discarded – undo
2853 2853
 			default:
2854 2854
 				error_log( __METHOD__."utf8 encode\n" .print_r(utf8_encode($text),true));
2855 2855
 				return utf8_encode($text);
2856
-        }
2857
-    }
2856
+		}
2857
+	}
2858 2858
 
2859
-    /**
2860
-     * Slashify - make sure path ends in a slash
2861
-     *
2862
-     * @param   string directory path
2863
-     * @returns string directory path wiht trailing slash
2864
-     */
2865
-    public static function _slashify($path)
2866
-    {
2859
+	/**
2860
+	 * Slashify - make sure path ends in a slash
2861
+	 *
2862
+	 * @param   string directory path
2863
+	 * @returns string directory path wiht trailing slash
2864
+	 */
2865
+	public static function _slashify($path)
2866
+	{
2867 2867
 		//error_log(__METHOD__." called with $path");
2868 2868
 		if ($path[self::bytes($path)-1] != '/') {
2869 2869
 			//error_log(__METHOD__." added slash at the end of path");
2870 2870
 			$path = $path."/";
2871 2871
 		}
2872 2872
 		return $path;
2873
-    }
2873
+	}
2874 2874
 
2875
-    /**
2876
-     * Unslashify - make sure path doesn't in a slash
2877
-     *
2878
-     * @param   string directory path
2879
-     * @returns string directory path wihtout trailing slash
2880
-     */
2881
-    public static function _unslashify($path)
2882
-    {
2883
-        //error_log(__METHOD__." called with $path");
2884
-        if ($path[self::bytes($path)-1] == '/') {
2885
-            $path = substr($path, 0, -1);
2875
+	/**
2876
+	 * Unslashify - make sure path doesn't in a slash
2877
+	 *
2878
+	 * @param   string directory path
2879
+	 * @returns string directory path wihtout trailing slash
2880
+	 */
2881
+	public static function _unslashify($path)
2882
+	{
2883
+		//error_log(__METHOD__." called with $path");
2884
+		if ($path[self::bytes($path)-1] == '/') {
2885
+			$path = substr($path, 0, -1);
2886 2886
 			//error_log(__METHOD__." removed slash at the end of path");
2887
-        }
2888
-        return $path;
2889
-    }
2887
+		}
2888
+		return $path;
2889
+	}
2890 2890
 
2891
-    /**
2892
-     * Merge two paths, make sure there is exactly one slash between them
2893
-     *
2894
-     * @param  string  parent path
2895
-     * @param  string  child path
2896
-     * @return string  merged path
2897
-     */
2898
-    public static function _mergePaths($parent, $child)
2899
-    {
2900
-        //error_log("merge called :\n$parent \n$child\n" . function_backtrace());
2901
-        //error_log("merge :\n".print_r($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)true));
2902
-        if ($child{0} == '/') {
2903
-            return self::_unslashify($parent).$child;
2904
-        } else {
2905
-            return self::_slashify($parent).$child;
2906
-        }
2907
-    }
2891
+	/**
2892
+	 * Merge two paths, make sure there is exactly one slash between them
2893
+	 *
2894
+	 * @param  string  parent path
2895
+	 * @param  string  child path
2896
+	 * @return string  merged path
2897
+	 */
2898
+	public static function _mergePaths($parent, $child)
2899
+	{
2900
+		//error_log("merge called :\n$parent \n$child\n" . function_backtrace());
2901
+		//error_log("merge :\n".print_r($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)true));
2902
+		if ($child{0} == '/') {
2903
+			return self::_unslashify($parent).$child;
2904
+		} else {
2905
+			return self::_slashify($parent).$child;
2906
+		}
2907
+	}
2908 2908
 
2909
-    /**
2910
-     * mbstring.func_overload save strlen version: counting the bytes not the chars
2911
-     *
2912
-     * @param string $str
2913
-     * @return int
2914
-     */
2915
-    public static function bytes($str)
2916
-    {
2917
-    	static $func_overload=null;
2918
-
2919
-    	if (is_null($func_overload))
2920
-    	{
2921
-    		$func_overload = @extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
2922
-    	}
2923
-    	return $func_overload & 2 ? mb_strlen($str,'ascii') : strlen($str);
2924
-    }
2909
+	/**
2910
+	 * mbstring.func_overload save strlen version: counting the bytes not the chars
2911
+	 *
2912
+	 * @param string $str
2913
+	 * @return int
2914
+	 */
2915
+	public static function bytes($str)
2916
+	{
2917
+		static $func_overload=null;
2918
+
2919
+		if (is_null($func_overload))
2920
+		{
2921
+			$func_overload = @extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
2922
+		}
2923
+		return $func_overload & 2 ? mb_strlen($str,'ascii') : strlen($str);
2924
+	}
2925 2925
 }
2926 2926
 
2927 2927
 /*
Please login to merge, or discard this patch.
Braces   +704 added lines, -290 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,35 +683,52 @@  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, $handler);
672
-        if ($this->store_request) $this->request = $propinfo->request;
673
-        if ($propinfo->error) {
697
+        if ($this->store_request)
698
+        {
699
+        	$this->request = $propinfo->request;
700
+        }
701
+        if ($propinfo->error)
702
+        {
674 703
             $this->http_status("400 Bad Request");
675
-			if (method_exists($this, 'log')) $this->log('Error parsing propfind: '.$propinfo->error);
704
+			if (method_exists($this, 'log'))
705
+			{
706
+				$this->log('Error parsing propfind: '.$propinfo->error);
707
+			}
676 708
             return;
677 709
         }
678 710
 		$options['root'] = $propinfo->root;
679 711
 		$options['props'] = $propinfo->props;
680 712
 		if ($propinfo->filters)
681
-			$options['filters'] = $propinfo->filters;
713
+		{
714
+					$options['filters'] = $propinfo->filters;
715
+		}
682 716
 		if ($propinfo->other)
683
-			$options['other'] = $propinfo->other;
717
+		{
718
+					$options['other'] = $propinfo->other;
719
+		}
684 720
 
685 721
         // call user handler
686
-        if (!($retval =$this->$handler($options, $files))) {
722
+        if (!($retval =$this->$handler($options, $files)))
723
+        {
687 724
             $files = array("files" => array());
688
-            if (method_exists($this, "checkLock")) {
725
+            if (method_exists($this, "checkLock"))
726
+            {
689 727
                 // is locked?
690 728
                 $lock = $this->checkLock($this->path);
691 729
 
692
-                if (is_array($lock) && count($lock)) {
730
+                if (is_array($lock) && count($lock))
731
+                {
693 732
                     $created          = isset($lock['created'])  ? $lock['created']  : time();
694 733
                     $modified         = isset($lock['modified']) ? $lock['modified'] : time();
695 734
                     $files['files'][] = array("path"  => self::_slashify($this->path),
@@ -703,7 +742,8 @@  discard block
 block discarded – undo
703 742
                 }
704 743
             }
705 744
 
706
-            if (empty($files['files'])) {
745
+            if (empty($files['files']))
746
+            {
707 747
                 $this->http_status("404 Not Found");
708 748
                 return;
709 749
             }
@@ -737,7 +777,8 @@  discard block
 block discarded – undo
737 777
         $allow = false;
738 778
 
739 779
         // allow extending class to modify DAV
740
-		if (method_exists($this,'OPTIONS')) {
780
+		if (method_exists($this,'OPTIONS'))
781
+		{
741 782
 			$this->OPTIONS($this->path,$dav,$allow);
742 783
 		}
743 784
         header("DAV: "  .join(", ", $dav));
@@ -776,8 +817,14 @@  discard block
 block discarded – undo
776 817
      */
777 818
     function multistatus_responses(&$files, $props, $initial_ns_hash=null, $initial_ns_defs=null)
778 819
     {
779
-    	if (!isset($initial_ns_hash)) $initial_ns_hash = array('DAV:' => 'D');
780
-    	if (!isset($initial_ns_defs)) $initial_ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';
820
+    	if (!isset($initial_ns_hash))
821
+    	{
822
+    		$initial_ns_hash = array('DAV:' => 'D');
823
+    	}
824
+    	if (!isset($initial_ns_defs))
825
+    	{
826
+    		$initial_ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';
827
+    	}
781 828
 
782 829
     	// using an ArrayIterator to prevent foreach from copying the array,
783 830
         // as we cant loop by reference, when an iterator is given in $files
@@ -791,10 +838,12 @@  discard block
 block discarded – undo
791 838
         	isset($this->_SERVER['HTTP_PREFER']) && in_array('depth-noroot', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER']));
792 839
 
793 840
         // now we loop over all returned file entries
794
-        foreach ($files as $file) {
841
+        foreach ($files as $file)
842
+        {
795 843
 
796 844
         	// skip first element (root), if requested by Prefer: depth-noroot
797
-        	if ($skip_root) {
845
+        	if ($skip_root)
846
+        	{
798 847
         		$skip_root = false;
799 848
         		continue;
800 849
         	}
@@ -806,17 +855,20 @@  discard block
 block discarded – undo
806 855
 	        $ns_defs = $initial_ns_defs;
807 856
 
808 857
             // nothing to do if no properties were returend for a file
809
-			if (isset($file["props"]) && is_array($file["props"])) {
858
+			if (isset($file["props"]) && is_array($file["props"]))
859
+			{
810 860
 
811 861
 	            // now loop over all returned properties
812
-	            foreach ($file["props"] as &$prop) {
862
+	            foreach ($file["props"] as &$prop)
863
+	            {
813 864
 	                // as a convenience feature we do not require that user handlers
814 865
 	                // restrict returned properties to the requested ones
815 866
 	                // here we strip all unrequested entries out of the response
816 867
 
817 868
 	            	// this can happen if we have allprop and prop in one propfind:
818 869
 	            	// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
819
-	                switch(is_array($props) ? $props[0] : $props) {
870
+	                switch(is_array($props) ? $props[0] : $props)
871
+	                {
820 872
 	                case "all":
821 873
 	                    // nothing to remove
822 874
 	                    break;
@@ -831,16 +883,19 @@  discard block
 block discarded – undo
831 883
 	                    $found = false;
832 884
 
833 885
 	                    // search property name in requested properties
834
-	                    foreach ((array)$props as $reqprop) {
886
+	                    foreach ((array)$props as $reqprop)
887
+	                    {
835 888
 	                        if (   $reqprop["name"]  == $prop["name"]
836
-	                               && @$reqprop["xmlns"] == $prop["ns"]) {
889
+	                               && @$reqprop["xmlns"] == $prop["ns"])
890
+	                        {
837 891
 	                            $found = true;
838 892
 	                            break;
839 893
 	                        }
840 894
 	                    }
841 895
 
842 896
 	                    // unset property and continue with next one if not found/requested
843
-	                    if (!$found) {
897
+	                    if (!$found)
898
+	                    {
844 899
 	                        $prop="";
845 900
 	                        continue(2);
846 901
 	                    }
@@ -848,10 +903,18 @@  discard block
 block discarded – undo
848 903
 	                }
849 904
 
850 905
 	                // namespace handling
851
-	                if (empty($prop["ns"])) continue; // no namespace
906
+	                if (empty($prop["ns"]))
907
+	                {
908
+	                	continue;
909
+	                }
910
+	                // no namespace
852 911
 	                $ns = $prop["ns"];
853 912
 	                //if ($ns == "DAV:") continue; // default namespace
854
-	                if (isset($ns_hash[$ns])) continue; // already known
913
+	                if (isset($ns_hash[$ns]))
914
+	                {
915
+	                	continue;
916
+	                }
917
+	                // already known
855 918
 
856 919
 	                // register namespace
857 920
 	                $ns_name = "ns".(count($ns_hash) + 1);
@@ -861,37 +924,50 @@  discard block
 block discarded – undo
861 924
 
862 925
 	            // we also need to add empty entries for properties that were requested
863 926
 	            // but for which no values where returned by the user handler
864
-	            if (is_array($props)) {
865
-	                foreach ($props as $reqprop) {
866
-	                    if (!is_array($reqprop) || $reqprop['name']=="") continue; // skip empty entries, or 'all' if <allprop /> used together with <prop>
927
+	            if (is_array($props))
928
+	            {
929
+	                foreach ($props as $reqprop)
930
+	                {
931
+	                    if (!is_array($reqprop) || $reqprop['name']=="")
932
+	                    {
933
+	                    	continue;
934
+	                    }
935
+	                    // skip empty entries, or 'all' if <allprop /> used together with <prop>
867 936
 
868 937
 	                    $found = false;
869 938
 
870 939
 	                    // check if property exists in result
871
-	                    foreach ($file["props"] as &$prop) {
940
+	                    foreach ($file["props"] as &$prop)
941
+	                    {
872 942
 	                        if (is_array($prop) && $reqprop["name"] == $prop["name"]
873
-	                               && @$reqprop["xmlns"] == $prop["ns"]) {
943
+	                               && @$reqprop["xmlns"] == $prop["ns"])
944
+	                        {
874 945
 	                            $found = true;
875 946
 	                            break;
876 947
 	                        }
877 948
 	                    }
878 949
 
879
-	                    if (!$found) {
880
-	                        if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") {
950
+	                    if (!$found)
951
+	                    {
952
+	                        if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery")
953
+	                        {
881 954
 	                            // lockdiscovery is handled by the base class
882 955
 	                            $file["props"][]
883 956
 	                                = $this->mkprop("DAV:",
884 957
 	                                                "lockdiscovery",
885 958
 	                                                $this->lockdiscovery($file['path']));
886 959
 	                        // only collect $file['noprops'] if we have NO Brief: t and NO Prefer: return=minimal HTTP Header
887
-	                        } elseif ((!isset($this->_SERVER['HTTP_BRIEF']) || $this->_SERVER['HTTP_BRIEF'] != 't') &&
888
-	                        	(!isset($this->_SERVER['HTTP_PREFER']) || !in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER'])))) {
960
+	                        }
961
+	                        elseif ((!isset($this->_SERVER['HTTP_BRIEF']) || $this->_SERVER['HTTP_BRIEF'] != 't') &&
962
+	                        	(!isset($this->_SERVER['HTTP_PREFER']) || !in_array('return=minimal', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER']))))
963
+	                        {
889 964
 	                            // add empty value for this property
890 965
 	                            $file["noprops"][] =
891 966
 	                                $this->mkprop($reqprop["xmlns"], $reqprop["name"], "");
892 967
 
893 968
 	                            // register property namespace if not known yet
894
-	                            if ($reqprop["xmlns"] != "DAV:" && !isset($ns_hash[$reqprop["xmlns"]])) {
969
+	                            if ($reqprop["xmlns"] != "DAV:" && !isset($ns_hash[$reqprop["xmlns"]]))
970
+	                            {
895 971
 	                                $ns_name = "ns".(count($ns_hash) + 1);
896 972
 	                                $ns_hash[$reqprop["xmlns"]] = $ns_name;
897 973
 	                                $ns_defs .= " xmlns:$ns_name=\"$reqprop[xmlns]\"";
@@ -902,9 +978,15 @@  discard block
 block discarded – undo
902 978
 	            }
903 979
 	        }
904 980
             // ignore empty or incomplete entries
905
-            if (!is_array($file) || empty($file) || !isset($file["path"])) continue;
981
+            if (!is_array($file) || empty($file) || !isset($file["path"]))
982
+            {
983
+            	continue;
984
+            }
906 985
             $path = $file['path'];
907
-            if (!is_string($path) || $path==="") continue;
986
+            if (!is_string($path) || $path==="")
987
+            {
988
+            	continue;
989
+            }
908 990
 
909 991
             if ($this->crrnd)
910 992
             {
@@ -933,38 +1015,56 @@  discard block
 block discarded – undo
933 1015
             }
934 1016
 
935 1017
             // report all found properties and their values (if any)
936
-            if (isset($file["props"]) && is_array($file["props"])) {
1018
+            if (isset($file["props"]) && is_array($file["props"]))
1019
+            {
937 1020
                 echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
938 1021
                 echo '    <'.($this->crrnd?'':'D:')."prop>\n";
939 1022
 
940
-                foreach ($file["props"] as &$prop) {
1023
+                foreach ($file["props"] as &$prop)
1024
+                {
941 1025
 
942
-                    if (!is_array($prop)) continue;
943
-                    if (!isset($prop["name"])) continue;
1026
+                    if (!is_array($prop))
1027
+                    {
1028
+                    	continue;
1029
+                    }
1030
+                    if (!isset($prop["name"]))
1031
+                    {
1032
+                    	continue;
1033
+                    }
944 1034
 
945
-                    if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) {
1035
+                    if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false)
1036
+                    {
946 1037
                         // empty properties (cannot use empty() for check as "0" is a legal value here)
947
-                        if ($prop["ns"]=="DAV:") {
1038
+                        if ($prop["ns"]=="DAV:")
1039
+                        {
948 1040
                             echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
949
-                        } else if (!empty($prop["ns"])) {
1041
+                        }
1042
+                        else if (!empty($prop["ns"]))
1043
+                        {
950 1044
                             echo "     <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
951
-                        } else {
1045
+                        }
1046
+                        else
1047
+                        {
952 1048
                             echo "     <$prop[name] xmlns=\"\"/>";
953 1049
                         }
954 1050
                     }
955 1051
                     // multiple level of responses required for expand-property reports
956 1052
                     elseif(isset($prop['props']) && is_array($prop['val']))
957 1053
                     {
958
-                        if ($prop['ns'] && !isset($ns_hash[$prop['ns']])) {
1054
+                        if ($prop['ns'] && !isset($ns_hash[$prop['ns']]))
1055
+                        {
959 1056
                             $ns_name = "ns".(count($ns_hash) + 1);
960 1057
                             $ns_hash[$prop['ns']] = $ns_name;
961 1058
                         }
962 1059
                     	echo '     <'.$ns_hash[$prop['ns']].":$prop[name]>\n";
963 1060
                         $this->multistatus_responses($prop['val'], $prop['props'], $ns_hash, '');
964 1061
                     	echo '     </'.$ns_hash[$prop['ns']].":$prop[name]>\n";
965
-                    } else if ($prop["ns"] == "DAV:") {
1062
+                    }
1063
+                    else if ($prop["ns"] == "DAV:")
1064
+                    {
966 1065
                         // some WebDAV properties need special treatment
967
-                        switch ($prop["name"]) {
1066
+                        switch ($prop["name"])
1067
+                        {
968 1068
                         case "creationdate":
969 1069
                             echo '     <'.($this->crrnd?'':'D:')."creationdate ns0:dt=\"dateTime.tz\">"
970 1070
                                 . gmdate("Y-m-d\\TH:i:s\\Z", $prop['val'])
@@ -1000,40 +1100,57 @@  discard block
 block discarded – undo
1000 1100
                             {
1001 1101
                             	$hns_hash = $ns_hash;
1002 1102
                             	$val = $this->_hierarchical_prop_encode($prop['val'], 'DAV:', $ns_defs, $hns_hash);
1003
-                            } elseif (isset($prop['raw'])) {
1103
+                            }
1104
+                            elseif (isset($prop['raw']))
1105
+                            {
1004 1106
                             	$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
1005
-                            } else {
1107
+                            }
1108
+                            else
1109
+                            {
1006 1110
 	                    		$val = $this->_prop_encode(htmlspecialchars($prop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8'));
1007 1111
                             }
1008 1112
 	                        echo '     <'.($this->crrnd?'':'D:')."$prop[name]$ns_defs>$val".
1009 1113
 	                        	'</'.($this->crrnd?'':'D:')."$prop[name]>\n";
1010 1114
                             break;
1011 1115
                         }
1012
-                    } else {
1116
+                    }
1117
+                    else
1118
+                    {
1013 1119
                         // allow multiple values and attributes, required eg. for caldav:supported-calendar-component-set
1014
-                        if ($prop['ns'] && is_array($prop['val'])) {
1015
-                    		if (!isset($ns_hash[$prop['ns']])) {
1120
+                        if ($prop['ns'] && is_array($prop['val']))
1121
+                        {
1122
+                    		if (!isset($ns_hash[$prop['ns']]))
1123
+                    		{
1016 1124
                                 $ns_name = "ns".(count($ns_hash) + 1);
1017 1125
                                 $ns_hash[$prop['ns']] = $ns_name;
1018 1126
                     		}
1019 1127
                   			$vals = $extra_ns = '';
1020 1128
                     		foreach($prop['val'] as $subprop)
1021 1129
                     		{
1022
-                    			if ($subprop['ns'] && $subprop['ns'] != 'DAV:') {
1130
+                    			if ($subprop['ns'] && $subprop['ns'] != 'DAV:')
1131
+                    			{
1023 1132
 		                    		// register property namespace if not known yet
1024
-		                    		if (!isset($ns_hash[$subprop['ns']])) {
1133
+		                    		if (!isset($ns_hash[$subprop['ns']]))
1134
+		                    		{
1025 1135
 			                    		$ns_name = "ns".(count($ns_hash) + 1);
1026 1136
 			                    		$ns_hash[$subprop['ns']] = $ns_name;
1027
-		                    		} else {
1137
+		                    		}
1138
+		                    		else
1139
+		                    		{
1028 1140
 			                    		$ns_name = $ns_hash[$subprop['ns']];
1029 1141
 		                    		}
1030
-		                    		if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) {
1142
+		                    		if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false)
1143
+		                    		{
1031 1144
 			                    		$extra_ns .= $extra;
1032 1145
 		                    		}
1033 1146
 		                    		$ns_name .= ':';
1034
-	                    		} elseif ($subprop['ns'] == 'DAV:') {
1147
+	                    		}
1148
+	                    		elseif ($subprop['ns'] == 'DAV:')
1149
+	                    		{
1035 1150
 		                    		$ns_name = 'D:';
1036
-	                    		} else {
1151
+	                    		}
1152
+	                    		else
1153
+	                    		{
1037 1154
 		                    		$ns_name = '';
1038 1155
 	                    		}
1039 1156
 	                    		$vals .= "<$ns_name$subprop[name]";
@@ -1048,7 +1165,7 @@  discard block
 block discarded – undo
1048 1165
 	                    			else	// val contains only attributes, no value
1049 1166
 	                    			{
1050 1167
 			                    		foreach($subprop['val'] as $attr => $val)
1051
-										{
1168
+			                    		{
1052 1169
 				                    		$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8').'"';
1053 1170
 										}
1054 1171
 			                    		$vals .= '/>';
@@ -1057,34 +1174,50 @@  discard block
 block discarded – undo
1057 1174
 	                    		else
1058 1175
 	                    		{
1059 1176
 	                    			$vals .= '>';
1060
-	                    			if (isset($subprop['raw'])) {
1177
+	                    			if (isset($subprop['raw']))
1178
+	                    			{
1061 1179
 	                    				$vals .= '<![CDATA['.$subprop['val'].']]>';
1062
-	                    			} else {
1063
-	                    				if($subprop['name'] == 'href') $subprop['val'] = $this->_urlencode($subprop['val']);
1180
+	                    			}
1181
+	                    			else
1182
+	                    			{
1183
+	                    				if($subprop['name'] == 'href')
1184
+	                    				{
1185
+	                    					$subprop['val'] = $this->_urlencode($subprop['val']);
1186
+	                    				}
1064 1187
 		                    			$vals .= htmlspecialchars($subprop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8');
1065 1188
 	                    			}
1066 1189
 	                    			$vals .= "</$ns_name$subprop[name]>";
1067 1190
 	                    		}
1068 1191
                     		}
1069 1192
                     		echo '     <'.$ns_hash[$prop['ns']].":$prop[name]$extra_ns>$vals</".$ns_hash[$prop['ns']].":$prop[name]>\n";
1070
-                        } else {
1193
+                        }
1194
+                        else
1195
+                        {
1071 1196
                         	if ($prop['raw'])
1072 1197
                         	{
1073 1198
                         		$val = '<![CDATA['.$prop['val'].']]>';
1074
-                        	} else {
1199
+                        	}
1200
+                        	else
1201
+                        	{
1075 1202
                         		$val = htmlspecialchars($prop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8');
1076 1203
                         	}
1077 1204
                         	$val = $this->_prop_encode($val);
1078 1205
 	                        // properties from namespaces != "DAV:" or without any namespace
1079
-	                        if ($prop['ns']) {
1080
-		                        if ($this->crrnd) {
1206
+	                        if ($prop['ns'])
1207
+	                        {
1208
+		                        if ($this->crrnd)
1209
+		                        {
1081 1210
 			                        echo "     <$prop[name] xmlns=".'"'.$prop["ns"].'">'
1082 1211
 									. $val . "</$prop[name]>\n";
1083
-		                        } else {
1212
+		                        }
1213
+		                        else
1214
+		                        {
1084 1215
 			                        echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]>"
1085 1216
 									. $val . '</'.$ns_hash[$prop['ns']].":$prop[name]>\n";
1086 1217
 		                        }
1087
-	                        } else {
1218
+	                        }
1219
+	                        else
1220
+	                        {
1088 1221
 		                        echo "     <$prop[name] xmlns=\"\">$val</$prop[name]>\n";
1089 1222
 	                        }
1090 1223
                         }
@@ -1106,16 +1239,23 @@  discard block
 block discarded – undo
1106 1239
             }
1107 1240
 
1108 1241
             // now report all properties requested but not found
1109
-            if (isset($file["noprops"])) {
1242
+            if (isset($file["noprops"]))
1243
+            {
1110 1244
                 echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1111 1245
                 echo '    <'.($this->crrnd?'':'D:')."prop>\n";
1112 1246
 
1113
-                foreach ($file["noprops"] as &$prop) {
1114
-                    if ($prop["ns"] == "DAV:") {
1247
+                foreach ($file["noprops"] as &$prop)
1248
+                {
1249
+                    if ($prop["ns"] == "DAV:")
1250
+                    {
1115 1251
                         echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
1116
-                    } else if ($prop["ns"] == "") {
1252
+                    }
1253
+                    else if ($prop["ns"] == "")
1254
+                    {
1117 1255
                         echo "     <$prop[name] xmlns=\"\"/>\n";
1118
-                    } else {
1256
+                    }
1257
+                    else
1258
+                    {
1119 1259
                         echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]/>\n";
1120 1260
                     }
1121 1261
                 }
@@ -1164,15 +1304,20 @@  discard block
 block discarded – undo
1164 1304
      */
1165 1305
     function http_PROPPATCH()
1166 1306
     {
1167
-        if ($this->_check_lock_status($this->path)) {
1307
+        if ($this->_check_lock_status($this->path))
1308
+        {
1168 1309
             $options = Array();
1169 1310
 
1170 1311
             $options["path"] = $this->path;
1171 1312
 
1172 1313
             $propinfo = new _parse_proppatch("php://input", $this->store_request);
1173
-            if ($this->store_request) $this->request = $propinfo->request;
1314
+            if ($this->store_request)
1315
+            {
1316
+            	$this->request = $propinfo->request;
1317
+            }
1174 1318
 
1175
-            if (!$propinfo->success) {
1319
+            if (!$propinfo->success)
1320
+            {
1176 1321
                 $this->http_status("400 Error");
1177 1322
                 return;
1178 1323
             }
@@ -1190,14 +1335,16 @@  discard block
 block discarded – undo
1190 1335
             echo ' <'.($this->crrnd?'':'D:')."response>\n";
1191 1336
             echo '  <'.($this->crrnd?'':'D:')."href>".$this->_urlencode($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)).'</'.($this->crrnd?'':'D:')."href>\n";
1192 1337
 
1193
-            foreach ($options["props"] as $prop) {
1338
+            foreach ($options["props"] as $prop)
1339
+            {
1194 1340
                 echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1195 1341
                 echo '    <'.($this->crrnd?'':'D:')."prop><$prop[name] xmlns=\"$prop[ns]\"/></".($this->crrnd?'':'D:')."prop>\n";
1196 1342
                 echo '    <'.($this->crrnd?'':'D:')."status>HTTP/1.1 $prop[status]</".($this->crrnd?'':'D:')."status>\n";
1197 1343
                 echo '   </'.($this->crrnd?'':'D:')."propstat>\n";
1198 1344
             }
1199 1345
 
1200
-            if ($responsedescr) {
1346
+            if ($responsedescr)
1347
+            {
1201 1348
                 echo '  <'.($this->crrnd?'':'D:')."responsedescription>".
1202 1349
                     $this->_prop_encode(htmlspecialchars($responsedescr, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8')).
1203 1350
                     '</'.($this->crrnd?'':'D:')."responsedescription>\n";
@@ -1205,7 +1352,9 @@  discard block
 block discarded – undo
1205 1352
 
1206 1353
             echo ' </'.($this->crrnd?'':'D:')."response>\n";
1207 1354
             echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
1208
-        } else {
1355
+        }
1356
+        else
1357
+        {
1209 1358
             $this->http_status("423 Locked");
1210 1359
         }
1211 1360
     }
@@ -1275,11 +1424,14 @@  discard block
 block discarded – undo
1275 1424
 
1276 1425
         $this->_get_ranges($options);
1277 1426
 
1278
-        if (true === ($status = $this->GET($options))) {
1279
-            if (!headers_sent()) {
1427
+        if (true === ($status = $this->GET($options)))
1428
+        {
1429
+            if (!headers_sent())
1430
+            {
1280 1431
                 $status = "200 OK";
1281 1432
 
1282
-                if (!isset($options['mimetype'])) {
1433
+                if (!isset($options['mimetype']))
1434
+                {
1283 1435
                     $options['mimetype'] = "application/octet-stream";
1284 1436
                 }
1285 1437
                 // switching off zlib.output_compression for everything but text files,
@@ -1291,7 +1443,8 @@  discard block
 block discarded – undo
1291 1443
                 }
1292 1444
                 header("Content-type: $options[mimetype]");
1293 1445
 
1294
-                if (isset($options['mtime'])) {
1446
+                if (isset($options['mtime']))
1447
+                {
1295 1448
                     header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1296 1449
                 }
1297 1450
                 // fix for IE and https, thanks to [email protected]
@@ -1300,55 +1453,82 @@  discard block
 block discarded – undo
1300 1453
 				header("Cache-Control: maxage=1"); //In seconds
1301 1454
 				header("Pragma: public");
1302 1455
 
1303
-                if (isset($options['stream'])) {
1456
+                if (isset($options['stream']))
1457
+                {
1304 1458
                     // GET handler returned a stream
1305
-                    if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET))) {
1459
+                    if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET)))
1460
+                    {
1306 1461
                         // partial request and stream is seekable
1307 1462
 
1308
-                        if (count($options['ranges']) === 1) {
1463
+                        if (count($options['ranges']) === 1)
1464
+                        {
1309 1465
                             $range = $options['ranges'][0];
1310 1466
 
1311
-                            if (isset($range['start'])) {
1467
+                            if (isset($range['start']))
1468
+                            {
1312 1469
                                 fseek($options['stream'], $range['start'], SEEK_SET);
1313
-                                if (feof($options['stream'])) {
1470
+                                if (feof($options['stream']))
1471
+                                {
1314 1472
                                     $this->http_status($status = "416 Requested range not satisfiable");
1315 1473
                                     return;
1316 1474
                                 }
1317 1475
 
1318
-                                if (!empty($range['end'])) {
1476
+                                if (!empty($range['end']))
1477
+                                {
1319 1478
                                     $size = $range['end']-$range['start']+1;
1320 1479
                                     $this->http_status($status = "206 Partial content");
1321
-                                    if (!self::use_compression()) header("Content-Length: $size");
1480
+                                    if (!self::use_compression())
1481
+                                    {
1482
+                                    	header("Content-Length: $size");
1483
+                                    }
1322 1484
                                     header("Content-Range: bytes $range[start]-$range[end]/"
1323 1485
                                            . (isset($options['size']) ? $options['size'] : "*"));
1324
-                                    while ($size > 0 && !feof($options['stream'])) {
1486
+                                    while ($size > 0 && !feof($options['stream']))
1487
+                                    {
1325 1488
                                         $buffer = fread($options['stream'], $size < 8192 ? $size : 8192);
1326 1489
                                         $size  -= self::bytes($buffer);
1327 1490
                                         echo $buffer;
1328 1491
                                     }
1329
-                                } else {
1492
+                                }
1493
+                                else
1494
+                                {
1330 1495
                                     $this->http_status($status = "206 Partial content");
1331
-                                    if (isset($options['size'])) {
1332
-                                        if (!self::use_compression()) header("Content-Length: ".($options['size'] - $range['start']));
1496
+                                    if (isset($options['size']))
1497
+                                    {
1498
+                                        if (!self::use_compression())
1499
+                                        {
1500
+                                        	header("Content-Length: ".($options['size'] - $range['start']));
1501
+                                        }
1333 1502
                                         header("Content-Range: bytes ".$range['start']."-".
1334 1503
 											(isset($options['size']) ? $options['size']-1 : "")."/"
1335 1504
 										   . (isset($options['size']) ? $options['size'] : "*"));
1336 1505
                                     }
1337 1506
                                     fpassthru($options['stream']);
1338 1507
                                 }
1339
-                            } else {
1340
-                                if (!self::use_compression()) header("Content-length: ".$range['last']);
1508
+                            }
1509
+                            else
1510
+                            {
1511
+                                if (!self::use_compression())
1512
+                                {
1513
+                                	header("Content-length: ".$range['last']);
1514
+                                }
1341 1515
                                 fseek($options['stream'], -$range['last'], SEEK_END);
1342 1516
                                 fpassthru($options['stream']);
1343 1517
                             }
1344
-                        } else {
1518
+                        }
1519
+                        else
1520
+                        {
1345 1521
                             $this->_multipart_byterange_header(); // init multipart
1346
-                            foreach ($options['ranges'] as $range) {
1522
+                            foreach ($options['ranges'] as $range)
1523
+                            {
1347 1524
                                 // TODO what if size unknown? 500?
1348
-                                if (isset($range['start'])) {
1525
+                                if (isset($range['start']))
1526
+                                {
1349 1527
                                     $from = $range['start'];
1350 1528
                                     $to   = !empty($range['end']) ? $range['end'] : $options['size']-1;
1351
-                                } else {
1529
+                                }
1530
+                                else
1531
+                                {
1352 1532
                                     $from = $options['size'] - $range['last']-1;
1353 1533
                                     $to   = $options['size'] -1;
1354 1534
                                 }
@@ -1358,7 +1538,8 @@  discard block
 block discarded – undo
1358 1538
 
1359 1539
 
1360 1540
                                 fseek($options['stream'], $from, SEEK_SET);
1361
-                                while ($size && !feof($options['stream'])) {
1541
+                                while ($size && !feof($options['stream']))
1542
+                                {
1362 1543
                                     $buffer = fread($options['stream'], 4096);
1363 1544
                                     $size  -= self::bytes($buffer);
1364 1545
                                     echo $buffer;
@@ -1366,29 +1547,44 @@  discard block
 block discarded – undo
1366 1547
                             }
1367 1548
                             $this->_multipart_byterange_header(); // end multipart
1368 1549
                         }
1369
-                    } else {
1550
+                    }
1551
+                    else
1552
+                    {
1370 1553
                         // normal request or stream isn't seekable, return full content
1371
-                        if (isset($options['size']) && !self::use_compression()) {
1554
+                        if (isset($options['size']) && !self::use_compression())
1555
+                        {
1372 1556
                             header("Content-Length: ".$options['size']);
1373 1557
                         }
1374 1558
                         fpassthru($options['stream']);
1375 1559
                         return; // no more headers
1376 1560
                     }
1377
-                } elseif (isset($options['data'])) {
1378
-                    if (is_array($options['data'])) {
1561
+                }
1562
+                elseif (isset($options['data']))
1563
+                {
1564
+                    if (is_array($options['data']))
1565
+                    {
1379 1566
                         // reply to partial request
1380
-                    } else {
1381
-                        if (!self::use_compression()) header("Content-Length: ".self::bytes($options['data']));
1567
+                    }
1568
+                    else
1569
+                    {
1570
+                        if (!self::use_compression())
1571
+                        {
1572
+                        	header("Content-Length: ".self::bytes($options['data']));
1573
+                        }
1382 1574
                         echo $options['data'];
1383 1575
                     }
1384 1576
                 }
1385 1577
             }
1386 1578
         }
1387 1579
 
1388
-        if (!headers_sent()) {
1389
-            if (false === $status) {
1580
+        if (!headers_sent())
1581
+        {
1582
+            if (false === $status)
1583
+            {
1390 1584
                 $this->http_status("404 not found");
1391
-            } else {
1585
+            }
1586
+            else
1587
+            {
1392 1588
                 // TODO: check setting of headers in various code paths above
1393 1589
                 $this->http_status("$status");
1394 1590
             }
@@ -1405,15 +1601,18 @@  discard block
 block discarded – undo
1405 1601
     function _get_ranges(&$options)
1406 1602
     {
1407 1603
         // process Range: header if present
1408
-        if (isset($this->_SERVER['HTTP_RANGE'])) {
1604
+        if (isset($this->_SERVER['HTTP_RANGE']))
1605
+        {
1409 1606
 
1410 1607
             // we only support standard "bytes" range specifications for now
1411 1608
 			$matches = null;
1412
-            if (preg_match('/bytes\s*=\s*(.+)/', $this->_SERVER['HTTP_RANGE'], $matches)) {
1609
+            if (preg_match('/bytes\s*=\s*(.+)/', $this->_SERVER['HTTP_RANGE'], $matches))
1610
+            {
1413 1611
                 $options["ranges"] = array();
1414 1612
 
1415 1613
                 // ranges are comma separated
1416
-                foreach (explode(",", $matches[1]) as $range) {
1614
+                foreach (explode(",", $matches[1]) as $range)
1615
+                {
1417 1616
                     // ranges are either from-to pairs or just end positions
1418 1617
                     list($start, $end) = explode("-", $range);
1419 1618
                     $options["ranges"][] = ($start==="")
@@ -1439,8 +1638,10 @@  discard block
 block discarded – undo
1439 1638
      */
1440 1639
     function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false)
1441 1640
     {
1442
-        if ($mimetype === false) {
1443
-            if (!isset($this->multipart_separator)) {
1641
+        if ($mimetype === false)
1642
+        {
1643
+            if (!isset($this->multipart_separator))
1644
+            {
1444 1645
                 // initial
1445 1646
 
1446 1647
                 // a little naive, this sequence *might* be part of the content
@@ -1449,13 +1650,17 @@  discard block
 block discarded – undo
1449 1650
 
1450 1651
                 // generate HTTP header
1451 1652
                 header("Content-type: multipart/byteranges; boundary=".$this->multipart_separator);
1452
-            } else {
1653
+            }
1654
+            else
1655
+            {
1453 1656
                 // final
1454 1657
 
1455 1658
                 // generate closing multipart sequence
1456 1659
                 echo "\n--{$this->multipart_separator}--";
1457 1660
             }
1458
-        } else {
1661
+        }
1662
+        else
1663
+        {
1459 1664
             // generate separator and header for next part
1460 1665
             echo "\n--{$this->multipart_separator}\n";
1461 1666
             echo "Content-type: $mimetype\n";
@@ -1482,32 +1687,45 @@  discard block
 block discarded – undo
1482 1687
         $options         = Array();
1483 1688
         $options["path"] = $this->path;
1484 1689
 
1485
-        if (method_exists($this, "HEAD")) {
1690
+        if (method_exists($this, "HEAD"))
1691
+        {
1486 1692
             $status = $this->head($options);
1487
-        } else if (method_exists($this, "GET")) {
1693
+        }
1694
+        else if (method_exists($this, "GET"))
1695
+        {
1488 1696
             ob_start();
1489 1697
             $status = $this->GET($options);
1490
-            if (!isset($options['size'])) {
1698
+            if (!isset($options['size']))
1699
+            {
1491 1700
                 $options['size'] = ob_get_length();
1492 1701
             }
1493 1702
             ob_end_clean();
1494 1703
         }
1495 1704
 
1496
-        if (!isset($options['mimetype'])) {
1705
+        if (!isset($options['mimetype']))
1706
+        {
1497 1707
             $options['mimetype'] = "application/octet-stream";
1498 1708
         }
1499 1709
         header("Content-type: $options[mimetype]");
1500 1710
 
1501
-        if (isset($options['mtime'])) {
1711
+        if (isset($options['mtime']))
1712
+        {
1502 1713
             header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
1503 1714
         }
1504 1715
 
1505
-        if (isset($options['size'])) {
1716
+        if (isset($options['size']))
1717
+        {
1506 1718
             header("Content-Length: ".$options['size']);
1507 1719
         }
1508 1720
 
1509
-        if ($status === true)  $status = "200 OK";
1510
-        if ($status === false) $status = "404 Not found";
1721
+        if ($status === true)
1722
+        {
1723
+        	$status = "200 OK";
1724
+        }
1725
+        if ($status === false)
1726
+        {
1727
+        	$status = "404 Not found";
1728
+        }
1511 1729
 
1512 1730
         $this->http_status($status);
1513 1731
     }
@@ -1533,21 +1751,25 @@  discard block
 block discarded – undo
1533 1751
 	        $options['content_length'] = $this->_SERVER['CONTENT_LENGTH'];
1534 1752
         }
1535 1753
         elseif (isset($this->_SERVER['X-Expected-Entity-Length']))
1536
-		{
1754
+        {
1537 1755
 	        // MacOS gives us that hint
1538 1756
 	        $options['content_length'] = $this->_SERVER['X-Expected-Entity-Length'];
1539 1757
 		}
1540 1758
 
1541 1759
         // get the Content-type
1542
-        if (isset($this->_SERVER["CONTENT_TYPE"])) {
1760
+        if (isset($this->_SERVER["CONTENT_TYPE"]))
1761
+        {
1543 1762
 	        // for now we do not support any sort of multipart requests
1544
-	        if (!strncmp($this->_SERVER["CONTENT_TYPE"], 'multipart/', 10)) {
1763
+	        if (!strncmp($this->_SERVER["CONTENT_TYPE"], 'multipart/', 10))
1764
+	        {
1545 1765
 		        $this->http_status('501 not implemented');
1546 1766
 		        echo 'The service does not support mulipart POST requests';
1547 1767
 		        return;
1548 1768
 	        }
1549 1769
 	        $options['content_type'] = $this->_SERVER['CONTENT_TYPE'];
1550
-        } else {
1770
+        }
1771
+        else
1772
+        {
1551 1773
 	        // default content type if none given
1552 1774
 	        $options['content_type'] = 'application/octet-stream';
1553 1775
         }
@@ -1558,7 +1780,7 @@  discard block
 block discarded – undo
1558 1780
     		case 'gzip':
1559 1781
     		case 'deflate':	//zlib
1560 1782
     			if (extension_loaded('zlib'))
1561
-     			{
1783
+    			{
1562 1784
       				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1563 1785
        			}
1564 1786
     	}
@@ -1579,15 +1801,23 @@  discard block
 block discarded – undo
1579 1801
          does not understand or implement and MUST return a 501
1580 1802
          (Not Implemented) response in such cases."
1581 1803
          */
1582
-        foreach ($this->_SERVER as $key => $val) {
1583
-	        if (strncmp($key, 'HTTP_CONTENT', 11)) continue;
1584
-	        switch ($key) {
1804
+        foreach ($this->_SERVER as $key => $val)
1805
+        {
1806
+	        if (strncmp($key, 'HTTP_CONTENT', 11))
1807
+	        {
1808
+	        	continue;
1809
+	        }
1810
+	        switch ($key)
1811
+	        {
1585 1812
 		        case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1586 1813
 		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1587 1814
 		        	{
1588 1815
 		        		case 'gzip':
1589 1816
 		        		case 'deflate':	//zlib
1590
-		        			if (extension_loaded('zlib')) break;
1817
+		        			if (extension_loaded('zlib'))
1818
+		        			{
1819
+		        				break;
1820
+		        			}
1591 1821
 		        			// fall through for no zlib support
1592 1822
 		        		default:
1593 1823
 					        $this->http_status('415 Unsupported Media Type');
@@ -1617,14 +1847,16 @@  discard block
 block discarded – undo
1617 1847
 			        // the header format is also specified in RFC 2616 14.16
1618 1848
 			        // TODO we have to ensure that implementations support this or send 501 instead
1619 1849
 					$matches = null;
1620
-			        if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
1850
+			        if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches))
1851
+			        {
1621 1852
 				        $this->http_status('400 bad request');
1622 1853
 				        echo 'The service does only support single byte ranges';
1623 1854
 				        return;
1624 1855
 			        }
1625 1856
 
1626 1857
 			        $range = array('start'=>$matches[1], 'end'=>$matches[2]);
1627
-			        if (is_numeric($matches[3])) {
1858
+			        if (is_numeric($matches[3]))
1859
+			        {
1628 1860
 				        $range['total_length'] = $matches[3];
1629 1861
 			        }
1630 1862
 			        $options['ranges'][] = $range;
@@ -1656,31 +1888,46 @@  discard block
 block discarded – undo
1656 1888
 	        }
1657 1889
         }
1658 1890
 
1659
-        if (method_exists($this, 'POST')) {
1891
+        if (method_exists($this, 'POST'))
1892
+        {
1660 1893
 	        $status = $this->POST($options);
1661 1894
 
1662
-	        if ($status === false) {
1895
+	        if ($status === false)
1896
+	        {
1663 1897
 		        $status = '400 Something went wrong';
1664
-	        } else if ($status === true) {
1898
+	        }
1899
+	        else if ($status === true)
1900
+	        {
1665 1901
 	        	$status = '200 OK';
1666
-	        } else if (is_resource($status) && get_resource_type($status) == 'stream') {
1902
+	        }
1903
+	        else if (is_resource($status) && get_resource_type($status) == 'stream')
1904
+	        {
1667 1905
 		        $stream = $status;
1668 1906
 
1669 1907
 		        $status = empty($options['new']) ? '200 OK' : '201 Created';
1670 1908
 
1671
-		        if (!empty($options['ranges'])) {
1909
+		        if (!empty($options['ranges']))
1910
+		        {
1672 1911
 			        // TODO multipart support is missing (see also above)
1673
-			        if (0 == fseek($stream, $range[0]['start'], SEEK_SET)) {
1912
+			        if (0 == fseek($stream, $range[0]['start'], SEEK_SET))
1913
+			        {
1674 1914
 				        $length = $range[0]['end']-$range[0]['start']+1;
1675
-				        if (!fwrite($stream, fread($options['stream'], $length))) {
1915
+				        if (!fwrite($stream, fread($options['stream'], $length)))
1916
+				        {
1676 1917
 					        $status = '403 Forbidden';
1677 1918
 				        }
1678
-			        } else {
1919
+			        }
1920
+			        else
1921
+			        {
1679 1922
 				        $status = '403 Forbidden';
1680 1923
 			        }
1681
-		        } else {
1682
-			        while (!feof($options['stream'])) {
1683
-				        if (false === fwrite($stream, fread($options['stream'], 4096))) {
1924
+		        }
1925
+		        else
1926
+		        {
1927
+			        while (!feof($options['stream']))
1928
+			        {
1929
+				        if (false === fwrite($stream, fread($options['stream'], 4096)))
1930
+				        {
1684 1931
 					        $status = '403 Forbidden';
1685 1932
 					        break;
1686 1933
 				        }
@@ -1704,7 +1951,8 @@  discard block
 block discarded – undo
1704 1951
      */
1705 1952
     function http_PUT()
1706 1953
     {
1707
-        if ($this->_check_lock_status($this->path)) {
1954
+        if ($this->_check_lock_status($this->path))
1955
+        {
1708 1956
             $options                   = Array();
1709 1957
             $options["path"]           = $this->path;
1710 1958
 
@@ -1719,15 +1967,19 @@  discard block
 block discarded – undo
1719 1967
             }
1720 1968
 
1721 1969
             // get the Content-type
1722
-            if (isset($this->_SERVER["CONTENT_TYPE"])) {
1970
+            if (isset($this->_SERVER["CONTENT_TYPE"]))
1971
+            {
1723 1972
                 // for now we do not support any sort of multipart requests
1724
-                if (!strncmp($this->_SERVER["CONTENT_TYPE"], "multipart/", 10)) {
1973
+                if (!strncmp($this->_SERVER["CONTENT_TYPE"], "multipart/", 10))
1974
+                {
1725 1975
                     $this->http_status("501 not implemented");
1726 1976
                     echo "The service does not support multipart PUT requests";
1727 1977
                     return;
1728 1978
                 }
1729 1979
                 $options["content_type"] = $this->_SERVER["CONTENT_TYPE"];
1730
-            } else {
1980
+            }
1981
+            else
1982
+            {
1731 1983
                 // default content type if none given
1732 1984
                 $options["content_type"] = "application/octet-stream";
1733 1985
             }
@@ -1738,7 +1990,7 @@  discard block
 block discarded – undo
1738 1990
 	    		case 'gzip':
1739 1991
 	    		case 'deflate':	//zlib
1740 1992
 	    			if (extension_loaded('zlib'))
1741
-	     			{
1993
+	    			{
1742 1994
 	      				stream_filter_append($options['stream'], 'zlib.inflate', STREAM_FILTER_READ);
1743 1995
 	       			}
1744 1996
 	    	}
@@ -1759,15 +2011,23 @@  discard block
 block discarded – undo
1759 2011
              does not understand or implement and MUST return a 501
1760 2012
              (Not Implemented) response in such cases."
1761 2013
             */
1762
-            foreach ($this->_SERVER as $key => $val) {
1763
-                if (strncmp($key, "HTTP_CONTENT", 11)) continue;
1764
-                switch ($key) {
2014
+            foreach ($this->_SERVER as $key => $val)
2015
+            {
2016
+                if (strncmp($key, "HTTP_CONTENT", 11))
2017
+                {
2018
+                	continue;
2019
+                }
2020
+                switch ($key)
2021
+                {
1765 2022
                 case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1766 2023
 		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1767 2024
 		        	{
1768 2025
 		        		case 'gzip':
1769 2026
 		        		case 'deflate':	//zlib
1770
-		        			if (extension_loaded('zlib')) break;
2027
+		        			if (extension_loaded('zlib'))
2028
+		        			{
2029
+		        				break;
2030
+		        			}
1771 2031
 		        			// fall through for no zlib support
1772 2032
 		        		default:
1773 2033
 					        $this->http_status('415 Unsupported Media Type');
@@ -1797,18 +2057,21 @@  discard block
 block discarded – undo
1797 2057
                     // the header format is also specified in RFC 2616 14.16
1798 2058
                     // TODO we have to ensure that implementations support this or send 501 instead
1799 2059
 					$matches = null;
1800
-                    if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
2060
+                    if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches))
2061
+                    {
1801 2062
                         $this->http_status("400 bad request");
1802 2063
                         echo "The service does only support single byte ranges";
1803 2064
                         return;
1804 2065
                     }
1805 2066
 
1806 2067
                     $range = array("start" => $matches[1], "end" => $matches[2]);
1807
-                    if (is_numeric($matches[3])) {
2068
+                    if (is_numeric($matches[3]))
2069
+                    {
1808 2070
                         $range["total_length"] = $matches[3];
1809 2071
                     }
1810 2072
 
1811
-                    if (!isset($options['ranges'])) {
2073
+                    if (!isset($options['ranges']))
2074
+                    {
1812 2075
                         $options['ranges'] = array();
1813 2076
                     }
1814 2077
 
@@ -1839,45 +2102,65 @@  discard block
 block discarded – undo
1839 2102
 
1840 2103
             $stat = $this->PUT($options);
1841 2104
 
1842
-            if ($stat === false) {
2105
+            if ($stat === false)
2106
+            {
1843 2107
                 $stat = "403 Forbidden";
1844
-            } else if (is_resource($stat) && get_resource_type($stat) == "stream") {
2108
+            }
2109
+            else if (is_resource($stat) && get_resource_type($stat) == "stream")
2110
+            {
1845 2111
                 $stream = $stat;
1846 2112
 
1847 2113
                 $stat = $options["new"] ? "201 Created" : "204 No Content";
1848 2114
 
1849
-                if (!empty($options["ranges"])) {
2115
+                if (!empty($options["ranges"]))
2116
+                {
1850 2117
                     // TODO multipart support is missing (see also above)
1851
-                    if (0 == fseek($stream, $options['ranges'][0]["start"], SEEK_SET)) {
2118
+                    if (0 == fseek($stream, $options['ranges'][0]["start"], SEEK_SET))
2119
+                    {
1852 2120
                         $length = $options['ranges'][0]["end"] - $options['ranges'][0]["start"]+1;
1853 2121
 
1854
-                        while (!feof($options['stream'])) {
1855
-                            if ($length <= 0) {
2122
+                        while (!feof($options['stream']))
2123
+                        {
2124
+                            if ($length <= 0)
2125
+                            {
1856 2126
                                break;
1857 2127
                             }
1858 2128
 
1859
-                            if ($length <= 8192) {
2129
+                            if ($length <= 8192)
2130
+                            {
1860 2131
                                 $data = fread($options['stream'], $length);
1861
-                            } else {
2132
+                            }
2133
+                            else
2134
+                            {
1862 2135
                                 $data = fread($options['stream'], 8192);
1863 2136
                             }
1864 2137
 
1865
-                            if ($data === false) {
2138
+                            if ($data === false)
2139
+                            {
1866 2140
                                 $stat = "400 Bad request";
1867
-                            } elseif (strlen($data)) {
1868
-                                if (false === fwrite($stream, $data)) {
2141
+                            }
2142
+                            elseif (strlen($data))
2143
+                            {
2144
+                                if (false === fwrite($stream, $data))
2145
+                                {
1869 2146
                                     $stat = "403 Forbidden";
1870 2147
                                     break;
1871 2148
                                 }
1872 2149
                                 $length -= strlen($data);
1873 2150
                             }
1874 2151
                         }
1875
-                    } else {
2152
+                    }
2153
+                    else
2154
+                    {
1876 2155
                         $stat = "403 Forbidden";
1877 2156
                     }
1878
-                } else {
1879
-                    while (!feof($options["stream"])) {
1880
-                        if (false === fwrite($stream, fread($options["stream"], 8192))) {
2157
+                }
2158
+                else
2159
+                {
2160
+                    while (!feof($options["stream"]))
2161
+                    {
2162
+                        if (false === fwrite($stream, fread($options["stream"], 8192)))
2163
+                        {
1881 2164
                             $stat = "403 Forbidden";
1882 2165
                             break;
1883 2166
                         }
@@ -1888,7 +2171,9 @@  discard block
 block discarded – undo
1888 2171
             }
1889 2172
 
1890 2173
             $this->http_status($stat);
1891
-        } else {
2174
+        }
2175
+        else
2176
+        {
1892 2177
             $this->http_status("423 Locked");
1893 2178
         }
1894 2179
     }
@@ -1907,8 +2192,10 @@  discard block
 block discarded – undo
1907 2192
     function http_DELETE()
1908 2193
     {
1909 2194
         // check RFC 2518 Section 9.2, last paragraph
1910
-        if (isset($this->_SERVER["HTTP_DEPTH"])) {
1911
-            if ($this->_SERVER["HTTP_DEPTH"] != "infinity") {
2195
+        if (isset($this->_SERVER["HTTP_DEPTH"]))
2196
+        {
2197
+            if ($this->_SERVER["HTTP_DEPTH"] != "infinity")
2198
+            {
1912 2199
 				if (stripos($_SERVER['HTTP_USER_AGENT'],'webdrive') !== false)
1913 2200
 				{
1914 2201
 					// pretend we didnt see it, as webdrive does not handle the depth parameter correctly while deleting collections
@@ -1922,7 +2209,8 @@  discard block
 block discarded – undo
1922 2209
         }
1923 2210
 
1924 2211
         // check lock status
1925
-        if ($this->_check_lock_status($this->path)) {
2212
+        if ($this->_check_lock_status($this->path))
2213
+        {
1926 2214
             // ok, proceed
1927 2215
             $options         = Array();
1928 2216
             $options["path"] = $this->path;
@@ -1930,7 +2218,9 @@  discard block
 block discarded – undo
1930 2218
             $stat = $this->DELETE($options);
1931 2219
 
1932 2220
             $this->http_status($stat);
1933
-        } else {
2221
+        }
2222
+        else
2223
+        {
1934 2224
             // sorry, its locked
1935 2225
             $this->http_status("423 Locked");
1936 2226
         }
@@ -1965,10 +2255,13 @@  discard block
 block discarded – undo
1965 2255
      */
1966 2256
     function http_MOVE()
1967 2257
     {
1968
-        if ($this->_check_lock_status($this->path)) {
2258
+        if ($this->_check_lock_status($this->path))
2259
+        {
1969 2260
             // destination lock status is always checked by the helper method
1970 2261
             $this->_copymove("move");
1971
-        } else {
2262
+        }
2263
+        else
2264
+        {
1972 2265
             $this->http_status("423 Locked");
1973 2266
         }
1974 2267
     }
@@ -1989,19 +2282,25 @@  discard block
 block discarded – undo
1989 2282
         $options         = Array();
1990 2283
         $options["path"] = $this->path;
1991 2284
 
1992
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
2285
+        if (isset($this->_SERVER['HTTP_DEPTH']))
2286
+        {
1993 2287
             $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
1994
-        } else {
2288
+        }
2289
+        else
2290
+        {
1995 2291
             $options["depth"] = "infinity";
1996 2292
         }
1997 2293
 
1998
-        if (isset($this->_SERVER["HTTP_TIMEOUT"])) {
2294
+        if (isset($this->_SERVER["HTTP_TIMEOUT"]))
2295
+        {
1999 2296
             $options["timeout"] = explode(",", $this->_SERVER["HTTP_TIMEOUT"]);
2000 2297
         }
2001 2298
 
2002
-        if (empty($this->_SERVER['CONTENT_LENGTH']) && !empty($this->_SERVER['HTTP_IF'])) {
2299
+        if (empty($this->_SERVER['CONTENT_LENGTH']) && !empty($this->_SERVER['HTTP_IF']))
2300
+        {
2003 2301
             // check if locking is possible
2004
-            if (!$this->_check_lock_status($this->path)) {
2302
+            if (!$this->_check_lock_status($this->path))
2303
+            {
2005 2304
                 $this->http_status("423 Locked");
2006 2305
                 return;
2007 2306
             }
@@ -2017,15 +2316,19 @@  discard block
 block discarded – undo
2017 2316
 
2018 2317
 
2019 2318
             $stat = $this->LOCK($options);
2020
-        } else {
2319
+        }
2320
+        else
2321
+        {
2021 2322
             // extract lock request information from request XML payload
2022 2323
             $lockinfo = new _parse_lockinfo("php://input");
2023
-            if (!$lockinfo->success) {
2324
+            if (!$lockinfo->success)
2325
+            {
2024 2326
                 $this->http_status("400 bad request");
2025 2327
             }
2026 2328
 
2027 2329
             // check if locking is possible
2028
-            if (!$this->_check_lock_status($this->path, $lockinfo->lockscope === "shared")) {
2330
+            if (!$this->_check_lock_status($this->path, $lockinfo->lockscope === "shared"))
2331
+            {
2029 2332
                 $this->http_status("423 Locked");
2030 2333
                 return;
2031 2334
             }
@@ -2040,36 +2343,51 @@  discard block
 block discarded – undo
2040 2343
             $stat = $this->LOCK($options);
2041 2344
         }
2042 2345
 
2043
-        if (is_bool($stat)) {
2346
+        if (is_bool($stat))
2347
+        {
2044 2348
             $http_stat = $stat ? "200 OK" : "423 Locked";
2045
-        } else {
2349
+        }
2350
+        else
2351
+        {
2046 2352
             $http_stat = (string)$stat;
2047 2353
         }
2048 2354
         $this->http_status($http_stat);
2049 2355
 
2050
-        if ($http_stat{0} == 2) { // 2xx states are ok
2051
-            if ($options["timeout"]) {
2356
+        if ($http_stat{0} == 2)
2357
+        {
2358
+// 2xx states are ok
2359
+            if ($options["timeout"])
2360
+            {
2052 2361
                 // if multiple timeout values were given we take the first only
2053
-                if (is_array($options["timeout"])) {
2362
+                if (is_array($options["timeout"]))
2363
+                {
2054 2364
                     reset($options["timeout"]);
2055 2365
                     $options["timeout"] = current($options["timeout"]);
2056 2366
                 }
2057 2367
                 // if the timeout is numeric only we need to reformat it
2058
-                if (is_numeric($options["timeout"])) {
2368
+                if (is_numeric($options["timeout"]))
2369
+                {
2059 2370
                     // more than a million is considered an absolute timestamp
2060 2371
                     // less is more likely a relative value
2061
-                    if ($options["timeout"]>1000000) {
2372
+                    if ($options["timeout"]>1000000)
2373
+                    {
2062 2374
                         $timeout = "Second-".($options['timeout']-time());
2063
-                    } else {
2375
+                    }
2376
+                    else
2377
+                    {
2064 2378
                         $timeout = "Second-$options[timeout]";
2065 2379
                     }
2066
-                } else {
2380
+                }
2381
+                else
2382
+                {
2067 2383
                     // non-numeric values are passed on verbatim,
2068 2384
                     // no error checking is performed here in this case
2069 2385
                     // TODO: send "Infinite" on invalid timeout strings?
2070 2386
                     $timeout = $options["timeout"];
2071 2387
                 }
2072
-            } else {
2388
+            }
2389
+            else
2390
+            {
2073 2391
                 $timeout = "Infinite";
2074 2392
             }
2075 2393
 
@@ -2107,9 +2425,12 @@  discard block
 block discarded – undo
2107 2425
         $options         = Array();
2108 2426
         $options["path"] = $this->path;
2109 2427
 
2110
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
2428
+        if (isset($this->_SERVER['HTTP_DEPTH']))
2429
+        {
2111 2430
             $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2112
-        } else {
2431
+        }
2432
+        else
2433
+        {
2113 2434
             $options["depth"] = "infinity";
2114 2435
         }
2115 2436
 
@@ -2138,9 +2459,12 @@  discard block
 block discarded – undo
2138 2459
         $options['path'] = $this->path;
2139 2460
         $options['errors'] = array();
2140 2461
 
2141
-        if (isset($this->_SERVER['HTTP_DEPTH'])) {
2462
+        if (isset($this->_SERVER['HTTP_DEPTH']))
2463
+        {
2142 2464
             $options['depth'] = $this->_SERVER['HTTP_DEPTH'];
2143
-        } else {
2465
+        }
2466
+        else
2467
+        {
2144 2468
             $options['depth'] = 'infinity';
2145 2469
         }
2146 2470
 
@@ -2151,18 +2475,26 @@  discard block
 block discarded – undo
2151 2475
 		$this->http_status($status);
2152 2476
 		$content = '';
2153 2477
 
2154
-        if (is_array($options['errors']) && count($options['errors'])) {
2478
+        if (is_array($options['errors']) && count($options['errors']))
2479
+        {
2155 2480
 	        header('Content-Type: text/xml; charset="utf-8"');
2156 2481
 	        // ... and payload
2157 2482
 	        $content .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2158 2483
 	        $content .= "<D:error xmlns:D=\"DAV:\"> \n";
2159
-	        foreach ($options['errors'] as $violation) {
2484
+	        foreach ($options['errors'] as $violation)
2485
+	        {
2160 2486
 	        	$content .= '<'.($this->crrnd?'':'D:')."$violation/>\n";
2161 2487
 	        }
2162 2488
 	        $content .=  '</'.($this->crrnd?'':'D:')."error>\n";
2163 2489
         }
2164
-        if (!self::use_compression()) header("Content-Length: ".self::bytes($content));
2165
-        if ($content) echo $options['content'];
2490
+        if (!self::use_compression())
2491
+        {
2492
+        	header("Content-Length: ".self::bytes($content));
2493
+        }
2494
+        if ($content)
2495
+        {
2496
+        	echo $options['content'];
2497
+        }
2166 2498
     }
2167 2499
 
2168 2500
     // }}}
@@ -2176,9 +2508,12 @@  discard block
 block discarded – undo
2176 2508
         $options         = Array();
2177 2509
         $options["path"] = $this->path;
2178 2510
 
2179
-        if (isset($this->_SERVER["HTTP_DEPTH"])) {
2511
+        if (isset($this->_SERVER["HTTP_DEPTH"]))
2512
+        {
2180 2513
             $options["depth"] = $this->_SERVER["HTTP_DEPTH"];
2181
-        } else {
2514
+        }
2515
+        else
2516
+        {
2182 2517
             $options["depth"] = "infinity";
2183 2518
         }
2184 2519
 
@@ -2187,33 +2522,45 @@  discard block
 block discarded – undo
2187 2522
         $url  = parse_url($this->_SERVER["HTTP_DESTINATION"]);
2188 2523
         $path = urldecode($url["path"]);
2189 2524
 
2190
-        if (isset($url["host"])) {
2525
+        if (isset($url["host"]))
2526
+        {
2191 2527
             // TODO check url scheme, too
2192 2528
             $http_host = $url["host"];
2193 2529
             if (isset($url["port"]) && $url["port"] != 80)
2194
-                $http_host.= ":".$url["port"];
2195
-        } else {
2530
+            {
2531
+                            $http_host.= ":".$url["port"];
2532
+            }
2533
+        }
2534
+        else
2535
+        {
2196 2536
             // only path given, set host to self
2197 2537
             $http_host = $http_header_host;
2198 2538
         }
2199 2539
 
2200 2540
         if ($http_host == $http_header_host &&
2201 2541
             !strncmp($this->_SERVER["SCRIPT_NAME"], $path,
2202
-                     strlen($this->_SERVER["SCRIPT_NAME"]))) {
2542
+                     strlen($this->_SERVER["SCRIPT_NAME"])))
2543
+        {
2203 2544
             $options["dest"] = substr($path, strlen($this->_SERVER["SCRIPT_NAME"]));
2204
-            if (!$this->_check_lock_status($options["dest"])) {
2545
+            if (!$this->_check_lock_status($options["dest"]))
2546
+            {
2205 2547
                 $this->http_status("423 Locked");
2206 2548
                 return;
2207 2549
             }
2208 2550
 
2209
-        } else {
2551
+        }
2552
+        else
2553
+        {
2210 2554
             $options["dest_url"] = $this->_SERVER["HTTP_DESTINATION"];
2211 2555
         }
2212 2556
 
2213 2557
         // see RFC 2518 Sections 9.6, 8.8.4 and 8.9.3
2214
-        if (isset($this->_SERVER["HTTP_OVERWRITE"])) {
2558
+        if (isset($this->_SERVER["HTTP_OVERWRITE"]))
2559
+        {
2215 2560
             $options["overwrite"] = $this->_SERVER["HTTP_OVERWRITE"] == "T";
2216
-        } else {
2561
+        }
2562
+        else
2563
+        {
2217 2564
             $options["overwrite"] = true;
2218 2565
         }
2219 2566
 
@@ -2239,10 +2586,13 @@  discard block
 block discarded – undo
2239 2586
         // all other METHODS need both a http_method() wrapper
2240 2587
         // and a method() implementation
2241 2588
         // the base class supplies wrappers only
2242
-        foreach (get_class_methods($this) as $method) {
2243
-            if (!strncmp("http_", $method, 5)) {
2589
+        foreach (get_class_methods($this) as $method)
2590
+        {
2591
+            if (!strncmp("http_", $method, 5))
2592
+            {
2244 2593
                 $method = strtoupper(substr($method, 5));
2245
-                if (method_exists($this, $method)) {
2594
+                if (method_exists($this, $method))
2595
+                {
2246 2596
                     $allow[$method] = $method;
2247 2597
                 }
2248 2598
             }
@@ -2250,10 +2600,13 @@  discard block
 block discarded – undo
2250 2600
 
2251 2601
         // we can emulate a missing HEAD implemetation using GET
2252 2602
         if (isset($allow["GET"]))
2253
-            $allow["HEAD"] = "HEAD";
2603
+        {
2604
+                    $allow["HEAD"] = "HEAD";
2605
+        }
2254 2606
 
2255 2607
         // no LOCK without checklok()
2256
-        if (!method_exists($this, "checklock")) {
2608
+        if (!method_exists($this, "checklock"))
2609
+        {
2257 2610
             unset($allow["LOCK"]);
2258 2611
             unset($allow["UNLOCK"]);
2259 2612
         }
@@ -2275,7 +2628,8 @@  discard block
 block discarded – undo
2275 2628
     public static function mkprop()
2276 2629
     {
2277 2630
 	    $args = func_get_args();
2278
-	    switch (count($args)) {
2631
+	    switch (count($args))
2632
+	    {
2279 2633
 		    case 4:
2280 2634
 			    return array('ns'   => $args[0],
2281 2635
 				    'name' => $args[1],
@@ -2302,17 +2656,22 @@  discard block
 block discarded – undo
2302 2656
      */
2303 2657
     function _check_auth()
2304 2658
     {
2305
-        if (method_exists($this, "checkAuth")) {
2659
+        if (method_exists($this, "checkAuth"))
2660
+        {
2306 2661
             // PEAR style method name
2307 2662
             return $this->checkAuth(@$this->_SERVER["AUTH_TYPE"],
2308 2663
                                     @$this->_SERVER["PHP_AUTH_USER"],
2309 2664
                                     @$this->_SERVER["PHP_AUTH_PW"]);
2310
-        } else if (method_exists($this, "check_auth")) {
2665
+        }
2666
+        else if (method_exists($this, "check_auth"))
2667
+        {
2311 2668
             // old (pre 1.0) method name
2312 2669
             return $this->check_auth(@$this->_SERVER["AUTH_TYPE"],
2313 2670
                                      @$this->_SERVER["PHP_AUTH_USER"],
2314 2671
                                      @$this->_SERVER["PHP_AUTH_PW"]);
2315
-        } else {
2672
+        }
2673
+        else
2674
+        {
2316 2675
             // no method found -> no authentication required
2317 2676
             return true;
2318 2677
         }
@@ -2331,7 +2690,8 @@  discard block
 block discarded – undo
2331 2690
     public static function _new_uuid()
2332 2691
     {
2333 2692
         // use uuid extension from PECL if available
2334
-        if (function_exists("uuid_create")) {
2693
+        if (function_exists("uuid_create"))
2694
+        {
2335 2695
             return uuid_create();
2336 2696
         }
2337 2697
 
@@ -2377,12 +2737,14 @@  discard block
 block discarded – undo
2377 2737
     function _if_header_lexer($string, &$pos)
2378 2738
     {
2379 2739
         // skip whitespace
2380
-        while (ctype_space($string{$pos})) {
2740
+        while (ctype_space($string{$pos}))
2741
+        {
2381 2742
             ++$pos;
2382 2743
         }
2383 2744
 
2384 2745
         // already at end of string?
2385
-        if (strlen($string) <= $pos) {
2746
+        if (strlen($string) <= $pos)
2747
+        {
2386 2748
             return false;
2387 2749
         }
2388 2750
 
@@ -2390,7 +2752,8 @@  discard block
 block discarded – undo
2390 2752
         $c = $string{$pos++};
2391 2753
 
2392 2754
         // now it depends on what we found
2393
-        switch ($c) {
2755
+        switch ($c)
2756
+        {
2394 2757
         case "<":
2395 2758
             // URIs are enclosed in <...>
2396 2759
             $pos2 = strpos($string, ">", $pos);
@@ -2400,10 +2763,13 @@  discard block
 block discarded – undo
2400 2763
 
2401 2764
         case "[":
2402 2765
             //Etags are enclosed in [...]
2403
-            if ($string{$pos} == "W") {
2766
+            if ($string{$pos} == "W")
2767
+            {
2404 2768
                 $type = "ETAG_WEAK";
2405 2769
                 $pos += 2;
2406
-            } else {
2770
+            }
2771
+            else
2772
+            {
2407 2773
                 $type = "ETAG_STRONG";
2408 2774
             }
2409 2775
             $pos2 = strpos($string, "]", $pos);
@@ -2435,35 +2801,44 @@  discard block
 block discarded – undo
2435 2801
         $uris = array();
2436 2802
 
2437 2803
         // parser loop
2438
-        while ($pos < $len) {
2804
+        while ($pos < $len)
2805
+        {
2439 2806
             // get next token
2440 2807
             $token = $this->_if_header_lexer($str, $pos);
2441 2808
 
2442 2809
             // check for URI
2443
-            if ($token[0] == "URI") {
2810
+            if ($token[0] == "URI")
2811
+            {
2444 2812
                 $uri   = $token[1]; // remember URI
2445 2813
                 $token = $this->_if_header_lexer($str, $pos); // get next token
2446
-            } else {
2814
+            }
2815
+            else
2816
+            {
2447 2817
                 $uri = "";
2448 2818
             }
2449 2819
 
2450 2820
             // sanity check
2451
-            if ($token[0] != "CHAR" || $token[1] != "(") {
2821
+            if ($token[0] != "CHAR" || $token[1] != "(")
2822
+            {
2452 2823
                 return false;
2453 2824
             }
2454 2825
 
2455 2826
             $list  = array();
2456 2827
             $level = 1;
2457 2828
             $not   = "";
2458
-            while ($level) {
2829
+            while ($level)
2830
+            {
2459 2831
                 $token = $this->_if_header_lexer($str, $pos);
2460
-                if ($token[0] == "NOT") {
2832
+                if ($token[0] == "NOT")
2833
+                {
2461 2834
                     $not = "!";
2462 2835
                     continue;
2463 2836
                 }
2464
-                switch ($token[0]) {
2837
+                switch ($token[0])
2838
+                {
2465 2839
                 case "CHAR":
2466
-                    switch ($token[1]) {
2840
+                    switch ($token[1])
2841
+                    {
2467 2842
                     case "(":
2468 2843
                         $level++;
2469 2844
                         break;
@@ -2493,9 +2868,12 @@  discard block
 block discarded – undo
2493 2868
                 $not = "";
2494 2869
             }
2495 2870
 
2496
-            if (@is_array($uris[$uri])) {
2871
+            if (@is_array($uris[$uri]))
2872
+            {
2497 2873
                 $uris[$uri] = array_merge($uris[$uri], $list);
2498
-            } else {
2874
+            }
2875
+            else
2876
+            {
2499 2877
                 $uris[$uri] = $list;
2500 2878
             }
2501 2879
         }
@@ -2514,27 +2892,34 @@  discard block
 block discarded – undo
2514 2892
      */
2515 2893
     function _check_if_header_conditions()
2516 2894
     {
2517
-        if (isset($this->_SERVER["HTTP_IF"])) {
2895
+        if (isset($this->_SERVER["HTTP_IF"]))
2896
+        {
2518 2897
             $this->_if_header_uris =
2519 2898
                 $this->_if_header_parser($this->_SERVER["HTTP_IF"]);
2520 2899
 
2521
-            foreach ($this->_if_header_uris as $uri => $conditions) {
2522
-                if ($uri == "") {
2900
+            foreach ($this->_if_header_uris as $uri => $conditions)
2901
+            {
2902
+                if ($uri == "")
2903
+                {
2523 2904
                     $uri = $this->uri;
2524 2905
                 }
2525 2906
                 // all must match
2526 2907
                 $state = true;
2527
-                foreach ($conditions as $condition) {
2908
+                foreach ($conditions as $condition)
2909
+                {
2528 2910
                     // lock tokens may be free form (RFC2518 6.3)
2529 2911
                     // but if opaquelocktokens are used (RFC2518 6.4)
2530 2912
                     // we have to check the format (litmus tests this)
2531
-                    if (!strncmp($condition, "<opaquelocktoken:", strlen("<opaquelocktoken"))) {
2532
-                        if (!preg_match('/^<opaquelocktoken:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}>$/', $condition)) {
2913
+                    if (!strncmp($condition, "<opaquelocktoken:", strlen("<opaquelocktoken")))
2914
+                    {
2915
+                        if (!preg_match('/^<opaquelocktoken:[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}>$/', $condition))
2916
+                        {
2533 2917
                             $this->http_status("423 Locked");
2534 2918
                             return false;
2535 2919
                         }
2536 2920
                     }
2537
-                    if (!$this->_check_uri_condition($uri, $condition)) {
2921
+                    if (!$this->_check_uri_condition($uri, $condition))
2922
+                    {
2538 2923
                         $this->http_status("412 Precondition failed");
2539 2924
                         $state = false;
2540 2925
                         break;
@@ -2542,7 +2927,8 @@  discard block
 block discarded – undo
2542 2927
                 }
2543 2928
 
2544 2929
                 // any match is ok
2545
-                if ($state == true) {
2930
+                if ($state == true)
2931
+                {
2546 2932
                     return true;
2547 2933
                 }
2548 2934
             }
@@ -2569,7 +2955,8 @@  discard block
 block discarded – undo
2569 2955
 
2570 2956
         // a lock token can never be from the DAV: scheme
2571 2957
         // litmus uses DAV:no-lock in some tests
2572
-        if (!strncmp("<DAV:", $condition, 5)) {
2958
+        if (!strncmp("<DAV:", $condition, 5))
2959
+        {
2573 2960
             return false;
2574 2961
         }
2575 2962
 
@@ -2586,16 +2973,21 @@  discard block
 block discarded – undo
2586 2973
     function _check_lock_status($path, $exclusive_only = false)
2587 2974
     {
2588 2975
         // FIXME depth -> ignored for now
2589
-        if (method_exists($this, "checkLock")) {
2976
+        if (method_exists($this, "checkLock"))
2977
+        {
2590 2978
             // is locked?
2591 2979
             $lock = $this->checkLock($path);
2592 2980
 
2593 2981
             // ... and lock is not owned?
2594
-            if (is_array($lock) && count($lock)) {
2982
+            if (is_array($lock) && count($lock))
2983
+            {
2595 2984
                 // FIXME doesn't check uri restrictions yet
2596
-                if (!isset($this->_SERVER["HTTP_IF"]) || !strstr($this->_SERVER["HTTP_IF"], $lock["token"])) {
2985
+                if (!isset($this->_SERVER["HTTP_IF"]) || !strstr($this->_SERVER["HTTP_IF"], $lock["token"]))
2986
+                {
2597 2987
                     if (!$exclusive_only || ($lock["scope"] !== "shared"))
2598
-                        return false;
2988
+                    {
2989
+                                            return false;
2990
+                    }
2599 2991
                 }
2600 2992
             }
2601 2993
         }
@@ -2615,7 +3007,8 @@  discard block
 block discarded – undo
2615 3007
     function lockdiscovery($path)
2616 3008
     {
2617 3009
         // no lock support without checklock() method
2618
-        if (!method_exists($this, "checklock")) {
3010
+        if (!method_exists($this, "checklock"))
3011
+        {
2619 3012
             return "";
2620 3013
         }
2621 3014
 
@@ -2626,13 +3019,19 @@  discard block
 block discarded – undo
2626 3019
         $lock = $this->checklock($path);
2627 3020
 
2628 3021
         // generate <activelock> block for returned data
2629
-        if (is_array($lock) && count($lock)) {
3022
+        if (is_array($lock) && count($lock))
3023
+        {
2630 3024
             // check for 'timeout' or 'expires'
2631
-            if (!empty($lock["expires"])) {
3025
+            if (!empty($lock["expires"]))
3026
+            {
2632 3027
                 $timeout = "Second-".($lock["expires"] - time());
2633
-            } else if (!empty($lock["timeout"])) {
3028
+            }
3029
+            else if (!empty($lock["timeout"]))
3030
+            {
2634 3031
                 $timeout = "Second-$lock[timeout]";
2635
-            } else {
3032
+            }
3033
+            else
3034
+            {
2636 3035
                 $timeout = "Infinite";
2637 3036
             }
2638 3037
 
@@ -2679,7 +3078,8 @@  discard block
 block discarded – undo
2679 3078
     function http_status($status)
2680 3079
     {
2681 3080
         // simplified success case
2682
-        if ($status === true) {
3081
+        if ($status === true)
3082
+        {
2683 3083
             $status = "200 OK";
2684 3084
         }
2685 3085
 
@@ -2764,18 +3164,24 @@  discard block
 block discarded – undo
2764 3164
      * @return string
2765 3165
      */
2766 3166
 	function _hierarchical_prop_encode(array $props, $ns, &$ns_defs, array &$ns_hash)
2767
-    {
3167
+	{
2768 3168
     	$ret = '';
2769 3169
 
2770 3170
     	//error_log(__METHOD__.'('.array2string($props).')');
2771
-    	if (isset($props['name'])) $props = array($props);
3171
+    	if (isset($props['name']))
3172
+    	{
3173
+    		$props = array($props);
3174
+    	}
2772 3175
 
2773 3176
     	foreach($props as $prop)
2774
-		{
2775
-	    	if (!isset($ns_hash[$prop['ns']])) // unknown namespace
3177
+    	{
3178
+	    	if (!isset($ns_hash[$prop['ns']]))
3179
+	    	{
3180
+	    		// unknown namespace
2776 3181
 	    	{
2777 3182
 		    	// register namespace
2778 3183
 		    	$ns_name = 'ns'.(count($ns_hash) + 1);
3184
+	    	}
2779 3185
 		    	$ns_hash[$prop['ns']] = $ns_name;
2780 3186
 		    	$ns_defs .= ' xmlns:'.$ns_name.'="'.$prop['ns'].'"';
2781 3187
 	    	}
@@ -2793,7 +3199,7 @@  discard block
 block discarded – undo
2793 3199
 			    	$vals = '';
2794 3200
 
2795 3201
 			    	foreach($subprop as $attr => $val)
2796
-					{
3202
+			    	{
2797 3203
 				    	$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8').'"';
2798 3204
 					}
2799 3205
 
@@ -2810,9 +3216,11 @@  discard block
 block discarded – undo
2810 3216
 		    	else
2811 3217
 		    	{
2812 3218
 			    	if(isset($prop['raw']))
2813
-					{
3219
+			    	{
2814 3220
 						$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
2815
-					} else {
3221
+					}
3222
+					else
3223
+					{
2816 3224
 						$val = $this->_prop_encode(htmlspecialchars($prop['val'], ENT_NOQUOTES, 'utf-8'));
2817 3225
 						// for href properties we need (minimalistic) urlencoding, eg. space
2818 3226
 						if ($prop['name'] == 'href')
@@ -2843,7 +3251,8 @@  discard block
 block discarded – undo
2843 3251
 		//error_log( __METHOD__."\n" .print_r($text,true));
2844 3252
 		//error_log("prop-encode:" . print_r($this->_prop_encoding,true));
2845 3253
 
2846
-		switch (strtolower($this->_prop_encoding)) {
3254
+		switch (strtolower($this->_prop_encoding))
3255
+		{
2847 3256
 			case "utf-8":
2848 3257
        			//error_log( __METHOD__."allready encoded\n" .print_r($text,true));
2849 3258
 				return $text;
@@ -2865,7 +3274,8 @@  discard block
 block discarded – undo
2865 3274
     public static function _slashify($path)
2866 3275
     {
2867 3276
 		//error_log(__METHOD__." called with $path");
2868
-		if ($path[self::bytes($path)-1] != '/') {
3277
+		if ($path[self::bytes($path)-1] != '/')
3278
+		{
2869 3279
 			//error_log(__METHOD__." added slash at the end of path");
2870 3280
 			$path = $path."/";
2871 3281
 		}
@@ -2881,7 +3291,8 @@  discard block
 block discarded – undo
2881 3291
     public static function _unslashify($path)
2882 3292
     {
2883 3293
         //error_log(__METHOD__." called with $path");
2884
-        if ($path[self::bytes($path)-1] == '/') {
3294
+        if ($path[self::bytes($path)-1] == '/')
3295
+        {
2885 3296
             $path = substr($path, 0, -1);
2886 3297
 			//error_log(__METHOD__." removed slash at the end of path");
2887 3298
         }
@@ -2899,9 +3310,12 @@  discard block
 block discarded – undo
2899 3310
     {
2900 3311
         //error_log("merge called :\n$parent \n$child\n" . function_backtrace());
2901 3312
         //error_log("merge :\n".print_r($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)true));
2902
-        if ($child{0} == '/') {
3313
+        if ($child{0} == '/')
3314
+        {
2903 3315
             return self::_unslashify($parent).$child;
2904
-        } else {
3316
+        }
3317
+        else
3318
+        {
2905 3319
             return self::_slashify($parent).$child;
2906 3320
         }
2907 3321
     }
Please login to merge, or discard this patch.
Spacing   +143 added lines, -145 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();
@@ -683,21 +683,21 @@  discard block
 block discarded – undo
683 683
 			$options['other'] = $propinfo->other;
684 684
 
685 685
         // call user handler
686
-        if (!($retval =$this->$handler($options, $files))) {
686
+        if (!($retval = $this->$handler($options, $files))) {
687 687
             $files = array("files" => array());
688 688
             if (method_exists($this, "checkLock")) {
689 689
                 // is locked?
690 690
                 $lock = $this->checkLock($this->path);
691 691
 
692 692
                 if (is_array($lock) && count($lock)) {
693
-                    $created          = isset($lock['created'])  ? $lock['created']  : time();
693
+                    $created          = isset($lock['created']) ? $lock['created'] : time();
694 694
                     $modified         = isset($lock['modified']) ? $lock['modified'] : time();
695 695
                     $files['files'][] = array("path"  => self::_slashify($this->path),
696
-                                              "props" => array($this->mkprop("displayname",      $this->path),
697
-                                                               $this->mkprop("creationdate",     $created),
698
-                                                               $this->mkprop("getlastmodified",  $modified),
699
-                                                               $this->mkprop("resourcetype",     ""),
700
-                                                               $this->mkprop("getcontenttype",   ""),
696
+                                              "props" => array($this->mkprop("displayname", $this->path),
697
+                                                               $this->mkprop("creationdate", $created),
698
+                                                               $this->mkprop("getlastmodified", $modified),
699
+                                                               $this->mkprop("resourcetype", ""),
700
+                                                               $this->mkprop("getcontenttype", ""),
701 701
                                                                $this->mkprop("getcontentlength", 0))
702 702
                                               );
703 703
                 }
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
 			header('Content-Type: text/html');
721 721
 			echo "<html><head><title>Error $retval</title></head>\n";
722 722
 			echo "<body><h1>$retval</h1>\n";
723
-			switch (substr($retval, 0 ,3))
723
+			switch (substr($retval, 0, 3))
724 724
 			{
725 725
 				case '501': // Not Implemented
726 726
 					echo "The requested feature is not (yet) supported by this server.\n";
@@ -728,19 +728,19 @@  discard block
 block discarded – undo
728 728
 				default:
729 729
 					echo "The request could not be handled by this server.\n";
730 730
 			}
731
-			echo '(URI ' . $this->_SERVER['REQUEST_URI'] . ")<br>\n<br>\n";
731
+			echo '(URI '.$this->_SERVER['REQUEST_URI'].")<br>\n<br>\n";
732 732
 			echo "</body></html>\n";
733 733
 			return;
734 734
 		}
735 735
 		// dav header
736
-        $dav = array(1);        // assume we are always dav class 1 compliant
736
+        $dav = array(1); // assume we are always dav class 1 compliant
737 737
         $allow = false;
738 738
 
739 739
         // allow extending class to modify DAV
740
-		if (method_exists($this,'OPTIONS')) {
741
-			$this->OPTIONS($this->path,$dav,$allow);
740
+		if (method_exists($this, 'OPTIONS')) {
741
+			$this->OPTIONS($this->path, $dav, $allow);
742 742
 		}
743
-        header("DAV: "  .join(", ", $dav));
743
+        header("DAV: ".join(", ", $dav));
744 744
         header('Content-Type: text/xml; charset="utf-8"');
745 745
 
746 746
         // add Vary and Preference-Applied header for Prefer: return=minimal
@@ -760,12 +760,11 @@  discard block
 block discarded – undo
760 760
         if (isset($files['sync-token']))
761 761
         {
762 762
             echo ($this->crrnd ? " <" : " <D:")."sync-token>".
763
-            	htmlspecialchars(!is_callable($files['sync-token']) ? $files['sync-token'] :
764
-            		call_user_func_array($files['sync-token'], (array)$files['sync-token-params'])).
763
+            	htmlspecialchars(!is_callable($files['sync-token']) ? $files['sync-token'] : call_user_func_array($files['sync-token'], (array)$files['sync-token-params'])).
765 764
             	($this->crrnd ? "</" : "</D:")."sync-token>\n";
766 765
         }
767 766
 
768
-        echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
767
+        echo '</'.($this->crrnd ? '' : 'D:')."multistatus>\n";
769 768
     }
770 769
 
771 770
     /**
@@ -774,7 +773,7 @@  discard block
 block discarded – undo
774 773
      * @param array|Iterator $files
775 774
      * @param array|string $props
776 775
      */
777
-    function multistatus_responses(&$files, $props, $initial_ns_hash=null, $initial_ns_defs=null)
776
+    function multistatus_responses(&$files, $props, $initial_ns_hash = null, $initial_ns_defs = null)
778 777
     {
779 778
     	if (!isset($initial_ns_hash)) $initial_ns_hash = array('DAV:' => 'D');
780 779
     	if (!isset($initial_ns_defs)) $initial_ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';
@@ -787,7 +786,7 @@  discard block
 block discarded – undo
787 786
         }
788 787
         // support for "Prefer: depth-noroot" header on PROPFIND
789 788
         $skip_root = $this->_SERVER['REQUEST_METHOD'] == 'PROPFIND' &&
790
-        	!isset($initial_ns_hash) &&	// multistatus_response calls itself, do NOT apply skip in that case
789
+        	!isset($initial_ns_hash) && // multistatus_response calls itself, do NOT apply skip in that case
791 790
         	isset($this->_SERVER['HTTP_PREFER']) && in_array('depth-noroot', preg_split('/, ?/', $this->_SERVER['HTTP_PREFER']));
792 791
 
793 792
         // now we loop over all returned file entries
@@ -816,9 +815,8 @@  discard block
 block discarded – undo
816 815
 
817 816
 	            	// this can happen if we have allprop and prop in one propfind:
818 817
 	            	// <allprop /><prop><blah /></prop>, eg. blah is not automatic returned by allprop
819
-	                switch(is_array($props) ? $props[0] : $props) {
820
-	                case "all":
821
-	                    // nothing to remove
818
+	                switch (is_array($props) ? $props[0] : $props) {
819
+	                case "all" : // nothing to remove
822 820
 	                    break;
823 821
 
824 822
 	                case "names":
@@ -832,7 +830,7 @@  discard block
 block discarded – undo
832 830
 
833 831
 	                    // search property name in requested properties
834 832
 	                    foreach ((array)$props as $reqprop) {
835
-	                        if (   $reqprop["name"]  == $prop["name"]
833
+	                        if ($reqprop["name"] == $prop["name"]
836 834
 	                               && @$reqprop["xmlns"] == $prop["ns"]) {
837 835
 	                            $found = true;
838 836
 	                            break;
@@ -841,7 +839,7 @@  discard block
 block discarded – undo
841 839
 
842 840
 	                    // unset property and continue with next one if not found/requested
843 841
 	                    if (!$found) {
844
-	                        $prop="";
842
+	                        $prop = "";
845 843
 	                        continue(2);
846 844
 	                    }
847 845
 	                    break;
@@ -863,7 +861,7 @@  discard block
 block discarded – undo
863 861
 	            // but for which no values where returned by the user handler
864 862
 	            if (is_array($props)) {
865 863
 	                foreach ($props as $reqprop) {
866
-	                    if (!is_array($reqprop) || $reqprop['name']=="") continue; // skip empty entries, or 'all' if <allprop /> used together with <prop>
864
+	                    if (!is_array($reqprop) || $reqprop['name'] == "") continue; // skip empty entries, or 'all' if <allprop /> used together with <prop>
867 865
 
868 866
 	                    $found = false;
869 867
 
@@ -877,7 +875,7 @@  discard block
 block discarded – undo
877 875
 	                    }
878 876
 
879 877
 	                    if (!$found) {
880
-	                        if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") {
878
+	                        if ($reqprop["xmlns"] === "DAV:" && $reqprop["name"] === "lockdiscovery") {
881 879
 	                            // lockdiscovery is handled by the base class
882 880
 	                            $file["props"][]
883 881
 	                                = $this->mkprop("DAV:",
@@ -904,7 +902,7 @@  discard block
 block discarded – undo
904 902
             // ignore empty or incomplete entries
905 903
             if (!is_array($file) || empty($file) || !isset($file["path"])) continue;
906 904
             $path = $file['path'];
907
-            if (!is_string($path) || $path==="") continue;
905
+            if (!is_string($path) || $path === "") continue;
908 906
 
909 907
             if ($this->crrnd)
910 908
             {
@@ -934,8 +932,8 @@  discard block
 block discarded – undo
934 932
 
935 933
             // report all found properties and their values (if any)
936 934
             if (isset($file["props"]) && is_array($file["props"])) {
937
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
938
-                echo '    <'.($this->crrnd?'':'D:')."prop>\n";
935
+                echo '   <'.($this->crrnd ? '' : 'D:')."propstat>\n";
936
+                echo '    <'.($this->crrnd ? '' : 'D:')."prop>\n";
939 937
 
940 938
                 foreach ($file["props"] as &$prop) {
941 939
 
@@ -944,8 +942,8 @@  discard block
 block discarded – undo
944 942
 
945 943
                     if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) {
946 944
                         // empty properties (cannot use empty() for check as "0" is a legal value here)
947
-                        if ($prop["ns"]=="DAV:") {
948
-                            echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
945
+                        if ($prop["ns"] == "DAV:") {
946
+                            echo '     <'.($this->crrnd ? '' : 'D:')."$prop[name]/>\n";
949 947
                         } else if (!empty($prop["ns"])) {
950 948
                             echo "     <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
951 949
                         } else {
@@ -953,7 +951,7 @@  discard block
 block discarded – undo
953 951
                         }
954 952
                     }
955 953
                     // multiple level of responses required for expand-property reports
956
-                    elseif(isset($prop['props']) && is_array($prop['val']))
954
+                    elseif (isset($prop['props']) && is_array($prop['val']))
957 955
                     {
958 956
                         if ($prop['ns'] && !isset($ns_hash[$prop['ns']])) {
959 957
                             $ns_name = "ns".(count($ns_hash) + 1);
@@ -966,33 +964,33 @@  discard block
 block discarded – undo
966 964
                         // some WebDAV properties need special treatment
967 965
                         switch ($prop["name"]) {
968 966
                         case "creationdate":
969
-                            echo '     <'.($this->crrnd?'':'D:')."creationdate ns0:dt=\"dateTime.tz\">"
967
+                            echo '     <'.($this->crrnd ? '' : 'D:')."creationdate ns0:dt=\"dateTime.tz\">"
970 968
                                 . gmdate("Y-m-d\\TH:i:s\\Z", $prop['val'])
971
-                                . '</'.($this->crrnd?'':'D:')."creationdate>\n";
969
+                                . '</'.($this->crrnd ? '' : 'D:')."creationdate>\n";
972 970
                             break;
973 971
                         case "getlastmodified":
974
-                            echo '     <'.($this->crrnd?'':'D:')."getlastmodified ns0:dt=\"dateTime.rfc1123\">"
972
+                            echo '     <'.($this->crrnd ? '' : 'D:')."getlastmodified ns0:dt=\"dateTime.rfc1123\">"
975 973
                                 . gmdate("D, d M Y H:i:s ", $prop['val'])
976
-                                . "GMT</".($this->crrnd?'':'D:')."getlastmodified>\n";
974
+                                . "GMT</".($this->crrnd ? '' : 'D:')."getlastmodified>\n";
977 975
                             break;
978 976
                         case "supportedlock":
979
-                            echo '     <'.($this->crrnd?'':'D:')."supportedlock>$prop[val]</".($this->crrnd?'':'D:')."supportedlock>\n";
977
+                            echo '     <'.($this->crrnd ? '' : 'D:')."supportedlock>$prop[val]</".($this->crrnd ? '' : 'D:')."supportedlock>\n";
980 978
                             break;
981 979
                         case "lockdiscovery":
982
-                            echo '     <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
980
+                            echo '     <'.($this->crrnd ? '' : 'D:')."lockdiscovery>\n";
983 981
                             echo $prop["val"];
984
-                            echo '     </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
982
+                            echo '     </'.($this->crrnd ? '' : 'D:')."lockdiscovery>\n";
985 983
                             break;
986 984
                         // the following are non-standard Microsoft extensions to the DAV namespace
987 985
                         case "lastaccessed":
988
-                            echo '     <'.($this->crrnd?'':'D:')."lastaccessed ns0:dt=\"dateTime.rfc1123\">"
986
+                            echo '     <'.($this->crrnd ? '' : 'D:')."lastaccessed ns0:dt=\"dateTime.rfc1123\">"
989 987
                                 . gmdate("D, d M Y H:i:s ", $prop['val'])
990
-                                . 'GMT</'.($this->crrnd?'':'D:')."lastaccessed>\n";
988
+                                . 'GMT</'.($this->crrnd ? '' : 'D:')."lastaccessed>\n";
991 989
                             break;
992 990
                         case "ishidden":
993
-                            echo '     <'.($this->crrnd?'':'D:')."ishidden>"
991
+                            echo '     <'.($this->crrnd ? '' : 'D:')."ishidden>"
994 992
                                 . is_string($prop['val']) ? $prop['val'] : ($prop['val'] ? 'true' : 'false')
995
-                                . '</'.($this->crrnd?'':'D:')."</D:ishidden>\n";
993
+                                . '</'.($this->crrnd ? '' : 'D:')."</D:ishidden>\n";
996 994
                             break;
997 995
                         default:
998 996
                         	$ns_defs = '';
@@ -1005,8 +1003,8 @@  discard block
 block discarded – undo
1005 1003
                             } else {
1006 1004
 	                    		$val = $this->_prop_encode(htmlspecialchars($prop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8'));
1007 1005
                             }
1008
-	                        echo '     <'.($this->crrnd?'':'D:')."$prop[name]$ns_defs>$val".
1009
-	                        	'</'.($this->crrnd?'':'D:')."$prop[name]>\n";
1006
+	                        echo '     <'.($this->crrnd ? '' : 'D:')."$prop[name]$ns_defs>$val".
1007
+	                        	'</'.($this->crrnd ? '' : 'D:')."$prop[name]>\n";
1010 1008
                             break;
1011 1009
                         }
1012 1010
                     } else {
@@ -1017,7 +1015,7 @@  discard block
 block discarded – undo
1017 1015
                                 $ns_hash[$prop['ns']] = $ns_name;
1018 1016
                     		}
1019 1017
                   			$vals = $extra_ns = '';
1020
-                    		foreach($prop['val'] as $subprop)
1018
+                    		foreach ($prop['val'] as $subprop)
1021 1019
                     		{
1022 1020
                     			if ($subprop['ns'] && $subprop['ns'] != 'DAV:') {
1023 1021
 		                    		// register property namespace if not known yet
@@ -1027,7 +1025,7 @@  discard block
 block discarded – undo
1027 1025
 		                    		} else {
1028 1026
 			                    		$ns_name = $ns_hash[$subprop['ns']];
1029 1027
 		                    		}
1030
-		                    		if (strchr($extra_ns,$extra=' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) {
1028
+		                    		if (strchr($extra_ns, $extra = ' xmlns:'.$ns_name.'="'.$subprop['ns'].'"') === false) {
1031 1029
 			                    		$extra_ns .= $extra;
1032 1030
 		                    		}
1033 1031
 		                    		$ns_name .= ':';
@@ -1047,7 +1045,7 @@  discard block
 block discarded – undo
1047 1045
 	                    			}
1048 1046
 	                    			else	// val contains only attributes, no value
1049 1047
 	                    			{
1050
-			                    		foreach($subprop['val'] as $attr => $val)
1048
+			                    		foreach ($subprop['val'] as $attr => $val)
1051 1049
 										{
1052 1050
 				                    		$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8').'"';
1053 1051
 										}
@@ -1060,7 +1058,7 @@  discard block
 block discarded – undo
1060 1058
 	                    			if (isset($subprop['raw'])) {
1061 1059
 	                    				$vals .= '<![CDATA['.$subprop['val'].']]>';
1062 1060
 	                    			} else {
1063
-	                    				if($subprop['name'] == 'href') $subprop['val'] = $this->_urlencode($subprop['val']);
1061
+	                    				if ($subprop['name'] == 'href') $subprop['val'] = $this->_urlencode($subprop['val']);
1064 1062
 		                    			$vals .= htmlspecialchars($subprop['val'], ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8');
1065 1063
 	                    			}
1066 1064
 	                    			$vals .= "</$ns_name$subprop[name]>";
@@ -1079,10 +1077,10 @@  discard block
 block discarded – undo
1079 1077
 	                        if ($prop['ns']) {
1080 1078
 		                        if ($this->crrnd) {
1081 1079
 			                        echo "     <$prop[name] xmlns=".'"'.$prop["ns"].'">'
1082
-									. $val . "</$prop[name]>\n";
1080
+									. $val."</$prop[name]>\n";
1083 1081
 		                        } else {
1084
-			                        echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]>"
1085
-									. $val . '</'.$ns_hash[$prop['ns']].":$prop[name]>\n";
1082
+			                        echo "     <".$ns_hash[$prop["ns"]].":$prop[name]>"
1083
+									. $val.'</'.$ns_hash[$prop['ns']].":$prop[name]>\n";
1086 1084
 		                        }
1087 1085
 	                        } else {
1088 1086
 		                        echo "     <$prop[name] xmlns=\"\">$val</$prop[name]>\n";
@@ -1107,16 +1105,16 @@  discard block
 block discarded – undo
1107 1105
 
1108 1106
             // now report all properties requested but not found
1109 1107
             if (isset($file["noprops"])) {
1110
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1111
-                echo '    <'.($this->crrnd?'':'D:')."prop>\n";
1108
+                echo '   <'.($this->crrnd ? '' : 'D:')."propstat>\n";
1109
+                echo '    <'.($this->crrnd ? '' : 'D:')."prop>\n";
1112 1110
 
1113 1111
                 foreach ($file["noprops"] as &$prop) {
1114 1112
                     if ($prop["ns"] == "DAV:") {
1115
-                        echo '     <'.($this->crrnd?'':'D:')."$prop[name]/>\n";
1113
+                        echo '     <'.($this->crrnd ? '' : 'D:')."$prop[name]/>\n";
1116 1114
                     } else if ($prop["ns"] == "") {
1117 1115
                         echo "     <$prop[name] xmlns=\"\"/>\n";
1118 1116
                     } else {
1119
-                        echo "     <" . $ns_hash[$prop["ns"]] . ":$prop[name]/>\n";
1117
+                        echo "     <".$ns_hash[$prop["ns"]].":$prop[name]/>\n";
1120 1118
                     }
1121 1119
                 }
1122 1120
 
@@ -1147,7 +1145,7 @@  discard block
 block discarded – undo
1147 1145
                 }
1148 1146
             }
1149 1147
 
1150
-            echo ' </'.($this->crrnd?'':'D:')."response>\n";
1148
+            echo ' </'.($this->crrnd ? '' : 'D:')."response>\n";
1151 1149
         }
1152 1150
     }
1153 1151
 
@@ -1187,24 +1185,24 @@  discard block
 block discarded – undo
1187 1185
             echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
1188 1186
 
1189 1187
             echo "<D:multistatus xmlns:D=\"DAV:\">\n";
1190
-            echo ' <'.($this->crrnd?'':'D:')."response>\n";
1191
-            echo '  <'.($this->crrnd?'':'D:')."href>".$this->_urlencode($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)).'</'.($this->crrnd?'':'D:')."href>\n";
1188
+            echo ' <'.($this->crrnd ? '' : 'D:')."response>\n";
1189
+            echo '  <'.($this->crrnd ? '' : 'D:')."href>".$this->_urlencode($this->_mergePaths($this->_SERVER["SCRIPT_NAME"], $this->path)).'</'.($this->crrnd ? '' : 'D:')."href>\n";
1192 1190
 
1193 1191
             foreach ($options["props"] as $prop) {
1194
-                echo '   <'.($this->crrnd?'':'D:')."propstat>\n";
1195
-                echo '    <'.($this->crrnd?'':'D:')."prop><$prop[name] xmlns=\"$prop[ns]\"/></".($this->crrnd?'':'D:')."prop>\n";
1196
-                echo '    <'.($this->crrnd?'':'D:')."status>HTTP/1.1 $prop[status]</".($this->crrnd?'':'D:')."status>\n";
1197
-                echo '   </'.($this->crrnd?'':'D:')."propstat>\n";
1192
+                echo '   <'.($this->crrnd ? '' : 'D:')."propstat>\n";
1193
+                echo '    <'.($this->crrnd ? '' : 'D:')."prop><$prop[name] xmlns=\"$prop[ns]\"/></".($this->crrnd ? '' : 'D:')."prop>\n";
1194
+                echo '    <'.($this->crrnd ? '' : 'D:')."status>HTTP/1.1 $prop[status]</".($this->crrnd ? '' : 'D:')."status>\n";
1195
+                echo '   </'.($this->crrnd ? '' : 'D:')."propstat>\n";
1198 1196
             }
1199 1197
 
1200 1198
             if ($responsedescr) {
1201
-                echo '  <'.($this->crrnd?'':'D:')."responsedescription>".
1199
+                echo '  <'.($this->crrnd ? '' : 'D:')."responsedescription>".
1202 1200
                     $this->_prop_encode(htmlspecialchars($responsedescr, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8')).
1203
-                    '</'.($this->crrnd?'':'D:')."responsedescription>\n";
1201
+                    '</'.($this->crrnd ? '' : 'D:')."responsedescription>\n";
1204 1202
             }
1205 1203
 
1206
-            echo ' </'.($this->crrnd?'':'D:')."response>\n";
1207
-            echo '</'.($this->crrnd?'':'D:')."multistatus>\n";
1204
+            echo ' </'.($this->crrnd ? '' : 'D:')."response>\n";
1205
+            echo '</'.($this->crrnd ? '' : 'D:')."multistatus>\n";
1208 1206
         } else {
1209 1207
             $this->http_status("423 Locked");
1210 1208
         }
@@ -1244,12 +1242,12 @@  discard block
 block discarded – undo
1244 1242
 	 * @param boolean $set =null
1245 1243
 	 * @return boolean true if we use compression, false otherwise
1246 1244
 	 */
1247
-	public static function use_compression($set=null)
1245
+	public static function use_compression($set = null)
1248 1246
 	{
1249 1247
 		static $compression = null;
1250 1248
 		if (isset($set))
1251 1249
 		{
1252
-			ini_set('zlib.output_compression', $compression=(boolean)$set);
1250
+			ini_set('zlib.output_compression', $compression = (boolean)$set);
1253 1251
 		}
1254 1252
 		elseif (!isset($compression))
1255 1253
 		{
@@ -1285,7 +1283,7 @@  discard block
 block discarded – undo
1285 1283
                 // switching off zlib.output_compression for everything but text files,
1286 1284
                 // as the double compression of zip files makes problems eg. with lighttpd
1287 1285
                 // and anyway little sense with with other content like pictures
1288
-                if (substr($options['mimetype'],0,5) != 'text/')
1286
+                if (substr($options['mimetype'], 0, 5) != 'text/')
1289 1287
                 {
1290 1288
 					self::use_compression(false);
1291 1289
                 }
@@ -1302,7 +1300,7 @@  discard block
 block discarded – undo
1302 1300
 
1303 1301
                 if (isset($options['stream'])) {
1304 1302
                     // GET handler returned a stream
1305
-                    if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET))) {
1303
+                    if (!empty($options['ranges']) && (0 === fseek($options['stream'], 0, SEEK_SET))) {
1306 1304
                         // partial request and stream is seekable
1307 1305
 
1308 1306
                         if (count($options['ranges']) === 1) {
@@ -1316,7 +1314,7 @@  discard block
 block discarded – undo
1316 1314
                                 }
1317 1315
 
1318 1316
                                 if (!empty($range['end'])) {
1319
-                                    $size = $range['end']-$range['start']+1;
1317
+                                    $size = $range['end'] - $range['start'] + 1;
1320 1318
                                     $this->http_status($status = "206 Partial content");
1321 1319
                                     if (!self::use_compression()) header("Content-Length: $size");
1322 1320
                                     header("Content-Range: bytes $range[start]-$range[end]/"
@@ -1331,7 +1329,7 @@  discard block
 block discarded – undo
1331 1329
                                     if (isset($options['size'])) {
1332 1330
                                         if (!self::use_compression()) header("Content-Length: ".($options['size'] - $range['start']));
1333 1331
                                         header("Content-Range: bytes ".$range['start']."-".
1334
-											(isset($options['size']) ? $options['size']-1 : "")."/"
1332
+											(isset($options['size']) ? $options['size'] - 1 : "")."/"
1335 1333
 										   . (isset($options['size']) ? $options['size'] : "*"));
1336 1334
                                     }
1337 1335
                                     fpassthru($options['stream']);
@@ -1347,10 +1345,10 @@  discard block
 block discarded – undo
1347 1345
                                 // TODO what if size unknown? 500?
1348 1346
                                 if (isset($range['start'])) {
1349 1347
                                     $from = $range['start'];
1350
-                                    $to   = !empty($range['end']) ? $range['end'] : $options['size']-1;
1348
+                                    $to   = !empty($range['end']) ? $range['end'] : $options['size'] - 1;
1351 1349
                                 } else {
1352
-                                    $from = $options['size'] - $range['last']-1;
1353
-                                    $to   = $options['size'] -1;
1350
+                                    $from = $options['size'] - $range['last'] - 1;
1351
+                                    $to   = $options['size'] - 1;
1354 1352
                                 }
1355 1353
                                 $total = isset($options['size']) ? $options['size'] : "*";
1356 1354
                                 $size  = $to - $from + 1;
@@ -1416,7 +1414,7 @@  discard block
 block discarded – undo
1416 1414
                 foreach (explode(",", $matches[1]) as $range) {
1417 1415
                     // ranges are either from-to pairs or just end positions
1418 1416
                     list($start, $end) = explode("-", $range);
1419
-                    $options["ranges"][] = ($start==="")
1417
+                    $options["ranges"][] = ($start === "")
1420 1418
                         ? array("last"=>$end)
1421 1419
                         : array("start"=>$start, "end"=>$end);
1422 1420
                 }
@@ -1437,7 +1435,7 @@  discard block
 block discarded – undo
1437 1435
      * @param  int     end   byte position
1438 1436
      * @param  int     total resource byte size
1439 1437
      */
1440
-    function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false)
1438
+    function _multipart_byterange_header($mimetype = false, $from = false, $to = false, $total = false)
1441 1439
     {
1442 1440
         if ($mimetype === false) {
1443 1441
             if (!isset($this->multipart_separator)) {
@@ -1459,7 +1457,7 @@  discard block
 block discarded – undo
1459 1457
             // generate separator and header for next part
1460 1458
             echo "\n--{$this->multipart_separator}\n";
1461 1459
             echo "Content-type: $mimetype\n";
1462
-            echo "Content-range: $from-$to/". ($total === false ? "*" : $total);
1460
+            echo "Content-range: $from-$to/".($total === false ? "*" : $total);
1463 1461
             echo "\n\n";
1464 1462
         }
1465 1463
     }
@@ -1553,7 +1551,7 @@  discard block
 block discarded – undo
1553 1551
         }
1554 1552
 
1555 1553
         $options['stream'] = fopen('php://input', 'r');
1556
-    	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1554
+    	switch ($this->_SERVER['HTTP_CONTENT_ENCODING'])
1557 1555
     	{
1558 1556
     		case 'gzip':
1559 1557
     		case 'deflate':	//zlib
@@ -1566,11 +1564,11 @@  discard block
 block discarded – undo
1566 1564
 		if ($this->store_request)
1567 1565
 		{
1568 1566
 			$options['content'] = '';
1569
-			while(!feof($options['stream']))
1567
+			while (!feof($options['stream']))
1570 1568
 			{
1571
-				$options['content'] .= fread($options['stream'],8192);
1569
+				$options['content'] .= fread($options['stream'], 8192);
1572 1570
 			}
1573
-			$this->request =& $options['content'];
1571
+			$this->request = & $options['content'];
1574 1572
 			unset($options['stream']);
1575 1573
 		}
1576 1574
 
@@ -1583,7 +1581,7 @@  discard block
 block discarded – undo
1583 1581
 	        if (strncmp($key, 'HTTP_CONTENT', 11)) continue;
1584 1582
 	        switch ($key) {
1585 1583
 		        case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1586
-		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1584
+		        	switch ($this->_SERVER['HTTP_CONTENT_ENCODING'])
1587 1585
 		        	{
1588 1586
 		        		case 'gzip':
1589 1587
 		        		case 'deflate':	//zlib
@@ -1671,7 +1669,7 @@  discard block
 block discarded – undo
1671 1669
 		        if (!empty($options['ranges'])) {
1672 1670
 			        // TODO multipart support is missing (see also above)
1673 1671
 			        if (0 == fseek($stream, $range[0]['start'], SEEK_SET)) {
1674
-				        $length = $range[0]['end']-$range[0]['start']+1;
1672
+				        $length = $range[0]['end'] - $range[0]['start'] + 1;
1675 1673
 				        if (!fwrite($stream, fread($options['stream'], $length))) {
1676 1674
 					        $status = '403 Forbidden';
1677 1675
 				        }
@@ -1733,7 +1731,7 @@  discard block
 block discarded – undo
1733 1731
             }
1734 1732
 
1735 1733
             $options["stream"] = fopen("php://input", "r");
1736
-	    	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1734
+	    	switch ($this->_SERVER['HTTP_CONTENT_ENCODING'])
1737 1735
 	    	{
1738 1736
 	    		case 'gzip':
1739 1737
 	    		case 'deflate':	//zlib
@@ -1746,11 +1744,11 @@  discard block
 block discarded – undo
1746 1744
 			if ($this->store_request)
1747 1745
 			{
1748 1746
 				$options['content'] = '';
1749
-				while(!feof($options['stream']))
1747
+				while (!feof($options['stream']))
1750 1748
 				{
1751
-					$options['content'] .= fread($options['stream'],8192);
1749
+					$options['content'] .= fread($options['stream'], 8192);
1752 1750
 				}
1753
-				$this->request =& $options['content'];
1751
+				$this->request = & $options['content'];
1754 1752
 				unset($options['stream']);
1755 1753
 			}
1756 1754
 
@@ -1763,7 +1761,7 @@  discard block
 block discarded – undo
1763 1761
                 if (strncmp($key, "HTTP_CONTENT", 11)) continue;
1764 1762
                 switch ($key) {
1765 1763
                 case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
1766
-		        	switch($this->_SERVER['HTTP_CONTENT_ENCODING'])
1764
+		        	switch ($this->_SERVER['HTTP_CONTENT_ENCODING'])
1767 1765
 		        	{
1768 1766
 		        		case 'gzip':
1769 1767
 		        		case 'deflate':	//zlib
@@ -1849,7 +1847,7 @@  discard block
 block discarded – undo
1849 1847
                 if (!empty($options["ranges"])) {
1850 1848
                     // TODO multipart support is missing (see also above)
1851 1849
                     if (0 == fseek($stream, $options['ranges'][0]["start"], SEEK_SET)) {
1852
-                        $length = $options['ranges'][0]["end"] - $options['ranges'][0]["start"]+1;
1850
+                        $length = $options['ranges'][0]["end"] - $options['ranges'][0]["start"] + 1;
1853 1851
 
1854 1852
                         while (!feof($options['stream'])) {
1855 1853
                             if ($length <= 0) {
@@ -1909,7 +1907,7 @@  discard block
 block discarded – undo
1909 1907
         // check RFC 2518 Section 9.2, last paragraph
1910 1908
         if (isset($this->_SERVER["HTTP_DEPTH"])) {
1911 1909
             if ($this->_SERVER["HTTP_DEPTH"] != "infinity") {
1912
-				if (stripos($_SERVER['HTTP_USER_AGENT'],'webdrive') !== false)
1910
+				if (stripos($_SERVER['HTTP_USER_AGENT'], 'webdrive') !== false)
1913 1911
 				{
1914 1912
 					// pretend we didnt see it, as webdrive does not handle the depth parameter correctly while deleting collections
1915 1913
 				}
@@ -2058,8 +2056,8 @@  discard block
 block discarded – undo
2058 2056
                 if (is_numeric($options["timeout"])) {
2059 2057
                     // more than a million is considered an absolute timestamp
2060 2058
                     // less is more likely a relative value
2061
-                    if ($options["timeout"]>1000000) {
2062
-                        $timeout = "Second-".($options['timeout']-time());
2059
+                    if ($options["timeout"] > 1000000) {
2060
+                        $timeout = "Second-".($options['timeout'] - time());
2063 2061
                     } else {
2064 2062
                         $timeout = "Second-$options[timeout]";
2065 2063
                     }
@@ -2077,17 +2075,17 @@  discard block
 block discarded – undo
2077 2075
             header("Lock-Token: <$options[locktoken]>");
2078 2076
             echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2079 2077
             echo "<D:prop xmlns:D=\"DAV:\">\n";
2080
-            echo ' <'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2081
-            echo '  <'.($this->crrnd?'':'D:')."activelock>\n";
2082
-            echo '   <'.($this->crrnd?'':'D:')."lockscope><D:$options[scope]/></".($this->crrnd?'':'D:')."lockscope>\n";
2083
-            echo '   <'.($this->crrnd?'':'D:')."locktype><D:$options[type]/></".($this->crrnd?'':'D:')."locktype>\n";
2084
-            echo '   <'.($this->crrnd?'':'D:')."depth>$options[depth]</".($this->crrnd?'':'D:')."depth>\n";
2085
-            echo '   <'.($this->crrnd?'':'D:')."owner>$options[owner]</".($this->crrnd?'':'D:')."owner>\n";
2086
-            echo '   <'.($this->crrnd?'':'D:')."timeout>$timeout</".($this->crrnd?'':'D:')."timeout>\n";
2087
-            echo '   <'.($this->crrnd?'':'D:')."locktoken><D:href>$options[locktoken]</D:href></".($this->crrnd?'':'D:')."locktoken>\n";
2088
-            echo '  </'.($this->crrnd?'':'D:')."activelock>\n";
2089
-            echo ' </'.($this->crrnd?'':'D:')."lockdiscovery>\n";
2090
-            echo '</'.($this->crrnd?'':'D:')."prop>\n\n";
2078
+            echo ' <'.($this->crrnd ? '' : 'D:')."lockdiscovery>\n";
2079
+            echo '  <'.($this->crrnd ? '' : 'D:')."activelock>\n";
2080
+            echo '   <'.($this->crrnd ? '' : 'D:')."lockscope><D:$options[scope]/></".($this->crrnd ? '' : 'D:')."lockscope>\n";
2081
+            echo '   <'.($this->crrnd ? '' : 'D:')."locktype><D:$options[type]/></".($this->crrnd ? '' : 'D:')."locktype>\n";
2082
+            echo '   <'.($this->crrnd ? '' : 'D:')."depth>$options[depth]</".($this->crrnd ? '' : 'D:')."depth>\n";
2083
+            echo '   <'.($this->crrnd ? '' : 'D:')."owner>$options[owner]</".($this->crrnd ? '' : 'D:')."owner>\n";
2084
+            echo '   <'.($this->crrnd ? '' : 'D:')."timeout>$timeout</".($this->crrnd ? '' : 'D:')."timeout>\n";
2085
+            echo '   <'.($this->crrnd ? '' : 'D:')."locktoken><D:href>$options[locktoken]</D:href></".($this->crrnd ? '' : 'D:')."locktoken>\n";
2086
+            echo '  </'.($this->crrnd ? '' : 'D:')."activelock>\n";
2087
+            echo ' </'.($this->crrnd ? '' : 'D:')."lockdiscovery>\n";
2088
+            echo '</'.($this->crrnd ? '' : 'D:')."prop>\n\n";
2091 2089
         }
2092 2090
     }
2093 2091
 
@@ -2157,9 +2155,9 @@  discard block
 block discarded – undo
2157 2155
 	        $content .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
2158 2156
 	        $content .= "<D:error xmlns:D=\"DAV:\"> \n";
2159 2157
 	        foreach ($options['errors'] as $violation) {
2160
-	        	$content .= '<'.($this->crrnd?'':'D:')."$violation/>\n";
2158
+	        	$content .= '<'.($this->crrnd ? '' : 'D:')."$violation/>\n";
2161 2159
 	        }
2162
-	        $content .=  '</'.($this->crrnd?'':'D:')."error>\n";
2160
+	        $content .= '</'.($this->crrnd ? '' : 'D:')."error>\n";
2163 2161
         }
2164 2162
         if (!self::use_compression()) header("Content-Length: ".self::bytes($content));
2165 2163
         if ($content) echo $options['content'];
@@ -2191,7 +2189,7 @@  discard block
 block discarded – undo
2191 2189
             // TODO check url scheme, too
2192 2190
             $http_host = $url["host"];
2193 2191
             if (isset($url["port"]) && $url["port"] != 80)
2194
-                $http_host.= ":".$url["port"];
2192
+                $http_host .= ":".$url["port"];
2195 2193
         } else {
2196 2194
             // only path given, set host to self
2197 2195
             $http_host = $http_header_host;
@@ -2336,17 +2334,17 @@  discard block
 block discarded – undo
2336 2334
         }
2337 2335
 
2338 2336
         // fallback
2339
-        $uuid = md5(microtime().getmypid());    // this should be random enough for now
2337
+        $uuid = md5(microtime().getmypid()); // this should be random enough for now
2340 2338
 
2341 2339
         // set variant and version fields for 'true' random uuid
2342 2340
         $uuid{12} = "4";
2343
-        $n = 8 + (ord($uuid{16}) & 3);
2341
+        $n = 8 + (ord($uuid{16})&3);
2344 2342
         $hex = "0123456789abcdef";
2345 2343
         $uuid{16} = $hex{$n};
2346 2344
 
2347 2345
         // return formated uuid
2348
-        return substr($uuid,  0, 8)."-"
2349
-            .  substr($uuid,  8, 4)."-"
2346
+        return substr($uuid, 0, 8)."-"
2347
+            .  substr($uuid, 8, 4)."-"
2350 2348
             .  substr($uuid, 12, 4)."-"
2351 2349
             .  substr($uuid, 16, 4)."-"
2352 2350
             .  substr($uuid, 20);
@@ -2563,7 +2561,7 @@  discard block
 block discarded – undo
2563 2561
      */
2564 2562
     function _check_uri_condition($uri, $condition)
2565 2563
     {
2566
-		unset($uri);	// not used, but required by function signature
2564
+		unset($uri); // not used, but required by function signature
2567 2565
         // not really implemented here,
2568 2566
         // implementations must override
2569 2567
 
@@ -2639,7 +2637,7 @@  discard block
 block discarded – undo
2639 2637
             // genreate response block
2640 2638
             if ($this->crrnd)
2641 2639
             {
2642
-	            $activelocks.= "
2640
+	            $activelocks .= "
2643 2641
 		            <activelock>
2644 2642
 		            <lockscope><$lock[scope]/></lockscope>
2645 2643
 		            <locktype><$lock[type]/></locktype>
@@ -2652,7 +2650,7 @@  discard block
 block discarded – undo
2652 2650
             }
2653 2651
             else
2654 2652
             {
2655
-	            $activelocks.= "
2653
+	            $activelocks .= "
2656 2654
 		            <D:activelock>
2657 2655
 		            <D:lockscope><D:$lock[scope]/></D:lockscope>
2658 2656
 		            <D:locktype><D:$lock[type]/></D:locktype>
@@ -2705,18 +2703,18 @@  discard block
 block discarded – undo
2705 2703
     {
2706 2704
 		// cadaver (and probably all neon using agents) need a more complete url encoding
2707 2705
 		// otherwise special chars like "$,()'" in filenames do NOT work
2708
-		if (strpos($_SERVER['HTTP_USER_AGENT'],'neon') !== false ||
2706
+		if (strpos($_SERVER['HTTP_USER_AGENT'], 'neon') !== false ||
2709 2707
 			// old netdrive does NOT use a User-Agent, but requires full urlencoding for non-ascii chars (eg. German Umlauts)
2710 2708
 			!isset($_SERVER['HTTP_USER_AGENT']) ||
2711 2709
 			// current netdrive uses "NetDrive 2.5.8" as user-agent
2712
-			stripos($_SERVER['HTTP_USER_AGENT'],'NetDrive') !== false ||
2710
+			stripos($_SERVER['HTTP_USER_AGENT'], 'NetDrive') !== false ||
2713 2711
 			// Cyberduck or Mountain Duck WebDAV clients
2714
-			stripos($_SERVER['HTTP_USER_AGENT'],'Cyberduck') !== false ||
2715
-			stripos($_SERVER['HTTP_USER_AGENT'],'Mountain Duck') !== false ||
2712
+			stripos($_SERVER['HTTP_USER_AGENT'], 'Cyberduck') !== false ||
2713
+			stripos($_SERVER['HTTP_USER_AGENT'], 'Mountain Duck') !== false ||
2716 2714
 			// OS X Finder (WebDAVFS/3.0.0 (03008000) Darwin/14.3.0 (x86_64))
2717
-			stripos($_SERVER['HTTP_USER_AGENT'],'WebDAVFS') !== false && stripos($_SERVER['HTTP_USER_AGENT'],'Darwin'))
2715
+			stripos($_SERVER['HTTP_USER_AGENT'], 'WebDAVFS') !== false && stripos($_SERVER['HTTP_USER_AGENT'], 'Darwin'))
2718 2716
 		{
2719
-			return strtr(rawurlencode($url),array(
2717
+			return strtr(rawurlencode($url), array(
2720 2718
 				'%2F' => '/',
2721 2719
 				'%3A' => ':',
2722 2720
 			));
@@ -2773,7 +2771,7 @@  discard block
 block discarded – undo
2773 2771
     	//error_log(__METHOD__.'('.array2string($props).')');
2774 2772
     	if (isset($props['name'])) $props = array($props);
2775 2773
 
2776
-    	foreach($props as $prop)
2774
+    	foreach ($props as $prop)
2777 2775
 		{
2778 2776
 	    	if (!isset($ns_hash[$prop['ns']])) // unknown namespace
2779 2777
 	    	{
@@ -2795,13 +2793,13 @@  discard block
 block discarded – undo
2795 2793
 		    	{
2796 2794
 			    	$vals = '';
2797 2795
 
2798
-			    	foreach($subprop as $attr => $val)
2796
+			    	foreach ($subprop as $attr => $val)
2799 2797
 					{
2800 2798
 				    	$vals .= ' '.$attr.'="'.htmlspecialchars($val, ENT_NOQUOTES|ENT_XML1|ENT_DISALLOWED, 'utf-8').'"';
2801 2799
 					}
2802 2800
 
2803 2801
 		             $ret .= '<'.($prop['ns'] == $ns ? ($this->crrnd ? '' : $ns_hash[$ns].':') : $ns_hash[$prop['ns']].':').$prop['name'].
2804
-				    	$vals .'/>';
2802
+				    	$vals.'/>';
2805 2803
 		    	}
2806 2804
 	    	}
2807 2805
 	    	else
@@ -2812,7 +2810,7 @@  discard block
 block discarded – undo
2812 2810
 		    	}
2813 2811
 		    	else
2814 2812
 		    	{
2815
-			    	if(isset($prop['raw']))
2813
+			    	if (isset($prop['raw']))
2816 2814
 					{
2817 2815
 						$val = $this->_prop_encode('<![CDATA['.$prop['val'].']]>');
2818 2816
 					} else {
@@ -2854,7 +2852,7 @@  discard block
 block discarded – undo
2854 2852
 			case "iso-8859-15":
2855 2853
 			case "latin-1":
2856 2854
 			default:
2857
-				error_log( __METHOD__."utf8 encode\n" .print_r(utf8_encode($text),true));
2855
+				error_log(__METHOD__."utf8 encode\n".print_r(utf8_encode($text), true));
2858 2856
 				return utf8_encode($text);
2859 2857
         }
2860 2858
     }
@@ -2868,7 +2866,7 @@  discard block
 block discarded – undo
2868 2866
     public static function _slashify($path)
2869 2867
     {
2870 2868
 		//error_log(__METHOD__." called with $path");
2871
-		if ($path[self::bytes($path)-1] != '/') {
2869
+		if ($path[self::bytes($path) - 1] != '/') {
2872 2870
 			//error_log(__METHOD__." added slash at the end of path");
2873 2871
 			$path = $path."/";
2874 2872
 		}
@@ -2884,7 +2882,7 @@  discard block
 block discarded – undo
2884 2882
     public static function _unslashify($path)
2885 2883
     {
2886 2884
         //error_log(__METHOD__." called with $path");
2887
-        if ($path[self::bytes($path)-1] == '/') {
2885
+        if ($path[self::bytes($path) - 1] == '/') {
2888 2886
             $path = substr($path, 0, -1);
2889 2887
 			//error_log(__METHOD__." removed slash at the end of path");
2890 2888
         }
@@ -2917,13 +2915,13 @@  discard block
 block discarded – undo
2917 2915
      */
2918 2916
     public static function bytes($str)
2919 2917
     {
2920
-    	static $func_overload=null;
2918
+    	static $func_overload = null;
2921 2919
 
2922 2920
     	if (is_null($func_overload))
2923 2921
     	{
2924 2922
     		$func_overload = @extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
2925 2923
     	}
2926
-    	return $func_overload & 2 ? mb_strlen($str,'ascii') : strlen($str);
2924
+    	return $func_overload&2 ? mb_strlen($str, 'ascii') : strlen($str);
2927 2925
     }
2928 2926
 }
2929 2927
 
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.
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.
Indentation   +824 added lines, -824 removed lines patch added patch discarded remove patch
@@ -44,794 +44,794 @@  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
-        }
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 525
 
526 526
 		// for range requests we need to open with "c" as "w" truncates the file!
527 527
 		$fp = fopen($fspath, empty($options['ranges']) ? "w" : "c");
528 528
 
529
-        return $fp;
530
-    }
531
-
532
-
533
-    /**
534
-     * MKCOL method handler
535
-     *
536
-     * @param  array  general parameter passing array
537
-     * @return bool   true on success
538
-     */
539
-    function MKCOL($options)
540
-    {
541
-        $path   = $this->base .$options["path"];
542
-        $parent = dirname($path);
543
-        $name   = basename($path);
544
-
545
-        if (!file_exists($parent)) {
546
-            return "409 Conflict";
547
-        }
548
-
549
-        if (!is_dir($parent)) {
550
-            return "403 Forbidden";
551
-        }
552
-
553
-        if ( file_exists($parent."/".$name) ) {
554
-            return "405 Method not allowed";
555
-        }
556
-
557
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
558
-            return "415 Unsupported media type";
559
-        }
560
-
561
-        $stat = mkdir($parent."/".$name, 0777);
562
-        if (!$stat) {
563
-            return "403 Forbidden";
564
-        }
565
-
566
-        return ("201 Created");
567
-    }
568
-
569
-
570
-    /**
571
-     * DELETE method handler
572
-     *
573
-     * @param  array  general parameter passing array
574
-     * @return bool   true on success
575
-     */
576
-    function DELETE($options)
577
-    {
578
-        $path = $this->base . "/" .$options["path"];
579
-
580
-        if (!file_exists($path)) {
581
-            return "404 Not found";
582
-        }
583
-
584
-        if (is_dir($path)) {
585
-            $query = "DELETE FROM {$this->db_prefix}properties
529
+		return $fp;
530
+	}
531
+
532
+
533
+	/**
534
+	 * MKCOL method handler
535
+	 *
536
+	 * @param  array  general parameter passing array
537
+	 * @return bool   true on success
538
+	 */
539
+	function MKCOL($options)
540
+	{
541
+		$path   = $this->base .$options["path"];
542
+		$parent = dirname($path);
543
+		$name   = basename($path);
544
+
545
+		if (!file_exists($parent)) {
546
+			return "409 Conflict";
547
+		}
548
+
549
+		if (!is_dir($parent)) {
550
+			return "403 Forbidden";
551
+		}
552
+
553
+		if ( file_exists($parent."/".$name) ) {
554
+			return "405 Method not allowed";
555
+		}
556
+
557
+		if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
558
+			return "415 Unsupported media type";
559
+		}
560
+
561
+		$stat = mkdir($parent."/".$name, 0777);
562
+		if (!$stat) {
563
+			return "403 Forbidden";
564
+		}
565
+
566
+		return ("201 Created");
567
+	}
568
+
569
+
570
+	/**
571
+	 * DELETE method handler
572
+	 *
573
+	 * @param  array  general parameter passing array
574
+	 * @return bool   true on success
575
+	 */
576
+	function DELETE($options)
577
+	{
578
+		$path = $this->base . "/" .$options["path"];
579
+
580
+		if (!file_exists($path)) {
581
+			return "404 Not found";
582
+		}
583
+
584
+		if (is_dir($path)) {
585
+			$query = "DELETE FROM {$this->db_prefix}properties
586 586
                            WHERE path LIKE '".$this->_slashify($options["path"])."%'";
587
-            mysql_query($query);
588
-            System::rm(array("-rf", $path));
589
-        } else {
590
-            unlink($path);
591
-        }
592
-        $query = "DELETE FROM {$this->db_prefix}properties
587
+			mysql_query($query);
588
+			System::rm(array("-rf", $path));
589
+		} else {
590
+			unlink($path);
591
+		}
592
+		$query = "DELETE FROM {$this->db_prefix}properties
593 593
                        WHERE path = '$options[path]'";
594
-        mysql_query($query);
595
-
596
-        return "204 No Content";
597
-    }
598
-
599
-
600
-    /**
601
-     * MOVE method handler
602
-     *
603
-     * @param  array  general parameter passing array
604
-     * @return bool   true on success
605
-     */
606
-    function MOVE($options)
607
-    {
608
-        return $this->COPY($options, true);
609
-    }
610
-
611
-    /**
612
-     * COPY method handler
613
-     *
614
-     * @param  array  general parameter passing array
615
-     * @return bool   true on success
616
-     */
617
-    function COPY($options, $del=false)
618
-    {
619
-        // TODO Property updates still broken (Litmus should detect this?)
620
-
621
-        if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
622
-            return "415 Unsupported media type";
623
-        }
624
-
625
-        // no copying to different WebDAV Servers yet
626
-        if (isset($options["dest_url"])) {
627
-            return "502 bad gateway";
628
-        }
629
-
630
-        $source = $this->base . $options["path"];
631
-        if (!file_exists($source)) {
632
-            return "404 Not found";
633
-        }
634
-
635
-        if (is_dir($source)) { // resource is a collection
636
-            switch ($options["depth"]) {
637
-            case "infinity": // valid
638
-                break;
639
-            case "0": // valid for COPY only
640
-                if ($del) { // MOVE?
641
-                    return "400 Bad request";
642
-                }
643
-                break;
644
-            case "1": // invalid for both COPY and MOVE
645
-            default:
646
-                return "400 Bad request";
647
-            }
648
-        }
649
-
650
-        $dest         = $this->base . $options["dest"];
651
-        $destdir      = dirname($dest);
652
-
653
-        if (!file_exists($destdir) || !is_dir($destdir)) {
654
-            return "409 Conflict";
655
-        }
656
-
657
-
658
-        $new          = !file_exists($dest);
659
-        $existing_col = false;
660
-
661
-        if (!$new) {
662
-            if ($del && is_dir($dest)) {
663
-                if (!$options["overwrite"]) {
664
-                    return "412 precondition failed";
665
-                }
666
-                $dest .= basename($source);
667
-                if (file_exists($dest)) {
668
-                    $options["dest"] .= basename($source);
669
-                } else {
670
-                    $new          = true;
671
-                    $existing_col = true;
672
-                }
673
-            }
674
-        }
675
-
676
-        if (!$new) {
677
-            if ($options["overwrite"]) {
678
-                $stat = $this->DELETE(array("path" => $options["dest"]));
679
-                if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
680
-                    return $stat;
681
-                }
682
-            } else {
683
-                return "412 precondition failed";
684
-            }
685
-        }
686
-
687
-        if ($del) {
688
-            if (!rename($source, $dest)) {
689
-                return "500 Internal server error";
690
-            }
691
-            $destpath = $this->_unslashify($options["dest"]);
692
-            if (is_dir($source)) {
693
-                $query = "UPDATE {$this->db_prefix}properties
594
+		mysql_query($query);
595
+
596
+		return "204 No Content";
597
+	}
598
+
599
+
600
+	/**
601
+	 * MOVE method handler
602
+	 *
603
+	 * @param  array  general parameter passing array
604
+	 * @return bool   true on success
605
+	 */
606
+	function MOVE($options)
607
+	{
608
+		return $this->COPY($options, true);
609
+	}
610
+
611
+	/**
612
+	 * COPY method handler
613
+	 *
614
+	 * @param  array  general parameter passing array
615
+	 * @return bool   true on success
616
+	 */
617
+	function COPY($options, $del=false)
618
+	{
619
+		// TODO Property updates still broken (Litmus should detect this?)
620
+
621
+		if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
622
+			return "415 Unsupported media type";
623
+		}
624
+
625
+		// no copying to different WebDAV Servers yet
626
+		if (isset($options["dest_url"])) {
627
+			return "502 bad gateway";
628
+		}
629
+
630
+		$source = $this->base . $options["path"];
631
+		if (!file_exists($source)) {
632
+			return "404 Not found";
633
+		}
634
+
635
+		if (is_dir($source)) { // resource is a collection
636
+			switch ($options["depth"]) {
637
+			case "infinity": // valid
638
+				break;
639
+			case "0": // valid for COPY only
640
+				if ($del) { // MOVE?
641
+					return "400 Bad request";
642
+				}
643
+				break;
644
+			case "1": // invalid for both COPY and MOVE
645
+			default:
646
+				return "400 Bad request";
647
+			}
648
+		}
649
+
650
+		$dest         = $this->base . $options["dest"];
651
+		$destdir      = dirname($dest);
652
+
653
+		if (!file_exists($destdir) || !is_dir($destdir)) {
654
+			return "409 Conflict";
655
+		}
656
+
657
+
658
+		$new          = !file_exists($dest);
659
+		$existing_col = false;
660
+
661
+		if (!$new) {
662
+			if ($del && is_dir($dest)) {
663
+				if (!$options["overwrite"]) {
664
+					return "412 precondition failed";
665
+				}
666
+				$dest .= basename($source);
667
+				if (file_exists($dest)) {
668
+					$options["dest"] .= basename($source);
669
+				} else {
670
+					$new          = true;
671
+					$existing_col = true;
672
+				}
673
+			}
674
+		}
675
+
676
+		if (!$new) {
677
+			if ($options["overwrite"]) {
678
+				$stat = $this->DELETE(array("path" => $options["dest"]));
679
+				if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) {
680
+					return $stat;
681
+				}
682
+			} else {
683
+				return "412 precondition failed";
684
+			}
685
+		}
686
+
687
+		if ($del) {
688
+			if (!rename($source, $dest)) {
689
+				return "500 Internal server error";
690
+			}
691
+			$destpath = $this->_unslashify($options["dest"]);
692
+			if (is_dir($source)) {
693
+				$query = "UPDATE {$this->db_prefix}properties
694 694
                                  SET path = REPLACE(path, '".$options["path"]."', '".$destpath."')
695 695
                                WHERE path LIKE '".$this->_slashify($options["path"])."%'";
696
-                mysql_query($query);
697
-            }
696
+				mysql_query($query);
697
+			}
698 698
 
699
-            $query = "UPDATE {$this->db_prefix}properties
699
+			$query = "UPDATE {$this->db_prefix}properties
700 700
                              SET path = '".$destpath."'
701 701
                            WHERE path = '".$options["path"]."'";
702
-            mysql_query($query);
703
-        } else {
704
-            if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
705
-                $files = System::find($source);
706
-                $files = array_reverse($files);
707
-            } else {
708
-                $files = array($source);
709
-            }
710
-
711
-            if (!is_array($files) || empty($files)) {
712
-                return "500 Internal server error";
713
-            }
714
-
715
-
716
-            foreach ($files as $file) {
717
-                if (is_dir($file)) {
718
-                    $file = $this->_slashify($file);
719
-                }
720
-
721
-                $destfile = str_replace($source, $dest, $file);
722
-
723
-                if (is_dir($file)) {
724
-                    if (!file_exists($destfile)) {
725
-                        if (!$this->_is_writable(dirname($destfile))) {
726
-                            return "403 Forbidden";
727
-                        }
728
-                        if (!mkdir($destfile)) {
729
-                            return "409 Conflict";
730
-                        }
731
-                    } else if (!is_dir($destfile)) {
732
-                        return "409 Conflict";
733
-                    }
734
-                } else {
735
-
736
-                    if (!copy($file, $destfile)) {
737
-                        return "409 Conflict";
738
-                    }
739
-                }
740
-            }
741
-
742
-            $query = "INSERT INTO {$this->db_prefix}properties
702
+			mysql_query($query);
703
+		} else {
704
+			if (is_dir($source) && $options["depth"] == "infinity") {	// no find for depth="0"
705
+				$files = System::find($source);
706
+				$files = array_reverse($files);
707
+			} else {
708
+				$files = array($source);
709
+			}
710
+
711
+			if (!is_array($files) || empty($files)) {
712
+				return "500 Internal server error";
713
+			}
714
+
715
+
716
+			foreach ($files as $file) {
717
+				if (is_dir($file)) {
718
+					$file = $this->_slashify($file);
719
+				}
720
+
721
+				$destfile = str_replace($source, $dest, $file);
722
+
723
+				if (is_dir($file)) {
724
+					if (!file_exists($destfile)) {
725
+						if (!$this->_is_writable(dirname($destfile))) {
726
+							return "403 Forbidden";
727
+						}
728
+						if (!mkdir($destfile)) {
729
+							return "409 Conflict";
730
+						}
731
+					} else if (!is_dir($destfile)) {
732
+						return "409 Conflict";
733
+					}
734
+				} else {
735
+
736
+					if (!copy($file, $destfile)) {
737
+						return "409 Conflict";
738
+					}
739
+				}
740
+			}
741
+
742
+			$query = "INSERT INTO {$this->db_prefix}properties
743 743
                                SELECT *
744 744
                                  FROM {$this->db_prefix}properties
745 745
                                 WHERE path = '".$options['path']."'";
746
-        }
747
-
748
-        return ($new && !$existing_col) ? "201 Created" : "204 No Content";
749
-    }
750
-
751
-    /**
752
-     * PROPPATCH method handler
753
-     *
754
-     * @param  array  general parameter passing array
755
-     * @return bool   true on success
756
-     */
757
-    function PROPPATCH(&$options)
758
-    {
759
-        global $prefs, $tab;
760
-
761
-        $msg  = "";
762
-        $path = $options["path"];
763
-        $dir  = dirname($path)."/";
764
-        $base = basename($path);
765
-
766
-        foreach ($options["props"] as $key => $prop) {
767
-            if ($prop["ns"] == "DAV:") {
768
-                $options["props"][$key]['status'] = "403 Forbidden";
769
-            } else {
770
-                if (isset($prop["val"])) {
771
-                    $query = "REPLACE INTO {$this->db_prefix}properties
746
+		}
747
+
748
+		return ($new && !$existing_col) ? "201 Created" : "204 No Content";
749
+	}
750
+
751
+	/**
752
+	 * PROPPATCH method handler
753
+	 *
754
+	 * @param  array  general parameter passing array
755
+	 * @return bool   true on success
756
+	 */
757
+	function PROPPATCH(&$options)
758
+	{
759
+		global $prefs, $tab;
760
+
761
+		$msg  = "";
762
+		$path = $options["path"];
763
+		$dir  = dirname($path)."/";
764
+		$base = basename($path);
765
+
766
+		foreach ($options["props"] as $key => $prop) {
767
+			if ($prop["ns"] == "DAV:") {
768
+				$options["props"][$key]['status'] = "403 Forbidden";
769
+			} else {
770
+				if (isset($prop["val"])) {
771
+					$query = "REPLACE INTO {$this->db_prefix}properties
772 772
                                            SET path = '$options[path]'
773 773
                                              , name = '$prop[name]'
774 774
                                              , ns= '$prop[ns]'
775 775
                                              , value = '$prop[val]'";
776
-                } else {
777
-                    $query = "DELETE FROM {$this->db_prefix}properties
776
+				} else {
777
+					$query = "DELETE FROM {$this->db_prefix}properties
778 778
                                         WHERE path = '$options[path]'
779 779
                                           AND name = '$prop[name]'
780 780
                                           AND ns = '$prop[ns]'";
781
-                }
782
-                mysql_query($query);
783
-            }
784
-        }
785
-
786
-        return "";
787
-    }
788
-
789
-
790
-    /**
791
-     * LOCK method handler
792
-     *
793
-     * @param  array  general parameter passing array
794
-     * @return bool   true on success
795
-     */
796
-    function LOCK(&$options)
797
-    {
798
-        // get absolute fs path to requested resource
799
-        $fspath = $this->base . $options["path"];
800
-
801
-        // TODO recursive locks on directories not supported yet
802
-        // makes litmus test "32. lock_collection" fail
803
-        if (is_dir($fspath) && !empty($options["depth"])) {
804
-            return "409 Conflict";
805
-        }
806
-
807
-        $options["timeout"] = time()+300; // 5min. hardcoded
808
-
809
-        if (isset($options["update"])) { // Lock Update
810
-            $where = "WHERE path = '$options[path]' AND token = '$options[update]'";
811
-
812
-            $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
813
-            $res   = mysql_query($query);
814
-            $row   = mysql_fetch_assoc($res);
815
-            mysql_free_result($res);
816
-
817
-            if (is_array($row)) {
818
-                $query = "UPDATE {$this->db_prefix}locks
781
+				}
782
+				mysql_query($query);
783
+			}
784
+		}
785
+
786
+		return "";
787
+	}
788
+
789
+
790
+	/**
791
+	 * LOCK method handler
792
+	 *
793
+	 * @param  array  general parameter passing array
794
+	 * @return bool   true on success
795
+	 */
796
+	function LOCK(&$options)
797
+	{
798
+		// get absolute fs path to requested resource
799
+		$fspath = $this->base . $options["path"];
800
+
801
+		// TODO recursive locks on directories not supported yet
802
+		// makes litmus test "32. lock_collection" fail
803
+		if (is_dir($fspath) && !empty($options["depth"])) {
804
+			return "409 Conflict";
805
+		}
806
+
807
+		$options["timeout"] = time()+300; // 5min. hardcoded
808
+
809
+		if (isset($options["update"])) { // Lock Update
810
+			$where = "WHERE path = '$options[path]' AND token = '$options[update]'";
811
+
812
+			$query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where";
813
+			$res   = mysql_query($query);
814
+			$row   = mysql_fetch_assoc($res);
815
+			mysql_free_result($res);
816
+
817
+			if (is_array($row)) {
818
+				$query = "UPDATE {$this->db_prefix}locks
819 819
                                  SET expires = '$options[timeout]'
820 820
                                    , modified = ".time()."
821 821
                               $where";
822
-                mysql_query($query);
822
+				mysql_query($query);
823 823
 
824
-                $options['owner'] = $row['owner'];
825
-                $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
826
-                $options['type']  = $row["exclusivelock"] ? "write"     : "read";
824
+				$options['owner'] = $row['owner'];
825
+				$options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared";
826
+				$options['type']  = $row["exclusivelock"] ? "write"     : "read";
827 827
 
828
-                return true;
829
-            } else {
830
-                return false;
831
-            }
832
-        }
828
+				return true;
829
+			} else {
830
+				return false;
831
+			}
832
+		}
833 833
 
834
-        $query = "INSERT INTO {$this->db_prefix}locks
834
+		$query = "INSERT INTO {$this->db_prefix}locks
835 835
                         SET token   = '$options[locktoken]'
836 836
                           , path    = '$options[path]'
837 837
                           , created = ".time()."
@@ -839,76 +839,76 @@  discard block
 block discarded – undo
839 839
                           , owner   = '$options[owner]'
840 840
                           , expires = '$options[timeout]'
841 841
                           , exclusivelock  = " .($options['scope'] === "exclusive" ? "1" : "0")
842
-            ;
843
-        mysql_query($query);
844
-
845
-        return mysql_affected_rows() ? "200 OK" : "409 Conflict";
846
-    }
847
-
848
-    /**
849
-     * UNLOCK method handler
850
-     *
851
-     * @param  array  general parameter passing array
852
-     * @return bool   true on success
853
-     */
854
-    function UNLOCK(&$options)
855
-    {
856
-        $query = "DELETE FROM {$this->db_prefix}locks
842
+			;
843
+		mysql_query($query);
844
+
845
+		return mysql_affected_rows() ? "200 OK" : "409 Conflict";
846
+	}
847
+
848
+	/**
849
+	 * UNLOCK method handler
850
+	 *
851
+	 * @param  array  general parameter passing array
852
+	 * @return bool   true on success
853
+	 */
854
+	function UNLOCK(&$options)
855
+	{
856
+		$query = "DELETE FROM {$this->db_prefix}locks
857 857
                       WHERE path = '$options[path]'
858 858
                         AND token = '$options[token]'";
859
-        mysql_query($query);
860
-
861
-        return mysql_affected_rows() ? "204 No Content" : "409 Conflict";
862
-    }
863
-
864
-    /**
865
-     * checkLock() helper
866
-     *
867
-     * @param  string resource path to check for locks
868
-     * @return bool   true on success
869
-     */
870
-    function checkLock($path)
871
-    {
872
-        $result = false;
873
-
874
-        $query = "SELECT owner, token, created, modified, expires, exclusivelock
859
+		mysql_query($query);
860
+
861
+		return mysql_affected_rows() ? "204 No Content" : "409 Conflict";
862
+	}
863
+
864
+	/**
865
+	 * checkLock() helper
866
+	 *
867
+	 * @param  string resource path to check for locks
868
+	 * @return bool   true on success
869
+	 */
870
+	function checkLock($path)
871
+	{
872
+		$result = false;
873
+
874
+		$query = "SELECT owner, token, created, modified, expires, exclusivelock
875 875
                   FROM {$this->db_prefix}locks
876 876
                  WHERE path = '$path'
877 877
                ";
878
-        $res = mysql_query($query);
879
-
880
-        if ($res) {
881
-            $row = mysql_fetch_array($res);
882
-            mysql_free_result($res);
883
-
884
-            if ($row) {
885
-                $result = array( "type"    => "write",
886
-                                 "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
887
-                                 "depth"   => 0,
888
-                                 "owner"   => $row['owner'],
889
-                                 "token"   => $row['token'],
890
-                                 "created" => $row['created'],
891
-                                 "modified" => $row['modified'],
892
-                                 "expires" => $row['expires']
893
-                                 );
894
-            }
895
-        }
896
-
897
-        return $result;
898
-    }
899
-
900
-
901
-    /**
902
-     * create database tables for property and lock storage
903
-     *
904
-     * @param  void
905
-     * @return bool   true on success
906
-     */
907
-    function create_database()
908
-    {
909
-        // TODO
910
-        return false;
911
-    }
878
+		$res = mysql_query($query);
879
+
880
+		if ($res) {
881
+			$row = mysql_fetch_array($res);
882
+			mysql_free_result($res);
883
+
884
+			if ($row) {
885
+				$result = array( "type"    => "write",
886
+								 "scope"   => $row["exclusivelock"] ? "exclusive" : "shared",
887
+								 "depth"   => 0,
888
+								 "owner"   => $row['owner'],
889
+								 "token"   => $row['token'],
890
+								 "created" => $row['created'],
891
+								 "modified" => $row['modified'],
892
+								 "expires" => $row['expires']
893
+								 );
894
+			}
895
+		}
896
+
897
+		return $result;
898
+	}
899
+
900
+
901
+	/**
902
+	 * create database tables for property and lock storage
903
+	 *
904
+	 * @param  void
905
+	 * @return bool   true on success
906
+	 */
907
+	function create_database()
908
+	{
909
+		// TODO
910
+		return false;
911
+	}
912 912
 }
913 913
 
914 914
 
Please login to merge, or discard this patch.
api/src/WebDAV/Tools/_parse_lockinfo.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -87,6 +87,7 @@
 block discarded – undo
87 87
      * constructor
88 88
      *
89 89
      * @param  string  path of stream to read
90
+     * @param string $path
90 91
      * @access public
91 92
      */
92 93
     function __construct($path)
Please login to merge, or discard this patch.
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -43,209 +43,209 @@
 block discarded – undo
43 43
  */
44 44
 class _parse_lockinfo
45 45
 {
46
-    /**
47
-     * success state flag
48
-     *
49
-     * @var bool
50
-     * @access public
51
-     */
52
-    var $success = false;
53
-
54
-    /**
55
-     * lock type, currently only "write"
56
-     *
57
-     * @var string
58
-     * @access public
59
-     */
60
-    var $locktype = "";
61
-
62
-    /**
63
-     * lock scope, "shared" or "exclusive"
64
-     *
65
-     * @var string
66
-     * @access public
67
-     */
68
-    var $lockscope = "";
69
-
70
-    /**
71
-     * lock owner information
72
-     *
73
-     * @var string
74
-     * @access public
75
-     */
76
-    var $owner = "";
77
-
78
-    /**
79
-     * flag that is set during lock owner read
80
-     *
81
-     * @var bool
82
-     * @access private
83
-     */
84
-    var $collect_owner = false;
85
-
86
-    /**
87
-     * constructor
88
-     *
89
-     * @param  string  path of stream to read
90
-     * @access public
91
-     */
92
-    function __construct($path)
93
-    {
94
-        // we assume success unless problems occur
95
-        $this->success = true;
96
-
97
-        // remember if any input was parsed
98
-        $had_input = false;
99
-
100
-        // open stream
101
-        $f_in = fopen($path, "r");
102
-        if (!$f_in) {
103
-            $this->success = false;
104
-            return;
105
-        }
106
-
107
-        // create namespace aware parser
108
-        $xml_parser = xml_parser_create_ns("UTF-8", " ");
109
-
110
-        // set tag and data handlers
111
-        xml_set_element_handler($xml_parser,
112
-                                array(&$this, "_startElement"),
113
-                                array(&$this, "_endElement"));
114
-        xml_set_character_data_handler($xml_parser,
115
-                                       array(&$this, "_data"));
116
-
117
-        // we want a case sensitive parser
118
-        xml_parser_set_option($xml_parser,
119
-                              XML_OPTION_CASE_FOLDING, false);
120
-
121
-        // parse input
122
-        while ($this->success && !feof($f_in)) {
123
-            $line = fgets($f_in);
124
-            if (is_string($line)) {
125
-                $had_input = true;
126
-                $this->success &= xml_parse($xml_parser, $line, false);
127
-            }
128
-        }
129
-
130
-        // finish parsing
131
-        if ($had_input) {
132
-            $this->success &= xml_parse($xml_parser, "", true);
133
-        }
134
-
135
-        // check if required tags where found
136
-        $this->success &= !empty($this->locktype);
137
-        $this->success &= !empty($this->lockscope);
138
-
139
-        // free parser resource
140
-        xml_parser_free($xml_parser);
141
-
142
-        // close input stream
143
-        fclose($f_in);
144
-    }
145
-
146
-
147
-    /**
148
-     * tag start handler
149
-     *
150
-     * @param  resource  parser
151
-     * @param  string    tag name
152
-     * @param  array     tag attributes
153
-     * @return void
154
-     * @access private
155
-     */
156
-    function _startElement($parser, $name, $attrs)
157
-    {
158
-        // namespace handling
159
-        if (strstr($name, " ")) {
160
-            list($ns, $tag) = explode(" ", $name);
161
-        } else {
162
-            $ns  = "";
163
-            $tag = $name;
164
-        }
165
-
166
-
167
-        if ($this->collect_owner) {
168
-            // everything within the <owner> tag needs to be collected
169
-            $ns_short = "";
170
-            $ns_attr  = "";
171
-            if ($ns) {
172
-                if ($ns == "DAV:") {
173
-                    $ns_short = "D:";
174
-                } else {
175
-                    $ns_attr = " xmlns='$ns'";
176
-                }
177
-            }
178
-            $this->owner .= "<$ns_short$tag$ns_attr>";
179
-        } else if ($ns == "DAV:") {
180
-            // parse only the essential tags
181
-            switch ($tag) {
182
-            case "write":
183
-                $this->locktype = $tag;
184
-                break;
185
-            case "exclusive":
186
-            case "shared":
187
-                $this->lockscope = $tag;
188
-                break;
189
-            case "owner":
190
-                $this->collect_owner = true;
191
-                break;
192
-            }
193
-        }
194
-    }
195
-
196
-    /**
197
-     * data handler
198
-     *
199
-     * @param  resource  parser
200
-     * @param  string    data
201
-     * @return void
202
-     * @access private
203
-     */
204
-    function _data($parser, $data)
205
-    {
206
-        // only the <owner> tag has data content
207
-        if ($this->collect_owner) {
208
-            $this->owner .= $data;
209
-        }
210
-    }
211
-
212
-    /**
213
-     * tag end handler
214
-     *
215
-     * @param  resource  parser
216
-     * @param  string    tag name
217
-     * @return void
218
-     * @access private
219
-     */
220
-    function _endElement($parser, $name)
221
-    {
222
-        // namespace handling
223
-        if (strstr($name, " ")) {
224
-            list($ns, $tag) = explode(" ", $name);
225
-        } else {
226
-            $ns  = "";
227
-            $tag = $name;
228
-        }
229
-
230
-        // <owner> finished?
231
-        if (($ns == "DAV:") && ($tag == "owner")) {
232
-            $this->collect_owner = false;
233
-        }
234
-
235
-        // within <owner> we have to collect everything
236
-        if ($this->collect_owner) {
237
-            $ns_short = "";
238
-            $ns_attr  = "";
239
-            if ($ns) {
240
-                if ($ns == "DAV:") {
241
-                    $ns_short = "D:";
242
-                } else {
243
-                    $ns_attr = " xmlns='$ns'";
244
-                }
245
-            }
246
-            $this->owner .= "</$ns_short$tag$ns_attr>";
247
-        }
248
-    }
46
+	/**
47
+	 * success state flag
48
+	 *
49
+	 * @var bool
50
+	 * @access public
51
+	 */
52
+	var $success = false;
53
+
54
+	/**
55
+	 * lock type, currently only "write"
56
+	 *
57
+	 * @var string
58
+	 * @access public
59
+	 */
60
+	var $locktype = "";
61
+
62
+	/**
63
+	 * lock scope, "shared" or "exclusive"
64
+	 *
65
+	 * @var string
66
+	 * @access public
67
+	 */
68
+	var $lockscope = "";
69
+
70
+	/**
71
+	 * lock owner information
72
+	 *
73
+	 * @var string
74
+	 * @access public
75
+	 */
76
+	var $owner = "";
77
+
78
+	/**
79
+	 * flag that is set during lock owner read
80
+	 *
81
+	 * @var bool
82
+	 * @access private
83
+	 */
84
+	var $collect_owner = false;
85
+
86
+	/**
87
+	 * constructor
88
+	 *
89
+	 * @param  string  path of stream to read
90
+	 * @access public
91
+	 */
92
+	function __construct($path)
93
+	{
94
+		// we assume success unless problems occur
95
+		$this->success = true;
96
+
97
+		// remember if any input was parsed
98
+		$had_input = false;
99
+
100
+		// open stream
101
+		$f_in = fopen($path, "r");
102
+		if (!$f_in) {
103
+			$this->success = false;
104
+			return;
105
+		}
106
+
107
+		// create namespace aware parser
108
+		$xml_parser = xml_parser_create_ns("UTF-8", " ");
109
+
110
+		// set tag and data handlers
111
+		xml_set_element_handler($xml_parser,
112
+								array(&$this, "_startElement"),
113
+								array(&$this, "_endElement"));
114
+		xml_set_character_data_handler($xml_parser,
115
+									   array(&$this, "_data"));
116
+
117
+		// we want a case sensitive parser
118
+		xml_parser_set_option($xml_parser,
119
+							  XML_OPTION_CASE_FOLDING, false);
120
+
121
+		// parse input
122
+		while ($this->success && !feof($f_in)) {
123
+			$line = fgets($f_in);
124
+			if (is_string($line)) {
125
+				$had_input = true;
126
+				$this->success &= xml_parse($xml_parser, $line, false);
127
+			}
128
+		}
129
+
130
+		// finish parsing
131
+		if ($had_input) {
132
+			$this->success &= xml_parse($xml_parser, "", true);
133
+		}
134
+
135
+		// check if required tags where found
136
+		$this->success &= !empty($this->locktype);
137
+		$this->success &= !empty($this->lockscope);
138
+
139
+		// free parser resource
140
+		xml_parser_free($xml_parser);
141
+
142
+		// close input stream
143
+		fclose($f_in);
144
+	}
145
+
146
+
147
+	/**
148
+	 * tag start handler
149
+	 *
150
+	 * @param  resource  parser
151
+	 * @param  string    tag name
152
+	 * @param  array     tag attributes
153
+	 * @return void
154
+	 * @access private
155
+	 */
156
+	function _startElement($parser, $name, $attrs)
157
+	{
158
+		// namespace handling
159
+		if (strstr($name, " ")) {
160
+			list($ns, $tag) = explode(" ", $name);
161
+		} else {
162
+			$ns  = "";
163
+			$tag = $name;
164
+		}
165
+
166
+
167
+		if ($this->collect_owner) {
168
+			// everything within the <owner> tag needs to be collected
169
+			$ns_short = "";
170
+			$ns_attr  = "";
171
+			if ($ns) {
172
+				if ($ns == "DAV:") {
173
+					$ns_short = "D:";
174
+				} else {
175
+					$ns_attr = " xmlns='$ns'";
176
+				}
177
+			}
178
+			$this->owner .= "<$ns_short$tag$ns_attr>";
179
+		} else if ($ns == "DAV:") {
180
+			// parse only the essential tags
181
+			switch ($tag) {
182
+			case "write":
183
+				$this->locktype = $tag;
184
+				break;
185
+			case "exclusive":
186
+			case "shared":
187
+				$this->lockscope = $tag;
188
+				break;
189
+			case "owner":
190
+				$this->collect_owner = true;
191
+				break;
192
+			}
193
+		}
194
+	}
195
+
196
+	/**
197
+	 * data handler
198
+	 *
199
+	 * @param  resource  parser
200
+	 * @param  string    data
201
+	 * @return void
202
+	 * @access private
203
+	 */
204
+	function _data($parser, $data)
205
+	{
206
+		// only the <owner> tag has data content
207
+		if ($this->collect_owner) {
208
+			$this->owner .= $data;
209
+		}
210
+	}
211
+
212
+	/**
213
+	 * tag end handler
214
+	 *
215
+	 * @param  resource  parser
216
+	 * @param  string    tag name
217
+	 * @return void
218
+	 * @access private
219
+	 */
220
+	function _endElement($parser, $name)
221
+	{
222
+		// namespace handling
223
+		if (strstr($name, " ")) {
224
+			list($ns, $tag) = explode(" ", $name);
225
+		} else {
226
+			$ns  = "";
227
+			$tag = $name;
228
+		}
229
+
230
+		// <owner> finished?
231
+		if (($ns == "DAV:") && ($tag == "owner")) {
232
+			$this->collect_owner = false;
233
+		}
234
+
235
+		// within <owner> we have to collect everything
236
+		if ($this->collect_owner) {
237
+			$ns_short = "";
238
+			$ns_attr  = "";
239
+			if ($ns) {
240
+				if ($ns == "DAV:") {
241
+					$ns_short = "D:";
242
+				} else {
243
+					$ns_attr = " xmlns='$ns'";
244
+				}
245
+			}
246
+			$this->owner .= "</$ns_short$tag$ns_attr>";
247
+		}
248
+	}
249 249
 }
250 250
 
251 251
 ?>
Please login to merge, or discard this patch.
Switch Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -179,16 +179,16 @@
 block discarded – undo
179 179
         } else if ($ns == "DAV:") {
180 180
             // parse only the essential tags
181 181
             switch ($tag) {
182
-            case "write":
183
-                $this->locktype = $tag;
184
-                break;
185
-            case "exclusive":
186
-            case "shared":
187
-                $this->lockscope = $tag;
188
-                break;
189
-            case "owner":
190
-                $this->collect_owner = true;
191
-                break;
182
+            	case "write":
183
+                	$this->locktype = $tag;
184
+                	break;
185
+            	case "exclusive":
186
+            	case "shared":
187
+                	$this->lockscope = $tag;
188
+                	break;
189
+            	case "owner":
190
+                	$this->collect_owner = true;
191
+                	break;
192 192
             }
193 193
         }
194 194
     }
Please login to merge, or discard this patch.
Braces   +45 added lines, -20 removed lines patch added patch discarded remove patch
@@ -99,7 +99,8 @@  discard block
 block discarded – undo
99 99
 
100 100
         // open stream
101 101
         $f_in = fopen($path, "r");
102
-        if (!$f_in) {
102
+        if (!$f_in)
103
+        {
103 104
             $this->success = false;
104 105
             return;
105 106
         }
@@ -119,16 +120,19 @@  discard block
 block discarded – undo
119 120
                               XML_OPTION_CASE_FOLDING, false);
120 121
 
121 122
         // parse input
122
-        while ($this->success && !feof($f_in)) {
123
+        while ($this->success && !feof($f_in))
124
+        {
123 125
             $line = fgets($f_in);
124
-            if (is_string($line)) {
126
+            if (is_string($line))
127
+            {
125 128
                 $had_input = true;
126 129
                 $this->success &= xml_parse($xml_parser, $line, false);
127 130
             }
128 131
         }
129 132
 
130 133
         // finish parsing
131
-        if ($had_input) {
134
+        if ($had_input)
135
+        {
132 136
             $this->success &= xml_parse($xml_parser, "", true);
133 137
         }
134 138
 
@@ -156,29 +160,40 @@  discard block
 block discarded – undo
156 160
     function _startElement($parser, $name, $attrs)
157 161
     {
158 162
         // namespace handling
159
-        if (strstr($name, " ")) {
163
+        if (strstr($name, " "))
164
+        {
160 165
             list($ns, $tag) = explode(" ", $name);
161
-        } else {
166
+        }
167
+        else
168
+        {
162 169
             $ns  = "";
163 170
             $tag = $name;
164 171
         }
165 172
 
166 173
 
167
-        if ($this->collect_owner) {
174
+        if ($this->collect_owner)
175
+        {
168 176
             // everything within the <owner> tag needs to be collected
169 177
             $ns_short = "";
170 178
             $ns_attr  = "";
171
-            if ($ns) {
172
-                if ($ns == "DAV:") {
179
+            if ($ns)
180
+            {
181
+                if ($ns == "DAV:")
182
+                {
173 183
                     $ns_short = "D:";
174
-                } else {
184
+                }
185
+                else
186
+                {
175 187
                     $ns_attr = " xmlns='$ns'";
176 188
                 }
177 189
             }
178 190
             $this->owner .= "<$ns_short$tag$ns_attr>";
179
-        } else if ($ns == "DAV:") {
191
+        }
192
+        else if ($ns == "DAV:")
193
+        {
180 194
             // parse only the essential tags
181
-            switch ($tag) {
195
+            switch ($tag)
196
+            {
182 197
             case "write":
183 198
                 $this->locktype = $tag;
184 199
                 break;
@@ -204,7 +219,8 @@  discard block
 block discarded – undo
204 219
     function _data($parser, $data)
205 220
     {
206 221
         // only the <owner> tag has data content
207
-        if ($this->collect_owner) {
222
+        if ($this->collect_owner)
223
+        {
208 224
             $this->owner .= $data;
209 225
         }
210 226
     }
@@ -220,26 +236,35 @@  discard block
 block discarded – undo
220 236
     function _endElement($parser, $name)
221 237
     {
222 238
         // namespace handling
223
-        if (strstr($name, " ")) {
239
+        if (strstr($name, " "))
240
+        {
224 241
             list($ns, $tag) = explode(" ", $name);
225
-        } else {
242
+        }
243
+        else
244
+        {
226 245
             $ns  = "";
227 246
             $tag = $name;
228 247
         }
229 248
 
230 249
         // <owner> finished?
231
-        if (($ns == "DAV:") && ($tag == "owner")) {
250
+        if (($ns == "DAV:") && ($tag == "owner"))
251
+        {
232 252
             $this->collect_owner = false;
233 253
         }
234 254
 
235 255
         // within <owner> we have to collect everything
236
-        if ($this->collect_owner) {
256
+        if ($this->collect_owner)
257
+        {
237 258
             $ns_short = "";
238 259
             $ns_attr  = "";
239
-            if ($ns) {
240
-                if ($ns == "DAV:") {
260
+            if ($ns)
261
+            {
262
+                if ($ns == "DAV:")
263
+                {
241 264
                     $ns_short = "D:";
242
-                } else {
265
+                }
266
+                else
267
+                {
243 268
                     $ns_attr = " xmlns='$ns'";
244 269
                 }
245 270
             }
Please login to merge, or discard this patch.