Completed
Push — release-2.1 ( 9fa566...084464 )
by Colin
17:59 queued 10:04
created
Sources/Subs-Package.php 1 patch
Braces   +799 added lines, -624 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
  * @version 2.1 Beta 4
17 17
  */
18 18
 
19
-if (!defined('SMF'))
19
+if (!defined('SMF')) {
20 20
 	die('No direct access...');
21
+}
21 22
 
22 23
 /**
23 24
  * Reads a .tar.gz file, filename, in and extracts file(s) from it.
@@ -67,47 +68,53 @@  discard block
 block discarded – undo
67 68
 	loadLanguage('Packages');
68 69
 
69 70
 	// This function sorta needs gzinflate!
70
-	if (!function_exists('gzinflate'))
71
-		fatal_lang_error('package_no_zlib', 'critical');
71
+	if (!function_exists('gzinflate')) {
72
+			fatal_lang_error('package_no_zlib', 'critical');
73
+	}
72 74
 
73 75
 	if (substr($gzfilename, 0, 7) == 'http://' || substr($gzfilename, 0, 8) == 'https://')
74 76
 	{
75 77
 		$data = fetch_web_data($gzfilename);
76 78
 
77
-		if ($data === false)
78
-			return false;
79
-	}
80
-	else
79
+		if ($data === false) {
80
+					return false;
81
+		}
82
+	} else
81 83
 	{
82 84
 		$data = @file_get_contents($gzfilename);
83 85
 
84
-		if ($data === false)
85
-			return false;
86
+		if ($data === false) {
87
+					return false;
88
+		}
86 89
 	}
87 90
 
88 91
 	umask(0);
89
-	if (!$single_file && $destination !== null && !file_exists($destination))
90
-		mktree($destination, 0777);
92
+	if (!$single_file && $destination !== null && !file_exists($destination)) {
93
+			mktree($destination, 0777);
94
+	}
91 95
 
92 96
 	// No signature?
93
-	if (strlen($data) < 2)
94
-		return false;
97
+	if (strlen($data) < 2) {
98
+			return false;
99
+	}
95 100
 
96 101
 	$id = unpack('H2a/H2b', substr($data, 0, 2));
97 102
 	if (strtolower($id['a'] . $id['b']) != '1f8b')
98 103
 	{
99 104
 		// Okay, this ain't no tar.gz, but maybe it's a zip file.
100
-		if (substr($data, 0, 2) == 'PK')
101
-			return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract);
102
-		else
103
-			return false;
105
+		if (substr($data, 0, 2) == 'PK') {
106
+					return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract);
107
+		} else {
108
+					return false;
109
+		}
104 110
 	}
105 111
 
106 112
 	$flags = unpack('Ct/Cf', substr($data, 2, 2));
107 113
 
108 114
 	// Not deflate!
109
-	if ($flags['t'] != 8)
110
-		return false;
115
+	if ($flags['t'] != 8) {
116
+			return false;
117
+	}
111 118
 	$flags = $flags['f'];
112 119
 
113 120
 	$offset = 10;
@@ -117,18 +124,21 @@  discard block
 block discarded – undo
117 124
 	// @todo Might be mussed.
118 125
 	if ($flags & 12)
119 126
 	{
120
-		while ($flags & 8 && $data{$offset++} != "\0")
121
-			continue;
122
-		while ($flags & 4 && $data{$offset++} != "\0")
123
-			continue;
127
+		while ($flags & 8 && $data{$offset++} != "\0") {
128
+					continue;
129
+		}
130
+		while ($flags & 4 && $data{$offset++} != "\0") {
131
+					continue;
132
+		}
124 133
 	}
125 134
 
126 135
 	$crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8));
127 136
 	$data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset));
128 137
 
129 138
 	// smf_crc32 and crc32 may not return the same results, so we accept either.
130
-	if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data))
131
-		return false;
139
+	if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) {
140
+			return false;
141
+	}
132 142
 
133 143
 	$blocks = strlen($data) / 512 - 1;
134 144
 	$offset = 0;
@@ -149,83 +159,98 @@  discard block
 block discarded – undo
149 159
 
150 160
 		foreach ($current as $k => $v)
151 161
 		{
152
-			if (in_array($k, $octdec))
153
-				$current[$k] = octdec(trim($v));
154
-			else
155
-				$current[$k] = trim($v);
162
+			if (in_array($k, $octdec)) {
163
+							$current[$k] = octdec(trim($v));
164
+			} else {
165
+							$current[$k] = trim($v);
166
+			}
156 167
 		}
157 168
 
158
-		if ($current['type'] == 5 && substr($current['filename'], -1) != '/')
159
-			$current['filename'] .= '/';
169
+		if ($current['type'] == 5 && substr($current['filename'], -1) != '/') {
170
+					$current['filename'] .= '/';
171
+		}
160 172
 
161 173
 		$checksum = 256;
162
-		for ($i = 0; $i < 148; $i++)
163
-			$checksum += ord($header{$i});
164
-		for ($i = 156; $i < 512; $i++)
165
-			$checksum += ord($header{$i});
174
+		for ($i = 0; $i < 148; $i++) {
175
+					$checksum += ord($header{$i});
176
+		}
177
+		for ($i = 156; $i < 512; $i++) {
178
+					$checksum += ord($header{$i});
179
+		}
166 180
 
167
-		if ($current['checksum'] != $checksum)
168
-			break;
181
+		if ($current['checksum'] != $checksum) {
182
+					break;
183
+		}
169 184
 
170 185
 		$size = ceil($current['size'] / 512);
171 186
 		$current['data'] = substr($data, ++$offset << 9, $current['size']);
172 187
 		$offset += $size;
173 188
 
174 189
 		// Not a directory and doesn't exist already...
175
-		if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename']))
176
-			$write_this = true;
190
+		if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) {
191
+					$write_this = true;
192
+		}
177 193
 		// File exists... check if it is newer.
178
-		elseif (substr($current['filename'], -1, 1) != '/')
179
-			$write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime'];
194
+		elseif (substr($current['filename'], -1, 1) != '/') {
195
+					$write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime'];
196
+		}
180 197
 		// Folder... create.
181 198
 		elseif ($destination !== null && !$single_file)
182 199
 		{
183 200
 			// Protect from accidental parent directory writing...
184 201
 			$current['filename'] = strtr($current['filename'], array('../' => '', '/..' => ''));
185 202
 
186
-			if (!file_exists($destination . '/' . $current['filename']))
187
-				mktree($destination . '/' . $current['filename'], 0777);
203
+			if (!file_exists($destination . '/' . $current['filename'])) {
204
+							mktree($destination . '/' . $current['filename'], 0777);
205
+			}
188 206
 			$write_this = false;
207
+		} else {
208
+					$write_this = false;
189 209
 		}
190
-		else
191
-			$write_this = false;
192 210
 
193 211
 		if ($write_this && $destination !== null)
194 212
 		{
195
-			if (strpos($current['filename'], '/') !== false && !$single_file)
196
-				mktree($destination . '/' . dirname($current['filename']), 0777);
213
+			if (strpos($current['filename'], '/') !== false && !$single_file) {
214
+							mktree($destination . '/' . dirname($current['filename']), 0777);
215
+			}
197 216
 
198 217
 			// Is this the file we're looking for?
199
-			if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename'])))
200
-				return $current['data'];
218
+			if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) {
219
+							return $current['data'];
220
+			}
201 221
 			// If we're looking for another file, keep going.
202
-			elseif ($single_file)
203
-				continue;
222
+			elseif ($single_file) {
223
+							continue;
224
+			}
204 225
 			// Looking for restricted files?
205
-			elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract))
206
-				continue;
226
+			elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) {
227
+							continue;
228
+			}
207 229
 
208 230
 			package_put_contents($destination . '/' . $current['filename'], $current['data']);
209 231
 		}
210 232
 
211
-		if (substr($current['filename'], -1, 1) != '/')
212
-			$return[] = array(
233
+		if (substr($current['filename'], -1, 1) != '/') {
234
+					$return[] = array(
213 235
 				'filename' => $current['filename'],
214 236
 				'md5' => md5($current['data']),
215 237
 				'preview' => substr($current['data'], 0, 100),
216 238
 				'size' => $current['size'],
217 239
 				'skipped' => false
218 240
 			);
241
+		}
219 242
 	}
220 243
 
221
-	if ($destination !== null && !$single_file)
222
-		package_flush_cache();
244
+	if ($destination !== null && !$single_file) {
245
+			package_flush_cache();
246
+	}
223 247
 
224
-	if ($single_file)
225
-		return false;
226
-	else
227
-		return $return;
228
-}
248
+	if ($single_file) {
249
+			return false;
250
+	} else {
251
+			return $return;
252
+	}
253
+	}
229 254
 
230 255
 /**
231 256
  * Extract zip data. A functional copy of {@list read_zip_data()}.
@@ -247,9 +272,10 @@  discard block
 block discarded – undo
247 272
 		$return = array();
248 273
 
249 274
 		// Some hosted unix platforms require an extension; win may have .tmp & that works ok
250
-		if (!in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), array('zip', 'tmp')))
251
-			if (@rename($file, $file . '.zip'))
275
+		if (!in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), array('zip', 'tmp'))) {
276
+					if (@rename($file, $file . '.zip'))
252 277
 				$file = $file . '.zip';
278
+		}
253 279
 
254 280
 		// Phar doesn't handle open_basedir restrictions very well and throws a PHP Warning. Ignore that.
255 281
 		set_error_handler(function($errno, $errstr, $errfile, $errline)
@@ -258,8 +284,9 @@  discard block
 block discarded – undo
258 284
 				if (0 === error_reporting()) {
259 285
 					return false;
260 286
 				}
261
-				if (strpos($errstr, 'PharData::__construct(): open_basedir') === false)
262
-					log_error($errstr, 'general', $errfile, $errline);
287
+				if (strpos($errstr, 'PharData::__construct(): open_basedir') === false) {
288
+									log_error($errstr, 'general', $errfile, $errline);
289
+				}
263 290
 			}
264 291
 		);
265 292
 		$archive = new PharData($file, RecursiveIteratorIterator::SELF_FIRST, null, Phar::ZIP);
@@ -272,65 +299,74 @@  discard block
 block discarded – undo
272 299
 			{
273 300
 				$i = $iterator->getSubPathname();
274 301
 				// If this is a file, and it doesn't exist.... happy days!
275
-				if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i))
276
-					$write_this = true;
302
+				if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) {
303
+									$write_this = true;
304
+				}
277 305
 				// If the file exists, we may not want to overwrite it.
278
-				elseif (substr($i, -1) != '/')
279
-					$write_this = $overwrite;
280
-				else
281
-					$write_this = false;
306
+				elseif (substr($i, -1) != '/') {
307
+									$write_this = $overwrite;
308
+				} else {
309
+									$write_this = false;
310
+				}
282 311
 
283 312
 				// Get the actual compressed data.
284
-				if (!$file_info->isDir())
285
-					$file_data = file_get_contents($file_info);
286
-				elseif ($destination !== null && !$single_file)
313
+				if (!$file_info->isDir()) {
314
+									$file_data = file_get_contents($file_info);
315
+				} elseif ($destination !== null && !$single_file)
287 316
 				{
288 317
 					// Folder... create.
289
-					if (!file_exists($destination . '/' . $i))
290
-						mktree($destination . '/' . $i, 0777);
318
+					if (!file_exists($destination . '/' . $i)) {
319
+											mktree($destination . '/' . $i, 0777);
320
+					}
291 321
 					$file_data = null;
322
+				} else {
323
+									$file_data = null;
292 324
 				}
293
-				else
294
-					$file_data = null;
295 325
 
296 326
 				// Okay!  We can write this file, looks good from here...
297 327
 				if ($write_this && $destination !== null)
298 328
 				{
299
-					if (!$single_file && !is_dir($destination . '/' . dirname($i)))
300
-						mktree($destination . '/' . dirname($i), 0777);
329
+					if (!$single_file && !is_dir($destination . '/' . dirname($i))) {
330
+											mktree($destination . '/' . dirname($i), 0777);
331
+					}
301 332
 
302 333
 					// If we're looking for a specific file, and this is it... ka-bam, baby.
303
-					if ($single_file && ($destination == $i || $destination == '*/' . basename($i)))
304
-						return $file_data;
334
+					if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) {
335
+											return $file_data;
336
+					}
305 337
 					// Oh?  Another file.  Fine.  You don't like this file, do you?  I know how it is.  Yeah... just go away.  No, don't apologize.  I know this file's just not *good enough* for you.
306
-					elseif ($single_file)
307
-						continue;
338
+					elseif ($single_file) {
339
+											continue;
340
+					}
308 341
 					// Don't really want this?
309
-					elseif ($files_to_extract !== null && !in_array($i, $files_to_extract))
310
-						continue;
342
+					elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) {
343
+											continue;
344
+					}
311 345
 
312 346
 					package_put_contents($destination . '/' . $i, $file_data);
313 347
 				}
314 348
 
315
-				if (substr($i, -1, 1) != '/')
316
-					$return[] = array(
349
+				if (substr($i, -1, 1) != '/') {
350
+									$return[] = array(
317 351
 						'filename' => $i,
318 352
 						'md5' => md5($file_data),
319 353
 						'preview' => substr($file_data, 0, 100),
320 354
 						'size' => strlen($file_data),
321 355
 						'skipped' => false
322 356
 					);
357
+				}
323 358
 			}
324 359
 
325
-		if ($destination !== null && !$single_file)
326
-			package_flush_cache();
360
+		if ($destination !== null && !$single_file) {
361
+					package_flush_cache();
362
+		}
327 363
 
328
-		if ($single_file)
329
-			return false;
330
-		else
331
-			return $return;
332
-	}
333
-	catch (Exception $e)
364
+		if ($single_file) {
365
+					return false;
366
+		} else {
367
+					return $return;
368
+		}
369
+	} catch (Exception $e)
334 370
 	{
335 371
 		log_error($e->getMessage(), 'general', $e->getFile(), $e->getLine());
336 372
 		return false;
@@ -353,13 +389,15 @@  discard block
 block discarded – undo
353 389
 function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null)
354 390
 {
355 391
 	umask(0);
356
-	if ($destination !== null && !file_exists($destination) && !$single_file)
357
-		mktree($destination, 0777);
392
+	if ($destination !== null && !file_exists($destination) && !$single_file) {
393
+			mktree($destination, 0777);
394
+	}
358 395
 
359 396
 	// Look for the end of directory signature 0x06054b50
360 397
 	$data_ecr = explode("\x50\x4b\x05\x06", $data);
361
-	if (!isset($data_ecr[1]))
362
-		return false;
398
+	if (!isset($data_ecr[1])) {
399
+			return false;
400
+	}
363 401
 
364 402
 	$return = array();
365 403
 
@@ -374,8 +412,9 @@  discard block
 block discarded – undo
374 412
 	array_shift($file_sections);
375 413
 
376 414
 	// sections and count from the signature must match or the zip file is bad
377
-	if (count($file_sections) != $zip_info['files'])
378
-		return false;
415
+	if (count($file_sections) != $zip_info['files']) {
416
+			return false;
417
+	}
379 418
 
380 419
 	// go though each file in the archive
381 420
 	foreach ($file_sections as $data)
@@ -397,68 +436,79 @@  discard block
 block discarded – undo
397 436
 		}
398 437
 
399 438
 		// If this is a file, and it doesn't exist.... happy days!
400
-		if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename']))
401
-			$write_this = true;
439
+		if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) {
440
+					$write_this = true;
441
+		}
402 442
 		// If the file exists, we may not want to overwrite it.
403
-		elseif (substr($file_info['filename'], -1) != '/')
404
-			$write_this = $overwrite;
443
+		elseif (substr($file_info['filename'], -1) != '/') {
444
+					$write_this = $overwrite;
445
+		}
405 446
 		// This is a directory, so we're gonna want to create it. (probably...)
406 447
 		elseif ($destination !== null && !$single_file)
407 448
 		{
408 449
 			// Just a little accident prevention, don't mind me.
409 450
 			$file_info['filename'] = strtr($file_info['filename'], array('../' => '', '/..' => ''));
410 451
 
411
-			if (!file_exists($destination . '/' . $file_info['filename']))
412
-				mktree($destination . '/' . $file_info['filename'], 0777);
452
+			if (!file_exists($destination . '/' . $file_info['filename'])) {
453
+							mktree($destination . '/' . $file_info['filename'], 0777);
454
+			}
413 455
 			$write_this = false;
456
+		} else {
457
+					$write_this = false;
414 458
 		}
415
-		else
416
-			$write_this = false;
417 459
 
418 460
 		// Get the actual compressed data.
419 461
 		$file_info['data'] = substr($data, 26 + $file_info['filename_length'] + $file_info['extrafield_length']);
420 462
 
421 463
 		// Only inflate it if we need to ;)
422
-		if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size']))
423
-			$file_info['data'] = gzinflate($file_info['data']);
464
+		if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) {
465
+					$file_info['data'] = gzinflate($file_info['data']);
466
+		}
424 467
 
425 468
 		// Okay!  We can write this file, looks good from here...
426 469
 		if ($write_this && $destination !== null)
427 470
 		{
428
-			if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir'])))
429
-				mktree($file_info['dir'], 0777);
471
+			if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) {
472
+							mktree($file_info['dir'], 0777);
473
+			}
430 474
 
431 475
 			// If we're looking for a specific file, and this is it... ka-bam, baby.
432
-			if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename'])))
433
-				return $file_info['data'];
476
+			if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) {
477
+							return $file_info['data'];
478
+			}
434 479
 			// Oh?  Another file.  Fine.  You don't like this file, do you?  I know how it is.  Yeah... just go away.  No, don't apologize.  I know this file's just not *good enough* for you.
435
-			elseif ($single_file)
436
-				continue;
480
+			elseif ($single_file) {
481
+							continue;
482
+			}
437 483
 			// Don't really want this?
438
-			elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract))
439
-				continue;
484
+			elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) {
485
+							continue;
486
+			}
440 487
 
441 488
 			package_put_contents($destination . '/' . $file_info['filename'], $file_info['data']);
442 489
 		}
443 490
 
444
-		if (substr($file_info['filename'], -1, 1) != '/')
445
-			$return[] = array(
491
+		if (substr($file_info['filename'], -1, 1) != '/') {
492
+					$return[] = array(
446 493
 				'filename' => $file_info['filename'],
447 494
 				'md5' => md5($file_info['data']),
448 495
 				'preview' => substr($file_info['data'], 0, 100),
449 496
 				'size' => $file_info['size'],
450 497
 				'skipped' => false
451 498
 			);
499
+		}
452 500
 	}
453 501
 
454
-	if ($destination !== null && !$single_file)
455
-		package_flush_cache();
502
+	if ($destination !== null && !$single_file) {
503
+			package_flush_cache();
504
+	}
456 505
 
457
-	if ($single_file)
458
-		return false;
459
-	else
460
-		return $return;
461
-}
506
+	if ($single_file) {
507
+			return false;
508
+	} else {
509
+			return $return;
510
+	}
511
+	}
462 512
 
463 513
 /**
464 514
  * Checks the existence of a remote file since file_exists() does not do remote.
@@ -470,14 +520,16 @@  discard block
 block discarded – undo
470 520
 {
471 521
 	$a_url = parse_url($url);
472 522
 
473
-	if (!isset($a_url['scheme']))
474
-		return false;
523
+	if (!isset($a_url['scheme'])) {
524
+			return false;
525
+	}
475 526
 
476 527
 	// Attempt to connect...
477 528
 	$temp = '';
478 529
 	$fid = fsockopen($a_url['host'], !isset($a_url['port']) ? 80 : $a_url['port'], $temp, $temp, 8);
479
-	if (!$fid)
480
-		return false;
530
+	if (!$fid) {
531
+			return false;
532
+	}
481 533
 
482 534
 	fputs($fid, 'HEAD ' . $a_url['path'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . $a_url['host'] . "\r\n\r\n");
483 535
 	$head = fread($fid, 1024);
@@ -512,8 +564,9 @@  discard block
 block discarded – undo
512 564
 	while ($row = $smcFunc['db_fetch_assoc']($request))
513 565
 	{
514 566
 		// Already found this? If so don't add it twice!
515
-		if (in_array($row['package_id'], $found))
516
-			continue;
567
+		if (in_array($row['package_id'], $found)) {
568
+					continue;
569
+		}
517 570
 
518 571
 		$found[] = $row['package_id'];
519 572
 
@@ -548,19 +601,21 @@  discard block
 block discarded – undo
548 601
 	global $sourcedir, $packagesdir;
549 602
 
550 603
 	// Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.)
551
-	if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false)
552
-		$packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true);
553
-	else
604
+	if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) {
605
+			$packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true);
606
+	} else
554 607
 	{
555
-		if (!file_exists($packagesdir . '/' . $gzfilename))
556
-			return 'package_get_error_not_found';
608
+		if (!file_exists($packagesdir . '/' . $gzfilename)) {
609
+					return 'package_get_error_not_found';
610
+		}
557 611
 
558
-		if (is_file($packagesdir . '/' . $gzfilename))
559
-			$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true);
560
-		elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml'))
561
-			$packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml');
562
-		else
563
-			return 'package_get_error_missing_xml';
612
+		if (is_file($packagesdir . '/' . $gzfilename)) {
613
+					$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true);
614
+		} elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) {
615
+					$packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml');
616
+		} else {
617
+					return 'package_get_error_missing_xml';
618
+		}
564 619
 	}
565 620
 
566 621
 	// Nothing?
@@ -568,10 +623,11 @@  discard block
 block discarded – undo
568 623
 	{
569 624
 		// Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function
570 625
 		$packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/theme_info.xml', true);
571
-		if (!empty($packageInfo))
572
-			return 'package_get_error_is_theme';
573
-		else
574
-			return 'package_get_error_is_zero';
626
+		if (!empty($packageInfo)) {
627
+					return 'package_get_error_is_theme';
628
+		} else {
629
+					return 'package_get_error_is_zero';
630
+		}
575 631
 	}
576 632
 
577 633
 	// Parse package-info.xml into an xmlArray.
@@ -579,8 +635,9 @@  discard block
 block discarded – undo
579 635
 	$packageInfo = new xmlArray($packageInfo);
580 636
 
581 637
 	// @todo Error message of some sort?
582
-	if (!$packageInfo->exists('package-info[0]'))
583
-		return 'package_get_error_packageinfo_corrupt';
638
+	if (!$packageInfo->exists('package-info[0]')) {
639
+			return 'package_get_error_packageinfo_corrupt';
640
+	}
584 641
 
585 642
 	$packageInfo = $packageInfo->path('package-info[0]');
586 643
 
@@ -599,8 +656,9 @@  discard block
 block discarded – undo
599 656
 		}
600 657
 	}
601 658
 
602
-	if (!isset($package['type']))
603
-		$package['type'] = 'modification';
659
+	if (!isset($package['type'])) {
660
+			$package['type'] = 'modification';
661
+	}
604 662
 
605 663
 	return $package;
606 664
 }
@@ -653,15 +711,14 @@  discard block
 block discarded – undo
653 711
 					{
654 712
 						$ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => ''));
655 713
 						$package_ftp->chmod($ftp_file, $perms);
714
+					} else {
715
+											smf_chmod($file, $perms);
656 716
 					}
657
-					else
658
-						smf_chmod($file, $perms);
659 717
 
660 718
 					$new_permissions = @fileperms($file);
661 719
 					$result = $new_permissions == $perms ? 'success' : 'failure';
662 720
 					unset($_SESSION['pack_ftp']['original_perms'][$file]);
663
-				}
664
-				elseif ($do_change)
721
+				} elseif ($do_change)
665 722
 				{
666 723
 					$new_permissions = '';
667 724
 					$result = 'skipped';
@@ -777,8 +834,7 @@  discard block
 block discarded – undo
777 834
 
778 835
 			$context['sub_template'] = 'show_list';
779 836
 			$context['default_list'] = 'restore_file_permissions';
780
-		}
781
-		else
837
+		} else
782 838
 		{
783 839
 			unset($listOptions['columns']['result']);
784 840
 		}
@@ -788,12 +844,14 @@  discard block
 block discarded – undo
788 844
 		createList($listOptions);
789 845
 
790 846
 		// If we just restored permissions then whereever we are, we are now done and dusted.
791
-		if (!empty($_POST['restore_perms']))
792
-			obExit();
847
+		if (!empty($_POST['restore_perms'])) {
848
+					obExit();
849
+		}
793 850
 	}
794 851
 	// Otherwise, it's entirely irrelevant?
795
-	elseif ($restore_write_status)
796
-		return true;
852
+	elseif ($restore_write_status) {
853
+			return true;
854
+	}
797 855
 
798 856
 	// This is where we report what we got up to.
799 857
 	$return_data = array(
@@ -831,11 +889,12 @@  discard block
 block discarded – undo
831 889
 			if (!in_array($_POST['ftp_path'], array('', '/')))
832 890
 			{
833 891
 				$ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
834
-				if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/'))
835
-					$ftp_root = substr($ftp_root, 0, -1);
892
+				if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) {
893
+									$ftp_root = substr($ftp_root, 0, -1);
894
+				}
895
+			} else {
896
+							$ftp_root = $boarddir;
836 897
 			}
837
-			else
838
-				$ftp_root = $boarddir;
839 898
 
840 899
 			$_SESSION['pack_ftp'] = array(
841 900
 				'server' => $_POST['ftp_server'],
@@ -847,8 +906,9 @@  discard block
 block discarded – undo
847 906
 				'connected' => true,
848 907
 			);
849 908
 
850
-			if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path'])
851
-				updateSettings(array('package_path' => $_POST['ftp_path']));
909
+			if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
910
+							updateSettings(array('package_path' => $_POST['ftp_path']));
911
+			}
852 912
 
853 913
 			// This is now the primary connection.
854 914
 			$package_ftp = $ftp;
@@ -861,12 +921,13 @@  discard block
 block discarded – undo
861 921
 		foreach ($chmodFiles as $k => $file)
862 922
 		{
863 923
 			// Sometimes this can somehow happen maybe?
864
-			if (empty($file))
865
-				unset($chmodFiles[$k]);
924
+			if (empty($file)) {
925
+							unset($chmodFiles[$k]);
926
+			}
866 927
 			// Already writable?
867
-			elseif (@is_writable($file))
868
-				$return_data['files']['writable'][] = $file;
869
-			else
928
+			elseif (@is_writable($file)) {
929
+							$return_data['files']['writable'][] = $file;
930
+			} else
870 931
 			{
871 932
 				// Now try to change that.
872 933
 				$return_data['files'][package_chmod($file, 'writable', true) ? 'writable' : 'notwritable'][] = $file;
@@ -883,19 +944,21 @@  discard block
 block discarded – undo
883 944
 			{
884 945
 				require_once($sourcedir . '/Class-Package.php');
885 946
 				$ftp = new ftp_connection(null);
947
+			} elseif ($ftp->error !== false && !isset($ftp_error)) {
948
+							$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
886 949
 			}
887
-			elseif ($ftp->error !== false && !isset($ftp_error))
888
-				$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
889 950
 
890 951
 			list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
891 952
 
892
-			if ($found_path)
893
-				$_POST['ftp_path'] = $detect_path;
894
-			elseif (!isset($_POST['ftp_path']))
895
-				$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
953
+			if ($found_path) {
954
+							$_POST['ftp_path'] = $detect_path;
955
+			} elseif (!isset($_POST['ftp_path'])) {
956
+							$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
957
+			}
896 958
 
897
-			if (!isset($_POST['ftp_username']))
898
-				$_POST['ftp_username'] = $username;
959
+			if (!isset($_POST['ftp_username'])) {
960
+							$_POST['ftp_username'] = $username;
961
+			}
899 962
 		}
900 963
 
901 964
 		$context['package_ftp'] = array(
@@ -908,8 +971,9 @@  discard block
 block discarded – undo
908 971
 		);
909 972
 
910 973
 		// Which files failed?
911
-		if (!isset($context['notwritable_files']))
912
-			$context['notwritable_files'] = array();
974
+		if (!isset($context['notwritable_files'])) {
975
+					$context['notwritable_files'] = array();
976
+		}
913 977
 		$context['notwritable_files'] = array_merge($context['notwritable_files'], $return_data['files']['notwritable']);
914 978
 
915 979
 		// Sent here to die?
@@ -942,40 +1006,48 @@  discard block
 block discarded – undo
942 1006
 		foreach ($files as $k => $file)
943 1007
 		{
944 1008
 			// If this file doesn't exist, then we actually want to look at the directory, no?
945
-			if (!file_exists($file))
946
-				$file = dirname($file);
1009
+			if (!file_exists($file)) {
1010
+							$file = dirname($file);
1011
+			}
947 1012
 
948 1013
 			// This looks odd, but it's an attempt to work around PHP suExec.
949
-			if (!@is_writable($file))
950
-				smf_chmod($file, 0755);
951
-			if (!@is_writable($file))
952
-				smf_chmod($file, 0777);
953
-			if (!@is_writable(dirname($file)))
954
-				smf_chmod($file, 0755);
955
-			if (!@is_writable(dirname($file)))
956
-				smf_chmod($file, 0777);
1014
+			if (!@is_writable($file)) {
1015
+							smf_chmod($file, 0755);
1016
+			}
1017
+			if (!@is_writable($file)) {
1018
+							smf_chmod($file, 0777);
1019
+			}
1020
+			if (!@is_writable(dirname($file))) {
1021
+							smf_chmod($file, 0755);
1022
+			}
1023
+			if (!@is_writable(dirname($file))) {
1024
+							smf_chmod($file, 0777);
1025
+			}
957 1026
 
958 1027
 			$fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb');
959 1028
 			if (@is_writable($file) && $fp)
960 1029
 			{
961 1030
 				unset($files[$k]);
962
-				if (!is_dir($file))
963
-					fclose($fp);
964
-				else
965
-					closedir($fp);
1031
+				if (!is_dir($file)) {
1032
+									fclose($fp);
1033
+				} else {
1034
+									closedir($fp);
1035
+				}
966 1036
 			}
967 1037
 		}
968 1038
 
969 1039
 		// No FTP required!
970
-		if (empty($files))
971
-			return array();
1040
+		if (empty($files)) {
1041
+					return array();
1042
+		}
972 1043
 	}
973 1044
 
974 1045
 	// They've opted to not use FTP, and try anyway.
975 1046
 	if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false)
976 1047
 	{
977
-		if ($files === null)
978
-			return array();
1048
+		if ($files === null) {
1049
+					return array();
1050
+		}
979 1051
 
980 1052
 		foreach ($files as $k => $file)
981 1053
 		{
@@ -987,26 +1059,29 @@  discard block
 block discarded – undo
987 1059
 				smf_chmod($file, 0755);
988 1060
 			}
989 1061
 
990
-			if (!@is_writable($file))
991
-				smf_chmod($file, 0777);
992
-			if (!@is_writable(dirname($file)))
993
-				smf_chmod(dirname($file), 0777);
1062
+			if (!@is_writable($file)) {
1063
+							smf_chmod($file, 0777);
1064
+			}
1065
+			if (!@is_writable(dirname($file))) {
1066
+							smf_chmod(dirname($file), 0777);
1067
+			}
994 1068
 
995
-			if (@is_writable($file))
996
-				unset($files[$k]);
1069
+			if (@is_writable($file)) {
1070
+							unset($files[$k]);
1071
+			}
997 1072
 		}
998 1073
 
999 1074
 		return $files;
1000
-	}
1001
-	elseif (isset($_SESSION['pack_ftp']))
1075
+	} elseif (isset($_SESSION['pack_ftp']))
1002 1076
 	{
1003 1077
 		// Load the file containing the ftp_connection class.
1004 1078
 		require_once($sourcedir . '/Class-Package.php');
1005 1079
 
1006 1080
 		$package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password']));
1007 1081
 
1008
-		if ($files === null)
1009
-			return array();
1082
+		if ($files === null) {
1083
+					return array();
1084
+		}
1010 1085
 
1011 1086
 		foreach ($files as $k => $file)
1012 1087
 		{
@@ -1020,13 +1095,16 @@  discard block
 block discarded – undo
1020 1095
 				$package_ftp->chmod($ftp_file, 0755);
1021 1096
 			}
1022 1097
 
1023
-			if (!@is_writable($file))
1024
-				$package_ftp->chmod($ftp_file, 0777);
1025
-			if (!@is_writable(dirname($file)))
1026
-				$package_ftp->chmod(dirname($ftp_file), 0777);
1098
+			if (!@is_writable($file)) {
1099
+							$package_ftp->chmod($ftp_file, 0777);
1100
+			}
1101
+			if (!@is_writable(dirname($file))) {
1102
+							$package_ftp->chmod(dirname($ftp_file), 0777);
1103
+			}
1027 1104
 
1028
-			if (@is_writable($file))
1029
-				unset($files[$k]);
1105
+			if (@is_writable($file)) {
1106
+							unset($files[$k]);
1107
+			}
1030 1108
 		}
1031 1109
 
1032 1110
 		return $files;
@@ -1038,8 +1116,7 @@  discard block
 block discarded – undo
1038 1116
 
1039 1117
 		$files = packageRequireFTP($destination_url, $files, $return);
1040 1118
 		return $files;
1041
-	}
1042
-	elseif (isset($_POST['ftp_username']))
1119
+	} elseif (isset($_POST['ftp_username']))
1043 1120
 	{
1044 1121
 		require_once($sourcedir . '/Class-Package.php');
1045 1122
 		$ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']);
@@ -1061,19 +1138,21 @@  discard block
 block discarded – undo
1061 1138
 		{
1062 1139
 			require_once($sourcedir . '/Class-Package.php');
1063 1140
 			$ftp = new ftp_connection(null);
1141
+		} elseif ($ftp->error !== false && !isset($ftp_error)) {
1142
+					$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
1064 1143
 		}
1065
-		elseif ($ftp->error !== false && !isset($ftp_error))
1066
-			$ftp_error = $ftp->last_message === null ? '' : $ftp->last_message;
1067 1144
 
1068 1145
 		list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir);
1069 1146
 
1070
-		if ($found_path)
1071
-			$_POST['ftp_path'] = $detect_path;
1072
-		elseif (!isset($_POST['ftp_path']))
1073
-			$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
1147
+		if ($found_path) {
1148
+					$_POST['ftp_path'] = $detect_path;
1149
+		} elseif (!isset($_POST['ftp_path'])) {
1150
+					$_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path;
1151
+		}
1074 1152
 
1075
-		if (!isset($_POST['ftp_username']))
1076
-			$_POST['ftp_username'] = $username;
1153
+		if (!isset($_POST['ftp_username'])) {
1154
+					$_POST['ftp_username'] = $username;
1155
+		}
1077 1156
 
1078 1157
 		$context['package_ftp'] = array(
1079 1158
 			'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'),
@@ -1085,23 +1164,24 @@  discard block
 block discarded – undo
1085 1164
 		);
1086 1165
 
1087 1166
 		// If we're returning dump out here.
1088
-		if ($return)
1089
-			return $files;
1167
+		if ($return) {
1168
+					return $files;
1169
+		}
1090 1170
 
1091 1171
 		$context['page_title'] = $txt['package_ftp_necessary'];
1092 1172
 		$context['sub_template'] = 'ftp_required';
1093 1173
 		obExit();
1094
-	}
1095
-	else
1174
+	} else
1096 1175
 	{
1097 1176
 		if (!in_array($_POST['ftp_path'], array('', '/')))
1098 1177
 		{
1099 1178
 			$ftp_root = strtr($boarddir, array($_POST['ftp_path'] => ''));
1100
-			if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/'))
1101
-				$ftp_root = substr($ftp_root, 0, -1);
1179
+			if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) {
1180
+							$ftp_root = substr($ftp_root, 0, -1);
1181
+			}
1182
+		} else {
1183
+					$ftp_root = $boarddir;
1102 1184
 		}
1103
-		else
1104
-			$ftp_root = $boarddir;
1105 1185
 
1106 1186
 		$_SESSION['pack_ftp'] = array(
1107 1187
 			'server' => $_POST['ftp_server'],
@@ -1112,8 +1192,9 @@  discard block
 block discarded – undo
1112 1192
 			'root' => $ftp_root,
1113 1193
 		);
1114 1194
 
1115
-		if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path'])
1116
-			updateSettings(array('package_path' => $_POST['ftp_path']));
1195
+		if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) {
1196
+					updateSettings(array('package_path' => $_POST['ftp_path']));
1197
+		}
1117 1198
 
1118 1199
 		$files = packageRequireFTP($destination_url, $files, $return);
1119 1200
 	}
@@ -1141,16 +1222,18 @@  discard block
 block discarded – undo
1141 1222
 	global $packagesdir, $forum_version, $context, $temp_path, $language, $smcFunc;
1142 1223
 
1143 1224
 	// Mayday!  That action doesn't exist!!
1144
-	if (empty($packageXML) || !$packageXML->exists($method))
1145
-		return array();
1225
+	if (empty($packageXML) || !$packageXML->exists($method)) {
1226
+			return array();
1227
+	}
1146 1228
 
1147 1229
 	// We haven't found the package script yet...
1148 1230
 	$script = false;
1149 1231
 	$the_version = strtr($forum_version, array('SMF ' => ''));
1150 1232
 
1151 1233
 	// Emulation support...
1152
-	if (!empty($_SESSION['version_emulate']))
1153
-		$the_version = $_SESSION['version_emulate'];
1234
+	if (!empty($_SESSION['version_emulate'])) {
1235
+			$the_version = $_SESSION['version_emulate'];
1236
+	}
1154 1237
 
1155 1238
 	// Single package emulation
1156 1239
 	if (!empty($_REQUEST['ve']) && !empty($_REQUEST['package']))
@@ -1158,8 +1241,9 @@  discard block
 block discarded – undo
1158 1241
 		$the_version = $_REQUEST['ve'];
1159 1242
 		$_SESSION['single_version_emulate'][$_REQUEST['package']] = $the_version;
1160 1243
 	}
1161
-	if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']])))
1162
-		$the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']];
1244
+	if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) {
1245
+			$the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']];
1246
+	}
1163 1247
 
1164 1248
 	// Get all the versions of this method and find the right one.
1165 1249
 	$these_methods = $packageXML->set($method);
@@ -1169,16 +1253,18 @@  discard block
 block discarded – undo
1169 1253
 		if ($this_method->exists('@for'))
1170 1254
 		{
1171 1255
 			// Don't keep going if this won't work for this version of SMF.
1172
-			if (!matchPackageVersion($the_version, $this_method->fetch('@for')))
1173
-				continue;
1256
+			if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) {
1257
+							continue;
1258
+			}
1174 1259
 		}
1175 1260
 
1176 1261
 		// Upgrades may go from a certain old version of the mod.
1177 1262
 		if ($method == 'upgrade' && $this_method->exists('@from'))
1178 1263
 		{
1179 1264
 			// Well, this is for the wrong old version...
1180
-			if (!matchPackageVersion($previous_version, $this_method->fetch('@from')))
1181
-				continue;
1265
+			if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) {
1266
+							continue;
1267
+			}
1182 1268
 		}
1183 1269
 
1184 1270
 		// We've found it!
@@ -1187,8 +1273,9 @@  discard block
 block discarded – undo
1187 1273
 	}
1188 1274
 
1189 1275
 	// Bad news, a matching script wasn't found!
1190
-	if (!($script instanceof xmlArray))
1191
-		return array();
1276
+	if (!($script instanceof xmlArray)) {
1277
+			return array();
1278
+	}
1192 1279
 
1193 1280
 	// Find all the actions in this method - in theory, these should only be allowed actions. (* means all.)
1194 1281
 	$actions = $script->set('*');
@@ -1217,12 +1304,12 @@  discard block
 block discarded – undo
1217 1304
 					if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language) || (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language))
1218 1305
 					{
1219 1306
 						// In case the user put the blocks in the wrong order.
1220
-						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default')
1221
-							$context[$type][] = 'default';
1307
+						if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') {
1308
+													$context[$type][] = 'default';
1309
+						}
1222 1310
 
1223 1311
 						$context[$type]['selected'] = $smcFunc['htmlspecialchars']($action->fetch('@lang'));
1224
-					}
1225
-					else
1312
+					} else
1226 1313
 					{
1227 1314
 						// We don't want this now, but we'll allow the user to select to read it.
1228 1315
 						$context[$type][] = $smcFunc['htmlspecialchars']($action->fetch('@lang'));
@@ -1237,9 +1324,9 @@  discard block
 block discarded – undo
1237 1324
 					{
1238 1325
 						$context[$type][] = 'default';
1239 1326
 						continue;
1327
+					} else {
1328
+											$context[$type]['selected'] = 'default';
1240 1329
 					}
1241
-					else
1242
-						$context[$type]['selected'] = 'default';
1243 1330
 				}
1244 1331
 			}
1245 1332
 
@@ -1249,9 +1336,9 @@  discard block
 block discarded – undo
1249 1336
 				$filename = $temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, array('readme', 'redirect', 'license')) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod'));
1250 1337
 				package_put_contents($filename, $action->fetch('.'));
1251 1338
 				$filename = strtr($filename, array($temp_path => ''));
1339
+			} else {
1340
+							$filename = $action->fetch('.');
1252 1341
 			}
1253
-			else
1254
-				$filename = $action->fetch('.');
1255 1342
 
1256 1343
 			$return[] = array(
1257 1344
 				'type' => $actionType,
@@ -1266,8 +1353,7 @@  discard block
 block discarded – undo
1266 1353
 			);
1267 1354
 
1268 1355
 			continue;
1269
-		}
1270
-		elseif ($actionType == 'hook')
1356
+		} elseif ($actionType == 'hook')
1271 1357
 		{
1272 1358
 			$return[] = array(
1273 1359
 				'type' => $actionType,
@@ -1279,16 +1365,16 @@  discard block
 block discarded – undo
1279 1365
 				'description' => '',
1280 1366
 			);
1281 1367
 			continue;
1282
-		}
1283
-		elseif ($actionType == 'credits')
1368
+		} elseif ($actionType == 'credits')
1284 1369
 		{
1285 1370
 			// quick check of any supplied url
1286 1371
 			$url = $action->exists('@url') ? $action->fetch('@url') : '';
1287 1372
 			if (strlen(trim($url)) > 0 && substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')
1288 1373
 			{
1289 1374
 				$url = 'http://' . $url;
1290
-				if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://'))
1291
-					$url = '';
1375
+				if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) {
1376
+									$url = '';
1377
+				}
1292 1378
 			}
1293 1379
 
1294 1380
 			$return[] = array(
@@ -1300,8 +1386,7 @@  discard block
 block discarded – undo
1300 1386
 				'title' => $action->fetch('.'),
1301 1387
 			);
1302 1388
 			continue;
1303
-		}
1304
-		elseif ($actionType == 'requires')
1389
+		} elseif ($actionType == 'requires')
1305 1390
 		{
1306 1391
 			$return[] = array(
1307 1392
 				'type' => $actionType,
@@ -1310,14 +1395,12 @@  discard block
 block discarded – undo
1310 1395
 				'description' => '',
1311 1396
 			);
1312 1397
 			continue;
1313
-		}
1314
-		elseif ($actionType == 'error')
1398
+		} elseif ($actionType == 'error')
1315 1399
 		{
1316 1400
 			$return[] = array(
1317 1401
 				'type' => 'error',
1318 1402
 			);
1319
-		}
1320
-		elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir')))
1403
+		} elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir')))
1321 1404
 		{
1322 1405
 			$this_action = &$return[];
1323 1406
 			$this_action = array(
@@ -1331,8 +1414,7 @@  discard block
 block discarded – undo
1331 1414
 			{
1332 1415
 				$this_action['unparsed_destination'] = $action->fetch('@destination');
1333 1416
 				$this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']);
1334
-			}
1335
-			else
1417
+			} else
1336 1418
 			{
1337 1419
 				$this_action['unparsed_filename'] = $this_action['filename'];
1338 1420
 				$this_action['filename'] = parse_path($this_action['filename']);
@@ -1341,10 +1423,11 @@  discard block
 block discarded – undo
1341 1423
 			// If we're moving or requiring (copying) a file.
1342 1424
 			if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require')
1343 1425
 			{
1344
-				if ($action->exists('@from'))
1345
-					$this_action['source'] = parse_path($action->fetch('@from'));
1346
-				else
1347
-					$this_action['source'] = $temp_path . $this_action['filename'];
1426
+				if ($action->exists('@from')) {
1427
+									$this_action['source'] = parse_path($action->fetch('@from'));
1428
+				} else {
1429
+									$this_action['source'] = $temp_path . $this_action['filename'];
1430
+				}
1348 1431
 			}
1349 1432
 
1350 1433
 			// Check if these things can be done. (chmod's etc.)
@@ -1353,22 +1436,23 @@  discard block
 block discarded – undo
1353 1436
 				if (!mktree($this_action['destination'], false))
1354 1437
 				{
1355 1438
 					$temp = $this_action['destination'];
1356
-					while (!file_exists($temp) && strlen($temp) > 1)
1357
-						$temp = dirname($temp);
1439
+					while (!file_exists($temp) && strlen($temp) > 1) {
1440
+											$temp = dirname($temp);
1441
+					}
1358 1442
 
1359 1443
 					$return[] = array(
1360 1444
 						'type' => 'chmod',
1361 1445
 						'filename' => $temp
1362 1446
 					);
1363 1447
 				}
1364
-			}
1365
-			elseif ($actionType == 'create-file')
1448
+			} elseif ($actionType == 'create-file')
1366 1449
 			{
1367 1450
 				if (!mktree(dirname($this_action['destination']), false))
1368 1451
 				{
1369 1452
 					$temp = dirname($this_action['destination']);
1370
-					while (!file_exists($temp) && strlen($temp) > 1)
1371
-						$temp = dirname($temp);
1453
+					while (!file_exists($temp) && strlen($temp) > 1) {
1454
+											$temp = dirname($temp);
1455
+					}
1372 1456
 
1373 1457
 					$return[] = array(
1374 1458
 						'type' => 'chmod',
@@ -1376,36 +1460,38 @@  discard block
 block discarded – undo
1376 1460
 					);
1377 1461
 				}
1378 1462
 
1379
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1380
-					$return[] = array(
1463
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1464
+									$return[] = array(
1381 1465
 						'type' => 'chmod',
1382 1466
 						'filename' => $this_action['destination']
1383 1467
 					);
1384
-			}
1385
-			elseif ($actionType == 'require-dir')
1468
+				}
1469
+			} elseif ($actionType == 'require-dir')
1386 1470
 			{
1387 1471
 				if (!mktree($this_action['destination'], false))
1388 1472
 				{
1389 1473
 					$temp = $this_action['destination'];
1390
-					while (!file_exists($temp) && strlen($temp) > 1)
1391
-						$temp = dirname($temp);
1474
+					while (!file_exists($temp) && strlen($temp) > 1) {
1475
+											$temp = dirname($temp);
1476
+					}
1392 1477
 
1393 1478
 					$return[] = array(
1394 1479
 						'type' => 'chmod',
1395 1480
 						'filename' => $temp
1396 1481
 					);
1397 1482
 				}
1398
-			}
1399
-			elseif ($actionType == 'require-file')
1483
+			} elseif ($actionType == 'require-file')
1400 1484
 			{
1401
-				if ($action->exists('@theme'))
1402
-					$this_action['theme_action'] = $action->fetch('@theme');
1485
+				if ($action->exists('@theme')) {
1486
+									$this_action['theme_action'] = $action->fetch('@theme');
1487
+				}
1403 1488
 
1404 1489
 				if (!mktree(dirname($this_action['destination']), false))
1405 1490
 				{
1406 1491
 					$temp = dirname($this_action['destination']);
1407
-					while (!file_exists($temp) && strlen($temp) > 1)
1408
-						$temp = dirname($temp);
1492
+					while (!file_exists($temp) && strlen($temp) > 1) {
1493
+											$temp = dirname($temp);
1494
+					}
1409 1495
 
1410 1496
 					$return[] = array(
1411 1497
 						'type' => 'chmod',
@@ -1413,19 +1499,20 @@  discard block
 block discarded – undo
1413 1499
 					);
1414 1500
 				}
1415 1501
 
1416
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1417
-					$return[] = array(
1502
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1503
+									$return[] = array(
1418 1504
 						'type' => 'chmod',
1419 1505
 						'filename' => $this_action['destination']
1420 1506
 					);
1421
-			}
1422
-			elseif ($actionType == 'move-dir' || $actionType == 'move-file')
1507
+				}
1508
+			} elseif ($actionType == 'move-dir' || $actionType == 'move-file')
1423 1509
 			{
1424 1510
 				if (!mktree(dirname($this_action['destination']), false))
1425 1511
 				{
1426 1512
 					$temp = dirname($this_action['destination']);
1427
-					while (!file_exists($temp) && strlen($temp) > 1)
1428
-						$temp = dirname($temp);
1513
+					while (!file_exists($temp) && strlen($temp) > 1) {
1514
+											$temp = dirname($temp);
1515
+					}
1429 1516
 
1430 1517
 					$return[] = array(
1431 1518
 						'type' => 'chmod',
@@ -1433,30 +1520,30 @@  discard block
 block discarded – undo
1433 1520
 					);
1434 1521
 				}
1435 1522
 
1436
-				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination']))))
1437
-					$return[] = array(
1523
+				if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) {
1524
+									$return[] = array(
1438 1525
 						'type' => 'chmod',
1439 1526
 						'filename' => $this_action['destination']
1440 1527
 					);
1441
-			}
1442
-			elseif ($actionType == 'remove-dir')
1528
+				}
1529
+			} elseif ($actionType == 'remove-dir')
1443 1530
 			{
1444
-				if (!is_writable($this_action['filename']) && file_exists($this_action['filename']))
1445
-					$return[] = array(
1531
+				if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) {
1532
+									$return[] = array(
1446 1533
 						'type' => 'chmod',
1447 1534
 						'filename' => $this_action['filename']
1448 1535
 					);
1449
-			}
1450
-			elseif ($actionType == 'remove-file')
1536
+				}
1537
+			} elseif ($actionType == 'remove-file')
1451 1538
 			{
1452
-				if (!is_writable($this_action['filename']) && file_exists($this_action['filename']))
1453
-					$return[] = array(
1539
+				if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) {
1540
+									$return[] = array(
1454 1541
 						'type' => 'chmod',
1455 1542
 						'filename' => $this_action['filename']
1456 1543
 					);
1544
+				}
1457 1545
 			}
1458
-		}
1459
-		else
1546
+		} else
1460 1547
 		{
1461 1548
 			$return[] = array(
1462 1549
 				'type' => 'error',
@@ -1467,8 +1554,9 @@  discard block
 block discarded – undo
1467 1554
 	}
1468 1555
 
1469 1556
 	// Only testing - just return a list of things to be done.
1470
-	if ($testing_only)
1471
-		return $return;
1557
+	if ($testing_only) {
1558
+			return $return;
1559
+	}
1472 1560
 
1473 1561
 	umask(0);
1474 1562
 
@@ -1476,78 +1564,81 @@  discard block
 block discarded – undo
1476 1564
 	$not_done = array(array('type' => '!'));
1477 1565
 	foreach ($return as $action)
1478 1566
 	{
1479
-		if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits')))
1480
-			$not_done[] = $action;
1567
+		if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) {
1568
+					$not_done[] = $action;
1569
+		}
1481 1570
 
1482 1571
 		if ($action['type'] == 'create-dir')
1483 1572
 		{
1484
-			if (!mktree($action['destination'], 0755) || !is_writable($action['destination']))
1485
-				$failure |= !mktree($action['destination'], 0777);
1486
-		}
1487
-		elseif ($action['type'] == 'create-file')
1573
+			if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) {
1574
+							$failure |= !mktree($action['destination'], 0777);
1575
+			}
1576
+		} elseif ($action['type'] == 'create-file')
1488 1577
 		{
1489
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1490
-				$failure |= !mktree(dirname($action['destination']), 0777);
1578
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1579
+							$failure |= !mktree(dirname($action['destination']), 0777);
1580
+			}
1491 1581
 
1492 1582
 			// Create an empty file.
1493 1583
 			package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only);
1494 1584
 
1495
-			if (!file_exists($action['destination']))
1496
-				$failure = true;
1497
-		}
1498
-		elseif ($action['type'] == 'require-dir')
1585
+			if (!file_exists($action['destination'])) {
1586
+							$failure = true;
1587
+			}
1588
+		} elseif ($action['type'] == 'require-dir')
1499 1589
 		{
1500 1590
 			copytree($action['source'], $action['destination']);
1501 1591
 			// Any other theme folders?
1502
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']]))
1503
-				foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1592
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) {
1593
+							foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1504 1594
 					copytree($action['source'], $theme_destination);
1505
-		}
1506
-		elseif ($action['type'] == 'require-file')
1595
+			}
1596
+		} elseif ($action['type'] == 'require-file')
1507 1597
 		{
1508
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1509
-				$failure |= !mktree(dirname($action['destination']), 0777);
1598
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1599
+							$failure |= !mktree(dirname($action['destination']), 0777);
1600
+			}
1510 1601
 
1511 1602
 			package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only);
1512 1603
 
1513 1604
 			$failure |= !copy($action['source'], $action['destination']);
1514 1605
 
1515 1606
 			// Any other theme files?
1516
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']]))
1517
-				foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1607
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) {
1608
+							foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination)
1518 1609
 				{
1519 1610
 					if (!mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination)))
1520 1611
 						$failure |= !mktree(dirname($theme_destination), 0777);
1612
+			}
1521 1613
 
1522 1614
 					package_put_contents($theme_destination, package_get_contents($action['source']), $testing_only);
1523 1615
 
1524 1616
 					$failure |= !copy($action['source'], $theme_destination);
1525 1617
 				}
1526
-		}
1527
-		elseif ($action['type'] == 'move-file')
1618
+		} elseif ($action['type'] == 'move-file')
1528 1619
 		{
1529
-			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination'])))
1530
-				$failure |= !mktree(dirname($action['destination']), 0777);
1620
+			if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) {
1621
+							$failure |= !mktree(dirname($action['destination']), 0777);
1622
+			}
1531 1623
 
1532 1624
 			$failure |= !rename($action['source'], $action['destination']);
1533
-		}
1534
-		elseif ($action['type'] == 'move-dir')
1625
+		} elseif ($action['type'] == 'move-dir')
1535 1626
 		{
1536
-			if (!mktree($action['destination'], 0755) || !is_writable($action['destination']))
1537
-				$failure |= !mktree($action['destination'], 0777);
1627
+			if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) {
1628
+							$failure |= !mktree($action['destination'], 0777);
1629
+			}
1538 1630
 
1539 1631
 			$failure |= !rename($action['source'], $action['destination']);
1540
-		}
1541
-		elseif ($action['type'] == 'remove-dir')
1632
+		} elseif ($action['type'] == 'remove-dir')
1542 1633
 		{
1543 1634
 			deltree($action['filename']);
1544 1635
 
1545 1636
 			// Any other theme folders?
1546
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']]))
1547
-				foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1637
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) {
1638
+							foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1548 1639
 					deltree($theme_destination);
1549
-		}
1550
-		elseif ($action['type'] == 'remove-file')
1640
+			}
1641
+		} elseif ($action['type'] == 'remove-file')
1551 1642
 		{
1552 1643
 			// Make sure the file exists before deleting it.
1553 1644
 			if (file_exists($action['filename']))
@@ -1556,16 +1647,18 @@  discard block
 block discarded – undo
1556 1647
 				$failure |= !unlink($action['filename']);
1557 1648
 			}
1558 1649
 			// The file that was supposed to be deleted couldn't be found.
1559
-			else
1560
-				$failure = true;
1650
+			else {
1651
+							$failure = true;
1652
+			}
1561 1653
 
1562 1654
 			// Any other theme folders?
1563
-			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']]))
1564
-				foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1655
+			if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) {
1656
+							foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination)
1565 1657
 					if (file_exists($theme_destination))
1566 1658
 						$failure |= !unlink($theme_destination);
1567
-					else
1568
-						$failure = true;
1659
+			} else {
1660
+											$failure = true;
1661
+					}
1569 1662
 		}
1570 1663
 	}
1571 1664
 
@@ -1587,8 +1680,9 @@  discard block
 block discarded – undo
1587 1680
 {
1588 1681
 	static $near_version = 0;
1589 1682
 
1590
-	if ($reset)
1591
-		$near_version = 0;
1683
+	if ($reset) {
1684
+			$near_version = 0;
1685
+	}
1592 1686
 
1593 1687
 	// Normalize the $versions while we remove our previous Doh!
1594 1688
 	$versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions)));
@@ -1597,16 +1691,19 @@  discard block
 block discarded – undo
1597 1691
 	foreach ($versions as $for)
1598 1692
 	{
1599 1693
 		// Adjust for those wild cards
1600
-		if (strpos($for, '*') !== false)
1601
-			$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1694
+		if (strpos($for, '*') !== false) {
1695
+					$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1696
+		}
1602 1697
 
1603 1698
 		// If we have a range, grab the lower value, done this way so it looks normal-er to the user e.g. 2.0 vs 2.0.99
1604
-		if (strpos($for, '-') !== false)
1605
-			list ($for, $higher) = explode('-', $for);
1699
+		if (strpos($for, '-') !== false) {
1700
+					list ($for, $higher) = explode('-', $for);
1701
+		}
1606 1702
 
1607 1703
 		// Do the compare, if the for is greater, than what we have but not greater than what we are running .....
1608
-		if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1)
1609
-			$near_version = $for;
1704
+		if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) {
1705
+					$near_version = $for;
1706
+		}
1610 1707
 	}
1611 1708
 
1612 1709
 	return !empty($near_version) ? $near_version : false;
@@ -1629,15 +1726,17 @@  discard block
 block discarded – undo
1629 1726
 	$versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions)));
1630 1727
 
1631 1728
 	// Perhaps we do accept anything?
1632
-	if (in_array('all', $versions))
1633
-		return true;
1729
+	if (in_array('all', $versions)) {
1730
+			return true;
1731
+	}
1634 1732
 
1635 1733
 	// Loop through each version.
1636 1734
 	foreach ($versions as $for)
1637 1735
 	{
1638 1736
 		// Wild card spotted?
1639
-		if (strpos($for, '*') !== false)
1640
-			$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1737
+		if (strpos($for, '*') !== false) {
1738
+					$for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for);
1739
+		}
1641 1740
 
1642 1741
 		// Do we have a range?
1643 1742
 		if (strpos($for, '-') !== false)
@@ -1645,12 +1744,14 @@  discard block
 block discarded – undo
1645 1744
 			list ($lower, $upper) = explode('-', $for);
1646 1745
 
1647 1746
 			// Compare the version against lower and upper bounds.
1648
-			if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1)
1649
-				return true;
1747
+			if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) {
1748
+							return true;
1749
+			}
1650 1750
 		}
1651 1751
 		// Otherwise check if they are equal...
1652
-		elseif (compareVersions($version, $for) === 0)
1653
-			return true;
1752
+		elseif (compareVersions($version, $for) === 0) {
1753
+					return true;
1754
+		}
1654 1755
 	}
1655 1756
 
1656 1757
 	return false;
@@ -1690,12 +1791,14 @@  discard block
 block discarded – undo
1690 1791
 	}
1691 1792
 
1692 1793
 	// Are they the same, perhaps?
1693
-	if ($versions[1] === $versions[2])
1694
-		return 0;
1794
+	if ($versions[1] === $versions[2]) {
1795
+			return 0;
1796
+	}
1695 1797
 
1696 1798
 	// Get version numbering categories...
1697
-	if (!isset($categories))
1698
-		$categories = array_keys($versions[1]);
1799
+	if (!isset($categories)) {
1800
+			$categories = array_keys($versions[1]);
1801
+	}
1699 1802
 
1700 1803
 	// Loop through each category.
1701 1804
 	foreach ($categories as $category)
@@ -1705,13 +1808,15 @@  discard block
 block discarded – undo
1705 1808
 		{
1706 1809
 			// Dev builds are a problematic exception.
1707 1810
 			// (stable) dev < (stable) but (unstable) dev = (unstable)
1708
-			if ($category == 'type')
1709
-				return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1);
1710
-			elseif ($category == 'dev')
1711
-				return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0);
1811
+			if ($category == 'type') {
1812
+							return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1);
1813
+			} elseif ($category == 'dev') {
1814
+							return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0);
1815
+			}
1712 1816
 			// Otherwise a simple comparison.
1713
-			else
1714
-				return $versions[1][$category] > $versions[2][$category] ? 1 : -1;
1817
+			else {
1818
+							return $versions[1][$category] > $versions[2][$category] ? 1 : -1;
1819
+			}
1715 1820
 		}
1716 1821
 	}
1717 1822
 
@@ -1745,11 +1850,13 @@  discard block
 block discarded – undo
1745 1850
 	);
1746 1851
 
1747 1852
 	// do we parse in a package directory?
1748
-	if (!empty($temp_path))
1749
-		$dirs['$package'] = $temp_path;
1853
+	if (!empty($temp_path)) {
1854
+			$dirs['$package'] = $temp_path;
1855
+	}
1750 1856
 
1751
-	if (strlen($path) == 0)
1752
-		trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR);
1857
+	if (strlen($path) == 0) {
1858
+			trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR);
1859
+	}
1753 1860
 
1754 1861
 	return strtr($path, $dirs);
1755 1862
 }
@@ -1766,8 +1873,9 @@  discard block
 block discarded – undo
1766 1873
 	/** @var ftp_connection $package_ftp */
1767 1874
 	global $package_ftp;
1768 1875
 
1769
-	if (!file_exists($dir))
1770
-		return;
1876
+	if (!file_exists($dir)) {
1877
+			return;
1878
+	}
1771 1879
 
1772 1880
 	$current_dir = @opendir($dir);
1773 1881
 	if ($current_dir == false)
@@ -1775,8 +1883,9 @@  discard block
 block discarded – undo
1775 1883
 		if ($delete_dir && isset($package_ftp))
1776 1884
 		{
1777 1885
 			$ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
1778
-			if (!is_dir($dir))
1779
-				$package_ftp->chmod($ftp_file, 0777);
1886
+			if (!is_dir($dir)) {
1887
+							$package_ftp->chmod($ftp_file, 0777);
1888
+			}
1780 1889
 			$package_ftp->unlink($ftp_file);
1781 1890
 		}
1782 1891
 
@@ -1785,26 +1894,28 @@  discard block
 block discarded – undo
1785 1894
 
1786 1895
 	while ($entryname = readdir($current_dir))
1787 1896
 	{
1788
-		if (in_array($entryname, array('.', '..')))
1789
-			continue;
1897
+		if (in_array($entryname, array('.', '..'))) {
1898
+					continue;
1899
+		}
1790 1900
 
1791
-		if (is_dir($dir . '/' . $entryname))
1792
-			deltree($dir . '/' . $entryname);
1793
-		else
1901
+		if (is_dir($dir . '/' . $entryname)) {
1902
+					deltree($dir . '/' . $entryname);
1903
+		} else
1794 1904
 		{
1795 1905
 			// Here, 755 doesn't really matter since we're deleting it anyway.
1796 1906
 			if (isset($package_ftp))
1797 1907
 			{
1798 1908
 				$ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
1799 1909
 
1800
-				if (!is_writable($dir . '/' . $entryname))
1801
-					$package_ftp->chmod($ftp_file, 0777);
1910
+				if (!is_writable($dir . '/' . $entryname)) {
1911
+									$package_ftp->chmod($ftp_file, 0777);
1912
+				}
1802 1913
 				$package_ftp->unlink($ftp_file);
1803
-			}
1804
-			else
1914
+			} else
1805 1915
 			{
1806
-				if (!is_writable($dir . '/' . $entryname))
1807
-					smf_chmod($dir . '/' . $entryname, 0777);
1916
+				if (!is_writable($dir . '/' . $entryname)) {
1917
+									smf_chmod($dir . '/' . $entryname, 0777);
1918
+				}
1808 1919
 				unlink($dir . '/' . $entryname);
1809 1920
 			}
1810 1921
 		}
@@ -1817,14 +1928,15 @@  discard block
 block discarded – undo
1817 1928
 		if (isset($package_ftp))
1818 1929
 		{
1819 1930
 			$ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => ''));
1820
-			if (!is_writable($dir . '/' . $entryname))
1821
-				$package_ftp->chmod($ftp_file, 0777);
1931
+			if (!is_writable($dir . '/' . $entryname)) {
1932
+							$package_ftp->chmod($ftp_file, 0777);
1933
+			}
1822 1934
 			$package_ftp->unlink($ftp_file);
1823
-		}
1824
-		else
1935
+		} else
1825 1936
 		{
1826
-			if (!is_writable($dir))
1827
-				smf_chmod($dir, 0777);
1937
+			if (!is_writable($dir)) {
1938
+							smf_chmod($dir, 0777);
1939
+			}
1828 1940
 			@rmdir($dir);
1829 1941
 		}
1830 1942
 	}
@@ -1847,10 +1959,11 @@  discard block
 block discarded – undo
1847 1959
 	{
1848 1960
 		if (!is_writable($strPath) && $mode !== false)
1849 1961
 		{
1850
-			if (isset($package_ftp))
1851
-				$package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode);
1852
-			else
1853
-				smf_chmod($strPath, $mode);
1962
+			if (isset($package_ftp)) {
1963
+							$package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode);
1964
+			} else {
1965
+							smf_chmod($strPath, $mode);
1966
+			}
1854 1967
 		}
1855 1968
 
1856 1969
 		$test = @opendir($strPath);
@@ -1858,36 +1971,37 @@  discard block
 block discarded – undo
1858 1971
 		{
1859 1972
 			closedir($test);
1860 1973
 			return is_writable($strPath);
1974
+		} else {
1975
+					return false;
1861 1976
 		}
1862
-		else
1863
-			return false;
1864 1977
 	}
1865 1978
 	// Is this an invalid path and/or we can't make the directory?
1866
-	if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode))
1867
-		return false;
1979
+	if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) {
1980
+			return false;
1981
+	}
1868 1982
 
1869 1983
 	if (!is_writable(dirname($strPath)) && $mode !== false)
1870 1984
 	{
1871
-		if (isset($package_ftp))
1872
-			$package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode);
1873
-		else
1874
-			smf_chmod(dirname($strPath), $mode);
1985
+		if (isset($package_ftp)) {
1986
+					$package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode);
1987
+		} else {
1988
+					smf_chmod(dirname($strPath), $mode);
1989
+		}
1875 1990
 	}
1876 1991
 
1877
-	if ($mode !== false && isset($package_ftp))
1878
-		return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')));
1879
-	elseif ($mode === false)
1992
+	if ($mode !== false && isset($package_ftp)) {
1993
+			return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')));
1994
+	} elseif ($mode === false)
1880 1995
 	{
1881 1996
 		$test = @opendir(dirname($strPath));
1882 1997
 		if ($test)
1883 1998
 		{
1884 1999
 			closedir($test);
1885 2000
 			return true;
2001
+		} else {
2002
+					return false;
1886 2003
 		}
1887
-		else
1888
-			return false;
1889
-	}
1890
-	else
2004
+	} else
1891 2005
 	{
1892 2006
 		@mkdir($strPath, $mode);
1893 2007
 		$test = @opendir($strPath);
@@ -1895,9 +2009,9 @@  discard block
 block discarded – undo
1895 2009
 		{
1896 2010
 			closedir($test);
1897 2011
 			return true;
2012
+		} else {
2013
+					return false;
1898 2014
 		}
1899
-		else
1900
-			return false;
1901 2015
 	}
1902 2016
 }
1903 2017
 
@@ -1913,39 +2027,46 @@  discard block
 block discarded – undo
1913 2027
 	/** @var ftp_connection $package_ftp */
1914 2028
 	global $package_ftp;
1915 2029
 
1916
-	if (!file_exists($destination) || !is_writable($destination))
1917
-		mktree($destination, 0755);
1918
-	if (!is_writable($destination))
1919
-		mktree($destination, 0777);
2030
+	if (!file_exists($destination) || !is_writable($destination)) {
2031
+			mktree($destination, 0755);
2032
+	}
2033
+	if (!is_writable($destination)) {
2034
+			mktree($destination, 0777);
2035
+	}
1920 2036
 
1921 2037
 	$current_dir = opendir($source);
1922
-	if ($current_dir == false)
1923
-		return;
2038
+	if ($current_dir == false) {
2039
+			return;
2040
+	}
1924 2041
 
1925 2042
 	while ($entryname = readdir($current_dir))
1926 2043
 	{
1927
-		if (in_array($entryname, array('.', '..')))
1928
-			continue;
2044
+		if (in_array($entryname, array('.', '..'))) {
2045
+					continue;
2046
+		}
1929 2047
 
1930
-		if (isset($package_ftp))
1931
-			$ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
2048
+		if (isset($package_ftp)) {
2049
+					$ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => ''));
2050
+		}
1932 2051
 
1933 2052
 		if (is_file($source . '/' . $entryname))
1934 2053
 		{
1935
-			if (isset($package_ftp) && !file_exists($destination . '/' . $entryname))
1936
-				$package_ftp->create_file($ftp_file);
1937
-			elseif (!file_exists($destination . '/' . $entryname))
1938
-				@touch($destination . '/' . $entryname);
2054
+			if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) {
2055
+							$package_ftp->create_file($ftp_file);
2056
+			} elseif (!file_exists($destination . '/' . $entryname)) {
2057
+							@touch($destination . '/' . $entryname);
2058
+			}
1939 2059
 		}
1940 2060
 
1941 2061
 		package_chmod($destination . '/' . $entryname);
1942 2062
 
1943
-		if (is_dir($source . '/' . $entryname))
1944
-			copytree($source . '/' . $entryname, $destination . '/' . $entryname);
1945
-		elseif (file_exists($destination . '/' . $entryname))
1946
-			package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname));
1947
-		else
1948
-			copy($source . '/' . $entryname, $destination . '/' . $entryname);
2063
+		if (is_dir($source . '/' . $entryname)) {
2064
+					copytree($source . '/' . $entryname, $destination . '/' . $entryname);
2065
+		} elseif (file_exists($destination . '/' . $entryname)) {
2066
+					package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname));
2067
+		} else {
2068
+					copy($source . '/' . $entryname, $destination . '/' . $entryname);
2069
+		}
1949 2070
 	}
1950 2071
 
1951 2072
 	closedir($current_dir);
@@ -1963,21 +2084,24 @@  discard block
 block discarded – undo
1963 2084
 	$data = array();
1964 2085
 
1965 2086
 	$dir = @dir($path . $sub_path);
1966
-	if (!$dir)
1967
-		return array();
2087
+	if (!$dir) {
2088
+			return array();
2089
+	}
1968 2090
 	while ($entry = $dir->read())
1969 2091
 	{
1970
-		if ($entry == '.' || $entry == '..')
1971
-			continue;
2092
+		if ($entry == '.' || $entry == '..') {
2093
+					continue;
2094
+		}
1972 2095
 
1973
-		if (is_dir($path . $sub_path . '/' . $entry))
1974
-			$data = array_merge($data, listtree($path, $sub_path . '/' . $entry));
1975
-		else
1976
-			$data[] = array(
2096
+		if (is_dir($path . $sub_path . '/' . $entry)) {
2097
+					$data = array_merge($data, listtree($path, $sub_path . '/' . $entry));
2098
+		} else {
2099
+					$data[] = array(
1977 2100
 				'filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry,
1978 2101
 				'size' => filesize($path . $sub_path . '/' . $entry),
1979 2102
 				'skipped' => false,
1980 2103
 			);
2104
+		}
1981 2105
 	}
1982 2106
 	$dir->close();
1983 2107
 
@@ -2032,8 +2156,9 @@  discard block
 block discarded – undo
2032 2156
 		{
2033 2157
 			// If this filename is relative, if so take a guess at what it should be.
2034 2158
 			$real_filename = $filename;
2035
-			if (strpos($filename, 'Themes') === 0)
2036
-				$real_filename = $boarddir . '/' . $filename;
2159
+			if (strpos($filename, 'Themes') === 0) {
2160
+							$real_filename = $boarddir . '/' . $filename;
2161
+			}
2037 2162
 
2038 2163
 			if (strpos($real_filename, $theme['theme_dir']) === 0)
2039 2164
 			{
@@ -2052,8 +2177,9 @@  discard block
 block discarded – undo
2052 2177
 		foreach ($theme_paths as $id => $theme)
2053 2178
 		{
2054 2179
 			// Default is getting done anyway, so no need for involvement here.
2055
-			if ($id == 1)
2056
-				continue;
2180
+			if ($id == 1) {
2181
+							continue;
2182
+			}
2057 2183
 
2058 2184
 			// For every template, do we want it? Yea, no, maybe?
2059 2185
 			foreach ($template_changes[1] as $index => $template_file)
@@ -2076,8 +2202,9 @@  discard block
 block discarded – undo
2076 2202
 		);
2077 2203
 
2078 2204
 		// Sometimes though, we have some additional files for other themes, if we have add them to the mix.
2079
-		if (isset($custom_themes_add[$files_to_change[1]]))
2080
-			$files_to_change += $custom_themes_add[$files_to_change[1]];
2205
+		if (isset($custom_themes_add[$files_to_change[1]])) {
2206
+					$files_to_change += $custom_themes_add[$files_to_change[1]];
2207
+		}
2081 2208
 
2082 2209
 		// Now, loop through all the files we're changing, and, well, change them ;)
2083 2210
 		foreach ($files_to_change as $theme => $working_file)
@@ -2111,11 +2238,13 @@  discard block
 block discarded – undo
2111 2238
 				continue;
2112 2239
 			}
2113 2240
 			// Okay, we're creating this file then...?
2114
-			elseif (!file_exists($working_file))
2115
-				$working_data = '';
2241
+			elseif (!file_exists($working_file)) {
2242
+							$working_data = '';
2243
+			}
2116 2244
 			// Phew, it exists!  Load 'er up!
2117
-			else
2118
-				$working_data = str_replace("\r", '', package_get_contents($working_file));
2245
+			else {
2246
+							$working_data = str_replace("\r", '', package_get_contents($working_file));
2247
+			}
2119 2248
 
2120 2249
 			$actions[] = array(
2121 2250
 				'type' => 'opened',
@@ -2136,8 +2265,8 @@  discard block
 block discarded – undo
2136 2265
 
2137 2266
 				// Grab all search items of this operation (in most cases just 1).
2138 2267
 				$searches = $operation->set('search');
2139
-				foreach ($searches as $i => $search)
2140
-					$actual_operation['searches'][] = array(
2268
+				foreach ($searches as $i => $search) {
2269
+									$actual_operation['searches'][] = array(
2141 2270
 						'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), array('before', 'after', 'replace', 'end')) ? trim($search->fetch('@position')) : 'replace',
2142 2271
 						'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true',
2143 2272
 						'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose',
@@ -2146,6 +2275,7 @@  discard block
 block discarded – undo
2146 2275
 						'preg_search' => '',
2147 2276
 						'preg_replace' => '',
2148 2277
 					);
2278
+				}
2149 2279
 
2150 2280
 				// At least one search should be defined.
2151 2281
 				if (empty($actual_operation['searches']))
@@ -2169,30 +2299,32 @@  discard block
 block discarded – undo
2169 2299
 						// Reverse modification of regular expressions are not allowed.
2170 2300
 						if ($search['is_reg_exp'])
2171 2301
 						{
2172
-							if ($actual_operation['error'] === 'fatal')
2173
-								$actions[] = array(
2302
+							if ($actual_operation['error'] === 'fatal') {
2303
+															$actions[] = array(
2174 2304
 									'type' => 'failure',
2175 2305
 									'filename' => $working_file,
2176 2306
 									'search' => $search['search'],
2177 2307
 									'is_custom' => $theme > 1 ? $theme : 0,
2178 2308
 								);
2309
+							}
2179 2310
 
2180 2311
 							// Continue to the next operation.
2181 2312
 							continue 2;
2182 2313
 						}
2183 2314
 
2184 2315
 						// The replacement is now the search subject...
2185
-						if ($search['position'] === 'replace' || $search['position'] === 'end')
2186
-							$actual_operation['searches'][$i]['search'] = $search['add'];
2187
-						else
2316
+						if ($search['position'] === 'replace' || $search['position'] === 'end') {
2317
+													$actual_operation['searches'][$i]['search'] = $search['add'];
2318
+						} else
2188 2319
 						{
2189 2320
 							// Reversing a before/after modification becomes a replacement.
2190 2321
 							$actual_operation['searches'][$i]['position'] = 'replace';
2191 2322
 
2192
-							if ($search['position'] === 'before')
2193
-								$actual_operation['searches'][$i]['search'] .= $search['add'];
2194
-							elseif ($search['position'] === 'after')
2195
-								$actual_operation['searches'][$i]['search'] = $search['add'] . $search['search'];
2323
+							if ($search['position'] === 'before') {
2324
+															$actual_operation['searches'][$i]['search'] .= $search['add'];
2325
+							} elseif ($search['position'] === 'after') {
2326
+															$actual_operation['searches'][$i]['search'] = $search['add'] . $search['search'];
2327
+							}
2196 2328
 						}
2197 2329
 
2198 2330
 						// ...and the search subject is now the replacement.
@@ -2220,16 +2352,17 @@  discard block
 block discarded – undo
2220 2352
 				foreach ($actual_operation['searches'] as $i => $search)
2221 2353
 				{
2222 2354
 					// Not much needed if the search subject is already a regexp.
2223
-					if ($search['is_reg_exp'])
2224
-						$actual_operation['searches'][$i]['preg_search'] = $search['search'];
2225
-					else
2355
+					if ($search['is_reg_exp']) {
2356
+											$actual_operation['searches'][$i]['preg_search'] = $search['search'];
2357
+					} else
2226 2358
 					{
2227 2359
 						// Make the search subject fit into a regular expression.
2228 2360
 						$actual_operation['searches'][$i]['preg_search'] = preg_quote($search['search'], '~');
2229 2361
 
2230 2362
 						// Using 'loose', a random amount of tabs and spaces may be used.
2231
-						if ($search['loose_whitespace'])
2232
-							$actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']);
2363
+						if ($search['loose_whitespace']) {
2364
+													$actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']);
2365
+						}
2233 2366
 					}
2234 2367
 
2235 2368
 					// Shuzzup.  This is done so we can safely use a regular expression. ($0 is bad!!)
@@ -2255,8 +2388,7 @@  discard block
 block discarded – undo
2255 2388
 						if ($undo)
2256 2389
 						{
2257 2390
 							$actual_operation['searches'][$i]['preg_replace'] = '';
2258
-						}
2259
-						else
2391
+						} else
2260 2392
 						{
2261 2393
 							$actual_operation['searches'][$i]['preg_search'] = '(\\n\\?\\>)?$';
2262 2394
 							$actual_operation['searches'][$i]['preg_replace'] .= '$1';
@@ -2303,8 +2435,9 @@  discard block
 block discarded – undo
2303 2435
 					}
2304 2436
 
2305 2437
 					// Replace it into nothing? That's not an option...unless it's an undoing end.
2306
-					if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo))
2307
-						continue;
2438
+					if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) {
2439
+											continue;
2440
+					}
2308 2441
 
2309 2442
 					// Finally, we're doing some replacements.
2310 2443
 					$working_data = preg_replace('~' . $actual_operation['searches'][$i]['preg_search'] . '~s', $actual_operation['searches'][$i]['preg_replace'], $working_data, 1);
@@ -2329,22 +2462,25 @@  discard block
 block discarded – undo
2329 2462
 
2330 2463
 			package_chmod($working_file);
2331 2464
 
2332
-			if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file))))
2333
-				$actions[] = array(
2465
+			if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) {
2466
+							$actions[] = array(
2334 2467
 					'type' => 'chmod',
2335 2468
 					'filename' => $working_file
2336 2469
 				);
2470
+			}
2337 2471
 
2338
-			if (basename($working_file) == 'Settings_bak.php')
2339
-				continue;
2472
+			if (basename($working_file) == 'Settings_bak.php') {
2473
+							continue;
2474
+			}
2340 2475
 
2341 2476
 			if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2342 2477
 			{
2343 2478
 				// No, no, not Settings.php!
2344
-				if (basename($working_file) == 'Settings.php')
2345
-					@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2346
-				else
2347
-					@copy($working_file, $working_file . '~');
2479
+				if (basename($working_file) == 'Settings.php') {
2480
+									@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2481
+				} else {
2482
+									@copy($working_file, $working_file . '~');
2483
+				}
2348 2484
 			}
2349 2485
 
2350 2486
 			// Always call this, even if in testing, because it won't really be written in testing mode.
@@ -2411,8 +2547,9 @@  discard block
 block discarded – undo
2411 2547
 		if ($code_match[1] != 'edit file' && $code_match[1] != 'file')
2412 2548
 		{
2413 2549
 			// It's a step, let's add that to the current steps.
2414
-			if (isset($temp_changes[$step_counter]))
2415
-				$temp_changes[$step_counter]['changes'][] = $code_match[0];
2550
+			if (isset($temp_changes[$step_counter])) {
2551
+							$temp_changes[$step_counter]['changes'][] = $code_match[0];
2552
+			}
2416 2553
 			continue;
2417 2554
 		}
2418 2555
 
@@ -2429,11 +2566,13 @@  discard block
 block discarded – undo
2429 2566
 		foreach ($theme_paths as $id => $theme)
2430 2567
 		{
2431 2568
 			// If this filename is relative, if so take a guess at what it should be.
2432
-			if (strpos($filename, 'Themes') === 0)
2433
-				$filename = $boarddir . '/' . $filename;
2569
+			if (strpos($filename, 'Themes') === 0) {
2570
+							$filename = $boarddir . '/' . $filename;
2571
+			}
2434 2572
 
2435
-			if (strpos($filename, $theme['theme_dir']) === 0)
2436
-				$template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
2573
+			if (strpos($filename, $theme['theme_dir']) === 0) {
2574
+							$template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1);
2575
+			}
2437 2576
 		}
2438 2577
 	}
2439 2578
 
@@ -2446,8 +2585,9 @@  discard block
 block discarded – undo
2446 2585
 		foreach ($theme_paths as $id => $theme)
2447 2586
 		{
2448 2587
 			// Don't do default, it means nothing to me.
2449
-			if ($id == 1)
2450
-				continue;
2588
+			if ($id == 1) {
2589
+							continue;
2590
+			}
2451 2591
 
2452 2592
 			// Now, for each file do we need to edit it?
2453 2593
 			foreach ($template_changes[1] as $pos => $template_file)
@@ -2483,32 +2623,36 @@  discard block
 block discarded – undo
2483 2623
 				package_chmod($working_file);
2484 2624
 
2485 2625
 				// Don't even dare.
2486
-				if (basename($working_file) == 'Settings_bak.php')
2487
-					continue;
2626
+				if (basename($working_file) == 'Settings_bak.php') {
2627
+									continue;
2628
+				}
2488 2629
 
2489
-				if (!is_writable($working_file))
2490
-					$actions[] = array(
2630
+				if (!is_writable($working_file)) {
2631
+									$actions[] = array(
2491 2632
 						'type' => 'chmod',
2492 2633
 						'filename' => $working_file
2493 2634
 					);
2635
+				}
2494 2636
 
2495 2637
 				if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2496 2638
 				{
2497
-					if (basename($working_file) == 'Settings.php')
2498
-						@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2499
-					else
2500
-						@copy($working_file, $working_file . '~');
2639
+					if (basename($working_file) == 'Settings.php') {
2640
+											@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2641
+					} else {
2642
+											@copy($working_file, $working_file . '~');
2643
+					}
2501 2644
 				}
2502 2645
 
2503 2646
 				package_put_contents($working_file, $working_data, $testing);
2504 2647
 			}
2505 2648
 
2506
-			if ($working_file !== null)
2507
-				$actions[] = array(
2649
+			if ($working_file !== null) {
2650
+							$actions[] = array(
2508 2651
 					'type' => 'saved',
2509 2652
 					'filename' => $working_file,
2510 2653
 					'is_custom' => $is_custom,
2511 2654
 				);
2655
+			}
2512 2656
 
2513 2657
 			// Is this "now working on" file a theme specific one?
2514 2658
 			$is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0;
@@ -2527,10 +2671,11 @@  discard block
 block discarded – undo
2527 2671
 			{
2528 2672
 				$places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages');
2529 2673
 
2530
-				foreach ($places_to_check as $place)
2531
-					if (file_exists($place . '/' . $working_file))
2674
+				foreach ($places_to_check as $place) {
2675
+									if (file_exists($place . '/' . $working_file))
2532 2676
 					{
2533 2677
 						$working_file = $place . '/' . $working_file;
2678
+				}
2534 2679
 						break;
2535 2680
 					}
2536 2681
 			}
@@ -2544,8 +2689,7 @@  discard block
 block discarded – undo
2544 2689
 					'type' => 'opened',
2545 2690
 					'filename' => $working_file
2546 2691
 				);
2547
-			}
2548
-			else
2692
+			} else
2549 2693
 			{
2550 2694
 				$actions[] = array(
2551 2695
 					'type' => 'missing',
@@ -2581,11 +2725,13 @@  discard block
 block discarded – undo
2581 2725
 			$replace_with = $code_match[2];
2582 2726
 
2583 2727
 			// Add this afterward...
2584
-			if ($code_match[1] == 'add' || $code_match[1] == 'add after')
2585
-				$replace_with = $working_search . "\n" . $replace_with;
2728
+			if ($code_match[1] == 'add' || $code_match[1] == 'add after') {
2729
+							$replace_with = $working_search . "\n" . $replace_with;
2730
+			}
2586 2731
 			// Add this beforehand.
2587
-			elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above')
2588
-				$replace_with .= "\n" . $working_search;
2732
+			elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') {
2733
+							$replace_with .= "\n" . $working_search;
2734
+			}
2589 2735
 			// Otherwise.. replace with $replace_with ;).
2590 2736
 		}
2591 2737
 
@@ -2648,29 +2794,32 @@  discard block
 block discarded – undo
2648 2794
 	{
2649 2795
 		package_chmod($working_file);
2650 2796
 
2651
-		if (!is_writable($working_file))
2652
-			$actions[] = array(
2797
+		if (!is_writable($working_file)) {
2798
+					$actions[] = array(
2653 2799
 				'type' => 'chmod',
2654 2800
 				'filename' => $working_file
2655 2801
 			);
2802
+		}
2656 2803
 
2657 2804
 		if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file))
2658 2805
 		{
2659
-			if (basename($working_file) == 'Settings.php')
2660
-				@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2661
-			else
2662
-				@copy($working_file, $working_file . '~');
2806
+			if (basename($working_file) == 'Settings.php') {
2807
+							@copy($working_file, dirname($working_file) . '/Settings_bak.php');
2808
+			} else {
2809
+							@copy($working_file, $working_file . '~');
2810
+			}
2663 2811
 		}
2664 2812
 
2665 2813
 		package_put_contents($working_file, $working_data, $testing);
2666 2814
 	}
2667 2815
 
2668
-	if ($working_file !== null)
2669
-		$actions[] = array(
2816
+	if ($working_file !== null) {
2817
+			$actions[] = array(
2670 2818
 			'type' => 'saved',
2671 2819
 			'filename' => $working_file,
2672 2820
 			'is_custom' => $is_custom,
2673 2821
 		);
2822
+	}
2674 2823
 
2675 2824
 	$actions[] = array(
2676 2825
 		'type' => 'result',
@@ -2695,17 +2844,19 @@  discard block
 block discarded – undo
2695 2844
 		$mem_check = setMemoryLimit('128M');
2696 2845
 
2697 2846
 		// Windows doesn't seem to care about the memory_limit.
2698
-		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false)
2699
-			$package_cache = array();
2700
-		else
2701
-			$package_cache = false;
2847
+		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) {
2848
+					$package_cache = array();
2849
+		} else {
2850
+					$package_cache = false;
2851
+		}
2702 2852
 	}
2703 2853
 
2704
-	if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename]))
2705
-		return file_get_contents($filename);
2706
-	else
2707
-		return $package_cache[$filename];
2708
-}
2854
+	if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) {
2855
+			return file_get_contents($filename);
2856
+	} else {
2857
+			return $package_cache[$filename];
2858
+	}
2859
+	}
2709 2860
 
2710 2861
 /**
2711 2862
  * Writes data to a file, almost exactly like the file_put_contents() function.
@@ -2729,19 +2880,22 @@  discard block
 block discarded – undo
2729 2880
 		// Try to increase the memory limit - we don't want to run out of ram!
2730 2881
 		$mem_check = setMemoryLimit('128M');
2731 2882
 
2732
-		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false)
2733
-			$package_cache = array();
2734
-		else
2735
-			$package_cache = false;
2883
+		if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) {
2884
+					$package_cache = array();
2885
+		} else {
2886
+					$package_cache = false;
2887
+		}
2736 2888
 	}
2737 2889
 
2738
-	if (isset($package_ftp))
2739
-		$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2890
+	if (isset($package_ftp)) {
2891
+			$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2892
+	}
2740 2893
 
2741
-	if (!file_exists($filename) && isset($package_ftp))
2742
-		$package_ftp->create_file($ftp_file);
2743
-	elseif (!file_exists($filename))
2744
-		@touch($filename);
2894
+	if (!file_exists($filename) && isset($package_ftp)) {
2895
+			$package_ftp->create_file($ftp_file);
2896
+	} elseif (!file_exists($filename)) {
2897
+			@touch($filename);
2898
+	}
2745 2899
 
2746 2900
 	package_chmod($filename);
2747 2901
 
@@ -2750,22 +2904,23 @@  discard block
 block discarded – undo
2750 2904
 		$fp = @fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb');
2751 2905
 
2752 2906
 		// We should show an error message or attempt a rollback, no?
2753
-		if (!$fp)
2754
-			return false;
2907
+		if (!$fp) {
2908
+					return false;
2909
+		}
2755 2910
 
2756 2911
 		fwrite($fp, $data);
2757 2912
 		fclose($fp);
2758
-	}
2759
-	elseif (strpos($filename, 'Packages/') !== false || $package_cache === false)
2760
-		return strlen($data);
2761
-	else
2913
+	} elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) {
2914
+			return strlen($data);
2915
+	} else
2762 2916
 	{
2763 2917
 		$package_cache[$filename] = $data;
2764 2918
 
2765 2919
 		// Permission denied, eh?
2766 2920
 		$fp = @fopen($filename, 'r+');
2767
-		if (!$fp)
2768
-			return false;
2921
+		if (!$fp) {
2922
+					return false;
2923
+		}
2769 2924
 		fclose($fp);
2770 2925
 	}
2771 2926
 
@@ -2783,19 +2938,22 @@  discard block
 block discarded – undo
2783 2938
 	global $package_ftp, $package_cache;
2784 2939
 	static $text_filetypes = array('php', 'txt', '.js', 'css', 'vbs', 'tml', 'htm');
2785 2940
 
2786
-	if (empty($package_cache))
2787
-		return;
2941
+	if (empty($package_cache)) {
2942
+			return;
2943
+	}
2788 2944
 
2789 2945
 	// First, let's check permissions!
2790 2946
 	foreach ($package_cache as $filename => $data)
2791 2947
 	{
2792
-		if (isset($package_ftp))
2793
-			$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2948
+		if (isset($package_ftp)) {
2949
+					$ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => ''));
2950
+		}
2794 2951
 
2795
-		if (!file_exists($filename) && isset($package_ftp))
2796
-			$package_ftp->create_file($ftp_file);
2797
-		elseif (!file_exists($filename))
2798
-			@touch($filename);
2952
+		if (!file_exists($filename) && isset($package_ftp)) {
2953
+					$package_ftp->create_file($ftp_file);
2954
+		} elseif (!file_exists($filename)) {
2955
+					@touch($filename);
2956
+		}
2799 2957
 
2800 2958
 		$result = package_chmod($filename);
2801 2959
 
@@ -2849,8 +3007,9 @@  discard block
 block discarded – undo
2849 3007
 	/** @var ftp_connection $package_ftp */
2850 3008
 	global $package_ftp;
2851 3009
 
2852
-	if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable')
2853
-		return true;
3010
+	if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') {
3011
+			return true;
3012
+	}
2854 3013
 
2855 3014
 	// Start off checking without FTP.
2856 3015
 	if (!isset($package_ftp) || $package_ftp === false)
@@ -2872,8 +3031,7 @@  discard block
 block discarded – undo
2872 3031
 
2873 3032
 				// Keep track of the writable status here.
2874 3033
 				$file_permissions = @fileperms($chmod_file);
2875
-			}
2876
-			else
3034
+			} else
2877 3035
 			{
2878 3036
 				// This looks odd, but it's an attempt to work around PHP suExec.
2879 3037
 				if (!file_exists($chmod_file) && $perm_state == 'writable')
@@ -2883,24 +3041,28 @@  discard block
 block discarded – undo
2883 3041
 					mktree(dirname($chmod_file), 0755);
2884 3042
 					@touch($chmod_file);
2885 3043
 					smf_chmod($chmod_file, 0755);
3044
+				} else {
3045
+									$file_permissions = @fileperms($chmod_file);
2886 3046
 				}
2887
-				else
2888
-					$file_permissions = @fileperms($chmod_file);
2889 3047
 			}
2890 3048
 
2891 3049
 			// This looks odd, but it's another attempt to work around PHP suExec.
2892
-			if ($perm_state != 'writable')
2893
-				smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644);
2894
-			else
3050
+			if ($perm_state != 'writable') {
3051
+							smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644);
3052
+			} else
2895 3053
 			{
2896
-				if (!@is_writable($chmod_file))
2897
-					smf_chmod($chmod_file, 0755);
2898
-				if (!@is_writable($chmod_file))
2899
-					smf_chmod($chmod_file, 0777);
2900
-				if (!@is_writable(dirname($chmod_file)))
2901
-					smf_chmod($chmod_file, 0755);
2902
-				if (!@is_writable(dirname($chmod_file)))
2903
-					smf_chmod($chmod_file, 0777);
3054
+				if (!@is_writable($chmod_file)) {
3055
+									smf_chmod($chmod_file, 0755);
3056
+				}
3057
+				if (!@is_writable($chmod_file)) {
3058
+									smf_chmod($chmod_file, 0777);
3059
+				}
3060
+				if (!@is_writable(dirname($chmod_file))) {
3061
+									smf_chmod($chmod_file, 0755);
3062
+				}
3063
+				if (!@is_writable(dirname($chmod_file))) {
3064
+									smf_chmod($chmod_file, 0777);
3065
+				}
2904 3066
 			}
2905 3067
 
2906 3068
 			// The ultimate writable test.
@@ -2909,20 +3071,22 @@  discard block
 block discarded – undo
2909 3071
 				$fp = is_dir($chmod_file) ? @opendir($chmod_file) : @fopen($chmod_file, 'rb');
2910 3072
 				if (@is_writable($chmod_file) && $fp)
2911 3073
 				{
2912
-					if (!is_dir($chmod_file))
2913
-						fclose($fp);
2914
-					else
2915
-						closedir($fp);
3074
+					if (!is_dir($chmod_file)) {
3075
+											fclose($fp);
3076
+					} else {
3077
+											closedir($fp);
3078
+					}
2916 3079
 
2917 3080
 					// It worked!
2918
-					if ($track_change)
2919
-						$_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions;
3081
+					if ($track_change) {
3082
+											$_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions;
3083
+					}
2920 3084
 
2921 3085
 					return true;
2922 3086
 				}
3087
+			} elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) {
3088
+							unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]);
2923 3089
 			}
2924
-			elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file]))
2925
-				unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]);
2926 3090
 		}
2927 3091
 
2928 3092
 		// If we're here we're a failure.
@@ -2941,31 +3105,33 @@  discard block
 block discarded – undo
2941 3105
 			mktree(dirname($filename), 0755);
2942 3106
 			$package_ftp->create_file($ftp_file);
2943 3107
 			$package_ftp->chmod($ftp_file, 0755);
3108
+		} else {
3109
+					$file_permissions = @fileperms($filename);
2944 3110
 		}
2945
-		else
2946
-			$file_permissions = @fileperms($filename);
2947 3111
 
2948 3112
 		if ($perm_state != 'writable')
2949 3113
 		{
2950 3114
 			$package_ftp->chmod($ftp_file, $perm_state == 'execute' ? 0755 : 0644);
2951
-		}
2952
-		else
3115
+		} else
2953 3116
 		{
2954
-			if (!@is_writable($filename))
2955
-				$package_ftp->chmod($ftp_file, 0777);
2956
-			if (!@is_writable(dirname($filename)))
2957
-				$package_ftp->chmod(dirname($ftp_file), 0777);
3117
+			if (!@is_writable($filename)) {
3118
+							$package_ftp->chmod($ftp_file, 0777);
3119
+			}
3120
+			if (!@is_writable(dirname($filename))) {
3121
+							$package_ftp->chmod(dirname($ftp_file), 0777);
3122
+			}
2958 3123
 		}
2959 3124
 
2960 3125
 		if (@is_writable($filename))
2961 3126
 		{
2962
-			if ($track_change)
2963
-				$_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions;
3127
+			if ($track_change) {
3128
+							$_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions;
3129
+			}
2964 3130
 
2965 3131
 			return true;
3132
+		} elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) {
3133
+					unset($_SESSION['pack_ftp']['original_perms'][$filename]);
2966 3134
 		}
2967
-		elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename]))
2968
-			unset($_SESSION['pack_ftp']['original_perms'][$filename]);
2969 3135
 	}
2970 3136
 
2971 3137
 	// Oh dear, we failed if we get here.
@@ -2983,11 +3149,13 @@  discard block
 block discarded – undo
2983 3149
 	$n = strlen($pass);
2984 3150
 
2985 3151
 	$salt = session_id();
2986
-	while (strlen($salt) < $n)
2987
-		$salt .= session_id();
3152
+	while (strlen($salt) < $n) {
3153
+			$salt .= session_id();
3154
+	}
2988 3155
 
2989
-	for ($i = 0; $i < $n; $i++)
2990
-		$pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
3156
+	for ($i = 0; $i < $n; $i++) {
3157
+			$pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32));
3158
+	}
2991 3159
 
2992 3160
 	return $pass;
2993 3161
 }
@@ -3006,8 +3174,9 @@  discard block
 block discarded – undo
3006 3174
 	$base_files = array('index.php', 'SSI.php', 'agreement.txt', 'cron.php', 'ssi_examples.php', 'ssi_examples.shtml', 'subscriptions.php');
3007 3175
 	foreach ($base_files as $file)
3008 3176
 	{
3009
-		if (file_exists($boarddir . '/' . $file))
3010
-			$files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file;
3177
+		if (file_exists($boarddir . '/' . $file)) {
3178
+					$files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file;
3179
+		}
3011 3180
 	}
3012 3181
 
3013 3182
 	$dirs = array(
@@ -3024,8 +3193,9 @@  discard block
 block discarded – undo
3024 3193
 			'theme_dir' => 'theme_dir',
3025 3194
 		)
3026 3195
 	);
3027
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3028
-		$dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/');
3196
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3197
+			$dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/');
3198
+	}
3029 3199
 	$smcFunc['db_free_result']($request);
3030 3200
 
3031 3201
 	try
@@ -3040,11 +3210,13 @@  discard block
 block discarded – undo
3040 3210
 
3041 3211
 			foreach ($iter as $entry => $dir)
3042 3212
 			{
3043
-				if ($dir->isDir())
3044
-					continue;
3213
+				if ($dir->isDir()) {
3214
+									continue;
3215
+				}
3045 3216
 
3046
-				if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0)
3047
-					continue;
3217
+				if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) {
3218
+									continue;
3219
+				}
3048 3220
 
3049 3221
 				$files[empty($_REQUEST['use_full_paths']) ? str_replace(realpath($boarddir), '', $entry) : $entry] = $entry;
3050 3222
 			}
@@ -3052,10 +3224,12 @@  discard block
 block discarded – undo
3052 3224
 		$obj = new ArrayObject($files);
3053 3225
 		$iterator = $obj->getIterator();
3054 3226
 
3055
-		if (!file_exists($packagesdir . '/backups'))
3056
-			mktree($packagesdir . '/backups', 0777);
3057
-		if (!is_writable($packagesdir . '/backups'))
3058
-			package_chmod($packagesdir . '/backups');
3227
+		if (!file_exists($packagesdir . '/backups')) {
3228
+					mktree($packagesdir . '/backups', 0777);
3229
+		}
3230
+		if (!is_writable($packagesdir . '/backups')) {
3231
+					package_chmod($packagesdir . '/backups');
3232
+		}
3059 3233
 		$output_file = $packagesdir . '/backups/' . strftime('%Y-%m-%d_') . preg_replace('~[$\\\\/:<>|?*"\']~', '', $id);
3060 3234
 		$output_ext = '.tar';
3061 3235
 		$output_ext_target = '.tar.gz';
@@ -3063,16 +3237,18 @@  discard block
 block discarded – undo
3063 3237
 		if (file_exists($output_file . $output_ext_target))
3064 3238
 		{
3065 3239
 			$i = 2;
3066
-			while (file_exists($output_file . '_' . $i . $output_ext_target))
3067
-				$i++;
3240
+			while (file_exists($output_file . '_' . $i . $output_ext_target)) {
3241
+							$i++;
3242
+			}
3068 3243
 			$output_file = $output_file . '_' . $i . $output_ext;
3244
+		} else {
3245
+					$output_file .= $output_ext;
3069 3246
 		}
3070
-		else
3071
-			$output_file .= $output_ext;
3072 3247
 
3073 3248
 		@set_time_limit(300);
3074
-		if (function_exists('apache_reset_timeout'))
3075
-			@apache_reset_timeout();
3249
+		if (function_exists('apache_reset_timeout')) {
3250
+					@apache_reset_timeout();
3251
+		}
3076 3252
 
3077 3253
 		$a = new PharData($output_file);
3078 3254
 		$a->buildFromIterator($iterator);
@@ -3084,8 +3260,7 @@  discard block
 block discarded – undo
3084 3260
 		 */
3085 3261
 		unset($a);
3086 3262
 		unlink($output_file);
3087
-	}
3088
-	catch (Exception $e)
3263
+	} catch (Exception $e)
3089 3264
 	{
3090 3265
 		log_error($e->getMessage(), 'backup');
3091 3266
 
Please login to merge, or discard this patch.