Passed
Push — release-2.1 ( feb19c...865955 )
by Mathias
25s
created
Sources/Recent.php 1 patch
Braces   +208 added lines, -170 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
  * Get the latest post made on the system
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 			'is_approved' => 1,
45 46
 		)
46 47
 	);
47
-	if ($smcFunc['db_num_rows']($request) == 0)
48
-		return array();
48
+	if ($smcFunc['db_num_rows']($request) == 0) {
49
+			return array();
50
+	}
49 51
 	$row = $smcFunc['db_fetch_assoc']($request);
50 52
 	$smcFunc['db_free_result']($request);
51 53
 
@@ -54,8 +56,9 @@  discard block
 block discarded – undo
54 56
 	censorText($row['body']);
55 57
 
56 58
 	$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled']), array('<br>' => '&#10;')));
57
-	if ($smcFunc['strlen']($row['body']) > 128)
58
-		$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
59
+	if ($smcFunc['strlen']($row['body']) > 128) {
60
+			$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
61
+	}
59 62
 
60 63
 	// Send the data.
61 64
 	return array(
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 
84 87
 	$context['is_redirect'] = false;
85 88
 
86
-	if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95)
87
-		$_REQUEST['start'] = 95;
89
+	if (isset($_REQUEST['start']) && $_REQUEST['start'] > 95) {
90
+			$_REQUEST['start'] = 95;
91
+	}
88 92
 
89 93
 	$_REQUEST['start'] = (int) $_REQUEST['start'];
90 94
 
@@ -92,8 +96,9 @@  discard block
 block discarded – undo
92 96
 	if (!empty($_REQUEST['c']) && empty($board))
93 97
 	{
94 98
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
95
-		foreach ($_REQUEST['c'] as $i => $c)
96
-			$_REQUEST['c'][$i] = (int) $c;
99
+		foreach ($_REQUEST['c'] as $i => $c) {
100
+					$_REQUEST['c'][$i] = (int) $c;
101
+		}
97 102
 
98 103
 		if (count($_REQUEST['c']) == 1)
99 104
 		{
@@ -109,8 +114,9 @@  discard block
 block discarded – undo
109 114
 			list ($name) = $smcFunc['db_fetch_row']($request);
110 115
 			$smcFunc['db_free_result']($request);
111 116
 
112
-			if (empty($name))
113
-				fatal_lang_error('no_access', false);
117
+			if (empty($name)) {
118
+							fatal_lang_error('no_access', false);
119
+			}
114 120
 
115 121
 			$context['linktree'][] = array(
116 122
 				'url' => $scripturl . '#c' . (int) $_REQUEST['c'],
@@ -142,8 +148,9 @@  discard block
 block discarded – undo
142 148
 		}
143 149
 		$smcFunc['db_free_result']($request);
144 150
 
145
-		if (empty($boards))
146
-			fatal_lang_error('error_no_boards_selected');
151
+		if (empty($boards)) {
152
+					fatal_lang_error('error_no_boards_selected');
153
+		}
147 154
 
148 155
 		$query_this_board = 'b.id_board IN ({array_int:boards})';
149 156
 		$query_parameters['boards'] = $boards;
@@ -157,12 +164,12 @@  discard block
 block discarded – undo
157 164
 		}
158 165
 
159 166
 		$context['page_index'] = constructPageIndex($scripturl . '?action=recent;c=' . implode(',', $_REQUEST['c']), $_REQUEST['start'], min(100, $total_cat_posts), 10, false);
160
-	}
161
-	elseif (!empty($_REQUEST['boards']))
167
+	} elseif (!empty($_REQUEST['boards']))
162 168
 	{
163 169
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
164
-		foreach ($_REQUEST['boards'] as $i => $b)
165
-			$_REQUEST['boards'][$i] = (int) $b;
170
+		foreach ($_REQUEST['boards'] as $i => $b) {
171
+					$_REQUEST['boards'][$i] = (int) $b;
172
+		}
166 173
 
167 174
 		$request = $smcFunc['db_query']('', '
168 175
 			SELECT b.id_board, b.num_posts
@@ -186,8 +193,9 @@  discard block
 block discarded – undo
186 193
 		}
187 194
 		$smcFunc['db_free_result']($request);
188 195
 
189
-		if (empty($boards))
190
-			fatal_lang_error('error_no_boards_selected');
196
+		if (empty($boards)) {
197
+					fatal_lang_error('error_no_boards_selected');
198
+		}
191 199
 
192 200
 		$query_this_board = 'b.id_board IN ({array_int:boards})';
193 201
 		$query_parameters['boards'] = $boards;
@@ -201,8 +209,7 @@  discard block
 block discarded – undo
201 209
 		}
202 210
 
203 211
 		$context['page_index'] = constructPageIndex($scripturl . '?action=recent;boards=' . implode(',', $_REQUEST['boards']), $_REQUEST['start'], min(100, $total_posts), 10, false);
204
-	}
205
-	elseif (!empty($board))
212
+	} elseif (!empty($board))
206 213
 	{
207 214
 		$request = $smcFunc['db_query']('', '
208 215
 			SELECT num_posts, redirect
@@ -235,8 +242,7 @@  discard block
 block discarded – undo
235 242
 		}
236 243
 
237 244
 		$context['page_index'] = constructPageIndex($scripturl . '?action=recent;board=' . $board . '.%1$d', $_REQUEST['start'], min(100, $total_posts), 10, true);
238
-	}
239
-	else
245
+	} else
240 246
 	{
241 247
 		$query_this_board = '{query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
242 248
 					AND b.id_board != {int:recycle_board}' : ''). '
@@ -271,8 +277,9 @@  discard block
 block discarded – undo
271 277
 	);
272 278
 
273 279
 	// If you selected a redirection board, don't try getting posts for it...
274
-	if ($context['is_redirect'])
275
-		$messages = 0;
280
+	if ($context['is_redirect']) {
281
+			$messages = 0;
282
+	}
276 283
 
277 284
 	$key = 'recent-' . $user_info['id'] . '-' . md5($smcFunc['json_encode'](array_diff_key($query_parameters, array('max_id_msg' => 0)))) . '-' . (int) $_REQUEST['start'];
278 285
 	if (!$context['is_redirect'] && (empty($modSettings['cache_enable']) || ($messages = cache_get_data($key, 120)) == null))
@@ -303,16 +310,18 @@  discard block
 block discarded – undo
303 310
 				$query_this_board = str_replace('AND m.id_msg >= {int:max_id_msg}', '', $query_this_board);
304 311
 				$cache_results = true;
305 312
 				unset($query_parameters['max_id_msg']);
313
+			} else {
314
+							$done = true;
306 315
 			}
307
-			else
308
-				$done = true;
309 316
 		}
310 317
 		$messages = array();
311
-		while ($row = $smcFunc['db_fetch_assoc']($request))
312
-			$messages[] = $row['id_msg'];
318
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
319
+					$messages[] = $row['id_msg'];
320
+		}
313 321
 		$smcFunc['db_free_result']($request);
314
-		if (!empty($cache_results))
315
-			cache_put_data($key, $messages, 120);
322
+		if (!empty($cache_results)) {
323
+					cache_put_data($key, $messages, 120);
324
+		}
316 325
 	}
317 326
 
318 327
 	// Nothing here... Or at least, nothing you can see...
@@ -399,8 +408,9 @@  discard block
 block discarded – undo
399 408
 			'css_class' => 'windowbg',
400 409
 		);
401 410
 
402
-		if ($user_info['id'] == $row['id_first_member'])
403
-			$board_ids['own'][$row['id_board']][] = $row['id_msg'];
411
+		if ($user_info['id'] == $row['id_first_member']) {
412
+					$board_ids['own'][$row['id_board']][] = $row['id_msg'];
413
+		}
404 414
 		$board_ids['any'][$row['id_board']][] = $row['id_msg'];
405 415
 	}
406 416
 	$smcFunc['db_free_result']($request);
@@ -426,20 +436,23 @@  discard block
 block discarded – undo
426 436
 			$boards = boardsAllowedTo($permission);
427 437
 
428 438
 			// If 0 is the only thing in the array, they can do it everywhere!
429
-			if (!empty($boards) && $boards[0] == 0)
430
-				$boards = array_keys($board_ids[$type]);
439
+			if (!empty($boards) && $boards[0] == 0) {
440
+							$boards = array_keys($board_ids[$type]);
441
+			}
431 442
 
432 443
 			// Go through the boards, and look for posts they can do this on.
433 444
 			foreach ($boards as $board_id)
434 445
 			{
435 446
 				// Hmm, they have permission, but there are no topics from that board on this page.
436
-				if (!isset($board_ids[$type][$board_id]))
437
-					continue;
447
+				if (!isset($board_ids[$type][$board_id])) {
448
+									continue;
449
+				}
438 450
 
439 451
 				// Okay, looks like they can do it for these posts.
440
-				foreach ($board_ids[$type][$board_id] as $counter)
441
-					if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id'])
452
+				foreach ($board_ids[$type][$board_id] as $counter) {
453
+									if ($type == 'any' || $context['posts'][$counter]['poster']['id'] == $user_info['id'])
442 454
 						$context['posts'][$counter][$allowed] = true;
455
+				}
443 456
 			}
444 457
 		}
445 458
 	}
@@ -482,17 +495,19 @@  discard block
 block discarded – undo
482 495
 	$context['showing_all_topics'] = isset($_GET['all']);
483 496
 	$context['start'] = (int) $_REQUEST['start'];
484 497
 	$context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
485
-	if ($_REQUEST['action'] == 'unread')
486
-		$context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit'];
487
-	else
488
-		$context['page_title'] = $txt['unread_replies'];
498
+	if ($_REQUEST['action'] == 'unread') {
499
+			$context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit'];
500
+	} else {
501
+			$context['page_title'] = $txt['unread_replies'];
502
+	}
489 503
 
490
-	if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread'])
491
-		fatal_lang_error('loadavg_allunread_disabled', false);
492
-	elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies'])
493
-		fatal_lang_error('loadavg_unreadreplies_disabled', false);
494
-	elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread'])
495
-		fatal_lang_error('loadavg_unread_disabled', false);
504
+	if ($context['showing_all_topics'] && !empty($context['load_average']) && !empty($modSettings['loadavg_allunread']) && $context['load_average'] >= $modSettings['loadavg_allunread']) {
505
+			fatal_lang_error('loadavg_allunread_disabled', false);
506
+	} elseif ($_REQUEST['action'] != 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unreadreplies']) && $context['load_average'] >= $modSettings['loadavg_unreadreplies']) {
507
+			fatal_lang_error('loadavg_unreadreplies_disabled', false);
508
+	} elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($context['load_average']) && !empty($modSettings['loadavg_unread']) && $context['load_average'] >= $modSettings['loadavg_unread']) {
509
+			fatal_lang_error('loadavg_unread_disabled', false);
510
+	}
496 511
 
497 512
 	// Parameters for the main query.
498 513
 	$query_parameters = array();
@@ -505,12 +520,14 @@  discard block
 block discarded – undo
505 520
 		if (!empty($_REQUEST['boards']))
506 521
 		{
507 522
 			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
508
-			foreach ($_REQUEST['boards'] as $b)
509
-				$boards[] = (int) $b;
523
+			foreach ($_REQUEST['boards'] as $b) {
524
+							$boards[] = (int) $b;
525
+			}
510 526
 		}
511 527
 
512
-		if (!empty($board))
513
-			$boards[] = (int) $board;
528
+		if (!empty($board)) {
529
+					$boards[] = (int) $board;
530
+		}
514 531
 
515 532
 		// The easiest thing is to just get all the boards they can see, but since we've specified the top of tree we ignore some of them
516 533
 		$request = $smcFunc['db_query']('', '
@@ -527,30 +544,31 @@  discard block
 block discarded – undo
527 544
 			)
528 545
 		);
529 546
 
530
-		while ($row = $smcFunc['db_fetch_assoc']($request))
531
-			if (in_array($row['id_parent'], $boards))
547
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
548
+					if (in_array($row['id_parent'], $boards))
532 549
 				$boards[] = $row['id_board'];
550
+		}
533 551
 
534 552
 		$smcFunc['db_free_result']($request);
535 553
 
536
-		if (empty($boards))
537
-			fatal_lang_error('error_no_boards_selected');
554
+		if (empty($boards)) {
555
+					fatal_lang_error('error_no_boards_selected');
556
+		}
538 557
 
539 558
 		$query_this_board = 'id_board IN ({array_int:boards})';
540 559
 		$query_parameters['boards'] = $boards;
541 560
 		$context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d';
542
-	}
543
-	elseif (!empty($board))
561
+	} elseif (!empty($board))
544 562
 	{
545 563
 		$query_this_board = 'id_board = {int:board}';
546 564
 		$query_parameters['board'] = $board;
547 565
 		$context['querystring_board_limits'] = ';board=' . $board . '.%1$d';
548
-	}
549
-	elseif (!empty($_REQUEST['boards']))
566
+	} elseif (!empty($_REQUEST['boards']))
550 567
 	{
551 568
 		$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
552
-		foreach ($_REQUEST['boards'] as $i => $b)
553
-			$_REQUEST['boards'][$i] = (int) $b;
569
+		foreach ($_REQUEST['boards'] as $i => $b) {
570
+					$_REQUEST['boards'][$i] = (int) $b;
571
+		}
554 572
 
555 573
 		$request = $smcFunc['db_query']('', '
556 574
 			SELECT b.id_board
@@ -562,22 +580,24 @@  discard block
 block discarded – undo
562 580
 			)
563 581
 		);
564 582
 		$boards = array();
565
-		while ($row = $smcFunc['db_fetch_assoc']($request))
566
-			$boards[] = $row['id_board'];
583
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
584
+					$boards[] = $row['id_board'];
585
+		}
567 586
 		$smcFunc['db_free_result']($request);
568 587
 
569
-		if (empty($boards))
570
-			fatal_lang_error('error_no_boards_selected');
588
+		if (empty($boards)) {
589
+					fatal_lang_error('error_no_boards_selected');
590
+		}
571 591
 
572 592
 		$query_this_board = 'id_board IN ({array_int:boards})';
573 593
 		$query_parameters['boards'] = $boards;
574 594
 		$context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d';
575
-	}
576
-	elseif (!empty($_REQUEST['c']))
595
+	} elseif (!empty($_REQUEST['c']))
577 596
 	{
578 597
 		$_REQUEST['c'] = explode(',', $_REQUEST['c']);
579
-		foreach ($_REQUEST['c'] as $i => $c)
580
-			$_REQUEST['c'][$i] = (int) $c;
598
+		foreach ($_REQUEST['c'] as $i => $c) {
599
+					$_REQUEST['c'][$i] = (int) $c;
600
+		}
581 601
 
582 602
 		$see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
583 603
 		$request = $smcFunc['db_query']('', '
@@ -590,18 +610,19 @@  discard block
 block discarded – undo
590 610
 			)
591 611
 		);
592 612
 		$boards = array();
593
-		while ($row = $smcFunc['db_fetch_assoc']($request))
594
-			$boards[] = $row['id_board'];
613
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
614
+					$boards[] = $row['id_board'];
615
+		}
595 616
 		$smcFunc['db_free_result']($request);
596 617
 
597
-		if (empty($boards))
598
-			fatal_lang_error('error_no_boards_selected');
618
+		if (empty($boards)) {
619
+					fatal_lang_error('error_no_boards_selected');
620
+		}
599 621
 
600 622
 		$query_this_board = 'id_board IN ({array_int:boards})';
601 623
 		$query_parameters['boards'] = $boards;
602 624
 		$context['querystring_board_limits'] = ';c=' . implode(',', $_REQUEST['c']) . ';start=%1$d';
603
-	}
604
-	else
625
+	} else
605 626
 	{
606 627
 		$see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
607 628
 		// Don't bother to show deleted posts!
@@ -615,12 +636,14 @@  discard block
 block discarded – undo
615 636
 			)
616 637
 		);
617 638
 		$boards = array();
618
-		while ($row = $smcFunc['db_fetch_assoc']($request))
619
-			$boards[] = $row['id_board'];
639
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
640
+					$boards[] = $row['id_board'];
641
+		}
620 642
 		$smcFunc['db_free_result']($request);
621 643
 
622
-		if (empty($boards))
623
-			fatal_lang_error('error_no_boards_available', false);
644
+		if (empty($boards)) {
645
+					fatal_lang_error('error_no_boards_available', false);
646
+		}
624 647
 
625 648
 		$query_this_board = 'id_board IN ({array_int:boards})';
626 649
 		$query_parameters['boards'] = $boards;
@@ -682,13 +705,14 @@  discard block
 block discarded – undo
682 705
 		'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies']
683 706
 	);
684 707
 
685
-	if ($context['showing_all_topics'])
686
-		$context['linktree'][] = array(
708
+	if ($context['showing_all_topics']) {
709
+			$context['linktree'][] = array(
687 710
 			'url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'],
688 711
 			'name' => $txt['unread_topics_all']
689 712
 		);
690
-	else
691
-		$txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits']));
713
+	} else {
714
+			$txt['unread_topics_visit_none'] = strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits']));
715
+	}
692 716
 
693 717
 	loadTemplate('Recent');
694 718
 	loadTemplate('MessageIndex');
@@ -696,8 +720,9 @@  discard block
 block discarded – undo
696 720
 
697 721
 	// Setup the default topic icons... for checking they exist and the like ;)
698 722
 	$context['icon_sources'] = array();
699
-	foreach ($context['stable_icons'] as $icon)
700
-		$context['icon_sources'][$icon] = 'images_url';
723
+	foreach ($context['stable_icons'] as $icon) {
724
+			$context['icon_sources'][$icon] = 'images_url';
725
+	}
701 726
 
702 727
 	$is_topics = $_REQUEST['action'] == 'unread';
703 728
 
@@ -727,8 +752,7 @@  discard block
 block discarded – undo
727 752
 			);
728 753
 			list ($earliest_msg) = $smcFunc['db_fetch_row']($request);
729 754
 			$smcFunc['db_free_result']($request);
730
-		}
731
-		else
755
+		} else
732 756
 		{
733 757
 			$request = $smcFunc['db_query']('', '
734 758
 				SELECT MIN(lmr.id_msg)
@@ -744,14 +768,14 @@  discard block
 block discarded – undo
744 768
 		}
745 769
 
746 770
 		// This is needed in case of topics marked unread.
747
-		if (empty($earliest_msg))
748
-			$earliest_msg = 0;
749
-		else
771
+		if (empty($earliest_msg)) {
772
+					$earliest_msg = 0;
773
+		} else
750 774
 		{
751 775
 			// Using caching, when possible, to ignore the below slow query.
752
-			if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time())
753
-				$earliest_msg2 = $_SESSION['cached_log_time'][1];
754
-			else
776
+			if (isset($_SESSION['cached_log_time']) && $_SESSION['cached_log_time'][0] + 45 > time()) {
777
+							$earliest_msg2 = $_SESSION['cached_log_time'][1];
778
+			} else
755 779
 			{
756 780
 				// This query is pretty slow, but it's needed to ensure nothing crucial is ignored.
757 781
 				$request = $smcFunc['db_query']('', '
@@ -766,8 +790,9 @@  discard block
 block discarded – undo
766 790
 				$smcFunc['db_free_result']($request);
767 791
 
768 792
 				// In theory this could be zero, if the first ever post is unread, so fudge it ;)
769
-				if ($earliest_msg2 == 0)
770
-					$earliest_msg2 = -1;
793
+				if ($earliest_msg2 == 0) {
794
+									$earliest_msg2 = -1;
795
+				}
771 796
 
772 797
 				$_SESSION['cached_log_time'] = array(time(), $earliest_msg2);
773 798
 			}
@@ -805,9 +830,9 @@  discard block
 block discarded – undo
805 830
 				'db_error_skip' => true,
806 831
 			))
807 832
 		) !== false;
833
+	} else {
834
+			$have_temp_table = false;
808 835
 	}
809
-	else
810
-		$have_temp_table = false;
811 836
 
812 837
 	if ($context['showing_all_topics'] && $have_temp_table)
813 838
 	{
@@ -853,14 +878,15 @@  discard block
 block discarded – undo
853 878
 
854 879
 			$context['topics'] = array();
855 880
 			$context['no_topic_listing'] = true;
856
-			if ($context['querystring_board_limits'] == ';start=%1$d')
857
-				$context['querystring_board_limits'] = '';
858
-			else
859
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
881
+			if ($context['querystring_board_limits'] == ';start=%1$d') {
882
+							$context['querystring_board_limits'] = '';
883
+			} else {
884
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
885
+			}
860 886
 			return;
887
+		} else {
888
+					$min_message = (int) $min_message;
861 889
 		}
862
-		else
863
-			$min_message = (int) $min_message;
864 890
 
865 891
 		$request = $smcFunc['db_query']('substring', '
866 892
 			SELECT ' . $select_clause . '
@@ -889,8 +915,7 @@  discard block
 block discarded – undo
889 915
 				'limit' => $context['topics_per_page'],
890 916
 			))
891 917
 		);
892
-	}
893
-	elseif ($is_topics)
918
+	} elseif ($is_topics)
894 919
 	{
895 920
 		$request = $smcFunc['db_query']('', '
896 921
 			SELECT COUNT(*), MIN(t.id_last_msg)
@@ -941,14 +966,15 @@  discard block
 block discarded – undo
941 966
 
942 967
 			$context['topics'] = array();
943 968
 			$context['no_topic_listing'] = true;
944
-			if ($context['querystring_board_limits'] == ';start=%d')
945
-				$context['querystring_board_limits'] = '';
946
-			else
947
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
969
+			if ($context['querystring_board_limits'] == ';start=%d') {
970
+							$context['querystring_board_limits'] = '';
971
+			} else {
972
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
973
+			}
948 974
 			return;
975
+		} else {
976
+					$min_message = (int) $min_message;
949 977
 		}
950
-		else
951
-			$min_message = (int) $min_message;
952 978
 
953 979
 		$request = $smcFunc['db_query']('substring', '
954 980
 			SELECT ' . $select_clause . '
@@ -978,8 +1004,7 @@  discard block
 block discarded – undo
978 1004
 				'limit' => $context['topics_per_page'],
979 1005
 			))
980 1006
 		);
981
-	}
982
-	else
1007
+	} else
983 1008
 	{
984 1009
 		if ($modSettings['totalMessages'] > 100000)
985 1010
 		{
@@ -1031,8 +1056,8 @@  discard block
 block discarded – undo
1031 1056
 			) !== false;
1032 1057
 
1033 1058
 			// If that worked, create a sample of the log_topics table too.
1034
-			if ($have_temp_table)
1035
-				$have_temp_table = $smcFunc['db_query']('', '
1059
+			if ($have_temp_table) {
1060
+							$have_temp_table = $smcFunc['db_query']('', '
1036 1061
 					CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in (
1037 1062
 						PRIMARY KEY (id_topic)
1038 1063
 					)
@@ -1045,6 +1070,7 @@  discard block
 block discarded – undo
1045 1070
 						'db_error_skip' => true,
1046 1071
 					)
1047 1072
 				) !== false;
1073
+			}
1048 1074
 		}
1049 1075
 
1050 1076
 		if (!empty($have_temp_table))
@@ -1060,8 +1086,7 @@  discard block
 block discarded – undo
1060 1086
 			);
1061 1087
 			list ($num_topics) = $smcFunc['db_fetch_row']($request);
1062 1088
 			$smcFunc['db_free_result']($request);
1063
-		}
1064
-		else
1089
+		} else
1065 1090
 		{
1066 1091
 			$request = $smcFunc['db_query']('unread_fetch_topic_count', '
1067 1092
 				SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg)
@@ -1102,15 +1127,16 @@  discard block
 block discarded – undo
1102 1127
 		{
1103 1128
 			$context['topics'] = array();
1104 1129
 			$context['no_topic_listing'] = true;
1105
-			if ($context['querystring_board_limits'] == ';start=%d')
1106
-				$context['querystring_board_limits'] = '';
1107
-			else
1108
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1130
+			if ($context['querystring_board_limits'] == ';start=%d') {
1131
+							$context['querystring_board_limits'] = '';
1132
+			} else {
1133
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1134
+			}
1109 1135
 			return;
1110 1136
 		}
1111 1137
 
1112
-		if (!empty($have_temp_table))
1113
-			$request = $smcFunc['db_query']('', '
1138
+		if (!empty($have_temp_table)) {
1139
+					$request = $smcFunc['db_query']('', '
1114 1140
 				SELECT t.id_topic
1115 1141
 				FROM {db_prefix}topics_posted_in AS t
1116 1142
 					LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic)
@@ -1124,8 +1150,8 @@  discard block
 block discarded – undo
1124 1150
 					'limit' => $context['topics_per_page'],
1125 1151
 				))
1126 1152
 			);
1127
-		else
1128
-			$request = $smcFunc['db_query']('', '
1153
+		} else {
1154
+					$request = $smcFunc['db_query']('', '
1129 1155
 				SELECT DISTINCT t.id_topic,'.$_REQUEST['sort'].'
1130 1156
 				FROM {db_prefix}topics AS t
1131 1157
 					INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : '
@@ -1149,10 +1175,12 @@  discard block
 block discarded – undo
1149 1175
 					'sort' => $_REQUEST['sort'],
1150 1176
 				))
1151 1177
 			);
1178
+		}
1152 1179
 
1153 1180
 		$topics = array();
1154
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1155
-			$topics[] = $row['id_topic'];
1181
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1182
+					$topics[] = $row['id_topic'];
1183
+		}
1156 1184
 		$smcFunc['db_free_result']($request);
1157 1185
 
1158 1186
 		// Sanity... where have you gone?
@@ -1160,10 +1188,11 @@  discard block
 block discarded – undo
1160 1188
 		{
1161 1189
 			$context['topics'] = array();
1162 1190
 			$context['no_topic_listing'] = true;
1163
-			if ($context['querystring_board_limits'] == ';start=%d')
1164
-				$context['querystring_board_limits'] = '';
1165
-			else
1166
-				$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1191
+			if ($context['querystring_board_limits'] == ';start=%d') {
1192
+							$context['querystring_board_limits'] = '';
1193
+			} else {
1194
+							$context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
1195
+			}
1167 1196
 			return;
1168 1197
 		}
1169 1198
 
@@ -1197,8 +1226,9 @@  discard block
 block discarded – undo
1197 1226
 
1198 1227
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1199 1228
 	{
1200
-		if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
1201
-			continue;
1229
+		if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') {
1230
+					continue;
1231
+		}
1202 1232
 
1203 1233
 		$topic_ids[] = $row['id_topic'];
1204 1234
 
@@ -1206,11 +1236,13 @@  discard block
 block discarded – undo
1206 1236
 		{
1207 1237
 			// Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise.
1208 1238
 			$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
1209
-			if ($smcFunc['strlen']($row['first_body']) > 128)
1210
-				$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...';
1239
+			if ($smcFunc['strlen']($row['first_body']) > 128) {
1240
+							$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, 128) . '...';
1241
+			}
1211 1242
 			$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
1212
-			if ($smcFunc['strlen']($row['last_body']) > 128)
1213
-				$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...';
1243
+			if ($smcFunc['strlen']($row['last_body']) > 128) {
1244
+							$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, 128) . '...';
1245
+			}
1214 1246
 
1215 1247
 			// Censor the subject and message preview.
1216 1248
 			censorText($row['first_subject']);
@@ -1221,23 +1253,22 @@  discard block
 block discarded – undo
1221 1253
 			{
1222 1254
 				$row['last_subject'] = $row['first_subject'];
1223 1255
 				$row['last_body'] = $row['first_body'];
1224
-			}
1225
-			else
1256
+			} else
1226 1257
 			{
1227 1258
 				censorText($row['last_subject']);
1228 1259
 				censorText($row['last_body']);
1229 1260
 			}
1230
-		}
1231
-		else
1261
+		} else
1232 1262
 		{
1233 1263
 			$row['first_body'] = '';
1234 1264
 			$row['last_body'] = '';
1235 1265
 			censorText($row['first_subject']);
1236 1266
 
1237
-			if ($row['id_first_msg'] == $row['id_last_msg'])
1238
-				$row['last_subject'] = $row['first_subject'];
1239
-			else
1240
-				censorText($row['last_subject']);
1267
+			if ($row['id_first_msg'] == $row['id_last_msg']) {
1268
+							$row['last_subject'] = $row['first_subject'];
1269
+			} else {
1270
+							censorText($row['last_subject']);
1271
+			}
1241 1272
 		}
1242 1273
 
1243 1274
 		// Decide how many pages the topic should have.
@@ -1249,22 +1280,24 @@  discard block
 block discarded – undo
1249 1280
 			$pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $topic_length, $messages_per_page, true, false);
1250 1281
 
1251 1282
 			// If we can use all, show all.
1252
-			if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages'])
1253
-				$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
1283
+			if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']) {
1284
+							$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
1285
+			}
1286
+		} else {
1287
+					$pages = '';
1254 1288
 		}
1255 1289
 
1256
-		else
1257
-			$pages = '';
1258
-
1259 1290
 		// We need to check the topic icons exist... you can never be too sure!
1260 1291
 		if (!empty($modSettings['messageIconChecks_enable']))
1261 1292
 		{
1262 1293
 			// First icon first... as you'd expect.
1263
-			if (!isset($context['icon_sources'][$row['first_icon']]))
1264
-				$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1294
+			if (!isset($context['icon_sources'][$row['first_icon']])) {
1295
+							$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1296
+			}
1265 1297
 			// Last icon... last... duh.
1266
-			if (!isset($context['icon_sources'][$row['last_icon']]))
1267
-				$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1298
+			if (!isset($context['icon_sources'][$row['last_icon']])) {
1299
+							$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1300
+			}
1268 1301
 		}
1269 1302
 
1270 1303
 		// Force the recycling icon if appropriate
@@ -1278,12 +1311,14 @@  discard block
 block discarded – undo
1278 1311
 		$colorClass = 'windowbg';
1279 1312
 
1280 1313
 		// Sticky topics should get a different color, too.
1281
-		if ($row['is_sticky'])
1282
-			$colorClass .= ' sticky';
1314
+		if ($row['is_sticky']) {
1315
+					$colorClass .= ' sticky';
1316
+		}
1283 1317
 
1284 1318
 		// Locked topics get special treatment as well.
1285
-		if ($row['locked'])
1286
-			$colorClass .= ' locked';
1319
+		if ($row['locked']) {
1320
+					$colorClass .= ' locked';
1321
+		}
1287 1322
 
1288 1323
 		// And build the array.
1289 1324
 		$context['topics'][$row['id_topic']] = array(
@@ -1380,8 +1415,9 @@  discard block
 block discarded – undo
1380 1415
 		);
1381 1416
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1382 1417
 		{
1383
-			if (empty($context['topics'][$row['id_topic']]['is_posted_in']))
1384
-				$context['topics'][$row['id_topic']]['is_posted_in'] = true;
1418
+			if (empty($context['topics'][$row['id_topic']]['is_posted_in'])) {
1419
+							$context['topics'][$row['id_topic']]['is_posted_in'] = true;
1420
+			}
1385 1421
 		}
1386 1422
 		$smcFunc['db_free_result']($result);
1387 1423
 	}
@@ -1396,28 +1432,30 @@  discard block
 block discarded – undo
1396 1432
 			'markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'custom' => 'data-confirm="'.  $txt['are_sure_mark_read'] .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']),
1397 1433
 		);
1398 1434
 
1399
-		if ($context['showCheckboxes'])
1400
-			$context['recent_buttons']['markselectread'] = array(
1435
+		if ($context['showCheckboxes']) {
1436
+					$context['recent_buttons']['markselectread'] = array(
1401 1437
 				'text' => 'quick_mod_markread',
1402 1438
 				'image' => 'markselectedread.png',
1403 1439
 				'url' => 'javascript:document.quickModForm.submit();',
1404 1440
 			);
1441
+		}
1405 1442
 
1406
-		if (!empty($context['topics']) && !$context['showing_all_topics'])
1407
-			$context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true);
1408
-	}
1409
-	elseif (!$is_topics && isset($context['topics_to_mark']))
1443
+		if (!empty($context['topics']) && !$context['showing_all_topics']) {
1444
+					$context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true);
1445
+		}
1446
+	} elseif (!$is_topics && isset($context['topics_to_mark']))
1410 1447
 	{
1411 1448
 		$context['recent_buttons'] = array(
1412 1449
 			'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="'. $txt['are_sure_mark_read']  .'"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']),
1413 1450
 		);
1414 1451
 
1415
-		if ($context['showCheckboxes'])
1416
-			$context['recent_buttons']['markselectread'] = array(
1452
+		if ($context['showCheckboxes']) {
1453
+					$context['recent_buttons']['markselectread'] = array(
1417 1454
 				'text' => 'quick_mod_markread',
1418 1455
 				'image' => 'markselectedread.png',
1419 1456
 				'url' => 'javascript:document.quickModForm.submit();',
1420 1457
 			);
1458
+		}
1421 1459
 	}
1422 1460
 
1423 1461
 	// Allow mods to add additional buttons here
Please login to merge, or discard this patch.
Themes/default/GenericControls.template.php 1 patch
Braces   +74 added lines, -54 removed lines patch added patch discarded remove patch
@@ -23,11 +23,13 @@  discard block
 block discarded – undo
23 23
 
24 24
 	$editor_context = &$context['controls']['richedit'][$editor_id];
25 25
 
26
-	if ($smileyContainer === null)
27
-		$editor_context['sce_options']['emoticonsEnabled'] = false;
26
+	if ($smileyContainer === null) {
27
+			$editor_context['sce_options']['emoticonsEnabled'] = false;
28
+	}
28 29
 
29
-	if ($bbcContainer === null)
30
-		$editor_context['sce_options']['toolbar'] = '';
30
+	if ($bbcContainer === null) {
31
+			$editor_context['sce_options']['toolbar'] = '';
32
+	}
31 33
 
32 34
 	echo '
33 35
 		<textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" cols="600" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="', $context['tabindex']++, '" style="width: ', $editor_context['width'], '; height: ', $editor_context['height'], ';', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? 'border: 1px solid red;' : '', '"', !empty($context['editor']['required']) ? ' required' : '', '>', $editor_context['value'], '</textarea>
@@ -40,18 +42,21 @@  discard block
 block discarded – undo
40 42
 				var textarea = $("#', $editor_id, '").get(0);
41 43
 				sceditor.create(textarea, ', $smcFunc['json_encode']($editor_context['sce_options'], JSON_PRETTY_PRINT), ');';
42 44
 
43
-	if ($editor_context['sce_options']['emoticonsEnabled'])
44
-		echo '
45
+	if ($editor_context['sce_options']['emoticonsEnabled']) {
46
+			echo '
45 47
 				sceditor.instance(textarea).createPermanentDropDown();';
48
+	}
46 49
 
47
-	if (empty($editor_context['rich_active']))
48
-		echo '
50
+	if (empty($editor_context['rich_active'])) {
51
+			echo '
49 52
 				sceditor.instance(textarea).toggleSourceMode();';
53
+	}
50 54
 
51
-	if (isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']))
52
-		echo '
55
+	if (isset($context['post_error']['no_message']) || isset($context['post_error']['long_message'])) {
56
+			echo '
53 57
 				$(".sceditor-container").find("textarea").each(function() {$(this).css({border: "1px solid red"})});
54 58
 				$(".sceditor-container").find("iframe").each(function() {$(this).css({border: "1px solid red"})});';
59
+	}
55 60
 
56 61
 	echo '
57 62
 			});';
@@ -88,42 +93,47 @@  discard block
 block discarded – undo
88 93
 
89 94
 	$tempTab = $context['tabindex'];
90 95
 
91
-	if (!empty($context['drafts_pm_save']))
92
-		$tempTab++;
93
-	elseif (!empty($context['drafts_save']))
94
-		$tempTab++;
95
-	elseif ($editor_context['preview_type'])
96
-		$tempTab++;
97
-	elseif ($context['show_spellchecking'])
98
-		$tempTab++;
96
+	if (!empty($context['drafts_pm_save'])) {
97
+			$tempTab++;
98
+	} elseif (!empty($context['drafts_save'])) {
99
+			$tempTab++;
100
+	} elseif ($editor_context['preview_type']) {
101
+			$tempTab++;
102
+	} elseif ($context['show_spellchecking']) {
103
+			$tempTab++;
104
+	}
99 105
 
100 106
 	$tempTab++;
101 107
 	$context['tabindex'] = $tempTab;
102 108
 
103
-	if (!empty($context['drafts_pm_save']))
104
-		echo '
109
+	if (!empty($context['drafts_pm_save'])) {
110
+			echo '
105 111
 		<input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="submitThisOnce(this);" accesskey="d" class="button">
106 112
 		<input type="hidden" id="id_pm_draft" name="id_pm_draft" value="', empty($context['id_pm_draft']) ? 0 : $context['id_pm_draft'], '">';
113
+	}
107 114
 
108
-	if (!empty($context['drafts_save']))
109
-		echo '
115
+	if (!empty($context['drafts_save'])) {
116
+			echo '
110 117
 		<input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="return confirm(' . JavaScriptEscape($txt['draft_save_note']) . ') && submitThisOnce(this);" accesskey="d" class="button">
111 118
 		<input type="hidden" id="id_draft" name="id_draft" value="', empty($context['id_draft']) ? 0 : $context['id_draft'], '">';
119
+	}
112 120
 
113
-	if ($context['show_spellchecking'])
114
-		echo '
121
+	if ($context['show_spellchecking']) {
122
+			echo '
115 123
 		<input type="button" value="', $txt['spell_check'], '" tabindex="', --$tempTab, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button">';
124
+	}
116 125
 
117
-	if ($editor_context['preview_type'])
118
-		echo '
126
+	if ($editor_context['preview_type']) {
127
+			echo '
119 128
 		<input type="submit" name="preview" value="', isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $txt['preview'], '" tabindex="', --$tempTab, '" onclick="', $editor_context['preview_type'] == 2 ? 'return event.ctrlKey || previewPost();' : 'return submitThisOnce(this);', '" accesskey="p" class="button">';
129
+	}
120 130
 
121 131
 	echo '
122 132
 		<input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['post'], '" name="post" tabindex="', --$tempTab, '" onclick="return submitThisOnce(this);" accesskey="s" class="button">';
123 133
 
124 134
 	// Load in the PM autosaver if it's enabled
125
-	if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave']))
126
-		echo '
135
+	if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave'])) {
136
+			echo '
127 137
 		<span class="righttext padding" style="display: block">
128 138
 			<span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon"></span>
129 139
 			<span id="draft_lastautosave" ></span>
@@ -141,10 +151,11 @@  discard block
 block discarded – undo
141 151
 				iFreq: ', (empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000), '
142 152
 			});
143 153
 		</script>';
154
+	}
144 155
 
145 156
 	// Start an instance of the auto saver if its enabled
146
-	if (!empty($context['drafts_save']) && !empty($context['drafts_autosave']))
147
-		echo '
157
+	if (!empty($context['drafts_save']) && !empty($context['drafts_autosave'])) {
158
+			echo '
148 159
 		<span class="righttext padding" style="display: block">
149 160
 			<span id="throbber" style="display:none"><img src="', $settings['images_url'], '/loading_sm.gif" alt="" class="centericon"></span>
150 161
 			<span id="draft_lastautosave" ></span>
@@ -161,7 +172,8 @@  discard block
 block discarded – undo
161 172
 				iFreq: ', $context['drafts_autosave_frequency'], '
162 173
 			});
163 174
 		</script>';
164
-}
175
+	}
176
+	}
165 177
 
166 178
 /**
167 179
  * This template displays a verification form
@@ -178,51 +190,57 @@  discard block
 block discarded – undo
178 190
 	$verify_context = &$context['controls']['verification'][$verify_id];
179 191
 
180 192
 	// Keep track of where we are.
181
-	if (empty($verify_context['tracking']) || $reset)
182
-		$verify_context['tracking'] = 0;
193
+	if (empty($verify_context['tracking']) || $reset) {
194
+			$verify_context['tracking'] = 0;
195
+	}
183 196
 
184 197
 	// How many items are there to display in total.
185 198
 	$total_items = count($verify_context['questions']) + ($verify_context['show_visual'] || $verify_context['can_recaptcha'] ? 1 : 0);
186 199
 
187 200
 	// If we've gone too far, stop.
188
-	if ($verify_context['tracking'] > $total_items)
189
-		return false;
201
+	if ($verify_context['tracking'] > $total_items) {
202
+			return false;
203
+	}
190 204
 
191 205
 	// Loop through each item to show them.
192 206
 	for ($i = 0; $i < $total_items; $i++)
193 207
 	{
194 208
 		// If we're after a single item only show it if we're in the right place.
195
-		if ($display_type == 'single' && $verify_context['tracking'] != $i)
196
-			continue;
209
+		if ($display_type == 'single' && $verify_context['tracking'] != $i) {
210
+					continue;
211
+		}
197 212
 
198
-		if ($display_type != 'single')
199
-			echo '
213
+		if ($display_type != 'single') {
214
+					echo '
200 215
 			<div id="verification_control_', $i, '" class="verification_control">';
216
+		}
201 217
 
202 218
 		// Display empty field, but only if we have one, and it's the first time.
203
-		if ($verify_context['empty_field'] && empty($i))
204
-			echo '
219
+		if ($verify_context['empty_field'] && empty($i)) {
220
+					echo '
205 221
 				<div class="smalltext vv_special">
206 222
 					', $txt['visual_verification_hidden'], ':
207 223
 					<input type="text" name="', $_SESSION[$verify_id . '_vv']['empty_field'], '" autocomplete="off" size="30" value="">
208 224
 				</div>';
225
+		}
209 226
 
210 227
 		// Do the actual stuff
211 228
 		if ($i == 0 && ($verify_context['show_visual'] || $verify_context['can_recaptcha']))
212 229
 		{
213 230
 			if ($verify_context['show_visual'])
214 231
 			{
215
-				if ($context['use_graphic_library'])
216
-					echo '
232
+				if ($context['use_graphic_library']) {
233
+									echo '
217 234
 				<img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '">';
218
-				else
219
-					echo '
235
+				} else {
236
+									echo '
220 237
 				<img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1">
221 238
 				<img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2">
222 239
 				<img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3">
223 240
 				<img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4">
224 241
 				<img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5">
225 242
 				<img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6">';
243
+				}
226 244
 
227 245
 				echo '
228 246
 				<div class="smalltext" style="margin: 4px 0 8px 0;">
@@ -240,8 +258,7 @@  discard block
 block discarded – undo
240 258
 				<br>
241 259
 				<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl='.$lang.'"></script>';
242 260
 			}
243
-		}
244
-		else
261
+		} else
245 262
 		{
246 263
 			// Where in the question array is this question?
247 264
 			$qIndex = $verify_context['show_visual'] ? $i - 1 : $i;
@@ -253,21 +270,24 @@  discard block
 block discarded – undo
253 270
 				</div>';
254 271
 		}
255 272
 
256
-		if ($display_type != 'single')
257
-			echo '
273
+		if ($display_type != 'single') {
274
+					echo '
258 275
 			</div><!-- #verification_control_[i] -->';
276
+		}
259 277
 
260 278
 		// If we were displaying just one and we did it, break.
261
-		if ($display_type == 'single' && $verify_context['tracking'] == $i)
262
-			break;
279
+		if ($display_type == 'single' && $verify_context['tracking'] == $i) {
280
+					break;
281
+		}
263 282
 	}
264 283
 
265 284
 	// Assume we found something, always.
266 285
 	$verify_context['tracking']++;
267 286
 
268 287
 	// Tell something displaying piecemeal to keep going.
269
-	if ($display_type == 'single')
270
-		return true;
271
-}
288
+	if ($display_type == 'single') {
289
+			return true;
290
+	}
291
+	}
272 292
 
273 293
 ?>
274 294
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1460 added lines, -1083 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];
@@ -747,17 +777,20 @@  discard block
 block discarded – undo
747 777
 	$user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M');
748 778
 
749 779
 	// Offset the time.
750
-	if (!$offset_type)
751
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
780
+	if (!$offset_type) {
781
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
782
+	}
752 783
 	// Just the forum offset?
753
-	elseif ($offset_type == 'forum')
754
-		$time = $log_time + $modSettings['time_offset'] * 3600;
755
-	else
756
-		$time = $log_time;
784
+	elseif ($offset_type == 'forum') {
785
+			$time = $log_time + $modSettings['time_offset'] * 3600;
786
+	} else {
787
+			$time = $log_time;
788
+	}
757 789
 
758 790
 	// We can't have a negative date (on Windows, at least.)
759
-	if ($log_time < 0)
760
-		$log_time = 0;
791
+	if ($log_time < 0) {
792
+			$log_time = 0;
793
+	}
761 794
 
762 795
 	// Today and Yesterday?
763 796
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -774,24 +807,27 @@  discard block
 block discarded – undo
774 807
 		{
775 808
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
776 809
 			$today_fmt = $h . ':%M' . $s . ' %p';
810
+		} else {
811
+					$today_fmt = '%H:%M' . $s;
777 812
 		}
778
-		else
779
-			$today_fmt = '%H:%M' . $s;
780 813
 
781 814
 		// Same day of the year, same year.... Today!
782
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
783
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
815
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
816
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
817
+		}
784 818
 
785 819
 		// 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...
786
-		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))
787
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
820
+		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)) {
821
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
822
+		}
788 823
 	}
789 824
 
790 825
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
791 826
 
792 827
 	// Use the cached formats if available
793
-	if (is_null($finalizedFormats))
794
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
828
+	if (is_null($finalizedFormats)) {
829
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
830
+	}
795 831
 
796 832
 	// Make a supported version for this format if we don't already have one
797 833
 	if (empty($finalizedFormats[$str]))
@@ -820,8 +856,9 @@  discard block
 block discarded – undo
820 856
 		);
821 857
 
822 858
 		// No need to do this part again if we already did it once
823
-		if (is_null($unsupportedFormats))
824
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
859
+		if (is_null($unsupportedFormats)) {
860
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
861
+		}
825 862
 		if (empty($unsupportedFormats))
826 863
 		{
827 864
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -837,20 +874,23 @@  discard block
 block discarded – undo
837 874
 
838 875
 				// Windows will return false for unsupported formats
839 876
 				// Other operating systems return the format string as a literal
840
-				if ($value === false || $value === $format)
841
-					$unsupportedFormats[] = $format;
877
+				if ($value === false || $value === $format) {
878
+									$unsupportedFormats[] = $format;
879
+				}
842 880
 			}
843 881
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
844 882
 		}
845 883
 
846 884
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
847
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
848
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
885
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
886
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
887
+		}
849 888
 
850 889
 		// Substitute unsupported formats with supported ones
851
-		if (!empty($unsupportedFormats))
852
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
890
+		if (!empty($unsupportedFormats)) {
891
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
853 892
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
893
+		}
854 894
 
855 895
 		// Remember this so we don't need to do it again
856 896
 		$finalizedFormats[$str] = $timeformat;
@@ -859,33 +899,39 @@  discard block
 block discarded – undo
859 899
 
860 900
 	$str = $finalizedFormats[$str];
861 901
 
862
-	if (!isset($locale_cache))
863
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
902
+	if (!isset($locale_cache)) {
903
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
904
+	}
864 905
 
865 906
 	if ($locale_cache !== false)
866 907
 	{
867 908
 		// Check if another process changed the locale
868
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
869
-			setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
909
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
910
+					setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
911
+		}
870 912
 
871
-		if (!isset($non_twelve_hour))
872
-			$non_twelve_hour = trim(strftime('%p')) === '';
873
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
874
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
913
+		if (!isset($non_twelve_hour)) {
914
+					$non_twelve_hour = trim(strftime('%p')) === '';
915
+		}
916
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
917
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
918
+		}
875 919
 
876
-		foreach (array('%a', '%A', '%b', '%B') as $token)
877
-			if (strpos($str, $token) !== false)
920
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
921
+					if (strpos($str, $token) !== false)
878 922
 				$str = str_replace($token, strftime($token, $time), $str);
879
-	}
880
-	else
923
+		}
924
+	} else
881 925
 	{
882 926
 		// Do-it-yourself time localization.  Fun.
883
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
884
-			if (strpos($str, $token) !== false)
927
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
928
+					if (strpos($str, $token) !== false)
885 929
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
930
+		}
886 931
 
887
-		if (strpos($str, '%p') !== false)
888
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
932
+		if (strpos($str, '%p') !== false) {
933
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
934
+		}
889 935
 	}
890 936
 
891 937
 	// Format the time and then restore any literal percent characters
@@ -908,16 +954,19 @@  discard block
 block discarded – undo
908 954
 	static $translation = array();
909 955
 
910 956
 	// Determine the character set... Default to UTF-8
911
-	if (empty($context['character_set']))
912
-		$charset = 'UTF-8';
957
+	if (empty($context['character_set'])) {
958
+			$charset = 'UTF-8';
959
+	}
913 960
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
914
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
915
-		$charset = 'ISO-8859-1';
916
-	else
917
-		$charset = $context['character_set'];
961
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
962
+			$charset = 'ISO-8859-1';
963
+	} else {
964
+			$charset = $context['character_set'];
965
+	}
918 966
 
919
-	if (empty($translation))
920
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
967
+	if (empty($translation)) {
968
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
969
+	}
921 970
 
922 971
 	return strtr($string, $translation);
923 972
 }
@@ -939,8 +988,9 @@  discard block
 block discarded – undo
939 988
 	global $smcFunc;
940 989
 
941 990
 	// It was already short enough!
942
-	if ($smcFunc['strlen']($subject) <= $len)
943
-		return $subject;
991
+	if ($smcFunc['strlen']($subject) <= $len) {
992
+			return $subject;
993
+	}
944 994
 
945 995
 	// Shorten it by the length it was too long, and strip off junk from the end.
946 996
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -959,10 +1009,11 @@  discard block
 block discarded – undo
959 1009
 {
960 1010
 	global $user_info, $modSettings;
961 1011
 
962
-	if ($timestamp === null)
963
-		$timestamp = time();
964
-	elseif ($timestamp == 0)
965
-		return 0;
1012
+	if ($timestamp === null) {
1013
+			$timestamp = time();
1014
+	} elseif ($timestamp == 0) {
1015
+			return 0;
1016
+	}
966 1017
 
967 1018
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
968 1019
 }
@@ -991,8 +1042,9 @@  discard block
 block discarded – undo
991 1042
 		$array[$i] = $array[$j];
992 1043
 		$array[$j] = $temp;
993 1044
 
994
-		for ($i = 1; $p[$i] == 0; $i++)
995
-			$p[$i] = 1;
1045
+		for ($i = 1; $p[$i] == 0; $i++) {
1046
+					$p[$i] = 1;
1047
+		}
996 1048
 
997 1049
 		$orders[] = $array;
998 1050
 	}
@@ -1024,12 +1076,14 @@  discard block
 block discarded – undo
1024 1076
 	static $disabled;
1025 1077
 
1026 1078
 	// Don't waste cycles
1027
-	if ($message === '')
1028
-		return '';
1079
+	if ($message === '') {
1080
+			return '';
1081
+	}
1029 1082
 
1030 1083
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1031
-	if (!isset($context['utf8']))
1032
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1084
+	if (!isset($context['utf8'])) {
1085
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1086
+	}
1033 1087
 
1034 1088
 	// Clean up any cut/paste issues we may have
1035 1089
 	$message = sanitizeMSCutPaste($message);
@@ -1041,13 +1095,15 @@  discard block
 block discarded – undo
1041 1095
 		return $message;
1042 1096
 	}
1043 1097
 
1044
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1045
-		$smileys = (bool) $smileys;
1098
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1099
+			$smileys = (bool) $smileys;
1100
+	}
1046 1101
 
1047 1102
 	if (empty($modSettings['enableBBC']) && $message !== false)
1048 1103
 	{
1049
-		if ($smileys === true)
1050
-			parsesmileys($message);
1104
+		if ($smileys === true) {
1105
+					parsesmileys($message);
1106
+		}
1051 1107
 
1052 1108
 		return $message;
1053 1109
 	}
@@ -1060,8 +1116,9 @@  discard block
 block discarded – undo
1060 1116
 	}
1061 1117
 
1062 1118
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1063
-	if (!empty($modSettings['autoLinkUrls']))
1064
-		set_tld_regex();
1119
+	if (!empty($modSettings['autoLinkUrls'])) {
1120
+			set_tld_regex();
1121
+	}
1065 1122
 
1066 1123
 	// Allow mods access before entering the main parse_bbc loop
1067 1124
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1075,12 +1132,14 @@  discard block
 block discarded – undo
1075 1132
 
1076 1133
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1077 1134
 
1078
-			foreach ($temp as $tag)
1079
-				$disabled[trim($tag)] = true;
1135
+			foreach ($temp as $tag) {
1136
+							$disabled[trim($tag)] = true;
1137
+			}
1080 1138
 		}
1081 1139
 
1082
-		if (empty($modSettings['enableEmbeddedFlash']))
1083
-			$disabled['flash'] = true;
1140
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1141
+					$disabled['flash'] = true;
1142
+		}
1084 1143
 
1085 1144
 		/* The following bbc are formatted as an array, with keys as follows:
1086 1145
 
@@ -1201,8 +1260,9 @@  discard block
 block discarded – undo
1201 1260
 					$returnContext = '';
1202 1261
 
1203 1262
 					// BBC or the entire attachments feature is disabled
1204
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1205
-						return $data;
1263
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1264
+											return $data;
1265
+					}
1206 1266
 
1207 1267
 					// Save the attach ID.
1208 1268
 					$attachID = $data;
@@ -1213,8 +1273,9 @@  discard block
 block discarded – undo
1213 1273
 					$currentAttachment = parseAttachBBC($attachID);
1214 1274
 
1215 1275
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1216
-					if (is_string($currentAttachment))
1217
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1276
+					if (is_string($currentAttachment)) {
1277
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1278
+					}
1218 1279
 
1219 1280
 					if (!empty($currentAttachment['is_image']))
1220 1281
 					{
@@ -1230,15 +1291,17 @@  discard block
 block discarded – undo
1230 1291
 							$height = ' height="' . $currentAttachment['height'] . '"';
1231 1292
 						}
1232 1293
 
1233
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1234
-							$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>';
1235
-						else
1236
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1294
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1295
+													$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>';
1296
+						} else {
1297
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1298
+						}
1237 1299
 					}
1238 1300
 
1239 1301
 					// No image. Show a link.
1240
-					else
1241
-						$returnContext .= $currentAttachment['link'];
1302
+					else {
1303
+											$returnContext .= $currentAttachment['link'];
1304
+					}
1242 1305
 
1243 1306
 					// Gotta append what we just did.
1244 1307
 					$data = $returnContext;
@@ -1269,8 +1332,9 @@  discard block
 block discarded – undo
1269 1332
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1270 1333
 						{
1271 1334
 							// Do PHP code coloring?
1272
-							if ($php_parts[$php_i] != '&lt;?php')
1273
-								continue;
1335
+							if ($php_parts[$php_i] != '&lt;?php') {
1336
+															continue;
1337
+							}
1274 1338
 
1275 1339
 							$php_string = '';
1276 1340
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1286,8 +1350,9 @@  discard block
 block discarded – undo
1286 1350
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1287 1351
 
1288 1352
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1289
-						if ($context['browser']['is_opera'])
1290
-							$data .= '&nbsp;';
1353
+						if ($context['browser']['is_opera']) {
1354
+													$data .= '&nbsp;';
1355
+						}
1291 1356
 					}
1292 1357
 				},
1293 1358
 				'block_level' => true,
@@ -1306,8 +1371,9 @@  discard block
 block discarded – undo
1306 1371
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1307 1372
 						{
1308 1373
 							// Do PHP code coloring?
1309
-							if ($php_parts[$php_i] != '&lt;?php')
1310
-								continue;
1374
+							if ($php_parts[$php_i] != '&lt;?php') {
1375
+															continue;
1376
+							}
1311 1377
 
1312 1378
 							$php_string = '';
1313 1379
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1323,8 +1389,9 @@  discard block
 block discarded – undo
1323 1389
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1324 1390
 
1325 1391
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1326
-						if ($context['browser']['is_opera'])
1327
-							$data[0] .= '&nbsp;';
1392
+						if ($context['browser']['is_opera']) {
1393
+													$data[0] .= '&nbsp;';
1394
+						}
1328 1395
 					}
1329 1396
 				},
1330 1397
 				'block_level' => true,
@@ -1362,11 +1429,13 @@  discard block
 block discarded – undo
1362 1429
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1363 1430
 				'validate' => function (&$tag, &$data, $disabled)
1364 1431
 				{
1365
-					if (isset($disabled['url']))
1366
-						$tag['content'] = '$1';
1432
+					if (isset($disabled['url'])) {
1433
+											$tag['content'] = '$1';
1434
+					}
1367 1435
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1368
-					if (empty($scheme))
1369
-						$data[0] = '//' . ltrim($data[0], ':/');
1436
+					if (empty($scheme)) {
1437
+											$data[0] = '//' . ltrim($data[0], ':/');
1438
+					}
1370 1439
 				},
1371 1440
 				'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>',
1372 1441
 			),
@@ -1380,10 +1449,11 @@  discard block
 block discarded – undo
1380 1449
 				{
1381 1450
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1382 1451
 
1383
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1384
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1385
-					else
1386
-						$css = '';
1452
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1453
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1454
+					} else {
1455
+											$css = '';
1456
+					}
1387 1457
 
1388 1458
 					$data = $class . $css;
1389 1459
 				},
@@ -1433,17 +1503,20 @@  discard block
 block discarded – undo
1433 1503
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1434 1504
 					if ($image_proxy_enabled)
1435 1505
 					{
1436
-						if (!empty($user_info['possibly_robot']))
1437
-							return;
1506
+						if (!empty($user_info['possibly_robot'])) {
1507
+													return;
1508
+						}
1438 1509
 
1439
-						if (empty($scheme))
1440
-							$data = 'http://' . ltrim($data, ':/');
1510
+						if (empty($scheme)) {
1511
+													$data = 'http://' . ltrim($data, ':/');
1512
+						}
1441 1513
 
1442
-						if ($scheme != 'https')
1443
-							$data = get_proxied_url($data);
1514
+						if ($scheme != 'https') {
1515
+													$data = get_proxied_url($data);
1516
+						}
1517
+					} elseif (empty($scheme)) {
1518
+											$data = '//' . ltrim($data, ':/');
1444 1519
 					}
1445
-					elseif (empty($scheme))
1446
-						$data = '//' . ltrim($data, ':/');
1447 1520
 				},
1448 1521
 				'disabled_content' => '($1)',
1449 1522
 			),
@@ -1459,17 +1532,20 @@  discard block
 block discarded – undo
1459 1532
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1460 1533
 					if ($image_proxy_enabled)
1461 1534
 					{
1462
-						if (!empty($user_info['possibly_robot']))
1463
-							return;
1535
+						if (!empty($user_info['possibly_robot'])) {
1536
+													return;
1537
+						}
1464 1538
 
1465
-						if (empty($scheme))
1466
-							$data = 'http://' . ltrim($data, ':/');
1539
+						if (empty($scheme)) {
1540
+													$data = 'http://' . ltrim($data, ':/');
1541
+						}
1467 1542
 
1468
-						if ($scheme != 'https')
1469
-							$data = get_proxied_url($data);
1543
+						if ($scheme != 'https') {
1544
+													$data = get_proxied_url($data);
1545
+						}
1546
+					} elseif (empty($scheme)) {
1547
+											$data = '//' . ltrim($data, ':/');
1470 1548
 					}
1471
-					elseif (empty($scheme))
1472
-						$data = '//' . ltrim($data, ':/');
1473 1549
 				},
1474 1550
 				'disabled_content' => '($1)',
1475 1551
 			),
@@ -1481,8 +1557,9 @@  discard block
 block discarded – undo
1481 1557
 				{
1482 1558
 					$data = strtr($data, array('<br>' => ''));
1483 1559
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1484
-					if (empty($scheme))
1485
-						$data = '//' . ltrim($data, ':/');
1560
+					if (empty($scheme)) {
1561
+											$data = '//' . ltrim($data, ':/');
1562
+					}
1486 1563
 				},
1487 1564
 			),
1488 1565
 			array(
@@ -1493,13 +1570,14 @@  discard block
 block discarded – undo
1493 1570
 				'after' => '</a>',
1494 1571
 				'validate' => function (&$tag, &$data, $disabled)
1495 1572
 				{
1496
-					if (substr($data, 0, 1) == '#')
1497
-						$data = '#post_' . substr($data, 1);
1498
-					else
1573
+					if (substr($data, 0, 1) == '#') {
1574
+											$data = '#post_' . substr($data, 1);
1575
+					} else
1499 1576
 					{
1500 1577
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1501
-						if (empty($scheme))
1502
-							$data = '//' . ltrim($data, ':/');
1578
+						if (empty($scheme)) {
1579
+													$data = '//' . ltrim($data, ':/');
1580
+						}
1503 1581
 					}
1504 1582
 				},
1505 1583
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1583,8 +1661,9 @@  discard block
 block discarded – undo
1583 1661
 					{
1584 1662
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1585 1663
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1586
-						if ($add_begin)
1587
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1664
+						if ($add_begin) {
1665
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1666
+						}
1588 1667
 					}
1589 1668
 				},
1590 1669
 				'block_level' => false,
@@ -1715,10 +1794,11 @@  discard block
 block discarded – undo
1715 1794
 				'content' => '$1',
1716 1795
 				'validate' => function (&$tag, &$data, $disabled)
1717 1796
 				{
1718
-					if (is_numeric($data))
1719
-						$data = timeformat($data);
1720
-					else
1721
-						$tag['content'] = '[time]$1[/time]';
1797
+					if (is_numeric($data)) {
1798
+											$data = timeformat($data);
1799
+					} else {
1800
+											$tag['content'] = '[time]$1[/time]';
1801
+					}
1722 1802
 				},
1723 1803
 			),
1724 1804
 			array(
@@ -1745,8 +1825,9 @@  discard block
 block discarded – undo
1745 1825
 				{
1746 1826
 					$data = strtr($data, array('<br>' => ''));
1747 1827
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1748
-					if (empty($scheme))
1749
-						$data = '//' . ltrim($data, ':/');
1828
+					if (empty($scheme)) {
1829
+											$data = '//' . ltrim($data, ':/');
1830
+					}
1750 1831
 				},
1751 1832
 			),
1752 1833
 			array(
@@ -1758,8 +1839,9 @@  discard block
 block discarded – undo
1758 1839
 				'validate' => function (&$tag, &$data, $disabled)
1759 1840
 				{
1760 1841
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1761
-					if (empty($scheme))
1762
-						$data = '//' . ltrim($data, ':/');
1842
+					if (empty($scheme)) {
1843
+											$data = '//' . ltrim($data, ':/');
1844
+					}
1763 1845
 				},
1764 1846
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1765 1847
 				'disabled_after' => ' ($1)',
@@ -1785,8 +1867,9 @@  discard block
 block discarded – undo
1785 1867
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1786 1868
 		if ($message === false)
1787 1869
 		{
1788
-			if (isset($temp_bbc))
1789
-				$bbc_codes = $temp_bbc;
1870
+			if (isset($temp_bbc)) {
1871
+							$bbc_codes = $temp_bbc;
1872
+			}
1790 1873
 			usort($codes, function ($a, $b) {
1791 1874
 				return strcmp($a['tag'], $b['tag']);
1792 1875
 			});
@@ -1806,8 +1889,9 @@  discard block
 block discarded – undo
1806 1889
 		);
1807 1890
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1808 1891
 		{
1809
-			foreach ($itemcodes as $c => $dummy)
1810
-				$bbc_codes[$c] = array();
1892
+			foreach ($itemcodes as $c => $dummy) {
1893
+							$bbc_codes[$c] = array();
1894
+			}
1811 1895
 		}
1812 1896
 
1813 1897
 		// Shhhh!
@@ -1828,12 +1912,14 @@  discard block
 block discarded – undo
1828 1912
 		foreach ($codes as $code)
1829 1913
 		{
1830 1914
 			// Make it easier to process parameters later
1831
-			if (!empty($code['parameters']))
1832
-				ksort($code['parameters'], SORT_STRING);
1915
+			if (!empty($code['parameters'])) {
1916
+							ksort($code['parameters'], SORT_STRING);
1917
+			}
1833 1918
 
1834 1919
 			// If we are not doing every tag only do ones we are interested in.
1835
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1836
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1920
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1921
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1922
+			}
1837 1923
 		}
1838 1924
 		$codes = null;
1839 1925
 	}
@@ -1844,8 +1930,9 @@  discard block
 block discarded – undo
1844 1930
 		// It's likely this will change if the message is modified.
1845 1931
 		$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']);
1846 1932
 
1847
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1848
-			return $temp;
1933
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1934
+					return $temp;
1935
+		}
1849 1936
 
1850 1937
 		$cache_t = microtime();
1851 1938
 	}
@@ -1877,8 +1964,9 @@  discard block
 block discarded – undo
1877 1964
 		$disabled['flash'] = true;
1878 1965
 
1879 1966
 		// @todo Change maybe?
1880
-		if (!isset($_GET['images']))
1881
-			$disabled['img'] = true;
1967
+		if (!isset($_GET['images'])) {
1968
+					$disabled['img'] = true;
1969
+		}
1882 1970
 
1883 1971
 		// @todo Interface/setting to add more?
1884 1972
 	}
@@ -1889,8 +1977,9 @@  discard block
 block discarded – undo
1889 1977
 	$alltags = array();
1890 1978
 	foreach ($bbc_codes as $section)
1891 1979
 	{
1892
-		foreach ($section as $code)
1893
-			$alltags[] = $code['tag'];
1980
+		foreach ($section as $code) {
1981
+					$alltags[] = $code['tag'];
1982
+		}
1894 1983
 	}
1895 1984
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
1896 1985
 
@@ -1902,8 +1991,9 @@  discard block
 block discarded – undo
1902 1991
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1903 1992
 
1904 1993
 		// Failsafe.
1905
-		if ($pos === false || $last_pos > $pos)
1906
-			$pos = strlen($message) + 1;
1994
+		if ($pos === false || $last_pos > $pos) {
1995
+					$pos = strlen($message) + 1;
1996
+		}
1907 1997
 
1908 1998
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1909 1999
 		if ($last_pos < $pos - 1)
@@ -1921,8 +2011,9 @@  discard block
 block discarded – undo
1921 2011
 
1922 2012
 				// <br> should be empty.
1923 2013
 				$empty_tags = array('br', 'hr');
1924
-				foreach ($empty_tags as $tag)
1925
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2014
+				foreach ($empty_tags as $tag) {
2015
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2016
+				}
1926 2017
 
1927 2018
 				// b, u, i, s, pre... basic tags.
1928 2019
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -1931,8 +2022,9 @@  discard block
 block discarded – undo
1931 2022
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1932 2023
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1933 2024
 
1934
-					if ($diff > 0)
1935
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2025
+					if ($diff > 0) {
2026
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2027
+					}
1936 2028
 				}
1937 2029
 
1938 2030
 				// Do <img ...> - with security... action= -> action-.
@@ -1945,8 +2037,9 @@  discard block
 block discarded – undo
1945 2037
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1946 2038
 
1947 2039
 						// Remove action= from the URL - no funny business, now.
1948
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1949
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2040
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2041
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2042
+						}
1950 2043
 
1951 2044
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1952 2045
 					}
@@ -1961,16 +2054,18 @@  discard block
 block discarded – undo
1961 2054
 				$no_autolink_area = false;
1962 2055
 				if (!empty($open_tags))
1963 2056
 				{
1964
-					foreach ($open_tags as $open_tag)
1965
-						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))
1966 2059
 							$no_autolink_area = true;
2060
+					}
1967 2061
 				}
1968 2062
 
1969 2063
 				// Don't go backwards.
1970 2064
 				// @todo Don't think is the real solution....
1971 2065
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1972
-				if ($pos < $lastAutoPos)
1973
-					$no_autolink_area = true;
2066
+				if ($pos < $lastAutoPos) {
2067
+									$no_autolink_area = true;
2068
+				}
1974 2069
 				$lastAutoPos = $pos;
1975 2070
 
1976 2071
 				if (!$no_autolink_area)
@@ -2075,29 +2170,33 @@  discard block
 block discarded – undo
2075 2170
 							$url = array_shift($matches);
2076 2171
 
2077 2172
 							// If this isn't a clean URL, bail out
2078
-							if ($url != sanitize_iri($url))
2079
-								return $url;
2173
+							if ($url != sanitize_iri($url)) {
2174
+															return $url;
2175
+							}
2080 2176
 
2081 2177
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2082 2178
 
2083 2179
 							if ($scheme == 'mailto')
2084 2180
 							{
2085 2181
 								$email_address = str_replace('mailto:', '', $url);
2086
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2087
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2088
-								else
2089
-									return $url;
2182
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2183
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2184
+								} else {
2185
+																	return $url;
2186
+								}
2090 2187
 							}
2091 2188
 
2092 2189
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2093
-							if (empty($scheme))
2094
-								$fullUrl = '//' . ltrim($url, ':/');
2095
-							else
2096
-								$fullUrl = $url;
2190
+							if (empty($scheme)) {
2191
+															$fullUrl = '//' . ltrim($url, ':/');
2192
+							} else {
2193
+															$fullUrl = $url;
2194
+							}
2097 2195
 
2098 2196
 							// Make sure that $fullUrl really is valid
2099
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2100
-								return $url;
2197
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2198
+															return $url;
2199
+							}
2101 2200
 
2102 2201
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2103 2202
 						}, $data);
@@ -2146,22 +2245,25 @@  discard block
 block discarded – undo
2146 2245
 		}
2147 2246
 
2148 2247
 		// Are we there yet?  Are we there yet?
2149
-		if ($pos >= strlen($message) - 1)
2150
-			break;
2248
+		if ($pos >= strlen($message) - 1) {
2249
+					break;
2250
+		}
2151 2251
 
2152 2252
 		$tags = strtolower($message[$pos + 1]);
2153 2253
 
2154 2254
 		if ($tags == '/' && !empty($open_tags))
2155 2255
 		{
2156 2256
 			$pos2 = strpos($message, ']', $pos + 1);
2157
-			if ($pos2 == $pos + 2)
2158
-				continue;
2257
+			if ($pos2 == $pos + 2) {
2258
+							continue;
2259
+			}
2159 2260
 
2160 2261
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2161 2262
 
2162 2263
 			// A closing tag that doesn't match any open tags? Skip it.
2163
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2164
-				continue;
2264
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2265
+							continue;
2266
+			}
2165 2267
 
2166 2268
 			$to_close = array();
2167 2269
 			$block_level = null;
@@ -2169,8 +2271,9 @@  discard block
 block discarded – undo
2169 2271
 			do
2170 2272
 			{
2171 2273
 				$tag = array_pop($open_tags);
2172
-				if (!$tag)
2173
-					break;
2274
+				if (!$tag) {
2275
+									break;
2276
+				}
2174 2277
 
2175 2278
 				if (!empty($tag['block_level']))
2176 2279
 				{
@@ -2184,10 +2287,11 @@  discard block
 block discarded – undo
2184 2287
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2185 2288
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2186 2289
 					{
2187
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2188
-							if ($temp['tag'] == $look_for)
2290
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2291
+													if ($temp['tag'] == $look_for)
2189 2292
 							{
2190 2293
 								$block_level = !empty($temp['block_level']);
2294
+						}
2191 2295
 								break;
2192 2296
 							}
2193 2297
 					}
@@ -2209,15 +2313,15 @@  discard block
 block discarded – undo
2209 2313
 			{
2210 2314
 				$open_tags = $to_close;
2211 2315
 				continue;
2212
-			}
2213
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2316
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2214 2317
 			{
2215 2318
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2216 2319
 				{
2217
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2218
-						if ($temp['tag'] == $look_for)
2320
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2321
+											if ($temp['tag'] == $look_for)
2219 2322
 						{
2220 2323
 							$block_level = !empty($temp['block_level']);
2324
+					}
2221 2325
 							break;
2222 2326
 						}
2223 2327
 				}
@@ -2225,8 +2329,9 @@  discard block
 block discarded – undo
2225 2329
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2226 2330
 				if (!$block_level)
2227 2331
 				{
2228
-					foreach ($to_close as $tag)
2229
-						array_push($open_tags, $tag);
2332
+					foreach ($to_close as $tag) {
2333
+											array_push($open_tags, $tag);
2334
+					}
2230 2335
 					continue;
2231 2336
 				}
2232 2337
 			}
@@ -2239,14 +2344,17 @@  discard block
 block discarded – undo
2239 2344
 
2240 2345
 				// See the comment at the end of the big loop - just eating whitespace ;).
2241 2346
 				$whitespace_regex = '';
2242
-				if (!empty($tag['block_level']))
2243
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2347
+				if (!empty($tag['block_level'])) {
2348
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2349
+				}
2244 2350
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2245
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2246
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2351
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2352
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2353
+				}
2247 2354
 
2248
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2249
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2355
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2356
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2357
+				}
2250 2358
 			}
2251 2359
 
2252 2360
 			if (!empty($to_close))
@@ -2259,8 +2367,9 @@  discard block
 block discarded – undo
2259 2367
 		}
2260 2368
 
2261 2369
 		// No tags for this character, so just keep going (fastest possible course.)
2262
-		if (!isset($bbc_codes[$tags]))
2263
-			continue;
2370
+		if (!isset($bbc_codes[$tags])) {
2371
+					continue;
2372
+		}
2264 2373
 
2265 2374
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2266 2375
 		$tag = null;
@@ -2269,48 +2378,57 @@  discard block
 block discarded – undo
2269 2378
 			$pt_strlen = strlen($possible['tag']);
2270 2379
 
2271 2380
 			// Not a match?
2272
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2273
-				continue;
2381
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2382
+							continue;
2383
+			}
2274 2384
 
2275 2385
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2276 2386
 
2277 2387
 			// A tag is the last char maybe
2278
-			if ($next_c == '')
2279
-				break;
2388
+			if ($next_c == '') {
2389
+							break;
2390
+			}
2280 2391
 
2281 2392
 			// A test validation?
2282
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2283
-				continue;
2393
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2394
+							continue;
2395
+			}
2284 2396
 			// Do we want parameters?
2285 2397
 			elseif (!empty($possible['parameters']))
2286 2398
 			{
2287
-				if ($next_c != ' ')
2288
-					continue;
2289
-			}
2290
-			elseif (isset($possible['type']))
2399
+				if ($next_c != ' ') {
2400
+									continue;
2401
+				}
2402
+			} elseif (isset($possible['type']))
2291 2403
 			{
2292 2404
 				// Do we need an equal sign?
2293
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2294
-					continue;
2405
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2406
+									continue;
2407
+				}
2295 2408
 				// Maybe we just want a /...
2296
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2297
-					continue;
2409
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2410
+									continue;
2411
+				}
2298 2412
 				// An immediate ]?
2299
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2300
-					continue;
2413
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2414
+									continue;
2415
+				}
2301 2416
 			}
2302 2417
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2303
-			elseif ($next_c != ']')
2304
-				continue;
2418
+			elseif ($next_c != ']') {
2419
+							continue;
2420
+			}
2305 2421
 
2306 2422
 			// Check allowed tree?
2307
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2308
-				continue;
2309
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2310
-				continue;
2423
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2424
+							continue;
2425
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2426
+							continue;
2427
+			}
2311 2428
 			// If this is in the list of disallowed child tags, don't parse it.
2312
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2313
-				continue;
2429
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2430
+							continue;
2431
+			}
2314 2432
 
2315 2433
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2316 2434
 
@@ -2322,8 +2440,9 @@  discard block
 block discarded – undo
2322 2440
 				foreach ($open_tags as $open_quote)
2323 2441
 				{
2324 2442
 					// Every parent quote this quote has flips the styling
2325
-					if ($open_quote['tag'] == 'quote')
2326
-						$quote_alt = !$quote_alt;
2443
+					if ($open_quote['tag'] == 'quote') {
2444
+											$quote_alt = !$quote_alt;
2445
+					}
2327 2446
 				}
2328 2447
 				// Add a class to the quote to style alternating blockquotes
2329 2448
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2334,8 +2453,9 @@  discard block
 block discarded – undo
2334 2453
 			{
2335 2454
 				// Build a regular expression for each parameter for the current tag.
2336 2455
 				$preg = array();
2337
-				foreach ($possible['parameters'] as $p => $info)
2338
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2456
+				foreach ($possible['parameters'] as $p => $info) {
2457
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2458
+				}
2339 2459
 
2340 2460
 				// Extract the string that potentially holds our parameters.
2341 2461
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2354,24 +2474,27 @@  discard block
 block discarded – undo
2354 2474
 
2355 2475
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2356 2476
 
2357
-					if ($match)
2358
-						$blob_counter = count($blobs) + 1;
2477
+					if ($match) {
2478
+											$blob_counter = count($blobs) + 1;
2479
+					}
2359 2480
 				}
2360 2481
 
2361 2482
 				// Didn't match our parameter list, try the next possible.
2362
-				if (!$match)
2363
-					continue;
2483
+				if (!$match) {
2484
+									continue;
2485
+				}
2364 2486
 
2365 2487
 				$params = array();
2366 2488
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2367 2489
 				{
2368 2490
 					$key = strtok(ltrim($matches[$i]), '=');
2369
-					if (isset($possible['parameters'][$key]['value']))
2370
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2371
-					elseif (isset($possible['parameters'][$key]['validate']))
2372
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2373
-					else
2374
-						$params['{' . $key . '}'] = $matches[$i + 1];
2491
+					if (isset($possible['parameters'][$key]['value'])) {
2492
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2493
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2494
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2495
+					} else {
2496
+											$params['{' . $key . '}'] = $matches[$i + 1];
2497
+					}
2375 2498
 
2376 2499
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2377 2500
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2379,23 +2502,26 @@  discard block
 block discarded – undo
2379 2502
 
2380 2503
 				foreach ($possible['parameters'] as $p => $info)
2381 2504
 				{
2382
-					if (!isset($params['{' . $p . '}']))
2383
-						$params['{' . $p . '}'] = '';
2505
+					if (!isset($params['{' . $p . '}'])) {
2506
+											$params['{' . $p . '}'] = '';
2507
+					}
2384 2508
 				}
2385 2509
 
2386 2510
 				$tag = $possible;
2387 2511
 
2388 2512
 				// Put the parameters into the string.
2389
-				if (isset($tag['before']))
2390
-					$tag['before'] = strtr($tag['before'], $params);
2391
-				if (isset($tag['after']))
2392
-					$tag['after'] = strtr($tag['after'], $params);
2393
-				if (isset($tag['content']))
2394
-					$tag['content'] = strtr($tag['content'], $params);
2513
+				if (isset($tag['before'])) {
2514
+									$tag['before'] = strtr($tag['before'], $params);
2515
+				}
2516
+				if (isset($tag['after'])) {
2517
+									$tag['after'] = strtr($tag['after'], $params);
2518
+				}
2519
+				if (isset($tag['content'])) {
2520
+									$tag['content'] = strtr($tag['content'], $params);
2521
+				}
2395 2522
 
2396 2523
 				$pos1 += strlen($given_param_string);
2397
-			}
2398
-			else
2524
+			} else
2399 2525
 			{
2400 2526
 				$tag = $possible;
2401 2527
 				$params = array();
@@ -2406,8 +2532,9 @@  discard block
 block discarded – undo
2406 2532
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2407 2533
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2408 2534
 		{
2409
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2410
-				continue;
2535
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2536
+							continue;
2537
+			}
2411 2538
 
2412 2539
 			$tag = $itemcodes[$message[$pos + 1]];
2413 2540
 
@@ -2428,9 +2555,9 @@  discard block
 block discarded – undo
2428 2555
 			{
2429 2556
 				array_pop($open_tags);
2430 2557
 				$code = '</li>';
2558
+			} else {
2559
+							$code = '';
2431 2560
 			}
2432
-			else
2433
-				$code = '';
2434 2561
 
2435 2562
 			// Now we open a new tag.
2436 2563
 			$open_tags[] = array(
@@ -2477,12 +2604,14 @@  discard block
 block discarded – undo
2477 2604
 		}
2478 2605
 
2479 2606
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2480
-		if ($tag === null)
2481
-			continue;
2607
+		if ($tag === null) {
2608
+					continue;
2609
+		}
2482 2610
 
2483 2611
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2484
-		if (isset($inside['disallow_children']))
2485
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2612
+		if (isset($inside['disallow_children'])) {
2613
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2614
+		}
2486 2615
 
2487 2616
 		// Is this tag disabled?
2488 2617
 		if (isset($disabled[$tag['tag']]))
@@ -2492,14 +2621,13 @@  discard block
 block discarded – undo
2492 2621
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2493 2622
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2494 2623
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2495
-			}
2496
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2624
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2497 2625
 			{
2498 2626
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2499 2627
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2628
+			} else {
2629
+							$tag['content'] = $tag['disabled_content'];
2500 2630
 			}
2501
-			else
2502
-				$tag['content'] = $tag['disabled_content'];
2503 2631
 		}
2504 2632
 
2505 2633
 		// we use this a lot
@@ -2509,8 +2637,9 @@  discard block
 block discarded – undo
2509 2637
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2510 2638
 		{
2511 2639
 			$n = count($open_tags) - 1;
2512
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2513
-				$n--;
2640
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2641
+							$n--;
2642
+			}
2514 2643
 
2515 2644
 			// Close all the non block level tags so this tag isn't surrounded by them.
2516 2645
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2522,12 +2651,15 @@  discard block
 block discarded – undo
2522 2651
 
2523 2652
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2524 2653
 				$whitespace_regex = '';
2525
-				if (!empty($tag['block_level']))
2526
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2527
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2528
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2529
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2530
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2654
+				if (!empty($tag['block_level'])) {
2655
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2656
+				}
2657
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2658
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2659
+				}
2660
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2661
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2662
+				}
2531 2663
 
2532 2664
 				array_pop($open_tags);
2533 2665
 			}
@@ -2548,16 +2680,19 @@  discard block
 block discarded – undo
2548 2680
 		elseif ($tag['type'] == 'unparsed_content')
2549 2681
 		{
2550 2682
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2551
-			if ($pos2 === false)
2552
-				continue;
2683
+			if ($pos2 === false) {
2684
+							continue;
2685
+			}
2553 2686
 
2554 2687
 			$data = substr($message, $pos1, $pos2 - $pos1);
2555 2688
 
2556
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2557
-				$data = substr($data, 4);
2689
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2690
+							$data = substr($data, 4);
2691
+			}
2558 2692
 
2559
-			if (isset($tag['validate']))
2560
-				$tag['validate']($tag, $data, $disabled, $params);
2693
+			if (isset($tag['validate'])) {
2694
+							$tag['validate']($tag, $data, $disabled, $params);
2695
+			}
2561 2696
 
2562 2697
 			$code = strtr($tag['content'], array('$1' => $data));
2563 2698
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2572,34 +2707,40 @@  discard block
 block discarded – undo
2572 2707
 			if (isset($tag['quoted']))
2573 2708
 			{
2574 2709
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2575
-				if ($tag['quoted'] != 'optional' && !$quoted)
2576
-					continue;
2710
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2711
+									continue;
2712
+				}
2577 2713
 
2578
-				if ($quoted)
2579
-					$pos1 += 6;
2714
+				if ($quoted) {
2715
+									$pos1 += 6;
2716
+				}
2717
+			} else {
2718
+							$quoted = false;
2580 2719
 			}
2581
-			else
2582
-				$quoted = false;
2583 2720
 
2584 2721
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2585
-			if ($pos2 === false)
2586
-				continue;
2722
+			if ($pos2 === false) {
2723
+							continue;
2724
+			}
2587 2725
 
2588 2726
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2589
-			if ($pos3 === false)
2590
-				continue;
2727
+			if ($pos3 === false) {
2728
+							continue;
2729
+			}
2591 2730
 
2592 2731
 			$data = array(
2593 2732
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2594 2733
 				substr($message, $pos1, $pos2 - $pos1)
2595 2734
 			);
2596 2735
 
2597
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2598
-				$data[0] = substr($data[0], 4);
2736
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2737
+							$data[0] = substr($data[0], 4);
2738
+			}
2599 2739
 
2600 2740
 			// Validation for my parking, please!
2601
-			if (isset($tag['validate']))
2602
-				$tag['validate']($tag, $data, $disabled, $params);
2741
+			if (isset($tag['validate'])) {
2742
+							$tag['validate']($tag, $data, $disabled, $params);
2743
+			}
2603 2744
 
2604 2745
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2605 2746
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2616,23 +2757,27 @@  discard block
 block discarded – undo
2616 2757
 		elseif ($tag['type'] == 'unparsed_commas_content')
2617 2758
 		{
2618 2759
 			$pos2 = strpos($message, ']', $pos1);
2619
-			if ($pos2 === false)
2620
-				continue;
2760
+			if ($pos2 === false) {
2761
+							continue;
2762
+			}
2621 2763
 
2622 2764
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2623
-			if ($pos3 === false)
2624
-				continue;
2765
+			if ($pos3 === false) {
2766
+							continue;
2767
+			}
2625 2768
 
2626 2769
 			// We want $1 to be the content, and the rest to be csv.
2627 2770
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2628 2771
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2629 2772
 
2630
-			if (isset($tag['validate']))
2631
-				$tag['validate']($tag, $data, $disabled, $params);
2773
+			if (isset($tag['validate'])) {
2774
+							$tag['validate']($tag, $data, $disabled, $params);
2775
+			}
2632 2776
 
2633 2777
 			$code = $tag['content'];
2634
-			foreach ($data as $k => $d)
2635
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2778
+			foreach ($data as $k => $d) {
2779
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2780
+			}
2636 2781
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2637 2782
 			$pos += strlen($code) - 1 + 2;
2638 2783
 		}
@@ -2640,24 +2785,28 @@  discard block
 block discarded – undo
2640 2785
 		elseif ($tag['type'] == 'unparsed_commas')
2641 2786
 		{
2642 2787
 			$pos2 = strpos($message, ']', $pos1);
2643
-			if ($pos2 === false)
2644
-				continue;
2788
+			if ($pos2 === false) {
2789
+							continue;
2790
+			}
2645 2791
 
2646 2792
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2647 2793
 
2648
-			if (isset($tag['validate']))
2649
-				$tag['validate']($tag, $data, $disabled, $params);
2794
+			if (isset($tag['validate'])) {
2795
+							$tag['validate']($tag, $data, $disabled, $params);
2796
+			}
2650 2797
 
2651 2798
 			// Fix after, for disabled code mainly.
2652
-			foreach ($data as $k => $d)
2653
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2799
+			foreach ($data as $k => $d) {
2800
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2801
+			}
2654 2802
 
2655 2803
 			$open_tags[] = $tag;
2656 2804
 
2657 2805
 			// Replace them out, $1, $2, $3, $4, etc.
2658 2806
 			$code = $tag['before'];
2659
-			foreach ($data as $k => $d)
2660
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2807
+			foreach ($data as $k => $d) {
2808
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2809
+			}
2661 2810
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2662 2811
 			$pos += strlen($code) - 1 + 2;
2663 2812
 		}
@@ -2668,28 +2817,33 @@  discard block
 block discarded – undo
2668 2817
 			if (isset($tag['quoted']))
2669 2818
 			{
2670 2819
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2671
-				if ($tag['quoted'] != 'optional' && !$quoted)
2672
-					continue;
2820
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2821
+									continue;
2822
+				}
2673 2823
 
2674
-				if ($quoted)
2675
-					$pos1 += 6;
2824
+				if ($quoted) {
2825
+									$pos1 += 6;
2826
+				}
2827
+			} else {
2828
+							$quoted = false;
2676 2829
 			}
2677
-			else
2678
-				$quoted = false;
2679 2830
 
2680 2831
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2681
-			if ($pos2 === false)
2682
-				continue;
2832
+			if ($pos2 === false) {
2833
+							continue;
2834
+			}
2683 2835
 
2684 2836
 			$data = substr($message, $pos1, $pos2 - $pos1);
2685 2837
 
2686 2838
 			// Validation for my parking, please!
2687
-			if (isset($tag['validate']))
2688
-				$tag['validate']($tag, $data, $disabled, $params);
2839
+			if (isset($tag['validate'])) {
2840
+							$tag['validate']($tag, $data, $disabled, $params);
2841
+			}
2689 2842
 
2690 2843
 			// For parsed content, we must recurse to avoid security problems.
2691
-			if ($tag['type'] != 'unparsed_equals')
2692
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2844
+			if ($tag['type'] != 'unparsed_equals') {
2845
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2846
+			}
2693 2847
 
2694 2848
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2695 2849
 
@@ -2701,34 +2855,40 @@  discard block
 block discarded – undo
2701 2855
 		}
2702 2856
 
2703 2857
 		// If this is block level, eat any breaks after it.
2704
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2705
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2858
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2859
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2860
+		}
2706 2861
 
2707 2862
 		// Are we trimming outside this tag?
2708
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2709
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2863
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2864
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2865
+		}
2710 2866
 	}
2711 2867
 
2712 2868
 	// Close any remaining tags.
2713
-	while ($tag = array_pop($open_tags))
2714
-		$message .= "\n" . $tag['after'] . "\n";
2869
+	while ($tag = array_pop($open_tags)) {
2870
+			$message .= "\n" . $tag['after'] . "\n";
2871
+	}
2715 2872
 
2716 2873
 	// Parse the smileys within the parts where it can be done safely.
2717 2874
 	if ($smileys === true)
2718 2875
 	{
2719 2876
 		$message_parts = explode("\n", $message);
2720
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2721
-			parsesmileys($message_parts[$i]);
2877
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2878
+					parsesmileys($message_parts[$i]);
2879
+		}
2722 2880
 
2723 2881
 		$message = implode('', $message_parts);
2724 2882
 	}
2725 2883
 
2726 2884
 	// No smileys, just get rid of the markers.
2727
-	else
2728
-		$message = strtr($message, array("\n" => ''));
2885
+	else {
2886
+			$message = strtr($message, array("\n" => ''));
2887
+	}
2729 2888
 
2730
-	if ($message !== '' && $message[0] === ' ')
2731
-		$message = '&nbsp;' . substr($message, 1);
2889
+	if ($message !== '' && $message[0] === ' ') {
2890
+			$message = '&nbsp;' . substr($message, 1);
2891
+	}
2732 2892
 
2733 2893
 	// Cleanup whitespace.
2734 2894
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2737,15 +2897,16 @@  discard block
 block discarded – undo
2737 2897
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2738 2898
 
2739 2899
 	// Cache the output if it took some time...
2740
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2741
-		cache_put_data($cache_key, $message, 240);
2900
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2901
+			cache_put_data($cache_key, $message, 240);
2902
+	}
2742 2903
 
2743 2904
 	// If this was a force parse revert if needed.
2744 2905
 	if (!empty($parse_tags))
2745 2906
 	{
2746
-		if (empty($temp_bbc))
2747
-			$bbc_codes = array();
2748
-		else
2907
+		if (empty($temp_bbc)) {
2908
+					$bbc_codes = array();
2909
+		} else
2749 2910
 		{
2750 2911
 			$bbc_codes = $temp_bbc;
2751 2912
 			unset($temp_bbc);
@@ -2772,8 +2933,9 @@  discard block
 block discarded – undo
2772 2933
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2773 2934
 
2774 2935
 	// No smiley set at all?!
2775
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2776
-		return;
2936
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2937
+			return;
2938
+	}
2777 2939
 
2778 2940
 	// Maybe a mod wants to implement an alternative method (e.g. emojis instead of images)
2779 2941
 	call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements));
@@ -2787,8 +2949,7 @@  discard block
 block discarded – undo
2787 2949
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2788 2950
 			$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');
2789 2951
 			$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'], '', '', '', '');
2790
-		}
2791
-		else
2952
+		} else
2792 2953
 		{
2793 2954
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2794 2955
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2812,9 +2973,9 @@  discard block
 block discarded – undo
2812 2973
 				$smcFunc['db_free_result']($result);
2813 2974
 
2814 2975
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2976
+			} else {
2977
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2815 2978
 			}
2816
-			else
2817
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2818 2979
 		}
2819 2980
 
2820 2981
 		// The non-breaking-space is a complex thing...
@@ -2836,16 +2997,18 @@  discard block
 block discarded – undo
2836 2997
 				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2837 2998
 				if (!empty($alt_images))
2838 2999
 				{
2839
-					foreach ($exts as $ext)
2840
-						if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
3000
+					foreach ($exts as $ext) {
3001
+											if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
2841 3002
 						{
2842 3003
 							$smileysto[$i] = $fname . '.' . $ext;
3004
+					}
2843 3005
 							break;
2844 3006
 						}
2845 3007
 				}
2846 3008
 				// If we have no image, just leave the text version in place
2847
-				else
2848
-					continue;
3009
+				else {
3010
+									continue;
3011
+				}
2849 3012
 			}
2850 3013
 
2851 3014
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
@@ -2913,12 +3076,14 @@  discard block
 block discarded – undo
2913 3076
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
2914 3077
 
2915 3078
 	// Only use the proxy if enabled and necessary
2916
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
2917
-		return $url;
3079
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3080
+			return $url;
3081
+	}
2918 3082
 
2919 3083
 	// We don't need to proxy our own resources
2920
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
2921
-		return strtr($url, array('http://' => 'https://'));
3084
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3085
+			return strtr($url, array('http://' => 'https://'));
3086
+	}
2922 3087
 
2923 3088
 	// By default, use SMF's own image proxy script
2924 3089
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -2943,35 +3108,41 @@  discard block
 block discarded – undo
2943 3108
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2944 3109
 
2945 3110
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2946
-	if (!empty($context['flush_mail']))
2947
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3111
+	if (!empty($context['flush_mail'])) {
3112
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2948 3113
 		AddMailQueue(true);
3114
+	}
2949 3115
 
2950 3116
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2951 3117
 
2952
-	if ($add)
2953
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3118
+	if ($add) {
3119
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3120
+	}
2954 3121
 
2955 3122
 	// Put the session ID in.
2956
-	if (defined('SID') && SID != '')
2957
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3123
+	if (defined('SID') && SID != '') {
3124
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3125
+	}
2958 3126
 	// Keep that debug in their for template debugging!
2959
-	elseif (isset($_GET['debug']))
2960
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3127
+	elseif (isset($_GET['debug'])) {
3128
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3129
+	}
2961 3130
 
2962 3131
 	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'])))
2963 3132
 	{
2964
-		if (defined('SID') && SID != '')
2965
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3133
+		if (defined('SID') && SID != '') {
3134
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2966 3135
 				function ($m) use ($scripturl)
2967 3136
 				{
2968 3137
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3138
+		}
2969 3139
 				}, $setLocation);
2970
-		else
2971
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3140
+		else {
3141
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2972 3142
 				function ($m) use ($scripturl)
2973 3143
 				{
2974 3144
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3145
+		}
2975 3146
 				}, $setLocation);
2976 3147
 	}
2977 3148
 
@@ -2982,8 +3153,9 @@  discard block
 block discarded – undo
2982 3153
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2983 3154
 
2984 3155
 	// Debugging.
2985
-	if (isset($db_show_debug) && $db_show_debug === true)
2986
-		$_SESSION['debug_redirect'] = $db_cache;
3156
+	if (isset($db_show_debug) && $db_show_debug === true) {
3157
+			$_SESSION['debug_redirect'] = $db_cache;
3158
+	}
2987 3159
 
2988 3160
 	obExit(false);
2989 3161
 }
@@ -3002,51 +3174,60 @@  discard block
 block discarded – undo
3002 3174
 
3003 3175
 	// Attempt to prevent a recursive loop.
3004 3176
 	++$level;
3005
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
3006
-		exit;
3007
-	if ($from_fatal_error)
3008
-		$has_fatal_error = true;
3177
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3178
+			exit;
3179
+	}
3180
+	if ($from_fatal_error) {
3181
+			$has_fatal_error = true;
3182
+	}
3009 3183
 
3010 3184
 	// Clear out the stat cache.
3011 3185
 	trackStats();
3012 3186
 
3013 3187
 	// If we have mail to send, send it.
3014
-	if (!empty($context['flush_mail']))
3015
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3188
+	if (!empty($context['flush_mail'])) {
3189
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3016 3190
 		AddMailQueue(true);
3191
+	}
3017 3192
 
3018 3193
 	$do_header = $header === null ? !$header_done : $header;
3019
-	if ($do_footer === null)
3020
-		$do_footer = $do_header;
3194
+	if ($do_footer === null) {
3195
+			$do_footer = $do_header;
3196
+	}
3021 3197
 
3022 3198
 	// Has the template/header been done yet?
3023 3199
 	if ($do_header)
3024 3200
 	{
3025 3201
 		// Was the page title set last minute? Also update the HTML safe one.
3026
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
3027
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3202
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3203
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3204
+		}
3028 3205
 
3029 3206
 		// Start up the session URL fixer.
3030 3207
 		ob_start('ob_sessrewrite');
3031 3208
 
3032
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3033
-			$buffers = explode(',', $settings['output_buffers']);
3034
-		elseif (!empty($settings['output_buffers']))
3035
-			$buffers = $settings['output_buffers'];
3036
-		else
3037
-			$buffers = array();
3209
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3210
+					$buffers = explode(',', $settings['output_buffers']);
3211
+		} elseif (!empty($settings['output_buffers'])) {
3212
+					$buffers = $settings['output_buffers'];
3213
+		} else {
3214
+					$buffers = array();
3215
+		}
3038 3216
 
3039
-		if (isset($modSettings['integrate_buffer']))
3040
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3217
+		if (isset($modSettings['integrate_buffer'])) {
3218
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3219
+		}
3041 3220
 
3042
-		if (!empty($buffers))
3043
-			foreach ($buffers as $function)
3221
+		if (!empty($buffers)) {
3222
+					foreach ($buffers as $function)
3044 3223
 			{
3045 3224
 				$call = call_helper($function, true);
3225
+		}
3046 3226
 
3047 3227
 				// Is it valid?
3048
-				if (!empty($call))
3049
-					ob_start($call);
3228
+				if (!empty($call)) {
3229
+									ob_start($call);
3230
+				}
3050 3231
 			}
3051 3232
 
3052 3233
 		// Display the screen in the logical order.
@@ -3058,8 +3239,9 @@  discard block
 block discarded – undo
3058 3239
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3059 3240
 
3060 3241
 		// Anything special to put out?
3061
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3062
-			echo $context['insert_after_template'];
3242
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3243
+					echo $context['insert_after_template'];
3244
+		}
3063 3245
 
3064 3246
 		// Just so we don't get caught in an endless loop of errors from the footer...
3065 3247
 		if (!$footer_done)
@@ -3068,14 +3250,16 @@  discard block
 block discarded – undo
3068 3250
 			template_footer();
3069 3251
 
3070 3252
 			// (since this is just debugging... it's okay that it's after </html>.)
3071
-			if (!isset($_REQUEST['xml']))
3072
-				displayDebug();
3253
+			if (!isset($_REQUEST['xml'])) {
3254
+							displayDebug();
3255
+			}
3073 3256
 		}
3074 3257
 	}
3075 3258
 
3076 3259
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3077
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3078
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3260
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3261
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3262
+	}
3079 3263
 
3080 3264
 	// For session check verification.... don't switch browsers...
3081 3265
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3084,9 +3268,10 @@  discard block
 block discarded – undo
3084 3268
 	call_integration_hook('integrate_exit', array($do_footer));
3085 3269
 
3086 3270
 	// Don't exit if we're coming from index.php; that will pass through normally.
3087
-	if (!$from_index)
3088
-		exit;
3089
-}
3271
+	if (!$from_index) {
3272
+			exit;
3273
+	}
3274
+	}
3090 3275
 
3091 3276
 /**
3092 3277
  * Get the size of a specified image with better error handling.
@@ -3105,8 +3290,9 @@  discard block
 block discarded – undo
3105 3290
 	$url = str_replace(' ', '%20', $url);
3106 3291
 
3107 3292
 	// Can we pull this from the cache... please please?
3108
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3109
-		return $temp;
3293
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3294
+			return $temp;
3295
+	}
3110 3296
 	$t = microtime();
3111 3297
 
3112 3298
 	// Get the host to pester...
@@ -3116,12 +3302,10 @@  discard block
 block discarded – undo
3116 3302
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3117 3303
 	{
3118 3304
 		return false;
3119
-	}
3120
-	elseif (!isset($match[1]))
3305
+	} elseif (!isset($match[1]))
3121 3306
 	{
3122 3307
 		$size = @getimagesize($url);
3123
-	}
3124
-	else
3308
+	} else
3125 3309
 	{
3126 3310
 		// Try to connect to the server... give it half a second.
3127 3311
 		$temp = 0;
@@ -3158,12 +3342,14 @@  discard block
 block discarded – undo
3158 3342
 	}
3159 3343
 
3160 3344
 	// If we didn't get it, we failed.
3161
-	if (!isset($size))
3162
-		$size = false;
3345
+	if (!isset($size)) {
3346
+			$size = false;
3347
+	}
3163 3348
 
3164 3349
 	// If this took a long time, we may never have to do it again, but then again we might...
3165
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3166
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3350
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3351
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3352
+	}
3167 3353
 
3168 3354
 	// Didn't work.
3169 3355
 	return $size;
@@ -3181,8 +3367,9 @@  discard block
 block discarded – undo
3181 3367
 
3182 3368
 	// Under SSI this function can be called more then once.  That can cause some problems.
3183 3369
 	//   So only run the function once unless we are forced to run it again.
3184
-	if ($loaded && !$forceload)
3185
-		return;
3370
+	if ($loaded && !$forceload) {
3371
+			return;
3372
+	}
3186 3373
 
3187 3374
 	$loaded = true;
3188 3375
 
@@ -3194,14 +3381,16 @@  discard block
 block discarded – undo
3194 3381
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3195 3382
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3196 3383
 	{
3197
-		if (trim($context['news_lines'][$i]) == '')
3198
-			continue;
3384
+		if (trim($context['news_lines'][$i]) == '') {
3385
+					continue;
3386
+		}
3199 3387
 
3200 3388
 		// Clean it up for presentation ;).
3201 3389
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3202 3390
 	}
3203
-	if (!empty($context['news_lines']))
3204
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3391
+	if (!empty($context['news_lines'])) {
3392
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3393
+	}
3205 3394
 
3206 3395
 	if (!$user_info['is_guest'])
3207 3396
 	{
@@ -3210,40 +3399,48 @@  discard block
 block discarded – undo
3210 3399
 		$context['user']['alerts'] = &$user_info['alerts'];
3211 3400
 
3212 3401
 		// Personal message popup...
3213
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3214
-			$context['user']['popup_messages'] = true;
3215
-		else
3216
-			$context['user']['popup_messages'] = false;
3402
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3403
+					$context['user']['popup_messages'] = true;
3404
+		} else {
3405
+					$context['user']['popup_messages'] = false;
3406
+		}
3217 3407
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3218 3408
 
3219
-		if (allowedTo('moderate_forum'))
3220
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3409
+		if (allowedTo('moderate_forum')) {
3410
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3411
+		}
3221 3412
 
3222 3413
 		$context['user']['avatar'] = array();
3223 3414
 
3224 3415
 		// Check for gravatar first since we might be forcing them...
3225 3416
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3226 3417
 		{
3227
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3228
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3229
-			else
3230
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3418
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3419
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3420
+			} else {
3421
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3422
+			}
3231 3423
 		}
3232 3424
 		// Uploaded?
3233
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3234
-			$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';
3425
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3426
+					$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';
3427
+		}
3235 3428
 		// Full URL?
3236
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3237
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3429
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3430
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3431
+		}
3238 3432
 		// Otherwise we assume it's server stored.
3239
-		elseif ($user_info['avatar']['url'] != '')
3240
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3433
+		elseif ($user_info['avatar']['url'] != '') {
3434
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3435
+		}
3241 3436
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3242
-		else
3243
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3437
+		else {
3438
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3439
+		}
3244 3440
 
3245
-		if (!empty($context['user']['avatar']))
3246
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3441
+		if (!empty($context['user']['avatar'])) {
3442
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3443
+		}
3247 3444
 
3248 3445
 		// Figure out how long they've been logged in.
3249 3446
 		$context['user']['total_time_logged_in'] = array(
@@ -3251,8 +3448,7 @@  discard block
 block discarded – undo
3251 3448
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3252 3449
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3253 3450
 		);
3254
-	}
3255
-	else
3451
+	} else
3256 3452
 	{
3257 3453
 		$context['user']['messages'] = 0;
3258 3454
 		$context['user']['unread_messages'] = 0;
@@ -3260,12 +3456,14 @@  discard block
 block discarded – undo
3260 3456
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3261 3457
 		$context['user']['popup_messages'] = false;
3262 3458
 
3263
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3264
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3459
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3460
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3461
+		}
3265 3462
 
3266 3463
 		// If we've upgraded recently, go easy on the passwords.
3267
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3268
-			$context['disable_login_hashing'] = true;
3464
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3465
+					$context['disable_login_hashing'] = true;
3466
+		}
3269 3467
 	}
3270 3468
 
3271 3469
 	// Setup the main menu items.
@@ -3278,8 +3476,8 @@  discard block
 block discarded – undo
3278 3476
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3279 3477
 
3280 3478
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3281
-	if ($context['show_pm_popup'])
3282
-		addInlineJavaScript('
3479
+	if ($context['show_pm_popup']) {
3480
+			addInlineJavaScript('
3283 3481
 		jQuery(document).ready(function($) {
3284 3482
 			new smc_Popup({
3285 3483
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3287,24 +3485,28 @@  discard block
 block discarded – undo
3287 3485
 				icon_class: \'generic_icons mail_new\'
3288 3486
 			});
3289 3487
 		});');
3488
+	}
3290 3489
 
3291 3490
 	// Add a generic "Are you sure?" confirmation message.
3292 3491
 	addInlineJavaScript('
3293 3492
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3294 3493
 
3295 3494
 	// Now add the capping code for avatars.
3296
-	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')
3297
-		addInlineCss('
3495
+	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') {
3496
+			addInlineCss('
3298 3497
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3498
+	}
3299 3499
 
3300 3500
 	// Add max image limits
3301
-	if (!empty($modSettings['max_image_width']))
3302
-		addInlineCss('
3501
+	if (!empty($modSettings['max_image_width'])) {
3502
+			addInlineCss('
3303 3503
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3504
+	}
3304 3505
 
3305
-	if (!empty($modSettings['max_image_height']))
3306
-		addInlineCss('
3506
+	if (!empty($modSettings['max_image_height'])) {
3507
+			addInlineCss('
3307 3508
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3509
+	}
3308 3510
 
3309 3511
 	// This looks weird, but it's because BoardIndex.php references the variable.
3310 3512
 	$context['common_stats']['latest_member'] = array(
@@ -3321,11 +3523,13 @@  discard block
 block discarded – undo
3321 3523
 	);
3322 3524
 	$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']);
3323 3525
 
3324
-	if (empty($settings['theme_version']))
3325
-		addJavaScriptVar('smf_scripturl', $scripturl);
3526
+	if (empty($settings['theme_version'])) {
3527
+			addJavaScriptVar('smf_scripturl', $scripturl);
3528
+	}
3326 3529
 
3327
-	if (!isset($context['page_title']))
3328
-		$context['page_title'] = '';
3530
+	if (!isset($context['page_title'])) {
3531
+			$context['page_title'] = '';
3532
+	}
3329 3533
 
3330 3534
 	// Set some specific vars.
3331 3535
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3335,21 +3539,23 @@  discard block
 block discarded – undo
3335 3539
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3336 3540
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3337 3541
 
3338
-	if (!empty($context['meta_keywords']))
3339
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3542
+	if (!empty($context['meta_keywords'])) {
3543
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3544
+	}
3340 3545
 
3341
-	if (!empty($context['canonical_url']))
3342
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3546
+	if (!empty($context['canonical_url'])) {
3547
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3548
+	}
3343 3549
 
3344
-	if (!empty($settings['og_image']))
3345
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3550
+	if (!empty($settings['og_image'])) {
3551
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3552
+	}
3346 3553
 
3347 3554
 	if (!empty($context['meta_description']))
3348 3555
 	{
3349 3556
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3350 3557
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3351
-	}
3352
-	else
3558
+	} else
3353 3559
 	{
3354 3560
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3355 3561
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3374,8 +3580,9 @@  discard block
 block discarded – undo
3374 3580
 	$memory_needed = memoryReturnBytes($needed);
3375 3581
 
3376 3582
 	// should we account for how much is currently being used?
3377
-	if ($in_use)
3378
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3583
+	if ($in_use) {
3584
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3585
+	}
3379 3586
 
3380 3587
 	// if more is needed, request it
3381 3588
 	if ($memory_current < $memory_needed)
@@ -3398,8 +3605,9 @@  discard block
 block discarded – undo
3398 3605
  */
3399 3606
 function memoryReturnBytes($val)
3400 3607
 {
3401
-	if (is_integer($val))
3402
-		return $val;
3608
+	if (is_integer($val)) {
3609
+			return $val;
3610
+	}
3403 3611
 
3404 3612
 	// Separate the number from the designator
3405 3613
 	$val = trim($val);
@@ -3435,10 +3643,11 @@  discard block
 block discarded – undo
3435 3643
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3436 3644
 
3437 3645
 		// Are we debugging the template/html content?
3438
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3439
-			header('content-type: application/xhtml+xml');
3440
-		elseif (!isset($_REQUEST['xml']))
3441
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3646
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3647
+					header('content-type: application/xhtml+xml');
3648
+		} elseif (!isset($_REQUEST['xml'])) {
3649
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3650
+		}
3442 3651
 	}
3443 3652
 
3444 3653
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3447,8 +3656,9 @@  discard block
 block discarded – undo
3447 3656
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3448 3657
 	{
3449 3658
 		$position = array_search('body', $context['template_layers']);
3450
-		if ($position === false)
3451
-			$position = array_search('main', $context['template_layers']);
3659
+		if ($position === false) {
3660
+					$position = array_search('main', $context['template_layers']);
3661
+		}
3452 3662
 
3453 3663
 		if ($position !== false)
3454 3664
 		{
@@ -3476,23 +3686,25 @@  discard block
 block discarded – undo
3476 3686
 
3477 3687
 			foreach ($securityFiles as $i => $securityFile)
3478 3688
 			{
3479
-				if (!file_exists($boarddir . '/' . $securityFile))
3480
-					unset($securityFiles[$i]);
3689
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3690
+									unset($securityFiles[$i]);
3691
+				}
3481 3692
 			}
3482 3693
 
3483 3694
 			// We are already checking so many files...just few more doesn't make any difference! :P
3484
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3485
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3486
-
3487
-			else
3488
-				$path = $modSettings['attachmentUploadDir'];
3695
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3696
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3697
+			} else {
3698
+							$path = $modSettings['attachmentUploadDir'];
3699
+			}
3489 3700
 
3490 3701
 			secureDirectory($path, true);
3491 3702
 			secureDirectory($cachedir);
3492 3703
 
3493 3704
 			// If agreement is enabled, at least the english version shall exists
3494
-			if ($modSettings['requireAgreement'])
3495
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3705
+			if ($modSettings['requireAgreement']) {
3706
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3707
+			}
3496 3708
 
3497 3709
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3498 3710
 			{
@@ -3507,18 +3719,21 @@  discard block
 block discarded – undo
3507 3719
 					echo '
3508 3720
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3509 3721
 
3510
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3511
-						echo '
3722
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3723
+											echo '
3512 3724
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3725
+					}
3513 3726
 				}
3514 3727
 
3515
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3516
-					echo '
3728
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3729
+									echo '
3517 3730
 				<strong>', $txt['cache_writable'], '</strong><br>';
3731
+				}
3518 3732
 
3519
-				if (!empty($agreement))
3520
-					echo '
3733
+				if (!empty($agreement)) {
3734
+									echo '
3521 3735
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3736
+				}
3522 3737
 
3523 3738
 				echo '
3524 3739
 			</p>
@@ -3533,16 +3748,18 @@  discard block
 block discarded – undo
3533 3748
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3534 3749
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3535 3750
 
3536
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3537
-				echo '
3751
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3752
+							echo '
3538 3753
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3754
+			}
3539 3755
 
3540
-			if (!empty($_SESSION['ban']['expire_time']))
3541
-				echo '
3756
+			if (!empty($_SESSION['ban']['expire_time'])) {
3757
+							echo '
3542 3758
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3543
-			else
3544
-				echo '
3759
+			} else {
3760
+							echo '
3545 3761
 					<div>', $txt['your_ban_expires_never'], '</div>';
3762
+			}
3546 3763
 
3547 3764
 			echo '
3548 3765
 				</div>';
@@ -3558,8 +3775,9 @@  discard block
 block discarded – undo
3558 3775
 	global $forum_copyright, $software_year, $forum_version;
3559 3776
 
3560 3777
 	// Don't display copyright for things like SSI.
3561
-	if (!isset($forum_version) || !isset($software_year))
3562
-		return;
3778
+	if (!isset($forum_version) || !isset($software_year)) {
3779
+			return;
3780
+	}
3563 3781
 
3564 3782
 	// Put in the version...
3565 3783
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3577,9 +3795,10 @@  discard block
 block discarded – undo
3577 3795
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3578 3796
 	$context['load_queries'] = $db_count;
3579 3797
 
3580
-	foreach (array_reverse($context['template_layers']) as $layer)
3581
-		loadSubTemplate($layer . '_below', true);
3582
-}
3798
+	foreach (array_reverse($context['template_layers']) as $layer) {
3799
+			loadSubTemplate($layer . '_below', true);
3800
+	}
3801
+	}
3583 3802
 
3584 3803
 /**
3585 3804
  * Output the Javascript files
@@ -3613,8 +3832,7 @@  discard block
 block discarded – undo
3613 3832
 			{
3614 3833
 				echo '
3615 3834
 		var ', $key, ';';
3616
-			}
3617
-			else
3835
+			} else
3618 3836
 			{
3619 3837
 				echo '
3620 3838
 		var ', $key, ' = ', $value, ';';
@@ -3633,27 +3851,29 @@  discard block
 block discarded – undo
3633 3851
 		foreach ($context['javascript_files'] as $id => $js_file)
3634 3852
 		{
3635 3853
 			// Last minute call! allow theme authors to disable single files.
3636
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3637
-				continue;
3854
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3855
+							continue;
3856
+			}
3638 3857
 
3639 3858
 			// By default files don't get minimized unless the file explicitly says so!
3640 3859
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3641 3860
 			{
3642
-				if (!empty($js_file['options']['async']))
3643
-					$toMinify['async'][] = $js_file;
3644
-				elseif (!empty($js_file['options']['defer']))
3645
-					$toMinify['defer'][] = $js_file;
3646
-				else
3647
-					$toMinify['standard'][] = $js_file;
3861
+				if (!empty($js_file['options']['async'])) {
3862
+									$toMinify['async'][] = $js_file;
3863
+				} elseif (!empty($js_file['options']['defer'])) {
3864
+									$toMinify['defer'][] = $js_file;
3865
+				} else {
3866
+									$toMinify['standard'][] = $js_file;
3867
+				}
3648 3868
 
3649 3869
 				// Grab a random seed.
3650
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3651
-					$minSeed = $js_file['options']['seed'];
3652
-			}
3653
-
3654
-			else
3655
-				echo '
3870
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3871
+									$minSeed = $js_file['options']['seed'];
3872
+				}
3873
+			} else {
3874
+							echo '
3656 3875
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
3876
+			}
3657 3877
 		}
3658 3878
 
3659 3879
 		foreach ($toMinify as $js_files)
@@ -3664,9 +3884,10 @@  discard block
 block discarded – undo
3664 3884
 
3665 3885
 				$minSuccessful = array_keys($result) === array('smf_minified');
3666 3886
 
3667
-				foreach ($result as $minFile)
3668
-					echo '
3887
+				foreach ($result as $minFile) {
3888
+									echo '
3669 3889
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
3890
+				}
3670 3891
 			}
3671 3892
 		}
3672 3893
 	}
@@ -3680,8 +3901,9 @@  discard block
 block discarded – undo
3680 3901
 <script>
3681 3902
 window.addEventListener("DOMContentLoaded", function() {';
3682 3903
 
3683
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3684
-				echo $js_code;
3904
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3905
+							echo $js_code;
3906
+			}
3685 3907
 
3686 3908
 			echo '
3687 3909
 });
@@ -3693,8 +3915,9 @@  discard block
 block discarded – undo
3693 3915
 			echo '
3694 3916
 	<script>';
3695 3917
 
3696
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3697
-				echo $js_code;
3918
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3919
+							echo $js_code;
3920
+			}
3698 3921
 
3699 3922
 			echo '
3700 3923
 	</script>';
@@ -3722,23 +3945,26 @@  discard block
 block discarded – undo
3722 3945
 	foreach ($context['css_files'] as $id => $file)
3723 3946
 	{
3724 3947
 		// Last minute call! allow theme authors to disable single files.
3725
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3726
-			continue;
3948
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3949
+					continue;
3950
+		}
3727 3951
 
3728 3952
 		// Files are minimized unless they explicitly opt out.
3729
-		if (!isset($file['options']['minimize']))
3730
-			$file['options']['minimize'] = true;
3953
+		if (!isset($file['options']['minimize'])) {
3954
+					$file['options']['minimize'] = true;
3955
+		}
3731 3956
 
3732 3957
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3733 3958
 		{
3734 3959
 			$toMinify[] = $file;
3735 3960
 
3736 3961
 			// Grab a random seed.
3737
-			if (!isset($minSeed) && isset($file['options']['seed']))
3738
-				$minSeed = $file['options']['seed'];
3962
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
3963
+							$minSeed = $file['options']['seed'];
3964
+			}
3965
+		} else {
3966
+					$normal[] = $file['fileUrl'];
3739 3967
 		}
3740
-		else
3741
-			$normal[] = $file['fileUrl'];
3742 3968
 	}
3743 3969
 
3744 3970
 	if (!empty($toMinify))
@@ -3747,23 +3973,26 @@  discard block
 block discarded – undo
3747 3973
 
3748 3974
 		$minSuccessful = array_keys($result) === array('smf_minified');
3749 3975
 
3750
-		foreach ($result as $minFile)
3751
-			echo '
3976
+		foreach ($result as $minFile) {
3977
+					echo '
3752 3978
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
3979
+		}
3753 3980
 	}
3754 3981
 
3755 3982
 	// Print the rest after the minified files.
3756
-	if (!empty($normal))
3757
-		foreach ($normal as $nf)
3983
+	if (!empty($normal)) {
3984
+			foreach ($normal as $nf)
3758 3985
 			echo '
3759 3986
 	<link rel="stylesheet" href="', $nf ,'">';
3987
+	}
3760 3988
 
3761 3989
 	if ($db_show_debug === true)
3762 3990
 	{
3763 3991
 		// Try to keep only what's useful.
3764 3992
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3765
-		foreach ($context['css_files'] as $file)
3766
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3993
+		foreach ($context['css_files'] as $file) {
3994
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3995
+		}
3767 3996
 	}
3768 3997
 
3769 3998
 	if (!empty($context['css_header']))
@@ -3771,9 +4000,10 @@  discard block
 block discarded – undo
3771 4000
 		echo '
3772 4001
 	<style>';
3773 4002
 
3774
-		foreach ($context['css_header'] as $css)
3775
-			echo $css .'
4003
+		foreach ($context['css_header'] as $css) {
4004
+					echo $css .'
3776 4005
 	';
4006
+		}
3777 4007
 
3778 4008
 		echo'
3779 4009
 	</style>';
@@ -3796,8 +4026,9 @@  discard block
 block discarded – undo
3796 4026
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3797 4027
 	$data = is_array($data) ? $data : array();
3798 4028
 
3799
-	if (empty($type) || empty($data))
3800
-		return $data;
4029
+	if (empty($type) || empty($data)) {
4030
+			return $data;
4031
+	}
3801 4032
 
3802 4033
 	// Different pages include different files, so we use a hash to label the different combinations
3803 4034
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3806,13 +4037,14 @@  discard block
 block discarded – undo
3806 4037
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3807 4038
 
3808 4039
 	// Already done?
3809
-	if (!empty($toCache))
3810
-		return array('smf_minified' => array(
4040
+	if (!empty($toCache)) {
4041
+			return array('smf_minified' => array(
3811 4042
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3812 4043
 			'filePath' => $toCache,
3813 4044
 			'fileName' => basename($toCache),
3814 4045
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3815 4046
 		));
4047
+	}
3816 4048
 
3817 4049
 
3818 4050
 	// No namespaces, sorry!
@@ -3842,9 +4074,9 @@  discard block
 block discarded – undo
3842 4074
 
3843 4075
 	foreach ($data as $id => $file)
3844 4076
 	{
3845
-		if (empty($file['filePath']))
3846
-			$toAdd = false;
3847
-		else
4077
+		if (empty($file['filePath'])) {
4078
+					$toAdd = false;
4079
+		} else
3848 4080
 		{
3849 4081
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3850 4082
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3852,12 +4084,14 @@  discard block
 block discarded – undo
3852 4084
 		}
3853 4085
 
3854 4086
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3855
-		if (empty($file['options']['async']))
3856
-			$async = false;
4087
+		if (empty($file['options']['async'])) {
4088
+					$async = false;
4089
+		}
3857 4090
 
3858 4091
 		// A minified script should only be deferred if all its components wanted to be.
3859
-		if (empty($file['options']['defer']))
3860
-			$defer = false;
4092
+		if (empty($file['options']['defer'])) {
4093
+					$defer = false;
4094
+		}
3861 4095
 
3862 4096
 		// The file couldn't be located so it won't be added. Log this error.
3863 4097
 		if (empty($toAdd))
@@ -3923,12 +4157,14 @@  discard block
 block discarded – undo
3923 4157
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
3924 4158
 			{
3925 4159
 				// Remove the cache entry
3926
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
3927
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4160
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4161
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4162
+				}
3928 4163
 
3929 4164
 				// Try to delete the file. Add it to our error list if it fails.
3930
-				if (!@unlink($filename))
3931
-					$not_deleted[] = $filename;
4165
+				if (!@unlink($filename)) {
4166
+									$not_deleted[] = $filename;
4167
+				}
3932 4168
 			}
3933 4169
 		}
3934 4170
 	}
@@ -3960,8 +4196,9 @@  discard block
 block discarded – undo
3960 4196
 	global $modSettings, $smcFunc;
3961 4197
 
3962 4198
 	// Just make up a nice hash...
3963
-	if ($new)
3964
-		return sha1(md5($filename . time()) . mt_rand());
4199
+	if ($new) {
4200
+			return sha1(md5($filename . time()) . mt_rand());
4201
+	}
3965 4202
 
3966 4203
 	// Just make sure that attachment id is only a int
3967 4204
 	$attachment_id = (int) $attachment_id;
@@ -3978,23 +4215,25 @@  discard block
 block discarded – undo
3978 4215
 				'id_attach' => $attachment_id,
3979 4216
 			));
3980 4217
 
3981
-		if ($smcFunc['db_num_rows']($request) === 0)
3982
-			return false;
4218
+		if ($smcFunc['db_num_rows']($request) === 0) {
4219
+					return false;
4220
+		}
3983 4221
 
3984 4222
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3985 4223
 		$smcFunc['db_free_result']($request);
3986 4224
 	}
3987 4225
 
3988 4226
 	// Still no hash? mmm...
3989
-	if (empty($file_hash))
3990
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4227
+	if (empty($file_hash)) {
4228
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4229
+	}
3991 4230
 
3992 4231
 	// Are we using multiple directories?
3993
-	if (is_array($modSettings['attachmentUploadDir']))
3994
-		$path = $modSettings['attachmentUploadDir'][$dir];
3995
-
3996
-	else
3997
-		$path = $modSettings['attachmentUploadDir'];
4232
+	if (is_array($modSettings['attachmentUploadDir'])) {
4233
+			$path = $modSettings['attachmentUploadDir'][$dir];
4234
+	} else {
4235
+			$path = $modSettings['attachmentUploadDir'];
4236
+	}
3998 4237
 
3999 4238
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4000 4239
 }
@@ -4009,8 +4248,9 @@  discard block
 block discarded – undo
4009 4248
 function ip2range($fullip)
4010 4249
 {
4011 4250
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
4012
-	if ($fullip == 'unknown')
4013
-		$fullip = '255.255.255.255';
4251
+	if ($fullip == 'unknown') {
4252
+			$fullip = '255.255.255.255';
4253
+	}
4014 4254
 
4015 4255
 	$ip_parts = explode('-', $fullip);
4016 4256
 	$ip_array = array();
@@ -4034,10 +4274,11 @@  discard block
 block discarded – undo
4034 4274
 		$ip_array['low'] = $ip_parts[0];
4035 4275
 		$ip_array['high'] = $ip_parts[1];
4036 4276
 		return $ip_array;
4037
-	}
4038
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4277
+	} elseif (count($ip_parts) == 2) {
4278
+		// if ip 22.22.*-22.22.*
4039 4279
 	{
4040 4280
 		$valid_low = isValidIP($ip_parts[0]);
4281
+	}
4041 4282
 		$valid_high = isValidIP($ip_parts[1]);
4042 4283
 		$count = 0;
4043 4284
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4052,7 +4293,9 @@  discard block
 block discarded – undo
4052 4293
 				$ip_parts[0] .= $mode . $min;
4053 4294
 				$valid_low = isValidIP($ip_parts[0]);
4054 4295
 				$count++;
4055
-				if ($count > 9) break;
4296
+				if ($count > 9) {
4297
+					break;
4298
+				}
4056 4299
 			}
4057 4300
 		}
4058 4301
 
@@ -4066,7 +4309,9 @@  discard block
 block discarded – undo
4066 4309
 				$ip_parts[1] .= $mode . $max;
4067 4310
 				$valid_high = isValidIP($ip_parts[1]);
4068 4311
 				$count++;
4069
-				if ($count > 9) break;
4312
+				if ($count > 9) {
4313
+					break;
4314
+				}
4070 4315
 			}
4071 4316
 		}
4072 4317
 
@@ -4090,46 +4335,54 @@  discard block
 block discarded – undo
4090 4335
 {
4091 4336
 	global $modSettings;
4092 4337
 
4093
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4094
-		return $host;
4338
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4339
+			return $host;
4340
+	}
4095 4341
 	$t = microtime();
4096 4342
 
4097 4343
 	// Try the Linux host command, perhaps?
4098 4344
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4099 4345
 	{
4100
-		if (!isset($modSettings['host_to_dis']))
4101
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4102
-		else
4103
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4346
+		if (!isset($modSettings['host_to_dis'])) {
4347
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4348
+		} else {
4349
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4350
+		}
4104 4351
 
4105 4352
 		// Did host say it didn't find anything?
4106
-		if (strpos($test, 'not found') !== false)
4107
-			$host = '';
4353
+		if (strpos($test, 'not found') !== false) {
4354
+					$host = '';
4355
+		}
4108 4356
 		// Invalid server option?
4109
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4110
-			updateSettings(array('host_to_dis' => 1));
4357
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4358
+					updateSettings(array('host_to_dis' => 1));
4359
+		}
4111 4360
 		// Maybe it found something, after all?
4112
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4113
-			$host = $match[1];
4361
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4362
+					$host = $match[1];
4363
+		}
4114 4364
 	}
4115 4365
 
4116 4366
 	// This is nslookup; usually only Windows, but possibly some Unix?
4117 4367
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4118 4368
 	{
4119 4369
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4120
-		if (strpos($test, 'Non-existent domain') !== false)
4121
-			$host = '';
4122
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4123
-			$host = $match[1];
4370
+		if (strpos($test, 'Non-existent domain') !== false) {
4371
+					$host = '';
4372
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4373
+					$host = $match[1];
4374
+		}
4124 4375
 	}
4125 4376
 
4126 4377
 	// This is the last try :/.
4127
-	if (!isset($host) || $host === false)
4128
-		$host = @gethostbyaddr($ip);
4378
+	if (!isset($host) || $host === false) {
4379
+			$host = @gethostbyaddr($ip);
4380
+	}
4129 4381
 
4130 4382
 	// It took a long time, so let's cache it!
4131
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4132
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4383
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4384
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4385
+	}
4133 4386
 
4134 4387
 	return $host;
4135 4388
 }
@@ -4165,20 +4418,21 @@  discard block
 block discarded – undo
4165 4418
 			{
4166 4419
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4167 4420
 				$total = 0;
4168
-				for ($i = 0; $i < $max_chars; $i++)
4169
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4421
+				for ($i = 0; $i < $max_chars; $i++) {
4422
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4423
+				}
4170 4424
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4171 4425
 			}
4172 4426
 		}
4173 4427
 		return array_unique($returned_ints);
4174
-	}
4175
-	else
4428
+	} else
4176 4429
 	{
4177 4430
 		// Trim characters before and after and add slashes for database insertion.
4178 4431
 		$returned_words = array();
4179
-		foreach ($words as $word)
4180
-			if (($word = trim($word, '-_\'')) !== '')
4432
+		foreach ($words as $word) {
4433
+					if (($word = trim($word, '-_\'')) !== '')
4181 4434
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4435
+		}
4182 4436
 
4183 4437
 		// Filter out all words that occur more than once.
4184 4438
 		return array_unique($returned_words);
@@ -4200,16 +4454,18 @@  discard block
 block discarded – undo
4200 4454
 	global $settings, $txt;
4201 4455
 
4202 4456
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4203
-	if (function_exists('template_create_button') && !$force_use)
4204
-		return template_create_button($name, $alt, $label = '', $custom = '');
4457
+	if (function_exists('template_create_button') && !$force_use) {
4458
+			return template_create_button($name, $alt, $label = '', $custom = '');
4459
+	}
4205 4460
 
4206
-	if (!$settings['use_image_buttons'])
4207
-		return $txt[$alt];
4208
-	elseif (!empty($settings['use_buttons']))
4209
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4210
-	else
4211
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4212
-}
4461
+	if (!$settings['use_image_buttons']) {
4462
+			return $txt[$alt];
4463
+	} elseif (!empty($settings['use_buttons'])) {
4464
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4465
+	} else {
4466
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4467
+	}
4468
+	}
4213 4469
 
4214 4470
 /**
4215 4471
  * Sets up all of the top menu buttons
@@ -4252,9 +4508,10 @@  discard block
 block discarded – undo
4252 4508
 	var user_menus = new smc_PopupMenu();
4253 4509
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4254 4510
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4255
-		if ($context['allow_pm'])
4256
-			addInlineJavaScript('
4511
+		if ($context['allow_pm']) {
4512
+					addInlineJavaScript('
4257 4513
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4514
+		}
4258 4515
 
4259 4516
 		if (!empty($modSettings['enable_ajax_alerts']))
4260 4517
 		{
@@ -4414,88 +4671,96 @@  discard block
 block discarded – undo
4414 4671
 
4415 4672
 		// Now we put the buttons in the context so the theme can use them.
4416 4673
 		$menu_buttons = array();
4417
-		foreach ($buttons as $act => $button)
4418
-			if (!empty($button['show']))
4674
+		foreach ($buttons as $act => $button) {
4675
+					if (!empty($button['show']))
4419 4676
 			{
4420 4677
 				$button['active_button'] = false;
4678
+		}
4421 4679
 
4422 4680
 				// This button needs some action.
4423
-				if (isset($button['action_hook']))
4424
-					$needs_action_hook = true;
4681
+				if (isset($button['action_hook'])) {
4682
+									$needs_action_hook = true;
4683
+				}
4425 4684
 
4426 4685
 				// Make sure the last button truly is the last button.
4427 4686
 				if (!empty($button['is_last']))
4428 4687
 				{
4429
-					if (isset($last_button))
4430
-						unset($menu_buttons[$last_button]['is_last']);
4688
+					if (isset($last_button)) {
4689
+											unset($menu_buttons[$last_button]['is_last']);
4690
+					}
4431 4691
 					$last_button = $act;
4432 4692
 				}
4433 4693
 
4434 4694
 				// Go through the sub buttons if there are any.
4435
-				if (!empty($button['sub_buttons']))
4436
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4695
+				if (!empty($button['sub_buttons'])) {
4696
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4437 4697
 					{
4438 4698
 						if (empty($subbutton['show']))
4439 4699
 							unset($button['sub_buttons'][$key]);
4700
+				}
4440 4701
 
4441 4702
 						// 2nd level sub buttons next...
4442 4703
 						if (!empty($subbutton['sub_buttons']))
4443 4704
 						{
4444 4705
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4445 4706
 							{
4446
-								if (empty($sub_button2['show']))
4447
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4707
+								if (empty($sub_button2['show'])) {
4708
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4709
+								}
4448 4710
 							}
4449 4711
 						}
4450 4712
 					}
4451 4713
 
4452 4714
 				// Does this button have its own icon?
4453
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4454
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4455
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4456
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4457
-				elseif (isset($button['icon']))
4458
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4459
-				else
4460
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4715
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4716
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4717
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4718
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4719
+				} elseif (isset($button['icon'])) {
4720
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4721
+				} else {
4722
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4723
+				}
4461 4724
 
4462 4725
 				$menu_buttons[$act] = $button;
4463 4726
 			}
4464 4727
 
4465
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4466
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4728
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4729
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4730
+		}
4467 4731
 	}
4468 4732
 
4469 4733
 	$context['menu_buttons'] = $menu_buttons;
4470 4734
 
4471 4735
 	// Logging out requires the session id in the url.
4472
-	if (isset($context['menu_buttons']['logout']))
4473
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4736
+	if (isset($context['menu_buttons']['logout'])) {
4737
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4738
+	}
4474 4739
 
4475 4740
 	// Figure out which action we are doing so we can set the active tab.
4476 4741
 	// Default to home.
4477 4742
 	$current_action = 'home';
4478 4743
 
4479
-	if (isset($context['menu_buttons'][$context['current_action']]))
4480
-		$current_action = $context['current_action'];
4481
-	elseif ($context['current_action'] == 'search2')
4482
-		$current_action = 'search';
4483
-	elseif ($context['current_action'] == 'theme')
4484
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4485
-	elseif ($context['current_action'] == 'register2')
4486
-		$current_action = 'register';
4487
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4488
-		$current_action = 'login';
4489
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4490
-		$current_action = 'moderate';
4744
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4745
+			$current_action = $context['current_action'];
4746
+	} elseif ($context['current_action'] == 'search2') {
4747
+			$current_action = 'search';
4748
+	} elseif ($context['current_action'] == 'theme') {
4749
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4750
+	} elseif ($context['current_action'] == 'register2') {
4751
+			$current_action = 'register';
4752
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4753
+			$current_action = 'login';
4754
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4755
+			$current_action = 'moderate';
4756
+	}
4491 4757
 
4492 4758
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4493 4759
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4494 4760
 	{
4495 4761
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4496 4762
 		$context[$current_action] = true;
4497
-	}
4498
-	elseif ($context['current_action'] == 'pm')
4763
+	} elseif ($context['current_action'] == 'pm')
4499 4764
 	{
4500 4765
 		$current_action = 'self_pm';
4501 4766
 		$context['self_pm'] = true;
@@ -4552,12 +4817,14 @@  discard block
 block discarded – undo
4552 4817
 	}
4553 4818
 
4554 4819
 	// Not all actions are simple.
4555
-	if (!empty($needs_action_hook))
4556
-		call_integration_hook('integrate_current_action', array(&$current_action));
4820
+	if (!empty($needs_action_hook)) {
4821
+			call_integration_hook('integrate_current_action', array(&$current_action));
4822
+	}
4557 4823
 
4558
-	if (isset($context['menu_buttons'][$current_action]))
4559
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4560
-}
4824
+	if (isset($context['menu_buttons'][$current_action])) {
4825
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4826
+	}
4827
+	}
4561 4828
 
4562 4829
 /**
4563 4830
  * Generate a random seed and ensure it's stored in settings.
@@ -4581,30 +4848,35 @@  discard block
 block discarded – undo
4581 4848
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4582 4849
 	global $context, $txt;
4583 4850
 
4584
-	if ($db_show_debug === true)
4585
-		$context['debug']['hooks'][] = $hook;
4851
+	if ($db_show_debug === true) {
4852
+			$context['debug']['hooks'][] = $hook;
4853
+	}
4586 4854
 
4587 4855
 	// Need to have some control.
4588
-	if (!isset($context['instances']))
4589
-		$context['instances'] = array();
4856
+	if (!isset($context['instances'])) {
4857
+			$context['instances'] = array();
4858
+	}
4590 4859
 
4591 4860
 	$results = array();
4592
-	if (empty($modSettings[$hook]))
4593
-		return $results;
4861
+	if (empty($modSettings[$hook])) {
4862
+			return $results;
4863
+	}
4594 4864
 
4595 4865
 	$functions = explode(',', $modSettings[$hook]);
4596 4866
 	// Loop through each function.
4597 4867
 	foreach ($functions as $function)
4598 4868
 	{
4599 4869
 		// Hook has been marked as "disabled". Skip it!
4600
-		if (strpos($function, '!') !== false)
4601
-			continue;
4870
+		if (strpos($function, '!') !== false) {
4871
+					continue;
4872
+		}
4602 4873
 
4603 4874
 		$call = call_helper($function, true);
4604 4875
 
4605 4876
 		// Is it valid?
4606
-		if (!empty($call))
4607
-			$results[$function] = call_user_func_array($call, $parameters);
4877
+		if (!empty($call)) {
4878
+					$results[$function] = call_user_func_array($call, $parameters);
4879
+		}
4608 4880
 
4609 4881
 		// Whatever it was suppose to call, it failed :(
4610 4882
 		elseif (!empty($function))
@@ -4620,8 +4892,9 @@  discard block
 block discarded – undo
4620 4892
 			}
4621 4893
 
4622 4894
 			// "Assume" the file resides on $boarddir somewhere...
4623
-			else
4624
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4895
+			else {
4896
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4897
+			}
4625 4898
 		}
4626 4899
 	}
4627 4900
 
@@ -4643,12 +4916,14 @@  discard block
 block discarded – undo
4643 4916
 	global $smcFunc, $modSettings;
4644 4917
 
4645 4918
 	// Any objects?
4646
-	if ($object)
4647
-		$function = $function . '#';
4919
+	if ($object) {
4920
+			$function = $function . '#';
4921
+	}
4648 4922
 
4649 4923
 	// Any files  to load?
4650
-	if (!empty($file) && is_string($file))
4651
-		$function = $file . (!empty($function) ? '|' . $function : '');
4924
+	if (!empty($file) && is_string($file)) {
4925
+			$function = $file . (!empty($function) ? '|' . $function : '');
4926
+	}
4652 4927
 
4653 4928
 	// Get the correct string.
4654 4929
 	$integration_call = $function;
@@ -4670,13 +4945,14 @@  discard block
 block discarded – undo
4670 4945
 		if (!empty($current_functions))
4671 4946
 		{
4672 4947
 			$current_functions = explode(',', $current_functions);
4673
-			if (in_array($integration_call, $current_functions))
4674
-				return;
4948
+			if (in_array($integration_call, $current_functions)) {
4949
+							return;
4950
+			}
4675 4951
 
4676 4952
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4953
+		} else {
4954
+					$permanent_functions = array($integration_call);
4677 4955
 		}
4678
-		else
4679
-			$permanent_functions = array($integration_call);
4680 4956
 
4681 4957
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4682 4958
 	}
@@ -4685,8 +4961,9 @@  discard block
 block discarded – undo
4685 4961
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4686 4962
 
4687 4963
 	// Do nothing, if it's already there.
4688
-	if (in_array($integration_call, $functions))
4689
-		return;
4964
+	if (in_array($integration_call, $functions)) {
4965
+			return;
4966
+	}
4690 4967
 
4691 4968
 	$functions[] = $integration_call;
4692 4969
 	$modSettings[$hook] = implode(',', $functions);
@@ -4709,12 +4986,14 @@  discard block
 block discarded – undo
4709 4986
 	global $smcFunc, $modSettings;
4710 4987
 
4711 4988
 	// Any objects?
4712
-	if ($object)
4713
-		$function = $function . '#';
4989
+	if ($object) {
4990
+			$function = $function . '#';
4991
+	}
4714 4992
 
4715 4993
 	// Any files  to load?
4716
-	if (!empty($file) && is_string($file))
4717
-		$function = $file . '|' . $function;
4994
+	if (!empty($file) && is_string($file)) {
4995
+			$function = $file . '|' . $function;
4996
+	}
4718 4997
 
4719 4998
 	// Get the correct string.
4720 4999
 	$integration_call = $function;
@@ -4735,16 +5014,18 @@  discard block
 block discarded – undo
4735 5014
 	{
4736 5015
 		$current_functions = explode(',', $current_functions);
4737 5016
 
4738
-		if (in_array($integration_call, $current_functions))
4739
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5017
+		if (in_array($integration_call, $current_functions)) {
5018
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5019
+		}
4740 5020
 	}
4741 5021
 
4742 5022
 	// Turn the function list into something usable.
4743 5023
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4744 5024
 
4745 5025
 	// You can only remove it if it's available.
4746
-	if (!in_array($integration_call, $functions))
4747
-		return;
5026
+	if (!in_array($integration_call, $functions)) {
5027
+			return;
5028
+	}
4748 5029
 
4749 5030
 	$functions = array_diff($functions, array($integration_call));
4750 5031
 	$modSettings[$hook] = implode(',', $functions);
@@ -4765,17 +5046,20 @@  discard block
 block discarded – undo
4765 5046
 	global $context, $smcFunc, $txt, $db_show_debug;
4766 5047
 
4767 5048
 	// Really?
4768
-	if (empty($string))
4769
-		return false;
5049
+	if (empty($string)) {
5050
+			return false;
5051
+	}
4770 5052
 
4771 5053
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4772 5054
 	// A closure? should be a callable one.
4773
-	if (is_array($string) || $string instanceof Closure)
4774
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5055
+	if (is_array($string) || $string instanceof Closure) {
5056
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5057
+	}
4775 5058
 
4776 5059
 	// No full objects, sorry! pass a method or a property instead!
4777
-	if (is_object($string))
4778
-		return false;
5060
+	if (is_object($string)) {
5061
+			return false;
5062
+	}
4779 5063
 
4780 5064
 	// Stay vitaminized my friends...
4781 5065
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4784,8 +5068,9 @@  discard block
 block discarded – undo
4784 5068
 	$string = load_file($string);
4785 5069
 
4786 5070
 	// Loaded file failed
4787
-	if (empty($string))
4788
-		return false;
5071
+	if (empty($string)) {
5072
+			return false;
5073
+	}
4789 5074
 
4790 5075
 	// Found a method.
4791 5076
 	if (strpos($string, '::') !== false)
@@ -4806,8 +5091,9 @@  discard block
 block discarded – undo
4806 5091
 				// Add another one to the list.
4807 5092
 				if ($db_show_debug === true)
4808 5093
 				{
4809
-					if (!isset($context['debug']['instances']))
4810
-						$context['debug']['instances'] = array();
5094
+					if (!isset($context['debug']['instances'])) {
5095
+											$context['debug']['instances'] = array();
5096
+					}
4811 5097
 
4812 5098
 					$context['debug']['instances'][$class] = $class;
4813 5099
 				}
@@ -4817,13 +5103,15 @@  discard block
 block discarded – undo
4817 5103
 		}
4818 5104
 
4819 5105
 		// Right then. This is a call to a static method.
4820
-		else
4821
-			$func = array($class, $method);
5106
+		else {
5107
+					$func = array($class, $method);
5108
+		}
4822 5109
 	}
4823 5110
 
4824 5111
 	// Nope! just a plain regular function.
4825
-	else
4826
-		$func = $string;
5112
+	else {
5113
+			$func = $string;
5114
+	}
4827 5115
 
4828 5116
 	// Right, we got what we need, time to do some checks.
4829 5117
 	if (!is_callable($func, false, $callable_name))
@@ -4839,17 +5127,18 @@  discard block
 block discarded – undo
4839 5127
 	else
4840 5128
 	{
4841 5129
 		// What are we gonna do about it?
4842
-		if ($return)
4843
-			return $func;
5130
+		if ($return) {
5131
+					return $func;
5132
+		}
4844 5133
 
4845 5134
 		// If this is a plain function, avoid the heat of calling call_user_func().
4846 5135
 		else
4847 5136
 		{
4848
-			if (is_array($func))
4849
-				call_user_func($func);
4850
-
4851
-			else
4852
-				$func();
5137
+			if (is_array($func)) {
5138
+							call_user_func($func);
5139
+			} else {
5140
+							$func();
5141
+			}
4853 5142
 		}
4854 5143
 	}
4855 5144
 }
@@ -4866,31 +5155,34 @@  discard block
 block discarded – undo
4866 5155
 {
4867 5156
 	global $sourcedir, $txt, $boarddir, $settings;
4868 5157
 
4869
-	if (empty($string))
4870
-		return false;
5158
+	if (empty($string)) {
5159
+			return false;
5160
+	}
4871 5161
 
4872 5162
 	if (strpos($string, '|') !== false)
4873 5163
 	{
4874 5164
 		list ($file, $string) = explode('|', $string);
4875 5165
 
4876 5166
 		// Match the wildcards to their regular vars.
4877
-		if (empty($settings['theme_dir']))
4878
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4879
-
4880
-		else
4881
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5167
+		if (empty($settings['theme_dir'])) {
5168
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5169
+		} else {
5170
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5171
+		}
4882 5172
 
4883 5173
 		// Load the file if it can be loaded.
4884
-		if (file_exists($absPath))
4885
-			require_once($absPath);
5174
+		if (file_exists($absPath)) {
5175
+					require_once($absPath);
5176
+		}
4886 5177
 
4887 5178
 		// No? try a fallback to $sourcedir
4888 5179
 		else
4889 5180
 		{
4890 5181
 			$absPath = $sourcedir .'/'. $file;
4891 5182
 
4892
-			if (file_exists($absPath))
4893
-				require_once($absPath);
5183
+			if (file_exists($absPath)) {
5184
+							require_once($absPath);
5185
+			}
4894 5186
 
4895 5187
 			// Sorry, can't do much for you at this point.
4896 5188
 			else
@@ -4929,8 +5221,9 @@  discard block
 block discarded – undo
4929 5221
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
4930 5222
 
4931 5223
 	// No scheme? No data for you!
4932
-	if (empty($match[1]))
4933
-		return false;
5224
+	if (empty($match[1])) {
5225
+			return false;
5226
+	}
4934 5227
 
4935 5228
 	// An FTP url. We should try connecting and RETRieving it...
4936 5229
 	elseif ($match[1] == 'ftp')
@@ -4940,23 +5233,26 @@  discard block
 block discarded – undo
4940 5233
 
4941 5234
 		// Establish a connection and attempt to enable passive mode.
4942 5235
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
4943
-		if ($ftp->error !== false || !$ftp->passive())
4944
-			return false;
5236
+		if ($ftp->error !== false || !$ftp->passive()) {
5237
+					return false;
5238
+		}
4945 5239
 
4946 5240
 		// I want that one *points*!
4947 5241
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
4948 5242
 
4949 5243
 		// Since passive mode worked (or we would have returned already!) open the connection.
4950 5244
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
4951
-		if (!$fp)
4952
-			return false;
5245
+		if (!$fp) {
5246
+					return false;
5247
+		}
4953 5248
 
4954 5249
 		// The server should now say something in acknowledgement.
4955 5250
 		$ftp->check_response(150);
4956 5251
 
4957 5252
 		$data = '';
4958
-		while (!feof($fp))
4959
-			$data .= fread($fp, 4096);
5253
+		while (!feof($fp)) {
5254
+					$data .= fread($fp, 4096);
5255
+		}
4960 5256
 		fclose($fp);
4961 5257
 
4962 5258
 		// All done, right?  Good.
@@ -4968,8 +5264,9 @@  discard block
 block discarded – undo
4968 5264
 	elseif (isset($match[1]) && $match[1] == 'http')
4969 5265
 	{
4970 5266
 		// First try to use fsockopen, because it is fastest.
4971
-		if ($keep_alive && $match[3] == $keep_alive_dom)
4972
-			$fp = $keep_alive_fp;
5267
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5268
+					$fp = $keep_alive_fp;
5269
+		}
4973 5270
 		if (empty($fp))
4974 5271
 		{
4975 5272
 			// Open the socket on the port we want...
@@ -4989,20 +5286,21 @@  discard block
 block discarded – undo
4989 5286
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
4990 5287
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
4991 5288
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
4992
-				if ($keep_alive)
4993
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
4994
-				else
4995
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
4996
-			}
4997
-			else
5289
+				if ($keep_alive) {
5290
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5291
+				} else {
5292
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5293
+				}
5294
+			} else
4998 5295
 			{
4999 5296
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
5000 5297
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5001 5298
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5002
-				if ($keep_alive)
5003
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5004
-				else
5005
-					fwrite($fp, 'connection: close' . "\r\n");
5299
+				if ($keep_alive) {
5300
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5301
+				} else {
5302
+									fwrite($fp, 'connection: close' . "\r\n");
5303
+				}
5006 5304
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
5007 5305
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
5008 5306
 				fwrite($fp, $post_data);
@@ -5015,30 +5313,33 @@  discard block
 block discarded – undo
5015 5313
 			{
5016 5314
 				$header = '';
5017 5315
 				$location = '';
5018
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5019
-					if (strpos($header, 'location:') !== false)
5316
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5317
+									if (strpos($header, 'location:') !== false)
5020 5318
 						$location = trim(substr($header, strpos($header, ':') + 1));
5319
+				}
5021 5320
 
5022
-				if (empty($location))
5023
-					return false;
5024
-				else
5321
+				if (empty($location)) {
5322
+									return false;
5323
+				} else
5025 5324
 				{
5026
-					if (!$keep_alive)
5027
-						fclose($fp);
5325
+					if (!$keep_alive) {
5326
+											fclose($fp);
5327
+					}
5028 5328
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
5029 5329
 				}
5030 5330
 			}
5031 5331
 
5032 5332
 			// Make sure we get a 200 OK.
5033
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5034
-				return false;
5333
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5334
+							return false;
5335
+			}
5035 5336
 
5036 5337
 			// Skip the headers...
5037 5338
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5038 5339
 			{
5039
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5040
-					$content_length = $match[1];
5041
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5340
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5341
+									$content_length = $match[1];
5342
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5042 5343
 				{
5043 5344
 					$keep_alive_dom = null;
5044 5345
 					$keep_alive = false;
@@ -5050,17 +5351,19 @@  discard block
 block discarded – undo
5050 5351
 			$data = '';
5051 5352
 			if (isset($content_length))
5052 5353
 			{
5053
-				while (!feof($fp) && strlen($data) < $content_length)
5054
-					$data .= fread($fp, $content_length - strlen($data));
5055
-			}
5056
-			else
5354
+				while (!feof($fp) && strlen($data) < $content_length) {
5355
+									$data .= fread($fp, $content_length - strlen($data));
5356
+				}
5357
+			} else
5057 5358
 			{
5058
-				while (!feof($fp))
5059
-					$data .= fread($fp, 4096);
5359
+				while (!feof($fp)) {
5360
+									$data .= fread($fp, 4096);
5361
+				}
5060 5362
 			}
5061 5363
 
5062
-			if (!$keep_alive)
5063
-				fclose($fp);
5364
+			if (!$keep_alive) {
5365
+							fclose($fp);
5366
+			}
5064 5367
 		}
5065 5368
 
5066 5369
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5073,17 +5376,18 @@  discard block
 block discarded – undo
5073 5376
 			$fetch_data->get_url_data($url, $post_data);
5074 5377
 
5075 5378
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5076
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5077
-				$data = $fetch_data->result('body');
5078
-			else
5079
-				return false;
5379
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5380
+							$data = $fetch_data->result('body');
5381
+			} else {
5382
+							return false;
5383
+			}
5080 5384
 		}
5081 5385
 
5082 5386
 		// Neither fsockopen nor curl are available. Well, phooey.
5083
-		else
5084
-			return false;
5085
-	}
5086
-	else
5387
+		else {
5388
+					return false;
5389
+		}
5390
+	} else
5087 5391
 	{
5088 5392
 		// Umm, this shouldn't happen?
5089 5393
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5103,8 +5407,9 @@  discard block
 block discarded – undo
5103 5407
 	global $user_info, $smcFunc;
5104 5408
 
5105 5409
 	// Make sure we have something to work with.
5106
-	if (empty($topic))
5107
-		return array();
5410
+	if (empty($topic)) {
5411
+			return array();
5412
+	}
5108 5413
 
5109 5414
 
5110 5415
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5127,8 +5432,9 @@  discard block
 block discarded – undo
5127 5432
 				'topic' => $topic,
5128 5433
 			)
5129 5434
 		);
5130
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5131
-			$temp[] = (int) $row['content_id'];
5435
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5436
+					$temp[] = (int) $row['content_id'];
5437
+		}
5132 5438
 
5133 5439
 		cache_put_data($cache_key, $temp, $ttl);
5134 5440
 	}
@@ -5149,8 +5455,9 @@  discard block
 block discarded – undo
5149 5455
 {
5150 5456
 	global $context;
5151 5457
 
5152
-	if (empty($string))
5153
-		return $string;
5458
+	if (empty($string)) {
5459
+			return $string;
5460
+	}
5154 5461
 
5155 5462
 	// UTF-8 occurences of MS special characters
5156 5463
 	$findchars_utf8 = array(
@@ -5191,10 +5498,11 @@  discard block
 block discarded – undo
5191 5498
 		'--',	// &mdash;
5192 5499
 	);
5193 5500
 
5194
-	if ($context['utf8'])
5195
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5196
-	else
5197
-		$string = str_replace($findchars_iso, $replacechars, $string);
5501
+	if ($context['utf8']) {
5502
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5503
+	} else {
5504
+			$string = str_replace($findchars_iso, $replacechars, $string);
5505
+	}
5198 5506
 
5199 5507
 	return $string;
5200 5508
 }
@@ -5213,49 +5521,59 @@  discard block
 block discarded – undo
5213 5521
 {
5214 5522
 	global $context;
5215 5523
 
5216
-	if (!isset($matches[2]))
5217
-		return '';
5524
+	if (!isset($matches[2])) {
5525
+			return '';
5526
+	}
5218 5527
 
5219 5528
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5220 5529
 
5221 5530
 	// remove left to right / right to left overrides
5222
-	if ($num === 0x202D || $num === 0x202E)
5223
-		return '';
5531
+	if ($num === 0x202D || $num === 0x202E) {
5532
+			return '';
5533
+	}
5224 5534
 
5225 5535
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5226
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5227
-		return '&#' . $num . ';';
5536
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5537
+			return '&#' . $num . ';';
5538
+	}
5228 5539
 
5229 5540
 	if (empty($context['utf8']))
5230 5541
 	{
5231 5542
 		// no control characters
5232
-		if ($num < 0x20)
5233
-			return '';
5543
+		if ($num < 0x20) {
5544
+					return '';
5545
+		}
5234 5546
 		// text is text
5235
-		elseif ($num < 0x80)
5236
-			return chr($num);
5547
+		elseif ($num < 0x80) {
5548
+					return chr($num);
5549
+		}
5237 5550
 		// all others get html-ised
5238
-		else
5239
-			return '&#' . $matches[2] . ';';
5240
-	}
5241
-	else
5551
+		else {
5552
+					return '&#' . $matches[2] . ';';
5553
+		}
5554
+	} else
5242 5555
 	{
5243 5556
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5244 5557
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5245
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5246
-			return '';
5558
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5559
+					return '';
5560
+		}
5247 5561
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5248
-		elseif ($num < 0x80)
5249
-			return chr($num);
5562
+		elseif ($num < 0x80) {
5563
+					return chr($num);
5564
+		}
5250 5565
 		// <0x800 (2048)
5251
-		elseif ($num < 0x800)
5252
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5566
+		elseif ($num < 0x800) {
5567
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5568
+		}
5253 5569
 		// < 0x10000 (65536)
5254
-		elseif ($num < 0x10000)
5255
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5570
+		elseif ($num < 0x10000) {
5571
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5572
+		}
5256 5573
 		// <= 0x10FFFF (1114111)
5257
-		else
5258
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5574
+		else {
5575
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5576
+		}
5259 5577
 	}
5260 5578
 }
5261 5579
 
@@ -5271,28 +5589,34 @@  discard block
 block discarded – undo
5271 5589
  */
5272 5590
 function fixchar__callback($matches)
5273 5591
 {
5274
-	if (!isset($matches[1]))
5275
-		return '';
5592
+	if (!isset($matches[1])) {
5593
+			return '';
5594
+	}
5276 5595
 
5277 5596
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5278 5597
 
5279 5598
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5280 5599
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5281
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5282
-		return '';
5600
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5601
+			return '';
5602
+	}
5283 5603
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5284
-	elseif ($num < 0x80)
5285
-		return chr($num);
5604
+	elseif ($num < 0x80) {
5605
+			return chr($num);
5606
+	}
5286 5607
 	// <0x800 (2048)
5287
-	elseif ($num < 0x800)
5288
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5608
+	elseif ($num < 0x800) {
5609
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5610
+	}
5289 5611
 	// < 0x10000 (65536)
5290
-	elseif ($num < 0x10000)
5291
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5612
+	elseif ($num < 0x10000) {
5613
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5614
+	}
5292 5615
 	// <= 0x10FFFF (1114111)
5293
-	else
5294
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5295
-}
5616
+	else {
5617
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5618
+	}
5619
+	}
5296 5620
 
5297 5621
 /**
5298 5622
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5305,17 +5629,19 @@  discard block
 block discarded – undo
5305 5629
  */
5306 5630
 function entity_fix__callback($matches)
5307 5631
 {
5308
-	if (!isset($matches[2]))
5309
-		return '';
5632
+	if (!isset($matches[2])) {
5633
+			return '';
5634
+	}
5310 5635
 
5311 5636
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5312 5637
 
5313 5638
 	// we don't allow control characters, characters out of range, byte markers, etc
5314
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5315
-		return '';
5316
-	else
5317
-		return '&#' . $num . ';';
5318
-}
5639
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5640
+			return '';
5641
+	} else {
5642
+			return '&#' . $num . ';';
5643
+	}
5644
+	}
5319 5645
 
5320 5646
 /**
5321 5647
  * Return a Gravatar URL based on
@@ -5339,18 +5665,23 @@  discard block
 block discarded – undo
5339 5665
 		$ratings = array('G', 'PG', 'R', 'X');
5340 5666
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5341 5667
 		$url_params = array();
5342
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5343
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5344
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5345
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5346
-		if (!empty($modSettings['avatar_max_width_external']))
5347
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5348
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5349
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5668
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5669
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5670
+		}
5671
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5672
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5673
+		}
5674
+		if (!empty($modSettings['avatar_max_width_external'])) {
5675
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5676
+		}
5677
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5678
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5350 5679
 				$size_string = $modSettings['avatar_max_height_external'];
5680
+		}
5351 5681
 
5352
-		if (!empty($size_string))
5353
-			$url_params[] = 's=' . $size_string;
5682
+		if (!empty($size_string)) {
5683
+					$url_params[] = 's=' . $size_string;
5684
+		}
5354 5685
 	}
5355 5686
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5356 5687
 
@@ -5369,22 +5700,26 @@  discard block
 block discarded – undo
5369 5700
 	static $timezones = null, $lastwhen = null;
5370 5701
 
5371 5702
 	// No point doing this over if we already did it once
5372
-	if (!empty($timezones) && $when == $lastwhen)
5373
-		return $timezones;
5374
-	else
5375
-		$lastwhen = $when;
5703
+	if (!empty($timezones) && $when == $lastwhen) {
5704
+			return $timezones;
5705
+	} else {
5706
+			$lastwhen = $when;
5707
+	}
5376 5708
 
5377 5709
 	// Parseable datetime string?
5378
-	if (is_int($timestamp = strtotime($when)))
5379
-		$when = $timestamp;
5710
+	if (is_int($timestamp = strtotime($when))) {
5711
+			$when = $timestamp;
5712
+	}
5380 5713
 
5381 5714
 	// A Unix timestamp?
5382
-	elseif (is_numeric($when))
5383
-		$when = intval($when);
5715
+	elseif (is_numeric($when)) {
5716
+			$when = intval($when);
5717
+	}
5384 5718
 
5385 5719
 	// Invalid value? Just get current Unix timestamp.
5386
-	else
5387
-		$when = time();
5720
+	else {
5721
+			$when = time();
5722
+	}
5388 5723
 
5389 5724
 	// We'll need these too
5390 5725
 	$date_when = date_create('@' . $when);
@@ -5399,8 +5734,9 @@  discard block
 block discarded – undo
5399 5734
 	foreach ($priority_countries as $country)
5400 5735
 	{
5401 5736
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5402
-		if (!empty($country_tzids))
5403
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5737
+		if (!empty($country_tzids)) {
5738
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5739
+		}
5404 5740
 	}
5405 5741
 
5406 5742
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5414,8 +5750,9 @@  discard block
 block discarded – undo
5414 5750
 	foreach ($tzids as $tzid)
5415 5751
 	{
5416 5752
 		// We don't want UTC right now
5417
-		if ($tzid == 'UTC')
5418
-			continue;
5753
+		if ($tzid == 'UTC') {
5754
+					continue;
5755
+		}
5419 5756
 
5420 5757
 		$tz = timezone_open($tzid);
5421 5758
 
@@ -5436,13 +5773,14 @@  discard block
 block discarded – undo
5436 5773
 		}
5437 5774
 
5438 5775
 		// A time zone from a prioritized country?
5439
-		if (in_array($tzid, $priority_tzids))
5440
-			$priority_zones[$tzkey] = true;
5776
+		if (in_array($tzid, $priority_tzids)) {
5777
+					$priority_zones[$tzkey] = true;
5778
+		}
5441 5779
 
5442 5780
 		// Keep track of the location and offset for this tzid
5443
-		if (!empty($txt[$tzid]))
5444
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5445
-		else
5781
+		if (!empty($txt[$tzid])) {
5782
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5783
+		} else
5446 5784
 		{
5447 5785
 			$tzid_parts = explode('/', $tzid);
5448 5786
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5462,23 +5800,27 @@  discard block
 block discarded – undo
5462 5800
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5463 5801
 
5464 5802
 		// Use the custom description, if there is one
5465
-		if (!empty($tztxt[$tzvalue['tzid']]))
5466
-			$desc = $tztxt[$tzvalue['tzid']];
5803
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5804
+					$desc = $tztxt[$tzvalue['tzid']];
5805
+		}
5467 5806
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5468
-		else
5469
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5807
+		else {
5808
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5809
+		}
5470 5810
 
5471 5811
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5472 5812
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5473 5813
 
5474
-		if (isset($priority_zones[$tzkey]))
5475
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5476
-		else
5477
-			$timezones[$tzvalue['tzid']] = $desc;
5814
+		if (isset($priority_zones[$tzkey])) {
5815
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5816
+		} else {
5817
+					$timezones[$tzvalue['tzid']] = $desc;
5818
+		}
5478 5819
 	}
5479 5820
 
5480
-	if (!empty($priority_timezones))
5481
-		$priority_timezones[] = '-----';
5821
+	if (!empty($priority_timezones)) {
5822
+			$priority_timezones[] = '-----';
5823
+	}
5482 5824
 
5483 5825
 	$timezones = array_merge(
5484 5826
 		$priority_timezones,
@@ -5495,8 +5837,9 @@  discard block
 block discarded – undo
5495 5837
  */
5496 5838
 function inet_ptod($ip_address)
5497 5839
 {
5498
-	if (!isValidIP($ip_address))
5499
-		return $ip_address;
5840
+	if (!isValidIP($ip_address)) {
5841
+			return $ip_address;
5842
+	}
5500 5843
 
5501 5844
 	$bin = inet_pton($ip_address);
5502 5845
 	return $bin;
@@ -5508,13 +5851,15 @@  discard block
 block discarded – undo
5508 5851
  */
5509 5852
 function inet_dtop($bin)
5510 5853
 {
5511
-	if(empty($bin))
5512
-		return '';
5854
+	if(empty($bin)) {
5855
+			return '';
5856
+	}
5513 5857
 
5514 5858
 	global $db_type;
5515 5859
 
5516
-	if ($db_type == 'postgresql')
5517
-		return $bin;
5860
+	if ($db_type == 'postgresql') {
5861
+			return $bin;
5862
+	}
5518 5863
 
5519 5864
 	$ip_address = inet_ntop($bin);
5520 5865
 
@@ -5539,26 +5884,32 @@  discard block
 block discarded – undo
5539 5884
  */
5540 5885
 function _safe_serialize($value)
5541 5886
 {
5542
-	if(is_null($value))
5543
-		return 'N;';
5887
+	if(is_null($value)) {
5888
+			return 'N;';
5889
+	}
5544 5890
 
5545
-	if(is_bool($value))
5546
-		return 'b:'. (int) $value .';';
5891
+	if(is_bool($value)) {
5892
+			return 'b:'. (int) $value .';';
5893
+	}
5547 5894
 
5548
-	if(is_int($value))
5549
-		return 'i:'. $value .';';
5895
+	if(is_int($value)) {
5896
+			return 'i:'. $value .';';
5897
+	}
5550 5898
 
5551
-	if(is_float($value))
5552
-		return 'd:'. str_replace(',', '.', $value) .';';
5899
+	if(is_float($value)) {
5900
+			return 'd:'. str_replace(',', '.', $value) .';';
5901
+	}
5553 5902
 
5554
-	if(is_string($value))
5555
-		return 's:'. strlen($value) .':"'. $value .'";';
5903
+	if(is_string($value)) {
5904
+			return 's:'. strlen($value) .':"'. $value .'";';
5905
+	}
5556 5906
 
5557 5907
 	if(is_array($value))
5558 5908
 	{
5559 5909
 		$out = '';
5560
-		foreach($value as $k => $v)
5561
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5910
+		foreach($value as $k => $v) {
5911
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5912
+		}
5562 5913
 
5563 5914
 		return 'a:'. count($value) .':{'. $out .'}';
5564 5915
 	}
@@ -5584,8 +5935,9 @@  discard block
 block discarded – undo
5584 5935
 
5585 5936
 	$out = _safe_serialize($value);
5586 5937
 
5587
-	if (isset($mbIntEnc))
5588
-		mb_internal_encoding($mbIntEnc);
5938
+	if (isset($mbIntEnc)) {
5939
+			mb_internal_encoding($mbIntEnc);
5940
+	}
5589 5941
 
5590 5942
 	return $out;
5591 5943
 }
@@ -5602,8 +5954,9 @@  discard block
 block discarded – undo
5602 5954
 function _safe_unserialize($str)
5603 5955
 {
5604 5956
 	// Input  is not a string.
5605
-	if(empty($str) || !is_string($str))
5606
-		return false;
5957
+	if(empty($str) || !is_string($str)) {
5958
+			return false;
5959
+	}
5607 5960
 
5608 5961
 	$stack = array();
5609 5962
 	$expected = array();
@@ -5619,43 +5972,38 @@  discard block
 block discarded – undo
5619 5972
 	while($state != 1)
5620 5973
 	{
5621 5974
 		$type = isset($str[0]) ? $str[0] : '';
5622
-		if($type == '}')
5623
-			$str = substr($str, 1);
5624
-
5625
-		else if($type == 'N' && $str[1] == ';')
5975
+		if($type == '}') {
5976
+					$str = substr($str, 1);
5977
+		} else if($type == 'N' && $str[1] == ';')
5626 5978
 		{
5627 5979
 			$value = null;
5628 5980
 			$str = substr($str, 2);
5629
-		}
5630
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5981
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5631 5982
 		{
5632 5983
 			$value = $matches[1] == '1' ? true : false;
5633 5984
 			$str = substr($str, 4);
5634
-		}
5635
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5985
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5636 5986
 		{
5637 5987
 			$value = (int)$matches[1];
5638 5988
 			$str = $matches[2];
5639
-		}
5640
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5989
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5641 5990
 		{
5642 5991
 			$value = (float)$matches[1];
5643 5992
 			$str = $matches[3];
5644
-		}
5645
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5993
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5646 5994
 		{
5647 5995
 			$value = substr($matches[2], 0, (int)$matches[1]);
5648 5996
 			$str = substr($matches[2], (int)$matches[1] + 2);
5649
-		}
5650
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5997
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5651 5998
 		{
5652 5999
 			$expectedLength = (int)$matches[1];
5653 6000
 			$str = $matches[2];
5654 6001
 		}
5655 6002
 
5656 6003
 		// Object or unknown/malformed type.
5657
-		else
5658
-			return false;
6004
+		else {
6005
+					return false;
6006
+		}
5659 6007
 
5660 6008
 		switch($state)
5661 6009
 		{
@@ -5683,8 +6031,9 @@  discard block
 block discarded – undo
5683 6031
 				if($type == '}')
5684 6032
 				{
5685 6033
 					// Array size is less than expected.
5686
-					if(count($list) < end($expected))
5687
-						return false;
6034
+					if(count($list) < end($expected)) {
6035
+											return false;
6036
+					}
5688 6037
 
5689 6038
 					unset($list);
5690 6039
 					$list = &$stack[count($stack)-1];
@@ -5693,8 +6042,9 @@  discard block
 block discarded – undo
5693 6042
 					// Go to terminal state if we're at the end of the root array.
5694 6043
 					array_pop($expected);
5695 6044
 
5696
-					if(count($expected) == 0)
5697
-						$state = 1;
6045
+					if(count($expected) == 0) {
6046
+											$state = 1;
6047
+					}
5698 6048
 
5699 6049
 					break;
5700 6050
 				}
@@ -5702,8 +6052,9 @@  discard block
 block discarded – undo
5702 6052
 				if($type == 'i' || $type == 's')
5703 6053
 				{
5704 6054
 					// Array size exceeds expected length.
5705
-					if(count($list) >= end($expected))
5706
-						return false;
6055
+					if(count($list) >= end($expected)) {
6056
+											return false;
6057
+					}
5707 6058
 
5708 6059
 					$key = $value;
5709 6060
 					$state = 3;
@@ -5737,8 +6088,9 @@  discard block
 block discarded – undo
5737 6088
 	}
5738 6089
 
5739 6090
 	// Trailing data in input.
5740
-	if(!empty($str))
5741
-		return false;
6091
+	if(!empty($str)) {
6092
+			return false;
6093
+	}
5742 6094
 
5743 6095
 	return $data;
5744 6096
 }
@@ -5761,8 +6113,9 @@  discard block
 block discarded – undo
5761 6113
 
5762 6114
 	$out = _safe_unserialize($str);
5763 6115
 
5764
-	if (isset($mbIntEnc))
5765
-		mb_internal_encoding($mbIntEnc);
6116
+	if (isset($mbIntEnc)) {
6117
+			mb_internal_encoding($mbIntEnc);
6118
+	}
5766 6119
 
5767 6120
 	return $out;
5768 6121
 }
@@ -5777,12 +6130,14 @@  discard block
 block discarded – undo
5777 6130
 function smf_chmod($file, $value = 0)
5778 6131
 {
5779 6132
 	// No file? no checks!
5780
-	if (empty($file))
5781
-		return false;
6133
+	if (empty($file)) {
6134
+			return false;
6135
+	}
5782 6136
 
5783 6137
 	// Already writable?
5784
-	if (is_writable($file))
5785
-		return true;
6138
+	if (is_writable($file)) {
6139
+			return true;
6140
+	}
5786 6141
 
5787 6142
 	// Do we have a file or a dir?
5788 6143
 	$isDir = is_dir($file);
@@ -5798,10 +6153,9 @@  discard block
 block discarded – undo
5798 6153
 		{
5799 6154
 			$isWritable = true;
5800 6155
 			break;
6156
+		} else {
6157
+					@chmod($file, $val);
5801 6158
 		}
5802
-
5803
-		else
5804
-			@chmod($file, $val);
5805 6159
 	}
5806 6160
 
5807 6161
 	return $isWritable;
@@ -5820,8 +6174,9 @@  discard block
 block discarded – undo
5820 6174
 	global $txt;
5821 6175
 
5822 6176
 	// Come on...
5823
-	if (empty($json) || !is_string($json))
5824
-		return array();
6177
+	if (empty($json) || !is_string($json)) {
6178
+			return array();
6179
+	}
5825 6180
 
5826 6181
 	$returnArray = @json_decode($json, $returnAsArray);
5827 6182
 
@@ -5859,11 +6214,11 @@  discard block
 block discarded – undo
5859 6214
 		$jsonDebug = $jsonDebug[0];
5860 6215
 		loadLanguage('Errors');
5861 6216
 
5862
-		if (!empty($jsonDebug))
5863
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5864
-
5865
-		else
5866
-			log_error($txt['json_'. $jsonError], 'critical');
6217
+		if (!empty($jsonDebug)) {
6218
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6219
+		} else {
6220
+					log_error($txt['json_'. $jsonError], 'critical');
6221
+		}
5867 6222
 
5868 6223
 		// Everyone expects an array.
5869 6224
 		return array();
@@ -5897,8 +6252,9 @@  discard block
 block discarded – undo
5897 6252
 	global $db_show_debug, $modSettings;
5898 6253
 
5899 6254
 	// Defensive programming anyone?
5900
-	if (empty($data))
5901
-		return false;
6255
+	if (empty($data)) {
6256
+			return false;
6257
+	}
5902 6258
 
5903 6259
 	// Don't need extra stuff...
5904 6260
 	$db_show_debug = false;
@@ -5906,11 +6262,11 @@  discard block
 block discarded – undo
5906 6262
 	// Kill anything else.
5907 6263
 	ob_end_clean();
5908 6264
 
5909
-	if (!empty($modSettings['CompressedOutput']))
5910
-		@ob_start('ob_gzhandler');
5911
-
5912
-	else
5913
-		ob_start();
6265
+	if (!empty($modSettings['CompressedOutput'])) {
6266
+			@ob_start('ob_gzhandler');
6267
+	} else {
6268
+			ob_start();
6269
+	}
5914 6270
 
5915 6271
 	// Set the header.
5916 6272
 	header($type);
@@ -5942,8 +6298,9 @@  discard block
 block discarded – undo
5942 6298
 	static $done = false;
5943 6299
 
5944 6300
 	// If we don't need to do anything, don't
5945
-	if (!$update && $done)
5946
-		return;
6301
+	if (!$update && $done) {
6302
+			return;
6303
+	}
5947 6304
 
5948 6305
 	// Should we get a new copy of the official list of TLDs?
5949 6306
 	if ($update)
@@ -5955,8 +6312,9 @@  discard block
 block discarded – undo
5955 6312
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
5956 6313
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
5957 6314
 		// update to see if civilization has been restored.
5958
-		if ($tlds === false)
5959
-			$postapocalypticNightmare = true;
6315
+		if ($tlds === false) {
6316
+					$postapocalypticNightmare = true;
6317
+		}
5960 6318
 	}
5961 6319
 	// If we aren't updating and the regex is valid, we're done
5962 6320
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -5971,10 +6329,11 @@  discard block
 block discarded – undo
5971 6329
 		// Clean $tlds and convert it to an array
5972 6330
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5973 6331
 			$line = trim($line);
5974
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5975
-				return false;
5976
-			else
5977
-				return true;
6332
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6333
+							return false;
6334
+			} else {
6335
+							return true;
6336
+			}
5978 6337
 		});
5979 6338
 
5980 6339
 		// Convert Punycode to Unicode
@@ -6066,8 +6425,7 @@  discard block
 block discarded – undo
6066 6425
 
6067 6426
 		$strlen = 'mb_strlen';
6068 6427
 		$substr = 'mb_substr';
6069
-	}
6070
-	else
6428
+	} else
6071 6429
 	{
6072 6430
 		$strlen = $smcFunc['strlen'];
6073 6431
 		$substr = $smcFunc['substr'];
@@ -6081,20 +6439,21 @@  discard block
 block discarded – undo
6081 6439
 
6082 6440
 		$first = $substr($string, 0, 1);
6083 6441
 
6084
-		if (empty($index[$first]))
6085
-			$index[$first] = array();
6442
+		if (empty($index[$first])) {
6443
+					$index[$first] = array();
6444
+		}
6086 6445
 
6087 6446
 		if ($strlen($string) > 1)
6088 6447
 		{
6089 6448
 			// Sanity check on recursion
6090
-			if ($depth > 99)
6091
-				$index[$first][$substr($string, 1)] = '';
6092
-
6093
-			else
6094
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6449
+			if ($depth > 99) {
6450
+							$index[$first][$substr($string, 1)] = '';
6451
+			} else {
6452
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6453
+			}
6454
+		} else {
6455
+					$index[$first][''] = '';
6095 6456
 		}
6096
-		else
6097
-			$index[$first][''] = '';
6098 6457
 
6099 6458
 		$depth--;
6100 6459
 		return $index;
@@ -6117,9 +6476,9 @@  discard block
 block discarded – undo
6117 6476
 			$key_regex = preg_quote($key, $delim);
6118 6477
 			$new_key = $key;
6119 6478
 
6120
-			if (empty($value))
6121
-				$sub_regex = '';
6122
-			else
6479
+			if (empty($value)) {
6480
+							$sub_regex = '';
6481
+			} else
6123 6482
 			{
6124 6483
 				$sub_regex = $index_to_regex($value, $delim);
6125 6484
 
@@ -6127,22 +6486,22 @@  discard block
 block discarded – undo
6127 6486
 				{
6128 6487
 					$new_key_array = explode('(?'.'>', $sub_regex);
6129 6488
 					$new_key .= $new_key_array[0];
6489
+				} else {
6490
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6130 6491
 				}
6131
-				else
6132
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6133 6492
 			}
6134 6493
 
6135
-			if ($depth > 1)
6136
-				$regex[$new_key] = $key_regex . $sub_regex;
6137
-			else
6494
+			if ($depth > 1) {
6495
+							$regex[$new_key] = $key_regex . $sub_regex;
6496
+			} else
6138 6497
 			{
6139 6498
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6140 6499
 				{
6141 6500
 					$regex[$new_key] = $key_regex . $sub_regex;
6142 6501
 					unset($index[$key]);
6502
+				} else {
6503
+									break;
6143 6504
 				}
6144
-				else
6145
-					break;
6146 6505
 			}
6147 6506
 		}
6148 6507
 
@@ -6151,10 +6510,11 @@  discard block
 block discarded – undo
6151 6510
 			$l1 = $strlen($k1);
6152 6511
 			$l2 = $strlen($k2);
6153 6512
 
6154
-			if ($l1 == $l2)
6155
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6156
-			else
6157
-				return $l1 > $l2 ? -1 : 1;
6513
+			if ($l1 == $l2) {
6514
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6515
+			} else {
6516
+							return $l1 > $l2 ? -1 : 1;
6517
+			}
6158 6518
 		});
6159 6519
 
6160 6520
 		$depth--;
@@ -6165,21 +6525,24 @@  discard block
 block discarded – undo
6165 6525
 	$index = array();
6166 6526
 	$regex = '';
6167 6527
 
6168
-	foreach ($strings as $string)
6169
-		$index = $add_string_to_index($string, $index);
6528
+	foreach ($strings as $string) {
6529
+			$index = $add_string_to_index($string, $index);
6530
+	}
6170 6531
 
6171 6532
 	if ($returnArray === true)
6172 6533
 	{
6173 6534
 		$regex = array();
6174
-		while (!empty($index))
6175
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6535
+		while (!empty($index)) {
6536
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6537
+		}
6538
+	} else {
6539
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6176 6540
 	}
6177
-	else
6178
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6179 6541
 
6180 6542
 	// Restore PHP's internal character encoding to whatever it was originally
6181
-	if (!empty($current_encoding))
6182
-		mb_internal_encoding($current_encoding);
6543
+	if (!empty($current_encoding)) {
6544
+			mb_internal_encoding($current_encoding);
6545
+	}
6183 6546
 
6184 6547
 	return $regex;
6185 6548
 }
@@ -6222,13 +6585,15 @@  discard block
 block discarded – undo
6222 6585
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6223 6586
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6224 6587
 	$headers = @get_headers($url);
6225
-	if ($headers === false)
6226
-		return false;
6588
+	if ($headers === false) {
6589
+			return false;
6590
+	}
6227 6591
 
6228 6592
 	// Now to see if it came back https...
6229 6593
 	// First check for a redirect status code in first row (301, 302, 307)
6230
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6231
-		return false;
6594
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6595
+			return false;
6596
+	}
6232 6597
 
6233 6598
 	// Search for the location entry to confirm https
6234 6599
 	$result = false;
@@ -6266,8 +6631,7 @@  discard block
 block discarded – undo
6266 6631
 		$is_admin = $user_info['is_admin'];
6267 6632
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6268 6633
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6269
-	}
6270
-	else
6634
+	} else
6271 6635
 	{
6272 6636
 		$request = $smcFunc['db_query']('', '
6273 6637
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6281,17 +6645,19 @@  discard block
 block discarded – undo
6281 6645
 
6282 6646
 		$row = $smcFunc['db_fetch_assoc']($request);
6283 6647
 
6284
-		if (empty($row['additional_groups']))
6285
-			$groups = array($row['id_group'], $row['id_post_group']);
6286
-		else
6287
-			$groups = array_merge(
6648
+		if (empty($row['additional_groups'])) {
6649
+					$groups = array($row['id_group'], $row['id_post_group']);
6650
+		} else {
6651
+					$groups = array_merge(
6288 6652
 					array($row['id_group'], $row['id_post_group']),
6289 6653
 					explode(',', $row['additional_groups'])
6290 6654
 			);
6655
+		}
6291 6656
 
6292 6657
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6293
-		foreach ($groups as $k => $v)
6294
-			$groups[$k] = (int) $v;
6658
+		foreach ($groups as $k => $v) {
6659
+					$groups[$k] = (int) $v;
6660
+		}
6295 6661
 
6296 6662
 		$is_admin = in_array(1, $groups);
6297 6663
 
@@ -6308,8 +6674,9 @@  discard block
 block discarded – undo
6308 6674
 				'current_member' => $userid,
6309 6675
 			)
6310 6676
 		);
6311
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6312
-			$boards_mod[] = $row['id_board'];
6677
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6678
+					$boards_mod[] = $row['id_board'];
6679
+		}
6313 6680
 		$smcFunc['db_free_result']($request);
6314 6681
 
6315 6682
 		// Can any of the groups they're in moderate any of the boards?
@@ -6321,8 +6688,9 @@  discard block
 block discarded – undo
6321 6688
 				'groups' => $groups,
6322 6689
 			)
6323 6690
 		);
6324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6325
-			$boards_mod[] = $row['id_board'];
6691
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6692
+					$boards_mod[] = $row['id_board'];
6693
+		}
6326 6694
 		$smcFunc['db_free_result']($request);
6327 6695
 
6328 6696
 		// Just in case we've got duplicates here...
@@ -6332,21 +6700,25 @@  discard block
 block discarded – undo
6332 6700
 	}
6333 6701
 
6334 6702
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6335
-	if ($is_admin)
6336
-		$query_part['query_see_board'] = '1=1';
6703
+	if ($is_admin) {
6704
+			$query_part['query_see_board'] = '1=1';
6705
+	}
6337 6706
 	// Otherwise just the groups in $user_info['groups'].
6338
-	else
6339
-		$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'] : '') . ')';
6707
+	else {
6708
+			$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'] : '') . ')';
6709
+	}
6340 6710
 
6341 6711
 	// Build the list of boards they WANT to see.
6342 6712
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6343 6713
 
6344 6714
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6345
-	if (empty($ignoreboards))
6346
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6715
+	if (empty($ignoreboards)) {
6716
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6717
+	}
6347 6718
 	// Ok I guess they don't want to see all the boards
6348
-	else
6349
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6719
+	else {
6720
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6721
+	}
6350 6722
 
6351 6723
 	return $query_part;
6352 6724
 }
@@ -6360,10 +6732,11 @@  discard block
 block discarded – undo
6360 6732
 {
6361 6733
 	$secure = false;
6362 6734
 
6363
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6364
-		$secure = true;
6365
-	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')
6366
-		$secure = true;
6735
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6736
+			$secure = true;
6737
+	} 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') {
6738
+			$secure = true;
6739
+	}
6367 6740
 
6368 6741
 	return $secure;
6369 6742
 }
@@ -6380,11 +6753,12 @@  discard block
 block discarded – undo
6380 6753
 {
6381 6754
 	$url = iri_to_url($iri);
6382 6755
 
6383
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6384
-		return $iri;
6385
-	else
6386
-		return false;
6387
-}
6756
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6757
+			return $iri;
6758
+	} else {
6759
+			return false;
6760
+	}
6761
+	}
6388 6762
 
6389 6763
 /**
6390 6764
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6427,8 +6801,9 @@  discard block
 block discarded – undo
6427 6801
 
6428 6802
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6429 6803
 
6430
-	if (empty($host))
6431
-		return $iri;
6804
+	if (empty($host)) {
6805
+			return $iri;
6806
+	}
6432 6807
 
6433 6808
 	// Convert the domain using the Punycode algorithm
6434 6809
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6464,8 +6839,9 @@  discard block
 block discarded – undo
6464 6839
 
6465 6840
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6466 6841
 
6467
-	if (empty($host))
6468
-		return $url;
6842
+	if (empty($host)) {
6843
+			return $url;
6844
+	}
6469 6845
 
6470 6846
 	// Decode the domain from Punycode
6471 6847
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6491,8 +6867,9 @@  discard block
 block discarded – undo
6491 6867
 {
6492 6868
 	global $user_info, $modSettings, $smcFunc, $txt;
6493 6869
 
6494
-	if (empty($modSettings['cron_last_checked']))
6495
-		$modSettings['cron_last_checked'] = 0;
6870
+	if (empty($modSettings['cron_last_checked'])) {
6871
+			$modSettings['cron_last_checked'] = 0;
6872
+	}
6496 6873
 
6497 6874
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6498 6875
 	{
@@ -6512,9 +6889,9 @@  discard block
 block discarded – undo
6512 6889
 			loadLanguage('ManageScheduledTasks');
6513 6890
 			log_error($txt['cron_not_working']);
6514 6891
 			updateSettings(array('cron_is_real_cron' => 0));
6892
+		} else {
6893
+					updateSettings(array('cron_last_checked' => time()));
6515 6894
 		}
6516
-		else
6517
-			updateSettings(array('cron_last_checked' => time()));
6518 6895
 	}
6519 6896
 }
6520 6897
 
Please login to merge, or discard this patch.
Sources/ManageBoards.php 1 patch
Braces   +150 added lines, -116 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
  * The main dispatcher; doesn't do anything, just delegates.
@@ -92,18 +93,19 @@  discard block
 block discarded – undo
92 93
 		checkSession('get');
93 94
 		validateToken('admin-bm-' . (int) $_REQUEST['src_board'], 'request');
94 95
 
95
-		if ($_REQUEST['move_to'] === 'top')
96
-			$boardOptions = array(
96
+		if ($_REQUEST['move_to'] === 'top') {
97
+					$boardOptions = array(
97 98
 				'move_to' => $_REQUEST['move_to'],
98 99
 				'target_category' => (int) $_REQUEST['target_cat'],
99 100
 				'move_first_child' => true,
100 101
 			);
101
-		else
102
-			$boardOptions = array(
102
+		} else {
103
+					$boardOptions = array(
103 104
 				'move_to' => $_REQUEST['move_to'],
104 105
 				'target_board' => (int) $_REQUEST['target_board'],
105 106
 				'move_first_child' => true,
106 107
 			);
108
+		}
107 109
 		modifyBoard((int) $_REQUEST['src_board'], $boardOptions);
108 110
 	}
109 111
 
@@ -148,15 +150,16 @@  discard block
 block discarded – undo
148 150
 			$security = $context['session_var'] . '=' . $context['session_id'] . ';' . $context['admin-bm-' . $context['move_board'] . '_token_var'] . '=' . $context['admin-bm-' . $context['move_board'] . '_token'];
149 151
 			foreach ($boardList[$catid] as $boardid)
150 152
 			{
151
-				if (!isset($context['categories'][$catid]['move_link']))
152
-					$context['categories'][$catid]['move_link'] = array(
153
+				if (!isset($context['categories'][$catid]['move_link'])) {
154
+									$context['categories'][$catid]['move_link'] = array(
153 155
 						'child_level' => 0,
154 156
 						'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
155 157
 						'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_board=' . $boardid . ';move_to=before;' . $security,
156 158
 					);
159
+				}
157 160
 
158
-				if (!$context['categories'][$catid]['boards'][$boardid]['move'])
159
-				$context['categories'][$catid]['boards'][$boardid]['move_links'] = array(
161
+				if (!$context['categories'][$catid]['boards'][$boardid]['move']) {
162
+								$context['categories'][$catid]['boards'][$boardid]['move_links'] = array(
160 163
 					array(
161 164
 						'child_level' => $boards[$boardid]['level'],
162 165
 						'label' => $txt['mboards_order_after'] . '\'' . $smcFunc['htmlspecialchars']($boards[$boardid]['name']) . '\'',
@@ -170,33 +173,38 @@  discard block
 block discarded – undo
170 173
 						'class' => 'here',
171 174
 					),
172 175
 				);
176
+				}
173 177
 
174 178
 				$difference = $boards[$boardid]['level'] - $prev_child_level;
175
-				if ($difference == 1)
176
-					array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null);
177
-				elseif ($difference < 0)
179
+				if ($difference == 1) {
180
+									array_push($stack, !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']) ? array_shift($context['categories'][$catid]['boards'][$prev_board]['move_links']) : null);
181
+				} elseif ($difference < 0)
178 182
 				{
179
-					if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
180
-						$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array();
181
-					for ($i = 0; $i < -$difference; $i++)
182
-						if (($temp = array_pop($stack)) != null)
183
+					if (empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) {
184
+											$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array();
185
+					}
186
+					for ($i = 0; $i < -$difference; $i++) {
187
+											if (($temp = array_pop($stack)) != null)
183 188
 							array_unshift($context['categories'][$catid]['boards'][$prev_board]['move_links'], $temp);
189
+					}
184 190
 				}
185 191
 
186 192
 				$prev_board = $boardid;
187 193
 				$prev_child_level = $boards[$boardid]['level'];
188 194
 			}
189
-			if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links']))
190
-				$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']);
191
-			elseif (!empty($stack))
192
-				$context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack;
195
+			if (!empty($stack) && !empty($context['categories'][$catid]['boards'][$prev_board]['move_links'])) {
196
+							$context['categories'][$catid]['boards'][$prev_board]['move_links'] = array_merge($stack, $context['categories'][$catid]['boards'][$prev_board]['move_links']);
197
+			} elseif (!empty($stack)) {
198
+							$context['categories'][$catid]['boards'][$prev_board]['move_links'] = $stack;
199
+			}
193 200
 
194
-			if (empty($boardList[$catid]))
195
-				$context['categories'][$catid]['move_link'] = array(
201
+			if (empty($boardList[$catid])) {
202
+							$context['categories'][$catid]['move_link'] = array(
196 203
 					'child_level' => 0,
197 204
 					'label' => $txt['mboards_order_before'] . ' \'' . $smcFunc['htmlspecialchars']($tree['node']['name']) . '\'',
198 205
 					'href' => $scripturl . '?action=admin;area=manageboards;sa=move;src_board=' . $context['move_board'] . ';target_cat=' . $catid . ';move_to=top;' . $security,
199 206
 				);
207
+			}
200 208
 		}
201 209
 	}
202 210
 
@@ -252,9 +260,9 @@  discard block
 block discarded – undo
252 260
 		);
253 261
 	}
254 262
 	// Category doesn't exist, man... sorry.
255
-	elseif (!isset($cat_tree[$_REQUEST['cat']]))
256
-		redirectexit('action=admin;area=manageboards');
257
-	else
263
+	elseif (!isset($cat_tree[$_REQUEST['cat']])) {
264
+			redirectexit('action=admin;area=manageboards');
265
+	} else
258 266
 	{
259 267
 		$context['category'] = array(
260 268
 			'id' => $_REQUEST['cat'],
@@ -266,30 +274,31 @@  discard block
 block discarded – undo
266 274
 			'is_empty' => empty($cat_tree[$_REQUEST['cat']]['children'])
267 275
 		);
268 276
 
269
-		foreach ($boardList[$_REQUEST['cat']] as $child_board)
270
-			$context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name'];
277
+		foreach ($boardList[$_REQUEST['cat']] as $child_board) {
278
+					$context['category']['children'][] = str_repeat('-', $boards[$child_board]['level']) . ' ' . $boards[$child_board]['name'];
279
+		}
271 280
 	}
272 281
 
273 282
 	$prevCat = 0;
274 283
 	foreach ($cat_tree as $catid => $tree)
275 284
 	{
276
-		if ($catid == $_REQUEST['cat'] && $prevCat > 0)
277
-			$context['category_order'][$prevCat]['selected'] = true;
278
-		elseif ($catid != $_REQUEST['cat'])
279
-			$context['category_order'][$catid] = array(
285
+		if ($catid == $_REQUEST['cat'] && $prevCat > 0) {
286
+					$context['category_order'][$prevCat]['selected'] = true;
287
+		} elseif ($catid != $_REQUEST['cat']) {
288
+					$context['category_order'][$catid] = array(
280 289
 				'id' => $catid,
281 290
 				'name' => $txt['mboards_order_after'] . $tree['node']['name'],
282 291
 				'selected' => false,
283 292
 				'true_name' => $tree['node']['name']
284 293
 			);
294
+		}
285 295
 		$prevCat = $catid;
286 296
 	}
287 297
 	if (!isset($_REQUEST['delete']))
288 298
 	{
289 299
 		$context['sub_template'] = 'modify_category';
290 300
 		$context['page_title'] = $_REQUEST['sa'] == 'newcat' ? $txt['mboards_new_cat_name'] : $txt['catEdit'];
291
-	}
292
-	else
301
+	} else
293 302
 	{
294 303
 		$context['sub_template'] = 'confirm_category_delete';
295 304
 		$context['page_title'] = $txt['mboards_delete_cat'];
@@ -326,8 +335,9 @@  discard block
 block discarded – undo
326 335
 	{
327 336
 		$catOptions = array();
328 337
 
329
-		if (isset($_POST['cat_order']))
330
-			$catOptions['move_after'] = (int) $_POST['cat_order'];
338
+		if (isset($_POST['cat_order'])) {
339
+					$catOptions['move_after'] = (int) $_POST['cat_order'];
340
+		}
331 341
 
332 342
 		// Change "This & That" to "This &amp; That" but don't change "&cent" to "&amp;cent;"...
333 343
 		$catOptions['cat_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['cat_name']), false, '', $context['description_allowed_tags']);
@@ -335,10 +345,11 @@  discard block
 block discarded – undo
335 345
 
336 346
 		$catOptions['is_collapsible'] = isset($_POST['collapse']);
337 347
 
338
-		if (isset($_POST['add']))
339
-			createCategory($catOptions);
340
-		else
341
-			modifyCategory($_POST['cat'], $catOptions);
348
+		if (isset($_POST['add'])) {
349
+					createCategory($catOptions);
350
+		} else {
351
+					modifyCategory($_POST['cat'], $catOptions);
352
+		}
342 353
 	}
343 354
 	// If they want to delete - first give them confirmation.
344 355
 	elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['empty']))
@@ -352,13 +363,14 @@  discard block
 block discarded – undo
352 363
 		// First off - check if we are moving all the current boards first - before we start deleting!
353 364
 		if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
354 365
 		{
355
-			if (empty($_POST['cat_to']))
356
-				fatal_lang_error('mboards_delete_error');
366
+			if (empty($_POST['cat_to'])) {
367
+							fatal_lang_error('mboards_delete_error');
368
+			}
357 369
 
358 370
 			deleteCategories(array($_POST['cat']), (int) $_POST['cat_to']);
371
+		} else {
372
+					deleteCategories(array($_POST['cat']));
359 373
 		}
360
-		else
361
-			deleteCategories(array($_POST['cat']));
362 374
 	}
363 375
 
364 376
 	redirectexit('action=admin;area=manageboards');
@@ -403,8 +415,9 @@  discard block
 block discarded – undo
403 415
 	if ($_REQUEST['sa'] == 'newboard')
404 416
 	{
405 417
 		// Category doesn't exist, man... sorry.
406
-		if (empty($_REQUEST['cat']))
407
-			redirectexit('action=admin;area=manageboards');
418
+		if (empty($_REQUEST['cat'])) {
419
+					redirectexit('action=admin;area=manageboards');
420
+		}
408 421
 
409 422
 		// Some things that need to be setup for a new board.
410 423
 		$curBoard = array(
@@ -428,8 +441,7 @@  discard block
 block discarded – undo
428 441
 			'category' => (int) $_REQUEST['cat'],
429 442
 			'no_children' => true,
430 443
 		);
431
-	}
432
-	else
444
+	} else
433 445
 	{
434 446
 		// Just some easy shortcuts.
435 447
 		$curBoard = &$boards[$_REQUEST['boardid']];
@@ -477,8 +489,9 @@  discard block
 block discarded – undo
477 489
 	);
478 490
 	while ($row = $smcFunc['db_fetch_assoc']($request))
479 491
 	{
480
-		if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1)
481
-			$curBoard['member_groups'][] = $row['id_group'];
492
+		if ($_REQUEST['sa'] == 'newboard' && $row['min_posts'] == -1) {
493
+					$curBoard['member_groups'][] = $row['id_group'];
494
+		}
482 495
 
483 496
 		$context['groups'][(int) $row['id_group']] = array(
484 497
 			'id' => $row['id_group'],
@@ -491,8 +504,9 @@  discard block
 block discarded – undo
491 504
 	$smcFunc['db_free_result']($request);
492 505
 
493 506
 	// Category doesn't exist, man... sorry.
494
-	if (!isset($boardList[$curBoard['category']]))
495
-		redirectexit('action=admin;area=manageboards');
507
+	if (!isset($boardList[$curBoard['category']])) {
508
+			redirectexit('action=admin;area=manageboards');
509
+	}
496 510
 
497 511
 	foreach ($boardList[$curBoard['category']] as $boardid)
498 512
 	{
@@ -506,8 +520,7 @@  discard block
 block discarded – undo
506 520
 				'is_child' => false,
507 521
 				'selected' => true
508 522
 			);
509
-		}
510
-		else
523
+		} else
511 524
 		{
512 525
 			$context['board_order'][] = array(
513 526
 				'id' => $boardid,
@@ -524,19 +537,21 @@  discard block
 block discarded – undo
524 537
 		$context['can_move_children'] = false;
525 538
 		$context['children'] = $boards[$_REQUEST['boardid']]['tree']['children'];
526 539
 
527
-		foreach ($context['board_order'] as $lBoard)
528
-			if ($lBoard['is_child'] == false && $lBoard['selected'] == false)
540
+		foreach ($context['board_order'] as $lBoard) {
541
+					if ($lBoard['is_child'] == false && $lBoard['selected'] == false)
529 542
 				$context['can_move_children'] = true;
543
+		}
530 544
 	}
531 545
 
532 546
 	// Get other available categories.
533 547
 	$context['categories'] = array();
534
-	foreach ($cat_tree as $catID => $tree)
535
-		$context['categories'][] = array(
548
+	foreach ($cat_tree as $catID => $tree) {
549
+			$context['categories'][] = array(
536 550
 			'id' => $catID == $curBoard['category'] ? 0 : $catID,
537 551
 			'name' => $tree['node']['name'],
538 552
 			'selected' => $catID == $curBoard['category']
539 553
 		);
554
+	}
540 555
 
541 556
 	$request = $smcFunc['db_query']('', '
542 557
 		SELECT mem.id_member, mem.real_name
@@ -548,14 +563,16 @@  discard block
 block discarded – undo
548 563
 		)
549 564
 	);
550 565
 	$context['board']['moderators'] = array();
551
-	while ($row = $smcFunc['db_fetch_assoc']($request))
552
-		$context['board']['moderators'][$row['id_member']] = $row['real_name'];
566
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
567
+			$context['board']['moderators'][$row['id_member']] = $row['real_name'];
568
+	}
553 569
 	$smcFunc['db_free_result']($request);
554 570
 
555 571
 	$context['board']['moderator_list'] = empty($context['board']['moderators']) ? '' : '&quot;' . implode('&quot;, &quot;', $context['board']['moderators']) . '&quot;';
556 572
 
557
-	if (!empty($context['board']['moderators']))
558
-		list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
573
+	if (!empty($context['board']['moderators'])) {
574
+			list ($context['board']['last_moderator_id']) = array_slice(array_keys($context['board']['moderators']), -1);
575
+	}
559 576
 
560 577
 	// Get all the groups assigned as moderators
561 578
 	$request = $smcFunc['db_query']('', '
@@ -567,14 +584,16 @@  discard block
 block discarded – undo
567 584
 		)
568 585
 	);
569 586
 	$context['board']['moderator_groups'] = array();
570
-	while ($row = $smcFunc['db_fetch_assoc']($request))
571
-		$context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name'];
587
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
588
+			$context['board']['moderator_groups'][$row['id_group']] = $context['groups'][$row['id_group']]['name'];
589
+	}
572 590
 	$smcFunc['db_free_result']($request);
573 591
 
574 592
 	$context['board']['moderator_groups_list'] = empty($context['board']['moderator_groups']) ? '' : '&quot;' . implode('&quot;, &qout;', $context['board']['moderator_groups']) . '&quot;';
575 593
 
576
-	if (!empty($context['board']['moderator_groups']))
577
-		list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1);
594
+	if (!empty($context['board']['moderator_groups'])) {
595
+			list ($context['board']['last_moderator_group_id']) = array_slice(array_keys($context['board']['moderator_groups']), -1);
596
+	}
578 597
 
579 598
 	// Get all the themes...
580 599
 	$request = $smcFunc['db_query']('', '
@@ -586,8 +605,9 @@  discard block
 block discarded – undo
586 605
 		)
587 606
 	);
588 607
 	$context['themes'] = array();
589
-	while ($row = $smcFunc['db_fetch_assoc']($request))
590
-		$context['themes'][] = $row;
608
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
609
+			$context['themes'][] = $row;
610
+	}
591 611
 	$smcFunc['db_free_result']($request);
592 612
 
593 613
 	if (!isset($_REQUEST['delete']))
@@ -595,8 +615,7 @@  discard block
 block discarded – undo
595 615
 		$context['sub_template'] = 'modify_board';
596 616
 		$context['page_title'] = $txt['boardsEdit'];
597 617
 		loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest');
598
-	}
599
-	else
618
+	} else
600 619
 	{
601 620
 		$context['sub_template'] = 'confirm_board_delete';
602 621
 		$context['page_title'] = $txt['mboards_delete_board'];
@@ -640,8 +659,9 @@  discard block
 block discarded – undo
640 659
 		// Change the boardorder of this board?
641 660
 		elseif (!empty($_POST['placement']) && !empty($_POST['board_order']))
642 661
 		{
643
-			if (!in_array($_POST['placement'], array('before', 'after', 'child')))
644
-				fatal_lang_error('mangled_post', false);
662
+			if (!in_array($_POST['placement'], array('before', 'after', 'child'))) {
663
+							fatal_lang_error('mangled_post', false);
664
+			}
645 665
 
646 666
 			$boardOptions['move_to'] = $_POST['placement'];
647 667
 			$boardOptions['target_board'] = (int) $_POST['board_order'];
@@ -654,13 +674,14 @@  discard block
 block discarded – undo
654 674
 		$boardOptions['access_groups'] = array();
655 675
 		$boardOptions['deny_groups'] = array();
656 676
 
657
-		if (!empty($_POST['groups']))
658
-			foreach ($_POST['groups'] as $group => $action)
677
+		if (!empty($_POST['groups'])) {
678
+					foreach ($_POST['groups'] as $group => $action)
659 679
 			{
660 680
 				if ($action == 'allow')
661 681
 					$boardOptions['access_groups'][] = (int) $group;
662
-				elseif ($action == 'deny')
663
-					$boardOptions['deny_groups'][] = (int) $group;
682
+		} elseif ($action == 'deny') {
683
+									$boardOptions['deny_groups'][] = (int) $group;
684
+				}
664 685
 			}
665 686
 
666 687
 		// People with manage-boards are special.
@@ -672,8 +693,9 @@  discard block
 block discarded – undo
672 693
 		// Secondly, make sure those with super cow powers (like apt-get, or in this case manage boards) are upgraded.
673 694
 		$boardOptions['access_groups'] = array_unique(array_merge($boardOptions['access_groups'], $board_managers));
674 695
 
675
-		if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255)
676
-			fatal_lang_error('too_many_groups', false);
696
+		if (strlen(implode(',', $boardOptions['access_groups'])) > 255 || strlen(implode(',', $boardOptions['deny_groups'])) > 255) {
697
+					fatal_lang_error('too_many_groups', false);
698
+		}
677 699
 
678 700
 		// Do not allow HTML tags. Parse the string.
679 701
 		$boardOptions['board_name'] = parse_bbc($smcFunc['htmlspecialchars']($_POST['board_name']), false, '', $context['description_allowed_tags']);
@@ -684,8 +706,9 @@  discard block
 block discarded – undo
684 706
 		if (isset($_POST['moderator_list']) && is_array($_POST['moderator_list']))
685 707
 		{
686 708
 			$moderators = array();
687
-			foreach ($_POST['moderator_list'] as $moderator)
688
-				$moderators[(int) $moderator] = (int) $moderator;
709
+			foreach ($_POST['moderator_list'] as $moderator) {
710
+							$moderators[(int) $moderator] = (int) $moderator;
711
+			}
689 712
 			$boardOptions['moderators'] = $moderators;
690 713
 		}
691 714
 
@@ -694,8 +717,9 @@  discard block
 block discarded – undo
694 717
 		if (isset($_POST['moderator_group_list']) && is_array($_POST['moderator_group_list']))
695 718
 		{
696 719
 			$moderator_groups = array();
697
-			foreach ($_POST['moderator_group_list'] as $moderator_group)
698
-				$moderator_groups[(int) $moderator_group] = (int) $moderator_group;
720
+			foreach ($_POST['moderator_group_list'] as $moderator_group) {
721
+							$moderator_groups[(int) $moderator_group] = (int) $moderator_group;
722
+			}
699 723
 			$boardOptions['moderator_groups'] = $moderator_groups;
700 724
 		}
701 725
 
@@ -721,56 +745,62 @@  discard block
 block discarded – undo
721 745
 			$smcFunc['db_free_result']($request);
722 746
 
723 747
 			// If we're turning redirection on check the board doesn't have posts in it - if it does don't make it a redirection board.
724
-			if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts)
725
-				unset($boardOptions['redirect']);
748
+			if ($boardOptions['redirect'] && empty($oldRedirect) && $numPosts) {
749
+							unset($boardOptions['redirect']);
750
+			}
726 751
 			// Reset the redirection count when switching on/off.
727
-			elseif (empty($boardOptions['redirect']) != empty($oldRedirect))
728
-				$boardOptions['num_posts'] = 0;
752
+			elseif (empty($boardOptions['redirect']) != empty($oldRedirect)) {
753
+							$boardOptions['num_posts'] = 0;
754
+			}
729 755
 			// Resetting the count?
730
-			elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect']))
731
-				$boardOptions['num_posts'] = 0;
756
+			elseif ($boardOptions['redirect'] && !empty($_POST['reset_redirect'])) {
757
+							$boardOptions['num_posts'] = 0;
758
+			}
732 759
 		}
733 760
 
734 761
 		// Create a new board...
735 762
 		if (isset($_POST['add']))
736 763
 		{
737 764
 			// New boards by default go to the bottom of the category.
738
-			if (empty($_POST['new_cat']))
739
-				$boardOptions['target_category'] = (int) $_POST['cur_cat'];
740
-			if (!isset($boardOptions['move_to']))
741
-				$boardOptions['move_to'] = 'bottom';
765
+			if (empty($_POST['new_cat'])) {
766
+							$boardOptions['target_category'] = (int) $_POST['cur_cat'];
767
+			}
768
+			if (!isset($boardOptions['move_to'])) {
769
+							$boardOptions['move_to'] = 'bottom';
770
+			}
742 771
 
743 772
 			createBoard($boardOptions);
744 773
 		}
745 774
 
746 775
 		// ...or update an existing board.
747
-		else
748
-			modifyBoard($_POST['boardid'], $boardOptions);
749
-	}
750
-	elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children']))
776
+		else {
777
+					modifyBoard($_POST['boardid'], $boardOptions);
778
+		}
779
+	} elseif (isset($_POST['delete']) && !isset($_POST['confirmation']) && !isset($_POST['no_children']))
751 780
 	{
752 781
 		EditBoard();
753 782
 		return;
754
-	}
755
-	elseif (isset($_POST['delete']))
783
+	} elseif (isset($_POST['delete']))
756 784
 	{
757 785
 		// First off - check if we are moving all the current child boards first - before we start deleting!
758 786
 		if (isset($_POST['delete_action']) && $_POST['delete_action'] == 1)
759 787
 		{
760
-			if (empty($_POST['board_to']))
761
-				fatal_lang_error('mboards_delete_board_error');
788
+			if (empty($_POST['board_to'])) {
789
+							fatal_lang_error('mboards_delete_board_error');
790
+			}
762 791
 
763 792
 			deleteBoards(array($_POST['boardid']), (int) $_POST['board_to']);
793
+		} else {
794
+					deleteBoards(array($_POST['boardid']), 0);
764 795
 		}
765
-		else
766
-			deleteBoards(array($_POST['boardid']), 0);
767 796
 	}
768 797
 
769
-	if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions')
770
-		redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
771
-	else
772
-		redirectexit('action=admin;area=manageboards');
773
-}
798
+	if (isset($_REQUEST['rid']) && $_REQUEST['rid'] == 'permissions') {
799
+			redirectexit('action=admin;area=permissions;sa=board;' . $context['session_var'] . '=' . $context['session_id']);
800
+	} else {
801
+			redirectexit('action=admin;area=manageboards');
802
+	}
803
+	}
774 804
 
775 805
 /**
776 806
  * Used to retrieve data for modifying a board category
@@ -807,8 +837,9 @@  discard block
 block discarded – undo
807 837
 	$smcFunc['db_free_result']($request);
808 838
 
809 839
 	// This would probably never happen, but just to be sure.
810
-	if ($cat .= $allowed_sa[1])
811
-		die(str_replace(',', ' to', $cat));
840
+	if ($cat .= $allowed_sa[1]) {
841
+			die(str_replace(',', ' to', $cat));
842
+	}
812 843
 
813 844
 	redirectexit();
814 845
 }
@@ -834,8 +865,9 @@  discard block
 block discarded – undo
834 865
 			'empty_string' => '',
835 866
 		)
836 867
 	);
837
-	while ($row = $smcFunc['db_fetch_assoc']($request))
838
-		$recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
868
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
869
+			$recycle_boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
870
+	}
839 871
 	$smcFunc['db_free_result']($request);
840 872
 
841 873
 	if (!empty($recycle_boards))
@@ -843,13 +875,14 @@  discard block
 block discarded – undo
843 875
 		require_once($sourcedir . '/Subs-Boards.php');
844 876
 		sortBoards($recycle_boards);
845 877
 		$recycle_boards = array('') + $recycle_boards;
878
+	} else {
879
+			$recycle_boards = array('');
846 880
 	}
847
-	else
848
-		$recycle_boards = array('');
849 881
 
850 882
 	// If this setting is missing, set it to 1
851
-	if (empty($modSettings['boardindex_max_depth']))
852
-		$modSettings['boardindex_max_depth'] = 1;
883
+	if (empty($modSettings['boardindex_max_depth'])) {
884
+			$modSettings['boardindex_max_depth'] = 1;
885
+	}
853 886
 
854 887
 	// Here and the board settings...
855 888
 	$config_vars = array(
@@ -868,8 +901,9 @@  discard block
 block discarded – undo
868 901
 
869 902
 	call_integration_hook('integrate_modify_board_settings', array(&$config_vars));
870 903
 
871
-	if ($return_config)
872
-		return $config_vars;
904
+	if ($return_config) {
905
+			return $config_vars;
906
+	}
873 907
 
874 908
 	// Needed for the settings template.
875 909
 	require_once($sourcedir . '/ManageServer.php');
Please login to merge, or discard this patch.
Sources/Subs-BoardIndex.php 1 patch
Braces   +66 added lines, -51 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Fetches a list of boards and (optional) categories including
@@ -37,15 +38,17 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Boards.php');
38 39
 
39 40
 	// For performance, track the latest post while going through the boards.
40
-	if (!empty($boardIndexOptions['set_latest_post']))
41
-		$latest_post = array(
41
+	if (!empty($boardIndexOptions['set_latest_post'])) {
42
+			$latest_post = array(
42 43
 			'timestamp' => 0,
43 44
 			'ref' => 0,
44 45
 		);
46
+	}
45 47
 
46 48
 	// This setting is not allowed to be empty
47
-	if (empty($modSettings['boardindex_max_depth']))
48
-		$modSettings['boardindex_max_depth'] = 1;
49
+	if (empty($modSettings['boardindex_max_depth'])) {
50
+			$modSettings['boardindex_max_depth'] = 1;
51
+	}
49 52
 
50 53
 	// Find all boards and categories, as well as related information.  This will be sorted by the natural order of boards and categories, which we control.
51 54
 	$result_boards = $smcFunc['db_query']('', '
@@ -78,16 +81,18 @@  discard block
 block discarded – undo
78 81
 	);
79 82
 
80 83
 	// Start with an empty array.
81
-	if ($boardIndexOptions['include_categories'])
82
-		$categories = array();
83
-	else
84
-		$this_category = array();
84
+	if ($boardIndexOptions['include_categories']) {
85
+			$categories = array();
86
+	} else {
87
+			$this_category = array();
88
+	}
85 89
 	$boards = array();
86 90
 
87 91
 	// Children can affect parents, so we need to gather all the boards first and then process them after.
88 92
 	$row_boards = array();
89
-	while ($row_board = $smcFunc['db_fetch_assoc']($result_boards))
90
-		$row_boards[$row_board['id_board']] = $row_board;
93
+	while ($row_board = $smcFunc['db_fetch_assoc']($result_boards)) {
94
+			$row_boards[$row_board['id_board']] = $row_board;
95
+	}
91 96
 	$smcFunc['db_free_result']($result_boards);
92 97
 
93 98
 	// Run through the categories and boards (or only boards)....
@@ -100,8 +105,9 @@  discard block
 block discarded – undo
100 105
 		$row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
101 106
 
102 107
 		// Add parent boards to the $boards list later used to fetch moderators
103
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'])
104
-			$boards[] = $row_board['id_board'];
108
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id']) {
109
+					$boards[] = $row_board['id_board'];
110
+		}
105 111
 
106 112
 		if ($boardIndexOptions['include_categories'])
107 113
 		{
@@ -123,8 +129,9 @@  discard block
 block discarded – undo
123 129
 			}
124 130
 
125 131
 			// If this board has new posts in it (and isn't the recycle bin!) then the category is new.
126
-			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board'])
127
-				$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']);
132
+			if (empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $row_board['id_board']) {
133
+							$categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']);
134
+			}
128 135
 
129 136
 			// Avoid showing category unread link where it only has redirection boards.
130 137
 			$categories[$row_board['id_cat']]['show_unread'] = !empty($categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
@@ -143,8 +150,9 @@  discard block
 block discarded – undo
143 150
 				$isChild = false;
144 151
 
145 152
 				// We might or might not have already added this board, so...
146
-				if (!isset($this_category[$row_board['id_board']]))
147
-					$this_category[$row_board['id_board']] = array();
153
+				if (!isset($this_category[$row_board['id_board']])) {
154
+									$this_category[$row_board['id_board']] = array();
155
+				}
148 156
 
149 157
 				$this_category[$row_board['id_board']] += array(
150 158
 					'new' => empty($row_board['is_read']),
@@ -177,14 +185,12 @@  discard block
 block discarded – undo
177 185
 				{
178 186
 					$this_category[$row_board['id_board']]['board_class'] = 'redirect';
179 187
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['redirect_board'];
180
-				}
181
-				elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
188
+				} elseif ($this_category[$row_board['id_board']]['new'] || $context['user']['is_guest'])
182 189
 				{
183 190
 					// If we're showing to guests, we want to give them the idea that something interesting is going on!
184 191
 					$this_category[$row_board['id_board']]['board_class'] = 'on';
185 192
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['new_posts'];
186
-				}
187
-				else
193
+				} else
188 194
 				{
189 195
 					$this_category[$row_board['id_board']]['board_tooltip'] = $txt['old_posts'];
190 196
 				}
@@ -196,12 +202,13 @@  discard block
 block discarded – undo
196 202
 			$isChild = true;
197 203
 
198 204
 			// Ensure the parent has at least the most important info defined
199
-			if (!isset($this_category[$row_board['id_parent']]))
200
-				$this_category[$row_board['id_parent']] = array(
205
+			if (!isset($this_category[$row_board['id_parent']])) {
206
+							$this_category[$row_board['id_parent']] = array(
201 207
 					'children' => array(),
202 208
 					'children_new' => false,
203 209
 					'board_class' => 'off',
204 210
 				);
211
+			}
205 212
 
206 213
 			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']] = array(
207 214
 				'id' => $row_board['id_board'],
@@ -245,8 +252,9 @@  discard block
 block discarded – undo
245 252
 			// Propagate some values to the parent board
246 253
 			if (isset($row_boards[$row_board['id_parent']]))
247 254
 			{
248
-				if (empty($row_board['is_read']))
249
-					$row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read'];
255
+				if (empty($row_board['is_read'])) {
256
+									$row_boards[$row_board['id_parent']]['is_read'] = $row_board['is_read'];
257
+				}
250 258
 
251 259
 				if (!empty($boardIndexOptions['countChildPosts']) && !$row_board['is_redirect'])
252 260
 				{
@@ -277,12 +285,13 @@  discard block
 block discarded – undo
277 285
 			'topic' => $row_board['id_topic']
278 286
 		);
279 287
 
280
-		if (!empty($settings['avatars_on_boardIndex']))
281
-			$this_last_post['member']['avatar'] = set_avatar_data(array(
288
+		if (!empty($settings['avatars_on_boardIndex'])) {
289
+					$this_last_post['member']['avatar'] = set_avatar_data(array(
282 290
 				'avatar' => $row_board['avatar'],
283 291
 				'email' => $row_board['email_address'],
284 292
 				'filename' => !empty($row_board['member_filename']) ? $row_board['member_filename'] : '',
285 293
 			));
294
+		}
286 295
 
287 296
 		// Provide the href and link.
288 297
 		if ($row_board['subject'] != '')
@@ -294,8 +303,7 @@  discard block
 block discarded – undo
294 303
 			link, href, subject, start (where they should go for the first unread post.),
295 304
 			and member. (which has id, name, link, href, username in it.) */
296 305
 			$this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['time']);
297
-		}
298
-		else
306
+		} else
299 307
 		{
300 308
 			$this_last_post['href'] = '';
301 309
 			$this_last_post['link'] = $txt['not_applicable'];
@@ -303,18 +311,21 @@  discard block
 block discarded – undo
303 311
 		}
304 312
 
305 313
 		// Set the last post in the parent board.
306
-		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && forum_time(true, $row_boards[$row_board['id_parent']]['poster_time']) < forum_time(true, $row_board['poster_time'])))
307
-			$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
314
+		if ($row_board['id_parent'] == $boardIndexOptions['parent_id'] || ($isChild && !empty($row_board['poster_time']) && forum_time(true, $row_boards[$row_board['id_parent']]['poster_time']) < forum_time(true, $row_board['poster_time']))) {
315
+					$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
316
+		}
308 317
 		// Just in the child...?
309
-		if ($isChild)
310
-			$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
318
+		if ($isChild) {
319
+					$this_category[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
320
+		}
311 321
 
312 322
 		// Determine a global most recent topic.
313
-		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard)
314
-			$latest_post = array(
323
+		if (!empty($boardIndexOptions['set_latest_post']) && !empty($row_board['poster_time']) && $row_board['poster_time'] > $latest_post['timestamp'] && !$ignoreThisBoard) {
324
+					$latest_post = array(
315 325
 				'timestamp' => $row_board['poster_time'],
316 326
 				'ref' => &$this_category[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'],
317 327
 			);
328
+		}
318 329
 	}
319 330
 
320 331
 	// Fetch the board's moderators and moderator groups
@@ -330,8 +341,9 @@  discard block
 block discarded – undo
330 341
 				if (!empty($moderators[$board['id']]))
331 342
 				{
332 343
 					$categories[$k]['boards'][$j]['moderators'] = $moderators[$board['id']];
333
-					foreach ($moderators[$board['id']] as $moderator)
334
-						$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
344
+					foreach ($moderators[$board['id']] as $moderator) {
345
+											$categories[$k]['boards'][$j]['link_moderators'][] = $moderator['link'];
346
+					}
335 347
 				}
336 348
 				if (!empty($groups[$board['id']]))
337 349
 				{
@@ -344,16 +356,16 @@  discard block
 block discarded – undo
344 356
 				}
345 357
 			}
346 358
 		}
347
-	}
348
-	else
359
+	} else
349 360
 	{
350 361
 		foreach ($this_category as $k => $board)
351 362
 		{
352 363
 			if (!empty($moderators[$board['id']]))
353 364
 			{
354 365
 				$this_category[$k]['moderators'] = $moderators[$board['id']];
355
-				foreach ($moderators[$board['id']] as $moderator)
356
-					$this_category[$k]['link_moderators'][] = $moderator['link'];
366
+				foreach ($moderators[$board['id']] as $moderator) {
367
+									$this_category[$k]['link_moderators'][] = $moderator['link'];
368
+				}
357 369
 			}
358 370
 			if (!empty($groups[$board['id']]))
359 371
 			{
@@ -367,20 +379,23 @@  discard block
 block discarded – undo
367 379
 		}
368 380
 	}
369 381
 
370
-	if ($boardIndexOptions['include_categories'])
371
-		sortCategories($categories);
372
-	else
373
-		sortBoards($this_category);
382
+	if ($boardIndexOptions['include_categories']) {
383
+			sortCategories($categories);
384
+	} else {
385
+			sortBoards($this_category);
386
+	}
374 387
 
375 388
 	// By now we should know the most recent post...if we wanna know it that is.
376
-	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref']))
377
-		$context['latest_post'] = $latest_post['ref'];
389
+	if (!empty($boardIndexOptions['set_latest_post']) && !empty($latest_post['ref'])) {
390
+			$context['latest_post'] = $latest_post['ref'];
391
+	}
378 392
 
379 393
 	// I can't remember why but trying to make a ternary to get this all in one line is actually a Very Bad Idea.
380
-	if ($boardIndexOptions['include_categories'])
381
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
382
-	else
383
-		call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
394
+	if ($boardIndexOptions['include_categories']) {
395
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$categories));
396
+	} else {
397
+			call_integration_hook('integrate_getboardtree', array($boardIndexOptions, &$this_category));
398
+	}
384 399
 
385 400
 	return $boardIndexOptions['include_categories'] ? $categories : $this_category;
386 401
 }
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +795 added lines, -599 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,30 +464,34 @@  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
-				$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
467
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
468
+							$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
469
+			}
450 470
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
471
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
472
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			}
453 474
 		}
454 475
 
455 476
 		// Did we find 'im?  If not, junk it.
456 477
 		if (!empty($user_settings))
457 478
 		{
458 479
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
480
+			if (!empty($already_verified) && $already_verified === true) {
481
+							$check = true;
482
+			}
461 483
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
484
+			elseif (strlen($password) == 128) {
485
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
486
+			} else {
487
+							$check = false;
488
+			}
466 489
 
467 490
 			// Wrong password or not activated - either way, you're going nowhere.
468 491
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
492
+		} else {
493
+					$id_member = 0;
469 494
 		}
470
-		else
471
-			$id_member = 0;
472 495
 
473 496
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 497
 		if (!$id_member)
@@ -497,8 +520,9 @@  discard block
 block discarded – undo
497 520
 
498 521
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
499 522
 
500
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
501
-						$tfasecret = null;
523
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
524
+											$tfasecret = null;
525
+					}
502 526
 				}
503 527
 
504 528
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -520,10 +544,12 @@  discard block
 block discarded – undo
520 544
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
521 545
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
522 546
 		{
523
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
547
+			if ($modSettings['tfa_mode'] == 2) {
548
+				//only do this if we are just forcing SOME membergroups
524 549
 			{
525 550
 				//Build an array of ALL user membergroups.
526 551
 				$full_groups = array($user_settings['id_group']);
552
+			}
527 553
 				if (!empty($user_settings['additional_groups']))
528 554
 				{
529 555
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -543,15 +569,17 @@  discard block
 block discarded – undo
543 569
 				);
544 570
 				$row = $smcFunc['db_fetch_assoc']($request);
545 571
 				$smcFunc['db_free_result']($request);
572
+			} else {
573
+							$row['total'] = 1;
546 574
 			}
547
-			else
548
-				$row['total'] = 1; //simplifies logics in the next "if"
575
+			//simplifies logics in the next "if"
549 576
 
550 577
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
551 578
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
552 579
 
553
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
554
-				redirectexit('action=profile;area=tfasetup;forced');
580
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
581
+							redirectexit('action=profile;area=tfasetup;forced');
582
+			}
555 583
 		}
556 584
 	}
557 585
 
@@ -588,33 +616,37 @@  discard block
 block discarded – undo
588 616
 				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']));
589 617
 				$user_settings['last_login'] = time();
590 618
 
591
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
592
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
619
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
620
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
621
+				}
593 622
 
594
-				if (!empty($modSettings['cache_enable']))
595
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
623
+				if (!empty($modSettings['cache_enable'])) {
624
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
625
+				}
596 626
 			}
627
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
628
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
597 629
 		}
598
-		elseif (empty($_SESSION['id_msg_last_visit']))
599
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
600 630
 
601 631
 		$username = $user_settings['member_name'];
602 632
 
603
-		if (empty($user_settings['additional_groups']))
604
-			$user_info = array(
633
+		if (empty($user_settings['additional_groups'])) {
634
+					$user_info = array(
605 635
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
606 636
 			);
607
-		else
608
-			$user_info = array(
637
+		} else {
638
+					$user_info = array(
609 639
 				'groups' => array_merge(
610 640
 					array($user_settings['id_group'], $user_settings['id_post_group']),
611 641
 					explode(',', $user_settings['additional_groups'])
612 642
 				)
613 643
 			);
644
+		}
614 645
 
615 646
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
616
-		foreach ($user_info['groups'] as $k => $v)
617
-			$user_info['groups'][$k] = (int) $v;
647
+		foreach ($user_info['groups'] as $k => $v) {
648
+					$user_info['groups'][$k] = (int) $v;
649
+		}
618 650
 
619 651
 		// This is a logged in user, so definitely not a spider.
620 652
 		$user_info['possibly_robot'] = false;
@@ -628,8 +660,7 @@  discard block
 block discarded – undo
628 660
 			$time_system = new DateTime('now', $tz_system);
629 661
 			$time_user = new DateTime('now', $tz_user);
630 662
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
631
-		}
632
-		else
663
+		} else
633 664
 		{
634 665
 			// !!! Compatibility.
635 666
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -643,8 +674,9 @@  discard block
 block discarded – undo
643 674
 		$user_info = array('groups' => array(-1));
644 675
 		$user_settings = array();
645 676
 
646
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
647
-			$_COOKIE[$cookiename] = '';
677
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
678
+					$_COOKIE[$cookiename] = '';
679
+		}
648 680
 
649 681
 		// Expire the 2FA cookie
650 682
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -661,19 +693,20 @@  discard block
 block discarded – undo
661 693
 		}
662 694
 
663 695
 		// Create a login token if it doesn't exist yet.
664
-		if (!isset($_SESSION['token']['post-login']))
665
-			createToken('login');
666
-		else
667
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
696
+		if (!isset($_SESSION['token']['post-login'])) {
697
+					createToken('login');
698
+		} else {
699
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
700
+		}
668 701
 
669 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
670 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
671 704
 		{
672 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
673 706
 			$user_info['possibly_robot'] = SpiderCheck();
707
+		} elseif (!empty($modSettings['spider_mode'])) {
708
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
674 709
 		}
675
-		elseif (!empty($modSettings['spider_mode']))
676
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
677 710
 		// If we haven't turned on proper spider hunts then have a guess!
678 711
 		else
679 712
 		{
@@ -721,8 +754,9 @@  discard block
 block discarded – undo
721 754
 	$user_info['groups'] = array_unique($user_info['groups']);
722 755
 
723 756
 	// 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.
724
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
725
-		unset($user_info['ignoreboards'][$tmp]);
757
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
758
+			unset($user_info['ignoreboards'][$tmp]);
759
+	}
726 760
 
727 761
 	// Allow the user to change their language.
728 762
 	if (!empty($modSettings['userLanguage']))
@@ -735,13 +769,14 @@  discard block
 block discarded – undo
735 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
736 770
 
737 771
 			// Make it permanent for members.
738
-			if (!empty($user_info['id']))
739
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
740
-			else
741
-				$_SESSION['language'] = $user_info['language'];
772
+			if (!empty($user_info['id'])) {
773
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
774
+			} else {
775
+							$_SESSION['language'] = $user_info['language'];
776
+			}
777
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
778
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
742 779
 		}
743
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
744
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
745 780
 	}
746 781
 
747 782
 	$temp = build_query_board($user_info['id']);
@@ -804,9 +839,9 @@  discard block
 block discarded – undo
804 839
 		}
805 840
 
806 841
 		// Remember redirection is the key to avoiding fallout from your bosses.
807
-		if (!empty($topic))
808
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
809
-		else
842
+		if (!empty($topic)) {
843
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
844
+		} else
810 845
 		{
811 846
 			loadPermissions();
812 847
 			loadTheme();
@@ -824,10 +859,11 @@  discard block
 block discarded – undo
824 859
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
825 860
 	{
826 861
 		// @todo SLOW?
827
-		if (!empty($topic))
828
-			$temp = cache_get_data('topic_board-' . $topic, 120);
829
-		else
830
-			$temp = cache_get_data('board-' . $board, 120);
862
+		if (!empty($topic)) {
863
+					$temp = cache_get_data('topic_board-' . $topic, 120);
864
+		} else {
865
+					$temp = cache_get_data('board-' . $board, 120);
866
+		}
831 867
 
832 868
 		if (!empty($temp))
833 869
 		{
@@ -865,8 +901,9 @@  discard block
 block discarded – undo
865 901
 			$row = $smcFunc['db_fetch_assoc']($request);
866 902
 
867 903
 			// Set the current board.
868
-			if (!empty($row['id_board']))
869
-				$board = $row['id_board'];
904
+			if (!empty($row['id_board'])) {
905
+							$board = $row['id_board'];
906
+			}
870 907
 
871 908
 			// Basic operating information. (globals... :/)
872 909
 			$board_info = array(
@@ -902,21 +939,23 @@  discard block
 block discarded – undo
902 939
 
903 940
 			do
904 941
 			{
905
-				if (!empty($row['id_moderator']))
906
-					$board_info['moderators'][$row['id_moderator']] = array(
942
+				if (!empty($row['id_moderator'])) {
943
+									$board_info['moderators'][$row['id_moderator']] = array(
907 944
 						'id' => $row['id_moderator'],
908 945
 						'name' => $row['real_name'],
909 946
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
910 947
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
911 948
 					);
949
+				}
912 950
 
913
-				if (!empty($row['id_moderator_group']))
914
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
951
+				if (!empty($row['id_moderator_group'])) {
952
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
915 953
 						'id' => $row['id_moderator_group'],
916 954
 						'name' => $row['group_name'],
917 955
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
918 956
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
919 957
 					);
958
+				}
920 959
 			}
921 960
 			while ($row = $smcFunc['db_fetch_assoc']($request));
922 961
 
@@ -948,12 +987,12 @@  discard block
 block discarded – undo
948 987
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
949 988
 			{
950 989
 				// @todo SLOW?
951
-				if (!empty($topic))
952
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
990
+				if (!empty($topic)) {
991
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
992
+				}
953 993
 				cache_put_data('board-' . $board, $board_info, 120);
954 994
 			}
955
-		}
956
-		else
995
+		} else
957 996
 		{
958 997
 			// Otherwise the topic is invalid, there are no moderators, etc.
959 998
 			$board_info = array(
@@ -967,8 +1006,9 @@  discard block
 block discarded – undo
967 1006
 		$smcFunc['db_free_result']($request);
968 1007
 	}
969 1008
 
970
-	if (!empty($topic))
971
-		$_GET['board'] = (int) $board;
1009
+	if (!empty($topic)) {
1010
+			$_GET['board'] = (int) $board;
1011
+	}
972 1012
 
973 1013
 	if (!empty($board))
974 1014
 	{
@@ -978,10 +1018,12 @@  discard block
 block discarded – undo
978 1018
 		// Now check if the user is a moderator.
979 1019
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
980 1020
 
981
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
982
-			$board_info['error'] = 'access';
983
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
984
-			$board_info['error'] = 'access';
1021
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1022
+					$board_info['error'] = 'access';
1023
+		}
1024
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1025
+					$board_info['error'] = 'access';
1026
+		}
985 1027
 
986 1028
 		// Build up the linktree.
987 1029
 		$context['linktree'] = array_merge(
@@ -1004,8 +1046,9 @@  discard block
 block discarded – undo
1004 1046
 	$context['current_board'] = $board;
1005 1047
 
1006 1048
 	// No posting in redirection boards!
1007
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1008
-		$board_info['error'] == 'post_in_redirect';
1049
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1050
+			$board_info['error'] == 'post_in_redirect';
1051
+	}
1009 1052
 
1010 1053
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1011 1054
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1031,24 +1074,23 @@  discard block
 block discarded – undo
1031 1074
 			ob_end_clean();
1032 1075
 			header('HTTP/1.1 403 Forbidden');
1033 1076
 			die;
1034
-		}
1035
-		elseif ($board_info['error'] == 'post_in_redirect')
1077
+		} elseif ($board_info['error'] == 'post_in_redirect')
1036 1078
 		{
1037 1079
 			// Slightly different error message here...
1038 1080
 			fatal_lang_error('cannot_post_redirect', false);
1039
-		}
1040
-		elseif ($user_info['is_guest'])
1081
+		} elseif ($user_info['is_guest'])
1041 1082
 		{
1042 1083
 			loadLanguage('Errors');
1043 1084
 			is_not_guest($txt['topic_gone']);
1085
+		} else {
1086
+					fatal_lang_error('topic_gone', false);
1044 1087
 		}
1045
-		else
1046
-			fatal_lang_error('topic_gone', false);
1047 1088
 	}
1048 1089
 
1049
-	if ($user_info['is_mod'])
1050
-		$user_info['groups'][] = 3;
1051
-}
1090
+	if ($user_info['is_mod']) {
1091
+			$user_info['groups'][] = 3;
1092
+	}
1093
+	}
1052 1094
 
1053 1095
 /**
1054 1096
  * Load this user's permissions.
@@ -1069,8 +1111,9 @@  discard block
 block discarded – undo
1069 1111
 		asort($cache_groups);
1070 1112
 		$cache_groups = implode(',', $cache_groups);
1071 1113
 		// If it's a spider then cache it different.
1072
-		if ($user_info['possibly_robot'])
1073
-			$cache_groups .= '-spider';
1114
+		if ($user_info['possibly_robot']) {
1115
+					$cache_groups .= '-spider';
1116
+		}
1074 1117
 
1075 1118
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1076 1119
 		{
@@ -1078,9 +1121,9 @@  discard block
 block discarded – undo
1078 1121
 			banPermissions();
1079 1122
 
1080 1123
 			return;
1124
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1125
+					list ($user_info['permissions'], $removals) = $temp;
1081 1126
 		}
1082
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1083
-			list ($user_info['permissions'], $removals) = $temp;
1084 1127
 	}
1085 1128
 
1086 1129
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1102,23 +1145,26 @@  discard block
 block discarded – undo
1102 1145
 		$removals = array();
1103 1146
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1104 1147
 		{
1105
-			if (empty($row['add_deny']))
1106
-				$removals[] = $row['permission'];
1107
-			else
1108
-				$user_info['permissions'][] = $row['permission'];
1148
+			if (empty($row['add_deny'])) {
1149
+							$removals[] = $row['permission'];
1150
+			} else {
1151
+							$user_info['permissions'][] = $row['permission'];
1152
+			}
1109 1153
 		}
1110 1154
 		$smcFunc['db_free_result']($request);
1111 1155
 
1112
-		if (isset($cache_groups))
1113
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1156
+		if (isset($cache_groups)) {
1157
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1158
+		}
1114 1159
 	}
1115 1160
 
1116 1161
 	// Get the board permissions.
1117 1162
 	if (!empty($board))
1118 1163
 	{
1119 1164
 		// Make sure the board (if any) has been loaded by loadBoard().
1120
-		if (!isset($board_info['profile']))
1121
-			fatal_lang_error('no_board');
1165
+		if (!isset($board_info['profile'])) {
1166
+					fatal_lang_error('no_board');
1167
+		}
1122 1168
 
1123 1169
 		$request = $smcFunc['db_query']('', '
1124 1170
 			SELECT permission, add_deny
@@ -1134,20 +1180,23 @@  discard block
 block discarded – undo
1134 1180
 		);
1135 1181
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1136 1182
 		{
1137
-			if (empty($row['add_deny']))
1138
-				$removals[] = $row['permission'];
1139
-			else
1140
-				$user_info['permissions'][] = $row['permission'];
1183
+			if (empty($row['add_deny'])) {
1184
+							$removals[] = $row['permission'];
1185
+			} else {
1186
+							$user_info['permissions'][] = $row['permission'];
1187
+			}
1141 1188
 		}
1142 1189
 		$smcFunc['db_free_result']($request);
1143 1190
 	}
1144 1191
 
1145 1192
 	// Remove all the permissions they shouldn't have ;).
1146
-	if (!empty($modSettings['permission_enable_deny']))
1147
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1193
+	if (!empty($modSettings['permission_enable_deny'])) {
1194
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1195
+	}
1148 1196
 
1149
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1150
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1197
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1198
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1199
+	}
1151 1200
 
1152 1201
 	// Banned?  Watch, don't touch..
1153 1202
 	banPermissions();
@@ -1159,17 +1208,18 @@  discard block
 block discarded – undo
1159 1208
 		{
1160 1209
 			require_once($sourcedir . '/Subs-Auth.php');
1161 1210
 			rebuildModCache();
1211
+		} else {
1212
+					$user_info['mod_cache'] = $_SESSION['mc'];
1162 1213
 		}
1163
-		else
1164
-			$user_info['mod_cache'] = $_SESSION['mc'];
1165 1214
 
1166 1215
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1167 1216
 		// For example this drastically simplifies certain changes to the profile area.
1168 1217
 		$user_info['permissions'][] = 'is_not_guest';
1169 1218
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1170 1219
 		$user_info['permissions'][] = 'profile_view_own';
1171
-		if (in_array('profile_view', $user_info['permissions']))
1172
-			$user_info['permissions'][] = 'profile_view_any';
1220
+		if (in_array('profile_view', $user_info['permissions'])) {
1221
+					$user_info['permissions'][] = 'profile_view_any';
1222
+		}
1173 1223
 	}
1174 1224
 }
1175 1225
 
@@ -1187,8 +1237,9 @@  discard block
 block discarded – undo
1187 1237
 	global $image_proxy_enabled, $boardurl, $user_info;
1188 1238
 
1189 1239
 	// Can't just look for no users :P.
1190
-	if (empty($users))
1191
-		return array();
1240
+	if (empty($users)) {
1241
+			return array();
1242
+	}
1192 1243
 
1193 1244
 	// Pass the set value
1194 1245
 	$context['loadMemberContext_set'] = $set;
@@ -1203,8 +1254,9 @@  discard block
 block discarded – undo
1203 1254
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1204 1255
 		{
1205 1256
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1206
-			if ($data == null)
1207
-				continue;
1257
+			if ($data == null) {
1258
+							continue;
1259
+			}
1208 1260
 
1209 1261
 			$loaded_ids[] = $data['id_member'];
1210 1262
 			$user_profile[$data['id_member']] = $data;
@@ -1271,16 +1323,19 @@  discard block
 block discarded – undo
1271 1323
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1272 1324
 
1273 1325
 			// Take care of proxying avatar if required, do this here for maximum reach
1274
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1275
-				$row['avatar'] = get_proxied_url($row['avatar']);
1326
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1327
+							$row['avatar'] = get_proxied_url($row['avatar']);
1328
+			}
1276 1329
 
1277 1330
 			// Keep track of the member's normal member group
1278 1331
 			$row['primary_group'] = $row['member_group'];
1279 1332
 
1280
-			if (isset($row['member_ip']))
1281
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1282
-			if (isset($row['member_ip2']))
1283
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1333
+			if (isset($row['member_ip'])) {
1334
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1335
+			}
1336
+			if (isset($row['member_ip2'])) {
1337
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1338
+			}
1284 1339
 			$new_loaded_ids[] = $row['id_member'];
1285 1340
 			$loaded_ids[] = $row['id_member'];
1286 1341
 			$row['options'] = array();
@@ -1299,8 +1354,9 @@  discard block
 block discarded – undo
1299 1354
 				'loaded_ids' => $new_loaded_ids,
1300 1355
 			)
1301 1356
 		);
1302
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1303
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1357
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1358
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1359
+		}
1304 1360
 		$smcFunc['db_free_result']($request);
1305 1361
 	}
1306 1362
 
@@ -1311,10 +1367,11 @@  discard block
 block discarded – undo
1311 1367
 	{
1312 1368
 		foreach ($loaded_ids as $a_member)
1313 1369
 		{
1314
-			if (!empty($user_profile[$a_member]['additional_groups']))
1315
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1316
-			else
1317
-				$groups = array($user_profile[$a_member]['id_group']);
1370
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1371
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1372
+			} else {
1373
+							$groups = array($user_profile[$a_member]['id_group']);
1374
+			}
1318 1375
 
1319 1376
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1320 1377
 
@@ -1327,8 +1384,9 @@  discard block
 block discarded – undo
1327 1384
 
1328 1385
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1329 1386
 	{
1330
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1331
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1387
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1388
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1389
+		}
1332 1390
 	}
1333 1391
 
1334 1392
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1354,14 +1412,17 @@  discard block
 block discarded – undo
1354 1412
 		foreach ($temp_mods as $id)
1355 1413
 		{
1356 1414
 			// By popular demand, don't show admins or global moderators as moderators.
1357
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1358
-				$user_profile[$id]['member_group'] = $row['member_group'];
1415
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1416
+							$user_profile[$id]['member_group'] = $row['member_group'];
1417
+			}
1359 1418
 
1360 1419
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1361
-			if (!empty($row['icons']))
1362
-				$user_profile[$id]['icons'] = $row['icons'];
1363
-			if (!empty($row['member_group_color']))
1364
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1420
+			if (!empty($row['icons'])) {
1421
+							$user_profile[$id]['icons'] = $row['icons'];
1422
+			}
1423
+			if (!empty($row['member_group_color'])) {
1424
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1425
+			}
1365 1426
 		}
1366 1427
 	}
1367 1428
 
@@ -1383,12 +1444,14 @@  discard block
 block discarded – undo
1383 1444
 	static $loadedLanguages = array();
1384 1445
 
1385 1446
 	// If this person's data is already loaded, skip it.
1386
-	if (isset($dataLoaded[$user]))
1387
-		return true;
1447
+	if (isset($dataLoaded[$user])) {
1448
+			return true;
1449
+	}
1388 1450
 
1389 1451
 	// We can't load guests or members not loaded by loadMemberData()!
1390
-	if ($user == 0)
1391
-		return false;
1452
+	if ($user == 0) {
1453
+			return false;
1454
+	}
1392 1455
 	if (!isset($user_profile[$user]))
1393 1456
 	{
1394 1457
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1414,12 +1477,16 @@  discard block
 block discarded – undo
1414 1477
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1415 1478
 
1416 1479
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1417
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1480
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1481
+		//icon is set and exists
1418 1482
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1419
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1483
+	} elseif (isset($profile['icons'][1])) {
1484
+		//icon is set and doesn't exist, fallback to default
1420 1485
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1421
-	else //not set, bye bye
1486
+	} else {
1487
+		//not set, bye bye
1422 1488
 		$group_icon_url = '';
1489
+	}
1423 1490
 
1424 1491
 	// These minimal values are always loaded
1425 1492
 	$memberContext[$user] = array(
@@ -1438,8 +1505,9 @@  discard block
 block discarded – undo
1438 1505
 	if ($context['loadMemberContext_set'] != 'minimal')
1439 1506
 	{
1440 1507
 		// Go the extra mile and load the user's native language name.
1441
-		if (empty($loadedLanguages))
1442
-			$loadedLanguages = getLanguages();
1508
+		if (empty($loadedLanguages)) {
1509
+					$loadedLanguages = getLanguages();
1510
+		}
1443 1511
 
1444 1512
 		$memberContext[$user] += array(
1445 1513
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1494,31 +1562,33 @@  discard block
 block discarded – undo
1494 1562
 	{
1495 1563
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1496 1564
 		{
1497
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1498
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1499
-			else
1500
-				$image = get_gravatar_url($profile['email_address']);
1501
-		}
1502
-		else
1565
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1566
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1567
+			} else {
1568
+							$image = get_gravatar_url($profile['email_address']);
1569
+			}
1570
+		} else
1503 1571
 		{
1504 1572
 			// So it's stored in the member table?
1505 1573
 			if (!empty($profile['avatar']))
1506 1574
 			{
1507 1575
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1576
+			} elseif (!empty($profile['filename'])) {
1577
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1508 1578
 			}
1509
-			elseif (!empty($profile['filename']))
1510
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1511 1579
 			// Right... no avatar...use the default one
1512
-			else
1513
-				$image = $modSettings['avatar_url'] . '/default.png';
1580
+			else {
1581
+							$image = $modSettings['avatar_url'] . '/default.png';
1582
+			}
1514 1583
 		}
1515
-		if (!empty($image))
1516
-			$memberContext[$user]['avatar'] = array(
1584
+		if (!empty($image)) {
1585
+					$memberContext[$user]['avatar'] = array(
1517 1586
 				'name' => $profile['avatar'],
1518 1587
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1519 1588
 				'href' => $image,
1520 1589
 				'url' => $image,
1521 1590
 			);
1591
+		}
1522 1592
 	}
1523 1593
 
1524 1594
 	// Are we also loading the members custom fields into context?
@@ -1526,13 +1596,15 @@  discard block
 block discarded – undo
1526 1596
 	{
1527 1597
 		$memberContext[$user]['custom_fields'] = array();
1528 1598
 
1529
-		if (!isset($context['display_fields']))
1530
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1599
+		if (!isset($context['display_fields'])) {
1600
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1601
+		}
1531 1602
 
1532 1603
 		foreach ($context['display_fields'] as $custom)
1533 1604
 		{
1534
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1535
-				continue;
1605
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1606
+							continue;
1607
+			}
1536 1608
 
1537 1609
 			$value = $profile['options'][$custom['col_name']];
1538 1610
 
@@ -1540,31 +1612,36 @@  discard block
 block discarded – undo
1540 1612
 			$currentKey = 0;
1541 1613
 
1542 1614
 			// Create a key => value array for multiple options fields
1543
-			if (!empty($custom['options']))
1544
-				foreach ($custom['options'] as $k => $v)
1615
+			if (!empty($custom['options'])) {
1616
+							foreach ($custom['options'] as $k => $v)
1545 1617
 				{
1546 1618
 					$fieldOptions[] = $v;
1547
-					if (empty($currentKey))
1548
-						$currentKey = $v == $value ? $k : 0;
1619
+			}
1620
+					if (empty($currentKey)) {
1621
+											$currentKey = $v == $value ? $k : 0;
1622
+					}
1549 1623
 				}
1550 1624
 
1551 1625
 			// BBC?
1552
-			if ($custom['bbc'])
1553
-				$value = parse_bbc($value);
1626
+			if ($custom['bbc']) {
1627
+							$value = parse_bbc($value);
1628
+			}
1554 1629
 
1555 1630
 			// ... or checkbox?
1556
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1557
-				$value = $value ? $txt['yes'] : $txt['no'];
1631
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1632
+							$value = $value ? $txt['yes'] : $txt['no'];
1633
+			}
1558 1634
 
1559 1635
 			// Enclosing the user input within some other text?
1560
-			if (!empty($custom['enclose']))
1561
-				$value = strtr($custom['enclose'], array(
1636
+			if (!empty($custom['enclose'])) {
1637
+							$value = strtr($custom['enclose'], array(
1562 1638
 					'{SCRIPTURL}' => $scripturl,
1563 1639
 					'{IMAGES_URL}' => $settings['images_url'],
1564 1640
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1565 1641
 					'{INPUT}' => $value,
1566 1642
 					'{KEY}' => $currentKey,
1567 1643
 				));
1644
+			}
1568 1645
 
1569 1646
 			$memberContext[$user]['custom_fields'][] = array(
1570 1647
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1591,8 +1668,9 @@  discard block
 block discarded – undo
1591 1668
 	global $smcFunc, $txt, $scripturl, $settings;
1592 1669
 
1593 1670
 	// Do not waste my time...
1594
-	if (empty($users) || empty($params))
1595
-		return false;
1671
+	if (empty($users) || empty($params)) {
1672
+			return false;
1673
+	}
1596 1674
 
1597 1675
 	// Make sure it's an array.
1598 1676
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1619,41 +1697,48 @@  discard block
 block discarded – undo
1619 1697
 		$currentKey = 0;
1620 1698
 
1621 1699
 		// Create a key => value array for multiple options fields
1622
-		if (!empty($row['field_options']))
1623
-			foreach (explode(',', $row['field_options']) as $k => $v)
1700
+		if (!empty($row['field_options'])) {
1701
+					foreach (explode(',', $row['field_options']) as $k => $v)
1624 1702
 			{
1625 1703
 				$fieldOptions[] = $v;
1626
-				if (empty($currentKey))
1627
-					$currentKey = $v == $row['value'] ? $k : 0;
1704
+		}
1705
+				if (empty($currentKey)) {
1706
+									$currentKey = $v == $row['value'] ? $k : 0;
1707
+				}
1628 1708
 			}
1629 1709
 
1630 1710
 		// BBC?
1631
-		if (!empty($row['bbc']))
1632
-			$row['value'] = parse_bbc($row['value']);
1711
+		if (!empty($row['bbc'])) {
1712
+					$row['value'] = parse_bbc($row['value']);
1713
+		}
1633 1714
 
1634 1715
 		// ... or checkbox?
1635
-		elseif (isset($row['type']) && $row['type'] == 'check')
1636
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1716
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1717
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1718
+		}
1637 1719
 
1638 1720
 		// Enclosing the user input within some other text?
1639
-		if (!empty($row['enclose']))
1640
-			$row['value'] = strtr($row['enclose'], array(
1721
+		if (!empty($row['enclose'])) {
1722
+					$row['value'] = strtr($row['enclose'], array(
1641 1723
 				'{SCRIPTURL}' => $scripturl,
1642 1724
 				'{IMAGES_URL}' => $settings['images_url'],
1643 1725
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1644 1726
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1645 1727
 				'{KEY}' => $currentKey,
1646 1728
 			));
1729
+		}
1647 1730
 
1648 1731
 		// Send a simple array if there is just 1 param
1649
-		if (count($params) == 1)
1650
-			$return[$row['id_member']] = $row;
1732
+		if (count($params) == 1) {
1733
+					$return[$row['id_member']] = $row;
1734
+		}
1651 1735
 
1652 1736
 		// More than 1? knock yourself out...
1653 1737
 		else
1654 1738
 		{
1655
-			if (!isset($return[$row['id_member']]))
1656
-				$return[$row['id_member']] = array();
1739
+			if (!isset($return[$row['id_member']])) {
1740
+							$return[$row['id_member']] = array();
1741
+			}
1657 1742
 
1658 1743
 			$return[$row['id_member']][$row['variable']] = $row;
1659 1744
 		}
@@ -1687,8 +1772,9 @@  discard block
 block discarded – undo
1687 1772
 	global $context;
1688 1773
 
1689 1774
 	// Don't know any browser!
1690
-	if (empty($context['browser']))
1691
-		detectBrowser();
1775
+	if (empty($context['browser'])) {
1776
+			detectBrowser();
1777
+	}
1692 1778
 
1693 1779
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1694 1780
 }
@@ -1706,8 +1792,9 @@  discard block
 block discarded – undo
1706 1792
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1707 1793
 
1708 1794
 	// The theme was specified by parameter.
1709
-	if (!empty($id_theme))
1710
-		$id_theme = (int) $id_theme;
1795
+	if (!empty($id_theme)) {
1796
+			$id_theme = (int) $id_theme;
1797
+	}
1711 1798
 	// The theme was specified by REQUEST.
1712 1799
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1713 1800
 	{
@@ -1715,32 +1802,38 @@  discard block
 block discarded – undo
1715 1802
 		$_SESSION['id_theme'] = $id_theme;
1716 1803
 	}
1717 1804
 	// The theme was specified by REQUEST... previously.
1718
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1719
-		$id_theme = (int) $_SESSION['id_theme'];
1805
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1806
+			$id_theme = (int) $_SESSION['id_theme'];
1807
+	}
1720 1808
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1721
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1722
-		$id_theme = $user_info['theme'];
1809
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1810
+			$id_theme = $user_info['theme'];
1811
+	}
1723 1812
 	// The theme was specified by the board.
1724
-	elseif (!empty($board_info['theme']))
1725
-		$id_theme = $board_info['theme'];
1813
+	elseif (!empty($board_info['theme'])) {
1814
+			$id_theme = $board_info['theme'];
1815
+	}
1726 1816
 	// The theme is the forum's default.
1727
-	else
1728
-		$id_theme = $modSettings['theme_guests'];
1817
+	else {
1818
+			$id_theme = $modSettings['theme_guests'];
1819
+	}
1729 1820
 
1730 1821
 	// Verify the id_theme... no foul play.
1731 1822
 	// Always allow the board specific theme, if they are overriding.
1732
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1733
-		$id_theme = $board_info['theme'];
1823
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1824
+			$id_theme = $board_info['theme'];
1825
+	}
1734 1826
 	// If they have specified a particular theme to use with SSI allow it to be used.
1735
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1736
-		$id_theme = (int) $id_theme;
1737
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1827
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1828
+			$id_theme = (int) $id_theme;
1829
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1738 1830
 	{
1739 1831
 		$themes = explode(',', $modSettings['enableThemes']);
1740
-		if (!in_array($id_theme, $themes))
1741
-			$id_theme = $modSettings['theme_guests'];
1742
-		else
1743
-			$id_theme = (int) $id_theme;
1832
+		if (!in_array($id_theme, $themes)) {
1833
+					$id_theme = $modSettings['theme_guests'];
1834
+		} else {
1835
+					$id_theme = (int) $id_theme;
1836
+		}
1744 1837
 	}
1745 1838
 		
1746 1839
 	// We already load the basic stuff?
@@ -1749,18 +1842,19 @@  discard block
 block discarded – undo
1749 1842
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1750 1843
 
1751 1844
 		// Disable image proxy if we don't have SSL enabled
1752
-		if (empty($modSettings['force_ssl']))
1753
-			$image_proxy_enabled = false;
1845
+		if (empty($modSettings['force_ssl'])) {
1846
+					$image_proxy_enabled = false;
1847
+		}
1754 1848
 
1755 1849
 		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'])
1756 1850
 		{
1757 1851
 			$themeData = $temp;
1758 1852
 			$flag = true;
1853
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1854
+					$themeData = $temp + array($member => array());
1855
+		} else {
1856
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1759 1857
 		}
1760
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1761
-			$themeData = $temp + array($member => array());
1762
-		else
1763
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1764 1858
 
1765 1859
 		if (empty($flag))
1766 1860
 		{
@@ -1780,31 +1874,37 @@  discard block
 block discarded – undo
1780 1874
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1781 1875
 			{
1782 1876
 				// There are just things we shouldn't be able to change as members.
1783
-				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')))
1784
-					continue;
1877
+				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'))) {
1878
+									continue;
1879
+				}
1785 1880
 
1786 1881
 				// If this is the theme_dir of the default theme, store it.
1787
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1788
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1882
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1883
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1884
+				}
1789 1885
 
1790 1886
 				// If this isn't set yet, is a theme option, or is not the default theme..
1791
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1792
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1887
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1888
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1889
+				}
1793 1890
 			}
1794 1891
 			$smcFunc['db_free_result']($result);
1795 1892
 
1796
-			if (!empty($themeData[-1]))
1797
-				foreach ($themeData[-1] as $k => $v)
1893
+			if (!empty($themeData[-1])) {
1894
+							foreach ($themeData[-1] as $k => $v)
1798 1895
 				{
1799 1896
 					if (!isset($themeData[$member][$k]))
1800 1897
 						$themeData[$member][$k] = $v;
1898
+			}
1801 1899
 				}
1802 1900
 
1803
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1804
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1901
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1902
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1903
+			}
1805 1904
 			// Only if we didn't already load that part of the cache...
1806
-			elseif (!isset($temp))
1807
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1905
+			elseif (!isset($temp)) {
1906
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1907
+			}
1808 1908
 		}
1809 1909
 
1810 1910
 		$settings = $themeData[0];
@@ -1821,17 +1921,20 @@  discard block
 block discarded – undo
1821 1921
 		$settings['template_dirs'][] = $settings['theme_dir'];
1822 1922
 
1823 1923
 		// Based on theme (if there is one).
1824
-		if (!empty($settings['base_theme_dir']))
1825
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1924
+		if (!empty($settings['base_theme_dir'])) {
1925
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1926
+		}
1826 1927
 
1827 1928
 		// Lastly the default theme.
1828
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1829
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1929
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1930
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1931
+		}
1830 1932
 	}
1831 1933
 
1832 1934
 
1833
-	if (!$initialize)
1834
-		return;
1935
+	if (!$initialize) {
1936
+			return;
1937
+	}
1835 1938
 
1836 1939
 	// Check to see if we're forcing SSL
1837 1940
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1852,8 +1955,9 @@  discard block
 block discarded – undo
1852 1955
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1853 1956
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1854 1957
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1855
-		if ($temp != '/')
1856
-			$detected_url .= $temp;
1958
+		if ($temp != '/') {
1959
+					$detected_url .= $temp;
1960
+		}
1857 1961
 	}
1858 1962
 	if (isset($detected_url) && $detected_url != $boardurl)
1859 1963
 	{
@@ -1865,8 +1969,9 @@  discard block
 block discarded – undo
1865 1969
 			foreach ($aliases as $alias)
1866 1970
 			{
1867 1971
 				// Rip off all the boring parts, spaces, etc.
1868
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1869
-					$do_fix = true;
1972
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1973
+									$do_fix = true;
1974
+				}
1870 1975
 			}
1871 1976
 		}
1872 1977
 
@@ -1874,21 +1979,23 @@  discard block
 block discarded – undo
1874 1979
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1875 1980
 		{
1876 1981
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1877
-			if (empty($_GET))
1878
-				redirectexit('wwwRedirect');
1879
-			else
1982
+			if (empty($_GET)) {
1983
+							redirectexit('wwwRedirect');
1984
+			} else
1880 1985
 			{
1881 1986
 				$k = key($_GET);
1882 1987
 				$v = current($_GET);
1883 1988
 
1884
-				if ($k != 'wwwRedirect')
1885
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1989
+				if ($k != 'wwwRedirect') {
1990
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1991
+				}
1886 1992
 			}
1887 1993
 		}
1888 1994
 
1889 1995
 		// #3 is just a check for SSL...
1890
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1891
-			$do_fix = true;
1996
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1997
+					$do_fix = true;
1998
+		}
1892 1999
 
1893 2000
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1894 2001
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1923,8 +2030,9 @@  discard block
 block discarded – undo
1923 2030
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1924 2031
 				}
1925 2032
 			}
1926
-			foreach ($context['linktree'] as $k => $dummy)
1927
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2033
+			foreach ($context['linktree'] as $k => $dummy) {
2034
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2035
+			}
1928 2036
 		}
1929 2037
 	}
1930 2038
 	// Set up the contextual user array.
@@ -1943,16 +2051,16 @@  discard block
 block discarded – undo
1943 2051
 			'email' => $user_info['email'],
1944 2052
 			'ignoreusers' => $user_info['ignoreusers'],
1945 2053
 		);
1946
-		if (!$context['user']['is_guest'])
1947
-			$context['user']['name'] = $user_info['name'];
1948
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1949
-			$context['user']['name'] = $txt['guest_title'];
2054
+		if (!$context['user']['is_guest']) {
2055
+					$context['user']['name'] = $user_info['name'];
2056
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2057
+					$context['user']['name'] = $txt['guest_title'];
2058
+		}
1950 2059
 
1951 2060
 		// Determine the current smiley set.
1952 2061
 		$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'];
1953 2062
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1954
-	}
1955
-	else
2063
+	} else
1956 2064
 	{
1957 2065
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1958 2066
 		$context['user'] = array(
@@ -1986,18 +2094,24 @@  discard block
 block discarded – undo
1986 2094
 	}
1987 2095
 
1988 2096
 	// Some basic information...
1989
-	if (!isset($context['html_headers']))
1990
-		$context['html_headers'] = '';
1991
-	if (!isset($context['javascript_files']))
1992
-		$context['javascript_files'] = array();
1993
-	if (!isset($context['css_files']))
1994
-		$context['css_files'] = array();
1995
-	if (!isset($context['css_header']))
1996
-		$context['css_header'] = array();
1997
-	if (!isset($context['javascript_inline']))
1998
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1999
-	if (!isset($context['javascript_vars']))
2000
-		$context['javascript_vars'] = array();
2097
+	if (!isset($context['html_headers'])) {
2098
+			$context['html_headers'] = '';
2099
+	}
2100
+	if (!isset($context['javascript_files'])) {
2101
+			$context['javascript_files'] = array();
2102
+	}
2103
+	if (!isset($context['css_files'])) {
2104
+			$context['css_files'] = array();
2105
+	}
2106
+	if (!isset($context['css_header'])) {
2107
+			$context['css_header'] = array();
2108
+	}
2109
+	if (!isset($context['javascript_inline'])) {
2110
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2111
+	}
2112
+	if (!isset($context['javascript_vars'])) {
2113
+			$context['javascript_vars'] = array();
2114
+	}
2001 2115
 
2002 2116
 	$context['login_url'] =  $scripturl . '?action=login2';
2003 2117
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2009,16 +2123,18 @@  discard block
 block discarded – undo
2009 2123
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2010 2124
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2011 2125
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2012
-	if (isset($modSettings['load_average']))
2013
-		$context['load_average'] = $modSettings['load_average'];
2126
+	if (isset($modSettings['load_average'])) {
2127
+			$context['load_average'] = $modSettings['load_average'];
2128
+	}
2014 2129
 
2015 2130
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2016 2131
 	detectBrowser();
2017 2132
 
2018 2133
 	// Set the top level linktree up.
2019 2134
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2020
-	if (empty($context['linktree']))
2021
-		$context['linktree'] = array();
2135
+	if (empty($context['linktree'])) {
2136
+			$context['linktree'] = array();
2137
+	}
2022 2138
 	array_unshift($context['linktree'], array(
2023 2139
 		'url' => $scripturl,
2024 2140
 		'name' => $context['forum_name_html_safe']
@@ -2027,8 +2143,9 @@  discard block
 block discarded – undo
2027 2143
 	// This allows sticking some HTML on the page output - useful for controls.
2028 2144
 	$context['insert_after_template'] = '';
2029 2145
 
2030
-	if (!isset($txt))
2031
-		$txt = array();
2146
+	if (!isset($txt)) {
2147
+			$txt = array();
2148
+	}
2032 2149
 
2033 2150
 	$simpleActions = array(
2034 2151
 		'findmember',
@@ -2074,9 +2191,10 @@  discard block
 block discarded – undo
2074 2191
 
2075 2192
 	// See if theres any extra param to check.
2076 2193
 	$requiresXML = false;
2077
-	foreach ($extraParams as $key => $extra)
2078
-		if (isset($_REQUEST[$extra]))
2194
+	foreach ($extraParams as $key => $extra) {
2195
+			if (isset($_REQUEST[$extra]))
2079 2196
 			$requiresXML = true;
2197
+	}
2080 2198
 
2081 2199
 	// Output is fully XML, so no need for the index template.
2082 2200
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2091,37 +2209,39 @@  discard block
 block discarded – undo
2091 2209
 	{
2092 2210
 		loadLanguage('index+Modifications');
2093 2211
 		$context['template_layers'] = array();
2094
-	}
2095
-
2096
-	else
2212
+	} else
2097 2213
 	{
2098 2214
 		// Custom templates to load, or just default?
2099
-		if (isset($settings['theme_templates']))
2100
-			$templates = explode(',', $settings['theme_templates']);
2101
-		else
2102
-			$templates = array('index');
2215
+		if (isset($settings['theme_templates'])) {
2216
+					$templates = explode(',', $settings['theme_templates']);
2217
+		} else {
2218
+					$templates = array('index');
2219
+		}
2103 2220
 
2104 2221
 		// Load each template...
2105
-		foreach ($templates as $template)
2106
-			loadTemplate($template);
2222
+		foreach ($templates as $template) {
2223
+					loadTemplate($template);
2224
+		}
2107 2225
 
2108 2226
 		// ...and attempt to load their associated language files.
2109 2227
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2110 2228
 		loadLanguage($required_files, '', false);
2111 2229
 
2112 2230
 		// Custom template layers?
2113
-		if (isset($settings['theme_layers']))
2114
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2115
-		else
2116
-			$context['template_layers'] = array('html', 'body');
2231
+		if (isset($settings['theme_layers'])) {
2232
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2233
+		} else {
2234
+					$context['template_layers'] = array('html', 'body');
2235
+		}
2117 2236
 	}
2118 2237
 
2119 2238
 	// Initialize the theme.
2120 2239
 	loadSubTemplate('init', 'ignore');
2121 2240
 
2122 2241
 	// Allow overriding the board wide time/number formats.
2123
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2124
-		$user_info['time_format'] = $txt['time_format'];
2242
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2243
+			$user_info['time_format'] = $txt['time_format'];
2244
+	}
2125 2245
 
2126 2246
 	// Set the character set from the template.
2127 2247
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2129,12 +2249,14 @@  discard block
 block discarded – undo
2129 2249
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2130 2250
 
2131 2251
 	// Guests may still need a name.
2132
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2133
-		$context['user']['name'] = $txt['guest_title'];
2252
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2253
+			$context['user']['name'] = $txt['guest_title'];
2254
+	}
2134 2255
 
2135 2256
 	// Any theme-related strings that need to be loaded?
2136
-	if (!empty($settings['require_theme_strings']))
2137
-		loadLanguage('ThemeStrings', '', false);
2257
+	if (!empty($settings['require_theme_strings'])) {
2258
+			loadLanguage('ThemeStrings', '', false);
2259
+	}
2138 2260
 
2139 2261
 	// Make a special URL for the language.
2140 2262
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2145,8 +2267,9 @@  discard block
 block discarded – undo
2145 2267
 	// Here is my luvly Responsive CSS
2146 2268
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2147 2269
 
2148
-	if ($context['right_to_left'])
2149
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2270
+	if ($context['right_to_left']) {
2271
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2272
+	}
2150 2273
 
2151 2274
 	// We allow theme variants, because we're cool.
2152 2275
 	$context['theme_variant'] = '';
@@ -2154,14 +2277,17 @@  discard block
 block discarded – undo
2154 2277
 	if (!empty($settings['theme_variants']))
2155 2278
 	{
2156 2279
 		// Overriding - for previews and that ilk.
2157
-		if (!empty($_REQUEST['variant']))
2158
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2280
+		if (!empty($_REQUEST['variant'])) {
2281
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2282
+		}
2159 2283
 		// User selection?
2160
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2161
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2284
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2285
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2286
+		}
2162 2287
 		// If not a user variant, select the default.
2163
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2164
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2288
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2289
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2290
+		}
2165 2291
 
2166 2292
 		// Do this to keep things easier in the templates.
2167 2293
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2170,20 +2296,23 @@  discard block
 block discarded – undo
2170 2296
 		if (!empty($context['theme_variant']))
2171 2297
 		{
2172 2298
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2173
-			if ($context['right_to_left'])
2174
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2299
+			if ($context['right_to_left']) {
2300
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2301
+			}
2175 2302
 		}
2176 2303
 	}
2177 2304
 
2178 2305
 	// Let's be compatible with old themes!
2179
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2180
-		$context['template_layers'] = array('main');
2306
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2307
+			$context['template_layers'] = array('main');
2308
+	}
2181 2309
 
2182 2310
 	$context['tabindex'] = 1;
2183 2311
 
2184 2312
 	// Compatibility.
2185
-	if (!isset($settings['theme_version']))
2186
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2313
+	if (!isset($settings['theme_version'])) {
2314
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2315
+	}
2187 2316
 
2188 2317
 	// Default JS variables for use in every theme
2189 2318
 	$context['javascript_vars'] = array(
@@ -2203,18 +2332,18 @@  discard block
 block discarded – undo
2203 2332
 	);
2204 2333
 
2205 2334
 	// Add the JQuery library to the list of files to load.
2206
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2207
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2208
-
2209
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2210
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2211
-
2212
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2213
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2335
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2336
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2337
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2338
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2339
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2340
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2341
+	}
2214 2342
 
2215 2343
 	// Auto loading? template_javascript() will take care of the local half of this.
2216
-	else
2217
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2344
+	else {
2345
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2346
+	}
2218 2347
 
2219 2348
 	// Queue our JQuery plugins!
2220 2349
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2237,12 +2366,12 @@  discard block
 block discarded – undo
2237 2366
 			require_once($sourcedir . '/ScheduledTasks.php');
2238 2367
 
2239 2368
 			// What to do, what to do?!
2240
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2241
-				AutoTask();
2242
-			else
2243
-				ReduceMailQueue();
2244
-		}
2245
-		else
2369
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2370
+							AutoTask();
2371
+			} else {
2372
+							ReduceMailQueue();
2373
+			}
2374
+		} else
2246 2375
 		{
2247 2376
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2248 2377
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2293,8 +2422,9 @@  discard block
 block discarded – undo
2293 2422
 		foreach ($theme_includes as $include)
2294 2423
 		{
2295 2424
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2296
-			if (file_exists($include))
2297
-				require_once($include);
2425
+			if (file_exists($include)) {
2426
+							require_once($include);
2427
+			}
2298 2428
 		}
2299 2429
 	}
2300 2430
 
@@ -2324,16 +2454,19 @@  discard block
 block discarded – undo
2324 2454
 	// Do any style sheets first, cause we're easy with those.
2325 2455
 	if (!empty($style_sheets))
2326 2456
 	{
2327
-		if (!is_array($style_sheets))
2328
-			$style_sheets = array($style_sheets);
2457
+		if (!is_array($style_sheets)) {
2458
+					$style_sheets = array($style_sheets);
2459
+		}
2329 2460
 
2330
-		foreach ($style_sheets as $sheet)
2331
-			loadCSSFile($sheet . '.css', array(), $sheet);
2461
+		foreach ($style_sheets as $sheet) {
2462
+					loadCSSFile($sheet . '.css', array(), $sheet);
2463
+		}
2332 2464
 	}
2333 2465
 
2334 2466
 	// No template to load?
2335
-	if ($template_name === false)
2336
-		return true;
2467
+	if ($template_name === false) {
2468
+			return true;
2469
+	}
2337 2470
 
2338 2471
 	$loaded = false;
2339 2472
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2348,12 +2481,14 @@  discard block
 block discarded – undo
2348 2481
 
2349 2482
 	if ($loaded)
2350 2483
 	{
2351
-		if ($db_show_debug === true)
2352
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2484
+		if ($db_show_debug === true) {
2485
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2486
+		}
2353 2487
 
2354 2488
 		// If they have specified an initialization function for this template, go ahead and call it now.
2355
-		if (function_exists('template_' . $template_name . '_init'))
2356
-			call_user_func('template_' . $template_name . '_init');
2489
+		if (function_exists('template_' . $template_name . '_init')) {
2490
+					call_user_func('template_' . $template_name . '_init');
2491
+		}
2357 2492
 	}
2358 2493
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2359 2494
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2373,13 +2508,14 @@  discard block
 block discarded – undo
2373 2508
 		loadTemplate($template_name);
2374 2509
 	}
2375 2510
 	// Cause an error otherwise.
2376
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2377
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2378
-	elseif ($fatal)
2379
-		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'));
2380
-	else
2381
-		return false;
2382
-}
2511
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2512
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2513
+	} elseif ($fatal) {
2514
+			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'));
2515
+	} else {
2516
+			return false;
2517
+	}
2518
+	}
2383 2519
 
2384 2520
 /**
2385 2521
  * Load a sub-template.
@@ -2397,17 +2533,19 @@  discard block
 block discarded – undo
2397 2533
 {
2398 2534
 	global $context, $txt, $db_show_debug;
2399 2535
 
2400
-	if ($db_show_debug === true)
2401
-		$context['debug']['sub_templates'][] = $sub_template_name;
2536
+	if ($db_show_debug === true) {
2537
+			$context['debug']['sub_templates'][] = $sub_template_name;
2538
+	}
2402 2539
 
2403 2540
 	// Figure out what the template function is named.
2404 2541
 	$theme_function = 'template_' . $sub_template_name;
2405
-	if (function_exists($theme_function))
2406
-		$theme_function();
2407
-	elseif ($fatal === false)
2408
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2409
-	elseif ($fatal !== 'ignore')
2410
-		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'));
2542
+	if (function_exists($theme_function)) {
2543
+			$theme_function();
2544
+	} elseif ($fatal === false) {
2545
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2546
+	} elseif ($fatal !== 'ignore') {
2547
+			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
+	}
2411 2549
 
2412 2550
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2413 2551
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2437,8 +2575,9 @@  discard block
 block discarded – undo
2437 2575
 {
2438 2576
 	global $settings, $context, $modSettings;
2439 2577
 
2440
-	if (empty($context['css_files_order']))
2441
-		$context['css_files_order'] = array();
2578
+	if (empty($context['css_files_order'])) {
2579
+			$context['css_files_order'] = array();
2580
+	}
2442 2581
 
2443 2582
 	$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']) : '');
2444 2583
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2449,8 +2588,9 @@  discard block
 block discarded – undo
2449 2588
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2450 2589
 
2451 2590
 	// If this is an external file, automatically set this to false.
2452
-	if (!empty($params['external']))
2453
-		$params['minimize'] = false;
2591
+	if (!empty($params['external'])) {
2592
+			$params['minimize'] = false;
2593
+	}
2454 2594
 
2455 2595
 	// Account for shorthand like admin.css?alp21 filenames
2456 2596
 	$has_seed = strpos($fileName, '.css?');
@@ -2467,16 +2607,12 @@  discard block
 block discarded – undo
2467 2607
 			{
2468 2608
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2469 2609
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2470
-			}
2471
-
2472
-			else
2610
+			} else
2473 2611
 			{
2474 2612
 				$fileUrl = false;
2475 2613
 				$filePath = false;
2476 2614
 			}
2477
-		}
2478
-
2479
-		else
2615
+		} else
2480 2616
 		{
2481 2617
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2482 2618
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2494,16 +2630,18 @@  discard block
 block discarded – undo
2494 2630
 	if (!empty($fileName))
2495 2631
 	{
2496 2632
 		// find a free number/position
2497
-		while (isset($context['css_files_order'][$params['order_pos']]))
2498
-			$params['order_pos']++;
2633
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2634
+					$params['order_pos']++;
2635
+		}
2499 2636
 		$context['css_files_order'][$params['order_pos']] = $id;
2500 2637
 
2501 2638
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2502 2639
 	}
2503 2640
 
2504
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2505
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2506
-}
2641
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2642
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2643
+	}
2644
+	}
2507 2645
 
2508 2646
 /**
2509 2647
  * Add a block of inline css code to be executed later
@@ -2520,8 +2658,9 @@  discard block
 block discarded – undo
2520 2658
 	global $context;
2521 2659
 
2522 2660
 	// Gotta add something...
2523
-	if (empty($css))
2524
-		return false;
2661
+	if (empty($css)) {
2662
+			return false;
2663
+	}
2525 2664
 
2526 2665
 	$context['css_header'][] = $css;
2527 2666
 }
@@ -2557,8 +2696,9 @@  discard block
 block discarded – undo
2557 2696
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2558 2697
 
2559 2698
 	// If this is an external file, automatically set this to false.
2560
-	if (!empty($params['external']))
2561
-		$params['minimize'] = false;
2699
+	if (!empty($params['external'])) {
2700
+			$params['minimize'] = false;
2701
+	}
2562 2702
 
2563 2703
 	// Account for shorthand like admin.js?alp21 filenames
2564 2704
 	$has_seed = strpos($fileName, '.js?');
@@ -2575,16 +2715,12 @@  discard block
 block discarded – undo
2575 2715
 			{
2576 2716
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2577 2717
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2578
-			}
2579
-
2580
-			else
2718
+			} else
2581 2719
 			{
2582 2720
 				$fileUrl = false;
2583 2721
 				$filePath = false;
2584 2722
 			}
2585
-		}
2586
-
2587
-		else
2723
+		} else
2588 2724
 		{
2589 2725
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2590 2726
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2599,9 +2735,10 @@  discard block
 block discarded – undo
2599 2735
 	}
2600 2736
 
2601 2737
 	// Add it to the array for use in the template
2602
-	if (!empty($fileName))
2603
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2604
-}
2738
+	if (!empty($fileName)) {
2739
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2740
+	}
2741
+	}
2605 2742
 
2606 2743
 /**
2607 2744
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2615,9 +2752,10 @@  discard block
 block discarded – undo
2615 2752
 {
2616 2753
 	global $context;
2617 2754
 
2618
-	if (!empty($key) && (!empty($value) || $value === '0'))
2619
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2620
-}
2755
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2756
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2757
+	}
2758
+	}
2621 2759
 
2622 2760
 /**
2623 2761
  * Add a block of inline Javascript code to be executed later
@@ -2634,8 +2772,9 @@  discard block
 block discarded – undo
2634 2772
 {
2635 2773
 	global $context;
2636 2774
 
2637
-	if (empty($javascript))
2638
-		return false;
2775
+	if (empty($javascript)) {
2776
+			return false;
2777
+	}
2639 2778
 
2640 2779
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2641 2780
 }
@@ -2656,15 +2795,18 @@  discard block
 block discarded – undo
2656 2795
 	static $already_loaded = array();
2657 2796
 
2658 2797
 	// Default to the user's language.
2659
-	if ($lang == '')
2660
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2798
+	if ($lang == '') {
2799
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2800
+	}
2661 2801
 
2662 2802
 	// Do we want the English version of language file as fallback?
2663
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2664
-		loadLanguage($template_name, 'english', false);
2803
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2804
+			loadLanguage($template_name, 'english', false);
2805
+	}
2665 2806
 
2666
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2667
-		return $lang;
2807
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2808
+			return $lang;
2809
+	}
2668 2810
 
2669 2811
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2670 2812
 	if (empty($settings['default_theme_dir']))
@@ -2675,8 +2817,9 @@  discard block
 block discarded – undo
2675 2817
 
2676 2818
 	// What theme are we in?
2677 2819
 	$theme_name = basename($settings['theme_url']);
2678
-	if (empty($theme_name))
2679
-		$theme_name = 'unknown';
2820
+	if (empty($theme_name)) {
2821
+			$theme_name = 'unknown';
2822
+	}
2680 2823
 
2681 2824
 	// For each file open it up and write it out!
2682 2825
 	foreach (explode('+', $template_name) as $template)
@@ -2718,8 +2861,9 @@  discard block
 block discarded – undo
2718 2861
 				$found = true;
2719 2862
 
2720 2863
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2721
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2722
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2864
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2865
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2866
+				}
2723 2867
 
2724 2868
 				break;
2725 2869
 			}
@@ -2759,8 +2903,9 @@  discard block
 block discarded – undo
2759 2903
 	}
2760 2904
 
2761 2905
 	// Keep track of what we're up to soldier.
2762
-	if ($db_show_debug === true)
2763
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2906
+	if ($db_show_debug === true) {
2907
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2908
+	}
2764 2909
 
2765 2910
 	// Remember what we have loaded, and in which language.
2766 2911
 	$already_loaded[$template_name] = $lang;
@@ -2806,8 +2951,9 @@  discard block
 block discarded – undo
2806 2951
 				)
2807 2952
 			);
2808 2953
 			// In the EXTREMELY unlikely event this happens, give an error message.
2809
-			if ($smcFunc['db_num_rows']($result) == 0)
2810
-				fatal_lang_error('parent_not_found', 'critical');
2954
+			if ($smcFunc['db_num_rows']($result) == 0) {
2955
+							fatal_lang_error('parent_not_found', 'critical');
2956
+			}
2811 2957
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2812 2958
 			{
2813 2959
 				if (!isset($boards[$row['id_board']]))
@@ -2824,8 +2970,8 @@  discard block
 block discarded – undo
2824 2970
 					);
2825 2971
 				}
2826 2972
 				// If a moderator exists for this board, add that moderator for all children too.
2827
-				if (!empty($row['id_moderator']))
2828
-					foreach ($boards as $id => $dummy)
2973
+				if (!empty($row['id_moderator'])) {
2974
+									foreach ($boards as $id => $dummy)
2829 2975
 					{
2830 2976
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2831 2977
 							'id' => $row['id_moderator'],
@@ -2833,11 +2979,12 @@  discard block
 block discarded – undo
2833 2979
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2834 2980
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2835 2981
 						);
2982
+				}
2836 2983
 					}
2837 2984
 
2838 2985
 				// If a moderator group exists for this board, add that moderator group for all children too
2839
-				if (!empty($row['id_moderator_group']))
2840
-					foreach ($boards as $id => $dummy)
2986
+				if (!empty($row['id_moderator_group'])) {
2987
+									foreach ($boards as $id => $dummy)
2841 2988
 					{
2842 2989
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2843 2990
 							'id' => $row['id_moderator_group'],
@@ -2845,6 +2992,7 @@  discard block
 block discarded – undo
2845 2992
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2846 2993
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2847 2994
 						);
2995
+				}
2848 2996
 					}
2849 2997
 			}
2850 2998
 			$smcFunc['db_free_result']($result);
@@ -2871,23 +3019,27 @@  discard block
 block discarded – undo
2871 3019
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2872 3020
 	{
2873 3021
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2874
-		if (empty($smcFunc['ucwords']))
2875
-			reloadSettings();
3022
+		if (empty($smcFunc['ucwords'])) {
3023
+					reloadSettings();
3024
+		}
2876 3025
 
2877 3026
 		// If we don't have our theme information yet, let's get it.
2878
-		if (empty($settings['default_theme_dir']))
2879
-			loadTheme(0, false);
3027
+		if (empty($settings['default_theme_dir'])) {
3028
+					loadTheme(0, false);
3029
+		}
2880 3030
 
2881 3031
 		// Default language directories to try.
2882 3032
 		$language_directories = array(
2883 3033
 			$settings['default_theme_dir'] . '/languages',
2884 3034
 		);
2885
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2886
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3035
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3036
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3037
+		}
2887 3038
 
2888 3039
 		// We possibly have a base theme directory.
2889
-		if (!empty($settings['base_theme_dir']))
2890
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3040
+		if (!empty($settings['base_theme_dir'])) {
3041
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3042
+		}
2891 3043
 
2892 3044
 		// Remove any duplicates.
2893 3045
 		$language_directories = array_unique($language_directories);
@@ -2901,20 +3053,21 @@  discard block
 block discarded – undo
2901 3053
 		foreach ($language_directories as $language_dir)
2902 3054
 		{
2903 3055
 			// Can't look in here... doesn't exist!
2904
-			if (!file_exists($language_dir))
2905
-				continue;
3056
+			if (!file_exists($language_dir)) {
3057
+							continue;
3058
+			}
2906 3059
 
2907 3060
 			$dir = dir($language_dir);
2908 3061
 			while ($entry = $dir->read())
2909 3062
 			{
2910 3063
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2911
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2912
-					continue;
2913
-
2914
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2915
-					$langName = $langList[$matches[1]];
3064
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3065
+									continue;
3066
+				}
2916 3067
 
2917
-				else
3068
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3069
+									$langName = $langList[$matches[1]];
3070
+				} else
2918 3071
 				{
2919 3072
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2920 3073
 
@@ -2955,12 +3108,14 @@  discard block
 block discarded – undo
2955 3108
 		}
2956 3109
 
2957 3110
 		// Do we need to store the lang list?
2958
-		if (empty($langList))
2959
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3111
+		if (empty($langList)) {
3112
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3113
+		}
2960 3114
 
2961 3115
 		// Let's cash in on this deal.
2962
-		if (!empty($modSettings['cache_enable']))
2963
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3116
+		if (!empty($modSettings['cache_enable'])) {
3117
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3118
+		}
2964 3119
 	}
2965 3120
 
2966 3121
 	return $context['languages'];
@@ -2983,8 +3138,9 @@  discard block
 block discarded – undo
2983 3138
 	global $modSettings, $options, $txt;
2984 3139
 	static $censor_vulgar = null, $censor_proper;
2985 3140
 
2986
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2987
-		return $text;
3141
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3142
+			return $text;
3143
+	}
2988 3144
 
2989 3145
 	// If they haven't yet been loaded, load them.
2990 3146
 	if ($censor_vulgar == null)
@@ -3015,9 +3171,9 @@  discard block
 block discarded – undo
3015 3171
 	{
3016 3172
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3017 3173
 		$text = $func($censor_vulgar, $censor_proper, $text);
3174
+	} else {
3175
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3018 3176
 	}
3019
-	else
3020
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3021 3177
 
3022 3178
 	return $text;
3023 3179
 }
@@ -3043,30 +3199,35 @@  discard block
 block discarded – undo
3043 3199
 	@ini_set('track_errors', '1');
3044 3200
 
3045 3201
 	// Don't include the file more than once, if $once is true.
3046
-	if ($once && in_array($filename, $templates))
3047
-		return;
3202
+	if ($once && in_array($filename, $templates)) {
3203
+			return;
3204
+	}
3048 3205
 	// Add this file to the include list, whether $once is true or not.
3049
-	else
3050
-		$templates[] = $filename;
3206
+	else {
3207
+			$templates[] = $filename;
3208
+	}
3051 3209
 
3052 3210
 
3053 3211
 	$file_found = file_exists($filename);
3054 3212
 
3055
-	if ($once && $file_found)
3056
-		require_once($filename);
3057
-	elseif ($file_found)
3058
-		require($filename);
3213
+	if ($once && $file_found) {
3214
+			require_once($filename);
3215
+	} elseif ($file_found) {
3216
+			require($filename);
3217
+	}
3059 3218
 
3060 3219
 	if ($file_found !== true)
3061 3220
 	{
3062 3221
 		ob_end_clean();
3063
-		if (!empty($modSettings['enableCompressedOutput']))
3064
-			@ob_start('ob_gzhandler');
3065
-		else
3066
-			ob_start();
3222
+		if (!empty($modSettings['enableCompressedOutput'])) {
3223
+					@ob_start('ob_gzhandler');
3224
+		} else {
3225
+					ob_start();
3226
+		}
3067 3227
 
3068
-		if (isset($_GET['debug']))
3069
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3228
+		if (isset($_GET['debug'])) {
3229
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3230
+		}
3070 3231
 
3071 3232
 		// Don't cache error pages!!
3072 3233
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3085,12 +3246,13 @@  discard block
 block discarded – undo
3085 3246
 		echo '<!DOCTYPE html>
3086 3247
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3087 3248
 	<head>';
3088
-		if (isset($context['character_set']))
3089
-			echo '
3249
+		if (isset($context['character_set'])) {
3250
+					echo '
3090 3251
 		<meta charset="', $context['character_set'], '">';
3252
+		}
3091 3253
 
3092
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3093
-			echo '
3254
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3255
+					echo '
3094 3256
 		<title>', $mtitle, '</title>
3095 3257
 	</head>
3096 3258
 	<body>
@@ -3098,8 +3260,8 @@  discard block
 block discarded – undo
3098 3260
 		', $mmessage, '
3099 3261
 	</body>
3100 3262
 </html>';
3101
-		elseif (!allowedTo('admin_forum'))
3102
-			echo '
3263
+		} elseif (!allowedTo('admin_forum')) {
3264
+					echo '
3103 3265
 		<title>', $txt['template_parse_error'], '</title>
3104 3266
 	</head>
3105 3267
 	<body>
@@ -3107,14 +3269,16 @@  discard block
 block discarded – undo
3107 3269
 		', $txt['template_parse_error_message'], '
3108 3270
 	</body>
3109 3271
 </html>';
3110
-		else
3272
+		} else
3111 3273
 		{
3112 3274
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3113 3275
 			$error_array = error_get_last();
3114
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3115
-				$error = $error_array['message'];
3116
-			if (empty($error))
3117
-				$error = $txt['template_parse_errmsg'];
3276
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3277
+							$error = $error_array['message'];
3278
+			}
3279
+			if (empty($error)) {
3280
+							$error = $txt['template_parse_errmsg'];
3281
+			}
3118 3282
 
3119 3283
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3120 3284
 
@@ -3125,11 +3289,12 @@  discard block
 block discarded – undo
3125 3289
 		<h3>', $txt['template_parse_error'], '</h3>
3126 3290
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3127 3291
 
3128
-			if (!empty($error))
3129
-				echo '
3292
+			if (!empty($error)) {
3293
+							echo '
3130 3294
 		<hr>
3131 3295
 
3132 3296
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3297
+			}
3133 3298
 
3134 3299
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3135 3300
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3139,10 +3304,11 @@  discard block
 block discarded – undo
3139 3304
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3140 3305
 
3141 3306
 				// Fix the PHP code stuff...
3142
-				if (!isBrowser('gecko'))
3143
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3144
-				else
3145
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3307
+				if (!isBrowser('gecko')) {
3308
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3309
+				} else {
3310
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3311
+				}
3146 3312
 
3147 3313
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3148 3314
 				$j = -1;
@@ -3150,8 +3316,9 @@  discard block
 block discarded – undo
3150 3316
 				{
3151 3317
 					$j++;
3152 3318
 
3153
-					if (substr_count($line, '<br>') == 0)
3154
-						continue;
3319
+					if (substr_count($line, '<br>') == 0) {
3320
+											continue;
3321
+					}
3155 3322
 
3156 3323
 					$n = substr_count($line, '<br>');
3157 3324
 					for ($i = 0; $i < $n; $i++)
@@ -3170,38 +3337,42 @@  discard block
 block discarded – undo
3170 3337
 				// Figure out what the color coding was before...
3171 3338
 				$line = max($match[1] - 9, 1);
3172 3339
 				$last_line = '';
3173
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3174
-					if (strpos($data2[$line2], '<') !== false)
3340
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3341
+									if (strpos($data2[$line2], '<') !== false)
3175 3342
 					{
3176 3343
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3177 3344
 							$last_line = $color_match[1];
3345
+				}
3178 3346
 						break;
3179 3347
 					}
3180 3348
 
3181 3349
 				// Show the relevant lines...
3182 3350
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3183 3351
 				{
3184
-					if ($line == $match[1])
3185
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3352
+					if ($line == $match[1]) {
3353
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3354
+					}
3186 3355
 
3187 3356
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3188
-					if (isset($data2[$line]) && $data2[$line] != '')
3189
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3357
+					if (isset($data2[$line]) && $data2[$line] != '') {
3358
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3359
+					}
3190 3360
 
3191 3361
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3192 3362
 					{
3193 3363
 						$last_line = $color_match[1];
3194 3364
 						echo '</', substr($last_line, 1, 4), '>';
3365
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3366
+											$last_line = '';
3367
+					} elseif ($last_line != '' && $data2[$line] != '') {
3368
+											echo '</', substr($last_line, 1, 4), '>';
3195 3369
 					}
3196
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3197
-						$last_line = '';
3198
-					elseif ($last_line != '' && $data2[$line] != '')
3199
-						echo '</', substr($last_line, 1, 4), '>';
3200 3370
 
3201
-					if ($line == $match[1])
3202
-						echo '</pre></div><pre style="margin: 0;">';
3203
-					else
3204
-						echo "\n";
3371
+					if ($line == $match[1]) {
3372
+											echo '</pre></div><pre style="margin: 0;">';
3373
+					} else {
3374
+											echo "\n";
3375
+					}
3205 3376
 				}
3206 3377
 
3207 3378
 				echo '</pre></div>';
@@ -3225,8 +3396,9 @@  discard block
 block discarded – undo
3225 3396
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4;
3226 3397
 
3227 3398
 	// Figure out what type of database we are using.
3228
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3229
-		$db_type = 'mysql';
3399
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3400
+			$db_type = 'mysql';
3401
+	}
3230 3402
 
3231 3403
 	// Load the file for the database.
3232 3404
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3234,11 +3406,13 @@  discard block
 block discarded – undo
3234 3406
 	$db_options = array();
3235 3407
 
3236 3408
 	// Add in the port if needed
3237
-	if (!empty($db_port))
3238
-		$db_options['port'] = $db_port;
3409
+	if (!empty($db_port)) {
3410
+			$db_options['port'] = $db_port;
3411
+	}
3239 3412
 
3240
-	if (!empty($db_mb4))
3241
-		$db_options['db_mb4'] = $db_mb4;
3413
+	if (!empty($db_mb4)) {
3414
+			$db_options['db_mb4'] = $db_mb4;
3415
+	}
3242 3416
 
3243 3417
 	// 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.
3244 3418
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3257,13 +3431,15 @@  discard block
 block discarded – undo
3257 3431
 	}
3258 3432
 
3259 3433
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3260
-	if (!$db_connection)
3261
-		display_db_error();
3434
+	if (!$db_connection) {
3435
+			display_db_error();
3436
+	}
3262 3437
 
3263 3438
 	// If in SSI mode fix up the prefix.
3264
-	if (SMF == 'SSI')
3265
-		db_fix_prefix($db_prefix, $db_name);
3266
-}
3439
+	if (SMF == 'SSI') {
3440
+			db_fix_prefix($db_prefix, $db_name);
3441
+	}
3442
+	}
3267 3443
 
3268 3444
 /**
3269 3445
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3277,10 +3453,11 @@  discard block
 block discarded – undo
3277 3453
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3278 3454
 
3279 3455
 	// Not overriding this and we have a cacheAPI, send it back.
3280
-	if (empty($overrideCache) && is_object($cacheAPI))
3281
-		return $cacheAPI;
3282
-	elseif (is_null($cacheAPI))
3283
-		$cacheAPI = false;
3456
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3457
+			return $cacheAPI;
3458
+	} elseif (is_null($cacheAPI)) {
3459
+			$cacheAPI = false;
3460
+	}
3284 3461
 
3285 3462
 	// Make sure our class is in session.
3286 3463
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3301,8 +3478,9 @@  discard block
 block discarded – undo
3301 3478
 		if (!$testAPI->isSupported())
3302 3479
 		{
3303 3480
 			// Can we save ourselves?
3304
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3305
-				return loadCacheAccelerator(null, false);
3481
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3482
+							return loadCacheAccelerator(null, false);
3483
+			}
3306 3484
 			return false;
3307 3485
 		}
3308 3486
 
@@ -3314,9 +3492,9 @@  discard block
 block discarded – undo
3314 3492
 		{
3315 3493
 			$cacheAPI = $testAPI;
3316 3494
 			return $cacheAPI;
3495
+		} else {
3496
+					return $testAPI;
3317 3497
 		}
3318
-		else
3319
-			return $testAPI;
3320 3498
 	}
3321 3499
 }
3322 3500
 
@@ -3336,8 +3514,9 @@  discard block
 block discarded – undo
3336 3514
 
3337 3515
 	// @todo Why are we doing this if caching is disabled?
3338 3516
 
3339
-	if (function_exists('call_integration_hook'))
3340
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3517
+	if (function_exists('call_integration_hook')) {
3518
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3519
+	}
3341 3520
 
3342 3521
 	/* Refresh the cache if either:
3343 3522
 		1. Caching is disabled.
@@ -3351,16 +3530,19 @@  discard block
 block discarded – undo
3351 3530
 		require_once($sourcedir . '/' . $file);
3352 3531
 		$cache_block = call_user_func_array($function, $params);
3353 3532
 
3354
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3355
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3533
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3534
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3535
+		}
3356 3536
 	}
3357 3537
 
3358 3538
 	// Some cached data may need a freshening up after retrieval.
3359
-	if (!empty($cache_block['post_retri_eval']))
3360
-		eval($cache_block['post_retri_eval']);
3539
+	if (!empty($cache_block['post_retri_eval'])) {
3540
+			eval($cache_block['post_retri_eval']);
3541
+	}
3361 3542
 
3362
-	if (function_exists('call_integration_hook'))
3363
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3543
+	if (function_exists('call_integration_hook')) {
3544
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3545
+	}
3364 3546
 
3365 3547
 	return $cache_block['data'];
3366 3548
 }
@@ -3387,8 +3569,9 @@  discard block
 block discarded – undo
3387 3569
 	global $smcFunc, $cache_enable, $cacheAPI;
3388 3570
 	global $cache_hits, $cache_count, $db_show_debug;
3389 3571
 
3390
-	if (empty($cache_enable) || empty($cacheAPI))
3391
-		return;
3572
+	if (empty($cache_enable) || empty($cacheAPI)) {
3573
+			return;
3574
+	}
3392 3575
 
3393 3576
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3394 3577
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3401,12 +3584,14 @@  discard block
 block discarded – undo
3401 3584
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3402 3585
 	$cacheAPI->putData($key, $value, $ttl);
3403 3586
 
3404
-	if (function_exists('call_integration_hook'))
3405
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3587
+	if (function_exists('call_integration_hook')) {
3588
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3589
+	}
3406 3590
 
3407
-	if (isset($db_show_debug) && $db_show_debug === true)
3408
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3409
-}
3591
+	if (isset($db_show_debug) && $db_show_debug === true) {
3592
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3593
+	}
3594
+	}
3410 3595
 
3411 3596
 /**
3412 3597
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3422,8 +3607,9 @@  discard block
 block discarded – undo
3422 3607
 	global $smcFunc, $cache_enable, $cacheAPI;
3423 3608
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3424 3609
 
3425
-	if (empty($cache_enable) || empty($cacheAPI))
3426
-		return;
3610
+	if (empty($cache_enable) || empty($cacheAPI)) {
3611
+			return;
3612
+	}
3427 3613
 
3428 3614
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3429 3615
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3443,16 +3629,18 @@  discard block
 block discarded – undo
3443 3629
 
3444 3630
 		if (empty($value))
3445 3631
 		{
3446
-			if (!is_array($cache_misses))
3447
-				$cache_misses = array();
3632
+			if (!is_array($cache_misses)) {
3633
+							$cache_misses = array();
3634
+			}
3448 3635
 
3449 3636
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3450 3637
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3451 3638
 		}
3452 3639
 	}
3453 3640
 
3454
-	if (function_exists('call_integration_hook') && isset($value))
3455
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3641
+	if (function_exists('call_integration_hook') && isset($value)) {
3642
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3643
+	}
3456 3644
 
3457 3645
 	return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3458 3646
 }
@@ -3474,8 +3662,9 @@  discard block
 block discarded – undo
3474 3662
 	global $cacheAPI;
3475 3663
 
3476 3664
 	// If we can't get to the API, can't do this.
3477
-	if (empty($cacheAPI))
3478
-		return;
3665
+	if (empty($cacheAPI)) {
3666
+			return;
3667
+	}
3479 3668
 
3480 3669
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3481 3670
 	$cacheAPI->cleanCache($type);
@@ -3500,8 +3689,9 @@  discard block
 block discarded – undo
3500 3689
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $user_info;
3501 3690
 
3502 3691
 	// Come on!
3503
-	if (empty($data))
3504
-		return array();
3692
+	if (empty($data)) {
3693
+			return array();
3694
+	}
3505 3695
 
3506 3696
 	// Set a nice default var.
3507 3697
 	$image = '';
@@ -3509,11 +3699,11 @@  discard block
 block discarded – undo
3509 3699
 	// Gravatar has been set as mandatory!
3510 3700
 	if (!empty($modSettings['gravatarOverride']))
3511 3701
 	{
3512
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3513
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3514
-
3515
-		else if (!empty($data['email']))
3516
-			$image = get_gravatar_url($data['email']);
3702
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3703
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3704
+		} else if (!empty($data['email'])) {
3705
+					$image = get_gravatar_url($data['email']);
3706
+		}
3517 3707
 	}
3518 3708
 
3519 3709
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3525,54 +3715,60 @@  discard block
 block discarded – undo
3525 3715
 			// Gravatar.
3526 3716
 			if (stristr($data['avatar'], 'gravatar://'))
3527 3717
 			{
3528
-				if ($data['avatar'] == 'gravatar://')
3529
-					$image = get_gravatar_url($data['email']);
3530
-
3531
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3532
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3718
+				if ($data['avatar'] == 'gravatar://') {
3719
+									$image = get_gravatar_url($data['email']);
3720
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3721
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3722
+				}
3533 3723
 			}
3534 3724
 
3535 3725
 			// External url.
3536 3726
 			else
3537 3727
 			{
3538 3728
 				// Using ssl?
3539
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3540
-					$image = get_proxied_url($data['avatar']);
3729
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3730
+									$image = get_proxied_url($data['avatar']);
3731
+				}
3541 3732
 
3542 3733
 				// Just a plain external url.
3543
-				else
3544
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3734
+				else {
3735
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3736
+				}
3545 3737
 			}
3546 3738
 		}
3547 3739
 
3548 3740
 		// Perhaps this user has an attachment as avatar...
3549
-		else if (!empty($data['filename']))
3550
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3741
+		else if (!empty($data['filename'])) {
3742
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3743
+		}
3551 3744
 
3552 3745
 		// Right... no avatar... use our default image.
3553
-		else
3554
-			$image = $modSettings['avatar_url'] . '/default.png';
3746
+		else {
3747
+					$image = $modSettings['avatar_url'] . '/default.png';
3748
+		}
3555 3749
 	}
3556 3750
 
3557 3751
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3558 3752
 
3559 3753
 	// 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.
3560
-	if (!empty($image))
3561
-		return array(
3754
+	if (!empty($image)) {
3755
+			return array(
3562 3756
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3563 3757
 			'image' => '<img class="avatar" src="' . $image . '" />',
3564 3758
 			'href' => $image,
3565 3759
 			'url' => $image,
3566 3760
 		);
3761
+	}
3567 3762
 
3568 3763
 	// Fallback to make life easier for everyone...
3569
-	else
3570
-		return array(
3764
+	else {
3765
+			return array(
3571 3766
 			'name' => '',
3572 3767
 			'image' => '',
3573 3768
 			'href' => '',
3574 3769
 			'url' => '',
3575 3770
 		);
3576
-}
3771
+	}
3772
+	}
3577 3773
 
3578 3774
 ?>
3579 3775
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Session.php 1 patch
Braces   +40 added lines, -27 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
  * @version 2.1 Beta 4
18 18
  */
19 19
 
20
-if (!defined('SMF'))
20
+if (!defined('SMF')) {
21 21
 	die('No direct access...');
22
+}
22 23
 
23 24
 /**
24 25
  * Attempt to start the session, unless it already has been.
@@ -38,8 +39,9 @@  discard block
 block discarded – undo
38 39
 	{
39 40
 		$parsed_url = parse_url($boardurl);
40 41
 
41
-		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
42
-			@ini_set('session.cookie_domain', '.' . $parts[1]);
42
+		if (preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
43
+					@ini_set('session.cookie_domain', '.' . $parts[1]);
44
+		}
43 45
 	}
44 46
 	// @todo Set the session cookie path?
45 47
 
@@ -47,8 +49,9 @@  discard block
 block discarded – undo
47 49
 	if ((ini_get('session.auto_start') == 1 && !empty($modSettings['databaseSession_enable'])) || session_id() == '')
48 50
 	{
49 51
 		// Attempt to end the already-started session.
50
-		if (ini_get('session.auto_start') == 1)
51
-			session_write_close();
52
+		if (ini_get('session.auto_start') == 1) {
53
+					session_write_close();
54
+		}
52 55
 
53 56
 		// This is here to stop people from using bad junky PHPSESSIDs.
54 57
 		if (isset($_REQUEST[session_name()]) && preg_match('~^[A-Za-z0-9,-]{16,64}$~', $_REQUEST[session_name()]) == 0 && !isset($_COOKIE[session_name()]))
@@ -63,23 +66,26 @@  discard block
 block discarded – undo
63 66
 		if (!empty($modSettings['databaseSession_enable']))
64 67
 		{
65 68
 			@ini_set('session.serialize_handler', 'php_serialize');
66
-			if (ini_get('session.serialize_handler') != 'php_serialize')
67
-				@ini_set('session.serialize_handler', 'php');
69
+			if (ini_get('session.serialize_handler') != 'php_serialize') {
70
+							@ini_set('session.serialize_handler', 'php');
71
+			}
68 72
 			session_set_save_handler('sessionOpen', 'sessionClose', 'sessionRead', 'sessionWrite', 'sessionDestroy', 'sessionGC');
69 73
 			@ini_set('session.gc_probability', '1');
74
+		} elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime'])) {
75
+					@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
70 76
 		}
71
-		elseif (ini_get('session.gc_maxlifetime') <= 1440 && !empty($modSettings['databaseSession_lifetime']))
72
-			@ini_set('session.gc_maxlifetime', max($modSettings['databaseSession_lifetime'], 60));
73 77
 
74 78
 		// Use cache setting sessions?
75
-		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli')
76
-			call_integration_hook('integrate_session_handlers');
79
+		if (empty($modSettings['databaseSession_enable']) && !empty($modSettings['cache_enable']) && php_sapi_name() != 'cli') {
80
+					call_integration_hook('integrate_session_handlers');
81
+		}
77 82
 
78 83
 		session_start();
79 84
 
80 85
 		// Change it so the cache settings are a little looser than default.
81
-		if (!empty($modSettings['databaseSession_loose']))
82
-			header('cache-control: private');
86
+		if (!empty($modSettings['databaseSession_loose'])) {
87
+					header('cache-control: private');
88
+		}
83 89
 	}
84 90
 
85 91
 	// Set the randomly generated code.
@@ -125,8 +131,9 @@  discard block
 block discarded – undo
125 131
 {
126 132
 	global $smcFunc;
127 133
 
128
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
129
-		return '';
134
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
135
+			return '';
136
+	}
130 137
 
131 138
 	// Look for it in the database.
132 139
 	$result = $smcFunc['db_query']('', '
@@ -156,8 +163,9 @@  discard block
 block discarded – undo
156 163
 	global $smcFunc, $db_connection, $db_server, $db_name, $db_user, $db_passwd;
157 164
 	global $db_prefix, $db_persist, $db_port, $db_mb4;
158 165
 
159
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
160
-		return false;
166
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
167
+			return false;
168
+	}
161 169
 
162 170
 	// php < 7.0 need this
163 171
 	if (empty($db_connection))
@@ -165,11 +173,13 @@  discard block
 block discarded – undo
165 173
 		$db_options = array();
166 174
 
167 175
 		// Add in the port if needed
168
-		if (!empty($db_port))
169
-			$db_options['port'] = $db_port;
176
+		if (!empty($db_port)) {
177
+					$db_options['port'] = $db_port;
178
+		}
170 179
 
171
-		if (!empty($db_mb4))
172
-		$db_options['db_mb4'] = $db_mb4;
180
+		if (!empty($db_mb4)) {
181
+				$db_options['db_mb4'] = $db_mb4;
182
+		}
173 183
 
174 184
 		$options = array_merge($db_options, array('persist' => $db_persist, 'dont_select_db' => SMF == 'SSI'));
175 185
 
@@ -189,13 +199,14 @@  discard block
 block discarded – undo
189 199
 	);
190 200
 
191 201
 	// If that didn't work, try inserting a new one.
192
-	if ($smcFunc['db_affected_rows']() == 0)
193
-		$smcFunc['db_insert']('ignore',
202
+	if ($smcFunc['db_affected_rows']() == 0) {
203
+			$smcFunc['db_insert']('ignore',
194 204
 			'{db_prefix}sessions',
195 205
 			array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'),
196 206
 			array($session_id, $data, time()),
197 207
 			array('session_id')
198 208
 		);
209
+	}
199 210
 
200 211
 	return ($smcFunc['db_affected_rows']() == 0 ? false : true);
201 212
 }
@@ -210,8 +221,9 @@  discard block
 block discarded – undo
210 221
 {
211 222
 	global $smcFunc;
212 223
 
213
-	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0)
214
-		return false;
224
+	if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) {
225
+			return false;
226
+	}
215 227
 
216 228
 	// Just delete the row...
217 229
 	$smcFunc['db_query']('', '
@@ -237,8 +249,9 @@  discard block
 block discarded – undo
237 249
 	global $modSettings, $smcFunc;
238 250
 
239 251
 	// Just set to the default or lower?  Ignore it for a higher value. (hopefully)
240
-	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime))
241
-		$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
252
+	if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) {
253
+			$max_lifetime = max($modSettings['databaseSession_lifetime'], 60);
254
+	}
242 255
 
243 256
 	// Clean up after yerself ;).
244 257
 	$smcFunc['db_query']('', '
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +260 added lines, -191 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
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -64,13 +65,16 @@  discard block
 block discarded – undo
64 65
 			'db_custom_order'			=> 'smf_db_custom_order',
65 66
 			'db_native_replace'			=> 'smf_db_native_replace',
66 67
 		);
68
+	}
67 69
 
68
-	if (!empty($db_options['persist']))
69
-		$db_server = 'p:' . $db_server;
70
+	if (!empty($db_options['persist'])) {
71
+			$db_server = 'p:' . $db_server;
72
+	}
70 73
 
71 74
 	// We are not going to make it very far without these.
72
-	if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect'))
73
-		display_db_error();
75
+	if (!function_exists('mysqli_init') || !function_exists('mysqli_real_connect')) {
76
+			display_db_error();
77
+	}
74 78
 
75 79
 	$connection = mysqli_init();
76 80
 
@@ -80,29 +84,33 @@  discard block
 block discarded – undo
80 84
 
81 85
 	if ($connection)
82 86
 	{
83
-		if (!empty($db_options['port']))
84
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
85
-		else
86
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
87
+		if (!empty($db_options['port'])) {
88
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, $db_options['port'], null, $flags);
89
+		} else {
90
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, null, 0, null, $flags);
91
+		}
87 92
 	}
88 93
 
89 94
 	// Something's wrong, show an error if its fatal (which we assume it is)
90 95
 	if ($success === false)
91 96
 	{
92
-		if (!empty($db_options['non_fatal']))
93
-			return null;
94
-		else
95
-			display_db_error();
97
+		if (!empty($db_options['non_fatal'])) {
98
+					return null;
99
+		} else {
100
+					display_db_error();
101
+		}
96 102
 	}
97 103
 
98 104
 	// Select the database, unless told not to
99
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
100
-		display_db_error();
105
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
106
+			display_db_error();
107
+	}
101 108
 
102 109
 	mysqli_query($connection, 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'');
103 110
 
104
-	if (!empty($db_options['db_mb4']))
105
-		$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
111
+	if (!empty($db_options['db_mb4'])) {
112
+			$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
113
+	}
106 114
 
107 115
 	return $connection;
108 116
 }
@@ -173,34 +181,42 @@  discard block
 block discarded – undo
173 181
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
174 182
 
175 183
 	list ($values, $connection) = $db_callback;
176
-	if (!is_object($connection))
177
-		display_db_error();
184
+	if (!is_object($connection)) {
185
+			display_db_error();
186
+	}
178 187
 
179
-	if ($matches[1] === 'db_prefix')
180
-		return $db_prefix;
188
+	if ($matches[1] === 'db_prefix') {
189
+			return $db_prefix;
190
+	}
181 191
 
182
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
183
-		return $user_info[$matches[1]];
192
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
193
+			return $user_info[$matches[1]];
194
+	}
184 195
 
185
-	if ($matches[1] === 'empty')
186
-		return '\'\'';
196
+	if ($matches[1] === 'empty') {
197
+			return '\'\'';
198
+	}
187 199
 
188
-	if (!isset($matches[2]))
189
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
200
+	if (!isset($matches[2])) {
201
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
202
+	}
190 203
 
191
-	if ($matches[1] === 'literal')
192
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
204
+	if ($matches[1] === 'literal') {
205
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
206
+	}
193 207
 
194
-	if (!isset($values[$matches[2]]))
195
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
208
+	if (!isset($values[$matches[2]])) {
209
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
210
+	}
196 211
 
197 212
 	$replacement = $values[$matches[2]];
198 213
 
199 214
 	switch ($matches[1])
200 215
 	{
201 216
 		case 'int':
202
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
203
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
217
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
218
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
219
+			}
204 220
 			return (string) (int) $replacement;
205 221
 		break;
206 222
 
@@ -212,65 +228,73 @@  discard block
 block discarded – undo
212 228
 		case 'array_int':
213 229
 			if (is_array($replacement))
214 230
 			{
215
-				if (empty($replacement))
216
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
231
+				if (empty($replacement)) {
232
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
233
+				}
217 234
 
218 235
 				foreach ($replacement as $key => $value)
219 236
 				{
220
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
221
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
237
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
238
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
239
+					}
222 240
 
223 241
 					$replacement[$key] = (string) (int) $value;
224 242
 				}
225 243
 
226 244
 				return implode(', ', $replacement);
245
+			} else {
246
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
227 247
 			}
228
-			else
229
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
230 248
 
231 249
 		break;
232 250
 
233 251
 		case 'array_string':
234 252
 			if (is_array($replacement))
235 253
 			{
236
-				if (empty($replacement))
237
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
254
+				if (empty($replacement)) {
255
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
256
+				}
238 257
 
239
-				foreach ($replacement as $key => $value)
240
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
258
+				foreach ($replacement as $key => $value) {
259
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
260
+				}
241 261
 
242 262
 				return implode(', ', $replacement);
263
+			} else {
264
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
243 265
 			}
244
-			else
245
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
246 266
 		break;
247 267
 
248 268
 		case 'date':
249
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
250
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
251
-			else
252
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
269
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
270
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
271
+			} else {
272
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
273
+			}
253 274
 		break;
254 275
 
255 276
 		case 'time':
256
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
257
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
258
-			else
259
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
277
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
278
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
279
+			} else {
280
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
281
+			}
260 282
 		break;
261 283
 
262 284
 		case 'datetime':
263
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
264
-				return 'str_to_date('.
285
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
286
+							return 'str_to_date('.
265 287
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
266 288
 					',\'%Y-%m-%d %h:%i:%s\')';
267
-			else
268
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
289
+			} else {
290
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
291
+			}
269 292
 		break;
270 293
 
271 294
 		case 'float':
272
-			if (!is_numeric($replacement))
273
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
295
+			if (!is_numeric($replacement)) {
296
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
297
+			}
274 298
 			return (string) (float) $replacement;
275 299
 		break;
276 300
 
@@ -284,32 +308,37 @@  discard block
 block discarded – undo
284 308
 		break;
285 309
 
286 310
 		case 'inet':
287
-			if ($replacement == 'null' || $replacement == '')
288
-				return 'null';
289
-			if (!isValidIP($replacement))
290
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
311
+			if ($replacement == 'null' || $replacement == '') {
312
+							return 'null';
313
+			}
314
+			if (!isValidIP($replacement)) {
315
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
316
+			}
291 317
 			//we don't use the native support of mysql > 5.6.2
292 318
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
293 319
 
294 320
 		case 'array_inet':
295 321
 			if (is_array($replacement))
296 322
 			{
297
-				if (empty($replacement))
298
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
323
+				if (empty($replacement)) {
324
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
325
+				}
299 326
 
300 327
 				foreach ($replacement as $key => $value)
301 328
 				{
302
-					if ($replacement == 'null' || $replacement == '')
303
-						$replacement[$key] = 'null';
304
-					if (!isValidIP($value))
305
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
329
+					if ($replacement == 'null' || $replacement == '') {
330
+											$replacement[$key] = 'null';
331
+					}
332
+					if (!isValidIP($value)) {
333
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
334
+					}
306 335
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
307 336
 				}
308 337
 
309 338
 				return implode(', ', $replacement);
339
+			} else {
340
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
310 341
 			}
311
-			else
312
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
313 342
 		break;
314 343
 
315 344
 		default:
@@ -380,18 +409,20 @@  discard block
 block discarded – undo
380 409
 	// One more query....
381 410
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
382 411
 
383
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
384
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
412
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
413
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
414
+	}
385 415
 
386 416
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
387 417
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
388 418
 	{
389 419
 		// Add before LIMIT
390
-		if ($pos = strpos($db_string, 'LIMIT '))
391
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
392
-		else
393
-			// Append it.
420
+		if ($pos = strpos($db_string, 'LIMIT ')) {
421
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
422
+		} else {
423
+					// Append it.
394 424
 			$db_string .= "\n\t\t\tORDER BY null";
425
+		}
395 426
 	}
396 427
 
397 428
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -417,17 +448,18 @@  discard block
 block discarded – undo
417 448
 		while (true)
418 449
 		{
419 450
 			$pos = strpos($db_string_1, '\'', $pos + 1);
420
-			if ($pos === false)
421
-				break;
451
+			if ($pos === false) {
452
+							break;
453
+			}
422 454
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
423 455
 
424 456
 			while (true)
425 457
 			{
426 458
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
427 459
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
428
-				if ($pos1 === false)
429
-					break;
430
-				elseif ($pos2 === false || $pos2 > $pos1)
460
+				if ($pos1 === false) {
461
+									break;
462
+				} elseif ($pos2 === false || $pos2 > $pos1)
431 463
 				{
432 464
 					$pos = $pos1;
433 465
 					break;
@@ -443,16 +475,19 @@  discard block
 block discarded – undo
443 475
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
444 476
 
445 477
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
446
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
447
-			$fail = true;
478
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
479
+					$fail = true;
480
+		}
448 481
 		// Trying to change passwords, slow us down, or something?
449
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
450
-			$fail = true;
451
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
452
-			$fail = true;
482
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
483
+					$fail = true;
484
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
485
+					$fail = true;
486
+		}
453 487
 
454
-		if (!empty($fail) && function_exists('log_error'))
455
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
488
+		if (!empty($fail) && function_exists('log_error')) {
489
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
490
+		}
456 491
 	}
457 492
 
458 493
 	// Debugging.
@@ -462,8 +497,9 @@  discard block
 block discarded – undo
462 497
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
463 498
 
464 499
 		// Initialize $db_cache if not already initialized.
465
-		if (!isset($db_cache))
466
-			$db_cache = array();
500
+		if (!isset($db_cache)) {
501
+					$db_cache = array();
502
+		}
467 503
 
468 504
 		if (!empty($_SESSION['debug_redirect']))
469 505
 		{
@@ -479,17 +515,20 @@  discard block
 block discarded – undo
479 515
 		$db_cache[$db_count]['s'] = ($st = microtime(true)) - $time_start;
480 516
 	}
481 517
 
482
-	if (empty($db_unbuffered))
483
-		$ret = @mysqli_query($connection, $db_string);
484
-	else
485
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
518
+	if (empty($db_unbuffered)) {
519
+			$ret = @mysqli_query($connection, $db_string);
520
+	} else {
521
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
522
+	}
486 523
 
487
-	if ($ret === false && empty($db_values['db_error_skip']))
488
-		$ret = smf_db_error($db_string, $connection);
524
+	if ($ret === false && empty($db_values['db_error_skip'])) {
525
+			$ret = smf_db_error($db_string, $connection);
526
+	}
489 527
 
490 528
 	// Debugging.
491
-	if (isset($db_show_debug) && $db_show_debug === true)
492
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
529
+	if (isset($db_show_debug) && $db_show_debug === true) {
530
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
531
+	}
493 532
 
494 533
 	return $ret;
495 534
 }
@@ -536,12 +575,13 @@  discard block
 block discarded – undo
536 575
 	// Decide which connection to use
537 576
 	$connection = $connection === null ? $db_connection : $connection;
538 577
 
539
-	if ($type == 'begin')
540
-		return @mysqli_query($connection, 'BEGIN');
541
-	elseif ($type == 'rollback')
542
-		return @mysqli_query($connection, 'ROLLBACK');
543
-	elseif ($type == 'commit')
544
-		return @mysqli_query($connection, 'COMMIT');
578
+	if ($type == 'begin') {
579
+			return @mysqli_query($connection, 'BEGIN');
580
+	} elseif ($type == 'rollback') {
581
+			return @mysqli_query($connection, 'ROLLBACK');
582
+	} elseif ($type == 'commit') {
583
+			return @mysqli_query($connection, 'COMMIT');
584
+	}
545 585
 
546 586
 	return false;
547 587
 }
@@ -579,8 +619,9 @@  discard block
 block discarded – undo
579 619
 	//    1213: Deadlock found.
580 620
 
581 621
 	// Log the error.
582
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
583
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
622
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
623
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
624
+	}
584 625
 
585 626
 	// Database error auto fixing ;).
586 627
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -589,8 +630,9 @@  discard block
 block discarded – undo
589 630
 		$old_cache = @$modSettings['cache_enable'];
590 631
 		$modSettings['cache_enable'] = '1';
591 632
 
592
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
593
-			$db_last_error = max(@$db_last_error, $temp);
633
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
634
+					$db_last_error = max(@$db_last_error, $temp);
635
+		}
594 636
 
595 637
 		if (@$db_last_error < time() - 3600 * 24 * 3)
596 638
 		{
@@ -606,8 +648,9 @@  discard block
 block discarded – undo
606 648
 					foreach ($tables as $table)
607 649
 					{
608 650
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
609
-						if (trim($table) != '')
610
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
651
+						if (trim($table) != '') {
652
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
653
+						}
611 654
 					}
612 655
 				}
613 656
 
@@ -616,8 +659,9 @@  discard block
 block discarded – undo
616 659
 			// Table crashed.  Let's try to fix it.
617 660
 			elseif ($query_errno == 1016)
618 661
 			{
619
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
620
-					$fix_tables = array('`' . $match[1] . '`');
662
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
663
+									$fix_tables = array('`' . $match[1] . '`');
664
+				}
621 665
 			}
622 666
 			// Indexes crashed.  Should be easy to fix!
623 667
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -636,13 +680,15 @@  discard block
 block discarded – undo
636 680
 
637 681
 			// Make a note of the REPAIR...
638 682
 			cache_put_data('db_last_error', time(), 600);
639
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
640
-				updateSettingsFile(array('db_last_error' => time()));
683
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
684
+							updateSettingsFile(array('db_last_error' => time()));
685
+			}
641 686
 
642 687
 			// Attempt to find and repair the broken table.
643
-			foreach ($fix_tables as $table)
644
-				$smcFunc['db_query']('', "
688
+			foreach ($fix_tables as $table) {
689
+							$smcFunc['db_query']('', "
645 690
 					REPAIR TABLE $table", false, false);
691
+			}
646 692
 
647 693
 			// And send off an email!
648 694
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -651,11 +697,12 @@  discard block
 block discarded – undo
651 697
 
652 698
 			// Try the query again...?
653 699
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
654
-			if ($ret !== false)
655
-				return $ret;
700
+			if ($ret !== false) {
701
+							return $ret;
702
+			}
703
+		} else {
704
+					$modSettings['cache_enable'] = $old_cache;
656 705
 		}
657
-		else
658
-			$modSettings['cache_enable'] = $old_cache;
659 706
 
660 707
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
661 708
 		if (in_array($query_errno, array(1205, 1213)))
@@ -668,24 +715,27 @@  discard block
 block discarded – undo
668 715
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
669 716
 
670 717
 					$new_errno = mysqli_errno($db_connection);
671
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
672
-						break;
718
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
719
+											break;
720
+					}
673 721
 				}
674 722
 
675 723
 				// If it failed again, shucks to be you... we're not trying it over and over.
676
-				if ($ret !== false)
677
-					return $ret;
724
+				if ($ret !== false) {
725
+									return $ret;
726
+				}
678 727
 			}
679 728
 		}
680 729
 		// Are they out of space, perhaps?
681 730
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
682 731
 		{
683
-			if (!isset($txt))
684
-				$query_error .= ' - check database storage space.';
685
-			else
732
+			if (!isset($txt)) {
733
+							$query_error .= ' - check database storage space.';
734
+			} else
686 735
 			{
687
-				if (!isset($txt['mysql_error_space']))
688
-					loadLanguage('Errors');
736
+				if (!isset($txt['mysql_error_space'])) {
737
+									loadLanguage('Errors');
738
+				}
689 739
 
690 740
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
691 741
 			}
@@ -693,15 +743,17 @@  discard block
 block discarded – undo
693 743
 	}
694 744
 
695 745
 	// Nothing's defined yet... just die with it.
696
-	if (empty($context) || empty($txt))
697
-		die($query_error);
746
+	if (empty($context) || empty($txt)) {
747
+			die($query_error);
748
+	}
698 749
 
699 750
 	// Show an error message, if possible.
700 751
 	$context['error_title'] = $txt['database_error'];
701
-	if (allowedTo('admin_forum'))
702
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
703
-	else
704
-		$context['error_message'] = $txt['try_again'];
752
+	if (allowedTo('admin_forum')) {
753
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
754
+	} else {
755
+			$context['error_message'] = $txt['try_again'];
756
+	}
705 757
 
706 758
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
707 759
 	{
@@ -733,8 +785,9 @@  discard block
 block discarded – undo
733 785
 	$return_var = null;
734 786
 
735 787
 	// With nothing to insert, simply return.
736
-	if (empty($data))
737
-		return;
788
+	if (empty($data)) {
789
+			return;
790
+	}
738 791
 
739 792
 	// Replace the prefix holder with the actual prefix.
740 793
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -744,23 +797,26 @@  discard block
 block discarded – undo
744 797
 	if (!empty($keys) && (count($keys) > 0) && $returnmode > 0)
745 798
 	{
746 799
 		$with_returning = true;
747
-		if ($returnmode == 2)
748
-			$return_var = array();
800
+		if ($returnmode == 2) {
801
+					$return_var = array();
802
+		}
749 803
 	}
750 804
 
751 805
 	// Inserting data as a single row can be done as a single array.
752
-	if (!is_array($data[array_rand($data)]))
753
-		$data = array($data);
806
+	if (!is_array($data[array_rand($data)])) {
807
+			$data = array($data);
808
+	}
754 809
 
755 810
 	// Create the mold for a single row insert.
756 811
 	$insertData = '(';
757 812
 	foreach ($columns as $columnName => $type)
758 813
 	{
759 814
 		// Are we restricting the length?
760
-		if (strpos($type, 'string-') !== false)
761
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
762
-		else
763
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
815
+		if (strpos($type, 'string-') !== false) {
816
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
817
+		} else {
818
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
819
+		}
764 820
 	}
765 821
 	$insertData = substr($insertData, 0, -2) . ')';
766 822
 
@@ -769,8 +825,9 @@  discard block
 block discarded – undo
769 825
 
770 826
 	// Here's where the variables are injected to the query.
771 827
 	$insertRows = array();
772
-	foreach ($data as $dataRow)
773
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
828
+	foreach ($data as $dataRow) {
829
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
830
+	}
774 831
 
775 832
 	// Determine the method of insertion.
776 833
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -789,8 +846,7 @@  discard block
 block discarded – undo
789 846
 			),
790 847
 			$connection
791 848
 		);
792
-	}
793
-	else //special way for ignore method with returning
849
+	} else //special way for ignore method with returning
794 850
 	{
795 851
 		$count = count($insertRows);
796 852
 		$ai = 0;
@@ -810,19 +866,21 @@  discard block
 block discarded – undo
810 866
 			);
811 867
 			$new_id = $smcFunc['db_insert_id']();
812 868
 
813
-			if ($last_id != $new_id) //the inserted value was new
869
+			if ($last_id != $new_id) {
870
+				//the inserted value was new
814 871
 			{
815 872
 				$ai = $new_id;
816 873
 			}
817
-			else	// the inserted value already exists we need to find the pk
874
+			} else	// the inserted value already exists we need to find the pk
818 875
 			{
819 876
 				$where_string = '';
820 877
 				$count2 = count($indexed_columns);
821 878
 				for ($x = 0; $x < $count2; $x++)
822 879
 				{
823 880
 					$where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x];
824
-					if (($x + 1) < $count2)
825
-						$where_string += ' AND ';
881
+					if (($x + 1) < $count2) {
882
+											$where_string += ' AND ';
883
+					}
826 884
 				}
827 885
 
828 886
 				$request = $smcFunc['db_query']('','
@@ -838,25 +896,27 @@  discard block
 block discarded – undo
838 896
 				}
839 897
 			}
840 898
 
841
-			if ($returnmode == 1)
842
-				$return_var = $ai;
843
-			else if ($returnmode == 2)
844
-				$return_var[] = $ai;
899
+			if ($returnmode == 1) {
900
+							$return_var = $ai;
901
+			} else if ($returnmode == 2) {
902
+							$return_var[] = $ai;
903
+			}
845 904
 		}
846 905
 	}
847 906
 
848 907
 
849 908
 	if ($with_returning)
850 909
 	{
851
-		if ($returnmode == 1 && empty($return_var))
852
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
853
-		else if ($returnmode == 2 && empty($return_var))
910
+		if ($returnmode == 1 && empty($return_var)) {
911
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
912
+		} else if ($returnmode == 2 && empty($return_var))
854 913
 		{
855 914
 			$return_var = array();
856 915
 			$count = count($insertRows);
857 916
 			$start = smf_db_insert_id($table, $keys[0]);
858
-			for ($i = 0; $i < $count; $i++ )
859
-				$return_var[] = $start + $i;
917
+			for ($i = 0; $i < $count; $i++ ) {
918
+							$return_var[] = $start + $i;
919
+			}
860 920
 		}
861 921
 		return $return_var;
862 922
 	}
@@ -874,8 +934,9 @@  discard block
 block discarded – undo
874 934
  */
875 935
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
876 936
 {
877
-	if (empty($log_message))
878
-		$log_message = $error_message;
937
+	if (empty($log_message)) {
938
+			$log_message = $error_message;
939
+	}
879 940
 
880 941
 	foreach (debug_backtrace() as $step)
881 942
 	{
@@ -894,12 +955,14 @@  discard block
 block discarded – undo
894 955
 	}
895 956
 
896 957
 	// A special case - we want the file and line numbers for debugging.
897
-	if ($error_type == 'return')
898
-		return array($file, $line);
958
+	if ($error_type == 'return') {
959
+			return array($file, $line);
960
+	}
899 961
 
900 962
 	// Is always a critical error.
901
-	if (function_exists('log_error'))
902
-		log_error($log_message, 'critical', $file, $line);
963
+	if (function_exists('log_error')) {
964
+			log_error($log_message, 'critical', $file, $line);
965
+	}
903 966
 
904 967
 	if (function_exists('fatal_error'))
905 968
 	{
@@ -907,12 +970,12 @@  discard block
 block discarded – undo
907 970
 
908 971
 		// Cannot continue...
909 972
 		exit;
973
+	} elseif ($error_type) {
974
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
975
+	} else {
976
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
977
+	}
910 978
 	}
911
-	elseif ($error_type)
912
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
913
-	else
914
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
915
-}
916 979
 
917 980
 /**
918 981
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -929,10 +992,11 @@  discard block
 block discarded – undo
929 992
 		'\\' => '\\\\',
930 993
 	);
931 994
 
932
-	if ($translate_human_wildcards)
933
-		$replacements += array(
995
+	if ($translate_human_wildcards) {
996
+			$replacements += array(
934 997
 			'*' => '%',
935 998
 		);
999
+	}
936 1000
 
937 1001
 	return strtr($string, $replacements);
938 1002
 }
@@ -946,8 +1010,9 @@  discard block
 block discarded – undo
946 1010
  */
947 1011
 function smf_is_resource($result)
948 1012
 {
949
-	if ($result instanceof mysqli_result)
950
-		return true;
1013
+	if ($result instanceof mysqli_result) {
1014
+			return true;
1015
+	}
951 1016
 
952 1017
 	return false;
953 1018
 }
@@ -976,19 +1041,22 @@  discard block
 block discarded – undo
976 1041
 	static $mysql_error_data_prep;
977 1042
 
978 1043
 	// without database we can't do anything
979
-	if (empty($db_connection))
980
-		return;
1044
+	if (empty($db_connection)) {
1045
+			return;
1046
+	}
981 1047
 
982
-	if (empty($mysql_error_data_prep))
983
-			$mysql_error_data_prep = mysqli_prepare($db_connection,
1048
+	if (empty($mysql_error_data_prep)) {
1049
+				$mysql_error_data_prep = mysqli_prepare($db_connection,
984 1050
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace)
985 1051
 													VALUES(		?,		?,		unhex(?), ?, 		?,		?,			?,		?,	?, ?)'
986 1052
 			);
1053
+	}
987 1054
 
988
-	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false)
989
-		$error_array[2] = bin2hex(inet_pton($error_array[2]));
990
-	else
991
-		$error_array[2] = null;
1055
+	if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) {
1056
+			$error_array[2] = bin2hex(inet_pton($error_array[2]));
1057
+	} else {
1058
+			$error_array[2] = null;
1059
+	}
992 1060
 	mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssis',
993 1061
 		$error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6],
994 1062
 		$error_array[7], $error_array[8], $error_array[9]);
@@ -1010,8 +1078,9 @@  discard block
 block discarded – undo
1010 1078
 	$count = count($array_values);
1011 1079
 	$then = ($desc ? ' THEN -' : ' THEN ');
1012 1080
 
1013
-	for ($i = 0; $i < $count; $i++)
1014
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1081
+	for ($i = 0; $i < $count; $i++) {
1082
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1083
+	}
1015 1084
 
1016 1085
 	$return .= 'END';
1017 1086
 	return $return;
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +238 added lines, -175 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
  * Maps the implementations in this file (smf_db_function_name)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']))
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc'])) {
39
+			$smcFunc += array(
39 40
 			'db_query'					=> 'smf_db_query',
40 41
 			'db_quote'					=> 'smf_db_quote',
41 42
 			'db_insert'					=> 'smf_db_insert',
@@ -65,15 +66,18 @@  discard block
 block discarded – undo
65 66
 			'db_custom_order'			=> 'smf_db_custom_order',
66 67
 			'db_native_replace'			=> 'smf_db_native_replace',
67 68
 		);
69
+	}
68 70
 
69 71
 	// We are not going to make it very far without these.
70
-	if (!function_exists('pg_pconnect'))
71
-		display_db_error();
72
+	if (!function_exists('pg_pconnect')) {
73
+			display_db_error();
74
+	}
72 75
 
73
-	if (!empty($db_options['persist']))
74
-		$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
75
-	else
76
-		$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
76
+	if (!empty($db_options['persist'])) {
77
+			$connection = @pg_pconnect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
78
+	} else {
79
+			$connection = @pg_connect((empty($db_server) ? '' : 'host=' . $db_server . ' ') . 'dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
80
+	}
77 81
 
78 82
 	// Something's wrong, show an error if its fatal (which we assume it is)
79 83
 	if (!$connection)
@@ -81,15 +85,15 @@  discard block
 block discarded – undo
81 85
 		if (!empty($db_options['non_fatal']))
82 86
 		{
83 87
 			return null;
84
-		}
85
-		else
88
+		} else
86 89
 		{
87 90
 			display_db_error();
88 91
 		}
89 92
 	}
90 93
 
91
-	if (!empty($db_options['db_mb4']))
92
-		$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
94
+	if (!empty($db_options['db_mb4'])) {
95
+			$smcFunc['db_mb4'] = (bool) $db_options['db_mb4'];
96
+	}
93 97
 
94 98
 	return $connection;
95 99
 }
@@ -136,31 +140,38 @@  discard block
 block discarded – undo
136 140
 
137 141
 	list ($values, $connection) = $db_callback;
138 142
 
139
-	if ($matches[1] === 'db_prefix')
140
-		return $db_prefix;
143
+	if ($matches[1] === 'db_prefix') {
144
+			return $db_prefix;
145
+	}
141 146
 
142
-	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false)
143
-		return $user_info[$matches[1]];
147
+	if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) {
148
+			return $user_info[$matches[1]];
149
+	}
144 150
 
145
-	if ($matches[1] === 'empty')
146
-		return '\'\'';
151
+	if ($matches[1] === 'empty') {
152
+			return '\'\'';
153
+	}
147 154
 
148
-	if (!isset($matches[2]))
149
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
155
+	if (!isset($matches[2])) {
156
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
157
+	}
150 158
 
151
-	if ($matches[1] === 'literal')
152
-		return '\'' . pg_escape_string($matches[2]) . '\'';
159
+	if ($matches[1] === 'literal') {
160
+			return '\'' . pg_escape_string($matches[2]) . '\'';
161
+	}
153 162
 
154
-	if (!isset($values[$matches[2]]))
155
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
163
+	if (!isset($values[$matches[2]])) {
164
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
165
+	}
156 166
 
157 167
 	$replacement = $values[$matches[2]];
158 168
 
159 169
 	switch ($matches[1])
160 170
 	{
161 171
 		case 'int':
162
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
163
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
172
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
173
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
174
+			}
164 175
 			return (string) (int) $replacement;
165 176
 		break;
166 177
 
@@ -172,65 +183,73 @@  discard block
 block discarded – undo
172 183
 		case 'array_int':
173 184
 			if (is_array($replacement))
174 185
 			{
175
-				if (empty($replacement))
176
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
186
+				if (empty($replacement)) {
187
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
188
+				}
177 189
 
178 190
 				foreach ($replacement as $key => $value)
179 191
 				{
180
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
181
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
192
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
193
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
194
+					}
182 195
 
183 196
 					$replacement[$key] = (string) (int) $value;
184 197
 				}
185 198
 
186 199
 				return implode(', ', $replacement);
200
+			} else {
201
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
187 202
 			}
188
-			else
189
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
190 203
 
191 204
 		break;
192 205
 
193 206
 		case 'array_string':
194 207
 			if (is_array($replacement))
195 208
 			{
196
-				if (empty($replacement))
197
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
209
+				if (empty($replacement)) {
210
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
211
+				}
198 212
 
199
-				foreach ($replacement as $key => $value)
200
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
213
+				foreach ($replacement as $key => $value) {
214
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
215
+				}
201 216
 
202 217
 				return implode(', ', $replacement);
218
+			} else {
219
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
203 220
 			}
204
-			else
205
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
206 221
 		break;
207 222
 
208 223
 		case 'date':
209
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
210
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
211
-			else
212
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
225
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date';
226
+			} else {
227
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
228
+			}
213 229
 		break;
214 230
 
215 231
 		case 'time':
216
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
217
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
218
-			else
219
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
232
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
233
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time';
234
+			} else {
235
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236
+			}
220 237
 		break;
221 238
 
222 239
 		case 'datetime':
223
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
224
-				return 'to_timestamp('.
240
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
241
+							return 'to_timestamp('.
225 242
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
226 243
 					',\'YYYY-MM-DD HH24:MI:SS\')';
227
-			else
228
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
244
+			} else {
245
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
246
+			}
229 247
 		break;
230 248
 
231 249
 		case 'float':
232
-			if (!is_numeric($replacement))
233
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
250
+			if (!is_numeric($replacement)) {
251
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
252
+			}
234 253
 			return (string) (float) $replacement;
235 254
 		break;
236 255
 
@@ -243,31 +262,36 @@  discard block
 block discarded – undo
243 262
 		break;
244 263
 
245 264
 		case 'inet':
246
-			if ($replacement == 'null' || $replacement == '')
247
-				return 'null';
248
-			if (inet_pton($replacement) === false)
249
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
265
+			if ($replacement == 'null' || $replacement == '') {
266
+							return 'null';
267
+			}
268
+			if (inet_pton($replacement) === false) {
269
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			}
250 271
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
251 272
 
252 273
 		case 'array_inet':
253 274
 			if (is_array($replacement))
254 275
 			{
255
-				if (empty($replacement))
256
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
276
+				if (empty($replacement)) {
277
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
278
+				}
257 279
 
258 280
 				foreach ($replacement as $key => $value)
259 281
 				{
260
-					if ($replacement == 'null' || $replacement == '')
261
-						$replacement[$key] = 'null';
262
-					if (!isValidIP($value))
263
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
282
+					if ($replacement == 'null' || $replacement == '') {
283
+											$replacement[$key] = 'null';
284
+					}
285
+					if (!isValidIP($value)) {
286
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
287
+					}
264 288
 					$replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value));
265 289
 				}
266 290
 
267 291
 				return implode(', ', $replacement);
292
+			} else {
293
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
268 294
 			}
269
-			else
270
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
271 295
 		break;
272 296
 
273 297
 		default:
@@ -355,14 +379,16 @@  discard block
 block discarded – undo
355 379
 		),
356 380
 	);
357 381
 
358
-	if (isset($replacements[$identifier]))
359
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
382
+	if (isset($replacements[$identifier])) {
383
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
384
+	}
360 385
 
361 386
 	// Limits need to be a little different.
362 387
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
363 388
 
364
-	if (trim($db_string) == '')
365
-		return false;
389
+	if (trim($db_string) == '') {
390
+			return false;
391
+	}
366 392
 
367 393
 	// Comments that are allowed in a query are preg_removed.
368 394
 	static $allowed_comments_from = array(
@@ -382,8 +408,9 @@  discard block
 block discarded – undo
382 408
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
383 409
 	$db_replace_result = 0;
384 410
 
385
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
386
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
411
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
412
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
413
+	}
387 414
 
388 415
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
389 416
 	{
@@ -408,17 +435,18 @@  discard block
 block discarded – undo
408 435
 		while (true)
409 436
 		{
410 437
 			$pos = strpos($db_string_1, '\'', $pos + 1);
411
-			if ($pos === false)
412
-				break;
438
+			if ($pos === false) {
439
+							break;
440
+			}
413 441
 			$clean .= substr($db_string_1, $old_pos, $pos - $old_pos);
414 442
 
415 443
 			while (true)
416 444
 			{
417 445
 				$pos1 = strpos($db_string_1, '\'', $pos + 1);
418 446
 				$pos2 = strpos($db_string_1, '\\', $pos + 1);
419
-				if ($pos1 === false)
420
-					break;
421
-				elseif ($pos2 === false || $pos2 > $pos1)
447
+				if ($pos1 === false) {
448
+									break;
449
+				} elseif ($pos2 === false || $pos2 > $pos1)
422 450
 				{
423 451
 					$pos = $pos1;
424 452
 					break;
@@ -434,16 +462,19 @@  discard block
 block discarded – undo
434 462
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
435 463
 
436 464
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
437
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
438
-			$fail = true;
465
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
466
+					$fail = true;
467
+		}
439 468
 		// Trying to change passwords, slow us down, or something?
440
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
441
-			$fail = true;
442
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
443
-			$fail = true;
469
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
470
+					$fail = true;
471
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
472
+					$fail = true;
473
+		}
444 474
 
445
-		if (!empty($fail) && function_exists('log_error'))
446
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
475
+		if (!empty($fail) && function_exists('log_error')) {
476
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
477
+		}
447 478
 	}
448 479
 
449 480
 	// Set optimize stuff
@@ -470,8 +501,9 @@  discard block
 block discarded – undo
470 501
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
471 502
 
472 503
 		// Initialize $db_cache if not already initialized.
473
-		if (!isset($db_cache))
474
-			$db_cache = array();
504
+		if (!isset($db_cache)) {
505
+					$db_cache = array();
506
+		}
475 507
 
476 508
 		if (!empty($_SESSION['debug_redirect']))
477 509
 		{
@@ -489,12 +521,14 @@  discard block
 block discarded – undo
489 521
 
490 522
 	$db_last_result = @pg_query($connection, $db_string);
491 523
 
492
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
493
-		$db_last_result = smf_db_error($db_string, $connection);
524
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
525
+			$db_last_result = smf_db_error($db_string, $connection);
526
+	}
494 527
 
495 528
 	// Debugging.
496
-	if (isset($db_show_debug) && $db_show_debug === true)
497
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
529
+	if (isset($db_show_debug) && $db_show_debug === true) {
530
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
531
+	}
498 532
 
499 533
 	return $db_last_result;
500 534
 }
@@ -511,10 +545,11 @@  discard block
 block discarded – undo
511 545
 {
512 546
 	global $db_last_result, $db_replace_result;
513 547
 
514
-	if ($db_replace_result)
515
-		return $db_replace_result;
516
-	elseif ($result === null && !$db_last_result)
517
-		return 0;
548
+	if ($db_replace_result) {
549
+			return $db_replace_result;
550
+	} elseif ($result === null && !$db_last_result) {
551
+			return 0;
552
+	}
518 553
 
519 554
 	return pg_affected_rows($result === null ? $db_last_result : $result);
520 555
 }
@@ -538,8 +573,9 @@  discard block
 block discarded – undo
538 573
 		array(
539 574
 		)
540 575
 	);
541
-	if (!$request)
542
-		return false;
576
+	if (!$request) {
577
+			return false;
578
+	}
543 579
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
544 580
 	$smcFunc['db_free_result']($request);
545 581
 
@@ -560,12 +596,13 @@  discard block
 block discarded – undo
560 596
 	// Decide which connection to use
561 597
 	$connection = $connection === null ? $db_connection : $connection;
562 598
 
563
-	if ($type == 'begin')
564
-		return @pg_query($connection, 'BEGIN');
565
-	elseif ($type == 'rollback')
566
-		return @pg_query($connection, 'ROLLBACK');
567
-	elseif ($type == 'commit')
568
-		return @pg_query($connection, 'COMMIT');
599
+	if ($type == 'begin') {
600
+			return @pg_query($connection, 'BEGIN');
601
+	} elseif ($type == 'rollback') {
602
+			return @pg_query($connection, 'ROLLBACK');
603
+	} elseif ($type == 'commit') {
604
+			return @pg_query($connection, 'COMMIT');
605
+	}
569 606
 
570 607
 	return false;
571 608
 }
@@ -593,19 +630,22 @@  discard block
 block discarded – undo
593 630
 	$query_error = @pg_last_error($connection);
594 631
 
595 632
 	// Log the error.
596
-	if (function_exists('log_error'))
597
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
633
+	if (function_exists('log_error')) {
634
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line);
635
+	}
598 636
 
599 637
 	// Nothing's defined yet... just die with it.
600
-	if (empty($context) || empty($txt))
601
-		die($query_error);
638
+	if (empty($context) || empty($txt)) {
639
+			die($query_error);
640
+	}
602 641
 
603 642
 	// Show an error message, if possible.
604 643
 	$context['error_title'] = $txt['database_error'];
605
-	if (allowedTo('admin_forum'))
606
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
607
-	else
608
-		$context['error_message'] = $txt['try_again'];
644
+	if (allowedTo('admin_forum')) {
645
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
646
+	} else {
647
+			$context['error_message'] = $txt['try_again'];
648
+	}
609 649
 
610 650
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
611 651
 	{
@@ -627,12 +667,14 @@  discard block
 block discarded – undo
627 667
 {
628 668
 	global $db_row_count;
629 669
 
630
-	if ($counter !== false)
631
-		return pg_fetch_row($request, $counter);
670
+	if ($counter !== false) {
671
+			return pg_fetch_row($request, $counter);
672
+	}
632 673
 
633 674
 	// Reset the row counter...
634
-	if (!isset($db_row_count[(int) $request]))
635
-		$db_row_count[(int) $request] = 0;
675
+	if (!isset($db_row_count[(int) $request])) {
676
+			$db_row_count[(int) $request] = 0;
677
+	}
636 678
 
637 679
 	// Return the right row.
638 680
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -649,12 +691,14 @@  discard block
 block discarded – undo
649 691
 {
650 692
 	global $db_row_count;
651 693
 
652
-	if ($counter !== false)
653
-		return pg_fetch_assoc($request, $counter);
694
+	if ($counter !== false) {
695
+			return pg_fetch_assoc($request, $counter);
696
+	}
654 697
 
655 698
 	// Reset the row counter...
656
-	if (!isset($db_row_count[(int) $request]))
657
-		$db_row_count[(int) $request] = 0;
699
+	if (!isset($db_row_count[(int) $request])) {
700
+			$db_row_count[(int) $request] = 0;
701
+	}
658 702
 
659 703
 	// Return the right row.
660 704
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -707,11 +751,13 @@  discard block
 block discarded – undo
707 751
 
708 752
 	$replace = '';
709 753
 
710
-	if (empty($data))
711
-		return;
754
+	if (empty($data)) {
755
+			return;
756
+	}
712 757
 
713
-	if (!is_array($data[array_rand($data)]))
714
-		$data = array($data);
758
+	if (!is_array($data[array_rand($data)])) {
759
+			$data = array($data);
760
+	}
715 761
 
716 762
 	// Replace the prefix holder with the actual prefix.
717 763
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -737,32 +783,35 @@  discard block
 block discarded – undo
737 783
 					$key_str .= ($count_pk > 0 ? ',' : '');
738 784
 					$key_str .= $columnName;
739 785
 					$count_pk++;
740
-				}
741
-				else if ($method == 'replace') //normal field
786
+				} else if ($method == 'replace') {
787
+					//normal field
742 788
 				{
743 789
 					$col_str .= ($count > 0 ? ',' : '');
790
+				}
744 791
 					$col_str .= $columnName . ' = EXCLUDED.' . $columnName;
745 792
 					$count++;
746 793
 				}
747 794
 			}
748
-			if ($method == 'replace')
749
-				$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
750
-			else
751
-				$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
752
-		}
753
-		else if ($method == 'replace')
795
+			if ($method == 'replace') {
796
+							$replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str;
797
+			} else {
798
+							$replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING';
799
+			}
800
+		} else if ($method == 'replace')
754 801
 		{
755 802
 			foreach ($columns as $columnName => $type)
756 803
 			{
757 804
 				// Are we restricting the length?
758
-				if (strpos($type, 'string-') !== false)
759
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
760
-				else
761
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
805
+				if (strpos($type, 'string-') !== false) {
806
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
807
+				} else {
808
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
809
+				}
762 810
 
763 811
 				// A key? That's what we were looking for.
764
-				if (in_array($columnName, $keys))
765
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
812
+				if (in_array($columnName, $keys)) {
813
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
814
+				}
766 815
 				$count++;
767 816
 			}
768 817
 
@@ -798,10 +847,11 @@  discard block
 block discarded – undo
798 847
 		foreach ($columns as $columnName => $type)
799 848
 		{
800 849
 			// Are we restricting the length?
801
-			if (strpos($type, 'string-') !== false)
802
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
803
-			else
804
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
850
+			if (strpos($type, 'string-') !== false) {
851
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
852
+			} else {
853
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
854
+			}
805 855
 		}
806 856
 		$insertData = substr($insertData, 0, -2) . ')';
807 857
 
@@ -810,8 +860,9 @@  discard block
 block discarded – undo
810 860
 
811 861
 		// Here's where the variables are injected to the query.
812 862
 		$insertRows = array();
813
-		foreach ($data as $dataRow)
814
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
863
+		foreach ($data as $dataRow) {
864
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
865
+		}
815 866
 
816 867
 		// Do the insert.
817 868
 		$request = $smcFunc['db_query']('', '
@@ -828,19 +879,21 @@  discard block
 block discarded – undo
828 879
 
829 880
 		if ($with_returning && $request !== false)
830 881
 		{
831
-			if ($returnmode === 2)
832
-				$return_var = array();
882
+			if ($returnmode === 2) {
883
+							$return_var = array();
884
+			}
833 885
 
834 886
 			while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning)
835 887
 			{
836
-				if (is_numeric($row[0])) // try to emulate mysql limitation
888
+				if (is_numeric($row[0])) {
889
+					// try to emulate mysql limitation
837 890
 				{
838 891
 					if ($returnmode === 1)
839 892
 						$return_var = $row[0];
840
-					elseif ($returnmode === 2)
841
-						$return_var[] = $row[0];
842
-				}
843
-				else
893
+				} elseif ($returnmode === 2) {
894
+											$return_var[] = $row[0];
895
+					}
896
+				} else
844 897
 				{
845 898
 					$with_returning = false;
846 899
 					trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR);
@@ -849,9 +902,10 @@  discard block
 block discarded – undo
849 902
 		}
850 903
 	}
851 904
 
852
-	if ($with_returning && !empty($return_var))
853
-		return $return_var;
854
-}
905
+	if ($with_returning && !empty($return_var)) {
906
+			return $return_var;
907
+	}
908
+	}
855 909
 
856 910
 /**
857 911
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -888,8 +942,9 @@  discard block
 block discarded – undo
888 942
  */
889 943
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
890 944
 {
891
-	if (empty($log_message))
892
-		$log_message = $error_message;
945
+	if (empty($log_message)) {
946
+			$log_message = $error_message;
947
+	}
893 948
 
894 949
 	foreach (debug_backtrace() as $step)
895 950
 	{
@@ -908,12 +963,14 @@  discard block
 block discarded – undo
908 963
 	}
909 964
 
910 965
 	// A special case - we want the file and line numbers for debugging.
911
-	if ($error_type == 'return')
912
-		return array($file, $line);
966
+	if ($error_type == 'return') {
967
+			return array($file, $line);
968
+	}
913 969
 
914 970
 	// Is always a critical error.
915
-	if (function_exists('log_error'))
916
-		log_error($log_message, 'critical', $file, $line);
971
+	if (function_exists('log_error')) {
972
+			log_error($log_message, 'critical', $file, $line);
973
+	}
917 974
 
918 975
 	if (function_exists('fatal_error'))
919 976
 	{
@@ -921,12 +978,12 @@  discard block
 block discarded – undo
921 978
 
922 979
 		// Cannot continue...
923 980
 		exit;
981
+	} elseif ($error_type) {
982
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
983
+	} else {
984
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
985
+	}
924 986
 	}
925
-	elseif ($error_type)
926
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
927
-	else
928
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
929
-}
930 987
 
931 988
 /**
932 989
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -943,10 +1000,11 @@  discard block
 block discarded – undo
943 1000
 		'\\' => '\\\\',
944 1001
 	);
945 1002
 
946
-	if ($translate_human_wildcards)
947
-		$replacements += array(
1003
+	if ($translate_human_wildcards) {
1004
+			$replacements += array(
948 1005
 			'*' => '%',
949 1006
 		);
1007
+	}
950 1008
 
951 1009
 	return strtr($string, $replacements);
952 1010
 }
@@ -975,14 +1033,16 @@  discard block
 block discarded – undo
975 1033
 	static $pg_error_data_prep;
976 1034
 
977 1035
 	// without database we can't do anything
978
-	if (empty($db_connection))
979
-		return;
1036
+	if (empty($db_connection)) {
1037
+			return;
1038
+	}
980 1039
 
981
-	if (empty($pg_error_data_prep))
982
-			$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
1040
+	if (empty($pg_error_data_prep)) {
1041
+				$pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors',
983 1042
 				'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line, backtrace)
984 1043
 													VALUES(		$1,		$2,		$3, $4, 	$5,		$6,			$7,		$8,	$9, $10)'
985 1044
 			);
1045
+	}
986 1046
 
987 1047
 	pg_execute($db_connection, 'smf_log_errors', $error_array);
988 1048
 }
@@ -1002,8 +1062,9 @@  discard block
 block discarded – undo
1002 1062
 	$count = count($array_values);
1003 1063
 	$then = ($desc ? ' THEN -' : ' THEN ');
1004 1064
 
1005
-	for ($i = 0; $i < $count; $i++)
1006
-		$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1065
+	for ($i = 0; $i < $count; $i++) {
1066
+			$return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' ';
1067
+	}
1007 1068
 
1008 1069
 	$return .= 'END';
1009 1070
 	return $return;
@@ -1026,11 +1087,13 @@  discard block
 block discarded – undo
1026 1087
 		//pg 9.5 got replace support
1027 1088
 		$pg_version = $smcFunc['db_get_version']();
1028 1089
 		// if we got a Beta Version
1029
-		if (stripos($pg_version, 'beta') !== false)
1030
-			$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
1090
+		if (stripos($pg_version, 'beta') !== false) {
1091
+					$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0';
1092
+		}
1031 1093
 		// or RC
1032
-		if (stripos($pg_version, 'rc') !== false)
1033
-			$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
1094
+		if (stripos($pg_version, 'rc') !== false) {
1095
+					$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0';
1096
+		}
1034 1097
 
1035 1098
 		$replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false);
1036 1099
 	}
Please login to merge, or discard this patch.