Completed
Push — release-2.1 ( 11eb43...b61572 )
by Mathias
07:44
created
Sources/Subs-Auth.php 1 patch
Braces   +160 added lines, -115 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
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -43,8 +44,9 @@  discard block
 block discarded – undo
43 44
 		$array = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
44 45
 
45 46
 		// Legacy format
46
-		if (is_null($array))
47
-			$array = safe_unserialize($_COOKIE[$cookiename]);
47
+		if (is_null($array)) {
48
+					$array = safe_unserialize($_COOKIE[$cookiename]);
49
+		}
48 50
 
49 51
 		// Out with the old, in with the new!
50 52
 		if (isset($array[3]) && $array[3] != $cookie_state)
@@ -62,8 +64,9 @@  discard block
 block discarded – undo
62 64
 	smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
63 65
 
64 66
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
65
-	if (empty($id) && !empty($modSettings['globalCookies']))
66
-		smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
67
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
68
+			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
69
+	}
67 70
 
68 71
 	// Any alias URLs?  This is mainly for use with frames, etc.
69 72
 	if (!empty($modSettings['forum_alias_urls']))
@@ -79,8 +82,9 @@  discard block
 block discarded – undo
79 82
 
80 83
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
81 84
 
82
-			if ($cookie_url[0] == '')
83
-				$cookie_url[0] = strtok($alias, '/');
85
+			if ($cookie_url[0] == '') {
86
+							$cookie_url[0] = strtok($alias, '/');
87
+			}
84 88
 
85 89
 			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
86 90
 		}
@@ -126,8 +130,9 @@  discard block
 block discarded – undo
126 130
 	$identifier = $cookiename . '_tfa';
127 131
 	$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
128 132
 
129
-	if ($preserve)
130
-		$cookie_length = 81600 * 30;
133
+	if ($preserve) {
134
+			$cookie_length = 81600 * 30;
135
+	}
131 136
 
132 137
 	// Get the data and path to set it on.
133 138
 	$data = $smcFunc['json_encode'](empty($id) ? array(0, '', 0, $cookie_state, false) : array($id, $secret, time() + $cookie_length, $cookie_state, $preserve));
@@ -137,8 +142,9 @@  discard block
 block discarded – undo
137 142
 	smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
138 143
 
139 144
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
140
-	if (empty($id) && !empty($modSettings['globalCookies']))
141
-		smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
145
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
146
+			smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
147
+	}
142 148
 
143 149
 	$_COOKIE[$identifier] = $data;
144 150
 }
@@ -160,23 +166,28 @@  discard block
 block discarded – undo
160 166
 	$parsed_url = parse_url($boardurl);
161 167
 
162 168
 	// Is local cookies off?
163
-	if (empty($parsed_url['path']) || !$local)
164
-		$parsed_url['path'] = '';
169
+	if (empty($parsed_url['path']) || !$local) {
170
+			$parsed_url['path'] = '';
171
+	}
165 172
 
166
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
167
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
173
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
174
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
175
+	}
168 176
 
169 177
 	// Globalize cookies across domains (filter out IP-addresses)?
170
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
171
-		$parsed_url['host'] = '.' . $parts[1];
178
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
179
+			$parsed_url['host'] = '.' . $parts[1];
180
+	}
172 181
 
173 182
 	// We shouldn't use a host at all if both options are off.
174
-	elseif (!$local && !$global)
175
-		$parsed_url['host'] = '';
183
+	elseif (!$local && !$global) {
184
+			$parsed_url['host'] = '';
185
+	}
176 186
 
177 187
 	// The host also shouldn't be set if there aren't any dots in it.
178
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
179
-		$parsed_url['host'] = '';
188
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
189
+			$parsed_url['host'] = '';
190
+	}
180 191
 
181 192
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
182 193
 }
@@ -195,8 +206,9 @@  discard block
 block discarded – undo
195 206
 	createToken('login');
196 207
 
197 208
 	// Never redirect to an attachment
198
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
199
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
209
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
210
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
211
+	}
200 212
 
201 213
 	$context['sub_template'] = 'kick_guest';
202 214
 	$context['page_title'] = $txt['login'];
@@ -251,10 +263,12 @@  discard block
 block discarded – undo
251 263
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
252 264
 		log_error($txt['security_wrong'], 'critical');
253 265
 
254
-		if (isset($_POST[$type . '_hash_pass']))
255
-			unset($_POST[$type . '_hash_pass']);
256
-		if (isset($_POST[$type . '_pass']))
257
-			unset($_POST[$type . '_pass']);
266
+		if (isset($_POST[$type . '_hash_pass'])) {
267
+					unset($_POST[$type . '_hash_pass']);
268
+		}
269
+		if (isset($_POST[$type . '_pass'])) {
270
+					unset($_POST[$type . '_pass']);
271
+		}
258 272
 
259 273
 		$context['incorrect_password'] = true;
260 274
 	}
@@ -267,15 +281,17 @@  discard block
 block discarded – undo
267 281
 
268 282
 	// Now go through $_POST.  Make sure the session hash is sent.
269 283
 	$_POST[$context['session_var']] = $context['session_id'];
270
-	foreach ($_POST as $k => $v)
271
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
284
+	foreach ($_POST as $k => $v) {
285
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
286
+	}
272 287
 
273 288
 	// Now we'll use the admin_login sub template of the Login template.
274 289
 	$context['sub_template'] = 'admin_login';
275 290
 
276 291
 	// And title the page something like "Login".
277
-	if (!isset($context['page_title']))
278
-		$context['page_title'] = $txt['login'];
292
+	if (!isset($context['page_title'])) {
293
+			$context['page_title'] = $txt['login'];
294
+	}
279 295
 
280 296
 	// The type of action.
281 297
 	$context['sessionCheckType'] = $type;
@@ -298,14 +314,15 @@  discard block
 block discarded – undo
298 314
 {
299 315
 	global $smcFunc;
300 316
 
301
-	if (!is_array($v))
302
-		return '
317
+	if (!is_array($v)) {
318
+			return '
303 319
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
304
-	else
320
+	} else
305 321
 	{
306 322
 		$ret = '';
307
-		foreach ($v as $k2 => $v2)
308
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
323
+		foreach ($v as $k2 => $v2) {
324
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
325
+		}
309 326
 
310 327
 		return $ret;
311 328
 	}
@@ -332,18 +349,20 @@  discard block
 block discarded – undo
332 349
 		foreach ($get as $k => $v)
333 350
 		{
334 351
 			// Only if it's not already in the $scripturl!
335
-			if (!isset($temp[$k]))
336
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
352
+			if (!isset($temp[$k])) {
353
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
354
+			}
337 355
 			// If it changed, put it out there, but with an ampersand.
338
-			elseif ($temp[$k] != $get[$k])
339
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
356
+			elseif ($temp[$k] != $get[$k]) {
357
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
358
+			}
340 359
 		}
341
-	}
342
-	else
360
+	} else
343 361
 	{
344 362
 		// Add up all the data from $_GET into get_data.
345
-		foreach ($get as $k => $v)
346
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
363
+		foreach ($get as $k => $v) {
364
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
365
+		}
347 366
 	}
348 367
 
349 368
 	$query_string = substr($query_string, 0, -1);
@@ -366,8 +385,9 @@  discard block
 block discarded – undo
366 385
 	global $scripturl, $user_info, $smcFunc;
367 386
 
368 387
 	// If it's not already an array, make it one.
369
-	if (!is_array($names))
370
-		$names = explode(',', $names);
388
+	if (!is_array($names)) {
389
+			$names = explode(',', $names);
390
+	}
371 391
 
372 392
 	$maybe_email = false;
373 393
 	foreach ($names as $i => $name)
@@ -378,10 +398,11 @@  discard block
 block discarded – undo
378 398
 		$maybe_email |= strpos($name, '@') !== false;
379 399
 
380 400
 		// Make it so standard wildcards will work. (* and ?)
381
-		if ($use_wildcards)
382
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
383
-		else
384
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
401
+		if ($use_wildcards) {
402
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
403
+		} else {
404
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
405
+		}
385 406
 	}
386 407
 
387 408
 	// What are we using to compare?
@@ -391,11 +412,12 @@  discard block
 block discarded – undo
391 412
 	$results = array();
392 413
 
393 414
 	// This ensures you can't search someones email address if you can't see it.
394
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
395
-		$email_condition = '
415
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
416
+			$email_condition = '
396 417
 			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
397
-	else
398
-		$email_condition = '';
418
+	} else {
419
+			$email_condition = '';
420
+	}
399 421
 
400 422
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
401 423
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -453,10 +475,11 @@  discard block
 block discarded – undo
453 475
 	$context['template_layers'] = array();
454 476
 	$context['sub_template'] = 'find_members';
455 477
 
456
-	if (isset($_REQUEST['search']))
457
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
458
-	else
459
-		$_REQUEST['start'] = 0;
478
+	if (isset($_REQUEST['search'])) {
479
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
480
+	} else {
481
+			$_REQUEST['start'] = 0;
482
+	}
460 483
 
461 484
 	// Allow the user to pass the input to be added to to the box.
462 485
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -497,10 +520,10 @@  discard block
 block discarded – undo
497 520
 		);
498 521
 
499 522
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
523
+	} else {
524
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
525
+	}
500 526
 	}
501
-	else
502
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
503
-}
504 527
 
505 528
 /**
506 529
  * Outputs each member name on its own line.
@@ -516,8 +539,9 @@  discard block
 block discarded – undo
516 539
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
517 540
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
518 541
 
519
-	if (function_exists('iconv'))
520
-		header('Content-Type: text/plain; charset=UTF-8');
542
+	if (function_exists('iconv')) {
543
+			header('Content-Type: text/plain; charset=UTF-8');
544
+	}
521 545
 
522 546
 	$request = $smcFunc['db_query']('', '
523 547
 		SELECT real_name
@@ -537,14 +561,16 @@  discard block
 block discarded – undo
537 561
 		if (function_exists('iconv'))
538 562
 		{
539 563
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
540
-			if ($utf8)
541
-				$row['real_name'] = $utf8;
564
+			if ($utf8) {
565
+							$row['real_name'] = $utf8;
566
+			}
542 567
 		}
543 568
 
544 569
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
545 570
 
546
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
547
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
571
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
572
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
573
+		}
548 574
 
549 575
 		echo $row['real_name'], "\n";
550 576
 	}
@@ -601,9 +627,9 @@  discard block
 block discarded – undo
601 627
 
602 628
 		// Update the database...
603 629
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
630
+	} else {
631
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
604 632
 	}
605
-	else
606
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
607 633
 
608 634
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
609 635
 
@@ -634,31 +660,37 @@  discard block
 block discarded – undo
634 660
 	$errors = array();
635 661
 
636 662
 	// Don't use too long a name.
637
-	if ($smcFunc['strlen']($username) > 25)
638
-		$errors[] = array('lang', 'error_long_name');
663
+	if ($smcFunc['strlen']($username) > 25) {
664
+			$errors[] = array('lang', 'error_long_name');
665
+	}
639 666
 
640 667
 	// No name?!  How can you register with no name?
641
-	if ($username == '')
642
-		$errors[] = array('lang', 'need_username');
668
+	if ($username == '') {
669
+			$errors[] = array('lang', 'need_username');
670
+	}
643 671
 
644 672
 	// Only these characters are permitted.
645
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
646
-		$errors[] = array('lang', 'error_invalid_characters_username');
673
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
674
+			$errors[] = array('lang', 'error_invalid_characters_username');
675
+	}
647 676
 
648
-	if (stristr($username, $txt['guest_title']) !== false)
649
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
677
+	if (stristr($username, $txt['guest_title']) !== false) {
678
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
679
+	}
650 680
 
651 681
 	if ($check_reserved_name)
652 682
 	{
653 683
 		require_once($sourcedir . '/Subs-Members.php');
654
-		if (isReservedName($username, $memID, false))
655
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
684
+		if (isReservedName($username, $memID, false)) {
685
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
686
+		}
656 687
 	}
657 688
 
658
-	if ($return_error)
659
-		return $errors;
660
-	elseif (empty($errors))
661
-		return null;
689
+	if ($return_error) {
690
+			return $errors;
691
+	} elseif (empty($errors)) {
692
+			return null;
693
+	}
662 694
 
663 695
 	loadLanguage('Errors');
664 696
 	$error = $errors[0];
@@ -684,22 +716,26 @@  discard block
 block discarded – undo
684 716
 	global $modSettings, $smcFunc;
685 717
 
686 718
 	// Perform basic requirements first.
687
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
688
-		return 'short';
719
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
720
+			return 'short';
721
+	}
689 722
 
690 723
 	// Is this enough?
691
-	if (empty($modSettings['password_strength']))
692
-		return null;
724
+	if (empty($modSettings['password_strength'])) {
725
+			return null;
726
+	}
693 727
 
694 728
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
695
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
696
-		return 'restricted_words';
697
-	elseif ($smcFunc['strpos']($password, $username) !== false)
698
-		return 'restricted_words';
729
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
730
+			return 'restricted_words';
731
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
732
+			return 'restricted_words';
733
+	}
699 734
 
700 735
 	// If just medium, we're done.
701
-	if ($modSettings['password_strength'] == 1)
702
-		return null;
736
+	if ($modSettings['password_strength'] == 1) {
737
+			return null;
738
+	}
703 739
 
704 740
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
705 741
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -731,14 +767,16 @@  discard block
 block discarded – undo
731 767
 			)
732 768
 		);
733 769
 		$groups = array();
734
-		while ($row = $smcFunc['db_fetch_assoc']($request))
735
-			$groups[] = $row['id_group'];
770
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
771
+					$groups[] = $row['id_group'];
772
+		}
736 773
 		$smcFunc['db_free_result']($request);
737 774
 
738
-		if (empty($groups))
739
-			$group_query = '0=1';
740
-		else
741
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
775
+		if (empty($groups)) {
776
+					$group_query = '0=1';
777
+		} else {
778
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
779
+		}
742 780
 	}
743 781
 
744 782
 	// Then, same again, just the boards this time!
@@ -748,10 +786,11 @@  discard block
 block discarded – undo
748 786
 	{
749 787
 		$boards = boardsAllowedTo('moderate_board', true);
750 788
 
751
-		if (empty($boards))
752
-			$board_query = '0=1';
753
-		else
754
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
789
+		if (empty($boards)) {
790
+					$board_query = '0=1';
791
+		} else {
792
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
793
+		}
755 794
 	}
756 795
 
757 796
 	// What boards are they the moderator of?
@@ -766,8 +805,9 @@  discard block
 block discarded – undo
766 805
 				'current_member' => $user_info['id'],
767 806
 			)
768 807
 		);
769
-		while ($row = $smcFunc['db_fetch_assoc']($request))
770
-			$boards_mod[] = $row['id_board'];
808
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
809
+					$boards_mod[] = $row['id_board'];
810
+		}
771 811
 		$smcFunc['db_free_result']($request);
772 812
 
773 813
 		// Can any of the groups they're in moderate any of the boards?
@@ -779,8 +819,9 @@  discard block
 block discarded – undo
779 819
 				'groups' => $user_info['groups'],
780 820
 			)
781 821
 		);
782
-		while ($row = $smcFunc['db_fetch_assoc']($request))
783
-			$boards_mod[] = $row['id_board'];
822
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
823
+					$boards_mod[] = $row['id_board'];
824
+		}
784 825
 		$smcFunc['db_free_result']($request);
785 826
 
786 827
 		// Just in case we've got duplicates here...
@@ -825,10 +866,12 @@  discard block
 block discarded – undo
825 866
 	global $modSettings;
826 867
 
827 868
 	// In case a customization wants to override the default settings
828
-	if ($httponly === null)
829
-		$httponly = !empty($modSettings['httponlyCookies']);
830
-	if ($secure === null)
831
-		$secure = !empty($modSettings['secureCookies']);
869
+	if ($httponly === null) {
870
+			$httponly = !empty($modSettings['httponlyCookies']);
871
+	}
872
+	if ($secure === null) {
873
+			$secure = !empty($modSettings['secureCookies']);
874
+	}
832 875
 
833 876
 	// Intercept cookie?
834 877
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -848,8 +891,9 @@  discard block
 block discarded – undo
848 891
 function hash_password($username, $password, $cost = null)
849 892
 {
850 893
 	global $sourcedir, $smcFunc, $modSettings;
851
-	if (!function_exists('password_hash'))
852
-		require_once($sourcedir . '/Subs-Password.php');
894
+	if (!function_exists('password_hash')) {
895
+			require_once($sourcedir . '/Subs-Password.php');
896
+	}
853 897
 
854 898
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
855 899
 
@@ -881,8 +925,9 @@  discard block
 block discarded – undo
881 925
 function hash_verify_password($username, $password, $hash)
882 926
 {
883 927
 	global $sourcedir, $smcFunc;
884
-	if (!function_exists('password_verify'))
885
-		require_once($sourcedir . '/Subs-Password.php');
928
+	if (!function_exists('password_verify')) {
929
+			require_once($sourcedir . '/Subs-Password.php');
930
+	}
886 931
 
887 932
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
888 933
 }
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +158 added lines, -124 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -102,19 +106,20 @@  discard block
 block discarded – undo
102 106
 			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
103 107
 
104 108
 			// That didn't work... Maybe it's using serialize?
105
-			if (is_null($timeout))
106
-				list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
107
-		}
108
-		elseif (isset($_SESSION['login_' . $cookiename]))
109
+			if (is_null($timeout)) {
110
+							list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
111
+			}
112
+		} elseif (isset($_SESSION['login_' . $cookiename]))
109 113
 		{
110 114
 			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
111 115
 
112 116
 			// Try for old format
113
-			if (is_null($timeout))
114
-				list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
117
+			if (is_null($timeout)) {
118
+							list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
119
+			}
120
+		} else {
121
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
115 122
 		}
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
118 123
 
119 124
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 125
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -127,10 +132,11 @@  discard block
 block discarded – undo
127 132
 			list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
128 133
 
129 134
 			// If we're preserving the cookie, reset it with updated salt
130
-			if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp)
131
-				setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
132
-			else
133
-				setTFACookie(-3600, 0, '');
135
+			if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) {
136
+							setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
137
+			} else {
138
+							setTFACookie(-3600, 0, '');
139
+			}
134 140
 		}
135 141
 
136 142
 		setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
@@ -141,20 +147,20 @@  discard block
 block discarded – undo
141 147
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
142 148
 	{
143 149
 		// Strike!  You're outta there!
144
-		if ($_GET['member'] != $user_info['id'])
145
-			fatal_lang_error('login_cookie_error', false);
150
+		if ($_GET['member'] != $user_info['id']) {
151
+					fatal_lang_error('login_cookie_error', false);
152
+		}
146 153
 
147 154
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
148 155
 
149 156
 		// Some whitelisting for login_url...
150
-		if (empty($_SESSION['login_url']))
151
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
152
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
157
+		if (empty($_SESSION['login_url'])) {
158
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
159
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
153 160
 		{
154 161
 			unset ($_SESSION['login_url']);
155 162
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
156
-		}
157
-		else
163
+		} else
158 164
 		{
159 165
 			// Best not to clutter the session data too much...
160 166
 			$temp = $_SESSION['login_url'];
@@ -165,8 +171,9 @@  discard block
 block discarded – undo
165 171
 	}
166 172
 
167 173
 	// Beyond this point you are assumed to be a guest trying to login.
168
-	if (!$user_info['is_guest'])
169
-		redirectexit();
174
+	if (!$user_info['is_guest']) {
175
+			redirectexit();
176
+	}
170 177
 
171 178
 	// Are you guessing with a script?
172 179
 	checkSession();
@@ -174,18 +181,21 @@  discard block
 block discarded – undo
174 181
 	spamProtection('login');
175 182
 
176 183
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
177
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
178
-		$_SESSION['login_url'] = $_SESSION['old_url'];
184
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
185
+			$_SESSION['login_url'] = $_SESSION['old_url'];
186
+	}
179 187
 
180 188
 	// Been guessing a lot, haven't we?
181
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
182
-		fatal_lang_error('login_threshold_fail', 'login');
189
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
190
+			fatal_lang_error('login_threshold_fail', 'login');
191
+	}
183 192
 
184 193
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
185
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
186
-		$modSettings['cookieTime'] = 3153600;
187
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
188
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
194
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
195
+			$modSettings['cookieTime'] = 3153600;
196
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
197
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
198
+	}
189 199
 
190 200
 	loadLanguage('Login');
191 201
 	// Load the template stuff.
@@ -305,8 +315,9 @@  discard block
 block discarded – undo
305 315
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
306 316
 
307 317
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
308
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
309
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
318
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
319
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
320
+			}
310 321
 
311 322
 			// phpBB3 users new hashing.  We now support it as well ;).
312 323
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -326,27 +337,29 @@  discard block
 block discarded – undo
326 337
 			// Some common md5 ones.
327 338
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
328 339
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
329
-		}
330
-		elseif (strlen($user_settings['passwd']) == 40)
340
+		} elseif (strlen($user_settings['passwd']) == 40)
331 341
 		{
332 342
 			// Maybe they are using a hash from before the password fix.
333 343
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
334 344
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
335 345
 
336 346
 			// BurningBoard3 style of hashing.
337
-			if (!empty($modSettings['enable_password_conversion']))
338
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
347
+			if (!empty($modSettings['enable_password_conversion'])) {
348
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
349
+			}
339 350
 
340 351
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
341 352
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
342 353
 			{
343 354
 				// Try iconv first, for no particular reason.
344
-				if (function_exists('iconv'))
345
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
355
+				if (function_exists('iconv')) {
356
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
357
+				}
346 358
 
347 359
 				// Say it aint so, iconv failed!
348
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
349
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
360
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
361
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
362
+				}
350 363
 			}
351 364
 		}
352 365
 
@@ -376,8 +389,9 @@  discard block
 block discarded – undo
376 389
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
377 390
 
378 391
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
379
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
380
-				redirectexit('action=reminder');
392
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
393
+							redirectexit('action=reminder');
394
+			}
381 395
 			// We'll give you another chance...
382 396
 			else
383 397
 			{
@@ -388,8 +402,7 @@  discard block
 block discarded – undo
388 402
 				return;
389 403
 			}
390 404
 		}
391
-	}
392
-	elseif (!empty($user_settings['passwd_flood']))
405
+	} elseif (!empty($user_settings['passwd_flood']))
393 406
 	{
394 407
 		// Let's be sure they weren't a little hacker.
395 408
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -406,8 +419,9 @@  discard block
 block discarded – undo
406 419
 	}
407 420
 
408 421
 	// Check their activation status.
409
-	if (!checkActivation())
410
-		return;
422
+	if (!checkActivation()) {
423
+			return;
424
+	}
411 425
 
412 426
 	DoLogin();
413 427
 }
@@ -419,8 +433,9 @@  discard block
 block discarded – undo
419 433
 {
420 434
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
421 435
 
422
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
423
-		fatal_lang_error('no_access', false);
436
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
437
+			fatal_lang_error('no_access', false);
438
+	}
424 439
 
425 440
 	loadLanguage('Profile');
426 441
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -428,8 +443,9 @@  discard block
 block discarded – undo
428 443
 	$member = $context['tfa_member'];
429 444
 
430 445
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
431
-	if (time() - $member['last_login'] < 120)
432
-		fatal_lang_error('tfa_wait', false);
446
+	if (time() - $member['last_login'] < 120) {
447
+			fatal_lang_error('tfa_wait', false);
448
+	}
433 449
 
434 450
 	$totp = new \TOTP\Auth($member['tfa_secret']);
435 451
 	$totp->setRange(1);
@@ -443,8 +459,9 @@  discard block
 block discarded – undo
443 459
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
444 460
 	{
445 461
 		// Check to ensure we're forcing SSL for authentication
446
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
447
-			fatal_lang_error('login_ssl_required');
462
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
463
+					fatal_lang_error('login_ssl_required');
464
+		}
448 465
 
449 466
 		$code = $_POST['tfa_code'];
450 467
 
@@ -454,20 +471,19 @@  discard block
 block discarded – undo
454 471
 
455 472
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve']));
456 473
 			redirectexit();
457
-		}
458
-		else
474
+		} else
459 475
 		{
460 476
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
461 477
 
462 478
 			$context['tfa_error'] = true;
463 479
 			$context['tfa_value'] = $_POST['tfa_code'];
464 480
 		}
465
-	}
466
-	elseif (!empty($_POST['tfa_backup']))
481
+	} elseif (!empty($_POST['tfa_backup']))
467 482
 	{
468 483
 		// Check to ensure we're forcing SSL for authentication
469
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
470
-			fatal_lang_error('login_ssl_required');
484
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
485
+					fatal_lang_error('login_ssl_required');
486
+		}
471 487
 
472 488
 		$backup = $_POST['tfa_backup'];
473 489
 
@@ -481,8 +497,7 @@  discard block
 block discarded – undo
481 497
 			));
482 498
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
483 499
 			redirectexit('action=profile;area=tfasetup;backup');
484
-		}
485
-		else
500
+		} else
486 501
 		{
487 502
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
488 503
 
@@ -505,8 +520,9 @@  discard block
 block discarded – undo
505 520
 {
506 521
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
507 522
 
508
-	if (!isset($context['login_errors']))
509
-		$context['login_errors'] = array();
523
+	if (!isset($context['login_errors'])) {
524
+			$context['login_errors'] = array();
525
+	}
510 526
 
511 527
 	// What is the true activation status of this account?
512 528
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -518,8 +534,9 @@  discard block
 block discarded – undo
518 534
 		return false;
519 535
 	}
520 536
 	// Awaiting approval still?
521
-	elseif ($activation_status == 3)
522
-		fatal_lang_error('still_awaiting_approval', 'user');
537
+	elseif ($activation_status == 3) {
538
+			fatal_lang_error('still_awaiting_approval', 'user');
539
+	}
523 540
 	// Awaiting deletion, changed their mind?
524 541
 	elseif ($activation_status == 4)
525 542
 	{
@@ -527,8 +544,7 @@  discard block
 block discarded – undo
527 544
 		{
528 545
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
529 546
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
530
-		}
531
-		else
547
+		} else
532 548
 		{
533 549
 			$context['disable_login_hashing'] = true;
534 550
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -568,8 +584,9 @@  discard block
 block discarded – undo
568 584
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
569 585
 
570 586
 	// Reset the login threshold.
571
-	if (isset($_SESSION['failed_login']))
572
-		unset($_SESSION['failed_login']);
587
+	if (isset($_SESSION['failed_login'])) {
588
+			unset($_SESSION['failed_login']);
589
+	}
573 590
 
574 591
 	$user_info['is_guest'] = false;
575 592
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -591,16 +608,18 @@  discard block
 block discarded – undo
591 608
 			'id_member' => $user_info['id'],
592 609
 		)
593 610
 	);
594
-	if ($smcFunc['db_num_rows']($request) == 1)
595
-		$_SESSION['first_login'] = true;
596
-	else
597
-		unset($_SESSION['first_login']);
611
+	if ($smcFunc['db_num_rows']($request) == 1) {
612
+			$_SESSION['first_login'] = true;
613
+	} else {
614
+			unset($_SESSION['first_login']);
615
+	}
598 616
 	$smcFunc['db_free_result']($request);
599 617
 
600 618
 	// You've logged in, haven't you?
601 619
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
602
-	if (empty($user_settings['tfa_secret']))
603
-		$update['last_login'] = time();
620
+	if (empty($user_settings['tfa_secret'])) {
621
+			$update['last_login'] = time();
622
+	}
604 623
 	updateMemberData($user_info['id'], $update);
605 624
 
606 625
 	// Get rid of the online entry for that old guest....
@@ -614,8 +633,8 @@  discard block
 block discarded – undo
614 633
 	$_SESSION['log_time'] = 0;
615 634
 
616 635
 	// Log this entry, only if we have it enabled.
617
-	if (!empty($modSettings['loginHistoryDays']))
618
-		$smcFunc['db_insert']('insert',
636
+	if (!empty($modSettings['loginHistoryDays'])) {
637
+			$smcFunc['db_insert']('insert',
619 638
 			'{db_prefix}member_logins',
620 639
 			array(
621 640
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -627,13 +646,15 @@  discard block
 block discarded – undo
627 646
 				'id_member', 'time'
628 647
 			)
629 648
 		);
649
+	}
630 650
 
631 651
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
632
-	if (empty($maintenance) || allowedTo('admin_forum'))
633
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
634
-	else
635
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
636
-}
652
+	if (empty($maintenance) || allowedTo('admin_forum')) {
653
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
654
+	} else {
655
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
656
+	}
657
+	}
637 658
 
638 659
 /**
639 660
  * Logs the current user out of their account.
@@ -649,13 +670,15 @@  discard block
 block discarded – undo
649 670
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
650 671
 
651 672
 	// Make sure they aren't being auto-logged out.
652
-	if (!$internal)
653
-		checkSession('get');
673
+	if (!$internal) {
674
+			checkSession('get');
675
+	}
654 676
 
655 677
 	require_once($sourcedir . '/Subs-Auth.php');
656 678
 
657
-	if (isset($_SESSION['pack_ftp']))
658
-		$_SESSION['pack_ftp'] = null;
679
+	if (isset($_SESSION['pack_ftp'])) {
680
+			$_SESSION['pack_ftp'] = null;
681
+	}
659 682
 
660 683
 	// It won't be first login anymore.
661 684
 	unset($_SESSION['first_login']);
@@ -683,8 +706,9 @@  discard block
 block discarded – undo
683 706
 
684 707
 	// And some other housekeeping while we're at it.
685 708
 	$salt = substr(md5(mt_rand()), 0, 4);
686
-	if (!empty($user_info['id']))
687
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
709
+	if (!empty($user_info['id'])) {
710
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
711
+	}
688 712
 
689 713
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
690 714
 	{
@@ -693,10 +717,11 @@  discard block
 block discarded – undo
693 717
 		list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
694 718
 
695 719
 		// If we're preserving the cookie, reset it with updated salt
696
-		if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp)
697
-			setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
698
-		else
699
-			setTFACookie(-3600, 0, '');
720
+		if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) {
721
+					setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
722
+		} else {
723
+					setTFACookie(-3600, 0, '');
724
+		}
700 725
 	}
701 726
 
702 727
 	session_destroy();
@@ -704,14 +729,13 @@  discard block
 block discarded – undo
704 729
 	// Off to the merry board index we go!
705 730
 	if ($redirect)
706 731
 	{
707
-		if (empty($_SESSION['logout_url']))
708
-			redirectexit('', $context['server']['needs_login_fix']);
709
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
732
+		if (empty($_SESSION['logout_url'])) {
733
+					redirectexit('', $context['server']['needs_login_fix']);
734
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
710 735
 		{
711 736
 			unset ($_SESSION['logout_url']);
712 737
 			redirectexit();
713
-		}
714
-		else
738
+		} else
715 739
 		{
716 740
 			$temp = $_SESSION['logout_url'];
717 741
 			unset($_SESSION['logout_url']);
@@ -744,8 +768,9 @@  discard block
 block discarded – undo
744 768
 function phpBB3_password_check($passwd, $passwd_hash)
745 769
 {
746 770
 	// Too long or too short?
747
-	if (strlen($passwd_hash) != 34)
748
-		return;
771
+	if (strlen($passwd_hash) != 34) {
772
+			return;
773
+	}
749 774
 
750 775
 	// Range of characters allowed.
751 776
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -756,8 +781,9 @@  discard block
 block discarded – undo
756 781
 	$salt = substr($passwd_hash, 4, 8);
757 782
 
758 783
 	$hash = md5($salt . $passwd, true);
759
-	for (; $count != 0; --$count)
760
-		$hash = md5($hash . $passwd, true);
784
+	for (; $count != 0; --$count) {
785
+			$hash = md5($hash . $passwd, true);
786
+	}
761 787
 
762 788
 	$output = substr($passwd_hash, 0, 12);
763 789
 	$i = 0;
@@ -766,21 +792,25 @@  discard block
 block discarded – undo
766 792
 		$value = ord($hash[$i++]);
767 793
 		$output .= $range[$value & 0x3f];
768 794
 
769
-		if ($i < 16)
770
-			$value |= ord($hash[$i]) << 8;
795
+		if ($i < 16) {
796
+					$value |= ord($hash[$i]) << 8;
797
+		}
771 798
 
772 799
 		$output .= $range[($value >> 6) & 0x3f];
773 800
 
774
-		if ($i++ >= 16)
775
-			break;
801
+		if ($i++ >= 16) {
802
+					break;
803
+		}
776 804
 
777
-		if ($i < 16)
778
-			$value |= ord($hash[$i]) << 16;
805
+		if ($i < 16) {
806
+					$value |= ord($hash[$i]) << 16;
807
+		}
779 808
 
780 809
 		$output .= $range[($value >> 12) & 0x3f];
781 810
 
782
-		if ($i++ >= 16)
783
-			break;
811
+		if ($i++ >= 16) {
812
+					break;
813
+		}
784 814
 
785 815
 		$output .= $range[($value >> 18) & 0x3f];
786 816
 	}
@@ -812,8 +842,9 @@  discard block
 block discarded – undo
812 842
 		require_once($sourcedir . '/Subs-Auth.php');
813 843
 		setLoginCookie(-3600, 0);
814 844
 
815
-		if (isset($_SESSION['login_' . $cookiename]))
816
-			unset($_SESSION['login_' . $cookiename]);
845
+		if (isset($_SESSION['login_' . $cookiename])) {
846
+					unset($_SESSION['login_' . $cookiename]);
847
+		}
817 848
 	}
818 849
 
819 850
 	// We need a member!
@@ -827,8 +858,9 @@  discard block
 block discarded – undo
827 858
 	}
828 859
 
829 860
 	// Right, have we got a flood value?
830
-	if ($password_flood_value !== false)
831
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
861
+	if ($password_flood_value !== false) {
862
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
863
+	}
832 864
 
833 865
 	// Timestamp or number of tries invalid?
834 866
 	if (empty($number_tries) || empty($time_stamp))
@@ -844,15 +876,17 @@  discard block
 block discarded – undo
844 876
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
845 877
 
846 878
 		// They are trying too fast, make them wait longer
847
-		if ($time_stamp < time() - 10)
848
-			$time_stamp = time();
879
+		if ($time_stamp < time() - 10) {
880
+					$time_stamp = time();
881
+		}
849 882
 	}
850 883
 
851 884
 	$number_tries++;
852 885
 
853 886
 	// Broken the law?
854
-	if ($number_tries > 5)
855
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
887
+	if ($number_tries > 5) {
888
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
889
+	}
856 890
 
857 891
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
858 892
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/Subs-Post.php 1 patch
Braces   +531 added lines, -395 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 	global $user_info, $modSettings, $context, $sourcedir;
32 33
 
33 34
 	// This line makes all languages *theoretically* work even with the wrong charset ;).
34
-	if (empty($context['utf8']))
35
-		$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
35
+	if (empty($context['utf8'])) {
36
+			$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
37
+	}
36 38
 
37 39
 	// Clean up after nobbc ;).
38 40
 	$message = preg_replace_callback('~\[nobbc\](.+?)\[/nobbc\]~is', function($a)
@@ -47,17 +49,19 @@  discard block
 block discarded – undo
47 49
 	$message = preg_replace('~\.{100,}~', '...', $message);
48 50
 
49 51
 	// Trim off trailing quotes - these often happen by accident.
50
-	while (substr($message, -7) == '[quote]')
51
-		$message = substr($message, 0, -7);
52
-	while (substr($message, 0, 8) == '[/quote]')
53
-		$message = substr($message, 8);
52
+	while (substr($message, -7) == '[quote]') {
53
+			$message = substr($message, 0, -7);
54
+	}
55
+	while (substr($message, 0, 8) == '[/quote]') {
56
+			$message = substr($message, 8);
57
+	}
54 58
 
55 59
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
56 60
 	$in_tag = false;
57 61
 	$had_tag = false;
58 62
 	$codeopen = 0;
59
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
60
-		foreach ($matches[0] as $index => $dummy)
63
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
64
+			foreach ($matches[0] as $index => $dummy)
61 65
 		{
62 66
 			// Closing?
63 67
 			if (!empty($matches[2][$index]))
@@ -65,6 +69,7 @@  discard block
 block discarded – undo
65 69
 				// If it's closing and we're not in a tag we need to open it...
66 70
 				if (!$in_tag)
67 71
 					$codeopen = true;
72
+	}
68 73
 				// Either way we ain't in one any more.
69 74
 				$in_tag = false;
70 75
 			}
@@ -73,17 +78,20 @@  discard block
 block discarded – undo
73 78
 			{
74 79
 				$had_tag = true;
75 80
 				// If we're in a tag don't do nought!
76
-				if (!$in_tag)
77
-					$in_tag = true;
81
+				if (!$in_tag) {
82
+									$in_tag = true;
83
+				}
78 84
 			}
79 85
 		}
80 86
 
81 87
 	// If we have an open tag, close it.
82
-	if ($in_tag)
83
-		$message .= '[/code]';
88
+	if ($in_tag) {
89
+			$message .= '[/code]';
90
+	}
84 91
 	// Open any ones that need to be open, only if we've never had a tag.
85
-	if ($codeopen && !$had_tag)
86
-		$message = '[code]' . $message;
92
+	if ($codeopen && !$had_tag) {
93
+			$message = '[code]' . $message;
94
+	}
87 95
 
88 96
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
89 97
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -109,23 +117,26 @@  discard block
 block discarded – undo
109 117
 	fixTags($message);
110 118
 
111 119
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
112
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
113
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
114
-	else
115
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
120
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
121
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
122
+	} else {
123
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
124
+	}
116 125
 
117 126
 	if (!$previewing && strpos($message, '[html]') !== false)
118 127
 	{
119
-		if (allowedTo('admin_forum'))
120
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
128
+		if (allowedTo('admin_forum')) {
129
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
121 130
 				return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => '&#13;', '  ' => ' &#32;', '[' => '&#91;', ']' => '&#93;')) . '[/html]';
131
+		}
122 132
 			}, $message);
123 133
 
124 134
 		// We should edit them out, or else if an admin edits the message they will get shown...
125 135
 		else
126 136
 		{
127
-			while (strpos($message, '[html]') !== false)
128
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			while (strpos($message, '[html]') !== false) {
138
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
139
+			}
129 140
 		}
130 141
 	}
131 142
 
@@ -147,10 +158,12 @@  discard block
 block discarded – undo
147 158
 
148 159
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
149 160
 	$list_close = substr_count($message, '[/list]');
150
-	if ($list_close - $list_open > 0)
151
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
152
-	if ($list_open - $list_close > 0)
153
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
161
+	if ($list_close - $list_open > 0) {
162
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
163
+	}
164
+	if ($list_open - $list_close > 0) {
165
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
166
+	}
154 167
 
155 168
 	$mistake_fixes = array(
156 169
 		// Find [table]s not followed by [tr].
@@ -199,8 +212,9 @@  discard block
 block discarded – undo
199 212
 	);
200 213
 
201 214
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
202
-	for ($j = 0; $j < 3; $j++)
203
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	for ($j = 0; $j < 3; $j++) {
216
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
217
+	}
204 218
 
205 219
 	// Remove empty bbc from the sections outside the code tags
206 220
 	$allowedEmpty = array(
@@ -210,24 +224,28 @@  discard block
 block discarded – undo
210 224
 
211 225
 	require_once($sourcedir . '/Subs.php');
212 226
 
213
-	foreach (($codes = parse_bbc(false)) as $code)
214
-		if (!in_array($code['tag'], $allowedEmpty))
227
+	foreach (($codes = parse_bbc(false)) as $code) {
228
+			if (!in_array($code['tag'], $allowedEmpty))
215 229
 			$alltags[] = $code['tag'];
230
+	}
216 231
 
217 232
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
218 233
 
219
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
220
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
235
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
236
+	}
221 237
 
222 238
 	// Restore code blocks
223
-	if (!empty($code_tags))
224
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	if (!empty($code_tags)) {
240
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
241
+	}
225 242
 
226 243
 	// Restore white space entities
227
-	if (!$previewing)
228
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
229
-	else
230
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	if (!$previewing) {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	} else {
247
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
248
+	}
231 249
 
232 250
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
233 251
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -270,8 +288,9 @@  discard block
 block discarded – undo
270 288
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
271 289
 	}, $message);
272 290
 
273
-	if (!empty($code_tags))
274
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	if (!empty($code_tags)) {
292
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
293
+	}
275 294
 
276 295
 	// Change breaks back to \n's and &nsbp; back to spaces.
277 296
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -352,8 +371,9 @@  discard block
 block discarded – undo
352 371
 	);
353 372
 
354 373
 	// Fix each type of tag.
355
-	foreach ($fixArray as $param)
356
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	foreach ($fixArray as $param) {
375
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
376
+	}
357 377
 
358 378
 	// Now fix possible security problems with images loading links automatically...
359 379
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -389,16 +409,19 @@  discard block
 block discarded – undo
389 409
 					$desired_height = $height;
390 410
 				}
391 411
 				// Scale it to the width...
392
-				elseif (empty($desired_width) && !empty($height))
393
-					$desired_width = (int) (($desired_height * $width) / $height);
412
+				elseif (empty($desired_width) && !empty($height)) {
413
+									$desired_width = (int) (($desired_height * $width) / $height);
414
+				}
394 415
 				// Scale if to the height.
395
-				elseif (!empty($width))
396
-					$desired_height = (int) (($desired_width * $height) / $width);
416
+				elseif (!empty($width)) {
417
+									$desired_height = (int) (($desired_width * $height) / $width);
418
+				}
397 419
 			}
398 420
 
399 421
 			// If the width and height are fine, just continue along...
400
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
401
-				continue;
422
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
423
+							continue;
424
+			}
402 425
 
403 426
 			// Too bad, it's too wide.  Make it as wide as the maximum.
404 427
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -418,8 +441,9 @@  discard block
 block discarded – undo
418 441
 		}
419 442
 
420 443
 		// If any img tags were actually changed...
421
-		if (!empty($replaces))
422
-			$message = strtr($message, $replaces);
444
+		if (!empty($replaces)) {
445
+					$message = strtr($message, $replaces);
446
+		}
423 447
 	}
424 448
 }
425 449
 
@@ -438,10 +462,11 @@  discard block
 block discarded – undo
438 462
 {
439 463
 	global $boardurl, $scripturl;
440 464
 
441
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
442
-		$domain_url = $match[1];
443
-	else
444
-		$domain_url = $boardurl . '/';
465
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
466
+			$domain_url = $match[1];
467
+	} else {
468
+			$domain_url = $boardurl . '/';
469
+	}
445 470
 
446 471
 	$replaces = array();
447 472
 
@@ -449,11 +474,11 @@  discard block
 block discarded – undo
449 474
 	{
450 475
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
451 476
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
477
+	} elseif ($hasEqualSign) {
478
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
479
+	} else {
480
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
452 481
 	}
453
-	elseif ($hasEqualSign)
454
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
455
-	else
456
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
457 482
 
458 483
 	foreach ($matches[0] as $k => $dummy)
459 484
 	{
@@ -466,49 +491,53 @@  discard block
 block discarded – undo
466 491
 		foreach ($protocols as $protocol)
467 492
 		{
468 493
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
469
-			if ($found)
470
-				break;
494
+			if ($found) {
495
+							break;
496
+			}
471 497
 		}
472 498
 
473 499
 		if (!$found && $protocols[0] == 'http')
474 500
 		{
475
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
476
-				$replace = $domain_url . $replace;
477
-			elseif (substr($replace, 0, 1) == '?')
478
-				$replace = $scripturl . $replace;
479
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
501
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
502
+							$replace = $domain_url . $replace;
503
+			} elseif (substr($replace, 0, 1) == '?') {
504
+							$replace = $scripturl . $replace;
505
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
480 506
 			{
481 507
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
482 508
 				$this_tag = 'iurl';
483 509
 				$this_close = 'iurl';
510
+			} elseif (substr($replace, 0, 2) != '//') {
511
+							$replace = $protocols[0] . '://' . $replace;
484 512
 			}
485
-			elseif (substr($replace, 0, 2) != '//')
486
-				$replace = $protocols[0] . '://' . $replace;
487
-		}
488
-		elseif (!$found && $protocols[0] == 'ftp')
489
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
490
-		elseif (!$found)
491
-			$replace = $protocols[0] . '://' . $replace;
492
-
493
-		if ($hasEqualSign && $embeddedUrl)
494
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
495
-		elseif ($hasEqualSign)
496
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
497
-		elseif ($embeddedUrl)
498
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
499
-		else
500
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
513
+		} elseif (!$found && $protocols[0] == 'ftp') {
514
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
515
+		} elseif (!$found) {
516
+					$replace = $protocols[0] . '://' . $replace;
517
+		}
518
+
519
+		if ($hasEqualSign && $embeddedUrl) {
520
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
521
+		} elseif ($hasEqualSign) {
522
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
523
+		} elseif ($embeddedUrl) {
524
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
525
+		} else {
526
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
527
+		}
501 528
 	}
502 529
 
503 530
 	foreach ($replaces as $k => $v)
504 531
 	{
505
-		if ($k == $v)
506
-			unset($replaces[$k]);
532
+		if ($k == $v) {
533
+					unset($replaces[$k]);
534
+		}
507 535
 	}
508 536
 
509
-	if (!empty($replaces))
510
-		$message = strtr($message, $replaces);
511
-}
537
+	if (!empty($replaces)) {
538
+			$message = strtr($message, $replaces);
539
+	}
540
+	}
512 541
 
513 542
 /**
514 543
  * This function sends an email to the specified recipient(s).
@@ -552,8 +581,9 @@  discard block
 block discarded – undo
552 581
 	}
553 582
 
554 583
 	// Nothing left? Nothing else to do
555
-	if (empty($to_array))
556
-		return true;
584
+	if (empty($to_array)) {
585
+			return true;
586
+	}
557 587
 
558 588
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
559 589
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -570,15 +600,17 @@  discard block
 block discarded – undo
570 600
 		}
571 601
 
572 602
 		// Call this function recursively for the hotmail addresses.
573
-		if (!empty($hotmail_to))
574
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
603
+		if (!empty($hotmail_to)) {
604
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
605
+		}
575 606
 
576 607
 		// The remaining addresses no longer need the fix.
577 608
 		$hotmail_fix = false;
578 609
 
579 610
 		// No other addresses left? Return instantly.
580
-		if (empty($to_array))
581
-			return $mail_result;
611
+		if (empty($to_array)) {
612
+					return $mail_result;
613
+		}
582 614
 	}
583 615
 
584 616
 	// Get rid of entities.
@@ -603,13 +635,15 @@  discard block
 block discarded – undo
603 635
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
604 636
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
605 637
 
606
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
607
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
638
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
639
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
640
+	}
608 641
 	$headers .= 'X-Mailer: SMF' . $line_break;
609 642
 
610 643
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
611
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
612
-		return false;
644
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
645
+			return false;
646
+	}
613 647
 
614 648
 	// Save the original message...
615 649
 	$orig_message = $message;
@@ -658,17 +692,19 @@  discard block
 block discarded – undo
658 692
 	}
659 693
 
660 694
 	// Are we using the mail queue, if so this is where we butt in...
661
-	if ($priority != 0)
662
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
695
+	if ($priority != 0) {
696
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
697
+	}
663 698
 
664 699
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
665 700
 	elseif (!empty($modSettings['mail_limit']))
666 701
 	{
667 702
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
668
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
669
-			$new_queue_stat = time() . '|' . 1;
670
-		else
671
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
703
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
704
+					$new_queue_stat = time() . '|' . 1;
705
+		} else {
706
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
707
+		}
672 708
 
673 709
 		updateSettings(array('mail_recent' => $new_queue_stat));
674 710
 	}
@@ -693,12 +729,13 @@  discard block
 block discarded – undo
693 729
 
694 730
 			// Wait, wait, I'm still sending here!
695 731
 			@set_time_limit(300);
696
-			if (function_exists('apache_reset_timeout'))
697
-				@apache_reset_timeout();
732
+			if (function_exists('apache_reset_timeout')) {
733
+							@apache_reset_timeout();
734
+			}
698 735
 		}
736
+	} else {
737
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
699 738
 	}
700
-	else
701
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
702 739
 
703 740
 	// Everything go smoothly?
704 741
 	return $mail_result;
@@ -724,8 +761,9 @@  discard block
 block discarded – undo
724 761
 	static $cur_insert = array();
725 762
 	static $cur_insert_len = 0;
726 763
 
727
-	if ($cur_insert_len == 0)
728
-		$cur_insert = array();
764
+	if ($cur_insert_len == 0) {
765
+			$cur_insert = array();
766
+	}
729 767
 
730 768
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
731 769
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -800,8 +838,9 @@  discard block
 block discarded – undo
800 838
 	}
801 839
 
802 840
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
803
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
804
-		return AddMailQueue(true);
841
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
842
+			return AddMailQueue(true);
843
+	}
805 844
 
806 845
 	return true;
807 846
 }
@@ -832,23 +871,26 @@  discard block
 block discarded – undo
832 871
 		'sent' => array()
833 872
 	);
834 873
 
835
-	if ($from === null)
836
-		$from = array(
874
+	if ($from === null) {
875
+			$from = array(
837 876
 			'id' => $user_info['id'],
838 877
 			'name' => $user_info['name'],
839 878
 			'username' => $user_info['username']
840 879
 		);
880
+	}
841 881
 
842 882
 	// This is the one that will go in their inbox.
843 883
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
844 884
 	preparsecode($htmlmessage);
845 885
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
846
-	if ($smcFunc['strlen']($htmlsubject) > 100)
847
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
886
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
887
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
888
+	}
848 889
 
849 890
 	// Make sure is an array
850
-	if (!is_array($recipients))
851
-		$recipients = array($recipients);
891
+	if (!is_array($recipients)) {
892
+			$recipients = array($recipients);
893
+	}
852 894
 
853 895
 	// Integrated PMs
854 896
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -876,21 +918,23 @@  discard block
 block discarded – undo
876 918
 				'usernames' => array_keys($usernames),
877 919
 			)
878 920
 		);
879
-		while ($row = $smcFunc['db_fetch_assoc']($request))
880
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
921
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
922
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
881 923
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
924
+		}
882 925
 		$smcFunc['db_free_result']($request);
883 926
 
884 927
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
885
-		foreach ($recipients as $rec_type => $rec)
886
-			foreach ($rec as $id => $member)
928
+		foreach ($recipients as $rec_type => $rec) {
929
+					foreach ($rec as $id => $member)
887 930
 			{
888 931
 				if (is_numeric($recipients[$rec_type][$id]))
889 932
 					continue;
933
+		}
890 934
 
891
-				if (!empty($usernames[$member]))
892
-					$recipients[$rec_type][$id] = $usernames[$member];
893
-				else
935
+				if (!empty($usernames[$member])) {
936
+									$recipients[$rec_type][$id] = $usernames[$member];
937
+				} else
894 938
 				{
895 939
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
896 940
 					unset($recipients[$rec_type][$id]);
@@ -928,8 +972,9 @@  discard block
 block discarded – undo
928 972
 		$delete = false;
929 973
 		foreach ($criteria as $criterium)
930 974
 		{
931
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
932
-				$delete = true;
975
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
976
+							$delete = true;
977
+			}
933 978
 			// If we're adding and one criteria don't match then we stop!
934 979
 			elseif (!$row['is_or'])
935 980
 			{
@@ -937,8 +982,9 @@  discard block
 block discarded – undo
937 982
 				break;
938 983
 			}
939 984
 		}
940
-		if ($delete)
941
-			$deletes[$row['id_member']] = 1;
985
+		if ($delete) {
986
+					$deletes[$row['id_member']] = 1;
987
+		}
942 988
 	}
943 989
 	$smcFunc['db_free_result']($request);
944 990
 
@@ -953,8 +999,9 @@  discard block
 block discarded – undo
953 999
 			array(
954 1000
 			)
955 1001
 		);
956
-		while ($row = $smcFunc['db_fetch_assoc']($request))
957
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1002
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1003
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1004
+		}
958 1005
 		$smcFunc['db_free_result']($request);
959 1006
 	}
960 1007
 
@@ -962,8 +1009,9 @@  discard block
 block discarded – undo
962 1009
 	require_once($sourcedir . '/Subs-Members.php');
963 1010
 	$pmReadGroups = groupsAllowedTo('pm_read');
964 1011
 
965
-	if (empty($modSettings['permission_enable_deny']))
966
-		$pmReadGroups['denied'] = array();
1012
+	if (empty($modSettings['permission_enable_deny'])) {
1013
+			$pmReadGroups['denied'] = array();
1014
+	}
967 1015
 
968 1016
 	// Load their alert preferences
969 1017
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -995,8 +1043,9 @@  discard block
 block discarded – undo
995 1043
 	while ($row = $smcFunc['db_fetch_assoc']($request))
996 1044
 	{
997 1045
 		// Don't do anything for members to be deleted!
998
-		if (isset($deletes[$row['id_member']]))
999
-			continue;
1046
+		if (isset($deletes[$row['id_member']])) {
1047
+					continue;
1048
+		}
1000 1049
 
1001 1050
 		// Load the preferences for this member (if any)
1002 1051
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1017,8 +1066,9 @@  discard block
 block discarded – undo
1017 1066
 		{
1018 1067
 			foreach ($groups as $id)
1019 1068
 			{
1020
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1021
-					$message_limit = $message_limit_cache[$id];
1069
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1070
+									$message_limit = $message_limit_cache[$id];
1071
+				}
1022 1072
 			}
1023 1073
 
1024 1074
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1066,8 +1116,9 @@  discard block
 block discarded – undo
1066 1116
 	$smcFunc['db_free_result']($request);
1067 1117
 
1068 1118
 	// Only 'send' the message if there are any recipients left.
1069
-	if (empty($all_to))
1070
-		return $log;
1119
+	if (empty($all_to)) {
1120
+			return $log;
1121
+	}
1071 1122
 
1072 1123
 	// Insert the message itself and then grab the last insert id.
1073 1124
 	$id_pm = $smcFunc['db_insert']('',
@@ -1088,8 +1139,8 @@  discard block
 block discarded – undo
1088 1139
 	if (!empty($id_pm))
1089 1140
 	{
1090 1141
 		// If this is new we need to set it part of it's own conversation.
1091
-		if (empty($pm_head))
1092
-			$smcFunc['db_query']('', '
1142
+		if (empty($pm_head)) {
1143
+					$smcFunc['db_query']('', '
1093 1144
 				UPDATE {db_prefix}personal_messages
1094 1145
 				SET id_pm_head = {int:id_pm_head}
1095 1146
 				WHERE id_pm = {int:id_pm_head}',
@@ -1097,6 +1148,7 @@  discard block
 block discarded – undo
1097 1148
 					'id_pm_head' => $id_pm,
1098 1149
 				)
1099 1150
 			);
1151
+		}
1100 1152
 
1101 1153
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1102 1154
 		$smcFunc['db_query']('', '
@@ -1112,8 +1164,9 @@  discard block
 block discarded – undo
1112 1164
 		foreach ($all_to as $to)
1113 1165
 		{
1114 1166
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1115
-			if (!in_array($to, $recipients['bcc']))
1116
-				$to_list[] = $to;
1167
+			if (!in_array($to, $recipients['bcc'])) {
1168
+							$to_list[] = $to;
1169
+			}
1117 1170
 		}
1118 1171
 
1119 1172
 		$smcFunc['db_insert']('insert',
@@ -1131,9 +1184,9 @@  discard block
 block discarded – undo
1131 1184
 	{
1132 1185
 		censorText($message);
1133 1186
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1187
+	} else {
1188
+			$message = '';
1134 1189
 	}
1135
-	else
1136
-		$message = '';
1137 1190
 
1138 1191
 	$to_names = array();
1139 1192
 	if (count($to_list) > 1)
@@ -1146,8 +1199,9 @@  discard block
 block discarded – undo
1146 1199
 				'to_members' => $to_list,
1147 1200
 			)
1148 1201
 		);
1149
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1150
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1203
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1204
+		}
1151 1205
 		$smcFunc['db_free_result']($request);
1152 1206
 	}
1153 1207
 	$replacements = array(
@@ -1175,11 +1229,13 @@  discard block
 block discarded – undo
1175 1229
 	loadLanguage('index+PersonalMessage');
1176 1230
 
1177 1231
 	// Add one to their unread and read message counts.
1178
-	foreach ($all_to as $k => $id)
1179
-		if (isset($deletes[$id]))
1232
+	foreach ($all_to as $k => $id) {
1233
+			if (isset($deletes[$id]))
1180 1234
 			unset($all_to[$k]);
1181
-	if (!empty($all_to))
1182
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1235
+	}
1236
+	if (!empty($all_to)) {
1237
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1238
+	}
1183 1239
 
1184 1240
 	return $log;
1185 1241
 }
@@ -1209,15 +1265,17 @@  discard block
 block discarded – undo
1209 1265
 		// Let's, for now, assume there are only &#021;'ish characters.
1210 1266
 		$simple = true;
1211 1267
 
1212
-		foreach ($matches[1] as $entity)
1213
-			if ($entity > 128)
1268
+		foreach ($matches[1] as $entity) {
1269
+					if ($entity > 128)
1214 1270
 				$simple = false;
1271
+		}
1215 1272
 		unset($matches);
1216 1273
 
1217
-		if ($simple)
1218
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1274
+		if ($simple) {
1275
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1219 1276
 			{
1220 1277
 				return chr("$m[1]");
1278
+		}
1221 1279
 			}, $string);
1222 1280
 		else
1223 1281
 		{
@@ -1225,8 +1283,9 @@  discard block
 block discarded – undo
1225 1283
 			if (!$context['utf8'] && function_exists('iconv'))
1226 1284
 			{
1227 1285
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1228
-				if ($newstring)
1229
-					$string = $newstring;
1286
+				if ($newstring) {
1287
+									$string = $newstring;
1288
+				}
1230 1289
 			}
1231 1290
 
1232 1291
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1242,23 +1301,25 @@  discard block
 block discarded – undo
1242 1301
 		if (!$context['utf8'] && function_exists('iconv'))
1243 1302
 		{
1244 1303
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1245
-			if ($newstring)
1246
-				$string = $newstring;
1304
+			if ($newstring) {
1305
+							$string = $newstring;
1306
+			}
1247 1307
 		}
1248 1308
 
1249 1309
 		$entityConvert = function($m)
1250 1310
 		{
1251 1311
 			$c = $m[1];
1252
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1253
-				return $c;
1254
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1255
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1256
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1257
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1258
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1259
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1260
-			else
1261
-				return "";
1312
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1313
+							return $c;
1314
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1315
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1316
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1317
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1318
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1319
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1320
+			} else {
1321
+							return "";
1322
+			}
1262 1323
 		};
1263 1324
 
1264 1325
 		// Convert all 'special' characters to HTML entities.
@@ -1272,19 +1333,20 @@  discard block
 block discarded – undo
1272 1333
 		$string = base64_encode($string);
1273 1334
 
1274 1335
 		// Show the characterset and the transfer-encoding for header strings.
1275
-		if ($with_charset)
1276
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1336
+		if ($with_charset) {
1337
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1338
+		}
1277 1339
 
1278 1340
 		// Break it up in lines (mail body).
1279
-		else
1280
-			$string = chunk_split($string, 76, $line_break);
1341
+		else {
1342
+					$string = chunk_split($string, 76, $line_break);
1343
+		}
1281 1344
 
1282 1345
 		return array($charset, $string, 'base64');
1346
+	} else {
1347
+			return array($charset, $string, '7bit');
1348
+	}
1283 1349
 	}
1284
-
1285
-	else
1286
-		return array($charset, $string, '7bit');
1287
-}
1288 1350
 
1289 1351
 /**
1290 1352
  * Sends mail, like mail() but over SMTP.
@@ -1308,8 +1370,9 @@  discard block
 block discarded – undo
1308 1370
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1309 1371
 	{
1310 1372
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1311
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1312
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1373
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1374
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1375
+		}
1313 1376
 
1314 1377
 		if ($socket)
1315 1378
 		{
@@ -1330,8 +1393,9 @@  discard block
 block discarded – undo
1330 1393
 		// Maybe we can still save this?  The port might be wrong.
1331 1394
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1332 1395
 		{
1333
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1334
-				log_error($txt['smtp_port_ssl']);
1396
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1397
+							log_error($txt['smtp_port_ssl']);
1398
+			}
1335 1399
 		}
1336 1400
 
1337 1401
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1343,20 +1407,23 @@  discard block
 block discarded – undo
1343 1407
 	}
1344 1408
 
1345 1409
 	// Wait for a response of 220, without "-" continuer.
1346
-	if (!server_parse(null, $socket, '220'))
1347
-		return false;
1410
+	if (!server_parse(null, $socket, '220')) {
1411
+			return false;
1412
+	}
1348 1413
 
1349 1414
 	// Try and determine the servers name, fall back to the mail servers if not found
1350 1415
 	$helo = false;
1351
-	if (function_exists('gethostname') && gethostname() !== false)
1352
-		$helo = gethostname();
1353
-	elseif (function_exists('php_uname'))
1354
-		$helo = php_uname('n');
1355
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1356
-		$helo = $_SERVER['SERVER_NAME'];
1416
+	if (function_exists('gethostname') && gethostname() !== false) {
1417
+			$helo = gethostname();
1418
+	} elseif (function_exists('php_uname')) {
1419
+			$helo = php_uname('n');
1420
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1421
+			$helo = $_SERVER['SERVER_NAME'];
1422
+	}
1357 1423
 
1358
-	if (empty($helo))
1359
-		$helo = $modSettings['smtp_host'];
1424
+	if (empty($helo)) {
1425
+			$helo = $modSettings['smtp_host'];
1426
+	}
1360 1427
 
1361 1428
 	// SMTP = 1, SMTP - STARTTLS = 2
1362 1429
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1368,33 +1435,39 @@  discard block
 block discarded – undo
1368 1435
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1369 1436
 			{
1370 1437
 				// Send STARTTLS to enable encryption
1371
-				if (!server_parse('STARTTLS', $socket, '220'))
1372
-					return false;
1438
+				if (!server_parse('STARTTLS', $socket, '220')) {
1439
+									return false;
1440
+				}
1373 1441
 				// Enable the encryption
1374
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1375
-					return false;
1442
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1443
+									return false;
1444
+				}
1376 1445
 				// Send the EHLO command again
1377
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1378
-					return false;
1446
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1447
+									return false;
1448
+				}
1379 1449
 			}
1380 1450
 
1381
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1382
-				return false;
1451
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1452
+							return false;
1453
+			}
1383 1454
 			// Send the username and password, encoded.
1384
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1385
-				return false;
1455
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1456
+							return false;
1457
+			}
1386 1458
 			// The password is already encoded ;)
1387
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1388
-				return false;
1459
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1460
+							return false;
1461
+			}
1462
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1463
+					return false;
1389 1464
 		}
1390
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1391
-			return false;
1392
-	}
1393
-	else
1465
+	} else
1394 1466
 	{
1395 1467
 		// Just say "helo".
1396
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1397
-			return false;
1468
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1469
+					return false;
1470
+		}
1398 1471
 	}
1399 1472
 
1400 1473
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1407,31 +1480,38 @@  discard block
 block discarded – undo
1407 1480
 		// Reset the connection to send another email.
1408 1481
 		if ($i != 0)
1409 1482
 		{
1410
-			if (!server_parse('RSET', $socket, '250'))
1411
-				return false;
1483
+			if (!server_parse('RSET', $socket, '250')) {
1484
+							return false;
1485
+			}
1412 1486
 		}
1413 1487
 
1414 1488
 		// From, to, and then start the data...
1415
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1416
-			return false;
1417
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1418
-			return false;
1419
-		if (!server_parse('DATA', $socket, '354'))
1420
-			return false;
1489
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1490
+					return false;
1491
+		}
1492
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1493
+					return false;
1494
+		}
1495
+		if (!server_parse('DATA', $socket, '354')) {
1496
+					return false;
1497
+		}
1421 1498
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1422
-		if (strlen($mail_to) > 0)
1423
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1499
+		if (strlen($mail_to) > 0) {
1500
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1501
+		}
1424 1502
 		fputs($socket, $headers . "\r\n\r\n");
1425 1503
 		fputs($socket, $message . "\r\n");
1426 1504
 
1427 1505
 		// Send a ., or in other words "end of data".
1428
-		if (!server_parse('.', $socket, '250'))
1429
-			return false;
1506
+		if (!server_parse('.', $socket, '250')) {
1507
+					return false;
1508
+		}
1430 1509
 
1431 1510
 		// Almost done, almost done... don't stop me just yet!
1432 1511
 		@set_time_limit(300);
1433
-		if (function_exists('apache_reset_timeout'))
1434
-			@apache_reset_timeout();
1512
+		if (function_exists('apache_reset_timeout')) {
1513
+					@apache_reset_timeout();
1514
+		}
1435 1515
 	}
1436 1516
 	fputs($socket, 'QUIT' . "\r\n");
1437 1517
 	fclose($socket);
@@ -1455,8 +1535,9 @@  discard block
 block discarded – undo
1455 1535
 {
1456 1536
 	global $txt;
1457 1537
 
1458
-	if ($message !== null)
1459
-		fputs($socket, $message . "\r\n");
1538
+	if ($message !== null) {
1539
+			fputs($socket, $message . "\r\n");
1540
+	}
1460 1541
 
1461 1542
 	// No response yet.
1462 1543
 	$server_response = '';
@@ -1472,8 +1553,9 @@  discard block
 block discarded – undo
1472 1553
 		$response .= $server_response;
1473 1554
 	}
1474 1555
 
1475
-	if ($code === null)
1476
-		return substr($server_response, 0, 3);
1556
+	if ($code === null) {
1557
+			return substr($server_response, 0, 3);
1558
+	}
1477 1559
 
1478 1560
 	if (substr($server_response, 0, 3) != $code)
1479 1561
 	{
@@ -1503,8 +1585,9 @@  discard block
 block discarded – undo
1503 1585
 	// Create a pspell or enchant dictionary resource
1504 1586
 	$dict = spell_init();
1505 1587
 
1506
-	if (!isset($_POST['spellstring']) || !$dict)
1507
-		die;
1588
+	if (!isset($_POST['spellstring']) || !$dict) {
1589
+			die;
1590
+	}
1508 1591
 
1509 1592
 	// Construct a bit of Javascript code.
1510 1593
 	$context['spell_js'] = '
@@ -1522,8 +1605,9 @@  discard block
 block discarded – undo
1522 1605
 		$check_word = explode('|', $alphas[$i]);
1523 1606
 
1524 1607
 		// If the word is a known word, or spelled right...
1525
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1526
-			continue;
1608
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1609
+					continue;
1610
+		}
1527 1611
 
1528 1612
 		// Find the word, and move up the "last occurrence" to here.
1529 1613
 		$found_words = true;
@@ -1537,20 +1621,23 @@  discard block
 block discarded – undo
1537 1621
 		if (!empty($suggestions))
1538 1622
 		{
1539 1623
 			// But first check they aren't going to be censored - no naughty words!
1540
-			foreach ($suggestions as $k => $word)
1541
-				if ($suggestions[$k] != censorText($word))
1624
+			foreach ($suggestions as $k => $word) {
1625
+							if ($suggestions[$k] != censorText($word))
1542 1626
 					unset($suggestions[$k]);
1627
+			}
1543 1628
 
1544
-			if (!empty($suggestions))
1545
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1629
+			if (!empty($suggestions)) {
1630
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1631
+			}
1546 1632
 		}
1547 1633
 
1548 1634
 		$context['spell_js'] .= ']),';
1549 1635
 	}
1550 1636
 
1551 1637
 	// If words were found, take off the last comma.
1552
-	if ($found_words)
1553
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1638
+	if ($found_words) {
1639
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1640
+	}
1554 1641
 
1555 1642
 	$context['spell_js'] .= '
1556 1643
 		);';
@@ -1585,11 +1672,13 @@  discard block
 block discarded – undo
1585 1672
 	global $user_info, $smcFunc;
1586 1673
 
1587 1674
 	// Can't do it if there's no topics.
1588
-	if (empty($topics))
1589
-		return;
1675
+	if (empty($topics)) {
1676
+			return;
1677
+	}
1590 1678
 	// It must be an array - it must!
1591
-	if (!is_array($topics))
1592
-		$topics = array($topics);
1679
+	if (!is_array($topics)) {
1680
+			$topics = array($topics);
1681
+	}
1593 1682
 
1594 1683
 	// Get the subject and body...
1595 1684
 	$result = $smcFunc['db_query']('', '
@@ -1637,14 +1726,15 @@  discard block
 block discarded – undo
1637 1726
 	}
1638 1727
 	$smcFunc['db_free_result']($result);
1639 1728
 
1640
-	if (!empty($task_rows))
1641
-		$smcFunc['db_insert']('',
1729
+	if (!empty($task_rows)) {
1730
+			$smcFunc['db_insert']('',
1642 1731
 			'{db_prefix}background_tasks',
1643 1732
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1644 1733
 			$task_rows,
1645 1734
 			array('id_task')
1646 1735
 		);
1647
-}
1736
+	}
1737
+	}
1648 1738
 
1649 1739
 /**
1650 1740
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1682,9 +1772,9 @@  discard block
 block discarded – undo
1682 1772
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1683 1773
 
1684 1774
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1685
-	if (!$modSettings['postmod_active'])
1686
-		$topicOptions['is_approved'] = true;
1687
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1775
+	if (!$modSettings['postmod_active']) {
1776
+			$topicOptions['is_approved'] = true;
1777
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1688 1778
 	{
1689 1779
 		$request = $smcFunc['db_query']('', '
1690 1780
 			SELECT approved
@@ -1707,8 +1797,7 @@  discard block
 block discarded – undo
1707 1797
 			$posterOptions['id'] = 0;
1708 1798
 			$posterOptions['name'] = $txt['guest_title'];
1709 1799
 			$posterOptions['email'] = '';
1710
-		}
1711
-		elseif ($posterOptions['id'] != $user_info['id'])
1800
+		} elseif ($posterOptions['id'] != $user_info['id'])
1712 1801
 		{
1713 1802
 			$request = $smcFunc['db_query']('', '
1714 1803
 				SELECT member_name, email_address
@@ -1726,12 +1815,11 @@  discard block
 block discarded – undo
1726 1815
 				$posterOptions['id'] = 0;
1727 1816
 				$posterOptions['name'] = $txt['guest_title'];
1728 1817
 				$posterOptions['email'] = '';
1818
+			} else {
1819
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1729 1820
 			}
1730
-			else
1731
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1732 1821
 			$smcFunc['db_free_result']($request);
1733
-		}
1734
-		else
1822
+		} else
1735 1823
 		{
1736 1824
 			$posterOptions['name'] = $user_info['name'];
1737 1825
 			$posterOptions['email'] = $user_info['email'];
@@ -1741,8 +1829,9 @@  discard block
 block discarded – undo
1741 1829
 	if (!empty($modSettings['enable_mentions']))
1742 1830
 	{
1743 1831
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1744
-		if (!empty($msgOptions['mentioned_members']))
1745
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1832
+		if (!empty($msgOptions['mentioned_members'])) {
1833
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1834
+		}
1746 1835
 	}
1747 1836
 
1748 1837
 	// It's do or die time: forget any user aborts!
@@ -1775,12 +1864,13 @@  discard block
 block discarded – undo
1775 1864
 	);
1776 1865
 
1777 1866
 	// Something went wrong creating the message...
1778
-	if (empty($msgOptions['id']))
1779
-		return false;
1867
+	if (empty($msgOptions['id'])) {
1868
+			return false;
1869
+	}
1780 1870
 
1781 1871
 	// Fix the attachments.
1782
-	if (!empty($msgOptions['attachments']))
1783
-		$smcFunc['db_query']('', '
1872
+	if (!empty($msgOptions['attachments'])) {
1873
+			$smcFunc['db_query']('', '
1784 1874
 			UPDATE {db_prefix}attachments
1785 1875
 			SET id_msg = {int:id_msg}
1786 1876
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1789,6 +1879,7 @@  discard block
 block discarded – undo
1789 1879
 				'id_msg' => $msgOptions['id'],
1790 1880
 			)
1791 1881
 		);
1882
+	}
1792 1883
 
1793 1884
 	// What if we want to export new posts out to a CMS?
1794 1885
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1865,20 +1956,23 @@  discard block
 block discarded – undo
1865 1956
 			'id_topic' => $topicOptions['id'],
1866 1957
 			'counter_increment' => 1,
1867 1958
 		);
1868
-		if ($msgOptions['approved'])
1869
-			$topics_columns = array(
1959
+		if ($msgOptions['approved']) {
1960
+					$topics_columns = array(
1870 1961
 				'id_member_updated = {int:poster_id}',
1871 1962
 				'id_last_msg = {int:id_msg}',
1872 1963
 				'num_replies = num_replies + {int:counter_increment}',
1873 1964
 			);
1874
-		else
1875
-			$topics_columns = array(
1965
+		} else {
1966
+					$topics_columns = array(
1876 1967
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1877 1968
 			);
1878
-		if ($topicOptions['lock_mode'] !== null)
1879
-			$topics_columns[] = 'locked = {int:locked}';
1880
-		if ($topicOptions['sticky_mode'] !== null)
1881
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1969
+		}
1970
+		if ($topicOptions['lock_mode'] !== null) {
1971
+					$topics_columns[] = 'locked = {int:locked}';
1972
+		}
1973
+		if ($topicOptions['sticky_mode'] !== null) {
1974
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1975
+		}
1882 1976
 
1883 1977
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1884 1978
 
@@ -1907,8 +2001,8 @@  discard block
 block discarded – undo
1907 2001
 	);
1908 2002
 
1909 2003
 	// Increase the number of posts and topics on the board.
1910
-	if ($msgOptions['approved'])
1911
-		$smcFunc['db_query']('', '
2004
+	if ($msgOptions['approved']) {
2005
+			$smcFunc['db_query']('', '
1912 2006
 			UPDATE {db_prefix}boards
1913 2007
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1914 2008
 			WHERE id_board = {int:id_board}',
@@ -1916,7 +2010,7 @@  discard block
 block discarded – undo
1916 2010
 				'id_board' => $topicOptions['board'],
1917 2011
 			)
1918 2012
 		);
1919
-	else
2013
+	} else
1920 2014
 	{
1921 2015
 		$smcFunc['db_query']('', '
1922 2016
 			UPDATE {db_prefix}boards
@@ -1986,8 +2080,8 @@  discard block
 block discarded – undo
1986 2080
 		}
1987 2081
 	}
1988 2082
 
1989
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1990
-		$smcFunc['db_insert']('',
2083
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2084
+			$smcFunc['db_insert']('',
1991 2085
 			'{db_prefix}background_tasks',
1992 2086
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1993 2087
 			array(
@@ -1999,19 +2093,22 @@  discard block
 block discarded – undo
1999 2093
 			),
2000 2094
 			array('id_task')
2001 2095
 		);
2096
+	}
2002 2097
 
2003 2098
 	// If there's a custom search index, it may need updating...
2004 2099
 	require_once($sourcedir . '/Search.php');
2005 2100
 	$searchAPI = findSearchAPI();
2006
-	if (is_callable(array($searchAPI, 'postCreated')))
2007
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2101
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2102
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2103
+	}
2008 2104
 
2009 2105
 	// Increase the post counter for the user that created the post.
2010 2106
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2011 2107
 	{
2012 2108
 		// Are you the one that happened to create this post?
2013
-		if ($user_info['id'] == $posterOptions['id'])
2014
-			$user_info['posts']++;
2109
+		if ($user_info['id'] == $posterOptions['id']) {
2110
+					$user_info['posts']++;
2111
+		}
2015 2112
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2016 2113
 	}
2017 2114
 
@@ -2019,19 +2116,21 @@  discard block
 block discarded – undo
2019 2116
 	$_SESSION['last_read_topic'] = 0;
2020 2117
 
2021 2118
 	// Better safe than sorry.
2022
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2023
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2119
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2120
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2121
+	}
2024 2122
 
2025 2123
 	// Update all the stats so everyone knows about this new topic and message.
2026 2124
 	updateStats('message', true, $msgOptions['id']);
2027 2125
 
2028 2126
 	// Update the last message on the board assuming it's approved AND the topic is.
2029
-	if ($msgOptions['approved'])
2030
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2127
+	if ($msgOptions['approved']) {
2128
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2129
+	}
2031 2130
 
2032 2131
 	// Queue createPost background notification
2033
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2034
-		$smcFunc['db_insert']('',
2132
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2133
+			$smcFunc['db_insert']('',
2035 2134
 			'{db_prefix}background_tasks',
2036 2135
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2037 2136
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
@@ -2042,6 +2141,7 @@  discard block
 block discarded – undo
2042 2141
 			)), 0),
2043 2142
 			array('id_task')
2044 2143
 		);
2144
+	}
2045 2145
 
2046 2146
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2047 2147
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2068,14 +2168,18 @@  discard block
 block discarded – undo
2068 2168
 
2069 2169
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2070 2170
 	$messages_columns = array();
2071
-	if (isset($posterOptions['name']))
2072
-		$messages_columns['poster_name'] = $posterOptions['name'];
2073
-	if (isset($posterOptions['email']))
2074
-		$messages_columns['poster_email'] = $posterOptions['email'];
2075
-	if (isset($msgOptions['icon']))
2076
-		$messages_columns['icon'] = $msgOptions['icon'];
2077
-	if (isset($msgOptions['subject']))
2078
-		$messages_columns['subject'] = $msgOptions['subject'];
2171
+	if (isset($posterOptions['name'])) {
2172
+			$messages_columns['poster_name'] = $posterOptions['name'];
2173
+	}
2174
+	if (isset($posterOptions['email'])) {
2175
+			$messages_columns['poster_email'] = $posterOptions['email'];
2176
+	}
2177
+	if (isset($msgOptions['icon'])) {
2178
+			$messages_columns['icon'] = $msgOptions['icon'];
2179
+	}
2180
+	if (isset($msgOptions['subject'])) {
2181
+			$messages_columns['subject'] = $msgOptions['subject'];
2182
+	}
2079 2183
 	if (isset($msgOptions['body']))
2080 2184
 	{
2081 2185
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2102,8 +2206,9 @@  discard block
 block discarded – undo
2102 2206
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2103 2207
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2104 2208
 	}
2105
-	if (isset($msgOptions['smileys_enabled']))
2106
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2209
+	if (isset($msgOptions['smileys_enabled'])) {
2210
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2211
+	}
2107 2212
 
2108 2213
 	// Which columns need to be ints?
2109 2214
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2121,23 +2226,27 @@  discard block
 block discarded – undo
2121 2226
 		{
2122 2227
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2123 2228
 
2124
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2125
-				foreach ($match[1] as $i => $oldID)
2229
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2230
+							foreach ($match[1] as $i => $oldID)
2126 2231
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2232
+			}
2127 2233
 
2128
-			if (empty($modSettings['search_custom_index_config']))
2129
-				unset($msgOptions['old_body']);
2234
+			if (empty($modSettings['search_custom_index_config'])) {
2235
+							unset($msgOptions['old_body']);
2236
+			}
2130 2237
 		}
2131 2238
 
2132 2239
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2133 2240
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2134 2241
 
2135 2242
 		// Remove the poster.
2136
-		if (isset($mentions[$user_info['id']]))
2137
-			unset($mentions[$user_info['id']]);
2243
+		if (isset($mentions[$user_info['id']])) {
2244
+					unset($mentions[$user_info['id']]);
2245
+		}
2138 2246
 
2139
-		if (isset($oldmentions[$user_info['id']]))
2140
-			unset($oldmentions[$user_info['id']]);
2247
+		if (isset($oldmentions[$user_info['id']])) {
2248
+					unset($oldmentions[$user_info['id']]);
2249
+		}
2141 2250
 
2142 2251
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2143 2252
 		{
@@ -2167,8 +2276,9 @@  discard block
 block discarded – undo
2167 2276
 	}
2168 2277
 
2169 2278
 	// Nothing to do?
2170
-	if (empty($messages_columns))
2171
-		return true;
2279
+	if (empty($messages_columns)) {
2280
+			return true;
2281
+	}
2172 2282
 
2173 2283
 	// Change the post.
2174 2284
 	$smcFunc['db_query']('', '
@@ -2229,8 +2339,9 @@  discard block
 block discarded – undo
2229 2339
 	// If there's a custom search index, it needs to be modified...
2230 2340
 	require_once($sourcedir . '/Search.php');
2231 2341
 	$searchAPI = findSearchAPI();
2232
-	if (is_callable(array($searchAPI, 'postModified')))
2233
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2342
+	if (is_callable(array($searchAPI, 'postModified'))) {
2343
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2344
+	}
2234 2345
 
2235 2346
 	if (isset($msgOptions['subject']))
2236 2347
 	{
@@ -2244,14 +2355,16 @@  discard block
 block discarded – undo
2244 2355
 				'id_first_msg' => $msgOptions['id'],
2245 2356
 			)
2246 2357
 		);
2247
-		if ($smcFunc['db_num_rows']($request) == 1)
2248
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2358
+		if ($smcFunc['db_num_rows']($request) == 1) {
2359
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2360
+		}
2249 2361
 		$smcFunc['db_free_result']($request);
2250 2362
 	}
2251 2363
 
2252 2364
 	// Finally, if we are setting the approved state we need to do much more work :(
2253
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2254
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2365
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2366
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2367
+	}
2255 2368
 
2256 2369
 	return true;
2257 2370
 }
@@ -2268,11 +2381,13 @@  discard block
 block discarded – undo
2268 2381
 {
2269 2382
 	global $smcFunc;
2270 2383
 
2271
-	if (!is_array($msgs))
2272
-		$msgs = array($msgs);
2384
+	if (!is_array($msgs)) {
2385
+			$msgs = array($msgs);
2386
+	}
2273 2387
 
2274
-	if (empty($msgs))
2275
-		return false;
2388
+	if (empty($msgs)) {
2389
+			return false;
2390
+	}
2276 2391
 
2277 2392
 	// May as well start at the beginning, working out *what* we need to change.
2278 2393
 	$request = $smcFunc['db_query']('', '
@@ -2304,20 +2419,22 @@  discard block
 block discarded – undo
2304 2419
 		$topics[] = $row['id_topic'];
2305 2420
 
2306 2421
 		// Ensure our change array exists already.
2307
-		if (!isset($topic_changes[$row['id_topic']]))
2308
-			$topic_changes[$row['id_topic']] = array(
2422
+		if (!isset($topic_changes[$row['id_topic']])) {
2423
+					$topic_changes[$row['id_topic']] = array(
2309 2424
 				'id_last_msg' => $row['id_last_msg'],
2310 2425
 				'approved' => $row['topic_approved'],
2311 2426
 				'replies' => 0,
2312 2427
 				'unapproved_posts' => 0,
2313 2428
 			);
2314
-		if (!isset($board_changes[$row['id_board']]))
2315
-			$board_changes[$row['id_board']] = array(
2429
+		}
2430
+		if (!isset($board_changes[$row['id_board']])) {
2431
+					$board_changes[$row['id_board']] = array(
2316 2432
 				'posts' => 0,
2317 2433
 				'topics' => 0,
2318 2434
 				'unapproved_posts' => 0,
2319 2435
 				'unapproved_topics' => 0,
2320 2436
 			);
2437
+		}
2321 2438
 
2322 2439
 		// If it's the first message then the topic state changes!
2323 2440
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2338,14 +2455,13 @@  discard block
 block discarded – undo
2338 2455
 				'poster' => $row['id_member'],
2339 2456
 				'new_topic' => true,
2340 2457
 			);
2341
-		}
2342
-		else
2458
+		} else
2343 2459
 		{
2344 2460
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2345 2461
 
2346 2462
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2347
-			if ($row['id_msg'] > $row['id_last_msg'])
2348
-				$notification_posts[$row['id_topic']] = array(
2463
+			if ($row['id_msg'] > $row['id_last_msg']) {
2464
+							$notification_posts[$row['id_topic']] = array(
2349 2465
 					'id' => $row['id_msg'],
2350 2466
 					'body' => $row['body'],
2351 2467
 					'subject' => $row['subject'],
@@ -2356,28 +2472,33 @@  discard block
 block discarded – undo
2356 2472
 					'new_topic' => false,
2357 2473
 					'msg' => $row['id_msg'],
2358 2474
 				);
2475
+			}
2359 2476
 		}
2360 2477
 
2361 2478
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2362
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2363
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2479
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2480
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2481
+		}
2364 2482
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2365
-		elseif (!$approve)
2366
-			// Default to the first message and then we'll override in a bit ;)
2483
+		elseif (!$approve) {
2484
+					// Default to the first message and then we'll override in a bit ;)
2367 2485
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2486
+		}
2368 2487
 
2369 2488
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2370 2489
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2371 2490
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2372 2491
 
2373 2492
 		// Post count for the user?
2374
-		if ($row['id_member'] && empty($row['count_posts']))
2375
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2493
+		if ($row['id_member'] && empty($row['count_posts'])) {
2494
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2495
+		}
2376 2496
 	}
2377 2497
 	$smcFunc['db_free_result']($request);
2378 2498
 
2379
-	if (empty($msgs))
2380
-		return;
2499
+	if (empty($msgs)) {
2500
+			return;
2501
+	}
2381 2502
 
2382 2503
 	// Now we have the differences make the changes, first the easy one.
2383 2504
 	$smcFunc['db_query']('', '
@@ -2404,14 +2525,15 @@  discard block
 block discarded – undo
2404 2525
 				'approved' => 1,
2405 2526
 			)
2406 2527
 		);
2407
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2408
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2528
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2529
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2530
+		}
2409 2531
 		$smcFunc['db_free_result']($request);
2410 2532
 	}
2411 2533
 
2412 2534
 	// ... next the topics...
2413
-	foreach ($topic_changes as $id => $changes)
2414
-		$smcFunc['db_query']('', '
2535
+	foreach ($topic_changes as $id => $changes) {
2536
+			$smcFunc['db_query']('', '
2415 2537
 			UPDATE {db_prefix}topics
2416 2538
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2417 2539
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2424,10 +2546,11 @@  discard block
 block discarded – undo
2424 2546
 				'id_topic' => $id,
2425 2547
 			)
2426 2548
 		);
2549
+	}
2427 2550
 
2428 2551
 	// ... finally the boards...
2429
-	foreach ($board_changes as $id => $changes)
2430
-		$smcFunc['db_query']('', '
2552
+	foreach ($board_changes as $id => $changes) {
2553
+			$smcFunc['db_query']('', '
2431 2554
 			UPDATE {db_prefix}boards
2432 2555
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2433 2556
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2440,13 +2563,14 @@  discard block
 block discarded – undo
2440 2563
 				'id_board' => $id,
2441 2564
 			)
2442 2565
 		);
2566
+	}
2443 2567
 
2444 2568
 	// Finally, least importantly, notifications!
2445 2569
 	if ($approve)
2446 2570
 	{
2447 2571
 		$task_rows = array();
2448
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2449
-			$task_rows[] = array(
2572
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2573
+					$task_rows[] = array(
2450 2574
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
2451 2575
 					'msgOptions' => array(
2452 2576
 						'id' => $topic['msg'],
@@ -2464,14 +2588,16 @@  discard block
 block discarded – undo
2464 2588
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2465 2589
 				)), 0
2466 2590
 			);
2591
+		}
2467 2592
 
2468
-		if ($notify)
2469
-			$smcFunc['db_insert']('',
2593
+		if ($notify) {
2594
+					$smcFunc['db_insert']('',
2470 2595
 				'{db_prefix}background_tasks',
2471 2596
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2472 2597
 				$task_rows,
2473 2598
 				array('id_task')
2474 2599
 			);
2600
+		}
2475 2601
 
2476 2602
 		$smcFunc['db_query']('', '
2477 2603
 			DELETE FROM {db_prefix}approval_queue
@@ -2487,8 +2613,9 @@  discard block
 block discarded – undo
2487 2613
 	else
2488 2614
 	{
2489 2615
 		$msgInserts = array();
2490
-		foreach ($msgs as $msg)
2491
-			$msgInserts[] = array($msg);
2616
+		foreach ($msgs as $msg) {
2617
+					$msgInserts[] = array($msg);
2618
+		}
2492 2619
 
2493 2620
 		$smcFunc['db_insert']('ignore',
2494 2621
 			'{db_prefix}approval_queue',
@@ -2502,9 +2629,10 @@  discard block
 block discarded – undo
2502 2629
 	updateLastMessages(array_keys($board_changes));
2503 2630
 
2504 2631
 	// Post count for the members?
2505
-	if (!empty($member_post_changes))
2506
-		foreach ($member_post_changes as $id_member => $count_change)
2632
+	if (!empty($member_post_changes)) {
2633
+			foreach ($member_post_changes as $id_member => $count_change)
2507 2634
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2635
+	}
2508 2636
 
2509 2637
 	return true;
2510 2638
 }
@@ -2521,11 +2649,13 @@  discard block
 block discarded – undo
2521 2649
 {
2522 2650
 	global $smcFunc;
2523 2651
 
2524
-	if (!is_array($topics))
2525
-		$topics = array($topics);
2652
+	if (!is_array($topics)) {
2653
+			$topics = array($topics);
2654
+	}
2526 2655
 
2527
-	if (empty($topics))
2528
-		return false;
2656
+	if (empty($topics)) {
2657
+			return false;
2658
+	}
2529 2659
 
2530 2660
 	$approve_type = $approve ? 0 : 1;
2531 2661
 
@@ -2541,8 +2671,9 @@  discard block
 block discarded – undo
2541 2671
 		)
2542 2672
 	);
2543 2673
 	$msgs = array();
2544
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2545
-		$msgs[] = $row['id_msg'];
2674
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2675
+			$msgs[] = $row['id_msg'];
2676
+	}
2546 2677
 	$smcFunc['db_free_result']($request);
2547 2678
 
2548 2679
 	return approvePosts($msgs, $approve);
@@ -2565,11 +2696,13 @@  discard block
 block discarded – undo
2565 2696
 	global $board_info, $board, $smcFunc;
2566 2697
 
2567 2698
 	// Please - let's be sane.
2568
-	if (empty($setboards))
2569
-		return false;
2699
+	if (empty($setboards)) {
2700
+			return false;
2701
+	}
2570 2702
 
2571
-	if (!is_array($setboards))
2572
-		$setboards = array($setboards);
2703
+	if (!is_array($setboards)) {
2704
+			$setboards = array($setboards);
2705
+	}
2573 2706
 
2574 2707
 	// If we don't know the id_msg we need to find it.
2575 2708
 	if (!$id_msg)
@@ -2587,15 +2720,16 @@  discard block
 block discarded – undo
2587 2720
 			)
2588 2721
 		);
2589 2722
 		$lastMsg = array();
2590
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2591
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2723
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2724
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2725
+		}
2592 2726
 		$smcFunc['db_free_result']($request);
2593
-	}
2594
-	else
2727
+	} else
2595 2728
 	{
2596 2729
 		// Just to note - there should only be one board passed if we are doing this.
2597
-		foreach ($setboards as $id_board)
2598
-			$lastMsg[$id_board] = $id_msg;
2730
+		foreach ($setboards as $id_board) {
2731
+					$lastMsg[$id_board] = $id_msg;
2732
+		}
2599 2733
 	}
2600 2734
 
2601 2735
 	$parent_boards = array();
@@ -2610,10 +2744,11 @@  discard block
 block discarded – undo
2610 2744
 			$lastModified[$id_board] = 0;
2611 2745
 		}
2612 2746
 
2613
-		if (!empty($board) && $id_board == $board)
2614
-			$parents = $board_info['parent_boards'];
2615
-		else
2616
-			$parents = getBoardParents($id_board);
2747
+		if (!empty($board) && $id_board == $board) {
2748
+					$parents = $board_info['parent_boards'];
2749
+		} else {
2750
+					$parents = getBoardParents($id_board);
2751
+		}
2617 2752
 
2618 2753
 		// Ignore any parents on the top child level.
2619 2754
 		// @todo Why?
@@ -2622,10 +2757,11 @@  discard block
 block discarded – undo
2622 2757
 			if ($parent['level'] != 0)
2623 2758
 			{
2624 2759
 				// If we're already doing this one as a board, is this a higher last modified?
2625
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2626
-					$lastModified[$id] = $lastModified[$id_board];
2627
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2628
-					$parent_boards[$id] = $lastModified[$id_board];
2760
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2761
+									$lastModified[$id] = $lastModified[$id_board];
2762
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2763
+									$parent_boards[$id] = $lastModified[$id_board];
2764
+				}
2629 2765
 			}
2630 2766
 		}
2631 2767
 	}
@@ -2638,23 +2774,24 @@  discard block
 block discarded – undo
2638 2774
 	// Finally, to save on queries make the changes...
2639 2775
 	foreach ($parent_boards as $id => $msg)
2640 2776
 	{
2641
-		if (!isset($parent_updates[$msg]))
2642
-			$parent_updates[$msg] = array($id);
2643
-		else
2644
-			$parent_updates[$msg][] = $id;
2777
+		if (!isset($parent_updates[$msg])) {
2778
+					$parent_updates[$msg] = array($id);
2779
+		} else {
2780
+					$parent_updates[$msg][] = $id;
2781
+		}
2645 2782
 	}
2646 2783
 
2647 2784
 	foreach ($lastMsg as $id => $msg)
2648 2785
 	{
2649
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2650
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2786
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2787
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2651 2788
 				'id' => $msg,
2652 2789
 				'updated' => $lastModified[$id],
2653 2790
 				'boards' => array($id)
2654 2791
 			);
2655
-
2656
-		else
2657
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2792
+		} else {
2793
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2794
+		}
2658 2795
 	}
2659 2796
 
2660 2797
 	// Now commit the changes!
@@ -2746,11 +2883,13 @@  discard block
 block discarded – undo
2746 2883
 	global $txt, $mbname, $scripturl, $settings;
2747 2884
 
2748 2885
 	// First things first, load up the email templates language file, if we need to.
2749
-	if ($loadLang)
2750
-		loadLanguage('EmailTemplates', $lang);
2886
+	if ($loadLang) {
2887
+			loadLanguage('EmailTemplates', $lang);
2888
+	}
2751 2889
 
2752
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2753
-		fatal_lang_error('email_no_template', 'template', array($template));
2890
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2891
+			fatal_lang_error('email_no_template', 'template', array($template));
2892
+	}
2754 2893
 
2755 2894
 	$ret = array(
2756 2895
 		'subject' => $txt[$template . '_subject'],
@@ -2800,17 +2939,18 @@  discard block
 block discarded – undo
2800 2939
 function user_info_callback($matches)
2801 2940
 {
2802 2941
 	global $user_info;
2803
-	if (empty($matches[1]))
2804
-		return '';
2942
+	if (empty($matches[1])) {
2943
+			return '';
2944
+	}
2805 2945
 
2806 2946
 	$use_ref = true;
2807 2947
 	$ref = &$user_info;
2808 2948
 
2809 2949
 	foreach (explode('.', $matches[1]) as $index)
2810 2950
 	{
2811
-		if ($use_ref && isset($ref[$index]))
2812
-			$ref = &$ref[$index];
2813
-		else
2951
+		if ($use_ref && isset($ref[$index])) {
2952
+					$ref = &$ref[$index];
2953
+		} else
2814 2954
 		{
2815 2955
 			$use_ref = false;
2816 2956
 			break;
@@ -2847,8 +2987,7 @@  discard block
 block discarded – undo
2847 2987
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2848 2988
 		{
2849 2989
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2850
-		}
2851
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2990
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2852 2991
 		{
2853 2992
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2854 2993
 		}
@@ -2858,8 +2997,7 @@  discard block
 block discarded – undo
2858 2997
 		{
2859 2998
 			$context['provider'] = 'enchant';
2860 2999
 			return $enchant_link;
2861
-		}
2862
-		else
3000
+		} else
2863 3001
 		{
2864 3002
 			// Free up any resources used...
2865 3003
 			@enchant_broker_free($context['enchant_broker']);
@@ -2880,8 +3018,9 @@  discard block
 block discarded – undo
2880 3018
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2881 3019
 
2882 3020
 		// Most people don't have anything but English installed... So we use English as a last resort.
2883
-		if (!$pspell_link)
2884
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3021
+		if (!$pspell_link) {
3022
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3023
+		}
2885 3024
 
2886 3025
 		error_reporting($old);
2887 3026
 		ob_end_clean();
@@ -2921,8 +3060,7 @@  discard block
 block discarded – undo
2921 3060
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2922 3061
 		}
2923 3062
 		return enchant_dict_check($dict, $word);
2924
-	}
2925
-	elseif ($context['provider'] == 'pspell')
3063
+	} elseif ($context['provider'] == 'pspell')
2926 3064
 	{
2927 3065
 		return pspell_check($dict, $word);
2928 3066
 	}
@@ -2958,13 +3096,11 @@  discard block
 block discarded – undo
2958 3096
 			}
2959 3097
 
2960 3098
 			return $suggestions;
2961
-		}
2962
-		else
3099
+		} else
2963 3100
 		{
2964 3101
 			return enchant_dict_suggest($dict, $word);
2965 3102
 		}
2966
-	}
2967
-	elseif ($context['provider'] == 'pspell')
3103
+	} elseif ($context['provider'] == 'pspell')
2968 3104
 	{
2969 3105
 		return pspell_suggest($dict, $word);
2970 3106
 	}
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +784 added lines, -593 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
 
@@ -403,27 +420,28 @@  discard block
 block discarded – undo
403 420
 				break;
404 421
 			}
405 422
 		}
423
+	} else {
424
+			$id_member = 0;
406 425
 	}
407
-	else
408
-		$id_member = 0;
409 426
 
410 427
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
411 428
 	{
412 429
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
413 430
 
414
-		if (empty($cookie_data))
415
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
431
+		if (empty($cookie_data)) {
432
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
433
+		}
416 434
 
417 435
 		list ($id_member, $password) = $cookie_data;
418 436
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
419
-	}
420
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
437
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
421 438
 	{
422 439
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
423 440
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
424 441
 
425
-		if (empty($cookie_data))
426
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		if (empty($cookie_data)) {
443
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
444
+		}
427 445
 
428 446
 		list ($id_member, $password, $login_span) = $cookie_data;
429 447
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -448,30 +466,34 @@  discard block
 block discarded – undo
448 466
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
449 467
 			$smcFunc['db_free_result']($request);
450 468
 
451
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
452
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
469
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
470
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
471
+			}
453 472
 
454
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
455
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
474
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
475
+			}
456 476
 		}
457 477
 
458 478
 		// Did we find 'im?  If not, junk it.
459 479
 		if (!empty($user_settings))
460 480
 		{
461 481
 			// As much as the password should be right, we can assume the integration set things up.
462
-			if (!empty($already_verified) && $already_verified === true)
463
-				$check = true;
482
+			if (!empty($already_verified) && $already_verified === true) {
483
+							$check = true;
484
+			}
464 485
 			// SHA-512 hash should be 128 characters long.
465
-			elseif (strlen($password) == 128)
466
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
467
-			else
468
-				$check = false;
486
+			elseif (strlen($password) == 128) {
487
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
488
+			} else {
489
+							$check = false;
490
+			}
469 491
 
470 492
 			// Wrong password or not activated - either way, you're going nowhere.
471 493
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
494
+		} else {
495
+					$id_member = 0;
472 496
 		}
473
-		else
474
-			$id_member = 0;
475 497
 
476 498
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
477 499
 		if (!$id_member)
@@ -500,8 +522,9 @@  discard block
 block discarded – undo
500 522
 
501 523
 					list ($tfamember, $tfasecret) = $tfa_data;
502 524
 
503
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
504
-						$tfasecret = null;
525
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
526
+											$tfasecret = null;
527
+					}
505 528
 				}
506 529
 
507 530
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -521,10 +544,12 @@  discard block
 block discarded – undo
521 544
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
522 545
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
523 546
 		{
524
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
547
+			if ($modSettings['tfa_mode'] == 2) {
548
+				//only do this if we are just forcing SOME membergroups
525 549
 			{
526 550
 				//Build an array of ALL user membergroups.
527 551
 				$full_groups = array($user_settings['id_group']);
552
+			}
528 553
 				if (!empty($user_settings['additional_groups']))
529 554
 				{
530 555
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -544,15 +569,17 @@  discard block
 block discarded – undo
544 569
 				);
545 570
 				$row = $smcFunc['db_fetch_assoc']($request);
546 571
 				$smcFunc['db_free_result']($request);
572
+			} else {
573
+							$row['total'] = 1;
547 574
 			}
548
-			else
549
-				$row['total'] = 1; //simplifies logics in the next "if"
575
+			//simplifies logics in the next "if"
550 576
 
551 577
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
552 578
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
553 579
 
554
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
555
-				redirectexit('action=profile;area=tfasetup;forced');
580
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
581
+							redirectexit('action=profile;area=tfasetup;forced');
582
+			}
556 583
 		}
557 584
 	}
558 585
 
@@ -589,33 +616,37 @@  discard block
 block discarded – undo
589 616
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
590 617
 				$user_settings['last_login'] = time();
591 618
 
592
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
593
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
619
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
620
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
621
+				}
594 622
 
595
-				if (!empty($modSettings['cache_enable']))
596
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
623
+				if (!empty($modSettings['cache_enable'])) {
624
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
625
+				}
597 626
 			}
627
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
628
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
598 629
 		}
599
-		elseif (empty($_SESSION['id_msg_last_visit']))
600
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
601 630
 
602 631
 		$username = $user_settings['member_name'];
603 632
 
604
-		if (empty($user_settings['additional_groups']))
605
-			$user_info = array(
633
+		if (empty($user_settings['additional_groups'])) {
634
+					$user_info = array(
606 635
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
607 636
 			);
608
-		else
609
-			$user_info = array(
637
+		} else {
638
+					$user_info = array(
610 639
 				'groups' => array_merge(
611 640
 					array($user_settings['id_group'], $user_settings['id_post_group']),
612 641
 					explode(',', $user_settings['additional_groups'])
613 642
 				)
614 643
 			);
644
+		}
615 645
 
616 646
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
617
-		foreach ($user_info['groups'] as $k => $v)
618
-			$user_info['groups'][$k] = (int) $v;
647
+		foreach ($user_info['groups'] as $k => $v) {
648
+					$user_info['groups'][$k] = (int) $v;
649
+		}
619 650
 
620 651
 		// This is a logged in user, so definitely not a spider.
621 652
 		$user_info['possibly_robot'] = false;
@@ -629,8 +660,7 @@  discard block
 block discarded – undo
629 660
 			$time_system = new DateTime('now', $tz_system);
630 661
 			$time_user = new DateTime('now', $tz_user);
631 662
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
632
-		}
633
-		else
663
+		} else
634 664
 		{
635 665
 			// !!! Compatibility.
636 666
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -644,8 +674,9 @@  discard block
 block discarded – undo
644 674
 		$user_info = array('groups' => array(-1));
645 675
 		$user_settings = array();
646 676
 
647
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
648
-			$_COOKIE[$cookiename] = '';
677
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
678
+					$_COOKIE[$cookiename] = '';
679
+		}
649 680
 
650 681
 		// Expire the 2FA cookie
651 682
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -662,19 +693,20 @@  discard block
 block discarded – undo
662 693
 		}
663 694
 
664 695
 		// Create a login token if it doesn't exist yet.
665
-		if (!isset($_SESSION['token']['post-login']))
666
-			createToken('login');
667
-		else
668
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
696
+		if (!isset($_SESSION['token']['post-login'])) {
697
+					createToken('login');
698
+		} else {
699
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
700
+		}
669 701
 
670 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
671 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
672 704
 		{
673 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
674 706
 			$user_info['possibly_robot'] = SpiderCheck();
707
+		} elseif (!empty($modSettings['spider_mode'])) {
708
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
675 709
 		}
676
-		elseif (!empty($modSettings['spider_mode']))
677
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
678 710
 		// If we haven't turned on proper spider hunts then have a guess!
679 711
 		else
680 712
 		{
@@ -722,8 +754,9 @@  discard block
 block discarded – undo
722 754
 	$user_info['groups'] = array_unique($user_info['groups']);
723 755
 
724 756
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
725
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
726
-		unset($user_info['ignoreboards'][$tmp]);
757
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
758
+			unset($user_info['ignoreboards'][$tmp]);
759
+	}
727 760
 
728 761
 	// Allow the user to change their language.
729 762
 	if (!empty($modSettings['userLanguage']))
@@ -736,13 +769,14 @@  discard block
 block discarded – undo
736 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
737 770
 
738 771
 			// Make it permanent for members.
739
-			if (!empty($user_info['id']))
740
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
741
-			else
742
-				$_SESSION['language'] = $user_info['language'];
772
+			if (!empty($user_info['id'])) {
773
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
774
+			} else {
775
+							$_SESSION['language'] = $user_info['language'];
776
+			}
777
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
778
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
743 779
 		}
744
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
745
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
746 780
 	}
747 781
 
748 782
 	$temp = build_query_board($user_info['id']);
@@ -805,9 +839,9 @@  discard block
 block discarded – undo
805 839
 		}
806 840
 
807 841
 		// Remember redirection is the key to avoiding fallout from your bosses.
808
-		if (!empty($topic))
809
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
810
-		else
842
+		if (!empty($topic)) {
843
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
844
+		} else
811 845
 		{
812 846
 			loadPermissions();
813 847
 			loadTheme();
@@ -825,10 +859,11 @@  discard block
 block discarded – undo
825 859
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
826 860
 	{
827 861
 		// @todo SLOW?
828
-		if (!empty($topic))
829
-			$temp = cache_get_data('topic_board-' . $topic, 120);
830
-		else
831
-			$temp = cache_get_data('board-' . $board, 120);
862
+		if (!empty($topic)) {
863
+					$temp = cache_get_data('topic_board-' . $topic, 120);
864
+		} else {
865
+					$temp = cache_get_data('board-' . $board, 120);
866
+		}
832 867
 
833 868
 		if (!empty($temp))
834 869
 		{
@@ -866,8 +901,9 @@  discard block
 block discarded – undo
866 901
 			$row = $smcFunc['db_fetch_assoc']($request);
867 902
 
868 903
 			// Set the current board.
869
-			if (!empty($row['id_board']))
870
-				$board = $row['id_board'];
904
+			if (!empty($row['id_board'])) {
905
+							$board = $row['id_board'];
906
+			}
871 907
 
872 908
 			// Basic operating information. (globals... :/)
873 909
 			$board_info = array(
@@ -903,21 +939,23 @@  discard block
 block discarded – undo
903 939
 
904 940
 			do
905 941
 			{
906
-				if (!empty($row['id_moderator']))
907
-					$board_info['moderators'][$row['id_moderator']] = array(
942
+				if (!empty($row['id_moderator'])) {
943
+									$board_info['moderators'][$row['id_moderator']] = array(
908 944
 						'id' => $row['id_moderator'],
909 945
 						'name' => $row['real_name'],
910 946
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
911 947
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
912 948
 					);
949
+				}
913 950
 
914
-				if (!empty($row['id_moderator_group']))
915
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
951
+				if (!empty($row['id_moderator_group'])) {
952
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
916 953
 						'id' => $row['id_moderator_group'],
917 954
 						'name' => $row['group_name'],
918 955
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
919 956
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
920 957
 					);
958
+				}
921 959
 			}
922 960
 			while ($row = $smcFunc['db_fetch_assoc']($request));
923 961
 
@@ -949,12 +987,12 @@  discard block
 block discarded – undo
949 987
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
950 988
 			{
951 989
 				// @todo SLOW?
952
-				if (!empty($topic))
953
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
990
+				if (!empty($topic)) {
991
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
992
+				}
954 993
 				cache_put_data('board-' . $board, $board_info, 120);
955 994
 			}
956
-		}
957
-		else
995
+		} else
958 996
 		{
959 997
 			// Otherwise the topic is invalid, there are no moderators, etc.
960 998
 			$board_info = array(
@@ -968,8 +1006,9 @@  discard block
 block discarded – undo
968 1006
 		$smcFunc['db_free_result']($request);
969 1007
 	}
970 1008
 
971
-	if (!empty($topic))
972
-		$_GET['board'] = (int) $board;
1009
+	if (!empty($topic)) {
1010
+			$_GET['board'] = (int) $board;
1011
+	}
973 1012
 
974 1013
 	if (!empty($board))
975 1014
 	{
@@ -979,10 +1018,12 @@  discard block
 block discarded – undo
979 1018
 		// Now check if the user is a moderator.
980 1019
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
981 1020
 
982
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
983
-			$board_info['error'] = 'access';
984
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
985
-			$board_info['error'] = 'access';
1021
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1022
+					$board_info['error'] = 'access';
1023
+		}
1024
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1025
+					$board_info['error'] = 'access';
1026
+		}
986 1027
 
987 1028
 		// Build up the linktree.
988 1029
 		$context['linktree'] = array_merge(
@@ -1005,8 +1046,9 @@  discard block
 block discarded – undo
1005 1046
 	$context['current_board'] = $board;
1006 1047
 
1007 1048
 	// No posting in redirection boards!
1008
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1009
-		$board_info['error'] == 'post_in_redirect';
1049
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1050
+			$board_info['error'] == 'post_in_redirect';
1051
+	}
1010 1052
 
1011 1053
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1012 1054
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1032,24 +1074,23 @@  discard block
 block discarded – undo
1032 1074
 			ob_end_clean();
1033 1075
 			header('HTTP/1.1 403 Forbidden');
1034 1076
 			die;
1035
-		}
1036
-		elseif ($board_info['error'] == 'post_in_redirect')
1077
+		} elseif ($board_info['error'] == 'post_in_redirect')
1037 1078
 		{
1038 1079
 			// Slightly different error message here...
1039 1080
 			fatal_lang_error('cannot_post_redirect', false);
1040
-		}
1041
-		elseif ($user_info['is_guest'])
1081
+		} elseif ($user_info['is_guest'])
1042 1082
 		{
1043 1083
 			loadLanguage('Errors');
1044 1084
 			is_not_guest($txt['topic_gone']);
1085
+		} else {
1086
+					fatal_lang_error('topic_gone', false);
1045 1087
 		}
1046
-		else
1047
-			fatal_lang_error('topic_gone', false);
1048 1088
 	}
1049 1089
 
1050
-	if ($user_info['is_mod'])
1051
-		$user_info['groups'][] = 3;
1052
-}
1090
+	if ($user_info['is_mod']) {
1091
+			$user_info['groups'][] = 3;
1092
+	}
1093
+	}
1053 1094
 
1054 1095
 /**
1055 1096
  * Load this user's permissions.
@@ -1070,8 +1111,9 @@  discard block
 block discarded – undo
1070 1111
 		asort($cache_groups);
1071 1112
 		$cache_groups = implode(',', $cache_groups);
1072 1113
 		// If it's a spider then cache it different.
1073
-		if ($user_info['possibly_robot'])
1074
-			$cache_groups .= '-spider';
1114
+		if ($user_info['possibly_robot']) {
1115
+					$cache_groups .= '-spider';
1116
+		}
1075 1117
 
1076 1118
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1077 1119
 		{
@@ -1079,9 +1121,9 @@  discard block
 block discarded – undo
1079 1121
 			banPermissions();
1080 1122
 
1081 1123
 			return;
1124
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1125
+					list ($user_info['permissions'], $removals) = $temp;
1082 1126
 		}
1083
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1084
-			list ($user_info['permissions'], $removals) = $temp;
1085 1127
 	}
1086 1128
 
1087 1129
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1103,23 +1145,26 @@  discard block
 block discarded – undo
1103 1145
 		$removals = array();
1104 1146
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1105 1147
 		{
1106
-			if (empty($row['add_deny']))
1107
-				$removals[] = $row['permission'];
1108
-			else
1109
-				$user_info['permissions'][] = $row['permission'];
1148
+			if (empty($row['add_deny'])) {
1149
+							$removals[] = $row['permission'];
1150
+			} else {
1151
+							$user_info['permissions'][] = $row['permission'];
1152
+			}
1110 1153
 		}
1111 1154
 		$smcFunc['db_free_result']($request);
1112 1155
 
1113
-		if (isset($cache_groups))
1114
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1156
+		if (isset($cache_groups)) {
1157
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1158
+		}
1115 1159
 	}
1116 1160
 
1117 1161
 	// Get the board permissions.
1118 1162
 	if (!empty($board))
1119 1163
 	{
1120 1164
 		// Make sure the board (if any) has been loaded by loadBoard().
1121
-		if (!isset($board_info['profile']))
1122
-			fatal_lang_error('no_board');
1165
+		if (!isset($board_info['profile'])) {
1166
+					fatal_lang_error('no_board');
1167
+		}
1123 1168
 
1124 1169
 		$request = $smcFunc['db_query']('', '
1125 1170
 			SELECT permission, add_deny
@@ -1135,20 +1180,23 @@  discard block
 block discarded – undo
1135 1180
 		);
1136 1181
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1137 1182
 		{
1138
-			if (empty($row['add_deny']))
1139
-				$removals[] = $row['permission'];
1140
-			else
1141
-				$user_info['permissions'][] = $row['permission'];
1183
+			if (empty($row['add_deny'])) {
1184
+							$removals[] = $row['permission'];
1185
+			} else {
1186
+							$user_info['permissions'][] = $row['permission'];
1187
+			}
1142 1188
 		}
1143 1189
 		$smcFunc['db_free_result']($request);
1144 1190
 	}
1145 1191
 
1146 1192
 	// Remove all the permissions they shouldn't have ;).
1147
-	if (!empty($modSettings['permission_enable_deny']))
1148
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1193
+	if (!empty($modSettings['permission_enable_deny'])) {
1194
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1195
+	}
1149 1196
 
1150
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1151
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1197
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1198
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1199
+	}
1152 1200
 
1153 1201
 	// Banned?  Watch, don't touch..
1154 1202
 	banPermissions();
@@ -1160,17 +1208,18 @@  discard block
 block discarded – undo
1160 1208
 		{
1161 1209
 			require_once($sourcedir . '/Subs-Auth.php');
1162 1210
 			rebuildModCache();
1211
+		} else {
1212
+					$user_info['mod_cache'] = $_SESSION['mc'];
1163 1213
 		}
1164
-		else
1165
-			$user_info['mod_cache'] = $_SESSION['mc'];
1166 1214
 
1167 1215
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1168 1216
 		// For example this drastically simplifies certain changes to the profile area.
1169 1217
 		$user_info['permissions'][] = 'is_not_guest';
1170 1218
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1171 1219
 		$user_info['permissions'][] = 'profile_view_own';
1172
-		if (in_array('profile_view', $user_info['permissions']))
1173
-			$user_info['permissions'][] = 'profile_view_any';
1220
+		if (in_array('profile_view', $user_info['permissions'])) {
1221
+					$user_info['permissions'][] = 'profile_view_any';
1222
+		}
1174 1223
 	}
1175 1224
 }
1176 1225
 
@@ -1188,8 +1237,9 @@  discard block
 block discarded – undo
1188 1237
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1189 1238
 
1190 1239
 	// Can't just look for no users :P.
1191
-	if (empty($users))
1192
-		return array();
1240
+	if (empty($users)) {
1241
+			return array();
1242
+	}
1193 1243
 
1194 1244
 	// Pass the set value
1195 1245
 	$context['loadMemberContext_set'] = $set;
@@ -1204,8 +1254,9 @@  discard block
 block discarded – undo
1204 1254
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1205 1255
 		{
1206 1256
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1207
-			if ($data == null)
1208
-				continue;
1257
+			if ($data == null) {
1258
+							continue;
1259
+			}
1209 1260
 
1210 1261
 			$loaded_ids[] = $data['id_member'];
1211 1262
 			$user_profile[$data['id_member']] = $data;
@@ -1272,16 +1323,19 @@  discard block
 block discarded – undo
1272 1323
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1273 1324
 
1274 1325
 			// Take care of proxying avatar if required, do this here for maximum reach
1275
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1276
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1326
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1327
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1328
+			}
1277 1329
 
1278 1330
 			// Keep track of the member's normal member group
1279 1331
 			$row['primary_group'] = $row['member_group'];
1280 1332
 
1281
-			if (isset($row['member_ip']))
1282
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1283
-			if (isset($row['member_ip2']))
1284
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1333
+			if (isset($row['member_ip'])) {
1334
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1335
+			}
1336
+			if (isset($row['member_ip2'])) {
1337
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1338
+			}
1285 1339
 			$new_loaded_ids[] = $row['id_member'];
1286 1340
 			$loaded_ids[] = $row['id_member'];
1287 1341
 			$row['options'] = array();
@@ -1300,8 +1354,9 @@  discard block
 block discarded – undo
1300 1354
 				'loaded_ids' => $new_loaded_ids,
1301 1355
 			)
1302 1356
 		);
1303
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1304
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1357
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1358
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1359
+		}
1305 1360
 		$smcFunc['db_free_result']($request);
1306 1361
 	}
1307 1362
 
@@ -1312,10 +1367,11 @@  discard block
 block discarded – undo
1312 1367
 	{
1313 1368
 		foreach ($loaded_ids as $a_member)
1314 1369
 		{
1315
-			if (!empty($user_profile[$a_member]['additional_groups']))
1316
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1317
-			else
1318
-				$groups = array($user_profile[$a_member]['id_group']);
1370
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1371
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1372
+			} else {
1373
+							$groups = array($user_profile[$a_member]['id_group']);
1374
+			}
1319 1375
 
1320 1376
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1321 1377
 
@@ -1328,8 +1384,9 @@  discard block
 block discarded – undo
1328 1384
 
1329 1385
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1330 1386
 	{
1331
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1332
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1387
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1388
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1389
+		}
1333 1390
 	}
1334 1391
 
1335 1392
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1355,14 +1412,17 @@  discard block
 block discarded – undo
1355 1412
 		foreach ($temp_mods as $id)
1356 1413
 		{
1357 1414
 			// By popular demand, don't show admins or global moderators as moderators.
1358
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1359
-				$user_profile[$id]['member_group'] = $row['member_group'];
1415
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1416
+							$user_profile[$id]['member_group'] = $row['member_group'];
1417
+			}
1360 1418
 
1361 1419
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1362
-			if (!empty($row['icons']))
1363
-				$user_profile[$id]['icons'] = $row['icons'];
1364
-			if (!empty($row['member_group_color']))
1365
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1420
+			if (!empty($row['icons'])) {
1421
+							$user_profile[$id]['icons'] = $row['icons'];
1422
+			}
1423
+			if (!empty($row['member_group_color'])) {
1424
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1425
+			}
1366 1426
 		}
1367 1427
 	}
1368 1428
 
@@ -1384,12 +1444,14 @@  discard block
 block discarded – undo
1384 1444
 	static $loadedLanguages = array();
1385 1445
 
1386 1446
 	// If this person's data is already loaded, skip it.
1387
-	if (isset($dataLoaded[$user]))
1388
-		return true;
1447
+	if (isset($dataLoaded[$user])) {
1448
+			return true;
1449
+	}
1389 1450
 
1390 1451
 	// We can't load guests or members not loaded by loadMemberData()!
1391
-	if ($user == 0)
1392
-		return false;
1452
+	if ($user == 0) {
1453
+			return false;
1454
+	}
1393 1455
 	if (!isset($user_profile[$user]))
1394 1456
 	{
1395 1457
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1415,12 +1477,16 @@  discard block
 block discarded – undo
1415 1477
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1416 1478
 
1417 1479
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1418
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1480
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1481
+		//icon is set and exists
1419 1482
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1420
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1483
+	} elseif (isset($profile['icons'][1])) {
1484
+		//icon is set and doesn't exist, fallback to default
1421 1485
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1422
-	else //not set, bye bye
1486
+	} else {
1487
+		//not set, bye bye
1423 1488
 		$group_icon_url = '';
1489
+	}
1424 1490
 
1425 1491
 	// These minimal values are always loaded
1426 1492
 	$memberContext[$user] = array(
@@ -1439,8 +1505,9 @@  discard block
 block discarded – undo
1439 1505
 	if ($context['loadMemberContext_set'] != 'minimal')
1440 1506
 	{
1441 1507
 		// Go the extra mile and load the user's native language name.
1442
-		if (empty($loadedLanguages))
1443
-			$loadedLanguages = getLanguages();
1508
+		if (empty($loadedLanguages)) {
1509
+					$loadedLanguages = getLanguages();
1510
+		}
1444 1511
 
1445 1512
 		$memberContext[$user] += array(
1446 1513
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1495,31 +1562,33 @@  discard block
 block discarded – undo
1495 1562
 	{
1496 1563
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1497 1564
 		{
1498
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1499
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1500
-			else
1501
-				$image = get_gravatar_url($profile['email_address']);
1502
-		}
1503
-		else
1565
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1566
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1567
+			} else {
1568
+							$image = get_gravatar_url($profile['email_address']);
1569
+			}
1570
+		} else
1504 1571
 		{
1505 1572
 			// So it's stored in the member table?
1506 1573
 			if (!empty($profile['avatar']))
1507 1574
 			{
1508 1575
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1576
+			} elseif (!empty($profile['filename'])) {
1577
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1509 1578
 			}
1510
-			elseif (!empty($profile['filename']))
1511
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1512 1579
 			// Right... no avatar...use the default one
1513
-			else
1514
-				$image = $modSettings['avatar_url'] . '/default.png';
1580
+			else {
1581
+							$image = $modSettings['avatar_url'] . '/default.png';
1582
+			}
1515 1583
 		}
1516
-		if (!empty($image))
1517
-			$memberContext[$user]['avatar'] = array(
1584
+		if (!empty($image)) {
1585
+					$memberContext[$user]['avatar'] = array(
1518 1586
 				'name' => $profile['avatar'],
1519 1587
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1520 1588
 				'href' => $image,
1521 1589
 				'url' => $image,
1522 1590
 			);
1591
+		}
1523 1592
 	}
1524 1593
 
1525 1594
 	// Are we also loading the members custom fields into context?
@@ -1527,35 +1596,41 @@  discard block
 block discarded – undo
1527 1596
 	{
1528 1597
 		$memberContext[$user]['custom_fields'] = array();
1529 1598
 
1530
-		if (!isset($context['display_fields']))
1531
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1599
+		if (!isset($context['display_fields'])) {
1600
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1601
+		}
1532 1602
 
1533 1603
 		foreach ($context['display_fields'] as $custom)
1534 1604
 		{
1535
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1536
-				continue;
1605
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1606
+							continue;
1607
+			}
1537 1608
 
1538 1609
 			$value = $profile['options'][$custom['col_name']];
1539 1610
 
1540 1611
 			// Don't show the "disabled" option for the "gender" field.
1541
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1542
-				continue;
1612
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1613
+							continue;
1614
+			}
1543 1615
 
1544 1616
 			// BBC?
1545
-			if ($custom['bbc'])
1546
-				$value = parse_bbc($value);
1617
+			if ($custom['bbc']) {
1618
+							$value = parse_bbc($value);
1619
+			}
1547 1620
 			// ... or checkbox?
1548
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1549
-				$value = $value ? $txt['yes'] : $txt['no'];
1621
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1622
+							$value = $value ? $txt['yes'] : $txt['no'];
1623
+			}
1550 1624
 
1551 1625
 			// Enclosing the user input within some other text?
1552
-			if (!empty($custom['enclose']))
1553
-				$value = strtr($custom['enclose'], array(
1626
+			if (!empty($custom['enclose'])) {
1627
+							$value = strtr($custom['enclose'], array(
1554 1628
 					'{SCRIPTURL}' => $scripturl,
1555 1629
 					'{IMAGES_URL}' => $settings['images_url'],
1556 1630
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1557 1631
 					'{INPUT}' => $value,
1558 1632
 				));
1633
+			}
1559 1634
 
1560 1635
 			$memberContext[$user]['custom_fields'][] = array(
1561 1636
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1582,8 +1657,9 @@  discard block
 block discarded – undo
1582 1657
 	global $smcFunc, $txt, $scripturl, $settings;
1583 1658
 
1584 1659
 	// Do not waste my time...
1585
-	if (empty($users) || empty($params))
1586
-		return false;
1660
+	if (empty($users) || empty($params)) {
1661
+			return false;
1662
+	}
1587 1663
 
1588 1664
 	// Make sure it's an array.
1589 1665
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1607,31 +1683,36 @@  discard block
 block discarded – undo
1607 1683
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1608 1684
 	{
1609 1685
 		// BBC?
1610
-		if (!empty($row['bbc']))
1611
-			$row['value'] = parse_bbc($row['value']);
1686
+		if (!empty($row['bbc'])) {
1687
+					$row['value'] = parse_bbc($row['value']);
1688
+		}
1612 1689
 
1613 1690
 		// ... or checkbox?
1614
-		elseif (isset($row['type']) && $row['type'] == 'check')
1615
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1691
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1692
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1693
+		}
1616 1694
 
1617 1695
 		// Enclosing the user input within some other text?
1618
-		if (!empty($row['enclose']))
1619
-			$row['value'] = strtr($row['enclose'], array(
1696
+		if (!empty($row['enclose'])) {
1697
+					$row['value'] = strtr($row['enclose'], array(
1620 1698
 				'{SCRIPTURL}' => $scripturl,
1621 1699
 				'{IMAGES_URL}' => $settings['images_url'],
1622 1700
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1623 1701
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1624 1702
 			));
1703
+		}
1625 1704
 
1626 1705
 		// Send a simple array if there is just 1 param
1627
-		if (count($params) == 1)
1628
-			$return[$row['id_member']] = $row;
1706
+		if (count($params) == 1) {
1707
+					$return[$row['id_member']] = $row;
1708
+		}
1629 1709
 
1630 1710
 		// More than 1? knock yourself out...
1631 1711
 		else
1632 1712
 		{
1633
-			if (!isset($return[$row['id_member']]))
1634
-				$return[$row['id_member']] = array();
1713
+			if (!isset($return[$row['id_member']])) {
1714
+							$return[$row['id_member']] = array();
1715
+			}
1635 1716
 
1636 1717
 			$return[$row['id_member']][$row['variable']] = $row;
1637 1718
 		}
@@ -1665,8 +1746,9 @@  discard block
 block discarded – undo
1665 1746
 	global $context;
1666 1747
 
1667 1748
 	// Don't know any browser!
1668
-	if (empty($context['browser']))
1669
-		detectBrowser();
1749
+	if (empty($context['browser'])) {
1750
+			detectBrowser();
1751
+	}
1670 1752
 
1671 1753
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1672 1754
 }
@@ -1684,8 +1766,9 @@  discard block
 block discarded – undo
1684 1766
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1685 1767
 
1686 1768
 	// The theme was specified by parameter.
1687
-	if (!empty($id_theme))
1688
-		$id_theme = (int) $id_theme;
1769
+	if (!empty($id_theme)) {
1770
+			$id_theme = (int) $id_theme;
1771
+	}
1689 1772
 	// The theme was specified by REQUEST.
1690 1773
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1691 1774
 	{
@@ -1693,54 +1776,61 @@  discard block
 block discarded – undo
1693 1776
 		$_SESSION['id_theme'] = $id_theme;
1694 1777
 	}
1695 1778
 	// The theme was specified by REQUEST... previously.
1696
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1697
-		$id_theme = (int) $_SESSION['id_theme'];
1779
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1780
+			$id_theme = (int) $_SESSION['id_theme'];
1781
+	}
1698 1782
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1699
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1700
-		$id_theme = $user_info['theme'];
1783
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1784
+			$id_theme = $user_info['theme'];
1785
+	}
1701 1786
 	// The theme was specified by the board.
1702
-	elseif (!empty($board_info['theme']))
1703
-		$id_theme = $board_info['theme'];
1787
+	elseif (!empty($board_info['theme'])) {
1788
+			$id_theme = $board_info['theme'];
1789
+	}
1704 1790
 	// The theme is the forum's default.
1705
-	else
1706
-		$id_theme = $modSettings['theme_guests'];
1791
+	else {
1792
+			$id_theme = $modSettings['theme_guests'];
1793
+	}
1707 1794
 
1708 1795
 	// We already load the basic stuff?
1709 1796
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1710 1797
 	{
1711 1798
 		// Verify the id_theme... no foul play.
1712 1799
 		// Always allow the board specific theme, if they are overriding.
1713
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1714
-			$id_theme = $board_info['theme'];
1800
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1801
+					$id_theme = $board_info['theme'];
1802
+		}
1715 1803
 		// If they have specified a particular theme to use with SSI allow it to be used.
1716
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1717
-			$id_theme = (int) $id_theme;
1718
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1804
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1805
+					$id_theme = (int) $id_theme;
1806
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1719 1807
 		{
1720 1808
 			$themes = explode(',', $modSettings['enableThemes']);
1721
-			if (!in_array($id_theme, $themes))
1722
-				$id_theme = $modSettings['theme_guests'];
1723
-			else
1724
-				$id_theme = (int) $id_theme;
1809
+			if (!in_array($id_theme, $themes)) {
1810
+							$id_theme = $modSettings['theme_guests'];
1811
+			} else {
1812
+							$id_theme = (int) $id_theme;
1813
+			}
1814
+		} else {
1815
+					$id_theme = (int) $id_theme;
1725 1816
 		}
1726
-		else
1727
-			$id_theme = (int) $id_theme;
1728 1817
 
1729 1818
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1730 1819
 
1731 1820
 		// Disable image proxy if we don't have SSL enabled
1732
-		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1733
-			$image_proxy_enabled = false;
1821
+		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1822
+					$image_proxy_enabled = false;
1823
+		}
1734 1824
 
1735 1825
 		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'])
1736 1826
 		{
1737 1827
 			$themeData = $temp;
1738 1828
 			$flag = true;
1829
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1830
+					$themeData = $temp + array($member => array());
1831
+		} else {
1832
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1739 1833
 		}
1740
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1741
-			$themeData = $temp + array($member => array());
1742
-		else
1743
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1744 1834
 
1745 1835
 		if (empty($flag))
1746 1836
 		{
@@ -1759,31 +1849,37 @@  discard block
 block discarded – undo
1759 1849
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1760 1850
 			{
1761 1851
 				// There are just things we shouldn't be able to change as members.
1762
-				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')))
1763
-					continue;
1852
+				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'))) {
1853
+									continue;
1854
+				}
1764 1855
 
1765 1856
 				// If this is the theme_dir of the default theme, store it.
1766
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1767
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1857
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1858
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1859
+				}
1768 1860
 
1769 1861
 				// If this isn't set yet, is a theme option, or is not the default theme..
1770
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1771
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1862
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1863
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1864
+				}
1772 1865
 			}
1773 1866
 			$smcFunc['db_free_result']($result);
1774 1867
 
1775
-			if (!empty($themeData[-1]))
1776
-				foreach ($themeData[-1] as $k => $v)
1868
+			if (!empty($themeData[-1])) {
1869
+							foreach ($themeData[-1] as $k => $v)
1777 1870
 				{
1778 1871
 					if (!isset($themeData[$member][$k]))
1779 1872
 						$themeData[$member][$k] = $v;
1873
+			}
1780 1874
 				}
1781 1875
 
1782
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1783
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1876
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1877
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1878
+			}
1784 1879
 			// Only if we didn't already load that part of the cache...
1785
-			elseif (!isset($temp))
1786
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1880
+			elseif (!isset($temp)) {
1881
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1882
+			}
1787 1883
 		}
1788 1884
 
1789 1885
 		$settings = $themeData[0];
@@ -1800,22 +1896,26 @@  discard block
 block discarded – undo
1800 1896
 		$settings['template_dirs'][] = $settings['theme_dir'];
1801 1897
 
1802 1898
 		// Based on theme (if there is one).
1803
-		if (!empty($settings['base_theme_dir']))
1804
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1899
+		if (!empty($settings['base_theme_dir'])) {
1900
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1901
+		}
1805 1902
 
1806 1903
 		// Lastly the default theme.
1807
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1808
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1904
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1905
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1906
+		}
1809 1907
 	}
1810 1908
 	
1811 1909
 
1812
-	if (!$initialize)
1813
-		return;
1910
+	if (!$initialize) {
1911
+			return;
1912
+	}
1814 1913
 
1815 1914
 	// Check to see if we're forcing SSL
1816 1915
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1817
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1818
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1916
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1917
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1918
+	}
1819 1919
 
1820 1920
 	// Check to see if they're accessing it from the wrong place.
1821 1921
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1823,8 +1923,9 @@  discard block
 block discarded – undo
1823 1923
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1824 1924
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1825 1925
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1826
-		if ($temp != '/')
1827
-			$detected_url .= $temp;
1926
+		if ($temp != '/') {
1927
+					$detected_url .= $temp;
1928
+		}
1828 1929
 	}
1829 1930
 	if (isset($detected_url) && $detected_url != $boardurl)
1830 1931
 	{
@@ -1836,8 +1937,9 @@  discard block
 block discarded – undo
1836 1937
 			foreach ($aliases as $alias)
1837 1938
 			{
1838 1939
 				// Rip off all the boring parts, spaces, etc.
1839
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1840
-					$do_fix = true;
1940
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1941
+									$do_fix = true;
1942
+				}
1841 1943
 			}
1842 1944
 		}
1843 1945
 
@@ -1845,20 +1947,22 @@  discard block
 block discarded – undo
1845 1947
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1846 1948
 		{
1847 1949
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1848
-			if (empty($_GET))
1849
-				redirectexit('wwwRedirect');
1850
-			else
1950
+			if (empty($_GET)) {
1951
+							redirectexit('wwwRedirect');
1952
+			} else
1851 1953
 			{
1852 1954
 				list ($k, $v) = each($_GET);
1853 1955
 
1854
-				if ($k != 'wwwRedirect')
1855
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1956
+				if ($k != 'wwwRedirect') {
1957
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1958
+				}
1856 1959
 			}
1857 1960
 		}
1858 1961
 
1859 1962
 		// #3 is just a check for SSL...
1860
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1861
-			$do_fix = true;
1963
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1964
+					$do_fix = true;
1965
+		}
1862 1966
 
1863 1967
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1864 1968
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1892,8 +1996,9 @@  discard block
 block discarded – undo
1892 1996
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1893 1997
 				}
1894 1998
 			}
1895
-			foreach ($context['linktree'] as $k => $dummy)
1896
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
1999
+			foreach ($context['linktree'] as $k => $dummy) {
2000
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2001
+			}
1897 2002
 		}
1898 2003
 	}
1899 2004
 	// Set up the contextual user array.
@@ -1912,16 +2017,16 @@  discard block
 block discarded – undo
1912 2017
 			'email' => $user_info['email'],
1913 2018
 			'ignoreusers' => $user_info['ignoreusers'],
1914 2019
 		);
1915
-		if (!$context['user']['is_guest'])
1916
-			$context['user']['name'] = $user_info['name'];
1917
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1918
-			$context['user']['name'] = $txt['guest_title'];
2020
+		if (!$context['user']['is_guest']) {
2021
+					$context['user']['name'] = $user_info['name'];
2022
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2023
+					$context['user']['name'] = $txt['guest_title'];
2024
+		}
1919 2025
 
1920 2026
 		// Determine the current smiley set.
1921 2027
 		$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'];
1922 2028
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1923
-	}
1924
-	else
2029
+	} else
1925 2030
 	{
1926 2031
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1927 2032
 		$context['user'] = array(
@@ -1955,18 +2060,24 @@  discard block
 block discarded – undo
1955 2060
 	}
1956 2061
 
1957 2062
 	// Some basic information...
1958
-	if (!isset($context['html_headers']))
1959
-		$context['html_headers'] = '';
1960
-	if (!isset($context['javascript_files']))
1961
-		$context['javascript_files'] = array();
1962
-	if (!isset($context['css_files']))
1963
-		$context['css_files'] = array();
1964
-	if (!isset($context['css_header']))
1965
-		$context['css_header'] = array();
1966
-	if (!isset($context['javascript_inline']))
1967
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1968
-	if (!isset($context['javascript_vars']))
1969
-		$context['javascript_vars'] = array();
2063
+	if (!isset($context['html_headers'])) {
2064
+			$context['html_headers'] = '';
2065
+	}
2066
+	if (!isset($context['javascript_files'])) {
2067
+			$context['javascript_files'] = array();
2068
+	}
2069
+	if (!isset($context['css_files'])) {
2070
+			$context['css_files'] = array();
2071
+	}
2072
+	if (!isset($context['css_header'])) {
2073
+			$context['css_header'] = array();
2074
+	}
2075
+	if (!isset($context['javascript_inline'])) {
2076
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2077
+	}
2078
+	if (!isset($context['javascript_vars'])) {
2079
+			$context['javascript_vars'] = array();
2080
+	}
1970 2081
 
1971 2082
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1972 2083
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1978,16 +2089,18 @@  discard block
 block discarded – undo
1978 2089
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1979 2090
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1980 2091
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1981
-	if (isset($modSettings['load_average']))
1982
-		$context['load_average'] = $modSettings['load_average'];
2092
+	if (isset($modSettings['load_average'])) {
2093
+			$context['load_average'] = $modSettings['load_average'];
2094
+	}
1983 2095
 
1984 2096
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1985 2097
 	detectBrowser();
1986 2098
 
1987 2099
 	// Set the top level linktree up.
1988 2100
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
1989
-	if (empty($context['linktree']))
1990
-		$context['linktree'] = array();
2101
+	if (empty($context['linktree'])) {
2102
+			$context['linktree'] = array();
2103
+	}
1991 2104
 	array_unshift($context['linktree'], array(
1992 2105
 		'url' => $scripturl,
1993 2106
 		'name' => $context['forum_name_html_safe']
@@ -1996,8 +2109,9 @@  discard block
 block discarded – undo
1996 2109
 	// This allows sticking some HTML on the page output - useful for controls.
1997 2110
 	$context['insert_after_template'] = '';
1998 2111
 
1999
-	if (!isset($txt))
2000
-		$txt = array();
2112
+	if (!isset($txt)) {
2113
+			$txt = array();
2114
+	}
2001 2115
 
2002 2116
 	$simpleActions = array(
2003 2117
 		'findmember',
@@ -2043,9 +2157,10 @@  discard block
 block discarded – undo
2043 2157
 
2044 2158
 	// See if theres any extra param to check.
2045 2159
 	$requiresXML = false;
2046
-	foreach ($extraParams as $key => $extra)
2047
-		if (isset($_REQUEST[$extra]))
2160
+	foreach ($extraParams as $key => $extra) {
2161
+			if (isset($_REQUEST[$extra]))
2048 2162
 			$requiresXML = true;
2163
+	}
2049 2164
 
2050 2165
 	// Output is fully XML, so no need for the index template.
2051 2166
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2060,37 +2175,39 @@  discard block
 block discarded – undo
2060 2175
 	{
2061 2176
 		loadLanguage('index+Modifications');
2062 2177
 		$context['template_layers'] = array();
2063
-	}
2064
-
2065
-	else
2178
+	} else
2066 2179
 	{
2067 2180
 		// Custom templates to load, or just default?
2068
-		if (isset($settings['theme_templates']))
2069
-			$templates = explode(',', $settings['theme_templates']);
2070
-		else
2071
-			$templates = array('index');
2181
+		if (isset($settings['theme_templates'])) {
2182
+					$templates = explode(',', $settings['theme_templates']);
2183
+		} else {
2184
+					$templates = array('index');
2185
+		}
2072 2186
 
2073 2187
 		// Load each template...
2074
-		foreach ($templates as $template)
2075
-			loadTemplate($template);
2188
+		foreach ($templates as $template) {
2189
+					loadTemplate($template);
2190
+		}
2076 2191
 
2077 2192
 		// ...and attempt to load their associated language files.
2078 2193
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2079 2194
 		loadLanguage($required_files, '', false);
2080 2195
 
2081 2196
 		// Custom template layers?
2082
-		if (isset($settings['theme_layers']))
2083
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2084
-		else
2085
-			$context['template_layers'] = array('html', 'body');
2197
+		if (isset($settings['theme_layers'])) {
2198
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2199
+		} else {
2200
+					$context['template_layers'] = array('html', 'body');
2201
+		}
2086 2202
 	}
2087 2203
 
2088 2204
 	// Initialize the theme.
2089 2205
 	loadSubTemplate('init', 'ignore');
2090 2206
 
2091 2207
 	// Allow overriding the board wide time/number formats.
2092
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2093
-		$user_info['time_format'] = $txt['time_format'];
2208
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2209
+			$user_info['time_format'] = $txt['time_format'];
2210
+	}
2094 2211
 
2095 2212
 	// Set the character set from the template.
2096 2213
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2098,12 +2215,14 @@  discard block
 block discarded – undo
2098 2215
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2099 2216
 
2100 2217
 	// Guests may still need a name.
2101
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2102
-		$context['user']['name'] = $txt['guest_title'];
2218
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2219
+			$context['user']['name'] = $txt['guest_title'];
2220
+	}
2103 2221
 
2104 2222
 	// Any theme-related strings that need to be loaded?
2105
-	if (!empty($settings['require_theme_strings']))
2106
-		loadLanguage('ThemeStrings', '', false);
2223
+	if (!empty($settings['require_theme_strings'])) {
2224
+			loadLanguage('ThemeStrings', '', false);
2225
+	}
2107 2226
 
2108 2227
 	// Make a special URL for the language.
2109 2228
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2114,8 +2233,9 @@  discard block
 block discarded – undo
2114 2233
 	// Here is my luvly Responsive CSS
2115 2234
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2116 2235
 
2117
-	if ($context['right_to_left'])
2118
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2236
+	if ($context['right_to_left']) {
2237
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2238
+	}
2119 2239
 
2120 2240
 	// We allow theme variants, because we're cool.
2121 2241
 	$context['theme_variant'] = '';
@@ -2123,14 +2243,17 @@  discard block
 block discarded – undo
2123 2243
 	if (!empty($settings['theme_variants']))
2124 2244
 	{
2125 2245
 		// Overriding - for previews and that ilk.
2126
-		if (!empty($_REQUEST['variant']))
2127
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2246
+		if (!empty($_REQUEST['variant'])) {
2247
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2248
+		}
2128 2249
 		// User selection?
2129
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2130
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2250
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2251
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2252
+		}
2131 2253
 		// If not a user variant, select the default.
2132
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2133
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2254
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2255
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2256
+		}
2134 2257
 
2135 2258
 		// Do this to keep things easier in the templates.
2136 2259
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2139,20 +2262,23 @@  discard block
 block discarded – undo
2139 2262
 		if (!empty($context['theme_variant']))
2140 2263
 		{
2141 2264
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2142
-			if ($context['right_to_left'])
2143
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2265
+			if ($context['right_to_left']) {
2266
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2267
+			}
2144 2268
 		}
2145 2269
 	}
2146 2270
 
2147 2271
 	// Let's be compatible with old themes!
2148
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2149
-		$context['template_layers'] = array('main');
2272
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2273
+			$context['template_layers'] = array('main');
2274
+	}
2150 2275
 
2151 2276
 	$context['tabindex'] = 1;
2152 2277
 
2153 2278
 	// Compatibility.
2154
-	if (!isset($settings['theme_version']))
2155
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2279
+	if (!isset($settings['theme_version'])) {
2280
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2281
+	}
2156 2282
 
2157 2283
 	// Default JS variables for use in every theme
2158 2284
 	$context['javascript_vars'] = array(
@@ -2171,18 +2297,18 @@  discard block
 block discarded – undo
2171 2297
 	);
2172 2298
 
2173 2299
 	// Add the JQuery library to the list of files to load.
2174
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2175
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2176
-
2177
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2178
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2179
-
2180
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2181
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2300
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2301
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2302
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2303
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2304
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2305
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2306
+	}
2182 2307
 
2183 2308
 	// Auto loading? template_javascript() will take care of the local half of this.
2184
-	else
2185
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2309
+	else {
2310
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2311
+	}
2186 2312
 
2187 2313
 	// Queue our JQuery plugins!
2188 2314
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2205,12 +2331,12 @@  discard block
 block discarded – undo
2205 2331
 			require_once($sourcedir . '/ScheduledTasks.php');
2206 2332
 
2207 2333
 			// What to do, what to do?!
2208
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2209
-				AutoTask();
2210
-			else
2211
-				ReduceMailQueue();
2212
-		}
2213
-		else
2334
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2335
+							AutoTask();
2336
+			} else {
2337
+							ReduceMailQueue();
2338
+			}
2339
+		} else
2214 2340
 		{
2215 2341
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2216 2342
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2261,8 +2387,9 @@  discard block
 block discarded – undo
2261 2387
 		foreach ($theme_includes as $include)
2262 2388
 		{
2263 2389
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2264
-			if (file_exists($include))
2265
-				require_once($include);
2390
+			if (file_exists($include)) {
2391
+							require_once($include);
2392
+			}
2266 2393
 		}
2267 2394
 	}
2268 2395
 
@@ -2292,16 +2419,19 @@  discard block
 block discarded – undo
2292 2419
 	// Do any style sheets first, cause we're easy with those.
2293 2420
 	if (!empty($style_sheets))
2294 2421
 	{
2295
-		if (!is_array($style_sheets))
2296
-			$style_sheets = array($style_sheets);
2422
+		if (!is_array($style_sheets)) {
2423
+					$style_sheets = array($style_sheets);
2424
+		}
2297 2425
 
2298
-		foreach ($style_sheets as $sheet)
2299
-			loadCSSFile($sheet . '.css', array(), $sheet);
2426
+		foreach ($style_sheets as $sheet) {
2427
+					loadCSSFile($sheet . '.css', array(), $sheet);
2428
+		}
2300 2429
 	}
2301 2430
 
2302 2431
 	// No template to load?
2303
-	if ($template_name === false)
2304
-		return true;
2432
+	if ($template_name === false) {
2433
+			return true;
2434
+	}
2305 2435
 
2306 2436
 	$loaded = false;
2307 2437
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2316,12 +2446,14 @@  discard block
 block discarded – undo
2316 2446
 
2317 2447
 	if ($loaded)
2318 2448
 	{
2319
-		if ($db_show_debug === true)
2320
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2449
+		if ($db_show_debug === true) {
2450
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2451
+		}
2321 2452
 
2322 2453
 		// If they have specified an initialization function for this template, go ahead and call it now.
2323
-		if (function_exists('template_' . $template_name . '_init'))
2324
-			call_user_func('template_' . $template_name . '_init');
2454
+		if (function_exists('template_' . $template_name . '_init')) {
2455
+					call_user_func('template_' . $template_name . '_init');
2456
+		}
2325 2457
 	}
2326 2458
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2327 2459
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2341,13 +2473,14 @@  discard block
 block discarded – undo
2341 2473
 		loadTemplate($template_name);
2342 2474
 	}
2343 2475
 	// Cause an error otherwise.
2344
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2345
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2346
-	elseif ($fatal)
2347
-		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'));
2348
-	else
2349
-		return false;
2350
-}
2476
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2477
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2478
+	} elseif ($fatal) {
2479
+			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'));
2480
+	} else {
2481
+			return false;
2482
+	}
2483
+	}
2351 2484
 
2352 2485
 /**
2353 2486
  * Load a sub-template.
@@ -2365,17 +2498,19 @@  discard block
 block discarded – undo
2365 2498
 {
2366 2499
 	global $context, $txt, $db_show_debug;
2367 2500
 
2368
-	if ($db_show_debug === true)
2369
-		$context['debug']['sub_templates'][] = $sub_template_name;
2501
+	if ($db_show_debug === true) {
2502
+			$context['debug']['sub_templates'][] = $sub_template_name;
2503
+	}
2370 2504
 
2371 2505
 	// Figure out what the template function is named.
2372 2506
 	$theme_function = 'template_' . $sub_template_name;
2373
-	if (function_exists($theme_function))
2374
-		$theme_function();
2375
-	elseif ($fatal === false)
2376
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2377
-	elseif ($fatal !== 'ignore')
2378
-		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'));
2507
+	if (function_exists($theme_function)) {
2508
+			$theme_function();
2509
+	} elseif ($fatal === false) {
2510
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2511
+	} elseif ($fatal !== 'ignore') {
2512
+			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'));
2513
+	}
2379 2514
 
2380 2515
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2381 2516
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2412,8 +2547,9 @@  discard block
 block discarded – undo
2412 2547
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2413 2548
 
2414 2549
 	// If this is an external file, automatically set this to false.
2415
-	if (!empty($params['external']))
2416
-		$params['minimize'] = false;
2550
+	if (!empty($params['external'])) {
2551
+			$params['minimize'] = false;
2552
+	}
2417 2553
 
2418 2554
 	// Account for shorthand like admin.css?alp21 filenames
2419 2555
 	$has_seed = strpos($fileName, '.css?');
@@ -2430,13 +2566,10 @@  discard block
 block discarded – undo
2430 2566
 			{
2431 2567
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2432 2568
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2569
+			} else {
2570
+							$fileUrl = false;
2433 2571
 			}
2434
-
2435
-			else
2436
-				$fileUrl = false;
2437
-		}
2438
-
2439
-		else
2572
+		} else
2440 2573
 		{
2441 2574
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2442 2575
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2451,12 +2584,14 @@  discard block
 block discarded – undo
2451 2584
 	}
2452 2585
 
2453 2586
 	// Add it to the array for use in the template
2454
-	if (!empty($fileName))
2455
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2587
+	if (!empty($fileName)) {
2588
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2589
+	}
2456 2590
 
2457
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2458
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2459
-}
2591
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2592
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2593
+	}
2594
+	}
2460 2595
 
2461 2596
 /**
2462 2597
  * Add a block of inline css code to be executed later
@@ -2473,8 +2608,9 @@  discard block
 block discarded – undo
2473 2608
 	global $context;
2474 2609
 
2475 2610
 	// Gotta add something...
2476
-	if (empty($css))
2477
-		return false;
2611
+	if (empty($css)) {
2612
+			return false;
2613
+	}
2478 2614
 
2479 2615
 	$context['css_header'][] = $css;
2480 2616
 }
@@ -2509,8 +2645,9 @@  discard block
 block discarded – undo
2509 2645
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2510 2646
 
2511 2647
 	// If this is an external file, automatically set this to false.
2512
-	if (!empty($params['external']))
2513
-		$params['minimize'] = false;
2648
+	if (!empty($params['external'])) {
2649
+			$params['minimize'] = false;
2650
+	}
2514 2651
 
2515 2652
 	// Account for shorthand like admin.js?alp21 filenames
2516 2653
 	$has_seed = strpos($fileName, '.js?');
@@ -2527,16 +2664,12 @@  discard block
 block discarded – undo
2527 2664
 			{
2528 2665
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2529 2666
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2530
-			}
2531
-
2532
-			else
2667
+			} else
2533 2668
 			{
2534 2669
 				$fileUrl = false;
2535 2670
 				$filePath = false;
2536 2671
 			}
2537
-		}
2538
-
2539
-		else
2672
+		} else
2540 2673
 		{
2541 2674
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2542 2675
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2551,9 +2684,10 @@  discard block
 block discarded – undo
2551 2684
 	}
2552 2685
 
2553 2686
 	// Add it to the array for use in the template
2554
-	if (!empty($fileName))
2555
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2556
-}
2687
+	if (!empty($fileName)) {
2688
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2689
+	}
2690
+	}
2557 2691
 
2558 2692
 /**
2559 2693
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2567,9 +2701,10 @@  discard block
 block discarded – undo
2567 2701
 {
2568 2702
 	global $context;
2569 2703
 
2570
-	if (!empty($key) && (!empty($value) || $value === '0'))
2571
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2572
-}
2704
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2705
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2706
+	}
2707
+	}
2573 2708
 
2574 2709
 /**
2575 2710
  * Add a block of inline Javascript code to be executed later
@@ -2586,8 +2721,9 @@  discard block
 block discarded – undo
2586 2721
 {
2587 2722
 	global $context;
2588 2723
 
2589
-	if (empty($javascript))
2590
-		return false;
2724
+	if (empty($javascript)) {
2725
+			return false;
2726
+	}
2591 2727
 
2592 2728
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2593 2729
 }
@@ -2608,15 +2744,18 @@  discard block
 block discarded – undo
2608 2744
 	static $already_loaded = array();
2609 2745
 
2610 2746
 	// Default to the user's language.
2611
-	if ($lang == '')
2612
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2747
+	if ($lang == '') {
2748
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2749
+	}
2613 2750
 
2614 2751
 	// Do we want the English version of language file as fallback?
2615
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2616
-		loadLanguage($template_name, 'english', false);
2752
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2753
+			loadLanguage($template_name, 'english', false);
2754
+	}
2617 2755
 
2618
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2619
-		return $lang;
2756
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2757
+			return $lang;
2758
+	}
2620 2759
 
2621 2760
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2622 2761
 	if (empty($settings['default_theme_dir']))
@@ -2627,8 +2766,9 @@  discard block
 block discarded – undo
2627 2766
 
2628 2767
 	// What theme are we in?
2629 2768
 	$theme_name = basename($settings['theme_url']);
2630
-	if (empty($theme_name))
2631
-		$theme_name = 'unknown';
2769
+	if (empty($theme_name)) {
2770
+			$theme_name = 'unknown';
2771
+	}
2632 2772
 
2633 2773
 	// For each file open it up and write it out!
2634 2774
 	foreach (explode('+', $template_name) as $template)
@@ -2670,8 +2810,9 @@  discard block
 block discarded – undo
2670 2810
 				$found = true;
2671 2811
 
2672 2812
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2673
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2674
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2813
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2814
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2815
+				}
2675 2816
 
2676 2817
 				break;
2677 2818
 			}
@@ -2711,8 +2852,9 @@  discard block
 block discarded – undo
2711 2852
 	}
2712 2853
 
2713 2854
 	// Keep track of what we're up to soldier.
2714
-	if ($db_show_debug === true)
2715
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2855
+	if ($db_show_debug === true) {
2856
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2857
+	}
2716 2858
 
2717 2859
 	// Remember what we have loaded, and in which language.
2718 2860
 	$already_loaded[$template_name] = $lang;
@@ -2758,8 +2900,9 @@  discard block
 block discarded – undo
2758 2900
 				)
2759 2901
 			);
2760 2902
 			// In the EXTREMELY unlikely event this happens, give an error message.
2761
-			if ($smcFunc['db_num_rows']($result) == 0)
2762
-				fatal_lang_error('parent_not_found', 'critical');
2903
+			if ($smcFunc['db_num_rows']($result) == 0) {
2904
+							fatal_lang_error('parent_not_found', 'critical');
2905
+			}
2763 2906
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2764 2907
 			{
2765 2908
 				if (!isset($boards[$row['id_board']]))
@@ -2776,8 +2919,8 @@  discard block
 block discarded – undo
2776 2919
 					);
2777 2920
 				}
2778 2921
 				// If a moderator exists for this board, add that moderator for all children too.
2779
-				if (!empty($row['id_moderator']))
2780
-					foreach ($boards as $id => $dummy)
2922
+				if (!empty($row['id_moderator'])) {
2923
+									foreach ($boards as $id => $dummy)
2781 2924
 					{
2782 2925
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2783 2926
 							'id' => $row['id_moderator'],
@@ -2785,11 +2928,12 @@  discard block
 block discarded – undo
2785 2928
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2786 2929
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2787 2930
 						);
2931
+				}
2788 2932
 					}
2789 2933
 
2790 2934
 				// If a moderator group exists for this board, add that moderator group for all children too
2791
-				if (!empty($row['id_moderator_group']))
2792
-					foreach ($boards as $id => $dummy)
2935
+				if (!empty($row['id_moderator_group'])) {
2936
+									foreach ($boards as $id => $dummy)
2793 2937
 					{
2794 2938
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2795 2939
 							'id' => $row['id_moderator_group'],
@@ -2797,6 +2941,7 @@  discard block
 block discarded – undo
2797 2941
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2798 2942
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2799 2943
 						);
2944
+				}
2800 2945
 					}
2801 2946
 			}
2802 2947
 			$smcFunc['db_free_result']($result);
@@ -2823,23 +2968,27 @@  discard block
 block discarded – undo
2823 2968
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2824 2969
 	{
2825 2970
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2826
-		if (empty($smcFunc['ucwords']))
2827
-			reloadSettings();
2971
+		if (empty($smcFunc['ucwords'])) {
2972
+					reloadSettings();
2973
+		}
2828 2974
 
2829 2975
 		// If we don't have our theme information yet, let's get it.
2830
-		if (empty($settings['default_theme_dir']))
2831
-			loadTheme(0, false);
2976
+		if (empty($settings['default_theme_dir'])) {
2977
+					loadTheme(0, false);
2978
+		}
2832 2979
 
2833 2980
 		// Default language directories to try.
2834 2981
 		$language_directories = array(
2835 2982
 			$settings['default_theme_dir'] . '/languages',
2836 2983
 		);
2837
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2838
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2984
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2985
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2986
+		}
2839 2987
 
2840 2988
 		// We possibly have a base theme directory.
2841
-		if (!empty($settings['base_theme_dir']))
2842
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2989
+		if (!empty($settings['base_theme_dir'])) {
2990
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2991
+		}
2843 2992
 
2844 2993
 		// Remove any duplicates.
2845 2994
 		$language_directories = array_unique($language_directories);
@@ -2853,20 +3002,21 @@  discard block
 block discarded – undo
2853 3002
 		foreach ($language_directories as $language_dir)
2854 3003
 		{
2855 3004
 			// Can't look in here... doesn't exist!
2856
-			if (!file_exists($language_dir))
2857
-				continue;
3005
+			if (!file_exists($language_dir)) {
3006
+							continue;
3007
+			}
2858 3008
 
2859 3009
 			$dir = dir($language_dir);
2860 3010
 			while ($entry = $dir->read())
2861 3011
 			{
2862 3012
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2863
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2864
-					continue;
2865
-
2866
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2867
-					$langName = $langList[$matches[1]];
3013
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3014
+									continue;
3015
+				}
2868 3016
 
2869
-				else
3017
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3018
+									$langName = $langList[$matches[1]];
3019
+				} else
2870 3020
 				{
2871 3021
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2872 3022
 
@@ -2907,12 +3057,14 @@  discard block
 block discarded – undo
2907 3057
 		}
2908 3058
 
2909 3059
 		// Do we need to store the lang list?
2910
-		if (empty($langList))
2911
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3060
+		if (empty($langList)) {
3061
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3062
+		}
2912 3063
 
2913 3064
 		// Let's cash in on this deal.
2914
-		if (!empty($modSettings['cache_enable']))
2915
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3065
+		if (!empty($modSettings['cache_enable'])) {
3066
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3067
+		}
2916 3068
 	}
2917 3069
 
2918 3070
 	return $context['languages'];
@@ -2935,8 +3087,9 @@  discard block
 block discarded – undo
2935 3087
 	global $modSettings, $options, $txt;
2936 3088
 	static $censor_vulgar = null, $censor_proper;
2937 3089
 
2938
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2939
-		return $text;
3090
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3091
+			return $text;
3092
+	}
2940 3093
 
2941 3094
 	// If they haven't yet been loaded, load them.
2942 3095
 	if ($censor_vulgar == null)
@@ -2964,9 +3117,9 @@  discard block
 block discarded – undo
2964 3117
 	{
2965 3118
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2966 3119
 		$text = $func($censor_vulgar, $censor_proper, $text);
3120
+	} else {
3121
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2967 3122
 	}
2968
-	else
2969
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2970 3123
 
2971 3124
 	return $text;
2972 3125
 }
@@ -2992,38 +3145,42 @@  discard block
 block discarded – undo
2992 3145
 	@ini_set('track_errors', '1');
2993 3146
 
2994 3147
 	// Don't include the file more than once, if $once is true.
2995
-	if ($once && in_array($filename, $templates))
2996
-		return;
3148
+	if ($once && in_array($filename, $templates)) {
3149
+			return;
3150
+	}
2997 3151
 	// Add this file to the include list, whether $once is true or not.
2998
-	else
2999
-		$templates[] = $filename;
3152
+	else {
3153
+			$templates[] = $filename;
3154
+	}
3000 3155
 
3001 3156
 	// Are we going to use eval?
3002 3157
 	if (empty($modSettings['disableTemplateEval']))
3003 3158
 	{
3004 3159
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3005 3160
 		$settings['current_include_filename'] = $filename;
3006
-	}
3007
-	else
3161
+	} else
3008 3162
 	{
3009 3163
 		$file_found = file_exists($filename);
3010 3164
 
3011
-		if ($once && $file_found)
3012
-			require_once($filename);
3013
-		elseif ($file_found)
3014
-			require($filename);
3165
+		if ($once && $file_found) {
3166
+					require_once($filename);
3167
+		} elseif ($file_found) {
3168
+					require($filename);
3169
+		}
3015 3170
 	}
3016 3171
 
3017 3172
 	if ($file_found !== true)
3018 3173
 	{
3019 3174
 		ob_end_clean();
3020
-		if (!empty($modSettings['enableCompressedOutput']))
3021
-			@ob_start('ob_gzhandler');
3022
-		else
3023
-			ob_start();
3175
+		if (!empty($modSettings['enableCompressedOutput'])) {
3176
+					@ob_start('ob_gzhandler');
3177
+		} else {
3178
+					ob_start();
3179
+		}
3024 3180
 
3025
-		if (isset($_GET['debug']))
3026
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3181
+		if (isset($_GET['debug'])) {
3182
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3183
+		}
3027 3184
 
3028 3185
 		// Don't cache error pages!!
3029 3186
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3042,12 +3199,13 @@  discard block
 block discarded – undo
3042 3199
 		echo '<!DOCTYPE html>
3043 3200
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3044 3201
 	<head>';
3045
-		if (isset($context['character_set']))
3046
-			echo '
3202
+		if (isset($context['character_set'])) {
3203
+					echo '
3047 3204
 		<meta charset="', $context['character_set'], '">';
3205
+		}
3048 3206
 
3049
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3050
-			echo '
3207
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3208
+					echo '
3051 3209
 		<title>', $mtitle, '</title>
3052 3210
 	</head>
3053 3211
 	<body>
@@ -3055,8 +3213,8 @@  discard block
 block discarded – undo
3055 3213
 		', $mmessage, '
3056 3214
 	</body>
3057 3215
 </html>';
3058
-		elseif (!allowedTo('admin_forum'))
3059
-			echo '
3216
+		} elseif (!allowedTo('admin_forum')) {
3217
+					echo '
3060 3218
 		<title>', $txt['template_parse_error'], '</title>
3061 3219
 	</head>
3062 3220
 	<body>
@@ -3064,16 +3222,18 @@  discard block
 block discarded – undo
3064 3222
 		', $txt['template_parse_error_message'], '
3065 3223
 	</body>
3066 3224
 </html>';
3067
-		else
3225
+		} else
3068 3226
 		{
3069 3227
 			require_once($sourcedir . '/Subs-Package.php');
3070 3228
 
3071 3229
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3072 3230
 			$error_array = error_get_last();
3073
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3074
-				$error = $error_array['message'];
3075
-			if (empty($error))
3076
-				$error = $txt['template_parse_errmsg'];
3231
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3232
+							$error = $error_array['message'];
3233
+			}
3234
+			if (empty($error)) {
3235
+							$error = $txt['template_parse_errmsg'];
3236
+			}
3077 3237
 
3078 3238
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3079 3239
 
@@ -3084,11 +3244,12 @@  discard block
 block discarded – undo
3084 3244
 		<h3>', $txt['template_parse_error'], '</h3>
3085 3245
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3086 3246
 
3087
-			if (!empty($error))
3088
-				echo '
3247
+			if (!empty($error)) {
3248
+							echo '
3089 3249
 		<hr>
3090 3250
 
3091 3251
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3252
+			}
3092 3253
 
3093 3254
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3094 3255
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3098,10 +3259,11 @@  discard block
 block discarded – undo
3098 3259
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3099 3260
 
3100 3261
 				// Fix the PHP code stuff...
3101
-				if (!isBrowser('gecko'))
3102
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3103
-				else
3104
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3262
+				if (!isBrowser('gecko')) {
3263
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3264
+				} else {
3265
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3266
+				}
3105 3267
 
3106 3268
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3107 3269
 				$j = -1;
@@ -3109,8 +3271,9 @@  discard block
 block discarded – undo
3109 3271
 				{
3110 3272
 					$j++;
3111 3273
 
3112
-					if (substr_count($line, '<br>') == 0)
3113
-						continue;
3274
+					if (substr_count($line, '<br>') == 0) {
3275
+											continue;
3276
+					}
3114 3277
 
3115 3278
 					$n = substr_count($line, '<br>');
3116 3279
 					for ($i = 0; $i < $n; $i++)
@@ -3129,38 +3292,42 @@  discard block
 block discarded – undo
3129 3292
 				// Figure out what the color coding was before...
3130 3293
 				$line = max($match[1] - 9, 1);
3131 3294
 				$last_line = '';
3132
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3133
-					if (strpos($data2[$line2], '<') !== false)
3295
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3296
+									if (strpos($data2[$line2], '<') !== false)
3134 3297
 					{
3135 3298
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3136 3299
 							$last_line = $color_match[1];
3300
+				}
3137 3301
 						break;
3138 3302
 					}
3139 3303
 
3140 3304
 				// Show the relevant lines...
3141 3305
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3142 3306
 				{
3143
-					if ($line == $match[1])
3144
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3307
+					if ($line == $match[1]) {
3308
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3309
+					}
3145 3310
 
3146 3311
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3147
-					if (isset($data2[$line]) && $data2[$line] != '')
3148
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3312
+					if (isset($data2[$line]) && $data2[$line] != '') {
3313
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3314
+					}
3149 3315
 
3150 3316
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3151 3317
 					{
3152 3318
 						$last_line = $color_match[1];
3153 3319
 						echo '</', substr($last_line, 1, 4), '>';
3320
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3321
+											$last_line = '';
3322
+					} elseif ($last_line != '' && $data2[$line] != '') {
3323
+											echo '</', substr($last_line, 1, 4), '>';
3154 3324
 					}
3155
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3156
-						$last_line = '';
3157
-					elseif ($last_line != '' && $data2[$line] != '')
3158
-						echo '</', substr($last_line, 1, 4), '>';
3159 3325
 
3160
-					if ($line == $match[1])
3161
-						echo '</pre></div><pre style="margin: 0;">';
3162
-					else
3163
-						echo "\n";
3326
+					if ($line == $match[1]) {
3327
+											echo '</pre></div><pre style="margin: 0;">';
3328
+					} else {
3329
+											echo "\n";
3330
+					}
3164 3331
 				}
3165 3332
 
3166 3333
 				echo '</pre></div>';
@@ -3184,8 +3351,9 @@  discard block
 block discarded – undo
3184 3351
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3185 3352
 
3186 3353
 	// Figure out what type of database we are using.
3187
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3188
-		$db_type = 'mysql';
3354
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3355
+			$db_type = 'mysql';
3356
+	}
3189 3357
 
3190 3358
 	// Load the file for the database.
3191 3359
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3193,8 +3361,9 @@  discard block
 block discarded – undo
3193 3361
 	$db_options = array();
3194 3362
 
3195 3363
 	// Add in the port if needed
3196
-	if (!empty($db_port))
3197
-		$db_options['port'] = $db_port;
3364
+	if (!empty($db_port)) {
3365
+			$db_options['port'] = $db_port;
3366
+	}
3198 3367
 
3199 3368
 	// 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.
3200 3369
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3213,13 +3382,15 @@  discard block
 block discarded – undo
3213 3382
 	}
3214 3383
 
3215 3384
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3216
-	if (!$db_connection)
3217
-		display_db_error();
3385
+	if (!$db_connection) {
3386
+			display_db_error();
3387
+	}
3218 3388
 
3219 3389
 	// If in SSI mode fix up the prefix.
3220
-	if (SMF == 'SSI')
3221
-		db_fix_prefix($db_prefix, $db_name);
3222
-}
3390
+	if (SMF == 'SSI') {
3391
+			db_fix_prefix($db_prefix, $db_name);
3392
+	}
3393
+	}
3223 3394
 
3224 3395
 /**
3225 3396
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3233,10 +3404,11 @@  discard block
 block discarded – undo
3233 3404
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3234 3405
 
3235 3406
 	// Not overriding this and we have a cacheAPI, send it back.
3236
-	if (empty($overrideCache) && is_object($cacheAPI))
3237
-		return $cacheAPI;
3238
-	elseif (is_null($cacheAPI))
3239
-		$cacheAPI = false;
3407
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3408
+			return $cacheAPI;
3409
+	} elseif (is_null($cacheAPI)) {
3410
+			$cacheAPI = false;
3411
+	}
3240 3412
 
3241 3413
 	// Make sure our class is in session.
3242 3414
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3257,8 +3429,9 @@  discard block
 block discarded – undo
3257 3429
 		if (!$testAPI->isSupported())
3258 3430
 		{
3259 3431
 			// Can we save ourselves?
3260
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3261
-				return loadCacheAccelerator(null, false);
3432
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3433
+							return loadCacheAccelerator(null, false);
3434
+			}
3262 3435
 			return false;
3263 3436
 		}
3264 3437
 
@@ -3270,9 +3443,9 @@  discard block
 block discarded – undo
3270 3443
 		{
3271 3444
 			$cacheAPI = $testAPI;
3272 3445
 			return $cacheAPI;
3446
+		} else {
3447
+					return $testAPI;
3273 3448
 		}
3274
-		else
3275
-			return $testAPI;
3276 3449
 	}
3277 3450
 }
3278 3451
 
@@ -3292,8 +3465,9 @@  discard block
 block discarded – undo
3292 3465
 
3293 3466
 	// @todo Why are we doing this if caching is disabled?
3294 3467
 
3295
-	if (function_exists('call_integration_hook'))
3296
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3468
+	if (function_exists('call_integration_hook')) {
3469
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3470
+	}
3297 3471
 
3298 3472
 	/* Refresh the cache if either:
3299 3473
 		1. Caching is disabled.
@@ -3307,16 +3481,19 @@  discard block
 block discarded – undo
3307 3481
 		require_once($sourcedir . '/' . $file);
3308 3482
 		$cache_block = call_user_func_array($function, $params);
3309 3483
 
3310
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3311
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3484
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3485
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3486
+		}
3312 3487
 	}
3313 3488
 
3314 3489
 	// Some cached data may need a freshening up after retrieval.
3315
-	if (!empty($cache_block['post_retri_eval']))
3316
-		eval($cache_block['post_retri_eval']);
3490
+	if (!empty($cache_block['post_retri_eval'])) {
3491
+			eval($cache_block['post_retri_eval']);
3492
+	}
3317 3493
 
3318
-	if (function_exists('call_integration_hook'))
3319
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3494
+	if (function_exists('call_integration_hook')) {
3495
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3496
+	}
3320 3497
 
3321 3498
 	return $cache_block['data'];
3322 3499
 }
@@ -3343,8 +3520,9 @@  discard block
 block discarded – undo
3343 3520
 	global $smcFunc, $cache_enable, $cacheAPI;
3344 3521
 	global $cache_hits, $cache_count, $db_show_debug;
3345 3522
 
3346
-	if (empty($cache_enable) || empty($cacheAPI))
3347
-		return;
3523
+	if (empty($cache_enable) || empty($cacheAPI)) {
3524
+			return;
3525
+	}
3348 3526
 
3349 3527
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3350 3528
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3357,12 +3535,14 @@  discard block
 block discarded – undo
3357 3535
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3358 3536
 	$cacheAPI->putData($key, $value, $ttl);
3359 3537
 
3360
-	if (function_exists('call_integration_hook'))
3361
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3538
+	if (function_exists('call_integration_hook')) {
3539
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3540
+	}
3362 3541
 
3363
-	if (isset($db_show_debug) && $db_show_debug === true)
3364
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3365
-}
3542
+	if (isset($db_show_debug) && $db_show_debug === true) {
3543
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3544
+	}
3545
+	}
3366 3546
 
3367 3547
 /**
3368 3548
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3378,8 +3558,9 @@  discard block
 block discarded – undo
3378 3558
 	global $smcFunc, $cache_enable, $cacheAPI;
3379 3559
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3380 3560
 
3381
-	if (empty($cache_enable) || empty($cacheAPI))
3382
-		return;
3561
+	if (empty($cache_enable) || empty($cacheAPI)) {
3562
+			return;
3563
+	}
3383 3564
 
3384 3565
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3385 3566
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3399,16 +3580,18 @@  discard block
 block discarded – undo
3399 3580
 
3400 3581
 		if (empty($value))
3401 3582
 		{
3402
-			if (!is_array($cache_misses))
3403
-				$cache_misses = array();
3583
+			if (!is_array($cache_misses)) {
3584
+							$cache_misses = array();
3585
+			}
3404 3586
 
3405 3587
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3406 3588
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3407 3589
 		}
3408 3590
 	}
3409 3591
 
3410
-	if (function_exists('call_integration_hook') && isset($value))
3411
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3592
+	if (function_exists('call_integration_hook') && isset($value)) {
3593
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3594
+	}
3412 3595
 
3413 3596
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3414 3597
 }
@@ -3430,8 +3613,9 @@  discard block
 block discarded – undo
3430 3613
 	global $cacheAPI;
3431 3614
 
3432 3615
 	// If we can't get to the API, can't do this.
3433
-	if (empty($cacheAPI))
3434
-		return;
3616
+	if (empty($cacheAPI)) {
3617
+			return;
3618
+	}
3435 3619
 
3436 3620
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3437 3621
 	$cacheAPI->cleanCache($type);
@@ -3456,8 +3640,9 @@  discard block
 block discarded – undo
3456 3640
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3457 3641
 
3458 3642
 	// Come on!
3459
-	if (empty($data))
3460
-		return array();
3643
+	if (empty($data)) {
3644
+			return array();
3645
+	}
3461 3646
 
3462 3647
 	// Set a nice default var.
3463 3648
 	$image = '';
@@ -3465,11 +3650,11 @@  discard block
 block discarded – undo
3465 3650
 	// Gravatar has been set as mandatory!
3466 3651
 	if (!empty($modSettings['gravatarOverride']))
3467 3652
 	{
3468
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3469
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3470
-
3471
-		else if (!empty($data['email']))
3472
-			$image = get_gravatar_url($data['email']);
3653
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3654
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3655
+		} else if (!empty($data['email'])) {
3656
+					$image = get_gravatar_url($data['email']);
3657
+		}
3473 3658
 	}
3474 3659
 
3475 3660
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3481,54 +3666,60 @@  discard block
 block discarded – undo
3481 3666
 			// Gravatar.
3482 3667
 			if (stristr($data['avatar'], 'gravatar://'))
3483 3668
 			{
3484
-				if ($data['avatar'] == 'gravatar://')
3485
-					$image = get_gravatar_url($data['email']);
3486
-
3487
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3488
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3669
+				if ($data['avatar'] == 'gravatar://') {
3670
+									$image = get_gravatar_url($data['email']);
3671
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3672
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3673
+				}
3489 3674
 			}
3490 3675
 
3491 3676
 			// External url.
3492 3677
 			else
3493 3678
 			{
3494 3679
 				// Using ssl?
3495
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3496
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3680
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3681
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3682
+				}
3497 3683
 
3498 3684
 				// Just a plain external url.
3499
-				else
3500
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3685
+				else {
3686
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3687
+				}
3501 3688
 			}
3502 3689
 		}
3503 3690
 
3504 3691
 		// Perhaps this user has an attachment as avatar...
3505
-		else if (!empty($data['filename']))
3506
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3692
+		else if (!empty($data['filename'])) {
3693
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3694
+		}
3507 3695
 
3508 3696
 		// Right... no avatar... use our default image.
3509
-		else
3510
-			$image = $modSettings['avatar_url'] . '/default.png';
3697
+		else {
3698
+					$image = $modSettings['avatar_url'] . '/default.png';
3699
+		}
3511 3700
 	}
3512 3701
 
3513 3702
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3514 3703
 
3515 3704
 	// 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.
3516
-	if (!empty($image))
3517
-		return array(
3705
+	if (!empty($image)) {
3706
+			return array(
3518 3707
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3519 3708
 			'image' => '<img class="avatar" src="' . $image . '" />',
3520 3709
 			'href' => $image,
3521 3710
 			'url' => $image,
3522 3711
 		);
3712
+	}
3523 3713
 
3524 3714
 	// Fallback to make life easier for everyone...
3525
-	else
3526
-		return array(
3715
+	else {
3716
+			return array(
3527 3717
 			'name' => '',
3528 3718
 			'image' => '',
3529 3719
 			'href' => '',
3530 3720
 			'url' => '',
3531 3721
 		);
3532
-}
3722
+	}
3723
+	}
3533 3724
 
3534 3725
 ?>
3535 3726
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Calendar.template.php 1 patch
Braces   +154 added lines, -118 removed lines patch added patch discarded remove patch
@@ -40,16 +40,14 @@  discard block
 block discarded – undo
40 40
 				', template_show_upcoming_list('main'), '
41 41
 			</div>
42 42
 		';
43
-	}
44
-	elseif ($context['calendar_view'] == 'viewweek')
43
+	} elseif ($context['calendar_view'] == 'viewweek')
45 44
 	{
46 45
 		echo '
47 46
 			<div id="main_grid">
48 47
 				', template_show_week_grid('main'), '
49 48
 			</div>
50 49
 		';
51
-	}
52
-	else
50
+	} else
53 51
 	{
54 52
 		echo '
55 53
 			<div id="main_grid">
@@ -75,8 +73,9 @@  discard block
 block discarded – undo
75 73
 	global $context, $scripturl, $txt;
76 74
 
77 75
 	// Bail out if we have nothing to work with
78
-	if (!isset($context['calendar_grid_' . $grid_name]))
79
-		return false;
76
+	if (!isset($context['calendar_grid_' . $grid_name])) {
77
+			return false;
78
+	}
80 79
 
81 80
 	// Protect programmer sanity
82 81
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -113,11 +112,13 @@  discard block
 block discarded – undo
113 112
 					<li class="windowbg">
114 113
 						<strong class="event_title">', $event['link'], '</strong>';
115 114
 
116
-				if ($event['can_edit'])
117
-					echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
115
+				if ($event['can_edit']) {
116
+									echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
117
+				}
118 118
 
119
-				if ($event['can_export'])
120
-					echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
119
+				if ($event['can_export']) {
120
+									echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
121
+				}
121 122
 
122 123
 				echo '
123 124
 						<br>';
@@ -125,14 +126,14 @@  discard block
 block discarded – undo
125 126
 				if (!empty($event['allday']))
126 127
 				{
127 128
 					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
128
-				}
129
-				else
129
+				} else
130 130
 				{
131 131
 					// Display event info relative to user's local timezone
132 132
 					echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
133 133
 
134
-					if ($event['start_date_local'] != $event['end_date_local'])
135
-						echo trim($event['end_date_local']) . ', ';
134
+					if ($event['start_date_local'] != $event['end_date_local']) {
135
+											echo trim($event['end_date_local']) . ', ';
136
+					}
136 137
 
137 138
 					echo trim($event['end_time_local']);
138 139
 
@@ -141,23 +142,27 @@  discard block
 block discarded – undo
141 142
 					{
142 143
 						echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
143 144
 
144
-						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
145
-							echo trim($event['start_date_orig']), ', ';
145
+						if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) {
146
+													echo trim($event['start_date_orig']), ', ';
147
+						}
146 148
 
147 149
 						echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
148 150
 
149
-						if ($event['start_date_orig'] != $event['end_date_orig'])
150
-							echo trim($event['end_date_orig']) . ', ';
151
+						if ($event['start_date_orig'] != $event['end_date_orig']) {
152
+													echo trim($event['end_date_orig']) . ', ';
153
+						}
151 154
 
152 155
 						echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
153 156
 					}
154 157
 					// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
155
-					else
156
-						echo ' ', $event['tz_abbrev'], '</time>';
158
+					else {
159
+											echo ' ', $event['tz_abbrev'], '</time>';
160
+					}
157 161
 				}
158 162
 
159
-				if (!empty($event['location']))
160
-					echo '<br>', $event['location'];
163
+				if (!empty($event['location'])) {
164
+									echo '<br>', $event['location'];
165
+				}
161 166
 
162 167
 				echo '
163 168
 					</li>';
@@ -189,8 +194,9 @@  discard block
 block discarded – undo
189 194
 
190 195
 			$birthdays = array();
191 196
 
192
-			foreach ($date as $member)
193
-				$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
197
+			foreach ($date as $member) {
198
+							$birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>';
199
+			}
194 200
 
195 201
 			echo implode(', ', $birthdays);
196 202
 
@@ -221,8 +227,9 @@  discard block
 block discarded – undo
221 227
 			$date_local = $date['date_local'];
222 228
 			unset($date['date_local']);
223 229
 
224
-			foreach ($date as $holiday)
225
-				$holidays[] = $holiday . ' (' . $date_local . ')';
230
+			foreach ($date as $holiday) {
231
+							$holidays[] = $holiday . ' (' . $date_local . ')';
232
+			}
226 233
 		}
227 234
 
228 235
 		echo implode(', ', $holidays);
@@ -245,17 +252,19 @@  discard block
 block discarded – undo
245 252
 	global $context, $txt, $scripturl, $modSettings;
246 253
 
247 254
 	// If the grid doesn't exist, no point in proceeding.
248
-	if (!isset($context['calendar_grid_' . $grid_name]))
249
-		return false;
255
+	if (!isset($context['calendar_grid_' . $grid_name])) {
256
+			return false;
257
+	}
250 258
 
251 259
 	// A handy little pointer variable.
252 260
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
253 261
 
254 262
 	// Some conditions for whether or not we should show the week links *here*.
255
-	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false)))
256
-		$show_week_links = true;
257
-	else
258
-		$show_week_links = false;
263
+	if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) {
264
+			$show_week_links = true;
265
+	} else {
266
+			$show_week_links = false;
267
+	}
259 268
 
260 269
 	// Assuming that we've not disabled it, show the title block!
261 270
 	if (empty($calendar_data['disable_title']))
@@ -294,8 +303,9 @@  discard block
 block discarded – undo
294 303
 	}
295 304
 
296 305
 	// Show the controls on main grids
297
-	if ($is_mini === false)
298
-		template_calendar_top($calendar_data);
306
+	if ($is_mini === false) {
307
+			template_calendar_top($calendar_data);
308
+	}
299 309
 
300 310
 	// Finally, the main calendar table.
301 311
 	echo '<table class="calendar_table">';
@@ -306,8 +316,9 @@  discard block
 block discarded – undo
306 316
 		echo '<tr>';
307 317
 
308 318
 		// If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared!
309
-		if ($show_week_links === true)
310
-			echo '<th>&nbsp;</th>';
319
+		if ($show_week_links === true) {
320
+					echo '<th>&nbsp;</th>';
321
+		}
311 322
 
312 323
 		// Now, loop through each actual day of the week.
313 324
 		foreach ($calendar_data['week_days'] as $day)
@@ -354,27 +365,29 @@  discard block
 block discarded – undo
354 365
 				// Additional classes are given for events, holidays, and birthdays.
355 366
 				if (!empty($day['events']) && !empty($calendar_data['highlight']['events']))
356 367
 				{
357
-					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3)))
358
-						$classes[] = 'events';
359
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3)))
360
-						$classes[] = 'events';
368
+					if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) {
369
+											$classes[] = 'events';
370
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) {
371
+											$classes[] = 'events';
372
+					}
361 373
 				}
362 374
 				if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays']))
363 375
 				{
364
-					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3)))
365
-						$classes[] = 'holidays';
366
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3)))
367
-						$classes[] = 'holidays';
376
+					if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) {
377
+											$classes[] = 'holidays';
378
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) {
379
+											$classes[] = 'holidays';
380
+					}
368 381
 				}
369 382
 				if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays']))
370 383
 				{
371
-					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3)))
372
-						$classes[] = 'birthdays';
373
-					elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3)))
374
-						$classes[] = 'birthdays';
384
+					if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) {
385
+											$classes[] = 'birthdays';
386
+					} elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) {
387
+											$classes[] = 'birthdays';
388
+					}
375 389
 				}
376
-			}
377
-			else
390
+			} else
378 391
 			{
379 392
 				// Default Classes (either compact or comfortable and disabled).
380 393
 				$classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable';
@@ -392,19 +405,21 @@  discard block
 block discarded – undo
392 405
 				$title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : '';
393 406
 
394 407
 				// The actual day number - be it a link, or just plain old text!
395
-				if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
396
-					echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
397
-				elseif ($is_mini)
398
-					echo '<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
399
-				else
400
-					echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
408
+				if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
409
+									echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
410
+				} elseif ($is_mini) {
411
+									echo '<a href="', $scripturl, '?action=calendar;', $context['calendar_view'], ';year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>';
412
+				} else {
413
+									echo '<span class="day_text">', $title_prefix, $day['day'], '</span>';
414
+				}
401 415
 
402 416
 				// A lot of stuff, we're not showing on mini-calendars to conserve space.
403 417
 				if ($is_mini === false)
404 418
 				{
405 419
 					// Holidays are always fun, let's show them!
406
-					if (!empty($day['holidays']))
407
-						echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
420
+					if (!empty($day['holidays'])) {
421
+											echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>';
422
+					}
408 423
 
409 424
 					// Happy Birthday Dear, Member!
410 425
 					if (!empty($day['birthdays']))
@@ -422,14 +437,16 @@  discard block
 block discarded – undo
422 437
 							echo '<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'] || ($count == 10 && $use_js_hide) ? '' : ', ';
423 438
 
424 439
 							// 9...10! Let's stop there.
425
-							if ($birthday_count == 10 && $use_js_hide)
426
-								// !!TODO - Inline CSS and JavaScript should be moved.
440
+							if ($birthday_count == 10 && $use_js_hide) {
441
+															// !!TODO - Inline CSS and JavaScript should be moved.
427 442
 								echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, ';
443
+							}
428 444
 
429 445
 							++$birthday_count;
430 446
 						}
431
-						if ($use_js_hide)
432
-							echo '</span>';
447
+						if ($use_js_hide) {
448
+													echo '</span>';
449
+						}
433 450
 
434 451
 						echo '</div>';
435 452
 					}
@@ -439,8 +456,9 @@  discard block
 block discarded – undo
439 456
 					{
440 457
 						// Sort events by start time (all day events will be listed first)
441 458
 						uasort($day['events'], function($a, $b) {
442
-						    if ($a['start_timestamp'] == $b['start_timestamp'])
443
-						        return 0;
459
+						    if ($a['start_timestamp'] == $b['start_timestamp']) {
460
+						    						        return 0;
461
+						    }
444 462
 						    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
445 463
 						});
446 464
 
@@ -456,17 +474,19 @@  discard block
 block discarded – undo
456 474
 
457 475
 							echo '<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">', $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
458 476
 
459
-							if (!empty($event['start_time_local']) && $event['starts_today'] == true)
460
-								echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
461
-							elseif (!empty($event['end_time_local']) && $event['ends_today'] == true)
462
-								echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
463
-							elseif (!empty($event['allday']))
464
-								echo $txt['calendar_allday'];
477
+							if (!empty($event['start_time_local']) && $event['starts_today'] == true) {
478
+															echo trim(str_replace(':00 ', ' ', $event['start_time_local']));
479
+							} elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) {
480
+															echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local']));
481
+							} elseif (!empty($event['allday'])) {
482
+															echo $txt['calendar_allday'];
483
+							}
465 484
 
466 485
 							echo '</span>';
467 486
 
468
-							if (!empty($event['location']))
469
-								echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
487
+							if (!empty($event['location'])) {
488
+															echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
489
+							}
470 490
 
471 491
 							if ($event['can_edit'] || $event['can_export'])
472 492
 							{
@@ -503,10 +523,11 @@  discard block
 block discarded – undo
503 523
 			// Otherwise, assuming it's not a mini-calendar, we can show previous / next month days!
504 524
 			elseif ($is_mini === false)
505 525
 			{
506
-				if (empty($current_month_started) && !empty($context['calendar_grid_prev']))
507
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
508
-				elseif (!empty($current_month_started) && !empty($context['calendar_grid_next']))
509
-					echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
526
+				if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) {
527
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>';
528
+				} elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) {
529
+									echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>';
530
+				}
510 531
 			}
511 532
 
512 533
 			// Close this day and increase var count.
@@ -532,8 +553,9 @@  discard block
 block discarded – undo
532 553
 	global $context, $txt, $scripturl, $modSettings;
533 554
 
534 555
 	// We might have no reason to proceed, if the variable isn't there.
535
-	if (!isset($context['calendar_grid_' . $grid_name]))
536
-		return false;
556
+	if (!isset($context['calendar_grid_' . $grid_name])) {
557
+			return false;
558
+	}
537 559
 
538 560
 	// Handy pointer.
539 561
 	$calendar_data = &$context['calendar_grid_' . $grid_name];
@@ -568,8 +590,9 @@  discard block
 block discarded – undo
568 590
 					}
569 591
 
570 592
 					// The Month Title + Week Number...
571
-					if (!empty($calendar_data['week_title']))
572
-							echo $calendar_data['week_title'];
593
+					if (!empty($calendar_data['week_title'])) {
594
+												echo $calendar_data['week_title'];
595
+					}
573 596
 
574 597
 					echo '
575 598
 					</h3>
@@ -608,10 +631,11 @@  discard block
 block discarded – undo
608 631
 						<tr class="days_wrapper">
609 632
 							<td class="', implode(' ', $classes), ' act_day">';
610 633
 							// Should the day number be a link?
611
-							if (!empty($modSettings['cal_daysaslink']) && $context['can_post'])
612
-								echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
613
-							else
614
-								echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
634
+							if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) {
635
+															echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>';
636
+							} else {
637
+															echo $txt['days'][$day['day_of_week']], ' - ', $day['day'];
638
+							}
615 639
 
616 640
 							echo '</td>
617 641
 							<td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">';
@@ -620,8 +644,9 @@  discard block
 block discarded – undo
620 644
 							{
621 645
 								// Sort events by start time (all day events will be listed first)
622 646
 								uasort($day['events'], function($a, $b) {
623
-								    if ($a['start_timestamp'] == $b['start_timestamp'])
624
-								        return 0;
647
+								    if ($a['start_timestamp'] == $b['start_timestamp']) {
648
+								    								        return 0;
649
+								    }
625 650
 								    return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1;
626 651
 								});
627 652
 
@@ -633,15 +658,17 @@  discard block
 block discarded – undo
633 658
 
634 659
 									echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">';
635 660
 
636
-									if (!empty($event['start_time_local']))
637
-										echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
638
-									else
639
-										echo $txt['calendar_allday'];
661
+									if (!empty($event['start_time_local'])) {
662
+																			echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' &ndash; ' . trim($event['end_time_local']) : '';
663
+									} else {
664
+																			echo $txt['calendar_allday'];
665
+									}
640 666
 
641 667
 									echo '</span>';
642 668
 
643
-									if (!empty($event['location']))
644
-										echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
669
+									if (!empty($event['location'])) {
670
+																			echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>';
671
+									}
645 672
 
646 673
 									if (!empty($event_icons_needed))
647 674
 									{
@@ -678,8 +705,7 @@  discard block
 block discarded – undo
678 705
 									</div>
679 706
 									<br class="clear">';
680 707
 								}
681
-							}
682
-							else
708
+							} else
683 709
 							{
684 710
 								if (!empty($context['can_post']))
685 711
 								{
@@ -692,8 +718,9 @@  discard block
 block discarded – undo
692 718
 							echo '</td>
693 719
 							<td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">';
694 720
 							// Show any holidays!
695
-							if (!empty($day['holidays']))
696
-								echo implode('<br>', $day['holidays']);
721
+							if (!empty($day['holidays'])) {
722
+															echo implode('<br>', $day['holidays']);
723
+							}
697 724
 
698 725
 							echo '</td>
699 726
 							<td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">';
@@ -751,8 +778,7 @@  discard block
 block discarded – undo
751 778
 				<input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="date_input end" data-type="date">
752 779
 				<input type="submit" class="button" style="float:none" id="view_button" value="', $txt['view'], '">
753 780
 			</form>';
754
-	}
755
-	else
781
+	} else
756 782
 	{
757 783
 		echo'
758 784
 			<form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '">
@@ -794,8 +820,9 @@  discard block
 block discarded – undo
794 820
 	echo '
795 821
 		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);" style="margin: 0;">';
796 822
 
797
-	if (!empty($context['event']['new']))
798
-		echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
823
+	if (!empty($context['event']['new'])) {
824
+			echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">';
825
+	}
799 826
 
800 827
 	// Start the main table.
801 828
 	echo '
@@ -845,9 +872,10 @@  discard block
 block discarded – undo
845 872
 		{
846 873
 			echo '
847 874
 								<optgroup label="', $category['name'], '">';
848
-			foreach ($category['boards'] as $board)
849
-				echo '
875
+			foreach ($category['boards'] as $board) {
876
+							echo '
850 877
 									<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '&nbsp;</option>';
878
+			}
851 879
 			echo '
852 880
 								</optgroup>';
853 881
 		}
@@ -883,9 +911,10 @@  discard block
 block discarded – undo
883 911
 							<span class="label">', $txt['calendar_timezone'], '</span>
884 912
 							<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
885 913
 
886
-	foreach ($context['all_timezones'] as $tz => $tzname)
887
-		echo '
914
+	foreach ($context['all_timezones'] as $tz => $tzname) {
915
+			echo '
888 916
 								<option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
917
+	}
889 918
 
890 919
 	echo '
891 920
 							</select>
@@ -900,9 +929,10 @@  discard block
 block discarded – undo
900 929
 	echo '
901 930
 				<input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button">';
902 931
 	// Delete button?
903
-	if (empty($context['event']['new']))
904
-		echo '
932
+	if (empty($context['event']['new'])) {
933
+			echo '
905 934
 				<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button you_sure">';
935
+	}
906 936
 
907 937
 	echo '
908 938
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -946,9 +976,10 @@  discard block
 block discarded – undo
946 976
 
947 977
 		foreach ($context['clockicons'] as $t => $v)
948 978
 		{
949
-			foreach ($v as $i)
950
-				echo '
979
+			foreach ($v as $i) {
980
+							echo '
951 981
 			icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
982
+			}
952 983
 		}
953 984
 
954 985
 		echo '
@@ -973,13 +1004,14 @@  discard block
 block discarded – undo
973 1004
 
974 1005
 		foreach ($context['clockicons'] as $t => $v)
975 1006
 		{
976
-			foreach ($v as $i)
977
-				echo '
1007
+			foreach ($v as $i) {
1008
+							echo '
978 1009
 			if (', $t, ' >= ', $i, ')
979 1010
 			{
980 1011
 				turnon.push("', $t, '_', $i, '");
981 1012
 				', $t, ' -= ', $i, ';
982 1013
 			}';
1014
+			}
983 1015
 		}
984 1016
 
985 1017
 		echo '
@@ -1043,9 +1075,10 @@  discard block
 block discarded – undo
1043 1075
 
1044 1076
 	foreach ($context['clockicons'] as $t => $v)
1045 1077
 	{
1046
-		foreach ($v as $i)
1047
-			echo '
1078
+		foreach ($v as $i) {
1079
+					echo '
1048 1080
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1081
+		}
1049 1082
 	}
1050 1083
 
1051 1084
 	echo '
@@ -1062,13 +1095,14 @@  discard block
 block discarded – undo
1062 1095
 
1063 1096
 	foreach ($context['clockicons'] as $t => $v)
1064 1097
 	{
1065
-		foreach ($v as $i)
1066
-			echo '
1098
+		foreach ($v as $i) {
1099
+					echo '
1067 1100
 		if (', $t, ' >= ', $i, ')
1068 1101
 		{
1069 1102
 			turnon.push("', $t, '_', $i, '");
1070 1103
 			', $t, ' -= ', $i, ';
1071 1104
 		}';
1105
+		}
1072 1106
 	}
1073 1107
 
1074 1108
 	echo '
@@ -1127,9 +1161,10 @@  discard block
 block discarded – undo
1127 1161
 
1128 1162
 	foreach ($context['clockicons'] as $t => $v)
1129 1163
 	{
1130
-		foreach ($v as $i)
1131
-			echo '
1164
+		foreach ($v as $i) {
1165
+					echo '
1132 1166
 		icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');';
1167
+		}
1133 1168
 	}
1134 1169
 
1135 1170
 	echo '
@@ -1150,13 +1185,14 @@  discard block
 block discarded – undo
1150 1185
 
1151 1186
 	foreach ($context['clockicons'] as $t => $v)
1152 1187
 	{
1153
-		foreach ($v as $i)
1154
-		echo '
1188
+		foreach ($v as $i) {
1189
+				echo '
1155 1190
 		if (', $t, ' >= ', $i, ')
1156 1191
 		{
1157 1192
 			turnon.push("', $t, '_', $i, '");
1158 1193
 			', $t, ' -= ', $i, ';
1159 1194
 		}';
1195
+		}
1160 1196
 	}
1161 1197
 
1162 1198
 	echo '
Please login to merge, or discard this patch.