Completed
Pull Request — release-2.1 (#5077)
by Mathias
07:41 queued 01:11
created
SSI.php 1 patch
Braces   +432 added lines, -309 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Don't do anything if SMF is already loaded.
15
-if (defined('SMF'))
15
+if (defined('SMF')) {
16 16
 	return true;
17
+}
17 18
 
18 19
 define('SMF', 'SSI');
19 20
 
@@ -28,16 +29,18 @@  discard block
 block discarded – undo
28 29
 $time_start = microtime(true);
29 30
 
30 31
 // Just being safe...
31
-foreach (array('db_character_set', 'cachedir') as $variable)
32
+foreach (array('db_character_set', 'cachedir') as $variable) {
32 33
 	if (isset($GLOBALS[$variable]))
33 34
 		unset($GLOBALS[$variable]);
35
+}
34 36
 
35 37
 // Get the forum's settings for database and file paths.
36 38
 require_once(dirname(__FILE__) . '/Settings.php');
37 39
 
38 40
 // Make absolutely sure the cache directory is defined.
39
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
41
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
40 42
 	$cachedir = $boarddir . '/cache';
43
+}
41 44
 
42 45
 $ssi_error_reporting = error_reporting(E_ALL);
43 46
 /* Set this to one of three values depending on what you want to happen in the case of a fatal error.
@@ -48,16 +51,19 @@  discard block
 block discarded – undo
48 51
 $ssi_on_error_method = false;
49 52
 
50 53
 // Don't do john didley if the forum's been shut down completely.
51
-if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true))
54
+if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) {
52 55
 	die($mmessage);
56
+}
53 57
 
54 58
 // Fix for using the current directory as a path.
55
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
59
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
56 60
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
61
+}
57 62
 
58 63
 // For php below 7
59
-if (!function_exists('random_int'))
64
+if (!function_exists('random_int')) {
60 65
 	require_once ($sourcedir . '/random_compat/random_int.php');
66
+}
61 67
 
62 68
 // Load the important includes.
63 69
 require_once($sourcedir . '/QueryString.php');
@@ -82,26 +88,30 @@  discard block
 block discarded – undo
82 88
 cleanRequest();
83 89
 
84 90
 // Seed the random generator?
85
-if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69)
91
+if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69) {
86 92
 	smf_seed_generator();
93
+}
87 94
 
88 95
 // Check on any hacking attempts.
89
-if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
96
+if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
90 97
 	die('No direct access...');
91
-elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme)
98
+} elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) {
92 99
 	die('No direct access...');
93
-elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme)
100
+} elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) {
94 101
 	die('No direct access...');
95
-elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers)
102
+} elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) {
96 103
 	die('No direct access...');
97
-if (isset($_REQUEST['context']))
104
+}
105
+if (isset($_REQUEST['context'])) {
98 106
 	die('No direct access...');
107
+}
99 108
 
100 109
 // Gzip output? (because it must be boolean and true, this can't be hacked.)
101
-if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>='))
110
+if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) {
102 111
 	ob_start('ob_gzhandler');
103
-else
112
+} else {
104 113
 	$modSettings['enableCompressedOutput'] = '0';
114
+}
105 115
 
106 116
 /**
107 117
  * An autoloader for certain classes.
@@ -150,9 +160,9 @@  discard block
 block discarded – undo
150 160
 ob_start('ob_sessrewrite');
151 161
 
152 162
 // Start the session... known to scramble SSI includes in cases...
153
-if (!headers_sent())
163
+if (!headers_sent()) {
154 164
 	loadSession();
155
-else
165
+} else
156 166
 {
157 167
 	if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()]))
158 168
 	{
@@ -186,12 +196,14 @@  discard block
 block discarded – undo
186 196
 loadTheme(isset($ssi_theme) ? (int) $ssi_theme : 0);
187 197
 
188 198
 // @todo: probably not the best place, but somewhere it should be set...
189
-if (!headers_sent())
199
+if (!headers_sent()) {
190 200
 	header('content-type: text/html; charset=' . (empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set']));
201
+}
191 202
 
192 203
 // Take care of any banning that needs to be done.
193
-if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true))
204
+if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) {
194 205
 	is_not_banned();
206
+}
195 207
 
196 208
 // Do we allow guests in here?
197 209
 if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php')
@@ -206,17 +218,19 @@  discard block
 block discarded – undo
206 218
 {
207 219
 	$context['template_layers'] = $ssi_layers;
208 220
 	template_header();
209
-}
210
-else
221
+} else {
211 222
 	setupThemeContext();
223
+}
212 224
 
213 225
 // Make sure they didn't muss around with the settings... but only if it's not cli.
214
-if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '')
226
+if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') {
215 227
 	trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);
228
+}
216 229
 
217 230
 // Without visiting the forum this session variable might not be set on submit.
218
-if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote'))
231
+if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) {
219 232
 	$_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
233
+}
220 234
 
221 235
 // Have the ability to easily add functions to SSI.
222 236
 call_integration_hook('integrate_SSI');
@@ -225,11 +239,13 @@  discard block
 block discarded – undo
225 239
 if (basename($_SERVER['PHP_SELF']) == 'SSI.php')
226 240
 {
227 241
 	// You shouldn't just access SSI.php directly by URL!!
228
-	if (!isset($_GET['ssi_function']))
229
-		die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
242
+	if (!isset($_GET['ssi_function'])) {
243
+			die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
244
+	}
230 245
 	// Call a function passed by GET.
231
-	if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest']))
232
-		call_user_func('ssi_' . $_GET['ssi_function']);
246
+	if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) {
247
+			call_user_func('ssi_' . $_GET['ssi_function']);
248
+	}
233 249
 	exit;
234 250
 }
235 251
 
@@ -246,9 +262,10 @@  discard block
 block discarded – undo
246 262
  */
247 263
 function ssi_shutdown()
248 264
 {
249
-	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown')
250
-		template_footer();
251
-}
265
+	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') {
266
+			template_footer();
267
+	}
268
+	}
252 269
 
253 270
 /**
254 271
  * Display a welcome message, like: Hey, User, you have 0 messages, 0 are new.
@@ -261,15 +278,17 @@  discard block
 block discarded – undo
261 278
 
262 279
 	if ($output_method == 'echo')
263 280
 	{
264
-		if ($context['user']['is_guest'])
265
-			echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
266
-		else
267
-			echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
281
+		if ($context['user']['is_guest']) {
282
+					echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
283
+		} else {
284
+					echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
285
+		}
268 286
 	}
269 287
 	// Don't echo... then do what?!
270
-	else
271
-		return $context['user'];
272
-}
288
+	else {
289
+			return $context['user'];
290
+	}
291
+	}
273 292
 
274 293
 /**
275 294
  * Display a menu bar, like is displayed at the top of the forum.
@@ -280,12 +299,14 @@  discard block
 block discarded – undo
280 299
 {
281 300
 	global $context;
282 301
 
283
-	if ($output_method == 'echo')
284
-		template_menu();
302
+	if ($output_method == 'echo') {
303
+			template_menu();
304
+	}
285 305
 	// What else could this do?
286
-	else
287
-		return $context['menu_buttons'];
288
-}
306
+	else {
307
+			return $context['menu_buttons'];
308
+	}
309
+	}
289 310
 
290 311
 /**
291 312
  * Show a logout link.
@@ -297,20 +318,23 @@  discard block
 block discarded – undo
297 318
 {
298 319
 	global $context, $txt, $scripturl;
299 320
 
300
-	if ($redirect_to != '')
301
-		$_SESSION['logout_url'] = $redirect_to;
321
+	if ($redirect_to != '') {
322
+			$_SESSION['logout_url'] = $redirect_to;
323
+	}
302 324
 
303 325
 	// Guests can't log out.
304
-	if ($context['user']['is_guest'])
305
-		return false;
326
+	if ($context['user']['is_guest']) {
327
+			return false;
328
+	}
306 329
 
307 330
 	$link = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>';
308 331
 
309
-	if ($output_method == 'echo')
310
-		echo $link;
311
-	else
312
-		return $link;
313
-}
332
+	if ($output_method == 'echo') {
333
+			echo $link;
334
+	} else {
335
+			return $link;
336
+	}
337
+	}
314 338
 
315 339
 /**
316 340
  * Recent post list:   [board] Subject by Poster    Date
@@ -326,17 +350,17 @@  discard block
 block discarded – undo
326 350
 	global $modSettings, $context;
327 351
 
328 352
 	// Excluding certain boards...
329
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
330
-		$exclude_boards = array($modSettings['recycle_board']);
331
-	else
332
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
353
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
354
+			$exclude_boards = array($modSettings['recycle_board']);
355
+	} else {
356
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
357
+	}
333 358
 
334 359
 	// What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter.
335 360
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
336 361
 	{
337 362
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
338
-	}
339
-	elseif ($include_boards != null)
363
+	} elseif ($include_boards != null)
340 364
 	{
341 365
 		$include_boards = array();
342 366
 	}
@@ -373,8 +397,9 @@  discard block
 block discarded – undo
373 397
 {
374 398
 	global $modSettings;
375 399
 
376
-	if (empty($post_ids))
377
-		return;
400
+	if (empty($post_ids)) {
401
+			return;
402
+	}
378 403
 
379 404
 	// Allow the user to request more than one - why not?
380 405
 	$post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
@@ -409,8 +434,9 @@  discard block
 block discarded – undo
409 434
 	global $scripturl, $txt, $user_info;
410 435
 	global $modSettings, $smcFunc, $context;
411 436
 
412
-	if (!empty($modSettings['enable_likes']))
413
-		$context['can_like'] = allowedTo('likes_like');
437
+	if (!empty($modSettings['enable_likes'])) {
438
+			$context['can_like'] = allowedTo('likes_like');
439
+	}
414 440
 
415 441
 	// Find all the posts. Newer ones will have higher IDs.
416 442
 	$request = $smcFunc['db_query']('substring', '
@@ -476,12 +502,13 @@  discard block
 block discarded – undo
476 502
 		);
477 503
 
478 504
 		// Get the likes for each message.
479
-		if (!empty($modSettings['enable_likes']))
480
-			$posts[$row['id_msg']]['likes'] = array(
505
+		if (!empty($modSettings['enable_likes'])) {
506
+					$posts[$row['id_msg']]['likes'] = array(
481 507
 				'count' => $row['likes'],
482 508
 				'you' => in_array($row['id_msg'], prepareLikesContext($row['id_topic'])),
483 509
 				'can_like' => !$context['user']['is_guest'] && $row['id_member'] != $context['user']['id'] && !empty($context['can_like']),
484 510
 			);
511
+		}
485 512
 	}
486 513
 	$smcFunc['db_free_result']($request);
487 514
 
@@ -489,13 +516,14 @@  discard block
 block discarded – undo
489 516
 	call_integration_hook('integrate_ssi_queryPosts', array(&$posts));
490 517
 
491 518
 	// Just return it.
492
-	if ($output_method != 'echo' || empty($posts))
493
-		return $posts;
519
+	if ($output_method != 'echo' || empty($posts)) {
520
+			return $posts;
521
+	}
494 522
 
495 523
 	echo '
496 524
 		<table style="border: none" class="ssi_table">';
497
-	foreach ($posts as $post)
498
-		echo '
525
+	foreach ($posts as $post) {
526
+			echo '
499 527
 			<tr>
500 528
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
501 529
 					[', $post['board']['link'], ']
@@ -509,6 +537,7 @@  discard block
 block discarded – undo
509 537
 					', $post['time'], '
510 538
 				</td>
511 539
 			</tr>';
540
+	}
512 541
 	echo '
513 542
 		</table>';
514 543
 }
@@ -526,25 +555,26 @@  discard block
 block discarded – undo
526 555
 	global $settings, $scripturl, $txt, $user_info;
527 556
 	global $modSettings, $smcFunc, $context;
528 557
 
529
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
530
-		$exclude_boards = array($modSettings['recycle_board']);
531
-	else
532
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
558
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
559
+			$exclude_boards = array($modSettings['recycle_board']);
560
+	} else {
561
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
562
+	}
533 563
 
534 564
 	// Only some boards?.
535 565
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
536 566
 	{
537 567
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
538
-	}
539
-	elseif ($include_boards != null)
568
+	} elseif ($include_boards != null)
540 569
 	{
541 570
 		$output_method = $include_boards;
542 571
 		$include_boards = array();
543 572
 	}
544 573
 
545 574
 	$icon_sources = array();
546
-	foreach ($context['stable_icons'] as $icon)
547
-		$icon_sources[$icon] = 'images_url';
575
+	foreach ($context['stable_icons'] as $icon) {
576
+			$icon_sources[$icon] = 'images_url';
577
+	}
548 578
 
549 579
 	// Find all the posts in distinct topics.  Newer ones will have higher IDs.
550 580
 	$request = $smcFunc['db_query']('substring', '
@@ -569,13 +599,15 @@  discard block
 block discarded – undo
569 599
 		)
570 600
 	);
571 601
 	$topics = array();
572
-	while ($row = $smcFunc['db_fetch_assoc']($request))
573
-		$topics[$row['id_topic']] = $row;
602
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
603
+			$topics[$row['id_topic']] = $row;
604
+	}
574 605
 	$smcFunc['db_free_result']($request);
575 606
 
576 607
 	// Did we find anything? If not, bail.
577
-	if (empty($topics))
578
-		return array();
608
+	if (empty($topics)) {
609
+			return array();
610
+	}
579 611
 
580 612
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
581 613
 
@@ -603,21 +635,24 @@  discard block
 block discarded – undo
603 635
 	while ($row = $smcFunc['db_fetch_assoc']($request))
604 636
 	{
605 637
 		$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => '&#10;')));
606
-		if ($smcFunc['strlen']($row['body']) > 128)
607
-			$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
638
+		if ($smcFunc['strlen']($row['body']) > 128) {
639
+					$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
640
+		}
608 641
 
609 642
 		// Censor the subject.
610 643
 		censorText($row['subject']);
611 644
 		censorText($row['body']);
612 645
 
613 646
 		// Recycled icon
614
-		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board'])
615
-			$row['icon'] = 'recycled';
647
+		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) {
648
+					$row['icon'] = 'recycled';
649
+		}
616 650
 
617
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
618
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
619
-		elseif (!isset($icon_sources[$row['icon']]))
620
-			$icon_sources[$row['icon']] = 'images_url';
651
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
652
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
653
+		} elseif (!isset($icon_sources[$row['icon']])) {
654
+					$icon_sources[$row['icon']] = 'images_url';
655
+		}
621 656
 
622 657
 		// Build the array.
623 658
 		$posts[] = array(
@@ -656,13 +691,14 @@  discard block
 block discarded – undo
656 691
 	call_integration_hook('integrate_ssi_recentTopics', array(&$posts));
657 692
 
658 693
 	// Just return it.
659
-	if ($output_method != 'echo' || empty($posts))
660
-		return $posts;
694
+	if ($output_method != 'echo' || empty($posts)) {
695
+			return $posts;
696
+	}
661 697
 
662 698
 	echo '
663 699
 		<table style="border: none" class="ssi_table">';
664
-	foreach ($posts as $post)
665
-		echo '
700
+	foreach ($posts as $post) {
701
+			echo '
666 702
 			<tr>
667 703
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
668 704
 					[', $post['board']['link'], ']
@@ -676,6 +712,7 @@  discard block
 block discarded – undo
676 712
 					', $post['time'], '
677 713
 				</td>
678 714
 			</tr>';
715
+	}
679 716
 	echo '
680 717
 		</table>';
681 718
 }
@@ -700,27 +737,30 @@  discard block
 block discarded – undo
700 737
 		)
701 738
 	);
702 739
 	$return = array();
703
-	while ($row = $smcFunc['db_fetch_assoc']($request))
704
-		$return[] = array(
740
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
741
+			$return[] = array(
705 742
 			'id' => $row['id_member'],
706 743
 			'name' => $row['real_name'],
707 744
 			'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
708 745
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
709 746
 			'posts' => $row['posts']
710 747
 		);
748
+	}
711 749
 	$smcFunc['db_free_result']($request);
712 750
 
713 751
 	// If mods want to do somthing with this list of members, let them do that now.
714 752
 	call_integration_hook('integrate_ssi_topPoster', array(&$return));
715 753
 
716 754
 	// Just return all the top posters.
717
-	if ($output_method != 'echo')
718
-		return $return;
755
+	if ($output_method != 'echo') {
756
+			return $return;
757
+	}
719 758
 
720 759
 	// Make a quick array to list the links in.
721 760
 	$temp_array = array();
722
-	foreach ($return as $member)
723
-		$temp_array[] = $member['link'];
761
+	foreach ($return as $member) {
762
+			$temp_array[] = $member['link'];
763
+	}
724 764
 
725 765
 	echo implode(', ', $temp_array);
726 766
 }
@@ -752,8 +792,8 @@  discard block
 block discarded – undo
752 792
 		)
753 793
 	);
754 794
 	$boards = array();
755
-	while ($row = $smcFunc['db_fetch_assoc']($request))
756
-		$boards[] = array(
795
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
796
+			$boards[] = array(
757 797
 			'id' => $row['id_board'],
758 798
 			'num_posts' => $row['num_posts'],
759 799
 			'num_topics' => $row['num_topics'],
@@ -762,14 +802,16 @@  discard block
 block discarded – undo
762 802
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
763 803
 			'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'
764 804
 		);
805
+	}
765 806
 	$smcFunc['db_free_result']($request);
766 807
 
767 808
 	// If mods want to do somthing with this list of boards, let them do that now.
768 809
 	call_integration_hook('integrate_ssi_topBoards', array(&$boards));
769 810
 
770 811
 	// If we shouldn't output or have nothing to output, just jump out.
771
-	if ($output_method != 'echo' || empty($boards))
772
-		return $boards;
812
+	if ($output_method != 'echo' || empty($boards)) {
813
+			return $boards;
814
+	}
773 815
 
774 816
 	echo '
775 817
 		<table class="ssi_table">
@@ -778,13 +820,14 @@  discard block
 block discarded – undo
778 820
 				<th style="text-align: left">', $txt['board_topics'], '</th>
779 821
 				<th style="text-align: left">', $txt['posts'], '</th>
780 822
 			</tr>';
781
-	foreach ($boards as $sBoard)
782
-		echo '
823
+	foreach ($boards as $sBoard) {
824
+			echo '
783 825
 			<tr>
784 826
 				<td>', $sBoard['link'], $sBoard['new'] ? ' <a href="' . $sBoard['href'] . '" class="new_posts">' . $txt['new'] . '</a>' : '', '</td>
785 827
 				<td style="text-align: right">', comma_format($sBoard['num_topics']), '</td>
786 828
 				<td style="text-align: right">', comma_format($sBoard['num_posts']), '</td>
787 829
 			</tr>';
830
+	}
788 831
 	echo '
789 832
 		</table>';
790 833
 }
@@ -817,12 +860,13 @@  discard block
 block discarded – undo
817 860
 			)
818 861
 		);
819 862
 		$topic_ids = array();
820
-		while ($row = $smcFunc['db_fetch_assoc']($request))
821
-			$topic_ids[] = $row['id_topic'];
863
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
864
+					$topic_ids[] = $row['id_topic'];
865
+		}
822 866
 		$smcFunc['db_free_result']($request);
867
+	} else {
868
+			$topic_ids = array();
823 869
 	}
824
-	else
825
-		$topic_ids = array();
826 870
 
827 871
 	$request = $smcFunc['db_query']('', '
828 872
 		SELECT m.subject, m.id_topic, t.num_views, t.num_replies
@@ -861,8 +905,9 @@  discard block
 block discarded – undo
861 905
 	// If mods want to do somthing with this list of topics, let them do that now.
862 906
 	call_integration_hook('integrate_ssi_topTopics', array(&$topics, $type));
863 907
 
864
-	if ($output_method != 'echo' || empty($topics))
865
-		return $topics;
908
+	if ($output_method != 'echo' || empty($topics)) {
909
+			return $topics;
910
+	}
866 911
 
867 912
 	echo '
868 913
 		<table class="ssi_table">
@@ -871,8 +916,8 @@  discard block
 block discarded – undo
871 916
 				<th style="text-align: left">', $txt['views'], '</th>
872 917
 				<th style="text-align: left">', $txt['replies'], '</th>
873 918
 			</tr>';
874
-	foreach ($topics as $sTopic)
875
-		echo '
919
+	foreach ($topics as $sTopic) {
920
+			echo '
876 921
 			<tr>
877 922
 				<td style="text-align: left">
878 923
 					', $sTopic['link'], '
@@ -880,6 +925,7 @@  discard block
 block discarded – undo
880 925
 				<td style="text-align: right">', comma_format($sTopic['num_views']), '</td>
881 926
 				<td style="text-align: right">', comma_format($sTopic['num_replies']), '</td>
882 927
 			</tr>';
928
+	}
883 929
 	echo '
884 930
 		</table>';
885 931
 }
@@ -915,12 +961,13 @@  discard block
 block discarded – undo
915 961
 {
916 962
 	global $txt, $context;
917 963
 
918
-	if ($output_method == 'echo')
919
-		echo '
964
+	if ($output_method == 'echo') {
965
+			echo '
920 966
 	', sprintf($txt['welcome_newest_member'], $context['common_stats']['latest_member']['link']), '<br>';
921
-	else
922
-		return $context['common_stats']['latest_member'];
923
-}
967
+	} else {
968
+			return $context['common_stats']['latest_member'];
969
+	}
970
+	}
924 971
 
925 972
 /**
926 973
  * Fetches a random member.
@@ -969,8 +1016,9 @@  discard block
 block discarded – undo
969 1016
 	}
970 1017
 
971 1018
 	// Just to be sure put the random generator back to something... random.
972
-	if ($random_type != '')
973
-		mt_srand(time());
1019
+	if ($random_type != '') {
1020
+			mt_srand(time());
1021
+	}
974 1022
 
975 1023
 	return $result;
976 1024
 }
@@ -983,8 +1031,9 @@  discard block
 block discarded – undo
983 1031
  */
984 1032
 function ssi_fetchMember($member_ids = array(), $output_method = 'echo')
985 1033
 {
986
-	if (empty($member_ids))
987
-		return;
1034
+	if (empty($member_ids)) {
1035
+			return;
1036
+	}
988 1037
 
989 1038
 	// Can have more than one member if you really want...
990 1039
 	$member_ids = is_array($member_ids) ? $member_ids : array($member_ids);
@@ -1009,8 +1058,9 @@  discard block
 block discarded – undo
1009 1058
  */
1010 1059
 function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo')
1011 1060
 {
1012
-	if ($group_id === null)
1013
-		return;
1061
+	if ($group_id === null) {
1062
+			return;
1063
+	}
1014 1064
 
1015 1065
 	$query_where = '
1016 1066
 		id_group = {int:id_group}
@@ -1037,8 +1087,9 @@  discard block
 block discarded – undo
1037 1087
 {
1038 1088
 	global $smcFunc, $memberContext;
1039 1089
 
1040
-	if ($query_where === null)
1041
-		return;
1090
+	if ($query_where === null) {
1091
+			return;
1092
+	}
1042 1093
 
1043 1094
 	// Fetch the members in question.
1044 1095
 	$request = $smcFunc['db_query']('', '
@@ -1051,12 +1102,14 @@  discard block
 block discarded – undo
1051 1102
 		))
1052 1103
 	);
1053 1104
 	$members = array();
1054
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1055
-		$members[] = $row['id_member'];
1105
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1106
+			$members[] = $row['id_member'];
1107
+	}
1056 1108
 	$smcFunc['db_free_result']($request);
1057 1109
 
1058
-	if (empty($members))
1059
-		return array();
1110
+	if (empty($members)) {
1111
+			return array();
1112
+	}
1060 1113
 
1061 1114
 	// If mods want to do somthing with this list of members, let them do that now.
1062 1115
 	call_integration_hook('integrate_ssi_queryMembers', array(&$members));
@@ -1065,23 +1118,25 @@  discard block
 block discarded – undo
1065 1118
 	loadMemberData($members);
1066 1119
 
1067 1120
 	// Draw the table!
1068
-	if ($output_method == 'echo')
1069
-		echo '
1121
+	if ($output_method == 'echo') {
1122
+			echo '
1070 1123
 		<table style="border: none" class="ssi_table">';
1124
+	}
1071 1125
 
1072 1126
 	$query_members = array();
1073 1127
 	foreach ($members as $member)
1074 1128
 	{
1075 1129
 		// Load their context data.
1076
-		if (!loadMemberContext($member))
1077
-			continue;
1130
+		if (!loadMemberContext($member)) {
1131
+					continue;
1132
+		}
1078 1133
 
1079 1134
 		// Store this member's information.
1080 1135
 		$query_members[$member] = $memberContext[$member];
1081 1136
 
1082 1137
 		// Only do something if we're echo'ing.
1083
-		if ($output_method == 'echo')
1084
-			echo '
1138
+		if ($output_method == 'echo') {
1139
+					echo '
1085 1140
 			<tr>
1086 1141
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
1087 1142
 					', $query_members[$member]['link'], '
@@ -1089,12 +1144,14 @@  discard block
 block discarded – undo
1089 1144
 					<br>', $query_members[$member]['avatar']['image'], '
1090 1145
 				</td>
1091 1146
 			</tr>';
1147
+		}
1092 1148
 	}
1093 1149
 
1094 1150
 	// End the table if appropriate.
1095
-	if ($output_method == 'echo')
1096
-		echo '
1151
+	if ($output_method == 'echo') {
1152
+			echo '
1097 1153
 		</table>';
1154
+	}
1098 1155
 
1099 1156
 	// Send back the data.
1100 1157
 	return $query_members;
@@ -1109,8 +1166,9 @@  discard block
 block discarded – undo
1109 1166
 {
1110 1167
 	global $txt, $scripturl, $modSettings, $smcFunc;
1111 1168
 
1112
-	if (!allowedTo('view_stats'))
1113
-		return;
1169
+	if (!allowedTo('view_stats')) {
1170
+			return;
1171
+	}
1114 1172
 
1115 1173
 	$totals = array(
1116 1174
 		'members' => $modSettings['totalMembers'],
@@ -1139,8 +1197,9 @@  discard block
 block discarded – undo
1139 1197
 	// If mods want to do somthing with the board stats, let them do that now.
1140 1198
 	call_integration_hook('integrate_ssi_boardStats', array(&$totals));
1141 1199
 
1142
-	if ($output_method != 'echo')
1143
-		return $totals;
1200
+	if ($output_method != 'echo') {
1201
+			return $totals;
1202
+	}
1144 1203
 
1145 1204
 	echo '
1146 1205
 		', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', comma_format($totals['members']), '</a><br>
@@ -1169,8 +1228,8 @@  discard block
 block discarded – undo
1169 1228
 	call_integration_hook('integrate_ssi_whosOnline', array(&$return));
1170 1229
 
1171 1230
 	// Add some redundancy for backwards compatibility reasons.
1172
-	if ($output_method != 'echo')
1173
-		return $return + array(
1231
+	if ($output_method != 'echo') {
1232
+			return $return + array(
1174 1233
 			'users' => $return['users_online'],
1175 1234
 			'guests' => $return['num_guests'],
1176 1235
 			'hidden' => $return['num_users_hidden'],
@@ -1178,29 +1237,35 @@  discard block
 block discarded – undo
1178 1237
 			'num_users' => $return['num_users_online'],
1179 1238
 			'total_users' => $return['num_users_online'] + $return['num_guests'],
1180 1239
 		);
1240
+	}
1181 1241
 
1182 1242
 	echo '
1183 1243
 		', comma_format($return['num_guests']), ' ', $return['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($return['num_users_online']), ' ', $return['num_users_online'] == 1 ? $txt['user'] : $txt['users'];
1184 1244
 
1185 1245
 	$bracketList = array();
1186
-	if (!empty($user_info['buddies']))
1187
-		$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1188
-	if (!empty($return['num_spiders']))
1189
-		$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1190
-	if (!empty($return['num_users_hidden']))
1191
-		$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1246
+	if (!empty($user_info['buddies'])) {
1247
+			$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1248
+	}
1249
+	if (!empty($return['num_spiders'])) {
1250
+			$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1251
+	}
1252
+	if (!empty($return['num_users_hidden'])) {
1253
+			$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1254
+	}
1192 1255
 
1193
-	if (!empty($bracketList))
1194
-		echo ' (' . implode(', ', $bracketList) . ')';
1256
+	if (!empty($bracketList)) {
1257
+			echo ' (' . implode(', ', $bracketList) . ')';
1258
+	}
1195 1259
 
1196 1260
 	echo '<br>
1197 1261
 			', implode(', ', $return['list_users_online']);
1198 1262
 
1199 1263
 	// Showing membergroups?
1200
-	if (!empty($settings['show_group_key']) && !empty($return['membergroups']))
1201
-		echo '<br>
1264
+	if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) {
1265
+			echo '<br>
1202 1266
 			[' . implode(']&nbsp;&nbsp;[', $return['membergroups']) . ']';
1203
-}
1267
+	}
1268
+	}
1204 1269
 
1205 1270
 /**
1206 1271
  * Just like whosOnline except it also logs the online presence.
@@ -1211,11 +1276,12 @@  discard block
 block discarded – undo
1211 1276
 {
1212 1277
 	writeLog();
1213 1278
 
1214
-	if ($output_method != 'echo')
1215
-		return ssi_whosOnline($output_method);
1216
-	else
1217
-		ssi_whosOnline($output_method);
1218
-}
1279
+	if ($output_method != 'echo') {
1280
+			return ssi_whosOnline($output_method);
1281
+	} else {
1282
+			ssi_whosOnline($output_method);
1283
+	}
1284
+	}
1219 1285
 
1220 1286
 // Shows a login box.
1221 1287
 /**
@@ -1228,11 +1294,13 @@  discard block
 block discarded – undo
1228 1294
 {
1229 1295
 	global $scripturl, $txt, $user_info, $context;
1230 1296
 
1231
-	if ($redirect_to != '')
1232
-		$_SESSION['login_url'] = $redirect_to;
1297
+	if ($redirect_to != '') {
1298
+			$_SESSION['login_url'] = $redirect_to;
1299
+	}
1233 1300
 
1234
-	if ($output_method != 'echo' || !$user_info['is_guest'])
1235
-		return $user_info['is_guest'];
1301
+	if ($output_method != 'echo' || !$user_info['is_guest']) {
1302
+			return $user_info['is_guest'];
1303
+	}
1236 1304
 
1237 1305
 	// Create a login token
1238 1306
 	createToken('login');
@@ -1284,8 +1352,9 @@  discard block
 block discarded – undo
1284 1352
 
1285 1353
 	$boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote'));
1286 1354
 
1287
-	if (empty($boardsAllowed))
1288
-		return array();
1355
+	if (empty($boardsAllowed)) {
1356
+			return array();
1357
+	}
1289 1358
 
1290 1359
 	$request = $smcFunc['db_query']('', '
1291 1360
 		SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time
@@ -1318,12 +1387,14 @@  discard block
 block discarded – undo
1318 1387
 	$smcFunc['db_free_result']($request);
1319 1388
 
1320 1389
 	// This user has voted on all the polls.
1321
-	if (empty($row) || !is_array($row))
1322
-		return array();
1390
+	if (empty($row) || !is_array($row)) {
1391
+			return array();
1392
+	}
1323 1393
 
1324 1394
 	// If this is a guest who's voted we'll through ourselves to show poll to show the results.
1325
-	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))))
1326
-		return ssi_showPoll($row['id_topic'], $output_method);
1395
+	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) {
1396
+			return ssi_showPoll($row['id_topic'], $output_method);
1397
+	}
1327 1398
 
1328 1399
 	$request = $smcFunc['db_query']('', '
1329 1400
 		SELECT COUNT(DISTINCT id_member)
@@ -1387,8 +1458,9 @@  discard block
 block discarded – undo
1387 1458
 	// If mods want to do somthing with this list of polls, let them do that now.
1388 1459
 	call_integration_hook('integrate_ssi_recentPoll', array(&$return, $topPollInstead));
1389 1460
 
1390
-	if ($output_method != 'echo')
1391
-		return $return;
1461
+	if ($output_method != 'echo') {
1462
+			return $return;
1463
+	}
1392 1464
 
1393 1465
 	if ($allow_view_results)
1394 1466
 	{
@@ -1397,19 +1469,20 @@  discard block
 block discarded – undo
1397 1469
 			<strong>', $return['question'], '</strong><br>
1398 1470
 			', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1399 1471
 
1400
-		foreach ($return['options'] as $option)
1401
-			echo '
1472
+		foreach ($return['options'] as $option) {
1473
+					echo '
1402 1474
 			<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1475
+		}
1403 1476
 
1404 1477
 		echo '
1405 1478
 			<input type="submit" value="', $txt['poll_vote'], '" class="button">
1406 1479
 			<input type="hidden" name="poll" value="', $return['id'], '">
1407 1480
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1408 1481
 		</form>';
1482
+	} else {
1483
+			echo $txt['poll_cannot_see'];
1484
+	}
1409 1485
 	}
1410
-	else
1411
-		echo $txt['poll_cannot_see'];
1412
-}
1413 1486
 
1414 1487
 /**
1415 1488
  * Shows the poll from the specified topic
@@ -1423,13 +1496,15 @@  discard block
 block discarded – undo
1423 1496
 
1424 1497
 	$boardsAllowed = boardsAllowedTo('poll_view');
1425 1498
 
1426
-	if (empty($boardsAllowed))
1427
-		return array();
1499
+	if (empty($boardsAllowed)) {
1500
+			return array();
1501
+	}
1428 1502
 
1429
-	if ($topic === null && isset($_REQUEST['ssi_topic']))
1430
-		$topic = (int) $_REQUEST['ssi_topic'];
1431
-	else
1432
-		$topic = (int) $topic;
1503
+	if ($topic === null && isset($_REQUEST['ssi_topic'])) {
1504
+			$topic = (int) $_REQUEST['ssi_topic'];
1505
+	} else {
1506
+			$topic = (int) $topic;
1507
+	}
1433 1508
 
1434 1509
 	$request = $smcFunc['db_query']('', '
1435 1510
 		SELECT
@@ -1450,17 +1525,18 @@  discard block
 block discarded – undo
1450 1525
 	);
1451 1526
 
1452 1527
 	// Either this topic has no poll, or the user cannot view it.
1453
-	if ($smcFunc['db_num_rows']($request) == 0)
1454
-		return array();
1528
+	if ($smcFunc['db_num_rows']($request) == 0) {
1529
+			return array();
1530
+	}
1455 1531
 
1456 1532
 	$row = $smcFunc['db_fetch_assoc']($request);
1457 1533
 	$smcFunc['db_free_result']($request);
1458 1534
 
1459 1535
 	// Check if they can vote.
1460 1536
 	$already_voted = false;
1461
-	if (!empty($row['expire_time']) && $row['expire_time'] < time())
1462
-		$allow_vote = false;
1463
-	elseif ($user_info['is_guest'])
1537
+	if (!empty($row['expire_time']) && $row['expire_time'] < time()) {
1538
+			$allow_vote = false;
1539
+	} elseif ($user_info['is_guest'])
1464 1540
 	{
1465 1541
 		// There's a difference between "allowed to vote" and "already voted"...
1466 1542
 		$allow_vote = $row['guest_vote'];
@@ -1470,10 +1546,9 @@  discard block
 block discarded – undo
1470 1546
 		{
1471 1547
 			$already_voted = true;
1472 1548
 		}
1473
-	}
1474
-	elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board']))
1475
-		$allow_vote = false;
1476
-	else
1549
+	} elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) {
1550
+			$allow_vote = false;
1551
+	} else
1477 1552
 	{
1478 1553
 		$request = $smcFunc['db_query']('', '
1479 1554
 			SELECT id_member
@@ -1555,8 +1630,9 @@  discard block
 block discarded – undo
1555 1630
 	// If mods want to do somthing with this poll, let them do that now.
1556 1631
 	call_integration_hook('integrate_ssi_showPoll', array(&$return));
1557 1632
 
1558
-	if ($output_method != 'echo')
1559
-		return $return;
1633
+	if ($output_method != 'echo') {
1634
+			return $return;
1635
+	}
1560 1636
 
1561 1637
 	if ($return['allow_vote'])
1562 1638
 	{
@@ -1565,17 +1641,17 @@  discard block
 block discarded – undo
1565 1641
 				<strong>', $return['question'], '</strong><br>
1566 1642
 				', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1567 1643
 
1568
-		foreach ($return['options'] as $option)
1569
-			echo '
1644
+		foreach ($return['options'] as $option) {
1645
+					echo '
1570 1646
 				<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1647
+		}
1571 1648
 
1572 1649
 		echo '
1573 1650
 				<input type="submit" value="', $txt['poll_vote'], '" class="button">
1574 1651
 				<input type="hidden" name="poll" value="', $return['id'], '">
1575 1652
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1576 1653
 			</form>';
1577
-	}
1578
-	else
1654
+	} else
1579 1655
 	{
1580 1656
 		echo '
1581 1657
 			<div class="ssi_poll">
@@ -1655,27 +1731,32 @@  discard block
 block discarded – undo
1655 1731
 			'is_approved' => 1,
1656 1732
 		)
1657 1733
 	);
1658
-	if ($smcFunc['db_num_rows']($request) == 0)
1659
-		die;
1734
+	if ($smcFunc['db_num_rows']($request) == 0) {
1735
+			die;
1736
+	}
1660 1737
 	$row = $smcFunc['db_fetch_assoc']($request);
1661 1738
 	$smcFunc['db_free_result']($request);
1662 1739
 
1663
-	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time']))
1664
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1740
+	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) {
1741
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1742
+	}
1665 1743
 
1666 1744
 	// Too many options checked?
1667
-	if (count($_REQUEST['options']) > $row['max_votes'])
1668
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1745
+	if (count($_REQUEST['options']) > $row['max_votes']) {
1746
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1747
+	}
1669 1748
 
1670 1749
 	// It's a guest who has already voted?
1671 1750
 	if ($user_info['is_guest'])
1672 1751
 	{
1673 1752
 		// Guest voting disabled?
1674
-		if (!$row['guest_vote'])
1675
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1753
+		if (!$row['guest_vote']) {
1754
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1755
+		}
1676 1756
 		// Already voted?
1677
-		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))
1678
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1757
+		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) {
1758
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1759
+		}
1679 1760
 	}
1680 1761
 
1681 1762
 	$sOptions = array();
@@ -1729,11 +1810,13 @@  discard block
 block discarded – undo
1729 1810
 {
1730 1811
 	global $scripturl, $txt, $context;
1731 1812
 
1732
-	if (!allowedTo('search_posts'))
1733
-		return;
1813
+	if (!allowedTo('search_posts')) {
1814
+			return;
1815
+	}
1734 1816
 
1735
-	if ($output_method != 'echo')
1736
-		return $scripturl . '?action=search';
1817
+	if ($output_method != 'echo') {
1818
+			return $scripturl . '?action=search';
1819
+	}
1737 1820
 
1738 1821
 	echo '
1739 1822
 		<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
@@ -1755,8 +1838,9 @@  discard block
 block discarded – undo
1755 1838
 	// If mods want to do somthing with the news, let them do that now. Don't need to pass the news line itself, since it is already in $context.
1756 1839
 	call_integration_hook('integrate_ssi_news');
1757 1840
 
1758
-	if ($output_method != 'echo')
1759
-		return $context['random_news_line'];
1841
+	if ($output_method != 'echo') {
1842
+			return $context['random_news_line'];
1843
+	}
1760 1844
 
1761 1845
 	echo $context['random_news_line'];
1762 1846
 }
@@ -1770,8 +1854,9 @@  discard block
 block discarded – undo
1770 1854
 {
1771 1855
 	global $scripturl, $modSettings, $user_info;
1772 1856
 
1773
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view'))
1774
-		return;
1857
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) {
1858
+			return;
1859
+	}
1775 1860
 
1776 1861
 	$eventOptions = array(
1777 1862
 		'include_birthdays' => true,
@@ -1782,13 +1867,15 @@  discard block
 block discarded – undo
1782 1867
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1783 1868
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1784 1869
 
1785
-	if ($output_method != 'echo')
1786
-		return $return['calendar_birthdays'];
1870
+	if ($output_method != 'echo') {
1871
+			return $return['calendar_birthdays'];
1872
+	}
1787 1873
 
1788
-	foreach ($return['calendar_birthdays'] as $member)
1789
-		echo '
1874
+	foreach ($return['calendar_birthdays'] as $member) {
1875
+			echo '
1790 1876
 			<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'] ? ', ' : '');
1791
-}
1877
+	}
1878
+	}
1792 1879
 
1793 1880
 /**
1794 1881
  * Shows today's holidays.
@@ -1799,8 +1886,9 @@  discard block
 block discarded – undo
1799 1886
 {
1800 1887
 	global $modSettings, $user_info;
1801 1888
 
1802
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1803
-		return;
1889
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1890
+			return;
1891
+	}
1804 1892
 
1805 1893
 	$eventOptions = array(
1806 1894
 		'include_holidays' => true,
@@ -1811,8 +1899,9 @@  discard block
 block discarded – undo
1811 1899
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1812 1900
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1813 1901
 
1814
-	if ($output_method != 'echo')
1815
-		return $return['calendar_holidays'];
1902
+	if ($output_method != 'echo') {
1903
+			return $return['calendar_holidays'];
1904
+	}
1816 1905
 
1817 1906
 	echo '
1818 1907
 		', implode(', ', $return['calendar_holidays']);
@@ -1826,8 +1915,9 @@  discard block
 block discarded – undo
1826 1915
 {
1827 1916
 	global $modSettings, $user_info;
1828 1917
 
1829
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1830
-		return;
1918
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1919
+			return;
1920
+	}
1831 1921
 
1832 1922
 	$eventOptions = array(
1833 1923
 		'include_events' => true,
@@ -1838,14 +1928,16 @@  discard block
 block discarded – undo
1838 1928
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1839 1929
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1840 1930
 
1841
-	if ($output_method != 'echo')
1842
-		return $return['calendar_events'];
1931
+	if ($output_method != 'echo') {
1932
+			return $return['calendar_events'];
1933
+	}
1843 1934
 
1844 1935
 	foreach ($return['calendar_events'] as $event)
1845 1936
 	{
1846
-		if ($event['can_edit'])
1847
-			echo '
1937
+		if ($event['can_edit']) {
1938
+					echo '
1848 1939
 	<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1940
+		}
1849 1941
 		echo '
1850 1942
 	' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1851 1943
 	}
@@ -1860,8 +1952,9 @@  discard block
 block discarded – undo
1860 1952
 {
1861 1953
 	global $modSettings, $txt, $scripturl, $user_info;
1862 1954
 
1863
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1864
-		return;
1955
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1956
+			return;
1957
+	}
1865 1958
 
1866 1959
 	$eventOptions = array(
1867 1960
 		'include_birthdays' => allowedTo('profile_view'),
@@ -1874,19 +1967,22 @@  discard block
 block discarded – undo
1874 1967
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1875 1968
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1876 1969
 
1877
-	if ($output_method != 'echo')
1878
-		return $return;
1970
+	if ($output_method != 'echo') {
1971
+			return $return;
1972
+	}
1879 1973
 
1880
-	if (!empty($return['calendar_holidays']))
1881
-		echo '
1974
+	if (!empty($return['calendar_holidays'])) {
1975
+			echo '
1882 1976
 			<span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br></span>';
1977
+	}
1883 1978
 	if (!empty($return['calendar_birthdays']))
1884 1979
 	{
1885 1980
 		echo '
1886 1981
 			<span class="birthday">' . $txt['birthdays_upcoming'] . '</span> ';
1887
-		foreach ($return['calendar_birthdays'] as $member)
1888
-			echo '
1982
+		foreach ($return['calendar_birthdays'] as $member) {
1983
+					echo '
1889 1984
 			<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'] ? ', ' : '';
1985
+		}
1890 1986
 		echo '
1891 1987
 			<br>';
1892 1988
 	}
@@ -1896,9 +1992,10 @@  discard block
 block discarded – undo
1896 1992
 			<span class="event">' . $txt['events_upcoming'] . '</span> ';
1897 1993
 		foreach ($return['calendar_events'] as $event)
1898 1994
 		{
1899
-			if ($event['can_edit'])
1900
-				echo '
1995
+			if ($event['can_edit']) {
1996
+							echo '
1901 1997
 			<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1998
+			}
1902 1999
 			echo '
1903 2000
 			' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1904 2001
 		}
@@ -1922,25 +2019,29 @@  discard block
 block discarded – undo
1922 2019
 	loadLanguage('Stats');
1923 2020
 
1924 2021
 	// Must be integers....
1925
-	if ($limit === null)
1926
-		$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
1927
-	else
1928
-		$limit = (int) $limit;
1929
-
1930
-	if ($start === null)
1931
-		$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1932
-	else
1933
-		$start = (int) $start;
1934
-
1935
-	if ($board !== null)
1936
-		$board = (int) $board;
1937
-	elseif (isset($_GET['board']))
1938
-		$board = (int) $_GET['board'];
1939
-
1940
-	if ($length === null)
1941
-		$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
1942
-	else
1943
-		$length = (int) $length;
2022
+	if ($limit === null) {
2023
+			$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
2024
+	} else {
2025
+			$limit = (int) $limit;
2026
+	}
2027
+
2028
+	if ($start === null) {
2029
+			$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
2030
+	} else {
2031
+			$start = (int) $start;
2032
+	}
2033
+
2034
+	if ($board !== null) {
2035
+			$board = (int) $board;
2036
+	} elseif (isset($_GET['board'])) {
2037
+			$board = (int) $_GET['board'];
2038
+	}
2039
+
2040
+	if ($length === null) {
2041
+			$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
2042
+	} else {
2043
+			$length = (int) $length;
2044
+	}
1944 2045
 
1945 2046
 	$limit = max(0, $limit);
1946 2047
 	$start = max(0, $start);
@@ -1958,17 +2059,19 @@  discard block
 block discarded – undo
1958 2059
 	);
1959 2060
 	if ($smcFunc['db_num_rows']($request) == 0)
1960 2061
 	{
1961
-		if ($output_method == 'echo')
1962
-			die($txt['ssi_no_guests']);
1963
-		else
1964
-			return array();
2062
+		if ($output_method == 'echo') {
2063
+					die($txt['ssi_no_guests']);
2064
+		} else {
2065
+					return array();
2066
+		}
1965 2067
 	}
1966 2068
 	list ($board) = $smcFunc['db_fetch_row']($request);
1967 2069
 	$smcFunc['db_free_result']($request);
1968 2070
 
1969 2071
 	$icon_sources = array();
1970
-	foreach ($context['stable_icons'] as $icon)
1971
-		$icon_sources[$icon] = 'images_url';
2072
+	foreach ($context['stable_icons'] as $icon) {
2073
+			$icon_sources[$icon] = 'images_url';
2074
+	}
1972 2075
 
1973 2076
 	if (!empty($modSettings['enable_likes']))
1974 2077
 	{
@@ -1991,12 +2094,14 @@  discard block
 block discarded – undo
1991 2094
 		)
1992 2095
 	);
1993 2096
 	$posts = array();
1994
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1995
-		$posts[] = $row['id_first_msg'];
2097
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2098
+			$posts[] = $row['id_first_msg'];
2099
+	}
1996 2100
 	$smcFunc['db_free_result']($request);
1997 2101
 
1998
-	if (empty($posts))
1999
-		return array();
2102
+	if (empty($posts)) {
2103
+			return array();
2104
+	}
2000 2105
 
2001 2106
 	// Find the posts.
2002 2107
 	$request = $smcFunc['db_query']('', '
@@ -2026,26 +2131,30 @@  discard block
 block discarded – undo
2026 2131
 			$last_space = strrpos($row['body'], ' ');
2027 2132
 			$last_open = strrpos($row['body'], '<');
2028 2133
 			$last_close = strrpos($row['body'], '>');
2029
-			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6)
2030
-				$cutoff = $last_open;
2031
-			elseif (empty($last_close) || $last_close < $last_open)
2032
-				$cutoff = $last_space;
2134
+			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6) {
2135
+							$cutoff = $last_open;
2136
+			} elseif (empty($last_close) || $last_close < $last_open) {
2137
+							$cutoff = $last_space;
2138
+			}
2033 2139
 
2034
-			if ($cutoff !== false)
2035
-				$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2140
+			if ($cutoff !== false) {
2141
+							$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2142
+			}
2036 2143
 			$row['body'] .= '...';
2037 2144
 		}
2038 2145
 
2039 2146
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
2040 2147
 
2041
-		if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
2042
-			$row['icon'] = 'recycled';
2148
+		if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
2149
+					$row['icon'] = 'recycled';
2150
+		}
2043 2151
 
2044 2152
 		// Check that this message icon is there...
2045
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
2046
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2047
-		elseif (!isset($icon_sources[$row['icon']]))
2048
-			$icon_sources[$row['icon']] = 'images_url';
2153
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
2154
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2155
+		} elseif (!isset($icon_sources[$row['icon']])) {
2156
+					$icon_sources[$row['icon']] = 'images_url';
2157
+		}
2049 2158
 
2050 2159
 		censorText($row['subject']);
2051 2160
 		censorText($row['body']);
@@ -2082,16 +2191,18 @@  discard block
 block discarded – undo
2082 2191
 	}
2083 2192
 	$smcFunc['db_free_result']($request);
2084 2193
 
2085
-	if (empty($return))
2086
-		return $return;
2194
+	if (empty($return)) {
2195
+			return $return;
2196
+	}
2087 2197
 
2088 2198
 	$return[count($return) - 1]['is_last'] = true;
2089 2199
 
2090 2200
 	// If mods want to do somthing with this list of posts, let them do that now.
2091 2201
 	call_integration_hook('integrate_ssi_boardNews', array(&$return));
2092 2202
 
2093
-	if ($output_method != 'echo')
2094
-		return $return;
2203
+	if ($output_method != 'echo') {
2204
+			return $return;
2205
+	}
2095 2206
 
2096 2207
 	foreach ($return as $news)
2097 2208
 	{
@@ -2143,9 +2254,10 @@  discard block
 block discarded – undo
2143 2254
 		echo '
2144 2255
 			</div>';
2145 2256
 
2146
-		if (!$news['is_last'])
2147
-			echo '
2257
+		if (!$news['is_last']) {
2258
+					echo '
2148 2259
 			<hr>';
2260
+		}
2149 2261
 	}
2150 2262
 }
2151 2263
 
@@ -2159,8 +2271,9 @@  discard block
 block discarded – undo
2159 2271
 {
2160 2272
 	global $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc;
2161 2273
 
2162
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
2163
-		return;
2274
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
2275
+			return;
2276
+	}
2164 2277
 
2165 2278
 	// Find all events which are happening in the near future that the member can see.
2166 2279
 	$request = $smcFunc['db_query']('', '
@@ -2186,20 +2299,23 @@  discard block
 block discarded – undo
2186 2299
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2187 2300
 	{
2188 2301
 		// Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
2189
-		if (!empty($duplicates[$row['title'] . $row['id_topic']]))
2190
-			continue;
2302
+		if (!empty($duplicates[$row['title'] . $row['id_topic']])) {
2303
+					continue;
2304
+		}
2191 2305
 
2192 2306
 		// Censor the title.
2193 2307
 		censorText($row['title']);
2194 2308
 
2195
-		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false)))
2196
-			$date = strftime('%Y-%m-%d', forum_time(false));
2197
-		else
2198
-			$date = $row['start_date'];
2309
+		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) {
2310
+					$date = strftime('%Y-%m-%d', forum_time(false));
2311
+		} else {
2312
+					$date = $row['start_date'];
2313
+		}
2199 2314
 
2200 2315
 		// If the topic it is attached to is not approved then don't link it.
2201
-		if (!empty($row['id_first_msg']) && !$row['approved'])
2202
-			$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2316
+		if (!empty($row['id_first_msg']) && !$row['approved']) {
2317
+					$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2318
+		}
2203 2319
 
2204 2320
 		$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
2205 2321
 
@@ -2225,24 +2341,27 @@  discard block
 block discarded – undo
2225 2341
 	}
2226 2342
 	$smcFunc['db_free_result']($request);
2227 2343
 
2228
-	foreach ($return as $mday => $array)
2229
-		$return[$mday][count($array) - 1]['is_last'] = true;
2344
+	foreach ($return as $mday => $array) {
2345
+			$return[$mday][count($array) - 1]['is_last'] = true;
2346
+	}
2230 2347
 
2231 2348
 	// If mods want to do somthing with this list of events, let them do that now.
2232 2349
 	call_integration_hook('integrate_ssi_recentEvents', array(&$return));
2233 2350
 
2234
-	if ($output_method != 'echo' || empty($return))
2235
-		return $return;
2351
+	if ($output_method != 'echo' || empty($return)) {
2352
+			return $return;
2353
+	}
2236 2354
 
2237 2355
 	// Well the output method is echo.
2238 2356
 	echo '
2239 2357
 			<span class="event">' . $txt['events'] . '</span> ';
2240
-	foreach ($return as $mday => $array)
2241
-		foreach ($array as $event)
2358
+	foreach ($return as $mday => $array) {
2359
+			foreach ($array as $event)
2242 2360
 		{
2243 2361
 			if ($event['can_edit'])
2244 2362
 				echo '
2245 2363
 				<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
2364
+	}
2246 2365
 
2247 2366
 			echo '
2248 2367
 				' . $event['link'] . (!$event['is_last'] ? ', ' : '');
@@ -2261,8 +2380,9 @@  discard block
 block discarded – undo
2261 2380
 	global $smcFunc;
2262 2381
 
2263 2382
 	// If $id is null, this was most likely called from a query string and should do nothing.
2264
-	if ($id === null)
2265
-		return;
2383
+	if ($id === null) {
2384
+			return;
2385
+	}
2266 2386
 
2267 2387
 	$request = $smcFunc['db_query']('', '
2268 2388
 		SELECT passwd, member_name, is_activated
@@ -2294,8 +2414,9 @@  discard block
 block discarded – undo
2294 2414
 	$attachments_boards = boardsAllowedTo('view_attachments');
2295 2415
 
2296 2416
 	// No boards?  Adios amigo.
2297
-	if (empty($attachments_boards))
2298
-		return array();
2417
+	if (empty($attachments_boards)) {
2418
+			return array();
2419
+	}
2299 2420
 
2300 2421
 	// Is it an array?
2301 2422
 	$attachment_ext = (array) $attachment_ext;
@@ -2379,8 +2500,9 @@  discard block
 block discarded – undo
2379 2500
 	call_integration_hook('integrate_ssi_recentAttachments', array(&$attachments));
2380 2501
 
2381 2502
 	// So you just want an array?  Here you can have it.
2382
-	if ($output_method == 'array' || empty($attachments))
2383
-		return $attachments;
2503
+	if ($output_method == 'array' || empty($attachments)) {
2504
+			return $attachments;
2505
+	}
2384 2506
 
2385 2507
 	// Give them the default.
2386 2508
 	echo '
@@ -2391,14 +2513,15 @@  discard block
 block discarded – undo
2391 2513
 				<th style="text-align: left; padding: 2">', $txt['downloads'], '</th>
2392 2514
 				<th style="text-align: left; padding: 2">', $txt['filesize'], '</th>
2393 2515
 			</tr>';
2394
-	foreach ($attachments as $attach)
2395
-		echo '
2516
+	foreach ($attachments as $attach) {
2517
+			echo '
2396 2518
 			<tr>
2397 2519
 				<td>', $attach['file']['link'], '</td>
2398 2520
 				<td>', $attach['member']['link'], '</td>
2399 2521
 				<td style="text-align: center">', $attach['file']['downloads'], '</td>
2400 2522
 				<td>', $attach['file']['filesize'], '</td>
2401 2523
 			</tr>';
2524
+	}
2402 2525
 	echo '
2403 2526
 		</table>';
2404 2527
 }
Please login to merge, or discard this patch.
index.php 1 patch
Braces   +40 added lines, -27 removed lines patch added patch discarded remove patch
@@ -32,20 +32,23 @@  discard block
 block discarded – undo
32 32
 ob_start();
33 33
 
34 34
 // Do some cleaning, just in case.
35
-foreach (array('db_character_set', 'cachedir') as $variable)
35
+foreach (array('db_character_set', 'cachedir') as $variable) {
36 36
 	if (isset($GLOBALS[$variable]))
37 37
 		unset($GLOBALS[$variable], $GLOBALS[$variable]);
38
+}
38 39
 
39 40
 // Load the settings...
40 41
 require_once(dirname(__FILE__) . '/Settings.php');
41 42
 
42 43
 // Make absolutely sure the cache directory is defined.
43
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
44
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
44 45
 	$cachedir = $boarddir . '/cache';
46
+}
45 47
 
46 48
 // For php below 7
47
-if (!function_exists('random_int'))
49
+if (!function_exists('random_int')) {
48 50
 	require_once ($sourcedir . '/random_compat/random_int.php');
51
+}
49 52
 
50 53
 // Without those we can't go anywhere
51 54
 require_once($sourcedir . '/QueryString.php');
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 require_once($sourcedir . '/Load.php');
56 59
 
57 60
 // If $maintenance is set specifically to 2, then we're upgrading or something.
58
-if (!empty($maintenance) && $maintenance == 2)
61
+if (!empty($maintenance) && $maintenance == 2) {
59 62
 	display_maintenance_message();
63
+}
60 64
 
61 65
 // Create a variable to store some SMF specific functions in.
62 66
 $smcFunc = array();
@@ -71,8 +75,9 @@  discard block
 block discarded – undo
71 75
 cleanRequest();
72 76
 
73 77
 // Seed the random generator.
74
-if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69)
78
+if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69) {
75 79
 	smf_seed_generator();
80
+}
76 81
 
77 82
 // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out!
78 83
 if (isset($_GET['scheduled']))
@@ -92,9 +97,9 @@  discard block
 block discarded – undo
92 97
 if (!empty($modSettings['enableCompressedOutput']) && !headers_sent())
93 98
 {
94 99
 	// If zlib is being used, turn off output compression.
95
-	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler')
96
-		$modSettings['enableCompressedOutput'] = '0';
97
-	else
100
+	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') {
101
+			$modSettings['enableCompressedOutput'] = '0';
102
+	} else
98 103
 	{
99 104
 		ob_end_clean();
100 105
 		ob_start('ob_gzhandler');
@@ -186,18 +191,21 @@  discard block
 block discarded – undo
186 191
 	loadPermissions();
187 192
 
188 193
 	// Attachments don't require the entire theme to be loaded.
189
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach')
190
-		detectBrowser();
194
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') {
195
+			detectBrowser();
196
+	}
191 197
 	// Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
192
-	else
193
-		loadTheme();
198
+	else {
199
+			loadTheme();
200
+	}
194 201
 
195 202
 	// Check if the user should be disallowed access.
196 203
 	is_not_banned();
197 204
 
198 205
 	// If we are in a topic and don't have permission to approve it then duck out now.
199
-	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest']))
200
-		fatal_lang_error('not_a_topic', false);
206
+	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) {
207
+			fatal_lang_error('not_a_topic', false);
208
+	}
201 209
 
202 210
 	$no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile');
203 211
 	call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions));
@@ -208,8 +216,9 @@  discard block
 block discarded – undo
208 216
 		writeLog();
209 217
 
210 218
 		// Track forum statistics and hits...?
211
-		if (!empty($modSettings['hitStats']))
212
-			trackStats(array('hits' => '+'));
219
+		if (!empty($modSettings['hitStats'])) {
220
+					trackStats(array('hits' => '+'));
221
+		}
213 222
 	}
214 223
 	unset($no_stat_actions);
215 224
 
@@ -226,13 +235,14 @@  discard block
 block discarded – undo
226 235
 			return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout'));
227 236
 		}
228 237
 		// Don't even try it, sonny.
229
-		else
230
-			return 'InMaintenance';
238
+		else {
239
+					return 'InMaintenance';
240
+		}
231 241
 	}
232 242
 	// If guest access is off, a guest can only do one of the very few following actions.
233
-	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2'))))
234
-		return 'KickGuest';
235
-	elseif (empty($_REQUEST['action']))
243
+	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) {
244
+			return 'KickGuest';
245
+	} elseif (empty($_REQUEST['action']))
236 246
 	{
237 247
 		// Action and board are both empty... BoardIndex! Unless someone else wants to do something different.
238 248
 		if (empty($board) && empty($topic))
@@ -246,8 +256,9 @@  discard block
 block discarded – undo
246 256
 
247 257
 				$call = call_helper($defaultAction, true);
248 258
 
249
-				if (!empty($call))
250
-					return $call;
259
+				if (!empty($call)) {
260
+									return $call;
261
+				}
251 262
 			}
252 263
 
253 264
 			// No default action huh? then go to our good old BoardIndex.
@@ -377,8 +388,9 @@  discard block
 block discarded – undo
377 388
 
378 389
 			$call = call_helper($fallbackAction, true);
379 390
 
380
-			if (!empty($call))
381
-				return $call;
391
+			if (!empty($call)) {
392
+							return $call;
393
+			}
382 394
 		}
383 395
 
384 396
 		// No fallback action, huh?
@@ -389,8 +401,9 @@  discard block
 block discarded – undo
389 401
 	}
390 402
 
391 403
 	// Otherwise, it was set - so let's go to that action.
392
-	if (!empty($actionArray[$_REQUEST['action']][0]))
393
-		require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]);
404
+	if (!empty($actionArray[$_REQUEST['action']][0])) {
405
+			require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]);
406
+	}
394 407
 
395 408
 	// Do the right thing.
396 409
 	return call_helper($actionArray[$_REQUEST['action']][1], true);
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +471 added lines, -349 removed lines patch added patch discarded remove patch
@@ -20,12 +20,14 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // For php below 7
23
-if (!function_exists('random_int'))
23
+if (!function_exists('random_int')) {
24 24
 	require_once ('Sources/random_compat/random_int.php');
25
+}
25 26
 
26 27
 // Let's pull in useful classes
27
-if (!defined('SMF'))
28
+if (!defined('SMF')) {
28 29
 	define('SMF', 1);
30
+}
29 31
 
30 32
 require_once('Sources/Class-Package.php');
31 33
 
@@ -67,10 +69,11 @@  discard block
 block discarded – undo
67 69
 
68 70
 			list ($charcode) = pg_fetch_row($request);
69 71
 
70
-			if ($charcode == 'UTF8')
71
-				return true;
72
-			else
73
-				return false;
72
+			if ($charcode == 'UTF8') {
73
+							return true;
74
+			} else {
75
+							return false;
76
+			}
74 77
 		},
75 78
 		'utf8_version' => '8.0',
76 79
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -80,12 +83,14 @@  discard block
 block discarded – undo
80 83
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
81 84
 
82 85
 			// Is it reserved?
83
-			if ($value == 'pg_')
84
-				return $txt['error_db_prefix_reserved'];
86
+			if ($value == 'pg_') {
87
+							return $txt['error_db_prefix_reserved'];
88
+			}
85 89
 
86 90
 			// Is the prefix numeric?
87
-			if (preg_match('~^\d~', $value))
88
-				return $txt['error_db_prefix_numeric'];
91
+			if (preg_match('~^\d~', $value)) {
92
+							return $txt['error_db_prefix_numeric'];
93
+			}
89 94
 
90 95
 			return true;
91 96
 		},
@@ -132,10 +137,11 @@  discard block
 block discarded – undo
132 137
 		$incontext['skip'] = false;
133 138
 
134 139
 		// Call the step and if it returns false that means pause!
135
-		if (function_exists($step[2]) && $step[2]() === false)
136
-			break;
137
-		elseif (function_exists($step[2]))
138
-			$incontext['current_step']++;
140
+		if (function_exists($step[2]) && $step[2]() === false) {
141
+					break;
142
+		} elseif (function_exists($step[2])) {
143
+					$incontext['current_step']++;
144
+		}
139 145
 
140 146
 		// No warnings pass on.
141 147
 		$incontext['warning'] = '';
@@ -151,8 +157,9 @@  discard block
 block discarded – undo
151 157
 	global $databases;
152 158
 
153 159
 	// Just so people using older versions of PHP aren't left in the cold.
154
-	if (!isset($_SERVER['PHP_SELF']))
155
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
160
+	if (!isset($_SERVER['PHP_SELF'])) {
161
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
162
+	}
156 163
 
157 164
 	// Enable error reporting for fatal errors.
158 165
 	error_reporting(E_ERROR | E_PARSE);
@@ -168,21 +175,23 @@  discard block
 block discarded – undo
168 175
 	{
169 176
 		ob_start();
170 177
 
171
-		if (ini_get('session.save_handler') == 'user')
172
-			@ini_set('session.save_handler', 'files');
173
-		if (function_exists('session_start'))
174
-			@session_start();
175
-	}
176
-	else
178
+		if (ini_get('session.save_handler') == 'user') {
179
+					@ini_set('session.save_handler', 'files');
180
+		}
181
+		if (function_exists('session_start')) {
182
+					@session_start();
183
+		}
184
+	} else
177 185
 	{
178 186
 		ob_start('ob_gzhandler');
179 187
 
180
-		if (ini_get('session.save_handler') == 'user')
181
-			@ini_set('session.save_handler', 'files');
188
+		if (ini_get('session.save_handler') == 'user') {
189
+					@ini_set('session.save_handler', 'files');
190
+		}
182 191
 		session_start();
183 192
 
184
-		if (!headers_sent())
185
-			echo '<!DOCTYPE html>
193
+		if (!headers_sent()) {
194
+					echo '<!DOCTYPE html>
186 195
 <html>
187 196
 	<head>
188 197
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -191,14 +200,16 @@  discard block
 block discarded – undo
191 200
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
192 201
 	</body>
193 202
 </html>';
203
+		}
194 204
 		exit;
195 205
 	}
196 206
 
197 207
 	// Add slashes, as long as they aren't already being added.
198
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
199
-		foreach ($_POST as $k => $v)
208
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
209
+			foreach ($_POST as $k => $v)
200 210
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
201 211
 				$_POST[$k] = addslashes($v);
212
+	}
202 213
 
203 214
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
204 215
 	if (isset($_GET['delete']))
@@ -219,8 +230,7 @@  discard block
 block discarded – undo
219 230
 			$ftp->close();
220 231
 
221 232
 			unset($_SESSION['installer_temp_ftp']);
222
-		}
223
-		else
233
+		} else
224 234
 		{
225 235
 			@unlink(__FILE__);
226 236
 
@@ -234,10 +244,11 @@  discard block
 block discarded – undo
234 244
 		// Now just redirect to a blank.png...
235 245
 		$secure = false;
236 246
 
237
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
238
-			$secure = true;
239
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
240
-			$secure = true;
247
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
248
+					$secure = true;
249
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
250
+					$secure = true;
251
+		}
241 252
 
242 253
 		header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
243 254
 		exit;
@@ -248,10 +259,11 @@  discard block
 block discarded – undo
248 259
 	{
249 260
 		// Get PHP's default timezone, if set
250 261
 		$ini_tz = ini_get('date.timezone');
251
-		if (!empty($ini_tz))
252
-			$timezone_id = $ini_tz;
253
-		else
254
-			$timezone_id = '';
262
+		if (!empty($ini_tz)) {
263
+					$timezone_id = $ini_tz;
264
+		} else {
265
+					$timezone_id = '';
266
+		}
255 267
 
256 268
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
257 269
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -281,8 +293,9 @@  discard block
 block discarded – undo
281 293
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
282 294
 		while ($entry = $dir->read())
283 295
 		{
284
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
285
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
296
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
297
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
298
+			}
286 299
 		}
287 300
 		$dir->close();
288 301
 	}
@@ -329,10 +342,11 @@  discard block
 block discarded – undo
329 342
 	}
330 343
 
331 344
 	// Override the language file?
332
-	if (isset($_GET['lang_file']))
333
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
334
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
335
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
345
+	if (isset($_GET['lang_file'])) {
346
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
347
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
348
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
349
+	}
336 350
 
337 351
 	// Make sure it exists, if it doesn't reset it.
338 352
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -341,8 +355,9 @@  discard block
 block discarded – undo
341 355
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
342 356
 
343 357
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
344
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
345
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
358
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
359
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
360
+		}
346 361
 	}
347 362
 
348 363
 	// And now include the actual language file itself.
@@ -359,15 +374,18 @@  discard block
 block discarded – undo
359 374
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings, $db_port;
360 375
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist, $db_mb4;
361 376
 
362
-	if (empty($sourcedir))
363
-		$sourcedir = dirname(__FILE__) . '/Sources';
377
+	if (empty($sourcedir)) {
378
+			$sourcedir = dirname(__FILE__) . '/Sources';
379
+	}
364 380
 
365 381
 	// Need this to check whether we need the database password.
366 382
 	require(dirname(__FILE__) . '/Settings.php');
367
-	if (!defined('SMF'))
368
-		define('SMF', 1);
369
-	if (empty($smcFunc))
370
-		$smcFunc = array();
383
+	if (!defined('SMF')) {
384
+			define('SMF', 1);
385
+	}
386
+	if (empty($smcFunc)) {
387
+			$smcFunc = array();
388
+	}
371 389
 
372 390
 	$modSettings['disableQueryCheck'] = true;
373 391
 
@@ -378,14 +396,17 @@  discard block
 block discarded – undo
378 396
 
379 397
 		$options = array('persist' => $db_persist);
380 398
 
381
-		if (!empty($db_port))
382
-			$options['port'] = $db_port;
399
+		if (!empty($db_port)) {
400
+					$options['port'] = $db_port;
401
+		}
383 402
 
384
-		if (!empty($db_mb4))
385
-			$options['db_mb4'] = $db_mb4;
403
+		if (!empty($db_mb4)) {
404
+					$options['db_mb4'] = $db_mb4;
405
+		}
386 406
 
387
-		if (!$db_connection)
388
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
407
+		if (!$db_connection) {
408
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
409
+		}
389 410
 	}
390 411
 }
391 412
 
@@ -413,8 +434,9 @@  discard block
 block discarded – undo
413 434
 		// @todo REMOVE THIS!!
414 435
 		else
415 436
 		{
416
-			if (function_exists('doStep' . $_GET['step']))
417
-				call_user_func('doStep' . $_GET['step']);
437
+			if (function_exists('doStep' . $_GET['step'])) {
438
+							call_user_func('doStep' . $_GET['step']);
439
+			}
418 440
 		}
419 441
 		// Show the footer.
420 442
 		template_install_below();
@@ -432,8 +454,9 @@  discard block
 block discarded – undo
432 454
 	$incontext['sub_template'] = 'welcome_message';
433 455
 
434 456
 	// Done the submission?
435
-	if (isset($_POST['contbutt']))
436
-		return true;
457
+	if (isset($_POST['contbutt'])) {
458
+			return true;
459
+	}
437 460
 
438 461
 	// See if we think they have already installed it?
439 462
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -441,14 +464,17 @@  discard block
 block discarded – undo
441 464
 		$probably_installed = 0;
442 465
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
443 466
 		{
444
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
445
-				$probably_installed++;
446
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
447
-				$probably_installed++;
467
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
468
+							$probably_installed++;
469
+			}
470
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
471
+							$probably_installed++;
472
+			}
448 473
 		}
449 474
 
450
-		if ($probably_installed == 2)
451
-			$incontext['warning'] = $txt['error_already_installed'];
475
+		if ($probably_installed == 2) {
476
+					$incontext['warning'] = $txt['error_already_installed'];
477
+		}
452 478
 	}
453 479
 
454 480
 	// Is some database support even compiled in?
@@ -463,45 +489,54 @@  discard block
 block discarded – undo
463 489
 				$databases[$key]['supported'] = false;
464 490
 				$notFoundSQLFile = true;
465 491
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
492
+			} else {
493
+							$incontext['supported_databases'][] = $db;
466 494
 			}
467
-			else
468
-				$incontext['supported_databases'][] = $db;
469 495
 		}
470 496
 	}
471 497
 
472 498
 	// Check the PHP version.
473
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
474
-		$error = 'error_php_too_low';
499
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
500
+			$error = 'error_php_too_low';
501
+	}
475 502
 	// Make sure we have a supported database
476
-	elseif (empty($incontext['supported_databases']))
477
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
503
+	elseif (empty($incontext['supported_databases'])) {
504
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
505
+	}
478 506
 	// How about session support?  Some crazy sysadmin remove it?
479
-	elseif (!function_exists('session_start'))
480
-		$error = 'error_session_missing';
507
+	elseif (!function_exists('session_start')) {
508
+			$error = 'error_session_missing';
509
+	}
481 510
 	// Make sure they uploaded all the files.
482
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
483
-		$error = 'error_missing_files';
511
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
512
+			$error = 'error_missing_files';
513
+	}
484 514
 	// Very simple check on the session.save_path for Windows.
485 515
 	// @todo Move this down later if they don't use database-driven sessions?
486
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
487
-		$error = 'error_session_save_path';
516
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
517
+			$error = 'error_session_save_path';
518
+	}
488 519
 
489 520
 	// Since each of the three messages would look the same, anyway...
490
-	if (isset($error))
491
-		$incontext['error'] = $txt[$error];
521
+	if (isset($error)) {
522
+			$incontext['error'] = $txt[$error];
523
+	}
492 524
 
493 525
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
494
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
495
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
526
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
527
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
528
+	}
496 529
 
497 530
 	// Confirm mbstring is loaded...
498
-	if (!extension_loaded('mbstring'))
499
-		$incontext['error'] = $txt['install_no_mbstring'];
531
+	if (!extension_loaded('mbstring')) {
532
+			$incontext['error'] = $txt['install_no_mbstring'];
533
+	}
500 534
 
501 535
 	// Check for https stream support.
502 536
 	$supported_streams = stream_get_wrappers();
503
-	if (!in_array('https', $supported_streams))
504
-		$incontext['warning'] = $txt['install_no_https'];
537
+	if (!in_array('https', $supported_streams)) {
538
+			$incontext['warning'] = $txt['install_no_https'];
539
+	}
505 540
 
506 541
 	return false;
507 542
 }
@@ -526,12 +561,14 @@  discard block
 block discarded – undo
526 561
 		'Settings_bak.php',
527 562
 	);
528 563
 
529
-	foreach ($incontext['detected_languages'] as $lang => $temp)
530
-		$extra_files[] = 'Themes/default/languages/' . $lang;
564
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
565
+			$extra_files[] = 'Themes/default/languages/' . $lang;
566
+	}
531 567
 
532 568
 	// With mod_security installed, we could attempt to fix it with .htaccess.
533
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
534
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
569
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
570
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
571
+	}
535 572
 
536 573
 	$failed_files = array();
537 574
 
@@ -543,20 +580,23 @@  discard block
 block discarded – undo
543 580
 		foreach ($writable_files as $file)
544 581
 		{
545 582
 			// Some files won't exist, try to address up front
546
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
547
-				@touch(dirname(__FILE__) . '/' . $file);
583
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
584
+							@touch(dirname(__FILE__) . '/' . $file);
585
+			}
548 586
 			// NOW do the writable check...
549 587
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
550 588
 			{
551 589
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
552 590
 
553 591
 				// Well, 755 hopefully worked... if not, try 777.
554
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
555
-					$failed_files[] = $file;
592
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
593
+									$failed_files[] = $file;
594
+				}
556 595
 			}
557 596
 		}
558
-		foreach ($extra_files as $file)
559
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
597
+		foreach ($extra_files as $file) {
598
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
599
+		}
560 600
 	}
561 601
 	// Windows is trickier.  Let's try opening for r+...
562 602
 	else
@@ -566,30 +606,35 @@  discard block
 block discarded – undo
566 606
 		foreach ($writable_files as $file)
567 607
 		{
568 608
 			// Folders can't be opened for write... but the index.php in them can ;)
569
-			if (is_dir(dirname(__FILE__) . '/' . $file))
570
-				$file .= '/index.php';
609
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
610
+							$file .= '/index.php';
611
+			}
571 612
 
572 613
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
573 614
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
574 615
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
575 616
 
576 617
 			// Hmm, okay, try just for write in that case...
577
-			if (!is_resource($fp))
578
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
618
+			if (!is_resource($fp)) {
619
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
620
+			}
579 621
 
580
-			if (!is_resource($fp))
581
-				$failed_files[] = $file;
622
+			if (!is_resource($fp)) {
623
+							$failed_files[] = $file;
624
+			}
582 625
 
583 626
 			@fclose($fp);
584 627
 		}
585
-		foreach ($extra_files as $file)
586
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
628
+		foreach ($extra_files as $file) {
629
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
630
+		}
587 631
 	}
588 632
 
589 633
 	$failure = count($failed_files) >= 1;
590 634
 
591
-	if (!isset($_SERVER))
592
-		return !$failure;
635
+	if (!isset($_SERVER)) {
636
+			return !$failure;
637
+	}
593 638
 
594 639
 	// Put the list into context.
595 640
 	$incontext['failed_files'] = $failed_files;
@@ -637,19 +682,23 @@  discard block
 block discarded – undo
637 682
 
638 683
 		if (!isset($ftp) || $ftp->error !== false)
639 684
 		{
640
-			if (!isset($ftp))
641
-				$ftp = new ftp_connection(null);
685
+			if (!isset($ftp)) {
686
+							$ftp = new ftp_connection(null);
687
+			}
642 688
 			// Save the error so we can mess with listing...
643
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
644
-				$incontext['ftp_errors'][] = $ftp->last_message;
689
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
690
+							$incontext['ftp_errors'][] = $ftp->last_message;
691
+			}
645 692
 
646 693
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
647 694
 
648
-			if (empty($_POST['ftp_path']) && $found_path)
649
-				$_POST['ftp_path'] = $detect_path;
695
+			if (empty($_POST['ftp_path']) && $found_path) {
696
+							$_POST['ftp_path'] = $detect_path;
697
+			}
650 698
 
651
-			if (!isset($_POST['ftp_username']))
652
-				$_POST['ftp_username'] = $username;
699
+			if (!isset($_POST['ftp_username'])) {
700
+							$_POST['ftp_username'] = $username;
701
+			}
653 702
 
654 703
 			// Set the username etc, into context.
655 704
 			$incontext['ftp'] = array(
@@ -661,8 +710,7 @@  discard block
 block discarded – undo
661 710
 			);
662 711
 
663 712
 			return false;
664
-		}
665
-		else
713
+		} else
666 714
 		{
667 715
 			$_SESSION['installer_temp_ftp'] = array(
668 716
 				'server' => $_POST['ftp_server'],
@@ -676,10 +724,12 @@  discard block
 block discarded – undo
676 724
 
677 725
 			foreach ($failed_files as $file)
678 726
 			{
679
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
680
-					$ftp->chmod($file, 0755);
681
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
682
-					$ftp->chmod($file, 0777);
727
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
728
+									$ftp->chmod($file, 0755);
729
+				}
730
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
731
+									$ftp->chmod($file, 0777);
732
+				}
683 733
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
684 734
 				{
685 735
 					$failed_files_updated[] = $file;
@@ -735,15 +785,17 @@  discard block
 block discarded – undo
735 785
 
736 786
 			if (!$foundOne)
737 787
 			{
738
-				if (isset($db['default_host']))
739
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
788
+				if (isset($db['default_host'])) {
789
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
790
+				}
740 791
 				if (isset($db['default_user']))
741 792
 				{
742 793
 					$incontext['db']['user'] = ini_get($db['default_user']);
743 794
 					$incontext['db']['name'] = ini_get($db['default_user']);
744 795
 				}
745
-				if (isset($db['default_password']))
746
-					$incontext['db']['pass'] = ini_get($db['default_password']);
796
+				if (isset($db['default_password'])) {
797
+									$incontext['db']['pass'] = ini_get($db['default_password']);
798
+				}
747 799
 
748 800
 				// For simplicity and less confusion, leave the port blank by default
749 801
 				$incontext['db']['port'] = '';
@@ -762,10 +814,10 @@  discard block
 block discarded – undo
762 814
 		$incontext['db']['server'] = $_POST['db_server'];
763 815
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
764 816
 
765
-		if (!empty($_POST['db_port']))
766
-			$incontext['db']['port'] = $_POST['db_port'];
767
-	}
768
-	else
817
+		if (!empty($_POST['db_port'])) {
818
+					$incontext['db']['port'] = $_POST['db_port'];
819
+		}
820
+	} else
769 821
 	{
770 822
 		$incontext['db']['prefix'] = 'smf_';
771 823
 	}
@@ -801,10 +853,11 @@  discard block
 block discarded – undo
801 853
 		if (!empty($_POST['db_port']))
802 854
 		{
803 855
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
804
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
805
-				$vars['db_port'] = (int) $_POST['db_port'];
806
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
807
-				$vars['db_port'] = (int) $_POST['db_port'];
856
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
857
+							$vars['db_port'] = (int) $_POST['db_port'];
858
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
859
+							$vars['db_port'] = (int) $_POST['db_port'];
860
+			}
808 861
 		}
809 862
 
810 863
 		// God I hope it saved!
@@ -817,8 +870,9 @@  discard block
 block discarded – undo
817 870
 		// Make sure it works.
818 871
 		require(dirname(__FILE__) . '/Settings.php');
819 872
 
820
-		if (empty($sourcedir))
821
-			$sourcedir = dirname(__FILE__) . '/Sources';
873
+		if (empty($sourcedir)) {
874
+					$sourcedir = dirname(__FILE__) . '/Sources';
875
+		}
822 876
 
823 877
 		// Better find the database file!
824 878
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -828,12 +882,14 @@  discard block
 block discarded – undo
828 882
 		}
829 883
 
830 884
 		// Now include it for database functions!
831
-		if (!defined('SMF'))
832
-			define('SMF', 1);
885
+		if (!defined('SMF')) {
886
+					define('SMF', 1);
887
+		}
833 888
 
834 889
 		$modSettings['disableQueryCheck'] = true;
835
-		if (empty($smcFunc))
836
-			$smcFunc = array();
890
+		if (empty($smcFunc)) {
891
+					$smcFunc = array();
892
+		}
837 893
 
838 894
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
839 895
 
@@ -842,11 +898,13 @@  discard block
 block discarded – undo
842 898
 
843 899
 		$options = array('non_fatal' => true, 'dont_select_db' => !$needsDB);
844 900
 		// Add in the port if needed
845
-		if (!empty($db_port))
846
-			$options['port'] = $db_port;
901
+		if (!empty($db_port)) {
902
+					$options['port'] = $db_port;
903
+		}
847 904
 		
848
-		if (!empty($db_mb4))
849
-			$options['db_mb4'] = $db_mb4;
905
+		if (!empty($db_mb4)) {
906
+					$options['db_mb4'] = $db_mb4;
907
+		}
850 908
 
851 909
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
852 910
 
@@ -932,12 +990,14 @@  discard block
 block discarded – undo
932 990
 	$incontext['page_title'] = $txt['install_settings'];
933 991
 
934 992
 	// Let's see if we got the database type correct.
935
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
936
-		$db_type = $_POST['db_type'];
993
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
994
+			$db_type = $_POST['db_type'];
995
+	}
937 996
 
938 997
 	// Else we'd better be able to get the connection.
939
-	else
940
-		load_database();
998
+	else {
999
+			load_database();
1000
+	}
941 1001
 
942 1002
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
943 1003
 
@@ -946,10 +1006,11 @@  discard block
 block discarded – undo
946 1006
 
947 1007
 		$secure = false;
948 1008
 
949
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
950
-			$secure = true;
951
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
952
-			$secure = true;
1009
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1010
+					$secure = true;
1011
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
1012
+					$secure = true;
1013
+		}
953 1014
 
954 1015
 	// Now, to put what we've learned together... and add a path.
955 1016
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -981,18 +1042,21 @@  discard block
 block discarded – undo
981 1042
 	// Submitting?
982 1043
 	if (isset($_POST['boardurl']))
983 1044
 	{
984
-		if (substr($_POST['boardurl'], -10) == '/index.php')
985
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
986
-		elseif (substr($_POST['boardurl'], -1) == '/')
987
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
988
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
989
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1045
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1046
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1047
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1048
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1049
+		}
1050
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1051
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1052
+		}
990 1053
 
991 1054
 		//Make sure boardurl is aligned with ssl setting
992
-		if (empty($_POST['force_ssl']))
993
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
994
-		else
995
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1055
+		if (empty($_POST['force_ssl'])) {
1056
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1057
+		} else {
1058
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1059
+		}
996 1060
 
997 1061
 		// Save these variables.
998 1062
 		$vars = array(
@@ -1031,10 +1095,10 @@  discard block
 block discarded – undo
1031 1095
 			{
1032 1096
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1033 1097
 				return false;
1034
-			}
1035
-			else
1036
-				// Set the character set here.
1098
+			} else {
1099
+							// Set the character set here.
1037 1100
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1101
+			}
1038 1102
 		}
1039 1103
 
1040 1104
 		// Good, skip on.
@@ -1054,8 +1118,9 @@  discard block
 block discarded – undo
1054 1118
 	$incontext['continue'] = 1;
1055 1119
 
1056 1120
 	// Already done?
1057
-	if (isset($_POST['pop_done']))
1058
-		return true;
1121
+	if (isset($_POST['pop_done'])) {
1122
+			return true;
1123
+	}
1059 1124
 
1060 1125
 	// Reload settings.
1061 1126
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1073,8 +1138,9 @@  discard block
 block discarded – undo
1073 1138
 	$modSettings = array();
1074 1139
 	if ($result !== false)
1075 1140
 	{
1076
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1077
-			$modSettings[$row['variable']] = $row['value'];
1141
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1142
+					$modSettings[$row['variable']] = $row['value'];
1143
+		}
1078 1144
 		$smcFunc['db_free_result']($result);
1079 1145
 
1080 1146
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1087,20 +1153,22 @@  discard block
 block discarded – undo
1087 1153
 	$modSettings['disableQueryCheck'] = true;
1088 1154
 
1089 1155
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1090
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1091
-		$smcFunc['db_query']('', '
1156
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1157
+			$smcFunc['db_query']('', '
1092 1158
 			SET NAMES {string:utf8}',
1093 1159
 			array(
1094 1160
 				'db_error_skip' => true,
1095 1161
 				'utf8' => 'utf8',
1096 1162
 			)
1097 1163
 		);
1164
+	}
1098 1165
 
1099 1166
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1100
-	if (substr(__DIR__, -1) == '\\')
1101
-		$attachdir = __DIR__ . 'attachments';
1102
-	else
1103
-		$attachdir = __DIR__ . '/attachments';
1167
+	if (substr(__DIR__, -1) == '\\') {
1168
+			$attachdir = __DIR__ . 'attachments';
1169
+	} else {
1170
+			$attachdir = __DIR__ . '/attachments';
1171
+	}
1104 1172
 
1105 1173
 	$replaces = array(
1106 1174
 		'{$db_prefix}' => $db_prefix,
@@ -1117,8 +1185,9 @@  discard block
 block discarded – undo
1117 1185
 
1118 1186
 	foreach ($txt as $key => $value)
1119 1187
 	{
1120
-		if (substr($key, 0, 8) == 'default_')
1121
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1188
+		if (substr($key, 0, 8) == 'default_') {
1189
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1190
+		}
1122 1191
 	}
1123 1192
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1124 1193
 
@@ -1133,8 +1202,9 @@  discard block
 block discarded – undo
1133 1202
 
1134 1203
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1135 1204
 		{
1136
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1137
-				$engines[] = $row['Engine'];
1205
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1206
+							$engines[] = $row['Engine'];
1207
+			}
1138 1208
 		}
1139 1209
 
1140 1210
 		// Done with this now
@@ -1158,8 +1228,7 @@  discard block
 block discarded – undo
1158 1228
 			$replaces['START TRANSACTION;'] = '';
1159 1229
 			$replaces['COMMIT;'] = '';
1160 1230
 		}
1161
-	}
1162
-	else
1231
+	} else
1163 1232
 	{
1164 1233
 		$has_innodb = false;
1165 1234
 	}
@@ -1181,21 +1250,24 @@  discard block
 block discarded – undo
1181 1250
 	foreach ($sql_lines as $count => $line)
1182 1251
 	{
1183 1252
 		// No comments allowed!
1184
-		if (substr(trim($line), 0, 1) != '#')
1185
-			$current_statement .= "\n" . rtrim($line);
1253
+		if (substr(trim($line), 0, 1) != '#') {
1254
+					$current_statement .= "\n" . rtrim($line);
1255
+		}
1186 1256
 
1187 1257
 		// Is this the end of the query string?
1188
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1189
-			continue;
1258
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1259
+					continue;
1260
+		}
1190 1261
 
1191 1262
 		// Does this table already exist?  If so, don't insert more data into it!
1192 1263
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1193 1264
 		{
1194 1265
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1195
-			if (!empty($matches[0]))
1196
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1197
-			else
1198
-				$incontext['sql_results']['insert_dups']++;
1266
+			if (!empty($matches[0])) {
1267
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1268
+			} else {
1269
+							$incontext['sql_results']['insert_dups']++;
1270
+			}
1199 1271
 
1200 1272
 			$current_statement = '';
1201 1273
 			continue;
@@ -1216,18 +1288,18 @@  discard block
 block discarded – undo
1216 1288
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1217 1289
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1218 1290
 			}
1219
-		}
1220
-		else
1291
+		} else
1221 1292
 		{
1222
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1223
-				$incontext['sql_results']['tables']++;
1224
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1293
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1294
+							$incontext['sql_results']['tables']++;
1295
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1225 1296
 			{
1226 1297
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1227
-				if (!empty($matches[0]))
1228
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1229
-				else
1230
-					$incontext['sql_results']['inserts']++;
1298
+				if (!empty($matches[0])) {
1299
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1300
+				} else {
1301
+									$incontext['sql_results']['inserts']++;
1302
+				}
1231 1303
 			}
1232 1304
 		}
1233 1305
 
@@ -1240,15 +1312,17 @@  discard block
 block discarded – undo
1240 1312
 	// Sort out the context for the SQL.
1241 1313
 	foreach ($incontext['sql_results'] as $key => $number)
1242 1314
 	{
1243
-		if ($number == 0)
1244
-			unset($incontext['sql_results'][$key]);
1245
-		else
1246
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1315
+		if ($number == 0) {
1316
+					unset($incontext['sql_results'][$key]);
1317
+		} else {
1318
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1319
+		}
1247 1320
 	}
1248 1321
 
1249 1322
 	// Make sure UTF will be used globally.
1250
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1251
-		$newSettings[] = array('global_character_set', 'UTF-8');
1323
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1324
+			$newSettings[] = array('global_character_set', 'UTF-8');
1325
+	}
1252 1326
 
1253 1327
 	// Auto-detect local & global cookie settings
1254 1328
 	$url_parts = parse_url($boardurl);
@@ -1277,15 +1351,19 @@  discard block
 block discarded – undo
1277 1351
 
1278 1352
 		// Look for subfolder, if found, set localCookie
1279 1353
 		// Checking for len > 1 ensures you don't have just a slash...
1280
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1281
-			$localCookies = '1';
1354
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1355
+					$localCookies = '1';
1356
+		}
1282 1357
 
1283
-		if (isset($globalCookies))
1284
-			$newSettings[] = array('globalCookies', $globalCookies);
1285
-		if (isset($globalCookiesDomain))
1286
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1287
-		if (isset($localCookies))
1288
-			$newSettings[] = array('localCookies', $localCookies);
1358
+		if (isset($globalCookies)) {
1359
+					$newSettings[] = array('globalCookies', $globalCookies);
1360
+		}
1361
+		if (isset($globalCookiesDomain)) {
1362
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1363
+		}
1364
+		if (isset($localCookies)) {
1365
+					$newSettings[] = array('localCookies', $localCookies);
1366
+		}
1289 1367
 	}
1290 1368
 
1291 1369
 	// Are we allowing stat collection?
@@ -1303,16 +1381,17 @@  discard block
 block discarded – undo
1303 1381
 			fwrite($fp, $out);
1304 1382
 
1305 1383
 			$return_data = '';
1306
-			while (!feof($fp))
1307
-				$return_data .= fgets($fp, 128);
1384
+			while (!feof($fp)) {
1385
+							$return_data .= fgets($fp, 128);
1386
+			}
1308 1387
 
1309 1388
 			fclose($fp);
1310 1389
 
1311 1390
 			// Get the unique site ID.
1312 1391
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1313 1392
 
1314
-			if (!empty($ID[1]))
1315
-				$smcFunc['db_insert']('replace',
1393
+			if (!empty($ID[1])) {
1394
+							$smcFunc['db_insert']('replace',
1316 1395
 					$db_prefix . 'settings',
1317 1396
 					array('variable' => 'string', 'value' => 'string'),
1318 1397
 					array(
@@ -1321,11 +1400,12 @@  discard block
 block discarded – undo
1321 1400
 					),
1322 1401
 					array('variable')
1323 1402
 				);
1403
+			}
1324 1404
 		}
1325 1405
 	}
1326 1406
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1327
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1328
-		$smcFunc['db_query']('', '
1407
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1408
+			$smcFunc['db_query']('', '
1329 1409
 			DELETE FROM {db_prefix}settings
1330 1410
 			WHERE variable = {string:enable_sm_stats}',
1331 1411
 			array(
@@ -1333,20 +1413,23 @@  discard block
 block discarded – undo
1333 1413
 				'db_error_skip' => true,
1334 1414
 			)
1335 1415
 		);
1416
+	}
1336 1417
 
1337 1418
 	// Are we enabling SSL?
1338
-	if (!empty($_POST['force_ssl']))
1339
-		$newSettings[] = array('force_ssl', 1);
1419
+	if (!empty($_POST['force_ssl'])) {
1420
+			$newSettings[] = array('force_ssl', 1);
1421
+	}
1340 1422
 
1341 1423
 	// Setting a timezone is required.
1342 1424
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1343 1425
 	{
1344 1426
 		// Get PHP's default timezone, if set
1345 1427
 		$ini_tz = ini_get('date.timezone');
1346
-		if (!empty($ini_tz))
1347
-			$timezone_id = $ini_tz;
1348
-		else
1349
-			$timezone_id = '';
1428
+		if (!empty($ini_tz)) {
1429
+					$timezone_id = $ini_tz;
1430
+		} else {
1431
+					$timezone_id = '';
1432
+		}
1350 1433
 
1351 1434
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1352 1435
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1355,8 +1438,9 @@  discard block
 block discarded – undo
1355 1438
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1356 1439
 		}
1357 1440
 
1358
-		if (date_default_timezone_set($timezone_id))
1359
-			$newSettings[] = array('default_timezone', $timezone_id);
1441
+		if (date_default_timezone_set($timezone_id)) {
1442
+					$newSettings[] = array('default_timezone', $timezone_id);
1443
+		}
1360 1444
 	}
1361 1445
 
1362 1446
 	if (!empty($newSettings))
@@ -1387,16 +1471,18 @@  discard block
 block discarded – undo
1387 1471
 	}
1388 1472
 
1389 1473
 	// MySQL specific stuff
1390
-	if (substr($db_type, 0, 5) != 'mysql')
1391
-		return false;
1474
+	if (substr($db_type, 0, 5) != 'mysql') {
1475
+			return false;
1476
+	}
1392 1477
 
1393 1478
 	// Find database user privileges.
1394 1479
 	$privs = array();
1395 1480
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1396 1481
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1397 1482
 	{
1398
-		if ($row['Privilege'] == 'Alter')
1399
-			$privs[] = $row['Privilege'];
1483
+		if ($row['Privilege'] == 'Alter') {
1484
+					$privs[] = $row['Privilege'];
1485
+		}
1400 1486
 	}
1401 1487
 	$smcFunc['db_free_result']($get_privs);
1402 1488
 
@@ -1426,8 +1512,9 @@  discard block
 block discarded – undo
1426 1512
 	$incontext['continue'] = 1;
1427 1513
 
1428 1514
 	// Skipping?
1429
-	if (!empty($_POST['skip']))
1430
-		return true;
1515
+	if (!empty($_POST['skip'])) {
1516
+			return true;
1517
+	}
1431 1518
 
1432 1519
 	// Need this to check whether we need the database password.
1433 1520
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1444,18 +1531,22 @@  discard block
 block discarded – undo
1444 1531
 	// We need this to properly hash the password for Admin
1445 1532
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1446 1533
 			global $sourcedir;
1447
-			if (function_exists('mb_strtolower'))
1448
-				return mb_strtolower($string, 'UTF-8');
1534
+			if (function_exists('mb_strtolower')) {
1535
+							return mb_strtolower($string, 'UTF-8');
1536
+			}
1449 1537
 			require_once($sourcedir . '/Subs-Charset.php');
1450 1538
 			return utf8_strtolower($string);
1451 1539
 		};
1452 1540
 
1453
-	if (!isset($_POST['username']))
1454
-		$_POST['username'] = '';
1455
-	if (!isset($_POST['email']))
1456
-		$_POST['email'] = '';
1457
-	if (!isset($_POST['server_email']))
1458
-		$_POST['server_email'] = '';
1541
+	if (!isset($_POST['username'])) {
1542
+			$_POST['username'] = '';
1543
+	}
1544
+	if (!isset($_POST['email'])) {
1545
+			$_POST['email'] = '';
1546
+	}
1547
+	if (!isset($_POST['server_email'])) {
1548
+			$_POST['server_email'] = '';
1549
+	}
1459 1550
 
1460 1551
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1461 1552
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1474,8 +1565,9 @@  discard block
 block discarded – undo
1474 1565
 			'admin_group' => 1,
1475 1566
 		)
1476 1567
 	);
1477
-	if ($smcFunc['db_num_rows']($request) != 0)
1478
-		$incontext['skip'] = 1;
1568
+	if ($smcFunc['db_num_rows']($request) != 0) {
1569
+			$incontext['skip'] = 1;
1570
+	}
1479 1571
 	$smcFunc['db_free_result']($request);
1480 1572
 
1481 1573
 	// Trying to create an account?
@@ -1506,8 +1598,9 @@  discard block
 block discarded – undo
1506 1598
 		}
1507 1599
 
1508 1600
 		// Update the webmaster's email?
1509
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1510
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1601
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1602
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1603
+		}
1511 1604
 
1512 1605
 		// Work out whether we're going to have dodgy characters and remove them.
1513 1606
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1530,32 +1623,27 @@  discard block
 block discarded – undo
1530 1623
 			$smcFunc['db_free_result']($result);
1531 1624
 
1532 1625
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1533
-		}
1534
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1626
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1535 1627
 		{
1536 1628
 			// Try the previous step again.
1537 1629
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1538 1630
 			return false;
1539
-		}
1540
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1631
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1541 1632
 		{
1542 1633
 			// Try the previous step again.
1543 1634
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1544 1635
 			return false;
1545
-		}
1546
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1636
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1547 1637
 		{
1548 1638
 			// One step back, this time fill out a proper admin email address.
1549 1639
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1550 1640
 			return false;
1551
-		}
1552
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1641
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1553 1642
 		{
1554 1643
 			// One step back, this time fill out a proper admin email address.
1555 1644
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1556 1645
 			return false;
1557
-		}
1558
-		elseif ($_POST['username'] != '')
1646
+		} elseif ($_POST['username'] != '')
1559 1647
 		{
1560 1648
 			$incontext['member_salt'] = substr(md5(random_int(0, PHP_INT_MAX)), 0, 4);
1561 1649
 
@@ -1623,17 +1711,19 @@  discard block
 block discarded – undo
1623 1711
 	reloadSettings();
1624 1712
 
1625 1713
 	// Bring a warning over.
1626
-	if (!empty($incontext['account_existed']))
1627
-		$incontext['warning'] = $incontext['account_existed'];
1714
+	if (!empty($incontext['account_existed'])) {
1715
+			$incontext['warning'] = $incontext['account_existed'];
1716
+	}
1628 1717
 
1629
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1630
-		$smcFunc['db_query']('', '
1718
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1719
+			$smcFunc['db_query']('', '
1631 1720
 			SET NAMES {string:db_character_set}',
1632 1721
 			array(
1633 1722
 				'db_character_set' => $db_character_set,
1634 1723
 				'db_error_skip' => true,
1635 1724
 			)
1636 1725
 		);
1726
+	}
1637 1727
 
1638 1728
 	// As track stats is by default enabled let's add some activity.
1639 1729
 	$smcFunc['db_insert']('ignore',
@@ -1654,14 +1744,16 @@  discard block
 block discarded – undo
1654 1744
 	// Only proceed if we can load the data.
1655 1745
 	if ($request)
1656 1746
 	{
1657
-		while ($row = $smcFunc['db_fetch_row']($request))
1658
-			$modSettings[$row[0]] = $row[1];
1747
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1748
+					$modSettings[$row[0]] = $row[1];
1749
+		}
1659 1750
 		$smcFunc['db_free_result']($request);
1660 1751
 	}
1661 1752
 
1662 1753
 	// Automatically log them in ;)
1663
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1664
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1754
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1755
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1756
+	}
1665 1757
 
1666 1758
 	$result = $smcFunc['db_query']('', '
1667 1759
 		SELECT value
@@ -1672,13 +1764,14 @@  discard block
 block discarded – undo
1672 1764
 			'db_error_skip' => true,
1673 1765
 		)
1674 1766
 	);
1675
-	if ($smcFunc['db_num_rows']($result) != 0)
1676
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1767
+	if ($smcFunc['db_num_rows']($result) != 0) {
1768
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1769
+	}
1677 1770
 	$smcFunc['db_free_result']($result);
1678 1771
 
1679
-	if (empty($db_sessions))
1680
-		$_SESSION['admin_time'] = time();
1681
-	else
1772
+	if (empty($db_sessions)) {
1773
+			$_SESSION['admin_time'] = time();
1774
+	} else
1682 1775
 	{
1683 1776
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1684 1777
 
@@ -1702,8 +1795,9 @@  discard block
 block discarded – undo
1702 1795
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1703 1796
 		function($string){
1704 1797
 			global $sourcedir;
1705
-			if (function_exists('mb_strtolower'))
1706
-				return mb_strtolower($string, 'UTF-8');
1798
+			if (function_exists('mb_strtolower')) {
1799
+							return mb_strtolower($string, 'UTF-8');
1800
+			}
1707 1801
 			require_once($sourcedir . '/Subs-Charset.php');
1708 1802
 			return utf8_strtolower($string);
1709 1803
 		};
@@ -1719,8 +1813,9 @@  discard block
 block discarded – undo
1719 1813
 		)
1720 1814
 	);
1721 1815
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1722
-	if ($smcFunc['db_num_rows']($request) > 0)
1723
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1816
+	if ($smcFunc['db_num_rows']($request) > 0) {
1817
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1818
+	}
1724 1819
 	$smcFunc['db_free_result']($request);
1725 1820
 
1726 1821
 	// Now is the perfect time to fetch the SM files.
@@ -1739,8 +1834,9 @@  discard block
 block discarded – undo
1739 1834
 
1740 1835
 	// Check if we need some stupid MySQL fix.
1741 1836
 	$server_version = $smcFunc['db_server_info']();
1742
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1743
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1837
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1838
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1839
+	}
1744 1840
 
1745 1841
 	// Some final context for the template.
1746 1842
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1760,8 +1856,9 @@  discard block
 block discarded – undo
1760 1856
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1761 1857
 
1762 1858
 	// @todo Do we just want to read the file in clean, and split it this way always?
1763
-	if (count($settingsArray) == 1)
1764
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1859
+	if (count($settingsArray) == 1) {
1860
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1861
+	}
1765 1862
 
1766 1863
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1767 1864
 	{
@@ -1769,25 +1866,29 @@  discard block
 block discarded – undo
1769 1866
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1770 1867
 		{
1771 1868
 			// Set the ten lines to nothing.
1772
-			for ($j=0; $j < 10; $j++)
1773
-				$settingsArray[$i++] = '';
1869
+			for ($j=0; $j < 10; $j++) {
1870
+							$settingsArray[$i++] = '';
1871
+			}
1774 1872
 
1775 1873
 			continue;
1776 1874
 		}
1777 1875
 
1778
-		if (trim($settingsArray[$i]) == '?' . '>')
1779
-			$settingsArray[$i] = '';
1876
+		if (trim($settingsArray[$i]) == '?' . '>') {
1877
+					$settingsArray[$i] = '';
1878
+		}
1780 1879
 
1781 1880
 		// Don't trim or bother with it if it's not a variable.
1782
-		if (substr($settingsArray[$i], 0, 1) != '$')
1783
-			continue;
1881
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1882
+					continue;
1883
+		}
1784 1884
 
1785 1885
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1786 1886
 
1787
-		foreach ($vars as $var => $val)
1788
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1887
+		foreach ($vars as $var => $val) {
1888
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1789 1889
 			{
1790 1890
 				$comment = strstr($settingsArray[$i], '#');
1891
+		}
1791 1892
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1792 1893
 				unset($vars[$var]);
1793 1894
 			}
@@ -1797,36 +1898,41 @@  discard block
 block discarded – undo
1797 1898
 	if (!empty($vars))
1798 1899
 	{
1799 1900
 		$settingsArray[$i++] = '';
1800
-		foreach ($vars as $var => $val)
1801
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1901
+		foreach ($vars as $var => $val) {
1902
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1903
+		}
1802 1904
 	}
1803 1905
 
1804 1906
 	// Blank out the file - done to fix a oddity with some servers.
1805 1907
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1806
-	if (!$fp)
1807
-		return false;
1908
+	if (!$fp) {
1909
+			return false;
1910
+	}
1808 1911
 	fclose($fp);
1809 1912
 
1810 1913
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1811 1914
 
1812 1915
 	// Gotta have one of these ;)
1813
-	if (trim($settingsArray[0]) != '<?php')
1814
-		fwrite($fp, "<?php\n");
1916
+	if (trim($settingsArray[0]) != '<?php') {
1917
+			fwrite($fp, "<?php\n");
1918
+	}
1815 1919
 
1816 1920
 	$lines = count($settingsArray);
1817 1921
 	for ($i = 0; $i < $lines - 1; $i++)
1818 1922
 	{
1819 1923
 		// Don't just write a bunch of blank lines.
1820
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1821
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1924
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1925
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1926
+		}
1822 1927
 	}
1823 1928
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1824 1929
 	fclose($fp);
1825 1930
 
1826 1931
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1827 1932
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1828
-	if (function_exists('opcache_invalidate'))
1829
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1933
+	if (function_exists('opcache_invalidate')) {
1934
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1935
+	}
1830 1936
 
1831 1937
 	return true;
1832 1938
 }
@@ -1836,10 +1942,11 @@  discard block
 block discarded – undo
1836 1942
 	global $cachedir;
1837 1943
 
1838 1944
 	// Write out the db_last_error file with the error timestamp
1839
-	if (!empty($cachedir) && is_writable($cachedir))
1840
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1841
-	else
1842
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1945
+	if (!empty($cachedir) && is_writable($cachedir)) {
1946
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1947
+	} else {
1948
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1949
+	}
1843 1950
 
1844 1951
 	return true;
1845 1952
 }
@@ -1856,9 +1963,9 @@  discard block
 block discarded – undo
1856 1963
 	SecFilterScanPOST Off
1857 1964
 </IfModule>';
1858 1965
 
1859
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1860
-		return true;
1861
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1966
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1967
+			return true;
1968
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1862 1969
 	{
1863 1970
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1864 1971
 
@@ -1870,29 +1977,28 @@  discard block
 block discarded – undo
1870 1977
 				fwrite($ht_handle, $htaccess_addition);
1871 1978
 				fclose($ht_handle);
1872 1979
 				return true;
1980
+			} else {
1981
+							return false;
1873 1982
 			}
1874
-			else
1875
-				return false;
1983
+		} else {
1984
+					return true;
1876 1985
 		}
1877
-		else
1878
-			return true;
1879
-	}
1880
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1881
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1882
-	elseif (is_writable(dirname(__FILE__)))
1986
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1987
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1988
+	} elseif (is_writable(dirname(__FILE__)))
1883 1989
 	{
1884 1990
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1885 1991
 		{
1886 1992
 			fwrite($ht_handle, $htaccess_addition);
1887 1993
 			fclose($ht_handle);
1888 1994
 			return true;
1995
+		} else {
1996
+					return false;
1889 1997
 		}
1890
-		else
1998
+	} else {
1891 1999
 			return false;
1892 2000
 	}
1893
-	else
1894
-		return false;
1895
-}
2001
+	}
1896 2002
 
1897 2003
 function template_install_above()
1898 2004
 {
@@ -1931,9 +2037,10 @@  discard block
 block discarded – undo
1931 2037
 							<label for="installer_language">', $txt['installer_language'], ':</label>
1932 2038
 							<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1933 2039
 
1934
-		foreach ($incontext['detected_languages'] as $lang => $name)
1935
-			echo '
2040
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2041
+					echo '
1936 2042
 								<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2043
+		}
1937 2044
 
1938 2045
 		echo '
1939 2046
 							</select>
@@ -1953,9 +2060,10 @@  discard block
 block discarded – undo
1953 2060
 					<h2>', $txt['upgrade_progress'], '</h2>
1954 2061
 					<ul>';
1955 2062
 
1956
-	foreach ($incontext['steps'] as $num => $step)
1957
-		echo '
2063
+	foreach ($incontext['steps'] as $num => $step) {
2064
+			echo '
1958 2065
 						<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2066
+	}
1959 2067
 
1960 2068
 	echo '
1961 2069
 					</ul>
@@ -1981,20 +2089,23 @@  discard block
 block discarded – undo
1981 2089
 		echo '
1982 2090
 							<div class="floatright">';
1983 2091
 
1984
-		if (!empty($incontext['continue']))
1985
-			echo '
2092
+		if (!empty($incontext['continue'])) {
2093
+					echo '
1986 2094
 								<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">';
1987
-		if (!empty($incontext['skip']))
1988
-			echo '
2095
+		}
2096
+		if (!empty($incontext['skip'])) {
2097
+					echo '
1989 2098
 								<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">';
2099
+		}
1990 2100
 		echo '
1991 2101
 							</div>';
1992 2102
 	}
1993 2103
 
1994 2104
 	// Show the closing form tag and other data only if not in the last step
1995
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1996
-		echo '
2105
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2106
+			echo '
1997 2107
 						</form>';
2108
+	}
1998 2109
 
1999 2110
 	echo '
2000 2111
 					</div><!-- .panel -->
@@ -2027,13 +2138,15 @@  discard block
 block discarded – undo
2027 2138
 		</div>';
2028 2139
 
2029 2140
 	// Show the warnings, or not.
2030
-	if (template_warning_divs())
2031
-		echo '
2141
+	if (template_warning_divs()) {
2142
+			echo '
2032 2143
 		<h3>', $txt['install_all_lovely'], '</h3>';
2144
+	}
2033 2145
 
2034 2146
 	// Say we want the continue button!
2035
-	if (empty($incontext['error']))
2036
-		$incontext['continue'] = 1;
2147
+	if (empty($incontext['error'])) {
2148
+			$incontext['continue'] = 1;
2149
+	}
2037 2150
 
2038 2151
 	// For the latest version stuff.
2039 2152
 	echo '
@@ -2067,19 +2180,21 @@  discard block
 block discarded – undo
2067 2180
 	global $txt, $incontext;
2068 2181
 
2069 2182
 	// Errors are very serious..
2070
-	if (!empty($incontext['error']))
2071
-		echo '
2183
+	if (!empty($incontext['error'])) {
2184
+			echo '
2072 2185
 		<div class="errorbox">
2073 2186
 			<h3>', $txt['upgrade_critical_error'], '</h3>
2074 2187
 			', $incontext['error'], '
2075 2188
 		</div>';
2189
+	}
2076 2190
 	// A warning message?
2077
-	elseif (!empty($incontext['warning']))
2078
-		echo '
2191
+	elseif (!empty($incontext['warning'])) {
2192
+			echo '
2079 2193
 		<div class="errorbox">
2080 2194
 			<h3>', $txt['upgrade_warning'], '</h3>
2081 2195
 			', $incontext['warning'], '
2082 2196
 		</div>';
2197
+	}
2083 2198
 
2084 2199
 	return empty($incontext['error']) && empty($incontext['warning']);
2085 2200
 }
@@ -2095,26 +2210,29 @@  discard block
 block discarded – undo
2095 2210
 			<li>', $incontext['failed_files']), '</li>
2096 2211
 		</ul>';
2097 2212
 
2098
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2099
-		echo '
2213
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2214
+			echo '
2100 2215
 		<hr>
2101 2216
 		<p>', $txt['chmod_linux_info'], '</p>
2102 2217
 		<samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>';
2218
+	}
2103 2219
 
2104 2220
 	// This is serious!
2105
-	if (!template_warning_divs())
2106
-		return;
2221
+	if (!template_warning_divs()) {
2222
+			return;
2223
+	}
2107 2224
 
2108 2225
 	echo '
2109 2226
 		<hr>
2110 2227
 		<p>', $txt['ftp_setup_info'], '</p>';
2111 2228
 
2112
-	if (!empty($incontext['ftp_errors']))
2113
-		echo '
2229
+	if (!empty($incontext['ftp_errors'])) {
2230
+			echo '
2114 2231
 		<div class="error_message">
2115 2232
 			', $txt['error_ftp_no_connect'], '<br><br>
2116 2233
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2117 2234
 		</div>';
2235
+	}
2118 2236
 
2119 2237
 	echo '
2120 2238
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2183,16 +2301,16 @@  discard block
 block discarded – undo
2183 2301
 			<dd>
2184 2302
 				<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2185 2303
 
2186
-	foreach ($incontext['supported_databases'] as $key => $db)
2187
-			echo '
2304
+	foreach ($incontext['supported_databases'] as $key => $db) {
2305
+				echo '
2188 2306
 					<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2307
+	}
2189 2308
 
2190 2309
 	echo '
2191 2310
 				</select>
2192 2311
 				<div class="smalltext">', $txt['db_settings_type_info'], '</div>
2193 2312
 			</dd>';
2194
-	}
2195
-	else
2313
+	} else
2196 2314
 	{
2197 2315
 		echo '
2198 2316
 			<dd>
@@ -2360,9 +2478,10 @@  discard block
 block discarded – undo
2360 2478
 		<div class="red">', $txt['error_db_queries'], '</div>
2361 2479
 		<ul>';
2362 2480
 
2363
-		foreach ($incontext['failures'] as $line => $fail)
2364
-			echo '
2481
+		foreach ($incontext['failures'] as $line => $fail) {
2482
+					echo '
2365 2483
 			<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2484
+		}
2366 2485
 
2367 2486
 		echo '
2368 2487
 		</ul>';
@@ -2427,15 +2546,16 @@  discard block
 block discarded – undo
2427 2546
 			</dd>
2428 2547
 		</dl>';
2429 2548
 
2430
-	if ($incontext['require_db_confirm'])
2431
-		echo '
2549
+	if ($incontext['require_db_confirm']) {
2550
+			echo '
2432 2551
 		<h2>', $txt['user_settings_database'], '</h2>
2433 2552
 		<p>', $txt['user_settings_database_info'], '</p>
2434 2553
 
2435 2554
 		<div class="lefttext">
2436 2555
 			<input type="password" name="password3" size="30">
2437 2556
 		</div>';
2438
-}
2557
+	}
2558
+	}
2439 2559
 
2440 2560
 // Tell them it's done, and to delete.
2441 2561
 function template_delete_install()
@@ -2448,13 +2568,14 @@  discard block
 block discarded – undo
2448 2568
 	template_warning_divs();
2449 2569
 
2450 2570
 	// Install directory still writable?
2451
-	if ($incontext['dir_still_writable'])
2452
-		echo '
2571
+	if ($incontext['dir_still_writable']) {
2572
+			echo '
2453 2573
 		<p><em>', $txt['still_writable'], '</em></p>';
2574
+	}
2454 2575
 
2455 2576
 	// Don't show the box if it's like 99% sure it won't work :P.
2456
-	if ($incontext['probably_delete_install'])
2457
-		echo '
2577
+	if ($incontext['probably_delete_install']) {
2578
+			echo '
2458 2579
 		<label>
2459 2580
 			<input type="checkbox" id="delete_self" onclick="doTheDelete();">
2460 2581
 			<strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong>
@@ -2470,6 +2591,7 @@  discard block
 block discarded – undo
2470 2591
 				theCheck.disabled = true;
2471 2592
 			}
2472 2593
 		</script>';
2594
+	}
2473 2595
 
2474 2596
 	echo '
2475 2597
 		<p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p>
Please login to merge, or discard this patch.
Sources/Subs-Members.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 		'member_name' => $regOptions['username'],
587 587
 		'email_address' => $regOptions['email'],
588 588
 		'passwd' => hash_password($regOptions['username'], $regOptions['password']),
589
-		'password_salt' => substr(md5(random_int(0, PHP_INT_MAX)), 0, 4) ,
589
+		'password_salt' => substr(md5(random_int(0, PHP_INT_MAX)), 0, 4),
590 590
 		'posts' => 0,
591 591
 		'date_registered' => time(),
592 592
 		'member_ip' => $regOptions['interface'] == 'admin' ? '127.0.0.1' : $user_info['ip'],
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 		'time_offset',
677 677
 	);
678 678
 	$knownInets = array(
679
-		'member_ip','member_ip2',
679
+		'member_ip', 'member_ip2',
680 680
 	);
681 681
 
682 682
 	// Call an optional function to validate the users' input.
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
 	$checkName = strtr($name, array('_' => '\\_', '%' => '\\%'));
905 905
 
906 906
 	//when we got no wildcard we can use equal -> fast
907
-	$operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '=' );
907
+	$operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '=');
908 908
 
909 909
 	// Make sure they don't want someone else's name.
910 910
 	$request = $smcFunc['db_query']('', '
@@ -1273,7 +1273,7 @@  discard block
 block discarded – undo
1273 1273
 		$user_info['buddies'][] = $userReceiver;
1274 1274
 
1275 1275
 		// And add a nice alert. Don't abuse though!
1276
-		if ((cache_get_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, 86400)) == null)
1276
+		if ((cache_get_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, 86400)) == null)
1277 1277
 		{
1278 1278
 			$smcFunc['db_insert']('insert',
1279 1279
 				'{db_prefix}background_tasks',
@@ -1288,7 +1288,7 @@  discard block
 block discarded – undo
1288 1288
 			);
1289 1289
 
1290 1290
 			// Store this in a cache entry to avoid creating multiple alerts. Give it a long life cycle.
1291
-			cache_put_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, '1', 86400);
1291
+			cache_put_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, '1', 86400);
1292 1292
 		}
1293 1293
 	}
1294 1294
 
Please login to merge, or discard this patch.
Sources/ShowAttachments.php 1 patch
Braces   +59 added lines, -52 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
  * Downloads an avatar or attachment based on $_GET['attach'], and increments the download count.
@@ -40,11 +41,11 @@  discard block
 block discarded – undo
40 41
 
41 42
 	if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0)
42 43
 	{
43
-		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler')
44
-			$modSettings['enableCompressedOutput'] = 0;
45
-
46
-		else
47
-			ob_start('ob_gzhandler');
44
+		if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler') {
45
+					$modSettings['enableCompressedOutput'] = 0;
46
+		} else {
47
+					ob_start('ob_gzhandler');
48
+		}
48 49
 	}
49 50
 
50 51
 	if (empty($modSettings['enableCompressedOutput']))
@@ -76,8 +77,9 @@  discard block
 block discarded – undo
76 77
 	}
77 78
 
78 79
 	// Use cache when possible.
79
-	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null)
80
-		list($file, $thumbFile) = $cache;
80
+	if (($cache = cache_get_data('attachment_lookup_id-' . $attachId)) != null) {
81
+			list($file, $thumbFile) = $cache;
82
+	}
81 83
 
82 84
 	// Get the info from the DB.
83 85
 	if (empty($file) || empty($thumbFile) && !empty($file['id_thumb']))
@@ -85,10 +87,9 @@  discard block
 block discarded – undo
85 87
 		// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
86 88
 		$attachRequest = null;
87 89
 		call_integration_hook('integrate_download_request', array(&$attachRequest));
88
-		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
89
-			$request = $attachRequest;
90
-
91
-		else
90
+		if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
91
+					$request = $attachRequest;
92
+		} else
92 93
 		{
93 94
 			// Make sure this attachment is on this board and load its info while we are at it.
94 95
 			$request = $smcFunc['db_query']('', '
@@ -181,13 +182,15 @@  discard block
 block discarded – undo
181 182
 		}
182 183
 
183 184
 		// Cache it.
184
-		if (!empty($file) || !empty($thumbFile))
185
-			cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), random_int(850, 900));
185
+		if (!empty($file) || !empty($thumbFile)) {
186
+					cache_put_data('attachment_lookup_id-' . $file['id_attach'], array($file, $thumbFile), random_int(850, 900));
187
+		}
186 188
 	}
187 189
 
188 190
 	// Replace the normal file with its thumbnail if it has one!
189
-	if (!empty($showThumb) && !empty($thumbFile))
190
-		$file = $thumbFile;
191
+	if (!empty($showThumb) && !empty($thumbFile)) {
192
+			$file = $thumbFile;
193
+	}
191 194
 
192 195
 	// No point in a nicer message, because this is supposed to be an attachment anyway...
193 196
 	if (!file_exists($file['filePath']))
@@ -237,8 +240,8 @@  discard block
 block discarded – undo
237 240
 	}
238 241
 
239 242
 	// Update the download counter (unless it's a thumbnail or resuming an incomplete download).
240
-	if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0)
241
-		$smcFunc['db_query']('', '
243
+	if ($file['attachment_type'] != 3 && empty($showThumb) && $range === 0) {
244
+			$smcFunc['db_query']('', '
242 245
 			UPDATE {db_prefix}attachments
243 246
 			SET downloads = downloads + 1
244 247
 			WHERE id_attach = {int:id_attach}',
@@ -246,12 +249,14 @@  discard block
 block discarded – undo
246 249
 				'id_attach' => $attachId,
247 250
 			)
248 251
 		);
252
+	}
249 253
 
250 254
 	// Send the attachment headers.
251 255
 	header('pragma: ');
252 256
 
253
-	if (!isBrowser('gecko'))
254
-		header('content-transfer-encoding: binary');
257
+	if (!isBrowser('gecko')) {
258
+			header('content-transfer-encoding: binary');
259
+	}
255 260
 
256 261
 	header('expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
257 262
 	header('last-modified: ' . gmdate('D, d M Y H:i:s', filemtime($file['filePath'])) . ' GMT');
@@ -260,18 +265,19 @@  discard block
 block discarded – undo
260 265
 	header('etag: ' . $eTag);
261 266
 
262 267
 	// Make sure the mime type warrants an inline display.
263
-	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0)
264
-		unset($_REQUEST['image']);
268
+	if (isset($_REQUEST['image']) && !empty($file['mime_type']) && strpos($file['mime_type'], 'image/') !== 0) {
269
+			unset($_REQUEST['image']);
270
+	}
265 271
 
266 272
 	// Does this have a mime type?
267
-	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
268
-		header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
269
-
270
-	else
273
+	elseif (!empty($file['mime_type']) && (isset($_REQUEST['image']) || !in_array($file['fileext'], array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
274
+			header('content-type: ' . strtr($file['mime_type'], array('image/bmp' => 'image/x-ms-bmp')));
275
+	} else
271 276
 	{
272 277
 		header('content-type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
273
-		if (isset($_REQUEST['image']))
274
-			unset($_REQUEST['image']);
278
+		if (isset($_REQUEST['image'])) {
279
+					unset($_REQUEST['image']);
280
+		}
275 281
 	}
276 282
 
277 283
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -279,24 +285,22 @@  discard block
 block discarded – undo
279 285
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
280 286
 
281 287
 	// Different browsers like different standards...
282
-	if (isBrowser('firefox'))
283
-		header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
284
-
285
-	elseif (isBrowser('opera'))
286
-		header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
287
-
288
-	elseif (isBrowser('ie'))
289
-		header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
290
-
291
-	else
292
-		header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"');
288
+	if (isBrowser('firefox')) {
289
+			header('content-disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
290
+	} elseif (isBrowser('opera')) {
291
+			header('content-disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
292
+	} elseif (isBrowser('ie')) {
293
+			header('content-disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
294
+	} else {
295
+			header('content-disposition: ' . $disposition . '; filename="' . $utf8name . '"');
296
+	}
293 297
 
294 298
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
295
-	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
296
-		header('cache-control: no-cache');
297
-
298
-	else
299
-		header('cache-control: max-age=' . (525600 * 60) . ', private');
299
+	if (!isset($_REQUEST['image']) && in_array($file['fileext'], array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
300
+			header('cache-control: no-cache');
301
+	} else {
302
+			header('cache-control: max-age=' . (525600 * 60) . ', private');
303
+	}
300 304
 
301 305
 	// Multipart and resuming support
302 306
 	if (isset($_SERVER['HTTP_RANGE']))
@@ -304,9 +308,9 @@  discard block
 block discarded – undo
304 308
 		send_http_status(206);
305 309
 		header("content-length: $new_length");
306 310
 		header("content-range: bytes $range-$range_end/$size");
311
+	} else {
312
+			header("content-length: " . $size);
307 313
 	}
308
-	else
309
-		header("content-length: " . $size);
310 314
 
311 315
 
312 316
 	// Try to buy some time...
@@ -315,8 +319,9 @@  discard block
 block discarded – undo
315 319
 	// For multipart/resumable downloads, send the requested chunk(s) of the file
316 320
 	if (isset($_SERVER['HTTP_RANGE']))
317 321
 	{
318
-		while (@ob_get_level() > 0)
319
-			@ob_end_clean();
322
+		while (@ob_get_level() > 0) {
323
+					@ob_end_clean();
324
+		}
320 325
 
321 326
 		// 40 kilobytes is a good-ish amount
322 327
 		$chunksize = 40 * 1024;
@@ -340,8 +345,9 @@  discard block
 block discarded – undo
340 345
 	elseif ($size > 4194304)
341 346
 	{
342 347
 		// Forcibly end any output buffering going on.
343
-		while (@ob_get_level() > 0)
344
-			@ob_end_clean();
348
+		while (@ob_get_level() > 0) {
349
+					@ob_end_clean();
350
+		}
345 351
 
346 352
 		$fp = fopen($file['filePath'], 'rb');
347 353
 		while (!feof($fp))
@@ -353,8 +359,9 @@  discard block
 block discarded – undo
353 359
 	}
354 360
 
355 361
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
356
-	elseif (@readfile($file['filePath']) === null)
357
-		echo file_get_contents($file['filePath']);
362
+	elseif (@readfile($file['filePath']) === null) {
363
+			echo file_get_contents($file['filePath']);
364
+	}
358 365
 
359 366
 	die();
360 367
 }
Please login to merge, or discard this patch.
Sources/Subs-Sound.php 1 patch
Braces   +32 added lines, -20 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
  * Creates a wave file that spells the letters of $word.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $settings, $user_info;
33 34
 
34 35
 	// Allow max 2 requests per 20 seconds.
35
-	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2)
36
-		die(send_http_status(400));
36
+	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) {
37
+			die(send_http_status(400));
38
+	}
37 39
 	cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20);
38 40
 	cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20);
39 41
 
@@ -42,16 +44,19 @@  discard block
 block discarded – undo
42 44
 	mt_srand(end($tmp));
43 45
 
44 46
 	// Try to see if there's a sound font in the user's language.
45
-	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav'))
46
-		$sound_language = $user_info['language'];
47
+	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) {
48
+			$sound_language = $user_info['language'];
49
+	}
47 50
 
48 51
 	// English should be there.
49
-	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav'))
50
-		$sound_language = 'english';
52
+	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) {
53
+			$sound_language = 'english';
54
+	}
51 55
 
52 56
 	// Guess not...
53
-	else
54
-		return false;
57
+	else {
58
+			return false;
59
+	}
55 60
 
56 61
 	// File names are in lower case so lets make sure that we are only using a lower case string
57 62
 	$word = strtolower($word);
@@ -61,20 +66,25 @@  discard block
 block discarded – undo
61 66
 	for ($i = 0; $i < strlen($word); $i++)
62 67
 	{
63 68
 		$sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav'));
64
-		if (strpos($sound_letter, 'data') === false)
65
-			return false;
69
+		if (strpos($sound_letter, 'data') === false) {
70
+					return false;
71
+		}
66 72
 
67 73
 		$sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8);
68 74
 		switch ($word{$i} === 's' ? 0 : random_int(0, 2))
69 75
 		{
70
-			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
71
-					for ($k = 0, $m = round(random_int(15, 25) / 10); $k < $m; $k++)
72
-						$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(random_int(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
76
+			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) {
77
+								for ($k = 0, $m = round(random_int(15, 25) / 10);
78
+			}
79
+			$k < $m; $k++) {
80
+											$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(random_int(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
81
+					}
73 82
 			break;
74 83
 
75 84
 			case 1:
76
-				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2)
77
-					$sound_word .= (random_int(0, 3) == 0 ? '' : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (random_int(0, 3) == 0 ? $sound_letter{$j + 1} : '');
85
+				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) {
86
+									$sound_word .= (random_int(0, 3) == 0 ? '' : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (random_int(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (random_int(0, 3) == 0 ? $sound_letter{$j + 1} : '');
87
+				}
78 88
 				$sound_word .= str_repeat($sound_letter{$n}, 2);
79 89
 			break;
80 90
 
@@ -82,10 +92,12 @@  discard block
 block discarded – undo
82 92
 				$shift = 0;
83 93
 				for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
84 94
 				{
85
-					if (random_int(0, 10) === 0)
86
-						$shift += random_int(-3, 3);
87
-					for ($k = 0, $m = round(random_int(15, 25) / 10); $k < $m; $k++)
88
-						$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
95
+					if (random_int(0, 10) === 0) {
96
+											$shift += random_int(-3, 3);
97
+					}
98
+					for ($k = 0, $m = round(random_int(15, 25) / 10); $k < $m; $k++) {
99
+											$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
100
+					}
89 101
 				}
90 102
 			break;
91 103
 		}
Please login to merge, or discard this patch.
Sources/random_compat/random_int.php 1 patch
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -1,204 +1,204 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (!is_callable('random_int')) {
4
-    /**
5
-     * Random_* Compatibility Library
6
-     * for using the new PHP 7 random_* API in PHP 5 projects
7
-     *
8
-     * The MIT License (MIT)
9
-     *
10
-     * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
11
-     *
12
-     * Permission is hereby granted, free of charge, to any person obtaining a copy
13
-     * of this software and associated documentation files (the "Software"), to deal
14
-     * in the Software without restriction, including without limitation the rights
15
-     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
-     * copies of the Software, and to permit persons to whom the Software is
17
-     * furnished to do so, subject to the following conditions:
18
-     *
19
-     * The above copyright notice and this permission notice shall be included in
20
-     * all copies or substantial portions of the Software.
21
-     *
22
-     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
-     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
-     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
-     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
-     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
-     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
-     * SOFTWARE.
29
-     */
30
-
31
-    /**
32
-     * Fetch a random integer between $min and $max inclusive
33
-     *
34
-     * @param int $min
35
-     * @param int $max
36
-     *
37
-     * @throws Exception
38
-     *
39
-     * @return int
40
-     */
41
-    function random_int($min, $max)
42
-    {
43
-        /**
44
-         * Type and input logic checks
45
-         *
46
-         * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX)
47
-         * (non-inclusive), it will sanely cast it to an int. If you it's equal to
48
-         * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats
49
-         * lose precision, so the <= and => operators might accidentally let a float
50
-         * through.
51
-         */
52
-
53
-        try {
54
-            /** @var int $min */
55
-            $min = RandomCompat_intval($min);
56
-        } catch (TypeError $ex) {
57
-            throw new TypeError(
58
-                'random_int(): $min must be an integer'
59
-            );
60
-        }
61
-
62
-        try {
63
-            /** @var int $max */
64
-            $max = RandomCompat_intval($max);
65
-        } catch (TypeError $ex) {
66
-            throw new TypeError(
67
-                'random_int(): $max must be an integer'
68
-            );
69
-        }
70
-
71
-        /**
72
-         * Now that we've verified our weak typing system has given us an integer,
73
-         * let's validate the logic then we can move forward with generating random
74
-         * integers along a given range.
75
-         */
76
-        if ($min > $max) {
77
-            throw new Error(
78
-                'Minimum value must be less than or equal to the maximum value'
79
-            );
80
-        }
81
-
82
-        if ($max === $min) {
83
-            return (int) $min;
84
-        }
85
-
86
-        /**
87
-         * Initialize variables to 0
88
-         *
89
-         * We want to store:
90
-         * $bytes => the number of random bytes we need
91
-         * $mask => an integer bitmask (for use with the &) operator
92
-         *          so we can minimize the number of discards
93
-         */
94
-        $attempts = $bits = $bytes = $mask = $valueShift = 0;
95
-        /** @var int $attempts */
96
-        /** @var int $bits */
97
-        /** @var int $bytes */
98
-        /** @var int $mask */
99
-        /** @var int $valueShift */
100
-
101
-        /**
102
-         * At this point, $range is a positive number greater than 0. It might
103
-         * overflow, however, if $max - $min > PHP_INT_MAX. PHP will cast it to
104
-         * a float and we will lose some precision.
105
-         *
106
-         * @var int|float $range
107
-         */
108
-        $range = $max - $min;
109
-
110
-        /**
111
-         * Test for integer overflow:
112
-         */
113
-        if (!is_int($range)) {
114
-
115
-            /**
116
-             * Still safely calculate wider ranges.
117
-             * Provided by @CodesInChaos, @oittaa
118
-             *
119
-             * @ref https://gist.github.com/CodesInChaos/03f9ea0b58e8b2b8d435
120
-             *
121
-             * We use ~0 as a mask in this case because it generates all 1s
122
-             *
123
-             * @ref https://eval.in/400356 (32-bit)
124
-             * @ref http://3v4l.org/XX9r5  (64-bit)
125
-             */
126
-            $bytes = PHP_INT_SIZE;
127
-            /** @var int $mask */
128
-            $mask = ~0;
129
-
130
-        } else {
131
-
132
-            /**
133
-             * $bits is effectively ceil(log($range, 2)) without dealing with
134
-             * type juggling
135
-             */
136
-            while ($range > 0) {
137
-                if ($bits % 8 === 0) {
138
-                    ++$bytes;
139
-                }
140
-                ++$bits;
141
-                $range >>= 1;
142
-                /** @var int $mask */
143
-                $mask = $mask << 1 | 1;
144
-            }
145
-            $valueShift = $min;
146
-        }
147
-
148
-        /** @var int $val */
149
-        $val = 0;
150
-        /**
151
-         * Now that we have our parameters set up, let's begin generating
152
-         * random integers until one falls between $min and $max
153
-         */
154
-        /** @psalm-suppress RedundantCondition */
155
-        do {
156
-            /**
157
-             * The rejection probability is at most 0.5, so this corresponds
158
-             * to a failure probability of 2^-128 for a working RNG
159
-             */
160
-            if ($attempts > 128) {
161
-                throw new Exception(
162
-                    'random_int: RNG is broken - too many rejections'
163
-                );
164
-            }
165
-
166
-            /**
167
-             * Let's grab the necessary number of random bytes
168
-             */
169
-            $randomByteString = random_bytes($bytes);
170
-
171
-            /**
172
-             * Let's turn $randomByteString into an integer
173
-             *
174
-             * This uses bitwise operators (<< and |) to build an integer
175
-             * out of the values extracted from ord()
176
-             *
177
-             * Example: [9F] | [6D] | [32] | [0C] =>
178
-             *   159 + 27904 + 3276800 + 201326592 =>
179
-             *   204631455
180
-             */
181
-            $val &= 0;
182
-            for ($i = 0; $i < $bytes; ++$i) {
183
-                $val |= ord($randomByteString[$i]) << ($i * 8);
184
-            }
185
-            /** @var int $val */
186
-
187
-            /**
188
-             * Apply mask
189
-             */
190
-            $val &= $mask;
191
-            $val += $valueShift;
192
-
193
-            ++$attempts;
194
-            /**
195
-             * If $val overflows to a floating point number,
196
-             * ... or is larger than $max,
197
-             * ... or smaller than $min,
198
-             * then try again.
199
-             */
200
-        } while (!is_int($val) || $val > $max || $val < $min);
201
-
202
-        return (int) $val;
203
-    }
4
+	/**
5
+	 * Random_* Compatibility Library
6
+	 * for using the new PHP 7 random_* API in PHP 5 projects
7
+	 *
8
+	 * The MIT License (MIT)
9
+	 *
10
+	 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
11
+	 *
12
+	 * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+	 * of this software and associated documentation files (the "Software"), to deal
14
+	 * in the Software without restriction, including without limitation the rights
15
+	 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+	 * copies of the Software, and to permit persons to whom the Software is
17
+	 * furnished to do so, subject to the following conditions:
18
+	 *
19
+	 * The above copyright notice and this permission notice shall be included in
20
+	 * all copies or substantial portions of the Software.
21
+	 *
22
+	 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+	 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+	 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+	 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+	 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+	 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+	 * SOFTWARE.
29
+	 */
30
+
31
+	/**
32
+	 * Fetch a random integer between $min and $max inclusive
33
+	 *
34
+	 * @param int $min
35
+	 * @param int $max
36
+	 *
37
+	 * @throws Exception
38
+	 *
39
+	 * @return int
40
+	 */
41
+	function random_int($min, $max)
42
+	{
43
+		/**
44
+		 * Type and input logic checks
45
+		 *
46
+		 * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX)
47
+		 * (non-inclusive), it will sanely cast it to an int. If you it's equal to
48
+		 * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats
49
+		 * lose precision, so the <= and => operators might accidentally let a float
50
+		 * through.
51
+		 */
52
+
53
+		try {
54
+			/** @var int $min */
55
+			$min = RandomCompat_intval($min);
56
+		} catch (TypeError $ex) {
57
+			throw new TypeError(
58
+				'random_int(): $min must be an integer'
59
+			);
60
+		}
61
+
62
+		try {
63
+			/** @var int $max */
64
+			$max = RandomCompat_intval($max);
65
+		} catch (TypeError $ex) {
66
+			throw new TypeError(
67
+				'random_int(): $max must be an integer'
68
+			);
69
+		}
70
+
71
+		/**
72
+		 * Now that we've verified our weak typing system has given us an integer,
73
+		 * let's validate the logic then we can move forward with generating random
74
+		 * integers along a given range.
75
+		 */
76
+		if ($min > $max) {
77
+			throw new Error(
78
+				'Minimum value must be less than or equal to the maximum value'
79
+			);
80
+		}
81
+
82
+		if ($max === $min) {
83
+			return (int) $min;
84
+		}
85
+
86
+		/**
87
+		 * Initialize variables to 0
88
+		 *
89
+		 * We want to store:
90
+		 * $bytes => the number of random bytes we need
91
+		 * $mask => an integer bitmask (for use with the &) operator
92
+		 *          so we can minimize the number of discards
93
+		 */
94
+		$attempts = $bits = $bytes = $mask = $valueShift = 0;
95
+		/** @var int $attempts */
96
+		/** @var int $bits */
97
+		/** @var int $bytes */
98
+		/** @var int $mask */
99
+		/** @var int $valueShift */
100
+
101
+		/**
102
+		 * At this point, $range is a positive number greater than 0. It might
103
+		 * overflow, however, if $max - $min > PHP_INT_MAX. PHP will cast it to
104
+		 * a float and we will lose some precision.
105
+		 *
106
+		 * @var int|float $range
107
+		 */
108
+		$range = $max - $min;
109
+
110
+		/**
111
+		 * Test for integer overflow:
112
+		 */
113
+		if (!is_int($range)) {
114
+
115
+			/**
116
+			 * Still safely calculate wider ranges.
117
+			 * Provided by @CodesInChaos, @oittaa
118
+			 *
119
+			 * @ref https://gist.github.com/CodesInChaos/03f9ea0b58e8b2b8d435
120
+			 *
121
+			 * We use ~0 as a mask in this case because it generates all 1s
122
+			 *
123
+			 * @ref https://eval.in/400356 (32-bit)
124
+			 * @ref http://3v4l.org/XX9r5  (64-bit)
125
+			 */
126
+			$bytes = PHP_INT_SIZE;
127
+			/** @var int $mask */
128
+			$mask = ~0;
129
+
130
+		} else {
131
+
132
+			/**
133
+			 * $bits is effectively ceil(log($range, 2)) without dealing with
134
+			 * type juggling
135
+			 */
136
+			while ($range > 0) {
137
+				if ($bits % 8 === 0) {
138
+					++$bytes;
139
+				}
140
+				++$bits;
141
+				$range >>= 1;
142
+				/** @var int $mask */
143
+				$mask = $mask << 1 | 1;
144
+			}
145
+			$valueShift = $min;
146
+		}
147
+
148
+		/** @var int $val */
149
+		$val = 0;
150
+		/**
151
+		 * Now that we have our parameters set up, let's begin generating
152
+		 * random integers until one falls between $min and $max
153
+		 */
154
+		/** @psalm-suppress RedundantCondition */
155
+		do {
156
+			/**
157
+			 * The rejection probability is at most 0.5, so this corresponds
158
+			 * to a failure probability of 2^-128 for a working RNG
159
+			 */
160
+			if ($attempts > 128) {
161
+				throw new Exception(
162
+					'random_int: RNG is broken - too many rejections'
163
+				);
164
+			}
165
+
166
+			/**
167
+			 * Let's grab the necessary number of random bytes
168
+			 */
169
+			$randomByteString = random_bytes($bytes);
170
+
171
+			/**
172
+			 * Let's turn $randomByteString into an integer
173
+			 *
174
+			 * This uses bitwise operators (<< and |) to build an integer
175
+			 * out of the values extracted from ord()
176
+			 *
177
+			 * Example: [9F] | [6D] | [32] | [0C] =>
178
+			 *   159 + 27904 + 3276800 + 201326592 =>
179
+			 *   204631455
180
+			 */
181
+			$val &= 0;
182
+			for ($i = 0; $i < $bytes; ++$i) {
183
+				$val |= ord($randomByteString[$i]) << ($i * 8);
184
+			}
185
+			/** @var int $val */
186
+
187
+			/**
188
+			 * Apply mask
189
+			 */
190
+			$val &= $mask;
191
+			$val += $valueShift;
192
+
193
+			++$attempts;
194
+			/**
195
+			 * If $val overflows to a floating point number,
196
+			 * ... or is larger than $max,
197
+			 * ... or smaller than $min,
198
+			 * then try again.
199
+			 */
200
+		} while (!is_int($val) || $val > $max || $val < $min);
201
+
202
+		return (int) $val;
203
+	}
204 204
 }
Please login to merge, or discard this patch.
Sources/Subs-Graphics.php 1 patch
Braces   +240 added lines, -196 removed lines patch added patch discarded remove patch
@@ -18,8 +18,9 @@  discard block
 block discarded – undo
18 18
  * @version 2.1 Beta 4
19 19
  */
20 20
 
21
-if (!defined('SMF'))
21
+if (!defined('SMF')) {
22 22
 	die('No direct access...');
23
+}
23 24
 
24 25
 /**
25 26
  * downloads a file from a url and stores it locally for avatar use by id_member.
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$destName = 'avatar_' . $memID . '_' . time() . '.' . $ext;
45 46
 
46 47
 	// Just making sure there is a non-zero member.
47
-	if (empty($memID))
48
-		return false;
48
+	if (empty($memID)) {
49
+			return false;
50
+	}
49 51
 
50 52
 	require_once($sourcedir . '/ManageAttachments.php');
51 53
 	removeAttachments(array('id_member' => $memID));
@@ -76,10 +78,11 @@  discard block
 block discarded – undo
76 78
 	$destName = $modSettings['custom_avatar_dir'] . '/' . $destName . '.tmp';
77 79
 
78 80
 	// Resize it.
79
-	if (!empty($modSettings['avatar_download_png']))
80
-		$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
81
-	else
82
-		$success = resizeImageFile($url, $destName, $max_width, $max_height);
81
+	if (!empty($modSettings['avatar_download_png'])) {
82
+			$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
83
+	} else {
84
+			$success = resizeImageFile($url, $destName, $max_width, $max_height);
85
+	}
83 86
 
84 87
 	// Remove the .tmp extension.
85 88
 	$destName = substr($destName, 0, -4);
@@ -108,11 +111,10 @@  discard block
 block discarded – undo
108 111
 				)
109 112
 			);
110 113
 			return true;
114
+		} else {
115
+					return false;
111 116
 		}
112
-		else
113
-			return false;
114
-	}
115
-	else
117
+	} else
116 118
 	{
117 119
 		$smcFunc['db_query']('', '
118 120
 			DELETE FROM {db_prefix}attachments
@@ -144,17 +146,18 @@  discard block
 block discarded – undo
144 146
 	$destName = $source . '_thumb.tmp';
145 147
 
146 148
 	// Do the actual resize.
147
-	if (!empty($modSettings['attachment_thumb_png']))
148
-		$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
149
-	else
150
-		$success = resizeImageFile($source, $destName, $max_width, $max_height);
149
+	if (!empty($modSettings['attachment_thumb_png'])) {
150
+			$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
151
+	} else {
152
+			$success = resizeImageFile($source, $destName, $max_width, $max_height);
153
+	}
151 154
 
152 155
 	// Okay, we're done with the temporary stuff.
153 156
 	$destName = substr($destName, 0, -4);
154 157
 
155
-	if ($success && @rename($destName . '.tmp', $destName))
156
-		return true;
157
-	else
158
+	if ($success && @rename($destName . '.tmp', $destName)) {
159
+			return true;
160
+	} else
158 161
 	{
159 162
 		@unlink($destName . '.tmp');
160 163
 		@touch($destName);
@@ -176,18 +179,21 @@  discard block
 block discarded – undo
176 179
 {
177 180
 	if (!resizeImageFile($fileName, $fileName . '.tmp', null, null, $preferred_format))
178 181
 	{
179
-		if (file_exists($fileName . '.tmp'))
180
-			unlink($fileName . '.tmp');
182
+		if (file_exists($fileName . '.tmp')) {
183
+					unlink($fileName . '.tmp');
184
+		}
181 185
 
182 186
 		return false;
183 187
 	}
184 188
 
185
-	if (!unlink($fileName))
186
-		return false;
189
+	if (!unlink($fileName)) {
190
+			return false;
191
+	}
187 192
 
188
-	if (!rename($fileName . '.tmp', $fileName))
189
-		return false;
190
-}
193
+	if (!rename($fileName . '.tmp', $fileName)) {
194
+			return false;
195
+	}
196
+	}
191 197
 
192 198
 /**
193 199
  * Searches through the file to see if there's potentially harmful non-binary content.
@@ -200,8 +206,9 @@  discard block
 block discarded – undo
200 206
 function checkImageContents($fileName, $extensiveCheck = false)
201 207
 {
202 208
 	$fp = fopen($fileName, 'rb');
203
-	if (!$fp)
204
-		fatal_lang_error('attach_timeout');
209
+	if (!$fp) {
210
+			fatal_lang_error('attach_timeout');
211
+	}
205 212
 
206 213
 	$prev_chunk = '';
207 214
 	while (!feof($fp))
@@ -218,8 +225,7 @@  discard block
 block discarded – undo
218 225
 				fclose($fp);
219 226
 				return false;
220 227
 			}
221
-		}
222
-		else
228
+		} else
223 229
 		{
224 230
 			// Check for potential infection - focus on clues for inline php & flash.
225 231
 			// Will result in significantly fewer false positives than the paranoid check.
@@ -247,8 +253,9 @@  discard block
 block discarded – undo
247 253
 	global $gd2;
248 254
 
249 255
 	// Check to see if GD is installed and what version.
250
-	if (($extensionFunctions = get_extension_funcs('gd')) === false)
251
-		return false;
256
+	if (($extensionFunctions = get_extension_funcs('gd')) === false) {
257
+			return false;
258
+	}
252 259
 
253 260
 	// Also determine if GD2 is installed and store it in a global.
254 261
 	$gd2 = in_array('imagecreatetruecolor', $extensionFunctions) && function_exists('imagecreatetruecolor');
@@ -320,8 +327,9 @@  discard block
 block discarded – undo
320 327
 	global $sourcedir;
321 328
 
322 329
 	// Nothing to do without GD or IM/MW
323
-	if (!checkGD() && !checkImagick() && !checkMagickWand())
324
-		return false;
330
+	if (!checkGD() && !checkImagick() && !checkMagickWand()) {
331
+			return false;
332
+	}
325 333
 
326 334
 	static $default_formats = array(
327 335
 		'1' => 'gif',
@@ -341,38 +349,39 @@  discard block
 block discarded – undo
341 349
 		fclose($fp_destination);
342 350
 
343 351
 		$sizes = @getimagesize($destination);
344
-	}
345
-	elseif ($fp_destination)
352
+	} elseif ($fp_destination)
346 353
 	{
347 354
 		$sizes = @getimagesize($source);
348 355
 
349 356
 		$fp_source = fopen($source, 'rb');
350 357
 		if ($fp_source !== false)
351 358
 		{
352
-			while (!feof($fp_source))
353
-				fwrite($fp_destination, fread($fp_source, 8192));
359
+			while (!feof($fp_source)) {
360
+							fwrite($fp_destination, fread($fp_source, 8192));
361
+			}
354 362
 			fclose($fp_source);
363
+		} else {
364
+					$sizes = array(-1, -1, -1);
355 365
 		}
356
-		else
357
-			$sizes = array(-1, -1, -1);
358 366
 		fclose($fp_destination);
359 367
 	}
360 368
 	// We can't get to the file.
361
-	else
362
-		$sizes = array(-1, -1, -1);
369
+	else {
370
+			$sizes = array(-1, -1, -1);
371
+	}
363 372
 
364 373
 	// See if we have -or- can get the needed memory for this operation
365 374
 	// ImageMagick isn't subject to PHP's memory limits :)
366
-	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes))
367
-		return false;
375
+	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) {
376
+			return false;
377
+	}
368 378
 
369 379
 	// A known and supported format?
370 380
 	// @todo test PSD and gif.
371 381
 	if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]]))
372 382
 	{
373 383
 		return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format);
374
-	}
375
-	elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
384
+	} elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
376 385
 	{
377 386
 		$imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
378 387
 		if ($src_img = @$imagecreatefrom($destination))
@@ -425,14 +434,14 @@  discard block
 block discarded – undo
425 434
 			$dest_width = empty($max_width) ? $src_width : $max_width;
426 435
 			$dest_height = empty($max_height) ? $src_height : $max_height;
427 436
 
428
-			if ($default_formats[$preferred_format] == 'jpeg')
429
-				$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
437
+			if ($default_formats[$preferred_format] == 'jpeg') {
438
+							$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
439
+			}
430 440
 
431 441
 			$imagick->setImageFormat($default_formats[$preferred_format]);
432 442
 			$imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true);
433 443
 			$success = $imagick->writeImage($destName);
434
-		}
435
-		else
444
+		} else
436 445
 		{
437 446
 			$magick_wand = newMagickWand();
438 447
 			MagickReadImage($magick_wand, $destName);
@@ -441,8 +450,9 @@  discard block
 block discarded – undo
441 450
 			$dest_width = empty($max_width) ? $src_width : $max_width;
442 451
 			$dest_height = empty($max_height) ? $src_height : $max_height;
443 452
 
444
-			if ($default_formats[$preferred_format] == 'jpeg')
445
-				MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
453
+			if ($default_formats[$preferred_format] == 'jpeg') {
454
+							MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
455
+			}
446 456
 
447 457
 			MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]);
448 458
 			MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true);
@@ -450,8 +460,7 @@  discard block
 block discarded – undo
450 460
 		}
451 461
 
452 462
 		return !empty($success);
453
-	}
454
-	elseif (checkGD())
463
+	} elseif (checkGD())
455 464
 	{
456 465
 		$success = false;
457 466
 
@@ -462,8 +471,7 @@  discard block
 block discarded – undo
462 471
 			{
463 472
 				$dst_width = $max_width;
464 473
 				$dst_height = round($src_height * $max_width / $src_width);
465
-			}
466
-			elseif (!empty($max_height))
474
+			} elseif (!empty($max_height))
467 475
 			{
468 476
 				$dst_width = round($src_width * $max_height / $src_height);
469 477
 				$dst_height = $max_height;
@@ -481,44 +489,48 @@  discard block
 block discarded – undo
481 489
 					if ((!empty($preferred_format)) && ($preferred_format == 3))
482 490
 					{
483 491
 						imagealphablending($dst_img, false);
484
-						if (function_exists('imagesavealpha'))
485
-							imagesavealpha($dst_img, true);
492
+						if (function_exists('imagesavealpha')) {
493
+													imagesavealpha($dst_img, true);
494
+						}
486 495
 					}
496
+				} else {
497
+									$dst_img = imagecreate($dst_width, $dst_height);
487 498
 				}
488
-				else
489
-					$dst_img = imagecreate($dst_width, $dst_height);
490 499
 
491 500
 				// Resize it!
492
-				if ($gd2)
493
-					imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
494
-				else
495
-					imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
501
+				if ($gd2) {
502
+									imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
503
+				} else {
504
+									imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
505
+				}
506
+			} else {
507
+							$dst_img = $src_img;
496 508
 			}
497
-			else
498
-				$dst_img = $src_img;
509
+		} else {
510
+					$dst_img = $src_img;
499 511
 		}
500
-		else
501
-			$dst_img = $src_img;
502 512
 
503 513
 		// Save the image as ...
504
-		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng'))
505
-			$success = imagepng($dst_img, $destName);
506
-		elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif'))
507
-			$success = imagegif($dst_img, $destName);
508
-		elseif (function_exists('imagejpeg'))
509
-			$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
514
+		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) {
515
+					$success = imagepng($dst_img, $destName);
516
+		} elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) {
517
+					$success = imagegif($dst_img, $destName);
518
+		} elseif (function_exists('imagejpeg')) {
519
+					$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
520
+		}
510 521
 
511 522
 		// Free the memory.
512 523
 		imagedestroy($src_img);
513
-		if ($dst_img != $src_img)
514
-			imagedestroy($dst_img);
524
+		if ($dst_img != $src_img) {
525
+					imagedestroy($dst_img);
526
+		}
515 527
 
516 528
 		return $success;
517
-	}
518
-	else
519
-		// Without GD, no image resizing at all.
529
+	} else {
530
+			// Without GD, no image resizing at all.
520 531
 		return false;
521
-}
532
+	}
533
+	}
522 534
 
523 535
 /**
524 536
  * Copy image.
@@ -572,8 +584,9 @@  discard block
 block discarded – undo
572 584
 			$color = imagecolorresolve($dst_img, $red, $green, $blue);
573 585
 			if ($color == -1)
574 586
 			{
575
-				if ($palsize++ < 256)
576
-					imagecolorallocate($dst_img, $red, $green, $blue);
587
+				if ($palsize++ < 256) {
588
+									imagecolorallocate($dst_img, $red, $green, $blue);
589
+				}
577 590
 				$color = imagecolorclosest($dst_img, $red, $green, $blue);
578 591
 			}
579 592
 
@@ -603,13 +616,15 @@  discard block
 block discarded – undo
603 616
 		$header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14));
604 617
 		$info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40));
605 618
 
606
-		if ($header['type'] != 0x4D42)
607
-			return false;
619
+		if ($header['type'] != 0x4D42) {
620
+					return false;
621
+		}
608 622
 
609
-		if ($gd2)
610
-			$dst_img = imagecreatetruecolor($info['width'], $info['height']);
611
-		else
612
-			$dst_img = imagecreate($info['width'], $info['height']);
623
+		if ($gd2) {
624
+					$dst_img = imagecreatetruecolor($info['width'], $info['height']);
625
+		} else {
626
+					$dst_img = imagecreate($info['width'], $info['height']);
627
+		}
613 628
 
614 629
 		$palette_size = $header['offset'] - 54;
615 630
 		$info['ncolor'] = $palette_size / 4;
@@ -635,8 +650,9 @@  discard block
 block discarded – undo
635 650
 			fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l);
636 651
 			$scan_line = fread($fp, $scan_line_size);
637 652
 
638
-			if (strlen($scan_line) < $scan_line_size)
639
-				continue;
653
+			if (strlen($scan_line) < $scan_line_size) {
654
+							continue;
655
+			}
640 656
 
641 657
 			if ($info['bits'] == 32)
642 658
 			{
@@ -654,14 +670,14 @@  discard block
 block discarded – undo
654 670
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
655 671
 
656 672
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
657
-						if ($color == -1)
658
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
673
+						if ($color == -1) {
674
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
675
+						}
659 676
 					}
660 677
 
661 678
 					imagesetpixel($dst_img, $x, $y, $color);
662 679
 				}
663
-			}
664
-			elseif ($info['bits'] == 24)
680
+			} elseif ($info['bits'] == 24)
665 681
 			{
666 682
 				$x = 0;
667 683
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -676,14 +692,14 @@  discard block
 block discarded – undo
676 692
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
677 693
 
678 694
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
679
-						if ($color == -1)
680
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
695
+						if ($color == -1) {
696
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
697
+						}
681 698
 					}
682 699
 
683 700
 					imagesetpixel($dst_img, $x, $y, $color);
684 701
 				}
685
-			}
686
-			elseif ($info['bits'] == 16)
702
+			} elseif ($info['bits'] == 16)
687 703
 			{
688 704
 				$x = 0;
689 705
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -704,20 +720,20 @@  discard block
 block discarded – undo
704 720
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
705 721
 
706 722
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
707
-						if ($color == -1)
708
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
723
+						if ($color == -1) {
724
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
725
+						}
709 726
 					}
710 727
 
711 728
 					imagesetpixel($dst_img, $x, $y, $color);
712 729
 				}
713
-			}
714
-			elseif ($info['bits'] == 8)
730
+			} elseif ($info['bits'] == 8)
715 731
 			{
716 732
 				$x = 0;
717
-				for ($j = 0; $j < $scan_line_size; $x++)
718
-					imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
719
-			}
720
-			elseif ($info['bits'] == 4)
733
+				for ($j = 0; $j < $scan_line_size; $x++) {
734
+									imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
735
+				}
736
+			} elseif ($info['bits'] == 4)
721 737
 			{
722 738
 				$x = 0;
723 739
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -726,11 +742,11 @@  discard block
 block discarded – undo
726 742
 
727 743
 					imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]);
728 744
 
729
-					if (++$x < $info['width'])
730
-						imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
745
+					if (++$x < $info['width']) {
746
+											imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
747
+					}
731 748
 				}
732
-			}
733
-			elseif ($info['bits'] == 1)
749
+			} elseif ($info['bits'] == 1)
734 750
 			{
735 751
 				$x = 0;
736 752
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -741,8 +757,9 @@  discard block
 block discarded – undo
741 757
 
742 758
 					for ($shift = 1; $shift < 8; $shift++)
743 759
 					{
744
-						if (++$x < $info['width'])
745
-							imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
760
+						if (++$x < $info['width']) {
761
+													imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
762
+						}
746 763
 					}
747 764
 				}
748 765
 			}
@@ -766,15 +783,18 @@  discard block
 block discarded – undo
766 783
  */
767 784
 function gif_outputAsPng($gif, $lpszFileName, $background_color = -1)
768 785
 {
769
-	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '')
770
-		return false;
786
+	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') {
787
+			return false;
788
+	}
771 789
 
772 790
 	$fd = $gif->get_png_data($background_color);
773
-	if (strlen($fd) <= 0)
774
-		return false;
791
+	if (strlen($fd) <= 0) {
792
+			return false;
793
+	}
775 794
 
776
-	if (!($fh = @fopen($lpszFileName, 'wb')))
777
-		return false;
795
+	if (!($fh = @fopen($lpszFileName, 'wb'))) {
796
+			return false;
797
+	}
778 798
 
779 799
 	@fwrite($fh, $fd, strlen($fd));
780 800
 	@fflush($fh);
@@ -801,8 +821,9 @@  discard block
 block discarded – undo
801 821
 	// What type are we going to be doing?
802 822
 	$imageType = $modSettings['visual_verification_type'];
803 823
 	// Special case to allow the admin center to show samples.
804
-	if ($user_info['is_admin'] && isset($_GET['type']))
805
-		$imageType = (int) $_GET['type'];
824
+	if ($user_info['is_admin'] && isset($_GET['type'])) {
825
+			$imageType = (int) $_GET['type'];
826
+	}
806 827
 
807 828
 	// Some quick references for what we do.
808 829
 	// Do we show no, low or high noise?
@@ -836,25 +857,28 @@  discard block
 block discarded – undo
836 857
 	$character_spacing = 1;
837 858
 
838 859
 	// What color is the background - generally white unless we're on "hard".
839
-	if ($simpleBGColor)
840
-		$background_color = array(255, 255, 255);
841
-	else
842
-		$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
860
+	if ($simpleBGColor) {
861
+			$background_color = array(255, 255, 255);
862
+	} else {
863
+			$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
864
+	}
843 865
 
844 866
 	// The color of the characters shown (red, green, blue).
845
-	if ($simpleFGColor)
846
-		$foreground_color = array(0, 0, 0);
847
-	else
867
+	if ($simpleFGColor) {
868
+			$foreground_color = array(0, 0, 0);
869
+	} else
848 870
 	{
849 871
 		$foreground_color = array(64, 101, 136);
850 872
 
851 873
 		// Has the theme author requested a custom color?
852
-		if (isset($settings['verification_foreground']))
853
-			$foreground_color = $settings['verification_foreground'];
874
+		if (isset($settings['verification_foreground'])) {
875
+					$foreground_color = $settings['verification_foreground'];
876
+		}
854 877
 	}
855 878
 
856
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
857
-		return false;
879
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
880
+			return false;
881
+	}
858 882
 
859 883
 	// Get a list of the available fonts.
860 884
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
@@ -865,25 +889,28 @@  discard block
 block discarded – undo
865 889
 	{
866 890
 		if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1)
867 891
 		{
868
-			if ($endian ^ (strpos($entry, '_end.gdf') === false))
869
-				$font_list[] = $entry;
892
+			if ($endian ^ (strpos($entry, '_end.gdf') === false)) {
893
+							$font_list[] = $entry;
894
+			}
895
+		} elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) {
896
+					$ttfont_list[] = $entry;
870 897
 		}
871
-		elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1)
872
-			$ttfont_list[] = $entry;
873 898
 	}
874 899
 
875
-	if (empty($font_list))
876
-		return false;
900
+	if (empty($font_list)) {
901
+			return false;
902
+	}
877 903
 
878 904
 	// For non-hard things don't even change fonts.
879 905
 	if (!$varyFonts)
880 906
 	{
881 907
 		$font_list = array($font_list[0]);
882 908
 		// Try use Screenge if we can - it looks good!
883
-		if (in_array('AnonymousPro.ttf', $ttfont_list))
884
-			$ttfont_list = array('AnonymousPro.ttf');
885
-		else
886
-			$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
909
+		if (in_array('AnonymousPro.ttf', $ttfont_list)) {
910
+					$ttfont_list = array('AnonymousPro.ttf');
911
+		} else {
912
+					$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
913
+		}
887 914
 	}
888 915
 
889 916
 	// Create a list of characters to be shown.
@@ -900,14 +927,16 @@  discard block
 block discarded – undo
900 927
 	}
901 928
 
902 929
 	// Load all fonts and determine the maximum font height.
903
-	foreach ($loaded_fonts as $font_index => $dummy)
904
-		$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
930
+	foreach ($loaded_fonts as $font_index => $dummy) {
931
+			$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
932
+	}
905 933
 
906 934
 	// Determine the dimensions of each character.
907
-	if ($imageType == 4 || $imageType == 5)
908
-		$extra = 80;
909
-	else
910
-		$extra = 45;
935
+	if ($imageType == 4 || $imageType == 5) {
936
+			$extra = 80;
937
+	} else {
938
+			$extra = 45;
939
+	}
911 940
 
912 941
 	$total_width = $character_spacing * strlen($code) + $extra;
913 942
 	$max_height = 0;
@@ -928,13 +957,15 @@  discard block
 block discarded – undo
928 957
 	imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color);
929 958
 
930 959
 	// Randomize the foreground color a little.
931
-	for ($i = 0; $i < 3; $i++)
932
-		$foreground_color[$i] = random_int(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
960
+	for ($i = 0; $i < 3; $i++) {
961
+			$foreground_color[$i] = random_int(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
962
+	}
933 963
 	$fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
934 964
 
935 965
 	// Color for the dots.
936
-	for ($i = 0; $i < 3; $i++)
937
-		$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? random_int(0, max($foreground_color[$i] - 20, 0)) : random_int(min($foreground_color[$i] + 20, 255), 255);
966
+	for ($i = 0; $i < 3; $i++) {
967
+			$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? random_int(0, max($foreground_color[$i] - 20, 0)) : random_int(min($foreground_color[$i] + 20, 255), 255);
968
+	}
938 969
 	$randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]);
939 970
 
940 971
 	// Some squares/rectanges for new extreme level
@@ -960,10 +991,11 @@  discard block
 block discarded – undo
960 991
 			$can_do_ttf = function_exists('imagettftext');
961 992
 
962 993
 			// How much rotation will we give?
963
-			if ($rotationType == 'none')
964
-				$angle = 0;
965
-			else
966
-				$angle = random_int(-100, 100) / ($rotationType == 'high' ? 6 : 10);
994
+			if ($rotationType == 'none') {
995
+							$angle = 0;
996
+			} else {
997
+							$angle = random_int(-100, 100) / ($rotationType == 'high' ? 6 : 10);
998
+			}
967 999
 
968 1000
 			// What color shall we do it?
969 1001
 			if ($fontColorType == 'cyclic')
@@ -977,51 +1009,56 @@  discard block
 block discarded – undo
977 1009
 					array(0, 0, 0),
978 1010
 					array(143, 39, 31),
979 1011
 				);
980
-				if (!isset($last_index))
981
-					$last_index = -1;
1012
+				if (!isset($last_index)) {
1013
+									$last_index = -1;
1014
+				}
982 1015
 				$new_index = $last_index;
983
-				while ($last_index == $new_index)
984
-					$new_index = random_int(0, count($colors) - 1);
1016
+				while ($last_index == $new_index) {
1017
+									$new_index = random_int(0, count($colors) - 1);
1018
+				}
985 1019
 				$char_fg_color = $colors[$new_index];
986 1020
 				$last_index = $new_index;
1021
+			} elseif ($fontColorType == 'random') {
1022
+							$char_fg_color = array(random_int(max($foreground_color[0] - 2, 0), $foreground_color[0]), random_int(max($foreground_color[1] - 2, 0), $foreground_color[1]), random_int(max($foreground_color[2] - 2, 0), $foreground_color[2]));
1023
+			} else {
1024
+							$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
987 1025
 			}
988
-			elseif ($fontColorType == 'random')
989
-				$char_fg_color = array(random_int(max($foreground_color[0] - 2, 0), $foreground_color[0]), random_int(max($foreground_color[1] - 2, 0), $foreground_color[1]), random_int(max($foreground_color[2] - 2, 0), $foreground_color[2]));
990
-			else
991
-				$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
992 1026
 
993 1027
 			if (!empty($can_do_ttf))
994 1028
 			{
995 1029
 				// GD2 handles font size differently.
996
-				if ($fontSizeRandom)
997
-					$font_size = $gd2 ? random_int(17, 19) : random_int(18, 25);
998
-				else
999
-					$font_size = $gd2 ? 18 : 24;
1030
+				if ($fontSizeRandom) {
1031
+									$font_size = $gd2 ? random_int(17, 19) : random_int(18, 25);
1032
+				} else {
1033
+									$font_size = $gd2 ? 18 : 24;
1034
+				}
1000 1035
 
1001 1036
 				// Work out the sizes - also fix the character width cause TTF not quite so wide!
1002 1037
 				$font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5;
1003 1038
 				$font_y = $max_height - ($fontVerPos == 'vrandom' ? random_int(2, 8) : ($fontVerPos == 'random' ? random_int(3, 5) : 5));
1004 1039
 
1005 1040
 				// What font face?
1006
-				if (!empty($ttfont_list))
1007
-					$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[random_int(0, count($ttfont_list) - 1)];
1041
+				if (!empty($ttfont_list)) {
1042
+									$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[random_int(0, count($ttfont_list) - 1)];
1043
+				}
1008 1044
 
1009 1045
 				// What color are we to do it in?
1010 1046
 				$is_reverse = $showReverseChars ? random_int(0, 1) : false;
1011 1047
 				$char_color = function_exists('imagecolorallocatealpha') && $fontTrans ? imagecolorallocatealpha($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2], 50) : imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]);
1012 1048
 
1013 1049
 				$fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']);
1014
-				if (empty($fontcord))
1015
-					$can_do_ttf = false;
1016
-				elseif ($is_reverse)
1050
+				if (empty($fontcord)) {
1051
+									$can_do_ttf = false;
1052
+				} elseif ($is_reverse)
1017 1053
 				{
1018 1054
 					imagefilledpolygon($code_image, $fontcord, 4, $fg_color);
1019 1055
 					// Put the character back!
1020 1056
 					imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']);
1021 1057
 				}
1022 1058
 
1023
-				if ($can_do_ttf)
1024
-					$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1059
+				if ($can_do_ttf) {
1060
+									$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1061
+				}
1025 1062
 			}
1026 1063
 
1027 1064
 			if (!$can_do_ttf)
@@ -1040,8 +1077,9 @@  discard block
 block discarded – undo
1040 1077
 				}
1041 1078
 
1042 1079
 				// Sorry, no rotation available.
1043
-				else
1044
-					imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1080
+				else {
1081
+									imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1082
+				}
1045 1083
 				$cur_x += $character['width'] + $character_spacing;
1046 1084
 			}
1047 1085
 		}
@@ -1054,17 +1092,22 @@  discard block
 block discarded – undo
1054 1092
 	}
1055 1093
 
1056 1094
 	// Make the background color transparent on the hard image.
1057
-	if (!$simpleBGColor)
1058
-		imagecolortransparent($code_image, $bg_color);
1059
-	if ($hasBorder)
1060
-		imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1095
+	if (!$simpleBGColor) {
1096
+			imagecolortransparent($code_image, $bg_color);
1097
+	}
1098
+	if ($hasBorder) {
1099
+			imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1100
+	}
1061 1101
 
1062 1102
 	// Add some noise to the background?
1063 1103
 	if ($noiseType != 'none')
1064 1104
 	{
1065
-		for ($i = random_int(0, 2); $i < $max_height; $i += random_int(1, 2))
1066
-			for ($j = random_int(0, 10); $j < $total_width; $j += random_int(1, 10))
1067
-				imagesetpixel($code_image, $j, $i, random_int(0, 1) ? $fg_color : $randomness_color);
1105
+		for ($i = random_int(0, 2); $i < $max_height; $i += random_int(1, 2)) {
1106
+					for ($j = random_int(0, 10);
1107
+		}
1108
+		$j < $total_width; $j += random_int(1, 10)) {
1109
+							imagesetpixel($code_image, $j, $i, random_int(0, 1) ? $fg_color : $randomness_color);
1110
+			}
1068 1111
 
1069 1112
 		// Put in some lines too?
1070 1113
 		if ($noiseType != 'extreme')
@@ -1077,8 +1120,7 @@  discard block
 block discarded – undo
1077 1120
 					$x1 = random_int(0, $total_width);
1078 1121
 					$x2 = random_int(0, $total_width);
1079 1122
 					$y1 = 0; $y2 = $max_height;
1080
-				}
1081
-				else
1123
+				} else
1082 1124
 				{
1083 1125
 					$y1 = random_int(0, $max_height);
1084 1126
 					$y2 = random_int(0, $max_height);
@@ -1087,8 +1129,7 @@  discard block
 block discarded – undo
1087 1129
 				imagesetthickness($code_image, random_int(1, 2));
1088 1130
 				imageline($code_image, $x1, $y1, $x2, $y2, random_int(0, 1) ? $fg_color : $randomness_color);
1089 1131
 			}
1090
-		}
1091
-		else
1132
+		} else
1092 1133
 		{
1093 1134
 			// Put in some ellipse
1094 1135
 			$num_ellipse = $noiseType == 'extreme' ? random_int(6, 12) : random_int(2, 6);
@@ -1108,8 +1149,7 @@  discard block
 block discarded – undo
1108 1149
 	{
1109 1150
 		header('content-type: image/gif');
1110 1151
 		imagegif($code_image);
1111
-	}
1112
-	else
1152
+	} else
1113 1153
 	{
1114 1154
 		header('content-type: image/png');
1115 1155
 		imagepng($code_image);
@@ -1132,25 +1172,29 @@  discard block
 block discarded – undo
1132 1172
 {
1133 1173
 	global $settings;
1134 1174
 
1135
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
1136
-		return false;
1175
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
1176
+			return false;
1177
+	}
1137 1178
 
1138 1179
 	// Get a list of the available font directories.
1139 1180
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
1140 1181
 	$font_list = array();
1141
-	while ($entry = $font_dir->read())
1142
-		if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1182
+	while ($entry = $font_dir->read()) {
1183
+			if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1143 1184
 			$font_list[] = $entry;
1185
+	}
1144 1186
 
1145
-	if (empty($font_list))
1146
-		return false;
1187
+	if (empty($font_list)) {
1188
+			return false;
1189
+	}
1147 1190
 
1148 1191
 	// Pick a random font.
1149 1192
 	$random_font = $font_list[array_rand($font_list)];
1150 1193
 
1151 1194
 	// Check if the given letter exists.
1152
-	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png'))
1153
-		return false;
1195
+	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) {
1196
+			return false;
1197
+	}
1154 1198
 
1155 1199
 	// Include it!
1156 1200
 	header('content-type: image/png');
Please login to merge, or discard this patch.
Sources/ManageSettings.php 1 patch
Braces   +276 added lines, -201 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
  * This function makes sure the requested subaction does exists, if it doesn't, it sets a default action or.
@@ -209,16 +210,18 @@  discard block
 block discarded – undo
209 210
 	{
210 211
 		$all_zones = timezone_identifiers_list();
211 212
 		// Make sure we set the value to the same as the printed value.
212
-		foreach ($all_zones as $zone)
213
-			$config_vars['default_timezone'][2][$zone] = $zone;
213
+		foreach ($all_zones as $zone) {
214
+					$config_vars['default_timezone'][2][$zone] = $zone;
215
+		}
216
+	} else {
217
+			unset($config_vars['default_timezone']);
214 218
 	}
215
-	else
216
-		unset($config_vars['default_timezone']);
217 219
 
218 220
 	call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));
219 221
 
220
-	if ($return_config)
221
-		return $config_vars;
222
+	if ($return_config) {
223
+			return $config_vars;
224
+	}
222 225
 
223 226
 	// Saving?
224 227
 	if (isset($_GET['save']))
@@ -226,8 +229,9 @@  discard block
 block discarded – undo
226 229
 		checkSession();
227 230
 
228 231
 		// Prevent absurd boundaries here - make it a day tops.
229
-		if (isset($_POST['lastActive']))
230
-			$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
232
+		if (isset($_POST['lastActive'])) {
233
+					$_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
234
+		}
231 235
 
232 236
 		call_integration_hook('integrate_save_basic_settings');
233 237
 
@@ -235,8 +239,9 @@  discard block
 block discarded – undo
235 239
 		$_SESSION['adm-save'] = true;
236 240
 
237 241
 		// Do a bit of housekeeping
238
-		if (empty($_POST['minimize_files']))
239
-			deleteAllMinified();
242
+		if (empty($_POST['minimize_files'])) {
243
+					deleteAllMinified();
244
+		}
240 245
 
241 246
 		writeLog();
242 247
 		redirectexit('action=admin;area=featuresettings;sa=basic');
@@ -276,8 +281,9 @@  discard block
 block discarded – undo
276 281
 
277 282
 	call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars));
278 283
 
279
-	if ($return_config)
280
-		return $config_vars;
284
+	if ($return_config) {
285
+			return $config_vars;
286
+	}
281 287
 
282 288
 	// Setup the template.
283 289
 	require_once($sourcedir . '/ManageServer.php');
@@ -294,13 +300,15 @@  discard block
 block discarded – undo
294 300
 
295 301
 		// Clean up the tags.
296 302
 		$bbcTags = array();
297
-		foreach (parse_bbc(false) as $tag)
298
-			$bbcTags[] = $tag['tag'];
303
+		foreach (parse_bbc(false) as $tag) {
304
+					$bbcTags[] = $tag['tag'];
305
+		}
299 306
 
300
-		if (!isset($_POST['disabledBBC_enabledTags']))
301
-			$_POST['disabledBBC_enabledTags'] = array();
302
-		elseif (!is_array($_POST['disabledBBC_enabledTags']))
303
-			$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
307
+		if (!isset($_POST['disabledBBC_enabledTags'])) {
308
+					$_POST['disabledBBC_enabledTags'] = array();
309
+		} elseif (!is_array($_POST['disabledBBC_enabledTags'])) {
310
+					$_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
311
+		}
304 312
 		// Work out what is actually disabled!
305 313
 		$_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
306 314
 
@@ -344,8 +352,9 @@  discard block
 block discarded – undo
344 352
 
345 353
 	call_integration_hook('integrate_layout_settings', array(&$config_vars));
346 354
 
347
-	if ($return_config)
348
-		return $config_vars;
355
+	if ($return_config) {
356
+			return $config_vars;
357
+	}
349 358
 
350 359
 	// Saving?
351 360
 	if (isset($_GET['save']))
@@ -385,8 +394,9 @@  discard block
 block discarded – undo
385 394
 
386 395
 	call_integration_hook('integrate_likes_settings', array(&$config_vars));
387 396
 
388
-	if ($return_config)
389
-		return $config_vars;
397
+	if ($return_config) {
398
+			return $config_vars;
399
+	}
390 400
 
391 401
 	// Saving?
392 402
 	if (isset($_GET['save']))
@@ -424,8 +434,9 @@  discard block
 block discarded – undo
424 434
 
425 435
 	call_integration_hook('integrate_mentions_settings', array(&$config_vars));
426 436
 
427
-	if ($return_config)
428
-		return $config_vars;
437
+	if ($return_config) {
438
+			return $config_vars;
439
+	}
429 440
 
430 441
 	// Saving?
431 442
 	if (isset($_GET['save']))
@@ -469,8 +480,8 @@  discard block
 block discarded – undo
469 480
 			'enable' => array('check', 'warning_enable'),
470 481
 	);
471 482
 
472
-	if (!empty($modSettings['warning_settings']) && $currently_enabled)
473
-		$config_vars += array(
483
+	if (!empty($modSettings['warning_settings']) && $currently_enabled) {
484
+			$config_vars += array(
474 485
 			'',
475 486
 				array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']),
476 487
 				'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']),
@@ -479,15 +490,18 @@  discard block
 block discarded – undo
479 490
 				'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']),
480 491
 				array('permissions', 'view_warning'),
481 492
 		);
493
+	}
482 494
 
483 495
 	call_integration_hook('integrate_warning_settings', array(&$config_vars));
484 496
 
485
-	if ($return_config)
486
-		return $config_vars;
497
+	if ($return_config) {
498
+			return $config_vars;
499
+	}
487 500
 
488 501
 	// Cannot use moderation if post moderation is not enabled.
489
-	if (!$modSettings['postmod_active'])
490
-		unset($config_vars['moderate']);
502
+	if (!$modSettings['postmod_active']) {
503
+			unset($config_vars['moderate']);
504
+	}
491 505
 
492 506
 	// Will need the utility functions from here.
493 507
 	require_once($sourcedir . '/ManageServer.php');
@@ -512,16 +526,16 @@  discard block
 block discarded – undo
512 526
 				'warning_watch' => 10,
513 527
 				'warning_mute' => 60,
514 528
 			);
515
-			if ($modSettings['postmod_active'])
516
-				$vars['warning_moderate'] = 35;
529
+			if ($modSettings['postmod_active']) {
530
+							$vars['warning_moderate'] = 35;
531
+			}
517 532
 
518 533
 			foreach ($vars as $var => $value)
519 534
 			{
520 535
 				$config_vars[] = array('int', $var);
521 536
 				$_POST[$var] = $value;
522 537
 			}
523
-		}
524
-		else
538
+		} else
525 539
 		{
526 540
 			$_POST['warning_watch'] = min($_POST['warning_watch'], 100);
527 541
 			$_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
@@ -609,8 +623,9 @@  discard block
 block discarded – undo
609 623
 
610 624
 	call_integration_hook('integrate_spam_settings', array(&$config_vars));
611 625
 
612
-	if ($return_config)
613
-		return $config_vars;
626
+	if ($return_config) {
627
+			return $config_vars;
628
+	}
614 629
 
615 630
 	// You need to be an admin to edit settings!
616 631
 	isAllowedTo('admin_forum');
@@ -644,8 +659,9 @@  discard block
 block discarded – undo
644 659
 
645 660
 	if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers']))
646 661
 	{
647
-		if (empty($context['settings_insert_above']))
648
-			$context['settings_insert_above'] = '';
662
+		if (empty($context['settings_insert_above'])) {
663
+					$context['settings_insert_above'] = '';
664
+		}
649 665
 
650 666
 		$context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>';
651 667
 	}
@@ -687,8 +703,9 @@  discard block
 block discarded – undo
687 703
 		$_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
688 704
 
689 705
 		// Hack in guest requiring verification!
690
-		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
691
-			$_POST['posts_require_captcha'] = -1;
706
+		if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) {
707
+					$_POST['posts_require_captcha'] = -1;
708
+		}
692 709
 
693 710
 		$save_vars = $config_vars;
694 711
 		unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
@@ -705,14 +722,16 @@  discard block
 block discarded – undo
705 722
 		foreach ($context['qa_languages'] as $lang_id => $dummy)
706 723
 		{
707 724
 			// If we had some questions for this language before, but don't now, delete everything from that language.
708
-			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id]))
709
-				$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
725
+			if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) {
726
+							$changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]);
727
+			}
710 728
 
711 729
 			// Now step through and see if any existing questions no longer exist.
712
-			if (!empty($context['qa_by_lang'][$lang_id]))
713
-				foreach ($context['qa_by_lang'][$lang_id] as $q_id)
730
+			if (!empty($context['qa_by_lang'][$lang_id])) {
731
+							foreach ($context['qa_by_lang'][$lang_id] as $q_id)
714 732
 					if (empty($_POST['question'][$lang_id][$q_id]))
715 733
 						$changes['delete'][] = $q_id;
734
+			}
716 735
 
717 736
 			// Now let's see if there are new questions or ones that need updating.
718 737
 			if (isset($_POST['question'][$lang_id]))
@@ -721,14 +740,16 @@  discard block
 block discarded – undo
721 740
 				{
722 741
 					// Ignore junky ids.
723 742
 					$q_id = (int) $q_id;
724
-					if ($q_id <= 0)
725
-						continue;
743
+					if ($q_id <= 0) {
744
+											continue;
745
+					}
726 746
 
727 747
 					// Check the question isn't empty (because they want to delete it?)
728 748
 					if (empty($question) || trim($question) == '')
729 749
 					{
730
-						if (isset($context['question_answers'][$q_id]))
731
-							$changes['delete'][] = $q_id;
750
+						if (isset($context['question_answers'][$q_id])) {
751
+													$changes['delete'][] = $q_id;
752
+						}
732 753
 						continue;
733 754
 					}
734 755
 					$question = $smcFunc['htmlspecialchars'](trim($question));
@@ -736,19 +757,22 @@  discard block
 block discarded – undo
736 757
 					// Get the answers. Firstly check there actually might be some.
737 758
 					if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id]))
738 759
 					{
739
-						if (isset($context['question_answers'][$q_id]))
740
-							$changes['delete'][] = $q_id;
760
+						if (isset($context['question_answers'][$q_id])) {
761
+													$changes['delete'][] = $q_id;
762
+						}
741 763
 						continue;
742 764
 					}
743 765
 					// Now get them and check that they might be viable.
744 766
 					$answers = array();
745
-					foreach ($_POST['answer'][$lang_id][$q_id] as $answer)
746
-						if (!empty($answer) && trim($answer) !== '')
767
+					foreach ($_POST['answer'][$lang_id][$q_id] as $answer) {
768
+											if (!empty($answer) && trim($answer) !== '')
747 769
 							$answers[] = $smcFunc['htmlspecialchars'](trim($answer));
770
+					}
748 771
 					if (empty($answers))
749 772
 					{
750
-						if (isset($context['question_answers'][$q_id]))
751
-							$changes['delete'][] = $q_id;
773
+						if (isset($context['question_answers'][$q_id])) {
774
+													$changes['delete'][] = $q_id;
775
+						}
752 776
 						continue;
753 777
 					}
754 778
 					$answers = $smcFunc['json_encode']($answers);
@@ -758,16 +782,17 @@  discard block
 block discarded – undo
758 782
 					{
759 783
 						// New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids.
760 784
 						$changes['insert'][] = array($lang_id, $question, $answers);
761
-					}
762
-					else
785
+					} else
763 786
 					{
764 787
 						// It's an existing question. Let's see what's changed, if anything.
765
-						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers'])
766
-							$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
788
+						if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) {
789
+													$changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers);
790
+						}
767 791
 					}
768 792
 
769
-					if (!isset($qs_per_lang[$lang_id]))
770
-						$qs_per_lang[$lang_id] = 0;
793
+					if (!isset($qs_per_lang[$lang_id])) {
794
+											$qs_per_lang[$lang_id] = 0;
795
+					}
771 796
 					$qs_per_lang[$lang_id]++;
772 797
 				}
773 798
 			}
@@ -817,8 +842,9 @@  discard block
 block discarded – undo
817 842
 
818 843
 		// Lastly, the count of messages needs to be no more than the lowest number of questions for any one language.
819 844
 		$count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang);
820
-		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
821
-			$_POST['qa_verification_number'] = $count_questions;
845
+		if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) {
846
+					$_POST['qa_verification_number'] = $count_questions;
847
+		}
822 848
 
823 849
 		call_integration_hook('integrate_save_spam_settings', array(&$save_vars));
824 850
 
@@ -833,24 +859,27 @@  discard block
 block discarded – undo
833 859
 
834 860
 	$character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
835 861
 	$_SESSION['visual_verification_code'] = '';
836
-	for ($i = 0; $i < 6; $i++)
837
-		$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
862
+	for ($i = 0; $i < 6; $i++) {
863
+			$_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
864
+	}
838 865
 
839 866
 	// Some javascript for CAPTCHA.
840 867
 	$context['settings_post_javascript'] = '';
841
-	if ($context['use_graphic_library'])
842
-		$context['settings_post_javascript'] .= '
868
+	if ($context['use_graphic_library']) {
869
+			$context['settings_post_javascript'] .= '
843 870
 		function refreshImages()
844 871
 		{
845 872
 			var imageType = document.getElementById(\'visual_verification_type\').value;
846 873
 			document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
847 874
 		}';
875
+	}
848 876
 
849 877
 	// Show the image itself, or text saying we can't.
850
-	if ($context['use_graphic_library'])
851
-		$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
852
-	else
853
-		$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
878
+	if ($context['use_graphic_library']) {
879
+			$config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>';
880
+	} else {
881
+			$config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
882
+	}
854 883
 
855 884
 	// Hack for PM spam settings.
856 885
 	list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
@@ -860,9 +889,10 @@  discard block
 block discarded – undo
860 889
 	$modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
861 890
 
862 891
 	// Some minor javascript for the guest post setting.
863
-	if ($modSettings['posts_require_captcha'])
864
-		$context['settings_post_javascript'] .= '
892
+	if ($modSettings['posts_require_captcha']) {
893
+			$context['settings_post_javascript'] .= '
865 894
 		document.getElementById(\'guests_require_captcha\').disabled = true;';
895
+	}
866 896
 
867 897
 	// And everything else.
868 898
 	$context['post_url'] = $scripturl . '?action=admin;area=antispam;save';
@@ -909,8 +939,9 @@  discard block
 block discarded – undo
909 939
 
910 940
 	call_integration_hook('integrate_signature_settings', array(&$config_vars));
911 941
 
912
-	if ($return_config)
913
-		return $config_vars;
942
+	if ($return_config) {
943
+			return $config_vars;
944
+	}
914 945
 
915 946
 	// Setup the template.
916 947
 	$context['page_title'] = $txt['signature_settings'];
@@ -965,8 +996,9 @@  discard block
 block discarded – undo
965 996
 				$sig = strtr($row['signature'], array('<br>' => "\n"));
966 997
 
967 998
 				// Max characters...
968
-				if (!empty($sig_limits[1]))
969
-					$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
999
+				if (!empty($sig_limits[1])) {
1000
+									$sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
1001
+				}
970 1002
 				// Max lines...
971 1003
 				if (!empty($sig_limits[2]))
972 1004
 				{
@@ -976,8 +1008,9 @@  discard block
 block discarded – undo
976 1008
 						if ($sig[$i] == "\n")
977 1009
 						{
978 1010
 							$count++;
979
-							if ($count >= $sig_limits[2])
980
-								$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1011
+							if ($count >= $sig_limits[2]) {
1012
+															$sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
1013
+							}
981 1014
 						}
982 1015
 					}
983 1016
 				}
@@ -988,17 +1021,19 @@  discard block
 block discarded – undo
988 1021
 					{
989 1022
 						$limit_broke = 0;
990 1023
 						// Attempt to allow all sizes of abuse, so to speak.
991
-						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
992
-							$limit_broke = $sig_limits[7] . 'px';
993
-						elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
994
-							$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
995
-						elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
996
-							$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
997
-						elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
998
-							$limit_broke = 'large';
999
-
1000
-						if ($limit_broke)
1001
-							$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1024
+						if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
1025
+													$limit_broke = $sig_limits[7] . 'px';
1026
+						} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
1027
+													$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
1028
+						} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
1029
+													$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
1030
+						} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
1031
+													$limit_broke = 'large';
1032
+						}
1033
+
1034
+						if ($limit_broke) {
1035
+													$sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
1036
+						}
1002 1037
 					}
1003 1038
 				}
1004 1039
 
@@ -1054,32 +1089,34 @@  discard block
 block discarded – undo
1054 1089
 											$img_offset = false;
1055 1090
 										}
1056 1091
 									}
1092
+								} else {
1093
+																	$replaces[$image] = '';
1057 1094
 								}
1058
-								else
1059
-									$replaces[$image] = '';
1060 1095
 
1061 1096
 								continue;
1062 1097
 							}
1063 1098
 
1064 1099
 							// Does it have predefined restraints? Width first.
1065
-							if ($matches[6][$key])
1066
-								$matches[2][$key] = $matches[6][$key];
1100
+							if ($matches[6][$key]) {
1101
+															$matches[2][$key] = $matches[6][$key];
1102
+							}
1067 1103
 							if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
1068 1104
 							{
1069 1105
 								$width = $sig_limits[5];
1070 1106
 								$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
1107
+							} elseif ($matches[2][$key]) {
1108
+															$width = $matches[2][$key];
1071 1109
 							}
1072
-							elseif ($matches[2][$key])
1073
-								$width = $matches[2][$key];
1074 1110
 							// ... and height.
1075 1111
 							if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
1076 1112
 							{
1077 1113
 								$height = $sig_limits[6];
1078
-								if ($width != -1)
1079
-									$width = $width * ($height / $matches[4][$key]);
1114
+								if ($width != -1) {
1115
+																	$width = $width * ($height / $matches[4][$key]);
1116
+								}
1117
+							} elseif ($matches[4][$key]) {
1118
+															$height = $matches[4][$key];
1080 1119
 							}
1081
-							elseif ($matches[4][$key])
1082
-								$height = $matches[4][$key];
1083 1120
 
1084 1121
 							// If the dimensions are still not fixed - we need to check the actual image.
1085 1122
 							if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -1097,12 +1134,13 @@  discard block
 block discarded – undo
1097 1134
 									if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
1098 1135
 									{
1099 1136
 										$height = $sig_limits[6];
1100
-										if ($width == -1)
1101
-											$width = $sizes[0];
1137
+										if ($width == -1) {
1138
+																					$width = $sizes[0];
1139
+										}
1102 1140
 										$width = $width * ($height / $sizes[1]);
1141
+									} elseif ($width != -1) {
1142
+																			$height = $sizes[1];
1103 1143
 									}
1104
-									elseif ($width != -1)
1105
-										$height = $sizes[1];
1106 1144
 								}
1107 1145
 							}
1108 1146
 
@@ -1115,8 +1153,9 @@  discard block
 block discarded – undo
1115 1153
 							// Record that we got one.
1116 1154
 							$image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
1117 1155
 						}
1118
-						if (!empty($replaces))
1119
-							$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1156
+						if (!empty($replaces)) {
1157
+													$sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
1158
+						}
1120 1159
 					}
1121 1160
 				}
1122 1161
 				// Try to fix disabled tags.
@@ -1128,18 +1167,20 @@  discard block
 block discarded – undo
1128 1167
 
1129 1168
 				$sig = strtr($sig, array("\n" => '<br>'));
1130 1169
 				call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags));
1131
-				if ($sig != $row['signature'])
1132
-					$changes[$row['id_member']] = $sig;
1170
+				if ($sig != $row['signature']) {
1171
+									$changes[$row['id_member']] = $sig;
1172
+				}
1173
+			}
1174
+			if ($smcFunc['db_num_rows']($request) == 0) {
1175
+							$done = true;
1133 1176
 			}
1134
-			if ($smcFunc['db_num_rows']($request) == 0)
1135
-				$done = true;
1136 1177
 			$smcFunc['db_free_result']($request);
1137 1178
 
1138 1179
 			// Do we need to delete what we have?
1139 1180
 			if (!empty($changes))
1140 1181
 			{
1141
-				foreach ($changes as $id => $sig)
1142
-					$smcFunc['db_query']('', '
1182
+				foreach ($changes as $id => $sig) {
1183
+									$smcFunc['db_query']('', '
1143 1184
 						UPDATE {db_prefix}members
1144 1185
 						SET signature = {string:signature}
1145 1186
 						WHERE id_member = {int:id_member}',
@@ -1148,11 +1189,13 @@  discard block
 block discarded – undo
1148 1189
 							'signature' => $sig,
1149 1190
 						)
1150 1191
 					);
1192
+				}
1151 1193
 			}
1152 1194
 
1153 1195
 			$_GET['step'] += 50;
1154
-			if (!$done)
1155
-				pauseSignatureApplySettings();
1196
+			if (!$done) {
1197
+							pauseSignatureApplySettings();
1198
+			}
1156 1199
 		}
1157 1200
 		$settings_applied = true;
1158 1201
 	}
@@ -1170,8 +1213,9 @@  discard block
 block discarded – undo
1170 1213
 	);
1171 1214
 
1172 1215
 	// Temporarily make each setting a modSetting!
1173
-	foreach ($context['signature_settings'] as $key => $value)
1174
-		$modSettings['signature_' . $key] = $value;
1216
+	foreach ($context['signature_settings'] as $key => $value) {
1217
+			$modSettings['signature_' . $key] = $value;
1218
+	}
1175 1219
 
1176 1220
 	// Make sure we check the right tags!
1177 1221
 	$modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
@@ -1183,23 +1227,26 @@  discard block
 block discarded – undo
1183 1227
 
1184 1228
 		// Clean up the tag stuff!
1185 1229
 		$bbcTags = array();
1186
-		foreach (parse_bbc(false) as $tag)
1187
-			$bbcTags[] = $tag['tag'];
1230
+		foreach (parse_bbc(false) as $tag) {
1231
+					$bbcTags[] = $tag['tag'];
1232
+		}
1188 1233
 
1189
-		if (!isset($_POST['signature_bbc_enabledTags']))
1190
-			$_POST['signature_bbc_enabledTags'] = array();
1191
-		elseif (!is_array($_POST['signature_bbc_enabledTags']))
1192
-			$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1234
+		if (!isset($_POST['signature_bbc_enabledTags'])) {
1235
+					$_POST['signature_bbc_enabledTags'] = array();
1236
+		} elseif (!is_array($_POST['signature_bbc_enabledTags'])) {
1237
+					$_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
1238
+		}
1193 1239
 
1194 1240
 		$sig_limits = array();
1195 1241
 		foreach ($context['signature_settings'] as $key => $value)
1196 1242
 		{
1197
-			if ($key == 'allow_smileys')
1198
-				continue;
1199
-			elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
1200
-				$sig_limits[] = -1;
1201
-			else
1202
-				$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1243
+			if ($key == 'allow_smileys') {
1244
+							continue;
1245
+			} elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) {
1246
+							$sig_limits[] = -1;
1247
+			} else {
1248
+							$sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
1249
+			}
1203 1250
 		}
1204 1251
 
1205 1252
 		call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags));
@@ -1232,12 +1279,14 @@  discard block
 block discarded – undo
1232 1279
 
1233 1280
 	// Try get more time...
1234 1281
 	@set_time_limit(600);
1235
-	if (function_exists('apache_reset_timeout'))
1236
-		@apache_reset_timeout();
1282
+	if (function_exists('apache_reset_timeout')) {
1283
+			@apache_reset_timeout();
1284
+	}
1237 1285
 
1238 1286
 	// Have we exhausted all the time we allowed?
1239
-	if (time() - array_sum(explode(' ', $sig_start)) < 3)
1240
-		return;
1287
+	if (time() - array_sum(explode(' ', $sig_start)) < 3) {
1288
+			return;
1289
+	}
1241 1290
 
1242 1291
 	$context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1243 1292
 	$context['page_title'] = $txt['not_done_title'];
@@ -1283,9 +1332,10 @@  discard block
 block discarded – undo
1283 1332
 		$disable_fields = array_flip($standard_fields);
1284 1333
 		if (!empty($_POST['active']))
1285 1334
 		{
1286
-			foreach ($_POST['active'] as $value)
1287
-				if (isset($disable_fields[$value]))
1335
+			foreach ($_POST['active'] as $value) {
1336
+							if (isset($disable_fields[$value]))
1288 1337
 					unset($disable_fields[$value]);
1338
+			}
1289 1339
 		}
1290 1340
 		// What we have left!
1291 1341
 		$changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
@@ -1294,16 +1344,18 @@  discard block
 block discarded – undo
1294 1344
 		$reg_fields = array();
1295 1345
 		if (!empty($_POST['reg']))
1296 1346
 		{
1297
-			foreach ($_POST['reg'] as $value)
1298
-				if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1347
+			foreach ($_POST['reg'] as $value) {
1348
+							if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
1299 1349
 					$reg_fields[] = $value;
1350
+			}
1300 1351
 		}
1301 1352
 		// What we have left!
1302 1353
 		$changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
1303 1354
 
1304 1355
 		$_SESSION['adm-save'] = true;
1305
-		if (!empty($changes))
1306
-			updateSettings($changes);
1356
+		if (!empty($changes)) {
1357
+					updateSettings($changes);
1358
+		}
1307 1359
 	}
1308 1360
 
1309 1361
 	createToken('admin-scp');
@@ -1406,11 +1458,13 @@  discard block
 block discarded – undo
1406 1458
 					{
1407 1459
 						$return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br>';
1408 1460
 
1409
-						if ($rowData['field_order'] > 1)
1410
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1461
+						if ($rowData['field_order'] > 1) {
1462
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>';
1463
+						}
1411 1464
 
1412
-						if ($rowData['field_order'] < $context['custFieldsMaxOrder'])
1413
-							$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1465
+						if ($rowData['field_order'] < $context['custFieldsMaxOrder']) {
1466
+													$return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>';
1467
+						}
1414 1468
 
1415 1469
 						$return .= '</p>';
1416 1470
 
@@ -1548,16 +1602,16 @@  discard block
 block discarded – undo
1548 1602
 		$disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
1549 1603
 		$registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
1550 1604
 
1551
-		foreach ($standard_fields as $field)
1552
-			$list[] = array(
1605
+		foreach ($standard_fields as $field) {
1606
+					$list[] = array(
1553 1607
 				'id' => $field,
1554 1608
 				'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
1555 1609
 				'disabled' => in_array($field, $disabled_fields),
1556 1610
 				'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
1557 1611
 				'can_show_register' => !in_array($field, $fields_no_registration),
1558 1612
 			);
1559
-	}
1560
-	else
1613
+		}
1614
+	} else
1561 1615
 	{
1562 1616
 		// Load all the fields.
1563 1617
 		$request = $smcFunc['db_query']('', '
@@ -1571,8 +1625,9 @@  discard block
 block discarded – undo
1571 1625
 				'items_per_page' => $items_per_page,
1572 1626
 			)
1573 1627
 		);
1574
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1575
-			$list[] = $row;
1628
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1629
+					$list[] = $row;
1630
+		}
1576 1631
 		$smcFunc['db_free_result']($request);
1577 1632
 	}
1578 1633
 
@@ -1638,9 +1693,9 @@  discard block
 block discarded – undo
1638 1693
 		$context['field'] = array();
1639 1694
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1640 1695
 		{
1641
-			if ($row['field_type'] == 'textarea')
1642
-				@list ($rows, $cols) = @explode(',', $row['default_value']);
1643
-			else
1696
+			if ($row['field_type'] == 'textarea') {
1697
+							@list ($rows, $cols) = @explode(',', $row['default_value']);
1698
+			} else
1644 1699
 			{
1645 1700
 				$rows = 3;
1646 1701
 				$cols = 30;
@@ -1676,8 +1731,8 @@  discard block
 block discarded – undo
1676 1731
 	}
1677 1732
 
1678 1733
 	// Setup the default values as needed.
1679
-	if (empty($context['field']))
1680
-		$context['field'] = array(
1734
+	if (empty($context['field'])) {
1735
+			$context['field'] = array(
1681 1736
 			'name' => '',
1682 1737
 			'col_name' => '???',
1683 1738
 			'desc' => '',
@@ -1702,6 +1757,7 @@  discard block
 block discarded – undo
1702 1757
 			'enclose' => '',
1703 1758
 			'placement' => 0,
1704 1759
 		);
1760
+	}
1705 1761
 
1706 1762
 	// Are we moving it?
1707 1763
 	if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to))
@@ -1710,8 +1766,10 @@  discard block
 block discarded – undo
1710 1766
 		$new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1));
1711 1767
 
1712 1768
 		// Is this a valid position?
1713
-		if ($new_order <= 0 || $new_order > $order_count)
1714
-			redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler
1769
+		if ($new_order <= 0 || $new_order > $order_count) {
1770
+					redirectexit('action=admin;area=featuresettings;sa=profile');
1771
+		}
1772
+		// @todo implement an error handler
1715 1773
 
1716 1774
 		// All good, proceed.
1717 1775
 		$smcFunc['db_query']('','
@@ -1742,12 +1800,14 @@  discard block
 block discarded – undo
1742 1800
 		validateToken('admin-ecp');
1743 1801
 
1744 1802
 		// Everyone needs a name - even the (bracket) unknown...
1745
-		if (trim($_POST['field_name']) == '')
1746
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1803
+		if (trim($_POST['field_name']) == '') {
1804
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
1805
+		}
1747 1806
 
1748 1807
 		// Regex you say?  Do a very basic test to see if the pattern is valid
1749
-		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
1750
-			redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1808
+		if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) {
1809
+					redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
1810
+		}
1751 1811
 
1752 1812
 		$_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
1753 1813
 		$_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
@@ -1764,8 +1824,9 @@  discard block
 block discarded – undo
1764 1824
 
1765 1825
 		// Some masking stuff...
1766 1826
 		$mask = isset($_POST['mask']) ? $_POST['mask'] : '';
1767
-		if ($mask == 'regex' && isset($_POST['regex']))
1768
-			$mask .= $_POST['regex'];
1827
+		if ($mask == 'regex' && isset($_POST['regex'])) {
1828
+					$mask .= $_POST['regex'];
1829
+		}
1769 1830
 
1770 1831
 		$field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
1771 1832
 		$enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
@@ -1784,8 +1845,9 @@  discard block
 block discarded – undo
1784 1845
 				$v = strtr($v, array(',' => ''));
1785 1846
 
1786 1847
 				// Nada, zip, etc...
1787
-				if (trim($v) == '')
1788
-					continue;
1848
+				if (trim($v) == '') {
1849
+									continue;
1850
+				}
1789 1851
 
1790 1852
 				// Otherwise, save it boy.
1791 1853
 				$field_options .= $v . ',';
@@ -1793,15 +1855,17 @@  discard block
 block discarded – undo
1793 1855
 				$newOptions[$k] = $v;
1794 1856
 
1795 1857
 				// Is it default?
1796
-				if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
1797
-					$default = $v;
1858
+				if (isset($_POST['default_select']) && $_POST['default_select'] == $k) {
1859
+									$default = $v;
1860
+				}
1798 1861
 			}
1799 1862
 			$field_options = substr($field_options, 0, -1);
1800 1863
 		}
1801 1864
 
1802 1865
 		// Text area has default has dimensions
1803
-		if ($_POST['field_type'] == 'textarea')
1804
-			$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1866
+		if ($_POST['field_type'] == 'textarea') {
1867
+					$default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
1868
+		}
1805 1869
 
1806 1870
 		// Come up with the unique name?
1807 1871
 		if (empty($context['fid']))
@@ -1810,32 +1874,36 @@  discard block
 block discarded – undo
1810 1874
 			preg_match('~([\w\d_-]+)~', $col_name, $matches);
1811 1875
 
1812 1876
 			// If there is nothing to the name, then let's start out own - for foreign languages etc.
1813
-			if (isset($matches[1]))
1814
-				$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1815
-			else
1816
-				$col_name = $initial_col_name = 'cust_' . random_int(1, 9999);
1877
+			if (isset($matches[1])) {
1878
+							$col_name = $initial_col_name = 'cust_' . strtolower($matches[1]);
1879
+			} else {
1880
+							$col_name = $initial_col_name = 'cust_' . random_int(1, 9999);
1881
+			}
1817 1882
 
1818 1883
 			// Make sure this is unique.
1819 1884
 			$current_fields = array();
1820 1885
 			$request = $smcFunc['db_query']('', '
1821 1886
 				SELECT id_field, col_name
1822 1887
 				FROM {db_prefix}custom_fields');
1823
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1824
-				$current_fields[$row['id_field']] = $row['col_name'];
1888
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1889
+							$current_fields[$row['id_field']] = $row['col_name'];
1890
+			}
1825 1891
 			$smcFunc['db_free_result']($request);
1826 1892
 
1827 1893
 			$unique = false;
1828 1894
 			for ($i = 0; !$unique && $i < 9; $i ++)
1829 1895
 			{
1830
-				if (!in_array($col_name, $current_fields))
1831
-					$unique = true;
1832
-				else
1833
-					$col_name = $initial_col_name . $i;
1896
+				if (!in_array($col_name, $current_fields)) {
1897
+									$unique = true;
1898
+				} else {
1899
+									$col_name = $initial_col_name . $i;
1900
+				}
1834 1901
 			}
1835 1902
 
1836 1903
 			// Still not a unique column name? Leave it up to the user, then.
1837
-			if (!$unique)
1838
-				fatal_lang_error('custom_option_not_unique');
1904
+			if (!$unique) {
1905
+							fatal_lang_error('custom_option_not_unique');
1906
+			}
1839 1907
 		}
1840 1908
 		// Work out what to do with the user data otherwise...
1841 1909
 		else
@@ -1863,8 +1931,9 @@  discard block
 block discarded – undo
1863 1931
 				// Work out what's changed!
1864 1932
 				foreach ($context['field']['options'] as $k => $option)
1865 1933
 				{
1866
-					if (trim($option) == '')
1867
-						continue;
1934
+					if (trim($option) == '') {
1935
+											continue;
1936
+					}
1868 1937
 
1869 1938
 					// Still exists?
1870 1939
 					if (in_array($option, $newOptions))
@@ -1878,8 +1947,8 @@  discard block
 block discarded – undo
1878 1947
 				foreach ($optionChanges as $k => $option)
1879 1948
 				{
1880 1949
 					// Just been renamed?
1881
-					if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
1882
-						$smcFunc['db_query']('', '
1950
+					if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) {
1951
+											$smcFunc['db_query']('', '
1883 1952
 							UPDATE {db_prefix}themes
1884 1953
 							SET value = {string:new_value}
1885 1954
 							WHERE variable = {string:current_column}
@@ -1892,6 +1961,7 @@  discard block
 block discarded – undo
1892 1961
 								'old_value' => $option,
1893 1962
 							)
1894 1963
 						);
1964
+					}
1895 1965
 				}
1896 1966
 			}
1897 1967
 			// @todo Maybe we should adjust based on new text length limits?
@@ -1934,8 +2004,8 @@  discard block
 block discarded – undo
1934 2004
 			);
1935 2005
 
1936 2006
 			// Just clean up any old selects - these are a pain!
1937
-			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
1938
-				$smcFunc['db_query']('', '
2007
+			if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) {
2008
+							$smcFunc['db_query']('', '
1939 2009
 					DELETE FROM {db_prefix}themes
1940 2010
 					WHERE variable = {string:current_column}
1941 2011
 						AND value NOT IN ({array_string:new_option_values})
@@ -1946,8 +2016,8 @@  discard block
 block discarded – undo
1946 2016
 						'current_column' => $context['field']['col_name'],
1947 2017
 					)
1948 2018
 				);
1949
-		}
1950
-		else
2019
+			}
2020
+		} else
1951 2021
 		{
1952 2022
 			// Gotta figure it out the order.
1953 2023
 			$new_order = $order_count > 1 ? ($order_count + 1) : 1;
@@ -2122,11 +2192,13 @@  discard block
 block discarded – undo
2122 2192
 	call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false));
2123 2193
 
2124 2194
 	$prune_toggle_dt = array();
2125
-	foreach ($prune_toggle as $item)
2126
-		$prune_toggle_dt[] = 'setting_' . $item;
2195
+	foreach ($prune_toggle as $item) {
2196
+			$prune_toggle_dt[] = 'setting_' . $item;
2197
+	}
2127 2198
 
2128
-	if ($return_config)
2129
-		return $config_vars;
2199
+	if ($return_config) {
2200
+			return $config_vars;
2201
+	}
2130 2202
 
2131 2203
 	addInlineJavaScript('
2132 2204
 	function togglePruned()
@@ -2164,15 +2236,16 @@  discard block
 block discarded – undo
2164 2236
 			$vals = array();
2165 2237
 			foreach ($config_vars as $index => $dummy)
2166 2238
 			{
2167
-				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle))
2168
-					continue;
2239
+				if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) {
2240
+									continue;
2241
+				}
2169 2242
 
2170 2243
 				$vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
2171 2244
 			}
2172 2245
 			$_POST['pruningOptions'] = implode(',', $vals);
2246
+		} else {
2247
+					$_POST['pruningOptions'] = '';
2173 2248
 		}
2174
-		else
2175
-			$_POST['pruningOptions'] = '';
2176 2249
 
2177 2250
 		saveDBSettings($savevar);
2178 2251
 		$_SESSION['adm-save'] = true;
@@ -2184,10 +2257,11 @@  discard block
 block discarded – undo
2184 2257
 	$context['sub_template'] = 'show_settings';
2185 2258
 
2186 2259
 	// Get the actual values
2187
-	if (!empty($modSettings['pruningOptions']))
2188
-		@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2189
-	else
2190
-		$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2260
+	if (!empty($modSettings['pruningOptions'])) {
2261
+			@list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
2262
+	} else {
2263
+			$modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0;
2264
+	}
2191 2265
 
2192 2266
 	prepareDBSettingContext($config_vars);
2193 2267
 }
@@ -2209,8 +2283,9 @@  discard block
 block discarded – undo
2209 2283
 	// Make it even easier to add new settings.
2210 2284
 	call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
2211 2285
 
2212
-	if ($return_config)
2213
-		return $config_vars;
2286
+	if ($return_config) {
2287
+			return $config_vars;
2288
+	}
2214 2289
 
2215 2290
 	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
2216 2291
 	$context['settings_title'] = $txt['mods_cat_modifications_misc'];
Please login to merge, or discard this patch.