Completed
Push — release-2.1 ( 35b3d8...b2efc6 )
by Mathias
09:11
created
SSI.php 1 patch
Braces   +426 added lines, -304 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Don't do anything if SMF is already loaded.
15
-if (defined('SMF'))
15
+if (defined('SMF')) {
16 16
 	return true;
17
+}
17 18
 
18 19
 define('SMF', 'SSI');
19 20
 
@@ -28,16 +29,18 @@  discard block
 block discarded – undo
28 29
 $time_start = microtime(true);
29 30
 
30 31
 // Just being safe...
31
-foreach (array('db_character_set', 'cachedir') as $variable)
32
+foreach (array('db_character_set', 'cachedir') as $variable) {
32 33
 	if (isset($GLOBALS[$variable]))
33 34
 		unset($GLOBALS[$variable]);
35
+}
34 36
 
35 37
 // Get the forum's settings for database and file paths.
36 38
 require_once(dirname(__FILE__) . '/Settings.php');
37 39
 
38 40
 // Make absolutely sure the cache directory is defined.
39
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
41
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
40 42
 	$cachedir = $boarddir . '/cache';
43
+}
41 44
 
42 45
 $ssi_error_reporting = error_reporting(E_ALL);
43 46
 /* Set this to one of three values depending on what you want to happen in the case of a fatal error.
@@ -48,12 +51,14 @@  discard block
 block discarded – undo
48 51
 $ssi_on_error_method = false;
49 52
 
50 53
 // Don't do john didley if the forum's been shut down completely.
51
-if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true))
54
+if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) {
52 55
 	die($mmessage);
56
+}
53 57
 
54 58
 // Fix for using the current directory as a path.
55
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
59
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
56 60
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
61
+}
57 62
 
58 63
 // Load the important includes.
59 64
 require_once($sourcedir . '/QueryString.php');
@@ -78,34 +83,38 @@  discard block
 block discarded – undo
78 83
 cleanRequest();
79 84
 
80 85
 // Seed the random generator?
81
-if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
86
+if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
82 87
 	smf_seed_generator();
88
+}
83 89
 
84 90
 // Check on any hacking attempts.
85
-if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
91
+if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
86 92
 	die('No direct access...');
87
-elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme)
93
+} elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) {
88 94
 	die('No direct access...');
89
-elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme)
95
+} elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) {
90 96
 	die('No direct access...');
91
-elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers)
97
+} elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) {
92 98
 	die('No direct access...');
93
-if (isset($_REQUEST['context']))
99
+}
100
+if (isset($_REQUEST['context'])) {
94 101
 	die('No direct access...');
102
+}
95 103
 
96 104
 // Gzip output? (because it must be boolean and true, this can't be hacked.)
97
-if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>='))
105
+if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) {
98 106
 	ob_start('ob_gzhandler');
99
-else
107
+} else {
100 108
 	$modSettings['enableCompressedOutput'] = '0';
109
+}
101 110
 
102 111
 // Primarily, this is to fix the URLs...
103 112
 ob_start('ob_sessrewrite');
104 113
 
105 114
 // Start the session... known to scramble SSI includes in cases...
106
-if (!headers_sent())
115
+if (!headers_sent()) {
107 116
 	loadSession();
108
-else
117
+} else
109 118
 {
110 119
 	if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()]))
111 120
 	{
@@ -139,12 +148,14 @@  discard block
 block discarded – undo
139 148
 loadTheme(isset($ssi_theme) ? (int) $ssi_theme : 0);
140 149
 
141 150
 // @todo: probably not the best place, but somewhere it should be set...
142
-if (!headers_sent())
151
+if (!headers_sent()) {
143 152
 	header('Content-Type: text/html; charset=' . (empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set']));
153
+}
144 154
 
145 155
 // Take care of any banning that needs to be done.
146
-if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true))
156
+if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) {
147 157
 	is_not_banned();
158
+}
148 159
 
149 160
 // Do we allow guests in here?
150 161
 if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php')
@@ -159,17 +170,19 @@  discard block
 block discarded – undo
159 170
 {
160 171
 	$context['template_layers'] = $ssi_layers;
161 172
 	template_header();
162
-}
163
-else
173
+} else {
164 174
 	setupThemeContext();
175
+}
165 176
 
166 177
 // Make sure they didn't muss around with the settings... but only if it's not cli.
167
-if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '')
178
+if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') {
168 179
 	trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);
180
+}
169 181
 
170 182
 // Without visiting the forum this session variable might not be set on submit.
171
-if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote'))
183
+if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) {
172 184
 	$_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
185
+}
173 186
 
174 187
 // Have the ability to easily add functions to SSI.
175 188
 call_integration_hook('integrate_SSI');
@@ -178,11 +191,13 @@  discard block
 block discarded – undo
178 191
 if (basename($_SERVER['PHP_SELF']) == 'SSI.php')
179 192
 {
180 193
 	// You shouldn't just access SSI.php directly by URL!!
181
-	if (!isset($_GET['ssi_function']))
182
-		die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
194
+	if (!isset($_GET['ssi_function'])) {
195
+			die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
196
+	}
183 197
 	// Call a function passed by GET.
184
-	if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest']))
185
-		call_user_func('ssi_' . $_GET['ssi_function']);
198
+	if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) {
199
+			call_user_func('ssi_' . $_GET['ssi_function']);
200
+	}
186 201
 	exit;
187 202
 }
188 203
 
@@ -199,9 +214,10 @@  discard block
 block discarded – undo
199 214
  */
200 215
 function ssi_shutdown()
201 216
 {
202
-	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown')
203
-		template_footer();
204
-}
217
+	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') {
218
+			template_footer();
219
+	}
220
+	}
205 221
 
206 222
 /**
207 223
  * Display a welcome message, like: Hey, User, you have 0 messages, 0 are new.
@@ -214,15 +230,17 @@  discard block
 block discarded – undo
214 230
 
215 231
 	if ($output_method == 'echo')
216 232
 	{
217
-		if ($context['user']['is_guest'])
218
-			echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
219
-		else
220
-			echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
233
+		if ($context['user']['is_guest']) {
234
+					echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
235
+		} else {
236
+					echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
237
+		}
221 238
 	}
222 239
 	// Don't echo... then do what?!
223
-	else
224
-		return $context['user'];
225
-}
240
+	else {
241
+			return $context['user'];
242
+	}
243
+	}
226 244
 
227 245
 /**
228 246
  * Display a menu bar, like is displayed at the top of the forum.
@@ -233,12 +251,14 @@  discard block
 block discarded – undo
233 251
 {
234 252
 	global $context;
235 253
 
236
-	if ($output_method == 'echo')
237
-		template_menu();
254
+	if ($output_method == 'echo') {
255
+			template_menu();
256
+	}
238 257
 	// What else could this do?
239
-	else
240
-		return $context['menu_buttons'];
241
-}
258
+	else {
259
+			return $context['menu_buttons'];
260
+	}
261
+	}
242 262
 
243 263
 /**
244 264
  * Show a logout link.
@@ -250,20 +270,23 @@  discard block
 block discarded – undo
250 270
 {
251 271
 	global $context, $txt, $scripturl;
252 272
 
253
-	if ($redirect_to != '')
254
-		$_SESSION['logout_url'] = $redirect_to;
273
+	if ($redirect_to != '') {
274
+			$_SESSION['logout_url'] = $redirect_to;
275
+	}
255 276
 
256 277
 	// Guests can't log out.
257
-	if ($context['user']['is_guest'])
258
-		return false;
278
+	if ($context['user']['is_guest']) {
279
+			return false;
280
+	}
259 281
 
260 282
 	$link = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>';
261 283
 
262
-	if ($output_method == 'echo')
263
-		echo $link;
264
-	else
265
-		return $link;
266
-}
284
+	if ($output_method == 'echo') {
285
+			echo $link;
286
+	} else {
287
+			return $link;
288
+	}
289
+	}
267 290
 
268 291
 /**
269 292
  * Recent post list:   [board] Subject by Poster    Date
@@ -279,17 +302,17 @@  discard block
 block discarded – undo
279 302
 	global $modSettings, $context;
280 303
 
281 304
 	// Excluding certain boards...
282
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
283
-		$exclude_boards = array($modSettings['recycle_board']);
284
-	else
285
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
305
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
306
+			$exclude_boards = array($modSettings['recycle_board']);
307
+	} else {
308
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
309
+	}
286 310
 
287 311
 	// What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter.
288 312
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
289 313
 	{
290 314
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
291
-	}
292
-	elseif ($include_boards != null)
315
+	} elseif ($include_boards != null)
293 316
 	{
294 317
 		$include_boards = array();
295 318
 	}
@@ -326,8 +349,9 @@  discard block
 block discarded – undo
326 349
 {
327 350
 	global $modSettings;
328 351
 
329
-	if (empty($post_ids))
330
-		return;
352
+	if (empty($post_ids)) {
353
+			return;
354
+	}
331 355
 
332 356
 	// Allow the user to request more than one - why not?
333 357
 	$post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
@@ -362,8 +386,9 @@  discard block
 block discarded – undo
362 386
 	global $scripturl, $txt, $user_info;
363 387
 	global $modSettings, $smcFunc, $context;
364 388
 
365
-	if (!empty($modSettings['enable_likes']))
366
-		$context['can_like'] = allowedTo('likes_like');
389
+	if (!empty($modSettings['enable_likes'])) {
390
+			$context['can_like'] = allowedTo('likes_like');
391
+	}
367 392
 
368 393
 	// Find all the posts. Newer ones will have higher IDs.
369 394
 	$request = $smcFunc['db_query']('substring', '
@@ -429,12 +454,13 @@  discard block
 block discarded – undo
429 454
 		);
430 455
 
431 456
 		// Get the likes for each message.
432
-		if (!empty($modSettings['enable_likes']))
433
-			$posts[$row['id_msg']]['likes'] = array(
457
+		if (!empty($modSettings['enable_likes'])) {
458
+					$posts[$row['id_msg']]['likes'] = array(
434 459
 				'count' => $row['likes'],
435 460
 				'you' => in_array($row['id_msg'], prepareLikesContext($row['id_topic'])),
436 461
 				'can_like' => !$context['user']['is_guest'] && $row['id_member'] != $context['user']['id'] && !empty($context['can_like']),
437 462
 			);
463
+		}
438 464
 	}
439 465
 	$smcFunc['db_free_result']($request);
440 466
 
@@ -442,13 +468,14 @@  discard block
 block discarded – undo
442 468
 	call_integration_hook('integrate_ssi_queryPosts', array(&$posts));
443 469
 
444 470
 	// Just return it.
445
-	if ($output_method != 'echo' || empty($posts))
446
-		return $posts;
471
+	if ($output_method != 'echo' || empty($posts)) {
472
+			return $posts;
473
+	}
447 474
 
448 475
 	echo '
449 476
 		<table style="border: none" class="ssi_table">';
450
-	foreach ($posts as $post)
451
-		echo '
477
+	foreach ($posts as $post) {
478
+			echo '
452 479
 			<tr>
453 480
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
454 481
 					[', $post['board']['link'], ']
@@ -462,6 +489,7 @@  discard block
 block discarded – undo
462 489
 					', $post['time'], '
463 490
 				</td>
464 491
 			</tr>';
492
+	}
465 493
 	echo '
466 494
 		</table>';
467 495
 }
@@ -479,25 +507,26 @@  discard block
 block discarded – undo
479 507
 	global $settings, $scripturl, $txt, $user_info;
480 508
 	global $modSettings, $smcFunc, $context;
481 509
 
482
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
483
-		$exclude_boards = array($modSettings['recycle_board']);
484
-	else
485
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
510
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
511
+			$exclude_boards = array($modSettings['recycle_board']);
512
+	} else {
513
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
514
+	}
486 515
 
487 516
 	// Only some boards?.
488 517
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
489 518
 	{
490 519
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
491
-	}
492
-	elseif ($include_boards != null)
520
+	} elseif ($include_boards != null)
493 521
 	{
494 522
 		$output_method = $include_boards;
495 523
 		$include_boards = array();
496 524
 	}
497 525
 
498 526
 	$icon_sources = array();
499
-	foreach ($context['stable_icons'] as $icon)
500
-		$icon_sources[$icon] = 'images_url';
527
+	foreach ($context['stable_icons'] as $icon) {
528
+			$icon_sources[$icon] = 'images_url';
529
+	}
501 530
 
502 531
 	// Find all the posts in distinct topics.  Newer ones will have higher IDs.
503 532
 	$request = $smcFunc['db_query']('substring', '
@@ -522,13 +551,15 @@  discard block
 block discarded – undo
522 551
 		)
523 552
 	);
524 553
 	$topics = array();
525
-	while ($row = $smcFunc['db_fetch_assoc']($request))
526
-		$topics[$row['id_topic']] = $row;
554
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
555
+			$topics[$row['id_topic']] = $row;
556
+	}
527 557
 	$smcFunc['db_free_result']($request);
528 558
 
529 559
 	// Did we find anything? If not, bail.
530
-	if (empty($topics))
531
-		return array();
560
+	if (empty($topics)) {
561
+			return array();
562
+	}
532 563
 
533 564
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
534 565
 
@@ -556,19 +587,22 @@  discard block
 block discarded – undo
556 587
 	while ($row = $smcFunc['db_fetch_assoc']($request))
557 588
 	{
558 589
 		$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => '&#10;')));
559
-		if ($smcFunc['strlen']($row['body']) > 128)
560
-			$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
590
+		if ($smcFunc['strlen']($row['body']) > 128) {
591
+					$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
592
+		}
561 593
 
562 594
 		// Censor the subject.
563 595
 		censorText($row['subject']);
564 596
 		censorText($row['body']);
565 597
 
566 598
 		// Recycled icon
567
-		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board'])
568
-			$row['icon'] = 'recycled';
599
+		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) {
600
+					$row['icon'] = 'recycled';
601
+		}
569 602
 
570
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
571
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
603
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
604
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
605
+		}
572 606
 
573 607
 		// Build the array.
574 608
 		$posts[] = array(
@@ -607,13 +641,14 @@  discard block
 block discarded – undo
607 641
 	call_integration_hook('integrate_ssi_recentTopics', array(&$posts));
608 642
 
609 643
 	// Just return it.
610
-	if ($output_method != 'echo' || empty($posts))
611
-		return $posts;
644
+	if ($output_method != 'echo' || empty($posts)) {
645
+			return $posts;
646
+	}
612 647
 
613 648
 	echo '
614 649
 		<table style="border: none" class="ssi_table">';
615
-	foreach ($posts as $post)
616
-		echo '
650
+	foreach ($posts as $post) {
651
+			echo '
617 652
 			<tr>
618 653
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
619 654
 					[', $post['board']['link'], ']
@@ -627,6 +662,7 @@  discard block
 block discarded – undo
627 662
 					', $post['time'], '
628 663
 				</td>
629 664
 			</tr>';
665
+	}
630 666
 	echo '
631 667
 		</table>';
632 668
 }
@@ -651,27 +687,30 @@  discard block
 block discarded – undo
651 687
 		)
652 688
 	);
653 689
 	$return = array();
654
-	while ($row = $smcFunc['db_fetch_assoc']($request))
655
-		$return[] = array(
690
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
691
+			$return[] = array(
656 692
 			'id' => $row['id_member'],
657 693
 			'name' => $row['real_name'],
658 694
 			'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
659 695
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
660 696
 			'posts' => $row['posts']
661 697
 		);
698
+	}
662 699
 	$smcFunc['db_free_result']($request);
663 700
 
664 701
 	// If mods want to do somthing with this list of members, let them do that now.
665 702
 	call_integration_hook('integrate_ssi_topPoster', array(&$return));
666 703
 
667 704
 	// Just return all the top posters.
668
-	if ($output_method != 'echo')
669
-		return $return;
705
+	if ($output_method != 'echo') {
706
+			return $return;
707
+	}
670 708
 
671 709
 	// Make a quick array to list the links in.
672 710
 	$temp_array = array();
673
-	foreach ($return as $member)
674
-		$temp_array[] = $member['link'];
711
+	foreach ($return as $member) {
712
+			$temp_array[] = $member['link'];
713
+	}
675 714
 
676 715
 	echo implode(', ', $temp_array);
677 716
 }
@@ -703,8 +742,8 @@  discard block
 block discarded – undo
703 742
 		)
704 743
 	);
705 744
 	$boards = array();
706
-	while ($row = $smcFunc['db_fetch_assoc']($request))
707
-		$boards[] = array(
745
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
746
+			$boards[] = array(
708 747
 			'id' => $row['id_board'],
709 748
 			'num_posts' => $row['num_posts'],
710 749
 			'num_topics' => $row['num_topics'],
@@ -713,14 +752,16 @@  discard block
 block discarded – undo
713 752
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
714 753
 			'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'
715 754
 		);
755
+	}
716 756
 	$smcFunc['db_free_result']($request);
717 757
 
718 758
 	// If mods want to do somthing with this list of boards, let them do that now.
719 759
 	call_integration_hook('integrate_ssi_topBoards', array(&$boards));
720 760
 
721 761
 	// If we shouldn't output or have nothing to output, just jump out.
722
-	if ($output_method != 'echo' || empty($boards))
723
-		return $boards;
762
+	if ($output_method != 'echo' || empty($boards)) {
763
+			return $boards;
764
+	}
724 765
 
725 766
 	echo '
726 767
 		<table class="ssi_table">
@@ -729,13 +770,14 @@  discard block
 block discarded – undo
729 770
 				<th style="text-align: left">', $txt['board_topics'], '</th>
730 771
 				<th style="text-align: left">', $txt['posts'], '</th>
731 772
 			</tr>';
732
-	foreach ($boards as $sBoard)
733
-		echo '
773
+	foreach ($boards as $sBoard) {
774
+			echo '
734 775
 			<tr>
735 776
 				<td>', $sBoard['link'], $sBoard['new'] ? ' <a href="' . $sBoard['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>' : '', '</td>
736 777
 				<td style="text-align: right">', comma_format($sBoard['num_topics']), '</td>
737 778
 				<td style="text-align: right">', comma_format($sBoard['num_posts']), '</td>
738 779
 			</tr>';
780
+	}
739 781
 	echo '
740 782
 		</table>';
741 783
 }
@@ -768,12 +810,13 @@  discard block
 block discarded – undo
768 810
 			)
769 811
 		);
770 812
 		$topic_ids = array();
771
-		while ($row = $smcFunc['db_fetch_assoc']($request))
772
-			$topic_ids[] = $row['id_topic'];
813
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
814
+					$topic_ids[] = $row['id_topic'];
815
+		}
773 816
 		$smcFunc['db_free_result']($request);
817
+	} else {
818
+			$topic_ids = array();
774 819
 	}
775
-	else
776
-		$topic_ids = array();
777 820
 
778 821
 	$request = $smcFunc['db_query']('', '
779 822
 		SELECT m.subject, m.id_topic, t.num_views, t.num_replies
@@ -812,8 +855,9 @@  discard block
 block discarded – undo
812 855
 	// If mods want to do somthing with this list of topics, let them do that now.
813 856
 	call_integration_hook('integrate_ssi_topTopics', array(&$topics, $type));
814 857
 
815
-	if ($output_method != 'echo' || empty($topics))
816
-		return $topics;
858
+	if ($output_method != 'echo' || empty($topics)) {
859
+			return $topics;
860
+	}
817 861
 
818 862
 	echo '
819 863
 		<table class="ssi_table">
@@ -822,8 +866,8 @@  discard block
 block discarded – undo
822 866
 				<th style="text-align: left">', $txt['views'], '</th>
823 867
 				<th style="text-align: left">', $txt['replies'], '</th>
824 868
 			</tr>';
825
-	foreach ($topics as $sTopic)
826
-		echo '
869
+	foreach ($topics as $sTopic) {
870
+			echo '
827 871
 			<tr>
828 872
 				<td style="text-align: left">
829 873
 					', $sTopic['link'], '
@@ -831,6 +875,7 @@  discard block
 block discarded – undo
831 875
 				<td style="text-align: right">', comma_format($sTopic['num_views']), '</td>
832 876
 				<td style="text-align: right">', comma_format($sTopic['num_replies']), '</td>
833 877
 			</tr>';
878
+	}
834 879
 	echo '
835 880
 		</table>';
836 881
 }
@@ -866,12 +911,13 @@  discard block
 block discarded – undo
866 911
 {
867 912
 	global $txt, $context;
868 913
 
869
-	if ($output_method == 'echo')
870
-		echo '
914
+	if ($output_method == 'echo') {
915
+			echo '
871 916
 	', sprintf($txt['welcome_newest_member'], $context['common_stats']['latest_member']['link']), '<br>';
872
-	else
873
-		return $context['common_stats']['latest_member'];
874
-}
917
+	} else {
918
+			return $context['common_stats']['latest_member'];
919
+	}
920
+	}
875 921
 
876 922
 /**
877 923
  * Fetches a random member.
@@ -920,8 +966,9 @@  discard block
 block discarded – undo
920 966
 	}
921 967
 
922 968
 	// Just to be sure put the random generator back to something... random.
923
-	if ($random_type != '')
924
-		mt_srand(time());
969
+	if ($random_type != '') {
970
+			mt_srand(time());
971
+	}
925 972
 
926 973
 	return $result;
927 974
 }
@@ -934,8 +981,9 @@  discard block
 block discarded – undo
934 981
  */
935 982
 function ssi_fetchMember($member_ids = array(), $output_method = 'echo')
936 983
 {
937
-	if (empty($member_ids))
938
-		return;
984
+	if (empty($member_ids)) {
985
+			return;
986
+	}
939 987
 
940 988
 	// Can have more than one member if you really want...
941 989
 	$member_ids = is_array($member_ids) ? $member_ids : array($member_ids);
@@ -960,8 +1008,9 @@  discard block
 block discarded – undo
960 1008
  */
961 1009
 function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo')
962 1010
 {
963
-	if ($group_id === null)
964
-		return;
1011
+	if ($group_id === null) {
1012
+			return;
1013
+	}
965 1014
 
966 1015
 	$query_where = '
967 1016
 		id_group = {int:id_group}
@@ -988,8 +1037,9 @@  discard block
 block discarded – undo
988 1037
 {
989 1038
 	global $smcFunc, $memberContext;
990 1039
 
991
-	if ($query_where === null)
992
-		return;
1040
+	if ($query_where === null) {
1041
+			return;
1042
+	}
993 1043
 
994 1044
 	// Fetch the members in question.
995 1045
 	$request = $smcFunc['db_query']('', '
@@ -1002,12 +1052,14 @@  discard block
 block discarded – undo
1002 1052
 		))
1003 1053
 	);
1004 1054
 	$members = array();
1005
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1006
-		$members[] = $row['id_member'];
1055
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1056
+			$members[] = $row['id_member'];
1057
+	}
1007 1058
 	$smcFunc['db_free_result']($request);
1008 1059
 
1009
-	if (empty($members))
1010
-		return array();
1060
+	if (empty($members)) {
1061
+			return array();
1062
+	}
1011 1063
 
1012 1064
 	// If mods want to do somthing with this list of members, let them do that now.
1013 1065
 	call_integration_hook('integrate_ssi_queryMembers', array(&$members));
@@ -1016,23 +1068,25 @@  discard block
 block discarded – undo
1016 1068
 	loadMemberData($members);
1017 1069
 
1018 1070
 	// Draw the table!
1019
-	if ($output_method == 'echo')
1020
-		echo '
1071
+	if ($output_method == 'echo') {
1072
+			echo '
1021 1073
 		<table style="border: none" class="ssi_table">';
1074
+	}
1022 1075
 
1023 1076
 	$query_members = array();
1024 1077
 	foreach ($members as $member)
1025 1078
 	{
1026 1079
 		// Load their context data.
1027
-		if (!loadMemberContext($member))
1028
-			continue;
1080
+		if (!loadMemberContext($member)) {
1081
+					continue;
1082
+		}
1029 1083
 
1030 1084
 		// Store this member's information.
1031 1085
 		$query_members[$member] = $memberContext[$member];
1032 1086
 
1033 1087
 		// Only do something if we're echo'ing.
1034
-		if ($output_method == 'echo')
1035
-			echo '
1088
+		if ($output_method == 'echo') {
1089
+					echo '
1036 1090
 			<tr>
1037 1091
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
1038 1092
 					', $query_members[$member]['link'], '
@@ -1040,12 +1094,14 @@  discard block
 block discarded – undo
1040 1094
 					<br>', $query_members[$member]['avatar']['image'], '
1041 1095
 				</td>
1042 1096
 			</tr>';
1097
+		}
1043 1098
 	}
1044 1099
 
1045 1100
 	// End the table if appropriate.
1046
-	if ($output_method == 'echo')
1047
-		echo '
1101
+	if ($output_method == 'echo') {
1102
+			echo '
1048 1103
 		</table>';
1104
+	}
1049 1105
 
1050 1106
 	// Send back the data.
1051 1107
 	return $query_members;
@@ -1060,8 +1116,9 @@  discard block
 block discarded – undo
1060 1116
 {
1061 1117
 	global $txt, $scripturl, $modSettings, $smcFunc;
1062 1118
 
1063
-	if (!allowedTo('view_stats'))
1064
-		return;
1119
+	if (!allowedTo('view_stats')) {
1120
+			return;
1121
+	}
1065 1122
 
1066 1123
 	$totals = array(
1067 1124
 		'members' => $modSettings['totalMembers'],
@@ -1090,8 +1147,9 @@  discard block
 block discarded – undo
1090 1147
 	// If mods want to do somthing with the board stats, let them do that now.
1091 1148
 	call_integration_hook('integrate_ssi_boardStats', array(&$totals));
1092 1149
 
1093
-	if ($output_method != 'echo')
1094
-		return $totals;
1150
+	if ($output_method != 'echo') {
1151
+			return $totals;
1152
+	}
1095 1153
 
1096 1154
 	echo '
1097 1155
 		', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', comma_format($totals['members']), '</a><br>
@@ -1120,8 +1178,8 @@  discard block
 block discarded – undo
1120 1178
 	call_integration_hook('integrate_ssi_whosOnline', array(&$return));
1121 1179
 
1122 1180
 	// Add some redundancy for backwards compatibility reasons.
1123
-	if ($output_method != 'echo')
1124
-		return $return + array(
1181
+	if ($output_method != 'echo') {
1182
+			return $return + array(
1125 1183
 			'users' => $return['users_online'],
1126 1184
 			'guests' => $return['num_guests'],
1127 1185
 			'hidden' => $return['num_users_hidden'],
@@ -1129,29 +1187,35 @@  discard block
 block discarded – undo
1129 1187
 			'num_users' => $return['num_users_online'],
1130 1188
 			'total_users' => $return['num_users_online'] + $return['num_guests'],
1131 1189
 		);
1190
+	}
1132 1191
 
1133 1192
 	echo '
1134 1193
 		', comma_format($return['num_guests']), ' ', $return['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($return['num_users_online']), ' ', $return['num_users_online'] == 1 ? $txt['user'] : $txt['users'];
1135 1194
 
1136 1195
 	$bracketList = array();
1137
-	if (!empty($user_info['buddies']))
1138
-		$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1139
-	if (!empty($return['num_spiders']))
1140
-		$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1141
-	if (!empty($return['num_users_hidden']))
1142
-		$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1196
+	if (!empty($user_info['buddies'])) {
1197
+			$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1198
+	}
1199
+	if (!empty($return['num_spiders'])) {
1200
+			$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1201
+	}
1202
+	if (!empty($return['num_users_hidden'])) {
1203
+			$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1204
+	}
1143 1205
 
1144
-	if (!empty($bracketList))
1145
-		echo ' (' . implode(', ', $bracketList) . ')';
1206
+	if (!empty($bracketList)) {
1207
+			echo ' (' . implode(', ', $bracketList) . ')';
1208
+	}
1146 1209
 
1147 1210
 	echo '<br>
1148 1211
 			', implode(', ', $return['list_users_online']);
1149 1212
 
1150 1213
 	// Showing membergroups?
1151
-	if (!empty($settings['show_group_key']) && !empty($return['membergroups']))
1152
-		echo '<br>
1214
+	if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) {
1215
+			echo '<br>
1153 1216
 			[' . implode(']&nbsp;&nbsp;[', $return['membergroups']) . ']';
1154
-}
1217
+	}
1218
+	}
1155 1219
 
1156 1220
 /**
1157 1221
  * Just like whosOnline except it also logs the online presence.
@@ -1162,11 +1226,12 @@  discard block
 block discarded – undo
1162 1226
 {
1163 1227
 	writeLog();
1164 1228
 
1165
-	if ($output_method != 'echo')
1166
-		return ssi_whosOnline($output_method);
1167
-	else
1168
-		ssi_whosOnline($output_method);
1169
-}
1229
+	if ($output_method != 'echo') {
1230
+			return ssi_whosOnline($output_method);
1231
+	} else {
1232
+			ssi_whosOnline($output_method);
1233
+	}
1234
+	}
1170 1235
 
1171 1236
 // Shows a login box.
1172 1237
 /**
@@ -1179,11 +1244,13 @@  discard block
 block discarded – undo
1179 1244
 {
1180 1245
 	global $scripturl, $txt, $user_info, $context;
1181 1246
 
1182
-	if ($redirect_to != '')
1183
-		$_SESSION['login_url'] = $redirect_to;
1247
+	if ($redirect_to != '') {
1248
+			$_SESSION['login_url'] = $redirect_to;
1249
+	}
1184 1250
 
1185
-	if ($output_method != 'echo' || !$user_info['is_guest'])
1186
-		return $user_info['is_guest'];
1251
+	if ($output_method != 'echo' || !$user_info['is_guest']) {
1252
+			return $user_info['is_guest'];
1253
+	}
1187 1254
 
1188 1255
 	// Create a login token
1189 1256
 	createToken('login');
@@ -1235,8 +1302,9 @@  discard block
 block discarded – undo
1235 1302
 
1236 1303
 	$boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote'));
1237 1304
 
1238
-	if (empty($boardsAllowed))
1239
-		return array();
1305
+	if (empty($boardsAllowed)) {
1306
+			return array();
1307
+	}
1240 1308
 
1241 1309
 	$request = $smcFunc['db_query']('', '
1242 1310
 		SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time
@@ -1269,12 +1337,14 @@  discard block
 block discarded – undo
1269 1337
 	$smcFunc['db_free_result']($request);
1270 1338
 
1271 1339
 	// This user has voted on all the polls.
1272
-	if (empty($row) || !is_array($row))
1273
-		return array();
1340
+	if (empty($row) || !is_array($row)) {
1341
+			return array();
1342
+	}
1274 1343
 
1275 1344
 	// If this is a guest who's voted we'll through ourselves to show poll to show the results.
1276
-	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))))
1277
-		return ssi_showPoll($row['id_topic'], $output_method);
1345
+	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) {
1346
+			return ssi_showPoll($row['id_topic'], $output_method);
1347
+	}
1278 1348
 
1279 1349
 	$request = $smcFunc['db_query']('', '
1280 1350
 		SELECT COUNT(DISTINCT id_member)
@@ -1338,8 +1408,9 @@  discard block
 block discarded – undo
1338 1408
 	// If mods want to do somthing with this list of polls, let them do that now.
1339 1409
 	call_integration_hook('integrate_ssi_recentPoll', array(&$return, $topPollInstead));
1340 1410
 
1341
-	if ($output_method != 'echo')
1342
-		return $return;
1411
+	if ($output_method != 'echo') {
1412
+			return $return;
1413
+	}
1343 1414
 
1344 1415
 	if ($allow_view_results)
1345 1416
 	{
@@ -1348,19 +1419,20 @@  discard block
 block discarded – undo
1348 1419
 			<strong>', $return['question'], '</strong><br>
1349 1420
 			', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1350 1421
 
1351
-		foreach ($return['options'] as $option)
1352
-			echo '
1422
+		foreach ($return['options'] as $option) {
1423
+					echo '
1353 1424
 			<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1425
+		}
1354 1426
 
1355 1427
 		echo '
1356 1428
 			<input type="submit" value="', $txt['poll_vote'], '" class="button">
1357 1429
 			<input type="hidden" name="poll" value="', $return['id'], '">
1358 1430
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1359 1431
 		</form>';
1432
+	} else {
1433
+			echo $txt['poll_cannot_see'];
1434
+	}
1360 1435
 	}
1361
-	else
1362
-		echo $txt['poll_cannot_see'];
1363
-}
1364 1436
 
1365 1437
 /**
1366 1438
  * Shows the poll from the specified topic
@@ -1374,13 +1446,15 @@  discard block
 block discarded – undo
1374 1446
 
1375 1447
 	$boardsAllowed = boardsAllowedTo('poll_view');
1376 1448
 
1377
-	if (empty($boardsAllowed))
1378
-		return array();
1449
+	if (empty($boardsAllowed)) {
1450
+			return array();
1451
+	}
1379 1452
 
1380
-	if ($topic === null && isset($_REQUEST['ssi_topic']))
1381
-		$topic = (int) $_REQUEST['ssi_topic'];
1382
-	else
1383
-		$topic = (int) $topic;
1453
+	if ($topic === null && isset($_REQUEST['ssi_topic'])) {
1454
+			$topic = (int) $_REQUEST['ssi_topic'];
1455
+	} else {
1456
+			$topic = (int) $topic;
1457
+	}
1384 1458
 
1385 1459
 	$request = $smcFunc['db_query']('', '
1386 1460
 		SELECT
@@ -1401,17 +1475,18 @@  discard block
 block discarded – undo
1401 1475
 	);
1402 1476
 
1403 1477
 	// Either this topic has no poll, or the user cannot view it.
1404
-	if ($smcFunc['db_num_rows']($request) == 0)
1405
-		return array();
1478
+	if ($smcFunc['db_num_rows']($request) == 0) {
1479
+			return array();
1480
+	}
1406 1481
 
1407 1482
 	$row = $smcFunc['db_fetch_assoc']($request);
1408 1483
 	$smcFunc['db_free_result']($request);
1409 1484
 
1410 1485
 	// Check if they can vote.
1411 1486
 	$already_voted = false;
1412
-	if (!empty($row['expire_time']) && $row['expire_time'] < time())
1413
-		$allow_vote = false;
1414
-	elseif ($user_info['is_guest'])
1487
+	if (!empty($row['expire_time']) && $row['expire_time'] < time()) {
1488
+			$allow_vote = false;
1489
+	} elseif ($user_info['is_guest'])
1415 1490
 	{
1416 1491
 		// There's a difference between "allowed to vote" and "already voted"...
1417 1492
 		$allow_vote = $row['guest_vote'];
@@ -1421,10 +1496,9 @@  discard block
 block discarded – undo
1421 1496
 		{
1422 1497
 			$already_voted = true;
1423 1498
 		}
1424
-	}
1425
-	elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board']))
1426
-		$allow_vote = false;
1427
-	else
1499
+	} elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) {
1500
+			$allow_vote = false;
1501
+	} else
1428 1502
 	{
1429 1503
 		$request = $smcFunc['db_query']('', '
1430 1504
 			SELECT id_member
@@ -1506,8 +1580,9 @@  discard block
 block discarded – undo
1506 1580
 	// If mods want to do somthing with this poll, let them do that now.
1507 1581
 	call_integration_hook('integrate_ssi_showPoll', array(&$return));
1508 1582
 
1509
-	if ($output_method != 'echo')
1510
-		return $return;
1583
+	if ($output_method != 'echo') {
1584
+			return $return;
1585
+	}
1511 1586
 
1512 1587
 	if ($return['allow_vote'])
1513 1588
 	{
@@ -1516,17 +1591,17 @@  discard block
 block discarded – undo
1516 1591
 				<strong>', $return['question'], '</strong><br>
1517 1592
 				', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1518 1593
 
1519
-		foreach ($return['options'] as $option)
1520
-			echo '
1594
+		foreach ($return['options'] as $option) {
1595
+					echo '
1521 1596
 				<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1597
+		}
1522 1598
 
1523 1599
 		echo '
1524 1600
 				<input type="submit" value="', $txt['poll_vote'], '" class="button">
1525 1601
 				<input type="hidden" name="poll" value="', $return['id'], '">
1526 1602
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1527 1603
 			</form>';
1528
-	}
1529
-	else
1604
+	} else
1530 1605
 	{
1531 1606
 		echo '
1532 1607
 			<div class="ssi_poll">
@@ -1606,27 +1681,32 @@  discard block
 block discarded – undo
1606 1681
 			'is_approved' => 1,
1607 1682
 		)
1608 1683
 	);
1609
-	if ($smcFunc['db_num_rows']($request) == 0)
1610
-		die;
1684
+	if ($smcFunc['db_num_rows']($request) == 0) {
1685
+			die;
1686
+	}
1611 1687
 	$row = $smcFunc['db_fetch_assoc']($request);
1612 1688
 	$smcFunc['db_free_result']($request);
1613 1689
 
1614
-	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time']))
1615
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1690
+	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) {
1691
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1692
+	}
1616 1693
 
1617 1694
 	// Too many options checked?
1618
-	if (count($_REQUEST['options']) > $row['max_votes'])
1619
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1695
+	if (count($_REQUEST['options']) > $row['max_votes']) {
1696
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1697
+	}
1620 1698
 
1621 1699
 	// It's a guest who has already voted?
1622 1700
 	if ($user_info['is_guest'])
1623 1701
 	{
1624 1702
 		// Guest voting disabled?
1625
-		if (!$row['guest_vote'])
1626
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1703
+		if (!$row['guest_vote']) {
1704
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1705
+		}
1627 1706
 		// Already voted?
1628
-		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))
1629
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1707
+		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) {
1708
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1709
+		}
1630 1710
 	}
1631 1711
 
1632 1712
 	$sOptions = array();
@@ -1680,11 +1760,13 @@  discard block
 block discarded – undo
1680 1760
 {
1681 1761
 	global $scripturl, $txt, $context;
1682 1762
 
1683
-	if (!allowedTo('search_posts'))
1684
-		return;
1763
+	if (!allowedTo('search_posts')) {
1764
+			return;
1765
+	}
1685 1766
 
1686
-	if ($output_method != 'echo')
1687
-		return $scripturl . '?action=search';
1767
+	if ($output_method != 'echo') {
1768
+			return $scripturl . '?action=search';
1769
+	}
1688 1770
 
1689 1771
 	echo '
1690 1772
 		<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
@@ -1706,8 +1788,9 @@  discard block
 block discarded – undo
1706 1788
 	// If mods want to do somthing with the news, let them do that now. Don't need to pass the news line itself, since it is already in $context.
1707 1789
 	call_integration_hook('integrate_ssi_news');
1708 1790
 
1709
-	if ($output_method != 'echo')
1710
-		return $context['random_news_line'];
1791
+	if ($output_method != 'echo') {
1792
+			return $context['random_news_line'];
1793
+	}
1711 1794
 
1712 1795
 	echo $context['random_news_line'];
1713 1796
 }
@@ -1721,8 +1804,9 @@  discard block
 block discarded – undo
1721 1804
 {
1722 1805
 	global $scripturl, $modSettings, $user_info;
1723 1806
 
1724
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view'))
1725
-		return;
1807
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) {
1808
+			return;
1809
+	}
1726 1810
 
1727 1811
 	$eventOptions = array(
1728 1812
 		'include_birthdays' => true,
@@ -1733,13 +1817,15 @@  discard block
 block discarded – undo
1733 1817
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1734 1818
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1735 1819
 
1736
-	if ($output_method != 'echo')
1737
-		return $return['calendar_birthdays'];
1820
+	if ($output_method != 'echo') {
1821
+			return $return['calendar_birthdays'];
1822
+	}
1738 1823
 
1739
-	foreach ($return['calendar_birthdays'] as $member)
1740
-		echo '
1824
+	foreach ($return['calendar_birthdays'] as $member) {
1825
+			echo '
1741 1826
 			<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">' . $member['name'] . '</span>' . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>' . (!$member['is_last'] ? ', ' : '');
1742
-}
1827
+	}
1828
+	}
1743 1829
 
1744 1830
 /**
1745 1831
  * Shows today's holidays.
@@ -1750,8 +1836,9 @@  discard block
 block discarded – undo
1750 1836
 {
1751 1837
 	global $modSettings, $user_info;
1752 1838
 
1753
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1754
-		return;
1839
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1840
+			return;
1841
+	}
1755 1842
 
1756 1843
 	$eventOptions = array(
1757 1844
 		'include_holidays' => true,
@@ -1762,8 +1849,9 @@  discard block
 block discarded – undo
1762 1849
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1763 1850
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1764 1851
 
1765
-	if ($output_method != 'echo')
1766
-		return $return['calendar_holidays'];
1852
+	if ($output_method != 'echo') {
1853
+			return $return['calendar_holidays'];
1854
+	}
1767 1855
 
1768 1856
 	echo '
1769 1857
 		', implode(', ', $return['calendar_holidays']);
@@ -1777,8 +1865,9 @@  discard block
 block discarded – undo
1777 1865
 {
1778 1866
 	global $modSettings, $user_info;
1779 1867
 
1780
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1781
-		return;
1868
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1869
+			return;
1870
+	}
1782 1871
 
1783 1872
 	$eventOptions = array(
1784 1873
 		'include_events' => true,
@@ -1789,14 +1878,16 @@  discard block
 block discarded – undo
1789 1878
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1790 1879
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1791 1880
 
1792
-	if ($output_method != 'echo')
1793
-		return $return['calendar_events'];
1881
+	if ($output_method != 'echo') {
1882
+			return $return['calendar_events'];
1883
+	}
1794 1884
 
1795 1885
 	foreach ($return['calendar_events'] as $event)
1796 1886
 	{
1797
-		if ($event['can_edit'])
1798
-			echo '
1887
+		if ($event['can_edit']) {
1888
+					echo '
1799 1889
 	<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1890
+		}
1800 1891
 		echo '
1801 1892
 	' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1802 1893
 	}
@@ -1811,8 +1902,9 @@  discard block
 block discarded – undo
1811 1902
 {
1812 1903
 	global $modSettings, $txt, $scripturl, $user_info;
1813 1904
 
1814
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1815
-		return;
1905
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1906
+			return;
1907
+	}
1816 1908
 
1817 1909
 	$eventOptions = array(
1818 1910
 		'include_birthdays' => allowedTo('profile_view'),
@@ -1825,19 +1917,22 @@  discard block
 block discarded – undo
1825 1917
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1826 1918
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1827 1919
 
1828
-	if ($output_method != 'echo')
1829
-		return $return;
1920
+	if ($output_method != 'echo') {
1921
+			return $return;
1922
+	}
1830 1923
 
1831
-	if (!empty($return['calendar_holidays']))
1832
-		echo '
1924
+	if (!empty($return['calendar_holidays'])) {
1925
+			echo '
1833 1926
 			<span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br></span>';
1927
+	}
1834 1928
 	if (!empty($return['calendar_birthdays']))
1835 1929
 	{
1836 1930
 		echo '
1837 1931
 			<span class="birthday">' . $txt['birthdays_upcoming'] . '</span> ';
1838
-		foreach ($return['calendar_birthdays'] as $member)
1839
-			echo '
1932
+		foreach ($return['calendar_birthdays'] as $member) {
1933
+					echo '
1840 1934
 			<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', !$member['is_last'] ? ', ' : '';
1935
+		}
1841 1936
 		echo '
1842 1937
 			<br>';
1843 1938
 	}
@@ -1847,9 +1942,10 @@  discard block
 block discarded – undo
1847 1942
 			<span class="event">' . $txt['events_upcoming'] . '</span> ';
1848 1943
 		foreach ($return['calendar_events'] as $event)
1849 1944
 		{
1850
-			if ($event['can_edit'])
1851
-				echo '
1945
+			if ($event['can_edit']) {
1946
+							echo '
1852 1947
 			<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1948
+			}
1853 1949
 			echo '
1854 1950
 			' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1855 1951
 		}
@@ -1873,25 +1969,29 @@  discard block
 block discarded – undo
1873 1969
 	loadLanguage('Stats');
1874 1970
 
1875 1971
 	// Must be integers....
1876
-	if ($limit === null)
1877
-		$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
1878
-	else
1879
-		$limit = (int) $limit;
1880
-
1881
-	if ($start === null)
1882
-		$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1883
-	else
1884
-		$start = (int) $start;
1885
-
1886
-	if ($board !== null)
1887
-		$board = (int) $board;
1888
-	elseif (isset($_GET['board']))
1889
-		$board = (int) $_GET['board'];
1890
-
1891
-	if ($length === null)
1892
-		$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
1893
-	else
1894
-		$length = (int) $length;
1972
+	if ($limit === null) {
1973
+			$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
1974
+	} else {
1975
+			$limit = (int) $limit;
1976
+	}
1977
+
1978
+	if ($start === null) {
1979
+			$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1980
+	} else {
1981
+			$start = (int) $start;
1982
+	}
1983
+
1984
+	if ($board !== null) {
1985
+			$board = (int) $board;
1986
+	} elseif (isset($_GET['board'])) {
1987
+			$board = (int) $_GET['board'];
1988
+	}
1989
+
1990
+	if ($length === null) {
1991
+			$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
1992
+	} else {
1993
+			$length = (int) $length;
1994
+	}
1895 1995
 
1896 1996
 	$limit = max(0, $limit);
1897 1997
 	$start = max(0, $start);
@@ -1909,17 +2009,19 @@  discard block
 block discarded – undo
1909 2009
 	);
1910 2010
 	if ($smcFunc['db_num_rows']($request) == 0)
1911 2011
 	{
1912
-		if ($output_method == 'echo')
1913
-			die($txt['ssi_no_guests']);
1914
-		else
1915
-			return array();
2012
+		if ($output_method == 'echo') {
2013
+					die($txt['ssi_no_guests']);
2014
+		} else {
2015
+					return array();
2016
+		}
1916 2017
 	}
1917 2018
 	list ($board) = $smcFunc['db_fetch_row']($request);
1918 2019
 	$smcFunc['db_free_result']($request);
1919 2020
 
1920 2021
 	$icon_sources = array();
1921
-	foreach ($context['stable_icons'] as $icon)
1922
-		$icon_sources[$icon] = 'images_url';
2022
+	foreach ($context['stable_icons'] as $icon) {
2023
+			$icon_sources[$icon] = 'images_url';
2024
+	}
1923 2025
 
1924 2026
 	if (!empty($modSettings['enable_likes']))
1925 2027
 	{
@@ -1942,12 +2044,14 @@  discard block
 block discarded – undo
1942 2044
 		)
1943 2045
 	);
1944 2046
 	$posts = array();
1945
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1946
-		$posts[] = $row['id_first_msg'];
2047
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2048
+			$posts[] = $row['id_first_msg'];
2049
+	}
1947 2050
 	$smcFunc['db_free_result']($request);
1948 2051
 
1949
-	if (empty($posts))
1950
-		return array();
2052
+	if (empty($posts)) {
2053
+			return array();
2054
+	}
1951 2055
 
1952 2056
 	// Find the posts.
1953 2057
 	$request = $smcFunc['db_query']('', '
@@ -1977,24 +2081,28 @@  discard block
 block discarded – undo
1977 2081
 			$last_space = strrpos($row['body'], ' ');
1978 2082
 			$last_open = strrpos($row['body'], '<');
1979 2083
 			$last_close = strrpos($row['body'], '>');
1980
-			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6)
1981
-				$cutoff = $last_open;
1982
-			elseif (empty($last_close) || $last_close < $last_open)
1983
-				$cutoff = $last_space;
2084
+			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6) {
2085
+							$cutoff = $last_open;
2086
+			} elseif (empty($last_close) || $last_close < $last_open) {
2087
+							$cutoff = $last_space;
2088
+			}
1984 2089
 
1985
-			if ($cutoff !== false)
1986
-				$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2090
+			if ($cutoff !== false) {
2091
+							$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2092
+			}
1987 2093
 			$row['body'] .= '...';
1988 2094
 		}
1989 2095
 
1990 2096
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
1991 2097
 
1992
-		if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
1993
-			$row['icon'] = 'recycled';
2098
+		if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
2099
+					$row['icon'] = 'recycled';
2100
+		}
1994 2101
 
1995 2102
 		// Check that this message icon is there...
1996
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
1997
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2103
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
2104
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2105
+		}
1998 2106
 
1999 2107
 		censorText($row['subject']);
2000 2108
 		censorText($row['body']);
@@ -2031,16 +2139,18 @@  discard block
 block discarded – undo
2031 2139
 	}
2032 2140
 	$smcFunc['db_free_result']($request);
2033 2141
 
2034
-	if (empty($return))
2035
-		return $return;
2142
+	if (empty($return)) {
2143
+			return $return;
2144
+	}
2036 2145
 
2037 2146
 	$return[count($return) - 1]['is_last'] = true;
2038 2147
 
2039 2148
 	// If mods want to do somthing with this list of posts, let them do that now.
2040 2149
 	call_integration_hook('integrate_ssi_boardNews', array(&$return));
2041 2150
 
2042
-	if ($output_method != 'echo')
2043
-		return $return;
2151
+	if ($output_method != 'echo') {
2152
+			return $return;
2153
+	}
2044 2154
 
2045 2155
 	foreach ($return as $news)
2046 2156
 	{
@@ -2092,9 +2202,10 @@  discard block
 block discarded – undo
2092 2202
 		echo '
2093 2203
 			</div>';
2094 2204
 
2095
-		if (!$news['is_last'])
2096
-			echo '
2205
+		if (!$news['is_last']) {
2206
+					echo '
2097 2207
 			<hr>';
2208
+		}
2098 2209
 	}
2099 2210
 }
2100 2211
 
@@ -2108,8 +2219,9 @@  discard block
 block discarded – undo
2108 2219
 {
2109 2220
 	global $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc;
2110 2221
 
2111
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
2112
-		return;
2222
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
2223
+			return;
2224
+	}
2113 2225
 
2114 2226
 	// Find all events which are happening in the near future that the member can see.
2115 2227
 	$request = $smcFunc['db_query']('', '
@@ -2135,20 +2247,23 @@  discard block
 block discarded – undo
2135 2247
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2136 2248
 	{
2137 2249
 		// Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
2138
-		if (!empty($duplicates[$row['title'] . $row['id_topic']]))
2139
-			continue;
2250
+		if (!empty($duplicates[$row['title'] . $row['id_topic']])) {
2251
+					continue;
2252
+		}
2140 2253
 
2141 2254
 		// Censor the title.
2142 2255
 		censorText($row['title']);
2143 2256
 
2144
-		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false)))
2145
-			$date = strftime('%Y-%m-%d', forum_time(false));
2146
-		else
2147
-			$date = $row['start_date'];
2257
+		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) {
2258
+					$date = strftime('%Y-%m-%d', forum_time(false));
2259
+		} else {
2260
+					$date = $row['start_date'];
2261
+		}
2148 2262
 
2149 2263
 		// If the topic it is attached to is not approved then don't link it.
2150
-		if (!empty($row['id_first_msg']) && !$row['approved'])
2151
-			$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2264
+		if (!empty($row['id_first_msg']) && !$row['approved']) {
2265
+					$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2266
+		}
2152 2267
 
2153 2268
 		$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
2154 2269
 
@@ -2174,24 +2289,27 @@  discard block
 block discarded – undo
2174 2289
 	}
2175 2290
 	$smcFunc['db_free_result']($request);
2176 2291
 
2177
-	foreach ($return as $mday => $array)
2178
-		$return[$mday][count($array) - 1]['is_last'] = true;
2292
+	foreach ($return as $mday => $array) {
2293
+			$return[$mday][count($array) - 1]['is_last'] = true;
2294
+	}
2179 2295
 
2180 2296
 	// If mods want to do somthing with this list of events, let them do that now.
2181 2297
 	call_integration_hook('integrate_ssi_recentEvents', array(&$return));
2182 2298
 
2183
-	if ($output_method != 'echo' || empty($return))
2184
-		return $return;
2299
+	if ($output_method != 'echo' || empty($return)) {
2300
+			return $return;
2301
+	}
2185 2302
 
2186 2303
 	// Well the output method is echo.
2187 2304
 	echo '
2188 2305
 			<span class="event">' . $txt['events'] . '</span> ';
2189
-	foreach ($return as $mday => $array)
2190
-		foreach ($array as $event)
2306
+	foreach ($return as $mday => $array) {
2307
+			foreach ($array as $event)
2191 2308
 		{
2192 2309
 			if ($event['can_edit'])
2193 2310
 				echo '
2194 2311
 				<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
2312
+	}
2195 2313
 
2196 2314
 			echo '
2197 2315
 				' . $event['link'] . (!$event['is_last'] ? ', ' : '');
@@ -2210,8 +2328,9 @@  discard block
 block discarded – undo
2210 2328
 	global $smcFunc;
2211 2329
 
2212 2330
 	// If $id is null, this was most likely called from a query string and should do nothing.
2213
-	if ($id === null)
2214
-		return;
2331
+	if ($id === null) {
2332
+			return;
2333
+	}
2215 2334
 
2216 2335
 	$request = $smcFunc['db_query']('', '
2217 2336
 		SELECT passwd, member_name, is_activated
@@ -2243,8 +2362,9 @@  discard block
 block discarded – undo
2243 2362
 	$attachments_boards = boardsAllowedTo('view_attachments');
2244 2363
 
2245 2364
 	// No boards?  Adios amigo.
2246
-	if (empty($attachments_boards))
2247
-		return array();
2365
+	if (empty($attachments_boards)) {
2366
+			return array();
2367
+	}
2248 2368
 
2249 2369
 	// Is it an array?
2250 2370
 	$attachment_ext = (array) $attachment_ext;
@@ -2328,8 +2448,9 @@  discard block
 block discarded – undo
2328 2448
 	call_integration_hook('integrate_ssi_recentAttachments', array(&$attachments));
2329 2449
 
2330 2450
 	// So you just want an array?  Here you can have it.
2331
-	if ($output_method == 'array' || empty($attachments))
2332
-		return $attachments;
2451
+	if ($output_method == 'array' || empty($attachments)) {
2452
+			return $attachments;
2453
+	}
2333 2454
 
2334 2455
 	// Give them the default.
2335 2456
 	echo '
@@ -2340,14 +2461,15 @@  discard block
 block discarded – undo
2340 2461
 				<th style="text-align: left; padding: 2">', $txt['downloads'], '</th>
2341 2462
 				<th style="text-align: left; padding: 2">', $txt['filesize'], '</th>
2342 2463
 			</tr>';
2343
-	foreach ($attachments as $attach)
2344
-		echo '
2464
+	foreach ($attachments as $attach) {
2465
+			echo '
2345 2466
 			<tr>
2346 2467
 				<td>', $attach['file']['link'], '</td>
2347 2468
 				<td>', $attach['member']['link'], '</td>
2348 2469
 				<td style="text-align: center">', $attach['file']['downloads'], '</td>
2349 2470
 				<td>', $attach['file']['filesize'], '</td>
2350 2471
 			</tr>';
2472
+	}
2351 2473
 	echo '
2352 2474
 		</table>';
2353 2475
 }
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +781 added lines, -591 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('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -405,27 +422,28 @@  discard block
 block discarded – undo
405 422
 				break;
406 423
 			}
407 424
 		}
425
+	} else {
426
+			$id_member = 0;
408 427
 	}
409
-	else
410
-		$id_member = 0;
411 428
 
412 429
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
413 430
 	{
414 431
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
415 432
 
416
-		if (empty($cookie_data))
417
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
433
+		if (empty($cookie_data)) {
434
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
435
+		}
418 436
 
419 437
 		list ($id_member, $password) = $cookie_data;
420 438
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
421
-	}
422
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
439
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
423 440
 	{
424 441
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
425 442
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
426 443
 
427
-		if (empty($cookie_data))
428
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
444
+		if (empty($cookie_data)) {
445
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
446
+		}
429 447
 
430 448
 		list ($id_member, $password, $login_span) = $cookie_data;
431 449
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -450,30 +468,34 @@  discard block
 block discarded – undo
450 468
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
451 469
 			$smcFunc['db_free_result']($request);
452 470
 
453
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
454
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
471
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
472
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
473
+			}
455 474
 
456
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
457
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
475
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
476
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
477
+			}
458 478
 		}
459 479
 
460 480
 		// Did we find 'im?  If not, junk it.
461 481
 		if (!empty($user_settings))
462 482
 		{
463 483
 			// As much as the password should be right, we can assume the integration set things up.
464
-			if (!empty($already_verified) && $already_verified === true)
465
-				$check = true;
484
+			if (!empty($already_verified) && $already_verified === true) {
485
+							$check = true;
486
+			}
466 487
 			// SHA-512 hash should be 128 characters long.
467
-			elseif (strlen($password) == 128)
468
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
469
-			else
470
-				$check = false;
488
+			elseif (strlen($password) == 128) {
489
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
490
+			} else {
491
+							$check = false;
492
+			}
471 493
 
472 494
 			// Wrong password or not activated - either way, you're going nowhere.
473 495
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
496
+		} else {
497
+					$id_member = 0;
474 498
 		}
475
-		else
476
-			$id_member = 0;
477 499
 
478 500
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
479 501
 		if (!$id_member)
@@ -502,8 +524,9 @@  discard block
 block discarded – undo
502 524
 
503 525
 					list ($tfamember, $tfasecret) = $tfa_data;
504 526
 
505
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
506
-						$tfasecret = null;
527
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
528
+											$tfasecret = null;
529
+					}
507 530
 				}
508 531
 
509 532
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -523,10 +546,12 @@  discard block
 block discarded – undo
523 546
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
524 547
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
525 548
 		{
526
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
549
+			if ($modSettings['tfa_mode'] == 2) {
550
+				//only do this if we are just forcing SOME membergroups
527 551
 			{
528 552
 				//Build an array of ALL user membergroups.
529 553
 				$full_groups = array($user_settings['id_group']);
554
+			}
530 555
 				if (!empty($user_settings['additional_groups']))
531 556
 				{
532 557
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -546,15 +571,17 @@  discard block
 block discarded – undo
546 571
 				);
547 572
 				$row = $smcFunc['db_fetch_assoc']($request);
548 573
 				$smcFunc['db_free_result']($request);
574
+			} else {
575
+							$row['total'] = 1;
549 576
 			}
550
-			else
551
-				$row['total'] = 1; //simplifies logics in the next "if"
577
+			//simplifies logics in the next "if"
552 578
 
553 579
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
554 580
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
555 581
 
556
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
557
-				redirectexit('action=profile;area=tfasetup;forced');
582
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
583
+							redirectexit('action=profile;area=tfasetup;forced');
584
+			}
558 585
 		}
559 586
 	}
560 587
 
@@ -591,33 +618,37 @@  discard block
 block discarded – undo
591 618
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
592 619
 				$user_settings['last_login'] = time();
593 620
 
594
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
595
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
621
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
622
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
623
+				}
596 624
 
597
-				if (!empty($modSettings['cache_enable']))
598
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
625
+				if (!empty($modSettings['cache_enable'])) {
626
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
627
+				}
599 628
 			}
629
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
630
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
600 631
 		}
601
-		elseif (empty($_SESSION['id_msg_last_visit']))
602
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
603 632
 
604 633
 		$username = $user_settings['member_name'];
605 634
 
606
-		if (empty($user_settings['additional_groups']))
607
-			$user_info = array(
635
+		if (empty($user_settings['additional_groups'])) {
636
+					$user_info = array(
608 637
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
609 638
 			);
610
-		else
611
-			$user_info = array(
639
+		} else {
640
+					$user_info = array(
612 641
 				'groups' => array_merge(
613 642
 					array($user_settings['id_group'], $user_settings['id_post_group']),
614 643
 					explode(',', $user_settings['additional_groups'])
615 644
 				)
616 645
 			);
646
+		}
617 647
 
618 648
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
619
-		foreach ($user_info['groups'] as $k => $v)
620
-			$user_info['groups'][$k] = (int) $v;
649
+		foreach ($user_info['groups'] as $k => $v) {
650
+					$user_info['groups'][$k] = (int) $v;
651
+		}
621 652
 
622 653
 		// This is a logged in user, so definitely not a spider.
623 654
 		$user_info['possibly_robot'] = false;
@@ -631,8 +662,7 @@  discard block
 block discarded – undo
631 662
 			$time_system = new DateTime('now', $tz_system);
632 663
 			$time_user = new DateTime('now', $tz_user);
633 664
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
634
-		}
635
-		else
665
+		} else
636 666
 		{
637 667
 			// !!! Compatibility.
638 668
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -646,8 +676,9 @@  discard block
 block discarded – undo
646 676
 		$user_info = array('groups' => array(-1));
647 677
 		$user_settings = array();
648 678
 
649
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
650
-			$_COOKIE[$cookiename] = '';
679
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
680
+					$_COOKIE[$cookiename] = '';
681
+		}
651 682
 
652 683
 		// Expire the 2FA cookie
653 684
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -664,19 +695,20 @@  discard block
 block discarded – undo
664 695
 		}
665 696
 
666 697
 		// Create a login token if it doesn't exist yet.
667
-		if (!isset($_SESSION['token']['post-login']))
668
-			createToken('login');
669
-		else
670
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
698
+		if (!isset($_SESSION['token']['post-login'])) {
699
+					createToken('login');
700
+		} else {
701
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
702
+		}
671 703
 
672 704
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
673 705
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
674 706
 		{
675 707
 			require_once($sourcedir . '/ManageSearchEngines.php');
676 708
 			$user_info['possibly_robot'] = SpiderCheck();
709
+		} elseif (!empty($modSettings['spider_mode'])) {
710
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
677 711
 		}
678
-		elseif (!empty($modSettings['spider_mode']))
679
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
680 712
 		// If we haven't turned on proper spider hunts then have a guess!
681 713
 		else
682 714
 		{
@@ -724,8 +756,9 @@  discard block
 block discarded – undo
724 756
 	$user_info['groups'] = array_unique($user_info['groups']);
725 757
 
726 758
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
727
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
728
-		unset($user_info['ignoreboards'][$tmp]);
759
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
760
+			unset($user_info['ignoreboards'][$tmp]);
761
+	}
729 762
 
730 763
 	// Allow the user to change their language.
731 764
 	if (!empty($modSettings['userLanguage']))
@@ -738,13 +771,14 @@  discard block
 block discarded – undo
738 771
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
739 772
 
740 773
 			// Make it permanent for members.
741
-			if (!empty($user_info['id']))
742
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
743
-			else
744
-				$_SESSION['language'] = $user_info['language'];
774
+			if (!empty($user_info['id'])) {
775
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
776
+			} else {
777
+							$_SESSION['language'] = $user_info['language'];
778
+			}
779
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
780
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
745 781
 		}
746
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
747
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
748 782
 	}
749 783
 
750 784
 	$temp = build_query_board($user_info['id']);
@@ -807,9 +841,9 @@  discard block
 block discarded – undo
807 841
 		}
808 842
 
809 843
 		// Remember redirection is the key to avoiding fallout from your bosses.
810
-		if (!empty($topic))
811
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
812
-		else
844
+		if (!empty($topic)) {
845
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
846
+		} else
813 847
 		{
814 848
 			loadPermissions();
815 849
 			loadTheme();
@@ -827,10 +861,11 @@  discard block
 block discarded – undo
827 861
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
828 862
 	{
829 863
 		// @todo SLOW?
830
-		if (!empty($topic))
831
-			$temp = cache_get_data('topic_board-' . $topic, 120);
832
-		else
833
-			$temp = cache_get_data('board-' . $board, 120);
864
+		if (!empty($topic)) {
865
+					$temp = cache_get_data('topic_board-' . $topic, 120);
866
+		} else {
867
+					$temp = cache_get_data('board-' . $board, 120);
868
+		}
834 869
 
835 870
 		if (!empty($temp))
836 871
 		{
@@ -868,8 +903,9 @@  discard block
 block discarded – undo
868 903
 			$row = $smcFunc['db_fetch_assoc']($request);
869 904
 
870 905
 			// Set the current board.
871
-			if (!empty($row['id_board']))
872
-				$board = $row['id_board'];
906
+			if (!empty($row['id_board'])) {
907
+							$board = $row['id_board'];
908
+			}
873 909
 
874 910
 			// Basic operating information. (globals... :/)
875 911
 			$board_info = array(
@@ -905,21 +941,23 @@  discard block
 block discarded – undo
905 941
 
906 942
 			do
907 943
 			{
908
-				if (!empty($row['id_moderator']))
909
-					$board_info['moderators'][$row['id_moderator']] = array(
944
+				if (!empty($row['id_moderator'])) {
945
+									$board_info['moderators'][$row['id_moderator']] = array(
910 946
 						'id' => $row['id_moderator'],
911 947
 						'name' => $row['real_name'],
912 948
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
913 949
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
914 950
 					);
951
+				}
915 952
 
916
-				if (!empty($row['id_moderator_group']))
917
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
953
+				if (!empty($row['id_moderator_group'])) {
954
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
918 955
 						'id' => $row['id_moderator_group'],
919 956
 						'name' => $row['group_name'],
920 957
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
921 958
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
922 959
 					);
960
+				}
923 961
 			}
924 962
 			while ($row = $smcFunc['db_fetch_assoc']($request));
925 963
 
@@ -951,12 +989,12 @@  discard block
 block discarded – undo
951 989
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
952 990
 			{
953 991
 				// @todo SLOW?
954
-				if (!empty($topic))
955
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
992
+				if (!empty($topic)) {
993
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
994
+				}
956 995
 				cache_put_data('board-' . $board, $board_info, 120);
957 996
 			}
958
-		}
959
-		else
997
+		} else
960 998
 		{
961 999
 			// Otherwise the topic is invalid, there are no moderators, etc.
962 1000
 			$board_info = array(
@@ -970,8 +1008,9 @@  discard block
 block discarded – undo
970 1008
 		$smcFunc['db_free_result']($request);
971 1009
 	}
972 1010
 
973
-	if (!empty($topic))
974
-		$_GET['board'] = (int) $board;
1011
+	if (!empty($topic)) {
1012
+			$_GET['board'] = (int) $board;
1013
+	}
975 1014
 
976 1015
 	if (!empty($board))
977 1016
 	{
@@ -981,10 +1020,12 @@  discard block
 block discarded – undo
981 1020
 		// Now check if the user is a moderator.
982 1021
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
983 1022
 
984
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
985
-			$board_info['error'] = 'access';
986
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
987
-			$board_info['error'] = 'access';
1023
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1024
+					$board_info['error'] = 'access';
1025
+		}
1026
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1027
+					$board_info['error'] = 'access';
1028
+		}
988 1029
 
989 1030
 		// Build up the linktree.
990 1031
 		$context['linktree'] = array_merge(
@@ -1007,8 +1048,9 @@  discard block
 block discarded – undo
1007 1048
 	$context['current_board'] = $board;
1008 1049
 
1009 1050
 	// No posting in redirection boards!
1010
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1011
-		$board_info['error'] == 'post_in_redirect';
1051
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1052
+			$board_info['error'] == 'post_in_redirect';
1053
+	}
1012 1054
 
1013 1055
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1014 1056
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1034,24 +1076,23 @@  discard block
 block discarded – undo
1034 1076
 			ob_end_clean();
1035 1077
 			header('HTTP/1.1 403 Forbidden');
1036 1078
 			die;
1037
-		}
1038
-		elseif ($board_info['error'] == 'post_in_redirect')
1079
+		} elseif ($board_info['error'] == 'post_in_redirect')
1039 1080
 		{
1040 1081
 			// Slightly different error message here...
1041 1082
 			fatal_lang_error('cannot_post_redirect', false);
1042
-		}
1043
-		elseif ($user_info['is_guest'])
1083
+		} elseif ($user_info['is_guest'])
1044 1084
 		{
1045 1085
 			loadLanguage('Errors');
1046 1086
 			is_not_guest($txt['topic_gone']);
1087
+		} else {
1088
+					fatal_lang_error('topic_gone', false);
1047 1089
 		}
1048
-		else
1049
-			fatal_lang_error('topic_gone', false);
1050 1090
 	}
1051 1091
 
1052
-	if ($user_info['is_mod'])
1053
-		$user_info['groups'][] = 3;
1054
-}
1092
+	if ($user_info['is_mod']) {
1093
+			$user_info['groups'][] = 3;
1094
+	}
1095
+	}
1055 1096
 
1056 1097
 /**
1057 1098
  * Load this user's permissions.
@@ -1072,8 +1113,9 @@  discard block
 block discarded – undo
1072 1113
 		asort($cache_groups);
1073 1114
 		$cache_groups = implode(',', $cache_groups);
1074 1115
 		// If it's a spider then cache it different.
1075
-		if ($user_info['possibly_robot'])
1076
-			$cache_groups .= '-spider';
1116
+		if ($user_info['possibly_robot']) {
1117
+					$cache_groups .= '-spider';
1118
+		}
1077 1119
 
1078 1120
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1079 1121
 		{
@@ -1081,9 +1123,9 @@  discard block
 block discarded – undo
1081 1123
 			banPermissions();
1082 1124
 
1083 1125
 			return;
1126
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1127
+					list ($user_info['permissions'], $removals) = $temp;
1084 1128
 		}
1085
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1086
-			list ($user_info['permissions'], $removals) = $temp;
1087 1129
 	}
1088 1130
 
1089 1131
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1105,23 +1147,26 @@  discard block
 block discarded – undo
1105 1147
 		$removals = array();
1106 1148
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1107 1149
 		{
1108
-			if (empty($row['add_deny']))
1109
-				$removals[] = $row['permission'];
1110
-			else
1111
-				$user_info['permissions'][] = $row['permission'];
1150
+			if (empty($row['add_deny'])) {
1151
+							$removals[] = $row['permission'];
1152
+			} else {
1153
+							$user_info['permissions'][] = $row['permission'];
1154
+			}
1112 1155
 		}
1113 1156
 		$smcFunc['db_free_result']($request);
1114 1157
 
1115
-		if (isset($cache_groups))
1116
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1158
+		if (isset($cache_groups)) {
1159
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1160
+		}
1117 1161
 	}
1118 1162
 
1119 1163
 	// Get the board permissions.
1120 1164
 	if (!empty($board))
1121 1165
 	{
1122 1166
 		// Make sure the board (if any) has been loaded by loadBoard().
1123
-		if (!isset($board_info['profile']))
1124
-			fatal_lang_error('no_board');
1167
+		if (!isset($board_info['profile'])) {
1168
+					fatal_lang_error('no_board');
1169
+		}
1125 1170
 
1126 1171
 		$request = $smcFunc['db_query']('', '
1127 1172
 			SELECT permission, add_deny
@@ -1137,20 +1182,23 @@  discard block
 block discarded – undo
1137 1182
 		);
1138 1183
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1139 1184
 		{
1140
-			if (empty($row['add_deny']))
1141
-				$removals[] = $row['permission'];
1142
-			else
1143
-				$user_info['permissions'][] = $row['permission'];
1185
+			if (empty($row['add_deny'])) {
1186
+							$removals[] = $row['permission'];
1187
+			} else {
1188
+							$user_info['permissions'][] = $row['permission'];
1189
+			}
1144 1190
 		}
1145 1191
 		$smcFunc['db_free_result']($request);
1146 1192
 	}
1147 1193
 
1148 1194
 	// Remove all the permissions they shouldn't have ;).
1149
-	if (!empty($modSettings['permission_enable_deny']))
1150
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1195
+	if (!empty($modSettings['permission_enable_deny'])) {
1196
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1197
+	}
1151 1198
 
1152
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1153
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1199
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1200
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1201
+	}
1154 1202
 
1155 1203
 	// Banned?  Watch, don't touch..
1156 1204
 	banPermissions();
@@ -1162,17 +1210,18 @@  discard block
 block discarded – undo
1162 1210
 		{
1163 1211
 			require_once($sourcedir . '/Subs-Auth.php');
1164 1212
 			rebuildModCache();
1213
+		} else {
1214
+					$user_info['mod_cache'] = $_SESSION['mc'];
1165 1215
 		}
1166
-		else
1167
-			$user_info['mod_cache'] = $_SESSION['mc'];
1168 1216
 
1169 1217
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1170 1218
 		// For example this drastically simplifies certain changes to the profile area.
1171 1219
 		$user_info['permissions'][] = 'is_not_guest';
1172 1220
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1173 1221
 		$user_info['permissions'][] = 'profile_view_own';
1174
-		if (in_array('profile_view', $user_info['permissions']))
1175
-			$user_info['permissions'][] = 'profile_view_any';
1222
+		if (in_array('profile_view', $user_info['permissions'])) {
1223
+					$user_info['permissions'][] = 'profile_view_any';
1224
+		}
1176 1225
 	}
1177 1226
 }
1178 1227
 
@@ -1190,8 +1239,9 @@  discard block
 block discarded – undo
1190 1239
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1191 1240
 
1192 1241
 	// Can't just look for no users :P.
1193
-	if (empty($users))
1194
-		return array();
1242
+	if (empty($users)) {
1243
+			return array();
1244
+	}
1195 1245
 
1196 1246
 	// Pass the set value
1197 1247
 	$context['loadMemberContext_set'] = $set;
@@ -1206,8 +1256,9 @@  discard block
 block discarded – undo
1206 1256
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1207 1257
 		{
1208 1258
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1209
-			if ($data == null)
1210
-				continue;
1259
+			if ($data == null) {
1260
+							continue;
1261
+			}
1211 1262
 
1212 1263
 			$loaded_ids[] = $data['id_member'];
1213 1264
 			$user_profile[$data['id_member']] = $data;
@@ -1274,16 +1325,19 @@  discard block
 block discarded – undo
1274 1325
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1275 1326
 
1276 1327
 			// Take care of proxying avatar if required, do this here for maximum reach
1277
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1278
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1328
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1329
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1330
+			}
1279 1331
 
1280 1332
 			// Keep track of the member's normal member group
1281 1333
 			$row['primary_group'] = $row['member_group'];
1282 1334
 
1283
-			if (isset($row['member_ip']))
1284
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1285
-			if (isset($row['member_ip2']))
1286
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1335
+			if (isset($row['member_ip'])) {
1336
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1337
+			}
1338
+			if (isset($row['member_ip2'])) {
1339
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1340
+			}
1287 1341
 			$new_loaded_ids[] = $row['id_member'];
1288 1342
 			$loaded_ids[] = $row['id_member'];
1289 1343
 			$row['options'] = array();
@@ -1302,8 +1356,9 @@  discard block
 block discarded – undo
1302 1356
 				'loaded_ids' => $new_loaded_ids,
1303 1357
 			)
1304 1358
 		);
1305
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1306
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1359
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1360
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1361
+		}
1307 1362
 		$smcFunc['db_free_result']($request);
1308 1363
 	}
1309 1364
 
@@ -1314,10 +1369,11 @@  discard block
 block discarded – undo
1314 1369
 	{
1315 1370
 		foreach ($loaded_ids as $a_member)
1316 1371
 		{
1317
-			if (!empty($user_profile[$a_member]['additional_groups']))
1318
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1319
-			else
1320
-				$groups = array($user_profile[$a_member]['id_group']);
1372
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1373
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1374
+			} else {
1375
+							$groups = array($user_profile[$a_member]['id_group']);
1376
+			}
1321 1377
 
1322 1378
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1323 1379
 
@@ -1330,8 +1386,9 @@  discard block
 block discarded – undo
1330 1386
 
1331 1387
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1332 1388
 	{
1333
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1334
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1389
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1390
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1391
+		}
1335 1392
 	}
1336 1393
 
1337 1394
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1357,14 +1414,17 @@  discard block
 block discarded – undo
1357 1414
 		foreach ($temp_mods as $id)
1358 1415
 		{
1359 1416
 			// By popular demand, don't show admins or global moderators as moderators.
1360
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1361
-				$user_profile[$id]['member_group'] = $row['member_group'];
1417
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1418
+							$user_profile[$id]['member_group'] = $row['member_group'];
1419
+			}
1362 1420
 
1363 1421
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1364
-			if (!empty($row['icons']))
1365
-				$user_profile[$id]['icons'] = $row['icons'];
1366
-			if (!empty($row['member_group_color']))
1367
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1422
+			if (!empty($row['icons'])) {
1423
+							$user_profile[$id]['icons'] = $row['icons'];
1424
+			}
1425
+			if (!empty($row['member_group_color'])) {
1426
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1427
+			}
1368 1428
 		}
1369 1429
 	}
1370 1430
 
@@ -1386,12 +1446,14 @@  discard block
 block discarded – undo
1386 1446
 	static $loadedLanguages = array();
1387 1447
 
1388 1448
 	// If this person's data is already loaded, skip it.
1389
-	if (isset($dataLoaded[$user]))
1390
-		return true;
1449
+	if (isset($dataLoaded[$user])) {
1450
+			return true;
1451
+	}
1391 1452
 
1392 1453
 	// We can't load guests or members not loaded by loadMemberData()!
1393
-	if ($user == 0)
1394
-		return false;
1454
+	if ($user == 0) {
1455
+			return false;
1456
+	}
1395 1457
 	if (!isset($user_profile[$user]))
1396 1458
 	{
1397 1459
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1417,12 +1479,16 @@  discard block
 block discarded – undo
1417 1479
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1418 1480
 
1419 1481
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1420
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1482
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1483
+		//icon is set and exists
1421 1484
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1422
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1485
+	} elseif (isset($profile['icons'][1])) {
1486
+		//icon is set and doesn't exist, fallback to default
1423 1487
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1424
-	else //not set, bye bye
1488
+	} else {
1489
+		//not set, bye bye
1425 1490
 		$group_icon_url = '';
1491
+	}
1426 1492
 
1427 1493
 	// These minimal values are always loaded
1428 1494
 	$memberContext[$user] = array(
@@ -1441,8 +1507,9 @@  discard block
 block discarded – undo
1441 1507
 	if ($context['loadMemberContext_set'] != 'minimal')
1442 1508
 	{
1443 1509
 		// Go the extra mile and load the user's native language name.
1444
-		if (empty($loadedLanguages))
1445
-			$loadedLanguages = getLanguages();
1510
+		if (empty($loadedLanguages)) {
1511
+					$loadedLanguages = getLanguages();
1512
+		}
1446 1513
 
1447 1514
 		$memberContext[$user] += array(
1448 1515
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1497,31 +1564,33 @@  discard block
 block discarded – undo
1497 1564
 	{
1498 1565
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1499 1566
 		{
1500
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1501
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1502
-			else
1503
-				$image = get_gravatar_url($profile['email_address']);
1504
-		}
1505
-		else
1567
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1568
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1569
+			} else {
1570
+							$image = get_gravatar_url($profile['email_address']);
1571
+			}
1572
+		} else
1506 1573
 		{
1507 1574
 			// So it's stored in the member table?
1508 1575
 			if (!empty($profile['avatar']))
1509 1576
 			{
1510 1577
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1578
+			} elseif (!empty($profile['filename'])) {
1579
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1511 1580
 			}
1512
-			elseif (!empty($profile['filename']))
1513
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1514 1581
 			// Right... no avatar...use the default one
1515
-			else
1516
-				$image = $modSettings['avatar_url'] . '/default.png';
1582
+			else {
1583
+							$image = $modSettings['avatar_url'] . '/default.png';
1584
+			}
1517 1585
 		}
1518
-		if (!empty($image))
1519
-			$memberContext[$user]['avatar'] = array(
1586
+		if (!empty($image)) {
1587
+					$memberContext[$user]['avatar'] = array(
1520 1588
 				'name' => $profile['avatar'],
1521 1589
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1522 1590
 				'href' => $image,
1523 1591
 				'url' => $image,
1524 1592
 			);
1593
+		}
1525 1594
 	}
1526 1595
 
1527 1596
 	// Are we also loading the members custom fields into context?
@@ -1529,35 +1598,41 @@  discard block
 block discarded – undo
1529 1598
 	{
1530 1599
 		$memberContext[$user]['custom_fields'] = array();
1531 1600
 
1532
-		if (!isset($context['display_fields']))
1533
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1601
+		if (!isset($context['display_fields'])) {
1602
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1603
+		}
1534 1604
 
1535 1605
 		foreach ($context['display_fields'] as $custom)
1536 1606
 		{
1537
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1538
-				continue;
1607
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1608
+							continue;
1609
+			}
1539 1610
 
1540 1611
 			$value = $profile['options'][$custom['col_name']];
1541 1612
 
1542 1613
 			// Don't show the "disabled" option for the "gender" field.
1543
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1544
-				continue;
1614
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1615
+							continue;
1616
+			}
1545 1617
 
1546 1618
 			// BBC?
1547
-			if ($custom['bbc'])
1548
-				$value = parse_bbc($value);
1619
+			if ($custom['bbc']) {
1620
+							$value = parse_bbc($value);
1621
+			}
1549 1622
 			// ... or checkbox?
1550
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1551
-				$value = $value ? $txt['yes'] : $txt['no'];
1623
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1624
+							$value = $value ? $txt['yes'] : $txt['no'];
1625
+			}
1552 1626
 
1553 1627
 			// Enclosing the user input within some other text?
1554
-			if (!empty($custom['enclose']))
1555
-				$value = strtr($custom['enclose'], array(
1628
+			if (!empty($custom['enclose'])) {
1629
+							$value = strtr($custom['enclose'], array(
1556 1630
 					'{SCRIPTURL}' => $scripturl,
1557 1631
 					'{IMAGES_URL}' => $settings['images_url'],
1558 1632
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1559 1633
 					'{INPUT}' => $value,
1560 1634
 				));
1635
+			}
1561 1636
 
1562 1637
 			$memberContext[$user]['custom_fields'][] = array(
1563 1638
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1584,8 +1659,9 @@  discard block
 block discarded – undo
1584 1659
 	global $smcFunc, $txt, $scripturl, $settings;
1585 1660
 
1586 1661
 	// Do not waste my time...
1587
-	if (empty($users) || empty($params))
1588
-		return false;
1662
+	if (empty($users) || empty($params)) {
1663
+			return false;
1664
+	}
1589 1665
 
1590 1666
 	// Make sure it's an array.
1591 1667
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1609,31 +1685,36 @@  discard block
 block discarded – undo
1609 1685
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1610 1686
 	{
1611 1687
 		// BBC?
1612
-		if (!empty($row['bbc']))
1613
-			$row['value'] = parse_bbc($row['value']);
1688
+		if (!empty($row['bbc'])) {
1689
+					$row['value'] = parse_bbc($row['value']);
1690
+		}
1614 1691
 
1615 1692
 		// ... or checkbox?
1616
-		elseif (isset($row['type']) && $row['type'] == 'check')
1617
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1693
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1694
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1695
+		}
1618 1696
 
1619 1697
 		// Enclosing the user input within some other text?
1620
-		if (!empty($row['enclose']))
1621
-			$row['value'] = strtr($row['enclose'], array(
1698
+		if (!empty($row['enclose'])) {
1699
+					$row['value'] = strtr($row['enclose'], array(
1622 1700
 				'{SCRIPTURL}' => $scripturl,
1623 1701
 				'{IMAGES_URL}' => $settings['images_url'],
1624 1702
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1625 1703
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1626 1704
 			));
1705
+		}
1627 1706
 
1628 1707
 		// Send a simple array if there is just 1 param
1629
-		if (count($params) == 1)
1630
-			$return[$row['id_member']] = $row;
1708
+		if (count($params) == 1) {
1709
+					$return[$row['id_member']] = $row;
1710
+		}
1631 1711
 
1632 1712
 		// More than 1? knock yourself out...
1633 1713
 		else
1634 1714
 		{
1635
-			if (!isset($return[$row['id_member']]))
1636
-				$return[$row['id_member']] = array();
1715
+			if (!isset($return[$row['id_member']])) {
1716
+							$return[$row['id_member']] = array();
1717
+			}
1637 1718
 
1638 1719
 			$return[$row['id_member']][$row['variable']] = $row;
1639 1720
 		}
@@ -1667,8 +1748,9 @@  discard block
 block discarded – undo
1667 1748
 	global $context;
1668 1749
 
1669 1750
 	// Don't know any browser!
1670
-	if (empty($context['browser']))
1671
-		detectBrowser();
1751
+	if (empty($context['browser'])) {
1752
+			detectBrowser();
1753
+	}
1672 1754
 
1673 1755
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1674 1756
 }
@@ -1686,8 +1768,9 @@  discard block
 block discarded – undo
1686 1768
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1687 1769
 
1688 1770
 	// The theme was specified by parameter.
1689
-	if (!empty($id_theme))
1690
-		$id_theme = (int) $id_theme;
1771
+	if (!empty($id_theme)) {
1772
+			$id_theme = (int) $id_theme;
1773
+	}
1691 1774
 	// The theme was specified by REQUEST.
1692 1775
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1693 1776
 	{
@@ -1695,54 +1778,61 @@  discard block
 block discarded – undo
1695 1778
 		$_SESSION['id_theme'] = $id_theme;
1696 1779
 	}
1697 1780
 	// The theme was specified by REQUEST... previously.
1698
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1699
-		$id_theme = (int) $_SESSION['id_theme'];
1781
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1782
+			$id_theme = (int) $_SESSION['id_theme'];
1783
+	}
1700 1784
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1701
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1702
-		$id_theme = $user_info['theme'];
1785
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1786
+			$id_theme = $user_info['theme'];
1787
+	}
1703 1788
 	// The theme was specified by the board.
1704
-	elseif (!empty($board_info['theme']))
1705
-		$id_theme = $board_info['theme'];
1789
+	elseif (!empty($board_info['theme'])) {
1790
+			$id_theme = $board_info['theme'];
1791
+	}
1706 1792
 	// The theme is the forum's default.
1707
-	else
1708
-		$id_theme = $modSettings['theme_guests'];
1793
+	else {
1794
+			$id_theme = $modSettings['theme_guests'];
1795
+	}
1709 1796
 
1710 1797
 	// We already load the basic stuff?
1711 1798
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1712 1799
 	{
1713 1800
 		// Verify the id_theme... no foul play.
1714 1801
 		// Always allow the board specific theme, if they are overriding.
1715
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1716
-			$id_theme = $board_info['theme'];
1802
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1803
+					$id_theme = $board_info['theme'];
1804
+		}
1717 1805
 		// If they have specified a particular theme to use with SSI allow it to be used.
1718
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1719
-			$id_theme = (int) $id_theme;
1720
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1806
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1807
+					$id_theme = (int) $id_theme;
1808
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1721 1809
 		{
1722 1810
 			$themes = explode(',', $modSettings['enableThemes']);
1723
-			if (!in_array($id_theme, $themes))
1724
-				$id_theme = $modSettings['theme_guests'];
1725
-			else
1726
-				$id_theme = (int) $id_theme;
1811
+			if (!in_array($id_theme, $themes)) {
1812
+							$id_theme = $modSettings['theme_guests'];
1813
+			} else {
1814
+							$id_theme = (int) $id_theme;
1815
+			}
1816
+		} else {
1817
+					$id_theme = (int) $id_theme;
1727 1818
 		}
1728
-		else
1729
-			$id_theme = (int) $id_theme;
1730 1819
 
1731 1820
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1732 1821
 
1733 1822
 		// Disable image proxy if we don't have SSL enabled
1734
-		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1735
-			$image_proxy_enabled = false;
1823
+		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1824
+					$image_proxy_enabled = false;
1825
+		}
1736 1826
 
1737 1827
 		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'])
1738 1828
 		{
1739 1829
 			$themeData = $temp;
1740 1830
 			$flag = true;
1831
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1832
+					$themeData = $temp + array($member => array());
1833
+		} else {
1834
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1741 1835
 		}
1742
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1743
-			$themeData = $temp + array($member => array());
1744
-		else
1745
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1746 1836
 
1747 1837
 		if (empty($flag))
1748 1838
 		{
@@ -1761,31 +1851,37 @@  discard block
 block discarded – undo
1761 1851
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1762 1852
 			{
1763 1853
 				// There are just things we shouldn't be able to change as members.
1764
-				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')))
1765
-					continue;
1854
+				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'))) {
1855
+									continue;
1856
+				}
1766 1857
 
1767 1858
 				// If this is the theme_dir of the default theme, store it.
1768
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1769
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1859
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1860
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1861
+				}
1770 1862
 
1771 1863
 				// If this isn't set yet, is a theme option, or is not the default theme..
1772
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1773
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1864
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1865
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1866
+				}
1774 1867
 			}
1775 1868
 			$smcFunc['db_free_result']($result);
1776 1869
 
1777
-			if (!empty($themeData[-1]))
1778
-				foreach ($themeData[-1] as $k => $v)
1870
+			if (!empty($themeData[-1])) {
1871
+							foreach ($themeData[-1] as $k => $v)
1779 1872
 				{
1780 1873
 					if (!isset($themeData[$member][$k]))
1781 1874
 						$themeData[$member][$k] = $v;
1875
+			}
1782 1876
 				}
1783 1877
 
1784
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1785
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1878
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1879
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1880
+			}
1786 1881
 			// Only if we didn't already load that part of the cache...
1787
-			elseif (!isset($temp))
1788
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1882
+			elseif (!isset($temp)) {
1883
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1884
+			}
1789 1885
 		}
1790 1886
 
1791 1887
 		$settings = $themeData[0];
@@ -1802,17 +1898,20 @@  discard block
 block discarded – undo
1802 1898
 		$settings['template_dirs'][] = $settings['theme_dir'];
1803 1899
 
1804 1900
 		// Based on theme (if there is one).
1805
-		if (!empty($settings['base_theme_dir']))
1806
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1901
+		if (!empty($settings['base_theme_dir'])) {
1902
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1903
+		}
1807 1904
 
1808 1905
 		// Lastly the default theme.
1809
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1810
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1906
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1907
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1908
+		}
1811 1909
 	}
1812 1910
 
1813 1911
 
1814
-	if (!$initialize)
1815
-		return;
1912
+	if (!$initialize) {
1913
+			return;
1914
+	}
1816 1915
 
1817 1916
 	// Check to see if we're forcing SSL
1818 1917
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
@@ -1833,8 +1932,9 @@  discard block
 block discarded – undo
1833 1932
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1834 1933
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1835 1934
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1836
-		if ($temp != '/')
1837
-			$detected_url .= $temp;
1935
+		if ($temp != '/') {
1936
+					$detected_url .= $temp;
1937
+		}
1838 1938
 	}
1839 1939
 	if (isset($detected_url) && $detected_url != $boardurl)
1840 1940
 	{
@@ -1846,8 +1946,9 @@  discard block
 block discarded – undo
1846 1946
 			foreach ($aliases as $alias)
1847 1947
 			{
1848 1948
 				// Rip off all the boring parts, spaces, etc.
1849
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1850
-					$do_fix = true;
1949
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1950
+									$do_fix = true;
1951
+				}
1851 1952
 			}
1852 1953
 		}
1853 1954
 
@@ -1855,21 +1956,23 @@  discard block
 block discarded – undo
1855 1956
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1856 1957
 		{
1857 1958
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1858
-			if (empty($_GET))
1859
-				redirectexit('wwwRedirect');
1860
-			else
1959
+			if (empty($_GET)) {
1960
+							redirectexit('wwwRedirect');
1961
+			} else
1861 1962
 			{
1862 1963
 				$k = key($_GET);
1863 1964
 				$v = current($_GET);
1864 1965
 
1865
-				if ($k != 'wwwRedirect')
1866
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1966
+				if ($k != 'wwwRedirect') {
1967
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1968
+				}
1867 1969
 			}
1868 1970
 		}
1869 1971
 
1870 1972
 		// #3 is just a check for SSL...
1871
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1872
-			$do_fix = true;
1973
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1974
+					$do_fix = true;
1975
+		}
1873 1976
 
1874 1977
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1875 1978
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1904,8 +2007,9 @@  discard block
 block discarded – undo
1904 2007
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1905 2008
 				}
1906 2009
 			}
1907
-			foreach ($context['linktree'] as $k => $dummy)
1908
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2010
+			foreach ($context['linktree'] as $k => $dummy) {
2011
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2012
+			}
1909 2013
 		}
1910 2014
 	}
1911 2015
 	// Set up the contextual user array.
@@ -1924,16 +2028,16 @@  discard block
 block discarded – undo
1924 2028
 			'email' => $user_info['email'],
1925 2029
 			'ignoreusers' => $user_info['ignoreusers'],
1926 2030
 		);
1927
-		if (!$context['user']['is_guest'])
1928
-			$context['user']['name'] = $user_info['name'];
1929
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1930
-			$context['user']['name'] = $txt['guest_title'];
2031
+		if (!$context['user']['is_guest']) {
2032
+					$context['user']['name'] = $user_info['name'];
2033
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2034
+					$context['user']['name'] = $txt['guest_title'];
2035
+		}
1931 2036
 
1932 2037
 		// Determine the current smiley set.
1933 2038
 		$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'];
1934 2039
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1935
-	}
1936
-	else
2040
+	} else
1937 2041
 	{
1938 2042
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1939 2043
 		$context['user'] = array(
@@ -1967,18 +2071,24 @@  discard block
 block discarded – undo
1967 2071
 	}
1968 2072
 
1969 2073
 	// Some basic information...
1970
-	if (!isset($context['html_headers']))
1971
-		$context['html_headers'] = '';
1972
-	if (!isset($context['javascript_files']))
1973
-		$context['javascript_files'] = array();
1974
-	if (!isset($context['css_files']))
1975
-		$context['css_files'] = array();
1976
-	if (!isset($context['css_header']))
1977
-		$context['css_header'] = array();
1978
-	if (!isset($context['javascript_inline']))
1979
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1980
-	if (!isset($context['javascript_vars']))
1981
-		$context['javascript_vars'] = array();
2074
+	if (!isset($context['html_headers'])) {
2075
+			$context['html_headers'] = '';
2076
+	}
2077
+	if (!isset($context['javascript_files'])) {
2078
+			$context['javascript_files'] = array();
2079
+	}
2080
+	if (!isset($context['css_files'])) {
2081
+			$context['css_files'] = array();
2082
+	}
2083
+	if (!isset($context['css_header'])) {
2084
+			$context['css_header'] = array();
2085
+	}
2086
+	if (!isset($context['javascript_inline'])) {
2087
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2088
+	}
2089
+	if (!isset($context['javascript_vars'])) {
2090
+			$context['javascript_vars'] = array();
2091
+	}
1982 2092
 
1983 2093
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1984 2094
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1990,16 +2100,18 @@  discard block
 block discarded – undo
1990 2100
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1991 2101
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1992 2102
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1993
-	if (isset($modSettings['load_average']))
1994
-		$context['load_average'] = $modSettings['load_average'];
2103
+	if (isset($modSettings['load_average'])) {
2104
+			$context['load_average'] = $modSettings['load_average'];
2105
+	}
1995 2106
 
1996 2107
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1997 2108
 	detectBrowser();
1998 2109
 
1999 2110
 	// Set the top level linktree up.
2000 2111
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2001
-	if (empty($context['linktree']))
2002
-		$context['linktree'] = array();
2112
+	if (empty($context['linktree'])) {
2113
+			$context['linktree'] = array();
2114
+	}
2003 2115
 	array_unshift($context['linktree'], array(
2004 2116
 		'url' => $scripturl,
2005 2117
 		'name' => $context['forum_name_html_safe']
@@ -2008,8 +2120,9 @@  discard block
 block discarded – undo
2008 2120
 	// This allows sticking some HTML on the page output - useful for controls.
2009 2121
 	$context['insert_after_template'] = '';
2010 2122
 
2011
-	if (!isset($txt))
2012
-		$txt = array();
2123
+	if (!isset($txt)) {
2124
+			$txt = array();
2125
+	}
2013 2126
 
2014 2127
 	$simpleActions = array(
2015 2128
 		'findmember',
@@ -2055,9 +2168,10 @@  discard block
 block discarded – undo
2055 2168
 
2056 2169
 	// See if theres any extra param to check.
2057 2170
 	$requiresXML = false;
2058
-	foreach ($extraParams as $key => $extra)
2059
-		if (isset($_REQUEST[$extra]))
2171
+	foreach ($extraParams as $key => $extra) {
2172
+			if (isset($_REQUEST[$extra]))
2060 2173
 			$requiresXML = true;
2174
+	}
2061 2175
 
2062 2176
 	// Output is fully XML, so no need for the index template.
2063 2177
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2072,37 +2186,39 @@  discard block
 block discarded – undo
2072 2186
 	{
2073 2187
 		loadLanguage('index+Modifications');
2074 2188
 		$context['template_layers'] = array();
2075
-	}
2076
-
2077
-	else
2189
+	} else
2078 2190
 	{
2079 2191
 		// Custom templates to load, or just default?
2080
-		if (isset($settings['theme_templates']))
2081
-			$templates = explode(',', $settings['theme_templates']);
2082
-		else
2083
-			$templates = array('index');
2192
+		if (isset($settings['theme_templates'])) {
2193
+					$templates = explode(',', $settings['theme_templates']);
2194
+		} else {
2195
+					$templates = array('index');
2196
+		}
2084 2197
 
2085 2198
 		// Load each template...
2086
-		foreach ($templates as $template)
2087
-			loadTemplate($template);
2199
+		foreach ($templates as $template) {
2200
+					loadTemplate($template);
2201
+		}
2088 2202
 
2089 2203
 		// ...and attempt to load their associated language files.
2090 2204
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2091 2205
 		loadLanguage($required_files, '', false);
2092 2206
 
2093 2207
 		// Custom template layers?
2094
-		if (isset($settings['theme_layers']))
2095
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2096
-		else
2097
-			$context['template_layers'] = array('html', 'body');
2208
+		if (isset($settings['theme_layers'])) {
2209
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2210
+		} else {
2211
+					$context['template_layers'] = array('html', 'body');
2212
+		}
2098 2213
 	}
2099 2214
 
2100 2215
 	// Initialize the theme.
2101 2216
 	loadSubTemplate('init', 'ignore');
2102 2217
 
2103 2218
 	// Allow overriding the board wide time/number formats.
2104
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2105
-		$user_info['time_format'] = $txt['time_format'];
2219
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2220
+			$user_info['time_format'] = $txt['time_format'];
2221
+	}
2106 2222
 
2107 2223
 	// Set the character set from the template.
2108 2224
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2110,12 +2226,14 @@  discard block
 block discarded – undo
2110 2226
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2111 2227
 
2112 2228
 	// Guests may still need a name.
2113
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2114
-		$context['user']['name'] = $txt['guest_title'];
2229
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2230
+			$context['user']['name'] = $txt['guest_title'];
2231
+	}
2115 2232
 
2116 2233
 	// Any theme-related strings that need to be loaded?
2117
-	if (!empty($settings['require_theme_strings']))
2118
-		loadLanguage('ThemeStrings', '', false);
2234
+	if (!empty($settings['require_theme_strings'])) {
2235
+			loadLanguage('ThemeStrings', '', false);
2236
+	}
2119 2237
 
2120 2238
 	// Make a special URL for the language.
2121 2239
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2126,8 +2244,9 @@  discard block
 block discarded – undo
2126 2244
 	// Here is my luvly Responsive CSS
2127 2245
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2128 2246
 
2129
-	if ($context['right_to_left'])
2130
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2247
+	if ($context['right_to_left']) {
2248
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2249
+	}
2131 2250
 
2132 2251
 	// We allow theme variants, because we're cool.
2133 2252
 	$context['theme_variant'] = '';
@@ -2135,14 +2254,17 @@  discard block
 block discarded – undo
2135 2254
 	if (!empty($settings['theme_variants']))
2136 2255
 	{
2137 2256
 		// Overriding - for previews and that ilk.
2138
-		if (!empty($_REQUEST['variant']))
2139
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2257
+		if (!empty($_REQUEST['variant'])) {
2258
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2259
+		}
2140 2260
 		// User selection?
2141
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2142
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2261
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2262
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2263
+		}
2143 2264
 		// If not a user variant, select the default.
2144
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2145
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2265
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2266
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2267
+		}
2146 2268
 
2147 2269
 		// Do this to keep things easier in the templates.
2148 2270
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2151,20 +2273,23 @@  discard block
 block discarded – undo
2151 2273
 		if (!empty($context['theme_variant']))
2152 2274
 		{
2153 2275
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2154
-			if ($context['right_to_left'])
2155
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2276
+			if ($context['right_to_left']) {
2277
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2278
+			}
2156 2279
 		}
2157 2280
 	}
2158 2281
 
2159 2282
 	// Let's be compatible with old themes!
2160
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2161
-		$context['template_layers'] = array('main');
2283
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2284
+			$context['template_layers'] = array('main');
2285
+	}
2162 2286
 
2163 2287
 	$context['tabindex'] = 1;
2164 2288
 
2165 2289
 	// Compatibility.
2166
-	if (!isset($settings['theme_version']))
2167
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2290
+	if (!isset($settings['theme_version'])) {
2291
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2292
+	}
2168 2293
 
2169 2294
 	// Default JS variables for use in every theme
2170 2295
 	$context['javascript_vars'] = array(
@@ -2183,18 +2308,18 @@  discard block
 block discarded – undo
2183 2308
 	);
2184 2309
 
2185 2310
 	// Add the JQuery library to the list of files to load.
2186
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2187
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2188
-
2189
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2190
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2191
-
2192
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2193
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2311
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2312
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2313
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2314
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2315
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2316
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2317
+	}
2194 2318
 
2195 2319
 	// Auto loading? template_javascript() will take care of the local half of this.
2196
-	else
2197
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2320
+	else {
2321
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2322
+	}
2198 2323
 
2199 2324
 	// Queue our JQuery plugins!
2200 2325
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2217,12 +2342,12 @@  discard block
 block discarded – undo
2217 2342
 			require_once($sourcedir . '/ScheduledTasks.php');
2218 2343
 
2219 2344
 			// What to do, what to do?!
2220
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2221
-				AutoTask();
2222
-			else
2223
-				ReduceMailQueue();
2224
-		}
2225
-		else
2345
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2346
+							AutoTask();
2347
+			} else {
2348
+							ReduceMailQueue();
2349
+			}
2350
+		} else
2226 2351
 		{
2227 2352
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2228 2353
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2273,8 +2398,9 @@  discard block
 block discarded – undo
2273 2398
 		foreach ($theme_includes as $include)
2274 2399
 		{
2275 2400
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2276
-			if (file_exists($include))
2277
-				require_once($include);
2401
+			if (file_exists($include)) {
2402
+							require_once($include);
2403
+			}
2278 2404
 		}
2279 2405
 	}
2280 2406
 
@@ -2304,16 +2430,19 @@  discard block
 block discarded – undo
2304 2430
 	// Do any style sheets first, cause we're easy with those.
2305 2431
 	if (!empty($style_sheets))
2306 2432
 	{
2307
-		if (!is_array($style_sheets))
2308
-			$style_sheets = array($style_sheets);
2433
+		if (!is_array($style_sheets)) {
2434
+					$style_sheets = array($style_sheets);
2435
+		}
2309 2436
 
2310
-		foreach ($style_sheets as $sheet)
2311
-			loadCSSFile($sheet . '.css', array(), $sheet);
2437
+		foreach ($style_sheets as $sheet) {
2438
+					loadCSSFile($sheet . '.css', array(), $sheet);
2439
+		}
2312 2440
 	}
2313 2441
 
2314 2442
 	// No template to load?
2315
-	if ($template_name === false)
2316
-		return true;
2443
+	if ($template_name === false) {
2444
+			return true;
2445
+	}
2317 2446
 
2318 2447
 	$loaded = false;
2319 2448
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2328,12 +2457,14 @@  discard block
 block discarded – undo
2328 2457
 
2329 2458
 	if ($loaded)
2330 2459
 	{
2331
-		if ($db_show_debug === true)
2332
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2460
+		if ($db_show_debug === true) {
2461
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2462
+		}
2333 2463
 
2334 2464
 		// If they have specified an initialization function for this template, go ahead and call it now.
2335
-		if (function_exists('template_' . $template_name . '_init'))
2336
-			call_user_func('template_' . $template_name . '_init');
2465
+		if (function_exists('template_' . $template_name . '_init')) {
2466
+					call_user_func('template_' . $template_name . '_init');
2467
+		}
2337 2468
 	}
2338 2469
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2339 2470
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2353,13 +2484,14 @@  discard block
 block discarded – undo
2353 2484
 		loadTemplate($template_name);
2354 2485
 	}
2355 2486
 	// Cause an error otherwise.
2356
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2357
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2358
-	elseif ($fatal)
2359
-		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'));
2360
-	else
2361
-		return false;
2362
-}
2487
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2488
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2489
+	} elseif ($fatal) {
2490
+			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'));
2491
+	} else {
2492
+			return false;
2493
+	}
2494
+	}
2363 2495
 
2364 2496
 /**
2365 2497
  * Load a sub-template.
@@ -2377,17 +2509,19 @@  discard block
 block discarded – undo
2377 2509
 {
2378 2510
 	global $context, $txt, $db_show_debug;
2379 2511
 
2380
-	if ($db_show_debug === true)
2381
-		$context['debug']['sub_templates'][] = $sub_template_name;
2512
+	if ($db_show_debug === true) {
2513
+			$context['debug']['sub_templates'][] = $sub_template_name;
2514
+	}
2382 2515
 
2383 2516
 	// Figure out what the template function is named.
2384 2517
 	$theme_function = 'template_' . $sub_template_name;
2385
-	if (function_exists($theme_function))
2386
-		$theme_function();
2387
-	elseif ($fatal === false)
2388
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2389
-	elseif ($fatal !== 'ignore')
2390
-		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'));
2518
+	if (function_exists($theme_function)) {
2519
+			$theme_function();
2520
+	} elseif ($fatal === false) {
2521
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2522
+	} elseif ($fatal !== 'ignore') {
2523
+			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'));
2524
+	}
2391 2525
 
2392 2526
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2393 2527
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2424,8 +2558,9 @@  discard block
 block discarded – undo
2424 2558
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2425 2559
 
2426 2560
 	// If this is an external file, automatically set this to false.
2427
-	if (!empty($params['external']))
2428
-		$params['minimize'] = false;
2561
+	if (!empty($params['external'])) {
2562
+			$params['minimize'] = false;
2563
+	}
2429 2564
 
2430 2565
 	// Account for shorthand like admin.css?alp21 filenames
2431 2566
 	$has_seed = strpos($fileName, '.css?');
@@ -2442,13 +2577,10 @@  discard block
 block discarded – undo
2442 2577
 			{
2443 2578
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2444 2579
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2580
+			} else {
2581
+							$fileUrl = false;
2445 2582
 			}
2446
-
2447
-			else
2448
-				$fileUrl = false;
2449
-		}
2450
-
2451
-		else
2583
+		} else
2452 2584
 		{
2453 2585
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2454 2586
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2463,12 +2595,14 @@  discard block
 block discarded – undo
2463 2595
 	}
2464 2596
 
2465 2597
 	// Add it to the array for use in the template
2466
-	if (!empty($fileName))
2467
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2598
+	if (!empty($fileName)) {
2599
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2600
+	}
2468 2601
 
2469
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2470
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2471
-}
2602
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2603
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2604
+	}
2605
+	}
2472 2606
 
2473 2607
 /**
2474 2608
  * Add a block of inline css code to be executed later
@@ -2485,8 +2619,9 @@  discard block
 block discarded – undo
2485 2619
 	global $context;
2486 2620
 
2487 2621
 	// Gotta add something...
2488
-	if (empty($css))
2489
-		return false;
2622
+	if (empty($css)) {
2623
+			return false;
2624
+	}
2490 2625
 
2491 2626
 	$context['css_header'][] = $css;
2492 2627
 }
@@ -2521,8 +2656,9 @@  discard block
 block discarded – undo
2521 2656
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2522 2657
 
2523 2658
 	// If this is an external file, automatically set this to false.
2524
-	if (!empty($params['external']))
2525
-		$params['minimize'] = false;
2659
+	if (!empty($params['external'])) {
2660
+			$params['minimize'] = false;
2661
+	}
2526 2662
 
2527 2663
 	// Account for shorthand like admin.js?alp21 filenames
2528 2664
 	$has_seed = strpos($fileName, '.js?');
@@ -2539,16 +2675,12 @@  discard block
 block discarded – undo
2539 2675
 			{
2540 2676
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2541 2677
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2542
-			}
2543
-
2544
-			else
2678
+			} else
2545 2679
 			{
2546 2680
 				$fileUrl = false;
2547 2681
 				$filePath = false;
2548 2682
 			}
2549
-		}
2550
-
2551
-		else
2683
+		} else
2552 2684
 		{
2553 2685
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2554 2686
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2563,9 +2695,10 @@  discard block
 block discarded – undo
2563 2695
 	}
2564 2696
 
2565 2697
 	// Add it to the array for use in the template
2566
-	if (!empty($fileName))
2567
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2568
-}
2698
+	if (!empty($fileName)) {
2699
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2700
+	}
2701
+	}
2569 2702
 
2570 2703
 /**
2571 2704
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2579,9 +2712,10 @@  discard block
 block discarded – undo
2579 2712
 {
2580 2713
 	global $context;
2581 2714
 
2582
-	if (!empty($key) && (!empty($value) || $value === '0'))
2583
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2584
-}
2715
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2716
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2717
+	}
2718
+	}
2585 2719
 
2586 2720
 /**
2587 2721
  * Add a block of inline Javascript code to be executed later
@@ -2598,8 +2732,9 @@  discard block
 block discarded – undo
2598 2732
 {
2599 2733
 	global $context;
2600 2734
 
2601
-	if (empty($javascript))
2602
-		return false;
2735
+	if (empty($javascript)) {
2736
+			return false;
2737
+	}
2603 2738
 
2604 2739
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2605 2740
 }
@@ -2620,15 +2755,18 @@  discard block
 block discarded – undo
2620 2755
 	static $already_loaded = array();
2621 2756
 
2622 2757
 	// Default to the user's language.
2623
-	if ($lang == '')
2624
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2758
+	if ($lang == '') {
2759
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2760
+	}
2625 2761
 
2626 2762
 	// Do we want the English version of language file as fallback?
2627
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2628
-		loadLanguage($template_name, 'english', false);
2763
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2764
+			loadLanguage($template_name, 'english', false);
2765
+	}
2629 2766
 
2630
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2631
-		return $lang;
2767
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2768
+			return $lang;
2769
+	}
2632 2770
 
2633 2771
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2634 2772
 	if (empty($settings['default_theme_dir']))
@@ -2639,8 +2777,9 @@  discard block
 block discarded – undo
2639 2777
 
2640 2778
 	// What theme are we in?
2641 2779
 	$theme_name = basename($settings['theme_url']);
2642
-	if (empty($theme_name))
2643
-		$theme_name = 'unknown';
2780
+	if (empty($theme_name)) {
2781
+			$theme_name = 'unknown';
2782
+	}
2644 2783
 
2645 2784
 	// For each file open it up and write it out!
2646 2785
 	foreach (explode('+', $template_name) as $template)
@@ -2682,8 +2821,9 @@  discard block
 block discarded – undo
2682 2821
 				$found = true;
2683 2822
 
2684 2823
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2685
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2686
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2824
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2825
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2826
+				}
2687 2827
 
2688 2828
 				break;
2689 2829
 			}
@@ -2723,8 +2863,9 @@  discard block
 block discarded – undo
2723 2863
 	}
2724 2864
 
2725 2865
 	// Keep track of what we're up to soldier.
2726
-	if ($db_show_debug === true)
2727
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2866
+	if ($db_show_debug === true) {
2867
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2868
+	}
2728 2869
 
2729 2870
 	// Remember what we have loaded, and in which language.
2730 2871
 	$already_loaded[$template_name] = $lang;
@@ -2770,8 +2911,9 @@  discard block
 block discarded – undo
2770 2911
 				)
2771 2912
 			);
2772 2913
 			// In the EXTREMELY unlikely event this happens, give an error message.
2773
-			if ($smcFunc['db_num_rows']($result) == 0)
2774
-				fatal_lang_error('parent_not_found', 'critical');
2914
+			if ($smcFunc['db_num_rows']($result) == 0) {
2915
+							fatal_lang_error('parent_not_found', 'critical');
2916
+			}
2775 2917
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2776 2918
 			{
2777 2919
 				if (!isset($boards[$row['id_board']]))
@@ -2788,8 +2930,8 @@  discard block
 block discarded – undo
2788 2930
 					);
2789 2931
 				}
2790 2932
 				// If a moderator exists for this board, add that moderator for all children too.
2791
-				if (!empty($row['id_moderator']))
2792
-					foreach ($boards as $id => $dummy)
2933
+				if (!empty($row['id_moderator'])) {
2934
+									foreach ($boards as $id => $dummy)
2793 2935
 					{
2794 2936
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2795 2937
 							'id' => $row['id_moderator'],
@@ -2797,11 +2939,12 @@  discard block
 block discarded – undo
2797 2939
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2798 2940
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2799 2941
 						);
2942
+				}
2800 2943
 					}
2801 2944
 
2802 2945
 				// If a moderator group exists for this board, add that moderator group for all children too
2803
-				if (!empty($row['id_moderator_group']))
2804
-					foreach ($boards as $id => $dummy)
2946
+				if (!empty($row['id_moderator_group'])) {
2947
+									foreach ($boards as $id => $dummy)
2805 2948
 					{
2806 2949
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2807 2950
 							'id' => $row['id_moderator_group'],
@@ -2809,6 +2952,7 @@  discard block
 block discarded – undo
2809 2952
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2810 2953
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2811 2954
 						);
2955
+				}
2812 2956
 					}
2813 2957
 			}
2814 2958
 			$smcFunc['db_free_result']($result);
@@ -2835,23 +2979,27 @@  discard block
 block discarded – undo
2835 2979
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2836 2980
 	{
2837 2981
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2838
-		if (empty($smcFunc['ucwords']))
2839
-			reloadSettings();
2982
+		if (empty($smcFunc['ucwords'])) {
2983
+					reloadSettings();
2984
+		}
2840 2985
 
2841 2986
 		// If we don't have our theme information yet, let's get it.
2842
-		if (empty($settings['default_theme_dir']))
2843
-			loadTheme(0, false);
2987
+		if (empty($settings['default_theme_dir'])) {
2988
+					loadTheme(0, false);
2989
+		}
2844 2990
 
2845 2991
 		// Default language directories to try.
2846 2992
 		$language_directories = array(
2847 2993
 			$settings['default_theme_dir'] . '/languages',
2848 2994
 		);
2849
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2850
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2995
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2996
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2997
+		}
2851 2998
 
2852 2999
 		// We possibly have a base theme directory.
2853
-		if (!empty($settings['base_theme_dir']))
2854
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3000
+		if (!empty($settings['base_theme_dir'])) {
3001
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3002
+		}
2855 3003
 
2856 3004
 		// Remove any duplicates.
2857 3005
 		$language_directories = array_unique($language_directories);
@@ -2865,20 +3013,21 @@  discard block
 block discarded – undo
2865 3013
 		foreach ($language_directories as $language_dir)
2866 3014
 		{
2867 3015
 			// Can't look in here... doesn't exist!
2868
-			if (!file_exists($language_dir))
2869
-				continue;
3016
+			if (!file_exists($language_dir)) {
3017
+							continue;
3018
+			}
2870 3019
 
2871 3020
 			$dir = dir($language_dir);
2872 3021
 			while ($entry = $dir->read())
2873 3022
 			{
2874 3023
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2875
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2876
-					continue;
2877
-
2878
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2879
-					$langName = $langList[$matches[1]];
3024
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3025
+									continue;
3026
+				}
2880 3027
 
2881
-				else
3028
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3029
+									$langName = $langList[$matches[1]];
3030
+				} else
2882 3031
 				{
2883 3032
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2884 3033
 
@@ -2919,12 +3068,14 @@  discard block
 block discarded – undo
2919 3068
 		}
2920 3069
 
2921 3070
 		// Do we need to store the lang list?
2922
-		if (empty($langList))
2923
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3071
+		if (empty($langList)) {
3072
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3073
+		}
2924 3074
 
2925 3075
 		// Let's cash in on this deal.
2926
-		if (!empty($modSettings['cache_enable']))
2927
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3076
+		if (!empty($modSettings['cache_enable'])) {
3077
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3078
+		}
2928 3079
 	}
2929 3080
 
2930 3081
 	return $context['languages'];
@@ -2947,8 +3098,9 @@  discard block
 block discarded – undo
2947 3098
 	global $modSettings, $options, $txt;
2948 3099
 	static $censor_vulgar = null, $censor_proper;
2949 3100
 
2950
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2951
-		return $text;
3101
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3102
+			return $text;
3103
+	}
2952 3104
 
2953 3105
 	// If they haven't yet been loaded, load them.
2954 3106
 	if ($censor_vulgar == null)
@@ -2976,9 +3128,9 @@  discard block
 block discarded – undo
2976 3128
 	{
2977 3129
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2978 3130
 		$text = $func($censor_vulgar, $censor_proper, $text);
3131
+	} else {
3132
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2979 3133
 	}
2980
-	else
2981
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2982 3134
 
2983 3135
 	return $text;
2984 3136
 }
@@ -3004,38 +3156,42 @@  discard block
 block discarded – undo
3004 3156
 	@ini_set('track_errors', '1');
3005 3157
 
3006 3158
 	// Don't include the file more than once, if $once is true.
3007
-	if ($once && in_array($filename, $templates))
3008
-		return;
3159
+	if ($once && in_array($filename, $templates)) {
3160
+			return;
3161
+	}
3009 3162
 	// Add this file to the include list, whether $once is true or not.
3010
-	else
3011
-		$templates[] = $filename;
3163
+	else {
3164
+			$templates[] = $filename;
3165
+	}
3012 3166
 
3013 3167
 	// Are we going to use eval?
3014 3168
 	if (empty($modSettings['disableTemplateEval']))
3015 3169
 	{
3016 3170
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3017 3171
 		$settings['current_include_filename'] = $filename;
3018
-	}
3019
-	else
3172
+	} else
3020 3173
 	{
3021 3174
 		$file_found = file_exists($filename);
3022 3175
 
3023
-		if ($once && $file_found)
3024
-			require_once($filename);
3025
-		elseif ($file_found)
3026
-			require($filename);
3176
+		if ($once && $file_found) {
3177
+					require_once($filename);
3178
+		} elseif ($file_found) {
3179
+					require($filename);
3180
+		}
3027 3181
 	}
3028 3182
 
3029 3183
 	if ($file_found !== true)
3030 3184
 	{
3031 3185
 		ob_end_clean();
3032
-		if (!empty($modSettings['enableCompressedOutput']))
3033
-			@ob_start('ob_gzhandler');
3034
-		else
3035
-			ob_start();
3186
+		if (!empty($modSettings['enableCompressedOutput'])) {
3187
+					@ob_start('ob_gzhandler');
3188
+		} else {
3189
+					ob_start();
3190
+		}
3036 3191
 
3037
-		if (isset($_GET['debug']))
3038
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3192
+		if (isset($_GET['debug'])) {
3193
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3194
+		}
3039 3195
 
3040 3196
 		// Don't cache error pages!!
3041 3197
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3054,12 +3210,13 @@  discard block
 block discarded – undo
3054 3210
 		echo '<!DOCTYPE html>
3055 3211
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3056 3212
 	<head>';
3057
-		if (isset($context['character_set']))
3058
-			echo '
3213
+		if (isset($context['character_set'])) {
3214
+					echo '
3059 3215
 		<meta charset="', $context['character_set'], '">';
3216
+		}
3060 3217
 
3061
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3062
-			echo '
3218
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3219
+					echo '
3063 3220
 		<title>', $mtitle, '</title>
3064 3221
 	</head>
3065 3222
 	<body>
@@ -3067,8 +3224,8 @@  discard block
 block discarded – undo
3067 3224
 		', $mmessage, '
3068 3225
 	</body>
3069 3226
 </html>';
3070
-		elseif (!allowedTo('admin_forum'))
3071
-			echo '
3227
+		} elseif (!allowedTo('admin_forum')) {
3228
+					echo '
3072 3229
 		<title>', $txt['template_parse_error'], '</title>
3073 3230
 	</head>
3074 3231
 	<body>
@@ -3076,16 +3233,18 @@  discard block
 block discarded – undo
3076 3233
 		', $txt['template_parse_error_message'], '
3077 3234
 	</body>
3078 3235
 </html>';
3079
-		else
3236
+		} else
3080 3237
 		{
3081 3238
 			require_once($sourcedir . '/Subs-Package.php');
3082 3239
 
3083 3240
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3084 3241
 			$error_array = error_get_last();
3085
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3086
-				$error = $error_array['message'];
3087
-			if (empty($error))
3088
-				$error = $txt['template_parse_errmsg'];
3242
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3243
+							$error = $error_array['message'];
3244
+			}
3245
+			if (empty($error)) {
3246
+							$error = $txt['template_parse_errmsg'];
3247
+			}
3089 3248
 
3090 3249
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3091 3250
 
@@ -3096,11 +3255,12 @@  discard block
 block discarded – undo
3096 3255
 		<h3>', $txt['template_parse_error'], '</h3>
3097 3256
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3098 3257
 
3099
-			if (!empty($error))
3100
-				echo '
3258
+			if (!empty($error)) {
3259
+							echo '
3101 3260
 		<hr>
3102 3261
 
3103 3262
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3263
+			}
3104 3264
 
3105 3265
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3106 3266
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3110,10 +3270,11 @@  discard block
 block discarded – undo
3110 3270
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3111 3271
 
3112 3272
 				// Fix the PHP code stuff...
3113
-				if (!isBrowser('gecko'))
3114
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3115
-				else
3116
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3273
+				if (!isBrowser('gecko')) {
3274
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3275
+				} else {
3276
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3277
+				}
3117 3278
 
3118 3279
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3119 3280
 				$j = -1;
@@ -3121,8 +3282,9 @@  discard block
 block discarded – undo
3121 3282
 				{
3122 3283
 					$j++;
3123 3284
 
3124
-					if (substr_count($line, '<br>') == 0)
3125
-						continue;
3285
+					if (substr_count($line, '<br>') == 0) {
3286
+											continue;
3287
+					}
3126 3288
 
3127 3289
 					$n = substr_count($line, '<br>');
3128 3290
 					for ($i = 0; $i < $n; $i++)
@@ -3141,38 +3303,42 @@  discard block
 block discarded – undo
3141 3303
 				// Figure out what the color coding was before...
3142 3304
 				$line = max($match[1] - 9, 1);
3143 3305
 				$last_line = '';
3144
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3145
-					if (strpos($data2[$line2], '<') !== false)
3306
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3307
+									if (strpos($data2[$line2], '<') !== false)
3146 3308
 					{
3147 3309
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3148 3310
 							$last_line = $color_match[1];
3311
+				}
3149 3312
 						break;
3150 3313
 					}
3151 3314
 
3152 3315
 				// Show the relevant lines...
3153 3316
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3154 3317
 				{
3155
-					if ($line == $match[1])
3156
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3318
+					if ($line == $match[1]) {
3319
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3320
+					}
3157 3321
 
3158 3322
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3159
-					if (isset($data2[$line]) && $data2[$line] != '')
3160
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3323
+					if (isset($data2[$line]) && $data2[$line] != '') {
3324
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3325
+					}
3161 3326
 
3162 3327
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3163 3328
 					{
3164 3329
 						$last_line = $color_match[1];
3165 3330
 						echo '</', substr($last_line, 1, 4), '>';
3331
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3332
+											$last_line = '';
3333
+					} elseif ($last_line != '' && $data2[$line] != '') {
3334
+											echo '</', substr($last_line, 1, 4), '>';
3166 3335
 					}
3167
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3168
-						$last_line = '';
3169
-					elseif ($last_line != '' && $data2[$line] != '')
3170
-						echo '</', substr($last_line, 1, 4), '>';
3171 3336
 
3172
-					if ($line == $match[1])
3173
-						echo '</pre></div><pre style="margin: 0;">';
3174
-					else
3175
-						echo "\n";
3337
+					if ($line == $match[1]) {
3338
+											echo '</pre></div><pre style="margin: 0;">';
3339
+					} else {
3340
+											echo "\n";
3341
+					}
3176 3342
 				}
3177 3343
 
3178 3344
 				echo '</pre></div>';
@@ -3196,8 +3362,9 @@  discard block
 block discarded – undo
3196 3362
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3197 3363
 
3198 3364
 	// Figure out what type of database we are using.
3199
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3200
-		$db_type = 'mysql';
3365
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3366
+			$db_type = 'mysql';
3367
+	}
3201 3368
 
3202 3369
 	// Load the file for the database.
3203 3370
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3205,8 +3372,9 @@  discard block
 block discarded – undo
3205 3372
 	$db_options = array();
3206 3373
 
3207 3374
 	// Add in the port if needed
3208
-	if (!empty($db_port))
3209
-		$db_options['port'] = $db_port;
3375
+	if (!empty($db_port)) {
3376
+			$db_options['port'] = $db_port;
3377
+	}
3210 3378
 
3211 3379
 	// 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.
3212 3380
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3225,13 +3393,15 @@  discard block
 block discarded – undo
3225 3393
 	}
3226 3394
 
3227 3395
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3228
-	if (!$db_connection)
3229
-		display_db_error();
3396
+	if (!$db_connection) {
3397
+			display_db_error();
3398
+	}
3230 3399
 
3231 3400
 	// If in SSI mode fix up the prefix.
3232
-	if (SMF == 'SSI')
3233
-		db_fix_prefix($db_prefix, $db_name);
3234
-}
3401
+	if (SMF == 'SSI') {
3402
+			db_fix_prefix($db_prefix, $db_name);
3403
+	}
3404
+	}
3235 3405
 
3236 3406
 /**
3237 3407
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3245,10 +3415,11 @@  discard block
 block discarded – undo
3245 3415
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3246 3416
 
3247 3417
 	// Not overriding this and we have a cacheAPI, send it back.
3248
-	if (empty($overrideCache) && is_object($cacheAPI))
3249
-		return $cacheAPI;
3250
-	elseif (is_null($cacheAPI))
3251
-		$cacheAPI = false;
3418
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3419
+			return $cacheAPI;
3420
+	} elseif (is_null($cacheAPI)) {
3421
+			$cacheAPI = false;
3422
+	}
3252 3423
 
3253 3424
 	// Make sure our class is in session.
3254 3425
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3269,8 +3440,9 @@  discard block
 block discarded – undo
3269 3440
 		if (!$testAPI->isSupported())
3270 3441
 		{
3271 3442
 			// Can we save ourselves?
3272
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3273
-				return loadCacheAccelerator(null, false);
3443
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3444
+							return loadCacheAccelerator(null, false);
3445
+			}
3274 3446
 			return false;
3275 3447
 		}
3276 3448
 
@@ -3282,9 +3454,9 @@  discard block
 block discarded – undo
3282 3454
 		{
3283 3455
 			$cacheAPI = $testAPI;
3284 3456
 			return $cacheAPI;
3457
+		} else {
3458
+					return $testAPI;
3285 3459
 		}
3286
-		else
3287
-			return $testAPI;
3288 3460
 	}
3289 3461
 }
3290 3462
 
@@ -3304,8 +3476,9 @@  discard block
 block discarded – undo
3304 3476
 
3305 3477
 	// @todo Why are we doing this if caching is disabled?
3306 3478
 
3307
-	if (function_exists('call_integration_hook'))
3308
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3479
+	if (function_exists('call_integration_hook')) {
3480
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3481
+	}
3309 3482
 
3310 3483
 	/* Refresh the cache if either:
3311 3484
 		1. Caching is disabled.
@@ -3319,16 +3492,19 @@  discard block
 block discarded – undo
3319 3492
 		require_once($sourcedir . '/' . $file);
3320 3493
 		$cache_block = call_user_func_array($function, $params);
3321 3494
 
3322
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3323
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3495
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3496
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3497
+		}
3324 3498
 	}
3325 3499
 
3326 3500
 	// Some cached data may need a freshening up after retrieval.
3327
-	if (!empty($cache_block['post_retri_eval']))
3328
-		eval($cache_block['post_retri_eval']);
3501
+	if (!empty($cache_block['post_retri_eval'])) {
3502
+			eval($cache_block['post_retri_eval']);
3503
+	}
3329 3504
 
3330
-	if (function_exists('call_integration_hook'))
3331
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3505
+	if (function_exists('call_integration_hook')) {
3506
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3507
+	}
3332 3508
 
3333 3509
 	return $cache_block['data'];
3334 3510
 }
@@ -3355,8 +3531,9 @@  discard block
 block discarded – undo
3355 3531
 	global $smcFunc, $cache_enable, $cacheAPI;
3356 3532
 	global $cache_hits, $cache_count, $db_show_debug;
3357 3533
 
3358
-	if (empty($cache_enable) || empty($cacheAPI))
3359
-		return;
3534
+	if (empty($cache_enable) || empty($cacheAPI)) {
3535
+			return;
3536
+	}
3360 3537
 
3361 3538
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3362 3539
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3369,12 +3546,14 @@  discard block
 block discarded – undo
3369 3546
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3370 3547
 	$cacheAPI->putData($key, $value, $ttl);
3371 3548
 
3372
-	if (function_exists('call_integration_hook'))
3373
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3549
+	if (function_exists('call_integration_hook')) {
3550
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3551
+	}
3374 3552
 
3375
-	if (isset($db_show_debug) && $db_show_debug === true)
3376
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3377
-}
3553
+	if (isset($db_show_debug) && $db_show_debug === true) {
3554
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3555
+	}
3556
+	}
3378 3557
 
3379 3558
 /**
3380 3559
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3390,8 +3569,9 @@  discard block
 block discarded – undo
3390 3569
 	global $smcFunc, $cache_enable, $cacheAPI;
3391 3570
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3392 3571
 
3393
-	if (empty($cache_enable) || empty($cacheAPI))
3394
-		return;
3572
+	if (empty($cache_enable) || empty($cacheAPI)) {
3573
+			return;
3574
+	}
3395 3575
 
3396 3576
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3397 3577
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3411,16 +3591,18 @@  discard block
 block discarded – undo
3411 3591
 
3412 3592
 		if (empty($value))
3413 3593
 		{
3414
-			if (!is_array($cache_misses))
3415
-				$cache_misses = array();
3594
+			if (!is_array($cache_misses)) {
3595
+							$cache_misses = array();
3596
+			}
3416 3597
 
3417 3598
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3418 3599
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3419 3600
 		}
3420 3601
 	}
3421 3602
 
3422
-	if (function_exists('call_integration_hook') && isset($value))
3423
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3603
+	if (function_exists('call_integration_hook') && isset($value)) {
3604
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3605
+	}
3424 3606
 
3425 3607
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3426 3608
 }
@@ -3442,8 +3624,9 @@  discard block
 block discarded – undo
3442 3624
 	global $cacheAPI;
3443 3625
 
3444 3626
 	// If we can't get to the API, can't do this.
3445
-	if (empty($cacheAPI))
3446
-		return;
3627
+	if (empty($cacheAPI)) {
3628
+			return;
3629
+	}
3447 3630
 
3448 3631
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3449 3632
 	$cacheAPI->cleanCache($type);
@@ -3468,8 +3651,9 @@  discard block
 block discarded – undo
3468 3651
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3469 3652
 
3470 3653
 	// Come on!
3471
-	if (empty($data))
3472
-		return array();
3654
+	if (empty($data)) {
3655
+			return array();
3656
+	}
3473 3657
 
3474 3658
 	// Set a nice default var.
3475 3659
 	$image = '';
@@ -3477,11 +3661,11 @@  discard block
 block discarded – undo
3477 3661
 	// Gravatar has been set as mandatory!
3478 3662
 	if (!empty($modSettings['gravatarOverride']))
3479 3663
 	{
3480
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3481
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3482
-
3483
-		else if (!empty($data['email']))
3484
-			$image = get_gravatar_url($data['email']);
3664
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3665
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3666
+		} else if (!empty($data['email'])) {
3667
+					$image = get_gravatar_url($data['email']);
3668
+		}
3485 3669
 	}
3486 3670
 
3487 3671
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3493,54 +3677,60 @@  discard block
 block discarded – undo
3493 3677
 			// Gravatar.
3494 3678
 			if (stristr($data['avatar'], 'gravatar://'))
3495 3679
 			{
3496
-				if ($data['avatar'] == 'gravatar://')
3497
-					$image = get_gravatar_url($data['email']);
3498
-
3499
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3500
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3680
+				if ($data['avatar'] == 'gravatar://') {
3681
+									$image = get_gravatar_url($data['email']);
3682
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3683
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3684
+				}
3501 3685
 			}
3502 3686
 
3503 3687
 			// External url.
3504 3688
 			else
3505 3689
 			{
3506 3690
 				// Using ssl?
3507
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3508
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3691
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3692
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3693
+				}
3509 3694
 
3510 3695
 				// Just a plain external url.
3511
-				else
3512
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3696
+				else {
3697
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3698
+				}
3513 3699
 			}
3514 3700
 		}
3515 3701
 
3516 3702
 		// Perhaps this user has an attachment as avatar...
3517
-		else if (!empty($data['filename']))
3518
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3703
+		else if (!empty($data['filename'])) {
3704
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3705
+		}
3519 3706
 
3520 3707
 		// Right... no avatar... use our default image.
3521
-		else
3522
-			$image = $modSettings['avatar_url'] . '/default.png';
3708
+		else {
3709
+					$image = $modSettings['avatar_url'] . '/default.png';
3710
+		}
3523 3711
 	}
3524 3712
 
3525 3713
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3526 3714
 
3527 3715
 	// 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.
3528
-	if (!empty($image))
3529
-		return array(
3716
+	if (!empty($image)) {
3717
+			return array(
3530 3718
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3531 3719
 			'image' => '<img class="avatar" src="' . $image . '" />',
3532 3720
 			'href' => $image,
3533 3721
 			'url' => $image,
3534 3722
 		);
3723
+	}
3535 3724
 
3536 3725
 	// Fallback to make life easier for everyone...
3537
-	else
3538
-		return array(
3726
+	else {
3727
+			return array(
3539 3728
 			'name' => '',
3540 3729
 			'image' => '',
3541 3730
 			'href' => '',
3542 3731
 			'url' => '',
3543 3732
 		);
3544
-}
3733
+	}
3734
+	}
3545 3735
 
3546 3736
 ?>
3547 3737
\ No newline at end of file
Please login to merge, or discard this patch.