Completed
Push — release-2.1 ( 3ad5fa...66bdad )
by Jeremy
04:59 queued 04:53
created
Sources/Subs-Attachments.php 1 patch
Braces   +297 added lines, -224 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $smcFunc, $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -54,21 +57,25 @@  discard block
 block discarded – undo
54 57
 
55 58
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
56 59
 	{
57
-			if (!is_array($modSettings['attachment_basedirectories']))
58
-				$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
60
+			if (!is_array($modSettings['attachment_basedirectories'])) {
61
+							$modSettings['attachment_basedirectories'] = $smcFunc['json_decode']($modSettings['attachment_basedirectories'], true);
62
+			}
59 63
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
64
+	} else {
65
+			$base_dir = 0;
60 66
 	}
61
-	else
62
-		$base_dir = 0;
63 67
 
64 68
 	if ($modSettings['automanage_attachments'] == 1)
65 69
 	{
66
-		if (!isset($modSettings['last_attachments_directory']))
67
-			$modSettings['last_attachments_directory'] = array();
68
-		if (!is_array($modSettings['last_attachments_directory']))
69
-			$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
70
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
71
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
70
+		if (!isset($modSettings['last_attachments_directory'])) {
71
+					$modSettings['last_attachments_directory'] = array();
72
+		}
73
+		if (!is_array($modSettings['last_attachments_directory'])) {
74
+					$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
75
+		}
76
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
77
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
78
+		}
72 79
 	}
73 80
 
74 81
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -97,12 +104,14 @@  discard block
 block discarded – undo
97 104
 			$updir = '';
98 105
 	}
99 106
 
100
-	if (!is_array($modSettings['attachmentUploadDir']))
101
-		$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
102
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
103
-		$outputCreation = automanage_attachments_create_directory($updir);
104
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
105
-		$outputCreation = true;
107
+	if (!is_array($modSettings['attachmentUploadDir'])) {
108
+			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
109
+	}
110
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
111
+			$outputCreation = automanage_attachments_create_directory($updir);
112
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
113
+			$outputCreation = true;
114
+	}
106 115
 
107 116
 	if ($outputCreation)
108 117
 	{
@@ -139,8 +148,9 @@  discard block
 block discarded – undo
139 148
 		$count = count($tree);
140 149
 
141 150
 		$directory = attachments_init_dir($tree, $count);
142
-		if ($directory === false)
143
-			return false;
151
+		if ($directory === false) {
152
+					return false;
153
+		}
144 154
 	}
145 155
 
146 156
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -168,8 +178,9 @@  discard block
 block discarded – undo
168 178
 	}
169 179
 
170 180
 	// Everything seems fine...let's create the .htaccess
171
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
172
-		secureDirectory($updir, true);
181
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
182
+			secureDirectory($updir, true);
183
+	}
173 184
 
174 185
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
175 186
 	$updir = rtrim($updir, $sep);
@@ -201,8 +212,9 @@  discard block
 block discarded – undo
201 212
 {
202 213
 	global $smcFunc, $modSettings, $boarddir;
203 214
 
204
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
205
-		return;
215
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
216
+			return;
217
+	}
206 218
 
207 219
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
208 220
 	// Just to be sure: I don't want directory separators at the end
@@ -214,13 +226,14 @@  discard block
 block discarded – undo
214 226
 	{
215 227
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
216 228
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
229
+	} else {
230
+			$base_dir = 0;
217 231
 	}
218
-	else
219
-		$base_dir = 0;
220 232
 
221 233
 	// Get the last attachment directory for that base directory
222
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
223
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
234
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
235
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
236
+	}
224 237
 	// And increment it.
225 238
 	$modSettings['last_attachments_directory'][$base_dir]++;
226 239
 
@@ -235,10 +248,10 @@  discard block
 block discarded – undo
235 248
 		$modSettings['last_attachments_directory'] = $smcFunc['json_decode']($modSettings['last_attachments_directory'], true);
236 249
 
237 250
 		return true;
251
+	} else {
252
+			return false;
253
+	}
238 254
 	}
239
-	else
240
-		return false;
241
-}
242 255
 
243 256
 /**
244 257
  * Split a path into a list of all directories and subdirectories
@@ -256,12 +269,13 @@  discard block
 block discarded – undo
256 269
 			* in Windows we need to explode for both \ and /
257 270
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
258 271
 	*/
259
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
260
-		$tree = preg_split('#[\\\/]#', $directory);
261
-	else
272
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
273
+			$tree = preg_split('#[\\\/]#', $directory);
274
+	} else
262 275
 	{
263
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
264
-			return false;
276
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
277
+					return false;
278
+		}
265 279
 
266 280
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
267 281
 	}
@@ -285,10 +299,11 @@  discard block
 block discarded – undo
285 299
 		 //Better be sure that the first part of the path is actually a drive letter...
286 300
 		 //...even if, I should check this in the admin page...isn't it?
287 301
 		 //...NHAAA Let's leave space for users' complains! :P
288
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
289
-			$directory = array_shift($tree);
290
-		else
291
-			return false;
302
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
303
+					$directory = array_shift($tree);
304
+		} else {
305
+					return false;
306
+		}
292 307
 
293 308
 		$count--;
294 309
 	}
@@ -303,18 +318,20 @@  discard block
 block discarded – undo
303 318
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
304 319
 
305 320
 	// Make sure we're uploading to the right place.
306
-	if (!empty($modSettings['automanage_attachments']))
307
-		automanage_attachments_check_directory();
321
+	if (!empty($modSettings['automanage_attachments'])) {
322
+			automanage_attachments_check_directory();
323
+	}
308 324
 
309
-	if (!is_array($modSettings['attachmentUploadDir']))
310
-		$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
325
+	if (!is_array($modSettings['attachmentUploadDir'])) {
326
+			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
327
+	}
311 328
 
312 329
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
313 330
 
314 331
 	// Is the attachments folder actualy there?
315
-	if (!empty($context['dir_creation_error']))
316
-		$initial_error = $context['dir_creation_error'];
317
-	elseif (!is_dir($context['attach_dir']))
332
+	if (!empty($context['dir_creation_error'])) {
333
+			$initial_error = $context['dir_creation_error'];
334
+	} elseif (!is_dir($context['attach_dir']))
318 335
 	{
319 336
 		$initial_error = 'attach_folder_warning';
320 337
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -337,12 +354,12 @@  discard block
 block discarded – undo
337 354
 			);
338 355
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
339 356
 			$smcFunc['db_free_result']($request);
340
-		}
341
-		else
342
-			$context['attachments'] = array(
357
+		} else {
358
+					$context['attachments'] = array(
343 359
 				'quantity' => 0,
344 360
 				'total_size' => 0,
345 361
 			);
362
+		}
346 363
 	}
347 364
 
348 365
 	// Hmm. There are still files in session.
@@ -352,39 +369,44 @@  discard block
 block discarded – undo
352 369
 		// Let's try to keep them. But...
353 370
 		$ignore_temp = true;
354 371
 		// If new files are being added. We can't ignore those
355
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
356
-			if (!empty($dummy))
372
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
373
+					if (!empty($dummy))
357 374
 			{
358 375
 				$ignore_temp = false;
376
+		}
359 377
 				break;
360 378
 			}
361 379
 
362 380
 		// Need to make space for the new files. So, bye bye.
363 381
 		if (!$ignore_temp)
364 382
 		{
365
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
366
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
383
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
384
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
367 385
 					unlink($attachment['tmp_name']);
386
+			}
368 387
 
369 388
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
370 389
 			$_SESSION['temp_attachments'] = array();
371 390
 		}
372 391
 	}
373 392
 
374
-	if (!isset($_FILES['attachment']['name']))
375
-		$_FILES['attachment']['tmp_name'] = array();
393
+	if (!isset($_FILES['attachment']['name'])) {
394
+			$_FILES['attachment']['tmp_name'] = array();
395
+	}
376 396
 
377
-	if (!isset($_SESSION['temp_attachments']))
378
-		$_SESSION['temp_attachments'] = array();
397
+	if (!isset($_SESSION['temp_attachments'])) {
398
+			$_SESSION['temp_attachments'] = array();
399
+	}
379 400
 
380 401
 	// Remember where we are at. If it's anywhere at all.
381
-	if (!$ignore_temp)
382
-		$_SESSION['temp_attachments']['post'] = array(
402
+	if (!$ignore_temp) {
403
+			$_SESSION['temp_attachments']['post'] = array(
383 404
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
384 405
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
385 406
 			'topic' => !empty($topic) ? $topic : 0,
386 407
 			'board' => !empty($board) ? $board : 0,
387 408
 		);
409
+	}
388 410
 
389 411
 	// If we have an initial error, lets just display it.
390 412
 	if (!empty($initial_error))
@@ -392,9 +414,10 @@  discard block
 block discarded – undo
392 414
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
393 415
 
394 416
 		// And delete the files 'cos they ain't going nowhere.
395
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
396
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
417
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
418
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
397 419
 				unlink($_FILES['attachment']['tmp_name'][$n]);
420
+		}
398 421
 
399 422
 		$_FILES['attachment']['tmp_name'] = array();
400 423
 	}
@@ -402,21 +425,24 @@  discard block
 block discarded – undo
402 425
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
403 426
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
404 427
 	{
405
-		if ($_FILES['attachment']['name'][$n] == '')
406
-			continue;
428
+		if ($_FILES['attachment']['name'][$n] == '') {
429
+					continue;
430
+		}
407 431
 
408 432
 		// First, let's first check for PHP upload errors.
409 433
 		$errors = array();
410 434
 		if (!empty($_FILES['attachment']['error'][$n]))
411 435
 		{
412
-			if ($_FILES['attachment']['error'][$n] == 2)
413
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
414
-			elseif ($_FILES['attachment']['error'][$n] == 6)
415
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
416
-			else
417
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
418
-			if (empty($errors))
419
-				$errors[] = 'attach_php_error';
436
+			if ($_FILES['attachment']['error'][$n] == 2) {
437
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
438
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
439
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
440
+			} else {
441
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
442
+			}
443
+			if (empty($errors)) {
444
+							$errors[] = 'attach_php_error';
445
+			}
420 446
 		}
421 447
 
422 448
 		// Try to move and rename the file before doing any more checks on it.
@@ -426,8 +452,9 @@  discard block
 block discarded – undo
426 452
 		{
427 453
 			// The reported MIME type of the attachment might not be reliable.
428 454
 			// Fortunately, PHP 5.3+ lets us easily verify the real MIME type.
429
-			if (function_exists('mime_content_type'))
430
-				$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
455
+			if (function_exists('mime_content_type')) {
456
+							$_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]);
457
+			}
431 458
 
432 459
 			$_SESSION['temp_attachments'][$attachID] = array(
433 460
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -439,16 +466,16 @@  discard block
 block discarded – undo
439 466
 			);
440 467
 
441 468
 			// Move the file to the attachments folder with a temp name for now.
442
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
443
-				smf_chmod($destName, 0644);
444
-			else
469
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
470
+							smf_chmod($destName, 0644);
471
+			} else
445 472
 			{
446 473
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
447
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
448
-					unlink($_FILES['attachment']['tmp_name'][$n]);
474
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
475
+									unlink($_FILES['attachment']['tmp_name'][$n]);
476
+				}
449 477
 			}
450
-		}
451
-		else
478
+		} else
452 479
 		{
453 480
 			$_SESSION['temp_attachments'][$attachID] = array(
454 481
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -456,12 +483,14 @@  discard block
 block discarded – undo
456 483
 				'errors' => $errors,
457 484
 			);
458 485
 
459
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
460
-				unlink($_FILES['attachment']['tmp_name'][$n]);
486
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
487
+							unlink($_FILES['attachment']['tmp_name'][$n]);
488
+			}
461 489
 		}
462 490
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
463
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
464
-			attachmentChecks($attachID);
491
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
492
+					attachmentChecks($attachID);
493
+		}
465 494
 	}
466 495
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
467 496
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -488,21 +517,20 @@  discard block
 block discarded – undo
488 517
 	global $modSettings, $context, $sourcedir, $smcFunc;
489 518
 
490 519
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
491
-	if (empty($_SESSION['temp_attachments'][$attachID]))
492
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
493
-
494
-	elseif (empty($attachID))
495
-		$error = '$attachID';
496
-
497
-	elseif (empty($context['attachments']))
498
-		$error = '$context[\'attachments\']';
499
-
500
-	elseif (empty($context['attach_dir']))
501
-		$error = '$context[\'attach_dir\']';
520
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
521
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
522
+	} elseif (empty($attachID)) {
523
+			$error = '$attachID';
524
+	} elseif (empty($context['attachments'])) {
525
+			$error = '$context[\'attachments\']';
526
+	} elseif (empty($context['attach_dir'])) {
527
+			$error = '$context[\'attach_dir\']';
528
+	}
502 529
 
503 530
 	// Let's get their attention.
504
-	if (!empty($error))
505
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
531
+	if (!empty($error)) {
532
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
533
+	}
506 534
 
507 535
 	// Just in case this slipped by the first checks, we stop it here and now
508 536
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -531,8 +559,9 @@  discard block
 block discarded – undo
531 559
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
532 560
 			if (!(empty($size)) && ($size[2] != $old_format))
533 561
 			{
534
-				if (isset($context['valid_image_types'][$size[2]]))
535
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['valid_image_types'][$size[2]];
562
+				if (isset($context['valid_image_types'][$size[2]])) {
563
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['valid_image_types'][$size[2]];
564
+				}
536 565
 			}
537 566
 		}
538 567
 	}
@@ -586,42 +615,48 @@  discard block
 block discarded – undo
586 615
 				// Or, let the user know that it ain't gonna happen.
587 616
 				else
588 617
 				{
589
-					if (isset($context['dir_creation_error']))
590
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
591
-					else
592
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
618
+					if (isset($context['dir_creation_error'])) {
619
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
620
+					} else {
621
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
622
+					}
593 623
 				}
624
+			} else {
625
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
594 626
 			}
595
-			else
596
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
597 627
 		}
598 628
 	}
599 629
 
600 630
 	// Is the file too big?
601 631
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
602
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
632
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
634
+	}
604 635
 
605 636
 	// Check the total upload size for this post...
606
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
607
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
637
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
638
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
639
+	}
608 640
 
609 641
 	// Have we reached the maximum number of files we are allowed?
610 642
 	$context['attachments']['quantity']++;
611 643
 
612 644
 	// Set a max limit if none exists
613
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
614
-		$modSettings['attachmentNumPerPostLimit'] = 50;
645
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
646
+			$modSettings['attachmentNumPerPostLimit'] = 50;
647
+	}
615 648
 
616
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
617
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
649
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
650
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
651
+	}
618 652
 
619 653
 	// File extension check
620 654
 	if (!empty($modSettings['attachmentCheckExtensions']))
621 655
 	{
622 656
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
623
-		foreach ($allowed as $k => $dummy)
624
-			$allowed[$k] = trim($dummy);
657
+		foreach ($allowed as $k => $dummy) {
658
+					$allowed[$k] = trim($dummy);
659
+		}
625 660
 
626 661
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
627 662
 		{
@@ -633,10 +668,12 @@  discard block
 block discarded – undo
633 668
 	// Undo the math if there's an error
634 669
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
635 670
 	{
636
-		if (isset($context['dir_size']))
637
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
638
-		if (isset($context['dir_files']))
639
-			$context['dir_files']--;
671
+		if (isset($context['dir_size'])) {
672
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
673
+		}
674
+		if (isset($context['dir_files'])) {
675
+					$context['dir_files']--;
676
+		}
640 677
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
641 678
 		$context['attachments']['quantity']--;
642 679
 		return false;
@@ -668,12 +705,14 @@  discard block
 block discarded – undo
668 705
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
669 706
 	{
670 707
 		// Got a proper mime type?
671
-		if (!empty($size['mime']))
672
-			$attachmentOptions['mime_type'] = $size['mime'];
708
+		if (!empty($size['mime'])) {
709
+					$attachmentOptions['mime_type'] = $size['mime'];
710
+		}
673 711
 
674 712
 		// Otherwise a valid one?
675
-		elseif (isset($context['valid_image_types'][$size[2]]))
676
-			$attachmentOptions['mime_type'] = 'image/' . $context['valid_image_types'][$size[2]];
713
+		elseif (isset($context['valid_image_types'][$size[2]])) {
714
+					$attachmentOptions['mime_type'] = 'image/' . $context['valid_image_types'][$size[2]];
715
+		}
677 716
 	}
678 717
 
679 718
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -685,15 +724,17 @@  discard block
 block discarded – undo
685 724
 	}
686 725
 
687 726
 	// Get the hash if no hash has been given yet.
688
-	if (empty($attachmentOptions['file_hash']))
689
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
727
+	if (empty($attachmentOptions['file_hash'])) {
728
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
729
+	}
690 730
 
691 731
 	// Assuming no-one set the extension let's take a look at it.
692 732
 	if (empty($attachmentOptions['fileext']))
693 733
 	{
694 734
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
695
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
696
-			$attachmentOptions['fileext'] = '';
735
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
736
+					$attachmentOptions['fileext'] = '';
737
+		}
697 738
 	}
698 739
 
699 740
 	// Last chance to change stuff!
@@ -702,8 +743,9 @@  discard block
 block discarded – undo
702 743
 	// Make sure the folder is valid...
703 744
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
704 745
 	$folders = array_keys($tmp);
705
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
706
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
746
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
747
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
748
+	}
707 749
 
708 750
 	$attachmentOptions['id'] = $smcFunc['db_insert']('',
709 751
 		'{db_prefix}attachments',
@@ -734,8 +776,8 @@  discard block
 block discarded – undo
734 776
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
735 777
 
736 778
 	// If it's not approved then add to the approval queue.
737
-	if (!$attachmentOptions['approved'])
738
-		$smcFunc['db_insert']('',
779
+	if (!$attachmentOptions['approved']) {
780
+			$smcFunc['db_insert']('',
739 781
 			'{db_prefix}approval_queue',
740 782
 			array(
741 783
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -745,9 +787,11 @@  discard block
 block discarded – undo
745 787
 			),
746 788
 			array()
747 789
 		);
790
+	}
748 791
 
749
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
750
-		return true;
792
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
793
+			return true;
794
+	}
751 795
 
752 796
 	// Like thumbnails, do we?
753 797
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -758,13 +802,15 @@  discard block
 block discarded – undo
758 802
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
759 803
 			list ($thumb_width, $thumb_height) = $size;
760 804
 
761
-			if (!empty($size['mime']))
762
-				$thumb_mime = $size['mime'];
763
-			elseif (isset($context['valid_image_types'][$size[2]]))
764
-				$thumb_mime = 'image/' . $context['valid_image_types'][$size[2]];
805
+			if (!empty($size['mime'])) {
806
+							$thumb_mime = $size['mime'];
807
+			} elseif (isset($context['valid_image_types'][$size[2]])) {
808
+							$thumb_mime = 'image/' . $context['valid_image_types'][$size[2]];
809
+			}
765 810
 			// Lord only knows how this happened...
766
-			else
767
-				$thumb_mime = '';
811
+			else {
812
+							$thumb_mime = '';
813
+			}
768 814
 
769 815
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
770 816
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -844,15 +890,17 @@  discard block
 block discarded – undo
844 890
 	global $smcFunc;
845 891
 
846 892
 	// Oh, come on!
847
-	if (empty($attachIDs) || empty($msgID))
848
-		return false;
893
+	if (empty($attachIDs) || empty($msgID)) {
894
+			return false;
895
+	}
849 896
 
850 897
 	// "I see what is right and approve, but I do what is wrong."
851 898
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
852 899
 
853 900
 	// One last check
854
-	if (empty($attachIDs))
855
-		return false;
901
+	if (empty($attachIDs)) {
902
+			return false;
903
+	}
856 904
 
857 905
 	// Perform.
858 906
 	$smcFunc['db_query']('', '
@@ -880,8 +928,9 @@  discard block
 block discarded – undo
880 928
 	global $board, $modSettings, $context, $scripturl, $smcFunc;
881 929
 
882 930
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
931
+	if (empty($attachID)) {
932
+			return 'attachments_no_data_loaded';
933
+	}
885 934
 
886 935
 	// Make it easy.
887 936
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +939,23 @@  discard block
 block discarded – undo
890 939
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 940
 
892 941
 	// "I am innocent of the blood of this just person: see ye to it."
893
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
894
-		return $externalParse;
942
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
943
+			return $externalParse;
944
+	}
895 945
 
896 946
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
947
+	if (empty($modSettings['attachmentEnable'])) {
948
+			return 'attachments_not_enable';
949
+	}
899 950
 
900 951
 	// Previewing much? no msg ID has been set yet.
901 952
 	if (!empty($context['preview_message']))
902 953
 	{
903 954
 		$allAttachments = getAttachsByMsg(0);
904 955
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
956
+		if (empty($allAttachments[0][$attachID])) {
957
+					return 'attachments_no_data_loaded';
958
+		}
907 959
 
908 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
909 961
 
@@ -915,57 +967,66 @@  discard block
 block discarded – undo
915 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
916 968
 
917 969
 		// Fix the thumbnail too, if the image has one.
918
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
919
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
970
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
971
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		}
920 973
 
921 974
 		return $attachContext;
922 975
 	}
923 976
 
924 977
 	// There is always the chance someone else has already done our dirty work...
925 978
 	// If so, all pertinent checks were already done. Hopefully...
926
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
927
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
928 982
 
929 983
 	// If we are lucky enough to be in $board's scope then check it!
930
-	if (!empty($board) && !allowedTo('view_attachments', $board))
931
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
932 987
 
933 988
 	// Get the message info associated with this particular attach ID.
934 989
 	$attachInfo = getAttachMsgInfo($attachID);
935 990
 
936 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
937
-	if (empty($attachInfo) || empty($attachInfo['msg']))
938
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
939 995
 
940 996
 	// Hold it! got the info now check if you can see this attachment.
941
-	if (!allowedTo('view_attachments', $attachInfo['board']))
942
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
943 1000
 
944 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
945 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
946 1003
 
947 1004
 	// No point in keep going further.
948
-	if (!allowedTo('view_attachments', $attachContext['board']))
949
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
950 1008
 
951 1009
 	// Load this particular attach's context.
952
-	if (!empty($attachContext))
953
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
954 1013
 
955 1014
 	// One last check, you know, gotta be paranoid...
956
-	else
957
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
958 1018
 
959 1019
 	// This is the last "if" I promise!
960
-	if (empty($attachLoaded))
961
-		return 'attachments_no_data_loaded';
962
-
963
-	else
964
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
965 1025
 
966 1026
 	// You may or may not want to show this under the post.
967
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
968
-		$context['show_attach_under_post'][$attachID] = $attachID;
1027
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1028
+			$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	}
969 1030
 
970 1031
 	// Last minute changes?
971 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -985,8 +1046,9 @@  discard block
 block discarded – undo
985 1046
 {
986 1047
 	global $smcFunc, $modSettings;
987 1048
 
988
-	if (empty($attachIDs))
989
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
990 1052
 
991 1053
 	$return = array();
992 1054
 
@@ -1002,11 +1064,12 @@  discard block
 block discarded – undo
1002 1064
 		)
1003 1065
 	);
1004 1066
 
1005
-	if ($smcFunc['db_num_rows']($request) != 1)
1006
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1007 1070
 
1008
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1009
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1010 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1011 1074
 			'size' => $row['size'],
1012 1075
 			'attachID' => $row['id_attach'],
@@ -1015,6 +1078,7 @@  discard block
 block discarded – undo
1015 1078
 			'mime_type' => $row['mime_type'],
1016 1079
 			'thumb' => $row['id_thumb'],
1017 1080
 		);
1081
+	}
1018 1082
 	$smcFunc['db_free_result']($request);
1019 1083
 
1020 1084
 	return $return;
@@ -1031,8 +1095,9 @@  discard block
 block discarded – undo
1031 1095
 {
1032 1096
 	global $smcFunc;
1033 1097
 
1034
-	if (empty($attachID))
1035
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1036 1101
 
1037 1102
 	$request = $smcFunc['db_query']('', '
1038 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1045,8 +1110,9 @@  discard block
 block discarded – undo
1045 1110
 		)
1046 1111
 	);
1047 1112
 
1048
-	if ($smcFunc['db_num_rows']($request) != 1)
1049
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1050 1116
 
1051 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1052 1118
 	$smcFunc['db_free_result']($request);
@@ -1087,8 +1153,9 @@  discard block
 block discarded – undo
1087 1153
 		$temp = array();
1088 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1089 1155
 		{
1090
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1091
-				continue;
1156
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1157
+							continue;
1158
+			}
1092 1159
 
1093 1160
 			$temp[$row['id_attach']] = $row;
1094 1161
 		}
@@ -1117,8 +1184,9 @@  discard block
 block discarded – undo
1117 1184
 {
1118 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1119 1186
 
1120
-	if (empty($attachments) || empty($attachments[$id_msg]))
1121
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1122 1190
 
1123 1191
 	// Set up the attachment info - based on code by Meriadoc.
1124 1192
 	$attachmentData = array();
@@ -1142,11 +1210,13 @@  discard block
 block discarded – undo
1142 1210
 			);
1143 1211
 
1144 1212
 			// If something is unapproved we'll note it so we can sort them.
1145
-			if (!$attachment['approved'])
1146
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1147 1216
 
1148
-			if (!$attachmentData[$i]['is_image'])
1149
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1150 1220
 
1151 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1152 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1167,11 +1237,11 @@  discard block
 block discarded – undo
1167 1237
 						// So what folder are we putting this image in?
1168 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1169 1239
 						{
1170
-							if (!is_array($modSettings['attachmentUploadDir']))
1171
-								$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1242
+							}
1172 1243
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1173
-						}
1174
-						else
1244
+						} else
1175 1245
 						{
1176 1246
 							$id_folder_thumb = 1;
1177 1247
 						}
@@ -1185,10 +1255,11 @@  discard block
 block discarded – undo
1185 1255
 						$thumb_ext = isset($context['valid_image_types'][$size[2]]) ? $context['valid_image_types'][$size[2]] : '';
1186 1256
 
1187 1257
 						// Figure out the mime type.
1188
-						if (!empty($size['mime']))
1189
-							$thumb_mime = $size['mime'];
1190
-						else
1191
-							$thumb_mime = 'image/' . $thumb_ext;
1258
+						if (!empty($size['mime'])) {
1259
+													$thumb_mime = $size['mime'];
1260
+						} else {
1261
+													$thumb_mime = 'image/' . $thumb_ext;
1262
+						}
1192 1263
 
1193 1264
 						$thumb_filename = $attachment['filename'] . '_thumb';
1194 1265
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1236,11 +1307,12 @@  discard block
 block discarded – undo
1236 1307
 				}
1237 1308
 			}
1238 1309
 
1239
-			if (!empty($attachment['id_thumb']))
1240
-				$attachmentData[$i]['thumbnail'] = array(
1310
+			if (!empty($attachment['id_thumb'])) {
1311
+							$attachmentData[$i]['thumbnail'] = array(
1241 1312
 					'id' => $attachment['id_thumb'],
1242 1313
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1243 1314
 				);
1315
+			}
1244 1316
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1245 1317
 
1246 1318
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1250,30 +1322,31 @@  discard block
 block discarded – undo
1250 1322
 				{
1251 1323
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1252 1324
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1253
-				}
1254
-				elseif (!empty($modSettings['max_image_width']))
1325
+				} elseif (!empty($modSettings['max_image_width']))
1255 1326
 				{
1256 1327
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1257 1328
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1258 1329
 				}
1259
-			}
1260
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1330
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1261 1331
 			{
1262 1332
 				// If the image is too large to show inline, make it a popup.
1263
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1264
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1265
-				else
1266
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1333
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1334
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1335
+				} else {
1336
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1337
+				}
1267 1338
 			}
1268 1339
 
1269
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1270
-				$attachmentData[$i]['downloads']++;
1340
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1341
+							$attachmentData[$i]['downloads']++;
1342
+			}
1271 1343
 		}
1272 1344
 	}
1273 1345
 
1274 1346
 	// Do we need to instigate a sort?
1275
-	if ($have_unapproved)
1276
-		usort($attachmentData, 'approved_attach_sort');
1347
+	if ($have_unapproved) {
1348
+			usort($attachmentData, 'approved_attach_sort');
1349
+	}
1277 1350
 
1278 1351
 	return $attachmentData;
1279 1352
 }
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +792 added lines, -597 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We explicitly do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -405,9 +422,9 @@  discard block
 block discarded – undo
405 422
 				break;
406 423
 			}
407 424
 		}
425
+	} else {
426
+			$id_member = 0;
408 427
 	}
409
-	else
410
-		$id_member = 0;
411 428
 
412 429
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
413 430
 	{
@@ -415,8 +432,9 @@  discard block
 block discarded – undo
415 432
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
416 433
 
417 434
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
418
-		if (empty($cookie_data))
419
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
435
+		if (empty($cookie_data)) {
436
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
437
+		}
420 438
 
421 439
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
422 440
 
@@ -424,16 +442,17 @@  discard block
 block discarded – undo
424 442
 
425 443
 		// Make sure the cookie is set to the correct domain and path
426 444
 		require_once($sourcedir . '/Subs-Auth.php');
427
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
428
-			setLoginCookie((int) $login_span - time(), $id_member);
429
-	}
430
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
445
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
446
+					setLoginCookie((int) $login_span - time(), $id_member);
447
+		}
448
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
431 449
 	{
432 450
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
433 451
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
434 452
 
435
-		if (empty($cookie_data))
436
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
453
+		if (empty($cookie_data)) {
454
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
455
+		}
437 456
 
438 457
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
439 458
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -458,30 +477,34 @@  discard block
 block discarded – undo
458 477
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
459 478
 			$smcFunc['db_free_result']($request);
460 479
 
461
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
462
-				$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
480
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
481
+							$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
482
+			}
463 483
 
464
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
465
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
484
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
485
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
486
+			}
466 487
 		}
467 488
 
468 489
 		// Did we find 'im?  If not, junk it.
469 490
 		if (!empty($user_settings))
470 491
 		{
471 492
 			// As much as the password should be right, we can assume the integration set things up.
472
-			if (!empty($already_verified) && $already_verified === true)
473
-				$check = true;
493
+			if (!empty($already_verified) && $already_verified === true) {
494
+							$check = true;
495
+			}
474 496
 			// SHA-512 hash should be 128 characters long.
475
-			elseif (strlen($password) == 128)
476
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
477
-			else
478
-				$check = false;
497
+			elseif (strlen($password) == 128) {
498
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
499
+			} else {
500
+							$check = false;
501
+			}
479 502
 
480 503
 			// Wrong password or not activated - either way, you're going nowhere.
481 504
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
505
+		} else {
506
+					$id_member = 0;
482 507
 		}
483
-		else
484
-			$id_member = 0;
485 508
 
486 509
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
487 510
 		if (!$id_member)
@@ -510,8 +533,9 @@  discard block
 block discarded – undo
510 533
 
511 534
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
512 535
 
513
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
514
-						$tfasecret = null;
536
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
537
+											$tfasecret = null;
538
+					}
515 539
 				}
516 540
 
517 541
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -533,10 +557,12 @@  discard block
 block discarded – undo
533 557
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
534 558
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
535 559
 		{
536
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
560
+			if ($modSettings['tfa_mode'] == 2) {
561
+				//only do this if we are just forcing SOME membergroups
537 562
 			{
538 563
 				//Build an array of ALL user membergroups.
539 564
 				$full_groups = array($user_settings['id_group']);
565
+			}
540 566
 				if (!empty($user_settings['additional_groups']))
541 567
 				{
542 568
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -556,15 +582,17 @@  discard block
 block discarded – undo
556 582
 				);
557 583
 				$row = $smcFunc['db_fetch_assoc']($request);
558 584
 				$smcFunc['db_free_result']($request);
585
+			} else {
586
+							$row['total'] = 1;
559 587
 			}
560
-			else
561
-				$row['total'] = 1; //simplifies logics in the next "if"
588
+			//simplifies logics in the next "if"
562 589
 
563 590
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
564 591
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
565 592
 
566
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
567
-				redirectexit('action=profile;area=tfasetup;forced');
593
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
594
+							redirectexit('action=profile;area=tfasetup;forced');
595
+			}
568 596
 		}
569 597
 	}
570 598
 
@@ -601,29 +629,32 @@  discard block
 block discarded – undo
601 629
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
602 630
 				$user_settings['last_login'] = time();
603 631
 
604
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
605
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
632
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
633
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
634
+				}
606 635
 
607
-				if (!empty($modSettings['cache_enable']))
608
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
636
+				if (!empty($modSettings['cache_enable'])) {
637
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
638
+				}
609 639
 			}
640
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
641
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
610 642
 		}
611
-		elseif (empty($_SESSION['id_msg_last_visit']))
612
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
613 643
 
614 644
 		$username = $user_settings['member_name'];
615 645
 
616
-		if (empty($user_settings['additional_groups']))
617
-			$user_info = array(
646
+		if (empty($user_settings['additional_groups'])) {
647
+					$user_info = array(
618 648
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
619 649
 			);
620
-		else
621
-			$user_info = array(
650
+		} else {
651
+					$user_info = array(
622 652
 				'groups' => array_merge(
623 653
 					array($user_settings['id_group'], $user_settings['id_post_group']),
624 654
 					explode(',', $user_settings['additional_groups'])
625 655
 				)
626 656
 			);
657
+		}
627 658
 
628 659
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
629 660
 		$user_info['groups'] = array_map('intval', $user_info['groups']);
@@ -640,8 +671,7 @@  discard block
 block discarded – undo
640 671
 			$time_system = new DateTime('now', $tz_system);
641 672
 			$time_user = new DateTime('now', $tz_user);
642 673
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
643
-		}
644
-		else
674
+		} else
645 675
 		{
646 676
 			// !!! Compatibility.
647 677
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -655,8 +685,9 @@  discard block
 block discarded – undo
655 685
 		$user_info = array('groups' => array(-1));
656 686
 		$user_settings = array();
657 687
 
658
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
659
-			$_COOKIE[$cookiename] = '';
688
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
689
+					$_COOKIE[$cookiename] = '';
690
+		}
660 691
 
661 692
 		// Expire the 2FA cookie
662 693
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -673,19 +704,20 @@  discard block
 block discarded – undo
673 704
 		}
674 705
 
675 706
 		// Create a login token if it doesn't exist yet.
676
-		if (!isset($_SESSION['token']['post-login']))
677
-			createToken('login');
678
-		else
679
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
707
+		if (!isset($_SESSION['token']['post-login'])) {
708
+					createToken('login');
709
+		} else {
710
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
711
+		}
680 712
 
681 713
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
682 714
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
683 715
 		{
684 716
 			require_once($sourcedir . '/ManageSearchEngines.php');
685 717
 			$user_info['possibly_robot'] = SpiderCheck();
718
+		} elseif (!empty($modSettings['spider_mode'])) {
719
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
686 720
 		}
687
-		elseif (!empty($modSettings['spider_mode']))
688
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
689 721
 		// If we haven't turned on proper spider hunts then have a guess!
690 722
 		else
691 723
 		{
@@ -733,8 +765,9 @@  discard block
 block discarded – undo
733 765
 	$user_info['groups'] = array_unique($user_info['groups']);
734 766
 
735 767
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
736
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
737
-		unset($user_info['ignoreboards'][$tmp]);
768
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
769
+			unset($user_info['ignoreboards'][$tmp]);
770
+	}
738 771
 
739 772
 	// Allow the user to change their language.
740 773
 	if (!empty($modSettings['userLanguage']))
@@ -747,13 +780,14 @@  discard block
 block discarded – undo
747 780
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
748 781
 
749 782
 			// Make it permanent for members.
750
-			if (!empty($user_info['id']))
751
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
752
-			else
753
-				$_SESSION['language'] = $user_info['language'];
783
+			if (!empty($user_info['id'])) {
784
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
785
+			} else {
786
+							$_SESSION['language'] = $user_info['language'];
787
+			}
788
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
789
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
754 790
 		}
755
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
756
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
757 791
 	}
758 792
 
759 793
 	$temp = build_query_board($user_info['id']);
@@ -816,9 +850,9 @@  discard block
 block discarded – undo
816 850
 		}
817 851
 
818 852
 		// Remember redirection is the key to avoiding fallout from your bosses.
819
-		if (!empty($topic))
820
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
821
-		else
853
+		if (!empty($topic)) {
854
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
855
+		} else
822 856
 		{
823 857
 			loadPermissions();
824 858
 			loadTheme();
@@ -836,10 +870,11 @@  discard block
 block discarded – undo
836 870
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
837 871
 	{
838 872
 		// @todo SLOW?
839
-		if (!empty($topic))
840
-			$temp = cache_get_data('topic_board-' . $topic, 120);
841
-		else
842
-			$temp = cache_get_data('board-' . $board, 120);
873
+		if (!empty($topic)) {
874
+					$temp = cache_get_data('topic_board-' . $topic, 120);
875
+		} else {
876
+					$temp = cache_get_data('board-' . $board, 120);
877
+		}
843 878
 
844 879
 		if (!empty($temp))
845 880
 		{
@@ -877,8 +912,9 @@  discard block
 block discarded – undo
877 912
 			$row = $smcFunc['db_fetch_assoc']($request);
878 913
 
879 914
 			// Set the current board.
880
-			if (!empty($row['id_board']))
881
-				$board = $row['id_board'];
915
+			if (!empty($row['id_board'])) {
916
+							$board = $row['id_board'];
917
+			}
882 918
 
883 919
 			// Basic operating information. (globals... :/)
884 920
 			$board_info = array(
@@ -914,21 +950,23 @@  discard block
 block discarded – undo
914 950
 
915 951
 			do
916 952
 			{
917
-				if (!empty($row['id_moderator']))
918
-					$board_info['moderators'][$row['id_moderator']] = array(
953
+				if (!empty($row['id_moderator'])) {
954
+									$board_info['moderators'][$row['id_moderator']] = array(
919 955
 						'id' => $row['id_moderator'],
920 956
 						'name' => $row['real_name'],
921 957
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
922 958
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
923 959
 					);
960
+				}
924 961
 
925
-				if (!empty($row['id_moderator_group']))
926
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
962
+				if (!empty($row['id_moderator_group'])) {
963
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
927 964
 						'id' => $row['id_moderator_group'],
928 965
 						'name' => $row['group_name'],
929 966
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
930 967
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
931 968
 					);
969
+				}
932 970
 			}
933 971
 			while ($row = $smcFunc['db_fetch_assoc']($request));
934 972
 
@@ -960,12 +998,12 @@  discard block
 block discarded – undo
960 998
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
961 999
 			{
962 1000
 				// @todo SLOW?
963
-				if (!empty($topic))
964
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1001
+				if (!empty($topic)) {
1002
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1003
+				}
965 1004
 				cache_put_data('board-' . $board, $board_info, 120);
966 1005
 			}
967
-		}
968
-		else
1006
+		} else
969 1007
 		{
970 1008
 			// Otherwise the topic is invalid, there are no moderators, etc.
971 1009
 			$board_info = array(
@@ -979,8 +1017,9 @@  discard block
 block discarded – undo
979 1017
 		$smcFunc['db_free_result']($request);
980 1018
 	}
981 1019
 
982
-	if (!empty($topic))
983
-		$_GET['board'] = (int) $board;
1020
+	if (!empty($topic)) {
1021
+			$_GET['board'] = (int) $board;
1022
+	}
984 1023
 
985 1024
 	if (!empty($board))
986 1025
 	{
@@ -990,10 +1029,12 @@  discard block
 block discarded – undo
990 1029
 		// Now check if the user is a moderator.
991 1030
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
992 1031
 
993
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
995
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
996
-			$board_info['error'] = 'access';
1032
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1033
+					$board_info['error'] = 'access';
1034
+		}
1035
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1036
+					$board_info['error'] = 'access';
1037
+		}
997 1038
 
998 1039
 		// Build up the linktree.
999 1040
 		$context['linktree'] = array_merge(
@@ -1016,8 +1057,9 @@  discard block
 block discarded – undo
1016 1057
 	$context['current_board'] = $board;
1017 1058
 
1018 1059
 	// No posting in redirection boards!
1019
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1020
-		$board_info['error'] == 'post_in_redirect';
1060
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1061
+			$board_info['error'] == 'post_in_redirect';
1062
+	}
1021 1063
 
1022 1064
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1023 1065
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1043,24 +1085,23 @@  discard block
 block discarded – undo
1043 1085
 			ob_end_clean();
1044 1086
 			header('HTTP/1.1 403 Forbidden');
1045 1087
 			die;
1046
-		}
1047
-		elseif ($board_info['error'] == 'post_in_redirect')
1088
+		} elseif ($board_info['error'] == 'post_in_redirect')
1048 1089
 		{
1049 1090
 			// Slightly different error message here...
1050 1091
 			fatal_lang_error('cannot_post_redirect', false);
1051
-		}
1052
-		elseif ($user_info['is_guest'])
1092
+		} elseif ($user_info['is_guest'])
1053 1093
 		{
1054 1094
 			loadLanguage('Errors');
1055 1095
 			is_not_guest($txt['topic_gone']);
1096
+		} else {
1097
+					fatal_lang_error('topic_gone', false);
1056 1098
 		}
1057
-		else
1058
-			fatal_lang_error('topic_gone', false);
1059 1099
 	}
1060 1100
 
1061
-	if ($user_info['is_mod'])
1062
-		$user_info['groups'][] = 3;
1063
-}
1101
+	if ($user_info['is_mod']) {
1102
+			$user_info['groups'][] = 3;
1103
+	}
1104
+	}
1064 1105
 
1065 1106
 /**
1066 1107
  * Load this user's permissions.
@@ -1081,8 +1122,9 @@  discard block
 block discarded – undo
1081 1122
 		asort($cache_groups);
1082 1123
 		$cache_groups = implode(',', $cache_groups);
1083 1124
 		// If it's a spider then cache it different.
1084
-		if ($user_info['possibly_robot'])
1085
-			$cache_groups .= '-spider';
1125
+		if ($user_info['possibly_robot']) {
1126
+					$cache_groups .= '-spider';
1127
+		}
1086 1128
 
1087 1129
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1088 1130
 		{
@@ -1090,9 +1132,9 @@  discard block
 block discarded – undo
1090 1132
 			banPermissions();
1091 1133
 
1092 1134
 			return;
1135
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1136
+					list ($user_info['permissions'], $removals) = $temp;
1093 1137
 		}
1094
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1095
-			list ($user_info['permissions'], $removals) = $temp;
1096 1138
 	}
1097 1139
 
1098 1140
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1114,23 +1156,26 @@  discard block
 block discarded – undo
1114 1156
 		$removals = array();
1115 1157
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1116 1158
 		{
1117
-			if (empty($row['add_deny']))
1118
-				$removals[] = $row['permission'];
1119
-			else
1120
-				$user_info['permissions'][] = $row['permission'];
1159
+			if (empty($row['add_deny'])) {
1160
+							$removals[] = $row['permission'];
1161
+			} else {
1162
+							$user_info['permissions'][] = $row['permission'];
1163
+			}
1121 1164
 		}
1122 1165
 		$smcFunc['db_free_result']($request);
1123 1166
 
1124
-		if (isset($cache_groups))
1125
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1167
+		if (isset($cache_groups)) {
1168
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1169
+		}
1126 1170
 	}
1127 1171
 
1128 1172
 	// Get the board permissions.
1129 1173
 	if (!empty($board))
1130 1174
 	{
1131 1175
 		// Make sure the board (if any) has been loaded by loadBoard().
1132
-		if (!isset($board_info['profile']))
1133
-			fatal_lang_error('no_board');
1176
+		if (!isset($board_info['profile'])) {
1177
+					fatal_lang_error('no_board');
1178
+		}
1134 1179
 
1135 1180
 		$request = $smcFunc['db_query']('', '
1136 1181
 			SELECT permission, add_deny
@@ -1146,20 +1191,23 @@  discard block
 block discarded – undo
1146 1191
 		);
1147 1192
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1148 1193
 		{
1149
-			if (empty($row['add_deny']))
1150
-				$removals[] = $row['permission'];
1151
-			else
1152
-				$user_info['permissions'][] = $row['permission'];
1194
+			if (empty($row['add_deny'])) {
1195
+							$removals[] = $row['permission'];
1196
+			} else {
1197
+							$user_info['permissions'][] = $row['permission'];
1198
+			}
1153 1199
 		}
1154 1200
 		$smcFunc['db_free_result']($request);
1155 1201
 	}
1156 1202
 
1157 1203
 	// Remove all the permissions they shouldn't have ;).
1158
-	if (!empty($modSettings['permission_enable_deny']))
1159
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1204
+	if (!empty($modSettings['permission_enable_deny'])) {
1205
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1206
+	}
1160 1207
 
1161
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1162
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1208
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1209
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1210
+	}
1163 1211
 
1164 1212
 	// Banned?  Watch, don't touch..
1165 1213
 	banPermissions();
@@ -1171,17 +1219,18 @@  discard block
 block discarded – undo
1171 1219
 		{
1172 1220
 			require_once($sourcedir . '/Subs-Auth.php');
1173 1221
 			rebuildModCache();
1222
+		} else {
1223
+					$user_info['mod_cache'] = $_SESSION['mc'];
1174 1224
 		}
1175
-		else
1176
-			$user_info['mod_cache'] = $_SESSION['mc'];
1177 1225
 
1178 1226
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1179 1227
 		// For example this drastically simplifies certain changes to the profile area.
1180 1228
 		$user_info['permissions'][] = 'is_not_guest';
1181 1229
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1182 1230
 		$user_info['permissions'][] = 'profile_view_own';
1183
-		if (in_array('profile_view', $user_info['permissions']))
1184
-			$user_info['permissions'][] = 'profile_view_any';
1231
+		if (in_array('profile_view', $user_info['permissions'])) {
1232
+					$user_info['permissions'][] = 'profile_view_any';
1233
+		}
1185 1234
 	}
1186 1235
 }
1187 1236
 
@@ -1199,8 +1248,9 @@  discard block
 block discarded – undo
1199 1248
 	global $image_proxy_enabled, $user_info;
1200 1249
 
1201 1250
 	// Can't just look for no users :P.
1202
-	if (empty($users))
1203
-		return array();
1251
+	if (empty($users)) {
1252
+			return array();
1253
+	}
1204 1254
 
1205 1255
 	// Pass the set value
1206 1256
 	$context['loadMemberContext_set'] = $set;
@@ -1215,8 +1265,9 @@  discard block
 block discarded – undo
1215 1265
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1216 1266
 		{
1217 1267
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1218
-			if ($data == null)
1219
-				continue;
1268
+			if ($data == null) {
1269
+							continue;
1270
+			}
1220 1271
 
1221 1272
 			$loaded_ids[] = $data['id_member'];
1222 1273
 			$user_profile[$data['id_member']] = $data;
@@ -1283,16 +1334,19 @@  discard block
 block discarded – undo
1283 1334
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1284 1335
 
1285 1336
 			// Take care of proxying avatar if required, do this here for maximum reach
1286
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1287
-				$row['avatar'] = get_proxied_url($row['avatar']);
1337
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1338
+							$row['avatar'] = get_proxied_url($row['avatar']);
1339
+			}
1288 1340
 
1289 1341
 			// Keep track of the member's normal member group
1290 1342
 			$row['primary_group'] = !empty($row['member_group']) ? $row['member_group'] : '';
1291 1343
 
1292
-			if (isset($row['member_ip']))
1293
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1294
-			if (isset($row['member_ip2']))
1295
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1344
+			if (isset($row['member_ip'])) {
1345
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1346
+			}
1347
+			if (isset($row['member_ip2'])) {
1348
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1349
+			}
1296 1350
 			$new_loaded_ids[] = $row['id_member'];
1297 1351
 			$loaded_ids[] = $row['id_member'];
1298 1352
 			$row['options'] = array();
@@ -1311,8 +1365,9 @@  discard block
 block discarded – undo
1311 1365
 				'loaded_ids' => $new_loaded_ids,
1312 1366
 			)
1313 1367
 		);
1314
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1315
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1368
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1369
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1370
+		}
1316 1371
 		$smcFunc['db_free_result']($request);
1317 1372
 	}
1318 1373
 
@@ -1323,10 +1378,11 @@  discard block
 block discarded – undo
1323 1378
 	{
1324 1379
 		foreach ($loaded_ids as $a_member)
1325 1380
 		{
1326
-			if (!empty($user_profile[$a_member]['additional_groups']))
1327
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1328
-			else
1329
-				$groups = array($user_profile[$a_member]['id_group']);
1381
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1382
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1383
+			} else {
1384
+							$groups = array($user_profile[$a_member]['id_group']);
1385
+			}
1330 1386
 
1331 1387
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1332 1388
 
@@ -1339,8 +1395,9 @@  discard block
 block discarded – undo
1339 1395
 
1340 1396
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1341 1397
 	{
1342
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1343
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1398
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1399
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1400
+		}
1344 1401
 	}
1345 1402
 
1346 1403
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1366,14 +1423,17 @@  discard block
 block discarded – undo
1366 1423
 		foreach ($temp_mods as $id)
1367 1424
 		{
1368 1425
 			// By popular demand, don't show admins or global moderators as moderators.
1369
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1370
-				$user_profile[$id]['member_group'] = $row['member_group'];
1426
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1427
+							$user_profile[$id]['member_group'] = $row['member_group'];
1428
+			}
1371 1429
 
1372 1430
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1373
-			if (!empty($row['icons']))
1374
-				$user_profile[$id]['icons'] = $row['icons'];
1375
-			if (!empty($row['member_group_color']))
1376
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1431
+			if (!empty($row['icons'])) {
1432
+							$user_profile[$id]['icons'] = $row['icons'];
1433
+			}
1434
+			if (!empty($row['member_group_color'])) {
1435
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1436
+			}
1377 1437
 		}
1378 1438
 	}
1379 1439
 
@@ -1395,12 +1455,14 @@  discard block
 block discarded – undo
1395 1455
 	static $loadedLanguages = array();
1396 1456
 
1397 1457
 	// If this person's data is already loaded, skip it.
1398
-	if (isset($dataLoaded[$user]))
1399
-		return true;
1458
+	if (isset($dataLoaded[$user])) {
1459
+			return true;
1460
+	}
1400 1461
 
1401 1462
 	// We can't load guests or members not loaded by loadMemberData()!
1402
-	if ($user == 0)
1403
-		return false;
1463
+	if ($user == 0) {
1464
+			return false;
1465
+	}
1404 1466
 	if (!isset($user_profile[$user]))
1405 1467
 	{
1406 1468
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1426,12 +1488,16 @@  discard block
 block discarded – undo
1426 1488
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1427 1489
 
1428 1490
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1429
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1491
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1492
+		//icon is set and exists
1430 1493
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1431
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1494
+	} elseif (isset($profile['icons'][1])) {
1495
+		//icon is set and doesn't exist, fallback to default
1432 1496
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1433
-	else //not set, bye bye
1497
+	} else {
1498
+		//not set, bye bye
1434 1499
 		$group_icon_url = '';
1500
+	}
1435 1501
 
1436 1502
 	// These minimal values are always loaded
1437 1503
 	$memberContext[$user] = array(
@@ -1450,8 +1516,9 @@  discard block
 block discarded – undo
1450 1516
 	if ($context['loadMemberContext_set'] != 'minimal')
1451 1517
 	{
1452 1518
 		// Go the extra mile and load the user's native language name.
1453
-		if (empty($loadedLanguages))
1454
-			$loadedLanguages = getLanguages();
1519
+		if (empty($loadedLanguages)) {
1520
+					$loadedLanguages = getLanguages();
1521
+		}
1455 1522
 
1456 1523
 		$memberContext[$user] += array(
1457 1524
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1506,31 +1573,33 @@  discard block
 block discarded – undo
1506 1573
 	{
1507 1574
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1508 1575
 		{
1509
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1510
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1511
-			else
1512
-				$image = get_gravatar_url($profile['email_address']);
1513
-		}
1514
-		else
1576
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1577
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1578
+			} else {
1579
+							$image = get_gravatar_url($profile['email_address']);
1580
+			}
1581
+		} else
1515 1582
 		{
1516 1583
 			// So it's stored in the member table?
1517 1584
 			if (!empty($profile['avatar']))
1518 1585
 			{
1519 1586
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1587
+			} elseif (!empty($profile['filename'])) {
1588
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1520 1589
 			}
1521
-			elseif (!empty($profile['filename']))
1522
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1523 1590
 			// Right... no avatar...use the default one
1524
-			else
1525
-				$image = $modSettings['avatar_url'] . '/default.png';
1591
+			else {
1592
+							$image = $modSettings['avatar_url'] . '/default.png';
1593
+			}
1526 1594
 		}
1527
-		if (!empty($image))
1528
-			$memberContext[$user]['avatar'] = array(
1595
+		if (!empty($image)) {
1596
+					$memberContext[$user]['avatar'] = array(
1529 1597
 				'name' => $profile['avatar'],
1530 1598
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1531 1599
 				'href' => $image,
1532 1600
 				'url' => $image,
1533 1601
 			);
1602
+		}
1534 1603
 	}
1535 1604
 
1536 1605
 	// Are we also loading the members custom fields into context?
@@ -1538,13 +1607,15 @@  discard block
 block discarded – undo
1538 1607
 	{
1539 1608
 		$memberContext[$user]['custom_fields'] = array();
1540 1609
 
1541
-		if (!isset($context['display_fields']))
1542
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1610
+		if (!isset($context['display_fields'])) {
1611
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1612
+		}
1543 1613
 
1544 1614
 		foreach ($context['display_fields'] as $custom)
1545 1615
 		{
1546
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1547
-				continue;
1616
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1617
+							continue;
1618
+			}
1548 1619
 
1549 1620
 			$value = $profile['options'][$custom['col_name']];
1550 1621
 
@@ -1552,31 +1623,36 @@  discard block
 block discarded – undo
1552 1623
 			$currentKey = 0;
1553 1624
 
1554 1625
 			// Create a key => value array for multiple options fields
1555
-			if (!empty($custom['options']))
1556
-				foreach ($custom['options'] as $k => $v)
1626
+			if (!empty($custom['options'])) {
1627
+							foreach ($custom['options'] as $k => $v)
1557 1628
 				{
1558 1629
 					$fieldOptions[] = $v;
1559
-					if (empty($currentKey))
1560
-						$currentKey = $v == $value ? $k : 0;
1630
+			}
1631
+					if (empty($currentKey)) {
1632
+											$currentKey = $v == $value ? $k : 0;
1633
+					}
1561 1634
 				}
1562 1635
 
1563 1636
 			// BBC?
1564
-			if ($custom['bbc'])
1565
-				$value = parse_bbc($value);
1637
+			if ($custom['bbc']) {
1638
+							$value = parse_bbc($value);
1639
+			}
1566 1640
 
1567 1641
 			// ... or checkbox?
1568
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1569
-				$value = $value ? $txt['yes'] : $txt['no'];
1642
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1643
+							$value = $value ? $txt['yes'] : $txt['no'];
1644
+			}
1570 1645
 
1571 1646
 			// Enclosing the user input within some other text?
1572
-			if (!empty($custom['enclose']))
1573
-				$value = strtr($custom['enclose'], array(
1647
+			if (!empty($custom['enclose'])) {
1648
+							$value = strtr($custom['enclose'], array(
1574 1649
 					'{SCRIPTURL}' => $scripturl,
1575 1650
 					'{IMAGES_URL}' => $settings['images_url'],
1576 1651
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1577 1652
 					'{INPUT}' => $value,
1578 1653
 					'{KEY}' => $currentKey,
1579 1654
 				));
1655
+			}
1580 1656
 
1581 1657
 			$memberContext[$user]['custom_fields'][] = array(
1582 1658
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1603,8 +1679,9 @@  discard block
 block discarded – undo
1603 1679
 	global $smcFunc, $txt, $scripturl, $settings;
1604 1680
 
1605 1681
 	// Do not waste my time...
1606
-	if (empty($users) || empty($params))
1607
-		return false;
1682
+	if (empty($users) || empty($params)) {
1683
+			return false;
1684
+	}
1608 1685
 
1609 1686
 	// Make sure it's an array.
1610 1687
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1631,41 +1708,48 @@  discard block
 block discarded – undo
1631 1708
 		$currentKey = 0;
1632 1709
 
1633 1710
 		// Create a key => value array for multiple options fields
1634
-		if (!empty($row['field_options']))
1635
-			foreach (explode(',', $row['field_options']) as $k => $v)
1711
+		if (!empty($row['field_options'])) {
1712
+					foreach (explode(',', $row['field_options']) as $k => $v)
1636 1713
 			{
1637 1714
 				$fieldOptions[] = $v;
1638
-				if (empty($currentKey))
1639
-					$currentKey = $v == $row['value'] ? $k : 0;
1715
+		}
1716
+				if (empty($currentKey)) {
1717
+									$currentKey = $v == $row['value'] ? $k : 0;
1718
+				}
1640 1719
 			}
1641 1720
 
1642 1721
 		// BBC?
1643
-		if (!empty($row['bbc']))
1644
-			$row['value'] = parse_bbc($row['value']);
1722
+		if (!empty($row['bbc'])) {
1723
+					$row['value'] = parse_bbc($row['value']);
1724
+		}
1645 1725
 
1646 1726
 		// ... or checkbox?
1647
-		elseif (isset($row['type']) && $row['type'] == 'check')
1648
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1727
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1728
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1729
+		}
1649 1730
 
1650 1731
 		// Enclosing the user input within some other text?
1651
-		if (!empty($row['enclose']))
1652
-			$row['value'] = strtr($row['enclose'], array(
1732
+		if (!empty($row['enclose'])) {
1733
+					$row['value'] = strtr($row['enclose'], array(
1653 1734
 				'{SCRIPTURL}' => $scripturl,
1654 1735
 				'{IMAGES_URL}' => $settings['images_url'],
1655 1736
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1656 1737
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1657 1738
 				'{KEY}' => $currentKey,
1658 1739
 			));
1740
+		}
1659 1741
 
1660 1742
 		// Send a simple array if there is just 1 param
1661
-		if (count($params) == 1)
1662
-			$return[$row['id_member']] = $row;
1743
+		if (count($params) == 1) {
1744
+					$return[$row['id_member']] = $row;
1745
+		}
1663 1746
 
1664 1747
 		// More than 1? knock yourself out...
1665 1748
 		else
1666 1749
 		{
1667
-			if (!isset($return[$row['id_member']]))
1668
-				$return[$row['id_member']] = array();
1750
+			if (!isset($return[$row['id_member']])) {
1751
+							$return[$row['id_member']] = array();
1752
+			}
1669 1753
 
1670 1754
 			$return[$row['id_member']][$row['variable']] = $row;
1671 1755
 		}
@@ -1699,8 +1783,9 @@  discard block
 block discarded – undo
1699 1783
 	global $context;
1700 1784
 
1701 1785
 	// Don't know any browser!
1702
-	if (empty($context['browser']))
1703
-		detectBrowser();
1786
+	if (empty($context['browser'])) {
1787
+			detectBrowser();
1788
+	}
1704 1789
 
1705 1790
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1706 1791
 }
@@ -1718,8 +1803,9 @@  discard block
 block discarded – undo
1718 1803
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1719 1804
 
1720 1805
 	// The theme was specified by parameter.
1721
-	if (!empty($id_theme))
1722
-		$id_theme = (int) $id_theme;
1806
+	if (!empty($id_theme)) {
1807
+			$id_theme = (int) $id_theme;
1808
+	}
1723 1809
 	// The theme was specified by REQUEST.
1724 1810
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1725 1811
 	{
@@ -1727,32 +1813,38 @@  discard block
 block discarded – undo
1727 1813
 		$_SESSION['id_theme'] = $id_theme;
1728 1814
 	}
1729 1815
 	// The theme was specified by REQUEST... previously.
1730
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1731
-		$id_theme = (int) $_SESSION['id_theme'];
1816
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1817
+			$id_theme = (int) $_SESSION['id_theme'];
1818
+	}
1732 1819
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1733
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1734
-		$id_theme = $user_info['theme'];
1820
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1821
+			$id_theme = $user_info['theme'];
1822
+	}
1735 1823
 	// The theme was specified by the board.
1736
-	elseif (!empty($board_info['theme']))
1737
-		$id_theme = $board_info['theme'];
1824
+	elseif (!empty($board_info['theme'])) {
1825
+			$id_theme = $board_info['theme'];
1826
+	}
1738 1827
 	// The theme is the forum's default.
1739
-	else
1740
-		$id_theme = $modSettings['theme_guests'];
1828
+	else {
1829
+			$id_theme = $modSettings['theme_guests'];
1830
+	}
1741 1831
 
1742 1832
 	// Verify the id_theme... no foul play.
1743 1833
 	// Always allow the board specific theme, if they are overriding.
1744
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1745
-		$id_theme = $board_info['theme'];
1834
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1835
+			$id_theme = $board_info['theme'];
1836
+	}
1746 1837
 	// If they have specified a particular theme to use with SSI allow it to be used.
1747
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1748
-		$id_theme = (int) $id_theme;
1749
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1838
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1839
+			$id_theme = (int) $id_theme;
1840
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1750 1841
 	{
1751 1842
 		$themes = explode(',', $modSettings['enableThemes']);
1752
-		if (!in_array($id_theme, $themes))
1753
-			$id_theme = $modSettings['theme_guests'];
1754
-		else
1755
-			$id_theme = (int) $id_theme;
1843
+		if (!in_array($id_theme, $themes)) {
1844
+					$id_theme = $modSettings['theme_guests'];
1845
+		} else {
1846
+					$id_theme = (int) $id_theme;
1847
+		}
1756 1848
 	}
1757 1849
 		
1758 1850
 	// We already load the basic stuff?
@@ -1761,18 +1853,19 @@  discard block
 block discarded – undo
1761 1853
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1762 1854
 
1763 1855
 		// Disable image proxy if we don't have SSL enabled
1764
-		if (empty($modSettings['force_ssl']))
1765
-			$image_proxy_enabled = false;
1856
+		if (empty($modSettings['force_ssl'])) {
1857
+					$image_proxy_enabled = false;
1858
+		}
1766 1859
 
1767 1860
 		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1768 1861
 		{
1769 1862
 			$themeData = $temp;
1770 1863
 			$flag = true;
1864
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1865
+					$themeData = $temp + array($member => array());
1866
+		} else {
1867
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1771 1868
 		}
1772
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1773
-			$themeData = $temp + array($member => array());
1774
-		else
1775
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1776 1869
 
1777 1870
 		if (empty($flag))
1778 1871
 		{
@@ -1792,31 +1885,37 @@  discard block
 block discarded – undo
1792 1885
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1793 1886
 			{
1794 1887
 				// There are just things we shouldn't be able to change as members.
1795
-				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1796
-					continue;
1888
+				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1889
+									continue;
1890
+				}
1797 1891
 
1798 1892
 				// If this is the theme_dir of the default theme, store it.
1799
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1800
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1893
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1894
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1895
+				}
1801 1896
 
1802 1897
 				// If this isn't set yet, is a theme option, or is not the default theme..
1803
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1804
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1898
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1899
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1900
+				}
1805 1901
 			}
1806 1902
 			$smcFunc['db_free_result']($result);
1807 1903
 
1808
-			if (!empty($themeData[-1]))
1809
-				foreach ($themeData[-1] as $k => $v)
1904
+			if (!empty($themeData[-1])) {
1905
+							foreach ($themeData[-1] as $k => $v)
1810 1906
 				{
1811 1907
 					if (!isset($themeData[$member][$k]))
1812 1908
 						$themeData[$member][$k] = $v;
1909
+			}
1813 1910
 				}
1814 1911
 
1815
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1816
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1912
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1913
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1914
+			}
1817 1915
 			// Only if we didn't already load that part of the cache...
1818
-			elseif (!isset($temp))
1819
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1916
+			elseif (!isset($temp)) {
1917
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1918
+			}
1820 1919
 		}
1821 1920
 
1822 1921
 		$settings = $themeData[0];
@@ -1833,17 +1932,20 @@  discard block
 block discarded – undo
1833 1932
 		$settings['template_dirs'][] = $settings['theme_dir'];
1834 1933
 
1835 1934
 		// Based on theme (if there is one).
1836
-		if (!empty($settings['base_theme_dir']))
1837
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1935
+		if (!empty($settings['base_theme_dir'])) {
1936
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1937
+		}
1838 1938
 
1839 1939
 		// Lastly the default theme.
1840
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1841
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1940
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1941
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1942
+		}
1842 1943
 	}
1843 1944
 
1844 1945
 
1845
-	if (!$initialize)
1846
-		return;
1946
+	if (!$initialize) {
1947
+			return;
1948
+	}
1847 1949
 
1848 1950
 	// Check to see if we're forcing SSL
1849 1951
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1864,8 +1966,9 @@  discard block
 block discarded – undo
1864 1966
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1865 1967
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1866 1968
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1867
-		if ($temp != '/')
1868
-			$detected_url .= $temp;
1969
+		if ($temp != '/') {
1970
+					$detected_url .= $temp;
1971
+		}
1869 1972
 	}
1870 1973
 	if (isset($detected_url) && $detected_url != $boardurl)
1871 1974
 	{
@@ -1877,8 +1980,9 @@  discard block
 block discarded – undo
1877 1980
 			foreach ($aliases as $alias)
1878 1981
 			{
1879 1982
 				// Rip off all the boring parts, spaces, etc.
1880
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1881
-					$do_fix = true;
1983
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1984
+									$do_fix = true;
1985
+				}
1882 1986
 			}
1883 1987
 		}
1884 1988
 
@@ -1886,21 +1990,23 @@  discard block
 block discarded – undo
1886 1990
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1887 1991
 		{
1888 1992
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1889
-			if (empty($_GET))
1890
-				redirectexit('wwwRedirect');
1891
-			else
1993
+			if (empty($_GET)) {
1994
+							redirectexit('wwwRedirect');
1995
+			} else
1892 1996
 			{
1893 1997
 				$k = key($_GET);
1894 1998
 				$v = current($_GET);
1895 1999
 
1896
-				if ($k != 'wwwRedirect')
1897
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
2000
+				if ($k != 'wwwRedirect') {
2001
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
2002
+				}
1898 2003
 			}
1899 2004
 		}
1900 2005
 
1901 2006
 		// #3 is just a check for SSL...
1902
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1903
-			$do_fix = true;
2007
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
2008
+					$do_fix = true;
2009
+		}
1904 2010
 
1905 2011
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1906 2012
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1935,8 +2041,9 @@  discard block
 block discarded – undo
1935 2041
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1936 2042
 				}
1937 2043
 			}
1938
-			foreach ($context['linktree'] as $k => $dummy)
1939
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2044
+			foreach ($context['linktree'] as $k => $dummy) {
2045
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2046
+			}
1940 2047
 		}
1941 2048
 	}
1942 2049
 	// Set up the contextual user array.
@@ -1955,16 +2062,16 @@  discard block
 block discarded – undo
1955 2062
 			'email' => $user_info['email'],
1956 2063
 			'ignoreusers' => $user_info['ignoreusers'],
1957 2064
 		);
1958
-		if (!$context['user']['is_guest'])
1959
-			$context['user']['name'] = $user_info['name'];
1960
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1961
-			$context['user']['name'] = $txt['guest_title'];
2065
+		if (!$context['user']['is_guest']) {
2066
+					$context['user']['name'] = $user_info['name'];
2067
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2068
+					$context['user']['name'] = $txt['guest_title'];
2069
+		}
1962 2070
 
1963 2071
 		// Determine the current smiley set.
1964 2072
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1965 2073
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1966
-	}
1967
-	else
2074
+	} else
1968 2075
 	{
1969 2076
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1970 2077
 		$context['user'] = array(
@@ -1998,18 +2105,24 @@  discard block
 block discarded – undo
1998 2105
 	}
1999 2106
 
2000 2107
 	// Some basic information...
2001
-	if (!isset($context['html_headers']))
2002
-		$context['html_headers'] = '';
2003
-	if (!isset($context['javascript_files']))
2004
-		$context['javascript_files'] = array();
2005
-	if (!isset($context['css_files']))
2006
-		$context['css_files'] = array();
2007
-	if (!isset($context['css_header']))
2008
-		$context['css_header'] = array();
2009
-	if (!isset($context['javascript_inline']))
2010
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2011
-	if (!isset($context['javascript_vars']))
2012
-		$context['javascript_vars'] = array();
2108
+	if (!isset($context['html_headers'])) {
2109
+			$context['html_headers'] = '';
2110
+	}
2111
+	if (!isset($context['javascript_files'])) {
2112
+			$context['javascript_files'] = array();
2113
+	}
2114
+	if (!isset($context['css_files'])) {
2115
+			$context['css_files'] = array();
2116
+	}
2117
+	if (!isset($context['css_header'])) {
2118
+			$context['css_header'] = array();
2119
+	}
2120
+	if (!isset($context['javascript_inline'])) {
2121
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2122
+	}
2123
+	if (!isset($context['javascript_vars'])) {
2124
+			$context['javascript_vars'] = array();
2125
+	}
2013 2126
 
2014 2127
 	$context['login_url'] =  $scripturl . '?action=login2';
2015 2128
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2021,16 +2134,18 @@  discard block
 block discarded – undo
2021 2134
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2022 2135
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2023 2136
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2024
-	if (isset($modSettings['load_average']))
2025
-		$context['load_average'] = $modSettings['load_average'];
2137
+	if (isset($modSettings['load_average'])) {
2138
+			$context['load_average'] = $modSettings['load_average'];
2139
+	}
2026 2140
 
2027 2141
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2028 2142
 	detectBrowser();
2029 2143
 
2030 2144
 	// Set the top level linktree up.
2031 2145
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2032
-	if (empty($context['linktree']))
2033
-		$context['linktree'] = array();
2146
+	if (empty($context['linktree'])) {
2147
+			$context['linktree'] = array();
2148
+	}
2034 2149
 	array_unshift($context['linktree'], array(
2035 2150
 		'url' => $scripturl,
2036 2151
 		'name' => $context['forum_name_html_safe']
@@ -2039,8 +2154,9 @@  discard block
 block discarded – undo
2039 2154
 	// This allows sticking some HTML on the page output - useful for controls.
2040 2155
 	$context['insert_after_template'] = '';
2041 2156
 
2042
-	if (!isset($txt))
2043
-		$txt = array();
2157
+	if (!isset($txt)) {
2158
+			$txt = array();
2159
+	}
2044 2160
 
2045 2161
 	$simpleActions = array(
2046 2162
 		'findmember',
@@ -2086,9 +2202,10 @@  discard block
 block discarded – undo
2086 2202
 
2087 2203
 	// See if theres any extra param to check.
2088 2204
 	$requiresXML = false;
2089
-	foreach ($extraParams as $key => $extra)
2090
-		if (isset($_REQUEST[$extra]))
2205
+	foreach ($extraParams as $key => $extra) {
2206
+			if (isset($_REQUEST[$extra]))
2091 2207
 			$requiresXML = true;
2208
+	}
2092 2209
 
2093 2210
 	// Output is fully XML, so no need for the index template.
2094 2211
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2103,37 +2220,39 @@  discard block
 block discarded – undo
2103 2220
 	{
2104 2221
 		loadLanguage('index+Modifications');
2105 2222
 		$context['template_layers'] = array();
2106
-	}
2107
-
2108
-	else
2223
+	} else
2109 2224
 	{
2110 2225
 		// Custom templates to load, or just default?
2111
-		if (isset($settings['theme_templates']))
2112
-			$templates = explode(',', $settings['theme_templates']);
2113
-		else
2114
-			$templates = array('index');
2226
+		if (isset($settings['theme_templates'])) {
2227
+					$templates = explode(',', $settings['theme_templates']);
2228
+		} else {
2229
+					$templates = array('index');
2230
+		}
2115 2231
 
2116 2232
 		// Load each template...
2117
-		foreach ($templates as $template)
2118
-			loadTemplate($template);
2233
+		foreach ($templates as $template) {
2234
+					loadTemplate($template);
2235
+		}
2119 2236
 
2120 2237
 		// ...and attempt to load their associated language files.
2121 2238
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2122 2239
 		loadLanguage($required_files, '', false);
2123 2240
 
2124 2241
 		// Custom template layers?
2125
-		if (isset($settings['theme_layers']))
2126
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2127
-		else
2128
-			$context['template_layers'] = array('html', 'body');
2242
+		if (isset($settings['theme_layers'])) {
2243
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2244
+		} else {
2245
+					$context['template_layers'] = array('html', 'body');
2246
+		}
2129 2247
 	}
2130 2248
 
2131 2249
 	// Initialize the theme.
2132 2250
 	loadSubTemplate('init', 'ignore');
2133 2251
 
2134 2252
 	// Allow overriding the board wide time/number formats.
2135
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2136
-		$user_info['time_format'] = $txt['time_format'];
2253
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2254
+			$user_info['time_format'] = $txt['time_format'];
2255
+	}
2137 2256
 
2138 2257
 	// Set the character set from the template.
2139 2258
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2141,12 +2260,14 @@  discard block
 block discarded – undo
2141 2260
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2142 2261
 
2143 2262
 	// Guests may still need a name.
2144
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2145
-		$context['user']['name'] = $txt['guest_title'];
2263
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2264
+			$context['user']['name'] = $txt['guest_title'];
2265
+	}
2146 2266
 
2147 2267
 	// Any theme-related strings that need to be loaded?
2148
-	if (!empty($settings['require_theme_strings']))
2149
-		loadLanguage('ThemeStrings', '', false);
2268
+	if (!empty($settings['require_theme_strings'])) {
2269
+			loadLanguage('ThemeStrings', '', false);
2270
+	}
2150 2271
 
2151 2272
 	// Make a special URL for the language.
2152 2273
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2157,8 +2278,9 @@  discard block
 block discarded – undo
2157 2278
 	// Here is my luvly Responsive CSS
2158 2279
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2159 2280
 
2160
-	if ($context['right_to_left'])
2161
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2281
+	if ($context['right_to_left']) {
2282
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2283
+	}
2162 2284
 
2163 2285
 	// We allow theme variants, because we're cool.
2164 2286
 	$context['theme_variant'] = '';
@@ -2166,14 +2288,17 @@  discard block
 block discarded – undo
2166 2288
 	if (!empty($settings['theme_variants']))
2167 2289
 	{
2168 2290
 		// Overriding - for previews and that ilk.
2169
-		if (!empty($_REQUEST['variant']))
2170
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2291
+		if (!empty($_REQUEST['variant'])) {
2292
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2293
+		}
2171 2294
 		// User selection?
2172
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2173
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2295
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2296
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2297
+		}
2174 2298
 		// If not a user variant, select the default.
2175
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2176
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2299
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2300
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2301
+		}
2177 2302
 
2178 2303
 		// Do this to keep things easier in the templates.
2179 2304
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2182,20 +2307,23 @@  discard block
 block discarded – undo
2182 2307
 		if (!empty($context['theme_variant']))
2183 2308
 		{
2184 2309
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2185
-			if ($context['right_to_left'])
2186
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2310
+			if ($context['right_to_left']) {
2311
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2312
+			}
2187 2313
 		}
2188 2314
 	}
2189 2315
 
2190 2316
 	// Let's be compatible with old themes!
2191
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2192
-		$context['template_layers'] = array('main');
2317
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2318
+			$context['template_layers'] = array('main');
2319
+	}
2193 2320
 
2194 2321
 	$context['tabindex'] = 1;
2195 2322
 
2196 2323
 	// Compatibility.
2197
-	if (!isset($settings['theme_version']))
2198
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2324
+	if (!isset($settings['theme_version'])) {
2325
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2326
+	}
2199 2327
 
2200 2328
 	// Default JS variables for use in every theme
2201 2329
 	$context['javascript_vars'] = array(
@@ -2215,18 +2343,18 @@  discard block
 block discarded – undo
2215 2343
 	);
2216 2344
 
2217 2345
 	// Add the JQuery library to the list of files to load.
2218
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2219
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2220
-
2221
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2222
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2223
-
2224
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2225
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2346
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2347
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2348
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2349
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2350
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2351
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2352
+	}
2226 2353
 
2227 2354
 	// Auto loading? template_javascript() will take care of the local half of this.
2228
-	else
2229
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2355
+	else {
2356
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2357
+	}
2230 2358
 
2231 2359
 	// Queue our JQuery plugins!
2232 2360
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2249,12 +2377,12 @@  discard block
 block discarded – undo
2249 2377
 			require_once($sourcedir . '/ScheduledTasks.php');
2250 2378
 
2251 2379
 			// What to do, what to do?!
2252
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2253
-				AutoTask();
2254
-			else
2255
-				ReduceMailQueue();
2256
-		}
2257
-		else
2380
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2381
+							AutoTask();
2382
+			} else {
2383
+							ReduceMailQueue();
2384
+			}
2385
+		} else
2258 2386
 		{
2259 2387
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2260 2388
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2305,8 +2433,9 @@  discard block
 block discarded – undo
2305 2433
 		foreach ($theme_includes as $include)
2306 2434
 		{
2307 2435
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2308
-			if (file_exists($include))
2309
-				require_once($include);
2436
+			if (file_exists($include)) {
2437
+							require_once($include);
2438
+			}
2310 2439
 		}
2311 2440
 	}
2312 2441
 
@@ -2336,16 +2465,19 @@  discard block
 block discarded – undo
2336 2465
 	// Do any style sheets first, cause we're easy with those.
2337 2466
 	if (!empty($style_sheets))
2338 2467
 	{
2339
-		if (!is_array($style_sheets))
2340
-			$style_sheets = array($style_sheets);
2468
+		if (!is_array($style_sheets)) {
2469
+					$style_sheets = array($style_sheets);
2470
+		}
2341 2471
 
2342
-		foreach ($style_sheets as $sheet)
2343
-			loadCSSFile($sheet . '.css', array(), $sheet);
2472
+		foreach ($style_sheets as $sheet) {
2473
+					loadCSSFile($sheet . '.css', array(), $sheet);
2474
+		}
2344 2475
 	}
2345 2476
 
2346 2477
 	// No template to load?
2347
-	if ($template_name === false)
2348
-		return true;
2478
+	if ($template_name === false) {
2479
+			return true;
2480
+	}
2349 2481
 
2350 2482
 	$loaded = false;
2351 2483
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2360,12 +2492,14 @@  discard block
 block discarded – undo
2360 2492
 
2361 2493
 	if ($loaded)
2362 2494
 	{
2363
-		if ($db_show_debug === true)
2364
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2495
+		if ($db_show_debug === true) {
2496
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2497
+		}
2365 2498
 
2366 2499
 		// If they have specified an initialization function for this template, go ahead and call it now.
2367
-		if (function_exists('template_' . $template_name . '_init'))
2368
-			call_user_func('template_' . $template_name . '_init');
2500
+		if (function_exists('template_' . $template_name . '_init')) {
2501
+					call_user_func('template_' . $template_name . '_init');
2502
+		}
2369 2503
 	}
2370 2504
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2371 2505
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2385,13 +2519,14 @@  discard block
 block discarded – undo
2385 2519
 		loadTemplate($template_name);
2386 2520
 	}
2387 2521
 	// Cause an error otherwise.
2388
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2389
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2390
-	elseif ($fatal)
2391
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2392
-	else
2393
-		return false;
2394
-}
2522
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2523
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2524
+	} elseif ($fatal) {
2525
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2526
+	} else {
2527
+			return false;
2528
+	}
2529
+	}
2395 2530
 
2396 2531
 /**
2397 2532
  * Load a sub-template.
@@ -2409,17 +2544,19 @@  discard block
 block discarded – undo
2409 2544
 {
2410 2545
 	global $context, $txt, $db_show_debug;
2411 2546
 
2412
-	if ($db_show_debug === true)
2413
-		$context['debug']['sub_templates'][] = $sub_template_name;
2547
+	if ($db_show_debug === true) {
2548
+			$context['debug']['sub_templates'][] = $sub_template_name;
2549
+	}
2414 2550
 
2415 2551
 	// Figure out what the template function is named.
2416 2552
 	$theme_function = 'template_' . $sub_template_name;
2417
-	if (function_exists($theme_function))
2418
-		$theme_function();
2419
-	elseif ($fatal === false)
2420
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2421
-	elseif ($fatal !== 'ignore')
2422
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2553
+	if (function_exists($theme_function)) {
2554
+			$theme_function();
2555
+	} elseif ($fatal === false) {
2556
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2557
+	} elseif ($fatal !== 'ignore') {
2558
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2559
+	}
2423 2560
 
2424 2561
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2425 2562
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2449,8 +2586,9 @@  discard block
 block discarded – undo
2449 2586
 {
2450 2587
 	global $settings, $context, $modSettings;
2451 2588
 
2452
-	if (empty($context['css_files_order']))
2453
-		$context['css_files_order'] = array();
2589
+	if (empty($context['css_files_order'])) {
2590
+			$context['css_files_order'] = array();
2591
+	}
2454 2592
 
2455 2593
 	$params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
2456 2594
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2461,8 +2599,9 @@  discard block
 block discarded – undo
2461 2599
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2462 2600
 
2463 2601
 	// If this is an external file, automatically set this to false.
2464
-	if (!empty($params['external']))
2465
-		$params['minimize'] = false;
2602
+	if (!empty($params['external'])) {
2603
+			$params['minimize'] = false;
2604
+	}
2466 2605
 
2467 2606
 	// Account for shorthand like admin.css?alp21 filenames
2468 2607
 	$has_seed = strpos($fileName, '.css?');
@@ -2479,16 +2618,12 @@  discard block
 block discarded – undo
2479 2618
 			{
2480 2619
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2481 2620
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2482
-			}
2483
-
2484
-			else
2621
+			} else
2485 2622
 			{
2486 2623
 				$fileUrl = false;
2487 2624
 				$filePath = false;
2488 2625
 			}
2489
-		}
2490
-
2491
-		else
2626
+		} else
2492 2627
 		{
2493 2628
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2494 2629
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2506,16 +2641,18 @@  discard block
 block discarded – undo
2506 2641
 	if (!empty($fileName))
2507 2642
 	{
2508 2643
 		// find a free number/position
2509
-		while (isset($context['css_files_order'][$params['order_pos']]))
2510
-			$params['order_pos']++;
2644
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2645
+					$params['order_pos']++;
2646
+		}
2511 2647
 		$context['css_files_order'][$params['order_pos']] = $id;
2512 2648
 
2513 2649
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2514 2650
 	}
2515 2651
 
2516
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2517
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2518
-}
2652
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2653
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2654
+	}
2655
+	}
2519 2656
 
2520 2657
 /**
2521 2658
  * Add a block of inline css code to be executed later
@@ -2532,8 +2669,9 @@  discard block
 block discarded – undo
2532 2669
 	global $context;
2533 2670
 
2534 2671
 	// Gotta add something...
2535
-	if (empty($css))
2536
-		return false;
2672
+	if (empty($css)) {
2673
+			return false;
2674
+	}
2537 2675
 
2538 2676
 	$context['css_header'][] = $css;
2539 2677
 }
@@ -2569,8 +2707,9 @@  discard block
 block discarded – undo
2569 2707
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2570 2708
 
2571 2709
 	// If this is an external file, automatically set this to false.
2572
-	if (!empty($params['external']))
2573
-		$params['minimize'] = false;
2710
+	if (!empty($params['external'])) {
2711
+			$params['minimize'] = false;
2712
+	}
2574 2713
 
2575 2714
 	// Account for shorthand like admin.js?alp21 filenames
2576 2715
 	$has_seed = strpos($fileName, '.js?');
@@ -2587,16 +2726,12 @@  discard block
 block discarded – undo
2587 2726
 			{
2588 2727
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2589 2728
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2590
-			}
2591
-
2592
-			else
2729
+			} else
2593 2730
 			{
2594 2731
 				$fileUrl = false;
2595 2732
 				$filePath = false;
2596 2733
 			}
2597
-		}
2598
-
2599
-		else
2734
+		} else
2600 2735
 		{
2601 2736
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2602 2737
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2611,9 +2746,10 @@  discard block
 block discarded – undo
2611 2746
 	}
2612 2747
 
2613 2748
 	// Add it to the array for use in the template
2614
-	if (!empty($fileName))
2615
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2616
-}
2749
+	if (!empty($fileName)) {
2750
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2751
+	}
2752
+	}
2617 2753
 
2618 2754
 /**
2619 2755
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2627,9 +2763,10 @@  discard block
 block discarded – undo
2627 2763
 {
2628 2764
 	global $context;
2629 2765
 
2630
-	if (!empty($key) && (!empty($value) || $value === '0'))
2631
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2632
-}
2766
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2767
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2768
+	}
2769
+	}
2633 2770
 
2634 2771
 /**
2635 2772
  * Add a block of inline Javascript code to be executed later
@@ -2646,8 +2783,9 @@  discard block
 block discarded – undo
2646 2783
 {
2647 2784
 	global $context;
2648 2785
 
2649
-	if (empty($javascript))
2650
-		return false;
2786
+	if (empty($javascript)) {
2787
+			return false;
2788
+	}
2651 2789
 
2652 2790
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2653 2791
 }
@@ -2668,15 +2806,18 @@  discard block
 block discarded – undo
2668 2806
 	static $already_loaded = array();
2669 2807
 
2670 2808
 	// Default to the user's language.
2671
-	if ($lang == '')
2672
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2809
+	if ($lang == '') {
2810
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2811
+	}
2673 2812
 
2674 2813
 	// Do we want the English version of language file as fallback?
2675
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2676
-		loadLanguage($template_name, 'english', false);
2814
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2815
+			loadLanguage($template_name, 'english', false);
2816
+	}
2677 2817
 
2678
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2679
-		return $lang;
2818
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2819
+			return $lang;
2820
+	}
2680 2821
 
2681 2822
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2682 2823
 	if (empty($settings['default_theme_dir']))
@@ -2687,8 +2828,9 @@  discard block
 block discarded – undo
2687 2828
 
2688 2829
 	// What theme are we in?
2689 2830
 	$theme_name = basename($settings['theme_url']);
2690
-	if (empty($theme_name))
2691
-		$theme_name = 'unknown';
2831
+	if (empty($theme_name)) {
2832
+			$theme_name = 'unknown';
2833
+	}
2692 2834
 
2693 2835
 	// For each file open it up and write it out!
2694 2836
 	foreach (explode('+', $template_name) as $template)
@@ -2730,8 +2872,9 @@  discard block
 block discarded – undo
2730 2872
 				$found = true;
2731 2873
 
2732 2874
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2733
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2734
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2875
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2876
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2877
+				}
2735 2878
 
2736 2879
 				break;
2737 2880
 			}
@@ -2771,8 +2914,9 @@  discard block
 block discarded – undo
2771 2914
 	}
2772 2915
 
2773 2916
 	// Keep track of what we're up to soldier.
2774
-	if ($db_show_debug === true)
2775
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2917
+	if ($db_show_debug === true) {
2918
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2919
+	}
2776 2920
 
2777 2921
 	// Remember what we have loaded, and in which language.
2778 2922
 	$already_loaded[$template_name] = $lang;
@@ -2818,8 +2962,9 @@  discard block
 block discarded – undo
2818 2962
 				)
2819 2963
 			);
2820 2964
 			// In the EXTREMELY unlikely event this happens, give an error message.
2821
-			if ($smcFunc['db_num_rows']($result) == 0)
2822
-				fatal_lang_error('parent_not_found', 'critical');
2965
+			if ($smcFunc['db_num_rows']($result) == 0) {
2966
+							fatal_lang_error('parent_not_found', 'critical');
2967
+			}
2823 2968
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2824 2969
 			{
2825 2970
 				if (!isset($boards[$row['id_board']]))
@@ -2836,8 +2981,8 @@  discard block
 block discarded – undo
2836 2981
 					);
2837 2982
 				}
2838 2983
 				// If a moderator exists for this board, add that moderator for all children too.
2839
-				if (!empty($row['id_moderator']))
2840
-					foreach ($boards as $id => $dummy)
2984
+				if (!empty($row['id_moderator'])) {
2985
+									foreach ($boards as $id => $dummy)
2841 2986
 					{
2842 2987
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2843 2988
 							'id' => $row['id_moderator'],
@@ -2845,11 +2990,12 @@  discard block
 block discarded – undo
2845 2990
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2846 2991
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2847 2992
 						);
2993
+				}
2848 2994
 					}
2849 2995
 
2850 2996
 				// If a moderator group exists for this board, add that moderator group for all children too
2851
-				if (!empty($row['id_moderator_group']))
2852
-					foreach ($boards as $id => $dummy)
2997
+				if (!empty($row['id_moderator_group'])) {
2998
+									foreach ($boards as $id => $dummy)
2853 2999
 					{
2854 3000
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2855 3001
 							'id' => $row['id_moderator_group'],
@@ -2857,6 +3003,7 @@  discard block
 block discarded – undo
2857 3003
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2858 3004
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2859 3005
 						);
3006
+				}
2860 3007
 					}
2861 3008
 			}
2862 3009
 			$smcFunc['db_free_result']($result);
@@ -2883,23 +3030,27 @@  discard block
 block discarded – undo
2883 3030
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2884 3031
 	{
2885 3032
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2886
-		if (empty($smcFunc['ucwords']))
2887
-			reloadSettings();
3033
+		if (empty($smcFunc['ucwords'])) {
3034
+					reloadSettings();
3035
+		}
2888 3036
 
2889 3037
 		// If we don't have our theme information yet, let's get it.
2890
-		if (empty($settings['default_theme_dir']))
2891
-			loadTheme(0, false);
3038
+		if (empty($settings['default_theme_dir'])) {
3039
+					loadTheme(0, false);
3040
+		}
2892 3041
 
2893 3042
 		// Default language directories to try.
2894 3043
 		$language_directories = array(
2895 3044
 			$settings['default_theme_dir'] . '/languages',
2896 3045
 		);
2897
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2898
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3046
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3047
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3048
+		}
2899 3049
 
2900 3050
 		// We possibly have a base theme directory.
2901
-		if (!empty($settings['base_theme_dir']))
2902
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3051
+		if (!empty($settings['base_theme_dir'])) {
3052
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3053
+		}
2903 3054
 
2904 3055
 		// Remove any duplicates.
2905 3056
 		$language_directories = array_unique($language_directories);
@@ -2913,20 +3064,21 @@  discard block
 block discarded – undo
2913 3064
 		foreach ($language_directories as $language_dir)
2914 3065
 		{
2915 3066
 			// Can't look in here... doesn't exist!
2916
-			if (!file_exists($language_dir))
2917
-				continue;
3067
+			if (!file_exists($language_dir)) {
3068
+							continue;
3069
+			}
2918 3070
 
2919 3071
 			$dir = dir($language_dir);
2920 3072
 			while ($entry = $dir->read())
2921 3073
 			{
2922 3074
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2923
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2924
-					continue;
2925
-
2926
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2927
-					$langName = $langList[$matches[1]];
3075
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3076
+									continue;
3077
+				}
2928 3078
 
2929
-				else
3079
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3080
+									$langName = $langList[$matches[1]];
3081
+				} else
2930 3082
 				{
2931 3083
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2932 3084
 
@@ -2967,12 +3119,14 @@  discard block
 block discarded – undo
2967 3119
 		}
2968 3120
 
2969 3121
 		// Do we need to store the lang list?
2970
-		if (empty($langList))
2971
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3122
+		if (empty($langList)) {
3123
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3124
+		}
2972 3125
 
2973 3126
 		// Let's cash in on this deal.
2974
-		if (!empty($modSettings['cache_enable']))
2975
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3127
+		if (!empty($modSettings['cache_enable'])) {
3128
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3129
+		}
2976 3130
 	}
2977 3131
 
2978 3132
 	return $context['languages'];
@@ -2995,8 +3149,9 @@  discard block
 block discarded – undo
2995 3149
 	global $modSettings, $options, $txt;
2996 3150
 	static $censor_vulgar = null, $censor_proper;
2997 3151
 
2998
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2999
-		return $text;
3152
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3153
+			return $text;
3154
+	}
3000 3155
 
3001 3156
 	// If they haven't yet been loaded, load them.
3002 3157
 	if ($censor_vulgar == null)
@@ -3027,9 +3182,9 @@  discard block
 block discarded – undo
3027 3182
 	{
3028 3183
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3029 3184
 		$text = $func($censor_vulgar, $censor_proper, $text);
3185
+	} else {
3186
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3030 3187
 	}
3031
-	else
3032
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3033 3188
 
3034 3189
 	return $text;
3035 3190
 }
@@ -3055,30 +3210,35 @@  discard block
 block discarded – undo
3055 3210
 	@ini_set('track_errors', '1');
3056 3211
 
3057 3212
 	// Don't include the file more than once, if $once is true.
3058
-	if ($once && in_array($filename, $templates))
3059
-		return;
3213
+	if ($once && in_array($filename, $templates)) {
3214
+			return;
3215
+	}
3060 3216
 	// Add this file to the include list, whether $once is true or not.
3061
-	else
3062
-		$templates[] = $filename;
3217
+	else {
3218
+			$templates[] = $filename;
3219
+	}
3063 3220
 
3064 3221
 
3065 3222
 	$file_found = file_exists($filename);
3066 3223
 
3067
-	if ($once && $file_found)
3068
-		require_once($filename);
3069
-	elseif ($file_found)
3070
-		require($filename);
3224
+	if ($once && $file_found) {
3225
+			require_once($filename);
3226
+	} elseif ($file_found) {
3227
+			require($filename);
3228
+	}
3071 3229
 
3072 3230
 	if ($file_found !== true)
3073 3231
 	{
3074 3232
 		ob_end_clean();
3075
-		if (!empty($modSettings['enableCompressedOutput']))
3076
-			@ob_start('ob_gzhandler');
3077
-		else
3078
-			ob_start();
3233
+		if (!empty($modSettings['enableCompressedOutput'])) {
3234
+					@ob_start('ob_gzhandler');
3235
+		} else {
3236
+					ob_start();
3237
+		}
3079 3238
 
3080
-		if (isset($_GET['debug']))
3081
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3239
+		if (isset($_GET['debug'])) {
3240
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3241
+		}
3082 3242
 
3083 3243
 		// Don't cache error pages!!
3084 3244
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3097,12 +3257,13 @@  discard block
 block discarded – undo
3097 3257
 		echo '<!DOCTYPE html>
3098 3258
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3099 3259
 	<head>';
3100
-		if (isset($context['character_set']))
3101
-			echo '
3260
+		if (isset($context['character_set'])) {
3261
+					echo '
3102 3262
 		<meta charset="', $context['character_set'], '">';
3263
+		}
3103 3264
 
3104
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3105
-			echo '
3265
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3266
+					echo '
3106 3267
 		<title>', $mtitle, '</title>
3107 3268
 	</head>
3108 3269
 	<body>
@@ -3110,8 +3271,8 @@  discard block
 block discarded – undo
3110 3271
 		', $mmessage, '
3111 3272
 	</body>
3112 3273
 </html>';
3113
-		elseif (!allowedTo('admin_forum'))
3114
-			echo '
3274
+		} elseif (!allowedTo('admin_forum')) {
3275
+					echo '
3115 3276
 		<title>', $txt['template_parse_error'], '</title>
3116 3277
 	</head>
3117 3278
 	<body>
@@ -3119,14 +3280,16 @@  discard block
 block discarded – undo
3119 3280
 		', $txt['template_parse_error_message'], '
3120 3281
 	</body>
3121 3282
 </html>';
3122
-		else
3283
+		} else
3123 3284
 		{
3124 3285
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3125 3286
 			$error_array = error_get_last();
3126
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3127
-				$error = $error_array['message'];
3128
-			if (empty($error))
3129
-				$error = $txt['template_parse_errmsg'];
3287
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3288
+							$error = $error_array['message'];
3289
+			}
3290
+			if (empty($error)) {
3291
+							$error = $txt['template_parse_errmsg'];
3292
+			}
3130 3293
 
3131 3294
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3132 3295
 
@@ -3137,11 +3300,12 @@  discard block
 block discarded – undo
3137 3300
 		<h3>', $txt['template_parse_error'], '</h3>
3138 3301
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3139 3302
 
3140
-			if (!empty($error))
3141
-				echo '
3303
+			if (!empty($error)) {
3304
+							echo '
3142 3305
 		<hr>
3143 3306
 
3144 3307
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3308
+			}
3145 3309
 
3146 3310
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3147 3311
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3151,10 +3315,11 @@  discard block
 block discarded – undo
3151 3315
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3152 3316
 
3153 3317
 				// Fix the PHP code stuff...
3154
-				if (!isBrowser('gecko'))
3155
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3156
-				else
3157
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3318
+				if (!isBrowser('gecko')) {
3319
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3320
+				} else {
3321
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3322
+				}
3158 3323
 
3159 3324
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3160 3325
 				$j = -1;
@@ -3162,8 +3327,9 @@  discard block
 block discarded – undo
3162 3327
 				{
3163 3328
 					$j++;
3164 3329
 
3165
-					if (substr_count($line, '<br>') == 0)
3166
-						continue;
3330
+					if (substr_count($line, '<br>') == 0) {
3331
+											continue;
3332
+					}
3167 3333
 
3168 3334
 					$n = substr_count($line, '<br>');
3169 3335
 					for ($i = 0; $i < $n; $i++)
@@ -3182,38 +3348,42 @@  discard block
 block discarded – undo
3182 3348
 				// Figure out what the color coding was before...
3183 3349
 				$line = max($match[1] - 9, 1);
3184 3350
 				$last_line = '';
3185
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3186
-					if (strpos($data2[$line2], '<') !== false)
3351
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3352
+									if (strpos($data2[$line2], '<') !== false)
3187 3353
 					{
3188 3354
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3189 3355
 							$last_line = $color_match[1];
3356
+				}
3190 3357
 						break;
3191 3358
 					}
3192 3359
 
3193 3360
 				// Show the relevant lines...
3194 3361
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3195 3362
 				{
3196
-					if ($line == $match[1])
3197
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3363
+					if ($line == $match[1]) {
3364
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3365
+					}
3198 3366
 
3199 3367
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3200
-					if (isset($data2[$line]) && $data2[$line] != '')
3201
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3368
+					if (isset($data2[$line]) && $data2[$line] != '') {
3369
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3370
+					}
3202 3371
 
3203 3372
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3204 3373
 					{
3205 3374
 						$last_line = $color_match[1];
3206 3375
 						echo '</', substr($last_line, 1, 4), '>';
3376
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3377
+											$last_line = '';
3378
+					} elseif ($last_line != '' && $data2[$line] != '') {
3379
+											echo '</', substr($last_line, 1, 4), '>';
3207 3380
 					}
3208
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3209
-						$last_line = '';
3210
-					elseif ($last_line != '' && $data2[$line] != '')
3211
-						echo '</', substr($last_line, 1, 4), '>';
3212 3381
 
3213
-					if ($line == $match[1])
3214
-						echo '</pre></div><pre style="margin: 0;">';
3215
-					else
3216
-						echo "\n";
3382
+					if ($line == $match[1]) {
3383
+											echo '</pre></div><pre style="margin: 0;">';
3384
+					} else {
3385
+											echo "\n";
3386
+					}
3217 3387
 				}
3218 3388
 
3219 3389
 				echo '</pre></div>';
@@ -3237,8 +3407,9 @@  discard block
 block discarded – undo
3237 3407
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4;
3238 3408
 
3239 3409
 	// Figure out what type of database we are using.
3240
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3241
-		$db_type = 'mysql';
3410
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3411
+			$db_type = 'mysql';
3412
+	}
3242 3413
 
3243 3414
 	// Load the file for the database.
3244 3415
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3246,11 +3417,13 @@  discard block
 block discarded – undo
3246 3417
 	$db_options = array();
3247 3418
 
3248 3419
 	// Add in the port if needed
3249
-	if (!empty($db_port))
3250
-		$db_options['port'] = $db_port;
3420
+	if (!empty($db_port)) {
3421
+			$db_options['port'] = $db_port;
3422
+	}
3251 3423
 
3252
-	if (!empty($db_mb4))
3253
-		$db_options['db_mb4'] = $db_mb4;
3424
+	if (!empty($db_mb4)) {
3425
+			$db_options['db_mb4'] = $db_mb4;
3426
+	}
3254 3427
 
3255 3428
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3256 3429
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3269,13 +3442,15 @@  discard block
 block discarded – undo
3269 3442
 	}
3270 3443
 
3271 3444
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3272
-	if (!$db_connection)
3273
-		display_db_error();
3445
+	if (!$db_connection) {
3446
+			display_db_error();
3447
+	}
3274 3448
 
3275 3449
 	// If in SSI mode fix up the prefix.
3276
-	if (SMF == 'SSI')
3277
-		db_fix_prefix($db_prefix, $db_name);
3278
-}
3450
+	if (SMF == 'SSI') {
3451
+			db_fix_prefix($db_prefix, $db_name);
3452
+	}
3453
+	}
3279 3454
 
3280 3455
 /**
3281 3456
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3289,10 +3464,11 @@  discard block
 block discarded – undo
3289 3464
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3290 3465
 
3291 3466
 	// Not overriding this and we have a cacheAPI, send it back.
3292
-	if (empty($overrideCache) && is_object($cacheAPI))
3293
-		return $cacheAPI;
3294
-	elseif (is_null($cacheAPI))
3295
-		$cacheAPI = false;
3467
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3468
+			return $cacheAPI;
3469
+	} elseif (is_null($cacheAPI)) {
3470
+			$cacheAPI = false;
3471
+	}
3296 3472
 
3297 3473
 	// Make sure our class is in session.
3298 3474
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3313,8 +3489,9 @@  discard block
 block discarded – undo
3313 3489
 		if (!$testAPI->isSupported())
3314 3490
 		{
3315 3491
 			// Can we save ourselves?
3316
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3317
-				return loadCacheAccelerator(null, false);
3492
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3493
+							return loadCacheAccelerator(null, false);
3494
+			}
3318 3495
 			return false;
3319 3496
 		}
3320 3497
 
@@ -3326,9 +3503,9 @@  discard block
 block discarded – undo
3326 3503
 		{
3327 3504
 			$cacheAPI = $testAPI;
3328 3505
 			return $cacheAPI;
3506
+		} else {
3507
+					return $testAPI;
3329 3508
 		}
3330
-		else
3331
-			return $testAPI;
3332 3509
 	}
3333 3510
 }
3334 3511
 
@@ -3348,8 +3525,9 @@  discard block
 block discarded – undo
3348 3525
 
3349 3526
 	// @todo Why are we doing this if caching is disabled?
3350 3527
 
3351
-	if (function_exists('call_integration_hook'))
3352
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3528
+	if (function_exists('call_integration_hook')) {
3529
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3530
+	}
3353 3531
 
3354 3532
 	/* Refresh the cache if either:
3355 3533
 		1. Caching is disabled.
@@ -3363,16 +3541,19 @@  discard block
 block discarded – undo
3363 3541
 		require_once($sourcedir . '/' . $file);
3364 3542
 		$cache_block = call_user_func_array($function, $params);
3365 3543
 
3366
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3367
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3544
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3545
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3546
+		}
3368 3547
 	}
3369 3548
 
3370 3549
 	// Some cached data may need a freshening up after retrieval.
3371
-	if (!empty($cache_block['post_retri_eval']))
3372
-		eval($cache_block['post_retri_eval']);
3550
+	if (!empty($cache_block['post_retri_eval'])) {
3551
+			eval($cache_block['post_retri_eval']);
3552
+	}
3373 3553
 
3374
-	if (function_exists('call_integration_hook'))
3375
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3554
+	if (function_exists('call_integration_hook')) {
3555
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3556
+	}
3376 3557
 
3377 3558
 	return $cache_block['data'];
3378 3559
 }
@@ -3399,8 +3580,9 @@  discard block
 block discarded – undo
3399 3580
 	global $smcFunc, $cache_enable, $cacheAPI;
3400 3581
 	global $cache_hits, $cache_count, $db_show_debug;
3401 3582
 
3402
-	if (empty($cache_enable) || empty($cacheAPI))
3403
-		return;
3583
+	if (empty($cache_enable) || empty($cacheAPI)) {
3584
+			return;
3585
+	}
3404 3586
 
3405 3587
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3406 3588
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3413,12 +3595,14 @@  discard block
 block discarded – undo
3413 3595
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3414 3596
 	$cacheAPI->putData($key, $value, $ttl);
3415 3597
 
3416
-	if (function_exists('call_integration_hook'))
3417
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3598
+	if (function_exists('call_integration_hook')) {
3599
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3600
+	}
3418 3601
 
3419
-	if (isset($db_show_debug) && $db_show_debug === true)
3420
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3421
-}
3602
+	if (isset($db_show_debug) && $db_show_debug === true) {
3603
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3604
+	}
3605
+	}
3422 3606
 
3423 3607
 /**
3424 3608
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3434,8 +3618,9 @@  discard block
 block discarded – undo
3434 3618
 	global $smcFunc, $cache_enable, $cacheAPI;
3435 3619
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3436 3620
 
3437
-	if (empty($cache_enable) || empty($cacheAPI))
3438
-		return;
3621
+	if (empty($cache_enable) || empty($cacheAPI)) {
3622
+			return;
3623
+	}
3439 3624
 
3440 3625
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3441 3626
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3455,16 +3640,18 @@  discard block
 block discarded – undo
3455 3640
 
3456 3641
 		if (empty($value))
3457 3642
 		{
3458
-			if (!is_array($cache_misses))
3459
-				$cache_misses = array();
3643
+			if (!is_array($cache_misses)) {
3644
+							$cache_misses = array();
3645
+			}
3460 3646
 
3461 3647
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3462 3648
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3463 3649
 		}
3464 3650
 	}
3465 3651
 
3466
-	if (function_exists('call_integration_hook') && isset($value))
3467
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3652
+	if (function_exists('call_integration_hook') && isset($value)) {
3653
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3654
+	}
3468 3655
 
3469 3656
 	return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3470 3657
 }
@@ -3486,8 +3673,9 @@  discard block
 block discarded – undo
3486 3673
 	global $cacheAPI;
3487 3674
 
3488 3675
 	// If we can't get to the API, can't do this.
3489
-	if (empty($cacheAPI))
3490
-		return;
3676
+	if (empty($cacheAPI)) {
3677
+			return;
3678
+	}
3491 3679
 
3492 3680
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3493 3681
 	$cacheAPI->cleanCache($type);
@@ -3512,8 +3700,9 @@  discard block
 block discarded – undo
3512 3700
 	global $modSettings, $smcFunc, $image_proxy_enabled, $user_info;
3513 3701
 
3514 3702
 	// Come on!
3515
-	if (empty($data))
3516
-		return array();
3703
+	if (empty($data)) {
3704
+			return array();
3705
+	}
3517 3706
 
3518 3707
 	// Set a nice default var.
3519 3708
 	$image = '';
@@ -3521,11 +3710,11 @@  discard block
 block discarded – undo
3521 3710
 	// Gravatar has been set as mandatory!
3522 3711
 	if (!empty($modSettings['gravatarOverride']))
3523 3712
 	{
3524
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3525
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3526
-
3527
-		else if (!empty($data['email']))
3528
-			$image = get_gravatar_url($data['email']);
3713
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3714
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3715
+		} else if (!empty($data['email'])) {
3716
+					$image = get_gravatar_url($data['email']);
3717
+		}
3529 3718
 	}
3530 3719
 
3531 3720
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3537,54 +3726,60 @@  discard block
 block discarded – undo
3537 3726
 			// Gravatar.
3538 3727
 			if (stristr($data['avatar'], 'gravatar://'))
3539 3728
 			{
3540
-				if ($data['avatar'] == 'gravatar://')
3541
-					$image = get_gravatar_url($data['email']);
3542
-
3543
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3544
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3729
+				if ($data['avatar'] == 'gravatar://') {
3730
+									$image = get_gravatar_url($data['email']);
3731
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3732
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3733
+				}
3545 3734
 			}
3546 3735
 
3547 3736
 			// External url.
3548 3737
 			else
3549 3738
 			{
3550 3739
 				// Using ssl?
3551
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3552
-					$image = get_proxied_url($data['avatar']);
3740
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3741
+									$image = get_proxied_url($data['avatar']);
3742
+				}
3553 3743
 
3554 3744
 				// Just a plain external url.
3555
-				else
3556
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3745
+				else {
3746
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3747
+				}
3557 3748
 			}
3558 3749
 		}
3559 3750
 
3560 3751
 		// Perhaps this user has an attachment as avatar...
3561
-		else if (!empty($data['filename']))
3562
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3752
+		else if (!empty($data['filename'])) {
3753
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3754
+		}
3563 3755
 
3564 3756
 		// Right... no avatar... use our default image.
3565
-		else
3566
-			$image = $modSettings['avatar_url'] . '/default.png';
3757
+		else {
3758
+					$image = $modSettings['avatar_url'] . '/default.png';
3759
+		}
3567 3760
 	}
3568 3761
 
3569 3762
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3570 3763
 
3571 3764
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3572
-	if (!empty($image))
3573
-		return array(
3765
+	if (!empty($image)) {
3766
+			return array(
3574 3767
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3575 3768
 			'image' => '<img class="avatar" src="' . $image . '" />',
3576 3769
 			'href' => $image,
3577 3770
 			'url' => $image,
3578 3771
 		);
3772
+	}
3579 3773
 
3580 3774
 	// Fallback to make life easier for everyone...
3581
-	else
3582
-		return array(
3775
+	else {
3776
+			return array(
3583 3777
 			'name' => '',
3584 3778
 			'image' => '',
3585 3779
 			'href' => '',
3586 3780
 			'url' => '',
3587 3781
 		);
3588
-}
3782
+	}
3783
+	}
3589 3784
 
3590 3785
 ?>
3591 3786
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1480 added lines, -1106 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,24 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-
195
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
196 199
 			{
197 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
198 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -213,8 +216,9 @@  discard block
 block discarded – undo
213 216
 
214 217
 		case 'postgroups':
215 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
216
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
217
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
218 222
 
219 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
220 224
 			if ($postgroups == null || $parameter1 == null)
@@ -229,8 +233,9 @@  discard block
 block discarded – undo
229 233
 					)
230 234
 				);
231 235
 				$postgroups = array();
232
-				while ($row = $smcFunc['db_fetch_assoc']($request))
233
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
234 239
 
235 240
 				$smcFunc['db_free_result']($request);
236 241
 
@@ -241,8 +246,9 @@  discard block
 block discarded – undo
241 246
 			}
242 247
 
243 248
 			// Oh great, they've screwed their post groups.
244
-			if (empty($postgroups))
245
-				return;
249
+			if (empty($postgroups)) {
250
+							return;
251
+			}
246 252
 
247 253
 			// Set all membergroups from most posts to least posts.
248 254
 			$conditions = '';
@@ -301,12 +307,9 @@  discard block
 block discarded – undo
301 307
 	{
302 308
 		$condition = 'id_member IN ({array_int:members})';
303 309
 		$parameters['members'] = $members;
304
-	}
305
-
306
-	elseif ($members === null)
307
-		$condition = '1=1';
308
-
309
-	else
310
+	} elseif ($members === null) {
311
+			$condition = '1=1';
312
+	} else
310 313
 	{
311 314
 		$condition = 'id_member = {int:member}';
312 315
 		$parameters['member'] = $members;
@@ -346,9 +349,9 @@  discard block
 block discarded – undo
346 349
 		if (count($vars_to_integrate) != 0)
347 350
 		{
348 351
 			// Fetch a list of member_names if necessary
349
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
350
-				$member_names = array($user_info['username']);
351
-			else
352
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
353
+							$member_names = array($user_info['username']);
354
+			} else
352 355
 			{
353 356
 				$member_names = array();
354 357
 				$request = $smcFunc['db_query']('', '
@@ -357,14 +360,16 @@  discard block
 block discarded – undo
357 360
 					WHERE ' . $condition,
358 361
 					$parameters
359 362
 				);
360
-				while ($row = $smcFunc['db_fetch_assoc']($request))
361
-					$member_names[] = $row['member_name'];
363
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
364
+									$member_names[] = $row['member_name'];
365
+				}
362 366
 				$smcFunc['db_free_result']($request);
363 367
 			}
364 368
 
365
-			if (!empty($member_names))
366
-				foreach ($vars_to_integrate as $var)
369
+			if (!empty($member_names)) {
370
+							foreach ($vars_to_integrate as $var)
367 371
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
372
+			}
368 373
 		}
369 374
 	}
370 375
 
@@ -372,16 +377,17 @@  discard block
 block discarded – undo
372 377
 	foreach ($data as $var => $val)
373 378
 	{
374 379
 		$type = 'string';
375
-		if (in_array($var, $knownInts))
376
-			$type = 'int';
377
-		elseif (in_array($var, $knownFloats))
378
-			$type = 'float';
379
-		elseif ($var == 'birthdate')
380
-			$type = 'date';
381
-		elseif ($var == 'member_ip')
382
-			$type = 'inet';
383
-		elseif ($var == 'member_ip2')
384
-			$type = 'inet';
380
+		if (in_array($var, $knownInts)) {
381
+					$type = 'int';
382
+		} elseif (in_array($var, $knownFloats)) {
383
+					$type = 'float';
384
+		} elseif ($var == 'birthdate') {
385
+					$type = 'date';
386
+		} elseif ($var == 'member_ip') {
387
+					$type = 'inet';
388
+		} elseif ($var == 'member_ip2') {
389
+					$type = 'inet';
390
+		}
385 391
 
386 392
 		// Doing an increment?
387 393
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -390,18 +396,17 @@  discard block
 block discarded – undo
390 396
 			if (is_array($members))
391 397
 			{
392 398
 				$val = 'CASE ';
393
-				foreach ($members as $k => $v)
394
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				foreach ($members as $k => $v) {
400
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
401
+				}
395 402
 				$val = $val . ' END';
396 403
 				$type = 'raw';
397
-			}
398
-			else
404
+			} else
399 405
 			{
400 406
 				$blub = fetch_alerts($members, false, 0, array(), false);
401 407
 				$val = count($blub);
402 408
 			}
403
-		}
404
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
409
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
405 410
 		{
406 411
 			$val = $var . ' ' . $val . ' 1';
407 412
 			$type = 'raw';
@@ -412,8 +417,9 @@  discard block
 block discarded – undo
412 417
 		{
413 418
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
414 419
 			{
415
-				if ($match[1] != '+ ')
416
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				if ($match[1] != '+ ') {
421
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
422
+				}
417 423
 				$type = 'raw';
418 424
 			}
419 425
 		}
@@ -434,8 +440,9 @@  discard block
 block discarded – undo
434 440
 	// Clear any caching?
435 441
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
436 442
 	{
437
-		if (!is_array($members))
438
-			$members = array($members);
443
+		if (!is_array($members)) {
444
+					$members = array($members);
445
+		}
439 446
 
440 447
 		foreach ($members as $member)
441 448
 		{
@@ -468,29 +475,32 @@  discard block
 block discarded – undo
468 475
 {
469 476
 	global $modSettings, $smcFunc;
470 477
 
471
-	if (empty($changeArray) || !is_array($changeArray))
472
-		return;
478
+	if (empty($changeArray) || !is_array($changeArray)) {
479
+			return;
480
+	}
473 481
 
474 482
 	$toRemove = array();
475 483
 
476 484
 	// Go check if there is any setting to be removed.
477
-	foreach ($changeArray as $k => $v)
478
-		if ($v === null)
485
+	foreach ($changeArray as $k => $v) {
486
+			if ($v === null)
479 487
 		{
480 488
 			// Found some, remove them from the original array and add them to ours.
481 489
 			unset($changeArray[$k]);
490
+	}
482 491
 			$toRemove[] = $k;
483 492
 		}
484 493
 
485 494
 	// Proceed with the deletion.
486
-	if (!empty($toRemove))
487
-		$smcFunc['db_query']('', '
495
+	if (!empty($toRemove)) {
496
+			$smcFunc['db_query']('', '
488 497
 			DELETE FROM {db_prefix}settings
489 498
 			WHERE variable IN ({array_string:remove})',
490 499
 			array(
491 500
 				'remove' => $toRemove,
492 501
 			)
493 502
 		);
503
+	}
494 504
 
495 505
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
496 506
 	if ($update)
@@ -519,19 +529,22 @@  discard block
 block discarded – undo
519 529
 	foreach ($changeArray as $variable => $value)
520 530
 	{
521 531
 		// Don't bother if it's already like that ;).
522
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
523
-			continue;
532
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
533
+					continue;
534
+		}
524 535
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
525
-		elseif (!isset($modSettings[$variable]) && empty($value))
526
-			continue;
536
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
537
+					continue;
538
+		}
527 539
 
528 540
 		$replaceArray[] = array($variable, $value);
529 541
 
530 542
 		$modSettings[$variable] = $value;
531 543
 	}
532 544
 
533
-	if (empty($replaceArray))
534
-		return;
545
+	if (empty($replaceArray)) {
546
+			return;
547
+	}
535 548
 
536 549
 	$smcFunc['db_insert']('replace',
537 550
 		'{db_prefix}settings',
@@ -577,14 +590,17 @@  discard block
 block discarded – undo
577 590
 	$start_invalid = $start < 0;
578 591
 
579 592
 	// Make sure $start is a proper variable - not less than 0.
580
-	if ($start_invalid)
581
-		$start = 0;
593
+	if ($start_invalid) {
594
+			$start = 0;
595
+	}
582 596
 	// Not greater than the upper bound.
583
-	elseif ($start >= $max_value)
584
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
597
+	elseif ($start >= $max_value) {
598
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
599
+	}
585 600
 	// And it has to be a multiple of $num_per_page!
586
-	else
587
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	else {
602
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
603
+	}
588 604
 
589 605
 	$context['current_page'] = $start / $num_per_page;
590 606
 
@@ -614,77 +630,87 @@  discard block
 block discarded – undo
614 630
 
615 631
 		// Show all the pages.
616 632
 		$display_page = 1;
617
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
618
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
634
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
635
+		}
619 636
 
620 637
 		// Show the right arrow.
621 638
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
622
-		if ($start != $counter - $max_value && !$start_invalid)
623
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
624
-	}
625
-	else
639
+		if ($start != $counter - $max_value && !$start_invalid) {
640
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
641
+		}
642
+	} else
626 643
 	{
627 644
 		// If they didn't enter an odd value, pretend they did.
628 645
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
629 646
 
630 647
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
631
-		if (!empty($start) && $show_prevnext)
632
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
633
-		else
634
-			$pageindex .= '';
648
+		if (!empty($start) && $show_prevnext) {
649
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
650
+		} else {
651
+					$pageindex .= '';
652
+		}
635 653
 
636 654
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
637
-		if ($start > $num_per_page * $PageContiguous)
638
-			$pageindex .= sprintf($base_link, 0, '1');
655
+		if ($start > $num_per_page * $PageContiguous) {
656
+					$pageindex .= sprintf($base_link, 0, '1');
657
+		}
639 658
 
640 659
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
641
-		if ($start > $num_per_page * ($PageContiguous + 1))
642
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
660
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
661
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
643 662
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
644 663
 				'{FIRST_PAGE}' => $num_per_page,
645 664
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
646 665
 				'{PER_PAGE}' => $num_per_page,
647 666
 			));
667
+		}
648 668
 
649 669
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
650
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
651
-			if ($start >= $num_per_page * $nCont)
670
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
671
+					if ($start >= $num_per_page * $nCont)
652 672
 			{
653 673
 				$tmpStart = $start - $num_per_page * $nCont;
674
+		}
654 675
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
655 676
 			}
656 677
 
657 678
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
658
-		if (!$start_invalid)
659
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
660
-		else
661
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
679
+		if (!$start_invalid) {
680
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
681
+		} else {
682
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
683
+		}
662 684
 
663 685
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
664 686
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
665
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
666
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
687
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
688
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
667 689
 			{
668 690
 				$tmpStart = $start + $num_per_page * $nCont;
691
+		}
669 692
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
670 693
 			}
671 694
 
672 695
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
673
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
674
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
696
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
697
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
675 698
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
676 699
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
677 700
 				'{LAST_PAGE}' => $tmpMaxPages,
678 701
 				'{PER_PAGE}' => $num_per_page,
679 702
 			));
703
+		}
680 704
 
681 705
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
682
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
683
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
707
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
708
+		}
684 709
 
685 710
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
686
-		if ($start != $tmpMaxPages && $show_prevnext)
687
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		if ($start != $tmpMaxPages && $show_prevnext) {
712
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
713
+		}
688 714
 	}
689 715
 	$pageindex .= $settings['page_index']['extra_after'];
690 716
 
@@ -710,8 +736,9 @@  discard block
 block discarded – undo
710 736
 	if ($decimal_separator === null)
711 737
 	{
712 738
 		// Not set for whatever reason?
713
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
714
-			return $number;
739
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
740
+					return $number;
741
+		}
715 742
 
716 743
 		// Cache these each load...
717 744
 		$thousands_separator = $matches[1];
@@ -752,17 +779,20 @@  discard block
 block discarded – undo
752 779
 	$user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M');
753 780
 
754 781
 	// Offset the time.
755
-	if (!$offset_type)
756
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
782
+	if (!$offset_type) {
783
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
784
+	}
757 785
 	// Just the forum offset?
758
-	elseif ($offset_type == 'forum')
759
-		$time = $log_time + $modSettings['time_offset'] * 3600;
760
-	else
761
-		$time = $log_time;
786
+	elseif ($offset_type == 'forum') {
787
+			$time = $log_time + $modSettings['time_offset'] * 3600;
788
+	} else {
789
+			$time = $log_time;
790
+	}
762 791
 
763 792
 	// We can't have a negative date (on Windows, at least.)
764
-	if ($log_time < 0)
765
-		$log_time = 0;
793
+	if ($log_time < 0) {
794
+			$log_time = 0;
795
+	}
766 796
 
767 797
 	// Today and Yesterday?
768 798
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -779,24 +809,27 @@  discard block
 block discarded – undo
779 809
 		{
780 810
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
781 811
 			$today_fmt = $h . ':%M' . $s . ' %p';
812
+		} else {
813
+					$today_fmt = '%H:%M' . $s;
782 814
 		}
783
-		else
784
-			$today_fmt = '%H:%M' . $s;
785 815
 
786 816
 		// Same day of the year, same year.... Today!
787
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
788
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
817
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
818
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
819
+		}
789 820
 
790 821
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
791
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
792
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
822
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
823
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
824
+		}
793 825
 	}
794 826
 
795 827
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
796 828
 
797 829
 	// Use the cached formats if available
798
-	if (is_null($finalizedFormats))
799
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
830
+	if (is_null($finalizedFormats)) {
831
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
832
+	}
800 833
 
801 834
 	// Make a supported version for this format if we don't already have one
802 835
 	if (empty($finalizedFormats[$str]))
@@ -825,8 +858,9 @@  discard block
 block discarded – undo
825 858
 		);
826 859
 
827 860
 		// No need to do this part again if we already did it once
828
-		if (is_null($unsupportedFormats))
829
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
861
+		if (is_null($unsupportedFormats)) {
862
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
863
+		}
830 864
 		if (empty($unsupportedFormats))
831 865
 		{
832 866
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -842,20 +876,23 @@  discard block
 block discarded – undo
842 876
 
843 877
 				// Windows will return false for unsupported formats
844 878
 				// Other operating systems return the format string as a literal
845
-				if ($value === false || $value === $format)
846
-					$unsupportedFormats[] = $format;
879
+				if ($value === false || $value === $format) {
880
+									$unsupportedFormats[] = $format;
881
+				}
847 882
 			}
848 883
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
849 884
 		}
850 885
 
851 886
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
852
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
853
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
887
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
888
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
889
+		}
854 890
 
855 891
 		// Substitute unsupported formats with supported ones
856
-		if (!empty($unsupportedFormats))
857
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
892
+		if (!empty($unsupportedFormats)) {
893
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
858 894
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
895
+		}
859 896
 
860 897
 		// Remember this so we don't need to do it again
861 898
 		$finalizedFormats[$str] = $timeformat;
@@ -864,33 +901,39 @@  discard block
 block discarded – undo
864 901
 
865 902
 	$str = $finalizedFormats[$str];
866 903
 
867
-	if (!isset($locale_cache))
868
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
904
+	if (!isset($locale_cache)) {
905
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
906
+	}
869 907
 
870 908
 	if ($locale_cache !== false)
871 909
 	{
872 910
 		// Check if another process changed the locale
873
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
874
-			setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
911
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
912
+					setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
913
+		}
875 914
 
876
-		if (!isset($non_twelve_hour))
877
-			$non_twelve_hour = trim(strftime('%p')) === '';
878
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
879
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
915
+		if (!isset($non_twelve_hour)) {
916
+					$non_twelve_hour = trim(strftime('%p')) === '';
917
+		}
918
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
919
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
920
+		}
880 921
 
881
-		foreach (array('%a', '%A', '%b', '%B') as $token)
882
-			if (strpos($str, $token) !== false)
922
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
923
+					if (strpos($str, $token) !== false)
883 924
 				$str = str_replace($token, strftime($token, $time), $str);
884
-	}
885
-	else
925
+		}
926
+	} else
886 927
 	{
887 928
 		// Do-it-yourself time localization.  Fun.
888
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
889
-			if (strpos($str, $token) !== false)
929
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
930
+					if (strpos($str, $token) !== false)
890 931
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
932
+		}
891 933
 
892
-		if (strpos($str, '%p') !== false)
893
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
934
+		if (strpos($str, '%p') !== false) {
935
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
936
+		}
894 937
 	}
895 938
 
896 939
 	// Format the time and then restore any literal percent characters
@@ -913,16 +956,19 @@  discard block
 block discarded – undo
913 956
 	static $translation = array();
914 957
 
915 958
 	// Determine the character set... Default to UTF-8
916
-	if (empty($context['character_set']))
917
-		$charset = 'UTF-8';
959
+	if (empty($context['character_set'])) {
960
+			$charset = 'UTF-8';
961
+	}
918 962
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
919
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
920
-		$charset = 'ISO-8859-1';
921
-	else
922
-		$charset = $context['character_set'];
963
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
964
+			$charset = 'ISO-8859-1';
965
+	} else {
966
+			$charset = $context['character_set'];
967
+	}
923 968
 
924
-	if (empty($translation))
925
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
969
+	if (empty($translation)) {
970
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
971
+	}
926 972
 
927 973
 	return strtr($string, $translation);
928 974
 }
@@ -944,8 +990,9 @@  discard block
 block discarded – undo
944 990
 	global $smcFunc;
945 991
 
946 992
 	// It was already short enough!
947
-	if ($smcFunc['strlen']($subject) <= $len)
948
-		return $subject;
993
+	if ($smcFunc['strlen']($subject) <= $len) {
994
+			return $subject;
995
+	}
949 996
 
950 997
 	// Shorten it by the length it was too long, and strip off junk from the end.
951 998
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -964,10 +1011,11 @@  discard block
 block discarded – undo
964 1011
 {
965 1012
 	global $user_info, $modSettings;
966 1013
 
967
-	if ($timestamp === null)
968
-		$timestamp = time();
969
-	elseif ($timestamp == 0)
970
-		return 0;
1014
+	if ($timestamp === null) {
1015
+			$timestamp = time();
1016
+	} elseif ($timestamp == 0) {
1017
+			return 0;
1018
+	}
971 1019
 
972 1020
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
973 1021
 }
@@ -996,8 +1044,9 @@  discard block
 block discarded – undo
996 1044
 		$array[$i] = $array[$j];
997 1045
 		$array[$j] = $temp;
998 1046
 
999
-		for ($i = 1; $p[$i] == 0; $i++)
1000
-			$p[$i] = 1;
1047
+		for ($i = 1; $p[$i] == 0; $i++) {
1048
+					$p[$i] = 1;
1049
+		}
1001 1050
 
1002 1051
 		$orders[] = $array;
1003 1052
 	}
@@ -1029,12 +1078,14 @@  discard block
 block discarded – undo
1029 1078
 	static $disabled;
1030 1079
 
1031 1080
 	// Don't waste cycles
1032
-	if ($message === '')
1033
-		return '';
1081
+	if ($message === '') {
1082
+			return '';
1083
+	}
1034 1084
 
1035 1085
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1036
-	if (!isset($context['utf8']))
1037
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1086
+	if (!isset($context['utf8'])) {
1087
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1088
+	}
1038 1089
 
1039 1090
 	// Clean up any cut/paste issues we may have
1040 1091
 	$message = sanitizeMSCutPaste($message);
@@ -1046,13 +1097,15 @@  discard block
 block discarded – undo
1046 1097
 		return $message;
1047 1098
 	}
1048 1099
 
1049
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1050
-		$smileys = (bool) $smileys;
1100
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1101
+			$smileys = (bool) $smileys;
1102
+	}
1051 1103
 
1052 1104
 	if (empty($modSettings['enableBBC']) && $message !== false)
1053 1105
 	{
1054
-		if ($smileys === true)
1055
-			parsesmileys($message);
1106
+		if ($smileys === true) {
1107
+					parsesmileys($message);
1108
+		}
1056 1109
 
1057 1110
 		return $message;
1058 1111
 	}
@@ -1065,8 +1118,9 @@  discard block
 block discarded – undo
1065 1118
 	}
1066 1119
 
1067 1120
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1068
-	if (!empty($modSettings['autoLinkUrls']))
1069
-		set_tld_regex();
1121
+	if (!empty($modSettings['autoLinkUrls'])) {
1122
+			set_tld_regex();
1123
+	}
1070 1124
 
1071 1125
 	// Allow mods access before entering the main parse_bbc loop
1072 1126
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1080,12 +1134,14 @@  discard block
 block discarded – undo
1080 1134
 
1081 1135
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1082 1136
 
1083
-			foreach ($temp as $tag)
1084
-				$disabled[trim($tag)] = true;
1137
+			foreach ($temp as $tag) {
1138
+							$disabled[trim($tag)] = true;
1139
+			}
1085 1140
 		}
1086 1141
 
1087
-		if (empty($modSettings['enableEmbeddedFlash']))
1088
-			$disabled['flash'] = true;
1142
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1143
+					$disabled['flash'] = true;
1144
+		}
1089 1145
 
1090 1146
 		/* The following bbc are formatted as an array, with keys as follows:
1091 1147
 
@@ -1214,8 +1270,9 @@  discard block
 block discarded – undo
1214 1270
 					$returnContext = '';
1215 1271
 
1216 1272
 					// BBC or the entire attachments feature is disabled
1217
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1218
-						return $data;
1273
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1274
+											return $data;
1275
+					}
1219 1276
 
1220 1277
 					// Save the attach ID.
1221 1278
 					$attachID = $data;
@@ -1226,8 +1283,9 @@  discard block
 block discarded – undo
1226 1283
 					$currentAttachment = parseAttachBBC($attachID);
1227 1284
 
1228 1285
 					// parseAttachBBC will return a string ($txt key) rather than dying with a fatal_error. Up to you to decide what to do.
1229
-					if (is_string($currentAttachment))
1230
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1286
+					if (is_string($currentAttachment)) {
1287
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1288
+					}
1231 1289
 
1232 1290
 					if (!empty($currentAttachment['is_image']))
1233 1291
 					{
@@ -1243,15 +1301,17 @@  discard block
 block discarded – undo
1243 1301
 							$height = ' height="' . $currentAttachment['height'] . '"';
1244 1302
 						}
1245 1303
 
1246
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1247
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1248
-						else
1249
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1304
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1305
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1306
+						} else {
1307
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1308
+						}
1250 1309
 					}
1251 1310
 
1252 1311
 					// No image. Show a link.
1253
-					else
1254
-						$returnContext .= $currentAttachment['link'];
1312
+					else {
1313
+											$returnContext .= $currentAttachment['link'];
1314
+					}
1255 1315
 
1256 1316
 					// Gotta append what we just did.
1257 1317
 					$data = $returnContext;
@@ -1305,8 +1365,9 @@  discard block
 block discarded – undo
1305 1365
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1306 1366
 						{
1307 1367
 							// Do PHP code coloring?
1308
-							if ($php_parts[$php_i] != '&lt;?php')
1309
-								continue;
1368
+							if ($php_parts[$php_i] != '&lt;?php') {
1369
+															continue;
1370
+							}
1310 1371
 
1311 1372
 							$php_string = '';
1312 1373
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1322,8 +1383,9 @@  discard block
 block discarded – undo
1322 1383
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1323 1384
 
1324 1385
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1325
-						if ($context['browser']['is_opera'])
1326
-							$data .= '&nbsp;';
1386
+						if ($context['browser']['is_opera']) {
1387
+													$data .= '&nbsp;';
1388
+						}
1327 1389
 					}
1328 1390
 				},
1329 1391
 				'block_level' => true,
@@ -1342,8 +1404,9 @@  discard block
 block discarded – undo
1342 1404
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1343 1405
 						{
1344 1406
 							// Do PHP code coloring?
1345
-							if ($php_parts[$php_i] != '&lt;?php')
1346
-								continue;
1407
+							if ($php_parts[$php_i] != '&lt;?php') {
1408
+															continue;
1409
+							}
1347 1410
 
1348 1411
 							$php_string = '';
1349 1412
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1359,8 +1422,9 @@  discard block
 block discarded – undo
1359 1422
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1360 1423
 
1361 1424
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1362
-						if ($context['browser']['is_opera'])
1363
-							$data[0] .= '&nbsp;';
1425
+						if ($context['browser']['is_opera']) {
1426
+													$data[0] .= '&nbsp;';
1427
+						}
1364 1428
 					}
1365 1429
 				},
1366 1430
 				'block_level' => true,
@@ -1398,11 +1462,13 @@  discard block
 block discarded – undo
1398 1462
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1399 1463
 				'validate' => function (&$tag, &$data, $disabled)
1400 1464
 				{
1401
-					if (isset($disabled['url']))
1402
-						$tag['content'] = '$1';
1465
+					if (isset($disabled['url'])) {
1466
+											$tag['content'] = '$1';
1467
+					}
1403 1468
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1404
-					if (empty($scheme))
1405
-						$data[0] = '//' . ltrim($data[0], ':/');
1469
+					if (empty($scheme)) {
1470
+											$data[0] = '//' . ltrim($data[0], ':/');
1471
+					}
1406 1472
 				},
1407 1473
 				'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>',
1408 1474
 			),
@@ -1416,10 +1482,11 @@  discard block
 block discarded – undo
1416 1482
 				{
1417 1483
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1418 1484
 
1419
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1420
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1421
-					else
1422
-						$css = '';
1485
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1486
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1487
+					} else {
1488
+											$css = '';
1489
+					}
1423 1490
 
1424 1491
 					$data = $class . $css;
1425 1492
 				},
@@ -1434,8 +1501,9 @@  discard block
 block discarded – undo
1434 1501
 				{
1435 1502
 					$data = strtr($data, array('<br />' => ''));
1436 1503
 
1437
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1438
-						$data = 'ftp://' . $data;
1504
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1505
+											$data = 'ftp://' . $data;
1506
+					}
1439 1507
 				},
1440 1508
 			),
1441 1509
 			array(
@@ -1445,8 +1513,9 @@  discard block
 block discarded – undo
1445 1513
 				'after' => '</a>',
1446 1514
 				'validate' => function(&$tag, &$data, $disabled)
1447 1515
 				{
1448
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1449
-						$data = 'ftp://' . $data;
1516
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1517
+											$data = 'ftp://' . $data;
1518
+					}
1450 1519
 				},
1451 1520
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1452 1521
 				'disabled_after' => ' ($1)',
@@ -1506,17 +1575,20 @@  discard block
 block discarded – undo
1506 1575
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1507 1576
 					if ($image_proxy_enabled)
1508 1577
 					{
1509
-						if (!empty($user_info['possibly_robot']))
1510
-							return;
1578
+						if (!empty($user_info['possibly_robot'])) {
1579
+													return;
1580
+						}
1511 1581
 
1512
-						if (empty($scheme))
1513
-							$data = 'http://' . ltrim($data, ':/');
1582
+						if (empty($scheme)) {
1583
+													$data = 'http://' . ltrim($data, ':/');
1584
+						}
1514 1585
 
1515
-						if ($scheme != 'https')
1516
-							$data = get_proxied_url($data);
1586
+						if ($scheme != 'https') {
1587
+													$data = get_proxied_url($data);
1588
+						}
1589
+					} elseif (empty($scheme)) {
1590
+											$data = '//' . ltrim($data, ':/');
1517 1591
 					}
1518
-					elseif (empty($scheme))
1519
-						$data = '//' . ltrim($data, ':/');
1520 1592
 				},
1521 1593
 				'disabled_content' => '($1)',
1522 1594
 			),
@@ -1532,17 +1604,20 @@  discard block
 block discarded – undo
1532 1604
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1533 1605
 					if ($image_proxy_enabled)
1534 1606
 					{
1535
-						if (!empty($user_info['possibly_robot']))
1536
-							return;
1607
+						if (!empty($user_info['possibly_robot'])) {
1608
+													return;
1609
+						}
1537 1610
 
1538
-						if (empty($scheme))
1539
-							$data = 'http://' . ltrim($data, ':/');
1611
+						if (empty($scheme)) {
1612
+													$data = 'http://' . ltrim($data, ':/');
1613
+						}
1540 1614
 
1541
-						if ($scheme != 'https')
1542
-							$data = get_proxied_url($data);
1615
+						if ($scheme != 'https') {
1616
+													$data = get_proxied_url($data);
1617
+						}
1618
+					} elseif (empty($scheme)) {
1619
+											$data = '//' . ltrim($data, ':/');
1543 1620
 					}
1544
-					elseif (empty($scheme))
1545
-						$data = '//' . ltrim($data, ':/');
1546 1621
 				},
1547 1622
 				'disabled_content' => '($1)',
1548 1623
 			),
@@ -1554,8 +1629,9 @@  discard block
 block discarded – undo
1554 1629
 				{
1555 1630
 					$data = strtr($data, array('<br>' => ''));
1556 1631
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1557
-					if (empty($scheme))
1558
-						$data = '//' . ltrim($data, ':/');
1632
+					if (empty($scheme)) {
1633
+											$data = '//' . ltrim($data, ':/');
1634
+					}
1559 1635
 				},
1560 1636
 			),
1561 1637
 			array(
@@ -1566,13 +1642,14 @@  discard block
 block discarded – undo
1566 1642
 				'after' => '</a>',
1567 1643
 				'validate' => function (&$tag, &$data, $disabled)
1568 1644
 				{
1569
-					if (substr($data, 0, 1) == '#')
1570
-						$data = '#post_' . substr($data, 1);
1571
-					else
1645
+					if (substr($data, 0, 1) == '#') {
1646
+											$data = '#post_' . substr($data, 1);
1647
+					} else
1572 1648
 					{
1573 1649
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1574
-						if (empty($scheme))
1575
-							$data = '//' . ltrim($data, ':/');
1650
+						if (empty($scheme)) {
1651
+													$data = '//' . ltrim($data, ':/');
1652
+						}
1576 1653
 					}
1577 1654
 				},
1578 1655
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1663,8 +1740,9 @@  discard block
 block discarded – undo
1663 1740
 					{
1664 1741
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1665 1742
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1666
-						if ($add_begin)
1667
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1743
+						if ($add_begin) {
1744
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1745
+						}
1668 1746
 					}
1669 1747
 				},
1670 1748
 				'block_level' => false,
@@ -1777,20 +1855,17 @@  discard block
 block discarded – undo
1777 1855
 					: function(&$tag, &$data, $disabled)
1778 1856
 					{
1779 1857
 
1780
-						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50))
1781
-							$data[1] = '0 -2px 1px';
1782
-
1783
-						elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100))
1784
-							$data[1] = '2px 0 1px';
1785
-
1786
-						elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190))
1787
-							$data[1] = '0 2px 1px';
1788
-
1789
-						elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280))
1790
-							$data[1] = '-2px 0 1px';
1791
-
1792
-						else
1793
-							$data[1] = '1px 1px 1px';
1858
+						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) {
1859
+													$data[1] = '0 -2px 1px';
1860
+						} elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) {
1861
+													$data[1] = '2px 0 1px';
1862
+						} elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) {
1863
+													$data[1] = '0 2px 1px';
1864
+						} elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) {
1865
+													$data[1] = '-2px 0 1px';
1866
+						} else {
1867
+													$data[1] = '1px 1px 1px';
1868
+						}
1794 1869
 					},
1795 1870
 			),
1796 1871
 			array(
@@ -1846,10 +1921,11 @@  discard block
 block discarded – undo
1846 1921
 				'content' => '$1',
1847 1922
 				'validate' => function (&$tag, &$data, $disabled)
1848 1923
 				{
1849
-					if (is_numeric($data))
1850
-						$data = timeformat($data);
1851
-					else
1852
-						$tag['content'] = '[time]$1[/time]';
1924
+					if (is_numeric($data)) {
1925
+											$data = timeformat($data);
1926
+					} else {
1927
+											$tag['content'] = '[time]$1[/time]';
1928
+					}
1853 1929
 				},
1854 1930
 			),
1855 1931
 			array(
@@ -1881,8 +1957,9 @@  discard block
 block discarded – undo
1881 1957
 				{
1882 1958
 					$data = strtr($data, array('<br>' => ''));
1883 1959
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1884
-					if (empty($scheme))
1885
-						$data = '//' . ltrim($data, ':/');
1960
+					if (empty($scheme)) {
1961
+											$data = '//' . ltrim($data, ':/');
1962
+					}
1886 1963
 				},
1887 1964
 			),
1888 1965
 			array(
@@ -1894,8 +1971,9 @@  discard block
 block discarded – undo
1894 1971
 				'validate' => function (&$tag, &$data, $disabled)
1895 1972
 				{
1896 1973
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1897
-					if (empty($scheme))
1898
-						$data = '//' . ltrim($data, ':/');
1974
+					if (empty($scheme)) {
1975
+											$data = '//' . ltrim($data, ':/');
1976
+					}
1899 1977
 				},
1900 1978
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1901 1979
 				'disabled_after' => ' ($1)',
@@ -1915,12 +1993,13 @@  discard block
 block discarded – undo
1915 1993
 		);
1916 1994
 
1917 1995
 		// Handle legacy bbc codes.
1918
-		foreach ($context['legacy_bbc'] as $bbc)
1919
-			$codes[] = array(
1996
+		foreach ($context['legacy_bbc'] as $bbc) {
1997
+					$codes[] = array(
1920 1998
 				'tag' => $bbc,
1921 1999
 				'before' => '',
1922 2000
 				'after' => '',
1923 2001
 			);
2002
+		}
1924 2003
 
1925 2004
 		// Let mods add new BBC without hassle.
1926 2005
 		call_integration_hook('integrate_bbc_codes', array(&$codes, &$no_autolink_tags));
@@ -1928,8 +2007,9 @@  discard block
 block discarded – undo
1928 2007
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1929 2008
 		if ($message === false)
1930 2009
 		{
1931
-			if (isset($temp_bbc))
1932
-				$bbc_codes = $temp_bbc;
2010
+			if (isset($temp_bbc)) {
2011
+							$bbc_codes = $temp_bbc;
2012
+			}
1933 2013
 			usort($codes, function ($a, $b) {
1934 2014
 				return strcmp($a['tag'], $b['tag']);
1935 2015
 			});
@@ -1949,8 +2029,9 @@  discard block
 block discarded – undo
1949 2029
 		);
1950 2030
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1951 2031
 		{
1952
-			foreach ($itemcodes as $c => $dummy)
1953
-				$bbc_codes[$c] = array();
2032
+			foreach ($itemcodes as $c => $dummy) {
2033
+							$bbc_codes[$c] = array();
2034
+			}
1954 2035
 		}
1955 2036
 
1956 2037
 		// Shhhh!
@@ -1971,12 +2052,14 @@  discard block
 block discarded – undo
1971 2052
 		foreach ($codes as $code)
1972 2053
 		{
1973 2054
 			// Make it easier to process parameters later
1974
-			if (!empty($code['parameters']))
1975
-				ksort($code['parameters'], SORT_STRING);
2055
+			if (!empty($code['parameters'])) {
2056
+							ksort($code['parameters'], SORT_STRING);
2057
+			}
1976 2058
 
1977 2059
 			// If we are not doing every tag only do ones we are interested in.
1978
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1979
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2060
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
2061
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2062
+			}
1980 2063
 		}
1981 2064
 		$codes = null;
1982 2065
 	}
@@ -1987,8 +2070,9 @@  discard block
 block discarded – undo
1987 2070
 		// It's likely this will change if the message is modified.
1988 2071
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1989 2072
 
1990
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1991
-			return $temp;
2073
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
2074
+					return $temp;
2075
+		}
1992 2076
 
1993 2077
 		$cache_t = microtime();
1994 2078
 	}
@@ -2020,8 +2104,9 @@  discard block
 block discarded – undo
2020 2104
 		$disabled['flash'] = true;
2021 2105
 
2022 2106
 		// @todo Change maybe?
2023
-		if (!isset($_GET['images']))
2024
-			$disabled['img'] = true;
2107
+		if (!isset($_GET['images'])) {
2108
+					$disabled['img'] = true;
2109
+		}
2025 2110
 
2026 2111
 		// @todo Interface/setting to add more?
2027 2112
 	}
@@ -2032,8 +2117,9 @@  discard block
 block discarded – undo
2032 2117
 	$alltags = array();
2033 2118
 	foreach ($bbc_codes as $section)
2034 2119
 	{
2035
-		foreach ($section as $code)
2036
-			$alltags[] = $code['tag'];
2120
+		foreach ($section as $code) {
2121
+					$alltags[] = $code['tag'];
2122
+		}
2037 2123
 	}
2038 2124
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
2039 2125
 
@@ -2045,8 +2131,9 @@  discard block
 block discarded – undo
2045 2131
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
2046 2132
 
2047 2133
 		// Failsafe.
2048
-		if ($pos === false || $last_pos > $pos)
2049
-			$pos = strlen($message) + 1;
2134
+		if ($pos === false || $last_pos > $pos) {
2135
+					$pos = strlen($message) + 1;
2136
+		}
2050 2137
 
2051 2138
 		// Can't have a one letter smiley, URL, or email! (sorry.)
2052 2139
 		if ($last_pos < $pos - 1)
@@ -2064,8 +2151,9 @@  discard block
 block discarded – undo
2064 2151
 
2065 2152
 				// <br> should be empty.
2066 2153
 				$empty_tags = array('br', 'hr');
2067
-				foreach ($empty_tags as $tag)
2068
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2154
+				foreach ($empty_tags as $tag) {
2155
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2156
+				}
2069 2157
 
2070 2158
 				// b, u, i, s, pre... basic tags.
2071 2159
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -2074,8 +2162,9 @@  discard block
 block discarded – undo
2074 2162
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
2075 2163
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
2076 2164
 
2077
-					if ($diff > 0)
2078
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2165
+					if ($diff > 0) {
2166
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2167
+					}
2079 2168
 				}
2080 2169
 
2081 2170
 				// Do <img ...> - with security... action= -> action-.
@@ -2088,8 +2177,9 @@  discard block
 block discarded – undo
2088 2177
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
2089 2178
 
2090 2179
 						// Remove action= from the URL - no funny business, now.
2091
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
2092
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2180
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2181
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2182
+						}
2093 2183
 
2094 2184
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
2095 2185
 					}
@@ -2104,16 +2194,18 @@  discard block
 block discarded – undo
2104 2194
 				$no_autolink_area = false;
2105 2195
 				if (!empty($open_tags))
2106 2196
 				{
2107
-					foreach ($open_tags as $open_tag)
2108
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2197
+					foreach ($open_tags as $open_tag) {
2198
+											if (in_array($open_tag['tag'], $no_autolink_tags))
2109 2199
 							$no_autolink_area = true;
2200
+					}
2110 2201
 				}
2111 2202
 
2112 2203
 				// Don't go backwards.
2113 2204
 				// @todo Don't think is the real solution....
2114 2205
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
2115
-				if ($pos < $lastAutoPos)
2116
-					$no_autolink_area = true;
2206
+				if ($pos < $lastAutoPos) {
2207
+									$no_autolink_area = true;
2208
+				}
2117 2209
 				$lastAutoPos = $pos;
2118 2210
 
2119 2211
 				if (!$no_autolink_area)
@@ -2218,29 +2310,33 @@  discard block
 block discarded – undo
2218 2310
 							$url = array_shift($matches);
2219 2311
 
2220 2312
 							// If this isn't a clean URL, bail out
2221
-							if ($url != sanitize_iri($url))
2222
-								return $url;
2313
+							if ($url != sanitize_iri($url)) {
2314
+															return $url;
2315
+							}
2223 2316
 
2224 2317
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2225 2318
 
2226 2319
 							if ($scheme == 'mailto')
2227 2320
 							{
2228 2321
 								$email_address = str_replace('mailto:', '', $url);
2229
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2230
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2231
-								else
2232
-									return $url;
2322
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2323
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2324
+								} else {
2325
+																	return $url;
2326
+								}
2233 2327
 							}
2234 2328
 
2235 2329
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2236
-							if (empty($scheme))
2237
-								$fullUrl = '//' . ltrim($url, ':/');
2238
-							else
2239
-								$fullUrl = $url;
2330
+							if (empty($scheme)) {
2331
+															$fullUrl = '//' . ltrim($url, ':/');
2332
+							} else {
2333
+															$fullUrl = $url;
2334
+							}
2240 2335
 
2241 2336
 							// Make sure that $fullUrl really is valid
2242
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2243
-								return $url;
2337
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2338
+															return $url;
2339
+							}
2244 2340
 
2245 2341
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2246 2342
 						}, $data);
@@ -2289,22 +2385,25 @@  discard block
 block discarded – undo
2289 2385
 		}
2290 2386
 
2291 2387
 		// Are we there yet?  Are we there yet?
2292
-		if ($pos >= strlen($message) - 1)
2293
-			break;
2388
+		if ($pos >= strlen($message) - 1) {
2389
+					break;
2390
+		}
2294 2391
 
2295 2392
 		$tags = strtolower($message[$pos + 1]);
2296 2393
 
2297 2394
 		if ($tags == '/' && !empty($open_tags))
2298 2395
 		{
2299 2396
 			$pos2 = strpos($message, ']', $pos + 1);
2300
-			if ($pos2 == $pos + 2)
2301
-				continue;
2397
+			if ($pos2 == $pos + 2) {
2398
+							continue;
2399
+			}
2302 2400
 
2303 2401
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2304 2402
 
2305 2403
 			// A closing tag that doesn't match any open tags? Skip it.
2306
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2307
-				continue;
2404
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2405
+							continue;
2406
+			}
2308 2407
 
2309 2408
 			$to_close = array();
2310 2409
 			$block_level = null;
@@ -2312,8 +2411,9 @@  discard block
 block discarded – undo
2312 2411
 			do
2313 2412
 			{
2314 2413
 				$tag = array_pop($open_tags);
2315
-				if (!$tag)
2316
-					break;
2414
+				if (!$tag) {
2415
+									break;
2416
+				}
2317 2417
 
2318 2418
 				if (!empty($tag['block_level']))
2319 2419
 				{
@@ -2327,10 +2427,11 @@  discard block
 block discarded – undo
2327 2427
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2328 2428
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2329 2429
 					{
2330
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2331
-							if ($temp['tag'] == $look_for)
2430
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2431
+													if ($temp['tag'] == $look_for)
2332 2432
 							{
2333 2433
 								$block_level = !empty($temp['block_level']);
2434
+						}
2334 2435
 								break;
2335 2436
 							}
2336 2437
 					}
@@ -2352,15 +2453,15 @@  discard block
 block discarded – undo
2352 2453
 			{
2353 2454
 				$open_tags = $to_close;
2354 2455
 				continue;
2355
-			}
2356
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2456
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2357 2457
 			{
2358 2458
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2359 2459
 				{
2360
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2361
-						if ($temp['tag'] == $look_for)
2460
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2461
+											if ($temp['tag'] == $look_for)
2362 2462
 						{
2363 2463
 							$block_level = !empty($temp['block_level']);
2464
+					}
2364 2465
 							break;
2365 2466
 						}
2366 2467
 				}
@@ -2368,8 +2469,9 @@  discard block
 block discarded – undo
2368 2469
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2369 2470
 				if (!$block_level)
2370 2471
 				{
2371
-					foreach ($to_close as $tag)
2372
-						array_push($open_tags, $tag);
2472
+					foreach ($to_close as $tag) {
2473
+											array_push($open_tags, $tag);
2474
+					}
2373 2475
 					continue;
2374 2476
 				}
2375 2477
 			}
@@ -2382,14 +2484,17 @@  discard block
 block discarded – undo
2382 2484
 
2383 2485
 				// See the comment at the end of the big loop - just eating whitespace ;).
2384 2486
 				$whitespace_regex = '';
2385
-				if (!empty($tag['block_level']))
2386
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2487
+				if (!empty($tag['block_level'])) {
2488
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2489
+				}
2387 2490
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2388
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2389
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2491
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2492
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2493
+				}
2390 2494
 
2391
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2392
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2495
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2496
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2497
+				}
2393 2498
 			}
2394 2499
 
2395 2500
 			if (!empty($to_close))
@@ -2402,8 +2507,9 @@  discard block
 block discarded – undo
2402 2507
 		}
2403 2508
 
2404 2509
 		// No tags for this character, so just keep going (fastest possible course.)
2405
-		if (!isset($bbc_codes[$tags]))
2406
-			continue;
2510
+		if (!isset($bbc_codes[$tags])) {
2511
+					continue;
2512
+		}
2407 2513
 
2408 2514
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2409 2515
 		$tag = null;
@@ -2412,48 +2518,57 @@  discard block
 block discarded – undo
2412 2518
 			$pt_strlen = strlen($possible['tag']);
2413 2519
 
2414 2520
 			// Not a match?
2415
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2416
-				continue;
2521
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2522
+							continue;
2523
+			}
2417 2524
 
2418 2525
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2419 2526
 
2420 2527
 			// A tag is the last char maybe
2421
-			if ($next_c == '')
2422
-				break;
2528
+			if ($next_c == '') {
2529
+							break;
2530
+			}
2423 2531
 
2424 2532
 			// A test validation?
2425
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2426
-				continue;
2533
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2534
+							continue;
2535
+			}
2427 2536
 			// Do we want parameters?
2428 2537
 			elseif (!empty($possible['parameters']))
2429 2538
 			{
2430
-				if ($next_c != ' ')
2431
-					continue;
2432
-			}
2433
-			elseif (isset($possible['type']))
2539
+				if ($next_c != ' ') {
2540
+									continue;
2541
+				}
2542
+			} elseif (isset($possible['type']))
2434 2543
 			{
2435 2544
 				// Do we need an equal sign?
2436
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2437
-					continue;
2545
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2546
+									continue;
2547
+				}
2438 2548
 				// Maybe we just want a /...
2439
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2440
-					continue;
2549
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2550
+									continue;
2551
+				}
2441 2552
 				// An immediate ]?
2442
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2443
-					continue;
2553
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2554
+									continue;
2555
+				}
2444 2556
 			}
2445 2557
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2446
-			elseif ($next_c != ']')
2447
-				continue;
2558
+			elseif ($next_c != ']') {
2559
+							continue;
2560
+			}
2448 2561
 
2449 2562
 			// Check allowed tree?
2450
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2451
-				continue;
2452
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2453
-				continue;
2563
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2564
+							continue;
2565
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2566
+							continue;
2567
+			}
2454 2568
 			// If this is in the list of disallowed child tags, don't parse it.
2455
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2456
-				continue;
2569
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2570
+							continue;
2571
+			}
2457 2572
 
2458 2573
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2459 2574
 
@@ -2465,8 +2580,9 @@  discard block
 block discarded – undo
2465 2580
 				foreach ($open_tags as $open_quote)
2466 2581
 				{
2467 2582
 					// Every parent quote this quote has flips the styling
2468
-					if ($open_quote['tag'] == 'quote')
2469
-						$quote_alt = !$quote_alt;
2583
+					if ($open_quote['tag'] == 'quote') {
2584
+											$quote_alt = !$quote_alt;
2585
+					}
2470 2586
 				}
2471 2587
 				// Add a class to the quote to style alternating blockquotes
2472 2588
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2477,8 +2593,9 @@  discard block
 block discarded – undo
2477 2593
 			{
2478 2594
 				// Build a regular expression for each parameter for the current tag.
2479 2595
 				$preg = array();
2480
-				foreach ($possible['parameters'] as $p => $info)
2481
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2596
+				foreach ($possible['parameters'] as $p => $info) {
2597
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2598
+				}
2482 2599
 
2483 2600
 				// Extract the string that potentially holds our parameters.
2484 2601
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2497,24 +2614,27 @@  discard block
 block discarded – undo
2497 2614
 
2498 2615
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2499 2616
 
2500
-					if ($match)
2501
-						$blob_counter = count($blobs) + 1;
2617
+					if ($match) {
2618
+											$blob_counter = count($blobs) + 1;
2619
+					}
2502 2620
 				}
2503 2621
 
2504 2622
 				// Didn't match our parameter list, try the next possible.
2505
-				if (!$match)
2506
-					continue;
2623
+				if (!$match) {
2624
+									continue;
2625
+				}
2507 2626
 
2508 2627
 				$params = array();
2509 2628
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2510 2629
 				{
2511 2630
 					$key = strtok(ltrim($matches[$i]), '=');
2512
-					if (isset($possible['parameters'][$key]['value']))
2513
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2514
-					elseif (isset($possible['parameters'][$key]['validate']))
2515
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2516
-					else
2517
-						$params['{' . $key . '}'] = $matches[$i + 1];
2631
+					if (isset($possible['parameters'][$key]['value'])) {
2632
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2633
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2634
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2635
+					} else {
2636
+											$params['{' . $key . '}'] = $matches[$i + 1];
2637
+					}
2518 2638
 
2519 2639
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2520 2640
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2522,23 +2642,26 @@  discard block
 block discarded – undo
2522 2642
 
2523 2643
 				foreach ($possible['parameters'] as $p => $info)
2524 2644
 				{
2525
-					if (!isset($params['{' . $p . '}']))
2526
-						$params['{' . $p . '}'] = '';
2645
+					if (!isset($params['{' . $p . '}'])) {
2646
+											$params['{' . $p . '}'] = '';
2647
+					}
2527 2648
 				}
2528 2649
 
2529 2650
 				$tag = $possible;
2530 2651
 
2531 2652
 				// Put the parameters into the string.
2532
-				if (isset($tag['before']))
2533
-					$tag['before'] = strtr($tag['before'], $params);
2534
-				if (isset($tag['after']))
2535
-					$tag['after'] = strtr($tag['after'], $params);
2536
-				if (isset($tag['content']))
2537
-					$tag['content'] = strtr($tag['content'], $params);
2653
+				if (isset($tag['before'])) {
2654
+									$tag['before'] = strtr($tag['before'], $params);
2655
+				}
2656
+				if (isset($tag['after'])) {
2657
+									$tag['after'] = strtr($tag['after'], $params);
2658
+				}
2659
+				if (isset($tag['content'])) {
2660
+									$tag['content'] = strtr($tag['content'], $params);
2661
+				}
2538 2662
 
2539 2663
 				$pos1 += strlen($given_param_string);
2540
-			}
2541
-			else
2664
+			} else
2542 2665
 			{
2543 2666
 				$tag = $possible;
2544 2667
 				$params = array();
@@ -2549,8 +2672,9 @@  discard block
 block discarded – undo
2549 2672
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2550 2673
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2551 2674
 		{
2552
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2553
-				continue;
2675
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2676
+							continue;
2677
+			}
2554 2678
 
2555 2679
 			$tag = $itemcodes[$message[$pos + 1]];
2556 2680
 
@@ -2571,9 +2695,9 @@  discard block
 block discarded – undo
2571 2695
 			{
2572 2696
 				array_pop($open_tags);
2573 2697
 				$code = '</li>';
2698
+			} else {
2699
+							$code = '';
2574 2700
 			}
2575
-			else
2576
-				$code = '';
2577 2701
 
2578 2702
 			// Now we open a new tag.
2579 2703
 			$open_tags[] = array(
@@ -2620,12 +2744,14 @@  discard block
 block discarded – undo
2620 2744
 		}
2621 2745
 
2622 2746
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2623
-		if ($tag === null)
2624
-			continue;
2747
+		if ($tag === null) {
2748
+					continue;
2749
+		}
2625 2750
 
2626 2751
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2627
-		if (isset($inside['disallow_children']))
2628
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2752
+		if (isset($inside['disallow_children'])) {
2753
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2754
+		}
2629 2755
 
2630 2756
 		// Is this tag disabled?
2631 2757
 		if (isset($disabled[$tag['tag']]))
@@ -2635,14 +2761,13 @@  discard block
 block discarded – undo
2635 2761
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2636 2762
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2637 2763
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2638
-			}
2639
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2764
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2640 2765
 			{
2641 2766
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2642 2767
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2768
+			} else {
2769
+							$tag['content'] = $tag['disabled_content'];
2643 2770
 			}
2644
-			else
2645
-				$tag['content'] = $tag['disabled_content'];
2646 2771
 		}
2647 2772
 
2648 2773
 		// we use this a lot
@@ -2652,8 +2777,9 @@  discard block
 block discarded – undo
2652 2777
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2653 2778
 		{
2654 2779
 			$n = count($open_tags) - 1;
2655
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2656
-				$n--;
2780
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2781
+							$n--;
2782
+			}
2657 2783
 
2658 2784
 			// Close all the non block level tags so this tag isn't surrounded by them.
2659 2785
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2665,12 +2791,15 @@  discard block
 block discarded – undo
2665 2791
 
2666 2792
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2667 2793
 				$whitespace_regex = '';
2668
-				if (!empty($tag['block_level']))
2669
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2670
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2671
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2672
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2673
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2794
+				if (!empty($tag['block_level'])) {
2795
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2796
+				}
2797
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2798
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2799
+				}
2800
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2801
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2802
+				}
2674 2803
 
2675 2804
 				array_pop($open_tags);
2676 2805
 			}
@@ -2691,16 +2820,19 @@  discard block
 block discarded – undo
2691 2820
 		elseif ($tag['type'] == 'unparsed_content')
2692 2821
 		{
2693 2822
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2694
-			if ($pos2 === false)
2695
-				continue;
2823
+			if ($pos2 === false) {
2824
+							continue;
2825
+			}
2696 2826
 
2697 2827
 			$data = substr($message, $pos1, $pos2 - $pos1);
2698 2828
 
2699
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2700
-				$data = substr($data, 4);
2829
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2830
+							$data = substr($data, 4);
2831
+			}
2701 2832
 
2702
-			if (isset($tag['validate']))
2703
-				$tag['validate']($tag, $data, $disabled, $params);
2833
+			if (isset($tag['validate'])) {
2834
+							$tag['validate']($tag, $data, $disabled, $params);
2835
+			}
2704 2836
 
2705 2837
 			$code = strtr($tag['content'], array('$1' => $data));
2706 2838
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2715,34 +2847,40 @@  discard block
 block discarded – undo
2715 2847
 			if (isset($tag['quoted']))
2716 2848
 			{
2717 2849
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2718
-				if ($tag['quoted'] != 'optional' && !$quoted)
2719
-					continue;
2850
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2851
+									continue;
2852
+				}
2720 2853
 
2721
-				if ($quoted)
2722
-					$pos1 += 6;
2854
+				if ($quoted) {
2855
+									$pos1 += 6;
2856
+				}
2857
+			} else {
2858
+							$quoted = false;
2723 2859
 			}
2724
-			else
2725
-				$quoted = false;
2726 2860
 
2727 2861
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2728
-			if ($pos2 === false)
2729
-				continue;
2862
+			if ($pos2 === false) {
2863
+							continue;
2864
+			}
2730 2865
 
2731 2866
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2732
-			if ($pos3 === false)
2733
-				continue;
2867
+			if ($pos3 === false) {
2868
+							continue;
2869
+			}
2734 2870
 
2735 2871
 			$data = array(
2736 2872
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2737 2873
 				substr($message, $pos1, $pos2 - $pos1)
2738 2874
 			);
2739 2875
 
2740
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2741
-				$data[0] = substr($data[0], 4);
2876
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2877
+							$data[0] = substr($data[0], 4);
2878
+			}
2742 2879
 
2743 2880
 			// Validation for my parking, please!
2744
-			if (isset($tag['validate']))
2745
-				$tag['validate']($tag, $data, $disabled, $params);
2881
+			if (isset($tag['validate'])) {
2882
+							$tag['validate']($tag, $data, $disabled, $params);
2883
+			}
2746 2884
 
2747 2885
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2748 2886
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2759,23 +2897,27 @@  discard block
 block discarded – undo
2759 2897
 		elseif ($tag['type'] == 'unparsed_commas_content')
2760 2898
 		{
2761 2899
 			$pos2 = strpos($message, ']', $pos1);
2762
-			if ($pos2 === false)
2763
-				continue;
2900
+			if ($pos2 === false) {
2901
+							continue;
2902
+			}
2764 2903
 
2765 2904
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2766
-			if ($pos3 === false)
2767
-				continue;
2905
+			if ($pos3 === false) {
2906
+							continue;
2907
+			}
2768 2908
 
2769 2909
 			// We want $1 to be the content, and the rest to be csv.
2770 2910
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2771 2911
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2772 2912
 
2773
-			if (isset($tag['validate']))
2774
-				$tag['validate']($tag, $data, $disabled, $params);
2913
+			if (isset($tag['validate'])) {
2914
+							$tag['validate']($tag, $data, $disabled, $params);
2915
+			}
2775 2916
 
2776 2917
 			$code = $tag['content'];
2777
-			foreach ($data as $k => $d)
2778
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2918
+			foreach ($data as $k => $d) {
2919
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2920
+			}
2779 2921
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2780 2922
 			$pos += strlen($code) - 1 + 2;
2781 2923
 		}
@@ -2783,24 +2925,28 @@  discard block
 block discarded – undo
2783 2925
 		elseif ($tag['type'] == 'unparsed_commas')
2784 2926
 		{
2785 2927
 			$pos2 = strpos($message, ']', $pos1);
2786
-			if ($pos2 === false)
2787
-				continue;
2928
+			if ($pos2 === false) {
2929
+							continue;
2930
+			}
2788 2931
 
2789 2932
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2790 2933
 
2791
-			if (isset($tag['validate']))
2792
-				$tag['validate']($tag, $data, $disabled, $params);
2934
+			if (isset($tag['validate'])) {
2935
+							$tag['validate']($tag, $data, $disabled, $params);
2936
+			}
2793 2937
 
2794 2938
 			// Fix after, for disabled code mainly.
2795
-			foreach ($data as $k => $d)
2796
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2939
+			foreach ($data as $k => $d) {
2940
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2941
+			}
2797 2942
 
2798 2943
 			$open_tags[] = $tag;
2799 2944
 
2800 2945
 			// Replace them out, $1, $2, $3, $4, etc.
2801 2946
 			$code = $tag['before'];
2802
-			foreach ($data as $k => $d)
2803
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2947
+			foreach ($data as $k => $d) {
2948
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2949
+			}
2804 2950
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2805 2951
 			$pos += strlen($code) - 1 + 2;
2806 2952
 		}
@@ -2811,28 +2957,33 @@  discard block
 block discarded – undo
2811 2957
 			if (isset($tag['quoted']))
2812 2958
 			{
2813 2959
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2814
-				if ($tag['quoted'] != 'optional' && !$quoted)
2815
-					continue;
2960
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2961
+									continue;
2962
+				}
2816 2963
 
2817
-				if ($quoted)
2818
-					$pos1 += 6;
2964
+				if ($quoted) {
2965
+									$pos1 += 6;
2966
+				}
2967
+			} else {
2968
+							$quoted = false;
2819 2969
 			}
2820
-			else
2821
-				$quoted = false;
2822 2970
 
2823 2971
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2824
-			if ($pos2 === false)
2825
-				continue;
2972
+			if ($pos2 === false) {
2973
+							continue;
2974
+			}
2826 2975
 
2827 2976
 			$data = substr($message, $pos1, $pos2 - $pos1);
2828 2977
 
2829 2978
 			// Validation for my parking, please!
2830
-			if (isset($tag['validate']))
2831
-				$tag['validate']($tag, $data, $disabled, $params);
2979
+			if (isset($tag['validate'])) {
2980
+							$tag['validate']($tag, $data, $disabled, $params);
2981
+			}
2832 2982
 
2833 2983
 			// For parsed content, we must recurse to avoid security problems.
2834
-			if ($tag['type'] != 'unparsed_equals')
2835
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2984
+			if ($tag['type'] != 'unparsed_equals') {
2985
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2986
+			}
2836 2987
 
2837 2988
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2838 2989
 
@@ -2844,34 +2995,40 @@  discard block
 block discarded – undo
2844 2995
 		}
2845 2996
 
2846 2997
 		// If this is block level, eat any breaks after it.
2847
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2848
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2998
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2999
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
3000
+		}
2849 3001
 
2850 3002
 		// Are we trimming outside this tag?
2851
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2852
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
3003
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
3004
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
3005
+		}
2853 3006
 	}
2854 3007
 
2855 3008
 	// Close any remaining tags.
2856
-	while ($tag = array_pop($open_tags))
2857
-		$message .= "\n" . $tag['after'] . "\n";
3009
+	while ($tag = array_pop($open_tags)) {
3010
+			$message .= "\n" . $tag['after'] . "\n";
3011
+	}
2858 3012
 
2859 3013
 	// Parse the smileys within the parts where it can be done safely.
2860 3014
 	if ($smileys === true)
2861 3015
 	{
2862 3016
 		$message_parts = explode("\n", $message);
2863
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2864
-			parsesmileys($message_parts[$i]);
3017
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
3018
+					parsesmileys($message_parts[$i]);
3019
+		}
2865 3020
 
2866 3021
 		$message = implode('', $message_parts);
2867 3022
 	}
2868 3023
 
2869 3024
 	// No smileys, just get rid of the markers.
2870
-	else
2871
-		$message = strtr($message, array("\n" => ''));
3025
+	else {
3026
+			$message = strtr($message, array("\n" => ''));
3027
+	}
2872 3028
 
2873
-	if ($message !== '' && $message[0] === ' ')
2874
-		$message = '&nbsp;' . substr($message, 1);
3029
+	if ($message !== '' && $message[0] === ' ') {
3030
+			$message = '&nbsp;' . substr($message, 1);
3031
+	}
2875 3032
 
2876 3033
 	// Cleanup whitespace.
2877 3034
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2880,15 +3037,16 @@  discard block
 block discarded – undo
2880 3037
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2881 3038
 
2882 3039
 	// Cache the output if it took some time...
2883
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2884
-		cache_put_data($cache_key, $message, 240);
3040
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
3041
+			cache_put_data($cache_key, $message, 240);
3042
+	}
2885 3043
 
2886 3044
 	// If this was a force parse revert if needed.
2887 3045
 	if (!empty($parse_tags))
2888 3046
 	{
2889
-		if (empty($temp_bbc))
2890
-			$bbc_codes = array();
2891
-		else
3047
+		if (empty($temp_bbc)) {
3048
+					$bbc_codes = array();
3049
+		} else
2892 3050
 		{
2893 3051
 			$bbc_codes = $temp_bbc;
2894 3052
 			unset($temp_bbc);
@@ -2915,8 +3073,9 @@  discard block
 block discarded – undo
2915 3073
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2916 3074
 
2917 3075
 	// No smiley set at all?!
2918
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2919
-		return;
3076
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
3077
+			return;
3078
+	}
2920 3079
 
2921 3080
 	// Maybe a mod wants to implement an alternative method (e.g. emojis instead of images)
2922 3081
 	call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements));
@@ -2930,8 +3089,7 @@  discard block
 block discarded – undo
2930 3089
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2931 3090
 			$smileysto = array('evil.png', 'cheesy.png', 'rolleyes.png', 'angry.png', 'laugh.png', 'smiley.png', 'wink.png', 'grin.png', 'sad.png', 'shocked.png', 'cool.png', 'tongue.png', 'huh.png', 'embarrassed.png', 'lipsrsealed.png', 'kiss.png', 'cry.png', 'undecided.png', 'azn.png', 'afro.png', 'police.png', 'angel.png');
2932 3091
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2933
-		}
2934
-		else
3092
+		} else
2935 3093
 		{
2936 3094
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2937 3095
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2955,9 +3113,9 @@  discard block
 block discarded – undo
2955 3113
 				$smcFunc['db_free_result']($result);
2956 3114
 
2957 3115
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
3116
+			} else {
3117
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2958 3118
 			}
2959
-			else
2960
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2961 3119
 		}
2962 3120
 
2963 3121
 		// The non-breaking-space is a complex thing...
@@ -2979,16 +3137,18 @@  discard block
 block discarded – undo
2979 3137
 				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2980 3138
 				if (!empty($alt_images))
2981 3139
 				{
2982
-					foreach ($exts as $ext)
2983
-						if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
3140
+					foreach ($exts as $ext) {
3141
+											if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
2984 3142
 						{
2985 3143
 							$smileysto[$i] = $fname . '.' . $ext;
3144
+					}
2986 3145
 							break;
2987 3146
 						}
2988 3147
 				}
2989 3148
 				// If we have no image, just leave the text version in place
2990
-				else
2991
-					continue;
3149
+				else {
3150
+									continue;
3151
+				}
2992 3152
 			}
2993 3153
 
2994 3154
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
@@ -3056,12 +3216,14 @@  discard block
 block discarded – undo
3056 3216
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
3057 3217
 
3058 3218
 	// Only use the proxy if enabled and necessary
3059
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
3060
-		return $url;
3219
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3220
+			return $url;
3221
+	}
3061 3222
 
3062 3223
 	// We don't need to proxy our own resources
3063
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
3064
-		return strtr($url, array('http://' => 'https://'));
3224
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3225
+			return strtr($url, array('http://' => 'https://'));
3226
+	}
3065 3227
 
3066 3228
 	// By default, use SMF's own image proxy script
3067 3229
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -3086,35 +3248,41 @@  discard block
 block discarded – undo
3086 3248
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
3087 3249
 
3088 3250
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
3089
-	if (!empty($context['flush_mail']))
3090
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3251
+	if (!empty($context['flush_mail'])) {
3252
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3091 3253
 		AddMailQueue(true);
3254
+	}
3092 3255
 
3093 3256
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
3094 3257
 
3095
-	if ($add)
3096
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3258
+	if ($add) {
3259
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3260
+	}
3097 3261
 
3098 3262
 	// Put the session ID in.
3099
-	if (defined('SID') && SID != '')
3100
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3263
+	if (defined('SID') && SID != '') {
3264
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3265
+	}
3101 3266
 	// Keep that debug in their for template debugging!
3102
-	elseif (isset($_GET['debug']))
3103
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3267
+	elseif (isset($_GET['debug'])) {
3268
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3269
+	}
3104 3270
 
3105 3271
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
3106 3272
 	{
3107
-		if (defined('SID') && SID != '')
3108
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3273
+		if (defined('SID') && SID != '') {
3274
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3109 3275
 				function ($m) use ($scripturl)
3110 3276
 				{
3111 3277
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3278
+		}
3112 3279
 				}, $setLocation);
3113
-		else
3114
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3280
+		else {
3281
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3115 3282
 				function ($m) use ($scripturl)
3116 3283
 				{
3117 3284
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3285
+		}
3118 3286
 				}, $setLocation);
3119 3287
 	}
3120 3288
 
@@ -3125,8 +3293,9 @@  discard block
 block discarded – undo
3125 3293
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
3126 3294
 
3127 3295
 	// Debugging.
3128
-	if (isset($db_show_debug) && $db_show_debug === true)
3129
-		$_SESSION['debug_redirect'] = $db_cache;
3296
+	if (isset($db_show_debug) && $db_show_debug === true) {
3297
+			$_SESSION['debug_redirect'] = $db_cache;
3298
+	}
3130 3299
 
3131 3300
 	obExit(false);
3132 3301
 }
@@ -3145,51 +3314,60 @@  discard block
 block discarded – undo
3145 3314
 
3146 3315
 	// Attempt to prevent a recursive loop.
3147 3316
 	++$level;
3148
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
3149
-		exit;
3150
-	if ($from_fatal_error)
3151
-		$has_fatal_error = true;
3317
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3318
+			exit;
3319
+	}
3320
+	if ($from_fatal_error) {
3321
+			$has_fatal_error = true;
3322
+	}
3152 3323
 
3153 3324
 	// Clear out the stat cache.
3154 3325
 	trackStats();
3155 3326
 
3156 3327
 	// If we have mail to send, send it.
3157
-	if (!empty($context['flush_mail']))
3158
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3328
+	if (!empty($context['flush_mail'])) {
3329
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3159 3330
 		AddMailQueue(true);
3331
+	}
3160 3332
 
3161 3333
 	$do_header = $header === null ? !$header_done : $header;
3162
-	if ($do_footer === null)
3163
-		$do_footer = $do_header;
3334
+	if ($do_footer === null) {
3335
+			$do_footer = $do_header;
3336
+	}
3164 3337
 
3165 3338
 	// Has the template/header been done yet?
3166 3339
 	if ($do_header)
3167 3340
 	{
3168 3341
 		// Was the page title set last minute? Also update the HTML safe one.
3169
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
3170
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3342
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3343
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3344
+		}
3171 3345
 
3172 3346
 		// Start up the session URL fixer.
3173 3347
 		ob_start('ob_sessrewrite');
3174 3348
 
3175
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3176
-			$buffers = explode(',', $settings['output_buffers']);
3177
-		elseif (!empty($settings['output_buffers']))
3178
-			$buffers = $settings['output_buffers'];
3179
-		else
3180
-			$buffers = array();
3349
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3350
+					$buffers = explode(',', $settings['output_buffers']);
3351
+		} elseif (!empty($settings['output_buffers'])) {
3352
+					$buffers = $settings['output_buffers'];
3353
+		} else {
3354
+					$buffers = array();
3355
+		}
3181 3356
 
3182
-		if (isset($modSettings['integrate_buffer']))
3183
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3357
+		if (isset($modSettings['integrate_buffer'])) {
3358
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3359
+		}
3184 3360
 
3185
-		if (!empty($buffers))
3186
-			foreach ($buffers as $function)
3361
+		if (!empty($buffers)) {
3362
+					foreach ($buffers as $function)
3187 3363
 			{
3188 3364
 				$call = call_helper($function, true);
3365
+		}
3189 3366
 
3190 3367
 				// Is it valid?
3191
-				if (!empty($call))
3192
-					ob_start($call);
3368
+				if (!empty($call)) {
3369
+									ob_start($call);
3370
+				}
3193 3371
 			}
3194 3372
 
3195 3373
 		// Display the screen in the logical order.
@@ -3201,8 +3379,9 @@  discard block
 block discarded – undo
3201 3379
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3202 3380
 
3203 3381
 		// Anything special to put out?
3204
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3205
-			echo $context['insert_after_template'];
3382
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3383
+					echo $context['insert_after_template'];
3384
+		}
3206 3385
 
3207 3386
 		// Just so we don't get caught in an endless loop of errors from the footer...
3208 3387
 		if (!$footer_done)
@@ -3211,14 +3390,16 @@  discard block
 block discarded – undo
3211 3390
 			template_footer();
3212 3391
 
3213 3392
 			// (since this is just debugging... it's okay that it's after </html>.)
3214
-			if (!isset($_REQUEST['xml']))
3215
-				displayDebug();
3393
+			if (!isset($_REQUEST['xml'])) {
3394
+							displayDebug();
3395
+			}
3216 3396
 		}
3217 3397
 	}
3218 3398
 
3219 3399
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3220
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3221
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3400
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3401
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3402
+	}
3222 3403
 
3223 3404
 	// For session check verification.... don't switch browsers...
3224 3405
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3227,9 +3408,10 @@  discard block
 block discarded – undo
3227 3408
 	call_integration_hook('integrate_exit', array($do_footer));
3228 3409
 
3229 3410
 	// Don't exit if we're coming from index.php; that will pass through normally.
3230
-	if (!$from_index)
3231
-		exit;
3232
-}
3411
+	if (!$from_index) {
3412
+			exit;
3413
+	}
3414
+	}
3233 3415
 
3234 3416
 /**
3235 3417
  * Get the size of a specified image with better error handling.
@@ -3248,8 +3430,9 @@  discard block
 block discarded – undo
3248 3430
 	$url = str_replace(' ', '%20', $url);
3249 3431
 
3250 3432
 	// Can we pull this from the cache... please please?
3251
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3252
-		return $temp;
3433
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3434
+			return $temp;
3435
+	}
3253 3436
 	$t = microtime();
3254 3437
 
3255 3438
 	// Get the host to pester...
@@ -3259,12 +3442,10 @@  discard block
 block discarded – undo
3259 3442
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3260 3443
 	{
3261 3444
 		return false;
3262
-	}
3263
-	elseif (!isset($match[1]))
3445
+	} elseif (!isset($match[1]))
3264 3446
 	{
3265 3447
 		$size = @getimagesize($url);
3266
-	}
3267
-	else
3448
+	} else
3268 3449
 	{
3269 3450
 		// Try to connect to the server... give it half a second.
3270 3451
 		$temp = 0;
@@ -3301,12 +3482,14 @@  discard block
 block discarded – undo
3301 3482
 	}
3302 3483
 
3303 3484
 	// If we didn't get it, we failed.
3304
-	if (!isset($size))
3305
-		$size = false;
3485
+	if (!isset($size)) {
3486
+			$size = false;
3487
+	}
3306 3488
 
3307 3489
 	// If this took a long time, we may never have to do it again, but then again we might...
3308
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3309
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3490
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3491
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3492
+	}
3310 3493
 
3311 3494
 	// Didn't work.
3312 3495
 	return $size;
@@ -3324,8 +3507,9 @@  discard block
 block discarded – undo
3324 3507
 
3325 3508
 	// Under SSI this function can be called more then once.  That can cause some problems.
3326 3509
 	//   So only run the function once unless we are forced to run it again.
3327
-	if ($loaded && !$forceload)
3328
-		return;
3510
+	if ($loaded && !$forceload) {
3511
+			return;
3512
+	}
3329 3513
 
3330 3514
 	$loaded = true;
3331 3515
 
@@ -3337,14 +3521,16 @@  discard block
 block discarded – undo
3337 3521
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3338 3522
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3339 3523
 	{
3340
-		if (trim($context['news_lines'][$i]) == '')
3341
-			continue;
3524
+		if (trim($context['news_lines'][$i]) == '') {
3525
+					continue;
3526
+		}
3342 3527
 
3343 3528
 		// Clean it up for presentation ;).
3344 3529
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3345 3530
 	}
3346
-	if (!empty($context['news_lines']))
3347
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3531
+	if (!empty($context['news_lines'])) {
3532
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3533
+	}
3348 3534
 
3349 3535
 	if (!$user_info['is_guest'])
3350 3536
 	{
@@ -3353,40 +3539,48 @@  discard block
 block discarded – undo
3353 3539
 		$context['user']['alerts'] = &$user_info['alerts'];
3354 3540
 
3355 3541
 		// Personal message popup...
3356
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3357
-			$context['user']['popup_messages'] = true;
3358
-		else
3359
-			$context['user']['popup_messages'] = false;
3542
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3543
+					$context['user']['popup_messages'] = true;
3544
+		} else {
3545
+					$context['user']['popup_messages'] = false;
3546
+		}
3360 3547
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3361 3548
 
3362
-		if (allowedTo('moderate_forum'))
3363
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3549
+		if (allowedTo('moderate_forum')) {
3550
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3551
+		}
3364 3552
 
3365 3553
 		$context['user']['avatar'] = array();
3366 3554
 
3367 3555
 		// Check for gravatar first since we might be forcing them...
3368 3556
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3369 3557
 		{
3370
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3371
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3372
-			else
3373
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3558
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3559
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3560
+			} else {
3561
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3562
+			}
3374 3563
 		}
3375 3564
 		// Uploaded?
3376
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3377
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3565
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3566
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3567
+		}
3378 3568
 		// Full URL?
3379
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3380
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3569
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3570
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3571
+		}
3381 3572
 		// Otherwise we assume it's server stored.
3382
-		elseif ($user_info['avatar']['url'] != '')
3383
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3573
+		elseif ($user_info['avatar']['url'] != '') {
3574
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3575
+		}
3384 3576
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3385
-		else
3386
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3577
+		else {
3578
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3579
+		}
3387 3580
 
3388
-		if (!empty($context['user']['avatar']))
3389
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3581
+		if (!empty($context['user']['avatar'])) {
3582
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3583
+		}
3390 3584
 
3391 3585
 		// Figure out how long they've been logged in.
3392 3586
 		$context['user']['total_time_logged_in'] = array(
@@ -3394,8 +3588,7 @@  discard block
 block discarded – undo
3394 3588
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3395 3589
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3396 3590
 		);
3397
-	}
3398
-	else
3591
+	} else
3399 3592
 	{
3400 3593
 		$context['user']['messages'] = 0;
3401 3594
 		$context['user']['unread_messages'] = 0;
@@ -3403,12 +3596,14 @@  discard block
 block discarded – undo
3403 3596
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3404 3597
 		$context['user']['popup_messages'] = false;
3405 3598
 
3406
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3407
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3599
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3600
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3601
+		}
3408 3602
 
3409 3603
 		// If we've upgraded recently, go easy on the passwords.
3410
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3411
-			$context['disable_login_hashing'] = true;
3604
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3605
+					$context['disable_login_hashing'] = true;
3606
+		}
3412 3607
 	}
3413 3608
 
3414 3609
 	// Setup the main menu items.
@@ -3421,8 +3616,8 @@  discard block
 block discarded – undo
3421 3616
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3422 3617
 
3423 3618
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3424
-	if ($context['show_pm_popup'])
3425
-		addInlineJavaScript('
3619
+	if ($context['show_pm_popup']) {
3620
+			addInlineJavaScript('
3426 3621
 		jQuery(document).ready(function($) {
3427 3622
 			new smc_Popup({
3428 3623
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3430,24 +3625,28 @@  discard block
 block discarded – undo
3430 3625
 				icon_class: \'generic_icons mail_new\'
3431 3626
 			});
3432 3627
 		});');
3628
+	}
3433 3629
 
3434 3630
 	// Add a generic "Are you sure?" confirmation message.
3435 3631
 	addInlineJavaScript('
3436 3632
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3437 3633
 
3438 3634
 	// Now add the capping code for avatars.
3439
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3440
-		addInlineCss('
3635
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3636
+			addInlineCss('
3441 3637
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3638
+	}
3442 3639
 
3443 3640
 	// Add max image limits
3444
-	if (!empty($modSettings['max_image_width']))
3445
-		addInlineCss('
3641
+	if (!empty($modSettings['max_image_width'])) {
3642
+			addInlineCss('
3446 3643
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3644
+	}
3447 3645
 
3448
-	if (!empty($modSettings['max_image_height']))
3449
-		addInlineCss('
3646
+	if (!empty($modSettings['max_image_height'])) {
3647
+			addInlineCss('
3450 3648
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3649
+	}
3451 3650
 
3452 3651
 	// This looks weird, but it's because BoardIndex.php references the variable.
3453 3652
 	$context['common_stats']['latest_member'] = array(
@@ -3464,11 +3663,13 @@  discard block
 block discarded – undo
3464 3663
 	);
3465 3664
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3466 3665
 
3467
-	if (empty($settings['theme_version']))
3468
-		addJavaScriptVar('smf_scripturl', $scripturl);
3666
+	if (empty($settings['theme_version'])) {
3667
+			addJavaScriptVar('smf_scripturl', $scripturl);
3668
+	}
3469 3669
 
3470
-	if (!isset($context['page_title']))
3471
-		$context['page_title'] = '';
3670
+	if (!isset($context['page_title'])) {
3671
+			$context['page_title'] = '';
3672
+	}
3472 3673
 
3473 3674
 	// Set some specific vars.
3474 3675
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3478,21 +3679,23 @@  discard block
 block discarded – undo
3478 3679
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3479 3680
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3480 3681
 
3481
-	if (!empty($context['meta_keywords']))
3482
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3682
+	if (!empty($context['meta_keywords'])) {
3683
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3684
+	}
3483 3685
 
3484
-	if (!empty($context['canonical_url']))
3485
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3686
+	if (!empty($context['canonical_url'])) {
3687
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3688
+	}
3486 3689
 
3487
-	if (!empty($settings['og_image']))
3488
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3690
+	if (!empty($settings['og_image'])) {
3691
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3692
+	}
3489 3693
 
3490 3694
 	if (!empty($context['meta_description']))
3491 3695
 	{
3492 3696
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3493 3697
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3494
-	}
3495
-	else
3698
+	} else
3496 3699
 	{
3497 3700
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3498 3701
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3517,8 +3720,9 @@  discard block
 block discarded – undo
3517 3720
 	$memory_needed = memoryReturnBytes($needed);
3518 3721
 
3519 3722
 	// should we account for how much is currently being used?
3520
-	if ($in_use)
3521
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3723
+	if ($in_use) {
3724
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3725
+	}
3522 3726
 
3523 3727
 	// if more is needed, request it
3524 3728
 	if ($memory_current < $memory_needed)
@@ -3541,8 +3745,9 @@  discard block
 block discarded – undo
3541 3745
  */
3542 3746
 function memoryReturnBytes($val)
3543 3747
 {
3544
-	if (is_integer($val))
3545
-		return $val;
3748
+	if (is_integer($val)) {
3749
+			return $val;
3750
+	}
3546 3751
 
3547 3752
 	// Separate the number from the designator
3548 3753
 	$val = trim($val);
@@ -3578,10 +3783,11 @@  discard block
 block discarded – undo
3578 3783
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3579 3784
 
3580 3785
 		// Are we debugging the template/html content?
3581
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3582
-			header('content-type: application/xhtml+xml');
3583
-		elseif (!isset($_REQUEST['xml']))
3584
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3786
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3787
+					header('content-type: application/xhtml+xml');
3788
+		} elseif (!isset($_REQUEST['xml'])) {
3789
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3790
+		}
3585 3791
 	}
3586 3792
 
3587 3793
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3590,8 +3796,9 @@  discard block
 block discarded – undo
3590 3796
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3591 3797
 	{
3592 3798
 		$position = array_search('body', $context['template_layers']);
3593
-		if ($position === false)
3594
-			$position = array_search('main', $context['template_layers']);
3799
+		if ($position === false) {
3800
+					$position = array_search('main', $context['template_layers']);
3801
+		}
3595 3802
 
3596 3803
 		if ($position !== false)
3597 3804
 		{
@@ -3619,23 +3826,25 @@  discard block
 block discarded – undo
3619 3826
 
3620 3827
 			foreach ($securityFiles as $i => $securityFile)
3621 3828
 			{
3622
-				if (!file_exists($boarddir . '/' . $securityFile))
3623
-					unset($securityFiles[$i]);
3829
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3830
+									unset($securityFiles[$i]);
3831
+				}
3624 3832
 			}
3625 3833
 
3626 3834
 			// We are already checking so many files...just few more doesn't make any difference! :P
3627
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3628
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3629
-
3630
-			else
3631
-				$path = $modSettings['attachmentUploadDir'];
3835
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3836
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3837
+			} else {
3838
+							$path = $modSettings['attachmentUploadDir'];
3839
+			}
3632 3840
 
3633 3841
 			secureDirectory($path, true);
3634 3842
 			secureDirectory($cachedir);
3635 3843
 
3636 3844
 			// If agreement is enabled, at least the english version shall exists
3637
-			if ($modSettings['requireAgreement'])
3638
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3845
+			if ($modSettings['requireAgreement']) {
3846
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3847
+			}
3639 3848
 
3640 3849
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3641 3850
 			{
@@ -3650,18 +3859,21 @@  discard block
 block discarded – undo
3650 3859
 					echo '
3651 3860
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3652 3861
 
3653
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3654
-						echo '
3862
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3863
+											echo '
3655 3864
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3865
+					}
3656 3866
 				}
3657 3867
 
3658
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3659
-					echo '
3868
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3869
+									echo '
3660 3870
 				<strong>', $txt['cache_writable'], '</strong><br>';
3871
+				}
3661 3872
 
3662
-				if (!empty($agreement))
3663
-					echo '
3873
+				if (!empty($agreement)) {
3874
+									echo '
3664 3875
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3876
+				}
3665 3877
 
3666 3878
 				echo '
3667 3879
 			</p>
@@ -3676,16 +3888,18 @@  discard block
 block discarded – undo
3676 3888
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3677 3889
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3678 3890
 
3679
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3680
-				echo '
3891
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3892
+							echo '
3681 3893
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3894
+			}
3682 3895
 
3683
-			if (!empty($_SESSION['ban']['expire_time']))
3684
-				echo '
3896
+			if (!empty($_SESSION['ban']['expire_time'])) {
3897
+							echo '
3685 3898
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3686
-			else
3687
-				echo '
3899
+			} else {
3900
+							echo '
3688 3901
 					<div>', $txt['your_ban_expires_never'], '</div>';
3902
+			}
3689 3903
 
3690 3904
 			echo '
3691 3905
 				</div>';
@@ -3701,8 +3915,9 @@  discard block
 block discarded – undo
3701 3915
 	global $forum_copyright, $software_year, $forum_version;
3702 3916
 
3703 3917
 	// Don't display copyright for things like SSI.
3704
-	if (!isset($forum_version) || !isset($software_year))
3705
-		return;
3918
+	if (!isset($forum_version) || !isset($software_year)) {
3919
+			return;
3920
+	}
3706 3921
 
3707 3922
 	// Put in the version...
3708 3923
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3720,9 +3935,10 @@  discard block
 block discarded – undo
3720 3935
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3721 3936
 	$context['load_queries'] = $db_count;
3722 3937
 
3723
-	foreach (array_reverse($context['template_layers']) as $layer)
3724
-		loadSubTemplate($layer . '_below', true);
3725
-}
3938
+	foreach (array_reverse($context['template_layers']) as $layer) {
3939
+			loadSubTemplate($layer . '_below', true);
3940
+	}
3941
+	}
3726 3942
 
3727 3943
 /**
3728 3944
  * Output the Javascript files
@@ -3756,8 +3972,7 @@  discard block
 block discarded – undo
3756 3972
 			{
3757 3973
 				echo '
3758 3974
 		var ', $key, ';';
3759
-			}
3760
-			else
3975
+			} else
3761 3976
 			{
3762 3977
 				echo '
3763 3978
 		var ', $key, ' = ', $value, ';';
@@ -3776,27 +3991,29 @@  discard block
 block discarded – undo
3776 3991
 		foreach ($context['javascript_files'] as $id => $js_file)
3777 3992
 		{
3778 3993
 			// Last minute call! allow theme authors to disable single files.
3779
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3780
-				continue;
3994
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3995
+							continue;
3996
+			}
3781 3997
 
3782 3998
 			// By default files don't get minimized unless the file explicitly says so!
3783 3999
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3784 4000
 			{
3785
-				if (!empty($js_file['options']['async']))
3786
-					$toMinify['async'][] = $js_file;
3787
-				elseif (!empty($js_file['options']['defer']))
3788
-					$toMinify['defer'][] = $js_file;
3789
-				else
3790
-					$toMinify['standard'][] = $js_file;
4001
+				if (!empty($js_file['options']['async'])) {
4002
+									$toMinify['async'][] = $js_file;
4003
+				} elseif (!empty($js_file['options']['defer'])) {
4004
+									$toMinify['defer'][] = $js_file;
4005
+				} else {
4006
+									$toMinify['standard'][] = $js_file;
4007
+				}
3791 4008
 
3792 4009
 				// Grab a random seed.
3793
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3794
-					$minSeed = $js_file['options']['seed'];
3795
-			}
3796
-
3797
-			else
3798
-				echo '
4010
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
4011
+									$minSeed = $js_file['options']['seed'];
4012
+				}
4013
+			} else {
4014
+							echo '
3799 4015
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
4016
+			}
3800 4017
 		}
3801 4018
 
3802 4019
 		foreach ($toMinify as $js_files)
@@ -3807,9 +4024,10 @@  discard block
 block discarded – undo
3807 4024
 
3808 4025
 				$minSuccessful = array_keys($result) === array('smf_minified');
3809 4026
 
3810
-				foreach ($result as $minFile)
3811
-					echo '
4027
+				foreach ($result as $minFile) {
4028
+									echo '
3812 4029
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
4030
+				}
3813 4031
 			}
3814 4032
 		}
3815 4033
 	}
@@ -3823,8 +4041,9 @@  discard block
 block discarded – undo
3823 4041
 <script>
3824 4042
 window.addEventListener("DOMContentLoaded", function() {';
3825 4043
 
3826
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3827
-				echo $js_code;
4044
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
4045
+							echo $js_code;
4046
+			}
3828 4047
 
3829 4048
 			echo '
3830 4049
 });
@@ -3836,8 +4055,9 @@  discard block
 block discarded – undo
3836 4055
 			echo '
3837 4056
 	<script>';
3838 4057
 
3839
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3840
-				echo $js_code;
4058
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
4059
+							echo $js_code;
4060
+			}
3841 4061
 
3842 4062
 			echo '
3843 4063
 	</script>';
@@ -3865,23 +4085,26 @@  discard block
 block discarded – undo
3865 4085
 	foreach ($context['css_files'] as $id => $file)
3866 4086
 	{
3867 4087
 		// Last minute call! allow theme authors to disable single files.
3868
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3869
-			continue;
4088
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
4089
+					continue;
4090
+		}
3870 4091
 
3871 4092
 		// Files are minimized unless they explicitly opt out.
3872
-		if (!isset($file['options']['minimize']))
3873
-			$file['options']['minimize'] = true;
4093
+		if (!isset($file['options']['minimize'])) {
4094
+					$file['options']['minimize'] = true;
4095
+		}
3874 4096
 
3875 4097
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3876 4098
 		{
3877 4099
 			$toMinify[] = $file;
3878 4100
 
3879 4101
 			// Grab a random seed.
3880
-			if (!isset($minSeed) && isset($file['options']['seed']))
3881
-				$minSeed = $file['options']['seed'];
4102
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
4103
+							$minSeed = $file['options']['seed'];
4104
+			}
4105
+		} else {
4106
+					$normal[] = $file['fileUrl'];
3882 4107
 		}
3883
-		else
3884
-			$normal[] = $file['fileUrl'];
3885 4108
 	}
3886 4109
 
3887 4110
 	if (!empty($toMinify))
@@ -3890,23 +4113,26 @@  discard block
 block discarded – undo
3890 4113
 
3891 4114
 		$minSuccessful = array_keys($result) === array('smf_minified');
3892 4115
 
3893
-		foreach ($result as $minFile)
3894
-			echo '
4116
+		foreach ($result as $minFile) {
4117
+					echo '
3895 4118
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
4119
+		}
3896 4120
 	}
3897 4121
 
3898 4122
 	// Print the rest after the minified files.
3899
-	if (!empty($normal))
3900
-		foreach ($normal as $nf)
4123
+	if (!empty($normal)) {
4124
+			foreach ($normal as $nf)
3901 4125
 			echo '
3902 4126
 	<link rel="stylesheet" href="', $nf ,'">';
4127
+	}
3903 4128
 
3904 4129
 	if ($db_show_debug === true)
3905 4130
 	{
3906 4131
 		// Try to keep only what's useful.
3907 4132
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3908
-		foreach ($context['css_files'] as $file)
3909
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4133
+		foreach ($context['css_files'] as $file) {
4134
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4135
+		}
3910 4136
 	}
3911 4137
 
3912 4138
 	if (!empty($context['css_header']))
@@ -3914,9 +4140,10 @@  discard block
 block discarded – undo
3914 4140
 		echo '
3915 4141
 	<style>';
3916 4142
 
3917
-		foreach ($context['css_header'] as $css)
3918
-			echo $css .'
4143
+		foreach ($context['css_header'] as $css) {
4144
+					echo $css .'
3919 4145
 	';
4146
+		}
3920 4147
 
3921 4148
 		echo'
3922 4149
 	</style>';
@@ -3939,8 +4166,9 @@  discard block
 block discarded – undo
3939 4166
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3940 4167
 	$data = is_array($data) ? $data : array();
3941 4168
 
3942
-	if (empty($type) || empty($data))
3943
-		return $data;
4169
+	if (empty($type) || empty($data)) {
4170
+			return $data;
4171
+	}
3944 4172
 
3945 4173
 	// Different pages include different files, so we use a hash to label the different combinations
3946 4174
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3949,13 +4177,14 @@  discard block
 block discarded – undo
3949 4177
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3950 4178
 
3951 4179
 	// Already done?
3952
-	if (!empty($toCache))
3953
-		return array('smf_minified' => array(
4180
+	if (!empty($toCache)) {
4181
+			return array('smf_minified' => array(
3954 4182
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3955 4183
 			'filePath' => $toCache,
3956 4184
 			'fileName' => basename($toCache),
3957 4185
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3958 4186
 		));
4187
+	}
3959 4188
 
3960 4189
 
3961 4190
 	// No namespaces, sorry!
@@ -3985,9 +4214,9 @@  discard block
 block discarded – undo
3985 4214
 
3986 4215
 	foreach ($data as $id => $file)
3987 4216
 	{
3988
-		if (empty($file['filePath']))
3989
-			$toAdd = false;
3990
-		else
4217
+		if (empty($file['filePath'])) {
4218
+					$toAdd = false;
4219
+		} else
3991 4220
 		{
3992 4221
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3993 4222
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3995,12 +4224,14 @@  discard block
 block discarded – undo
3995 4224
 		}
3996 4225
 
3997 4226
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3998
-		if (empty($file['options']['async']))
3999
-			$async = false;
4227
+		if (empty($file['options']['async'])) {
4228
+					$async = false;
4229
+		}
4000 4230
 
4001 4231
 		// A minified script should only be deferred if all its components wanted to be.
4002
-		if (empty($file['options']['defer']))
4003
-			$defer = false;
4232
+		if (empty($file['options']['defer'])) {
4233
+					$defer = false;
4234
+		}
4004 4235
 
4005 4236
 		// The file couldn't be located so it won't be added. Log this error.
4006 4237
 		if (empty($toAdd))
@@ -4066,12 +4297,14 @@  discard block
 block discarded – undo
4066 4297
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
4067 4298
 			{
4068 4299
 				// Remove the cache entry
4069
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
4070
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4300
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4301
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4302
+				}
4071 4303
 
4072 4304
 				// Try to delete the file. Add it to our error list if it fails.
4073
-				if (!@unlink($filename))
4074
-					$not_deleted[] = $filename;
4305
+				if (!@unlink($filename)) {
4306
+									$not_deleted[] = $filename;
4307
+				}
4075 4308
 			}
4076 4309
 		}
4077 4310
 	}
@@ -4103,8 +4336,9 @@  discard block
 block discarded – undo
4103 4336
 	global $modSettings, $smcFunc;
4104 4337
 
4105 4338
 	// Just make up a nice hash...
4106
-	if ($new)
4107
-		return sha1(md5($filename . time()) . mt_rand());
4339
+	if ($new) {
4340
+			return sha1(md5($filename . time()) . mt_rand());
4341
+	}
4108 4342
 
4109 4343
 	// Just make sure that attachment id is only a int
4110 4344
 	$attachment_id = (int) $attachment_id;
@@ -4121,23 +4355,25 @@  discard block
 block discarded – undo
4121 4355
 				'id_attach' => $attachment_id,
4122 4356
 			));
4123 4357
 
4124
-		if ($smcFunc['db_num_rows']($request) === 0)
4125
-			return false;
4358
+		if ($smcFunc['db_num_rows']($request) === 0) {
4359
+					return false;
4360
+		}
4126 4361
 
4127 4362
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
4128 4363
 		$smcFunc['db_free_result']($request);
4129 4364
 	}
4130 4365
 
4131 4366
 	// Still no hash? mmm...
4132
-	if (empty($file_hash))
4133
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4367
+	if (empty($file_hash)) {
4368
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4369
+	}
4134 4370
 
4135 4371
 	// Are we using multiple directories?
4136
-	if (is_array($modSettings['attachmentUploadDir']))
4137
-		$path = $modSettings['attachmentUploadDir'][$dir];
4138
-
4139
-	else
4140
-		$path = $modSettings['attachmentUploadDir'];
4372
+	if (is_array($modSettings['attachmentUploadDir'])) {
4373
+			$path = $modSettings['attachmentUploadDir'][$dir];
4374
+	} else {
4375
+			$path = $modSettings['attachmentUploadDir'];
4376
+	}
4141 4377
 
4142 4378
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4143 4379
 }
@@ -4152,8 +4388,9 @@  discard block
 block discarded – undo
4152 4388
 function ip2range($fullip)
4153 4389
 {
4154 4390
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
4155
-	if ($fullip == 'unknown')
4156
-		$fullip = '255.255.255.255';
4391
+	if ($fullip == 'unknown') {
4392
+			$fullip = '255.255.255.255';
4393
+	}
4157 4394
 
4158 4395
 	$ip_parts = explode('-', $fullip);
4159 4396
 	$ip_array = array();
@@ -4177,10 +4414,11 @@  discard block
 block discarded – undo
4177 4414
 		$ip_array['low'] = $ip_parts[0];
4178 4415
 		$ip_array['high'] = $ip_parts[1];
4179 4416
 		return $ip_array;
4180
-	}
4181
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4417
+	} elseif (count($ip_parts) == 2) {
4418
+		// if ip 22.22.*-22.22.*
4182 4419
 	{
4183 4420
 		$valid_low = isValidIP($ip_parts[0]);
4421
+	}
4184 4422
 		$valid_high = isValidIP($ip_parts[1]);
4185 4423
 		$count = 0;
4186 4424
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4195,7 +4433,9 @@  discard block
 block discarded – undo
4195 4433
 				$ip_parts[0] .= $mode . $min;
4196 4434
 				$valid_low = isValidIP($ip_parts[0]);
4197 4435
 				$count++;
4198
-				if ($count > 9) break;
4436
+				if ($count > 9) {
4437
+					break;
4438
+				}
4199 4439
 			}
4200 4440
 		}
4201 4441
 
@@ -4209,7 +4449,9 @@  discard block
 block discarded – undo
4209 4449
 				$ip_parts[1] .= $mode . $max;
4210 4450
 				$valid_high = isValidIP($ip_parts[1]);
4211 4451
 				$count++;
4212
-				if ($count > 9) break;
4452
+				if ($count > 9) {
4453
+					break;
4454
+				}
4213 4455
 			}
4214 4456
 		}
4215 4457
 
@@ -4233,46 +4475,54 @@  discard block
 block discarded – undo
4233 4475
 {
4234 4476
 	global $modSettings;
4235 4477
 
4236
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4237
-		return $host;
4478
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4479
+			return $host;
4480
+	}
4238 4481
 	$t = microtime();
4239 4482
 
4240 4483
 	// Try the Linux host command, perhaps?
4241 4484
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4242 4485
 	{
4243
-		if (!isset($modSettings['host_to_dis']))
4244
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4245
-		else
4246
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4486
+		if (!isset($modSettings['host_to_dis'])) {
4487
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4488
+		} else {
4489
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4490
+		}
4247 4491
 
4248 4492
 		// Did host say it didn't find anything?
4249
-		if (strpos($test, 'not found') !== false)
4250
-			$host = '';
4493
+		if (strpos($test, 'not found') !== false) {
4494
+					$host = '';
4495
+		}
4251 4496
 		// Invalid server option?
4252
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4253
-			updateSettings(array('host_to_dis' => 1));
4497
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4498
+					updateSettings(array('host_to_dis' => 1));
4499
+		}
4254 4500
 		// Maybe it found something, after all?
4255
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4256
-			$host = $match[1];
4501
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4502
+					$host = $match[1];
4503
+		}
4257 4504
 	}
4258 4505
 
4259 4506
 	// This is nslookup; usually only Windows, but possibly some Unix?
4260 4507
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4261 4508
 	{
4262 4509
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4263
-		if (strpos($test, 'Non-existent domain') !== false)
4264
-			$host = '';
4265
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4266
-			$host = $match[1];
4510
+		if (strpos($test, 'Non-existent domain') !== false) {
4511
+					$host = '';
4512
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4513
+					$host = $match[1];
4514
+		}
4267 4515
 	}
4268 4516
 
4269 4517
 	// This is the last try :/.
4270
-	if (!isset($host) || $host === false)
4271
-		$host = @gethostbyaddr($ip);
4518
+	if (!isset($host) || $host === false) {
4519
+			$host = @gethostbyaddr($ip);
4520
+	}
4272 4521
 
4273 4522
 	// It took a long time, so let's cache it!
4274
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4275
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4523
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4524
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4525
+	}
4276 4526
 
4277 4527
 	return $host;
4278 4528
 }
@@ -4308,20 +4558,21 @@  discard block
 block discarded – undo
4308 4558
 			{
4309 4559
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4310 4560
 				$total = 0;
4311
-				for ($i = 0; $i < $max_chars; $i++)
4312
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4561
+				for ($i = 0; $i < $max_chars; $i++) {
4562
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4563
+				}
4313 4564
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4314 4565
 			}
4315 4566
 		}
4316 4567
 		return array_unique($returned_ints);
4317
-	}
4318
-	else
4568
+	} else
4319 4569
 	{
4320 4570
 		// Trim characters before and after and add slashes for database insertion.
4321 4571
 		$returned_words = array();
4322
-		foreach ($words as $word)
4323
-			if (($word = trim($word, '-_\'')) !== '')
4572
+		foreach ($words as $word) {
4573
+					if (($word = trim($word, '-_\'')) !== '')
4324 4574
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4575
+		}
4325 4576
 
4326 4577
 		// Filter out all words that occur more than once.
4327 4578
 		return array_unique($returned_words);
@@ -4343,16 +4594,18 @@  discard block
 block discarded – undo
4343 4594
 	global $settings, $txt;
4344 4595
 
4345 4596
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4346
-	if (function_exists('template_create_button') && !$force_use)
4347
-		return template_create_button($name, $alt, $label = '', $custom = '');
4597
+	if (function_exists('template_create_button') && !$force_use) {
4598
+			return template_create_button($name, $alt, $label = '', $custom = '');
4599
+	}
4348 4600
 
4349
-	if (!$settings['use_image_buttons'])
4350
-		return $txt[$alt];
4351
-	elseif (!empty($settings['use_buttons']))
4352
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4353
-	else
4354
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4355
-}
4601
+	if (!$settings['use_image_buttons']) {
4602
+			return $txt[$alt];
4603
+	} elseif (!empty($settings['use_buttons'])) {
4604
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4605
+	} else {
4606
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4607
+	}
4608
+	}
4356 4609
 
4357 4610
 /**
4358 4611
  * Sets up all of the top menu buttons
@@ -4395,9 +4648,10 @@  discard block
 block discarded – undo
4395 4648
 	var user_menus = new smc_PopupMenu();
4396 4649
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4397 4650
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4398
-		if ($context['allow_pm'])
4399
-			addInlineJavaScript('
4651
+		if ($context['allow_pm']) {
4652
+					addInlineJavaScript('
4400 4653
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4654
+		}
4401 4655
 
4402 4656
 		if (!empty($modSettings['enable_ajax_alerts']))
4403 4657
 		{
@@ -4557,88 +4811,96 @@  discard block
 block discarded – undo
4557 4811
 
4558 4812
 		// Now we put the buttons in the context so the theme can use them.
4559 4813
 		$menu_buttons = array();
4560
-		foreach ($buttons as $act => $button)
4561
-			if (!empty($button['show']))
4814
+		foreach ($buttons as $act => $button) {
4815
+					if (!empty($button['show']))
4562 4816
 			{
4563 4817
 				$button['active_button'] = false;
4818
+		}
4564 4819
 
4565 4820
 				// This button needs some action.
4566
-				if (isset($button['action_hook']))
4567
-					$needs_action_hook = true;
4821
+				if (isset($button['action_hook'])) {
4822
+									$needs_action_hook = true;
4823
+				}
4568 4824
 
4569 4825
 				// Make sure the last button truly is the last button.
4570 4826
 				if (!empty($button['is_last']))
4571 4827
 				{
4572
-					if (isset($last_button))
4573
-						unset($menu_buttons[$last_button]['is_last']);
4828
+					if (isset($last_button)) {
4829
+											unset($menu_buttons[$last_button]['is_last']);
4830
+					}
4574 4831
 					$last_button = $act;
4575 4832
 				}
4576 4833
 
4577 4834
 				// Go through the sub buttons if there are any.
4578
-				if (!empty($button['sub_buttons']))
4579
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4835
+				if (!empty($button['sub_buttons'])) {
4836
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4580 4837
 					{
4581 4838
 						if (empty($subbutton['show']))
4582 4839
 							unset($button['sub_buttons'][$key]);
4840
+				}
4583 4841
 
4584 4842
 						// 2nd level sub buttons next...
4585 4843
 						if (!empty($subbutton['sub_buttons']))
4586 4844
 						{
4587 4845
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4588 4846
 							{
4589
-								if (empty($sub_button2['show']))
4590
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4847
+								if (empty($sub_button2['show'])) {
4848
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4849
+								}
4591 4850
 							}
4592 4851
 						}
4593 4852
 					}
4594 4853
 
4595 4854
 				// Does this button have its own icon?
4596
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4597
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4598
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4599
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4600
-				elseif (isset($button['icon']))
4601
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4602
-				else
4603
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4855
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4856
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4857
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4858
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4859
+				} elseif (isset($button['icon'])) {
4860
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4861
+				} else {
4862
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4863
+				}
4604 4864
 
4605 4865
 				$menu_buttons[$act] = $button;
4606 4866
 			}
4607 4867
 
4608
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4609
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4868
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4869
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4870
+		}
4610 4871
 	}
4611 4872
 
4612 4873
 	$context['menu_buttons'] = $menu_buttons;
4613 4874
 
4614 4875
 	// Logging out requires the session id in the url.
4615
-	if (isset($context['menu_buttons']['logout']))
4616
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4876
+	if (isset($context['menu_buttons']['logout'])) {
4877
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4878
+	}
4617 4879
 
4618 4880
 	// Figure out which action we are doing so we can set the active tab.
4619 4881
 	// Default to home.
4620 4882
 	$current_action = 'home';
4621 4883
 
4622
-	if (isset($context['menu_buttons'][$context['current_action']]))
4623
-		$current_action = $context['current_action'];
4624
-	elseif ($context['current_action'] == 'search2')
4625
-		$current_action = 'search';
4626
-	elseif ($context['current_action'] == 'theme')
4627
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4628
-	elseif ($context['current_action'] == 'register2')
4629
-		$current_action = 'register';
4630
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4631
-		$current_action = 'login';
4632
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4633
-		$current_action = 'moderate';
4884
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4885
+			$current_action = $context['current_action'];
4886
+	} elseif ($context['current_action'] == 'search2') {
4887
+			$current_action = 'search';
4888
+	} elseif ($context['current_action'] == 'theme') {
4889
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4890
+	} elseif ($context['current_action'] == 'register2') {
4891
+			$current_action = 'register';
4892
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4893
+			$current_action = 'login';
4894
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4895
+			$current_action = 'moderate';
4896
+	}
4634 4897
 
4635 4898
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4636 4899
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4637 4900
 	{
4638 4901
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4639 4902
 		$context[$current_action] = true;
4640
-	}
4641
-	elseif ($context['current_action'] == 'pm')
4903
+	} elseif ($context['current_action'] == 'pm')
4642 4904
 	{
4643 4905
 		$current_action = 'self_pm';
4644 4906
 		$context['self_pm'] = true;
@@ -4695,12 +4957,14 @@  discard block
 block discarded – undo
4695 4957
 	}
4696 4958
 
4697 4959
 	// Not all actions are simple.
4698
-	if (!empty($needs_action_hook))
4699
-		call_integration_hook('integrate_current_action', array(&$current_action));
4960
+	if (!empty($needs_action_hook)) {
4961
+			call_integration_hook('integrate_current_action', array(&$current_action));
4962
+	}
4700 4963
 
4701
-	if (isset($context['menu_buttons'][$current_action]))
4702
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4703
-}
4964
+	if (isset($context['menu_buttons'][$current_action])) {
4965
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4966
+	}
4967
+	}
4704 4968
 
4705 4969
 /**
4706 4970
  * Generate a random seed and ensure it's stored in settings.
@@ -4724,30 +4988,35 @@  discard block
 block discarded – undo
4724 4988
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4725 4989
 	global $context, $txt;
4726 4990
 
4727
-	if ($db_show_debug === true)
4728
-		$context['debug']['hooks'][] = $hook;
4991
+	if ($db_show_debug === true) {
4992
+			$context['debug']['hooks'][] = $hook;
4993
+	}
4729 4994
 
4730 4995
 	// Need to have some control.
4731
-	if (!isset($context['instances']))
4732
-		$context['instances'] = array();
4996
+	if (!isset($context['instances'])) {
4997
+			$context['instances'] = array();
4998
+	}
4733 4999
 
4734 5000
 	$results = array();
4735
-	if (empty($modSettings[$hook]))
4736
-		return $results;
5001
+	if (empty($modSettings[$hook])) {
5002
+			return $results;
5003
+	}
4737 5004
 
4738 5005
 	$functions = explode(',', $modSettings[$hook]);
4739 5006
 	// Loop through each function.
4740 5007
 	foreach ($functions as $function)
4741 5008
 	{
4742 5009
 		// Hook has been marked as "disabled". Skip it!
4743
-		if (strpos($function, '!') !== false)
4744
-			continue;
5010
+		if (strpos($function, '!') !== false) {
5011
+					continue;
5012
+		}
4745 5013
 
4746 5014
 		$call = call_helper($function, true);
4747 5015
 
4748 5016
 		// Is it valid?
4749
-		if (!empty($call))
4750
-			$results[$function] = call_user_func_array($call, $parameters);
5017
+		if (!empty($call)) {
5018
+					$results[$function] = call_user_func_array($call, $parameters);
5019
+		}
4751 5020
 
4752 5021
 		// Whatever it was suppose to call, it failed :(
4753 5022
 		elseif (!empty($function))
@@ -4763,8 +5032,9 @@  discard block
 block discarded – undo
4763 5032
 			}
4764 5033
 
4765 5034
 			// "Assume" the file resides on $boarddir somewhere...
4766
-			else
4767
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5035
+			else {
5036
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5037
+			}
4768 5038
 		}
4769 5039
 	}
4770 5040
 
@@ -4786,12 +5056,14 @@  discard block
 block discarded – undo
4786 5056
 	global $smcFunc, $modSettings;
4787 5057
 
4788 5058
 	// Any objects?
4789
-	if ($object)
4790
-		$function = $function . '#';
5059
+	if ($object) {
5060
+			$function = $function . '#';
5061
+	}
4791 5062
 
4792 5063
 	// Any files  to load?
4793
-	if (!empty($file) && is_string($file))
4794
-		$function = $file . (!empty($function) ? '|' . $function : '');
5064
+	if (!empty($file) && is_string($file)) {
5065
+			$function = $file . (!empty($function) ? '|' . $function : '');
5066
+	}
4795 5067
 
4796 5068
 	// Get the correct string.
4797 5069
 	$integration_call = $function;
@@ -4813,13 +5085,14 @@  discard block
 block discarded – undo
4813 5085
 		if (!empty($current_functions))
4814 5086
 		{
4815 5087
 			$current_functions = explode(',', $current_functions);
4816
-			if (in_array($integration_call, $current_functions))
4817
-				return;
5088
+			if (in_array($integration_call, $current_functions)) {
5089
+							return;
5090
+			}
4818 5091
 
4819 5092
 			$permanent_functions = array_merge($current_functions, array($integration_call));
5093
+		} else {
5094
+					$permanent_functions = array($integration_call);
4820 5095
 		}
4821
-		else
4822
-			$permanent_functions = array($integration_call);
4823 5096
 
4824 5097
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4825 5098
 	}
@@ -4828,8 +5101,9 @@  discard block
 block discarded – undo
4828 5101
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4829 5102
 
4830 5103
 	// Do nothing, if it's already there.
4831
-	if (in_array($integration_call, $functions))
4832
-		return;
5104
+	if (in_array($integration_call, $functions)) {
5105
+			return;
5106
+	}
4833 5107
 
4834 5108
 	$functions[] = $integration_call;
4835 5109
 	$modSettings[$hook] = implode(',', $functions);
@@ -4852,12 +5126,14 @@  discard block
 block discarded – undo
4852 5126
 	global $smcFunc, $modSettings;
4853 5127
 
4854 5128
 	// Any objects?
4855
-	if ($object)
4856
-		$function = $function . '#';
5129
+	if ($object) {
5130
+			$function = $function . '#';
5131
+	}
4857 5132
 
4858 5133
 	// Any files  to load?
4859
-	if (!empty($file) && is_string($file))
4860
-		$function = $file . '|' . $function;
5134
+	if (!empty($file) && is_string($file)) {
5135
+			$function = $file . '|' . $function;
5136
+	}
4861 5137
 
4862 5138
 	// Get the correct string.
4863 5139
 	$integration_call = $function;
@@ -4878,16 +5154,18 @@  discard block
 block discarded – undo
4878 5154
 	{
4879 5155
 		$current_functions = explode(',', $current_functions);
4880 5156
 
4881
-		if (in_array($integration_call, $current_functions))
4882
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5157
+		if (in_array($integration_call, $current_functions)) {
5158
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5159
+		}
4883 5160
 	}
4884 5161
 
4885 5162
 	// Turn the function list into something usable.
4886 5163
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4887 5164
 
4888 5165
 	// You can only remove it if it's available.
4889
-	if (!in_array($integration_call, $functions))
4890
-		return;
5166
+	if (!in_array($integration_call, $functions)) {
5167
+			return;
5168
+	}
4891 5169
 
4892 5170
 	$functions = array_diff($functions, array($integration_call));
4893 5171
 	$modSettings[$hook] = implode(',', $functions);
@@ -4908,17 +5186,20 @@  discard block
 block discarded – undo
4908 5186
 	global $context, $smcFunc, $txt, $db_show_debug;
4909 5187
 
4910 5188
 	// Really?
4911
-	if (empty($string))
4912
-		return false;
5189
+	if (empty($string)) {
5190
+			return false;
5191
+	}
4913 5192
 
4914 5193
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4915 5194
 	// A closure? should be a callable one.
4916
-	if (is_array($string) || $string instanceof Closure)
4917
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5195
+	if (is_array($string) || $string instanceof Closure) {
5196
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5197
+	}
4918 5198
 
4919 5199
 	// No full objects, sorry! pass a method or a property instead!
4920
-	if (is_object($string))
4921
-		return false;
5200
+	if (is_object($string)) {
5201
+			return false;
5202
+	}
4922 5203
 
4923 5204
 	// Stay vitaminized my friends...
4924 5205
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4927,8 +5208,9 @@  discard block
 block discarded – undo
4927 5208
 	$string = load_file($string);
4928 5209
 
4929 5210
 	// Loaded file failed
4930
-	if (empty($string))
4931
-		return false;
5211
+	if (empty($string)) {
5212
+			return false;
5213
+	}
4932 5214
 
4933 5215
 	// Found a method.
4934 5216
 	if (strpos($string, '::') !== false)
@@ -4949,8 +5231,9 @@  discard block
 block discarded – undo
4949 5231
 				// Add another one to the list.
4950 5232
 				if ($db_show_debug === true)
4951 5233
 				{
4952
-					if (!isset($context['debug']['instances']))
4953
-						$context['debug']['instances'] = array();
5234
+					if (!isset($context['debug']['instances'])) {
5235
+											$context['debug']['instances'] = array();
5236
+					}
4954 5237
 
4955 5238
 					$context['debug']['instances'][$class] = $class;
4956 5239
 				}
@@ -4960,13 +5243,15 @@  discard block
 block discarded – undo
4960 5243
 		}
4961 5244
 
4962 5245
 		// Right then. This is a call to a static method.
4963
-		else
4964
-			$func = array($class, $method);
5246
+		else {
5247
+					$func = array($class, $method);
5248
+		}
4965 5249
 	}
4966 5250
 
4967 5251
 	// Nope! just a plain regular function.
4968
-	else
4969
-		$func = $string;
5252
+	else {
5253
+			$func = $string;
5254
+	}
4970 5255
 
4971 5256
 	// Right, we got what we need, time to do some checks.
4972 5257
 	if (!is_callable($func, false, $callable_name))
@@ -4982,17 +5267,18 @@  discard block
 block discarded – undo
4982 5267
 	else
4983 5268
 	{
4984 5269
 		// What are we gonna do about it?
4985
-		if ($return)
4986
-			return $func;
5270
+		if ($return) {
5271
+					return $func;
5272
+		}
4987 5273
 
4988 5274
 		// If this is a plain function, avoid the heat of calling call_user_func().
4989 5275
 		else
4990 5276
 		{
4991
-			if (is_array($func))
4992
-				call_user_func($func);
4993
-
4994
-			else
4995
-				$func();
5277
+			if (is_array($func)) {
5278
+							call_user_func($func);
5279
+			} else {
5280
+							$func();
5281
+			}
4996 5282
 		}
4997 5283
 	}
4998 5284
 }
@@ -5009,31 +5295,34 @@  discard block
 block discarded – undo
5009 5295
 {
5010 5296
 	global $sourcedir, $txt, $boarddir, $settings;
5011 5297
 
5012
-	if (empty($string))
5013
-		return false;
5298
+	if (empty($string)) {
5299
+			return false;
5300
+	}
5014 5301
 
5015 5302
 	if (strpos($string, '|') !== false)
5016 5303
 	{
5017 5304
 		list ($file, $string) = explode('|', $string);
5018 5305
 
5019 5306
 		// Match the wildcards to their regular vars.
5020
-		if (empty($settings['theme_dir']))
5021
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5022
-
5023
-		else
5024
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5307
+		if (empty($settings['theme_dir'])) {
5308
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5309
+		} else {
5310
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5311
+		}
5025 5312
 
5026 5313
 		// Load the file if it can be loaded.
5027
-		if (file_exists($absPath))
5028
-			require_once($absPath);
5314
+		if (file_exists($absPath)) {
5315
+					require_once($absPath);
5316
+		}
5029 5317
 
5030 5318
 		// No? try a fallback to $sourcedir
5031 5319
 		else
5032 5320
 		{
5033 5321
 			$absPath = $sourcedir .'/'. $file;
5034 5322
 
5035
-			if (file_exists($absPath))
5036
-				require_once($absPath);
5323
+			if (file_exists($absPath)) {
5324
+							require_once($absPath);
5325
+			}
5037 5326
 
5038 5327
 			// Sorry, can't do much for you at this point.
5039 5328
 			else
@@ -5072,8 +5361,9 @@  discard block
 block discarded – undo
5072 5361
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
5073 5362
 
5074 5363
 	// No scheme? No data for you!
5075
-	if (empty($match[1]))
5076
-		return false;
5364
+	if (empty($match[1])) {
5365
+			return false;
5366
+	}
5077 5367
 
5078 5368
 	// An FTP url. We should try connecting and RETRieving it...
5079 5369
 	elseif ($match[1] == 'ftp')
@@ -5083,23 +5373,26 @@  discard block
 block discarded – undo
5083 5373
 
5084 5374
 		// Establish a connection and attempt to enable passive mode.
5085 5375
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
5086
-		if ($ftp->error !== false || !$ftp->passive())
5087
-			return false;
5376
+		if ($ftp->error !== false || !$ftp->passive()) {
5377
+					return false;
5378
+		}
5088 5379
 
5089 5380
 		// I want that one *points*!
5090 5381
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
5091 5382
 
5092 5383
 		// Since passive mode worked (or we would have returned already!) open the connection.
5093 5384
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
5094
-		if (!$fp)
5095
-			return false;
5385
+		if (!$fp) {
5386
+					return false;
5387
+		}
5096 5388
 
5097 5389
 		// The server should now say something in acknowledgement.
5098 5390
 		$ftp->check_response(150);
5099 5391
 
5100 5392
 		$data = '';
5101
-		while (!feof($fp))
5102
-			$data .= fread($fp, 4096);
5393
+		while (!feof($fp)) {
5394
+					$data .= fread($fp, 4096);
5395
+		}
5103 5396
 		fclose($fp);
5104 5397
 
5105 5398
 		// All done, right?  Good.
@@ -5111,8 +5404,9 @@  discard block
 block discarded – undo
5111 5404
 	elseif (isset($match[1]) && $match[1] == 'http')
5112 5405
 	{
5113 5406
 		// First try to use fsockopen, because it is fastest.
5114
-		if ($keep_alive && $match[3] == $keep_alive_dom)
5115
-			$fp = $keep_alive_fp;
5407
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5408
+					$fp = $keep_alive_fp;
5409
+		}
5116 5410
 		if (empty($fp))
5117 5411
 		{
5118 5412
 			// Open the socket on the port we want...
@@ -5132,20 +5426,21 @@  discard block
 block discarded – undo
5132 5426
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
5133 5427
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5134 5428
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5135
-				if ($keep_alive)
5136
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5137
-				else
5138
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
5139
-			}
5140
-			else
5429
+				if ($keep_alive) {
5430
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5431
+				} else {
5432
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5433
+				}
5434
+			} else
5141 5435
 			{
5142 5436
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
5143 5437
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5144 5438
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5145
-				if ($keep_alive)
5146
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5147
-				else
5148
-					fwrite($fp, 'connection: close' . "\r\n");
5439
+				if ($keep_alive) {
5440
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5441
+				} else {
5442
+									fwrite($fp, 'connection: close' . "\r\n");
5443
+				}
5149 5444
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
5150 5445
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
5151 5446
 				fwrite($fp, $post_data);
@@ -5158,30 +5453,33 @@  discard block
 block discarded – undo
5158 5453
 			{
5159 5454
 				$header = '';
5160 5455
 				$location = '';
5161
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5162
-					if (strpos($header, 'location:') !== false)
5456
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5457
+									if (strpos($header, 'location:') !== false)
5163 5458
 						$location = trim(substr($header, strpos($header, ':') + 1));
5459
+				}
5164 5460
 
5165
-				if (empty($location))
5166
-					return false;
5167
-				else
5461
+				if (empty($location)) {
5462
+									return false;
5463
+				} else
5168 5464
 				{
5169
-					if (!$keep_alive)
5170
-						fclose($fp);
5465
+					if (!$keep_alive) {
5466
+											fclose($fp);
5467
+					}
5171 5468
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
5172 5469
 				}
5173 5470
 			}
5174 5471
 
5175 5472
 			// Make sure we get a 200 OK.
5176
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5177
-				return false;
5473
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5474
+							return false;
5475
+			}
5178 5476
 
5179 5477
 			// Skip the headers...
5180 5478
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5181 5479
 			{
5182
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5183
-					$content_length = $match[1];
5184
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5480
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5481
+									$content_length = $match[1];
5482
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5185 5483
 				{
5186 5484
 					$keep_alive_dom = null;
5187 5485
 					$keep_alive = false;
@@ -5193,17 +5491,19 @@  discard block
 block discarded – undo
5193 5491
 			$data = '';
5194 5492
 			if (isset($content_length))
5195 5493
 			{
5196
-				while (!feof($fp) && strlen($data) < $content_length)
5197
-					$data .= fread($fp, $content_length - strlen($data));
5198
-			}
5199
-			else
5494
+				while (!feof($fp) && strlen($data) < $content_length) {
5495
+									$data .= fread($fp, $content_length - strlen($data));
5496
+				}
5497
+			} else
5200 5498
 			{
5201
-				while (!feof($fp))
5202
-					$data .= fread($fp, 4096);
5499
+				while (!feof($fp)) {
5500
+									$data .= fread($fp, 4096);
5501
+				}
5203 5502
 			}
5204 5503
 
5205
-			if (!$keep_alive)
5206
-				fclose($fp);
5504
+			if (!$keep_alive) {
5505
+							fclose($fp);
5506
+			}
5207 5507
 		}
5208 5508
 
5209 5509
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5216,17 +5516,18 @@  discard block
 block discarded – undo
5216 5516
 			$fetch_data->get_url_data($url, $post_data);
5217 5517
 
5218 5518
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5219
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5220
-				$data = $fetch_data->result('body');
5221
-			else
5222
-				return false;
5519
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5520
+							$data = $fetch_data->result('body');
5521
+			} else {
5522
+							return false;
5523
+			}
5223 5524
 		}
5224 5525
 
5225 5526
 		// Neither fsockopen nor curl are available. Well, phooey.
5226
-		else
5227
-			return false;
5228
-	}
5229
-	else
5527
+		else {
5528
+					return false;
5529
+		}
5530
+	} else
5230 5531
 	{
5231 5532
 		// Umm, this shouldn't happen?
5232 5533
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5246,8 +5547,9 @@  discard block
 block discarded – undo
5246 5547
 	global $user_info, $smcFunc;
5247 5548
 
5248 5549
 	// Make sure we have something to work with.
5249
-	if (empty($topic))
5250
-		return array();
5550
+	if (empty($topic)) {
5551
+			return array();
5552
+	}
5251 5553
 
5252 5554
 
5253 5555
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5270,8 +5572,9 @@  discard block
 block discarded – undo
5270 5572
 				'topic' => $topic,
5271 5573
 			)
5272 5574
 		);
5273
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5274
-			$temp[] = (int) $row['content_id'];
5575
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5576
+					$temp[] = (int) $row['content_id'];
5577
+		}
5275 5578
 
5276 5579
 		cache_put_data($cache_key, $temp, $ttl);
5277 5580
 	}
@@ -5292,8 +5595,9 @@  discard block
 block discarded – undo
5292 5595
 {
5293 5596
 	global $context;
5294 5597
 
5295
-	if (empty($string))
5296
-		return $string;
5598
+	if (empty($string)) {
5599
+			return $string;
5600
+	}
5297 5601
 
5298 5602
 	// UTF-8 occurences of MS special characters
5299 5603
 	$findchars_utf8 = array(
@@ -5334,10 +5638,11 @@  discard block
 block discarded – undo
5334 5638
 		'--',	// &mdash;
5335 5639
 	);
5336 5640
 
5337
-	if ($context['utf8'])
5338
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5339
-	else
5340
-		$string = str_replace($findchars_iso, $replacechars, $string);
5641
+	if ($context['utf8']) {
5642
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5643
+	} else {
5644
+			$string = str_replace($findchars_iso, $replacechars, $string);
5645
+	}
5341 5646
 
5342 5647
 	return $string;
5343 5648
 }
@@ -5356,49 +5661,59 @@  discard block
 block discarded – undo
5356 5661
 {
5357 5662
 	global $context;
5358 5663
 
5359
-	if (!isset($matches[2]))
5360
-		return '';
5664
+	if (!isset($matches[2])) {
5665
+			return '';
5666
+	}
5361 5667
 
5362 5668
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5363 5669
 
5364 5670
 	// remove left to right / right to left overrides
5365
-	if ($num === 0x202D || $num === 0x202E)
5366
-		return '';
5671
+	if ($num === 0x202D || $num === 0x202E) {
5672
+			return '';
5673
+	}
5367 5674
 
5368 5675
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5369
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5370
-		return '&#' . $num . ';';
5676
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5677
+			return '&#' . $num . ';';
5678
+	}
5371 5679
 
5372 5680
 	if (empty($context['utf8']))
5373 5681
 	{
5374 5682
 		// no control characters
5375
-		if ($num < 0x20)
5376
-			return '';
5683
+		if ($num < 0x20) {
5684
+					return '';
5685
+		}
5377 5686
 		// text is text
5378
-		elseif ($num < 0x80)
5379
-			return chr($num);
5687
+		elseif ($num < 0x80) {
5688
+					return chr($num);
5689
+		}
5380 5690
 		// all others get html-ised
5381
-		else
5382
-			return '&#' . $matches[2] . ';';
5383
-	}
5384
-	else
5691
+		else {
5692
+					return '&#' . $matches[2] . ';';
5693
+		}
5694
+	} else
5385 5695
 	{
5386 5696
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5387 5697
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5388
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5389
-			return '';
5698
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5699
+					return '';
5700
+		}
5390 5701
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5391
-		elseif ($num < 0x80)
5392
-			return chr($num);
5702
+		elseif ($num < 0x80) {
5703
+					return chr($num);
5704
+		}
5393 5705
 		// <0x800 (2048)
5394
-		elseif ($num < 0x800)
5395
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5706
+		elseif ($num < 0x800) {
5707
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5708
+		}
5396 5709
 		// < 0x10000 (65536)
5397
-		elseif ($num < 0x10000)
5398
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5710
+		elseif ($num < 0x10000) {
5711
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5712
+		}
5399 5713
 		// <= 0x10FFFF (1114111)
5400
-		else
5401
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5714
+		else {
5715
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5716
+		}
5402 5717
 	}
5403 5718
 }
5404 5719
 
@@ -5414,28 +5729,34 @@  discard block
 block discarded – undo
5414 5729
  */
5415 5730
 function fixchar__callback($matches)
5416 5731
 {
5417
-	if (!isset($matches[1]))
5418
-		return '';
5732
+	if (!isset($matches[1])) {
5733
+			return '';
5734
+	}
5419 5735
 
5420 5736
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5421 5737
 
5422 5738
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5423 5739
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5424
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5425
-		return '';
5740
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5741
+			return '';
5742
+	}
5426 5743
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5427
-	elseif ($num < 0x80)
5428
-		return chr($num);
5744
+	elseif ($num < 0x80) {
5745
+			return chr($num);
5746
+	}
5429 5747
 	// <0x800 (2048)
5430
-	elseif ($num < 0x800)
5431
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5748
+	elseif ($num < 0x800) {
5749
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5750
+	}
5432 5751
 	// < 0x10000 (65536)
5433
-	elseif ($num < 0x10000)
5434
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5752
+	elseif ($num < 0x10000) {
5753
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5754
+	}
5435 5755
 	// <= 0x10FFFF (1114111)
5436
-	else
5437
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5438
-}
5756
+	else {
5757
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5758
+	}
5759
+	}
5439 5760
 
5440 5761
 /**
5441 5762
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5448,17 +5769,19 @@  discard block
 block discarded – undo
5448 5769
  */
5449 5770
 function entity_fix__callback($matches)
5450 5771
 {
5451
-	if (!isset($matches[2]))
5452
-		return '';
5772
+	if (!isset($matches[2])) {
5773
+			return '';
5774
+	}
5453 5775
 
5454 5776
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5455 5777
 
5456 5778
 	// we don't allow control characters, characters out of range, byte markers, etc
5457
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5458
-		return '';
5459
-	else
5460
-		return '&#' . $num . ';';
5461
-}
5779
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5780
+			return '';
5781
+	} else {
5782
+			return '&#' . $num . ';';
5783
+	}
5784
+	}
5462 5785
 
5463 5786
 /**
5464 5787
  * Return a Gravatar URL based on
@@ -5482,18 +5805,23 @@  discard block
 block discarded – undo
5482 5805
 		$ratings = array('G', 'PG', 'R', 'X');
5483 5806
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5484 5807
 		$url_params = array();
5485
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5486
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5487
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5488
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5489
-		if (!empty($modSettings['avatar_max_width_external']))
5490
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5491
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5492
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5808
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5809
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5810
+		}
5811
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5812
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5813
+		}
5814
+		if (!empty($modSettings['avatar_max_width_external'])) {
5815
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5816
+		}
5817
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5818
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5493 5819
 				$size_string = $modSettings['avatar_max_height_external'];
5820
+		}
5494 5821
 
5495
-		if (!empty($size_string))
5496
-			$url_params[] = 's=' . $size_string;
5822
+		if (!empty($size_string)) {
5823
+					$url_params[] = 's=' . $size_string;
5824
+		}
5497 5825
 	}
5498 5826
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5499 5827
 
@@ -5512,22 +5840,26 @@  discard block
 block discarded – undo
5512 5840
 	static $timezones = null, $lastwhen = null;
5513 5841
 
5514 5842
 	// No point doing this over if we already did it once
5515
-	if (!empty($timezones) && $when == $lastwhen)
5516
-		return $timezones;
5517
-	else
5518
-		$lastwhen = $when;
5843
+	if (!empty($timezones) && $when == $lastwhen) {
5844
+			return $timezones;
5845
+	} else {
5846
+			$lastwhen = $when;
5847
+	}
5519 5848
 
5520 5849
 	// Parseable datetime string?
5521
-	if (is_int($timestamp = strtotime($when)))
5522
-		$when = $timestamp;
5850
+	if (is_int($timestamp = strtotime($when))) {
5851
+			$when = $timestamp;
5852
+	}
5523 5853
 
5524 5854
 	// A Unix timestamp?
5525
-	elseif (is_numeric($when))
5526
-		$when = intval($when);
5855
+	elseif (is_numeric($when)) {
5856
+			$when = intval($when);
5857
+	}
5527 5858
 
5528 5859
 	// Invalid value? Just get current Unix timestamp.
5529
-	else
5530
-		$when = time();
5860
+	else {
5861
+			$when = time();
5862
+	}
5531 5863
 
5532 5864
 	// We'll need these too
5533 5865
 	$date_when = date_create('@' . $when);
@@ -5542,8 +5874,9 @@  discard block
 block discarded – undo
5542 5874
 	foreach ($priority_countries as $country)
5543 5875
 	{
5544 5876
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5545
-		if (!empty($country_tzids))
5546
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5877
+		if (!empty($country_tzids)) {
5878
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5879
+		}
5547 5880
 	}
5548 5881
 
5549 5882
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5557,8 +5890,9 @@  discard block
 block discarded – undo
5557 5890
 	foreach ($tzids as $tzid)
5558 5891
 	{
5559 5892
 		// We don't want UTC right now
5560
-		if ($tzid == 'UTC')
5561
-			continue;
5893
+		if ($tzid == 'UTC') {
5894
+					continue;
5895
+		}
5562 5896
 
5563 5897
 		$tz = timezone_open($tzid);
5564 5898
 
@@ -5579,13 +5913,14 @@  discard block
 block discarded – undo
5579 5913
 		}
5580 5914
 
5581 5915
 		// A time zone from a prioritized country?
5582
-		if (in_array($tzid, $priority_tzids))
5583
-			$priority_zones[$tzkey] = true;
5916
+		if (in_array($tzid, $priority_tzids)) {
5917
+					$priority_zones[$tzkey] = true;
5918
+		}
5584 5919
 
5585 5920
 		// Keep track of the location and offset for this tzid
5586
-		if (!empty($txt[$tzid]))
5587
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5588
-		else
5921
+		if (!empty($txt[$tzid])) {
5922
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5923
+		} else
5589 5924
 		{
5590 5925
 			$tzid_parts = explode('/', $tzid);
5591 5926
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5605,23 +5940,27 @@  discard block
 block discarded – undo
5605 5940
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5606 5941
 
5607 5942
 		// Use the custom description, if there is one
5608
-		if (!empty($tztxt[$tzvalue['tzid']]))
5609
-			$desc = $tztxt[$tzvalue['tzid']];
5943
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5944
+					$desc = $tztxt[$tzvalue['tzid']];
5945
+		}
5610 5946
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5611
-		else
5612
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5947
+		else {
5948
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5949
+		}
5613 5950
 
5614 5951
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5615 5952
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5616 5953
 
5617
-		if (isset($priority_zones[$tzkey]))
5618
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5619
-		else
5620
-			$timezones[$tzvalue['tzid']] = $desc;
5954
+		if (isset($priority_zones[$tzkey])) {
5955
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5956
+		} else {
5957
+					$timezones[$tzvalue['tzid']] = $desc;
5958
+		}
5621 5959
 	}
5622 5960
 
5623
-	if (!empty($priority_timezones))
5624
-		$priority_timezones[] = '-----';
5961
+	if (!empty($priority_timezones)) {
5962
+			$priority_timezones[] = '-----';
5963
+	}
5625 5964
 
5626 5965
 	$timezones = array_merge(
5627 5966
 		$priority_timezones,
@@ -5638,8 +5977,9 @@  discard block
 block discarded – undo
5638 5977
  */
5639 5978
 function inet_ptod($ip_address)
5640 5979
 {
5641
-	if (!isValidIP($ip_address))
5642
-		return $ip_address;
5980
+	if (!isValidIP($ip_address)) {
5981
+			return $ip_address;
5982
+	}
5643 5983
 
5644 5984
 	$bin = inet_pton($ip_address);
5645 5985
 	return $bin;
@@ -5651,13 +5991,15 @@  discard block
 block discarded – undo
5651 5991
  */
5652 5992
 function inet_dtop($bin)
5653 5993
 {
5654
-	if(empty($bin))
5655
-		return '';
5994
+	if(empty($bin)) {
5995
+			return '';
5996
+	}
5656 5997
 
5657 5998
 	global $db_type;
5658 5999
 
5659
-	if ($db_type == 'postgresql')
5660
-		return $bin;
6000
+	if ($db_type == 'postgresql') {
6001
+			return $bin;
6002
+	}
5661 6003
 
5662 6004
 	$ip_address = inet_ntop($bin);
5663 6005
 
@@ -5682,26 +6024,32 @@  discard block
 block discarded – undo
5682 6024
  */
5683 6025
 function _safe_serialize($value)
5684 6026
 {
5685
-	if(is_null($value))
5686
-		return 'N;';
6027
+	if(is_null($value)) {
6028
+			return 'N;';
6029
+	}
5687 6030
 
5688
-	if(is_bool($value))
5689
-		return 'b:'. (int) $value .';';
6031
+	if(is_bool($value)) {
6032
+			return 'b:'. (int) $value .';';
6033
+	}
5690 6034
 
5691
-	if(is_int($value))
5692
-		return 'i:'. $value .';';
6035
+	if(is_int($value)) {
6036
+			return 'i:'. $value .';';
6037
+	}
5693 6038
 
5694
-	if(is_float($value))
5695
-		return 'd:'. str_replace(',', '.', $value) .';';
6039
+	if(is_float($value)) {
6040
+			return 'd:'. str_replace(',', '.', $value) .';';
6041
+	}
5696 6042
 
5697
-	if(is_string($value))
5698
-		return 's:'. strlen($value) .':"'. $value .'";';
6043
+	if(is_string($value)) {
6044
+			return 's:'. strlen($value) .':"'. $value .'";';
6045
+	}
5699 6046
 
5700 6047
 	if(is_array($value))
5701 6048
 	{
5702 6049
 		$out = '';
5703
-		foreach($value as $k => $v)
5704
-			$out .= _safe_serialize($k) . _safe_serialize($v);
6050
+		foreach($value as $k => $v) {
6051
+					$out .= _safe_serialize($k) . _safe_serialize($v);
6052
+		}
5705 6053
 
5706 6054
 		return 'a:'. count($value) .':{'. $out .'}';
5707 6055
 	}
@@ -5727,8 +6075,9 @@  discard block
 block discarded – undo
5727 6075
 
5728 6076
 	$out = _safe_serialize($value);
5729 6077
 
5730
-	if (isset($mbIntEnc))
5731
-		mb_internal_encoding($mbIntEnc);
6078
+	if (isset($mbIntEnc)) {
6079
+			mb_internal_encoding($mbIntEnc);
6080
+	}
5732 6081
 
5733 6082
 	return $out;
5734 6083
 }
@@ -5745,8 +6094,9 @@  discard block
 block discarded – undo
5745 6094
 function _safe_unserialize($str)
5746 6095
 {
5747 6096
 	// Input  is not a string.
5748
-	if(empty($str) || !is_string($str))
5749
-		return false;
6097
+	if(empty($str) || !is_string($str)) {
6098
+			return false;
6099
+	}
5750 6100
 
5751 6101
 	$stack = array();
5752 6102
 	$expected = array();
@@ -5762,43 +6112,38 @@  discard block
 block discarded – undo
5762 6112
 	while($state != 1)
5763 6113
 	{
5764 6114
 		$type = isset($str[0]) ? $str[0] : '';
5765
-		if($type == '}')
5766
-			$str = substr($str, 1);
5767
-
5768
-		else if($type == 'N' && $str[1] == ';')
6115
+		if($type == '}') {
6116
+					$str = substr($str, 1);
6117
+		} else if($type == 'N' && $str[1] == ';')
5769 6118
 		{
5770 6119
 			$value = null;
5771 6120
 			$str = substr($str, 2);
5772
-		}
5773
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
6121
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5774 6122
 		{
5775 6123
 			$value = $matches[1] == '1' ? true : false;
5776 6124
 			$str = substr($str, 4);
5777
-		}
5778
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
6125
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5779 6126
 		{
5780 6127
 			$value = (int)$matches[1];
5781 6128
 			$str = $matches[2];
5782
-		}
5783
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
6129
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5784 6130
 		{
5785 6131
 			$value = (float)$matches[1];
5786 6132
 			$str = $matches[3];
5787
-		}
5788
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
6133
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5789 6134
 		{
5790 6135
 			$value = substr($matches[2], 0, (int)$matches[1]);
5791 6136
 			$str = substr($matches[2], (int)$matches[1] + 2);
5792
-		}
5793
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
6137
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5794 6138
 		{
5795 6139
 			$expectedLength = (int)$matches[1];
5796 6140
 			$str = $matches[2];
5797 6141
 		}
5798 6142
 
5799 6143
 		// Object or unknown/malformed type.
5800
-		else
5801
-			return false;
6144
+		else {
6145
+					return false;
6146
+		}
5802 6147
 
5803 6148
 		switch($state)
5804 6149
 		{
@@ -5826,8 +6171,9 @@  discard block
 block discarded – undo
5826 6171
 				if($type == '}')
5827 6172
 				{
5828 6173
 					// Array size is less than expected.
5829
-					if(count($list) < end($expected))
5830
-						return false;
6174
+					if(count($list) < end($expected)) {
6175
+											return false;
6176
+					}
5831 6177
 
5832 6178
 					unset($list);
5833 6179
 					$list = &$stack[count($stack)-1];
@@ -5836,8 +6182,9 @@  discard block
 block discarded – undo
5836 6182
 					// Go to terminal state if we're at the end of the root array.
5837 6183
 					array_pop($expected);
5838 6184
 
5839
-					if(count($expected) == 0)
5840
-						$state = 1;
6185
+					if(count($expected) == 0) {
6186
+											$state = 1;
6187
+					}
5841 6188
 
5842 6189
 					break;
5843 6190
 				}
@@ -5845,8 +6192,9 @@  discard block
 block discarded – undo
5845 6192
 				if($type == 'i' || $type == 's')
5846 6193
 				{
5847 6194
 					// Array size exceeds expected length.
5848
-					if(count($list) >= end($expected))
5849
-						return false;
6195
+					if(count($list) >= end($expected)) {
6196
+											return false;
6197
+					}
5850 6198
 
5851 6199
 					$key = $value;
5852 6200
 					$state = 3;
@@ -5880,8 +6228,9 @@  discard block
 block discarded – undo
5880 6228
 	}
5881 6229
 
5882 6230
 	// Trailing data in input.
5883
-	if(!empty($str))
5884
-		return false;
6231
+	if(!empty($str)) {
6232
+			return false;
6233
+	}
5885 6234
 
5886 6235
 	return $data;
5887 6236
 }
@@ -5904,8 +6253,9 @@  discard block
 block discarded – undo
5904 6253
 
5905 6254
 	$out = _safe_unserialize($str);
5906 6255
 
5907
-	if (isset($mbIntEnc))
5908
-		mb_internal_encoding($mbIntEnc);
6256
+	if (isset($mbIntEnc)) {
6257
+			mb_internal_encoding($mbIntEnc);
6258
+	}
5909 6259
 
5910 6260
 	return $out;
5911 6261
 }
@@ -5920,12 +6270,14 @@  discard block
 block discarded – undo
5920 6270
 function smf_chmod($file, $value = 0)
5921 6271
 {
5922 6272
 	// No file? no checks!
5923
-	if (empty($file))
5924
-		return false;
6273
+	if (empty($file)) {
6274
+			return false;
6275
+	}
5925 6276
 
5926 6277
 	// Already writable?
5927
-	if (is_writable($file))
5928
-		return true;
6278
+	if (is_writable($file)) {
6279
+			return true;
6280
+	}
5929 6281
 
5930 6282
 	// Do we have a file or a dir?
5931 6283
 	$isDir = is_dir($file);
@@ -5941,10 +6293,9 @@  discard block
 block discarded – undo
5941 6293
 		{
5942 6294
 			$isWritable = true;
5943 6295
 			break;
6296
+		} else {
6297
+					@chmod($file, $val);
5944 6298
 		}
5945
-
5946
-		else
5947
-			@chmod($file, $val);
5948 6299
 	}
5949 6300
 
5950 6301
 	return $isWritable;
@@ -5963,8 +6314,9 @@  discard block
 block discarded – undo
5963 6314
 	global $txt;
5964 6315
 
5965 6316
 	// Come on...
5966
-	if (empty($json) || !is_string($json))
5967
-		return array();
6317
+	if (empty($json) || !is_string($json)) {
6318
+			return array();
6319
+	}
5968 6320
 
5969 6321
 	$returnArray = @json_decode($json, $returnAsArray);
5970 6322
 
@@ -6002,11 +6354,11 @@  discard block
 block discarded – undo
6002 6354
 		$jsonDebug = $jsonDebug[0];
6003 6355
 		loadLanguage('Errors');
6004 6356
 
6005
-		if (!empty($jsonDebug))
6006
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6007
-
6008
-		else
6009
-			log_error($txt['json_'. $jsonError], 'critical');
6357
+		if (!empty($jsonDebug)) {
6358
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6359
+		} else {
6360
+					log_error($txt['json_'. $jsonError], 'critical');
6361
+		}
6010 6362
 
6011 6363
 		// Everyone expects an array.
6012 6364
 		return array();
@@ -6040,8 +6392,9 @@  discard block
 block discarded – undo
6040 6392
 	global $db_show_debug, $modSettings;
6041 6393
 
6042 6394
 	// Defensive programming anyone?
6043
-	if (empty($data))
6044
-		return false;
6395
+	if (empty($data)) {
6396
+			return false;
6397
+	}
6045 6398
 
6046 6399
 	// Don't need extra stuff...
6047 6400
 	$db_show_debug = false;
@@ -6049,11 +6402,11 @@  discard block
 block discarded – undo
6049 6402
 	// Kill anything else.
6050 6403
 	ob_end_clean();
6051 6404
 
6052
-	if (!empty($modSettings['CompressedOutput']))
6053
-		@ob_start('ob_gzhandler');
6054
-
6055
-	else
6056
-		ob_start();
6405
+	if (!empty($modSettings['CompressedOutput'])) {
6406
+			@ob_start('ob_gzhandler');
6407
+	} else {
6408
+			ob_start();
6409
+	}
6057 6410
 
6058 6411
 	// Set the header.
6059 6412
 	header($type);
@@ -6085,8 +6438,9 @@  discard block
 block discarded – undo
6085 6438
 	static $done = false;
6086 6439
 
6087 6440
 	// If we don't need to do anything, don't
6088
-	if (!$update && $done)
6089
-		return;
6441
+	if (!$update && $done) {
6442
+			return;
6443
+	}
6090 6444
 
6091 6445
 	// Should we get a new copy of the official list of TLDs?
6092 6446
 	if ($update)
@@ -6098,8 +6452,9 @@  discard block
 block discarded – undo
6098 6452
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
6099 6453
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
6100 6454
 		// update to see if civilization has been restored.
6101
-		if ($tlds === false)
6102
-			$postapocalypticNightmare = true;
6455
+		if ($tlds === false) {
6456
+					$postapocalypticNightmare = true;
6457
+		}
6103 6458
 	}
6104 6459
 	// If we aren't updating and the regex is valid, we're done
6105 6460
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -6114,10 +6469,11 @@  discard block
 block discarded – undo
6114 6469
 		// Clean $tlds and convert it to an array
6115 6470
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
6116 6471
 			$line = trim($line);
6117
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
6118
-				return false;
6119
-			else
6120
-				return true;
6472
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6473
+							return false;
6474
+			} else {
6475
+							return true;
6476
+			}
6121 6477
 		});
6122 6478
 
6123 6479
 		// Convert Punycode to Unicode
@@ -6209,8 +6565,7 @@  discard block
 block discarded – undo
6209 6565
 
6210 6566
 		$strlen = 'mb_strlen';
6211 6567
 		$substr = 'mb_substr';
6212
-	}
6213
-	else
6568
+	} else
6214 6569
 	{
6215 6570
 		$strlen = $smcFunc['strlen'];
6216 6571
 		$substr = $smcFunc['substr'];
@@ -6224,20 +6579,21 @@  discard block
 block discarded – undo
6224 6579
 
6225 6580
 		$first = $substr($string, 0, 1);
6226 6581
 
6227
-		if (empty($index[$first]))
6228
-			$index[$first] = array();
6582
+		if (empty($index[$first])) {
6583
+					$index[$first] = array();
6584
+		}
6229 6585
 
6230 6586
 		if ($strlen($string) > 1)
6231 6587
 		{
6232 6588
 			// Sanity check on recursion
6233
-			if ($depth > 99)
6234
-				$index[$first][$substr($string, 1)] = '';
6235
-
6236
-			else
6237
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6589
+			if ($depth > 99) {
6590
+							$index[$first][$substr($string, 1)] = '';
6591
+			} else {
6592
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6593
+			}
6594
+		} else {
6595
+					$index[$first][''] = '';
6238 6596
 		}
6239
-		else
6240
-			$index[$first][''] = '';
6241 6597
 
6242 6598
 		$depth--;
6243 6599
 		return $index;
@@ -6260,9 +6616,9 @@  discard block
 block discarded – undo
6260 6616
 			$key_regex = preg_quote($key, $delim);
6261 6617
 			$new_key = $key;
6262 6618
 
6263
-			if (empty($value))
6264
-				$sub_regex = '';
6265
-			else
6619
+			if (empty($value)) {
6620
+							$sub_regex = '';
6621
+			} else
6266 6622
 			{
6267 6623
 				$sub_regex = $index_to_regex($value, $delim);
6268 6624
 
@@ -6270,22 +6626,22 @@  discard block
 block discarded – undo
6270 6626
 				{
6271 6627
 					$new_key_array = explode('(?'.'>', $sub_regex);
6272 6628
 					$new_key .= $new_key_array[0];
6629
+				} else {
6630
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6273 6631
 				}
6274
-				else
6275
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6276 6632
 			}
6277 6633
 
6278
-			if ($depth > 1)
6279
-				$regex[$new_key] = $key_regex . $sub_regex;
6280
-			else
6634
+			if ($depth > 1) {
6635
+							$regex[$new_key] = $key_regex . $sub_regex;
6636
+			} else
6281 6637
 			{
6282 6638
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6283 6639
 				{
6284 6640
 					$regex[$new_key] = $key_regex . $sub_regex;
6285 6641
 					unset($index[$key]);
6642
+				} else {
6643
+									break;
6286 6644
 				}
6287
-				else
6288
-					break;
6289 6645
 			}
6290 6646
 		}
6291 6647
 
@@ -6294,10 +6650,11 @@  discard block
 block discarded – undo
6294 6650
 			$l1 = $strlen($k1);
6295 6651
 			$l2 = $strlen($k2);
6296 6652
 
6297
-			if ($l1 == $l2)
6298
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6299
-			else
6300
-				return $l1 > $l2 ? -1 : 1;
6653
+			if ($l1 == $l2) {
6654
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6655
+			} else {
6656
+							return $l1 > $l2 ? -1 : 1;
6657
+			}
6301 6658
 		});
6302 6659
 
6303 6660
 		$depth--;
@@ -6308,21 +6665,24 @@  discard block
 block discarded – undo
6308 6665
 	$index = array();
6309 6666
 	$regex = '';
6310 6667
 
6311
-	foreach ($strings as $string)
6312
-		$index = $add_string_to_index($string, $index);
6668
+	foreach ($strings as $string) {
6669
+			$index = $add_string_to_index($string, $index);
6670
+	}
6313 6671
 
6314 6672
 	if ($returnArray === true)
6315 6673
 	{
6316 6674
 		$regex = array();
6317
-		while (!empty($index))
6318
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6675
+		while (!empty($index)) {
6676
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6677
+		}
6678
+	} else {
6679
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6319 6680
 	}
6320
-	else
6321
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6322 6681
 
6323 6682
 	// Restore PHP's internal character encoding to whatever it was originally
6324
-	if (!empty($current_encoding))
6325
-		mb_internal_encoding($current_encoding);
6683
+	if (!empty($current_encoding)) {
6684
+			mb_internal_encoding($current_encoding);
6685
+	}
6326 6686
 
6327 6687
 	return $regex;
6328 6688
 }
@@ -6365,13 +6725,15 @@  discard block
 block discarded – undo
6365 6725
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6366 6726
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6367 6727
 	$headers = @get_headers($url);
6368
-	if ($headers === false)
6369
-		return false;
6728
+	if ($headers === false) {
6729
+			return false;
6730
+	}
6370 6731
 
6371 6732
 	// Now to see if it came back https...
6372 6733
 	// First check for a redirect status code in first row (301, 302, 307)
6373
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6374
-		return false;
6734
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6735
+			return false;
6736
+	}
6375 6737
 
6376 6738
 	// Search for the location entry to confirm https
6377 6739
 	$result = false;
@@ -6409,8 +6771,7 @@  discard block
 block discarded – undo
6409 6771
 		$is_admin = $user_info['is_admin'];
6410 6772
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6411 6773
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6412
-	}
6413
-	else
6774
+	} else
6414 6775
 	{
6415 6776
 		$request = $smcFunc['db_query']('', '
6416 6777
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6424,17 +6785,19 @@  discard block
 block discarded – undo
6424 6785
 
6425 6786
 		$row = $smcFunc['db_fetch_assoc']($request);
6426 6787
 
6427
-		if (empty($row['additional_groups']))
6428
-			$groups = array($row['id_group'], $row['id_post_group']);
6429
-		else
6430
-			$groups = array_merge(
6788
+		if (empty($row['additional_groups'])) {
6789
+					$groups = array($row['id_group'], $row['id_post_group']);
6790
+		} else {
6791
+					$groups = array_merge(
6431 6792
 					array($row['id_group'], $row['id_post_group']),
6432 6793
 					explode(',', $row['additional_groups'])
6433 6794
 			);
6795
+		}
6434 6796
 
6435 6797
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6436
-		foreach ($groups as $k => $v)
6437
-			$groups[$k] = (int) $v;
6798
+		foreach ($groups as $k => $v) {
6799
+					$groups[$k] = (int) $v;
6800
+		}
6438 6801
 
6439 6802
 		$is_admin = in_array(1, $groups);
6440 6803
 
@@ -6451,8 +6814,9 @@  discard block
 block discarded – undo
6451 6814
 				'current_member' => $userid,
6452 6815
 			)
6453 6816
 		);
6454
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6455
-			$boards_mod[] = $row['id_board'];
6817
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6818
+					$boards_mod[] = $row['id_board'];
6819
+		}
6456 6820
 		$smcFunc['db_free_result']($request);
6457 6821
 
6458 6822
 		// Can any of the groups they're in moderate any of the boards?
@@ -6464,8 +6828,9 @@  discard block
 block discarded – undo
6464 6828
 				'groups' => $groups,
6465 6829
 			)
6466 6830
 		);
6467
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6468
-			$boards_mod[] = $row['id_board'];
6831
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6832
+					$boards_mod[] = $row['id_board'];
6833
+		}
6469 6834
 		$smcFunc['db_free_result']($request);
6470 6835
 
6471 6836
 		// Just in case we've got duplicates here...
@@ -6475,21 +6840,25 @@  discard block
 block discarded – undo
6475 6840
 	}
6476 6841
 
6477 6842
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6478
-	if ($is_admin)
6479
-		$query_part['query_see_board'] = '1=1';
6843
+	if ($is_admin) {
6844
+			$query_part['query_see_board'] = '1=1';
6845
+	}
6480 6846
 	// Otherwise just the groups in $user_info['groups'].
6481
-	else
6482
-		$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6847
+	else {
6848
+			$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6849
+	}
6483 6850
 
6484 6851
 	// Build the list of boards they WANT to see.
6485 6852
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6486 6853
 
6487 6854
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6488
-	if (empty($ignoreboards))
6489
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6855
+	if (empty($ignoreboards)) {
6856
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6857
+	}
6490 6858
 	// Ok I guess they don't want to see all the boards
6491
-	else
6492
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6859
+	else {
6860
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6861
+	}
6493 6862
 
6494 6863
 	return $query_part;
6495 6864
 }
@@ -6503,10 +6872,11 @@  discard block
 block discarded – undo
6503 6872
 {
6504 6873
 	$secure = false;
6505 6874
 
6506
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6507
-		$secure = true;
6508
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
6509
-		$secure = true;
6875
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6876
+			$secure = true;
6877
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
6878
+			$secure = true;
6879
+	}
6510 6880
 
6511 6881
 	return $secure;
6512 6882
 }
@@ -6523,11 +6893,12 @@  discard block
 block discarded – undo
6523 6893
 {
6524 6894
 	$url = iri_to_url($iri);
6525 6895
 
6526
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6527
-		return $iri;
6528
-	else
6529
-		return false;
6530
-}
6896
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6897
+			return $iri;
6898
+	} else {
6899
+			return false;
6900
+	}
6901
+	}
6531 6902
 
6532 6903
 /**
6533 6904
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6570,8 +6941,9 @@  discard block
 block discarded – undo
6570 6941
 
6571 6942
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6572 6943
 
6573
-	if (empty($host))
6574
-		return $iri;
6944
+	if (empty($host)) {
6945
+			return $iri;
6946
+	}
6575 6947
 
6576 6948
 	// Convert the domain using the Punycode algorithm
6577 6949
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6607,8 +6979,9 @@  discard block
 block discarded – undo
6607 6979
 
6608 6980
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6609 6981
 
6610
-	if (empty($host))
6611
-		return $url;
6982
+	if (empty($host)) {
6983
+			return $url;
6984
+	}
6612 6985
 
6613 6986
 	// Decode the domain from Punycode
6614 6987
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6634,8 +7007,9 @@  discard block
 block discarded – undo
6634 7007
 {
6635 7008
 	global $user_info, $modSettings, $smcFunc, $txt;
6636 7009
 
6637
-	if (empty($modSettings['cron_last_checked']))
6638
-		$modSettings['cron_last_checked'] = 0;
7010
+	if (empty($modSettings['cron_last_checked'])) {
7011
+			$modSettings['cron_last_checked'] = 0;
7012
+	}
6639 7013
 
6640 7014
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6641 7015
 	{
@@ -6655,9 +7029,9 @@  discard block
 block discarded – undo
6655 7029
 			loadLanguage('ManageScheduledTasks');
6656 7030
 			log_error($txt['cron_not_working']);
6657 7031
 			updateSettings(array('cron_is_real_cron' => 0));
7032
+		} else {
7033
+					updateSettings(array('cron_last_checked' => time()));
6658 7034
 		}
6659
-		else
6660
-			updateSettings(array('cron_last_checked' => time()));
6661 7035
 	}
6662 7036
 }
6663 7037
 
Please login to merge, or discard this patch.