Completed
Push — release-2.1 ( 996344...c049e9 )
by Mert
16s queued 10s
created
Sources/Subs.php 1 patch
Braces   +1368 added lines, -1014 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,23 +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
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -385,18 +394,17 @@  discard block
 block discarded – undo
385 394
 			if (is_array($members))
386 395
 			{
387 396
 				$val = 'CASE ';
388
-				foreach ($members as $k => $v)
389
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
397
+				foreach ($members as $k => $v) {
398
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				}
390 400
 				$val = $val . ' END';
391 401
 				$type = 'raw';
392
-			}
393
-			else
402
+			} else
394 403
 			{
395 404
 				$blub = fetch_alerts($members, false, 0, array(), false);
396 405
 				$val = count($blub);
397 406
 			}
398
-		}
399
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
407
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
400 408
 		{
401 409
 			$val = $var . ' ' . $val . ' 1';
402 410
 			$type = 'raw';
@@ -407,8 +415,9 @@  discard block
 block discarded – undo
407 415
 		{
408 416
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
409 417
 			{
410
-				if ($match[1] != '+ ')
411
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
418
+				if ($match[1] != '+ ') {
419
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				}
412 421
 				$type = 'raw';
413 422
 			}
414 423
 		}
@@ -429,8 +438,9 @@  discard block
 block discarded – undo
429 438
 	// Clear any caching?
430 439
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
431 440
 	{
432
-		if (!is_array($members))
433
-			$members = array($members);
441
+		if (!is_array($members)) {
442
+					$members = array($members);
443
+		}
434 444
 
435 445
 		foreach ($members as $member)
436 446
 		{
@@ -463,29 +473,32 @@  discard block
 block discarded – undo
463 473
 {
464 474
 	global $modSettings, $smcFunc;
465 475
 
466
-	if (empty($changeArray) || !is_array($changeArray))
467
-		return;
476
+	if (empty($changeArray) || !is_array($changeArray)) {
477
+			return;
478
+	}
468 479
 
469 480
 	$toRemove = array();
470 481
 
471 482
 	// Go check if there is any setting to be removed.
472
-	foreach ($changeArray as $k => $v)
473
-		if ($v === null)
483
+	foreach ($changeArray as $k => $v) {
484
+			if ($v === null)
474 485
 		{
475 486
 			// Found some, remove them from the original array and add them to ours.
476 487
 			unset($changeArray[$k]);
488
+	}
477 489
 			$toRemove[] = $k;
478 490
 		}
479 491
 
480 492
 	// Proceed with the deletion.
481
-	if (!empty($toRemove))
482
-		$smcFunc['db_query']('', '
493
+	if (!empty($toRemove)) {
494
+			$smcFunc['db_query']('', '
483 495
 			DELETE FROM {db_prefix}settings
484 496
 			WHERE variable IN ({array_string:remove})',
485 497
 			array(
486 498
 				'remove' => $toRemove,
487 499
 			)
488 500
 		);
501
+	}
489 502
 
490 503
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
491 504
 	if ($update)
@@ -514,19 +527,22 @@  discard block
 block discarded – undo
514 527
 	foreach ($changeArray as $variable => $value)
515 528
 	{
516 529
 		// Don't bother if it's already like that ;).
517
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
518
-			continue;
530
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
531
+					continue;
532
+		}
519 533
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
520
-		elseif (!isset($modSettings[$variable]) && empty($value))
521
-			continue;
534
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
535
+					continue;
536
+		}
522 537
 
523 538
 		$replaceArray[] = array($variable, $value);
524 539
 
525 540
 		$modSettings[$variable] = $value;
526 541
 	}
527 542
 
528
-	if (empty($replaceArray))
529
-		return;
543
+	if (empty($replaceArray)) {
544
+			return;
545
+	}
530 546
 
531 547
 	$smcFunc['db_insert']('replace',
532 548
 		'{db_prefix}settings',
@@ -572,14 +588,17 @@  discard block
 block discarded – undo
572 588
 	$start_invalid = $start < 0;
573 589
 
574 590
 	// Make sure $start is a proper variable - not less than 0.
575
-	if ($start_invalid)
576
-		$start = 0;
591
+	if ($start_invalid) {
592
+			$start = 0;
593
+	}
577 594
 	// Not greater than the upper bound.
578
-	elseif ($start >= $max_value)
579
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
595
+	elseif ($start >= $max_value) {
596
+			$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
+	}
580 598
 	// And it has to be a multiple of $num_per_page!
581
-	else
582
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
599
+	else {
600
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	}
583 602
 
584 603
 	$context['current_page'] = $start / $num_per_page;
585 604
 
@@ -609,77 +628,87 @@  discard block
 block discarded – undo
609 628
 
610 629
 		// Show all the pages.
611 630
 		$display_page = 1;
612
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
613
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
631
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
632
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		}
614 634
 
615 635
 		// Show the right arrow.
616 636
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
617
-		if ($start != $counter - $max_value && !$start_invalid)
618
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
619
-	}
620
-	else
637
+		if ($start != $counter - $max_value && !$start_invalid) {
638
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
639
+		}
640
+	} else
621 641
 	{
622 642
 		// If they didn't enter an odd value, pretend they did.
623 643
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
624 644
 
625 645
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
626
-		if (!empty($start) && $show_prevnext)
627
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
628
-		else
629
-			$pageindex .= '';
646
+		if (!empty($start) && $show_prevnext) {
647
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
648
+		} else {
649
+					$pageindex .= '';
650
+		}
630 651
 
631 652
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
632
-		if ($start > $num_per_page * $PageContiguous)
633
-			$pageindex .= sprintf($base_link, 0, '1');
653
+		if ($start > $num_per_page * $PageContiguous) {
654
+					$pageindex .= sprintf($base_link, 0, '1');
655
+		}
634 656
 
635 657
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
636
-		if ($start > $num_per_page * ($PageContiguous + 1))
637
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
658
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
659
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
638 660
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
639 661
 				'{FIRST_PAGE}' => $num_per_page,
640 662
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
641 663
 				'{PER_PAGE}' => $num_per_page,
642 664
 			));
665
+		}
643 666
 
644 667
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
645
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
646
-			if ($start >= $num_per_page * $nCont)
668
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
669
+					if ($start >= $num_per_page * $nCont)
647 670
 			{
648 671
 				$tmpStart = $start - $num_per_page * $nCont;
672
+		}
649 673
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
650 674
 			}
651 675
 
652 676
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
653
-		if (!$start_invalid)
654
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
655
-		else
656
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
677
+		if (!$start_invalid) {
678
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
679
+		} else {
680
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
681
+		}
657 682
 
658 683
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
659 684
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
660
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
661
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
685
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
686
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
662 687
 			{
663 688
 				$tmpStart = $start + $num_per_page * $nCont;
689
+		}
664 690
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
665 691
 			}
666 692
 
667 693
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
668
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
669
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
694
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
695
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
670 696
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
671 697
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
672 698
 				'{LAST_PAGE}' => $tmpMaxPages,
673 699
 				'{PER_PAGE}' => $num_per_page,
674 700
 			));
701
+		}
675 702
 
676 703
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
677
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
678
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
704
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
705
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		}
679 707
 
680 708
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
681
-		if ($start != $tmpMaxPages && $show_prevnext)
682
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
709
+		if ($start != $tmpMaxPages && $show_prevnext) {
710
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		}
683 712
 	}
684 713
 	$pageindex .= $settings['page_index']['extra_after'];
685 714
 
@@ -705,8 +734,9 @@  discard block
 block discarded – undo
705 734
 	if ($decimal_separator === null)
706 735
 	{
707 736
 		// Not set for whatever reason?
708
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
709
-			return $number;
737
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
738
+					return $number;
739
+		}
710 740
 
711 741
 		// Cache these each load...
712 742
 		$thousands_separator = $matches[1];
@@ -740,17 +770,20 @@  discard block
 block discarded – undo
740 770
 	static $unsupportedFormats, $finalizedFormats;
741 771
 
742 772
 	// Offset the time.
743
-	if (!$offset_type)
744
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
773
+	if (!$offset_type) {
774
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
775
+	}
745 776
 	// Just the forum offset?
746
-	elseif ($offset_type == 'forum')
747
-		$time = $log_time + $modSettings['time_offset'] * 3600;
748
-	else
749
-		$time = $log_time;
777
+	elseif ($offset_type == 'forum') {
778
+			$time = $log_time + $modSettings['time_offset'] * 3600;
779
+	} else {
780
+			$time = $log_time;
781
+	}
750 782
 
751 783
 	// We can't have a negative date (on Windows, at least.)
752
-	if ($log_time < 0)
753
-		$log_time = 0;
784
+	if ($log_time < 0) {
785
+			$log_time = 0;
786
+	}
754 787
 
755 788
 	// Today and Yesterday?
756 789
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -767,24 +800,27 @@  discard block
 block discarded – undo
767 800
 		{
768 801
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
769 802
 			$today_fmt = $h . ':%M' . $s . ' %p';
803
+		} else {
804
+					$today_fmt = '%H:%M' . $s;
770 805
 		}
771
-		else
772
-			$today_fmt = '%H:%M' . $s;
773 806
 
774 807
 		// Same day of the year, same year.... Today!
775
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
776
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
808
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
809
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
810
+		}
777 811
 
778 812
 		// 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...
779
-		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))
780
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
813
+		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)) {
814
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
815
+		}
781 816
 	}
782 817
 
783 818
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
784 819
 
785 820
 	// Use the cached formats if available
786
-	if (is_null($finalizedFormats))
787
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
821
+	if (is_null($finalizedFormats)) {
822
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
823
+	}
788 824
 
789 825
 	// Make a supported version for this format if we don't already have one
790 826
 	if (empty($finalizedFormats[$str]))
@@ -813,8 +849,9 @@  discard block
 block discarded – undo
813 849
 		);
814 850
 
815 851
 		// No need to do this part again if we already did it once
816
-		if (is_null($unsupportedFormats))
817
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
852
+		if (is_null($unsupportedFormats)) {
853
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
854
+		}
818 855
 		if (empty($unsupportedFormats))
819 856
 		{
820 857
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -823,20 +860,23 @@  discard block
 block discarded – undo
823 860
 
824 861
 				// Windows will return false for unsupported formats
825 862
 				// Other operating systems return the format string as a literal
826
-				if ($value === false || $value === $format)
827
-					$unsupportedFormats[] = $format;
863
+				if ($value === false || $value === $format) {
864
+									$unsupportedFormats[] = $format;
865
+				}
828 866
 			}
829 867
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
830 868
 		}
831 869
 
832 870
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
833
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
834
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
871
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
872
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
873
+		}
835 874
 
836 875
 		// Substitute unsupported formats with supported ones
837
-		if (!empty($unsupportedFormats))
838
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
876
+		if (!empty($unsupportedFormats)) {
877
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
839 878
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
879
+		}
840 880
 
841 881
 		// Remember this so we don't need to do it again
842 882
 		$finalizedFormats[$str] = $timeformat;
@@ -845,33 +885,39 @@  discard block
 block discarded – undo
845 885
 
846 886
 	$str = $finalizedFormats[$str];
847 887
 
848
-	if (!isset($locale_cache))
849
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale']);
888
+	if (!isset($locale_cache)) {
889
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale']);
890
+	}
850 891
 
851 892
 	if ($locale_cache !== false)
852 893
 	{
853 894
 		// Check if another process changed the locale
854
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
855
-			setlocale(LC_TIME, $txt['lang_locale']);
895
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
896
+					setlocale(LC_TIME, $txt['lang_locale']);
897
+		}
856 898
 
857
-		if (!isset($non_twelve_hour))
858
-			$non_twelve_hour = trim(strftime('%p')) === '';
859
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
860
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
899
+		if (!isset($non_twelve_hour)) {
900
+					$non_twelve_hour = trim(strftime('%p')) === '';
901
+		}
902
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
903
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
904
+		}
861 905
 
862
-		foreach (array('%a', '%A', '%b', '%B') as $token)
863
-			if (strpos($str, $token) !== false)
906
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
907
+					if (strpos($str, $token) !== false)
864 908
 				$str = str_replace($token, strftime($token, $time), $str);
865
-	}
866
-	else
909
+		}
910
+	} else
867 911
 	{
868 912
 		// Do-it-yourself time localization.  Fun.
869
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
870
-			if (strpos($str, $token) !== false)
913
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
914
+					if (strpos($str, $token) !== false)
871 915
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
916
+		}
872 917
 
873
-		if (strpos($str, '%p') !== false)
874
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
918
+		if (strpos($str, '%p') !== false) {
919
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
920
+		}
875 921
 	}
876 922
 
877 923
 	// Format the time and then restore any literal percent characters
@@ -894,16 +940,19 @@  discard block
 block discarded – undo
894 940
 	static $translation = array();
895 941
 
896 942
 	// Determine the character set... Default to UTF-8
897
-	if (empty($context['character_set']))
898
-		$charset = 'UTF-8';
943
+	if (empty($context['character_set'])) {
944
+			$charset = 'UTF-8';
945
+	}
899 946
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
900
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
901
-		$charset = 'ISO-8859-1';
902
-	else
903
-		$charset = $context['character_set'];
947
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
948
+			$charset = 'ISO-8859-1';
949
+	} else {
950
+			$charset = $context['character_set'];
951
+	}
904 952
 
905
-	if (empty($translation))
906
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
953
+	if (empty($translation)) {
954
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
955
+	}
907 956
 
908 957
 	return strtr($string, $translation);
909 958
 }
@@ -925,8 +974,9 @@  discard block
 block discarded – undo
925 974
 	global $smcFunc;
926 975
 
927 976
 	// It was already short enough!
928
-	if ($smcFunc['strlen']($subject) <= $len)
929
-		return $subject;
977
+	if ($smcFunc['strlen']($subject) <= $len) {
978
+			return $subject;
979
+	}
930 980
 
931 981
 	// Shorten it by the length it was too long, and strip off junk from the end.
932 982
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -945,10 +995,11 @@  discard block
 block discarded – undo
945 995
 {
946 996
 	global $user_info, $modSettings;
947 997
 
948
-	if ($timestamp === null)
949
-		$timestamp = time();
950
-	elseif ($timestamp == 0)
951
-		return 0;
998
+	if ($timestamp === null) {
999
+			$timestamp = time();
1000
+	} elseif ($timestamp == 0) {
1001
+			return 0;
1002
+	}
952 1003
 
953 1004
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
954 1005
 }
@@ -977,8 +1028,9 @@  discard block
 block discarded – undo
977 1028
 		$array[$i] = $array[$j];
978 1029
 		$array[$j] = $temp;
979 1030
 
980
-		for ($i = 1; $p[$i] == 0; $i++)
981
-			$p[$i] = 1;
1031
+		for ($i = 1; $p[$i] == 0; $i++) {
1032
+					$p[$i] = 1;
1033
+		}
982 1034
 
983 1035
 		$orders[] = $array;
984 1036
 	}
@@ -1010,12 +1062,14 @@  discard block
 block discarded – undo
1010 1062
 	static $disabled;
1011 1063
 
1012 1064
 	// Don't waste cycles
1013
-	if ($message === '')
1014
-		return '';
1065
+	if ($message === '') {
1066
+			return '';
1067
+	}
1015 1068
 
1016 1069
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1017
-	if (!isset($context['utf8']))
1018
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1070
+	if (!isset($context['utf8'])) {
1071
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1072
+	}
1019 1073
 
1020 1074
 	// Clean up any cut/paste issues we may have
1021 1075
 	$message = sanitizeMSCutPaste($message);
@@ -1027,13 +1081,15 @@  discard block
 block discarded – undo
1027 1081
 		return $message;
1028 1082
 	}
1029 1083
 
1030
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1031
-		$smileys = (bool) $smileys;
1084
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1085
+			$smileys = (bool) $smileys;
1086
+	}
1032 1087
 
1033 1088
 	if (empty($modSettings['enableBBC']) && $message !== false)
1034 1089
 	{
1035
-		if ($smileys === true)
1036
-			parsesmileys($message);
1090
+		if ($smileys === true) {
1091
+					parsesmileys($message);
1092
+		}
1037 1093
 
1038 1094
 		return $message;
1039 1095
 	}
@@ -1046,8 +1102,9 @@  discard block
 block discarded – undo
1046 1102
 	}
1047 1103
 
1048 1104
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1049
-	if (!empty($modSettings['autoLinkUrls']))
1050
-		set_tld_regex();
1105
+	if (!empty($modSettings['autoLinkUrls'])) {
1106
+			set_tld_regex();
1107
+	}
1051 1108
 
1052 1109
 	// Allow mods access before entering the main parse_bbc loop
1053 1110
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1061,12 +1118,14 @@  discard block
 block discarded – undo
1061 1118
 
1062 1119
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1063 1120
 
1064
-			foreach ($temp as $tag)
1065
-				$disabled[trim($tag)] = true;
1121
+			foreach ($temp as $tag) {
1122
+							$disabled[trim($tag)] = true;
1123
+			}
1066 1124
 		}
1067 1125
 
1068
-		if (empty($modSettings['enableEmbeddedFlash']))
1069
-			$disabled['flash'] = true;
1126
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1127
+					$disabled['flash'] = true;
1128
+		}
1070 1129
 
1071 1130
 		/* The following bbc are formatted as an array, with keys as follows:
1072 1131
 
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 					$returnContext = '';
1188 1247
 
1189 1248
 					// BBC or the entire attachments feature is disabled
1190
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1191
-						return $data;
1249
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1250
+											return $data;
1251
+					}
1192 1252
 
1193 1253
 					// Save the attach ID.
1194 1254
 					$attachID = $data;
@@ -1199,8 +1259,9 @@  discard block
 block discarded – undo
1199 1259
 					$currentAttachment = parseAttachBBC($attachID);
1200 1260
 
1201 1261
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1202
-					if (is_string($currentAttachment))
1203
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1262
+					if (is_string($currentAttachment)) {
1263
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1264
+					}
1204 1265
 
1205 1266
 					if (!empty($currentAttachment['is_image']))
1206 1267
 					{
@@ -1216,15 +1277,17 @@  discard block
 block discarded – undo
1216 1277
 							$height = ' height="' . $currentAttachment['height'] . '"';
1217 1278
 						}
1218 1279
 
1219
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1220
-							$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>';
1221
-						else
1222
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1280
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1281
+													$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>';
1282
+						} else {
1283
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1284
+						}
1223 1285
 					}
1224 1286
 
1225 1287
 					// No image. Show a link.
1226
-					else
1227
-						$returnContext .= $currentAttachment['link'];
1288
+					else {
1289
+											$returnContext .= $currentAttachment['link'];
1290
+					}
1228 1291
 
1229 1292
 					// Gotta append what we just did.
1230 1293
 					$data = $returnContext;
@@ -1255,8 +1318,9 @@  discard block
 block discarded – undo
1255 1318
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1256 1319
 						{
1257 1320
 							// Do PHP code coloring?
1258
-							if ($php_parts[$php_i] != '&lt;?php')
1259
-								continue;
1321
+							if ($php_parts[$php_i] != '&lt;?php') {
1322
+															continue;
1323
+							}
1260 1324
 
1261 1325
 							$php_string = '';
1262 1326
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1272,8 +1336,9 @@  discard block
 block discarded – undo
1272 1336
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1273 1337
 
1274 1338
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1275
-						if ($context['browser']['is_opera'])
1276
-							$data .= '&nbsp;';
1339
+						if ($context['browser']['is_opera']) {
1340
+													$data .= '&nbsp;';
1341
+						}
1277 1342
 					}
1278 1343
 				},
1279 1344
 				'block_level' => true,
@@ -1292,8 +1357,9 @@  discard block
 block discarded – undo
1292 1357
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1293 1358
 						{
1294 1359
 							// Do PHP code coloring?
1295
-							if ($php_parts[$php_i] != '&lt;?php')
1296
-								continue;
1360
+							if ($php_parts[$php_i] != '&lt;?php') {
1361
+															continue;
1362
+							}
1297 1363
 
1298 1364
 							$php_string = '';
1299 1365
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1309,8 +1375,9 @@  discard block
 block discarded – undo
1309 1375
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1310 1376
 
1311 1377
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1312
-						if ($context['browser']['is_opera'])
1313
-							$data[0] .= '&nbsp;';
1378
+						if ($context['browser']['is_opera']) {
1379
+													$data[0] .= '&nbsp;';
1380
+						}
1314 1381
 					}
1315 1382
 				},
1316 1383
 				'block_level' => true,
@@ -1348,11 +1415,13 @@  discard block
 block discarded – undo
1348 1415
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1349 1416
 				'validate' => function (&$tag, &$data, $disabled)
1350 1417
 				{
1351
-					if (isset($disabled['url']))
1352
-						$tag['content'] = '$1';
1418
+					if (isset($disabled['url'])) {
1419
+											$tag['content'] = '$1';
1420
+					}
1353 1421
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1354
-					if (empty($scheme))
1355
-						$data[0] = '//' . ltrim($data[0], ':/');
1422
+					if (empty($scheme)) {
1423
+											$data[0] = '//' . ltrim($data[0], ':/');
1424
+					}
1356 1425
 				},
1357 1426
 				'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>',
1358 1427
 			),
@@ -1366,10 +1435,11 @@  discard block
 block discarded – undo
1366 1435
 				{
1367 1436
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1368 1437
 
1369
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1370
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1371
-					else
1372
-						$css = '';
1438
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1439
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1440
+					} else {
1441
+											$css = '';
1442
+					}
1373 1443
 
1374 1444
 					$data = $class . $css;
1375 1445
 				},
@@ -1419,20 +1489,23 @@  discard block
 block discarded – undo
1419 1489
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1420 1490
 					if ($image_proxy_enabled)
1421 1491
 					{
1422
-						if (!empty($user_info['possibly_robot']))
1423
-							return;
1492
+						if (!empty($user_info['possibly_robot'])) {
1493
+													return;
1494
+						}
1424 1495
 
1425
-						if (empty($scheme))
1426
-							$data = 'http://' . ltrim($data, ':/');
1496
+						if (empty($scheme)) {
1497
+													$data = 'http://' . ltrim($data, ':/');
1498
+						}
1427 1499
 
1428
-						if ($scheme != 'https')
1429
-							if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
1500
+						if ($scheme != 'https') {
1501
+													if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
1430 1502
 								$data = $image_proxy_url . urlencode($data);
1431
-							else
1432
-								$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1503
+						} else {
1504
+															$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1505
+							}
1506
+					} elseif (empty($scheme)) {
1507
+											$data = '//' . ltrim($data, ':/');
1433 1508
 					}
1434
-					elseif (empty($scheme))
1435
-						$data = '//' . ltrim($data, ':/');
1436 1509
 				},
1437 1510
 				'disabled_content' => '($1)',
1438 1511
 			),
@@ -1448,20 +1521,23 @@  discard block
 block discarded – undo
1448 1521
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1449 1522
 					if ($image_proxy_enabled)
1450 1523
 					{
1451
-						if (!empty($user_info['possibly_robot']))
1452
-							return;
1524
+						if (!empty($user_info['possibly_robot'])) {
1525
+													return;
1526
+						}
1453 1527
 
1454
-						if (empty($scheme))
1455
-							$data = 'http://' . ltrim($data, ':/');
1528
+						if (empty($scheme)) {
1529
+													$data = 'http://' . ltrim($data, ':/');
1530
+						}
1456 1531
 
1457
-						if ($scheme != 'https')
1458
-							if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
1532
+						if ($scheme != 'https') {
1533
+													if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
1459 1534
 								$data = $image_proxy_url . urlencode($data);
1460
-							else
1461
-								$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1535
+						} else {
1536
+															$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1537
+							}
1538
+					} elseif (empty($scheme)) {
1539
+											$data = '//' . ltrim($data, ':/');
1462 1540
 					}
1463
-					elseif (empty($scheme))
1464
-						$data = '//' . ltrim($data, ':/');
1465 1541
 				},
1466 1542
 				'disabled_content' => '($1)',
1467 1543
 			),
@@ -1473,8 +1549,9 @@  discard block
 block discarded – undo
1473 1549
 				{
1474 1550
 					$data = strtr($data, array('<br>' => ''));
1475 1551
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1476
-					if (empty($scheme))
1477
-						$data = '//' . ltrim($data, ':/');
1552
+					if (empty($scheme)) {
1553
+											$data = '//' . ltrim($data, ':/');
1554
+					}
1478 1555
 				},
1479 1556
 			),
1480 1557
 			array(
@@ -1485,13 +1562,14 @@  discard block
 block discarded – undo
1485 1562
 				'after' => '</a>',
1486 1563
 				'validate' => function (&$tag, &$data, $disabled)
1487 1564
 				{
1488
-					if (substr($data, 0, 1) == '#')
1489
-						$data = '#post_' . substr($data, 1);
1490
-					else
1565
+					if (substr($data, 0, 1) == '#') {
1566
+											$data = '#post_' . substr($data, 1);
1567
+					} else
1491 1568
 					{
1492 1569
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1493
-						if (empty($scheme))
1494
-							$data = '//' . ltrim($data, ':/');
1570
+						if (empty($scheme)) {
1571
+													$data = '//' . ltrim($data, ':/');
1572
+						}
1495 1573
 					}
1496 1574
 				},
1497 1575
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1569,8 +1647,9 @@  discard block
 block discarded – undo
1569 1647
 					{
1570 1648
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1571 1649
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1572
-						if ($add_begin)
1573
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1650
+						if ($add_begin) {
1651
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1652
+						}
1574 1653
 					}
1575 1654
 				},
1576 1655
 				'block_level' => false,
@@ -1701,10 +1780,11 @@  discard block
 block discarded – undo
1701 1780
 				'content' => '$1',
1702 1781
 				'validate' => function (&$tag, &$data, $disabled)
1703 1782
 				{
1704
-					if (is_numeric($data))
1705
-						$data = timeformat($data);
1706
-					else
1707
-						$tag['content'] = '[time]$1[/time]';
1783
+					if (is_numeric($data)) {
1784
+											$data = timeformat($data);
1785
+					} else {
1786
+											$tag['content'] = '[time]$1[/time]';
1787
+					}
1708 1788
 				},
1709 1789
 			),
1710 1790
 			array(
@@ -1731,8 +1811,9 @@  discard block
 block discarded – undo
1731 1811
 				{
1732 1812
 					$data = strtr($data, array('<br>' => ''));
1733 1813
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1734
-					if (empty($scheme))
1735
-						$data = '//' . ltrim($data, ':/');
1814
+					if (empty($scheme)) {
1815
+											$data = '//' . ltrim($data, ':/');
1816
+					}
1736 1817
 				},
1737 1818
 			),
1738 1819
 			array(
@@ -1744,8 +1825,9 @@  discard block
 block discarded – undo
1744 1825
 				'validate' => function (&$tag, &$data, $disabled)
1745 1826
 				{
1746 1827
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1747
-					if (empty($scheme))
1748
-						$data = '//' . ltrim($data, ':/');
1828
+					if (empty($scheme)) {
1829
+											$data = '//' . ltrim($data, ':/');
1830
+					}
1749 1831
 				},
1750 1832
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1751 1833
 				'disabled_after' => ' ($1)',
@@ -1765,8 +1847,9 @@  discard block
 block discarded – undo
1765 1847
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1766 1848
 		if ($message === false)
1767 1849
 		{
1768
-			if (isset($temp_bbc))
1769
-				$bbc_codes = $temp_bbc;
1850
+			if (isset($temp_bbc)) {
1851
+							$bbc_codes = $temp_bbc;
1852
+			}
1770 1853
 			usort($codes, function ($a, $b) {
1771 1854
 				return strcmp($a['tag'], $b['tag']);
1772 1855
 			});
@@ -1786,8 +1869,9 @@  discard block
 block discarded – undo
1786 1869
 		);
1787 1870
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1788 1871
 		{
1789
-			foreach ($itemcodes as $c => $dummy)
1790
-				$bbc_codes[$c] = array();
1872
+			foreach ($itemcodes as $c => $dummy) {
1873
+							$bbc_codes[$c] = array();
1874
+			}
1791 1875
 		}
1792 1876
 
1793 1877
 		// Shhhh!
@@ -1808,12 +1892,14 @@  discard block
 block discarded – undo
1808 1892
 		foreach ($codes as $code)
1809 1893
 		{
1810 1894
 			// Make it easier to process parameters later
1811
-			if (!empty($code['parameters']))
1812
-				ksort($code['parameters'], SORT_STRING);
1895
+			if (!empty($code['parameters'])) {
1896
+							ksort($code['parameters'], SORT_STRING);
1897
+			}
1813 1898
 
1814 1899
 			// If we are not doing every tag only do ones we are interested in.
1815
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1816
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1900
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1901
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1902
+			}
1817 1903
 		}
1818 1904
 		$codes = null;
1819 1905
 	}
@@ -1824,8 +1910,9 @@  discard block
 block discarded – undo
1824 1910
 		// It's likely this will change if the message is modified.
1825 1911
 		$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']);
1826 1912
 
1827
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1828
-			return $temp;
1913
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1914
+					return $temp;
1915
+		}
1829 1916
 
1830 1917
 		$cache_t = microtime();
1831 1918
 	}
@@ -1857,8 +1944,9 @@  discard block
 block discarded – undo
1857 1944
 		$disabled['flash'] = true;
1858 1945
 
1859 1946
 		// @todo Change maybe?
1860
-		if (!isset($_GET['images']))
1861
-			$disabled['img'] = true;
1947
+		if (!isset($_GET['images'])) {
1948
+					$disabled['img'] = true;
1949
+		}
1862 1950
 
1863 1951
 		// @todo Interface/setting to add more?
1864 1952
 	}
@@ -1882,8 +1970,9 @@  discard block
 block discarded – undo
1882 1970
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1883 1971
 
1884 1972
 		// Failsafe.
1885
-		if ($pos === false || $last_pos > $pos)
1886
-			$pos = strlen($message) + 1;
1973
+		if ($pos === false || $last_pos > $pos) {
1974
+					$pos = strlen($message) + 1;
1975
+		}
1887 1976
 
1888 1977
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1889 1978
 		if ($last_pos < $pos - 1)
@@ -1901,8 +1990,9 @@  discard block
 block discarded – undo
1901 1990
 
1902 1991
 				// <br> should be empty.
1903 1992
 				$empty_tags = array('br', 'hr');
1904
-				foreach ($empty_tags as $tag)
1905
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
1993
+				foreach ($empty_tags as $tag) {
1994
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
1995
+				}
1906 1996
 
1907 1997
 				// b, u, i, s, pre... basic tags.
1908 1998
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -1911,8 +2001,9 @@  discard block
 block discarded – undo
1911 2001
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1912 2002
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1913 2003
 
1914
-					if ($diff > 0)
1915
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2004
+					if ($diff > 0) {
2005
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2006
+					}
1916 2007
 				}
1917 2008
 
1918 2009
 				// Do <img ...> - with security... action= -> action-.
@@ -1925,8 +2016,9 @@  discard block
 block discarded – undo
1925 2016
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1926 2017
 
1927 2018
 						// Remove action= from the URL - no funny business, now.
1928
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1929
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2019
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2020
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2021
+						}
1930 2022
 
1931 2023
 						// Check if the image is larger than allowed.
1932 2024
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1947,9 +2039,9 @@  discard block
 block discarded – undo
1947 2039
 
1948 2040
 							// Set the new image tag.
1949 2041
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
2042
+						} else {
2043
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1950 2044
 						}
1951
-						else
1952
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1953 2045
 					}
1954 2046
 
1955 2047
 					$data = strtr($data, $replaces);
@@ -1962,16 +2054,18 @@  discard block
 block discarded – undo
1962 2054
 				$no_autolink_area = false;
1963 2055
 				if (!empty($open_tags))
1964 2056
 				{
1965
-					foreach ($open_tags as $open_tag)
1966
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2057
+					foreach ($open_tags as $open_tag) {
2058
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1967 2059
 							$no_autolink_area = true;
2060
+					}
1968 2061
 				}
1969 2062
 
1970 2063
 				// Don't go backwards.
1971 2064
 				// @todo Don't think is the real solution....
1972 2065
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1973
-				if ($pos < $lastAutoPos)
1974
-					$no_autolink_area = true;
2066
+				if ($pos < $lastAutoPos) {
2067
+									$no_autolink_area = true;
2068
+				}
1975 2069
 				$lastAutoPos = $pos;
1976 2070
 
1977 2071
 				if (!$no_autolink_area)
@@ -2080,17 +2174,19 @@  discard block
 block discarded – undo
2080 2174
 							if ($scheme == 'mailto')
2081 2175
 							{
2082 2176
 								$email_address = str_replace('mailto:', '', $url);
2083
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2084
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2085
-								else
2086
-									return $url;
2177
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2178
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2179
+								} else {
2180
+																	return $url;
2181
+								}
2087 2182
 							}
2088 2183
 
2089 2184
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2090
-							if (empty($scheme))
2091
-								$fullUrl = '//' . ltrim($url, ':/');
2092
-							else
2093
-								$fullUrl = $url;
2185
+							if (empty($scheme)) {
2186
+															$fullUrl = '//' . ltrim($url, ':/');
2187
+							} else {
2188
+															$fullUrl = $url;
2189
+							}
2094 2190
 
2095 2191
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2096 2192
 						}, $data);
@@ -2139,22 +2235,25 @@  discard block
 block discarded – undo
2139 2235
 		}
2140 2236
 
2141 2237
 		// Are we there yet?  Are we there yet?
2142
-		if ($pos >= strlen($message) - 1)
2143
-			break;
2238
+		if ($pos >= strlen($message) - 1) {
2239
+					break;
2240
+		}
2144 2241
 
2145 2242
 		$tags = strtolower($message[$pos + 1]);
2146 2243
 
2147 2244
 		if ($tags == '/' && !empty($open_tags))
2148 2245
 		{
2149 2246
 			$pos2 = strpos($message, ']', $pos + 1);
2150
-			if ($pos2 == $pos + 2)
2151
-				continue;
2247
+			if ($pos2 == $pos + 2) {
2248
+							continue;
2249
+			}
2152 2250
 
2153 2251
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2154 2252
 
2155 2253
 			// A closing tag that doesn't match any open tags? Skip it.
2156
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2157
-				continue;
2254
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2255
+							continue;
2256
+			}
2158 2257
 
2159 2258
 			$to_close = array();
2160 2259
 			$block_level = null;
@@ -2162,8 +2261,9 @@  discard block
 block discarded – undo
2162 2261
 			do
2163 2262
 			{
2164 2263
 				$tag = array_pop($open_tags);
2165
-				if (!$tag)
2166
-					break;
2264
+				if (!$tag) {
2265
+									break;
2266
+				}
2167 2267
 
2168 2268
 				if (!empty($tag['block_level']))
2169 2269
 				{
@@ -2177,10 +2277,11 @@  discard block
 block discarded – undo
2177 2277
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2178 2278
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2179 2279
 					{
2180
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2181
-							if ($temp['tag'] == $look_for)
2280
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2281
+													if ($temp['tag'] == $look_for)
2182 2282
 							{
2183 2283
 								$block_level = !empty($temp['block_level']);
2284
+						}
2184 2285
 								break;
2185 2286
 							}
2186 2287
 					}
@@ -2202,15 +2303,15 @@  discard block
 block discarded – undo
2202 2303
 			{
2203 2304
 				$open_tags = $to_close;
2204 2305
 				continue;
2205
-			}
2206
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2306
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2207 2307
 			{
2208 2308
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2209 2309
 				{
2210
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2211
-						if ($temp['tag'] == $look_for)
2310
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2311
+											if ($temp['tag'] == $look_for)
2212 2312
 						{
2213 2313
 							$block_level = !empty($temp['block_level']);
2314
+					}
2214 2315
 							break;
2215 2316
 						}
2216 2317
 				}
@@ -2218,8 +2319,9 @@  discard block
 block discarded – undo
2218 2319
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2219 2320
 				if (!$block_level)
2220 2321
 				{
2221
-					foreach ($to_close as $tag)
2222
-						array_push($open_tags, $tag);
2322
+					foreach ($to_close as $tag) {
2323
+											array_push($open_tags, $tag);
2324
+					}
2223 2325
 					continue;
2224 2326
 				}
2225 2327
 			}
@@ -2232,14 +2334,17 @@  discard block
 block discarded – undo
2232 2334
 
2233 2335
 				// See the comment at the end of the big loop - just eating whitespace ;).
2234 2336
 				$whitespace_regex = '';
2235
-				if (!empty($tag['block_level']))
2236
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2337
+				if (!empty($tag['block_level'])) {
2338
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2339
+				}
2237 2340
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2238
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2239
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2341
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2342
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2343
+				}
2240 2344
 
2241
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2242
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2345
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2346
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2347
+				}
2243 2348
 			}
2244 2349
 
2245 2350
 			if (!empty($to_close))
@@ -2252,8 +2357,9 @@  discard block
 block discarded – undo
2252 2357
 		}
2253 2358
 
2254 2359
 		// No tags for this character, so just keep going (fastest possible course.)
2255
-		if (!isset($bbc_codes[$tags]))
2256
-			continue;
2360
+		if (!isset($bbc_codes[$tags])) {
2361
+					continue;
2362
+		}
2257 2363
 
2258 2364
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2259 2365
 		$tag = null;
@@ -2262,48 +2368,57 @@  discard block
 block discarded – undo
2262 2368
 			$pt_strlen = strlen($possible['tag']);
2263 2369
 
2264 2370
 			// Not a match?
2265
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2266
-				continue;
2371
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2372
+							continue;
2373
+			}
2267 2374
 
2268 2375
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2269 2376
 
2270 2377
 			// A tag is the last char maybe
2271
-			if ($next_c == '')
2272
-				break;
2378
+			if ($next_c == '') {
2379
+							break;
2380
+			}
2273 2381
 
2274 2382
 			// A test validation?
2275
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2276
-				continue;
2383
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2384
+							continue;
2385
+			}
2277 2386
 			// Do we want parameters?
2278 2387
 			elseif (!empty($possible['parameters']))
2279 2388
 			{
2280
-				if ($next_c != ' ')
2281
-					continue;
2282
-			}
2283
-			elseif (isset($possible['type']))
2389
+				if ($next_c != ' ') {
2390
+									continue;
2391
+				}
2392
+			} elseif (isset($possible['type']))
2284 2393
 			{
2285 2394
 				// Do we need an equal sign?
2286
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2287
-					continue;
2395
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2396
+									continue;
2397
+				}
2288 2398
 				// Maybe we just want a /...
2289
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2290
-					continue;
2399
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2400
+									continue;
2401
+				}
2291 2402
 				// An immediate ]?
2292
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2293
-					continue;
2403
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2404
+									continue;
2405
+				}
2294 2406
 			}
2295 2407
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2296
-			elseif ($next_c != ']')
2297
-				continue;
2408
+			elseif ($next_c != ']') {
2409
+							continue;
2410
+			}
2298 2411
 
2299 2412
 			// Check allowed tree?
2300
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2301
-				continue;
2302
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2303
-				continue;
2413
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2414
+							continue;
2415
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2416
+							continue;
2417
+			}
2304 2418
 			// If this is in the list of disallowed child tags, don't parse it.
2305
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2306
-				continue;
2419
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2420
+							continue;
2421
+			}
2307 2422
 
2308 2423
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2309 2424
 
@@ -2315,8 +2430,9 @@  discard block
 block discarded – undo
2315 2430
 				foreach ($open_tags as $open_quote)
2316 2431
 				{
2317 2432
 					// Every parent quote this quote has flips the styling
2318
-					if ($open_quote['tag'] == 'quote')
2319
-						$quote_alt = !$quote_alt;
2433
+					if ($open_quote['tag'] == 'quote') {
2434
+											$quote_alt = !$quote_alt;
2435
+					}
2320 2436
 				}
2321 2437
 				// Add a class to the quote to style alternating blockquotes
2322 2438
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2327,8 +2443,9 @@  discard block
 block discarded – undo
2327 2443
 			{
2328 2444
 				// Build a regular expression for each parameter for the current tag.
2329 2445
 				$preg = array();
2330
-				foreach ($possible['parameters'] as $p => $info)
2331
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2446
+				foreach ($possible['parameters'] as $p => $info) {
2447
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2448
+				}
2332 2449
 
2333 2450
 				// Extract the string that potentially holds our parameters.
2334 2451
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2348,24 +2465,27 @@  discard block
 block discarded – undo
2348 2465
 
2349 2466
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2350 2467
 
2351
-					if ($match)
2352
-						$blob_counter = count($blobs) + 1;
2468
+					if ($match) {
2469
+											$blob_counter = count($blobs) + 1;
2470
+					}
2353 2471
 				}
2354 2472
 
2355 2473
 				// Didn't match our parameter list, try the next possible.
2356
-				if (!$match)
2357
-					continue;
2474
+				if (!$match) {
2475
+									continue;
2476
+				}
2358 2477
 
2359 2478
 				$params = array();
2360 2479
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2361 2480
 				{
2362 2481
 					$key = strtok(ltrim($matches[$i]), '=');
2363
-					if (isset($possible['parameters'][$key]['value']))
2364
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2365
-					elseif (isset($possible['parameters'][$key]['validate']))
2366
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2367
-					else
2368
-						$params['{' . $key . '}'] = $matches[$i + 1];
2482
+					if (isset($possible['parameters'][$key]['value'])) {
2483
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2484
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2485
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2486
+					} else {
2487
+											$params['{' . $key . '}'] = $matches[$i + 1];
2488
+					}
2369 2489
 
2370 2490
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2371 2491
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2373,23 +2493,26 @@  discard block
 block discarded – undo
2373 2493
 
2374 2494
 				foreach ($possible['parameters'] as $p => $info)
2375 2495
 				{
2376
-					if (!isset($params['{' . $p . '}']))
2377
-						$params['{' . $p . '}'] = '';
2496
+					if (!isset($params['{' . $p . '}'])) {
2497
+											$params['{' . $p . '}'] = '';
2498
+					}
2378 2499
 				}
2379 2500
 
2380 2501
 				$tag = $possible;
2381 2502
 
2382 2503
 				// Put the parameters into the string.
2383
-				if (isset($tag['before']))
2384
-					$tag['before'] = strtr($tag['before'], $params);
2385
-				if (isset($tag['after']))
2386
-					$tag['after'] = strtr($tag['after'], $params);
2387
-				if (isset($tag['content']))
2388
-					$tag['content'] = strtr($tag['content'], $params);
2504
+				if (isset($tag['before'])) {
2505
+									$tag['before'] = strtr($tag['before'], $params);
2506
+				}
2507
+				if (isset($tag['after'])) {
2508
+									$tag['after'] = strtr($tag['after'], $params);
2509
+				}
2510
+				if (isset($tag['content'])) {
2511
+									$tag['content'] = strtr($tag['content'], $params);
2512
+				}
2389 2513
 
2390 2514
 				$pos1 += strlen($given_param_string);
2391
-			}
2392
-			else
2515
+			} else
2393 2516
 			{
2394 2517
 				$tag = $possible;
2395 2518
 				$params = array();
@@ -2400,8 +2523,9 @@  discard block
 block discarded – undo
2400 2523
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2401 2524
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2402 2525
 		{
2403
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2404
-				continue;
2526
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2527
+							continue;
2528
+			}
2405 2529
 
2406 2530
 			$tag = $itemcodes[$message[$pos + 1]];
2407 2531
 
@@ -2422,9 +2546,9 @@  discard block
 block discarded – undo
2422 2546
 			{
2423 2547
 				array_pop($open_tags);
2424 2548
 				$code = '</li>';
2549
+			} else {
2550
+							$code = '';
2425 2551
 			}
2426
-			else
2427
-				$code = '';
2428 2552
 
2429 2553
 			// Now we open a new tag.
2430 2554
 			$open_tags[] = array(
@@ -2471,12 +2595,14 @@  discard block
 block discarded – undo
2471 2595
 		}
2472 2596
 
2473 2597
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2474
-		if ($tag === null)
2475
-			continue;
2598
+		if ($tag === null) {
2599
+					continue;
2600
+		}
2476 2601
 
2477 2602
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2478
-		if (isset($inside['disallow_children']))
2479
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2603
+		if (isset($inside['disallow_children'])) {
2604
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2605
+		}
2480 2606
 
2481 2607
 		// Is this tag disabled?
2482 2608
 		if (isset($disabled[$tag['tag']]))
@@ -2486,14 +2612,13 @@  discard block
 block discarded – undo
2486 2612
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2487 2613
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2488 2614
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2489
-			}
2490
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2615
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2491 2616
 			{
2492 2617
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2493 2618
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2619
+			} else {
2620
+							$tag['content'] = $tag['disabled_content'];
2494 2621
 			}
2495
-			else
2496
-				$tag['content'] = $tag['disabled_content'];
2497 2622
 		}
2498 2623
 
2499 2624
 		// we use this a lot
@@ -2503,8 +2628,9 @@  discard block
 block discarded – undo
2503 2628
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2504 2629
 		{
2505 2630
 			$n = count($open_tags) - 1;
2506
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2507
-				$n--;
2631
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2632
+							$n--;
2633
+			}
2508 2634
 
2509 2635
 			// Close all the non block level tags so this tag isn't surrounded by them.
2510 2636
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2516,12 +2642,15 @@  discard block
 block discarded – undo
2516 2642
 
2517 2643
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2518 2644
 				$whitespace_regex = '';
2519
-				if (!empty($tag['block_level']))
2520
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2521
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2522
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2523
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2524
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2645
+				if (!empty($tag['block_level'])) {
2646
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2647
+				}
2648
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2649
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2650
+				}
2651
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2652
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2653
+				}
2525 2654
 
2526 2655
 				array_pop($open_tags);
2527 2656
 			}
@@ -2542,16 +2671,19 @@  discard block
 block discarded – undo
2542 2671
 		elseif ($tag['type'] == 'unparsed_content')
2543 2672
 		{
2544 2673
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2545
-			if ($pos2 === false)
2546
-				continue;
2674
+			if ($pos2 === false) {
2675
+							continue;
2676
+			}
2547 2677
 
2548 2678
 			$data = substr($message, $pos1, $pos2 - $pos1);
2549 2679
 
2550
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2551
-				$data = substr($data, 4);
2680
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2681
+							$data = substr($data, 4);
2682
+			}
2552 2683
 
2553
-			if (isset($tag['validate']))
2554
-				$tag['validate']($tag, $data, $disabled, $params);
2684
+			if (isset($tag['validate'])) {
2685
+							$tag['validate']($tag, $data, $disabled, $params);
2686
+			}
2555 2687
 
2556 2688
 			$code = strtr($tag['content'], array('$1' => $data));
2557 2689
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2567,34 +2699,40 @@  discard block
 block discarded – undo
2567 2699
 			if (isset($tag['quoted']))
2568 2700
 			{
2569 2701
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2570
-				if ($tag['quoted'] != 'optional' && !$quoted)
2571
-					continue;
2702
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2703
+									continue;
2704
+				}
2572 2705
 
2573
-				if ($quoted)
2574
-					$pos1 += 6;
2706
+				if ($quoted) {
2707
+									$pos1 += 6;
2708
+				}
2709
+			} else {
2710
+							$quoted = false;
2575 2711
 			}
2576
-			else
2577
-				$quoted = false;
2578 2712
 
2579 2713
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2580
-			if ($pos2 === false)
2581
-				continue;
2714
+			if ($pos2 === false) {
2715
+							continue;
2716
+			}
2582 2717
 
2583 2718
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2584
-			if ($pos3 === false)
2585
-				continue;
2719
+			if ($pos3 === false) {
2720
+							continue;
2721
+			}
2586 2722
 
2587 2723
 			$data = array(
2588 2724
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2589 2725
 				substr($message, $pos1, $pos2 - $pos1)
2590 2726
 			);
2591 2727
 
2592
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2593
-				$data[0] = substr($data[0], 4);
2728
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2729
+							$data[0] = substr($data[0], 4);
2730
+			}
2594 2731
 
2595 2732
 			// Validation for my parking, please!
2596
-			if (isset($tag['validate']))
2597
-				$tag['validate']($tag, $data, $disabled, $params);
2733
+			if (isset($tag['validate'])) {
2734
+							$tag['validate']($tag, $data, $disabled, $params);
2735
+			}
2598 2736
 
2599 2737
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2600 2738
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2611,23 +2749,27 @@  discard block
 block discarded – undo
2611 2749
 		elseif ($tag['type'] == 'unparsed_commas_content')
2612 2750
 		{
2613 2751
 			$pos2 = strpos($message, ']', $pos1);
2614
-			if ($pos2 === false)
2615
-				continue;
2752
+			if ($pos2 === false) {
2753
+							continue;
2754
+			}
2616 2755
 
2617 2756
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2618
-			if ($pos3 === false)
2619
-				continue;
2757
+			if ($pos3 === false) {
2758
+							continue;
2759
+			}
2620 2760
 
2621 2761
 			// We want $1 to be the content, and the rest to be csv.
2622 2762
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2623 2763
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2624 2764
 
2625
-			if (isset($tag['validate']))
2626
-				$tag['validate']($tag, $data, $disabled, $params);
2765
+			if (isset($tag['validate'])) {
2766
+							$tag['validate']($tag, $data, $disabled, $params);
2767
+			}
2627 2768
 
2628 2769
 			$code = $tag['content'];
2629
-			foreach ($data as $k => $d)
2630
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2770
+			foreach ($data as $k => $d) {
2771
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2772
+			}
2631 2773
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2632 2774
 			$pos += strlen($code) - 1 + 2;
2633 2775
 		}
@@ -2635,24 +2777,28 @@  discard block
 block discarded – undo
2635 2777
 		elseif ($tag['type'] == 'unparsed_commas')
2636 2778
 		{
2637 2779
 			$pos2 = strpos($message, ']', $pos1);
2638
-			if ($pos2 === false)
2639
-				continue;
2780
+			if ($pos2 === false) {
2781
+							continue;
2782
+			}
2640 2783
 
2641 2784
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2642 2785
 
2643
-			if (isset($tag['validate']))
2644
-				$tag['validate']($tag, $data, $disabled, $params);
2786
+			if (isset($tag['validate'])) {
2787
+							$tag['validate']($tag, $data, $disabled, $params);
2788
+			}
2645 2789
 
2646 2790
 			// Fix after, for disabled code mainly.
2647
-			foreach ($data as $k => $d)
2648
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2791
+			foreach ($data as $k => $d) {
2792
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2793
+			}
2649 2794
 
2650 2795
 			$open_tags[] = $tag;
2651 2796
 
2652 2797
 			// Replace them out, $1, $2, $3, $4, etc.
2653 2798
 			$code = $tag['before'];
2654
-			foreach ($data as $k => $d)
2655
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2799
+			foreach ($data as $k => $d) {
2800
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2801
+			}
2656 2802
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2657 2803
 			$pos += strlen($code) - 1 + 2;
2658 2804
 		}
@@ -2663,28 +2809,33 @@  discard block
 block discarded – undo
2663 2809
 			if (isset($tag['quoted']))
2664 2810
 			{
2665 2811
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2666
-				if ($tag['quoted'] != 'optional' && !$quoted)
2667
-					continue;
2812
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2813
+									continue;
2814
+				}
2668 2815
 
2669
-				if ($quoted)
2670
-					$pos1 += 6;
2816
+				if ($quoted) {
2817
+									$pos1 += 6;
2818
+				}
2819
+			} else {
2820
+							$quoted = false;
2671 2821
 			}
2672
-			else
2673
-				$quoted = false;
2674 2822
 
2675 2823
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2676
-			if ($pos2 === false)
2677
-				continue;
2824
+			if ($pos2 === false) {
2825
+							continue;
2826
+			}
2678 2827
 
2679 2828
 			$data = substr($message, $pos1, $pos2 - $pos1);
2680 2829
 
2681 2830
 			// Validation for my parking, please!
2682
-			if (isset($tag['validate']))
2683
-				$tag['validate']($tag, $data, $disabled, $params);
2831
+			if (isset($tag['validate'])) {
2832
+							$tag['validate']($tag, $data, $disabled, $params);
2833
+			}
2684 2834
 
2685 2835
 			// For parsed content, we must recurse to avoid security problems.
2686
-			if ($tag['type'] != 'unparsed_equals')
2687
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2836
+			if ($tag['type'] != 'unparsed_equals') {
2837
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2838
+			}
2688 2839
 
2689 2840
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2690 2841
 
@@ -2696,34 +2847,40 @@  discard block
 block discarded – undo
2696 2847
 		}
2697 2848
 
2698 2849
 		// If this is block level, eat any breaks after it.
2699
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2700
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2850
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2851
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2852
+		}
2701 2853
 
2702 2854
 		// Are we trimming outside this tag?
2703
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2704
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2855
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2856
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2857
+		}
2705 2858
 	}
2706 2859
 
2707 2860
 	// Close any remaining tags.
2708
-	while ($tag = array_pop($open_tags))
2709
-		$message .= "\n" . $tag['after'] . "\n";
2861
+	while ($tag = array_pop($open_tags)) {
2862
+			$message .= "\n" . $tag['after'] . "\n";
2863
+	}
2710 2864
 
2711 2865
 	// Parse the smileys within the parts where it can be done safely.
2712 2866
 	if ($smileys === true)
2713 2867
 	{
2714 2868
 		$message_parts = explode("\n", $message);
2715
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2716
-			parsesmileys($message_parts[$i]);
2869
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2870
+					parsesmileys($message_parts[$i]);
2871
+		}
2717 2872
 
2718 2873
 		$message = implode('', $message_parts);
2719 2874
 	}
2720 2875
 
2721 2876
 	// No smileys, just get rid of the markers.
2722
-	else
2723
-		$message = strtr($message, array("\n" => ''));
2877
+	else {
2878
+			$message = strtr($message, array("\n" => ''));
2879
+	}
2724 2880
 
2725
-	if ($message !== '' && $message[0] === ' ')
2726
-		$message = '&nbsp;' . substr($message, 1);
2881
+	if ($message !== '' && $message[0] === ' ') {
2882
+			$message = '&nbsp;' . substr($message, 1);
2883
+	}
2727 2884
 
2728 2885
 	// Cleanup whitespace.
2729 2886
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2732,15 +2889,16 @@  discard block
 block discarded – undo
2732 2889
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2733 2890
 
2734 2891
 	// Cache the output if it took some time...
2735
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2736
-		cache_put_data($cache_key, $message, 240);
2892
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2893
+			cache_put_data($cache_key, $message, 240);
2894
+	}
2737 2895
 
2738 2896
 	// If this was a force parse revert if needed.
2739 2897
 	if (!empty($parse_tags))
2740 2898
 	{
2741
-		if (empty($temp_bbc))
2742
-			$bbc_codes = array();
2743
-		else
2899
+		if (empty($temp_bbc)) {
2900
+					$bbc_codes = array();
2901
+		} else
2744 2902
 		{
2745 2903
 			$bbc_codes = $temp_bbc;
2746 2904
 			unset($temp_bbc);
@@ -2767,8 +2925,9 @@  discard block
 block discarded – undo
2767 2925
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2768 2926
 
2769 2927
 	// No smiley set at all?!
2770
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2771
-		return;
2928
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2929
+			return;
2930
+	}
2772 2931
 
2773 2932
 	// If smileyPregSearch hasn't been set, do it now.
2774 2933
 	if (empty($smileyPregSearch))
@@ -2779,8 +2938,7 @@  discard block
 block discarded – undo
2779 2938
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2780 2939
 			$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');
2781 2940
 			$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'], '', '', '', '');
2782
-		}
2783
-		else
2941
+		} else
2784 2942
 		{
2785 2943
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2786 2944
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2804,9 +2962,9 @@  discard block
 block discarded – undo
2804 2962
 				$smcFunc['db_free_result']($result);
2805 2963
 
2806 2964
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2965
+			} else {
2966
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2807 2967
 			}
2808
-			else
2809
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2810 2968
 		}
2811 2969
 
2812 2970
 		// The non-breaking-space is a complex thing...
@@ -2883,35 +3041,41 @@  discard block
 block discarded – undo
2883 3041
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2884 3042
 
2885 3043
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2886
-	if (!empty($context['flush_mail']))
2887
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3044
+	if (!empty($context['flush_mail'])) {
3045
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2888 3046
 		AddMailQueue(true);
3047
+	}
2889 3048
 
2890 3049
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2891 3050
 
2892
-	if ($add)
2893
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3051
+	if ($add) {
3052
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3053
+	}
2894 3054
 
2895 3055
 	// Put the session ID in.
2896
-	if (defined('SID') && SID != '')
2897
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3056
+	if (defined('SID') && SID != '') {
3057
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3058
+	}
2898 3059
 	// Keep that debug in their for template debugging!
2899
-	elseif (isset($_GET['debug']))
2900
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3060
+	elseif (isset($_GET['debug'])) {
3061
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3062
+	}
2901 3063
 
2902 3064
 	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'])))
2903 3065
 	{
2904
-		if (defined('SID') && SID != '')
2905
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3066
+		if (defined('SID') && SID != '') {
3067
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2906 3068
 				function ($m) use ($scripturl)
2907 3069
 				{
2908 3070
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3071
+		}
2909 3072
 				}, $setLocation);
2910
-		else
2911
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3073
+		else {
3074
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2912 3075
 				function ($m) use ($scripturl)
2913 3076
 				{
2914 3077
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3078
+		}
2915 3079
 				}, $setLocation);
2916 3080
 	}
2917 3081
 
@@ -2922,8 +3086,9 @@  discard block
 block discarded – undo
2922 3086
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2923 3087
 
2924 3088
 	// Debugging.
2925
-	if (isset($db_show_debug) && $db_show_debug === true)
2926
-		$_SESSION['debug_redirect'] = $db_cache;
3089
+	if (isset($db_show_debug) && $db_show_debug === true) {
3090
+			$_SESSION['debug_redirect'] = $db_cache;
3091
+	}
2927 3092
 
2928 3093
 	obExit(false);
2929 3094
 }
@@ -2942,51 +3107,60 @@  discard block
 block discarded – undo
2942 3107
 
2943 3108
 	// Attempt to prevent a recursive loop.
2944 3109
 	++$level;
2945
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2946
-		exit;
2947
-	if ($from_fatal_error)
2948
-		$has_fatal_error = true;
3110
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3111
+			exit;
3112
+	}
3113
+	if ($from_fatal_error) {
3114
+			$has_fatal_error = true;
3115
+	}
2949 3116
 
2950 3117
 	// Clear out the stat cache.
2951 3118
 	trackStats();
2952 3119
 
2953 3120
 	// If we have mail to send, send it.
2954
-	if (!empty($context['flush_mail']))
2955
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3121
+	if (!empty($context['flush_mail'])) {
3122
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2956 3123
 		AddMailQueue(true);
3124
+	}
2957 3125
 
2958 3126
 	$do_header = $header === null ? !$header_done : $header;
2959
-	if ($do_footer === null)
2960
-		$do_footer = $do_header;
3127
+	if ($do_footer === null) {
3128
+			$do_footer = $do_header;
3129
+	}
2961 3130
 
2962 3131
 	// Has the template/header been done yet?
2963 3132
 	if ($do_header)
2964 3133
 	{
2965 3134
 		// Was the page title set last minute? Also update the HTML safe one.
2966
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2967
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3135
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3136
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3137
+		}
2968 3138
 
2969 3139
 		// Start up the session URL fixer.
2970 3140
 		ob_start('ob_sessrewrite');
2971 3141
 
2972
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2973
-			$buffers = explode(',', $settings['output_buffers']);
2974
-		elseif (!empty($settings['output_buffers']))
2975
-			$buffers = $settings['output_buffers'];
2976
-		else
2977
-			$buffers = array();
3142
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3143
+					$buffers = explode(',', $settings['output_buffers']);
3144
+		} elseif (!empty($settings['output_buffers'])) {
3145
+					$buffers = $settings['output_buffers'];
3146
+		} else {
3147
+					$buffers = array();
3148
+		}
2978 3149
 
2979
-		if (isset($modSettings['integrate_buffer']))
2980
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3150
+		if (isset($modSettings['integrate_buffer'])) {
3151
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3152
+		}
2981 3153
 
2982
-		if (!empty($buffers))
2983
-			foreach ($buffers as $function)
3154
+		if (!empty($buffers)) {
3155
+					foreach ($buffers as $function)
2984 3156
 			{
2985 3157
 				$call = call_helper($function, true);
3158
+		}
2986 3159
 
2987 3160
 				// Is it valid?
2988
-				if (!empty($call))
2989
-					ob_start($call);
3161
+				if (!empty($call)) {
3162
+									ob_start($call);
3163
+				}
2990 3164
 			}
2991 3165
 
2992 3166
 		// Display the screen in the logical order.
@@ -2998,8 +3172,9 @@  discard block
 block discarded – undo
2998 3172
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2999 3173
 
3000 3174
 		// Anything special to put out?
3001
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3002
-			echo $context['insert_after_template'];
3175
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3176
+					echo $context['insert_after_template'];
3177
+		}
3003 3178
 
3004 3179
 		// Just so we don't get caught in an endless loop of errors from the footer...
3005 3180
 		if (!$footer_done)
@@ -3008,14 +3183,16 @@  discard block
 block discarded – undo
3008 3183
 			template_footer();
3009 3184
 
3010 3185
 			// (since this is just debugging... it's okay that it's after </html>.)
3011
-			if (!isset($_REQUEST['xml']))
3012
-				displayDebug();
3186
+			if (!isset($_REQUEST['xml'])) {
3187
+							displayDebug();
3188
+			}
3013 3189
 		}
3014 3190
 	}
3015 3191
 
3016 3192
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3017
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3018
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3193
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3194
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3195
+	}
3019 3196
 
3020 3197
 	// For session check verification.... don't switch browsers...
3021 3198
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3024,9 +3201,10 @@  discard block
 block discarded – undo
3024 3201
 	call_integration_hook('integrate_exit', array($do_footer));
3025 3202
 
3026 3203
 	// Don't exit if we're coming from index.php; that will pass through normally.
3027
-	if (!$from_index)
3028
-		exit;
3029
-}
3204
+	if (!$from_index) {
3205
+			exit;
3206
+	}
3207
+	}
3030 3208
 
3031 3209
 /**
3032 3210
  * Get the size of a specified image with better error handling.
@@ -3045,8 +3223,9 @@  discard block
 block discarded – undo
3045 3223
 	$url = str_replace(' ', '%20', $url);
3046 3224
 
3047 3225
 	// Can we pull this from the cache... please please?
3048
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3049
-		return $temp;
3226
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3227
+			return $temp;
3228
+	}
3050 3229
 	$t = microtime();
3051 3230
 
3052 3231
 	// Get the host to pester...
@@ -3056,12 +3235,10 @@  discard block
 block discarded – undo
3056 3235
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3057 3236
 	{
3058 3237
 		return false;
3059
-	}
3060
-	elseif (!isset($match[1]))
3238
+	} elseif (!isset($match[1]))
3061 3239
 	{
3062 3240
 		$size = @getimagesize($url);
3063
-	}
3064
-	else
3241
+	} else
3065 3242
 	{
3066 3243
 		// Try to connect to the server... give it half a second.
3067 3244
 		$temp = 0;
@@ -3100,12 +3277,14 @@  discard block
 block discarded – undo
3100 3277
 	}
3101 3278
 
3102 3279
 	// If we didn't get it, we failed.
3103
-	if (!isset($size))
3104
-		$size = false;
3280
+	if (!isset($size)) {
3281
+			$size = false;
3282
+	}
3105 3283
 
3106 3284
 	// If this took a long time, we may never have to do it again, but then again we might...
3107
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3108
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3285
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3286
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3287
+	}
3109 3288
 
3110 3289
 	// Didn't work.
3111 3290
 	return $size;
@@ -3123,8 +3302,9 @@  discard block
 block discarded – undo
3123 3302
 
3124 3303
 	// Under SSI this function can be called more then once.  That can cause some problems.
3125 3304
 	//   So only run the function once unless we are forced to run it again.
3126
-	if ($loaded && !$forceload)
3127
-		return;
3305
+	if ($loaded && !$forceload) {
3306
+			return;
3307
+	}
3128 3308
 
3129 3309
 	$loaded = true;
3130 3310
 
@@ -3136,14 +3316,16 @@  discard block
 block discarded – undo
3136 3316
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3137 3317
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3138 3318
 	{
3139
-		if (trim($context['news_lines'][$i]) == '')
3140
-			continue;
3319
+		if (trim($context['news_lines'][$i]) == '') {
3320
+					continue;
3321
+		}
3141 3322
 
3142 3323
 		// Clean it up for presentation ;).
3143 3324
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3144 3325
 	}
3145
-	if (!empty($context['news_lines']))
3146
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3326
+	if (!empty($context['news_lines'])) {
3327
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3328
+	}
3147 3329
 
3148 3330
 	if (!$user_info['is_guest'])
3149 3331
 	{
@@ -3152,40 +3334,48 @@  discard block
 block discarded – undo
3152 3334
 		$context['user']['alerts'] = &$user_info['alerts'];
3153 3335
 
3154 3336
 		// Personal message popup...
3155
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3156
-			$context['user']['popup_messages'] = true;
3157
-		else
3158
-			$context['user']['popup_messages'] = false;
3337
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3338
+					$context['user']['popup_messages'] = true;
3339
+		} else {
3340
+					$context['user']['popup_messages'] = false;
3341
+		}
3159 3342
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3160 3343
 
3161
-		if (allowedTo('moderate_forum'))
3162
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3344
+		if (allowedTo('moderate_forum')) {
3345
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3346
+		}
3163 3347
 
3164 3348
 		$context['user']['avatar'] = array();
3165 3349
 
3166 3350
 		// Check for gravatar first since we might be forcing them...
3167 3351
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3168 3352
 		{
3169
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3170
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3171
-			else
3172
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3353
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3354
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3355
+			} else {
3356
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3357
+			}
3173 3358
 		}
3174 3359
 		// Uploaded?
3175
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3176
-			$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';
3360
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3361
+					$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';
3362
+		}
3177 3363
 		// Full URL?
3178
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3179
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3364
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3365
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3366
+		}
3180 3367
 		// Otherwise we assume it's server stored.
3181
-		elseif ($user_info['avatar']['url'] != '')
3182
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3368
+		elseif ($user_info['avatar']['url'] != '') {
3369
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3370
+		}
3183 3371
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3184
-		else
3185
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3372
+		else {
3373
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3374
+		}
3186 3375
 
3187
-		if (!empty($context['user']['avatar']))
3188
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3376
+		if (!empty($context['user']['avatar'])) {
3377
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3378
+		}
3189 3379
 
3190 3380
 		// Figure out how long they've been logged in.
3191 3381
 		$context['user']['total_time_logged_in'] = array(
@@ -3193,8 +3383,7 @@  discard block
 block discarded – undo
3193 3383
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3194 3384
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3195 3385
 		);
3196
-	}
3197
-	else
3386
+	} else
3198 3387
 	{
3199 3388
 		$context['user']['messages'] = 0;
3200 3389
 		$context['user']['unread_messages'] = 0;
@@ -3202,12 +3391,14 @@  discard block
 block discarded – undo
3202 3391
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3203 3392
 		$context['user']['popup_messages'] = false;
3204 3393
 
3205
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3206
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3394
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3395
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3396
+		}
3207 3397
 
3208 3398
 		// If we've upgraded recently, go easy on the passwords.
3209
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3210
-			$context['disable_login_hashing'] = true;
3399
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3400
+					$context['disable_login_hashing'] = true;
3401
+		}
3211 3402
 	}
3212 3403
 
3213 3404
 	// Setup the main menu items.
@@ -3220,8 +3411,8 @@  discard block
 block discarded – undo
3220 3411
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3221 3412
 
3222 3413
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3223
-	if ($context['show_pm_popup'])
3224
-		addInlineJavaScript('
3414
+	if ($context['show_pm_popup']) {
3415
+			addInlineJavaScript('
3225 3416
 		jQuery(document).ready(function($) {
3226 3417
 			new smc_Popup({
3227 3418
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3229,15 +3420,17 @@  discard block
 block discarded – undo
3229 3420
 				icon_class: \'generic_icons mail_new\'
3230 3421
 			});
3231 3422
 		});');
3423
+	}
3232 3424
 
3233 3425
 	// Add a generic "Are you sure?" confirmation message.
3234 3426
 	addInlineJavaScript('
3235 3427
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3236 3428
 
3237 3429
 	// Now add the capping code for avatars.
3238
-	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')
3239
-		addInlineCss('
3430
+	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') {
3431
+			addInlineCss('
3240 3432
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3433
+	}
3241 3434
 
3242 3435
 	// This looks weird, but it's because BoardIndex.php references the variable.
3243 3436
 	$context['common_stats']['latest_member'] = array(
@@ -3254,11 +3447,13 @@  discard block
 block discarded – undo
3254 3447
 	);
3255 3448
 	$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']);
3256 3449
 
3257
-	if (empty($settings['theme_version']))
3258
-		addJavaScriptVar('smf_scripturl', $scripturl);
3450
+	if (empty($settings['theme_version'])) {
3451
+			addJavaScriptVar('smf_scripturl', $scripturl);
3452
+	}
3259 3453
 
3260
-	if (!isset($context['page_title']))
3261
-		$context['page_title'] = '';
3454
+	if (!isset($context['page_title'])) {
3455
+			$context['page_title'] = '';
3456
+	}
3262 3457
 
3263 3458
 	// Set some specific vars.
3264 3459
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3268,21 +3463,23 @@  discard block
 block discarded – undo
3268 3463
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3269 3464
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3270 3465
 
3271
-	if (!empty($context['meta_keywords']))
3272
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3466
+	if (!empty($context['meta_keywords'])) {
3467
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3468
+	}
3273 3469
 
3274
-	if (!empty($context['canonical_url']))
3275
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3470
+	if (!empty($context['canonical_url'])) {
3471
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3472
+	}
3276 3473
 
3277
-	if (!empty($settings['og_image']))
3278
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3474
+	if (!empty($settings['og_image'])) {
3475
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3476
+	}
3279 3477
 
3280 3478
 	if (!empty($context['meta_description']))
3281 3479
 	{
3282 3480
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3283 3481
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3284
-	}
3285
-	else
3482
+	} else
3286 3483
 	{
3287 3484
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3288 3485
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3307,8 +3504,9 @@  discard block
 block discarded – undo
3307 3504
 	$memory_needed = memoryReturnBytes($needed);
3308 3505
 
3309 3506
 	// should we account for how much is currently being used?
3310
-	if ($in_use)
3311
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3507
+	if ($in_use) {
3508
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3509
+	}
3312 3510
 
3313 3511
 	// if more is needed, request it
3314 3512
 	if ($memory_current < $memory_needed)
@@ -3331,8 +3529,9 @@  discard block
 block discarded – undo
3331 3529
  */
3332 3530
 function memoryReturnBytes($val)
3333 3531
 {
3334
-	if (is_integer($val))
3335
-		return $val;
3532
+	if (is_integer($val)) {
3533
+			return $val;
3534
+	}
3336 3535
 
3337 3536
 	// Separate the number from the designator
3338 3537
 	$val = trim($val);
@@ -3368,10 +3567,11 @@  discard block
 block discarded – undo
3368 3567
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3369 3568
 
3370 3569
 		// Are we debugging the template/html content?
3371
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3372
-			header('content-type: application/xhtml+xml');
3373
-		elseif (!isset($_REQUEST['xml']))
3374
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3570
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3571
+					header('content-type: application/xhtml+xml');
3572
+		} elseif (!isset($_REQUEST['xml'])) {
3573
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3574
+		}
3375 3575
 	}
3376 3576
 
3377 3577
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3380,8 +3580,9 @@  discard block
 block discarded – undo
3380 3580
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3381 3581
 	{
3382 3582
 		$position = array_search('body', $context['template_layers']);
3383
-		if ($position === false)
3384
-			$position = array_search('main', $context['template_layers']);
3583
+		if ($position === false) {
3584
+					$position = array_search('main', $context['template_layers']);
3585
+		}
3385 3586
 
3386 3587
 		if ($position !== false)
3387 3588
 		{
@@ -3409,23 +3610,25 @@  discard block
 block discarded – undo
3409 3610
 
3410 3611
 			foreach ($securityFiles as $i => $securityFile)
3411 3612
 			{
3412
-				if (!file_exists($boarddir . '/' . $securityFile))
3413
-					unset($securityFiles[$i]);
3613
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3614
+									unset($securityFiles[$i]);
3615
+				}
3414 3616
 			}
3415 3617
 
3416 3618
 			// We are already checking so many files...just few more doesn't make any difference! :P
3417
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3418
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3419
-
3420
-			else
3421
-				$path = $modSettings['attachmentUploadDir'];
3619
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3620
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3621
+			} else {
3622
+							$path = $modSettings['attachmentUploadDir'];
3623
+			}
3422 3624
 
3423 3625
 			secureDirectory($path, true);
3424 3626
 			secureDirectory($cachedir);
3425 3627
 
3426 3628
 			// If agreement is enabled, at least the english version shall exists
3427
-			if ($modSettings['requireAgreement'])
3428
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3629
+			if ($modSettings['requireAgreement']) {
3630
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3631
+			}
3429 3632
 
3430 3633
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3431 3634
 			{
@@ -3440,18 +3643,21 @@  discard block
 block discarded – undo
3440 3643
 					echo '
3441 3644
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3442 3645
 
3443
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3444
-						echo '
3646
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3647
+											echo '
3445 3648
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3649
+					}
3446 3650
 				}
3447 3651
 
3448
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3449
-					echo '
3652
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3653
+									echo '
3450 3654
 				<strong>', $txt['cache_writable'], '</strong><br>';
3655
+				}
3451 3656
 
3452
-				if (!empty($agreement))
3453
-					echo '
3657
+				if (!empty($agreement)) {
3658
+									echo '
3454 3659
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3660
+				}
3455 3661
 
3456 3662
 				echo '
3457 3663
 			</p>
@@ -3466,16 +3672,18 @@  discard block
 block discarded – undo
3466 3672
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3467 3673
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3468 3674
 
3469
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3470
-				echo '
3675
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3676
+							echo '
3471 3677
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3678
+			}
3472 3679
 
3473
-			if (!empty($_SESSION['ban']['expire_time']))
3474
-				echo '
3680
+			if (!empty($_SESSION['ban']['expire_time'])) {
3681
+							echo '
3475 3682
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3476
-			else
3477
-				echo '
3683
+			} else {
3684
+							echo '
3478 3685
 					<div>', $txt['your_ban_expires_never'], '</div>';
3686
+			}
3479 3687
 
3480 3688
 			echo '
3481 3689
 				</div>';
@@ -3491,8 +3699,9 @@  discard block
 block discarded – undo
3491 3699
 	global $forum_copyright, $software_year, $forum_version;
3492 3700
 
3493 3701
 	// Don't display copyright for things like SSI.
3494
-	if (!isset($forum_version) || !isset($software_year))
3495
-		return;
3702
+	if (!isset($forum_version) || !isset($software_year)) {
3703
+			return;
3704
+	}
3496 3705
 
3497 3706
 	// Put in the version...
3498 3707
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3510,9 +3719,10 @@  discard block
 block discarded – undo
3510 3719
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3511 3720
 	$context['load_queries'] = $db_count;
3512 3721
 
3513
-	foreach (array_reverse($context['template_layers']) as $layer)
3514
-		loadSubTemplate($layer . '_below', true);
3515
-}
3722
+	foreach (array_reverse($context['template_layers']) as $layer) {
3723
+			loadSubTemplate($layer . '_below', true);
3724
+	}
3725
+	}
3516 3726
 
3517 3727
 /**
3518 3728
  * Output the Javascript files
@@ -3543,8 +3753,7 @@  discard block
 block discarded – undo
3543 3753
 			{
3544 3754
 				echo '
3545 3755
 		var ', $key, ';';
3546
-			}
3547
-			else
3756
+			} else
3548 3757
 			{
3549 3758
 				echo '
3550 3759
 		var ', $key, ' = ', $value, ';';
@@ -3559,26 +3768,27 @@  discard block
 block discarded – undo
3559 3768
 	foreach ($context['javascript_files'] as $id => $js_file)
3560 3769
 	{
3561 3770
 		// Last minute call! allow theme authors to disable single files.
3562
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3563
-			continue;
3771
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3772
+					continue;
3773
+		}
3564 3774
 
3565 3775
 		// By default all files don't get minimized unless the file explicitly says so!
3566 3776
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3567 3777
 		{
3568
-			if ($do_deferred && !empty($js_file['options']['defer']))
3569
-				$toMinifyDefer[] = $js_file;
3570
-
3571
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3572
-				$toMinify[] = $js_file;
3778
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3779
+							$toMinifyDefer[] = $js_file;
3780
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3781
+							$toMinify[] = $js_file;
3782
+			}
3573 3783
 
3574 3784
 			// Grab a random seed.
3575
-			if (!isset($minSeed) && isset($js_file['options']['seed']))
3576
-				$minSeed = $js_file['options']['seed'];
3577
-		}
3578
-
3579
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3580
-			echo '
3785
+			if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3786
+							$minSeed = $js_file['options']['seed'];
3787
+			}
3788
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3789
+					echo '
3581 3790
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3791
+		}
3582 3792
 	}
3583 3793
 
3584 3794
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3587,9 +3797,10 @@  discard block
 block discarded – undo
3587 3797
 
3588 3798
 		$minSuccessful = array_keys($result) === array('smf_minified');
3589 3799
 
3590
-		foreach ($result as $minFile)
3591
-			echo '
3800
+		foreach ($result as $minFile) {
3801
+					echo '
3592 3802
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async="async"' : '', '></script>';
3803
+		}
3593 3804
 
3594 3805
 	}
3595 3806
 
@@ -3601,8 +3812,9 @@  discard block
 block discarded – undo
3601 3812
 			echo '
3602 3813
 <script>';
3603 3814
 
3604
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3605
-				echo $js_code;
3815
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3816
+							echo $js_code;
3817
+			}
3606 3818
 
3607 3819
 			echo '
3608 3820
 </script>';
@@ -3613,8 +3825,9 @@  discard block
 block discarded – undo
3613 3825
 			echo '
3614 3826
 	<script>';
3615 3827
 
3616
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3617
-				echo $js_code;
3828
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3829
+							echo $js_code;
3830
+			}
3618 3831
 
3619 3832
 			echo '
3620 3833
 	</script>';
@@ -3642,23 +3855,26 @@  discard block
 block discarded – undo
3642 3855
 	foreach ($context['css_files'] as $id => $file)
3643 3856
 	{
3644 3857
 		// Last minute call! allow theme authors to disable single files.
3645
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3646
-			continue;
3858
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3859
+					continue;
3860
+		}
3647 3861
 
3648 3862
 		// Files are minimized unless they explicitly opt out.
3649
-		if (!isset($file['options']['minimize']))
3650
-			$file['options']['minimize'] = true;
3863
+		if (!isset($file['options']['minimize'])) {
3864
+					$file['options']['minimize'] = true;
3865
+		}
3651 3866
 
3652 3867
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3653 3868
 		{
3654 3869
 			$toMinify[] = $file;
3655 3870
 
3656 3871
 			// Grab a random seed.
3657
-			if (!isset($minSeed) && isset($file['options']['seed']))
3658
-				$minSeed = $file['options']['seed'];
3872
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
3873
+							$minSeed = $file['options']['seed'];
3874
+			}
3875
+		} else {
3876
+					$normal[] = $file['fileUrl'];
3659 3877
 		}
3660
-		else
3661
-			$normal[] = $file['fileUrl'];
3662 3878
 	}
3663 3879
 
3664 3880
 	if (!empty($toMinify))
@@ -3667,23 +3883,26 @@  discard block
 block discarded – undo
3667 3883
 
3668 3884
 		$minSuccessful = array_keys($result) === array('smf_minified');
3669 3885
 
3670
-		foreach ($result as $minFile)
3671
-			echo '
3886
+		foreach ($result as $minFile) {
3887
+					echo '
3672 3888
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
3889
+		}
3673 3890
 	}
3674 3891
 
3675 3892
 	// Print the rest after the minified files.
3676
-	if (!empty($normal))
3677
-		foreach ($normal as $nf)
3893
+	if (!empty($normal)) {
3894
+			foreach ($normal as $nf)
3678 3895
 			echo '
3679 3896
 	<link rel="stylesheet" href="', $nf ,'">';
3897
+	}
3680 3898
 
3681 3899
 	if ($db_show_debug === true)
3682 3900
 	{
3683 3901
 		// Try to keep only what's useful.
3684 3902
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3685
-		foreach ($context['css_files'] as $file)
3686
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3903
+		foreach ($context['css_files'] as $file) {
3904
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3905
+		}
3687 3906
 	}
3688 3907
 
3689 3908
 	if (!empty($context['css_header']))
@@ -3691,9 +3910,10 @@  discard block
 block discarded – undo
3691 3910
 		echo '
3692 3911
 	<style>';
3693 3912
 
3694
-		foreach ($context['css_header'] as $css)
3695
-			echo $css .'
3913
+		foreach ($context['css_header'] as $css) {
3914
+					echo $css .'
3696 3915
 	';
3916
+		}
3697 3917
 
3698 3918
 		echo'
3699 3919
 	</style>';
@@ -3717,8 +3937,9 @@  discard block
 block discarded – undo
3717 3937
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3718 3938
 	$data = !empty($data) ? $data : false;
3719 3939
 
3720
-	if (empty($type) || empty($data))
3721
-		return false;
3940
+	if (empty($type) || empty($data)) {
3941
+			return false;
3942
+	}
3722 3943
 
3723 3944
 	// Different pages include different files, so we use a hash to label the different combinations
3724 3945
 	$hash = md5(implode(' ', array_keys($data)));
@@ -3727,8 +3948,9 @@  discard block
 block discarded – undo
3727 3948
 	$toCache = cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400);
3728 3949
 
3729 3950
 	// Already done?
3730
-	if (!empty($toCache))
3731
-		return true;
3951
+	if (!empty($toCache)) {
3952
+			return true;
3953
+	}
3732 3954
 
3733 3955
 	// No namespaces, sorry!
3734 3956
 	$classType = 'MatthiasMullie\\Minify\\'. strtoupper($type);
@@ -3760,8 +3982,9 @@  discard block
 block discarded – undo
3760 3982
 		$toAdd = file_exists($tempFile) ? $tempFile : false;
3761 3983
 
3762 3984
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3763
-		if (empty($file['options']['async']))
3764
-			$async = false;
3985
+		if (empty($file['options']['async'])) {
3986
+					$async = false;
3987
+		}
3765 3988
 
3766 3989
 		// The file couldn't be located so it won't be added. Log this error.
3767 3990
 		if (empty($toAdd))
@@ -3821,8 +4044,9 @@  discard block
 block discarded – undo
3821 4044
 	global $modSettings, $smcFunc;
3822 4045
 
3823 4046
 	// Just make up a nice hash...
3824
-	if ($new)
3825
-		return sha1(md5($filename . time()) . mt_rand());
4047
+	if ($new) {
4048
+			return sha1(md5($filename . time()) . mt_rand());
4049
+	}
3826 4050
 
3827 4051
 	// Just make sure that attachment id is only a int
3828 4052
 	$attachment_id = (int) $attachment_id;
@@ -3839,23 +4063,25 @@  discard block
 block discarded – undo
3839 4063
 				'id_attach' => $attachment_id,
3840 4064
 			));
3841 4065
 
3842
-		if ($smcFunc['db_num_rows']($request) === 0)
3843
-			return false;
4066
+		if ($smcFunc['db_num_rows']($request) === 0) {
4067
+					return false;
4068
+		}
3844 4069
 
3845 4070
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3846 4071
 		$smcFunc['db_free_result']($request);
3847 4072
 	}
3848 4073
 
3849 4074
 	// Still no hash? mmm...
3850
-	if (empty($file_hash))
3851
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4075
+	if (empty($file_hash)) {
4076
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4077
+	}
3852 4078
 
3853 4079
 	// Are we using multiple directories?
3854
-	if (is_array($modSettings['attachmentUploadDir']))
3855
-		$path = $modSettings['attachmentUploadDir'][$dir];
3856
-
3857
-	else
3858
-		$path = $modSettings['attachmentUploadDir'];
4080
+	if (is_array($modSettings['attachmentUploadDir'])) {
4081
+			$path = $modSettings['attachmentUploadDir'][$dir];
4082
+	} else {
4083
+			$path = $modSettings['attachmentUploadDir'];
4084
+	}
3859 4085
 
3860 4086
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3861 4087
 }
@@ -3870,8 +4096,9 @@  discard block
 block discarded – undo
3870 4096
 function ip2range($fullip)
3871 4097
 {
3872 4098
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3873
-	if ($fullip == 'unknown')
3874
-		$fullip = '255.255.255.255';
4099
+	if ($fullip == 'unknown') {
4100
+			$fullip = '255.255.255.255';
4101
+	}
3875 4102
 
3876 4103
 	$ip_parts = explode('-', $fullip);
3877 4104
 	$ip_array = array();
@@ -3895,10 +4122,11 @@  discard block
 block discarded – undo
3895 4122
 		$ip_array['low'] = $ip_parts[0];
3896 4123
 		$ip_array['high'] = $ip_parts[1];
3897 4124
 		return $ip_array;
3898
-	}
3899
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4125
+	} elseif (count($ip_parts) == 2) {
4126
+		// if ip 22.22.*-22.22.*
3900 4127
 	{
3901 4128
 		$valid_low = isValidIP($ip_parts[0]);
4129
+	}
3902 4130
 		$valid_high = isValidIP($ip_parts[1]);
3903 4131
 		$count = 0;
3904 4132
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3913,7 +4141,9 @@  discard block
 block discarded – undo
3913 4141
 				$ip_parts[0] .= $mode . $min;
3914 4142
 				$valid_low = isValidIP($ip_parts[0]);
3915 4143
 				$count++;
3916
-				if ($count > 9) break;
4144
+				if ($count > 9) {
4145
+					break;
4146
+				}
3917 4147
 			}
3918 4148
 		}
3919 4149
 
@@ -3927,7 +4157,9 @@  discard block
 block discarded – undo
3927 4157
 				$ip_parts[1] .= $mode . $max;
3928 4158
 				$valid_high = isValidIP($ip_parts[1]);
3929 4159
 				$count++;
3930
-				if ($count > 9) break;
4160
+				if ($count > 9) {
4161
+					break;
4162
+				}
3931 4163
 			}
3932 4164
 		}
3933 4165
 
@@ -3952,46 +4184,54 @@  discard block
 block discarded – undo
3952 4184
 {
3953 4185
 	global $modSettings;
3954 4186
 
3955
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3956
-		return $host;
4187
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4188
+			return $host;
4189
+	}
3957 4190
 	$t = microtime();
3958 4191
 
3959 4192
 	// Try the Linux host command, perhaps?
3960 4193
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3961 4194
 	{
3962
-		if (!isset($modSettings['host_to_dis']))
3963
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3964
-		else
3965
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4195
+		if (!isset($modSettings['host_to_dis'])) {
4196
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4197
+		} else {
4198
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4199
+		}
3966 4200
 
3967 4201
 		// Did host say it didn't find anything?
3968
-		if (strpos($test, 'not found') !== false)
3969
-			$host = '';
4202
+		if (strpos($test, 'not found') !== false) {
4203
+					$host = '';
4204
+		}
3970 4205
 		// Invalid server option?
3971
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3972
-			updateSettings(array('host_to_dis' => 1));
4206
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4207
+					updateSettings(array('host_to_dis' => 1));
4208
+		}
3973 4209
 		// Maybe it found something, after all?
3974
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3975
-			$host = $match[1];
4210
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4211
+					$host = $match[1];
4212
+		}
3976 4213
 	}
3977 4214
 
3978 4215
 	// This is nslookup; usually only Windows, but possibly some Unix?
3979 4216
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3980 4217
 	{
3981 4218
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3982
-		if (strpos($test, 'Non-existent domain') !== false)
3983
-			$host = '';
3984
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3985
-			$host = $match[1];
4219
+		if (strpos($test, 'Non-existent domain') !== false) {
4220
+					$host = '';
4221
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4222
+					$host = $match[1];
4223
+		}
3986 4224
 	}
3987 4225
 
3988 4226
 	// This is the last try :/.
3989
-	if (!isset($host) || $host === false)
3990
-		$host = @gethostbyaddr($ip);
4227
+	if (!isset($host) || $host === false) {
4228
+			$host = @gethostbyaddr($ip);
4229
+	}
3991 4230
 
3992 4231
 	// It took a long time, so let's cache it!
3993
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3994
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4232
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4233
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4234
+	}
3995 4235
 
3996 4236
 	return $host;
3997 4237
 }
@@ -4027,20 +4267,21 @@  discard block
 block discarded – undo
4027 4267
 			{
4028 4268
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4029 4269
 				$total = 0;
4030
-				for ($i = 0; $i < $max_chars; $i++)
4031
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4270
+				for ($i = 0; $i < $max_chars; $i++) {
4271
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4272
+				}
4032 4273
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4033 4274
 			}
4034 4275
 		}
4035 4276
 		return array_unique($returned_ints);
4036
-	}
4037
-	else
4277
+	} else
4038 4278
 	{
4039 4279
 		// Trim characters before and after and add slashes for database insertion.
4040 4280
 		$returned_words = array();
4041
-		foreach ($words as $word)
4042
-			if (($word = trim($word, '-_\'')) !== '')
4281
+		foreach ($words as $word) {
4282
+					if (($word = trim($word, '-_\'')) !== '')
4043 4283
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4284
+		}
4044 4285
 
4045 4286
 		// Filter out all words that occur more than once.
4046 4287
 		return array_unique($returned_words);
@@ -4062,16 +4303,18 @@  discard block
 block discarded – undo
4062 4303
 	global $settings, $txt;
4063 4304
 
4064 4305
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4065
-	if (function_exists('template_create_button') && !$force_use)
4066
-		return template_create_button($name, $alt, $label = '', $custom = '');
4306
+	if (function_exists('template_create_button') && !$force_use) {
4307
+			return template_create_button($name, $alt, $label = '', $custom = '');
4308
+	}
4067 4309
 
4068
-	if (!$settings['use_image_buttons'])
4069
-		return $txt[$alt];
4070
-	elseif (!empty($settings['use_buttons']))
4071
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4072
-	else
4073
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4074
-}
4310
+	if (!$settings['use_image_buttons']) {
4311
+			return $txt[$alt];
4312
+	} elseif (!empty($settings['use_buttons'])) {
4313
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4314
+	} else {
4315
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4316
+	}
4317
+	}
4075 4318
 
4076 4319
 /**
4077 4320
  * Sets up all of the top menu buttons
@@ -4114,9 +4357,10 @@  discard block
 block discarded – undo
4114 4357
 	var user_menus = new smc_PopupMenu();
4115 4358
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4116 4359
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4117
-		if ($context['allow_pm'])
4118
-			addInlineJavaScript('
4360
+		if ($context['allow_pm']) {
4361
+					addInlineJavaScript('
4119 4362
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4363
+		}
4120 4364
 
4121 4365
 		if (!empty($modSettings['enable_ajax_alerts']))
4122 4366
 		{
@@ -4276,88 +4520,96 @@  discard block
 block discarded – undo
4276 4520
 
4277 4521
 		// Now we put the buttons in the context so the theme can use them.
4278 4522
 		$menu_buttons = array();
4279
-		foreach ($buttons as $act => $button)
4280
-			if (!empty($button['show']))
4523
+		foreach ($buttons as $act => $button) {
4524
+					if (!empty($button['show']))
4281 4525
 			{
4282 4526
 				$button['active_button'] = false;
4527
+		}
4283 4528
 
4284 4529
 				// This button needs some action.
4285
-				if (isset($button['action_hook']))
4286
-					$needs_action_hook = true;
4530
+				if (isset($button['action_hook'])) {
4531
+									$needs_action_hook = true;
4532
+				}
4287 4533
 
4288 4534
 				// Make sure the last button truly is the last button.
4289 4535
 				if (!empty($button['is_last']))
4290 4536
 				{
4291
-					if (isset($last_button))
4292
-						unset($menu_buttons[$last_button]['is_last']);
4537
+					if (isset($last_button)) {
4538
+											unset($menu_buttons[$last_button]['is_last']);
4539
+					}
4293 4540
 					$last_button = $act;
4294 4541
 				}
4295 4542
 
4296 4543
 				// Go through the sub buttons if there are any.
4297
-				if (!empty($button['sub_buttons']))
4298
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4544
+				if (!empty($button['sub_buttons'])) {
4545
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4299 4546
 					{
4300 4547
 						if (empty($subbutton['show']))
4301 4548
 							unset($button['sub_buttons'][$key]);
4549
+				}
4302 4550
 
4303 4551
 						// 2nd level sub buttons next...
4304 4552
 						if (!empty($subbutton['sub_buttons']))
4305 4553
 						{
4306 4554
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4307 4555
 							{
4308
-								if (empty($sub_button2['show']))
4309
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4556
+								if (empty($sub_button2['show'])) {
4557
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4558
+								}
4310 4559
 							}
4311 4560
 						}
4312 4561
 					}
4313 4562
 
4314 4563
 				// Does this button have its own icon?
4315
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4316
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4317
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4318
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4319
-				elseif (isset($button['icon']))
4320
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4321
-				else
4322
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4564
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4565
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4566
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4567
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4568
+				} elseif (isset($button['icon'])) {
4569
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4570
+				} else {
4571
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4572
+				}
4323 4573
 
4324 4574
 				$menu_buttons[$act] = $button;
4325 4575
 			}
4326 4576
 
4327
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4328
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4577
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4578
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4579
+		}
4329 4580
 	}
4330 4581
 
4331 4582
 	$context['menu_buttons'] = $menu_buttons;
4332 4583
 
4333 4584
 	// Logging out requires the session id in the url.
4334
-	if (isset($context['menu_buttons']['logout']))
4335
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4585
+	if (isset($context['menu_buttons']['logout'])) {
4586
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4587
+	}
4336 4588
 
4337 4589
 	// Figure out which action we are doing so we can set the active tab.
4338 4590
 	// Default to home.
4339 4591
 	$current_action = 'home';
4340 4592
 
4341
-	if (isset($context['menu_buttons'][$context['current_action']]))
4342
-		$current_action = $context['current_action'];
4343
-	elseif ($context['current_action'] == 'search2')
4344
-		$current_action = 'search';
4345
-	elseif ($context['current_action'] == 'theme')
4346
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4347
-	elseif ($context['current_action'] == 'register2')
4348
-		$current_action = 'register';
4349
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4350
-		$current_action = 'login';
4351
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4352
-		$current_action = 'moderate';
4593
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4594
+			$current_action = $context['current_action'];
4595
+	} elseif ($context['current_action'] == 'search2') {
4596
+			$current_action = 'search';
4597
+	} elseif ($context['current_action'] == 'theme') {
4598
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4599
+	} elseif ($context['current_action'] == 'register2') {
4600
+			$current_action = 'register';
4601
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4602
+			$current_action = 'login';
4603
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4604
+			$current_action = 'moderate';
4605
+	}
4353 4606
 
4354 4607
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4355 4608
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4356 4609
 	{
4357 4610
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4358 4611
 		$context[$current_action] = true;
4359
-	}
4360
-	elseif ($context['current_action'] == 'pm')
4612
+	} elseif ($context['current_action'] == 'pm')
4361 4613
 	{
4362 4614
 		$current_action = 'self_pm';
4363 4615
 		$context['self_pm'] = true;
@@ -4414,12 +4666,14 @@  discard block
 block discarded – undo
4414 4666
 	}
4415 4667
 
4416 4668
 	// Not all actions are simple.
4417
-	if (!empty($needs_action_hook))
4418
-		call_integration_hook('integrate_current_action', array(&$current_action));
4669
+	if (!empty($needs_action_hook)) {
4670
+			call_integration_hook('integrate_current_action', array(&$current_action));
4671
+	}
4419 4672
 
4420
-	if (isset($context['menu_buttons'][$current_action]))
4421
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4422
-}
4673
+	if (isset($context['menu_buttons'][$current_action])) {
4674
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4675
+	}
4676
+	}
4423 4677
 
4424 4678
 /**
4425 4679
  * Generate a random seed and ensure it's stored in settings.
@@ -4443,30 +4697,35 @@  discard block
 block discarded – undo
4443 4697
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4444 4698
 	global $context, $txt;
4445 4699
 
4446
-	if ($db_show_debug === true)
4447
-		$context['debug']['hooks'][] = $hook;
4700
+	if ($db_show_debug === true) {
4701
+			$context['debug']['hooks'][] = $hook;
4702
+	}
4448 4703
 
4449 4704
 	// Need to have some control.
4450
-	if (!isset($context['instances']))
4451
-		$context['instances'] = array();
4705
+	if (!isset($context['instances'])) {
4706
+			$context['instances'] = array();
4707
+	}
4452 4708
 
4453 4709
 	$results = array();
4454
-	if (empty($modSettings[$hook]))
4455
-		return $results;
4710
+	if (empty($modSettings[$hook])) {
4711
+			return $results;
4712
+	}
4456 4713
 
4457 4714
 	$functions = explode(',', $modSettings[$hook]);
4458 4715
 	// Loop through each function.
4459 4716
 	foreach ($functions as $function)
4460 4717
 	{
4461 4718
 		// Hook has been marked as "disabled". Skip it!
4462
-		if (strpos($function, '!') !== false)
4463
-			continue;
4719
+		if (strpos($function, '!') !== false) {
4720
+					continue;
4721
+		}
4464 4722
 
4465 4723
 		$call = call_helper($function, true);
4466 4724
 
4467 4725
 		// Is it valid?
4468
-		if (!empty($call))
4469
-			$results[$function] = call_user_func_array($call, $parameters);
4726
+		if (!empty($call)) {
4727
+					$results[$function] = call_user_func_array($call, $parameters);
4728
+		}
4470 4729
 
4471 4730
 		// Whatever it was suppose to call, it failed :(
4472 4731
 		elseif (!empty($function))
@@ -4482,8 +4741,9 @@  discard block
 block discarded – undo
4482 4741
 			}
4483 4742
 
4484 4743
 			// "Assume" the file resides on $boarddir somewhere...
4485
-			else
4486
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4744
+			else {
4745
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4746
+			}
4487 4747
 		}
4488 4748
 	}
4489 4749
 
@@ -4505,12 +4765,14 @@  discard block
 block discarded – undo
4505 4765
 	global $smcFunc, $modSettings;
4506 4766
 
4507 4767
 	// Any objects?
4508
-	if ($object)
4509
-		$function = $function . '#';
4768
+	if ($object) {
4769
+			$function = $function . '#';
4770
+	}
4510 4771
 
4511 4772
 	// Any files  to load?
4512
-	if (!empty($file) && is_string($file))
4513
-		$function = $file . (!empty($function) ? '|' . $function : '');
4773
+	if (!empty($file) && is_string($file)) {
4774
+			$function = $file . (!empty($function) ? '|' . $function : '');
4775
+	}
4514 4776
 
4515 4777
 	// Get the correct string.
4516 4778
 	$integration_call = $function;
@@ -4532,13 +4794,14 @@  discard block
 block discarded – undo
4532 4794
 		if (!empty($current_functions))
4533 4795
 		{
4534 4796
 			$current_functions = explode(',', $current_functions);
4535
-			if (in_array($integration_call, $current_functions))
4536
-				return;
4797
+			if (in_array($integration_call, $current_functions)) {
4798
+							return;
4799
+			}
4537 4800
 
4538 4801
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4802
+		} else {
4803
+					$permanent_functions = array($integration_call);
4539 4804
 		}
4540
-		else
4541
-			$permanent_functions = array($integration_call);
4542 4805
 
4543 4806
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4544 4807
 	}
@@ -4547,8 +4810,9 @@  discard block
 block discarded – undo
4547 4810
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4548 4811
 
4549 4812
 	// Do nothing, if it's already there.
4550
-	if (in_array($integration_call, $functions))
4551
-		return;
4813
+	if (in_array($integration_call, $functions)) {
4814
+			return;
4815
+	}
4552 4816
 
4553 4817
 	$functions[] = $integration_call;
4554 4818
 	$modSettings[$hook] = implode(',', $functions);
@@ -4571,12 +4835,14 @@  discard block
 block discarded – undo
4571 4835
 	global $smcFunc, $modSettings;
4572 4836
 
4573 4837
 	// Any objects?
4574
-	if ($object)
4575
-		$function = $function . '#';
4838
+	if ($object) {
4839
+			$function = $function . '#';
4840
+	}
4576 4841
 
4577 4842
 	// Any files  to load?
4578
-	if (!empty($file) && is_string($file))
4579
-		$function = $file . '|' . $function;
4843
+	if (!empty($file) && is_string($file)) {
4844
+			$function = $file . '|' . $function;
4845
+	}
4580 4846
 
4581 4847
 	// Get the correct string.
4582 4848
 	$integration_call = $function;
@@ -4597,16 +4863,18 @@  discard block
 block discarded – undo
4597 4863
 	{
4598 4864
 		$current_functions = explode(',', $current_functions);
4599 4865
 
4600
-		if (in_array($integration_call, $current_functions))
4601
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4866
+		if (in_array($integration_call, $current_functions)) {
4867
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4868
+		}
4602 4869
 	}
4603 4870
 
4604 4871
 	// Turn the function list into something usable.
4605 4872
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4606 4873
 
4607 4874
 	// You can only remove it if it's available.
4608
-	if (!in_array($integration_call, $functions))
4609
-		return;
4875
+	if (!in_array($integration_call, $functions)) {
4876
+			return;
4877
+	}
4610 4878
 
4611 4879
 	$functions = array_diff($functions, array($integration_call));
4612 4880
 	$modSettings[$hook] = implode(',', $functions);
@@ -4627,17 +4895,20 @@  discard block
 block discarded – undo
4627 4895
 	global $context, $smcFunc, $txt, $db_show_debug;
4628 4896
 
4629 4897
 	// Really?
4630
-	if (empty($string))
4631
-		return false;
4898
+	if (empty($string)) {
4899
+			return false;
4900
+	}
4632 4901
 
4633 4902
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4634 4903
 	// A closure? should be a callable one.
4635
-	if (is_array($string) || $string instanceof Closure)
4636
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4904
+	if (is_array($string) || $string instanceof Closure) {
4905
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4906
+	}
4637 4907
 
4638 4908
 	// No full objects, sorry! pass a method or a property instead!
4639
-	if (is_object($string))
4640
-		return false;
4909
+	if (is_object($string)) {
4910
+			return false;
4911
+	}
4641 4912
 
4642 4913
 	// Stay vitaminized my friends...
4643 4914
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4646,8 +4917,9 @@  discard block
 block discarded – undo
4646 4917
 	$string = load_file($string);
4647 4918
 
4648 4919
 	// Loaded file failed
4649
-	if (empty($string))
4650
-		return false;
4920
+	if (empty($string)) {
4921
+			return false;
4922
+	}
4651 4923
 
4652 4924
 	// Found a method.
4653 4925
 	if (strpos($string, '::') !== false)
@@ -4668,8 +4940,9 @@  discard block
 block discarded – undo
4668 4940
 				// Add another one to the list.
4669 4941
 				if ($db_show_debug === true)
4670 4942
 				{
4671
-					if (!isset($context['debug']['instances']))
4672
-						$context['debug']['instances'] = array();
4943
+					if (!isset($context['debug']['instances'])) {
4944
+											$context['debug']['instances'] = array();
4945
+					}
4673 4946
 
4674 4947
 					$context['debug']['instances'][$class] = $class;
4675 4948
 				}
@@ -4679,13 +4952,15 @@  discard block
 block discarded – undo
4679 4952
 		}
4680 4953
 
4681 4954
 		// Right then. This is a call to a static method.
4682
-		else
4683
-			$func = array($class, $method);
4955
+		else {
4956
+					$func = array($class, $method);
4957
+		}
4684 4958
 	}
4685 4959
 
4686 4960
 	// Nope! just a plain regular function.
4687
-	else
4688
-		$func = $string;
4961
+	else {
4962
+			$func = $string;
4963
+	}
4689 4964
 
4690 4965
 	// Right, we got what we need, time to do some checks.
4691 4966
 	if (!is_callable($func, false, $callable_name))
@@ -4701,17 +4976,18 @@  discard block
 block discarded – undo
4701 4976
 	else
4702 4977
 	{
4703 4978
 		// What are we gonna do about it?
4704
-		if ($return)
4705
-			return $func;
4979
+		if ($return) {
4980
+					return $func;
4981
+		}
4706 4982
 
4707 4983
 		// If this is a plain function, avoid the heat of calling call_user_func().
4708 4984
 		else
4709 4985
 		{
4710
-			if (is_array($func))
4711
-				call_user_func($func);
4712
-
4713
-			else
4714
-				$func();
4986
+			if (is_array($func)) {
4987
+							call_user_func($func);
4988
+			} else {
4989
+							$func();
4990
+			}
4715 4991
 		}
4716 4992
 	}
4717 4993
 }
@@ -4728,31 +5004,34 @@  discard block
 block discarded – undo
4728 5004
 {
4729 5005
 	global $sourcedir, $txt, $boarddir, $settings;
4730 5006
 
4731
-	if (empty($string))
4732
-		return false;
5007
+	if (empty($string)) {
5008
+			return false;
5009
+	}
4733 5010
 
4734 5011
 	if (strpos($string, '|') !== false)
4735 5012
 	{
4736 5013
 		list ($file, $string) = explode('|', $string);
4737 5014
 
4738 5015
 		// Match the wildcards to their regular vars.
4739
-		if (empty($settings['theme_dir']))
4740
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4741
-
4742
-		else
4743
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5016
+		if (empty($settings['theme_dir'])) {
5017
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5018
+		} else {
5019
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5020
+		}
4744 5021
 
4745 5022
 		// Load the file if it can be loaded.
4746
-		if (file_exists($absPath))
4747
-			require_once($absPath);
5023
+		if (file_exists($absPath)) {
5024
+					require_once($absPath);
5025
+		}
4748 5026
 
4749 5027
 		// No? try a fallback to $sourcedir
4750 5028
 		else
4751 5029
 		{
4752 5030
 			$absPath = $sourcedir .'/'. $file;
4753 5031
 
4754
-			if (file_exists($absPath))
4755
-				require_once($absPath);
5032
+			if (file_exists($absPath)) {
5033
+							require_once($absPath);
5034
+			}
4756 5035
 
4757 5036
 			// Sorry, can't do much for you at this point.
4758 5037
 			else
@@ -4779,8 +5058,9 @@  discard block
 block discarded – undo
4779 5058
 	global $user_info, $smcFunc;
4780 5059
 
4781 5060
 	// Make sure we have something to work with.
4782
-	if (empty($topic))
4783
-		return array();
5061
+	if (empty($topic)) {
5062
+			return array();
5063
+	}
4784 5064
 
4785 5065
 
4786 5066
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4803,8 +5083,9 @@  discard block
 block discarded – undo
4803 5083
 				'topic' => $topic,
4804 5084
 			)
4805 5085
 		);
4806
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4807
-			$temp[] = (int) $row['content_id'];
5086
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5087
+					$temp[] = (int) $row['content_id'];
5088
+		}
4808 5089
 
4809 5090
 		cache_put_data($cache_key, $temp, $ttl);
4810 5091
 	}
@@ -4825,8 +5106,9 @@  discard block
 block discarded – undo
4825 5106
 {
4826 5107
 	global $context;
4827 5108
 
4828
-	if (empty($string))
4829
-		return $string;
5109
+	if (empty($string)) {
5110
+			return $string;
5111
+	}
4830 5112
 
4831 5113
 	// UTF-8 occurences of MS special characters
4832 5114
 	$findchars_utf8 = array(
@@ -4867,10 +5149,11 @@  discard block
 block discarded – undo
4867 5149
 		'--',	// &mdash;
4868 5150
 	);
4869 5151
 
4870
-	if ($context['utf8'])
4871
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4872
-	else
4873
-		$string = str_replace($findchars_iso, $replacechars, $string);
5152
+	if ($context['utf8']) {
5153
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5154
+	} else {
5155
+			$string = str_replace($findchars_iso, $replacechars, $string);
5156
+	}
4874 5157
 
4875 5158
 	return $string;
4876 5159
 }
@@ -4889,49 +5172,59 @@  discard block
 block discarded – undo
4889 5172
 {
4890 5173
 	global $context;
4891 5174
 
4892
-	if (!isset($matches[2]))
4893
-		return '';
5175
+	if (!isset($matches[2])) {
5176
+			return '';
5177
+	}
4894 5178
 
4895 5179
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4896 5180
 
4897 5181
 	// remove left to right / right to left overrides
4898
-	if ($num === 0x202D || $num === 0x202E)
4899
-		return '';
5182
+	if ($num === 0x202D || $num === 0x202E) {
5183
+			return '';
5184
+	}
4900 5185
 
4901 5186
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4902
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4903
-		return '&#' . $num . ';';
5187
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5188
+			return '&#' . $num . ';';
5189
+	}
4904 5190
 
4905 5191
 	if (empty($context['utf8']))
4906 5192
 	{
4907 5193
 		// no control characters
4908
-		if ($num < 0x20)
4909
-			return '';
5194
+		if ($num < 0x20) {
5195
+					return '';
5196
+		}
4910 5197
 		// text is text
4911
-		elseif ($num < 0x80)
4912
-			return chr($num);
5198
+		elseif ($num < 0x80) {
5199
+					return chr($num);
5200
+		}
4913 5201
 		// all others get html-ised
4914
-		else
4915
-			return '&#' . $matches[2] . ';';
4916
-	}
4917
-	else
5202
+		else {
5203
+					return '&#' . $matches[2] . ';';
5204
+		}
5205
+	} else
4918 5206
 	{
4919 5207
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4920 5208
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4921
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4922
-			return '';
5209
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5210
+					return '';
5211
+		}
4923 5212
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4924
-		elseif ($num < 0x80)
4925
-			return chr($num);
5213
+		elseif ($num < 0x80) {
5214
+					return chr($num);
5215
+		}
4926 5216
 		// <0x800 (2048)
4927
-		elseif ($num < 0x800)
4928
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5217
+		elseif ($num < 0x800) {
5218
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5219
+		}
4929 5220
 		// < 0x10000 (65536)
4930
-		elseif ($num < 0x10000)
4931
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5221
+		elseif ($num < 0x10000) {
5222
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5223
+		}
4932 5224
 		// <= 0x10FFFF (1114111)
4933
-		else
4934
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5225
+		else {
5226
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5227
+		}
4935 5228
 	}
4936 5229
 }
4937 5230
 
@@ -4947,28 +5240,34 @@  discard block
 block discarded – undo
4947 5240
  */
4948 5241
 function fixchar__callback($matches)
4949 5242
 {
4950
-	if (!isset($matches[1]))
4951
-		return '';
5243
+	if (!isset($matches[1])) {
5244
+			return '';
5245
+	}
4952 5246
 
4953 5247
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4954 5248
 
4955 5249
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4956 5250
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4957
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4958
-		return '';
5251
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5252
+			return '';
5253
+	}
4959 5254
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4960
-	elseif ($num < 0x80)
4961
-		return chr($num);
5255
+	elseif ($num < 0x80) {
5256
+			return chr($num);
5257
+	}
4962 5258
 	// <0x800 (2048)
4963
-	elseif ($num < 0x800)
4964
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5259
+	elseif ($num < 0x800) {
5260
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5261
+	}
4965 5262
 	// < 0x10000 (65536)
4966
-	elseif ($num < 0x10000)
4967
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5263
+	elseif ($num < 0x10000) {
5264
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5265
+	}
4968 5266
 	// <= 0x10FFFF (1114111)
4969
-	else
4970
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4971
-}
5267
+	else {
5268
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5269
+	}
5270
+	}
4972 5271
 
4973 5272
 /**
4974 5273
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4981,17 +5280,19 @@  discard block
 block discarded – undo
4981 5280
  */
4982 5281
 function entity_fix__callback($matches)
4983 5282
 {
4984
-	if (!isset($matches[2]))
4985
-		return '';
5283
+	if (!isset($matches[2])) {
5284
+			return '';
5285
+	}
4986 5286
 
4987 5287
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4988 5288
 
4989 5289
 	// we don't allow control characters, characters out of range, byte markers, etc
4990
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4991
-		return '';
4992
-	else
4993
-		return '&#' . $num . ';';
4994
-}
5290
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5291
+			return '';
5292
+	} else {
5293
+			return '&#' . $num . ';';
5294
+	}
5295
+	}
4995 5296
 
4996 5297
 /**
4997 5298
  * Return a Gravatar URL based on
@@ -5015,18 +5316,23 @@  discard block
 block discarded – undo
5015 5316
 		$ratings = array('G', 'PG', 'R', 'X');
5016 5317
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5017 5318
 		$url_params = array();
5018
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5019
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5020
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5021
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5022
-		if (!empty($modSettings['avatar_max_width_external']))
5023
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5024
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5025
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5319
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5320
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5321
+		}
5322
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5323
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5324
+		}
5325
+		if (!empty($modSettings['avatar_max_width_external'])) {
5326
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5327
+		}
5328
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5329
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5026 5330
 				$size_string = $modSettings['avatar_max_height_external'];
5331
+		}
5027 5332
 
5028
-		if (!empty($size_string))
5029
-			$url_params[] = 's=' . $size_string;
5333
+		if (!empty($size_string)) {
5334
+					$url_params[] = 's=' . $size_string;
5335
+		}
5030 5336
 	}
5031 5337
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5032 5338
 
@@ -5045,22 +5351,26 @@  discard block
 block discarded – undo
5045 5351
 	static $timezones = null, $lastwhen = null;
5046 5352
 
5047 5353
 	// No point doing this over if we already did it once
5048
-	if (!empty($timezones) && $when == $lastwhen)
5049
-		return $timezones;
5050
-	else
5051
-		$lastwhen = $when;
5354
+	if (!empty($timezones) && $when == $lastwhen) {
5355
+			return $timezones;
5356
+	} else {
5357
+			$lastwhen = $when;
5358
+	}
5052 5359
 
5053 5360
 	// Parseable datetime string?
5054
-	if (is_int($timestamp = strtotime($when)))
5055
-		$when = $timestamp;
5361
+	if (is_int($timestamp = strtotime($when))) {
5362
+			$when = $timestamp;
5363
+	}
5056 5364
 
5057 5365
 	// A Unix timestamp?
5058
-	elseif (is_numeric($when))
5059
-		$when = intval($when);
5366
+	elseif (is_numeric($when)) {
5367
+			$when = intval($when);
5368
+	}
5060 5369
 
5061 5370
 	// Invalid value? Just get current Unix timestamp.
5062
-	else
5063
-		$when = time();
5371
+	else {
5372
+			$when = time();
5373
+	}
5064 5374
 
5065 5375
 	// We'll need these too
5066 5376
 	$date_when = date_create('@' . $when);
@@ -5124,8 +5434,9 @@  discard block
 block discarded – undo
5124 5434
 	foreach ($priority_countries as $country)
5125 5435
 	{
5126 5436
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5127
-		if (!empty($country_tzids))
5128
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5437
+		if (!empty($country_tzids)) {
5438
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5439
+		}
5129 5440
 	}
5130 5441
 
5131 5442
 	// Process the preferred timezones first, then the rest.
@@ -5135,8 +5446,9 @@  discard block
 block discarded – undo
5135 5446
 	foreach ($tzids as $tzid)
5136 5447
 	{
5137 5448
 		// We don't want UTC right now
5138
-		if ($tzid == 'UTC')
5139
-			continue;
5449
+		if ($tzid == 'UTC') {
5450
+					continue;
5451
+		}
5140 5452
 
5141 5453
 		$tz = timezone_open($tzid);
5142 5454
 
@@ -5157,8 +5469,9 @@  discard block
 block discarded – undo
5157 5469
 		}
5158 5470
 
5159 5471
 		// A time zone from a prioritized country?
5160
-		if (in_array($tzid, $priority_tzids))
5161
-			$priority_zones[$tzkey] = true;
5472
+		if (in_array($tzid, $priority_tzids)) {
5473
+					$priority_zones[$tzkey] = true;
5474
+		}
5162 5475
 
5163 5476
 		// Keep track of the location and offset for this tzid
5164 5477
 		$tzid_parts = explode('/', $tzid);
@@ -5177,15 +5490,17 @@  discard block
 block discarded – undo
5177 5490
 	{
5178 5491
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5179 5492
 
5180
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5181
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5182
-		else
5183
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5493
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5494
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5495
+		} else {
5496
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5497
+		}
5184 5498
 
5185
-		if (isset($priority_zones[$tzkey]))
5186
-			$priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5187
-		else
5188
-			$timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5499
+		if (isset($priority_zones[$tzkey])) {
5500
+					$priority_timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5501
+		} else {
5502
+					$timezones[$tzvalue['tzid']] = $tzvalue['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']';
5503
+		}
5189 5504
 	}
5190 5505
 
5191 5506
 	$timezones = array_merge(
@@ -5239,9 +5554,9 @@  discard block
 block discarded – undo
5239 5554
 			'Indian/Kerguelen' => 'TFT',
5240 5555
 		);
5241 5556
 
5242
-		if (!empty($missing_tz_abbrs[$tzid]))
5243
-			$tz_abbrev = $missing_tz_abbrs[$tzid];
5244
-		else
5557
+		if (!empty($missing_tz_abbrs[$tzid])) {
5558
+					$tz_abbrev = $missing_tz_abbrs[$tzid];
5559
+		} else
5245 5560
 		{
5246 5561
 			// Russia likes to experiment with time zones often, and names them as offsets from Moscow
5247 5562
 			$tz_location = timezone_location_get(timezone_open($tzid));
@@ -5269,8 +5584,9 @@  discard block
 block discarded – undo
5269 5584
  */
5270 5585
 function inet_ptod($ip_address)
5271 5586
 {
5272
-	if (!isValidIP($ip_address))
5273
-		return $ip_address;
5587
+	if (!isValidIP($ip_address)) {
5588
+			return $ip_address;
5589
+	}
5274 5590
 
5275 5591
 	$bin = inet_pton($ip_address);
5276 5592
 	return $bin;
@@ -5282,13 +5598,15 @@  discard block
 block discarded – undo
5282 5598
  */
5283 5599
 function inet_dtop($bin)
5284 5600
 {
5285
-	if(empty($bin))
5286
-		return '';
5601
+	if(empty($bin)) {
5602
+			return '';
5603
+	}
5287 5604
 
5288 5605
 	global $db_type;
5289 5606
 
5290
-	if ($db_type == 'postgresql')
5291
-		return $bin;
5607
+	if ($db_type == 'postgresql') {
5608
+			return $bin;
5609
+	}
5292 5610
 
5293 5611
 	$ip_address = inet_ntop($bin);
5294 5612
 
@@ -5313,26 +5631,32 @@  discard block
 block discarded – undo
5313 5631
  */
5314 5632
 function _safe_serialize($value)
5315 5633
 {
5316
-	if(is_null($value))
5317
-		return 'N;';
5634
+	if(is_null($value)) {
5635
+			return 'N;';
5636
+	}
5318 5637
 
5319
-	if(is_bool($value))
5320
-		return 'b:'. (int) $value .';';
5638
+	if(is_bool($value)) {
5639
+			return 'b:'. (int) $value .';';
5640
+	}
5321 5641
 
5322
-	if(is_int($value))
5323
-		return 'i:'. $value .';';
5642
+	if(is_int($value)) {
5643
+			return 'i:'. $value .';';
5644
+	}
5324 5645
 
5325
-	if(is_float($value))
5326
-		return 'd:'. str_replace(',', '.', $value) .';';
5646
+	if(is_float($value)) {
5647
+			return 'd:'. str_replace(',', '.', $value) .';';
5648
+	}
5327 5649
 
5328
-	if(is_string($value))
5329
-		return 's:'. strlen($value) .':"'. $value .'";';
5650
+	if(is_string($value)) {
5651
+			return 's:'. strlen($value) .':"'. $value .'";';
5652
+	}
5330 5653
 
5331 5654
 	if(is_array($value))
5332 5655
 	{
5333 5656
 		$out = '';
5334
-		foreach($value as $k => $v)
5335
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5657
+		foreach($value as $k => $v) {
5658
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5659
+		}
5336 5660
 
5337 5661
 		return 'a:'. count($value) .':{'. $out .'}';
5338 5662
 	}
@@ -5358,8 +5682,9 @@  discard block
 block discarded – undo
5358 5682
 
5359 5683
 	$out = _safe_serialize($value);
5360 5684
 
5361
-	if (isset($mbIntEnc))
5362
-		mb_internal_encoding($mbIntEnc);
5685
+	if (isset($mbIntEnc)) {
5686
+			mb_internal_encoding($mbIntEnc);
5687
+	}
5363 5688
 
5364 5689
 	return $out;
5365 5690
 }
@@ -5376,8 +5701,9 @@  discard block
 block discarded – undo
5376 5701
 function _safe_unserialize($str)
5377 5702
 {
5378 5703
 	// Input  is not a string.
5379
-	if(empty($str) || !is_string($str))
5380
-		return false;
5704
+	if(empty($str) || !is_string($str)) {
5705
+			return false;
5706
+	}
5381 5707
 
5382 5708
 	$stack = array();
5383 5709
 	$expected = array();
@@ -5393,43 +5719,38 @@  discard block
 block discarded – undo
5393 5719
 	while($state != 1)
5394 5720
 	{
5395 5721
 		$type = isset($str[0]) ? $str[0] : '';
5396
-		if($type == '}')
5397
-			$str = substr($str, 1);
5398
-
5399
-		else if($type == 'N' && $str[1] == ';')
5722
+		if($type == '}') {
5723
+					$str = substr($str, 1);
5724
+		} else if($type == 'N' && $str[1] == ';')
5400 5725
 		{
5401 5726
 			$value = null;
5402 5727
 			$str = substr($str, 2);
5403
-		}
5404
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5728
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5405 5729
 		{
5406 5730
 			$value = $matches[1] == '1' ? true : false;
5407 5731
 			$str = substr($str, 4);
5408
-		}
5409
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5732
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5410 5733
 		{
5411 5734
 			$value = (int)$matches[1];
5412 5735
 			$str = $matches[2];
5413
-		}
5414
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5736
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5415 5737
 		{
5416 5738
 			$value = (float)$matches[1];
5417 5739
 			$str = $matches[3];
5418
-		}
5419
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5740
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5420 5741
 		{
5421 5742
 			$value = substr($matches[2], 0, (int)$matches[1]);
5422 5743
 			$str = substr($matches[2], (int)$matches[1] + 2);
5423
-		}
5424
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5744
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5425 5745
 		{
5426 5746
 			$expectedLength = (int)$matches[1];
5427 5747
 			$str = $matches[2];
5428 5748
 		}
5429 5749
 
5430 5750
 		// Object or unknown/malformed type.
5431
-		else
5432
-			return false;
5751
+		else {
5752
+					return false;
5753
+		}
5433 5754
 
5434 5755
 		switch($state)
5435 5756
 		{
@@ -5457,8 +5778,9 @@  discard block
 block discarded – undo
5457 5778
 				if($type == '}')
5458 5779
 				{
5459 5780
 					// Array size is less than expected.
5460
-					if(count($list) < end($expected))
5461
-						return false;
5781
+					if(count($list) < end($expected)) {
5782
+											return false;
5783
+					}
5462 5784
 
5463 5785
 					unset($list);
5464 5786
 					$list = &$stack[count($stack)-1];
@@ -5467,8 +5789,9 @@  discard block
 block discarded – undo
5467 5789
 					// Go to terminal state if we're at the end of the root array.
5468 5790
 					array_pop($expected);
5469 5791
 
5470
-					if(count($expected) == 0)
5471
-						$state = 1;
5792
+					if(count($expected) == 0) {
5793
+											$state = 1;
5794
+					}
5472 5795
 
5473 5796
 					break;
5474 5797
 				}
@@ -5476,8 +5799,9 @@  discard block
 block discarded – undo
5476 5799
 				if($type == 'i' || $type == 's')
5477 5800
 				{
5478 5801
 					// Array size exceeds expected length.
5479
-					if(count($list) >= end($expected))
5480
-						return false;
5802
+					if(count($list) >= end($expected)) {
5803
+											return false;
5804
+					}
5481 5805
 
5482 5806
 					$key = $value;
5483 5807
 					$state = 3;
@@ -5511,8 +5835,9 @@  discard block
 block discarded – undo
5511 5835
 	}
5512 5836
 
5513 5837
 	// Trailing data in input.
5514
-	if(!empty($str))
5515
-		return false;
5838
+	if(!empty($str)) {
5839
+			return false;
5840
+	}
5516 5841
 
5517 5842
 	return $data;
5518 5843
 }
@@ -5535,8 +5860,9 @@  discard block
 block discarded – undo
5535 5860
 
5536 5861
 	$out = _safe_unserialize($str);
5537 5862
 
5538
-	if (isset($mbIntEnc))
5539
-		mb_internal_encoding($mbIntEnc);
5863
+	if (isset($mbIntEnc)) {
5864
+			mb_internal_encoding($mbIntEnc);
5865
+	}
5540 5866
 
5541 5867
 	return $out;
5542 5868
 }
@@ -5551,12 +5877,14 @@  discard block
 block discarded – undo
5551 5877
 function smf_chmod($file, $value = 0)
5552 5878
 {
5553 5879
 	// No file? no checks!
5554
-	if (empty($file))
5555
-		return false;
5880
+	if (empty($file)) {
5881
+			return false;
5882
+	}
5556 5883
 
5557 5884
 	// Already writable?
5558
-	if (is_writable($file))
5559
-		return true;
5885
+	if (is_writable($file)) {
5886
+			return true;
5887
+	}
5560 5888
 
5561 5889
 	// Do we have a file or a dir?
5562 5890
 	$isDir = is_dir($file);
@@ -5572,10 +5900,9 @@  discard block
 block discarded – undo
5572 5900
 		{
5573 5901
 			$isWritable = true;
5574 5902
 			break;
5903
+		} else {
5904
+					@chmod($file, $val);
5575 5905
 		}
5576
-
5577
-		else
5578
-			@chmod($file, $val);
5579 5906
 	}
5580 5907
 
5581 5908
 	return $isWritable;
@@ -5594,8 +5921,9 @@  discard block
 block discarded – undo
5594 5921
 	global $txt;
5595 5922
 
5596 5923
 	// Come on...
5597
-	if (empty($json) || !is_string($json))
5598
-		return array();
5924
+	if (empty($json) || !is_string($json)) {
5925
+			return array();
5926
+	}
5599 5927
 
5600 5928
 	$returnArray = @json_decode($json, $returnAsArray);
5601 5929
 
@@ -5633,11 +5961,11 @@  discard block
 block discarded – undo
5633 5961
 		$jsonDebug = $jsonDebug[0];
5634 5962
 		loadLanguage('Errors');
5635 5963
 
5636
-		if (!empty($jsonDebug))
5637
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5638
-
5639
-		else
5640
-			log_error($txt['json_'. $jsonError], 'critical');
5964
+		if (!empty($jsonDebug)) {
5965
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5966
+		} else {
5967
+					log_error($txt['json_'. $jsonError], 'critical');
5968
+		}
5641 5969
 
5642 5970
 		// Everyone expects an array.
5643 5971
 		return array();
@@ -5671,8 +5999,9 @@  discard block
 block discarded – undo
5671 5999
 	global $db_show_debug, $modSettings;
5672 6000
 
5673 6001
 	// Defensive programming anyone?
5674
-	if (empty($data))
5675
-		return false;
6002
+	if (empty($data)) {
6003
+			return false;
6004
+	}
5676 6005
 
5677 6006
 	// Don't need extra stuff...
5678 6007
 	$db_show_debug = false;
@@ -5680,11 +6009,11 @@  discard block
 block discarded – undo
5680 6009
 	// Kill anything else.
5681 6010
 	ob_end_clean();
5682 6011
 
5683
-	if (!empty($modSettings['CompressedOutput']))
5684
-		@ob_start('ob_gzhandler');
5685
-
5686
-	else
5687
-		ob_start();
6012
+	if (!empty($modSettings['CompressedOutput'])) {
6013
+			@ob_start('ob_gzhandler');
6014
+	} else {
6015
+			ob_start();
6016
+	}
5688 6017
 
5689 6018
 	// Set the header.
5690 6019
 	header($type);
@@ -5716,8 +6045,9 @@  discard block
 block discarded – undo
5716 6045
 	static $done = false;
5717 6046
 
5718 6047
 	// If we don't need to do anything, don't
5719
-	if (!$update && $done)
5720
-		return;
6048
+	if (!$update && $done) {
6049
+			return;
6050
+	}
5721 6051
 
5722 6052
 	// Should we get a new copy of the official list of TLDs?
5723 6053
 	if ($update)
@@ -5726,8 +6056,9 @@  discard block
 block discarded – undo
5726 6056
 		$tlds = fetch_web_data('https://data.iana.org/TLD/tlds-alpha-by-domain.txt');
5727 6057
 
5728 6058
 		// If the Internet Assigned Numbers Authority can't be reached, the Internet is gone. We're probably running on a server hidden in a bunker deep underground to protect it from marauding bandits roaming on the surface. We don't want to waste precious electricity on pointlessly repeating background tasks, so we'll wait until the next regularly scheduled update to see if civilization has been restored.
5729
-		if ($tlds === false)
5730
-			$postapocalypticNightmare = true;
6059
+		if ($tlds === false) {
6060
+					$postapocalypticNightmare = true;
6061
+		}
5731 6062
 	}
5732 6063
 	// If we aren't updating and the regex is valid, we're done
5733 6064
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -5742,10 +6073,11 @@  discard block
 block discarded – undo
5742 6073
 		// Clean $tlds and convert it to an array
5743 6074
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5744 6075
 			$line = trim($line);
5745
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5746
-				return false;
5747
-			else
5748
-				return true;
6076
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6077
+							return false;
6078
+			} else {
6079
+							return true;
6080
+			}
5749 6081
 		});
5750 6082
 
5751 6083
 		// Convert Punycode to Unicode
@@ -5799,8 +6131,9 @@  discard block
 block discarded – undo
5799 6131
 						$idx += $digit * $w;
5800 6132
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5801 6133
 
5802
-						if ($digit < $t)
5803
-							break;
6134
+						if ($digit < $t) {
6135
+													break;
6136
+						}
5804 6137
 
5805 6138
 						$w = (int) ($w * ($base - $t));
5806 6139
 					}
@@ -5809,8 +6142,9 @@  discard block
 block discarded – undo
5809 6142
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5810 6143
 					$delta += intval($delta / ($deco_len + 1));
5811 6144
 
5812
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5813
-						$delta = intval($delta / ($base - $tmin));
6145
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
6146
+											$delta = intval($delta / ($base - $tmin));
6147
+					}
5814 6148
 
5815 6149
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5816 6150
 					$is_first = false;
@@ -5819,8 +6153,9 @@  discard block
 block discarded – undo
5819 6153
 
5820 6154
 					if ($deco_len > 0)
5821 6155
 					{
5822
-						for ($i = $deco_len; $i > $idx; $i--)
5823
-							$decoded[$i] = $decoded[($i - 1)];
6156
+						for ($i = $deco_len; $i > $idx; $i--) {
6157
+													$decoded[$i] = $decoded[($i - 1)];
6158
+						}
5824 6159
 					}
5825 6160
 					$decoded[$idx++] = $char;
5826 6161
 				}
@@ -5828,24 +6163,29 @@  discard block
 block discarded – undo
5828 6163
 				foreach ($decoded as $k => $v)
5829 6164
 				{
5830 6165
 					// 7bit are transferred literally
5831
-					if ($v < 128)
5832
-						$output .= chr($v);
6166
+					if ($v < 128) {
6167
+											$output .= chr($v);
6168
+					}
5833 6169
 
5834 6170
 					// 2 bytes
5835
-					elseif ($v < (1 << 11))
5836
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6171
+					elseif ($v < (1 << 11)) {
6172
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
6173
+					}
5837 6174
 
5838 6175
 					// 3 bytes
5839
-					elseif ($v < (1 << 16))
5840
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6176
+					elseif ($v < (1 << 16)) {
6177
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6178
+					}
5841 6179
 
5842 6180
 					// 4 bytes
5843
-					elseif ($v < (1 << 21))
5844
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6181
+					elseif ($v < (1 << 21)) {
6182
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
6183
+					}
5845 6184
 
5846 6185
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5847
-					else
5848
-						$output .= $safe_char;
6186
+					else {
6187
+											$output .= $safe_char;
6188
+					}
5849 6189
 				}
5850 6190
 
5851 6191
 				$output_parts[] = $output;
@@ -5938,8 +6278,7 @@  discard block
 block discarded – undo
5938 6278
 
5939 6279
 		$strlen = 'mb_strlen';
5940 6280
 		$substr = 'mb_substr';
5941
-	}
5942
-	else
6281
+	} else
5943 6282
 	{
5944 6283
 		$strlen = $smcFunc['strlen'];
5945 6284
 		$substr = $smcFunc['substr'];
@@ -5953,20 +6292,21 @@  discard block
 block discarded – undo
5953 6292
 
5954 6293
 		$first = $substr($string, 0, 1);
5955 6294
 
5956
-		if (empty($index[$first]))
5957
-			$index[$first] = array();
6295
+		if (empty($index[$first])) {
6296
+					$index[$first] = array();
6297
+		}
5958 6298
 
5959 6299
 		if ($strlen($string) > 1)
5960 6300
 		{
5961 6301
 			// Sanity check on recursion
5962
-			if ($depth > 99)
5963
-				$index[$first][$substr($string, 1)] = '';
5964
-
5965
-			else
5966
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6302
+			if ($depth > 99) {
6303
+							$index[$first][$substr($string, 1)] = '';
6304
+			} else {
6305
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6306
+			}
6307
+		} else {
6308
+					$index[$first][''] = '';
5967 6309
 		}
5968
-		else
5969
-			$index[$first][''] = '';
5970 6310
 
5971 6311
 		$depth--;
5972 6312
 		return $index;
@@ -5989,9 +6329,9 @@  discard block
 block discarded – undo
5989 6329
 			$key_regex = preg_quote($key, $delim);
5990 6330
 			$new_key = $key;
5991 6331
 
5992
-			if (empty($value))
5993
-				$sub_regex = '';
5994
-			else
6332
+			if (empty($value)) {
6333
+							$sub_regex = '';
6334
+			} else
5995 6335
 			{
5996 6336
 				$sub_regex = $index_to_regex($value, $delim);
5997 6337
 
@@ -5999,22 +6339,22 @@  discard block
 block discarded – undo
5999 6339
 				{
6000 6340
 					$new_key_array = explode('(?'.'>', $sub_regex);
6001 6341
 					$new_key .= $new_key_array[0];
6342
+				} else {
6343
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6002 6344
 				}
6003
-				else
6004
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6005 6345
 			}
6006 6346
 
6007
-			if ($depth > 1)
6008
-				$regex[$new_key] = $key_regex . $sub_regex;
6009
-			else
6347
+			if ($depth > 1) {
6348
+							$regex[$new_key] = $key_regex . $sub_regex;
6349
+			} else
6010 6350
 			{
6011 6351
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6012 6352
 				{
6013 6353
 					$regex[$new_key] = $key_regex . $sub_regex;
6014 6354
 					unset($index[$key]);
6355
+				} else {
6356
+									break;
6015 6357
 				}
6016
-				else
6017
-					break;
6018 6358
 			}
6019 6359
 		}
6020 6360
 
@@ -6023,10 +6363,11 @@  discard block
 block discarded – undo
6023 6363
 			$l1 = $strlen($k1);
6024 6364
 			$l2 = $strlen($k2);
6025 6365
 
6026
-			if ($l1 == $l2)
6027
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6028
-			else
6029
-				return $l1 > $l2 ? -1 : 1;
6366
+			if ($l1 == $l2) {
6367
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6368
+			} else {
6369
+							return $l1 > $l2 ? -1 : 1;
6370
+			}
6030 6371
 		});
6031 6372
 
6032 6373
 		$depth--;
@@ -6037,21 +6378,24 @@  discard block
 block discarded – undo
6037 6378
 	$index = array();
6038 6379
 	$regex = '';
6039 6380
 
6040
-	foreach ($strings as $string)
6041
-		$index = $add_string_to_index($string, $index);
6381
+	foreach ($strings as $string) {
6382
+			$index = $add_string_to_index($string, $index);
6383
+	}
6042 6384
 
6043 6385
 	if ($returnArray === true)
6044 6386
 	{
6045 6387
 		$regex = array();
6046
-		while (!empty($index))
6047
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6388
+		while (!empty($index)) {
6389
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6390
+		}
6391
+	} else {
6392
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6048 6393
 	}
6049
-	else
6050
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6051 6394
 
6052 6395
 	// Restore PHP's internal character encoding to whatever it was originally
6053
-	if (!empty($current_encoding))
6054
-		mb_internal_encoding($current_encoding);
6396
+	if (!empty($current_encoding)) {
6397
+			mb_internal_encoding($current_encoding);
6398
+	}
6055 6399
 
6056 6400
 	return $regex;
6057 6401
 }
@@ -6094,13 +6438,15 @@  discard block
 block discarded – undo
6094 6438
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6095 6439
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6096 6440
 	$headers = @get_headers($url);
6097
-	if ($headers === false)
6098
-		return false;
6441
+	if ($headers === false) {
6442
+			return false;
6443
+	}
6099 6444
 
6100 6445
 	// Now to see if it came back https...
6101 6446
 	// First check for a redirect status code in first row (301, 302, 307)
6102
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6103
-		return false;
6447
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6448
+			return false;
6449
+	}
6104 6450
 
6105 6451
 	// Search for the location entry to confirm https
6106 6452
 	$result = false;
@@ -6136,8 +6482,7 @@  discard block
 block discarded – undo
6136 6482
 		$is_admin = $user_info['is_admin'];
6137 6483
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6138 6484
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6139
-	}
6140
-	else
6485
+	} else
6141 6486
 	{
6142 6487
 		$request = $smcFunc['db_query']('', '
6143 6488
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6151,17 +6496,19 @@  discard block
 block discarded – undo
6151 6496
 
6152 6497
 		$row = $smcFunc['db_fetch_assoc']($request);
6153 6498
 
6154
-		if (empty($row['additional_groups']))
6155
-			$groups = array($row['id_group'], $row['id_post_group']);
6156
-		else
6157
-			$groups = array_merge(
6499
+		if (empty($row['additional_groups'])) {
6500
+					$groups = array($row['id_group'], $row['id_post_group']);
6501
+		} else {
6502
+					$groups = array_merge(
6158 6503
 					array($row['id_group'], $row['id_post_group']),
6159 6504
 					explode(',', $row['additional_groups'])
6160 6505
 			);
6506
+		}
6161 6507
 
6162 6508
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6163
-		foreach ($groups as $k => $v)
6164
-			$groups[$k] = (int) $v;
6509
+		foreach ($groups as $k => $v) {
6510
+					$groups[$k] = (int) $v;
6511
+		}
6165 6512
 
6166 6513
 		$is_admin = in_array(1, $groups);
6167 6514
 
@@ -6178,8 +6525,9 @@  discard block
 block discarded – undo
6178 6525
 				'current_member' => $userid,
6179 6526
 			)
6180 6527
 		);
6181
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6182
-			$boards_mod[] = $row['id_board'];
6528
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6529
+					$boards_mod[] = $row['id_board'];
6530
+		}
6183 6531
 		$smcFunc['db_free_result']($request);
6184 6532
 
6185 6533
 		// Can any of the groups they're in moderate any of the boards?
@@ -6191,8 +6539,9 @@  discard block
 block discarded – undo
6191 6539
 				'groups' => $groups,
6192 6540
 			)
6193 6541
 		);
6194
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6195
-			$boards_mod[] = $row['id_board'];
6542
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6543
+					$boards_mod[] = $row['id_board'];
6544
+		}
6196 6545
 		$smcFunc['db_free_result']($request);
6197 6546
 
6198 6547
 		// Just in case we've got duplicates here...
@@ -6202,21 +6551,25 @@  discard block
 block discarded – undo
6202 6551
 	}
6203 6552
 
6204 6553
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6205
-	if ($is_admin)
6206
-		$query_part['query_see_board'] = '1=1';
6554
+	if ($is_admin) {
6555
+			$query_part['query_see_board'] = '1=1';
6556
+	}
6207 6557
 	// Otherwise just the groups in $user_info['groups'].
6208
-	else
6209
-		$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'] : '') . ')';
6558
+	else {
6559
+			$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'] : '') . ')';
6560
+	}
6210 6561
 
6211 6562
 	// Build the list of boards they WANT to see.
6212 6563
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6213 6564
 
6214 6565
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6215
-	if (empty($ignoreboards))
6216
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6566
+	if (empty($ignoreboards)) {
6567
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6568
+	}
6217 6569
 	// Ok I guess they don't want to see all the boards
6218
-	else
6219
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6570
+	else {
6571
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6572
+	}
6220 6573
 
6221 6574
 	return $query_part;
6222 6575
 }
@@ -6230,10 +6583,11 @@  discard block
 block discarded – undo
6230 6583
 {
6231 6584
 	$secure = false;
6232 6585
 
6233
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6234
-		$secure = true;
6235
-	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')
6236
-		$secure = true;
6586
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6587
+			$secure = true;
6588
+	} 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') {
6589
+			$secure = true;
6590
+	}
6237 6591
 
6238 6592
 	return $secure;
6239 6593
 }
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +801 added lines, -607 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 excpiclity 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
 
@@ -392,9 +409,9 @@  discard block
 block discarded – undo
392 409
 				break;
393 410
 			}
394 411
 		}
412
+	} else {
413
+			$id_member = 0;
395 414
 	}
396
-	else
397
-		$id_member = 0;
398 415
 
399 416
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
400 417
 	{
@@ -402,8 +419,9 @@  discard block
 block discarded – undo
402 419
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
403 420
 
404 421
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
405
-		if (empty($cookie_data))
406
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
422
+		if (empty($cookie_data)) {
423
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
424
+		}
407 425
 
408 426
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
409 427
 
@@ -411,16 +429,17 @@  discard block
 block discarded – undo
411 429
 
412 430
 		// Make sure the cookie is set to the correct domain and path
413 431
 		require_once($sourcedir . '/Subs-Auth.php');
414
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
415
-			setLoginCookie((int) $login_span - time(), $id_member);
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
432
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
433
+					setLoginCookie((int) $login_span - time(), $id_member);
434
+		}
435
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 436
 	{
419 437
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 438
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
421 439
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
440
+		if (empty($cookie_data)) {
441
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		}
424 443
 
425 444
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
426 445
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -445,33 +464,37 @@  discard block
 block discarded – undo
445 464
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 465
 			$smcFunc['db_free_result']($request);
447 466
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
449
-				if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
467
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
468
+							if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
450 469
 					$user_settings['avatar'] = $image_proxy_url . urlencode($user_settings['avatar']);
451
-				else
452
-					$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
470
+			} else {
471
+									$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
472
+				}
453 473
 
454
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
455
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
474
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
475
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
476
+			}
456 477
 		}
457 478
 
458 479
 		// Did we find 'im?  If not, junk it.
459 480
 		if (!empty($user_settings))
460 481
 		{
461 482
 			// As much as the password should be right, we can assume the integration set things up.
462
-			if (!empty($already_verified) && $already_verified === true)
463
-				$check = true;
483
+			if (!empty($already_verified) && $already_verified === true) {
484
+							$check = true;
485
+			}
464 486
 			// SHA-512 hash should be 128 characters long.
465
-			elseif (strlen($password) == 128)
466
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
467
-			else
468
-				$check = false;
487
+			elseif (strlen($password) == 128) {
488
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
489
+			} else {
490
+							$check = false;
491
+			}
469 492
 
470 493
 			// Wrong password or not activated - either way, you're going nowhere.
471 494
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
495
+		} else {
496
+					$id_member = 0;
472 497
 		}
473
-		else
474
-			$id_member = 0;
475 498
 
476 499
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
477 500
 		if (!$id_member)
@@ -500,8 +523,9 @@  discard block
 block discarded – undo
500 523
 
501 524
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
502 525
 
503
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
504
-						$tfasecret = null;
526
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
527
+											$tfasecret = null;
528
+					}
505 529
 				}
506 530
 
507 531
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -523,10 +547,12 @@  discard block
 block discarded – undo
523 547
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
524 548
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
525 549
 		{
526
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
550
+			if ($modSettings['tfa_mode'] == 2) {
551
+				//only do this if we are just forcing SOME membergroups
527 552
 			{
528 553
 				//Build an array of ALL user membergroups.
529 554
 				$full_groups = array($user_settings['id_group']);
555
+			}
530 556
 				if (!empty($user_settings['additional_groups']))
531 557
 				{
532 558
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -546,15 +572,17 @@  discard block
 block discarded – undo
546 572
 				);
547 573
 				$row = $smcFunc['db_fetch_assoc']($request);
548 574
 				$smcFunc['db_free_result']($request);
575
+			} else {
576
+							$row['total'] = 1;
549 577
 			}
550
-			else
551
-				$row['total'] = 1; //simplifies logics in the next "if"
578
+			//simplifies logics in the next "if"
552 579
 
553 580
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
554 581
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
555 582
 
556
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
557
-				redirectexit('action=profile;area=tfasetup;forced');
583
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
584
+							redirectexit('action=profile;area=tfasetup;forced');
585
+			}
558 586
 		}
559 587
 	}
560 588
 
@@ -591,33 +619,37 @@  discard block
 block discarded – undo
591 619
 				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']));
592 620
 				$user_settings['last_login'] = time();
593 621
 
594
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
595
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
622
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
623
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
624
+				}
596 625
 
597
-				if (!empty($modSettings['cache_enable']))
598
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
626
+				if (!empty($modSettings['cache_enable'])) {
627
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
628
+				}
599 629
 			}
630
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
631
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
600 632
 		}
601
-		elseif (empty($_SESSION['id_msg_last_visit']))
602
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
603 633
 
604 634
 		$username = $user_settings['member_name'];
605 635
 
606
-		if (empty($user_settings['additional_groups']))
607
-			$user_info = array(
636
+		if (empty($user_settings['additional_groups'])) {
637
+					$user_info = array(
608 638
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
609 639
 			);
610
-		else
611
-			$user_info = array(
640
+		} else {
641
+					$user_info = array(
612 642
 				'groups' => array_merge(
613 643
 					array($user_settings['id_group'], $user_settings['id_post_group']),
614 644
 					explode(',', $user_settings['additional_groups'])
615 645
 				)
616 646
 			);
647
+		}
617 648
 
618 649
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
619
-		foreach ($user_info['groups'] as $k => $v)
620
-			$user_info['groups'][$k] = (int) $v;
650
+		foreach ($user_info['groups'] as $k => $v) {
651
+					$user_info['groups'][$k] = (int) $v;
652
+		}
621 653
 
622 654
 		// This is a logged in user, so definitely not a spider.
623 655
 		$user_info['possibly_robot'] = false;
@@ -631,8 +663,7 @@  discard block
 block discarded – undo
631 663
 			$time_system = new DateTime('now', $tz_system);
632 664
 			$time_user = new DateTime('now', $tz_user);
633 665
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
634
-		}
635
-		else
666
+		} else
636 667
 		{
637 668
 			// !!! Compatibility.
638 669
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -646,8 +677,9 @@  discard block
 block discarded – undo
646 677
 		$user_info = array('groups' => array(-1));
647 678
 		$user_settings = array();
648 679
 
649
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
650
-			$_COOKIE[$cookiename] = '';
680
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
681
+					$_COOKIE[$cookiename] = '';
682
+		}
651 683
 
652 684
 		// Expire the 2FA cookie
653 685
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -664,19 +696,20 @@  discard block
 block discarded – undo
664 696
 		}
665 697
 
666 698
 		// Create a login token if it doesn't exist yet.
667
-		if (!isset($_SESSION['token']['post-login']))
668
-			createToken('login');
669
-		else
670
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
699
+		if (!isset($_SESSION['token']['post-login'])) {
700
+					createToken('login');
701
+		} else {
702
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
703
+		}
671 704
 
672 705
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
673 706
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
674 707
 		{
675 708
 			require_once($sourcedir . '/ManageSearchEngines.php');
676 709
 			$user_info['possibly_robot'] = SpiderCheck();
710
+		} elseif (!empty($modSettings['spider_mode'])) {
711
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
677 712
 		}
678
-		elseif (!empty($modSettings['spider_mode']))
679
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
680 713
 		// If we haven't turned on proper spider hunts then have a guess!
681 714
 		else
682 715
 		{
@@ -724,8 +757,9 @@  discard block
 block discarded – undo
724 757
 	$user_info['groups'] = array_unique($user_info['groups']);
725 758
 
726 759
 	// 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.
727
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
728
-		unset($user_info['ignoreboards'][$tmp]);
760
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
761
+			unset($user_info['ignoreboards'][$tmp]);
762
+	}
729 763
 
730 764
 	// Allow the user to change their language.
731 765
 	if (!empty($modSettings['userLanguage']))
@@ -738,13 +772,14 @@  discard block
 block discarded – undo
738 772
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
739 773
 
740 774
 			// Make it permanent for members.
741
-			if (!empty($user_info['id']))
742
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
743
-			else
744
-				$_SESSION['language'] = $user_info['language'];
775
+			if (!empty($user_info['id'])) {
776
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
777
+			} else {
778
+							$_SESSION['language'] = $user_info['language'];
779
+			}
780
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
781
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
745 782
 		}
746
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
747
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
748 783
 	}
749 784
 
750 785
 	$temp = build_query_board($user_info['id']);
@@ -807,9 +842,9 @@  discard block
 block discarded – undo
807 842
 		}
808 843
 
809 844
 		// Remember redirection is the key to avoiding fallout from your bosses.
810
-		if (!empty($topic))
811
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
812
-		else
845
+		if (!empty($topic)) {
846
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
847
+		} else
813 848
 		{
814 849
 			loadPermissions();
815 850
 			loadTheme();
@@ -827,10 +862,11 @@  discard block
 block discarded – undo
827 862
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
828 863
 	{
829 864
 		// @todo SLOW?
830
-		if (!empty($topic))
831
-			$temp = cache_get_data('topic_board-' . $topic, 120);
832
-		else
833
-			$temp = cache_get_data('board-' . $board, 120);
865
+		if (!empty($topic)) {
866
+					$temp = cache_get_data('topic_board-' . $topic, 120);
867
+		} else {
868
+					$temp = cache_get_data('board-' . $board, 120);
869
+		}
834 870
 
835 871
 		if (!empty($temp))
836 872
 		{
@@ -868,8 +904,9 @@  discard block
 block discarded – undo
868 904
 			$row = $smcFunc['db_fetch_assoc']($request);
869 905
 
870 906
 			// Set the current board.
871
-			if (!empty($row['id_board']))
872
-				$board = $row['id_board'];
907
+			if (!empty($row['id_board'])) {
908
+							$board = $row['id_board'];
909
+			}
873 910
 
874 911
 			// Basic operating information. (globals... :/)
875 912
 			$board_info = array(
@@ -905,21 +942,23 @@  discard block
 block discarded – undo
905 942
 
906 943
 			do
907 944
 			{
908
-				if (!empty($row['id_moderator']))
909
-					$board_info['moderators'][$row['id_moderator']] = array(
945
+				if (!empty($row['id_moderator'])) {
946
+									$board_info['moderators'][$row['id_moderator']] = array(
910 947
 						'id' => $row['id_moderator'],
911 948
 						'name' => $row['real_name'],
912 949
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
913 950
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
914 951
 					);
952
+				}
915 953
 
916
-				if (!empty($row['id_moderator_group']))
917
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
954
+				if (!empty($row['id_moderator_group'])) {
955
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
918 956
 						'id' => $row['id_moderator_group'],
919 957
 						'name' => $row['group_name'],
920 958
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
921 959
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
922 960
 					);
961
+				}
923 962
 			}
924 963
 			while ($row = $smcFunc['db_fetch_assoc']($request));
925 964
 
@@ -951,12 +990,12 @@  discard block
 block discarded – undo
951 990
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
952 991
 			{
953 992
 				// @todo SLOW?
954
-				if (!empty($topic))
955
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
993
+				if (!empty($topic)) {
994
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
995
+				}
956 996
 				cache_put_data('board-' . $board, $board_info, 120);
957 997
 			}
958
-		}
959
-		else
998
+		} else
960 999
 		{
961 1000
 			// Otherwise the topic is invalid, there are no moderators, etc.
962 1001
 			$board_info = array(
@@ -970,8 +1009,9 @@  discard block
 block discarded – undo
970 1009
 		$smcFunc['db_free_result']($request);
971 1010
 	}
972 1011
 
973
-	if (!empty($topic))
974
-		$_GET['board'] = (int) $board;
1012
+	if (!empty($topic)) {
1013
+			$_GET['board'] = (int) $board;
1014
+	}
975 1015
 
976 1016
 	if (!empty($board))
977 1017
 	{
@@ -981,10 +1021,12 @@  discard block
 block discarded – undo
981 1021
 		// Now check if the user is a moderator.
982 1022
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
983 1023
 
984
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
985
-			$board_info['error'] = 'access';
986
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
987
-			$board_info['error'] = 'access';
1024
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1025
+					$board_info['error'] = 'access';
1026
+		}
1027
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1028
+					$board_info['error'] = 'access';
1029
+		}
988 1030
 
989 1031
 		// Build up the linktree.
990 1032
 		$context['linktree'] = array_merge(
@@ -1007,8 +1049,9 @@  discard block
 block discarded – undo
1007 1049
 	$context['current_board'] = $board;
1008 1050
 
1009 1051
 	// No posting in redirection boards!
1010
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1011
-		$board_info['error'] == 'post_in_redirect';
1052
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1053
+			$board_info['error'] == 'post_in_redirect';
1054
+	}
1012 1055
 
1013 1056
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1014 1057
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1034,24 +1077,23 @@  discard block
 block discarded – undo
1034 1077
 			ob_end_clean();
1035 1078
 			header('HTTP/1.1 403 Forbidden');
1036 1079
 			die;
1037
-		}
1038
-		elseif ($board_info['error'] == 'post_in_redirect')
1080
+		} elseif ($board_info['error'] == 'post_in_redirect')
1039 1081
 		{
1040 1082
 			// Slightly different error message here...
1041 1083
 			fatal_lang_error('cannot_post_redirect', false);
1042
-		}
1043
-		elseif ($user_info['is_guest'])
1084
+		} elseif ($user_info['is_guest'])
1044 1085
 		{
1045 1086
 			loadLanguage('Errors');
1046 1087
 			is_not_guest($txt['topic_gone']);
1088
+		} else {
1089
+					fatal_lang_error('topic_gone', false);
1047 1090
 		}
1048
-		else
1049
-			fatal_lang_error('topic_gone', false);
1050 1091
 	}
1051 1092
 
1052
-	if ($user_info['is_mod'])
1053
-		$user_info['groups'][] = 3;
1054
-}
1093
+	if ($user_info['is_mod']) {
1094
+			$user_info['groups'][] = 3;
1095
+	}
1096
+	}
1055 1097
 
1056 1098
 /**
1057 1099
  * Load this user's permissions.
@@ -1072,8 +1114,9 @@  discard block
 block discarded – undo
1072 1114
 		asort($cache_groups);
1073 1115
 		$cache_groups = implode(',', $cache_groups);
1074 1116
 		// If it's a spider then cache it different.
1075
-		if ($user_info['possibly_robot'])
1076
-			$cache_groups .= '-spider';
1117
+		if ($user_info['possibly_robot']) {
1118
+					$cache_groups .= '-spider';
1119
+		}
1077 1120
 
1078 1121
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1079 1122
 		{
@@ -1081,9 +1124,9 @@  discard block
 block discarded – undo
1081 1124
 			banPermissions();
1082 1125
 
1083 1126
 			return;
1127
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1128
+					list ($user_info['permissions'], $removals) = $temp;
1084 1129
 		}
1085
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1086
-			list ($user_info['permissions'], $removals) = $temp;
1087 1130
 	}
1088 1131
 
1089 1132
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1105,23 +1148,26 @@  discard block
 block discarded – undo
1105 1148
 		$removals = array();
1106 1149
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1107 1150
 		{
1108
-			if (empty($row['add_deny']))
1109
-				$removals[] = $row['permission'];
1110
-			else
1111
-				$user_info['permissions'][] = $row['permission'];
1151
+			if (empty($row['add_deny'])) {
1152
+							$removals[] = $row['permission'];
1153
+			} else {
1154
+							$user_info['permissions'][] = $row['permission'];
1155
+			}
1112 1156
 		}
1113 1157
 		$smcFunc['db_free_result']($request);
1114 1158
 
1115
-		if (isset($cache_groups))
1116
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1159
+		if (isset($cache_groups)) {
1160
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1161
+		}
1117 1162
 	}
1118 1163
 
1119 1164
 	// Get the board permissions.
1120 1165
 	if (!empty($board))
1121 1166
 	{
1122 1167
 		// Make sure the board (if any) has been loaded by loadBoard().
1123
-		if (!isset($board_info['profile']))
1124
-			fatal_lang_error('no_board');
1168
+		if (!isset($board_info['profile'])) {
1169
+					fatal_lang_error('no_board');
1170
+		}
1125 1171
 
1126 1172
 		$request = $smcFunc['db_query']('', '
1127 1173
 			SELECT permission, add_deny
@@ -1137,20 +1183,23 @@  discard block
 block discarded – undo
1137 1183
 		);
1138 1184
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1139 1185
 		{
1140
-			if (empty($row['add_deny']))
1141
-				$removals[] = $row['permission'];
1142
-			else
1143
-				$user_info['permissions'][] = $row['permission'];
1186
+			if (empty($row['add_deny'])) {
1187
+							$removals[] = $row['permission'];
1188
+			} else {
1189
+							$user_info['permissions'][] = $row['permission'];
1190
+			}
1144 1191
 		}
1145 1192
 		$smcFunc['db_free_result']($request);
1146 1193
 	}
1147 1194
 
1148 1195
 	// Remove all the permissions they shouldn't have ;).
1149
-	if (!empty($modSettings['permission_enable_deny']))
1150
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1196
+	if (!empty($modSettings['permission_enable_deny'])) {
1197
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1198
+	}
1151 1199
 
1152
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1153
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1200
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1201
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1202
+	}
1154 1203
 
1155 1204
 	// Banned?  Watch, don't touch..
1156 1205
 	banPermissions();
@@ -1162,17 +1211,18 @@  discard block
 block discarded – undo
1162 1211
 		{
1163 1212
 			require_once($sourcedir . '/Subs-Auth.php');
1164 1213
 			rebuildModCache();
1214
+		} else {
1215
+					$user_info['mod_cache'] = $_SESSION['mc'];
1165 1216
 		}
1166
-		else
1167
-			$user_info['mod_cache'] = $_SESSION['mc'];
1168 1217
 
1169 1218
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1170 1219
 		// For example this drastically simplifies certain changes to the profile area.
1171 1220
 		$user_info['permissions'][] = 'is_not_guest';
1172 1221
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1173 1222
 		$user_info['permissions'][] = 'profile_view_own';
1174
-		if (in_array('profile_view', $user_info['permissions']))
1175
-			$user_info['permissions'][] = 'profile_view_any';
1223
+		if (in_array('profile_view', $user_info['permissions'])) {
1224
+					$user_info['permissions'][] = 'profile_view_any';
1225
+		}
1176 1226
 	}
1177 1227
 }
1178 1228
 
@@ -1190,8 +1240,9 @@  discard block
 block discarded – undo
1190 1240
 	global $image_proxy_enabled, $image_proxy_url, $image_proxy_secret, $boardurl, $user_info;
1191 1241
 
1192 1242
 	// Can't just look for no users :P.
1193
-	if (empty($users))
1194
-		return array();
1243
+	if (empty($users)) {
1244
+			return array();
1245
+	}
1195 1246
 
1196 1247
 	// Pass the set value
1197 1248
 	$context['loadMemberContext_set'] = $set;
@@ -1206,8 +1257,9 @@  discard block
 block discarded – undo
1206 1257
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1207 1258
 		{
1208 1259
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1209
-			if ($data == null)
1210
-				continue;
1260
+			if ($data == null) {
1261
+							continue;
1262
+			}
1211 1263
 
1212 1264
 			$loaded_ids[] = $data['id_member'];
1213 1265
 			$user_profile[$data['id_member']] = $data;
@@ -1274,19 +1326,22 @@  discard block
 block discarded – undo
1274 1326
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1275 1327
 
1276 1328
 			// Take care of proxying avatar if required, do this here for maximum reach
1277
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1278
-				if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
1329
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1330
+							if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
1279 1331
 					$row['avatar'] = $image_proxy_url . urlencode($row['avatar']);
1280
-				else
1281
-					$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1332
+			} else {
1333
+									$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1334
+				}
1282 1335
 
1283 1336
 			// Keep track of the member's normal member group
1284 1337
 			$row['primary_group'] = $row['member_group'];
1285 1338
 
1286
-			if (isset($row['member_ip']))
1287
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1288
-			if (isset($row['member_ip2']))
1289
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1339
+			if (isset($row['member_ip'])) {
1340
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1341
+			}
1342
+			if (isset($row['member_ip2'])) {
1343
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1344
+			}
1290 1345
 			$new_loaded_ids[] = $row['id_member'];
1291 1346
 			$loaded_ids[] = $row['id_member'];
1292 1347
 			$row['options'] = array();
@@ -1305,8 +1360,9 @@  discard block
 block discarded – undo
1305 1360
 				'loaded_ids' => $new_loaded_ids,
1306 1361
 			)
1307 1362
 		);
1308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1309
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1363
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1364
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1365
+		}
1310 1366
 		$smcFunc['db_free_result']($request);
1311 1367
 	}
1312 1368
 
@@ -1317,10 +1373,11 @@  discard block
 block discarded – undo
1317 1373
 	{
1318 1374
 		foreach ($loaded_ids as $a_member)
1319 1375
 		{
1320
-			if (!empty($user_profile[$a_member]['additional_groups']))
1321
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1322
-			else
1323
-				$groups = array($user_profile[$a_member]['id_group']);
1376
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1377
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1378
+			} else {
1379
+							$groups = array($user_profile[$a_member]['id_group']);
1380
+			}
1324 1381
 
1325 1382
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1326 1383
 
@@ -1333,8 +1390,9 @@  discard block
 block discarded – undo
1333 1390
 
1334 1391
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1335 1392
 	{
1336
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1337
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1393
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1394
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1395
+		}
1338 1396
 	}
1339 1397
 
1340 1398
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1360,14 +1418,17 @@  discard block
 block discarded – undo
1360 1418
 		foreach ($temp_mods as $id)
1361 1419
 		{
1362 1420
 			// By popular demand, don't show admins or global moderators as moderators.
1363
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1364
-				$user_profile[$id]['member_group'] = $row['member_group'];
1421
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1422
+							$user_profile[$id]['member_group'] = $row['member_group'];
1423
+			}
1365 1424
 
1366 1425
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1367
-			if (!empty($row['icons']))
1368
-				$user_profile[$id]['icons'] = $row['icons'];
1369
-			if (!empty($row['member_group_color']))
1370
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1426
+			if (!empty($row['icons'])) {
1427
+							$user_profile[$id]['icons'] = $row['icons'];
1428
+			}
1429
+			if (!empty($row['member_group_color'])) {
1430
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1431
+			}
1371 1432
 		}
1372 1433
 	}
1373 1434
 
@@ -1389,12 +1450,14 @@  discard block
 block discarded – undo
1389 1450
 	static $loadedLanguages = array();
1390 1451
 
1391 1452
 	// If this person's data is already loaded, skip it.
1392
-	if (isset($dataLoaded[$user]))
1393
-		return true;
1453
+	if (isset($dataLoaded[$user])) {
1454
+			return true;
1455
+	}
1394 1456
 
1395 1457
 	// We can't load guests or members not loaded by loadMemberData()!
1396
-	if ($user == 0)
1397
-		return false;
1458
+	if ($user == 0) {
1459
+			return false;
1460
+	}
1398 1461
 	if (!isset($user_profile[$user]))
1399 1462
 	{
1400 1463
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1420,12 +1483,16 @@  discard block
 block discarded – undo
1420 1483
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1421 1484
 
1422 1485
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1423
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1486
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1487
+		//icon is set and exists
1424 1488
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1425
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1489
+	} elseif (isset($profile['icons'][1])) {
1490
+		//icon is set and doesn't exist, fallback to default
1426 1491
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1427
-	else //not set, bye bye
1492
+	} else {
1493
+		//not set, bye bye
1428 1494
 		$group_icon_url = '';
1495
+	}
1429 1496
 
1430 1497
 	// These minimal values are always loaded
1431 1498
 	$memberContext[$user] = array(
@@ -1444,8 +1511,9 @@  discard block
 block discarded – undo
1444 1511
 	if ($context['loadMemberContext_set'] != 'minimal')
1445 1512
 	{
1446 1513
 		// Go the extra mile and load the user's native language name.
1447
-		if (empty($loadedLanguages))
1448
-			$loadedLanguages = getLanguages();
1514
+		if (empty($loadedLanguages)) {
1515
+					$loadedLanguages = getLanguages();
1516
+		}
1449 1517
 
1450 1518
 		$memberContext[$user] += array(
1451 1519
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1500,31 +1568,33 @@  discard block
 block discarded – undo
1500 1568
 	{
1501 1569
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1502 1570
 		{
1503
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1504
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1505
-			else
1506
-				$image = get_gravatar_url($profile['email_address']);
1507
-		}
1508
-		else
1571
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1572
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1573
+			} else {
1574
+							$image = get_gravatar_url($profile['email_address']);
1575
+			}
1576
+		} else
1509 1577
 		{
1510 1578
 			// So it's stored in the member table?
1511 1579
 			if (!empty($profile['avatar']))
1512 1580
 			{
1513 1581
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1582
+			} elseif (!empty($profile['filename'])) {
1583
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1514 1584
 			}
1515
-			elseif (!empty($profile['filename']))
1516
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1517 1585
 			// Right... no avatar...use the default one
1518
-			else
1519
-				$image = $modSettings['avatar_url'] . '/default.png';
1586
+			else {
1587
+							$image = $modSettings['avatar_url'] . '/default.png';
1588
+			}
1520 1589
 		}
1521
-		if (!empty($image))
1522
-			$memberContext[$user]['avatar'] = array(
1590
+		if (!empty($image)) {
1591
+					$memberContext[$user]['avatar'] = array(
1523 1592
 				'name' => $profile['avatar'],
1524 1593
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1525 1594
 				'href' => $image,
1526 1595
 				'url' => $image,
1527 1596
 			);
1597
+		}
1528 1598
 	}
1529 1599
 
1530 1600
 	// Are we also loading the members custom fields into context?
@@ -1532,13 +1602,15 @@  discard block
 block discarded – undo
1532 1602
 	{
1533 1603
 		$memberContext[$user]['custom_fields'] = array();
1534 1604
 
1535
-		if (!isset($context['display_fields']))
1536
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1605
+		if (!isset($context['display_fields'])) {
1606
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1607
+		}
1537 1608
 
1538 1609
 		foreach ($context['display_fields'] as $custom)
1539 1610
 		{
1540
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1541
-				continue;
1611
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1612
+							continue;
1613
+			}
1542 1614
 
1543 1615
 			$value = $profile['options'][$custom['col_name']];
1544 1616
 
@@ -1546,31 +1618,36 @@  discard block
 block discarded – undo
1546 1618
 			$currentKey = 0;
1547 1619
 
1548 1620
 			// Create a key => value array for multiple options fields
1549
-			if (!empty($custom['options']))
1550
-				foreach ($custom['options'] as $k => $v)
1621
+			if (!empty($custom['options'])) {
1622
+							foreach ($custom['options'] as $k => $v)
1551 1623
 				{
1552 1624
 					$fieldOptions[] = $v;
1553
-					if (empty($currentKey))
1554
-						$currentKey = $v == $value ? $k : 0;
1625
+			}
1626
+					if (empty($currentKey)) {
1627
+											$currentKey = $v == $value ? $k : 0;
1628
+					}
1555 1629
 				}
1556 1630
 
1557 1631
 			// BBC?
1558
-			if ($custom['bbc'])
1559
-				$value = parse_bbc($value);
1632
+			if ($custom['bbc']) {
1633
+							$value = parse_bbc($value);
1634
+			}
1560 1635
 
1561 1636
 			// ... or checkbox?
1562
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1563
-				$value = $value ? $txt['yes'] : $txt['no'];
1637
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1638
+							$value = $value ? $txt['yes'] : $txt['no'];
1639
+			}
1564 1640
 
1565 1641
 			// Enclosing the user input within some other text?
1566
-			if (!empty($custom['enclose']))
1567
-				$value = strtr($custom['enclose'], array(
1642
+			if (!empty($custom['enclose'])) {
1643
+							$value = strtr($custom['enclose'], array(
1568 1644
 					'{SCRIPTURL}' => $scripturl,
1569 1645
 					'{IMAGES_URL}' => $settings['images_url'],
1570 1646
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1571 1647
 					'{INPUT}' => $value,
1572 1648
 					'{KEY}' => $currentKey,
1573 1649
 				));
1650
+			}
1574 1651
 
1575 1652
 			$memberContext[$user]['custom_fields'][] = array(
1576 1653
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1597,8 +1674,9 @@  discard block
 block discarded – undo
1597 1674
 	global $smcFunc, $txt, $scripturl, $settings;
1598 1675
 
1599 1676
 	// Do not waste my time...
1600
-	if (empty($users) || empty($params))
1601
-		return false;
1677
+	if (empty($users) || empty($params)) {
1678
+			return false;
1679
+	}
1602 1680
 
1603 1681
 	// Make sure it's an array.
1604 1682
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1625,41 +1703,48 @@  discard block
 block discarded – undo
1625 1703
 		$currentKey = 0;
1626 1704
 
1627 1705
 		// Create a key => value array for multiple options fields
1628
-		if (!empty($row['field_options']))
1629
-			foreach (explode(',', $row['field_options']) as $k => $v)
1706
+		if (!empty($row['field_options'])) {
1707
+					foreach (explode(',', $row['field_options']) as $k => $v)
1630 1708
 			{
1631 1709
 				$fieldOptions[] = $v;
1632
-				if (empty($currentKey))
1633
-					$currentKey = $v == $row['value'] ? $k : 0;
1710
+		}
1711
+				if (empty($currentKey)) {
1712
+									$currentKey = $v == $row['value'] ? $k : 0;
1713
+				}
1634 1714
 			}
1635 1715
 
1636 1716
 		// BBC?
1637
-		if (!empty($row['bbc']))
1638
-			$row['value'] = parse_bbc($row['value']);
1717
+		if (!empty($row['bbc'])) {
1718
+					$row['value'] = parse_bbc($row['value']);
1719
+		}
1639 1720
 
1640 1721
 		// ... or checkbox?
1641
-		elseif (isset($row['type']) && $row['type'] == 'check')
1642
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1722
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1723
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1724
+		}
1643 1725
 
1644 1726
 		// Enclosing the user input within some other text?
1645
-		if (!empty($row['enclose']))
1646
-			$row['value'] = strtr($row['enclose'], array(
1727
+		if (!empty($row['enclose'])) {
1728
+					$row['value'] = strtr($row['enclose'], array(
1647 1729
 				'{SCRIPTURL}' => $scripturl,
1648 1730
 				'{IMAGES_URL}' => $settings['images_url'],
1649 1731
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1650 1732
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1651 1733
 				'{KEY}' => $currentKey,
1652 1734
 			));
1735
+		}
1653 1736
 
1654 1737
 		// Send a simple array if there is just 1 param
1655
-		if (count($params) == 1)
1656
-			$return[$row['id_member']] = $row;
1738
+		if (count($params) == 1) {
1739
+					$return[$row['id_member']] = $row;
1740
+		}
1657 1741
 
1658 1742
 		// More than 1? knock yourself out...
1659 1743
 		else
1660 1744
 		{
1661
-			if (!isset($return[$row['id_member']]))
1662
-				$return[$row['id_member']] = array();
1745
+			if (!isset($return[$row['id_member']])) {
1746
+							$return[$row['id_member']] = array();
1747
+			}
1663 1748
 
1664 1749
 			$return[$row['id_member']][$row['variable']] = $row;
1665 1750
 		}
@@ -1693,8 +1778,9 @@  discard block
 block discarded – undo
1693 1778
 	global $context;
1694 1779
 
1695 1780
 	// Don't know any browser!
1696
-	if (empty($context['browser']))
1697
-		detectBrowser();
1781
+	if (empty($context['browser'])) {
1782
+			detectBrowser();
1783
+	}
1698 1784
 
1699 1785
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1700 1786
 }
@@ -1712,8 +1798,9 @@  discard block
 block discarded – undo
1712 1798
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1713 1799
 
1714 1800
 	// The theme was specified by parameter.
1715
-	if (!empty($id_theme))
1716
-		$id_theme = (int) $id_theme;
1801
+	if (!empty($id_theme)) {
1802
+			$id_theme = (int) $id_theme;
1803
+	}
1717 1804
 	// The theme was specified by REQUEST.
1718 1805
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1719 1806
 	{
@@ -1721,54 +1808,61 @@  discard block
 block discarded – undo
1721 1808
 		$_SESSION['id_theme'] = $id_theme;
1722 1809
 	}
1723 1810
 	// The theme was specified by REQUEST... previously.
1724
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1725
-		$id_theme = (int) $_SESSION['id_theme'];
1811
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1812
+			$id_theme = (int) $_SESSION['id_theme'];
1813
+	}
1726 1814
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1727
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1728
-		$id_theme = $user_info['theme'];
1815
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1816
+			$id_theme = $user_info['theme'];
1817
+	}
1729 1818
 	// The theme was specified by the board.
1730
-	elseif (!empty($board_info['theme']))
1731
-		$id_theme = $board_info['theme'];
1819
+	elseif (!empty($board_info['theme'])) {
1820
+			$id_theme = $board_info['theme'];
1821
+	}
1732 1822
 	// The theme is the forum's default.
1733
-	else
1734
-		$id_theme = $modSettings['theme_guests'];
1823
+	else {
1824
+			$id_theme = $modSettings['theme_guests'];
1825
+	}
1735 1826
 
1736 1827
 	// We already load the basic stuff?
1737 1828
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1738 1829
 	{
1739 1830
 		// Verify the id_theme... no foul play.
1740 1831
 		// Always allow the board specific theme, if they are overriding.
1741
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1742
-			$id_theme = $board_info['theme'];
1832
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1833
+					$id_theme = $board_info['theme'];
1834
+		}
1743 1835
 		// If they have specified a particular theme to use with SSI allow it to be used.
1744
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1745
-			$id_theme = (int) $id_theme;
1746
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1836
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1837
+					$id_theme = (int) $id_theme;
1838
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1747 1839
 		{
1748 1840
 			$themes = explode(',', $modSettings['enableThemes']);
1749
-			if (!in_array($id_theme, $themes))
1750
-				$id_theme = $modSettings['theme_guests'];
1751
-			else
1752
-				$id_theme = (int) $id_theme;
1841
+			if (!in_array($id_theme, $themes)) {
1842
+							$id_theme = $modSettings['theme_guests'];
1843
+			} else {
1844
+							$id_theme = (int) $id_theme;
1845
+			}
1846
+		} else {
1847
+					$id_theme = (int) $id_theme;
1753 1848
 		}
1754
-		else
1755
-			$id_theme = (int) $id_theme;
1756 1849
 
1757 1850
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1758 1851
 
1759 1852
 		// Disable image proxy if we don't have SSL enabled
1760
-		if (empty($modSettings['force_ssl']))
1761
-			$image_proxy_enabled = false;
1853
+		if (empty($modSettings['force_ssl'])) {
1854
+					$image_proxy_enabled = false;
1855
+		}
1762 1856
 
1763 1857
 		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'])
1764 1858
 		{
1765 1859
 			$themeData = $temp;
1766 1860
 			$flag = true;
1861
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1862
+					$themeData = $temp + array($member => array());
1863
+		} else {
1864
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1767 1865
 		}
1768
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1769
-			$themeData = $temp + array($member => array());
1770
-		else
1771
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1772 1866
 
1773 1867
 		if (empty($flag))
1774 1868
 		{
@@ -1787,31 +1881,37 @@  discard block
 block discarded – undo
1787 1881
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1788 1882
 			{
1789 1883
 				// There are just things we shouldn't be able to change as members.
1790
-				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')))
1791
-					continue;
1884
+				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'))) {
1885
+									continue;
1886
+				}
1792 1887
 
1793 1888
 				// If this is the theme_dir of the default theme, store it.
1794
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1795
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1889
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1890
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1891
+				}
1796 1892
 
1797 1893
 				// If this isn't set yet, is a theme option, or is not the default theme..
1798
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1799
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1894
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1895
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1896
+				}
1800 1897
 			}
1801 1898
 			$smcFunc['db_free_result']($result);
1802 1899
 
1803
-			if (!empty($themeData[-1]))
1804
-				foreach ($themeData[-1] as $k => $v)
1900
+			if (!empty($themeData[-1])) {
1901
+							foreach ($themeData[-1] as $k => $v)
1805 1902
 				{
1806 1903
 					if (!isset($themeData[$member][$k]))
1807 1904
 						$themeData[$member][$k] = $v;
1905
+			}
1808 1906
 				}
1809 1907
 
1810
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1811
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1908
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1909
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1910
+			}
1812 1911
 			// Only if we didn't already load that part of the cache...
1813
-			elseif (!isset($temp))
1814
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1912
+			elseif (!isset($temp)) {
1913
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1914
+			}
1815 1915
 		}
1816 1916
 
1817 1917
 		$settings = $themeData[0];
@@ -1828,17 +1928,20 @@  discard block
 block discarded – undo
1828 1928
 		$settings['template_dirs'][] = $settings['theme_dir'];
1829 1929
 
1830 1930
 		// Based on theme (if there is one).
1831
-		if (!empty($settings['base_theme_dir']))
1832
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1931
+		if (!empty($settings['base_theme_dir'])) {
1932
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1933
+		}
1833 1934
 
1834 1935
 		// Lastly the default theme.
1835
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1836
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1936
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1937
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1938
+		}
1837 1939
 	}
1838 1940
 
1839 1941
 
1840
-	if (!$initialize)
1841
-		return;
1942
+	if (!$initialize) {
1943
+			return;
1944
+	}
1842 1945
 
1843 1946
 	// Check to see if we're forcing SSL
1844 1947
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1859,8 +1962,9 @@  discard block
 block discarded – undo
1859 1962
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1860 1963
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1861 1964
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1862
-		if ($temp != '/')
1863
-			$detected_url .= $temp;
1965
+		if ($temp != '/') {
1966
+					$detected_url .= $temp;
1967
+		}
1864 1968
 	}
1865 1969
 	if (isset($detected_url) && $detected_url != $boardurl)
1866 1970
 	{
@@ -1872,8 +1976,9 @@  discard block
 block discarded – undo
1872 1976
 			foreach ($aliases as $alias)
1873 1977
 			{
1874 1978
 				// Rip off all the boring parts, spaces, etc.
1875
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1876
-					$do_fix = true;
1979
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1980
+									$do_fix = true;
1981
+				}
1877 1982
 			}
1878 1983
 		}
1879 1984
 
@@ -1881,21 +1986,23 @@  discard block
 block discarded – undo
1881 1986
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1882 1987
 		{
1883 1988
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1884
-			if (empty($_GET))
1885
-				redirectexit('wwwRedirect');
1886
-			else
1989
+			if (empty($_GET)) {
1990
+							redirectexit('wwwRedirect');
1991
+			} else
1887 1992
 			{
1888 1993
 				$k = key($_GET);
1889 1994
 				$v = current($_GET);
1890 1995
 
1891
-				if ($k != 'wwwRedirect')
1892
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1996
+				if ($k != 'wwwRedirect') {
1997
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1998
+				}
1893 1999
 			}
1894 2000
 		}
1895 2001
 
1896 2002
 		// #3 is just a check for SSL...
1897
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1898
-			$do_fix = true;
2003
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
2004
+					$do_fix = true;
2005
+		}
1899 2006
 
1900 2007
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1901 2008
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1930,8 +2037,9 @@  discard block
 block discarded – undo
1930 2037
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1931 2038
 				}
1932 2039
 			}
1933
-			foreach ($context['linktree'] as $k => $dummy)
1934
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2040
+			foreach ($context['linktree'] as $k => $dummy) {
2041
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2042
+			}
1935 2043
 		}
1936 2044
 	}
1937 2045
 	// Set up the contextual user array.
@@ -1950,16 +2058,16 @@  discard block
 block discarded – undo
1950 2058
 			'email' => $user_info['email'],
1951 2059
 			'ignoreusers' => $user_info['ignoreusers'],
1952 2060
 		);
1953
-		if (!$context['user']['is_guest'])
1954
-			$context['user']['name'] = $user_info['name'];
1955
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1956
-			$context['user']['name'] = $txt['guest_title'];
2061
+		if (!$context['user']['is_guest']) {
2062
+					$context['user']['name'] = $user_info['name'];
2063
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2064
+					$context['user']['name'] = $txt['guest_title'];
2065
+		}
1957 2066
 
1958 2067
 		// Determine the current smiley set.
1959 2068
 		$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'];
1960 2069
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1961
-	}
1962
-	else
2070
+	} else
1963 2071
 	{
1964 2072
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1965 2073
 		$context['user'] = array(
@@ -1993,18 +2101,24 @@  discard block
 block discarded – undo
1993 2101
 	}
1994 2102
 
1995 2103
 	// Some basic information...
1996
-	if (!isset($context['html_headers']))
1997
-		$context['html_headers'] = '';
1998
-	if (!isset($context['javascript_files']))
1999
-		$context['javascript_files'] = array();
2000
-	if (!isset($context['css_files']))
2001
-		$context['css_files'] = array();
2002
-	if (!isset($context['css_header']))
2003
-		$context['css_header'] = array();
2004
-	if (!isset($context['javascript_inline']))
2005
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2006
-	if (!isset($context['javascript_vars']))
2007
-		$context['javascript_vars'] = array();
2104
+	if (!isset($context['html_headers'])) {
2105
+			$context['html_headers'] = '';
2106
+	}
2107
+	if (!isset($context['javascript_files'])) {
2108
+			$context['javascript_files'] = array();
2109
+	}
2110
+	if (!isset($context['css_files'])) {
2111
+			$context['css_files'] = array();
2112
+	}
2113
+	if (!isset($context['css_header'])) {
2114
+			$context['css_header'] = array();
2115
+	}
2116
+	if (!isset($context['javascript_inline'])) {
2117
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2118
+	}
2119
+	if (!isset($context['javascript_vars'])) {
2120
+			$context['javascript_vars'] = array();
2121
+	}
2008 2122
 
2009 2123
 	$context['login_url'] =  $scripturl . '?action=login2';
2010 2124
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2016,16 +2130,18 @@  discard block
 block discarded – undo
2016 2130
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2017 2131
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2018 2132
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2019
-	if (isset($modSettings['load_average']))
2020
-		$context['load_average'] = $modSettings['load_average'];
2133
+	if (isset($modSettings['load_average'])) {
2134
+			$context['load_average'] = $modSettings['load_average'];
2135
+	}
2021 2136
 
2022 2137
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2023 2138
 	detectBrowser();
2024 2139
 
2025 2140
 	// Set the top level linktree up.
2026 2141
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2027
-	if (empty($context['linktree']))
2028
-		$context['linktree'] = array();
2142
+	if (empty($context['linktree'])) {
2143
+			$context['linktree'] = array();
2144
+	}
2029 2145
 	array_unshift($context['linktree'], array(
2030 2146
 		'url' => $scripturl,
2031 2147
 		'name' => $context['forum_name_html_safe']
@@ -2034,8 +2150,9 @@  discard block
 block discarded – undo
2034 2150
 	// This allows sticking some HTML on the page output - useful for controls.
2035 2151
 	$context['insert_after_template'] = '';
2036 2152
 
2037
-	if (!isset($txt))
2038
-		$txt = array();
2153
+	if (!isset($txt)) {
2154
+			$txt = array();
2155
+	}
2039 2156
 
2040 2157
 	$simpleActions = array(
2041 2158
 		'findmember',
@@ -2081,9 +2198,10 @@  discard block
 block discarded – undo
2081 2198
 
2082 2199
 	// See if theres any extra param to check.
2083 2200
 	$requiresXML = false;
2084
-	foreach ($extraParams as $key => $extra)
2085
-		if (isset($_REQUEST[$extra]))
2201
+	foreach ($extraParams as $key => $extra) {
2202
+			if (isset($_REQUEST[$extra]))
2086 2203
 			$requiresXML = true;
2204
+	}
2087 2205
 
2088 2206
 	// Output is fully XML, so no need for the index template.
2089 2207
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2098,37 +2216,39 @@  discard block
 block discarded – undo
2098 2216
 	{
2099 2217
 		loadLanguage('index+Modifications');
2100 2218
 		$context['template_layers'] = array();
2101
-	}
2102
-
2103
-	else
2219
+	} else
2104 2220
 	{
2105 2221
 		// Custom templates to load, or just default?
2106
-		if (isset($settings['theme_templates']))
2107
-			$templates = explode(',', $settings['theme_templates']);
2108
-		else
2109
-			$templates = array('index');
2222
+		if (isset($settings['theme_templates'])) {
2223
+					$templates = explode(',', $settings['theme_templates']);
2224
+		} else {
2225
+					$templates = array('index');
2226
+		}
2110 2227
 
2111 2228
 		// Load each template...
2112
-		foreach ($templates as $template)
2113
-			loadTemplate($template);
2229
+		foreach ($templates as $template) {
2230
+					loadTemplate($template);
2231
+		}
2114 2232
 
2115 2233
 		// ...and attempt to load their associated language files.
2116 2234
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2117 2235
 		loadLanguage($required_files, '', false);
2118 2236
 
2119 2237
 		// Custom template layers?
2120
-		if (isset($settings['theme_layers']))
2121
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2122
-		else
2123
-			$context['template_layers'] = array('html', 'body');
2238
+		if (isset($settings['theme_layers'])) {
2239
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2240
+		} else {
2241
+					$context['template_layers'] = array('html', 'body');
2242
+		}
2124 2243
 	}
2125 2244
 
2126 2245
 	// Initialize the theme.
2127 2246
 	loadSubTemplate('init', 'ignore');
2128 2247
 
2129 2248
 	// Allow overriding the board wide time/number formats.
2130
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2131
-		$user_info['time_format'] = $txt['time_format'];
2249
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2250
+			$user_info['time_format'] = $txt['time_format'];
2251
+	}
2132 2252
 
2133 2253
 	// Set the character set from the template.
2134 2254
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2136,12 +2256,14 @@  discard block
 block discarded – undo
2136 2256
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2137 2257
 
2138 2258
 	// Guests may still need a name.
2139
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2140
-		$context['user']['name'] = $txt['guest_title'];
2259
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2260
+			$context['user']['name'] = $txt['guest_title'];
2261
+	}
2141 2262
 
2142 2263
 	// Any theme-related strings that need to be loaded?
2143
-	if (!empty($settings['require_theme_strings']))
2144
-		loadLanguage('ThemeStrings', '', false);
2264
+	if (!empty($settings['require_theme_strings'])) {
2265
+			loadLanguage('ThemeStrings', '', false);
2266
+	}
2145 2267
 
2146 2268
 	// Make a special URL for the language.
2147 2269
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2152,8 +2274,9 @@  discard block
 block discarded – undo
2152 2274
 	// Here is my luvly Responsive CSS
2153 2275
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2154 2276
 
2155
-	if ($context['right_to_left'])
2156
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2277
+	if ($context['right_to_left']) {
2278
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2279
+	}
2157 2280
 
2158 2281
 	// We allow theme variants, because we're cool.
2159 2282
 	$context['theme_variant'] = '';
@@ -2161,14 +2284,17 @@  discard block
 block discarded – undo
2161 2284
 	if (!empty($settings['theme_variants']))
2162 2285
 	{
2163 2286
 		// Overriding - for previews and that ilk.
2164
-		if (!empty($_REQUEST['variant']))
2165
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2287
+		if (!empty($_REQUEST['variant'])) {
2288
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2289
+		}
2166 2290
 		// User selection?
2167
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2168
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2291
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2292
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2293
+		}
2169 2294
 		// If not a user variant, select the default.
2170
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2171
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2295
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2296
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2297
+		}
2172 2298
 
2173 2299
 		// Do this to keep things easier in the templates.
2174 2300
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2177,20 +2303,23 @@  discard block
 block discarded – undo
2177 2303
 		if (!empty($context['theme_variant']))
2178 2304
 		{
2179 2305
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2180
-			if ($context['right_to_left'])
2181
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2306
+			if ($context['right_to_left']) {
2307
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2308
+			}
2182 2309
 		}
2183 2310
 	}
2184 2311
 
2185 2312
 	// Let's be compatible with old themes!
2186
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2187
-		$context['template_layers'] = array('main');
2313
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2314
+			$context['template_layers'] = array('main');
2315
+	}
2188 2316
 
2189 2317
 	$context['tabindex'] = 1;
2190 2318
 
2191 2319
 	// Compatibility.
2192
-	if (!isset($settings['theme_version']))
2193
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2320
+	if (!isset($settings['theme_version'])) {
2321
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2322
+	}
2194 2323
 
2195 2324
 	// Default JS variables for use in every theme
2196 2325
 	$context['javascript_vars'] = array(
@@ -2209,18 +2338,18 @@  discard block
 block discarded – undo
2209 2338
 	);
2210 2339
 
2211 2340
 	// Add the JQuery library to the list of files to load.
2212
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2213
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2214
-
2215
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2216
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2217
-
2218
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2219
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2341
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2342
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2343
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2344
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2345
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2346
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2347
+	}
2220 2348
 
2221 2349
 	// Auto loading? template_javascript() will take care of the local half of this.
2222
-	else
2223
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2350
+	else {
2351
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2352
+	}
2224 2353
 
2225 2354
 	// Queue our JQuery plugins!
2226 2355
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2243,12 +2372,12 @@  discard block
 block discarded – undo
2243 2372
 			require_once($sourcedir . '/ScheduledTasks.php');
2244 2373
 
2245 2374
 			// What to do, what to do?!
2246
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2247
-				AutoTask();
2248
-			else
2249
-				ReduceMailQueue();
2250
-		}
2251
-		else
2375
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2376
+							AutoTask();
2377
+			} else {
2378
+							ReduceMailQueue();
2379
+			}
2380
+		} else
2252 2381
 		{
2253 2382
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2254 2383
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2299,8 +2428,9 @@  discard block
 block discarded – undo
2299 2428
 		foreach ($theme_includes as $include)
2300 2429
 		{
2301 2430
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2302
-			if (file_exists($include))
2303
-				require_once($include);
2431
+			if (file_exists($include)) {
2432
+							require_once($include);
2433
+			}
2304 2434
 		}
2305 2435
 	}
2306 2436
 
@@ -2330,16 +2460,19 @@  discard block
 block discarded – undo
2330 2460
 	// Do any style sheets first, cause we're easy with those.
2331 2461
 	if (!empty($style_sheets))
2332 2462
 	{
2333
-		if (!is_array($style_sheets))
2334
-			$style_sheets = array($style_sheets);
2463
+		if (!is_array($style_sheets)) {
2464
+					$style_sheets = array($style_sheets);
2465
+		}
2335 2466
 
2336
-		foreach ($style_sheets as $sheet)
2337
-			loadCSSFile($sheet . '.css', array(), $sheet);
2467
+		foreach ($style_sheets as $sheet) {
2468
+					loadCSSFile($sheet . '.css', array(), $sheet);
2469
+		}
2338 2470
 	}
2339 2471
 
2340 2472
 	// No template to load?
2341
-	if ($template_name === false)
2342
-		return true;
2473
+	if ($template_name === false) {
2474
+			return true;
2475
+	}
2343 2476
 
2344 2477
 	$loaded = false;
2345 2478
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2354,12 +2487,14 @@  discard block
 block discarded – undo
2354 2487
 
2355 2488
 	if ($loaded)
2356 2489
 	{
2357
-		if ($db_show_debug === true)
2358
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2490
+		if ($db_show_debug === true) {
2491
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2492
+		}
2359 2493
 
2360 2494
 		// If they have specified an initialization function for this template, go ahead and call it now.
2361
-		if (function_exists('template_' . $template_name . '_init'))
2362
-			call_user_func('template_' . $template_name . '_init');
2495
+		if (function_exists('template_' . $template_name . '_init')) {
2496
+					call_user_func('template_' . $template_name . '_init');
2497
+		}
2363 2498
 	}
2364 2499
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2365 2500
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2379,13 +2514,14 @@  discard block
 block discarded – undo
2379 2514
 		loadTemplate($template_name);
2380 2515
 	}
2381 2516
 	// Cause an error otherwise.
2382
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2383
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2384
-	elseif ($fatal)
2385
-		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'));
2386
-	else
2387
-		return false;
2388
-}
2517
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2518
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2519
+	} elseif ($fatal) {
2520
+			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'));
2521
+	} else {
2522
+			return false;
2523
+	}
2524
+	}
2389 2525
 
2390 2526
 /**
2391 2527
  * Load a sub-template.
@@ -2403,17 +2539,19 @@  discard block
 block discarded – undo
2403 2539
 {
2404 2540
 	global $context, $txt, $db_show_debug;
2405 2541
 
2406
-	if ($db_show_debug === true)
2407
-		$context['debug']['sub_templates'][] = $sub_template_name;
2542
+	if ($db_show_debug === true) {
2543
+			$context['debug']['sub_templates'][] = $sub_template_name;
2544
+	}
2408 2545
 
2409 2546
 	// Figure out what the template function is named.
2410 2547
 	$theme_function = 'template_' . $sub_template_name;
2411
-	if (function_exists($theme_function))
2412
-		$theme_function();
2413
-	elseif ($fatal === false)
2414
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2415
-	elseif ($fatal !== 'ignore')
2416
-		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'));
2548
+	if (function_exists($theme_function)) {
2549
+			$theme_function();
2550
+	} elseif ($fatal === false) {
2551
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2552
+	} elseif ($fatal !== 'ignore') {
2553
+			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'));
2554
+	}
2417 2555
 
2418 2556
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2419 2557
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2443,8 +2581,9 @@  discard block
 block discarded – undo
2443 2581
 {
2444 2582
 	global $settings, $context, $modSettings;
2445 2583
 
2446
-	if (empty($context['css_files_order']))
2447
-		$context['css_files_order'] = array();
2584
+	if (empty($context['css_files_order'])) {
2585
+			$context['css_files_order'] = array();
2586
+	}
2448 2587
 
2449 2588
 	$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']) : '');
2450 2589
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2455,8 +2594,9 @@  discard block
 block discarded – undo
2455 2594
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2456 2595
 
2457 2596
 	// If this is an external file, automatically set this to false.
2458
-	if (!empty($params['external']))
2459
-		$params['minimize'] = false;
2597
+	if (!empty($params['external'])) {
2598
+			$params['minimize'] = false;
2599
+	}
2460 2600
 
2461 2601
 	// Account for shorthand like admin.css?alp21 filenames
2462 2602
 	$has_seed = strpos($fileName, '.css?');
@@ -2473,16 +2613,12 @@  discard block
 block discarded – undo
2473 2613
 			{
2474 2614
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2475 2615
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2476
-			}
2477
-
2478
-			else
2616
+			} else
2479 2617
 			{
2480 2618
 				$fileUrl = false;
2481 2619
 				$filePath = false;
2482 2620
 			}
2483
-		}
2484
-
2485
-		else
2621
+		} else
2486 2622
 		{
2487 2623
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2488 2624
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2500,16 +2636,18 @@  discard block
 block discarded – undo
2500 2636
 	if (!empty($fileName))
2501 2637
 	{
2502 2638
 		// find a free number/position
2503
-		while (isset($context['css_files_order'][$params['order_pos']]))
2504
-			$params['order_pos']++;
2639
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2640
+					$params['order_pos']++;
2641
+		}
2505 2642
 		$context['css_files_order'][$params['order_pos']] = $id;
2506 2643
 
2507 2644
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2508 2645
 	}
2509 2646
 
2510
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2511
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2512
-}
2647
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2648
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2649
+	}
2650
+	}
2513 2651
 
2514 2652
 /**
2515 2653
  * Add a block of inline css code to be executed later
@@ -2526,8 +2664,9 @@  discard block
 block discarded – undo
2526 2664
 	global $context;
2527 2665
 
2528 2666
 	// Gotta add something...
2529
-	if (empty($css))
2530
-		return false;
2667
+	if (empty($css)) {
2668
+			return false;
2669
+	}
2531 2670
 
2532 2671
 	$context['css_header'][] = $css;
2533 2672
 }
@@ -2562,8 +2701,9 @@  discard block
 block discarded – undo
2562 2701
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2563 2702
 
2564 2703
 	// If this is an external file, automatically set this to false.
2565
-	if (!empty($params['external']))
2566
-		$params['minimize'] = false;
2704
+	if (!empty($params['external'])) {
2705
+			$params['minimize'] = false;
2706
+	}
2567 2707
 
2568 2708
 	// Account for shorthand like admin.js?alp21 filenames
2569 2709
 	$has_seed = strpos($fileName, '.js?');
@@ -2580,16 +2720,12 @@  discard block
 block discarded – undo
2580 2720
 			{
2581 2721
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2582 2722
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2583
-			}
2584
-
2585
-			else
2723
+			} else
2586 2724
 			{
2587 2725
 				$fileUrl = false;
2588 2726
 				$filePath = false;
2589 2727
 			}
2590
-		}
2591
-
2592
-		else
2728
+		} else
2593 2729
 		{
2594 2730
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2595 2731
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2604,9 +2740,10 @@  discard block
 block discarded – undo
2604 2740
 	}
2605 2741
 
2606 2742
 	// Add it to the array for use in the template
2607
-	if (!empty($fileName))
2608
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2609
-}
2743
+	if (!empty($fileName)) {
2744
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2745
+	}
2746
+	}
2610 2747
 
2611 2748
 /**
2612 2749
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2620,9 +2757,10 @@  discard block
 block discarded – undo
2620 2757
 {
2621 2758
 	global $context;
2622 2759
 
2623
-	if (!empty($key) && (!empty($value) || $value === '0'))
2624
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2625
-}
2760
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2761
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2762
+	}
2763
+	}
2626 2764
 
2627 2765
 /**
2628 2766
  * Add a block of inline Javascript code to be executed later
@@ -2639,8 +2777,9 @@  discard block
 block discarded – undo
2639 2777
 {
2640 2778
 	global $context;
2641 2779
 
2642
-	if (empty($javascript))
2643
-		return false;
2780
+	if (empty($javascript)) {
2781
+			return false;
2782
+	}
2644 2783
 
2645 2784
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2646 2785
 }
@@ -2661,15 +2800,18 @@  discard block
 block discarded – undo
2661 2800
 	static $already_loaded = array();
2662 2801
 
2663 2802
 	// Default to the user's language.
2664
-	if ($lang == '')
2665
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2803
+	if ($lang == '') {
2804
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2805
+	}
2666 2806
 
2667 2807
 	// Do we want the English version of language file as fallback?
2668
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2669
-		loadLanguage($template_name, 'english', false);
2808
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2809
+			loadLanguage($template_name, 'english', false);
2810
+	}
2670 2811
 
2671
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2672
-		return $lang;
2812
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2813
+			return $lang;
2814
+	}
2673 2815
 
2674 2816
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2675 2817
 	if (empty($settings['default_theme_dir']))
@@ -2680,8 +2822,9 @@  discard block
 block discarded – undo
2680 2822
 
2681 2823
 	// What theme are we in?
2682 2824
 	$theme_name = basename($settings['theme_url']);
2683
-	if (empty($theme_name))
2684
-		$theme_name = 'unknown';
2825
+	if (empty($theme_name)) {
2826
+			$theme_name = 'unknown';
2827
+	}
2685 2828
 
2686 2829
 	// For each file open it up and write it out!
2687 2830
 	foreach (explode('+', $template_name) as $template)
@@ -2723,8 +2866,9 @@  discard block
 block discarded – undo
2723 2866
 				$found = true;
2724 2867
 
2725 2868
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2726
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2727
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2869
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2870
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2871
+				}
2728 2872
 
2729 2873
 				break;
2730 2874
 			}
@@ -2764,8 +2908,9 @@  discard block
 block discarded – undo
2764 2908
 	}
2765 2909
 
2766 2910
 	// Keep track of what we're up to soldier.
2767
-	if ($db_show_debug === true)
2768
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2911
+	if ($db_show_debug === true) {
2912
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2913
+	}
2769 2914
 
2770 2915
 	// Remember what we have loaded, and in which language.
2771 2916
 	$already_loaded[$template_name] = $lang;
@@ -2811,8 +2956,9 @@  discard block
 block discarded – undo
2811 2956
 				)
2812 2957
 			);
2813 2958
 			// In the EXTREMELY unlikely event this happens, give an error message.
2814
-			if ($smcFunc['db_num_rows']($result) == 0)
2815
-				fatal_lang_error('parent_not_found', 'critical');
2959
+			if ($smcFunc['db_num_rows']($result) == 0) {
2960
+							fatal_lang_error('parent_not_found', 'critical');
2961
+			}
2816 2962
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2817 2963
 			{
2818 2964
 				if (!isset($boards[$row['id_board']]))
@@ -2829,8 +2975,8 @@  discard block
 block discarded – undo
2829 2975
 					);
2830 2976
 				}
2831 2977
 				// If a moderator exists for this board, add that moderator for all children too.
2832
-				if (!empty($row['id_moderator']))
2833
-					foreach ($boards as $id => $dummy)
2978
+				if (!empty($row['id_moderator'])) {
2979
+									foreach ($boards as $id => $dummy)
2834 2980
 					{
2835 2981
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2836 2982
 							'id' => $row['id_moderator'],
@@ -2838,11 +2984,12 @@  discard block
 block discarded – undo
2838 2984
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2839 2985
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2840 2986
 						);
2987
+				}
2841 2988
 					}
2842 2989
 
2843 2990
 				// If a moderator group exists for this board, add that moderator group for all children too
2844
-				if (!empty($row['id_moderator_group']))
2845
-					foreach ($boards as $id => $dummy)
2991
+				if (!empty($row['id_moderator_group'])) {
2992
+									foreach ($boards as $id => $dummy)
2846 2993
 					{
2847 2994
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2848 2995
 							'id' => $row['id_moderator_group'],
@@ -2850,6 +2997,7 @@  discard block
 block discarded – undo
2850 2997
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2851 2998
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2852 2999
 						);
3000
+				}
2853 3001
 					}
2854 3002
 			}
2855 3003
 			$smcFunc['db_free_result']($result);
@@ -2876,23 +3024,27 @@  discard block
 block discarded – undo
2876 3024
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2877 3025
 	{
2878 3026
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2879
-		if (empty($smcFunc['ucwords']))
2880
-			reloadSettings();
3027
+		if (empty($smcFunc['ucwords'])) {
3028
+					reloadSettings();
3029
+		}
2881 3030
 
2882 3031
 		// If we don't have our theme information yet, let's get it.
2883
-		if (empty($settings['default_theme_dir']))
2884
-			loadTheme(0, false);
3032
+		if (empty($settings['default_theme_dir'])) {
3033
+					loadTheme(0, false);
3034
+		}
2885 3035
 
2886 3036
 		// Default language directories to try.
2887 3037
 		$language_directories = array(
2888 3038
 			$settings['default_theme_dir'] . '/languages',
2889 3039
 		);
2890
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2891
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3040
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3041
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3042
+		}
2892 3043
 
2893 3044
 		// We possibly have a base theme directory.
2894
-		if (!empty($settings['base_theme_dir']))
2895
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3045
+		if (!empty($settings['base_theme_dir'])) {
3046
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3047
+		}
2896 3048
 
2897 3049
 		// Remove any duplicates.
2898 3050
 		$language_directories = array_unique($language_directories);
@@ -2906,20 +3058,21 @@  discard block
 block discarded – undo
2906 3058
 		foreach ($language_directories as $language_dir)
2907 3059
 		{
2908 3060
 			// Can't look in here... doesn't exist!
2909
-			if (!file_exists($language_dir))
2910
-				continue;
3061
+			if (!file_exists($language_dir)) {
3062
+							continue;
3063
+			}
2911 3064
 
2912 3065
 			$dir = dir($language_dir);
2913 3066
 			while ($entry = $dir->read())
2914 3067
 			{
2915 3068
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2916
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2917
-					continue;
2918
-
2919
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2920
-					$langName = $langList[$matches[1]];
3069
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3070
+									continue;
3071
+				}
2921 3072
 
2922
-				else
3073
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3074
+									$langName = $langList[$matches[1]];
3075
+				} else
2923 3076
 				{
2924 3077
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2925 3078
 
@@ -2960,12 +3113,14 @@  discard block
 block discarded – undo
2960 3113
 		}
2961 3114
 
2962 3115
 		// Do we need to store the lang list?
2963
-		if (empty($langList))
2964
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3116
+		if (empty($langList)) {
3117
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3118
+		}
2965 3119
 
2966 3120
 		// Let's cash in on this deal.
2967
-		if (!empty($modSettings['cache_enable']))
2968
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3121
+		if (!empty($modSettings['cache_enable'])) {
3122
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3123
+		}
2969 3124
 	}
2970 3125
 
2971 3126
 	return $context['languages'];
@@ -2988,8 +3143,9 @@  discard block
 block discarded – undo
2988 3143
 	global $modSettings, $options, $txt;
2989 3144
 	static $censor_vulgar = null, $censor_proper;
2990 3145
 
2991
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2992
-		return $text;
3146
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3147
+			return $text;
3148
+	}
2993 3149
 
2994 3150
 	// If they haven't yet been loaded, load them.
2995 3151
 	if ($censor_vulgar == null)
@@ -3020,9 +3176,9 @@  discard block
 block discarded – undo
3020 3176
 	{
3021 3177
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3022 3178
 		$text = $func($censor_vulgar, $censor_proper, $text);
3179
+	} else {
3180
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3023 3181
 	}
3024
-	else
3025
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3026 3182
 
3027 3183
 	return $text;
3028 3184
 }
@@ -3048,38 +3204,42 @@  discard block
 block discarded – undo
3048 3204
 	@ini_set('track_errors', '1');
3049 3205
 
3050 3206
 	// Don't include the file more than once, if $once is true.
3051
-	if ($once && in_array($filename, $templates))
3052
-		return;
3207
+	if ($once && in_array($filename, $templates)) {
3208
+			return;
3209
+	}
3053 3210
 	// Add this file to the include list, whether $once is true or not.
3054
-	else
3055
-		$templates[] = $filename;
3211
+	else {
3212
+			$templates[] = $filename;
3213
+	}
3056 3214
 
3057 3215
 	// Are we going to use eval?
3058 3216
 	if (empty($modSettings['disableTemplateEval']))
3059 3217
 	{
3060 3218
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3061 3219
 		$settings['current_include_filename'] = $filename;
3062
-	}
3063
-	else
3220
+	} else
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
 
3073 3231
 	if ($file_found !== true)
3074 3232
 	{
3075 3233
 		ob_end_clean();
3076
-		if (!empty($modSettings['enableCompressedOutput']))
3077
-			@ob_start('ob_gzhandler');
3078
-		else
3079
-			ob_start();
3234
+		if (!empty($modSettings['enableCompressedOutput'])) {
3235
+					@ob_start('ob_gzhandler');
3236
+		} else {
3237
+					ob_start();
3238
+		}
3080 3239
 
3081
-		if (isset($_GET['debug']))
3082
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3240
+		if (isset($_GET['debug'])) {
3241
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3242
+		}
3083 3243
 
3084 3244
 		// Don't cache error pages!!
3085 3245
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3098,12 +3258,13 @@  discard block
 block discarded – undo
3098 3258
 		echo '<!DOCTYPE html>
3099 3259
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3100 3260
 	<head>';
3101
-		if (isset($context['character_set']))
3102
-			echo '
3261
+		if (isset($context['character_set'])) {
3262
+					echo '
3103 3263
 		<meta charset="', $context['character_set'], '">';
3264
+		}
3104 3265
 
3105
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3106
-			echo '
3266
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3267
+					echo '
3107 3268
 		<title>', $mtitle, '</title>
3108 3269
 	</head>
3109 3270
 	<body>
@@ -3111,8 +3272,8 @@  discard block
 block discarded – undo
3111 3272
 		', $mmessage, '
3112 3273
 	</body>
3113 3274
 </html>';
3114
-		elseif (!allowedTo('admin_forum'))
3115
-			echo '
3275
+		} elseif (!allowedTo('admin_forum')) {
3276
+					echo '
3116 3277
 		<title>', $txt['template_parse_error'], '</title>
3117 3278
 	</head>
3118 3279
 	<body>
@@ -3120,16 +3281,18 @@  discard block
 block discarded – undo
3120 3281
 		', $txt['template_parse_error_message'], '
3121 3282
 	</body>
3122 3283
 </html>';
3123
-		else
3284
+		} else
3124 3285
 		{
3125 3286
 			require_once($sourcedir . '/Subs-Package.php');
3126 3287
 
3127 3288
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3128 3289
 			$error_array = error_get_last();
3129
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3130
-				$error = $error_array['message'];
3131
-			if (empty($error))
3132
-				$error = $txt['template_parse_errmsg'];
3290
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3291
+							$error = $error_array['message'];
3292
+			}
3293
+			if (empty($error)) {
3294
+							$error = $txt['template_parse_errmsg'];
3295
+			}
3133 3296
 
3134 3297
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3135 3298
 
@@ -3140,11 +3303,12 @@  discard block
 block discarded – undo
3140 3303
 		<h3>', $txt['template_parse_error'], '</h3>
3141 3304
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3142 3305
 
3143
-			if (!empty($error))
3144
-				echo '
3306
+			if (!empty($error)) {
3307
+							echo '
3145 3308
 		<hr>
3146 3309
 
3147 3310
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3311
+			}
3148 3312
 
3149 3313
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3150 3314
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3154,10 +3318,11 @@  discard block
 block discarded – undo
3154 3318
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3155 3319
 
3156 3320
 				// Fix the PHP code stuff...
3157
-				if (!isBrowser('gecko'))
3158
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3159
-				else
3160
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3321
+				if (!isBrowser('gecko')) {
3322
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3323
+				} else {
3324
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3325
+				}
3161 3326
 
3162 3327
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3163 3328
 				$j = -1;
@@ -3165,8 +3330,9 @@  discard block
 block discarded – undo
3165 3330
 				{
3166 3331
 					$j++;
3167 3332
 
3168
-					if (substr_count($line, '<br>') == 0)
3169
-						continue;
3333
+					if (substr_count($line, '<br>') == 0) {
3334
+											continue;
3335
+					}
3170 3336
 
3171 3337
 					$n = substr_count($line, '<br>');
3172 3338
 					for ($i = 0; $i < $n; $i++)
@@ -3185,38 +3351,42 @@  discard block
 block discarded – undo
3185 3351
 				// Figure out what the color coding was before...
3186 3352
 				$line = max($match[1] - 9, 1);
3187 3353
 				$last_line = '';
3188
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3189
-					if (strpos($data2[$line2], '<') !== false)
3354
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3355
+									if (strpos($data2[$line2], '<') !== false)
3190 3356
 					{
3191 3357
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3192 3358
 							$last_line = $color_match[1];
3359
+				}
3193 3360
 						break;
3194 3361
 					}
3195 3362
 
3196 3363
 				// Show the relevant lines...
3197 3364
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3198 3365
 				{
3199
-					if ($line == $match[1])
3200
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3366
+					if ($line == $match[1]) {
3367
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3368
+					}
3201 3369
 
3202 3370
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3203
-					if (isset($data2[$line]) && $data2[$line] != '')
3204
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3371
+					if (isset($data2[$line]) && $data2[$line] != '') {
3372
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3373
+					}
3205 3374
 
3206 3375
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3207 3376
 					{
3208 3377
 						$last_line = $color_match[1];
3209 3378
 						echo '</', substr($last_line, 1, 4), '>';
3379
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3380
+											$last_line = '';
3381
+					} elseif ($last_line != '' && $data2[$line] != '') {
3382
+											echo '</', substr($last_line, 1, 4), '>';
3210 3383
 					}
3211
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3212
-						$last_line = '';
3213
-					elseif ($last_line != '' && $data2[$line] != '')
3214
-						echo '</', substr($last_line, 1, 4), '>';
3215 3384
 
3216
-					if ($line == $match[1])
3217
-						echo '</pre></div><pre style="margin: 0;">';
3218
-					else
3219
-						echo "\n";
3385
+					if ($line == $match[1]) {
3386
+											echo '</pre></div><pre style="margin: 0;">';
3387
+					} else {
3388
+											echo "\n";
3389
+					}
3220 3390
 				}
3221 3391
 
3222 3392
 				echo '</pre></div>';
@@ -3240,8 +3410,9 @@  discard block
 block discarded – undo
3240 3410
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3241 3411
 
3242 3412
 	// Figure out what type of database we are using.
3243
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3244
-		$db_type = 'mysql';
3413
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3414
+			$db_type = 'mysql';
3415
+	}
3245 3416
 
3246 3417
 	// Load the file for the database.
3247 3418
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3249,8 +3420,9 @@  discard block
 block discarded – undo
3249 3420
 	$db_options = array();
3250 3421
 
3251 3422
 	// Add in the port if needed
3252
-	if (!empty($db_port))
3253
-		$db_options['port'] = $db_port;
3423
+	if (!empty($db_port)) {
3424
+			$db_options['port'] = $db_port;
3425
+	}
3254 3426
 
3255 3427
 	// 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 3428
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3269,13 +3441,15 @@  discard block
 block discarded – undo
3269 3441
 	}
3270 3442
 
3271 3443
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3272
-	if (!$db_connection)
3273
-		display_db_error();
3444
+	if (!$db_connection) {
3445
+			display_db_error();
3446
+	}
3274 3447
 
3275 3448
 	// If in SSI mode fix up the prefix.
3276
-	if (SMF == 'SSI')
3277
-		db_fix_prefix($db_prefix, $db_name);
3278
-}
3449
+	if (SMF == 'SSI') {
3450
+			db_fix_prefix($db_prefix, $db_name);
3451
+	}
3452
+	}
3279 3453
 
3280 3454
 /**
3281 3455
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3289,10 +3463,11 @@  discard block
 block discarded – undo
3289 3463
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3290 3464
 
3291 3465
 	// 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;
3466
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3467
+			return $cacheAPI;
3468
+	} elseif (is_null($cacheAPI)) {
3469
+			$cacheAPI = false;
3470
+	}
3296 3471
 
3297 3472
 	// Make sure our class is in session.
3298 3473
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3313,8 +3488,9 @@  discard block
 block discarded – undo
3313 3488
 		if (!$testAPI->isSupported())
3314 3489
 		{
3315 3490
 			// Can we save ourselves?
3316
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3317
-				return loadCacheAccelerator(null, false);
3491
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3492
+							return loadCacheAccelerator(null, false);
3493
+			}
3318 3494
 			return false;
3319 3495
 		}
3320 3496
 
@@ -3326,9 +3502,9 @@  discard block
 block discarded – undo
3326 3502
 		{
3327 3503
 			$cacheAPI = $testAPI;
3328 3504
 			return $cacheAPI;
3505
+		} else {
3506
+					return $testAPI;
3329 3507
 		}
3330
-		else
3331
-			return $testAPI;
3332 3508
 	}
3333 3509
 }
3334 3510
 
@@ -3348,8 +3524,9 @@  discard block
 block discarded – undo
3348 3524
 
3349 3525
 	// @todo Why are we doing this if caching is disabled?
3350 3526
 
3351
-	if (function_exists('call_integration_hook'))
3352
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3527
+	if (function_exists('call_integration_hook')) {
3528
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3529
+	}
3353 3530
 
3354 3531
 	/* Refresh the cache if either:
3355 3532
 		1. Caching is disabled.
@@ -3363,16 +3540,19 @@  discard block
 block discarded – undo
3363 3540
 		require_once($sourcedir . '/' . $file);
3364 3541
 		$cache_block = call_user_func_array($function, $params);
3365 3542
 
3366
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3367
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3543
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3544
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3545
+		}
3368 3546
 	}
3369 3547
 
3370 3548
 	// 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']);
3549
+	if (!empty($cache_block['post_retri_eval'])) {
3550
+			eval($cache_block['post_retri_eval']);
3551
+	}
3373 3552
 
3374
-	if (function_exists('call_integration_hook'))
3375
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3553
+	if (function_exists('call_integration_hook')) {
3554
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3555
+	}
3376 3556
 
3377 3557
 	return $cache_block['data'];
3378 3558
 }
@@ -3399,8 +3579,9 @@  discard block
 block discarded – undo
3399 3579
 	global $smcFunc, $cache_enable, $cacheAPI;
3400 3580
 	global $cache_hits, $cache_count, $db_show_debug;
3401 3581
 
3402
-	if (empty($cache_enable) || empty($cacheAPI))
3403
-		return;
3582
+	if (empty($cache_enable) || empty($cacheAPI)) {
3583
+			return;
3584
+	}
3404 3585
 
3405 3586
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3406 3587
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3413,12 +3594,14 @@  discard block
 block discarded – undo
3413 3594
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3414 3595
 	$cacheAPI->putData($key, $value, $ttl);
3415 3596
 
3416
-	if (function_exists('call_integration_hook'))
3417
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3597
+	if (function_exists('call_integration_hook')) {
3598
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3599
+	}
3418 3600
 
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
-}
3601
+	if (isset($db_show_debug) && $db_show_debug === true) {
3602
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3603
+	}
3604
+	}
3422 3605
 
3423 3606
 /**
3424 3607
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3434,8 +3617,9 @@  discard block
 block discarded – undo
3434 3617
 	global $smcFunc, $cache_enable, $cacheAPI;
3435 3618
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3436 3619
 
3437
-	if (empty($cache_enable) || empty($cacheAPI))
3438
-		return;
3620
+	if (empty($cache_enable) || empty($cacheAPI)) {
3621
+			return;
3622
+	}
3439 3623
 
3440 3624
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3441 3625
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3455,16 +3639,18 @@  discard block
 block discarded – undo
3455 3639
 
3456 3640
 		if (empty($value))
3457 3641
 		{
3458
-			if (!is_array($cache_misses))
3459
-				$cache_misses = array();
3642
+			if (!is_array($cache_misses)) {
3643
+							$cache_misses = array();
3644
+			}
3460 3645
 
3461 3646
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3462 3647
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3463 3648
 		}
3464 3649
 	}
3465 3650
 
3466
-	if (function_exists('call_integration_hook') && isset($value))
3467
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3651
+	if (function_exists('call_integration_hook') && isset($value)) {
3652
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3653
+	}
3468 3654
 
3469 3655
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3470 3656
 }
@@ -3486,8 +3672,9 @@  discard block
 block discarded – undo
3486 3672
 	global $cacheAPI;
3487 3673
 
3488 3674
 	// If we can't get to the API, can't do this.
3489
-	if (empty($cacheAPI))
3490
-		return;
3675
+	if (empty($cacheAPI)) {
3676
+			return;
3677
+	}
3491 3678
 
3492 3679
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3493 3680
 	$cacheAPI->cleanCache($type);
@@ -3512,8 +3699,9 @@  discard block
 block discarded – undo
3512 3699
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_url, $image_proxy_secret, $user_info;
3513 3700
 
3514 3701
 	// Come on!
3515
-	if (empty($data))
3516
-		return array();
3702
+	if (empty($data)) {
3703
+			return array();
3704
+	}
3517 3705
 
3518 3706
 	// Set a nice default var.
3519 3707
 	$image = '';
@@ -3521,11 +3709,11 @@  discard block
 block discarded – undo
3521 3709
 	// Gravatar has been set as mandatory!
3522 3710
 	if (!empty($modSettings['gravatarOverride']))
3523 3711
 	{
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']);
3712
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3713
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3714
+		} else if (!empty($data['email'])) {
3715
+					$image = get_gravatar_url($data['email']);
3716
+		}
3529 3717
 	}
3530 3718
 
3531 3719
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3537,57 +3725,63 @@  discard block
 block discarded – undo
3537 3725
 			// Gravatar.
3538 3726
 			if (stristr($data['avatar'], 'gravatar://'))
3539 3727
 			{
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));
3728
+				if ($data['avatar'] == 'gravatar://') {
3729
+									$image = get_gravatar_url($data['email']);
3730
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3731
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3732
+				}
3545 3733
 			}
3546 3734
 
3547 3735
 			// External url.
3548 3736
 			else
3549 3737
 			{
3550 3738
 				// Using ssl?
3551
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3552
-					if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
3739
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3740
+									if ($image_proxy_enabled === 2 && !empty($image_proxy_url))
3553 3741
 						$image = $image_proxy_url . urlencode($data['avatar']);
3554
-					else
3555
-						$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3742
+				} else {
3743
+											$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3744
+					}
3556 3745
 
3557 3746
 				// Just a plain external url.
3558
-				else
3559
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3747
+				else {
3748
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3749
+				}
3560 3750
 			}
3561 3751
 		}
3562 3752
 
3563 3753
 		// Perhaps this user has an attachment as avatar...
3564
-		else if (!empty($data['filename']))
3565
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3754
+		else if (!empty($data['filename'])) {
3755
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3756
+		}
3566 3757
 
3567 3758
 		// Right... no avatar... use our default image.
3568
-		else
3569
-			$image = $modSettings['avatar_url'] . '/default.png';
3759
+		else {
3760
+					$image = $modSettings['avatar_url'] . '/default.png';
3761
+		}
3570 3762
 	}
3571 3763
 
3572 3764
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3573 3765
 
3574 3766
 	// 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.
3575
-	if (!empty($image))
3576
-		return array(
3767
+	if (!empty($image)) {
3768
+			return array(
3577 3769
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3578 3770
 			'image' => '<img class="avatar" src="' . $image . '" />',
3579 3771
 			'href' => $image,
3580 3772
 			'url' => $image,
3581 3773
 		);
3774
+	}
3582 3775
 
3583 3776
 	// Fallback to make life easier for everyone...
3584
-	else
3585
-		return array(
3777
+	else {
3778
+			return array(
3586 3779
 			'name' => '',
3587 3780
 			'image' => '',
3588 3781
 			'href' => '',
3589 3782
 			'url' => '',
3590 3783
 		);
3591
-}
3784
+	}
3785
+	}
3592 3786
 
3593 3787
 ?>
3594 3788
\ No newline at end of file
Please login to merge, or discard this patch.