Completed
Pull Request — release-2.1 (#3761)
by Rick
10:12 queued 03:10
created
Sources/ManageAttachments.php 1 patch
Braces   +429 added lines, -325 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * The main 'Attachments and Avatars' management function.
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 	call_integration_hook('integrate_manage_attachments', array(&$subActions));
64 65
 
65 66
 	// Pick the correct sub-action.
66
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
67
-		$context['sub_action'] = $_REQUEST['sa'];
68
-	else
69
-		$context['sub_action'] = 'browse';
67
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
68
+			$context['sub_action'] = $_REQUEST['sa'];
69
+	} else {
70
+			$context['sub_action'] = 'browse';
71
+	}
70 72
 
71 73
 	// Default page title is good.
72 74
 	$context['page_title'] = $txt['attachments_avatars'];
@@ -94,20 +96,20 @@  discard block
 block discarded – undo
94 96
 	$context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
95 97
 
96 98
 	// If not set, show a default path for the base directory
97
-	if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments']))
98
-		if (is_dir($modSettings['attachmentUploadDir'][1]))
99
+	if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) {
100
+			if (is_dir($modSettings['attachmentUploadDir'][1]))
99 101
 			$modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1];
100
-
101
-	else
102
-		$modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir'];
102
+	} else {
103
+			$modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir'];
104
+	}
103 105
 
104 106
 	$context['valid_upload_dir'] = is_dir($context['attachmentUploadDir']) && is_writable($context['attachmentUploadDir']);
105 107
 
106
-	if (!empty($modSettings['automanage_attachments']))
107
-		$context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']);
108
-
109
-	else
110
-		$context['valid_basedirectory'] = true;
108
+	if (!empty($modSettings['automanage_attachments'])) {
109
+			$context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']);
110
+	} else {
111
+			$context['valid_basedirectory'] = true;
112
+	}
111 113
 
112 114
 	// A bit of razzle dazzle with the $txt strings. :)
113 115
 	$txt['attachment_path'] = $context['attachmentUploadDir'];
@@ -185,8 +187,9 @@  discard block
 block discarded – undo
185 187
 
186 188
 	call_integration_hook('integrate_modify_attachment_settings', array(&$config_vars));
187 189
 
188
-	if ($return_config)
189
-		return $config_vars;
190
+	if ($return_config) {
191
+			return $config_vars;
192
+	}
190 193
 
191 194
 	// These are very likely to come in handy! (i.e. without them we're doomed!)
192 195
 	require_once($sourcedir . '/ManagePermissions.php');
@@ -197,21 +200,24 @@  discard block
 block discarded – undo
197 200
 	{
198 201
 		checkSession();
199 202
 
200
-		if (isset($_POST['attachmentUploadDir']))
201
-			unset($_POST['attachmentUploadDir']);
203
+		if (isset($_POST['attachmentUploadDir'])) {
204
+					unset($_POST['attachmentUploadDir']);
205
+		}
202 206
 
203 207
 		if (!empty($_POST['use_subdirectories_for_attachments']))
204 208
 		{
205
-			if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments']))
206
-				$_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
209
+			if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) {
210
+							$_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
211
+			}
207 212
 
208 213
 			if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($modSettings['attachment_basedirectories']))
209 214
 			{
210
-				if (!is_array($modSettings['attachment_basedirectories']))
211
-					$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
215
+				if (!is_array($modSettings['attachment_basedirectories'])) {
216
+									$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
217
+				}
218
+			} else {
219
+							$modSettings['attachment_basedirectories'] = array();
212 220
 			}
213
-			else
214
-				$modSettings['attachment_basedirectories'] = array();
215 221
 
216 222
 			if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
217 223
 			{
@@ -219,8 +225,9 @@  discard block
 block discarded – undo
219 225
 
220 226
 				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir']))
221 227
 				{
222
-					if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments']))
223
-						$_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments'];
228
+					if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) {
229
+											$_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments'];
230
+					}
224 231
 				}
225 232
 
226 233
 				if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']))
@@ -336,8 +343,9 @@  discard block
 block discarded – undo
336 343
 
337 344
 	call_integration_hook('integrate_modify_avatar_settings', array(&$config_vars));
338 345
 
339
-	if ($return_config)
340
-		return $config_vars;
346
+	if ($return_config) {
347
+			return $config_vars;
348
+	}
341 349
 
342 350
 	// We need this file for the settings template.
343 351
 	require_once($sourcedir . '/ManageServer.php');
@@ -348,17 +356,21 @@  discard block
 block discarded – undo
348 356
 		checkSession();
349 357
 
350 358
 		// These settings cannot be left empty!
351
-		if (empty($_POST['custom_avatar_dir']))
352
-			$_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar';
359
+		if (empty($_POST['custom_avatar_dir'])) {
360
+					$_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar';
361
+		}
353 362
 
354
-		if (empty($_POST['custom_avatar_url']))
355
-			$_POST['custom_avatar_url'] = $boardurl . '/custom_avatar';
363
+		if (empty($_POST['custom_avatar_url'])) {
364
+					$_POST['custom_avatar_url'] = $boardurl . '/custom_avatar';
365
+		}
356 366
 
357
-		if (empty($_POST['avatar_directory']))
358
-			$_POST['avatar_directory'] = $boarddir . '/avatars';
367
+		if (empty($_POST['avatar_directory'])) {
368
+					$_POST['avatar_directory'] = $boarddir . '/avatars';
369
+		}
359 370
 
360
-		if (empty($_POST['avatar_url']))
361
-			$_POST['avatar_url'] = $boardurl . '/avatars';
371
+		if (empty($_POST['avatar_url'])) {
372
+					$_POST['avatar_url'] = $boardurl . '/avatars';
373
+		}
362 374
 
363 375
 		call_integration_hook('integrate_save_avatar_settings');
364 376
 
@@ -406,11 +418,13 @@  discard block
 block discarded – undo
406 418
 	$list_title = $txt['attachment_manager_browse_files'] . ': ';
407 419
 	foreach ($titles as $browse_type => $details)
408 420
 	{
409
-		if ($browse_type != 'attachments')
410
-			$list_title .= ' | ';
421
+		if ($browse_type != 'attachments') {
422
+					$list_title .= ' | ';
423
+		}
411 424
 
412
-		if ($context['browse_type'] == $browse_type)
413
-			$list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt="&gt;"> ';
425
+		if ($context['browse_type'] == $browse_type) {
426
+					$list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt="&gt;"> ';
427
+		}
414 428
 
415 429
 		$list_title .= '<a href="' . $scripturl . $details[0] . '">' . $details[1] . '</a>';
416 430
 	}
@@ -446,28 +460,33 @@  discard block
 block discarded – undo
446 460
 						$link = '<a href="';
447 461
 
448 462
 						// In case of a custom avatar URL attachments have a fixed directory.
449
-						if ($rowData['attachment_type'] == 1)
450
-							$link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']);
463
+						if ($rowData['attachment_type'] == 1) {
464
+													$link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']);
465
+						}
451 466
 
452 467
 						// By default avatars are downloaded almost as attachments.
453
-						elseif ($context['browse_type'] == 'avatars')
454
-							$link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']);
468
+						elseif ($context['browse_type'] == 'avatars') {
469
+													$link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']);
470
+						}
455 471
 
456 472
 						// Normal attachments are always linked to a topic ID.
457
-						else
458
-							$link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']);
473
+						else {
474
+													$link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']);
475
+						}
459 476
 
460 477
 						$link .= '"';
461 478
 
462 479
 						// Show a popup on click if it's a picture and we know its dimensions.
463
-						if (!empty($rowData['width']) && !empty($rowData['height']))
464
-							$link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20);
480
+						if (!empty($rowData['width']) && !empty($rowData['height'])) {
481
+													$link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20);
482
+						}
465 483
 
466 484
 						$link .= sprintf('>%1$s</a>', preg_replace('~&amp;#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\\\1;', $smcFunc['htmlspecialchars']($rowData['filename'])));
467 485
 
468 486
 						// Show the dimensions.
469
-						if (!empty($rowData['width']) && !empty($rowData['height']))
470
-							$link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']);
487
+						if (!empty($rowData['width']) && !empty($rowData['height'])) {
488
+													$link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']);
489
+						}
471 490
 
472 491
 						return $link;
473 492
 					},
@@ -500,12 +519,14 @@  discard block
 block discarded – undo
500 519
 					'function' => function($rowData) use ($scripturl, $smcFunc)
501 520
 					{
502 521
 						// In case of an attachment, return the poster of the attachment.
503
-						if (empty($rowData['id_member']))
504
-							return $smcFunc['htmlspecialchars']($rowData['poster_name']);
522
+						if (empty($rowData['id_member'])) {
523
+													return $smcFunc['htmlspecialchars']($rowData['poster_name']);
524
+						}
505 525
 
506 526
 						// Otherwise it must be an avatar, return the link to the owner of it.
507
-						else
508
-							return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']);
527
+						else {
528
+													return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']);
529
+						}
509 530
 					},
510 531
 				),
511 532
 				'sort' => array(
@@ -524,8 +545,9 @@  discard block
 block discarded – undo
524 545
 						$date = empty($rowData['poster_time']) ? $txt['never'] : timeformat($rowData['poster_time']);
525 546
 
526 547
 						// Add a link to the topic in case of an attachment.
527
-						if ($context['browse_type'] !== 'avatars')
528
-							$date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']);
548
+						if ($context['browse_type'] !== 'avatars') {
549
+													$date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']);
550
+						}
529 551
 
530 552
 						return $date;
531 553
 					},
@@ -610,8 +632,8 @@  discard block
 block discarded – undo
610 632
 	global $smcFunc, $txt;
611 633
 
612 634
 	// Choose a query depending on what we are viewing.
613
-	if ($browse_type === 'avatars')
614
-		$request = $smcFunc['db_query']('', '
635
+	if ($browse_type === 'avatars') {
636
+			$request = $smcFunc['db_query']('', '
615 637
 			SELECT
616 638
 				{string:blank_text} AS id_msg, COALESCE(mem.real_name, {string:not_applicable_text}) AS poster_name,
617 639
 				mem.last_login AS poster_time, 0 AS id_topic, a.id_member, a.id_attach, a.filename, a.file_hash, a.attachment_type,
@@ -630,8 +652,8 @@  discard block
 block discarded – undo
630 652
 				'per_page' => $items_per_page,
631 653
 			)
632 654
 		);
633
-	else
634
-		$request = $smcFunc['db_query']('', '
655
+	} else {
656
+			$request = $smcFunc['db_query']('', '
635 657
 			SELECT
636 658
 				m.id_msg, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_topic, m.id_member,
637 659
 				a.id_attach, a.filename, a.file_hash, a.attachment_type, a.size, a.width, a.height, a.downloads, mf.subject, t.id_board
@@ -650,9 +672,11 @@  discard block
 block discarded – undo
650 672
 				'per_page' => $items_per_page,
651 673
 			)
652 674
 		);
675
+	}
653 676
 	$files = array();
654
-	while ($row = $smcFunc['db_fetch_assoc']($request))
655
-		$files[] = $row;
677
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
678
+			$files[] = $row;
679
+	}
656 680
 	$smcFunc['db_free_result']($request);
657 681
 
658 682
 	return $files;
@@ -670,8 +694,8 @@  discard block
 block discarded – undo
670 694
 	global $smcFunc;
671 695
 
672 696
 	// Depending on the type of file, different queries are used.
673
-	if ($browse_type === 'avatars')
674
-		$request = $smcFunc['db_query']('', '
697
+	if ($browse_type === 'avatars') {
698
+			$request = $smcFunc['db_query']('', '
675 699
 		SELECT COUNT(*)
676 700
 		FROM {db_prefix}attachments
677 701
 		WHERE id_member != {int:guest_id_member}',
@@ -679,8 +703,8 @@  discard block
 block discarded – undo
679 703
 			'guest_id_member' => 0,
680 704
 		)
681 705
 	);
682
-	else
683
-		$request = $smcFunc['db_query']('', '
706
+	} else {
707
+			$request = $smcFunc['db_query']('', '
684 708
 			SELECT COUNT(*) AS num_attach
685 709
 			FROM {db_prefix}attachments AS a
686 710
 				INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
@@ -693,6 +717,7 @@  discard block
 block discarded – undo
693 717
 				'guest_id_member' => 0,
694 718
 			)
695 719
 		);
720
+	}
696 721
 
697 722
 	list ($num_files) = $smcFunc['db_fetch_row']($request);
698 723
 	$smcFunc['db_free_result']($request);
@@ -775,12 +800,14 @@  discard block
 block discarded – undo
775 800
 	$current_dir_size /= 1024;
776 801
 
777 802
 	// If they specified a limit only....
778
-	if (!empty($modSettings['attachmentDirSizeLimit']))
779
-		$context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2);
803
+	if (!empty($modSettings['attachmentDirSizeLimit'])) {
804
+			$context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2);
805
+	}
780 806
 	$context['attachment_current_size'] = comma_format($current_dir_size, 2);
781 807
 
782
-	if (!empty($modSettings['attachmentDirFileLimit']))
783
-		$context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0);
808
+	if (!empty($modSettings['attachmentDirFileLimit'])) {
809
+			$context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0);
810
+	}
784 811
 	$context['attachment_current_files'] = comma_format($current_dir_files, 0);
785 812
 
786 813
 	$context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false;
@@ -817,8 +844,8 @@  discard block
 block discarded – undo
817 844
 		$messages = removeAttachments(array('attachment_type' => 0, 'poster_time' => (time() - 24 * 60 * 60 * $_POST['age'])), 'messages', true);
818 845
 
819 846
 		// Update the messages to reflect the change.
820
-		if (!empty($messages) && !empty($_POST['notice']))
821
-			$smcFunc['db_query']('', '
847
+		if (!empty($messages) && !empty($_POST['notice'])) {
848
+					$smcFunc['db_query']('', '
822 849
 				UPDATE {db_prefix}messages
823 850
 				SET body = CONCAT(body, {string:notice})
824 851
 				WHERE id_msg IN ({array_int:messages})',
@@ -827,8 +854,8 @@  discard block
 block discarded – undo
827 854
 					'notice' => '<br><br>' . $_POST['notice'],
828 855
 				)
829 856
 			);
830
-	}
831
-	else
857
+		}
858
+	} else
832 859
 	{
833 860
 		// Remove all the old avatars.
834 861
 		removeAttachments(array('not_id_member' => 0, 'last_login' => (time() - 24 * 60 * 60 * $_POST['age'])), 'members');
@@ -853,8 +880,8 @@  discard block
 block discarded – undo
853 880
 	$messages = removeAttachments(array('attachment_type' => 0, 'size' => 1024 * $_POST['size']), 'messages', true);
854 881
 
855 882
 	// And make a note on the post.
856
-	if (!empty($messages) && !empty($_POST['notice']))
857
-		$smcFunc['db_query']('', '
883
+	if (!empty($messages) && !empty($_POST['notice'])) {
884
+			$smcFunc['db_query']('', '
858 885
 			UPDATE {db_prefix}messages
859 886
 			SET body = CONCAT(body, {string:notice})
860 887
 			WHERE id_msg IN ({array_int:messages})',
@@ -863,6 +890,7 @@  discard block
 block discarded – undo
863 890
 				'notice' => '<br><br>' . $_POST['notice'],
864 891
 			)
865 892
 		);
893
+	}
866 894
 
867 895
 	redirectexit('action=admin;area=manageattachments;sa=maintenance');
868 896
 }
@@ -882,16 +910,17 @@  discard block
 block discarded – undo
882 910
 	{
883 911
 		$attachments = array();
884 912
 		// There must be a quicker way to pass this safety test??
885
-		foreach ($_POST['remove'] as $removeID => $dummy)
886
-			$attachments[] = (int) $removeID;
913
+		foreach ($_POST['remove'] as $removeID => $dummy) {
914
+					$attachments[] = (int) $removeID;
915
+		}
887 916
 
888 917
 		// If the attachments are from a 3rd party, let them remove it. Hooks should remove their ids from the array.
889 918
 		$filesRemoved = false;
890 919
 		call_integration_hook('integrate_attachment_remove', array(&$filesRemoved, $attachments));
891 920
 
892
-		if ($_REQUEST['type'] == 'avatars' && !empty($attachments))
893
-			removeAttachments(array('id_attach' => $attachments));
894
-		else if (!empty($attachments))
921
+		if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) {
922
+					removeAttachments(array('id_attach' => $attachments));
923
+		} else if (!empty($attachments))
895 924
 		{
896 925
 			$messages = removeAttachments(array('id_attach' => $attachments), 'messages', true);
897 926
 
@@ -930,12 +959,13 @@  discard block
 block discarded – undo
930 959
 
931 960
 	$messages = removeAttachments(array('attachment_type' => 0), '', true);
932 961
 
933
-	if (!isset($_POST['notice']))
934
-		$_POST['notice'] = $txt['attachment_delete_admin'];
962
+	if (!isset($_POST['notice'])) {
963
+			$_POST['notice'] = $txt['attachment_delete_admin'];
964
+	}
935 965
 
936 966
 	// Add the notice on the end of the changed messages.
937
-	if (!empty($messages))
938
-		$smcFunc['db_query']('', '
967
+	if (!empty($messages)) {
968
+			$smcFunc['db_query']('', '
939 969
 			UPDATE {db_prefix}messages
940 970
 			SET body = CONCAT(body, {string:deleted_message})
941 971
 			WHERE id_msg IN ({array_int:messages})',
@@ -944,6 +974,7 @@  discard block
 block discarded – undo
944 974
 				'deleted_message' => '<br><br>' . $_POST['notice'],
945 975
 			)
946 976
 		);
977
+	}
947 978
 
948 979
 	redirectexit('action=admin;area=manageattachments;sa=maintenance');
949 980
 }
@@ -982,24 +1013,26 @@  discard block
 block discarded – undo
982 1013
 			$is_not = substr($real_type, 0, 4) == 'not_';
983 1014
 			$type = $is_not ? substr($real_type, 4) : $real_type;
984 1015
 
985
-			if (in_array($type, array('id_member', 'id_attach', 'id_msg')))
986
-				$new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
987
-			elseif ($type == 'attachment_type')
988
-				$new_condition[] = 'a.attachment_type = {int:' . $real_type . '}';
989
-			elseif ($type == 'poster_time')
990
-				$new_condition[] = 'm.poster_time < {int:' . $real_type . '}';
991
-			elseif ($type == 'last_login')
992
-				$new_condition[] = 'mem.last_login < {int:' . $real_type . '}';
993
-			elseif ($type == 'size')
994
-				$new_condition[] = 'a.size > {int:' . $real_type . '}';
995
-			elseif ($type == 'id_topic')
996
-				$new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
1016
+			if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) {
1017
+							$new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
1018
+			} elseif ($type == 'attachment_type') {
1019
+							$new_condition[] = 'a.attachment_type = {int:' . $real_type . '}';
1020
+			} elseif ($type == 'poster_time') {
1021
+							$new_condition[] = 'm.poster_time < {int:' . $real_type . '}';
1022
+			} elseif ($type == 'last_login') {
1023
+							$new_condition[] = 'mem.last_login < {int:' . $real_type . '}';
1024
+			} elseif ($type == 'size') {
1025
+							$new_condition[] = 'a.size > {int:' . $real_type . '}';
1026
+			} elseif ($type == 'id_topic') {
1027
+							$new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
1028
+			}
997 1029
 
998 1030
 			// Add the parameter!
999 1031
 			$query_parameter[$real_type] = $restriction;
1000 1032
 
1001
-			if ($type == 'do_logging')
1002
-				$do_logging = $condition['id_attach'];
1033
+			if ($type == 'do_logging') {
1034
+							$do_logging = $condition['id_attach'];
1035
+			}
1003 1036
 		}
1004 1037
 		$condition = implode(' AND ', $new_condition);
1005 1038
 	}
@@ -1031,15 +1064,15 @@  discard block
 block discarded – undo
1031 1064
 			// wasn't it obvious? :P
1032 1065
 			// @todo look again at this.
1033 1066
 			@unlink($modSettings['custom_avatar_dir'] . '/' . $row['filename']);
1034
-		}
1035
-		else
1067
+		} else
1036 1068
 		{
1037 1069
 			$filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
1038 1070
 			@unlink($filename);
1039 1071
 
1040 1072
 			// If this was a thumb, the parent attachment should know about it.
1041
-			if (!empty($row['id_parent']))
1042
-				$parents[] = $row['id_parent'];
1073
+			if (!empty($row['id_parent'])) {
1074
+							$parents[] = $row['id_parent'];
1075
+			}
1043 1076
 
1044 1077
 			// If this attachments has a thumb, remove it as well.
1045 1078
 			if (!empty($row['id_thumb']) && $autoThumbRemoval)
@@ -1051,8 +1084,9 @@  discard block
 block discarded – undo
1051 1084
 		}
1052 1085
 
1053 1086
 		// Make a list.
1054
-		if ($return_affected_messages && empty($row['attachment_type']))
1055
-			$msgs[] = $row['id_msg'];
1087
+		if ($return_affected_messages && empty($row['attachment_type'])) {
1088
+					$msgs[] = $row['id_msg'];
1089
+		}
1056 1090
 
1057 1091
 		$attach[] = $row['id_attach'];
1058 1092
 	}
@@ -1060,8 +1094,8 @@  discard block
 block discarded – undo
1060 1094
 
1061 1095
 	// Removed attachments don't have to be updated anymore.
1062 1096
 	$parents = array_diff($parents, $attach);
1063
-	if (!empty($parents))
1064
-		$smcFunc['db_query']('', '
1097
+	if (!empty($parents)) {
1098
+			$smcFunc['db_query']('', '
1065 1099
 			UPDATE {db_prefix}attachments
1066 1100
 			SET id_thumb = {int:no_thumb}
1067 1101
 			WHERE id_attach IN ({array_int:parent_attachments})',
@@ -1070,6 +1104,7 @@  discard block
 block discarded – undo
1070 1104
 				'no_thumb' => 0,
1071 1105
 			)
1072 1106
 		);
1107
+	}
1073 1108
 
1074 1109
 	if (!empty($do_logging))
1075 1110
 	{
@@ -1086,31 +1121,34 @@  discard block
 block discarded – undo
1086 1121
 			)
1087 1122
 		);
1088 1123
 
1089
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1090
-			logAction(
1124
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1125
+					logAction(
1091 1126
 				'remove_attach',
1092 1127
 				array(
1093 1128
 					'message' => $row['id_msg'],
1094 1129
 					'filename' => preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])),
1095 1130
 				)
1096 1131
 			);
1132
+		}
1097 1133
 		$smcFunc['db_free_result']($request);
1098 1134
 	}
1099 1135
 
1100
-	if (!empty($attach))
1101
-		$smcFunc['db_query']('', '
1136
+	if (!empty($attach)) {
1137
+			$smcFunc['db_query']('', '
1102 1138
 			DELETE FROM {db_prefix}attachments
1103 1139
 			WHERE id_attach IN ({array_int:attachment_list})',
1104 1140
 			array(
1105 1141
 				'attachment_list' => $attach,
1106 1142
 			)
1107 1143
 		);
1144
+	}
1108 1145
 
1109 1146
 	call_integration_hook('integrate_remove_attachments', array($attach));
1110 1147
 
1111
-	if ($return_affected_messages)
1112
-		return array_unique($msgs);
1113
-}
1148
+	if ($return_affected_messages) {
1149
+			return array_unique($msgs);
1150
+	}
1151
+	}
1114 1152
 
1115 1153
 /**
1116 1154
  * This function should find attachments in the database that no longer exist and clear them, and fix filesize issues.
@@ -1122,8 +1160,9 @@  discard block
 block discarded – undo
1122 1160
 	checkSession('get');
1123 1161
 
1124 1162
 	// If we choose cancel, redirect right back.
1125
-	if (isset($_POST['cancel']))
1126
-		redirectexit('action=admin;area=manageattachments;sa=maintenance');
1163
+	if (isset($_POST['cancel'])) {
1164
+			redirectexit('action=admin;area=manageattachments;sa=maintenance');
1165
+	}
1127 1166
 
1128 1167
 	// Try give us a while to sort this out...
1129 1168
 	@set_time_limit(600);
@@ -1140,13 +1179,15 @@  discard block
 block discarded – undo
1140 1179
 		if (isset($_GET['fixErrors']))
1141 1180
 		{
1142 1181
 			// Nothing?
1143
-			if (empty($_POST['to_fix']))
1144
-				redirectexit('action=admin;area=manageattachments;sa=maintenance');
1182
+			if (empty($_POST['to_fix'])) {
1183
+							redirectexit('action=admin;area=manageattachments;sa=maintenance');
1184
+			}
1145 1185
 
1146 1186
 			$_SESSION['attachments_to_fix'] = array();
1147 1187
 			// @todo No need to do this I think.
1148
-			foreach ($_POST['to_fix'] as $value)
1149
-				$_SESSION['attachments_to_fix'][] = $value;
1188
+			foreach ($_POST['to_fix'] as $value) {
1189
+							$_SESSION['attachments_to_fix'][] = $value;
1190
+			}
1150 1191
 		}
1151 1192
 	}
1152 1193
 
@@ -1213,13 +1254,14 @@  discard block
 block discarded – undo
1213 1254
 					}
1214 1255
 				}
1215 1256
 			}
1216
-			if ($smcFunc['db_num_rows']($result) != 0)
1217
-				$to_fix[] = 'missing_thumbnail_parent';
1257
+			if ($smcFunc['db_num_rows']($result) != 0) {
1258
+							$to_fix[] = 'missing_thumbnail_parent';
1259
+			}
1218 1260
 			$smcFunc['db_free_result']($result);
1219 1261
 
1220 1262
 			// Do we need to delete what we have?
1221
-			if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix))
1222
-				$smcFunc['db_query']('', '
1263
+			if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) {
1264
+							$smcFunc['db_query']('', '
1223 1265
 					DELETE FROM {db_prefix}attachments
1224 1266
 					WHERE id_attach IN ({array_int:to_remove})
1225 1267
 						AND attachment_type = {int:attachment_type}',
@@ -1228,6 +1270,7 @@  discard block
 block discarded – undo
1228 1270
 						'attachment_type' => 3,
1229 1271
 					)
1230 1272
 				);
1273
+			}
1231 1274
 
1232 1275
 			pauseAttachmentMaintenance($to_fix, $thumbnails);
1233 1276
 		}
@@ -1272,13 +1315,14 @@  discard block
 block discarded – undo
1272 1315
 				$to_update[] = $row['id_attach'];
1273 1316
 				$context['repair_errors']['parent_missing_thumbnail']++;
1274 1317
 			}
1275
-			if ($smcFunc['db_num_rows']($result) != 0)
1276
-				$to_fix[] = 'parent_missing_thumbnail';
1318
+			if ($smcFunc['db_num_rows']($result) != 0) {
1319
+							$to_fix[] = 'parent_missing_thumbnail';
1320
+			}
1277 1321
 			$smcFunc['db_free_result']($result);
1278 1322
 
1279 1323
 			// Do we need to delete what we have?
1280
-			if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix))
1281
-				$smcFunc['db_query']('', '
1324
+			if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) {
1325
+							$smcFunc['db_query']('', '
1282 1326
 					UPDATE {db_prefix}attachments
1283 1327
 					SET id_thumb = {int:no_thumb}
1284 1328
 					WHERE id_attach IN ({array_int:to_update})',
@@ -1287,6 +1331,7 @@  discard block
 block discarded – undo
1287 1331
 						'no_thumb' => 0,
1288 1332
 					)
1289 1333
 				);
1334
+			}
1290 1335
 
1291 1336
 			pauseAttachmentMaintenance($to_fix, $thumbnails);
1292 1337
 		}
@@ -1324,10 +1369,11 @@  discard block
 block discarded – undo
1324 1369
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1325 1370
 			{
1326 1371
 				// Get the filename.
1327
-				if ($row['attachment_type'] == 1)
1328
-					$filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename'];
1329
-				else
1330
-					$filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
1372
+				if ($row['attachment_type'] == 1) {
1373
+									$filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename'];
1374
+				} else {
1375
+									$filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
1376
+				}
1331 1377
 
1332 1378
 				// File doesn't exist?
1333 1379
 				if (!file_exists($filename))
@@ -1339,15 +1385,16 @@  discard block
 block discarded – undo
1339 1385
 						$attachment_name = $row['id_attach'] . '_' . $row['file_hash'] . '.dat';
1340 1386
 
1341 1387
 						// Loop through the other folders.
1342
-						foreach ($modSettings['attachmentUploadDir'] as $id => $dir)
1343
-							if (file_exists($dir . '/' . $attachment_name))
1388
+						foreach ($modSettings['attachmentUploadDir'] as $id => $dir) {
1389
+													if (file_exists($dir . '/' . $attachment_name))
1344 1390
 							{
1345 1391
 								$context['repair_errors']['wrong_folder']++;
1392
+						}
1346 1393
 								$errors_found[] = 'wrong_folder';
1347 1394
 
1348 1395
 								// Are we going to fix this now?
1349
-								if ($fix_errors && in_array('wrong_folder', $to_fix))
1350
-									$smcFunc['db_query']('', '
1396
+								if ($fix_errors && in_array('wrong_folder', $to_fix)) {
1397
+																	$smcFunc['db_query']('', '
1351 1398
 										UPDATE {db_prefix}attachments
1352 1399
 										SET id_folder = {int:new_folder}
1353 1400
 										WHERE id_attach = {int:id_attach}',
@@ -1356,6 +1403,7 @@  discard block
 block discarded – undo
1356 1403
 											'id_attach' => $row['id_attach'],
1357 1404
 										)
1358 1405
 									);
1406
+								}
1359 1407
 
1360 1408
 								continue 2;
1361 1409
 							}
@@ -1364,8 +1412,7 @@  discard block
 block discarded – undo
1364 1412
 					$to_remove[] = $row['id_attach'];
1365 1413
 					$context['repair_errors']['file_missing_on_disk']++;
1366 1414
 					$errors_found[] = 'file_missing_on_disk';
1367
-				}
1368
-				elseif (filesize($filename) == 0)
1415
+				} elseif (filesize($filename) == 0)
1369 1416
 				{
1370 1417
 					$context['repair_errors']['file_size_of_zero']++;
1371 1418
 					$errors_found[] = 'file_size_of_zero';
@@ -1376,8 +1423,7 @@  discard block
 block discarded – undo
1376 1423
 						$to_remove[] = $row['id_attach'];
1377 1424
 						@unlink($filename);
1378 1425
 					}
1379
-				}
1380
-				elseif (filesize($filename) != $row['size'])
1426
+				} elseif (filesize($filename) != $row['size'])
1381 1427
 				{
1382 1428
 					$context['repair_errors']['file_wrong_size']++;
1383 1429
 					$errors_found[] = 'file_wrong_size';
@@ -1398,14 +1444,18 @@  discard block
 block discarded – undo
1398 1444
 				}
1399 1445
 			}
1400 1446
 
1401
-			if (in_array('file_missing_on_disk', $errors_found))
1402
-				$to_fix[] = 'file_missing_on_disk';
1403
-			if (in_array('file_size_of_zero', $errors_found))
1404
-				$to_fix[] = 'file_size_of_zero';
1405
-			if (in_array('file_wrong_size', $errors_found))
1406
-				$to_fix[] = 'file_wrong_size';
1407
-			if (in_array('wrong_folder', $errors_found))
1408
-				$to_fix[] = 'wrong_folder';
1447
+			if (in_array('file_missing_on_disk', $errors_found)) {
1448
+							$to_fix[] = 'file_missing_on_disk';
1449
+			}
1450
+			if (in_array('file_size_of_zero', $errors_found)) {
1451
+							$to_fix[] = 'file_size_of_zero';
1452
+			}
1453
+			if (in_array('file_wrong_size', $errors_found)) {
1454
+							$to_fix[] = 'file_wrong_size';
1455
+			}
1456
+			if (in_array('wrong_folder', $errors_found)) {
1457
+							$to_fix[] = 'wrong_folder';
1458
+			}
1409 1459
 			$smcFunc['db_free_result']($result);
1410 1460
 
1411 1461
 			// Do we need to delete what we have?
@@ -1475,20 +1525,22 @@  discard block
 block discarded – undo
1475 1525
 				// If we are repairing remove the file from disk now.
1476 1526
 				if ($fix_errors && in_array('avatar_no_member', $to_fix))
1477 1527
 				{
1478
-					if ($row['attachment_type'] == 1)
1479
-						$filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename'];
1480
-					else
1481
-						$filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
1528
+					if ($row['attachment_type'] == 1) {
1529
+											$filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename'];
1530
+					} else {
1531
+											$filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
1532
+					}
1482 1533
 					@unlink($filename);
1483 1534
 				}
1484 1535
 			}
1485
-			if ($smcFunc['db_num_rows']($result) != 0)
1486
-				$to_fix[] = 'avatar_no_member';
1536
+			if ($smcFunc['db_num_rows']($result) != 0) {
1537
+							$to_fix[] = 'avatar_no_member';
1538
+			}
1487 1539
 			$smcFunc['db_free_result']($result);
1488 1540
 
1489 1541
 			// Do we need to delete what we have?
1490
-			if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix))
1491
-				$smcFunc['db_query']('', '
1542
+			if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) {
1543
+							$smcFunc['db_query']('', '
1492 1544
 					DELETE FROM {db_prefix}attachments
1493 1545
 					WHERE id_attach IN ({array_int:to_remove})
1494 1546
 						AND id_member != {int:no_member}
@@ -1499,6 +1551,7 @@  discard block
 block discarded – undo
1499 1551
 						'no_msg' => 0,
1500 1552
 					)
1501 1553
 				);
1554
+			}
1502 1555
 
1503 1556
 			pauseAttachmentMaintenance($to_fix, $thumbnails);
1504 1557
 		}
@@ -1554,13 +1607,14 @@  discard block
 block discarded – undo
1554 1607
 					@unlink($filename);
1555 1608
 				}
1556 1609
 			}
1557
-			if ($smcFunc['db_num_rows']($result) != 0)
1558
-				$to_fix[] = 'attachment_no_msg';
1610
+			if ($smcFunc['db_num_rows']($result) != 0) {
1611
+							$to_fix[] = 'attachment_no_msg';
1612
+			}
1559 1613
 			$smcFunc['db_free_result']($result);
1560 1614
 
1561 1615
 			// Do we need to delete what we have?
1562
-			if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix))
1563
-				$smcFunc['db_query']('', '
1616
+			if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) {
1617
+							$smcFunc['db_query']('', '
1564 1618
 					DELETE FROM {db_prefix}attachments
1565 1619
 					WHERE id_attach IN ({array_int:to_remove})
1566 1620
 						AND id_member = {int:no_member}
@@ -1571,6 +1625,7 @@  discard block
 block discarded – undo
1571 1625
 						'no_msg' => 0,
1572 1626
 					)
1573 1627
 				);
1628
+			}
1574 1629
 
1575 1630
 			pauseAttachmentMaintenance($to_fix, $thumbnails);
1576 1631
 		}
@@ -1594,8 +1649,9 @@  discard block
 block discarded – undo
1594 1649
 			{
1595 1650
 				while ($file = readdir($dir))
1596 1651
 				{
1597
-					if (in_array($file, array('.', '..', '.htaccess', 'index.php')))
1598
-						continue;
1652
+					if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) {
1653
+											continue;
1654
+					}
1599 1655
 
1600 1656
 					if ($files_checked <= $current_check)
1601 1657
 					{
@@ -1603,8 +1659,9 @@  discard block
 block discarded – undo
1603 1659
 						if (strpos($file, 'post_tmp_') !== false)
1604 1660
 						{
1605 1661
 							// Temp file is more than 5 hours old!
1606
-							if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1607
-								@unlink($attach_dir . '/' . $file);
1662
+							if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1663
+															@unlink($attach_dir . '/' . $file);
1664
+							}
1608 1665
 						}
1609 1666
 						// That should be an attachment, let's check if we have it in the database
1610 1667
 						elseif (strpos($file, '_') !== false)
@@ -1626,8 +1683,7 @@  discard block
 block discarded – undo
1626 1683
 									if ($fix_errors && in_array('files_without_attachment', $to_fix))
1627 1684
 									{
1628 1685
 										@unlink($attach_dir . '/' . $file);
1629
-									}
1630
-									else
1686
+									} else
1631 1687
 									{
1632 1688
 										$context['repair_errors']['files_without_attachment']++;
1633 1689
 										$to_fix[] = 'files_without_attachment';
@@ -1635,14 +1691,12 @@  discard block
 block discarded – undo
1635 1691
 								}
1636 1692
 								$smcFunc['db_free_result']($request);
1637 1693
 							}
1638
-						}
1639
-						else
1694
+						} else
1640 1695
 						{
1641 1696
 							if ($fix_errors && in_array('files_without_attachment', $to_fix))
1642 1697
 							{
1643 1698
 								@unlink($attach_dir . '/' . $file);
1644
-							}
1645
-							else
1699
+							} else
1646 1700
 							{
1647 1701
 								$context['repair_errors']['files_without_attachment']++;
1648 1702
 								$to_fix[] = 'files_without_attachment';
@@ -1651,8 +1705,9 @@  discard block
 block discarded – undo
1651 1705
 					}
1652 1706
 					$current_check++;
1653 1707
 					$_GET['substep'] = $current_check;
1654
-					if ($current_check - $files_checked >= $max_checks)
1655
-						pauseAttachmentMaintenance($to_fix);
1708
+					if ($current_check - $files_checked >= $max_checks) {
1709
+											pauseAttachmentMaintenance($to_fix);
1710
+					}
1656 1711
 				}
1657 1712
 				closedir($dir);
1658 1713
 			}
@@ -1688,12 +1743,14 @@  discard block
 block discarded – undo
1688 1743
 
1689 1744
 	// Try get more time...
1690 1745
 	@set_time_limit(600);
1691
-	if (function_exists('apache_reset_timeout'))
1692
-		@apache_reset_timeout();
1746
+	if (function_exists('apache_reset_timeout')) {
1747
+			@apache_reset_timeout();
1748
+	}
1693 1749
 
1694 1750
 	// Have we already used our maximum time?
1695
-	if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep'])
1696
-		return;
1751
+	if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) {
1752
+			return;
1753
+	}
1697 1754
 
1698 1755
 	$context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1699 1756
 	$context['page_title'] = $txt['not_done_title'];
@@ -1705,10 +1762,11 @@  discard block
 block discarded – undo
1705 1762
 	$context[$context['admin_menu_name']]['current_subsection'] = 'maintenance';
1706 1763
 
1707 1764
 	// Change these two if more steps are added!
1708
-	if (empty($max_substep))
1709
-		$context['continue_percent'] = round(($_GET['step'] * 100) / 25);
1710
-	else
1711
-		$context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25);
1765
+	if (empty($max_substep)) {
1766
+			$context['continue_percent'] = round(($_GET['step'] * 100) / 25);
1767
+	} else {
1768
+			$context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25);
1769
+	}
1712 1770
 
1713 1771
 	// Never more than 100%!
1714 1772
 	$context['continue_percent'] = min($context['continue_percent'], 100);
@@ -1750,15 +1808,17 @@  discard block
 block discarded – undo
1750 1808
 				'attachment_type' => 0,
1751 1809
 			)
1752 1810
 		);
1753
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1754
-			$attachments[] = $row['id_attach'];
1811
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1812
+					$attachments[] = $row['id_attach'];
1813
+		}
1755 1814
 		$smcFunc['db_free_result']($request);
1815
+	} elseif (!empty($_GET['aid'])) {
1816
+			$attachments[] = (int) $_GET['aid'];
1756 1817
 	}
1757
-	elseif (!empty($_GET['aid']))
1758
-		$attachments[] = (int) $_GET['aid'];
1759 1818
 
1760
-	if (empty($attachments))
1761
-		fatal_lang_error('no_access', false);
1819
+	if (empty($attachments)) {
1820
+			fatal_lang_error('no_access', false);
1821
+	}
1762 1822
 
1763 1823
 	// Now we have some ID's cleaned and ready to approve, but first - let's check we have permission!
1764 1824
 	$allowed_boards = boardsAllowedTo('approve_posts');
@@ -1791,17 +1851,18 @@  discard block
 block discarded – undo
1791 1851
 	}
1792 1852
 	$smcFunc['db_free_result']($request);
1793 1853
 
1794
-	if (empty($attachments))
1795
-		fatal_lang_error('no_access', false);
1854
+	if (empty($attachments)) {
1855
+			fatal_lang_error('no_access', false);
1856
+	}
1796 1857
 
1797 1858
 	// Finally, we are there. Follow through!
1798 1859
 	if ($is_approve)
1799 1860
 	{
1800 1861
 		// Checked and deemed worthy.
1801 1862
 		ApproveAttachments($attachments);
1863
+	} else {
1864
+			removeAttachments(array('id_attach' => $attachments, 'do_logging' => true));
1802 1865
 	}
1803
-	else
1804
-		removeAttachments(array('id_attach' => $attachments, 'do_logging' => true));
1805 1866
 
1806 1867
 	// Return to the topic....
1807 1868
 	redirectexit($redirect);
@@ -1817,8 +1878,9 @@  discard block
 block discarded – undo
1817 1878
 {
1818 1879
 	global $smcFunc;
1819 1880
 
1820
-	if (empty($attachments))
1821
-		return 0;
1881
+	if (empty($attachments)) {
1882
+			return 0;
1883
+	}
1822 1884
 
1823 1885
 	// For safety, check for thumbnails...
1824 1886
 	$request = $smcFunc['db_query']('', '
@@ -1837,15 +1899,17 @@  discard block
 block discarded – undo
1837 1899
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1838 1900
 	{
1839 1901
 		// Update the thumbnail too...
1840
-		if (!empty($row['id_thumb']))
1841
-			$attachments[] = $row['id_thumb'];
1902
+		if (!empty($row['id_thumb'])) {
1903
+					$attachments[] = $row['id_thumb'];
1904
+		}
1842 1905
 
1843 1906
 		$attachments[] = $row['id_attach'];
1844 1907
 	}
1845 1908
 	$smcFunc['db_free_result']($request);
1846 1909
 
1847
-	if (empty($attachments))
1848
-		return 0;
1910
+	if (empty($attachments)) {
1911
+			return 0;
1912
+	}
1849 1913
 
1850 1914
 	// Approving an attachment is not hard - it's easy.
1851 1915
 	$smcFunc['db_query']('', '
@@ -1871,14 +1935,15 @@  discard block
 block discarded – undo
1871 1935
 		)
1872 1936
 	);
1873 1937
 
1874
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1875
-		logAction(
1938
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1939
+			logAction(
1876 1940
 			'approve_attach',
1877 1941
 			array(
1878 1942
 				'message' => $row['id_msg'],
1879 1943
 				'filename' => preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])),
1880 1944
 			)
1881 1945
 		);
1946
+	}
1882 1947
 	$smcFunc['db_free_result']($request);
1883 1948
 
1884 1949
 	// Remove from the approval queue.
@@ -1901,11 +1966,11 @@  discard block
 block discarded – undo
1901 1966
 	global $modSettings, $scripturl, $context, $txt, $sourcedir, $boarddir, $smcFunc, $settings;
1902 1967
 
1903 1968
 	// Since this needs to be done eventually.
1904
-	if (!isset($modSettings['attachment_basedirectories']))
1905
-		$modSettings['attachment_basedirectories'] = array();
1906
-
1907
-	elseif (!is_array($modSettings['attachment_basedirectories']))
1908
-		$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
1969
+	if (!isset($modSettings['attachment_basedirectories'])) {
1970
+			$modSettings['attachment_basedirectories'] = array();
1971
+	} elseif (!is_array($modSettings['attachment_basedirectories'])) {
1972
+			$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
1973
+	}
1909 1974
 
1910 1975
 	$errors = array();
1911 1976
 
@@ -1920,8 +1985,9 @@  discard block
 block discarded – undo
1920 1985
 		{
1921 1986
 			$error = '';
1922 1987
 			$id = (int) $id;
1923
-			if ($id < 1)
1924
-				continue;
1988
+			if ($id < 1) {
1989
+							continue;
1990
+			}
1925 1991
 
1926 1992
 			// Sorry, these dirs are NOT valid
1927 1993
 			$invalid_dirs = array($boarddir, $settings['default_theme_dir'], $sourcedir);
@@ -1940,8 +2006,7 @@  discard block
 block discarded – undo
1940 2006
 				{
1941 2007
 						$errors[] = $path . ': ' . $txt['attach_dir_duplicate_msg'];
1942 2008
 						continue;
1943
-				}
1944
-				elseif (empty($path))
2009
+				} elseif (empty($path))
1945 2010
 				{
1946 2011
 					// Ignore this and set $id to one less
1947 2012
 					continue;
@@ -1949,10 +2014,11 @@  discard block
 block discarded – undo
1949 2014
 
1950 2015
 				// OK, so let's try to create it then.
1951 2016
 				require_once($sourcedir . '/Subs-Attachments.php');
1952
-				if (automanage_attachments_create_directory($path))
1953
-					$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
1954
-				else
1955
-					$errors[] = $path . ': ' . $txt[$context['dir_creation_error']];
2017
+				if (automanage_attachments_create_directory($path)) {
2018
+									$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
2019
+				} else {
2020
+									$errors[] = $path . ': ' . $txt[$context['dir_creation_error']];
2021
+				}
1956 2022
 			}
1957 2023
 
1958 2024
 			// Changing a directory name?
@@ -1965,8 +2031,7 @@  discard block
 block discarded – undo
1965 2031
 						$errors[] = $path . ': ' . $txt['attach_dir_no_rename'];
1966 2032
 						$path = $modSettings['attachmentUploadDir'][$id];
1967 2033
 					}
1968
-				}
1969
-				else
2034
+				} else
1970 2035
 				{
1971 2036
 					$errors[] = $path . ': ' . $txt['attach_dir_exists_msg'];
1972 2037
 					$path = $modSettings['attachmentUploadDir'][$id];
@@ -1991,12 +2056,13 @@  discard block
 block discarded – undo
1991 2056
 				$path = $modSettings['attachmentUploadDir'][$id];
1992 2057
 
1993 2058
 				// It's not a good idea to delete the current directory.
1994
-				if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir']))
1995
-					$errors[] = $path . ': ' . $txt['attach_dir_is_current'];
2059
+				if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) {
2060
+									$errors[] = $path . ': ' . $txt['attach_dir_is_current'];
2061
+				}
1996 2062
 				// Or the current base directory
1997
-				elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id])
1998
-					$errors[] = $path . ': ' . $txt['attach_dir_is_current_bd'];
1999
-				else
2063
+				elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) {
2064
+									$errors[] = $path . ': ' . $txt['attach_dir_is_current_bd'];
2065
+				} else
2000 2066
 				{
2001 2067
 					// Let's not try to delete a path with files in it.
2002 2068
 					$request = $smcFunc['db_query']('', '
@@ -2015,17 +2081,18 @@  discard block
 block discarded – undo
2015 2081
 					if (!empty($modSettings['attachment_basedirectories']))
2016 2082
 					{
2017 2083
 						// Count any sub-folders.
2018
-						foreach ($modSettings['attachmentUploadDir'] as $sub)
2019
-							if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false)
2084
+						foreach ($modSettings['attachmentUploadDir'] as $sub) {
2085
+													if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false)
2020 2086
 								$num_attach++;
2087
+						}
2021 2088
 					}
2022 2089
 
2023 2090
 					// It's safe to delete. So try to delete the folder also
2024 2091
 					if ($num_attach == 0)
2025 2092
 					{
2026
-						if (is_dir($path))
2027
-							$doit = true;
2028
-						elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path))
2093
+						if (is_dir($path)) {
2094
+													$doit = true;
2095
+						} elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path))
2029 2096
 						{
2030 2097
 							$doit = true;
2031 2098
 							$path = $boarddir . DIRECTORY_SEPARATOR . $path;
@@ -2035,8 +2102,9 @@  discard block
 block discarded – undo
2035 2102
 						{
2036 2103
 							unlink($path . '/.htaccess');
2037 2104
 							unlink($path . '/index.php');
2038
-							if (!@rmdir($path))
2039
-								$error = $path . ': ' . $txt['attach_dir_no_delete'];
2105
+							if (!@rmdir($path)) {
2106
+															$error = $path . ': ' . $txt['attach_dir_no_delete'];
2107
+							}
2040 2108
 						}
2041 2109
 
2042 2110
 						// Remove it from the base directory list.
@@ -2046,14 +2114,15 @@  discard block
 block discarded – undo
2046 2114
 							updateSettings(array('attachment_basedirectories' => json_encode($modSettings['attachment_basedirectories'])));
2047 2115
 							$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
2048 2116
 						}
2117
+					} else {
2118
+											$error = $path . ': ' . $txt['attach_dir_no_remove'];
2049 2119
 					}
2050
-					else
2051
-						$error = $path . ': ' . $txt['attach_dir_no_remove'];
2052 2120
 
2053
-					if (empty($error))
2054
-						continue;
2055
-					else
2056
-						$errors[] = $error;
2121
+					if (empty($error)) {
2122
+											continue;
2123
+					} else {
2124
+											$errors[] = $error;
2125
+					}
2057 2126
 				}
2058 2127
 			}
2059 2128
 
@@ -2061,23 +2130,26 @@  discard block
 block discarded – undo
2061 2130
 		}
2062 2131
 
2063 2132
 		// We need to make sure the current directory is right.
2064
-		if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir']))
2065
-			$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
2133
+		if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) {
2134
+					$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
2135
+		}
2066 2136
 
2067 2137
 		// Find the current directory if there's no value carried,
2068 2138
 		if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']]))
2069 2139
 		{
2070
-			if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir']))
2071
-				$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
2072
-			else
2073
-				$_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir']));
2140
+			if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) {
2141
+							$_POST['current_dir'] = $modSettings['currentAttachmentUploadDir'];
2142
+			} else {
2143
+							$_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir']));
2144
+			}
2074 2145
 		}
2075 2146
 
2076 2147
 		// If the user wishes to go back, update the last_dir array
2077 2148
 		if ($_POST['current_dir'] != $modSettings['currentAttachmentUploadDir'] && !empty($modSettings['last_attachments_directory']) && (isset($modSettings['last_attachments_directory'][$_POST['current_dir']]) || isset($modSettings['last_attachments_directory'][0])))
2078 2149
 		{
2079
-			if (!is_array($modSettings['last_attachments_directory']))
2080
-				$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
2150
+			if (!is_array($modSettings['last_attachments_directory'])) {
2151
+							$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
2152
+			}
2081 2153
 			$num = substr(strrchr($modSettings['attachmentUploadDir'][$_POST['current_dir']], '_'), 1);
2082 2154
 
2083 2155
 			if (is_numeric($num))
@@ -2085,16 +2157,18 @@  discard block
 block discarded – undo
2085 2157
 				// Need to find the base folder.
2086 2158
 				$bid = -1;
2087 2159
 				$use_subdirectories_for_attachments = 0;
2088
-				if (!empty($modSettings['attachment_basedirectories']))
2089
-					foreach ($modSettings['attachment_basedirectories'] as $bid => $base)
2160
+				if (!empty($modSettings['attachment_basedirectories'])) {
2161
+									foreach ($modSettings['attachment_basedirectories'] as $bid => $base)
2090 2162
 						if (strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $base . DIRECTORY_SEPARATOR) !== false)
2091 2163
 						{
2092 2164
 							$use_subdirectories_for_attachments = 1;
2165
+				}
2093 2166
 							break;
2094 2167
 						}
2095 2168
 
2096
-				if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false)
2097
-					$bid = 0;
2169
+				if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) {
2170
+									$bid = 0;
2171
+				}
2098 2172
 
2099 2173
 				$modSettings['last_attachments_directory'][$bid] = (int) $num;
2100 2174
 				$modSettings['basedirectory_for_attachments'] = !empty($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : '';
@@ -2113,8 +2187,8 @@  discard block
 block discarded – undo
2113 2187
 			// We might need to reset the paths. This loop will just loop through once.
2114 2188
 			foreach ($new_dirs as $id => $dir)
2115 2189
 			{
2116
-				if ($id != 1)
2117
-					$smcFunc['db_query']('', '
2190
+				if ($id != 1) {
2191
+									$smcFunc['db_query']('', '
2118 2192
 						UPDATE {db_prefix}attachments
2119 2193
 						SET id_folder = {int:default_folder}
2120 2194
 						WHERE id_folder = {int:current_folder}',
@@ -2123,14 +2197,14 @@  discard block
 block discarded – undo
2123 2197
 							'current_folder' => $id,
2124 2198
 						)
2125 2199
 					);
2200
+				}
2126 2201
 
2127 2202
 				$update = array(
2128 2203
 					'currentAttachmentUploadDir' => 1,
2129 2204
 					'attachmentUploadDir' => json_encode(array(1 => $dir)),
2130 2205
 				);
2131 2206
 			}
2132
-		}
2133
-		else
2207
+		} else
2134 2208
 		{
2135 2209
 			// Save it to the database.
2136 2210
 			$update = array(
@@ -2139,11 +2213,13 @@  discard block
 block discarded – undo
2139 2213
 			);
2140 2214
 		}
2141 2215
 
2142
-		if (!empty($update))
2143
-			updateSettings($update);
2216
+		if (!empty($update)) {
2217
+					updateSettings($update);
2218
+		}
2144 2219
 
2145
-		if (!empty($errors))
2146
-			$_SESSION['errors']['dir'] = $errors;
2220
+		if (!empty($errors)) {
2221
+					$_SESSION['errors']['dir'] = $errors;
2222
+		}
2147 2223
 
2148 2224
 		redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']);
2149 2225
 	}
@@ -2157,10 +2233,11 @@  discard block
 block discarded – undo
2157 2233
 		$_POST['current_base_dir'] = isset($_POST['current_base_dir']) ? (int) $_POST['current_base_dir'] : 1;
2158 2234
 		if (empty($_POST['new_base_dir']) && !empty($_POST['current_base_dir']))
2159 2235
 		{
2160
-			if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']])
2161
-				$update = (array(
2236
+			if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) {
2237
+							$update = (array(
2162 2238
 					'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']],
2163 2239
 				));
2240
+			}
2164 2241
 		}
2165 2242
 
2166 2243
 		if (isset($_POST['base_dir']))
@@ -2208,13 +2285,15 @@  discard block
 block discarded – undo
2208 2285
 
2209 2286
 			if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir']))
2210 2287
 			{
2211
-				if (!automanage_attachments_create_directory($_POST['new_base_dir']))
2212
-					$errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create'];
2288
+				if (!automanage_attachments_create_directory($_POST['new_base_dir'])) {
2289
+									$errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create'];
2290
+				}
2213 2291
 			}
2214 2292
 
2215 2293
 			$modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], $modSettings['attachmentUploadDir']);
2216
-			if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories']))
2217
-				$modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir'];
2294
+			if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) {
2295
+							$modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir'];
2296
+			}
2218 2297
 			ksort($modSettings['attachment_basedirectories']);
2219 2298
 
2220 2299
 			$update = (array(
@@ -2224,11 +2303,13 @@  discard block
 block discarded – undo
2224 2303
 			));
2225 2304
 		}
2226 2305
 
2227
-		if (!empty($errors))
2228
-			$_SESSION['errors']['base'] = $errors;
2306
+		if (!empty($errors)) {
2307
+					$_SESSION['errors']['base'] = $errors;
2308
+		}
2229 2309
 
2230
-		if (!empty($update))
2231
-			updateSettings($update);
2310
+		if (!empty($update)) {
2311
+					updateSettings($update);
2312
+		}
2232 2313
 
2233 2314
 		redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']);
2234 2315
 	}
@@ -2238,13 +2319,15 @@  discard block
 block discarded – undo
2238 2319
 		if (is_array($_SESSION['errors']))
2239 2320
 		{
2240 2321
 			$errors = array();
2241
-			if (!empty($_SESSION['errors']['dir']))
2242
-				foreach ($_SESSION['errors']['dir'] as $error)
2322
+			if (!empty($_SESSION['errors']['dir'])) {
2323
+							foreach ($_SESSION['errors']['dir'] as $error)
2243 2324
 					$errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES);
2325
+			}
2244 2326
 
2245
-			if (!empty($_SESSION['errors']['base']))
2246
-				foreach ($_SESSION['errors']['base'] as $error)
2327
+			if (!empty($_SESSION['errors']['base'])) {
2328
+							foreach ($_SESSION['errors']['base'] as $error)
2247 2329
 					$errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES);
2330
+			}
2248 2331
 		}
2249 2332
 		unset($_SESSION['errors']);
2250 2333
 	}
@@ -2454,8 +2537,9 @@  discard block
 block discarded – undo
2454 2537
 	foreach ($modSettings['attachmentUploadDir'] as $id => $dir)
2455 2538
 	{
2456 2539
 		// If there aren't any attachments in this directory this won't exist.
2457
-		if (!isset($expected_files[$id]))
2458
-			$expected_files[$id] = 0;
2540
+		if (!isset($expected_files[$id])) {
2541
+					$expected_files[$id] = 0;
2542
+		}
2459 2543
 
2460 2544
 		// Check if the directory is doing okay.
2461 2545
 		list ($status, $error, $files) = attachDirStatus($dir, $expected_files[$id]);
@@ -2468,10 +2552,11 @@  discard block
 block discarded – undo
2468 2552
 			$is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']);
2469 2553
 
2470 2554
 			// Count any sub-folders.
2471
-			foreach ($modSettings['attachmentUploadDir'] as $sid => $sub)
2472
-				if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
2555
+			foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) {
2556
+							if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
2473 2557
 				{
2474 2558
 					$expected_files[$id]++;
2559
+			}
2475 2560
 					$sub_dirs++;
2476 2561
 				}
2477 2562
 		}
@@ -2489,8 +2574,8 @@  discard block
 block discarded – undo
2489 2574
 	}
2490 2575
 
2491 2576
 	// Just stick a new directory on at the bottom.
2492
-	if (isset($_REQUEST['new_path']))
2493
-		$attachdirs[] = array(
2577
+	if (isset($_REQUEST['new_path'])) {
2578
+			$attachdirs[] = array(
2494 2579
 			'id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1,
2495 2580
 			'current' => false,
2496 2581
 			'path' => '',
@@ -2498,6 +2583,7 @@  discard block
 block discarded – undo
2498 2583
 			'num_files' => '',
2499 2584
 			'status' => '',
2500 2585
 		);
2586
+	}
2501 2587
 
2502 2588
 	return $attachdirs;
2503 2589
 }
@@ -2510,8 +2596,9 @@  discard block
 block discarded – undo
2510 2596
 {
2511 2597
 	global $modSettings, $txt;
2512 2598
 
2513
-	if (empty($modSettings['attachment_basedirectories']))
2514
-		return;
2599
+	if (empty($modSettings['attachment_basedirectories'])) {
2600
+			return;
2601
+	}
2515 2602
 
2516 2603
 	$basedirs = array();
2517 2604
 	// Get a list of the base directories.
@@ -2519,16 +2606,18 @@  discard block
 block discarded – undo
2519 2606
 	{
2520 2607
 		// Loop through the attach directory array to count any sub-directories
2521 2608
 		$expected_dirs = 0;
2522
-		foreach ($modSettings['attachmentUploadDir'] as $sid => $sub)
2523
-			if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
2609
+		foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) {
2610
+					if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false)
2524 2611
 				$expected_dirs++;
2612
+		}
2525 2613
 
2526
-		if (!is_dir($dir))
2527
-			$status = 'does_not_exist';
2528
-		elseif (!is_writeable($dir))
2529
-			$status = 'not_writable';
2530
-		else
2531
-			$status = 'ok';
2614
+		if (!is_dir($dir)) {
2615
+					$status = 'does_not_exist';
2616
+		} elseif (!is_writeable($dir)) {
2617
+					$status = 'not_writable';
2618
+		} else {
2619
+					$status = 'ok';
2620
+		}
2532 2621
 
2533 2622
 		$basedirs[] = array(
2534 2623
 			'id' => $id,
@@ -2539,14 +2628,15 @@  discard block
 block discarded – undo
2539 2628
 		);
2540 2629
 	}
2541 2630
 
2542
-	if (isset($_REQUEST['new_base_path']))
2543
-		$basedirs[] = array(
2631
+	if (isset($_REQUEST['new_base_path'])) {
2632
+			$basedirs[] = array(
2544 2633
 			'id' => '',
2545 2634
 			'current' => false,
2546 2635
 			'path' => '<input type="text" name="new_base_dir" value="" size="40">',
2547 2636
 			'num_dirs' => '',
2548 2637
 			'status' => '',
2549 2638
 		);
2639
+	}
2550 2640
 
2551 2641
 	return $basedirs;
2552 2642
 }
@@ -2562,10 +2652,11 @@  discard block
 block discarded – undo
2562 2652
  */
2563 2653
 function attachDirStatus($dir, $expected_files)
2564 2654
 {
2565
-	if (!is_dir($dir))
2566
-		return array('does_not_exist', true, '');
2567
-	elseif (!is_writable($dir))
2568
-		return array('not_writable', true, '');
2655
+	if (!is_dir($dir)) {
2656
+			return array('does_not_exist', true, '');
2657
+	} elseif (!is_writable($dir)) {
2658
+			return array('not_writable', true, '');
2659
+	}
2569 2660
 
2570 2661
 	// Everything is okay so far, start to scan through the directory.
2571 2662
 	$num_files = 0;
@@ -2573,22 +2664,26 @@  discard block
 block discarded – undo
2573 2664
 	while ($file = $dir_handle->read())
2574 2665
 	{
2575 2666
 		// Now do we have a real file here?
2576
-		if (in_array($file, array('.', '..', '.htaccess', 'index.php')))
2577
-			continue;
2667
+		if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) {
2668
+					continue;
2669
+		}
2578 2670
 
2579 2671
 		$num_files++;
2580 2672
 	}
2581 2673
 	$dir_handle->close();
2582 2674
 
2583
-	if ($num_files < $expected_files)
2584
-		return array('files_missing', true, $num_files);
2675
+	if ($num_files < $expected_files) {
2676
+			return array('files_missing', true, $num_files);
2677
+	}
2585 2678
 	// Empty?
2586
-	elseif ($expected_files == 0)
2587
-		return array('unused', false, $num_files);
2679
+	elseif ($expected_files == 0) {
2680
+			return array('unused', false, $num_files);
2681
+	}
2588 2682
 	// All good!
2589
-	else
2590
-		return array('ok', false, $num_files);
2591
-}
2683
+	else {
2684
+			return array('ok', false, $num_files);
2685
+	}
2686
+	}
2592 2687
 
2593 2688
 /**
2594 2689
  * Maintance function to move attachments from one directory to another
@@ -2600,10 +2695,11 @@  discard block
 block discarded – undo
2600 2695
 	checkSession();
2601 2696
 
2602 2697
 	$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2603
-	if (!empty($modSettings['attachment_basedirectories']))
2604
-		$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
2605
-	else
2606
-		$modSettings['basedirectory_for_attachments'] = array();
2698
+	if (!empty($modSettings['attachment_basedirectories'])) {
2699
+			$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
2700
+	} else {
2701
+			$modSettings['basedirectory_for_attachments'] = array();
2702
+	}
2607 2703
 
2608 2704
 	$_POST['from'] = (int) $_POST['from'];
2609 2705
 	$_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0;
@@ -2617,11 +2713,13 @@  discard block
 block discarded – undo
2617 2713
 	$total_moved = 0;
2618 2714
 	$total_not_moved = 0;
2619 2715
 
2620
-	if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to'])))
2621
-		$results[] = $txt['attachment_transfer_no_dir'];
2716
+	if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) {
2717
+			$results[] = $txt['attachment_transfer_no_dir'];
2718
+	}
2622 2719
 
2623
-	if ($_POST['from'] == $_POST['to'])
2624
-		$results[] = $txt['attachment_transfer_same_dir'];
2720
+	if ($_POST['from'] == $_POST['to']) {
2721
+			$results[] = $txt['attachment_transfer_same_dir'];
2722
+	}
2625 2723
 
2626 2724
 	if (empty($results))
2627 2725
 	{
@@ -2640,8 +2738,9 @@  discard block
 block discarded – undo
2640 2738
 		$smcFunc['db_free_result']($request);
2641 2739
 		$total_progress -= $start;
2642 2740
 
2643
-		if ($total_progress < 1)
2644
-			$results[] = $txt['attachment_transfer_no_find'];
2741
+		if ($total_progress < 1) {
2742
+					$results[] = $txt['attachment_transfer_no_find'];
2743
+		}
2645 2744
 	}
2646 2745
 
2647 2746
 	if (empty($results))
@@ -2657,9 +2756,9 @@  discard block
 block discarded – undo
2657 2756
 
2658 2757
 			automanage_attachments_check_directory();
2659 2758
 			$new_dir = $modSettings['currentAttachmentUploadDir'];
2759
+		} else {
2760
+					$new_dir = $_POST['to'];
2660 2761
 		}
2661
-		else
2662
-			$new_dir = $_POST['to'];
2663 2762
 
2664 2763
 		$modSettings['currentAttachmentUploadDir'] = $new_dir;
2665 2764
 
@@ -2667,8 +2766,9 @@  discard block
 block discarded – undo
2667 2766
 		while ($break == false)
2668 2767
 		{
2669 2768
 			@set_time_limit(300);
2670
-			if (function_exists('apache_reset_timeout'))
2671
-				@apache_reset_timeout();
2769
+			if (function_exists('apache_reset_timeout')) {
2770
+							@apache_reset_timeout();
2771
+			}
2672 2772
 
2673 2773
 			// If limits are set, get the file count and size for the destination folder
2674 2774
 			if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit'])))
@@ -2704,13 +2804,15 @@  discard block
 block discarded – undo
2704 2804
 
2705 2805
 			if ($smcFunc['db_num_rows']($request) === 0)
2706 2806
 			{
2707
-				if (empty($current_progress))
2708
-					$results[] = $txt['attachment_transfer_no_find'];
2807
+				if (empty($current_progress)) {
2808
+									$results[] = $txt['attachment_transfer_no_find'];
2809
+				}
2709 2810
 				break;
2710 2811
 			}
2711 2812
 
2712
-			if ($smcFunc['db_num_rows']($request) < $limit)
2713
-				$break = true;
2813
+			if ($smcFunc['db_num_rows']($request) < $limit) {
2814
+							$break = true;
2815
+			}
2714 2816
 
2715 2817
 			// Move them
2716 2818
 			$moved = array();
@@ -2734,8 +2836,9 @@  discard block
 block discarded – undo
2734 2836
 							automanage_attachments_by_space();
2735 2837
 
2736 2838
 							$results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]);
2737
-							if (!empty($total_not_moved))
2738
-								$results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved);
2839
+							if (!empty($total_not_moved)) {
2840
+															$results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved);
2841
+							}
2739 2842
 
2740 2843
 							$dir_files = 0;
2741 2844
 							$total_moved = 0;
@@ -2743,8 +2846,7 @@  discard block
 block discarded – undo
2743 2846
 
2744 2847
 							$break = false;
2745 2848
 							break;
2746
-						}
2747
-						else
2849
+						} else
2748 2850
 						{
2749 2851
 							// Hmm, not in auto. Time to bail out then...
2750 2852
 							$results[] = $txt['attachment_transfer_no_room'];
@@ -2759,9 +2861,9 @@  discard block
 block discarded – undo
2759 2861
 					$total_moved++;
2760 2862
 					$current_progress++;
2761 2863
 					$moved[] = $row['id_attach'];
2864
+				} else {
2865
+									$total_not_moved++;
2762 2866
 				}
2763
-				else
2764
-					$total_not_moved++;
2765 2867
 			}
2766 2868
 			$smcFunc['db_free_result']($request);
2767 2869
 
@@ -2800,13 +2902,15 @@  discard block
 block discarded – undo
2800 2902
 		}
2801 2903
 
2802 2904
 		$results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]);
2803
-		if (!empty($total_not_moved))
2804
-			$results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved);
2905
+		if (!empty($total_not_moved)) {
2906
+					$results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved);
2907
+		}
2805 2908
 	}
2806 2909
 
2807 2910
 	$_SESSION['results'] = $results;
2808
-	if (file_exists($boarddir . '/progress.php'))
2809
-		unlink($boarddir . '/progress.php');
2911
+	if (file_exists($boarddir . '/progress.php')) {
2912
+			unlink($boarddir . '/progress.php');
2913
+	}
2810 2914
 
2811 2915
 	redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer');
2812 2916
 }
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 3
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(header('HTTP/1.1 400 Bad Request'));
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(header('HTTP/1.1 400 Bad Request'));
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
 
@@ -41,16 +43,19 @@  discard block
 block discarded – undo
41 43
 	mt_srand(end(unpack('n', md5($word . session_id()))));
42 44
 
43 45
 	// Try to see if there's a sound font in the user's language.
44
-	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav'))
45
-		$sound_language = $user_info['language'];
46
+	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) {
47
+			$sound_language = $user_info['language'];
48
+	}
46 49
 
47 50
 	// English should be there.
48
-	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav'))
49
-		$sound_language = 'english';
51
+	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) {
52
+			$sound_language = 'english';
53
+	}
50 54
 
51 55
 	// Guess not...
52
-	else
53
-		return false;
56
+	else {
57
+			return false;
58
+	}
54 59
 
55 60
 	// File names are in lower case so lets make sure that we are only using a lower case string
56 61
 	$word = strtolower($word);
@@ -60,20 +65,25 @@  discard block
 block discarded – undo
60 65
 	for ($i = 0; $i < strlen($word); $i++)
61 66
 	{
62 67
 		$sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav'));
63
-		if (strpos($sound_letter, 'data') === false)
64
-			return false;
68
+		if (strpos($sound_letter, 'data') === false) {
69
+					return false;
70
+		}
65 71
 
66 72
 		$sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8);
67 73
 		switch ($word{$i} === 's' ? 0 : mt_rand(0, 2))
68 74
 		{
69
-			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
70
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
71
-						$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
75
+			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) {
76
+								for ($k = 0, $m = round(mt_rand(15, 25) / 10);
77
+			}
78
+			$k < $m; $k++) {
79
+											$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
80
+					}
72 81
 			break;
73 82
 
74 83
 			case 1:
75
-				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2)
76
-					$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
84
+				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) {
85
+									$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
86
+				}
77 87
 				$sound_word .= str_repeat($sound_letter{$n}, 2);
78 88
 			break;
79 89
 
@@ -81,10 +91,12 @@  discard block
 block discarded – undo
81 91
 				$shift = 0;
82 92
 				for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
83 93
 				{
84
-					if (mt_rand(0, 10) === 0)
85
-						$shift += mt_rand(-3, 3);
86
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
87
-						$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
94
+					if (mt_rand(0, 10) === 0) {
95
+											$shift += mt_rand(-3, 3);
96
+					}
97
+					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) {
98
+											$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
99
+					}
88 100
 				}
89 101
 			break;
90 102
 
Please login to merge, or discard this patch.
Sources/Subs-Post.php 1 patch
Braces   +528 added lines, -393 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -46,17 +47,19 @@  discard block
 block discarded – undo
46 47
 	$message = preg_replace('~\.{100,}~', '...', $message);
47 48
 
48 49
 	// Trim off trailing quotes - these often happen by accident.
49
-	while (substr($message, -7) == '[quote]')
50
-		$message = substr($message, 0, -7);
51
-	while (substr($message, 0, 8) == '[/quote]')
52
-		$message = substr($message, 8);
50
+	while (substr($message, -7) == '[quote]') {
51
+			$message = substr($message, 0, -7);
52
+	}
53
+	while (substr($message, 0, 8) == '[/quote]') {
54
+			$message = substr($message, 8);
55
+	}
53 56
 
54 57
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
55 58
 	$in_tag = false;
56 59
 	$had_tag = false;
57 60
 	$codeopen = 0;
58
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
59
-		foreach ($matches[0] as $index => $dummy)
61
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
62
+			foreach ($matches[0] as $index => $dummy)
60 63
 		{
61 64
 			// Closing?
62 65
 			if (!empty($matches[2][$index]))
@@ -64,6 +67,7 @@  discard block
 block discarded – undo
64 67
 				// If it's closing and we're not in a tag we need to open it...
65 68
 				if (!$in_tag)
66 69
 					$codeopen = true;
70
+	}
67 71
 				// Either way we ain't in one any more.
68 72
 				$in_tag = false;
69 73
 			}
@@ -72,17 +76,20 @@  discard block
 block discarded – undo
72 76
 			{
73 77
 				$had_tag = true;
74 78
 				// If we're in a tag don't do nought!
75
-				if (!$in_tag)
76
-					$in_tag = true;
79
+				if (!$in_tag) {
80
+									$in_tag = true;
81
+				}
77 82
 			}
78 83
 		}
79 84
 
80 85
 	// If we have an open tag, close it.
81
-	if ($in_tag)
82
-		$message .= '[/code]';
86
+	if ($in_tag) {
87
+			$message .= '[/code]';
88
+	}
83 89
 	// Open any ones that need to be open, only if we've never had a tag.
84
-	if ($codeopen && !$had_tag)
85
-		$message = '[code]' . $message;
90
+	if ($codeopen && !$had_tag) {
91
+			$message = '[code]' . $message;
92
+	}
86 93
 
87 94
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
88 95
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -108,23 +115,26 @@  discard block
 block discarded – undo
108 115
 	fixTags($message);
109 116
 
110 117
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
111
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
112
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
113
-	else
114
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
118
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
119
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
120
+	} else {
121
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
122
+	}
115 123
 
116 124
 	if (!$previewing && strpos($message, '[html]') !== false)
117 125
 	{
118
-		if (allowedTo('admin_forum'))
119
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
126
+		if (allowedTo('admin_forum')) {
127
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
120 128
 				return '[html]' . strtr(un_htmlspecialchars($m), array("\n" => '&#13;', '  ' => ' &#32;', '[' => '&#91;', ']' => '&#93;')) . '[/html]';
129
+		}
121 130
 			}, $message);
122 131
 
123 132
 		// We should edit them out, or else if an admin edits the message they will get shown...
124 133
 		else
125 134
 		{
126
-			while (strpos($message, '[html]') !== false)
127
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
135
+			while (strpos($message, '[html]') !== false) {
136
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			}
128 138
 		}
129 139
 	}
130 140
 
@@ -146,10 +156,12 @@  discard block
 block discarded – undo
146 156
 
147 157
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
148 158
 	$list_close = substr_count($message, '[/list]');
149
-	if ($list_close - $list_open > 0)
150
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
151
-	if ($list_open - $list_close > 0)
152
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
159
+	if ($list_close - $list_open > 0) {
160
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
161
+	}
162
+	if ($list_open - $list_close > 0) {
163
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
164
+	}
153 165
 
154 166
 	$mistake_fixes = array(
155 167
 		// Find [table]s not followed by [tr].
@@ -198,8 +210,9 @@  discard block
 block discarded – undo
198 210
 	);
199 211
 
200 212
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
201
-	for ($j = 0; $j < 3; $j++)
202
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
213
+	for ($j = 0; $j < 3; $j++) {
214
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	}
203 216
 
204 217
 	// Remove empty bbc from the sections outside the code tags
205 218
 	$allowedEmpty = array(
@@ -209,24 +222,28 @@  discard block
 block discarded – undo
209 222
 
210 223
 	require_once($sourcedir . '/Subs.php');
211 224
 
212
-	foreach (($codes = parse_bbc(false)) as $code)
213
-		if (!in_array($code['tag'], $allowedEmpty))
225
+	foreach (($codes = parse_bbc(false)) as $code) {
226
+			if (!in_array($code['tag'], $allowedEmpty))
214 227
 			$alltags[] = $code['tag'];
228
+	}
215 229
 
216 230
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
217 231
 
218
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
219
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
232
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
233
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	}
220 235
 
221 236
 	// Restore code blocks
222
-	if (!empty($code_tags))
223
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
237
+	if (!empty($code_tags)) {
238
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	}
224 240
 
225 241
 	// Restore white space entities
226
-	if (!$previewing)
227
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
228
-	else
229
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
242
+	if (!$previewing) {
243
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	} else {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	}
230 247
 
231 248
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
232 249
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -269,8 +286,9 @@  discard block
 block discarded – undo
269 286
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
270 287
 	}, $message);
271 288
 
272
-	if (!empty($code_tags))
273
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
289
+	if (!empty($code_tags)) {
290
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	}
274 292
 
275 293
 	// Change breaks back to \n's and &nsbp; back to spaces.
276 294
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -351,8 +369,9 @@  discard block
 block discarded – undo
351 369
 	);
352 370
 
353 371
 	// Fix each type of tag.
354
-	foreach ($fixArray as $param)
355
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
372
+	foreach ($fixArray as $param) {
373
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	}
356 375
 
357 376
 	// Now fix possible security problems with images loading links automatically...
358 377
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -388,16 +407,19 @@  discard block
 block discarded – undo
388 407
 					$desired_height = $height;
389 408
 				}
390 409
 				// Scale it to the width...
391
-				elseif (empty($desired_width) && !empty($height))
392
-					$desired_width = (int) (($desired_height * $width) / $height);
410
+				elseif (empty($desired_width) && !empty($height)) {
411
+									$desired_width = (int) (($desired_height * $width) / $height);
412
+				}
393 413
 				// Scale if to the height.
394
-				elseif (!empty($width))
395
-					$desired_height = (int) (($desired_width * $height) / $width);
414
+				elseif (!empty($width)) {
415
+									$desired_height = (int) (($desired_width * $height) / $width);
416
+				}
396 417
 			}
397 418
 
398 419
 			// If the width and height are fine, just continue along...
399
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
400
-				continue;
420
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
421
+							continue;
422
+			}
401 423
 
402 424
 			// Too bad, it's too wide.  Make it as wide as the maximum.
403 425
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -417,8 +439,9 @@  discard block
 block discarded – undo
417 439
 		}
418 440
 
419 441
 		// If any img tags were actually changed...
420
-		if (!empty($replaces))
421
-			$message = strtr($message, $replaces);
442
+		if (!empty($replaces)) {
443
+					$message = strtr($message, $replaces);
444
+		}
422 445
 	}
423 446
 }
424 447
 
@@ -437,10 +460,11 @@  discard block
 block discarded – undo
437 460
 {
438 461
 	global $boardurl, $scripturl;
439 462
 
440
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
441
-		$domain_url = $match[1];
442
-	else
443
-		$domain_url = $boardurl . '/';
463
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
464
+			$domain_url = $match[1];
465
+	} else {
466
+			$domain_url = $boardurl . '/';
467
+	}
444 468
 
445 469
 	$replaces = array();
446 470
 
@@ -448,11 +472,11 @@  discard block
 block discarded – undo
448 472
 	{
449 473
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
450 474
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
475
+	} elseif ($hasEqualSign) {
476
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
477
+	} else {
478
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
451 479
 	}
452
-	elseif ($hasEqualSign)
453
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
454
-	else
455
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
456 480
 
457 481
 	foreach ($matches[0] as $k => $dummy)
458 482
 	{
@@ -465,49 +489,53 @@  discard block
 block discarded – undo
465 489
 		foreach ($protocols as $protocol)
466 490
 		{
467 491
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
468
-			if ($found)
469
-				break;
492
+			if ($found) {
493
+							break;
494
+			}
470 495
 		}
471 496
 
472 497
 		if (!$found && $protocols[0] == 'http')
473 498
 		{
474
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
475
-				$replace = $domain_url . $replace;
476
-			elseif (substr($replace, 0, 1) == '?')
477
-				$replace = $scripturl . $replace;
478
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
499
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
500
+							$replace = $domain_url . $replace;
501
+			} elseif (substr($replace, 0, 1) == '?') {
502
+							$replace = $scripturl . $replace;
503
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
479 504
 			{
480 505
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
481 506
 				$this_tag = 'iurl';
482 507
 				$this_close = 'iurl';
508
+			} elseif (substr($replace, 0, 2) != '//') {
509
+							$replace = $protocols[0] . '://' . $replace;
483 510
 			}
484
-			elseif (substr($replace, 0, 2) != '//')
485
-				$replace = $protocols[0] . '://' . $replace;
486
-		}
487
-		elseif (!$found && $protocols[0] == 'ftp')
488
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
489
-		elseif (!$found)
490
-			$replace = $protocols[0] . '://' . $replace;
491
-
492
-		if ($hasEqualSign && $embeddedUrl)
493
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
494
-		elseif ($hasEqualSign)
495
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
496
-		elseif ($embeddedUrl)
497
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
498
-		else
499
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
511
+		} elseif (!$found && $protocols[0] == 'ftp') {
512
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
513
+		} elseif (!$found) {
514
+					$replace = $protocols[0] . '://' . $replace;
515
+		}
516
+
517
+		if ($hasEqualSign && $embeddedUrl) {
518
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
519
+		} elseif ($hasEqualSign) {
520
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
521
+		} elseif ($embeddedUrl) {
522
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
523
+		} else {
524
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
525
+		}
500 526
 	}
501 527
 
502 528
 	foreach ($replaces as $k => $v)
503 529
 	{
504
-		if ($k == $v)
505
-			unset($replaces[$k]);
530
+		if ($k == $v) {
531
+					unset($replaces[$k]);
532
+		}
506 533
 	}
507 534
 
508
-	if (!empty($replaces))
509
-		$message = strtr($message, $replaces);
510
-}
535
+	if (!empty($replaces)) {
536
+			$message = strtr($message, $replaces);
537
+	}
538
+	}
511 539
 
512 540
 /**
513 541
  * This function sends an email to the specified recipient(s).
@@ -551,8 +579,9 @@  discard block
 block discarded – undo
551 579
 	}
552 580
 
553 581
 	// Nothing left? Nothing else to do
554
-	if (empty($to_array))
555
-		return true;
582
+	if (empty($to_array)) {
583
+			return true;
584
+	}
556 585
 
557 586
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
558 587
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -569,15 +598,17 @@  discard block
 block discarded – undo
569 598
 		}
570 599
 
571 600
 		// Call this function recursively for the hotmail addresses.
572
-		if (!empty($hotmail_to))
573
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
601
+		if (!empty($hotmail_to)) {
602
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
603
+		}
574 604
 
575 605
 		// The remaining addresses no longer need the fix.
576 606
 		$hotmail_fix = false;
577 607
 
578 608
 		// No other addresses left? Return instantly.
579
-		if (empty($to_array))
580
-			return $mail_result;
609
+		if (empty($to_array)) {
610
+					return $mail_result;
611
+		}
581 612
 	}
582 613
 
583 614
 	// Get rid of entities.
@@ -602,13 +633,15 @@  discard block
 block discarded – undo
602 633
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
603 634
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
604 635
 
605
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
606
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
636
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
637
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
638
+	}
607 639
 	$headers .= 'X-Mailer: SMF' . $line_break;
608 640
 
609 641
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
610
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
611
-		return false;
642
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
643
+			return false;
644
+	}
612 645
 
613 646
 	// Save the original message...
614 647
 	$orig_message = $message;
@@ -657,17 +690,19 @@  discard block
 block discarded – undo
657 690
 	}
658 691
 
659 692
 	// Are we using the mail queue, if so this is where we butt in...
660
-	if ($priority != 0)
661
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
693
+	if ($priority != 0) {
694
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
695
+	}
662 696
 
663 697
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
664 698
 	elseif (!empty($modSettings['mail_limit']))
665 699
 	{
666 700
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
667
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
668
-			$new_queue_stat = time() . '|' . 1;
669
-		else
670
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
701
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
702
+					$new_queue_stat = time() . '|' . 1;
703
+		} else {
704
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
705
+		}
671 706
 
672 707
 		updateSettings(array('mail_recent' => $new_queue_stat));
673 708
 	}
@@ -692,12 +727,13 @@  discard block
 block discarded – undo
692 727
 
693 728
 			// Wait, wait, I'm still sending here!
694 729
 			@set_time_limit(300);
695
-			if (function_exists('apache_reset_timeout'))
696
-				@apache_reset_timeout();
730
+			if (function_exists('apache_reset_timeout')) {
731
+							@apache_reset_timeout();
732
+			}
697 733
 		}
734
+	} else {
735
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
698 736
 	}
699
-	else
700
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
701 737
 
702 738
 	// Everything go smoothly?
703 739
 	return $mail_result;
@@ -723,8 +759,9 @@  discard block
 block discarded – undo
723 759
 	static $cur_insert = array();
724 760
 	static $cur_insert_len = 0;
725 761
 
726
-	if ($cur_insert_len == 0)
727
-		$cur_insert = array();
762
+	if ($cur_insert_len == 0) {
763
+			$cur_insert = array();
764
+	}
728 765
 
729 766
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
730 767
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -799,8 +836,9 @@  discard block
 block discarded – undo
799 836
 	}
800 837
 
801 838
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
802
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
803
-		return AddMailQueue(true);
839
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
840
+			return AddMailQueue(true);
841
+	}
804 842
 
805 843
 	return true;
806 844
 }
@@ -833,23 +871,26 @@  discard block
 block discarded – undo
833 871
 		'sent' => array()
834 872
 	);
835 873
 
836
-	if ($from === null)
837
-		$from = array(
874
+	if ($from === null) {
875
+			$from = array(
838 876
 			'id' => $user_info['id'],
839 877
 			'name' => $user_info['name'],
840 878
 			'username' => $user_info['username']
841 879
 		);
880
+	}
842 881
 
843 882
 	// This is the one that will go in their inbox.
844 883
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
845 884
 	preparsecode($htmlmessage);
846 885
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
847
-	if ($smcFunc['strlen']($htmlsubject) > 100)
848
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
886
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
887
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
888
+	}
849 889
 
850 890
 	// Make sure is an array
851
-	if (!is_array($recipients))
852
-		$recipients = array($recipients);
891
+	if (!is_array($recipients)) {
892
+			$recipients = array($recipients);
893
+	}
853 894
 
854 895
 	// Integrated PMs
855 896
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -877,21 +918,23 @@  discard block
 block discarded – undo
877 918
 				'usernames' => array_keys($usernames),
878 919
 			)
879 920
 		);
880
-		while ($row = $smcFunc['db_fetch_assoc']($request))
881
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
921
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
922
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
882 923
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
924
+		}
883 925
 		$smcFunc['db_free_result']($request);
884 926
 
885 927
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
886
-		foreach ($recipients as $rec_type => $rec)
887
-			foreach ($rec as $id => $member)
928
+		foreach ($recipients as $rec_type => $rec) {
929
+					foreach ($rec as $id => $member)
888 930
 			{
889 931
 				if (is_numeric($recipients[$rec_type][$id]))
890 932
 					continue;
933
+		}
891 934
 
892
-				if (!empty($usernames[$member]))
893
-					$recipients[$rec_type][$id] = $usernames[$member];
894
-				else
935
+				if (!empty($usernames[$member])) {
936
+									$recipients[$rec_type][$id] = $usernames[$member];
937
+				} else
895 938
 				{
896 939
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
897 940
 					unset($recipients[$rec_type][$id]);
@@ -930,8 +973,9 @@  discard block
 block discarded – undo
930 973
 		foreach ($criteria as $criterium)
931 974
 		{
932 975
 			$match = false;
933
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
934
-				$delete = true;
976
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
977
+							$delete = true;
978
+			}
935 979
 			// If we're adding and one criteria don't match then we stop!
936 980
 			elseif (!$row['is_or'])
937 981
 			{
@@ -939,8 +983,9 @@  discard block
 block discarded – undo
939 983
 				break;
940 984
 			}
941 985
 		}
942
-		if ($delete)
943
-			$deletes[$row['id_member']] = 1;
986
+		if ($delete) {
987
+					$deletes[$row['id_member']] = 1;
988
+		}
944 989
 	}
945 990
 	$smcFunc['db_free_result']($request);
946 991
 
@@ -955,8 +1000,9 @@  discard block
 block discarded – undo
955 1000
 			array(
956 1001
 			)
957 1002
 		);
958
-		while ($row = $smcFunc['db_fetch_assoc']($request))
959
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1003
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1004
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1005
+		}
960 1006
 		$smcFunc['db_free_result']($request);
961 1007
 	}
962 1008
 
@@ -964,8 +1010,9 @@  discard block
 block discarded – undo
964 1010
 	require_once($sourcedir . '/Subs-Members.php');
965 1011
 	$pmReadGroups = groupsAllowedTo('pm_read');
966 1012
 
967
-	if (empty($modSettings['permission_enable_deny']))
968
-		$pmReadGroups['denied'] = array();
1013
+	if (empty($modSettings['permission_enable_deny'])) {
1014
+			$pmReadGroups['denied'] = array();
1015
+	}
969 1016
 
970 1017
 	// Load their alert preferences
971 1018
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -997,8 +1044,9 @@  discard block
 block discarded – undo
997 1044
 	while ($row = $smcFunc['db_fetch_assoc']($request))
998 1045
 	{
999 1046
 		// Don't do anything for members to be deleted!
1000
-		if (isset($deletes[$row['id_member']]))
1001
-			continue;
1047
+		if (isset($deletes[$row['id_member']])) {
1048
+					continue;
1049
+		}
1002 1050
 
1003 1051
 		// Load the preferences for this member (if any)
1004 1052
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1019,8 +1067,9 @@  discard block
 block discarded – undo
1019 1067
 		{
1020 1068
 			foreach ($groups as $id)
1021 1069
 			{
1022
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1023
-					$message_limit = $message_limit_cache[$id];
1070
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1071
+									$message_limit = $message_limit_cache[$id];
1072
+				}
1024 1073
 			}
1025 1074
 
1026 1075
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1068,8 +1117,9 @@  discard block
 block discarded – undo
1068 1117
 	$smcFunc['db_free_result']($request);
1069 1118
 
1070 1119
 	// Only 'send' the message if there are any recipients left.
1071
-	if (empty($all_to))
1072
-		return $log;
1120
+	if (empty($all_to)) {
1121
+			return $log;
1122
+	}
1073 1123
 
1074 1124
 	// Insert the message itself and then grab the last insert id.
1075 1125
 	$smcFunc['db_insert']('',
@@ -1090,8 +1140,8 @@  discard block
 block discarded – undo
1090 1140
 	if (!empty($id_pm))
1091 1141
 	{
1092 1142
 		// If this is new we need to set it part of it's own conversation.
1093
-		if (empty($pm_head))
1094
-			$smcFunc['db_query']('', '
1143
+		if (empty($pm_head)) {
1144
+					$smcFunc['db_query']('', '
1095 1145
 				UPDATE {db_prefix}personal_messages
1096 1146
 				SET id_pm_head = {int:id_pm_head}
1097 1147
 				WHERE id_pm = {int:id_pm_head}',
@@ -1099,6 +1149,7 @@  discard block
 block discarded – undo
1099 1149
 					'id_pm_head' => $id_pm,
1100 1150
 				)
1101 1151
 			);
1152
+		}
1102 1153
 
1103 1154
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1104 1155
 		$smcFunc['db_query']('', '
@@ -1114,8 +1165,9 @@  discard block
 block discarded – undo
1114 1165
 		foreach ($all_to as $to)
1115 1166
 		{
1116 1167
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1117
-			if (!in_array($to, $recipients['bcc']))
1118
-				$to_list[] = $to;
1168
+			if (!in_array($to, $recipients['bcc'])) {
1169
+							$to_list[] = $to;
1170
+			}
1119 1171
 		}
1120 1172
 
1121 1173
 		$smcFunc['db_insert']('insert',
@@ -1133,9 +1185,9 @@  discard block
 block discarded – undo
1133 1185
 	{
1134 1186
 		censorText($message);
1135 1187
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1188
+	} else {
1189
+			$message = '';
1136 1190
 	}
1137
-	else
1138
-		$message = '';
1139 1191
 
1140 1192
 	$to_names = array();
1141 1193
 	if (count($to_list) > 1)
@@ -1148,8 +1200,9 @@  discard block
 block discarded – undo
1148 1200
 				'to_members' => $to_list,
1149 1201
 			)
1150 1202
 		);
1151
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1152
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1203
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1204
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1205
+		}
1153 1206
 		$smcFunc['db_free_result']($request);
1154 1207
 	}
1155 1208
 	$replacements = array(
@@ -1177,11 +1230,13 @@  discard block
 block discarded – undo
1177 1230
 	loadLanguage('index+PersonalMessage');
1178 1231
 
1179 1232
 	// Add one to their unread and read message counts.
1180
-	foreach ($all_to as $k => $id)
1181
-		if (isset($deletes[$id]))
1233
+	foreach ($all_to as $k => $id) {
1234
+			if (isset($deletes[$id]))
1182 1235
 			unset($all_to[$k]);
1183
-	if (!empty($all_to))
1184
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1236
+	}
1237
+	if (!empty($all_to)) {
1238
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1239
+	}
1185 1240
 
1186 1241
 	return $log;
1187 1242
 }
@@ -1211,15 +1266,17 @@  discard block
 block discarded – undo
1211 1266
 		// Let's, for now, assume there are only &#021;'ish characters.
1212 1267
 		$simple = true;
1213 1268
 
1214
-		foreach ($matches[1] as $entity)
1215
-			if ($entity > 128)
1269
+		foreach ($matches[1] as $entity) {
1270
+					if ($entity > 128)
1216 1271
 				$simple = false;
1272
+		}
1217 1273
 		unset($matches);
1218 1274
 
1219
-		if ($simple)
1220
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1275
+		if ($simple) {
1276
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1221 1277
 			{
1222 1278
 				return chr("$m[1]");
1279
+		}
1223 1280
 			}, $string);
1224 1281
 		else
1225 1282
 		{
@@ -1227,8 +1284,9 @@  discard block
 block discarded – undo
1227 1284
 			if (!$context['utf8'] && function_exists('iconv'))
1228 1285
 			{
1229 1286
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1230
-				if ($newstring)
1231
-					$string = $newstring;
1287
+				if ($newstring) {
1288
+									$string = $newstring;
1289
+				}
1232 1290
 			}
1233 1291
 
1234 1292
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1244,23 +1302,25 @@  discard block
 block discarded – undo
1244 1302
 		if (!$context['utf8'] && function_exists('iconv'))
1245 1303
 		{
1246 1304
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1247
-			if ($newstring)
1248
-				$string = $newstring;
1305
+			if ($newstring) {
1306
+							$string = $newstring;
1307
+			}
1249 1308
 		}
1250 1309
 
1251 1310
 		$entityConvert = function($m)
1252 1311
 		{
1253 1312
 			$c = $m[1];
1254
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1255
-				return $c;
1256
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1257
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1258
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1259
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1260
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1261
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1262
-			else
1263
-				return "";
1313
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1314
+							return $c;
1315
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1316
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1317
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1318
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1319
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1320
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1321
+			} else {
1322
+							return "";
1323
+			}
1264 1324
 		};
1265 1325
 
1266 1326
 		// Convert all 'special' characters to HTML entities.
@@ -1274,19 +1334,20 @@  discard block
 block discarded – undo
1274 1334
 		$string = base64_encode($string);
1275 1335
 
1276 1336
 		// Show the characterset and the transfer-encoding for header strings.
1277
-		if ($with_charset)
1278
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1337
+		if ($with_charset) {
1338
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1339
+		}
1279 1340
 
1280 1341
 		// Break it up in lines (mail body).
1281
-		else
1282
-			$string = chunk_split($string, 76, $line_break);
1342
+		else {
1343
+					$string = chunk_split($string, 76, $line_break);
1344
+		}
1283 1345
 
1284 1346
 		return array($charset, $string, 'base64');
1347
+	} else {
1348
+			return array($charset, $string, '7bit');
1349
+	}
1285 1350
 	}
1286
-
1287
-	else
1288
-		return array($charset, $string, '7bit');
1289
-}
1290 1351
 
1291 1352
 /**
1292 1353
  * Sends mail, like mail() but over SMTP.
@@ -1310,8 +1371,9 @@  discard block
 block discarded – undo
1310 1371
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1311 1372
 	{
1312 1373
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1313
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1314
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1374
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1375
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1376
+		}
1315 1377
 
1316 1378
 		if ($socket)
1317 1379
 		{
@@ -1332,8 +1394,9 @@  discard block
 block discarded – undo
1332 1394
 		// Maybe we can still save this?  The port might be wrong.
1333 1395
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1334 1396
 		{
1335
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1336
-				log_error($txt['smtp_port_ssl']);
1397
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1398
+							log_error($txt['smtp_port_ssl']);
1399
+			}
1337 1400
 		}
1338 1401
 
1339 1402
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1345,20 +1408,23 @@  discard block
 block discarded – undo
1345 1408
 	}
1346 1409
 
1347 1410
 	// Wait for a response of 220, without "-" continuer.
1348
-	if (!server_parse(null, $socket, '220'))
1349
-		return false;
1411
+	if (!server_parse(null, $socket, '220')) {
1412
+			return false;
1413
+	}
1350 1414
 
1351 1415
 	// Try and determine the servers name, fall back to the mail servers if not found
1352 1416
 	$helo = false;
1353
-	if (function_exists('gethostname') && gethostname() !== false)
1354
-		$helo = gethostname();
1355
-	elseif (function_exists('php_uname'))
1356
-		$helo = php_uname('n');
1357
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1358
-		$helo = $_SERVER['SERVER_NAME'];
1417
+	if (function_exists('gethostname') && gethostname() !== false) {
1418
+			$helo = gethostname();
1419
+	} elseif (function_exists('php_uname')) {
1420
+			$helo = php_uname('n');
1421
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1422
+			$helo = $_SERVER['SERVER_NAME'];
1423
+	}
1359 1424
 
1360
-	if (empty($helo))
1361
-		$helo = $modSettings['smtp_host'];
1425
+	if (empty($helo)) {
1426
+			$helo = $modSettings['smtp_host'];
1427
+	}
1362 1428
 
1363 1429
 	// SMTP = 1, SMTP - STARTTLS = 2
1364 1430
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1370,33 +1436,39 @@  discard block
 block discarded – undo
1370 1436
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1371 1437
 			{
1372 1438
 				// Send STARTTLS to enable encryption
1373
-				if (!server_parse('STARTTLS', $socket, '220'))
1374
-					return false;
1439
+				if (!server_parse('STARTTLS', $socket, '220')) {
1440
+									return false;
1441
+				}
1375 1442
 				// Enable the encryption
1376
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1377
-					return false;
1443
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1444
+									return false;
1445
+				}
1378 1446
 				// Send the EHLO command again
1379
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1380
-					return false;
1447
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1448
+									return false;
1449
+				}
1381 1450
 			}
1382 1451
 
1383
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1384
-				return false;
1452
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1453
+							return false;
1454
+			}
1385 1455
 			// Send the username and password, encoded.
1386
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1387
-				return false;
1456
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1457
+							return false;
1458
+			}
1388 1459
 			// The password is already encoded ;)
1389
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1390
-				return false;
1460
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1461
+							return false;
1462
+			}
1463
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1464
+					return false;
1391 1465
 		}
1392
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1393
-			return false;
1394
-	}
1395
-	else
1466
+	} else
1396 1467
 	{
1397 1468
 		// Just say "helo".
1398
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1399
-			return false;
1469
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1470
+					return false;
1471
+		}
1400 1472
 	}
1401 1473
 
1402 1474
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1409,31 +1481,38 @@  discard block
 block discarded – undo
1409 1481
 		// Reset the connection to send another email.
1410 1482
 		if ($i != 0)
1411 1483
 		{
1412
-			if (!server_parse('RSET', $socket, '250'))
1413
-				return false;
1484
+			if (!server_parse('RSET', $socket, '250')) {
1485
+							return false;
1486
+			}
1414 1487
 		}
1415 1488
 
1416 1489
 		// From, to, and then start the data...
1417
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1418
-			return false;
1419
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1420
-			return false;
1421
-		if (!server_parse('DATA', $socket, '354'))
1422
-			return false;
1490
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1491
+					return false;
1492
+		}
1493
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1494
+					return false;
1495
+		}
1496
+		if (!server_parse('DATA', $socket, '354')) {
1497
+					return false;
1498
+		}
1423 1499
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1424
-		if (strlen($mail_to) > 0)
1425
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1500
+		if (strlen($mail_to) > 0) {
1501
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1502
+		}
1426 1503
 		fputs($socket, $headers . "\r\n\r\n");
1427 1504
 		fputs($socket, $message . "\r\n");
1428 1505
 
1429 1506
 		// Send a ., or in other words "end of data".
1430
-		if (!server_parse('.', $socket, '250'))
1431
-			return false;
1507
+		if (!server_parse('.', $socket, '250')) {
1508
+					return false;
1509
+		}
1432 1510
 
1433 1511
 		// Almost done, almost done... don't stop me just yet!
1434 1512
 		@set_time_limit(300);
1435
-		if (function_exists('apache_reset_timeout'))
1436
-			@apache_reset_timeout();
1513
+		if (function_exists('apache_reset_timeout')) {
1514
+					@apache_reset_timeout();
1515
+		}
1437 1516
 	}
1438 1517
 	fputs($socket, 'QUIT' . "\r\n");
1439 1518
 	fclose($socket);
@@ -1457,8 +1536,9 @@  discard block
 block discarded – undo
1457 1536
 {
1458 1537
 	global $txt;
1459 1538
 
1460
-	if ($message !== null)
1461
-		fputs($socket, $message . "\r\n");
1539
+	if ($message !== null) {
1540
+			fputs($socket, $message . "\r\n");
1541
+	}
1462 1542
 
1463 1543
 	// No response yet.
1464 1544
 	$server_response = '';
@@ -1474,8 +1554,9 @@  discard block
 block discarded – undo
1474 1554
 		$response .= $server_response;
1475 1555
 	}
1476 1556
 
1477
-	if ($code === null)
1478
-		return substr($server_response, 0, 3);
1557
+	if ($code === null) {
1558
+			return substr($server_response, 0, 3);
1559
+	}
1479 1560
 
1480 1561
 	if (substr($server_response, 0, 3) != $code)
1481 1562
 	{
@@ -1505,8 +1586,9 @@  discard block
 block discarded – undo
1505 1586
 	// Create a pspell or enchant dictionary resource
1506 1587
 	$dict = spell_init();
1507 1588
 
1508
-	if (!isset($_POST['spellstring']) || !$dict)
1509
-		die;
1589
+	if (!isset($_POST['spellstring']) || !$dict) {
1590
+			die;
1591
+	}
1510 1592
 
1511 1593
 	// Construct a bit of Javascript code.
1512 1594
 	$context['spell_js'] = '
@@ -1524,8 +1606,9 @@  discard block
 block discarded – undo
1524 1606
 		$check_word = explode('|', $alphas[$i]);
1525 1607
 
1526 1608
 		// If the word is a known word, or spelled right...
1527
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1528
-			continue;
1609
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1610
+					continue;
1611
+		}
1529 1612
 
1530 1613
 		// Find the word, and move up the "last occurrence" to here.
1531 1614
 		$found_words = true;
@@ -1539,20 +1622,23 @@  discard block
 block discarded – undo
1539 1622
 		if (!empty($suggestions))
1540 1623
 		{
1541 1624
 			// But first check they aren't going to be censored - no naughty words!
1542
-			foreach ($suggestions as $k => $word)
1543
-				if ($suggestions[$k] != censorText($word))
1625
+			foreach ($suggestions as $k => $word) {
1626
+							if ($suggestions[$k] != censorText($word))
1544 1627
 					unset($suggestions[$k]);
1628
+			}
1545 1629
 
1546
-			if (!empty($suggestions))
1547
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1630
+			if (!empty($suggestions)) {
1631
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1632
+			}
1548 1633
 		}
1549 1634
 
1550 1635
 		$context['spell_js'] .= ']),';
1551 1636
 	}
1552 1637
 
1553 1638
 	// If words were found, take off the last comma.
1554
-	if ($found_words)
1555
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1639
+	if ($found_words) {
1640
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1641
+	}
1556 1642
 
1557 1643
 	$context['spell_js'] .= '
1558 1644
 		);';
@@ -1587,11 +1673,13 @@  discard block
 block discarded – undo
1587 1673
 	global $user_info, $smcFunc;
1588 1674
 
1589 1675
 	// Can't do it if there's no topics.
1590
-	if (empty($topics))
1591
-		return;
1676
+	if (empty($topics)) {
1677
+			return;
1678
+	}
1592 1679
 	// It must be an array - it must!
1593
-	if (!is_array($topics))
1594
-		$topics = array($topics);
1680
+	if (!is_array($topics)) {
1681
+			$topics = array($topics);
1682
+	}
1595 1683
 
1596 1684
 	// Get the subject and body...
1597 1685
 	$result = $smcFunc['db_query']('', '
@@ -1639,14 +1727,15 @@  discard block
 block discarded – undo
1639 1727
 	}
1640 1728
 	$smcFunc['db_free_result']($result);
1641 1729
 
1642
-	if (!empty($task_rows))
1643
-		$smcFunc['db_insert']('',
1730
+	if (!empty($task_rows)) {
1731
+			$smcFunc['db_insert']('',
1644 1732
 			'{db_prefix}background_tasks',
1645 1733
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1646 1734
 			$task_rows,
1647 1735
 			array('id_task')
1648 1736
 		);
1649
-}
1737
+	}
1738
+	}
1650 1739
 
1651 1740
 /**
1652 1741
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1684,9 +1773,9 @@  discard block
 block discarded – undo
1684 1773
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1685 1774
 
1686 1775
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1687
-	if (!$modSettings['postmod_active'])
1688
-		$topicOptions['is_approved'] = true;
1689
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1776
+	if (!$modSettings['postmod_active']) {
1777
+			$topicOptions['is_approved'] = true;
1778
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1690 1779
 	{
1691 1780
 		$request = $smcFunc['db_query']('', '
1692 1781
 			SELECT approved
@@ -1709,8 +1798,7 @@  discard block
 block discarded – undo
1709 1798
 			$posterOptions['id'] = 0;
1710 1799
 			$posterOptions['name'] = $txt['guest_title'];
1711 1800
 			$posterOptions['email'] = '';
1712
-		}
1713
-		elseif ($posterOptions['id'] != $user_info['id'])
1801
+		} elseif ($posterOptions['id'] != $user_info['id'])
1714 1802
 		{
1715 1803
 			$request = $smcFunc['db_query']('', '
1716 1804
 				SELECT member_name, email_address
@@ -1728,12 +1816,11 @@  discard block
 block discarded – undo
1728 1816
 				$posterOptions['id'] = 0;
1729 1817
 				$posterOptions['name'] = $txt['guest_title'];
1730 1818
 				$posterOptions['email'] = '';
1819
+			} else {
1820
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1731 1821
 			}
1732
-			else
1733
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1734 1822
 			$smcFunc['db_free_result']($request);
1735
-		}
1736
-		else
1823
+		} else
1737 1824
 		{
1738 1825
 			$posterOptions['name'] = $user_info['name'];
1739 1826
 			$posterOptions['email'] = $user_info['email'];
@@ -1743,8 +1830,9 @@  discard block
 block discarded – undo
1743 1830
 	if (!empty($modSettings['enable_mentions']))
1744 1831
 	{
1745 1832
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1746
-		if (!empty($msgOptions['mentioned_members']))
1747
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1833
+		if (!empty($msgOptions['mentioned_members'])) {
1834
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1835
+		}
1748 1836
 	}
1749 1837
 
1750 1838
 	// It's do or die time: forget any user aborts!
@@ -1777,12 +1865,13 @@  discard block
 block discarded – undo
1777 1865
 	$msgOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}messages', 'id_msg');
1778 1866
 
1779 1867
 	// Something went wrong creating the message...
1780
-	if (empty($msgOptions['id']))
1781
-		return false;
1868
+	if (empty($msgOptions['id'])) {
1869
+			return false;
1870
+	}
1782 1871
 
1783 1872
 	// Fix the attachments.
1784
-	if (!empty($msgOptions['attachments']))
1785
-		$smcFunc['db_query']('', '
1873
+	if (!empty($msgOptions['attachments'])) {
1874
+			$smcFunc['db_query']('', '
1786 1875
 			UPDATE {db_prefix}attachments
1787 1876
 			SET id_msg = {int:id_msg}
1788 1877
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1791,6 +1880,7 @@  discard block
 block discarded – undo
1791 1880
 				'id_msg' => $msgOptions['id'],
1792 1881
 			)
1793 1882
 		);
1883
+	}
1794 1884
 
1795 1885
 	// What if we want to export new posts out to a CMS?
1796 1886
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1868,20 +1958,23 @@  discard block
 block discarded – undo
1868 1958
 			'counter_increment' => 1,
1869 1959
 		);
1870 1960
 		$topics_columns = array();
1871
-		if ($msgOptions['approved'])
1872
-			$topics_columns = array(
1961
+		if ($msgOptions['approved']) {
1962
+					$topics_columns = array(
1873 1963
 				'id_member_updated = {int:poster_id}',
1874 1964
 				'id_last_msg = {int:id_msg}',
1875 1965
 				'num_replies = num_replies + {int:counter_increment}',
1876 1966
 			);
1877
-		else
1878
-			$topics_columns = array(
1967
+		} else {
1968
+					$topics_columns = array(
1879 1969
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1880 1970
 			);
1881
-		if ($topicOptions['lock_mode'] !== null)
1882
-			$topics_columns[] = 'locked = {int:locked}';
1883
-		if ($topicOptions['sticky_mode'] !== null)
1884
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1971
+		}
1972
+		if ($topicOptions['lock_mode'] !== null) {
1973
+					$topics_columns[] = 'locked = {int:locked}';
1974
+		}
1975
+		if ($topicOptions['sticky_mode'] !== null) {
1976
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1977
+		}
1885 1978
 
1886 1979
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1887 1980
 
@@ -1910,8 +2003,8 @@  discard block
 block discarded – undo
1910 2003
 	);
1911 2004
 
1912 2005
 	// Increase the number of posts and topics on the board.
1913
-	if ($msgOptions['approved'])
1914
-		$smcFunc['db_query']('', '
2006
+	if ($msgOptions['approved']) {
2007
+			$smcFunc['db_query']('', '
1915 2008
 			UPDATE {db_prefix}boards
1916 2009
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1917 2010
 			WHERE id_board = {int:id_board}',
@@ -1919,7 +2012,7 @@  discard block
 block discarded – undo
1919 2012
 				'id_board' => $topicOptions['board'],
1920 2013
 			)
1921 2014
 		);
1922
-	else
2015
+	} else
1923 2016
 	{
1924 2017
 		$smcFunc['db_query']('', '
1925 2018
 			UPDATE {db_prefix}boards
@@ -1989,8 +2082,8 @@  discard block
 block discarded – undo
1989 2082
 		}
1990 2083
 	}
1991 2084
 
1992
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1993
-		$smcFunc['db_insert']('',
2085
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2086
+			$smcFunc['db_insert']('',
1994 2087
 			'{db_prefix}background_tasks',
1995 2088
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1996 2089
 			array(
@@ -2002,19 +2095,22 @@  discard block
 block discarded – undo
2002 2095
 			),
2003 2096
 			array('id_task')
2004 2097
 		);
2098
+	}
2005 2099
 
2006 2100
 	// If there's a custom search index, it may need updating...
2007 2101
 	require_once($sourcedir . '/Search.php');
2008 2102
 	$searchAPI = findSearchAPI();
2009
-	if (is_callable(array($searchAPI, 'postCreated')))
2010
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2103
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2104
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2105
+	}
2011 2106
 
2012 2107
 	// Increase the post counter for the user that created the post.
2013 2108
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2014 2109
 	{
2015 2110
 		// Are you the one that happened to create this post?
2016
-		if ($user_info['id'] == $posterOptions['id'])
2017
-			$user_info['posts']++;
2111
+		if ($user_info['id'] == $posterOptions['id']) {
2112
+					$user_info['posts']++;
2113
+		}
2018 2114
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2019 2115
 	}
2020 2116
 
@@ -2022,19 +2118,21 @@  discard block
 block discarded – undo
2022 2118
 	$_SESSION['last_read_topic'] = 0;
2023 2119
 
2024 2120
 	// Better safe than sorry.
2025
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2026
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2121
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2122
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2123
+	}
2027 2124
 
2028 2125
 	// Update all the stats so everyone knows about this new topic and message.
2029 2126
 	updateStats('message', true, $msgOptions['id']);
2030 2127
 
2031 2128
 	// Update the last message on the board assuming it's approved AND the topic is.
2032
-	if ($msgOptions['approved'])
2033
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2129
+	if ($msgOptions['approved']) {
2130
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2131
+	}
2034 2132
 
2035 2133
 	// Queue createPost background notification
2036
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2037
-		$smcFunc['db_insert']('',
2134
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2135
+			$smcFunc['db_insert']('',
2038 2136
 			'{db_prefix}background_tasks',
2039 2137
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2040 2138
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array(
@@ -2045,6 +2143,7 @@  discard block
 block discarded – undo
2045 2143
 			)), 0),
2046 2144
 			array('id_task')
2047 2145
 		);
2146
+	}
2048 2147
 
2049 2148
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2050 2149
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2071,14 +2170,18 @@  discard block
 block discarded – undo
2071 2170
 
2072 2171
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2073 2172
 	$messages_columns = array();
2074
-	if (isset($posterOptions['name']))
2075
-		$messages_columns['poster_name'] = $posterOptions['name'];
2076
-	if (isset($posterOptions['email']))
2077
-		$messages_columns['poster_email'] = $posterOptions['email'];
2078
-	if (isset($msgOptions['icon']))
2079
-		$messages_columns['icon'] = $msgOptions['icon'];
2080
-	if (isset($msgOptions['subject']))
2081
-		$messages_columns['subject'] = $msgOptions['subject'];
2173
+	if (isset($posterOptions['name'])) {
2174
+			$messages_columns['poster_name'] = $posterOptions['name'];
2175
+	}
2176
+	if (isset($posterOptions['email'])) {
2177
+			$messages_columns['poster_email'] = $posterOptions['email'];
2178
+	}
2179
+	if (isset($msgOptions['icon'])) {
2180
+			$messages_columns['icon'] = $msgOptions['icon'];
2181
+	}
2182
+	if (isset($msgOptions['subject'])) {
2183
+			$messages_columns['subject'] = $msgOptions['subject'];
2184
+	}
2082 2185
 	if (isset($msgOptions['body']))
2083 2186
 	{
2084 2187
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2105,8 +2208,9 @@  discard block
 block discarded – undo
2105 2208
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2106 2209
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2107 2210
 	}
2108
-	if (isset($msgOptions['smileys_enabled']))
2109
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2211
+	if (isset($msgOptions['smileys_enabled'])) {
2212
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2213
+	}
2110 2214
 
2111 2215
 	// Which columns need to be ints?
2112 2216
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2124,23 +2228,27 @@  discard block
 block discarded – undo
2124 2228
 		{
2125 2229
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2126 2230
 
2127
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2128
-				foreach ($match[1] as $i => $oldID)
2231
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2232
+							foreach ($match[1] as $i => $oldID)
2129 2233
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2234
+			}
2130 2235
 
2131
-			if (empty($modSettings['search_custom_index_config']))
2132
-				unset($msgOptions['old_body']);
2236
+			if (empty($modSettings['search_custom_index_config'])) {
2237
+							unset($msgOptions['old_body']);
2238
+			}
2133 2239
 		}
2134 2240
 
2135 2241
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2136 2242
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2137 2243
 
2138 2244
 		// Remove the poster.
2139
-		if (isset($mentions[$user_info['id']]))
2140
-			unset($mentions[$user_info['id']]);
2245
+		if (isset($mentions[$user_info['id']])) {
2246
+					unset($mentions[$user_info['id']]);
2247
+		}
2141 2248
 
2142
-		if (isset($oldmentions[$user_info['id']]))
2143
-			unset($oldmentions[$user_info['id']]);
2249
+		if (isset($oldmentions[$user_info['id']])) {
2250
+					unset($oldmentions[$user_info['id']]);
2251
+		}
2144 2252
 
2145 2253
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2146 2254
 		{
@@ -2170,8 +2278,9 @@  discard block
 block discarded – undo
2170 2278
 	}
2171 2279
 
2172 2280
 	// Nothing to do?
2173
-	if (empty($messages_columns))
2174
-		return true;
2281
+	if (empty($messages_columns)) {
2282
+			return true;
2283
+	}
2175 2284
 
2176 2285
 	// Change the post.
2177 2286
 	$smcFunc['db_query']('', '
@@ -2232,8 +2341,9 @@  discard block
 block discarded – undo
2232 2341
 	// If there's a custom search index, it needs to be modified...
2233 2342
 	require_once($sourcedir . '/Search.php');
2234 2343
 	$searchAPI = findSearchAPI();
2235
-	if (is_callable(array($searchAPI, 'postModified')))
2236
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2344
+	if (is_callable(array($searchAPI, 'postModified'))) {
2345
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2346
+	}
2237 2347
 
2238 2348
 	if (isset($msgOptions['subject']))
2239 2349
 	{
@@ -2247,14 +2357,16 @@  discard block
 block discarded – undo
2247 2357
 				'id_first_msg' => $msgOptions['id'],
2248 2358
 			)
2249 2359
 		);
2250
-		if ($smcFunc['db_num_rows']($request) == 1)
2251
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2360
+		if ($smcFunc['db_num_rows']($request) == 1) {
2361
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2362
+		}
2252 2363
 		$smcFunc['db_free_result']($request);
2253 2364
 	}
2254 2365
 
2255 2366
 	// Finally, if we are setting the approved state we need to do much more work :(
2256
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2257
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2367
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2368
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2369
+	}
2258 2370
 
2259 2371
 	return true;
2260 2372
 }
@@ -2271,11 +2383,13 @@  discard block
 block discarded – undo
2271 2383
 {
2272 2384
 	global $smcFunc;
2273 2385
 
2274
-	if (!is_array($msgs))
2275
-		$msgs = array($msgs);
2386
+	if (!is_array($msgs)) {
2387
+			$msgs = array($msgs);
2388
+	}
2276 2389
 
2277
-	if (empty($msgs))
2278
-		return false;
2390
+	if (empty($msgs)) {
2391
+			return false;
2392
+	}
2279 2393
 
2280 2394
 	// May as well start at the beginning, working out *what* we need to change.
2281 2395
 	$request = $smcFunc['db_query']('', '
@@ -2307,20 +2421,22 @@  discard block
 block discarded – undo
2307 2421
 		$topics[] = $row['id_topic'];
2308 2422
 
2309 2423
 		// Ensure our change array exists already.
2310
-		if (!isset($topic_changes[$row['id_topic']]))
2311
-			$topic_changes[$row['id_topic']] = array(
2424
+		if (!isset($topic_changes[$row['id_topic']])) {
2425
+					$topic_changes[$row['id_topic']] = array(
2312 2426
 				'id_last_msg' => $row['id_last_msg'],
2313 2427
 				'approved' => $row['topic_approved'],
2314 2428
 				'replies' => 0,
2315 2429
 				'unapproved_posts' => 0,
2316 2430
 			);
2317
-		if (!isset($board_changes[$row['id_board']]))
2318
-			$board_changes[$row['id_board']] = array(
2431
+		}
2432
+		if (!isset($board_changes[$row['id_board']])) {
2433
+					$board_changes[$row['id_board']] = array(
2319 2434
 				'posts' => 0,
2320 2435
 				'topics' => 0,
2321 2436
 				'unapproved_posts' => 0,
2322 2437
 				'unapproved_topics' => 0,
2323 2438
 			);
2439
+		}
2324 2440
 
2325 2441
 		// If it's the first message then the topic state changes!
2326 2442
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2341,14 +2457,13 @@  discard block
 block discarded – undo
2341 2457
 				'poster' => $row['id_member'],
2342 2458
 				'new_topic' => true,
2343 2459
 			);
2344
-		}
2345
-		else
2460
+		} else
2346 2461
 		{
2347 2462
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2348 2463
 
2349 2464
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2350
-			if ($row['id_msg'] > $row['id_last_msg'])
2351
-				$notification_posts[$row['id_topic']] = array(
2465
+			if ($row['id_msg'] > $row['id_last_msg']) {
2466
+							$notification_posts[$row['id_topic']] = array(
2352 2467
 					'id' => $row['id_msg'],
2353 2468
 					'body' => $row['body'],
2354 2469
 					'subject' => $row['subject'],
@@ -2359,28 +2474,33 @@  discard block
 block discarded – undo
2359 2474
 					'new_topic' => false,
2360 2475
 					'msg' => $row['id_msg'],
2361 2476
 				);
2477
+			}
2362 2478
 		}
2363 2479
 
2364 2480
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2365
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2366
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2481
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2482
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2483
+		}
2367 2484
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2368
-		elseif (!$approve)
2369
-			// Default to the first message and then we'll override in a bit ;)
2485
+		elseif (!$approve) {
2486
+					// Default to the first message and then we'll override in a bit ;)
2370 2487
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2488
+		}
2371 2489
 
2372 2490
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2373 2491
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2374 2492
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2375 2493
 
2376 2494
 		// Post count for the user?
2377
-		if ($row['id_member'] && empty($row['count_posts']))
2378
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2495
+		if ($row['id_member'] && empty($row['count_posts'])) {
2496
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2497
+		}
2379 2498
 	}
2380 2499
 	$smcFunc['db_free_result']($request);
2381 2500
 
2382
-	if (empty($msgs))
2383
-		return;
2501
+	if (empty($msgs)) {
2502
+			return;
2503
+	}
2384 2504
 
2385 2505
 	// Now we have the differences make the changes, first the easy one.
2386 2506
 	$smcFunc['db_query']('', '
@@ -2407,14 +2527,15 @@  discard block
 block discarded – undo
2407 2527
 				'approved' => 1,
2408 2528
 			)
2409 2529
 		);
2410
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2411
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2530
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2531
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2532
+		}
2412 2533
 		$smcFunc['db_free_result']($request);
2413 2534
 	}
2414 2535
 
2415 2536
 	// ... next the topics...
2416
-	foreach ($topic_changes as $id => $changes)
2417
-		$smcFunc['db_query']('', '
2537
+	foreach ($topic_changes as $id => $changes) {
2538
+			$smcFunc['db_query']('', '
2418 2539
 			UPDATE {db_prefix}topics
2419 2540
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2420 2541
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2427,10 +2548,11 @@  discard block
 block discarded – undo
2427 2548
 				'id_topic' => $id,
2428 2549
 			)
2429 2550
 		);
2551
+	}
2430 2552
 
2431 2553
 	// ... finally the boards...
2432
-	foreach ($board_changes as $id => $changes)
2433
-		$smcFunc['db_query']('', '
2554
+	foreach ($board_changes as $id => $changes) {
2555
+			$smcFunc['db_query']('', '
2434 2556
 			UPDATE {db_prefix}boards
2435 2557
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2436 2558
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2443,13 +2565,14 @@  discard block
 block discarded – undo
2443 2565
 				'id_board' => $id,
2444 2566
 			)
2445 2567
 		);
2568
+	}
2446 2569
 
2447 2570
 	// Finally, least importantly, notifications!
2448 2571
 	if ($approve)
2449 2572
 	{
2450 2573
 		$task_rows = array();
2451
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2452
-			$task_rows[] = array(
2574
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2575
+					$task_rows[] = array(
2453 2576
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', json_encode(array(
2454 2577
 					'msgOptions' => array(
2455 2578
 						'id' => $topic['msg'],
@@ -2467,14 +2590,16 @@  discard block
 block discarded – undo
2467 2590
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2468 2591
 				)), 0
2469 2592
 			);
2593
+		}
2470 2594
 
2471
-		if ($notify)
2472
-			$smcFunc['db_insert']('',
2595
+		if ($notify) {
2596
+					$smcFunc['db_insert']('',
2473 2597
 				'{db_prefix}background_tasks',
2474 2598
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2475 2599
 				$task_rows,
2476 2600
 				array('id_task')
2477 2601
 			);
2602
+		}
2478 2603
 
2479 2604
 		$smcFunc['db_query']('', '
2480 2605
 			DELETE FROM {db_prefix}approval_queue
@@ -2490,8 +2615,9 @@  discard block
 block discarded – undo
2490 2615
 	else
2491 2616
 	{
2492 2617
 		$msgInserts = array();
2493
-		foreach ($msgs as $msg)
2494
-			$msgInserts[] = array($msg);
2618
+		foreach ($msgs as $msg) {
2619
+					$msgInserts[] = array($msg);
2620
+		}
2495 2621
 
2496 2622
 		$smcFunc['db_insert']('ignore',
2497 2623
 			'{db_prefix}approval_queue',
@@ -2505,9 +2631,10 @@  discard block
 block discarded – undo
2505 2631
 	updateLastMessages(array_keys($board_changes));
2506 2632
 
2507 2633
 	// Post count for the members?
2508
-	if (!empty($member_post_changes))
2509
-		foreach ($member_post_changes as $id_member => $count_change)
2634
+	if (!empty($member_post_changes)) {
2635
+			foreach ($member_post_changes as $id_member => $count_change)
2510 2636
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2637
+	}
2511 2638
 
2512 2639
 	return true;
2513 2640
 }
@@ -2524,11 +2651,13 @@  discard block
 block discarded – undo
2524 2651
 {
2525 2652
 	global $smcFunc;
2526 2653
 
2527
-	if (!is_array($topics))
2528
-		$topics = array($topics);
2654
+	if (!is_array($topics)) {
2655
+			$topics = array($topics);
2656
+	}
2529 2657
 
2530
-	if (empty($topics))
2531
-		return false;
2658
+	if (empty($topics)) {
2659
+			return false;
2660
+	}
2532 2661
 
2533 2662
 	$approve_type = $approve ? 0 : 1;
2534 2663
 
@@ -2544,8 +2673,9 @@  discard block
 block discarded – undo
2544 2673
 		)
2545 2674
 	);
2546 2675
 	$msgs = array();
2547
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2548
-		$msgs[] = $row['id_msg'];
2676
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2677
+			$msgs[] = $row['id_msg'];
2678
+	}
2549 2679
 	$smcFunc['db_free_result']($request);
2550 2680
 
2551 2681
 	return approvePosts($msgs, $approve);
@@ -2568,11 +2698,13 @@  discard block
 block discarded – undo
2568 2698
 	global $board_info, $board, $smcFunc;
2569 2699
 
2570 2700
 	// Please - let's be sane.
2571
-	if (empty($setboards))
2572
-		return false;
2701
+	if (empty($setboards)) {
2702
+			return false;
2703
+	}
2573 2704
 
2574
-	if (!is_array($setboards))
2575
-		$setboards = array($setboards);
2705
+	if (!is_array($setboards)) {
2706
+			$setboards = array($setboards);
2707
+	}
2576 2708
 
2577 2709
 	// If we don't know the id_msg we need to find it.
2578 2710
 	if (!$id_msg)
@@ -2590,15 +2722,16 @@  discard block
 block discarded – undo
2590 2722
 			)
2591 2723
 		);
2592 2724
 		$lastMsg = array();
2593
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2594
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2725
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2726
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2727
+		}
2595 2728
 		$smcFunc['db_free_result']($request);
2596
-	}
2597
-	else
2729
+	} else
2598 2730
 	{
2599 2731
 		// Just to note - there should only be one board passed if we are doing this.
2600
-		foreach ($setboards as $id_board)
2601
-			$lastMsg[$id_board] = $id_msg;
2732
+		foreach ($setboards as $id_board) {
2733
+					$lastMsg[$id_board] = $id_msg;
2734
+		}
2602 2735
 	}
2603 2736
 
2604 2737
 	$parent_boards = array();
@@ -2613,10 +2746,11 @@  discard block
 block discarded – undo
2613 2746
 			$lastModified[$id_board] = 0;
2614 2747
 		}
2615 2748
 
2616
-		if (!empty($board) && $id_board == $board)
2617
-			$parents = $board_info['parent_boards'];
2618
-		else
2619
-			$parents = getBoardParents($id_board);
2749
+		if (!empty($board) && $id_board == $board) {
2750
+					$parents = $board_info['parent_boards'];
2751
+		} else {
2752
+					$parents = getBoardParents($id_board);
2753
+		}
2620 2754
 
2621 2755
 		// Ignore any parents on the top child level.
2622 2756
 		// @todo Why?
@@ -2625,10 +2759,11 @@  discard block
 block discarded – undo
2625 2759
 			if ($parent['level'] != 0)
2626 2760
 			{
2627 2761
 				// If we're already doing this one as a board, is this a higher last modified?
2628
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2629
-					$lastModified[$id] = $lastModified[$id_board];
2630
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2631
-					$parent_boards[$id] = $lastModified[$id_board];
2762
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2763
+									$lastModified[$id] = $lastModified[$id_board];
2764
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2765
+									$parent_boards[$id] = $lastModified[$id_board];
2766
+				}
2632 2767
 			}
2633 2768
 		}
2634 2769
 	}
@@ -2641,23 +2776,24 @@  discard block
 block discarded – undo
2641 2776
 	// Finally, to save on queries make the changes...
2642 2777
 	foreach ($parent_boards as $id => $msg)
2643 2778
 	{
2644
-		if (!isset($parent_updates[$msg]))
2645
-			$parent_updates[$msg] = array($id);
2646
-		else
2647
-			$parent_updates[$msg][] = $id;
2779
+		if (!isset($parent_updates[$msg])) {
2780
+					$parent_updates[$msg] = array($id);
2781
+		} else {
2782
+					$parent_updates[$msg][] = $id;
2783
+		}
2648 2784
 	}
2649 2785
 
2650 2786
 	foreach ($lastMsg as $id => $msg)
2651 2787
 	{
2652
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2653
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2788
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2789
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2654 2790
 				'id' => $msg,
2655 2791
 				'updated' => $lastModified[$id],
2656 2792
 				'boards' => array($id)
2657 2793
 			);
2658
-
2659
-		else
2660
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2794
+		} else {
2795
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2796
+		}
2661 2797
 	}
2662 2798
 
2663 2799
 	// Now commit the changes!
@@ -2749,11 +2885,13 @@  discard block
 block discarded – undo
2749 2885
 	global $txt, $mbname, $scripturl, $settings;
2750 2886
 
2751 2887
 	// First things first, load up the email templates language file, if we need to.
2752
-	if ($loadLang)
2753
-		loadLanguage('EmailTemplates', $lang);
2888
+	if ($loadLang) {
2889
+			loadLanguage('EmailTemplates', $lang);
2890
+	}
2754 2891
 
2755
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2756
-		fatal_lang_error('email_no_template', 'template', array($template));
2892
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2893
+			fatal_lang_error('email_no_template', 'template', array($template));
2894
+	}
2757 2895
 
2758 2896
 	$ret = array(
2759 2897
 		'subject' => $txt[$template . '_subject'],
@@ -2803,17 +2941,18 @@  discard block
 block discarded – undo
2803 2941
 function user_info_callback($matches)
2804 2942
 {
2805 2943
 	global $user_info;
2806
-	if (empty($matches[1]))
2807
-		return '';
2944
+	if (empty($matches[1])) {
2945
+			return '';
2946
+	}
2808 2947
 
2809 2948
 	$use_ref = true;
2810 2949
 	$ref = &$user_info;
2811 2950
 
2812 2951
 	foreach (explode('.', $matches[1]) as $index)
2813 2952
 	{
2814
-		if ($use_ref && isset($ref[$index]))
2815
-			$ref = &$ref[$index];
2816
-		else
2953
+		if ($use_ref && isset($ref[$index])) {
2954
+					$ref = &$ref[$index];
2955
+		} else
2817 2956
 		{
2818 2957
 			$use_ref = false;
2819 2958
 			break;
@@ -2850,8 +2989,7 @@  discard block
 block discarded – undo
2850 2989
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2851 2990
 		{
2852 2991
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2853
-		}
2854
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2992
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2855 2993
 		{
2856 2994
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2857 2995
 		}
@@ -2861,8 +2999,7 @@  discard block
 block discarded – undo
2861 2999
 		{
2862 3000
 			$context['provider'] = 'enchant';
2863 3001
 			return $enchant_link;
2864
-		}
2865
-		else
3002
+		} else
2866 3003
 		{
2867 3004
 			// Free up any resources used...
2868 3005
 			@enchant_broker_free($context['enchant_broker']);
@@ -2883,8 +3020,9 @@  discard block
 block discarded – undo
2883 3020
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2884 3021
 
2885 3022
 		// Most people don't have anything but English installed... So we use English as a last resort.
2886
-		if (!$pspell_link)
2887
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3023
+		if (!$pspell_link) {
3024
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3025
+		}
2888 3026
 
2889 3027
 		error_reporting($old);
2890 3028
 		ob_end_clean();
@@ -2924,8 +3062,7 @@  discard block
 block discarded – undo
2924 3062
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2925 3063
 		}
2926 3064
 		return enchant_dict_check($dict, $word);
2927
-	}
2928
-	elseif ($context['provider'] == 'pspell')
3065
+	} elseif ($context['provider'] == 'pspell')
2929 3066
 	{
2930 3067
 		return pspell_check($dict, $word);
2931 3068
 	}
@@ -2961,13 +3098,11 @@  discard block
 block discarded – undo
2961 3098
 			}
2962 3099
 
2963 3100
 			return $suggestions;
2964
-		}
2965
-		else
3101
+		} else
2966 3102
 		{
2967 3103
 			return enchant_dict_suggest($dict, $word);
2968 3104
 		}
2969
-	}
2970
-	elseif ($context['provider'] == 'pspell')
3105
+	} elseif ($context['provider'] == 'pspell')
2971 3106
 	{
2972 3107
 		return pspell_suggest($dict, $word);
2973 3108
 	}
Please login to merge, or discard this patch.
Sources/Packages.php 1 patch
Braces   +599 added lines, -484 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * This is the notoriously defunct package manager..... :/.
@@ -57,10 +58,11 @@  discard block
 block discarded – undo
57 58
 	);
58 59
 
59 60
 	// Work out exactly who it is we are calling.
60
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
61
-		$context['sub_action'] = $_REQUEST['sa'];
62
-	else
63
-		$context['sub_action'] = 'browse';
61
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
62
+			$context['sub_action'] = $_REQUEST['sa'];
63
+	} else {
64
+			$context['sub_action'] = 'browse';
65
+	}
64 66
 
65 67
 	// Set up some tabs...
66 68
 	$context[$context['admin_menu_name']]['tab_data'] = array(
@@ -82,8 +84,9 @@  discard block
 block discarded – undo
82 84
 		),
83 85
 	);
84 86
 
85
-	if ($context['sub_action'] == 'browse')
86
-		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
87
+	if ($context['sub_action'] == 'browse') {
88
+			loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
89
+	}
87 90
 
88 91
 	call_integration_hook('integrate_manage_packages', array(&$subActions));
89 92
 
@@ -99,8 +102,9 @@  discard block
 block discarded – undo
99 102
 	global $boarddir, $txt, $context, $scripturl, $sourcedir, $packagesdir, $modSettings, $smcFunc, $settings;
100 103
 
101 104
 	// You have to specify a file!!
102
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
103
-		redirectexit('action=admin;area=packages');
105
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
106
+			redirectexit('action=admin;area=packages');
107
+	}
104 108
 	$context['filename'] = preg_replace('~[\.]+~', '.', $_REQUEST['package']);
105 109
 
106 110
 	// Do we have an existing id, for uninstalls and the like.
@@ -112,8 +116,9 @@  discard block
 block discarded – undo
112 116
 	create_chmod_control();
113 117
 
114 118
 	// Make sure temp directory exists and is empty.
115
-	if (file_exists($packagesdir . '/temp'))
116
-		deltree($packagesdir . '/temp', false);
119
+	if (file_exists($packagesdir . '/temp')) {
120
+			deltree($packagesdir . '/temp', false);
121
+	}
117 122
 
118 123
 	if (!mktree($packagesdir . '/temp', 0755))
119 124
 	{
@@ -124,8 +129,9 @@  discard block
 block discarded – undo
124 129
 			create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package'], 'crash_on_error' => true));
125 130
 
126 131
 			deltree($packagesdir . '/temp', false);
127
-			if (!mktree($packagesdir . '/temp', 0777))
128
-				fatal_lang_error('package_cant_download', false);
132
+			if (!mktree($packagesdir . '/temp', 0777)) {
133
+							fatal_lang_error('package_cant_download', false);
134
+			}
129 135
 		}
130 136
 	}
131 137
 
@@ -151,25 +157,26 @@  discard block
 block discarded – undo
151 157
 	{
152 158
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
153 159
 
154
-		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml'))
155
-			foreach ($context['extracted_files'] as $file)
160
+		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) {
161
+					foreach ($context['extracted_files'] as $file)
156 162
 				if (basename($file['filename']) == 'package-info.xml')
157 163
 				{
158 164
 					$context['base_path'] = dirname($file['filename']) . '/';
165
+		}
159 166
 					break;
160 167
 				}
161 168
 
162
-		if (!isset($context['base_path']))
163
-			$context['base_path'] = '';
164
-	}
165
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
169
+		if (!isset($context['base_path'])) {
170
+					$context['base_path'] = '';
171
+		}
172
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
166 173
 	{
167 174
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
168 175
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
169 176
 		$context['base_path'] = '';
177
+	} else {
178
+			fatal_lang_error('no_access', false);
170 179
 	}
171
-	else
172
-		fatal_lang_error('no_access', false);
173 180
 
174 181
 	// Load up any custom themes we may want to install into...
175 182
 	$request = $smcFunc['db_query']('', '
@@ -185,15 +192,17 @@  discard block
 block discarded – undo
185 192
 		)
186 193
 	);
187 194
 	$theme_paths = array();
188
-	while ($row = $smcFunc['db_fetch_assoc']($request))
189
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
195
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
196
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
197
+	}
190 198
 	$smcFunc['db_free_result']($request);
191 199
 
192 200
 	// Get the package info...
193 201
 	$packageInfo = getPackageInfo($context['filename']);
194 202
 
195
-	if (!is_array($packageInfo))
196
-		fatal_lang_error($packageInfo);
203
+	if (!is_array($packageInfo)) {
204
+			fatal_lang_error($packageInfo);
205
+	}
197 206
 
198 207
 	$packageInfo['filename'] = $context['filename'];
199 208
 	$context['package_name'] = isset($packageInfo['name']) ? $packageInfo['name'] : $context['filename'];
@@ -227,18 +236,19 @@  discard block
 block discarded – undo
227 236
 	$smcFunc['db_free_result']($request);
228 237
 
229 238
 	$context['database_changes'] = array();
230
-	if (isset($packageInfo['uninstall']['database']))
231
-		$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
232
-	elseif (!empty($db_changes))
239
+	if (isset($packageInfo['uninstall']['database'])) {
240
+			$context['database_changes'][] = $txt['execute_database_changes'] . ' - ' . $packageInfo['uninstall']['database'];
241
+	} elseif (!empty($db_changes))
233 242
 	{
234 243
 		foreach ($db_changes as $change)
235 244
 		{
236
-			if (isset($change[2]) && isset($txt['package_db_' . $change[0]]))
237
-				$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
238
-			elseif (isset($txt['package_db_' . $change[0]]))
239
-				$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
240
-			else
241
-				$context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
245
+			if (isset($change[2]) && isset($txt['package_db_' . $change[0]])) {
246
+							$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1], $change[2]);
247
+			} elseif (isset($txt['package_db_' . $change[0]])) {
248
+							$context['database_changes'][] = sprintf($txt['package_db_' . $change[0]], $change[1]);
249
+			} else {
250
+							$context['database_changes'][] = $change[0] . '-' . $change[1] . (isset($change[2]) ? '-' . $change[2] : '');
251
+			}
242 252
 		}
243 253
 	}
244 254
 
@@ -265,31 +275,33 @@  discard block
 block discarded – undo
265 275
 		$context['themes_locked'] = true;
266 276
 
267 277
 		// Only let them uninstall themes it was installed into.
268
-		foreach ($theme_paths as $id => $data)
269
-			if ($id != 1 && !in_array($id, $old_themes))
278
+		foreach ($theme_paths as $id => $data) {
279
+					if ($id != 1 && !in_array($id, $old_themes))
270 280
 				unset($theme_paths[$id]);
271
-	}
272
-	elseif (isset($old_version) && $old_version != $packageInfo['version'])
281
+		}
282
+	} elseif (isset($old_version) && $old_version != $packageInfo['version'])
273 283
 	{
274 284
 		// Look for an upgrade...
275 285
 		$actions = parsePackageInfo($packageInfo['xml'], true, 'upgrade', $old_version);
276 286
 
277 287
 		// There was no upgrade....
278
-		if (empty($actions))
279
-			$context['is_installed'] = true;
280
-		else
288
+		if (empty($actions)) {
289
+					$context['is_installed'] = true;
290
+		} else
281 291
 		{
282 292
 			// Otherwise they can only upgrade themes from the first time around.
283
-			foreach ($theme_paths as $id => $data)
284
-				if ($id != 1 && !in_array($id, $old_themes))
293
+			foreach ($theme_paths as $id => $data) {
294
+							if ($id != 1 && !in_array($id, $old_themes))
285 295
 					unset($theme_paths[$id]);
296
+			}
286 297
 		}
298
+	} elseif (isset($old_version) && $old_version == $packageInfo['version']) {
299
+			$context['is_installed'] = true;
287 300
 	}
288
-	elseif (isset($old_version) && $old_version == $packageInfo['version'])
289
-		$context['is_installed'] = true;
290 301
 
291
-	if (!isset($old_version) || $context['is_installed'])
292
-		$actions = parsePackageInfo($packageInfo['xml'], true, 'install');
302
+	if (!isset($old_version) || $context['is_installed']) {
303
+			$actions = parsePackageInfo($packageInfo['xml'], true, 'install');
304
+	}
293 305
 
294 306
 	$context['actions'] = array();
295 307
 	$context['ftp_needed'] = false;
@@ -297,8 +309,9 @@  discard block
 block discarded – undo
297 309
 	$chmod_files = array();
298 310
 
299 311
 	// no actions found, return so we can display an error
300
-	if (empty($actions))
301
-		return;
312
+	if (empty($actions)) {
313
+			return;
314
+	}
302 315
 
303 316
 	// This will hold data about anything that can be installed in other themes.
304 317
 	$themeFinds = array(
@@ -317,14 +330,14 @@  discard block
 block discarded – undo
317 330
 		{
318 331
 			$chmod_files[] = $action['filename'];
319 332
 			continue;
320
-		}
321
-		elseif ($action['type'] == 'readme' || $action['type'] == 'license')
333
+		} elseif ($action['type'] == 'readme' || $action['type'] == 'license')
322 334
 		{
323 335
 			$type = 'package_' . $action['type'];
324
-			if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
325
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
326
-			elseif (file_exists($action['filename']))
327
-				$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
336
+			if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
337
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), "\n\r"));
338
+			} elseif (file_exists($action['filename'])) {
339
+							$context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r"));
340
+			}
328 341
 
329 342
 			if (!empty($action['parse_bbc']))
330 343
 			{
@@ -332,24 +345,24 @@  discard block
 block discarded – undo
332 345
 				$context[$type] = preg_replace('~\[[/]?html\]~i', '', $context[$type]);
333 346
 				preparsecode($context[$type]);
334 347
 				$context[$type] = parse_bbc($context[$type]);
348
+			} else {
349
+							$context[$type] = nl2br($context[$type]);
335 350
 			}
336
-			else
337
-				$context[$type] = nl2br($context[$type]);
338 351
 
339 352
 			continue;
340 353
 		}
341 354
 		// Don't show redirects.
342
-		elseif ($action['type'] == 'redirect')
343
-			continue;
344
-		elseif ($action['type'] == 'error')
355
+		elseif ($action['type'] == 'redirect') {
356
+					continue;
357
+		} elseif ($action['type'] == 'error')
345 358
 		{
346 359
 			$context['has_failure'] = true;
347
-			if (isset($action['error_msg']) && isset($action['error_var']))
348
-				$context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
349
-			elseif (isset($action['error_msg']))
350
-				$context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
351
-		}
352
-		elseif ($action['type'] == 'modification')
360
+			if (isset($action['error_msg']) && isset($action['error_var'])) {
361
+							$context['failure_details'] = sprintf($txt['package_will_fail_' . $action['error_msg']], $action['error_var']);
362
+			} elseif (isset($action['error_msg'])) {
363
+							$context['failure_details'] = isset($txt['package_will_fail_' . $action['error_msg']]) ? $txt['package_will_fail_' . $action['error_msg']] : $action['error_msg'];
364
+			}
365
+		} elseif ($action['type'] == 'modification')
353 366
 		{
354 367
 			if (!file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
355 368
 			{
@@ -361,52 +374,54 @@  discard block
 block discarded – undo
361 374
 					'description' => $txt['package_action_missing'],
362 375
 					'failed' => true,
363 376
 				);
364
-			}
365
-			else
377
+			} else
366 378
 			{
367 379
 
368
-				if ($action['boardmod'])
369
-					$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
370
-				else
371
-					$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
380
+				if ($action['boardmod']) {
381
+									$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
382
+				} else {
383
+									$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), true, $action['reverse'], $theme_paths);
384
+				}
372 385
 
373
-				if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-')
374
-					$mod_actions[0]['filename'] = $action['filename'];
386
+				if (count($mod_actions) == 1 && isset($mod_actions[0]) && $mod_actions[0]['type'] == 'error' && $mod_actions[0]['filename'] == '-') {
387
+									$mod_actions[0]['filename'] = $action['filename'];
388
+				}
375 389
 
376 390
 				foreach ($mod_actions as $key => $mod_action)
377 391
 				{
378 392
 					// Lets get the last section of the file name.
379
-					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php')
380
-						$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
381
-					elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches))
382
-						$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
383
-					else
384
-						$actual_filename = $key;
385
-
386
-					if ($mod_action['type'] == 'opened')
387
-						$failed = false;
388
-					elseif ($mod_action['type'] == 'failure')
393
+					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
394
+											$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
395
+					} elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) {
396
+											$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
397
+					} else {
398
+											$actual_filename = $key;
399
+					}
400
+
401
+					if ($mod_action['type'] == 'opened') {
402
+											$failed = false;
403
+					} elseif ($mod_action['type'] == 'failure')
389 404
 					{
390
-						if (empty($mod_action['is_custom']))
391
-							$context['has_failure'] = true;
405
+						if (empty($mod_action['is_custom'])) {
406
+													$context['has_failure'] = true;
407
+						}
392 408
 						$failed = true;
393
-					}
394
-					elseif ($mod_action['type'] == 'chmod')
409
+					} elseif ($mod_action['type'] == 'chmod')
395 410
 					{
396 411
 						$chmod_files[] = $mod_action['filename'];
397
-					}
398
-					elseif ($mod_action['type'] == 'saved')
412
+					} elseif ($mod_action['type'] == 'saved')
399 413
 					{
400 414
 						if (!empty($mod_action['is_custom']))
401 415
 						{
402
-							if (!isset($context['theme_actions'][$mod_action['is_custom']]))
403
-								$context['theme_actions'][$mod_action['is_custom']] = array(
416
+							if (!isset($context['theme_actions'][$mod_action['is_custom']])) {
417
+															$context['theme_actions'][$mod_action['is_custom']] = array(
404 418
 									'name' => $theme_paths[$mod_action['is_custom']]['name'],
405 419
 									'actions' => array(),
406 420
 									'has_failure' => $failed,
407 421
 								);
408
-							else
409
-								$context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
422
+							} else {
423
+															$context['theme_actions'][$mod_action['is_custom']]['has_failure'] |= $failed;
424
+							}
410 425
 
411 426
 							$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename] = array(
412 427
 								'type' => $txt['execute_modification'],
@@ -414,8 +429,7 @@  discard block
 block discarded – undo
414 429
 								'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'],
415 430
 								'failed' => $failed,
416 431
 							);
417
-						}
418
-						elseif (!isset($context['actions'][$actual_filename]))
432
+						} elseif (!isset($context['actions'][$actual_filename]))
419 433
 						{
420 434
 							$context['actions'][$actual_filename] = array(
421 435
 								'type' => $txt['execute_modification'],
@@ -423,22 +437,19 @@  discard block
 block discarded – undo
423 437
 								'description' => $failed ? $txt['package_action_failure'] : $txt['package_action_success'],
424 438
 								'failed' => $failed,
425 439
 							);
426
-						}
427
-						else
440
+						} else
428 441
 						{
429 442
 								$context['actions'][$actual_filename]['failed'] |= $failed;
430 443
 								$context['actions'][$actual_filename]['description'] = $context['actions'][$actual_filename]['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'];
431 444
 						}
432
-					}
433
-					elseif ($mod_action['type'] == 'skipping')
445
+					} elseif ($mod_action['type'] == 'skipping')
434 446
 					{
435 447
 						$context['actions'][$actual_filename] = array(
436 448
 							'type' => $txt['execute_modification'],
437 449
 							'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
438 450
 							'description' => $txt['package_action_skipping']
439 451
 						);
440
-					}
441
-					elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom']))
452
+					} elseif ($mod_action['type'] == 'missing' && empty($mod_action['is_custom']))
442 453
 					{
443 454
 						$context['has_failure'] = true;
444 455
 						$context['actions'][$actual_filename] = array(
@@ -447,32 +458,33 @@  discard block
 block discarded – undo
447 458
 							'description' => $txt['package_action_missing'],
448 459
 							'failed' => true,
449 460
 						);
450
-					}
451
-					elseif ($mod_action['type'] == 'error')
452
-						$context['actions'][$actual_filename] = array(
461
+					} elseif ($mod_action['type'] == 'error') {
462
+											$context['actions'][$actual_filename] = array(
453 463
 							'type' => $txt['execute_modification'],
454 464
 							'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
455 465
 							'description' => $txt['package_action_error'],
456 466
 							'failed' => true,
457 467
 						);
468
+					}
458 469
 				}
459 470
 
460 471
 				// We need to loop again just to get the operations down correctly.
461 472
 				foreach ($mod_actions as $operation_key => $mod_action)
462 473
 				{
463 474
 					// Lets get the last section of the file name.
464
-					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php')
465
-						$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
466
-					elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches))
467
-						$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
468
-					else
469
-						$actual_filename = $key;
475
+					if (isset($mod_action['filename']) && substr($mod_action['filename'], -13) != '.template.php') {
476
+											$actual_filename = strtolower(substr(strrchr($mod_action['filename'], '/'), 1) . '||' . $action['filename']);
477
+					} elseif (isset($mod_action['filename']) && preg_match('~([\w]*)/([\w]*)\.template\.php$~', $mod_action['filename'], $matches)) {
478
+											$actual_filename = strtolower($matches[1] . '/' . $matches[2] . '.template.php' . '||' . $action['filename']);
479
+					} else {
480
+											$actual_filename = $key;
481
+					}
470 482
 
471 483
 					// We just need it for actual parse changes.
472 484
 					if (!in_array($mod_action['type'], array('error', 'result', 'opened', 'saved', 'end', 'missing', 'skipping', 'chmod')))
473 485
 					{
474
-						if (empty($mod_action['is_custom']))
475
-							$context['actions'][$actual_filename]['operations'][] = array(
486
+						if (empty($mod_action['is_custom'])) {
487
+													$context['actions'][$actual_filename]['operations'][] = array(
476 488
 								'type' => $txt['execute_modification'],
477 489
 								'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
478 490
 								'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'],
@@ -483,10 +495,11 @@  discard block
 block discarded – undo
483 495
 								'failed' => $mod_action['failed'],
484 496
 								'ignore_failure' => !empty($mod_action['ignore_failure']),
485 497
 							);
498
+						}
486 499
 
487 500
 						// Themes are under the saved type.
488
-						if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']]))
489
-							$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array(
501
+						if (isset($mod_action['is_custom']) && isset($context['theme_actions'][$mod_action['is_custom']])) {
502
+													$context['theme_actions'][$mod_action['is_custom']]['actions'][$actual_filename]['operations'][] = array(
490 503
 								'type' => $txt['execute_modification'],
491 504
 								'action' => $smcFunc['htmlspecialchars'](strtr($mod_action['filename'], array($boarddir => '.'))),
492 505
 								'description' => $mod_action['failed'] ? $txt['package_action_failure'] : $txt['package_action_success'],
@@ -497,59 +510,55 @@  discard block
 block discarded – undo
497 510
 								'failed' => $mod_action['failed'],
498 511
 								'ignore_failure' => !empty($mod_action['ignore_failure']),
499 512
 							);
513
+						}
500 514
 					}
501 515
 				}
502 516
 			}
503
-		}
504
-		elseif ($action['type'] == 'code')
517
+		} elseif ($action['type'] == 'code')
505 518
 		{
506 519
 			$thisAction = array(
507 520
 				'type' => $txt['execute_code'],
508 521
 				'action' => $smcFunc['htmlspecialchars']($action['filename']),
509 522
 			);
510
-		}
511
-		elseif ($action['type'] == 'database')
523
+		} elseif ($action['type'] == 'database')
512 524
 		{
513 525
 			$thisAction = array(
514 526
 				'type' => $txt['execute_database_changes'],
515 527
 				'action' => $smcFunc['htmlspecialchars']($action['filename']),
516 528
 			);
517
-		}
518
-		elseif (in_array($action['type'], array('create-dir', 'create-file')))
529
+		} elseif (in_array($action['type'], array('create-dir', 'create-file')))
519 530
 		{
520 531
 			$thisAction = array(
521 532
 				'type' => $txt['package_create'] . ' ' . ($action['type'] == 'create-dir' ? $txt['package_tree'] : $txt['package_file']),
522 533
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
523 534
 			);
524
-		}
525
-		elseif ($action['type'] == 'hook')
535
+		} elseif ($action['type'] == 'hook')
526 536
 		{
527 537
 			$action['description'] = !isset($action['hook'], $action['function']) ? $txt['package_action_failure'] : $txt['package_action_success'];
528 538
 
529
-			if (!isset($action['hook'], $action['function']))
530
-				$context['has_failure'] = true;
539
+			if (!isset($action['hook'], $action['function'])) {
540
+							$context['has_failure'] = true;
541
+			}
531 542
 
532 543
 			$thisAction = array(
533 544
 				'type' => $action['reverse'] ? $txt['execute_hook_remove'] : $txt['execute_hook_add'],
534 545
 				'action' => sprintf($txt['execute_hook_action' . ($action['reverse'] ? '_inverse' : '')], $smcFunc['htmlspecialchars']($action['hook'])),
535 546
 			);
536
-		}
537
-		elseif ($action['type'] == 'credits')
547
+		} elseif ($action['type'] == 'credits')
538 548
 		{
539 549
 			$thisAction = array(
540 550
 				'type' => $txt['execute_credits_add'],
541 551
 				'action' => sprintf($txt['execute_credits_action'], $smcFunc['htmlspecialchars']($action['title'])),
542 552
 			);
543
-		}
544
-		elseif ($action['type'] == 'requires')
553
+		} elseif ($action['type'] == 'requires')
545 554
 		{
546 555
 			$installed = false;
547 556
 			$version = true;
548 557
 
549 558
 			// package missing required values?
550
-			if (!isset($action['id']))
551
-				$context['has_failure'] = true;
552
-			else
559
+			if (!isset($action['id'])) {
560
+							$context['has_failure'] = true;
561
+			} else
553 562
 			{
554 563
 				// See if this dependancy is installed
555 564
 				$request = $smcFunc['db_query']('', '
@@ -565,8 +574,9 @@  discard block
 block discarded – undo
565 574
 					)
566 575
 				);
567 576
 				$installed = ($smcFunc['db_num_rows']($request) !== 0);
568
-				if ($installed)
569
-					list ($version) = $smcFunc['db_fetch_row']($request);
577
+				if ($installed) {
578
+									list ($version) = $smcFunc['db_fetch_row']($request);
579
+				}
570 580
 				$smcFunc['db_free_result']($request);
571 581
 
572 582
 				// do a version level check (if requested) in the most basic way
@@ -581,8 +591,7 @@  discard block
 block discarded – undo
581 591
 				'type' => $txt['package_requires'],
582 592
 				'action' => $txt['package_check_for'] . ' ' . $action['id'] . (isset($action['version']) ? (' / ' . ($version ? $action['version'] : '<span class="error">' . $action['version'] . '</span>')) : ''),
583 593
 			);
584
-		}
585
-		elseif (in_array($action['type'], array('require-dir', 'require-file')))
594
+		} elseif (in_array($action['type'], array('require-dir', 'require-file')))
586 595
 		{
587 596
 			// Do this one...
588 597
 			$thisAction = array(
@@ -596,26 +605,29 @@  discard block
 block discarded – undo
596 605
 				// Is the action already stated?
597 606
 				$theme_action = !empty($action['theme_action']) && in_array($action['theme_action'], array('no', 'yes', 'auto')) ? $action['theme_action'] : 'auto';
598 607
 				// If it's not auto do we think we have something we can act upon?
599
-				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir')))
600
-					$theme_action = '';
608
+				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
609
+									$theme_action = '';
610
+				}
601 611
 				// ... or if it's auto do we even want to do anything?
602
-				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir')
603
-					$theme_action = '';
612
+				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
613
+									$theme_action = '';
614
+				}
604 615
 
605 616
 				// So, we still want to do something?
606
-				if ($theme_action != '')
607
-					$themeFinds['candidates'][] = $action;
617
+				if ($theme_action != '') {
618
+									$themeFinds['candidates'][] = $action;
619
+				}
608 620
 				// Otherwise is this is going into another theme record it.
609
-				elseif ($matches[1] == 'themes_dir')
610
-					$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
621
+				elseif ($matches[1] == 'themes_dir') {
622
+									$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_destination']), array('\\' => '/')) . '/' . basename($action['filename']));
623
+				}
611 624
 			}
612
-		}
613
-		elseif (in_array($action['type'], array('move-dir', 'move-file')))
614
-			$thisAction = array(
625
+		} elseif (in_array($action['type'], array('move-dir', 'move-file'))) {
626
+					$thisAction = array(
615 627
 				'type' => $txt['package_move'] . ' ' . ($action['type'] == 'move-dir' ? $txt['package_tree'] : $txt['package_file']),
616 628
 				'action' => $smcFunc['htmlspecialchars'](strtr($action['source'], array($boarddir => '.'))) . ' => ' . $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.')))
617 629
 			);
618
-		elseif (in_array($action['type'], array('remove-dir', 'remove-file')))
630
+		} elseif (in_array($action['type'], array('remove-dir', 'remove-file')))
619 631
 		{
620 632
 			$thisAction = array(
621 633
 				'type' => $txt['package_delete'] . ' ' . ($action['type'] == 'remove-dir' ? $txt['package_tree'] : $txt['package_file']),
@@ -631,30 +643,36 @@  discard block
 block discarded – undo
631 643
 				$action['unparsed_destination'] = $action['unparsed_filename'];
632 644
 
633 645
 				// If it's not auto do we think we have something we can act upon?
634
-				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir')))
635
-					$theme_action = '';
646
+				if ($theme_action != 'auto' && !in_array($matches[1], array('languagedir', 'languages_dir', 'imagesdir', 'themedir'))) {
647
+									$theme_action = '';
648
+				}
636 649
 				// ... or if it's auto do we even want to do anything?
637
-				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir')
638
-					$theme_action = '';
650
+				elseif ($theme_action == 'auto' && $matches[1] != 'imagesdir') {
651
+									$theme_action = '';
652
+				}
639 653
 
640 654
 				// So, we still want to do something?
641
-				if ($theme_action != '')
642
-					$themeFinds['candidates'][] = $action;
655
+				if ($theme_action != '') {
656
+									$themeFinds['candidates'][] = $action;
657
+				}
643 658
 				// Otherwise is this is going into another theme record it.
644
-				elseif ($matches[1] == 'themes_dir')
645
-					$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
659
+				elseif ($matches[1] == 'themes_dir') {
660
+									$themeFinds['other_themes'][] = strtolower(strtr(parse_path($action['unparsed_filename']), array('\\' => '/')) . '/' . basename($action['filename']));
661
+				}
646 662
 			}
647 663
 		}
648 664
 
649
-		if (empty($thisAction))
650
-			continue;
665
+		if (empty($thisAction)) {
666
+					continue;
667
+		}
651 668
 
652 669
 		if (!in_array($action['type'], array('hook', 'credits')))
653 670
 		{
654
-			if ($context['uninstalling'])
655
-				$file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
656
-			else
657
-				$file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
671
+			if ($context['uninstalling']) {
672
+							$file = in_array($action['type'], array('remove-dir', 'remove-file')) ? $action['filename'] : $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
673
+			} else {
674
+							$file = $packagesdir . '/temp/' . $context['base_path'] . $action['filename'];
675
+			}
658 676
 		}
659 677
 
660 678
 		// Don't fail if a file/directory we're trying to create doesn't exist...
@@ -669,8 +687,9 @@  discard block
 block discarded – undo
669 687
 		}
670 688
 
671 689
 		// @todo None given?
672
-		if (empty($thisAction['description']))
673
-			$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
690
+		if (empty($thisAction['description'])) {
691
+					$thisAction['description'] = isset($action['description']) ? $action['description'] : '';
692
+		}
674 693
 
675 694
 		$context['actions'][] = $thisAction;
676 695
 	}
@@ -683,18 +702,21 @@  discard block
 block discarded – undo
683 702
 			// Get the part of the file we'll be dealing with.
684 703
 			preg_match('~^\$(languagedir|languages_dir|imagesdir|themedir)(\\|/)*(.+)*~i', $action_data['unparsed_destination'], $matches);
685 704
 
686
-			if ($matches[1] == 'imagesdir')
687
-				$path = '/' . basename($settings['default_images_url']);
688
-			elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir')
689
-				$path = '/languages';
690
-			else
691
-				$path = '';
705
+			if ($matches[1] == 'imagesdir') {
706
+							$path = '/' . basename($settings['default_images_url']);
707
+			} elseif ($matches[1] == 'languagedir' || $matches[1] == 'languages_dir') {
708
+							$path = '/languages';
709
+			} else {
710
+							$path = '';
711
+			}
692 712
 
693
-			if (!empty($matches[3]))
694
-				$path .= $matches[3];
713
+			if (!empty($matches[3])) {
714
+							$path .= $matches[3];
715
+			}
695 716
 
696
-			if (!$context['uninstalling'])
697
-				$path .= '/' . basename($action_data['filename']);
717
+			if (!$context['uninstalling']) {
718
+							$path .= '/' . basename($action_data['filename']);
719
+			}
698 720
 
699 721
 			// Loop through each custom theme to note it's candidacy!
700 722
 			foreach ($theme_paths as $id => $theme_data)
@@ -710,36 +732,40 @@  discard block
 block discarded – undo
710 732
 						if (!mktree(dirname($real_path), false))
711 733
 						{
712 734
 							$temp = dirname($real_path);
713
-							while (!file_exists($temp) && strlen($temp) > 1)
714
-								$temp = dirname($temp);
735
+							while (!file_exists($temp) && strlen($temp) > 1) {
736
+															$temp = dirname($temp);
737
+							}
715 738
 							$chmod_files[] = $temp;
716 739
 						}
717 740
 
718
-						if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path))))
719
-							$chmod_files[] = $real_path;
741
+						if ($action_data['type'] == 'require-dir' && !is_writable($real_path) && (file_exists($real_path) || !is_writable(dirname($real_path)))) {
742
+													$chmod_files[] = $real_path;
743
+						}
720 744
 
721
-						if (!isset($context['theme_actions'][$id]))
722
-							$context['theme_actions'][$id] = array(
745
+						if (!isset($context['theme_actions'][$id])) {
746
+													$context['theme_actions'][$id] = array(
723 747
 								'name' => $theme_data['name'],
724 748
 								'actions' => array(),
725 749
 							);
750
+						}
726 751
 
727
-						if ($context['uninstalling'])
728
-							$context['theme_actions'][$id]['actions'][] = array(
752
+						if ($context['uninstalling']) {
753
+													$context['theme_actions'][$id]['actions'][] = array(
729 754
 								'type' => $txt['package_delete'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']),
730 755
 								'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')),
731 756
 								'description' => '',
732 757
 								'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['filename'], 'future' => $real_path, 'id' => $id))),
733 758
 								'not_mod' => true,
734 759
 							);
735
-						else
736
-							$context['theme_actions'][$id]['actions'][] = array(
760
+						} else {
761
+													$context['theme_actions'][$id]['actions'][] = array(
737 762
 								'type' => $txt['package_extract'] . ' ' . ($action_data['type'] == 'require-dir' ? $txt['package_tree'] : $txt['package_file']),
738 763
 								'action' => strtr($real_path, array('\\' => '/', $boarddir => '.')),
739 764
 								'description' => '',
740 765
 								'value' => base64_encode(json_encode(array('type' => $action_data['type'], 'orig' => $action_data['destination'], 'future' => $real_path, 'id' => $id))),
741 766
 								'not_mod' => true,
742 767
 							);
768
+						}
743 769
 					}
744 770
 				}
745 771
 			}
@@ -749,8 +775,9 @@  discard block
 block discarded – undo
749 775
 	// Trash the cache... which will also check permissions for us!
750 776
 	package_flush_cache(true);
751 777
 
752
-	if (file_exists($packagesdir . '/temp'))
753
-		deltree($packagesdir . '/temp');
778
+	if (file_exists($packagesdir . '/temp')) {
779
+			deltree($packagesdir . '/temp');
780
+	}
754 781
 
755 782
 	if (!empty($chmod_files))
756 783
 	{
@@ -775,8 +802,9 @@  discard block
 block discarded – undo
775 802
 	checkSession();
776 803
 
777 804
 	// If there's no file, what are we installing?
778
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
779
-		redirectexit('action=admin;area=packages');
805
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
806
+			redirectexit('action=admin;area=packages');
807
+	}
780 808
 	$context['filename'] = $_REQUEST['package'];
781 809
 
782 810
 	// If this is an uninstall, we'll have an id.
@@ -797,51 +825,55 @@  discard block
 block discarded – undo
797 825
 
798 826
 	$context['sub_template'] = 'extract_package';
799 827
 
800
-	if (!file_exists($packagesdir . '/' . $context['filename']))
801
-		fatal_lang_error('package_no_file', false);
828
+	if (!file_exists($packagesdir . '/' . $context['filename'])) {
829
+			fatal_lang_error('package_no_file', false);
830
+	}
802 831
 
803 832
 	// Load up the package FTP information?
804 833
 	create_chmod_control(array(), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=' . $_REQUEST['sa'] . ';package=' . $_REQUEST['package']));
805 834
 
806 835
 	// Make sure temp directory exists and is empty!
807
-	if (file_exists($packagesdir . '/temp'))
808
-		deltree($packagesdir . '/temp', false);
809
-	else
810
-		mktree($packagesdir . '/temp', 0777);
836
+	if (file_exists($packagesdir . '/temp')) {
837
+			deltree($packagesdir . '/temp', false);
838
+	} else {
839
+			mktree($packagesdir . '/temp', 0777);
840
+	}
811 841
 
812 842
 	// Let the unpacker do the work.
813 843
 	if (is_file($packagesdir . '/' . $context['filename']))
814 844
 	{
815 845
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
816 846
 
817
-		if (!file_exists($packagesdir . '/temp/package-info.xml'))
818
-			foreach ($context['extracted_files'] as $file)
847
+		if (!file_exists($packagesdir . '/temp/package-info.xml')) {
848
+					foreach ($context['extracted_files'] as $file)
819 849
 				if (basename($file['filename']) == 'package-info.xml')
820 850
 				{
821 851
 					$context['base_path'] = dirname($file['filename']) . '/';
852
+		}
822 853
 					break;
823 854
 				}
824 855
 
825
-		if (!isset($context['base_path']))
826
-			$context['base_path'] = '';
827
-	}
828
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
856
+		if (!isset($context['base_path'])) {
857
+					$context['base_path'] = '';
858
+		}
859
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
829 860
 	{
830 861
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
831 862
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
832 863
 		$context['base_path'] = '';
864
+	} else {
865
+			fatal_lang_error('no_access', false);
833 866
 	}
834
-	else
835
-		fatal_lang_error('no_access', false);
836 867
 
837 868
 	// Are we installing this into any custom themes?
838 869
 	$custom_themes = array(1);
839 870
 	$known_themes = explode(',', $modSettings['knownThemes']);
840 871
 	if (!empty($_POST['custom_theme']))
841 872
 	{
842
-		foreach ($_POST['custom_theme'] as $tid)
843
-			if (in_array($tid, $known_themes))
873
+		foreach ($_POST['custom_theme'] as $tid) {
874
+					if (in_array($tid, $known_themes))
844 875
 				$custom_themes[] = (int) $tid;
876
+		}
845 877
 	}
846 878
 
847 879
 	// Now load up the paths of the themes that we need to know about.
@@ -858,8 +890,9 @@  discard block
 block discarded – undo
858 890
 	);
859 891
 	$theme_paths = array();
860 892
 	$themes_installed = array(1);
861
-	while ($row = $smcFunc['db_fetch_assoc']($request))
862
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
893
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
894
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
895
+	}
863 896
 	$smcFunc['db_free_result']($request);
864 897
 
865 898
 	// Are there any theme copying that we want to take place?
@@ -871,11 +904,13 @@  discard block
 block discarded – undo
871 904
 	{
872 905
 		foreach ($_POST['theme_changes'] as $change)
873 906
 		{
874
-			if (empty($change))
875
-				continue;
907
+			if (empty($change)) {
908
+							continue;
909
+			}
876 910
 			$theme_data = smf_json_decode(base64_decode($change), true);
877
-			if (empty($theme_data['type']))
878
-				continue;
911
+			if (empty($theme_data['type'])) {
912
+							continue;
913
+			}
879 914
 
880 915
 			$themes_installed[] = $theme_data['id'];
881 916
 			$context['theme_copies'][$theme_data['type']][$theme_data['orig']][] = $theme_data['future'];
@@ -884,8 +919,9 @@  discard block
 block discarded – undo
884 919
 
885 920
 	// Get the package info...
886 921
 	$packageInfo = getPackageInfo($context['filename']);
887
-	if (!is_array($packageInfo))
888
-		fatal_lang_error($packageInfo);
922
+	if (!is_array($packageInfo)) {
923
+			fatal_lang_error($packageInfo);
924
+	}
889 925
 
890 926
 	$packageInfo['filename'] = $context['filename'];
891 927
 
@@ -897,8 +933,9 @@  discard block
 block discarded – undo
897 933
 	{
898 934
 		$_SESSION['last_backup_for'] = $context['filename'] . ($context['uninstalling'] ? '$$' : '$');
899 935
 		$result = package_create_backup(($context['uninstalling'] ? 'backup_' : 'before_') . strtok($context['filename'], '.'));
900
-		if (!$result)
901
-			fatal_lang_error('could_not_package_backup', false);
936
+		if (!$result) {
937
+					fatal_lang_error('could_not_package_backup', false);
938
+		}
902 939
 	}
903 940
 
904 941
 	// The mod isn't installed.... unless proven otherwise.
@@ -938,35 +975,38 @@  discard block
 block discarded – undo
938 975
 		$install_log = parsePackageInfo($packageInfo['xml'], false, 'uninstall');
939 976
 
940 977
 		// Gadzooks!  There's no uninstaller at all!?
941
-		if (empty($install_log))
942
-			fatal_lang_error('package_uninstall_cannot', false);
978
+		if (empty($install_log)) {
979
+					fatal_lang_error('package_uninstall_cannot', false);
980
+		}
943 981
 
944 982
 		// They can only uninstall from what it was originally installed into.
945
-		foreach ($theme_paths as $id => $data)
946
-			if ($id != 1 && !in_array($id, $old_themes))
983
+		foreach ($theme_paths as $id => $data) {
984
+					if ($id != 1 && !in_array($id, $old_themes))
947 985
 				unset($theme_paths[$id]);
948
-	}
949
-	elseif (isset($old_version) && $old_version != $packageInfo['version'])
986
+		}
987
+	} elseif (isset($old_version) && $old_version != $packageInfo['version'])
950 988
 	{
951 989
 		// Look for an upgrade...
952 990
 		$install_log = parsePackageInfo($packageInfo['xml'], false, 'upgrade', $old_version);
953 991
 
954 992
 		// There was no upgrade....
955
-		if (empty($install_log))
956
-			$context['is_installed'] = true;
957
-		else
993
+		if (empty($install_log)) {
994
+					$context['is_installed'] = true;
995
+		} else
958 996
 		{
959 997
 			// Upgrade previous themes only!
960
-			foreach ($theme_paths as $id => $data)
961
-				if ($id != 1 && !in_array($id, $old_themes))
998
+			foreach ($theme_paths as $id => $data) {
999
+							if ($id != 1 && !in_array($id, $old_themes))
962 1000
 					unset($theme_paths[$id]);
1001
+			}
963 1002
 		}
1003
+	} elseif (isset($old_version) && $old_version == $packageInfo['version']) {
1004
+			$context['is_installed'] = true;
964 1005
 	}
965
-	elseif (isset($old_version) && $old_version == $packageInfo['version'])
966
-		$context['is_installed'] = true;
967 1006
 
968
-	if (!isset($old_version) || $context['is_installed'])
969
-		$install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
1007
+	if (!isset($old_version) || $context['is_installed']) {
1008
+			$install_log = parsePackageInfo($packageInfo['xml'], false, 'install');
1009
+	}
970 1010
 
971 1011
 	$context['install_finished'] = false;
972 1012
 
@@ -983,37 +1023,39 @@  discard block
 block discarded – undo
983 1023
 
984 1024
 			if ($action['type'] == 'modification' && !empty($action['filename']))
985 1025
 			{
986
-				if ($action['boardmod'])
987
-					$mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
988
-				else
989
-					$mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1026
+				if ($action['boardmod']) {
1027
+									$mod_actions = parseBoardMod(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1028
+				} else {
1029
+									$mod_actions = parseModification(file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $action['filename']), false, $action['reverse'], $theme_paths);
1030
+				}
990 1031
 
991 1032
 				// Any errors worth noting?
992 1033
 				foreach ($mod_actions as $key => $action)
993 1034
 				{
994
-					if ($action['type'] == 'failure')
995
-						$failed_steps[] = array(
1035
+					if ($action['type'] == 'failure') {
1036
+											$failed_steps[] = array(
996 1037
 							'file' => $action['filename'],
997 1038
 							'large_step' => $failed_count,
998 1039
 							'sub_step' => $key,
999 1040
 							'theme' => 1,
1000 1041
 						);
1042
+					}
1001 1043
 
1002 1044
 					// Gather the themes we installed into.
1003
-					if (!empty($action['is_custom']))
1004
-						$themes_installed[] = $action['is_custom'];
1045
+					if (!empty($action['is_custom'])) {
1046
+											$themes_installed[] = $action['is_custom'];
1047
+					}
1005 1048
 				}
1006
-			}
1007
-			elseif ($action['type'] == 'code' && !empty($action['filename']))
1049
+			} elseif ($action['type'] == 'code' && !empty($action['filename']))
1008 1050
 			{
1009 1051
 				// This is just here as reference for what is available.
1010 1052
 				global $txt, $boarddir, $sourcedir, $modSettings, $context, $settings, $forum_version, $smcFunc;
1011 1053
 
1012 1054
 				// Now include the file and be done with it ;).
1013
-				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
1014
-					require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1015
-			}
1016
-			elseif ($action['type'] == 'credits')
1055
+				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
1056
+									require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1057
+				}
1058
+			} elseif ($action['type'] == 'credits')
1017 1059
 			{
1018 1060
 				// Time to build the billboard
1019 1061
 				$credits_tag = array(
@@ -1023,13 +1065,13 @@  discard block
 block discarded – undo
1023 1065
 					'copyright' => $action['copyright'],
1024 1066
 					'title' => $action['title'],
1025 1067
 				);
1026
-			}
1027
-			elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
1068
+			} elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
1028 1069
 			{
1029
-				if ($action['reverse'])
1030
-					remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1031
-				else
1032
-					add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1070
+				if ($action['reverse']) {
1071
+									remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1072
+				} else {
1073
+									add_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
1074
+				}
1033 1075
 			}
1034 1076
 			// Only do the database changes on uninstall if requested.
1035 1077
 			elseif ($action['type'] == 'database' && !empty($action['filename']) && (!$context['uninstalling'] || !empty($_POST['do_db_changes'])))
@@ -1042,8 +1084,9 @@  discard block
 block discarded – undo
1042 1084
 				db_extend('packages');
1043 1085
 
1044 1086
 				// Let the file work its magic ;)
1045
-				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename']))
1046
-					require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1087
+				if (file_exists($packagesdir . '/temp/' . $context['base_path'] . $action['filename'])) {
1088
+									require($packagesdir . '/temp/' . $context['base_path'] . $action['filename']);
1089
+				}
1047 1090
 			}
1048 1091
 			// Handle a redirect...
1049 1092
 			elseif ($action['type'] == 'redirect' && !empty($action['redirect_url']))
@@ -1125,8 +1168,9 @@  discard block
 block discarded – undo
1125 1168
 			reloadSettings();
1126 1169
 
1127 1170
 			// Any db changes from older version?
1128
-			if (!empty($old_db_changes))
1129
-				$db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
1171
+			if (!empty($old_db_changes)) {
1172
+							$db_package_log = empty($db_package_log) ? $old_db_changes : array_merge($old_db_changes, $db_package_log);
1173
+			}
1130 1174
 
1131 1175
 			// If there are some database changes we might want to remove then filter them out.
1132 1176
 			if (!empty($db_package_log))
@@ -1142,22 +1186,24 @@  discard block
 block discarded – undo
1142 1186
 				 */
1143 1187
 				function sort_table_first($a, $b)
1144 1188
 				{
1145
-					if ($a[0] == $b[0])
1146
-						return 0;
1189
+					if ($a[0] == $b[0]) {
1190
+											return 0;
1191
+					}
1147 1192
 					return $a[0] == 'remove_table' ? -1 : 1;
1148 1193
 				}
1149 1194
 				usort($db_package_log, 'sort_table_first');
1150 1195
 				foreach ($db_package_log as $k => $log)
1151 1196
 				{
1152
-					if ($log[0] == 'remove_table')
1153
-						$tables[] = $log[1];
1154
-					elseif (in_array($log[1], $tables))
1155
-						unset($db_package_log[$k]);
1197
+					if ($log[0] == 'remove_table') {
1198
+											$tables[] = $log[1];
1199
+					} elseif (in_array($log[1], $tables)) {
1200
+											unset($db_package_log[$k]);
1201
+					}
1156 1202
 				}
1157 1203
 				$db_changes = json_encode($db_package_log);
1204
+			} else {
1205
+							$db_changes = '';
1158 1206
 			}
1159
-			else
1160
-				$db_changes = '';
1161 1207
 
1162 1208
 			// What themes did we actually install?
1163 1209
 			$themes_installed = array_unique($themes_installed);
@@ -1206,18 +1252,20 @@  discard block
 block discarded – undo
1206 1252
 
1207 1253
 		foreach ($db_changes as $change)
1208 1254
 		{
1209
-			if ($change[0] == 'remove_table' && isset($change[1]))
1210
-				$smcFunc['db_drop_table']($change[1]);
1211
-			elseif ($change[0] == 'remove_column' && isset($change[2]))
1212
-				$smcFunc['db_remove_column']($change[1], $change[2]);
1213
-			elseif ($change[0] == 'remove_index' && isset($change[2]))
1214
-				$smcFunc['db_remove_index']($change[1], $change[2]);
1255
+			if ($change[0] == 'remove_table' && isset($change[1])) {
1256
+							$smcFunc['db_drop_table']($change[1]);
1257
+			} elseif ($change[0] == 'remove_column' && isset($change[2])) {
1258
+							$smcFunc['db_remove_column']($change[1], $change[2]);
1259
+			} elseif ($change[0] == 'remove_index' && isset($change[2])) {
1260
+							$smcFunc['db_remove_index']($change[1], $change[2]);
1261
+			}
1215 1262
 		}
1216 1263
 	}
1217 1264
 
1218 1265
 	// Clean house... get rid of the evidence ;).
1219
-	if (file_exists($packagesdir . '/temp'))
1220
-		deltree($packagesdir . '/temp');
1266
+	if (file_exists($packagesdir . '/temp')) {
1267
+			deltree($packagesdir . '/temp');
1268
+	}
1221 1269
 
1222 1270
 	// Log what we just did.
1223 1271
 	logAction($context['uninstalling'] ? 'uninstall_package' : (!empty($is_upgrade) ? 'upgrade_package' : 'install_package'), array('package' => $smcFunc['htmlspecialchars']($packageInfo['name']), 'version' => $smcFunc['htmlspecialchars']($packageInfo['version'])), 'admin');
@@ -1239,8 +1287,9 @@  discard block
 block discarded – undo
1239 1287
 	require_once($sourcedir . '/Subs-Package.php');
1240 1288
 
1241 1289
 	// No package?  Show him or her the door.
1242
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
1243
-		redirectexit('action=admin;area=packages');
1290
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
1291
+			redirectexit('action=admin;area=packages');
1292
+	}
1244 1293
 
1245 1294
 	$context['linktree'][] = array(
1246 1295
 		'url' => $scripturl . '?action=admin;area=packages;sa=list;package=' . $_REQUEST['package'],
@@ -1253,11 +1302,12 @@  discard block
 block discarded – undo
1253 1302
 	$context['filename'] = $_REQUEST['package'];
1254 1303
 
1255 1304
 	// Let the unpacker do the work.
1256
-	if (is_file($packagesdir . '/' . $context['filename']))
1257
-		$context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null);
1258
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
1259
-		$context['files'] = listtree($packagesdir . '/' . $context['filename']);
1260
-}
1305
+	if (is_file($packagesdir . '/' . $context['filename'])) {
1306
+			$context['files'] = read_tgz_file($packagesdir . '/' . $context['filename'], null);
1307
+	} elseif (is_dir($packagesdir . '/' . $context['filename'])) {
1308
+			$context['files'] = listtree($packagesdir . '/' . $context['filename']);
1309
+	}
1310
+	}
1261 1311
 
1262 1312
 /**
1263 1313
  * Display one of the files in a package.
@@ -1269,22 +1319,25 @@  discard block
 block discarded – undo
1269 1319
 	require_once($sourcedir . '/Subs-Package.php');
1270 1320
 
1271 1321
 	// No package?  Show him or her the door.
1272
-	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '')
1273
-		redirectexit('action=admin;area=packages');
1322
+	if (!isset($_REQUEST['package']) || $_REQUEST['package'] == '') {
1323
+			redirectexit('action=admin;area=packages');
1324
+	}
1274 1325
 
1275 1326
 	// No file?  Show him or her the door.
1276
-	if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '')
1277
-		redirectexit('action=admin;area=packages');
1327
+	if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') {
1328
+			redirectexit('action=admin;area=packages');
1329
+	}
1278 1330
 
1279 1331
 	$_REQUEST['package'] = preg_replace('~[\.]+~', '.', strtr($_REQUEST['package'], array('/' => '_', '\\' => '_')));
1280 1332
 	$_REQUEST['file'] = preg_replace('~[\.]+~', '.', $_REQUEST['file']);
1281 1333
 
1282 1334
 	if (isset($_REQUEST['raw']))
1283 1335
 	{
1284
-		if (is_file($packagesdir . '/' . $_REQUEST['package']))
1285
-			echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true);
1286
-		elseif (is_dir($packagesdir . '/' . $_REQUEST['package']))
1287
-			echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
1336
+		if (is_file($packagesdir . '/' . $_REQUEST['package'])) {
1337
+					echo read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true);
1338
+		} elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) {
1339
+					echo file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
1340
+		}
1288 1341
 
1289 1342
 		obExit(false);
1290 1343
 	}
@@ -1301,17 +1354,19 @@  discard block
 block discarded – undo
1301 1354
 	$context['filename'] = $_REQUEST['file'];
1302 1355
 
1303 1356
 	// Let the unpacker do the work.... but make sure we handle images properly.
1304
-	if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png')))
1305
-		$context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">';
1306
-	else
1357
+	if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) {
1358
+			$context['filedata'] = '<img src="' . $scripturl . '?action=admin;area=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw" alt="' . $_REQUEST['file'] . '">';
1359
+	} else
1307 1360
 	{
1308
-		if (is_file($packagesdir . '/' . $_REQUEST['package']))
1309
-			$context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true));
1310
-		elseif (is_dir($packagesdir . '/' . $_REQUEST['package']))
1311
-			$context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
1361
+		if (is_file($packagesdir . '/' . $_REQUEST['package'])) {
1362
+					$context['filedata'] = $smcFunc['htmlspecialchars'](read_tgz_file($packagesdir . '/' . $_REQUEST['package'], $_REQUEST['file'], true));
1363
+		} elseif (is_dir($packagesdir . '/' . $_REQUEST['package'])) {
1364
+					$context['filedata'] = $smcFunc['htmlspecialchars'](file_get_contents($packagesdir . '/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
1365
+		}
1312 1366
 
1313
-		if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php')
1314
-			$context['filedata'] = highlight_php_code($context['filedata']);
1367
+		if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') {
1368
+					$context['filedata'] = highlight_php_code($context['filedata']);
1369
+		}
1315 1370
 	}
1316 1371
 }
1317 1372
 
@@ -1326,8 +1381,9 @@  discard block
 block discarded – undo
1326 1381
 	checkSession('get');
1327 1382
 
1328 1383
 	// Ack, don't allow deletion of arbitrary files here, could become a security hole somehow!
1329
-	if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups')
1330
-		redirectexit('action=admin;area=packages;sa=browse');
1384
+	if (!isset($_GET['package']) || $_GET['package'] == 'index.php' || $_GET['package'] == 'backups') {
1385
+			redirectexit('action=admin;area=packages;sa=browse');
1386
+	}
1331 1387
 	$_GET['package'] = preg_replace('~[\.]+~', '.', strtr($_GET['package'], array('/' => '_', '\\' => '_')));
1332 1388
 
1333 1389
 	// Can't delete what's not there.
@@ -1335,9 +1391,9 @@  discard block
 block discarded – undo
1335 1391
 	{
1336 1392
 		create_chmod_control(array($packagesdir . '/' . $_GET['package']), array('destination_url' => $scripturl . '?action=admin;area=packages;sa=remove;package=' . $_GET['package'], 'crash_on_error' => true));
1337 1393
 
1338
-		if (is_dir($packagesdir . '/' . $_GET['package']))
1339
-			deltree($packagesdir . '/' . $_GET['package']);
1340
-		else
1394
+		if (is_dir($packagesdir . '/' . $_GET['package'])) {
1395
+					deltree($packagesdir . '/' . $_GET['package']);
1396
+		} else
1341 1397
 		{
1342 1398
 			smf_chmod($packagesdir . '/' . $_GET['package'], 0777);
1343 1399
 			unlink($packagesdir . '/' . $_GET['package']);
@@ -1385,8 +1441,9 @@  discard block
 block discarded – undo
1385 1441
 					'data' => array(
1386 1442
 						'function' => function($package_md5) use ($type, &$context)
1387 1443
 						{
1388
-							if (isset($context['available_' . $type . ''][$package_md5]))
1389
-								return $context['available_' . $type . ''][$package_md5]['sort_id'];
1444
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1445
+															return $context['available_' . $type . ''][$package_md5]['sort_id'];
1446
+							}
1390 1447
 						},
1391 1448
 					),
1392 1449
 					'sort' => array(
@@ -1402,8 +1459,9 @@  discard block
 block discarded – undo
1402 1459
 					'data' => array(
1403 1460
 						'function' => function($package_md5) use ($type, &$context)
1404 1461
 						{
1405
-							if (isset($context['available_' . $type . ''][$package_md5]))
1406
-								return $context['available_' . $type . ''][$package_md5]['name'];
1462
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1463
+															return $context['available_' . $type . ''][$package_md5]['name'];
1464
+							}
1407 1465
 						},
1408 1466
 					),
1409 1467
 					'sort' => array(
@@ -1418,8 +1476,9 @@  discard block
 block discarded – undo
1418 1476
 					'data' => array(
1419 1477
 						'function' => function($package_md5) use ($type, &$context)
1420 1478
 						{
1421
-							if (isset($context['available_' . $type . ''][$package_md5]))
1422
-								return $context['available_' . $type . ''][$package_md5]['version'];
1479
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1480
+															return $context['available_' . $type . ''][$package_md5]['version'];
1481
+							}
1423 1482
 						},
1424 1483
 					),
1425 1484
 					'sort' => array(
@@ -1434,8 +1493,9 @@  discard block
 block discarded – undo
1434 1493
 					'data' => array(
1435 1494
 						'function' => function($package_md5) use ($type, $txt, &$context)
1436 1495
 						{
1437
-							if (isset($context['available_' . $type . ''][$package_md5]))
1438
-								return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable'];
1496
+							if (isset($context['available_' . $type . ''][$package_md5])) {
1497
+															return !empty($context['available_' . $type . ''][$package_md5]['time_installed']) ? timeformat($context['available_' . $type . ''][$package_md5]['time_installed']) : $txt['not_applicable'];
1498
+							}
1439 1499
 						},
1440 1500
 						'class' => 'smalltext',
1441 1501
 					),
@@ -1451,28 +1511,30 @@  discard block
 block discarded – undo
1451 1511
 					'data' => array(
1452 1512
 						'function' => function($package_md5) use ($type, &$context, $scripturl, $txt)
1453 1513
 						{
1454
-							if (!isset($context['available_' . $type . ''][$package_md5]))
1455
-								return '';
1514
+							if (!isset($context['available_' . $type . ''][$package_md5])) {
1515
+															return '';
1516
+							}
1456 1517
 
1457 1518
 							// Rewrite shortcut
1458 1519
 							$package = $context['available_' . $type . ''][$package_md5];
1459 1520
 							$return = '';
1460 1521
 
1461
-							if ($package['can_uninstall'])
1462
-								$return = '
1522
+							if ($package['can_uninstall']) {
1523
+															$return = '
1463 1524
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['uninstall'] . '</a>';
1464
-							elseif ($package['can_emulate_uninstall'])
1465
-								$return = '
1525
+							} elseif ($package['can_emulate_uninstall']) {
1526
+															$return = '
1466 1527
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=uninstall;ve=' . $package['can_emulate_uninstall'] . ';package=' . $package['filename'] . ';pid=' . $package['installed_id'] . '" class="button">' . $txt['package_emulate_uninstall'] . ' ' . $package['can_emulate_uninstall'] . '</a>';
1467
-							elseif ($package['can_upgrade'])
1468
-								$return = '
1528
+							} elseif ($package['can_upgrade']) {
1529
+															$return = '
1469 1530
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['package_upgrade'] . '</a>';
1470
-							elseif ($package['can_install'])
1471
-								$return = '
1531
+							} elseif ($package['can_install']) {
1532
+															$return = '
1472 1533
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;package=' . $package['filename'] . '" class="button">' . $txt['install_mod'] . '</a>';
1473
-							elseif ($package['can_emulate_install'])
1474
-								$return = '
1534
+							} elseif ($package['can_emulate_install']) {
1535
+															$return = '
1475 1536
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=install;ve=' . $package['can_emulate_install'] . ';package=' . $package['filename'] . '" class="button">' . $txt['package_emulate_install'] . ' ' . $package['can_emulate_install'] . '</a>';
1537
+							}
1476 1538
 
1477 1539
 							return $return . '
1478 1540
 									<a href="' . $scripturl . '?action=admin;area=packages;sa=list;package=' . $package['filename'] . '" class="button">' . $txt['list_files'] . '</a>
@@ -1537,12 +1599,14 @@  discard block
 block discarded – undo
1537 1599
 	static $packages, $installed_mods;
1538 1600
 
1539 1601
 	// Start things up
1540
-	if (!isset($packages[$params]))
1541
-		$packages[$params] = array();
1602
+	if (!isset($packages[$params])) {
1603
+			$packages[$params] = array();
1604
+	}
1542 1605
 
1543 1606
 	// We need the packages directory to be writable for this.
1544
-	if (!@is_writable($packagesdir))
1545
-		create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true));
1607
+	if (!@is_writable($packagesdir)) {
1608
+			create_chmod_control(array($packagesdir), array('destination_url' => $scripturl . '?action=admin;area=packages', 'crash_on_error' => true));
1609
+	}
1546 1610
 
1547 1611
 	$the_version = strtr($forum_version, array('SMF ' => ''));
1548 1612
 
@@ -1550,41 +1614,44 @@  discard block
 block discarded – undo
1550 1614
 	if (isset($_GET['version_emulate']) && strtr($_GET['version_emulate'], array('SMF ' => '')) == $the_version)
1551 1615
 	{
1552 1616
 		unset($_SESSION['version_emulate']);
1553
-	}
1554
-	elseif (isset($_GET['version_emulate']))
1617
+	} elseif (isset($_GET['version_emulate']))
1555 1618
 	{
1556
-		if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate']))
1557
-			unset($_SESSION['version_emulate']);
1558
-		elseif ($_GET['version_emulate'] !== 0)
1559
-			$_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => ''));
1619
+		if (($_GET['version_emulate'] === 0 || $_GET['version_emulate'] === $forum_version) && isset($_SESSION['version_emulate'])) {
1620
+					unset($_SESSION['version_emulate']);
1621
+		} elseif ($_GET['version_emulate'] !== 0) {
1622
+					$_SESSION['version_emulate'] = strtr($_GET['version_emulate'], array('-' => ' ', '+' => ' ', 'SMF ' => ''));
1623
+		}
1560 1624
 	}
1561 1625
 	if (!empty($_SESSION['version_emulate']))
1562 1626
 	{
1563 1627
 		$context['forum_version'] = 'SMF ' . $_SESSION['version_emulate'];
1564 1628
 		$the_version = $_SESSION['version_emulate'];
1565 1629
 	}
1566
-	if (isset($_SESSION['single_version_emulate']))
1567
-		unset($_SESSION['single_version_emulate']);
1630
+	if (isset($_SESSION['single_version_emulate'])) {
1631
+			unset($_SESSION['single_version_emulate']);
1632
+	}
1568 1633
 
1569 1634
 	if (empty($installed_mods))
1570 1635
 	{
1571 1636
 		$instmods = loadInstalledPackages();
1572 1637
 		$installed_mods = array();
1573 1638
 		// Look through the list of installed mods...
1574
-		foreach ($instmods as $installed_mod)
1575
-			$installed_mods[$installed_mod['package_id']] = array(
1639
+		foreach ($instmods as $installed_mod) {
1640
+					$installed_mods[$installed_mod['package_id']] = array(
1576 1641
 				'id' => $installed_mod['id'],
1577 1642
 				'version' => $installed_mod['version'],
1578 1643
 				'time_installed' => $installed_mod['time_installed'],
1579 1644
 			);
1645
+		}
1580 1646
 
1581 1647
 		// Get a list of all the ids installed, so the latest packages won't include already installed ones.
1582 1648
 		$context['installed_mods'] = array_keys($installed_mods);
1583 1649
 	}
1584 1650
 
1585
-	if (empty($packages))
1586
-		foreach ($context['modification_types'] as $type)
1651
+	if (empty($packages)) {
1652
+			foreach ($context['modification_types'] as $type)
1587 1653
 			$packages[$type] = array();
1654
+	}
1588 1655
 
1589 1656
 	if ($dir = @opendir($packagesdir))
1590 1657
 	{
@@ -1600,50 +1667,56 @@  discard block
 block discarded – undo
1600 1667
 
1601 1668
 		while ($package = readdir($dir))
1602 1669
 		{
1603
-			if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip'))
1604
-				continue;
1670
+			if ($package == '.' || $package == '..' || $package == 'temp' || (!(is_dir($packagesdir . '/' . $package) && file_exists($packagesdir . '/' . $package . '/package-info.xml')) && substr(strtolower($package), -7) != '.tar.gz' && substr(strtolower($package), -4) != '.tgz' && substr(strtolower($package), -4) != '.zip')) {
1671
+							continue;
1672
+			}
1605 1673
 
1606 1674
 			$skip = false;
1607
-			foreach ($context['modification_types'] as $type)
1608
-				if (isset($context['available_' . $type][md5($package)]))
1675
+			foreach ($context['modification_types'] as $type) {
1676
+							if (isset($context['available_' . $type][md5($package)]))
1609 1677
 					$skip = true;
1678
+			}
1610 1679
 
1611
-			if ($skip)
1612
-				continue;
1680
+			if ($skip) {
1681
+							continue;
1682
+			}
1613 1683
 
1614 1684
 			// Skip directories or files that are named the same.
1615 1685
 			if (is_dir($packagesdir . '/' . $package))
1616 1686
 			{
1617
-				if (in_array($package, $dirs))
1618
-					continue;
1687
+				if (in_array($package, $dirs)) {
1688
+									continue;
1689
+				}
1619 1690
 				$dirs[] = $package;
1620
-			}
1621
-			elseif (substr(strtolower($package), -7) == '.tar.gz')
1691
+			} elseif (substr(strtolower($package), -7) == '.tar.gz')
1622 1692
 			{
1623
-				if (in_array(substr($package, 0, -7), $dirs))
1624
-					continue;
1693
+				if (in_array(substr($package, 0, -7), $dirs)) {
1694
+									continue;
1695
+				}
1625 1696
 				$dirs[] = substr($package, 0, -7);
1626
-			}
1627
-			elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz')
1697
+			} elseif (substr(strtolower($package), -4) == '.zip' || substr(strtolower($package), -4) == '.tgz')
1628 1698
 			{
1629
-				if (in_array(substr($package, 0, -4), $dirs))
1630
-					continue;
1699
+				if (in_array(substr($package, 0, -4), $dirs)) {
1700
+									continue;
1701
+				}
1631 1702
 				$dirs[] = substr($package, 0, -4);
1632 1703
 			}
1633 1704
 
1634 1705
 			$packageInfo = getPackageInfo($package);
1635
-			if (!is_array($packageInfo))
1636
-				continue;
1706
+			if (!is_array($packageInfo)) {
1707
+							continue;
1708
+			}
1637 1709
 
1638 1710
 			if (!empty($packageInfo))
1639 1711
 			{
1640 1712
 				$packageInfo['installed_id'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['id'] : 0;
1641 1713
 				$packageInfo['time_installed'] = isset($installed_mods[$packageInfo['id']]) ? $installed_mods[$packageInfo['id']]['time_installed'] : 0;
1642 1714
 
1643
-				if (!isset($sort_id[$packageInfo['type']]))
1644
-					$packageInfo['sort_id'] = $sort_id['unknown'];
1645
-				else
1646
-					$packageInfo['sort_id'] = $sort_id[$packageInfo['type']];
1715
+				if (!isset($sort_id[$packageInfo['type']])) {
1716
+									$packageInfo['sort_id'] = $sort_id['unknown'];
1717
+				} else {
1718
+									$packageInfo['sort_id'] = $sort_id[$packageInfo['type']];
1719
+				}
1647 1720
 
1648 1721
 				$packageInfo['is_installed'] = isset($installed_mods[$packageInfo['id']]);
1649 1722
 				$packageInfo['is_current'] = $packageInfo['is_installed'] && ($installed_mods[$packageInfo['id']]['version'] == $packageInfo['version']);
@@ -1692,10 +1765,11 @@  discard block
 block discarded – undo
1692 1765
 					foreach ($upgrades as $upgrade)
1693 1766
 					{
1694 1767
 						// Even if it is for this SMF, is it for the installed version of the mod?
1695
-						if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for')))
1696
-							if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from')))
1768
+						if (!$upgrade->exists('@for') || matchPackageVersion($the_version, $upgrade->fetch('@for'))) {
1769
+													if (!$upgrade->exists('@from') || matchPackageVersion($installed_mods[$packageInfo['id']]['version'], $upgrade->fetch('@from')))
1697 1770
 							{
1698 1771
 								$packageInfo['can_upgrade'] = true;
1772
+						}
1699 1773
 								break;
1700 1774
 							}
1701 1775
 					}
@@ -1772,10 +1846,11 @@  discard block
 block discarded – undo
1772 1846
 
1773 1847
 	if (isset($_GET['type']) && $_GET['type'] == $params)
1774 1848
 	{
1775
-		if (isset($_GET['desc']))
1776
-			krsort($packages[$params]);
1777
-		else
1778
-			ksort($packages[$params]);
1849
+		if (isset($_GET['desc'])) {
1850
+					krsort($packages[$params]);
1851
+		} else {
1852
+					ksort($packages[$params]);
1853
+		}
1779 1854
 	}
1780 1855
 
1781 1856
 	return $packages[$params];
@@ -1804,10 +1879,11 @@  discard block
 block discarded – undo
1804 1879
 		redirectexit('action=admin;area=packages;sa=options');
1805 1880
 	}
1806 1881
 
1807
-	if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
1808
-		$default_username = $match[1];
1809
-	else
1810
-		$default_username = '';
1882
+	if (preg_match('~^/home\d*/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match)) {
1883
+			$default_username = $match[1];
1884
+	} else {
1885
+			$default_username = '';
1886
+	}
1811 1887
 
1812 1888
 	$context['page_title'] = $txt['package_settings'];
1813 1889
 	$context['sub_template'] = 'install_options';
@@ -1836,8 +1912,9 @@  discard block
 block discarded – undo
1836 1912
 	isAllowedTo('admin_forum');
1837 1913
 
1838 1914
 	// We need to know the operation key for the search and replace, mod file looking at, is it a board mod?
1839
-	if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key']))
1840
-		fatal_lang_error('operation_invalid', 'general');
1915
+	if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) {
1916
+			fatal_lang_error('operation_invalid', 'general');
1917
+	}
1841 1918
 
1842 1919
 	// Load the required file.
1843 1920
 	require_once($sourcedir . '/Subs-Package.php');
@@ -1853,18 +1930,19 @@  discard block
 block discarded – undo
1853 1930
 	{
1854 1931
 		$context['extracted_files'] = read_tgz_file($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
1855 1932
 
1856
-		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml'))
1857
-			foreach ($context['extracted_files'] as $file)
1933
+		if ($context['extracted_files'] && !file_exists($packagesdir . '/temp/package-info.xml')) {
1934
+					foreach ($context['extracted_files'] as $file)
1858 1935
 				if (basename($file['filename']) == 'package-info.xml')
1859 1936
 				{
1860 1937
 					$context['base_path'] = dirname($file['filename']) . '/';
1938
+		}
1861 1939
 					break;
1862 1940
 				}
1863 1941
 
1864
-		if (!isset($context['base_path']))
1865
-			$context['base_path'] = '';
1866
-	}
1867
-	elseif (is_dir($packagesdir . '/' . $context['filename']))
1942
+		if (!isset($context['base_path'])) {
1943
+					$context['base_path'] = '';
1944
+		}
1945
+	} elseif (is_dir($packagesdir . '/' . $context['filename']))
1868 1946
 	{
1869 1947
 		copytree($packagesdir . '/' . $context['filename'], $packagesdir . '/temp');
1870 1948
 		$context['extracted_files'] = listtree($packagesdir . '/temp');
@@ -1885,8 +1963,9 @@  discard block
 block discarded – undo
1885 1963
 		)
1886 1964
 	);
1887 1965
 	$theme_paths = array();
1888
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1889
-		$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1966
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1967
+			$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
1968
+	}
1890 1969
 	$smcFunc['db_free_result']($request);
1891 1970
 
1892 1971
 	// If we're viewing uninstall operations, only consider themes that
@@ -1911,19 +1990,21 @@  discard block
 block discarded – undo
1911 1990
 				list ($old_themes) = $smcFunc['db_fetch_row']($request);
1912 1991
 				$old_themes = explode(',', $old_themes);
1913 1992
 
1914
-				foreach ($theme_paths as $id => $data)
1915
-					if ($id != 1 && !in_array($id, $old_themes))
1993
+				foreach ($theme_paths as $id => $data) {
1994
+									if ($id != 1 && !in_array($id, $old_themes))
1916 1995
 						unset($theme_paths[$id]);
1996
+				}
1917 1997
 			}
1918 1998
 			$smcFunc['db_free_result']($request);
1919 1999
 		}
1920 2000
 	}
1921 2001
 
1922 2002
 	// Boardmod?
1923
-	if (isset($_REQUEST['boardmod']))
1924
-		$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
1925
-	else
1926
-		$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2003
+	if (isset($_REQUEST['boardmod'])) {
2004
+			$mod_actions = parseBoardMod(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2005
+	} else {
2006
+			$mod_actions = parseModification(@file_get_contents($packagesdir . '/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
2007
+	}
1927 2008
 
1928 2009
 	// Ok lets get the content of the file.
1929 2010
 	$context['operations'] = array(
@@ -1979,9 +2060,9 @@  discard block
 block discarded – undo
1979 2060
 			'path' => $detect_path,
1980 2061
 			'form_elements_only' => true,
1981 2062
 		);
2063
+	} else {
2064
+			$context['ftp_connected'] = true;
1982 2065
 	}
1983
-	else
1984
-		$context['ftp_connected'] = true;
1985 2066
 
1986 2067
 	// Define the template.
1987 2068
 	$context['page_title'] = $txt['package_file_perms'];
@@ -2094,18 +2175,19 @@  discard block
 block discarded – undo
2094 2175
 	{
2095 2176
 		unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']);
2096 2177
 
2097
-		if (!is_array($modSettings['attachmentUploadDir']))
2098
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2178
+		if (!is_array($modSettings['attachmentUploadDir'])) {
2179
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
2180
+		}
2099 2181
 
2100 2182
 		// @todo Should we suggest non-current directories be read only?
2101
-		foreach ($modSettings['attachmentUploadDir'] as $dir)
2102
-			$context['file_tree'][strtr($dir, array('\\' => '/'))] = array(
2183
+		foreach ($modSettings['attachmentUploadDir'] as $dir) {
2184
+					$context['file_tree'][strtr($dir, array('\\' => '/'))] = array(
2103 2185
 			'type' => 'dir',
2104 2186
 			'writable_on' => 'restrictive',
2105 2187
 		);
2188
+		}
2106 2189
 
2107
-	}
2108
-	elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir)
2190
+	} elseif (substr($modSettings['attachmentUploadDir'], 0, strlen($boarddir)) != $boarddir)
2109 2191
 	{
2110 2192
 		unset($context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['attachments']);
2111 2193
 		$context['file_tree'][strtr($modSettings['attachmentUploadDir'], array('\\' => '/'))] = array(
@@ -2155,8 +2237,8 @@  discard block
 block discarded – undo
2155 2237
 	);
2156 2238
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2157 2239
 	{
2158
-		if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes'))
2159
-			$context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array(
2240
+		if (substr(strtolower(strtr($row['value'], array('\\' => '/'))), 0, strlen($boarddir) + 7) == strtolower(strtr($boarddir, array('\\' => '/')) . '/Themes')) {
2241
+					$context['file_tree'][strtr($boarddir, array('\\' => '/'))]['contents']['Themes']['contents'][substr($row['value'], strlen($boarddir) + 8)] = array(
2160 2242
 				'type' => 'dir_recursive',
2161 2243
 				'list_contents' => true,
2162 2244
 				'contents' => array(
@@ -2166,7 +2248,7 @@  discard block
 block discarded – undo
2166 2248
 					),
2167 2249
 				),
2168 2250
 			);
2169
-		else
2251
+		} else
2170 2252
 		{
2171 2253
 			$context['file_tree'][strtr($row['value'], array('\\' => '/'))] = array(
2172 2254
 				'type' => 'dir_recursive',
@@ -2183,28 +2265,33 @@  discard block
 block discarded – undo
2183 2265
 	$smcFunc['db_free_result']($request);
2184 2266
 
2185 2267
 	// If we're submitting then let's move on to another function to keep things cleaner..
2186
-	if (isset($_POST['action_changes']))
2187
-		return PackagePermissionsAction();
2268
+	if (isset($_POST['action_changes'])) {
2269
+			return PackagePermissionsAction();
2270
+	}
2188 2271
 
2189 2272
 	$context['look_for'] = array();
2190 2273
 	// Are we looking for a particular tree - normally an expansion?
2191
-	if (!empty($_REQUEST['find']))
2192
-		$context['look_for'][] = base64_decode($_REQUEST['find']);
2274
+	if (!empty($_REQUEST['find'])) {
2275
+			$context['look_for'][] = base64_decode($_REQUEST['find']);
2276
+	}
2193 2277
 	// Only that tree?
2194 2278
 	$context['only_find'] = isset($_GET['xml']) && !empty($_REQUEST['onlyfind']) ? $_REQUEST['onlyfind'] : '';
2195
-	if ($context['only_find'])
2196
-		$context['look_for'][] = $context['only_find'];
2279
+	if ($context['only_find']) {
2280
+			$context['look_for'][] = $context['only_find'];
2281
+	}
2197 2282
 
2198 2283
 	// Have we got a load of back-catalogue trees to expand from a submit etc?
2199 2284
 	if (!empty($_GET['back_look']))
2200 2285
 	{
2201 2286
 		$potententialTrees = smf_json_decode(base64_decode($_GET['back_look']), true);
2202
-		foreach ($potententialTrees as $tree)
2203
-			$context['look_for'][] = $tree;
2287
+		foreach ($potententialTrees as $tree) {
2288
+					$context['look_for'][] = $tree;
2289
+		}
2204 2290
 	}
2205 2291
 	// ... maybe posted?
2206
-	if (!empty($_POST['back_look']))
2207
-		$context['only_find'] = array_merge($context['only_find'], $_POST['back_look']);
2292
+	if (!empty($_POST['back_look'])) {
2293
+			$context['only_find'] = array_merge($context['only_find'], $_POST['back_look']);
2294
+	}
2208 2295
 
2209 2296
 	$context['back_look_data'] = base64_encode(json_encode(array_slice($context['look_for'], 0, 15)));
2210 2297
 
@@ -2243,9 +2330,9 @@  discard block
 block discarded – undo
2243 2330
 				'chmod' => @is_writable($path),
2244 2331
 				'perms' => @fileperms($path),
2245 2332
 			);
2333
+		} else {
2334
+					unset($context['file_tree'][$path]);
2246 2335
 		}
2247
-		else
2248
-			unset($context['file_tree'][$path]);
2249 2336
 	}
2250 2337
 
2251 2338
 	// Is this actually xml?
@@ -2269,22 +2356,25 @@  discard block
 block discarded – undo
2269 2356
 	global $context;
2270 2357
 
2271 2358
 	$isLikelyPath = false;
2272
-	foreach ($context['look_for'] as $possiblePath)
2273
-		if (substr($possiblePath, 0, strlen($path)) == $path)
2359
+	foreach ($context['look_for'] as $possiblePath) {
2360
+			if (substr($possiblePath, 0, strlen($path)) == $path)
2274 2361
 			$isLikelyPath = true;
2362
+	}
2275 2363
 
2276 2364
 	// Is this where we stop?
2277
-	if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath)
2278
-		return;
2279
-	elseif ($level > $context['default_level'] && !$isLikelyPath)
2280
-		return;
2365
+	if (isset($_GET['xml']) && !empty($context['look_for']) && !$isLikelyPath) {
2366
+			return;
2367
+	} elseif ($level > $context['default_level'] && !$isLikelyPath) {
2368
+			return;
2369
+	}
2281 2370
 
2282 2371
 	// Are we actually interested in saving this data?
2283 2372
 	$save_data = empty($context['only_find']) || $context['only_find'] == $path;
2284 2373
 
2285 2374
 	// @todo Shouldn't happen - but better error message?
2286
-	if (!is_dir($path))
2287
-		fatal_lang_error('no_access', false);
2375
+	if (!is_dir($path)) {
2376
+			fatal_lang_error('no_access', false);
2377
+	}
2288 2378
 
2289 2379
 	// This is where we put stuff we've found for sorting.
2290 2380
 	$foundData = array(
@@ -2299,11 +2389,13 @@  discard block
 block discarded – undo
2299 2389
 		if (is_file($path . '/' . $entry))
2300 2390
 		{
2301 2391
 			// Are we listing PHP files in this directory?
2302
-			if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php')
2303
-				$foundData['files'][$entry] = true;
2392
+			if ($save_data && !empty($data['list_contents']) && substr($entry, -4) == '.php') {
2393
+							$foundData['files'][$entry] = true;
2394
+			}
2304 2395
 			// A file we were looking for.
2305
-			elseif ($save_data && isset($data['contents'][$entry]))
2306
-				$foundData['files'][$entry] = true;
2396
+			elseif ($save_data && isset($data['contents'][$entry])) {
2397
+							$foundData['files'][$entry] = true;
2398
+			}
2307 2399
 		}
2308 2400
 		// It's a directory - we're interested one way or another, probably...
2309 2401
 		elseif ($entry != '.' && $entry != '..')
@@ -2311,32 +2403,36 @@  discard block
 block discarded – undo
2311 2403
 			// Going further?
2312 2404
 			if ((!empty($data['type']) && $data['type'] == 'dir_recursive') || (isset($data['contents'][$entry]) && (!empty($data['contents'][$entry]['list_contents']) || (!empty($data['contents'][$entry]['type']) && $data['contents'][$entry]['type'] == 'dir_recursive'))))
2313 2405
 			{
2314
-				if (!isset($data['contents'][$entry]))
2315
-					$foundData['folders'][$entry] = 'dir_recursive';
2316
-				else
2317
-					$foundData['folders'][$entry] = true;
2406
+				if (!isset($data['contents'][$entry])) {
2407
+									$foundData['folders'][$entry] = 'dir_recursive';
2408
+				} else {
2409
+									$foundData['folders'][$entry] = true;
2410
+				}
2318 2411
 
2319 2412
 				// If this wasn't expected inherit the recusiveness...
2320
-				if (!isset($data['contents'][$entry]))
2321
-					// We need to do this as we will be going all recursive.
2413
+				if (!isset($data['contents'][$entry])) {
2414
+									// We need to do this as we will be going all recursive.
2322 2415
 					$data['contents'][$entry] = array(
2323 2416
 						'type' => 'dir_recursive',
2324 2417
 					);
2418
+				}
2325 2419
 
2326 2420
 				// Actually do the recursive stuff...
2327 2421
 				fetchPerms__recursive($path . '/' . $entry, $data['contents'][$entry], $level + 1);
2328 2422
 			}
2329 2423
 			// Maybe it is a folder we are not descending into.
2330
-			elseif (isset($data['contents'][$entry]))
2331
-				$foundData['folders'][$entry] = true;
2424
+			elseif (isset($data['contents'][$entry])) {
2425
+							$foundData['folders'][$entry] = true;
2426
+			}
2332 2427
 			// Otherwise we stop here.
2333 2428
 		}
2334 2429
 	}
2335 2430
 	closedir($dh);
2336 2431
 
2337 2432
 	// Nothing to see here?
2338
-	if (!$save_data)
2339
-		return;
2433
+	if (!$save_data) {
2434
+			return;
2435
+	}
2340 2436
 
2341 2437
 	// Now actually add the data, starting with the folders.
2342 2438
 	ksort($foundData['folders']);
@@ -2348,8 +2444,9 @@  discard block
 block discarded – undo
2348 2444
 				'perms' => @fileperms($path . '/' . $folder),
2349 2445
 			),
2350 2446
 		);
2351
-		if ($type !== true)
2352
-			$additional_data['type'] = $type;
2447
+		if ($type !== true) {
2448
+					$additional_data['type'] = $type;
2449
+		}
2353 2450
 
2354 2451
 		// If there's an offset ignore any folders in XML mode.
2355 2452
 		if (isset($_GET['xml']) && $context['file_offset'] == 0)
@@ -2368,13 +2465,13 @@  discard block
 block discarded – undo
2368 2465
 				),
2369 2466
 				'value' => $folder,
2370 2467
 			);
2371
-		}
2372
-		elseif (!isset($_GET['xml']))
2468
+		} elseif (!isset($_GET['xml']))
2373 2469
 		{
2374
-			if (isset($data['contents'][$folder]))
2375
-				$data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data);
2376
-			else
2377
-				$data['contents'][$folder] = $additional_data;
2470
+			if (isset($data['contents'][$folder])) {
2471
+							$data['contents'][$folder] = array_merge($data['contents'][$folder], $additional_data);
2472
+			} else {
2473
+							$data['contents'][$folder] = $additional_data;
2474
+			}
2378 2475
 		}
2379 2476
 	}
2380 2477
 
@@ -2386,11 +2483,13 @@  discard block
 block discarded – undo
2386 2483
 		$counter++;
2387 2484
 
2388 2485
 		// Have we reached our offset?
2389
-		if ($context['file_offset'] > $counter)
2390
-			continue;
2486
+		if ($context['file_offset'] > $counter) {
2487
+					continue;
2488
+		}
2391 2489
 		// Gone too far?
2392
-		if ($counter > ($context['file_offset'] + $context['file_limit']))
2393
-			continue;
2490
+		if ($counter > ($context['file_offset'] + $context['file_limit'])) {
2491
+					continue;
2492
+		}
2394 2493
 
2395 2494
 		$additional_data = array(
2396 2495
 			'perms' => array(
@@ -2416,13 +2515,13 @@  discard block
 block discarded – undo
2416 2515
 				),
2417 2516
 				'value' => $file,
2418 2517
 			);
2419
-		}
2420
-		elseif ($counter != ($context['file_offset'] + $context['file_limit']))
2518
+		} elseif ($counter != ($context['file_offset'] + $context['file_limit']))
2421 2519
 		{
2422
-			if (isset($data['contents'][$file]))
2423
-				$data['contents'][$file] = array_merge($data['contents'][$file], $additional_data);
2424
-			else
2425
-				$data['contents'][$file] = $additional_data;
2520
+			if (isset($data['contents'][$file])) {
2521
+							$data['contents'][$file] = array_merge($data['contents'][$file], $additional_data);
2522
+			} else {
2523
+							$data['contents'][$file] = $additional_data;
2524
+			}
2426 2525
 		}
2427 2526
 	}
2428 2527
 }
@@ -2444,8 +2543,9 @@  discard block
 block discarded – undo
2444 2543
 	$context['back_look_data'] = isset($_POST['back_look']) ? $_POST['back_look'] : array();
2445 2544
 
2446 2545
 	// Skipping use of FTP?
2447
-	if (empty($package_ftp))
2448
-		$context['skip_ftp'] = true;
2546
+	if (empty($package_ftp)) {
2547
+			$context['skip_ftp'] = true;
2548
+	}
2449 2549
 
2450 2550
 	// We'll start off in a good place, security. Make sure that if we're dealing with individual files that they seem in the right place.
2451 2551
 	if ($context['method'] == 'individual')
@@ -2455,8 +2555,9 @@  discard block
 block discarded – undo
2455 2555
 		$context['custom_value'] = (int) $_POST['custom_value'];
2456 2556
 
2457 2557
 		// Continuing?
2458
-		if (isset($_POST['toProcess']))
2459
-			$_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true);
2558
+		if (isset($_POST['toProcess'])) {
2559
+					$_POST['permStatus'] = smf_json_decode(base64_decode($_POST['toProcess']), true);
2560
+		}
2460 2561
 
2461 2562
 		if (isset($_POST['permStatus']))
2462 2563
 		{
@@ -2465,22 +2566,27 @@  discard block
 block discarded – undo
2465 2566
 			foreach ($_POST['permStatus'] as $path => $status)
2466 2567
 			{
2467 2568
 				// Nothing to see here?
2468
-				if ($status == 'no_change')
2469
-					continue;
2569
+				if ($status == 'no_change') {
2570
+									continue;
2571
+				}
2470 2572
 				$legal = false;
2471
-				foreach ($legal_roots as $root)
2472
-					if (substr($path, 0, strlen($root)) == $root)
2573
+				foreach ($legal_roots as $root) {
2574
+									if (substr($path, 0, strlen($root)) == $root)
2473 2575
 						$legal = true;
2576
+				}
2474 2577
 
2475
-				if (!$legal)
2476
-					continue;
2578
+				if (!$legal) {
2579
+									continue;
2580
+				}
2477 2581
 
2478 2582
 				// Check it exists.
2479
-				if (!file_exists($path))
2480
-					continue;
2583
+				if (!file_exists($path)) {
2584
+									continue;
2585
+				}
2481 2586
 
2482
-				if ($status == 'custom')
2483
-					$validate_custom = true;
2587
+				if ($status == 'custom') {
2588
+									$validate_custom = true;
2589
+				}
2484 2590
 
2485 2591
 				// Now add it.
2486 2592
 				$context['to_process'][$path] = $status;
@@ -2490,17 +2596,20 @@  discard block
 block discarded – undo
2490 2596
 			// Make sure the chmod status is valid?
2491 2597
 			if ($validate_custom)
2492 2598
 			{
2493
-				if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false)
2494
-					fatal_error($txt['chmod_value_invalid']);
2599
+				if (preg_match('~^[4567][4567][4567]$~', $context['custom_value']) == false) {
2600
+									fatal_error($txt['chmod_value_invalid']);
2601
+				}
2495 2602
 			}
2496 2603
 
2497 2604
 			// Nothing to do?
2498
-			if (empty($context['to_process']))
2499
-				redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']);
2605
+			if (empty($context['to_process'])) {
2606
+							redirectexit('action=admin;area=packages;sa=perms' . (!empty($context['back_look_data']) ? ';back_look=' . base64_encode(json_encode($context['back_look_data'])) : '') . ';' . $context['session_var'] . '=' . $context['session_id']);
2607
+			}
2500 2608
 		}
2501 2609
 		// Should never get here,
2502
-		else
2503
-			fatal_lang_error('no_access', false);
2610
+		else {
2611
+					fatal_lang_error('no_access', false);
2612
+		}
2504 2613
 
2505 2614
 		// Setup the custom value.
2506 2615
 		$custom_value = octdec('0' . $context['custom_value']);
@@ -2508,26 +2617,27 @@  discard block
 block discarded – undo
2508 2617
 		// Start processing items.
2509 2618
 		foreach ($context['to_process'] as $path => $status)
2510 2619
 		{
2511
-			if (in_array($status, array('execute', 'writable', 'read')))
2512
-				package_chmod($path, $status);
2513
-			elseif ($status == 'custom' && !empty($custom_value))
2620
+			if (in_array($status, array('execute', 'writable', 'read'))) {
2621
+							package_chmod($path, $status);
2622
+			} elseif ($status == 'custom' && !empty($custom_value))
2514 2623
 			{
2515 2624
 				// Use FTP if we have it.
2516 2625
 				if (!empty($package_ftp) && !empty($_SESSION['pack_ftp']))
2517 2626
 				{
2518 2627
 					$ftp_file = strtr($path, array($_SESSION['pack_ftp']['root'] => ''));
2519 2628
 					$package_ftp->chmod($ftp_file, $custom_value);
2629
+				} else {
2630
+									smf_chmod($path, $custom_value);
2520 2631
 				}
2521
-				else
2522
-					smf_chmod($path, $custom_value);
2523 2632
 			}
2524 2633
 
2525 2634
 			// This fish is fried...
2526 2635
 			unset($context['to_process'][$path]);
2527 2636
 
2528 2637
 			// See if we're out of time?
2529
-			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit)
2530
-				return false;
2638
+			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) {
2639
+							return false;
2640
+			}
2531 2641
 		}
2532 2642
 	}
2533 2643
 	// If predefined this is a little different.
@@ -2595,23 +2705,27 @@  discard block
 block discarded – undo
2595 2705
 			{
2596 2706
 				global $context;
2597 2707
 
2598
-				if (!empty($data['writable_on']))
2599
-					if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive')
2708
+				if (!empty($data['writable_on'])) {
2709
+									if ($context['predefined_type'] == 'standard' || $data['writable_on'] == 'restrictive')
2600 2710
 						$context['special_files'][$path] = 1;
2711
+				}
2601 2712
 
2602
-				if (!empty($data['contents']))
2603
-					foreach ($data['contents'] as $name => $contents)
2713
+				if (!empty($data['contents'])) {
2714
+									foreach ($data['contents'] as $name => $contents)
2604 2715
 						build_special_files__recursive($path . '/' . $name, $contents);
2716
+				}
2605 2717
 			}
2606 2718
 
2607
-			foreach ($context['file_tree'] as $path => $data)
2608
-				build_special_files__recursive($path, $data);
2719
+			foreach ($context['file_tree'] as $path => $data) {
2720
+							build_special_files__recursive($path, $data);
2721
+			}
2609 2722
 		}
2610 2723
 		// Free doesn't need special files.
2611
-		elseif ($context['predefined_type'] == 'free')
2612
-			$context['special_files'] = array();
2613
-		else
2614
-			$context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true);
2724
+		elseif ($context['predefined_type'] == 'free') {
2725
+					$context['special_files'] = array();
2726
+		} else {
2727
+					$context['special_files'] = smf_json_decode(base64_decode($_POST['specialFiles']), true);
2728
+		}
2615 2729
 
2616 2730
 		// Now we definitely know where we are, we need to go through again doing the chmod!
2617 2731
 		foreach ($context['directory_list'] as $path => $dummy)
@@ -2656,8 +2770,9 @@  discard block
 block discarded – undo
2656 2770
 			unset($context['directory_list'][$path]);
2657 2771
 
2658 2772
 			// See if we're out of time?
2659
-			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit)
2660
-				return false;
2773
+			if (time() - array_sum(explode(' ', $time_start)) > $timeout_limit) {
2774
+							return false;
2775
+			}
2661 2776
 		}
2662 2777
 	}
2663 2778
 
Please login to merge, or discard this patch.
Sources/MessageIndex.php 1 patch
Braces   +264 added lines, -197 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
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
  * Show the list of topics in this board, along with any child boards.
@@ -56,8 +57,9 @@  discard block
 block discarded – undo
56 57
 
57 58
 	$context['name'] = $board_info['name'];
58 59
 	$context['description'] = $board_info['description'];
59
-	if (!empty($board_info['description']))
60
-		$context['meta_description'] = strip_tags($board_info['description']);
60
+	if (!empty($board_info['description'])) {
61
+			$context['meta_description'] = strip_tags($board_info['description']);
62
+	}
61 63
 
62 64
 	// How many topics do we have in total?
63 65
 	$board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics'];
@@ -73,12 +75,14 @@  discard block
 block discarded – undo
73 75
 		$session_name = session_name();
74 76
 		foreach ($_GET as $k => $v)
75 77
 		{
76
-			if (!in_array($k, array('board', 'start', $session_name)))
77
-				$context['robot_no_index'] = true;
78
+			if (!in_array($k, array('board', 'start', $session_name))) {
79
+							$context['robot_no_index'] = true;
80
+			}
78 81
 		}
79 82
 	}
80
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
81
-		$context['robot_no_index'] = true;
83
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
84
+			$context['robot_no_index'] = true;
85
+	}
82 86
 
83 87
 	// If we can view unapproved messages and there are some build up a list.
84 88
 	if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts']))
@@ -89,14 +93,16 @@  discard block
 block discarded – undo
89 93
 	}
90 94
 
91 95
 	// We only know these.
92
-	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post')))
93
-		$_REQUEST['sort'] = 'last_post';
96
+	if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'first_post', 'last_post'))) {
97
+			$_REQUEST['sort'] = 'last_post';
98
+	}
94 99
 
95 100
 	// Make sure the starting place makes sense and construct the page index.
96
-	if (isset($_REQUEST['sort']))
97
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);
98
-	else
99
-		$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);
101
+	if (isset($_REQUEST['sort'])) {
102
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);
103
+	} else {
104
+			$context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d', $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);
105
+	}
100 106
 	$context['start'] = &$_REQUEST['start'];
101 107
 
102 108
 	// Set a canonical URL for this page.
@@ -132,14 +138,16 @@  discard block
 block discarded – undo
132 138
 	$context['link_moderators'] = array();
133 139
 	if (!empty($board_info['moderators']))
134 140
 	{
135
-		foreach ($board_info['moderators'] as $mod)
136
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
141
+		foreach ($board_info['moderators'] as $mod) {
142
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
143
+		}
137 144
 	}
138 145
 	if (!empty($board_info['moderator_groups']))
139 146
 	{
140 147
 		// By default just tack the moderator groups onto the end of the members
141
-		foreach ($board_info['moderator_groups'] as $mod_group)
142
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
148
+		foreach ($board_info['moderator_groups'] as $mod_group) {
149
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
150
+		}
143 151
 	}
144 152
 
145 153
 	// Now we tack the info onto the end of the linktree
@@ -191,20 +199,24 @@  discard block
 block discarded – undo
191 199
 		);
192 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
193 201
 		{
194
-			if (empty($row['id_member']))
195
-				continue;
202
+			if (empty($row['id_member'])) {
203
+							continue;
204
+			}
196 205
 
197
-			if (!empty($row['online_color']))
198
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
199
-			else
200
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
206
+			if (!empty($row['online_color'])) {
207
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
208
+			} else {
209
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
210
+			}
201 211
 
202 212
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
203
-			if ($is_buddy)
204
-				$link = '<strong>' . $link . '</strong>';
213
+			if ($is_buddy) {
214
+							$link = '<strong>' . $link . '</strong>';
215
+			}
205 216
 
206
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
207
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
217
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
218
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
219
+			}
208 220
 			// @todo why are we filling this array of data that are just counted (twice) and discarded? ???
209 221
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
210 222
 				'id' => $row['id_member'],
@@ -217,8 +229,9 @@  discard block
 block discarded – undo
217 229
 				'hidden' => empty($row['show_online']),
218 230
 			);
219 231
 
220
-			if (empty($row['show_online']))
221
-				$context['view_num_hidden']++;
232
+			if (empty($row['show_online'])) {
233
+							$context['view_num_hidden']++;
234
+			}
222 235
 		}
223 236
 		$context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']);
224 237
 		$smcFunc['db_free_result']($request);
@@ -257,8 +270,9 @@  discard block
 block discarded – undo
257 270
 	$context['sort_direction'] = $ascending ? 'up' : 'down';
258 271
 	$txt['starter'] = $txt['started_by'];
259 272
 
260
-	foreach ($sort_methods as $key => $val)
261
-		$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
273
+	foreach ($sort_methods as $key => $val) {
274
+			$context['topics_headers'][$key] = '<a href="' . $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : '') . '">' . $txt[$key] . ($context['sort_by'] == $key ? '<span class="sort sort_' . $context['sort_direction'] . '"></span>' : '') . '</a>';
275
+	}
262 276
 
263 277
 	// Calculate the fastest way to get the topics.
264 278
 	$start = (int) $_REQUEST['start'];
@@ -268,14 +282,15 @@  discard block
 block discarded – undo
268 282
 		$fake_ascending = true;
269 283
 		$maxindex = $board_info['total_topics'] < $start + $maxindex + 1 ? $board_info['total_topics'] - $start : $maxindex;
270 284
 		$start = $board_info['total_topics'] < $start + $maxindex + 1 ? 0 : $board_info['total_topics'] - $start - $maxindex;
285
+	} else {
286
+			$fake_ascending = false;
271 287
 	}
272
-	else
273
-		$fake_ascending = false;
274 288
 
275 289
 	// Setup the default topic icons...
276 290
 	$context['icon_sources'] = array();
277
-	foreach ($context['stable_icons'] as $icon)
278
-		$context['icon_sources'][$icon] = 'images_url';
291
+	foreach ($context['stable_icons'] as $icon) {
292
+			$context['icon_sources'][$icon] = 'images_url';
293
+	}
279 294
 
280 295
 	$topic_ids = array();
281 296
 	$context['topics'] = array();
@@ -306,8 +321,9 @@  discard block
 block discarded – undo
306 321
 			)
307 322
 		);
308 323
 		$topic_ids = array();
309
-		while ($row = $smcFunc['db_fetch_assoc']($request))
310
-			$topic_ids[] = $row['id_topic'];
324
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
325
+					$topic_ids[] = $row['id_topic'];
326
+		}
311 327
 	}
312 328
 
313 329
 	// Grab the appropriate topic information...
@@ -363,11 +379,13 @@  discard block
 block discarded – undo
363 379
 		// Begin 'printing' the message index for current board.
364 380
 		while ($row = $smcFunc['db_fetch_assoc']($result))
365 381
 		{
366
-			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
367
-				continue;
382
+			if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0') {
383
+							continue;
384
+			}
368 385
 
369
-			if (!$pre_query)
370
-				$topic_ids[] = $row['id_topic'];
386
+			if (!$pre_query) {
387
+							$topic_ids[] = $row['id_topic'];
388
+			}
371 389
 
372 390
 			// Reference the main color class.
373 391
 			$colorClass = 'windowbg';
@@ -377,8 +395,9 @@  discard block
 block discarded – undo
377 395
 			{
378 396
 				// Limit them to $modSettings['preview_characters'] characters
379 397
 				$row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], $row['first_smileys'], $row['id_first_msg']), array('<br>' => '&#10;')));
380
-				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters'])
381
-					$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
398
+				if ($smcFunc['strlen']($row['first_body']) > $modSettings['preview_characters']) {
399
+									$row['first_body'] = $smcFunc['substr']($row['first_body'], 0, $modSettings['preview_characters']) . '...';
400
+				}
382 401
 
383 402
 				// Censor the subject and message preview.
384 403
 				censorText($row['first_subject']);
@@ -389,27 +408,27 @@  discard block
 block discarded – undo
389 408
 				{
390 409
 					$row['last_subject'] = $row['first_subject'];
391 410
 					$row['last_body'] = $row['first_body'];
392
-				}
393
-				else
411
+				} else
394 412
 				{
395 413
 					$row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], $row['last_smileys'], $row['id_last_msg']), array('<br>' => '&#10;')));
396
-					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters'])
397
-						$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
414
+					if ($smcFunc['strlen']($row['last_body']) > $modSettings['preview_characters']) {
415
+											$row['last_body'] = $smcFunc['substr']($row['last_body'], 0, $modSettings['preview_characters']) . '...';
416
+					}
398 417
 
399 418
 					censorText($row['last_subject']);
400 419
 					censorText($row['last_body']);
401 420
 				}
402
-			}
403
-			else
421
+			} else
404 422
 			{
405 423
 				$row['first_body'] = '';
406 424
 				$row['last_body'] = '';
407 425
 				censorText($row['first_subject']);
408 426
 
409
-				if ($row['id_first_msg'] == $row['id_last_msg'])
410
-					$row['last_subject'] = $row['first_subject'];
411
-				else
412
-					censorText($row['last_subject']);
427
+				if ($row['id_first_msg'] == $row['id_last_msg']) {
428
+									$row['last_subject'] = $row['first_subject'];
429
+				} else {
430
+									censorText($row['last_subject']);
431
+				}
413 432
 			}
414 433
 
415 434
 			// Decide how many pages the topic should have.
@@ -420,42 +439,50 @@  discard block
 block discarded – undo
420 439
 				$pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, false);
421 440
 
422 441
 				// If we can use all, show all.
423
-				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages'])
424
-					$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
442
+				if (!empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']) {
443
+									$pages .= ' &nbsp;<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
444
+				}
445
+			} else {
446
+							$pages = '';
425 447
 			}
426
-			else
427
-				$pages = '';
428 448
 
429 449
 			// We need to check the topic icons exist...
430 450
 			if (!empty($modSettings['messageIconChecks_enable']))
431 451
 			{
432
-				if (!isset($context['icon_sources'][$row['first_icon']]))
433
-					$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
434
-				if (!isset($context['icon_sources'][$row['last_icon']]))
435
-					$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
436
-			}
437
-			else
452
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
453
+									$context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
454
+				}
455
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
456
+									$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
457
+				}
458
+			} else
438 459
 			{
439
-				if (!isset($context['icon_sources'][$row['first_icon']]))
440
-					$context['icon_sources'][$row['first_icon']] = 'images_url';
441
-				if (!isset($context['icon_sources'][$row['last_icon']]))
442
-					$context['icon_sources'][$row['last_icon']] = 'images_url';
460
+				if (!isset($context['icon_sources'][$row['first_icon']])) {
461
+									$context['icon_sources'][$row['first_icon']] = 'images_url';
462
+				}
463
+				if (!isset($context['icon_sources'][$row['last_icon']])) {
464
+									$context['icon_sources'][$row['last_icon']] = 'images_url';
465
+				}
443 466
 			}
444 467
 
445
-			if (!empty($board_info['recycle']))
446
-				$row['first_icon'] = 'recycled';
468
+			if (!empty($board_info['recycle'])) {
469
+							$row['first_icon'] = 'recycled';
470
+			}
447 471
 
448 472
 			// Is this topic pending approval, or does it have any posts pending approval?
449
-			if ($context['can_approve_posts'] && $row['unapproved_posts'])
450
-				$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
473
+			if ($context['can_approve_posts'] && $row['unapproved_posts']) {
474
+							$colorClass .= (!$row['approved'] ? ' approvetopic' : ' approvepost');
475
+			}
451 476
 
452 477
 			// Sticky topics should get a different color, too.
453
-			if ($row['is_sticky'])
454
-				$colorClass .= ' sticky';
478
+			if ($row['is_sticky']) {
479
+							$colorClass .= ' sticky';
480
+			}
455 481
 
456 482
 			// Locked topics get special treatment as well.
457
-			if ($row['locked'])
458
-				$colorClass .= ' locked';
483
+			if ($row['locked']) {
484
+							$colorClass .= ' locked';
485
+			}
459 486
 
460 487
 			// 'Print' the topic info.
461 488
 			$context['topics'][$row['id_topic']] = array_merge($row, array(
@@ -536,8 +563,9 @@  discard block
 block discarded – undo
536 563
 		$smcFunc['db_free_result']($result);
537 564
 
538 565
 		// Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...)
539
-		if ($fake_ascending)
540
-			$context['topics'] = array_reverse($context['topics'], true);
566
+		if ($fake_ascending) {
567
+					$context['topics'] = array_reverse($context['topics'], true);
568
+		}
541 569
 
542 570
 		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'] && !empty($topic_ids))
543 571
 		{
@@ -554,8 +582,9 @@  discard block
 block discarded – undo
554 582
 					'limit' => count($topic_ids),
555 583
 				)
556 584
 			);
557
-			while ($row = $smcFunc['db_fetch_assoc']($result))
558
-				$context['topics'][$row['id_topic']]['is_posted_in'] = true;
585
+			while ($row = $smcFunc['db_fetch_assoc']($result)) {
586
+							$context['topics'][$row['id_topic']]['is_posted_in'] = true;
587
+			}
559 588
 			$smcFunc['db_free_result']($result);
560 589
 		}
561 590
 	}
@@ -580,9 +609,9 @@  discard block
 block discarded – undo
580 609
 		// Can we restore topics?
581 610
 		$context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']);
582 611
 
583
-		if ($user_info['is_admin'] || $modSettings['topic_move_any'])
584
-			$context['can_move_any'] = true;
585
-		else
612
+		if ($user_info['is_admin'] || $modSettings['topic_move_any']) {
613
+					$context['can_move_any'] = true;
614
+		} else
586 615
 		{
587 616
 			// We'll use this in a minute
588 617
 			$boards_allowed = boardsAllowedTo('post_new');
@@ -609,11 +638,13 @@  discard block
 block discarded – undo
609 638
 		}
610 639
 
611 640
 		// Can we use quick moderation checkboxes?
612
-		if ($options['display_quick_mod'] == 1)
613
-			$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
641
+		if ($options['display_quick_mod'] == 1) {
642
+					$context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
643
+		}
614 644
 		// Or the icons?
615
-		else
616
-			$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
645
+		else {
646
+					$context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
647
+		}
617 648
 	}
618 649
 
619 650
 	if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1)
@@ -647,13 +678,15 @@  discard block
 block discarded – undo
647 678
 			);
648 679
 
649 680
 			// We've seen all these boards now!
650
-			foreach ($board_info['parent_boards'] as $k => $dummy)
651
-				if (isset($_SESSION['topicseen_cache'][$k]))
681
+			foreach ($board_info['parent_boards'] as $k => $dummy) {
682
+							if (isset($_SESSION['topicseen_cache'][$k]))
652 683
 					unset($_SESSION['topicseen_cache'][$k]);
684
+			}
653 685
 		}
654 686
 
655
-		if (isset($_SESSION['topicseen_cache'][$board]))
656
-			unset($_SESSION['topicseen_cache'][$board]);
687
+		if (isset($_SESSION['topicseen_cache'][$board])) {
688
+					unset($_SESSION['topicseen_cache'][$board]);
689
+		}
657 690
 
658 691
 		$request = $smcFunc['db_query']('', '
659 692
 			SELECT id_topic, id_board, sent
@@ -675,8 +708,9 @@  discard block
 block discarded – undo
675 708
 				$context['is_marked_notify'] = true;
676 709
 				$board_sent = $row['sent'];
677 710
 			}
678
-			if (!empty($row['id_topic']))
679
-				$context['topics'][$row['id_topic']]['is_watched'] = true;
711
+			if (!empty($row['id_topic'])) {
712
+							$context['topics'][$row['id_topic']]['is_watched'] = true;
713
+			}
680 714
 		}
681 715
 		$smcFunc['db_free_result']($request);
682 716
 
@@ -700,8 +734,7 @@  discard block
 block discarded – undo
700 734
 		$pref = !empty($pref[$user_info['id']]) ? $pref[$user_info['id']] : array();
701 735
 		$pref = isset($pref['board_notify_' . $board]) ? $pref['board_notify_' . $board] : (!empty($pref['board_notify']) ? $pref['board_notify'] : 0);
702 736
 		$context['board_notification_mode'] = !$context['is_marked_notify'] ? 1 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1));
703
-	}
704
-	else
737
+	} else
705 738
 	{
706 739
 		$context['is_marked_notify'] = false;
707 740
 		$context['board_notification_mode'] = 1;
@@ -714,23 +747,27 @@  discard block
 block discarded – undo
714 747
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
715 748
 
716 749
 	// Don't want to show this forever...
717
-	if ($context['becomesUnapproved'])
718
-		unset($_SESSION['becomesUnapproved']);
750
+	if ($context['becomesUnapproved']) {
751
+			unset($_SESSION['becomesUnapproved']);
752
+	}
719 753
 
720 754
 	// Build the message index button array.
721 755
 	$context['normal_buttons'] = array();
722 756
 	
723
-	if ($context['can_post_new'])
724
-		$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
757
+	if ($context['can_post_new']) {
758
+			$context['normal_buttons']['new_topic'] = array('text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true);
759
+	}
725 760
 	
726
-	if ($context['can_post_poll'])
727
-		$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
761
+	if ($context['can_post_poll']) {
762
+			$context['normal_buttons']['post_poll'] = array('text' => 'new_poll', 'image' => 'new_poll.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0;poll');
763
+	}
728 764
 	
729
-	if (!$context['user']['is_logged'])
730
-		$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
765
+	if (!$context['user']['is_logged']) {
766
+			$context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
767
+	}
731 768
 
732
-	if ($context['can_mark_notify'])
733
-		$context['normal_buttons']['notify'] = array(
769
+	if ($context['can_mark_notify']) {
770
+			$context['normal_buttons']['notify'] = array(
734 771
 			'lang' => true,
735 772
 			'text' => 'notify_board_' . $context['board_notification_mode'],
736 773
 			'sub_buttons' => array(
@@ -748,6 +785,7 @@  discard block
 block discarded – undo
748 785
 				),
749 786
 			),
750 787
 		);
788
+	}
751 789
 
752 790
 	// Javascript for inline editing.
753 791
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -769,18 +807,21 @@  discard block
 block discarded – undo
769 807
 	checkSession('request');
770 808
 
771 809
 	// Lets go straight to the restore area.
772
-	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics']))
773
-		redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
810
+	if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) {
811
+			redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
812
+	}
774 813
 
775
-	if (isset($_SESSION['topicseen_cache']))
776
-		$_SESSION['topicseen_cache'] = array();
814
+	if (isset($_SESSION['topicseen_cache'])) {
815
+			$_SESSION['topicseen_cache'] = array();
816
+	}
777 817
 
778 818
 	// This is going to be needed to send off the notifications and for updateLastMessages().
779 819
 	require_once($sourcedir . '/Subs-Post.php');
780 820
 
781 821
 	// Remember the last board they moved things to.
782
-	if (isset($_REQUEST['move_to']))
783
-		$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
822
+	if (isset($_REQUEST['move_to'])) {
823
+			$_SESSION['move_to_topic'] = $_REQUEST['move_to'];
824
+	}
784 825
 
785 826
 	// Only a few possible actions.
786 827
 	$possibleActions = array();
@@ -800,8 +841,7 @@  discard block
 block discarded – undo
800 841
 		);
801 842
 
802 843
 		$redirect_url = 'board=' . $board . '.' . $_REQUEST['start'];
803
-	}
804
-	else
844
+	} else
805 845
 	{
806 846
 		/**
807 847
 		 * @todo Ugly. There's no getting around this, is there?
@@ -819,8 +859,7 @@  discard block
 block discarded – undo
819 859
 		if (!empty($board))
820 860
 		{
821 861
 			$boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board));
822
-		}
823
-		else
862
+		} else
824 863
 		{
825 864
 			$boards_can['post_new'] = boardsAllowedTo('post_new');
826 865
 		}
@@ -831,55 +870,67 @@  discard block
 block discarded – undo
831 870
 		}
832 871
 	}
833 872
 
834
-	if (!$user_info['is_guest'])
835
-		$possibleActions[] = 'markread';
836
-	if (!empty($boards_can['make_sticky']))
837
-		$possibleActions[] = 'sticky';
838
-	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own']))
839
-		$possibleActions[] = 'move';
840
-	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own']))
841
-		$possibleActions[] = 'remove';
842
-	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own']))
843
-		$possibleActions[] = 'lock';
844
-	if (!empty($boards_can['merge_any']))
845
-		$possibleActions[] = 'merge';
846
-	if (!empty($boards_can['approve_posts']))
847
-		$possibleActions[] = 'approve';
873
+	if (!$user_info['is_guest']) {
874
+			$possibleActions[] = 'markread';
875
+	}
876
+	if (!empty($boards_can['make_sticky'])) {
877
+			$possibleActions[] = 'sticky';
878
+	}
879
+	if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) {
880
+			$possibleActions[] = 'move';
881
+	}
882
+	if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) {
883
+			$possibleActions[] = 'remove';
884
+	}
885
+	if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) {
886
+			$possibleActions[] = 'lock';
887
+	}
888
+	if (!empty($boards_can['merge_any'])) {
889
+			$possibleActions[] = 'merge';
890
+	}
891
+	if (!empty($boards_can['approve_posts'])) {
892
+			$possibleActions[] = 'approve';
893
+	}
848 894
 
849 895
 	// Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction'].
850 896
 	// (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.)
851 897
 	if (!empty($_REQUEST['topics']))
852 898
 	{
853 899
 		// If the action isn't valid, just quit now.
854
-		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions))
855
-			redirectexit($redirect_url);
900
+		if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) {
901
+					redirectexit($redirect_url);
902
+		}
856 903
 
857 904
 		// Merge requires all topics as one parameter and can be done at once.
858 905
 		if ($_REQUEST['qaction'] == 'merge')
859 906
 		{
860 907
 			// Merge requires at least two topics.
861
-			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2)
862
-				redirectexit($redirect_url);
908
+			if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) {
909
+							redirectexit($redirect_url);
910
+			}
863 911
 
864 912
 			require_once($sourcedir . '/SplitTopics.php');
865 913
 			return MergeExecute($_REQUEST['topics']);
866 914
 		}
867 915
 
868 916
 		// Just convert to the other method, to make it easier.
869
-		foreach ($_REQUEST['topics'] as $topic)
870
-			$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
917
+		foreach ($_REQUEST['topics'] as $topic) {
918
+					$_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
919
+		}
871 920
 	}
872 921
 
873 922
 	// Weird... how'd you get here?
874
-	if (empty($_REQUEST['actions']))
875
-		redirectexit($redirect_url);
923
+	if (empty($_REQUEST['actions'])) {
924
+			redirectexit($redirect_url);
925
+	}
876 926
 
877 927
 	// Validate each action.
878 928
 	$temp = array();
879 929
 	foreach ($_REQUEST['actions'] as $topic => $action)
880 930
 	{
881
-		if (in_array($action, $possibleActions))
882
-			$temp[(int) $topic] = $action;
931
+		if (in_array($action, $possibleActions)) {
932
+					$temp[(int) $topic] = $action;
933
+		}
883 934
 	}
884 935
 	$_REQUEST['actions'] = $temp;
885 936
 
@@ -900,27 +951,31 @@  discard block
 block discarded – undo
900 951
 		{
901 952
 			if (!empty($board))
902 953
 			{
903
-				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts')))
904
-					unset($_REQUEST['actions'][$row['id_topic']]);
905
-			}
906
-			else
954
+				if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) {
955
+									unset($_REQUEST['actions'][$row['id_topic']]);
956
+				}
957
+			} else
907 958
 			{
908 959
 				// Don't allow them to act on unapproved posts they can't see...
909
-				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))
910
-					unset($_REQUEST['actions'][$row['id_topic']]);
960
+				if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) {
961
+									unset($_REQUEST['actions'][$row['id_topic']]);
962
+				}
911 963
 				// Goodness, this is fun.  We need to validate the action.
912
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky']))
913
-					unset($_REQUEST['actions'][$row['id_topic']]);
914
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own']))))
915
-					unset($_REQUEST['actions'][$row['id_topic']]);
916
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own']))))
917
-					unset($_REQUEST['actions'][$row['id_topic']]);
964
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) {
965
+									unset($_REQUEST['actions'][$row['id_topic']]);
966
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) {
967
+									unset($_REQUEST['actions'][$row['id_topic']]);
968
+				} elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) {
969
+									unset($_REQUEST['actions'][$row['id_topic']]);
970
+				}
918 971
 				// @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked'])
919
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own']))))
920
-					unset($_REQUEST['actions'][$row['id_topic']]);
972
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) {
973
+									unset($_REQUEST['actions'][$row['id_topic']]);
974
+				}
921 975
 				// If the topic is approved then you need permission to approve the posts within.
922
-				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))))
923
-					unset($_REQUEST['actions'][$row['id_topic']]);
976
+				elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) {
977
+									unset($_REQUEST['actions'][$row['id_topic']]);
978
+				}
924 979
 			}
925 980
 		}
926 981
 		$smcFunc['db_free_result']($request);
@@ -938,11 +993,11 @@  discard block
 block discarded – undo
938 993
 	{
939 994
 		$topic = (int) $topic;
940 995
 
941
-		if ($action == 'markread')
942
-			$markCache[] = $topic;
943
-		elseif ($action == 'sticky')
944
-			$stickyCache[] = $topic;
945
-		elseif ($action == 'move')
996
+		if ($action == 'markread') {
997
+					$markCache[] = $topic;
998
+		} elseif ($action == 'sticky') {
999
+					$stickyCache[] = $topic;
1000
+		} elseif ($action == 'move')
946 1001
 		{
947 1002
 			require_once($sourcedir . '/MoveTopic.php');
948 1003
 			moveTopicConcurrence();
@@ -950,23 +1005,25 @@  discard block
 block discarded – undo
950 1005
 			// $moveCache[0] is the topic, $moveCache[1] is the board to move to.
951 1006
 			$moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']);
952 1007
 
953
-			if (empty($moveCache[1][$topic]))
954
-				continue;
1008
+			if (empty($moveCache[1][$topic])) {
1009
+							continue;
1010
+			}
955 1011
 
956 1012
 			$moveCache[0][] = $topic;
1013
+		} elseif ($action == 'remove') {
1014
+					$removeCache[] = $topic;
1015
+		} elseif ($action == 'lock') {
1016
+					$lockCache[] = $topic;
1017
+		} elseif ($action == 'approve') {
1018
+					$approveCache[] = $topic;
957 1019
 		}
958
-		elseif ($action == 'remove')
959
-			$removeCache[] = $topic;
960
-		elseif ($action == 'lock')
961
-			$lockCache[] = $topic;
962
-		elseif ($action == 'approve')
963
-			$approveCache[] = $topic;
964 1020
 	}
965 1021
 
966
-	if (empty($board))
967
-		$affectedBoards = array();
968
-	else
969
-		$affectedBoards = array($board => array(0, 0));
1022
+	if (empty($board)) {
1023
+			$affectedBoards = array();
1024
+	} else {
1025
+			$affectedBoards = array($board => array(0, 0));
1026
+	}
970 1027
 
971 1028
 	// Do all the stickies...
972 1029
 	if (!empty($stickyCache))
@@ -1026,14 +1083,16 @@  discard block
 block discarded – undo
1026 1083
 		{
1027 1084
 			$to = $moveCache[1][$row['id_topic']];
1028 1085
 
1029
-			if (empty($to))
1030
-				continue;
1086
+			if (empty($to)) {
1087
+							continue;
1088
+			}
1031 1089
 
1032 1090
 			// Does this topic's board count the posts or not?
1033 1091
 			$countPosts[$row['id_topic']] = empty($row['count_posts']);
1034 1092
 
1035
-			if (!isset($moveTos[$to]))
1036
-				$moveTos[$to] = array();
1093
+			if (!isset($moveTos[$to])) {
1094
+							$moveTos[$to] = array();
1095
+			}
1037 1096
 
1038 1097
 			$moveTos[$to][] = $row['id_topic'];
1039 1098
 
@@ -1047,8 +1106,9 @@  discard block
 block discarded – undo
1047 1106
 		require_once($sourcedir . '/MoveTopic.php');
1048 1107
 
1049 1108
 		// Do the actual moves...
1050
-		foreach ($moveTos as $to => $topics)
1051
-			moveTopics($topics, $to);
1109
+		foreach ($moveTos as $to => $topics) {
1110
+					moveTopics($topics, $to);
1111
+		}
1052 1112
 
1053 1113
 		// Does the post counts need to be updated?
1054 1114
 		if (!empty($moveTos))
@@ -1097,20 +1157,23 @@  discard block
 block discarded – undo
1097 1157
 
1098 1158
 				while ($row = $smcFunc['db_fetch_assoc']($request))
1099 1159
 				{
1100
-					if (!isset($members[$row['id_member']]))
1101
-						$members[$row['id_member']] = 0;
1160
+					if (!isset($members[$row['id_member']])) {
1161
+											$members[$row['id_member']] = 0;
1162
+					}
1102 1163
 
1103
-					if ($topicRecounts[$row['id_topic']] === '+')
1104
-						$members[$row['id_member']] += 1;
1105
-					else
1106
-						$members[$row['id_member']] -= 1;
1164
+					if ($topicRecounts[$row['id_topic']] === '+') {
1165
+											$members[$row['id_member']] += 1;
1166
+					} else {
1167
+											$members[$row['id_member']] -= 1;
1168
+					}
1107 1169
 				}
1108 1170
 
1109 1171
 				$smcFunc['db_free_result']($request);
1110 1172
 
1111 1173
 				// And now update them member's post counts
1112
-				foreach ($members as $id_member => $post_adj)
1113
-					updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1174
+				foreach ($members as $id_member => $post_adj) {
1175
+									updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
1176
+				}
1114 1177
 
1115 1178
 			}
1116 1179
 		}
@@ -1190,8 +1253,9 @@  discard block
 block discarded – undo
1190 1253
 			approveTopics($approveCache);
1191 1254
 
1192 1255
 			// Time for some logging!
1193
-			foreach ($approveCache as $topic)
1194
-				logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1256
+			foreach ($approveCache as $topic) {
1257
+							logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
1258
+			}
1195 1259
 		}
1196 1260
 	}
1197 1261
 
@@ -1226,8 +1290,7 @@  discard block
 block discarded – undo
1226 1290
 				$lockStatus[$row['id_topic']] = empty($row['locked']);
1227 1291
 			}
1228 1292
 			$smcFunc['db_free_result']($result);
1229
-		}
1230
-		else
1293
+		} else
1231 1294
 		{
1232 1295
 			$result = $smcFunc['db_query']('', '
1233 1296
 				SELECT id_topic, locked, id_board
@@ -1277,13 +1340,15 @@  discard block
 block discarded – undo
1277 1340
 			)
1278 1341
 		);
1279 1342
 		$logged_topics = array();
1280
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1281
-			$logged_topics[$row['id_topic']] = $row['unwatched'];
1343
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1344
+					$logged_topics[$row['id_topic']] = $row['unwatched'];
1345
+		}
1282 1346
 		$smcFunc['db_free_result']($request);
1283 1347
 
1284 1348
 		$markArray = array();
1285
-		foreach ($markCache as $topic)
1286
-			$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1349
+		foreach ($markCache as $topic) {
1350
+					$markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0));
1351
+		}
1287 1352
 
1288 1353
 		$smcFunc['db_insert']('replace',
1289 1354
 			'{db_prefix}log_topics',
@@ -1296,8 +1361,9 @@  discard block
 block discarded – undo
1296 1361
 	foreach ($moveCache as $topic)
1297 1362
 	{
1298 1363
 		// Didn't actually move anything!
1299
-		if (!isset($topic[0]))
1300
-			break;
1364
+		if (!isset($topic[0])) {
1365
+					break;
1366
+		}
1301 1367
 
1302 1368
 		logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2]));
1303 1369
 		sendNotifications($topic[0], 'move');
@@ -1319,8 +1385,9 @@  discard block
 block discarded – undo
1319 1385
 		'calendar_updated' => time(),
1320 1386
 	));
1321 1387
 
1322
-	if (!empty($affectedBoards))
1323
-		updateLastMessages(array_keys($affectedBoards));
1388
+	if (!empty($affectedBoards)) {
1389
+			updateLastMessages(array_keys($affectedBoards));
1390
+	}
1324 1391
 
1325 1392
 	redirectexit($redirect_url);
1326 1393
 }
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +207 added lines, -149 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -61,10 +62,11 @@  discard block
 block discarded – undo
61 62
 	$bday = array();
62 63
 	while ($row = $smcFunc['db_fetch_assoc']($result))
63 64
 	{
64
-		if ($year_low != $year_high)
65
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
66
-		else
67
-			$age_year = $year_low;
65
+		if ($year_low != $year_high) {
66
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
67
+		} else {
68
+					$age_year = $year_low;
69
+		}
68 70
 
69 71
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
70 72
 			'id' => $row['id_member'],
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$smcFunc['db_free_result']($result);
77 79
 
78 80
 	// Set is_last, so the themes know when to stop placing separators.
79
-	foreach ($bday as $mday => $array)
80
-		$bday[$mday][count($array) - 1]['is_last'] = true;
81
+	foreach ($bday as $mday => $array) {
82
+			$bday[$mday][count($array) - 1]['is_last'] = true;
83
+	}
81 84
 
82 85
 	return $bday;
83 86
 }
@@ -125,8 +128,9 @@  discard block
 block discarded – undo
125 128
 	while ($row = $smcFunc['db_fetch_assoc']($result))
126 129
 	{
127 130
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
128
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
129
-			continue;
131
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
132
+					continue;
133
+		}
130 134
 
131 135
 		// Force a censor of the title - as often these are used by others.
132 136
 		censorText($row['title'], $use_permissions ? false : true);
@@ -135,8 +139,9 @@  discard block
 block discarded – undo
135 139
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
136 140
 
137 141
 		// Sanity check
138
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
139
-			continue;
142
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
143
+					continue;
144
+		}
140 145
 
141 146
 		// Get set up for the loop
142 147
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -200,8 +205,8 @@  discard block
 block discarded – undo
200 205
 			);
201 206
 
202 207
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
203
-			if ($use_permissions)
204
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
208
+			if ($use_permissions) {
209
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
205 210
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
206 211
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
207 212
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -209,9 +214,10 @@  discard block
 block discarded – undo
209 214
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
210 215
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
211 216
 				));
217
+			}
212 218
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
213
-			else
214
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
219
+			else {
220
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
215 221
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
216 222
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
217 223
 					'can_edit' => false,
@@ -221,6 +227,7 @@  discard block
 block discarded – undo
221 227
 					'poster' => $row['id_member'],
222 228
 					'allowed_groups' => explode(',', $row['member_groups']),
223 229
 				));
230
+			}
224 231
 
225 232
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
226 233
 		}
@@ -230,8 +237,9 @@  discard block
 block discarded – undo
230 237
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
231 238
 	if ($use_permissions)
232 239
 	{
233
-		foreach ($events as $mday => $array)
234
-			$events[$mday][count($array) - 1]['is_last'] = true;
240
+		foreach ($events as $mday => $array) {
241
+					$events[$mday][count($array) - 1]['is_last'] = true;
242
+		}
235 243
 	}
236 244
 
237 245
 	return $events;
@@ -249,11 +257,12 @@  discard block
 block discarded – undo
249 257
 	global $smcFunc;
250 258
 
251 259
 	// Get the lowest and highest dates for "all years".
252
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
253
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
260
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
261
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
254 262
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
255
-	else
256
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
263
+	} else {
264
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
265
+	}
257 266
 
258 267
 	// Find some holidays... ;).
259 268
 	$result = $smcFunc['db_query']('', '
@@ -273,10 +282,11 @@  discard block
 block discarded – undo
273 282
 	$holidays = array();
274 283
 	while ($row = $smcFunc['db_fetch_assoc']($result))
275 284
 	{
276
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
277
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
278
-		else
279
-			$event_year = substr($low_date, 0, 4);
285
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
286
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
287
+		} else {
288
+					$event_year = substr($low_date, 0, 4);
289
+		}
280 290
 
281 291
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
282 292
 	}
@@ -300,10 +310,12 @@  discard block
 block discarded – undo
300 310
 	isAllowedTo('calendar_post');
301 311
 
302 312
 	// No board?  No topic?!?
303
-	if (empty($board))
304
-		fatal_lang_error('missing_board_id', false);
305
-	if (empty($topic))
306
-		fatal_lang_error('missing_topic_id', false);
313
+	if (empty($board)) {
314
+			fatal_lang_error('missing_board_id', false);
315
+	}
316
+	if (empty($topic)) {
317
+			fatal_lang_error('missing_topic_id', false);
318
+	}
307 319
 
308 320
 	// Administrator, Moderator, or owner.  Period.
309 321
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -321,12 +333,14 @@  discard block
 block discarded – undo
321 333
 		if ($row = $smcFunc['db_fetch_assoc']($result))
322 334
 		{
323 335
 			// Not the owner of the topic.
324
-			if ($row['id_member_started'] != $user_info['id'])
325
-				fatal_lang_error('not_your_topic', 'user');
336
+			if ($row['id_member_started'] != $user_info['id']) {
337
+							fatal_lang_error('not_your_topic', 'user');
338
+			}
326 339
 		}
327 340
 		// Topic/Board doesn't exist.....
328
-		else
329
-			fatal_lang_error('calendar_no_topic', 'general');
341
+		else {
342
+					fatal_lang_error('calendar_no_topic', 'general');
343
+		}
330 344
 		$smcFunc['db_free_result']($result);
331 345
 	}
332 346
 }
@@ -414,14 +428,16 @@  discard block
 block discarded – undo
414 428
 	if (!empty($calendarOptions['start_day']))
415 429
 	{
416 430
 		$nShift -= $calendarOptions['start_day'];
417
-		if ($nShift < 0)
418
-			$nShift = 7 + $nShift;
431
+		if ($nShift < 0) {
432
+					$nShift = 7 + $nShift;
433
+		}
419 434
 	}
420 435
 
421 436
 	// Number of rows required to fit the month.
422 437
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
423
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
424
-		$nRows++;
438
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
439
+			$nRows++;
440
+	}
425 441
 
426 442
 	// Fetch the arrays for birthdays, posted events, and holidays.
427 443
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -434,8 +450,9 @@  discard block
 block discarded – undo
434 450
 	{
435 451
 		$calendarGrid['week_days'][] = $count;
436 452
 		$count++;
437
-		if ($count == 7)
438
-			$count = 0;
453
+		if ($count == 7) {
454
+					$count = 0;
455
+		}
439 456
 	}
440 457
 
441 458
 	// Iterate through each week.
@@ -452,8 +469,9 @@  discard block
 block discarded – undo
452 469
 		{
453 470
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
454 471
 
455
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
456
-				$nDay = 0;
472
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
473
+							$nDay = 0;
474
+			}
457 475
 
458 476
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
459 477
 
@@ -471,8 +489,9 @@  discard block
 block discarded – undo
471 489
 	}
472 490
 
473 491
 	// What is the last day of the month?
474
-	if ($is_previous === true)
475
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
492
+	if ($is_previous === true) {
493
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
494
+	}
476 495
 
477 496
 	// We'll use the shift in the template.
478 497
 	$calendarGrid['shift'] = $nShift;
@@ -506,8 +525,9 @@  discard block
 block discarded – undo
506 525
 	{
507 526
 		// Here we offset accordingly to get things to the real start of a week.
508 527
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
509
-		if ($date_diff < 0)
510
-			$date_diff += 7;
528
+		if ($date_diff < 0) {
529
+					$date_diff += 7;
530
+		}
511 531
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
512 532
 		$day = (int) strftime('%d', $new_timestamp);
513 533
 		$month = (int) strftime('%m', $new_timestamp);
@@ -658,8 +678,9 @@  discard block
 block discarded – undo
658 678
 	// Holidays between now and now + days.
659 679
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
660 680
 	{
661
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
662
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
681
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
682
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
683
+		}
663 684
 	}
664 685
 
665 686
 	// Happy Birthday, guys and gals!
@@ -668,8 +689,9 @@  discard block
 block discarded – undo
668 689
 		$loop_date = strftime('%Y-%m-%d', $i);
669 690
 		if (isset($cached_data['birthdays'][$loop_date]))
670 691
 		{
671
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
672
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
692
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
693
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
694
+			}
673 695
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
674 696
 		}
675 697
 	}
@@ -681,8 +703,9 @@  discard block
 block discarded – undo
681 703
 		$loop_date = strftime('%Y-%m-%d', $i);
682 704
 
683 705
 		// No events today? Check the next day.
684
-		if (empty($cached_data['events'][$loop_date]))
685
-			continue;
706
+		if (empty($cached_data['events'][$loop_date])) {
707
+					continue;
708
+		}
686 709
 
687 710
 		// Loop through all events to add a few last-minute values.
688 711
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -695,9 +718,9 @@  discard block
 block discarded – undo
695 718
 			{
696 719
 				unset($cached_data['events'][$loop_date][$ev]);
697 720
 				continue;
721
+			} else {
722
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
698 723
 			}
699
-			else
700
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
701 724
 
702 725
 			// Might be set to true afterwards, depending on the permissions.
703 726
 			$this_event['can_edit'] = false;
@@ -705,15 +728,18 @@  discard block
 block discarded – undo
705 728
 			$this_event['date'] = $loop_date;
706 729
 		}
707 730
 
708
-		if (!empty($cached_data['events'][$loop_date]))
709
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
731
+		if (!empty($cached_data['events'][$loop_date])) {
732
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
733
+		}
710 734
 	}
711 735
 
712 736
 	// Mark the last item so that a list separator can be used in the template.
713
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
714
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
715
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
716
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
737
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
738
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
739
+	}
740
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
741
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
742
+	}
717 743
 
718 744
 	return array(
719 745
 		'data' => $return_data,
@@ -761,37 +787,46 @@  discard block
 block discarded – undo
761 787
 		if (isset($_POST['start_date']))
762 788
 		{
763 789
 			$d = date_parse($_POST['start_date']);
764
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
765
-				fatal_lang_error('invalid_date', false);
766
-			if (empty($d['year']))
767
-				fatal_lang_error('event_year_missing', false);
768
-			if (empty($d['month']))
769
-				fatal_lang_error('event_month_missing', false);
770
-		}
771
-		elseif (isset($_POST['start_datetime']))
790
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
791
+							fatal_lang_error('invalid_date', false);
792
+			}
793
+			if (empty($d['year'])) {
794
+							fatal_lang_error('event_year_missing', false);
795
+			}
796
+			if (empty($d['month'])) {
797
+							fatal_lang_error('event_month_missing', false);
798
+			}
799
+		} elseif (isset($_POST['start_datetime']))
772 800
 		{
773 801
 			$d = date_parse($_POST['start_datetime']);
774
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
775
-				fatal_lang_error('invalid_date', false);
776
-			if (empty($d['year']))
777
-				fatal_lang_error('event_year_missing', false);
778
-			if (empty($d['month']))
779
-				fatal_lang_error('event_month_missing', false);
802
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
803
+							fatal_lang_error('invalid_date', false);
804
+			}
805
+			if (empty($d['year'])) {
806
+							fatal_lang_error('event_year_missing', false);
807
+			}
808
+			if (empty($d['month'])) {
809
+							fatal_lang_error('event_month_missing', false);
810
+			}
780 811
 		}
781 812
 		// The 2.0 way
782 813
 		else
783 814
 		{
784 815
 			// No month?  No year?
785
-			if (!isset($_POST['month']))
786
-				fatal_lang_error('event_month_missing', false);
787
-			if (!isset($_POST['year']))
788
-				fatal_lang_error('event_year_missing', false);
816
+			if (!isset($_POST['month'])) {
817
+							fatal_lang_error('event_month_missing', false);
818
+			}
819
+			if (!isset($_POST['year'])) {
820
+							fatal_lang_error('event_year_missing', false);
821
+			}
789 822
 
790 823
 			// Check the month and year...
791
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
792
-				fatal_lang_error('invalid_month', false);
793
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
794
-				fatal_lang_error('invalid_year', false);
824
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
825
+							fatal_lang_error('invalid_month', false);
826
+			}
827
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
828
+							fatal_lang_error('invalid_year', false);
829
+			}
795 830
 		}
796 831
 	}
797 832
 
@@ -801,8 +836,9 @@  discard block
 block discarded – undo
801 836
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
802 837
 	if (isset($_POST['span']))
803 838
 	{
804
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
805
-			fatal_lang_error('invalid_days_numb', false);
839
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
840
+					fatal_lang_error('invalid_days_numb', false);
841
+		}
806 842
 	}
807 843
 
808 844
 	// There is no need to validate the following values if we are just deleting the event.
@@ -812,24 +848,29 @@  discard block
 block discarded – undo
812 848
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
813 849
 		{
814 850
 			// No day?
815
-			if (!isset($_POST['day']))
816
-				fatal_lang_error('event_day_missing', false);
851
+			if (!isset($_POST['day'])) {
852
+							fatal_lang_error('event_day_missing', false);
853
+			}
817 854
 
818 855
 			// Bad day?
819
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
820
-				fatal_lang_error('invalid_date', false);
856
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
857
+							fatal_lang_error('invalid_date', false);
858
+			}
821 859
 		}
822 860
 
823
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
824
-			fatal_lang_error('event_title_missing', false);
825
-		elseif (!isset($_POST['evtitle']))
826
-			$_POST['evtitle'] = $_POST['subject'];
861
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
862
+					fatal_lang_error('event_title_missing', false);
863
+		} elseif (!isset($_POST['evtitle'])) {
864
+					$_POST['evtitle'] = $_POST['subject'];
865
+		}
827 866
 
828 867
 		// No title?
829
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
830
-			fatal_lang_error('no_event_title', false);
831
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
832
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
868
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
869
+					fatal_lang_error('no_event_title', false);
870
+		}
871
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
872
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
873
+		}
833 874
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
834 875
 	}
835 876
 }
@@ -856,8 +897,9 @@  discard block
 block discarded – undo
856 897
 	);
857 898
 
858 899
 	// No results, return false.
859
-	if ($smcFunc['db_num_rows'] === 0)
860
-		return false;
900
+	if ($smcFunc['db_num_rows'] === 0) {
901
+			return false;
902
+	}
861 903
 
862 904
 	// Grab the results and return.
863 905
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -993,8 +1035,9 @@  discard block
 block discarded – undo
993 1035
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
994 1036
 
995 1037
 	$column_clauses = array();
996
-	foreach ($event_columns as $col => $crit)
997
-		$column_clauses[] = $col . ' = ' . $crit;
1038
+	foreach ($event_columns as $col => $crit) {
1039
+			$column_clauses[] = $col . ' = ' . $crit;
1040
+	}
998 1041
 
999 1042
 	$smcFunc['db_query']('', '
1000 1043
 		UPDATE {db_prefix}calendar
@@ -1079,8 +1122,9 @@  discard block
 block discarded – undo
1079 1122
 	);
1080 1123
 
1081 1124
 	// If nothing returned, we are in poo, poo.
1082
-	if ($smcFunc['db_num_rows']($request) === 0)
1083
-		return false;
1125
+	if ($smcFunc['db_num_rows']($request) === 0) {
1126
+			return false;
1127
+	}
1084 1128
 
1085 1129
 	$row = $smcFunc['db_fetch_assoc']($request);
1086 1130
 	$smcFunc['db_free_result']($request);
@@ -1088,8 +1132,9 @@  discard block
 block discarded – undo
1088 1132
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1089 1133
 
1090 1134
 	// Sanity check
1091
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1092
-		return false;
1135
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1136
+			return false;
1137
+	}
1093 1138
 
1094 1139
 	$return_value = array(
1095 1140
 		'boards' => array(),
@@ -1226,24 +1271,27 @@  discard block
 block discarded – undo
1226 1271
 
1227 1272
 	// Set $span, in case we need it
1228 1273
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1229
-	if ($span > 0)
1230
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1274
+	if ($span > 0) {
1275
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1276
+	}
1231 1277
 
1232 1278
 	// Define the timezone for this event, falling back to the default if not provided
1233
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1234
-		$tz = $eventOptions['tz'];
1235
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1236
-		$tz = $_POST['tz'];
1237
-	else
1238
-		$tz = getUserTimezone();
1279
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1280
+			$tz = $eventOptions['tz'];
1281
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1282
+			$tz = $_POST['tz'];
1283
+	} else {
1284
+			$tz = getUserTimezone();
1285
+	}
1239 1286
 
1240 1287
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1241
-	if (isset($eventOptions['allday']))
1242
-		$allday = $eventOptions['allday'];
1243
-	elseif (empty($_POST['allday']))
1244
-		$allday = false;
1245
-	else
1246
-		$allday = true;
1288
+	if (isset($eventOptions['allday'])) {
1289
+			$allday = $eventOptions['allday'];
1290
+	} elseif (empty($_POST['allday'])) {
1291
+			$allday = false;
1292
+	} else {
1293
+			$allday = true;
1294
+	}
1247 1295
 
1248 1296
 	// Input might come as individual parameters...
1249 1297
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1270,10 +1318,12 @@  discard block
 block discarded – undo
1270 1318
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1271 1319
 
1272 1320
 	// If the date and time were given in separate strings, combine them
1273
-	if (empty($start_string) && isset($start_date_string))
1274
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1275
-	if (empty($end_string) && isset($end_date_string))
1276
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1321
+	if (empty($start_string) && isset($start_date_string)) {
1322
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1323
+	}
1324
+	if (empty($end_string) && isset($end_date_string)) {
1325
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1326
+	}
1277 1327
 
1278 1328
 	// If some form of string input was given, override individually defined options with it
1279 1329
 	if (isset($start_string))
@@ -1364,10 +1414,11 @@  discard block
 block discarded – undo
1364 1414
 	if ($start_object >= $end_object)
1365 1415
 	{
1366 1416
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1367
-		if ($span > 0)
1368
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1369
-		else
1370
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1417
+		if ($span > 0) {
1418
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1419
+		} else {
1420
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1421
+		}
1371 1422
 	}
1372 1423
 
1373 1424
 	// Is $end_object too late?
@@ -1380,9 +1431,9 @@  discard block
 block discarded – undo
1380 1431
 			{
1381 1432
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1382 1433
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1434
+			} else {
1435
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1383 1436
 			}
1384
-			else
1385
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1386 1437
 		}
1387 1438
 	}
1388 1439
 
@@ -1395,8 +1446,7 @@  discard block
 block discarded – undo
1395 1446
 		$start_time = null;
1396 1447
 		$end_time = null;
1397 1448
 		$tz = null;
1398
-	}
1399
-	else
1449
+	} else
1400 1450
 	{
1401 1451
 		$start_time = date_format($start_object, 'H:i:s');
1402 1452
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1417,16 +1467,18 @@  discard block
 block discarded – undo
1417 1467
 	require_once($sourcedir . '/Subs.php');
1418 1468
 
1419 1469
 	// First, try to create a better date format, ignoring the "time" elements.
1420
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1421
-		$date_format = '%F';
1422
-	else
1423
-		$date_format = $matches[0];
1470
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1471
+			$date_format = '%F';
1472
+	} else {
1473
+			$date_format = $matches[0];
1474
+	}
1424 1475
 
1425 1476
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1426
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1427
-		$time_format = '%k:%M';
1428
-	else
1429
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1477
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1478
+			$time_format = '%k:%M';
1479
+	} else {
1480
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1481
+	}
1430 1482
 
1431 1483
 	// Should this be an all day event?
1432 1484
 	$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;
@@ -1435,8 +1487,9 @@  discard block
 block discarded – undo
1435 1487
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1436 1488
 
1437 1489
 	// We need to have a defined timezone in the steps below
1438
-	if (empty($row['timezone']))
1439
-		$row['timezone'] = getUserTimezone();
1490
+	if (empty($row['timezone'])) {
1491
+			$row['timezone'] = getUserTimezone();
1492
+	}
1440 1493
 
1441 1494
 	// Get most of the standard date information for the start and end datetimes
1442 1495
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1482,8 +1535,9 @@  discard block
 block discarded – undo
1482 1535
 		$tz_location = timezone_location_get(timezone_open($row['timezone']));
1483 1536
 
1484 1537
 		// Kazakstan
1485
-		if ($tz_location['country_code'] == 'KZ')
1486
-			$tz_abbrev = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tz_abbrev);
1538
+		if ($tz_location['country_code'] == 'KZ') {
1539
+					$tz_abbrev = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tz_abbrev);
1540
+		}
1487 1541
 
1488 1542
 		// Russia likes to experiment with time zones
1489 1543
 		if ($tz_location['country_code'] == 'RU')
@@ -1494,8 +1548,9 @@  discard block
 block discarded – undo
1494 1548
 		}
1495 1549
 
1496 1550
 		// Still no good? We'll just mark it as a UTC offset
1497
-		if (strspn($tz_abbrev, '+-') > 0)
1498
-			$tz_abbrev = 'UTC' . $tz_abbrev;
1551
+		if (strspn($tz_abbrev, '+-') > 0) {
1552
+					$tz_abbrev = 'UTC' . $tz_abbrev;
1553
+		}
1499 1554
 	}
1500 1555
 
1501 1556
 	return array($start, $end, $allday, $span, $tz, $tz_abbrev);
@@ -1511,8 +1566,9 @@  discard block
 block discarded – undo
1511 1566
 {
1512 1567
 	global $smcFunc, $context, $sourcedir, $user_info, $modSettings;
1513 1568
 
1514
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1515
-		$id_member = $context['user']['id'];
1569
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1570
+			$id_member = $context['user']['id'];
1571
+	}
1516 1572
 
1517 1573
 	if (isset($id_member))
1518 1574
 	{
@@ -1528,8 +1584,9 @@  discard block
 block discarded – undo
1528 1584
 		$smcFunc['db_free_result']($request);
1529 1585
 	}
1530 1586
 
1531
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1532
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1587
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1588
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1589
+	}
1533 1590
 
1534 1591
 	return $timezone;
1535 1592
 }
@@ -1558,8 +1615,9 @@  discard block
 block discarded – undo
1558 1615
 		)
1559 1616
 	);
1560 1617
 	$holidays = array();
1561
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1562
-		$holidays[] = $row;
1618
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1619
+			$holidays[] = $row;
1620
+	}
1563 1621
 	$smcFunc['db_free_result']($request);
1564 1622
 
1565 1623
 	return $holidays;
Please login to merge, or discard this patch.
Sources/ManageLanguages.php 1 patch
Braces   +190 added lines, -142 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * This is the main function for the languages area.
@@ -153,11 +154,11 @@  discard block
 block discarded – undo
153 154
 	$language_list = new xmlArray(fetch_web_data($url), true);
154 155
 
155 156
 	// Check that the site responded and that the language exists.
156
-	if (!$language_list->exists('languages'))
157
-		$context['smf_error'] = 'no_response';
158
-	elseif (!$language_list->exists('languages/language'))
159
-		$context['smf_error'] = 'no_files';
160
-	else
157
+	if (!$language_list->exists('languages')) {
158
+			$context['smf_error'] = 'no_response';
159
+	} elseif (!$language_list->exists('languages/language')) {
160
+			$context['smf_error'] = 'no_files';
161
+	} else
161 162
 	{
162 163
 		$language_list = $language_list->path('languages[0]');
163 164
 		$lang_files = $language_list->set('language');
@@ -165,8 +166,9 @@  discard block
 block discarded – undo
165 166
 		foreach ($lang_files as $file)
166 167
 		{
167 168
 			// Were we searching?
168
-			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false)
169
-				continue;
169
+			if (!empty($context['smf_search_term']) && strpos($file->fetch('name'), $smcFunc['strtolower']($context['smf_search_term'])) === false) {
170
+							continue;
171
+			}
170 172
 
171 173
 			$smf_languages[] = array(
172 174
 				'id' => $file->fetch('id'),
@@ -177,10 +179,11 @@  discard block
 block discarded – undo
177 179
 				'install_link' => '<a href="' . $scripturl . '?action=admin;area=languages;sa=downloadlang;did=' . $file->fetch('id') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['add_language_smf_install'] . '</a>',
178 180
 			);
179 181
 		}
180
-		if (empty($smf_languages))
181
-			$context['smf_error'] = 'no_files';
182
-		else
183
-			return $smf_languages;
182
+		if (empty($smf_languages)) {
183
+					$context['smf_error'] = 'no_files';
184
+		} else {
185
+					return $smf_languages;
186
+		}
184 187
 	}
185 188
 }
186 189
 
@@ -202,8 +205,9 @@  discard block
 block discarded – undo
202 205
 	require_once($sourcedir . '/Subs-Package.php');
203 206
 
204 207
 	// Clearly we need to know what to request.
205
-	if (!isset($_GET['did']))
206
-		fatal_lang_error('no_access', false);
208
+	if (!isset($_GET['did'])) {
209
+			fatal_lang_error('no_access', false);
210
+	}
207 211
 
208 212
 	// Some lovely context.
209 213
 	$context['download_id'] = $_GET['did'];
@@ -223,8 +227,9 @@  discard block
 block discarded – undo
223 227
 		foreach ($_POST['copy_file'] as $file)
224 228
 		{
225 229
 			// Check it's not very bad.
226
-			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file)))
227
-				fatal_error($txt['languages_download_illegal_paths']);
230
+			if (strpos($file, '..') !== false || (strpos($file, 'Themes') !== 0 && !preg_match('~agreement\.[A-Za-z-_0-9]+\.txt$~', $file))) {
231
+							fatal_error($txt['languages_download_illegal_paths']);
232
+			}
228 233
 
229 234
 			$chmod_files[] = $boarddir . '/' . $file;
230 235
 			$install_files[] = $file;
@@ -235,8 +240,9 @@  discard block
 block discarded – undo
235 240
 		$files_left = $file_status['files']['notwritable'];
236 241
 
237 242
 		// Something not writable?
238
-		if (!empty($files_left))
239
-			$context['error_message'] = $txt['languages_download_not_chmod'];
243
+		if (!empty($files_left)) {
244
+					$context['error_message'] = $txt['languages_download_not_chmod'];
245
+		}
240 246
 		// Otherwise, go go go!
241 247
 		elseif (!empty($install_files))
242 248
 		{
@@ -250,11 +256,13 @@  discard block
 block discarded – undo
250 256
 	}
251 257
 
252 258
 	// Open up the old china.
253
-	if (!isset($archive_content))
254
-		$archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
259
+	if (!isset($archive_content)) {
260
+			$archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
261
+	}
255 262
 
256
-	if (empty($archive_content))
257
-		fatal_error($txt['add_language_error_no_response']);
263
+	if (empty($archive_content)) {
264
+			fatal_error($txt['add_language_error_no_response']);
265
+	}
258 266
 
259 267
 	// Now for each of the files, let's do some *stuff*
260 268
 	$context['files'] = array(
@@ -269,8 +277,9 @@  discard block
 block discarded – undo
269 277
 		$extension = substr($filename, strrpos($filename, '.') + 1);
270 278
 
271 279
 		// Don't do anything with files we don't understand.
272
-		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt')))
273
-			continue;
280
+		if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) {
281
+					continue;
282
+		}
274 283
 
275 284
 		// Basic data.
276 285
 		$context_data = array(
@@ -289,8 +298,9 @@  discard block
 block discarded – undo
289 298
 		// Does the file exist, is it different and can we overwrite?
290 299
 		if (file_exists($boarddir . '/' . $file['filename']))
291 300
 		{
292
-			if (is_writable($boarddir . '/' . $file['filename']))
293
-				$context_data['writable'] = true;
301
+			if (is_writable($boarddir . '/' . $file['filename'])) {
302
+							$context_data['writable'] = true;
303
+			}
294 304
 
295 305
 			// Finally, do we actually think the content has changed?
296 306
 			if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename']))
@@ -303,16 +313,17 @@  discard block
 block discarded – undo
303 313
 			{
304 314
 				$context_data['exists'] = 'same';
305 315
 				$context_data['default_copy'] = false;
316
+			} else {
317
+							$context_data['exists'] = 'different';
306 318
 			}
307
-			else
308
-				$context_data['exists'] = 'different';
309 319
 		}
310 320
 		// No overwrite?
311 321
 		else
312 322
 		{
313 323
 			// Can we at least stick it in the directory...
314
-			if (is_writable($boarddir . '/' . $dirname))
315
-				$context_data['writable'] = true;
324
+			if (is_writable($boarddir . '/' . $dirname)) {
325
+							$context_data['writable'] = true;
326
+			}
316 327
 		}
317 328
 
318 329
 		// I love PHP files, that's why I'm a developer and not an artistic type spending my time drinking absinth and living a life of sin...
@@ -327,8 +338,9 @@  discard block
 block discarded – undo
327 338
 			list ($name, $language) = explode('.', $filename);
328 339
 
329 340
 			// Let's get the new version, I like versions, they tell me that I'm up to date.
330
-			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1)
331
-				$context_data['version'] = $match[1];
341
+			if (preg_match('~\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) {
342
+							$context_data['version'] = $match[1];
343
+			}
332 344
 
333 345
 			// Now does the old file exist - if so what is it's version?
334 346
 			if (file_exists($boarddir . '/' . $file['filename']))
@@ -344,34 +356,35 @@  discard block
 block discarded – undo
344 356
 					$context_data['cur_version'] = $match[1];
345 357
 
346 358
 					// How does this compare?
347
-					if ($context_data['cur_version'] == $context_data['version'])
348
-						$context_data['version_compare'] = 'same';
349
-					elseif ($context_data['cur_version'] > $context_data['version'])
350
-						$context_data['version_compare'] = 'older';
359
+					if ($context_data['cur_version'] == $context_data['version']) {
360
+											$context_data['version_compare'] = 'same';
361
+					} elseif ($context_data['cur_version'] > $context_data['version']) {
362
+											$context_data['version_compare'] = 'older';
363
+					}
351 364
 
352 365
 					// Don't recommend copying if the version is the same.
353
-					if ($context_data['version_compare'] != 'newer')
354
-						$context_data['default_copy'] = false;
366
+					if ($context_data['version_compare'] != 'newer') {
367
+											$context_data['default_copy'] = false;
368
+					}
355 369
 				}
356 370
 			}
357 371
 
358 372
 			// Add the context data to the main set.
359 373
 			$context['files']['lang'][] = $context_data;
360
-		}
361
-		elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
374
+		} elseif ($extension == '.txt' && stripos($filename, 'agreement') !== false)
362 375
 		{
363 376
 			// Registration agreement is a primary file
364 377
 			$context['files']['lang'][] = $context_data;
365
-		}
366
-		else
378
+		} else
367 379
 		{
368 380
 			// There shouldn't be anything else, but load this into "other" in case we decide to handle it in the future
369 381
 			$context['files']['other'][] = $context_data;
370 382
 		}
371 383
 
372 384
 		// Collect together all non-writable areas.
373
-		if (!$context_data['writable'])
374
-			$context['make_writable'][] = $context_data['destination'];
385
+		if (!$context_data['writable']) {
386
+					$context['make_writable'][] = $context_data['destination'];
387
+		}
375 388
 	}
376 389
 
377 390
 	// Before we go to far can we make anything writable, eh, eh?
@@ -386,22 +399,24 @@  discard block
 block discarded – undo
386 399
 		{
387 400
 			if ($type == 'lang')
388 401
 			{
389
-				foreach ($data as $k => $file)
390
-					if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
402
+				foreach ($data as $k => $file) {
403
+									if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
391 404
 						$context['files'][$type][$k]['writable'] = true;
392
-			}
393
-			else
405
+				}
406
+			} else
394 407
 			{
395
-				foreach ($data as $theme => $files)
396
-					foreach ($files as $k => $file)
408
+				foreach ($data as $theme => $files) {
409
+									foreach ($files as $k => $file)
397 410
 						if (!$file['writable'] && !in_array($file['destination'], $context['still_not_writable']))
398 411
 							$context['files'][$type][$theme][$k]['writable'] = true;
412
+				}
399 413
 			}
400 414
 		}
401 415
 
402 416
 		// Are we going to need more language stuff?
403
-		if (!empty($context['still_not_writable']))
404
-			loadLanguage('Packages');
417
+		if (!empty($context['still_not_writable'])) {
418
+					loadLanguage('Packages');
419
+		}
405 420
 	}
406 421
 
407 422
 	// This is the list for the main files.
@@ -614,12 +629,13 @@  discard block
 block discarded – undo
614 629
 	highlightSelected("list_language_list_' . ($language == '' ? 'english' : $language) . '");', true);
615 630
 
616 631
 	// Display a warning if we cannot edit the default setting.
617
-	if (!is_writable($boarddir . '/Settings.php'))
618
-		$listOptions['additional_rows'][] = array(
632
+	if (!is_writable($boarddir . '/Settings.php')) {
633
+			$listOptions['additional_rows'][] = array(
619 634
 				'position' => 'after_title',
620 635
 				'value' => $txt['language_settings_writable'],
621 636
 				'class' => 'smalltext alert',
622 637
 			);
638
+	}
623 639
 
624 640
 	require_once($sourcedir . '/Subs-List.php');
625 641
 	createList($listOptions);
@@ -661,10 +677,11 @@  discard block
 block discarded – undo
661 677
 
662 678
 	// Put them back.
663 679
 	$settings['actual_theme_dir'] = $backup_actual_theme_dir;
664
-	if (!empty($backup_base_theme_dir))
665
-		$settings['base_theme_dir'] = $backup_base_theme_dir;
666
-	else
667
-		unset($settings['base_theme_dir']);
680
+	if (!empty($backup_base_theme_dir)) {
681
+			$settings['base_theme_dir'] = $backup_base_theme_dir;
682
+	} else {
683
+			unset($settings['base_theme_dir']);
684
+	}
668 685
 
669 686
 	// Get the language files and data...
670 687
 	foreach ($context['languages'] as $lang)
@@ -693,13 +710,15 @@  discard block
 block discarded – undo
693 710
 	while ($row = $smcFunc['db_fetch_assoc']($request))
694 711
 	{
695 712
 		// Default?
696
-		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']]))
697
-			$row['lngfile'] = $language;
713
+		if (empty($row['lngfile']) || !isset($languages[$row['lngfile']])) {
714
+					$row['lngfile'] = $language;
715
+		}
698 716
 
699
-		if (!isset($languages[$row['lngfile']]) && isset($languages['english']))
700
-			$languages['english']['count'] += $row['num_users'];
701
-		elseif (isset($languages[$row['lngfile']]))
702
-			$languages[$row['lngfile']]['count'] += $row['num_users'];
717
+		if (!isset($languages[$row['lngfile']]) && isset($languages['english'])) {
718
+					$languages['english']['count'] += $row['num_users'];
719
+		} elseif (isset($languages[$row['lngfile']])) {
720
+					$languages[$row['lngfile']]['count'] += $row['num_users'];
721
+		}
703 722
 	}
704 723
 	$smcFunc['db_free_result']($request);
705 724
 
@@ -739,13 +758,15 @@  discard block
 block discarded – undo
739 758
 
740 759
 	call_integration_hook('integrate_language_settings', array(&$config_vars));
741 760
 
742
-	if ($return_config)
743
-		return $config_vars;
761
+	if ($return_config) {
762
+			return $config_vars;
763
+	}
744 764
 
745 765
 	// Get our languages. No cache and use utf8.
746 766
 	getLanguages(false, false);
747
-	foreach ($context['languages'] as $lang)
748
-		$config_vars['language'][4][$lang['filename']] = array($lang['filename'], strtr($lang['name'], array('-utf8' => ' (UTF-8)')));
767
+	foreach ($context['languages'] as $lang) {
768
+			$config_vars['language'][4][$lang['filename']] = array($lang['filename'], strtr($lang['name'], array('-utf8' => ' (UTF-8)')));
769
+	}
749 770
 
750 771
 	// Saving settings?
751 772
 	if (isset($_REQUEST['save']))
@@ -755,8 +776,9 @@  discard block
 block discarded – undo
755 776
 		call_integration_hook('integrate_save_language_settings', array(&$config_vars));
756 777
 
757 778
 		saveSettings($config_vars);
758
-		if (!$settings_not_writable && !$settings_backup_fail)
759
-			$_SESSION['adm-save'] = true;
779
+		if (!$settings_not_writable && !$settings_backup_fail) {
780
+					$_SESSION['adm-save'] = true;
781
+		}
760 782
 		redirectexit('action=admin;area=languages;sa=settings');
761 783
 	}
762 784
 
@@ -765,10 +787,11 @@  discard block
 block discarded – undo
765 787
 	$context['settings_title'] = $txt['language_settings'];
766 788
 	$context['save_disabled'] = $settings_not_writable;
767 789
 
768
-	if ($settings_not_writable)
769
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
770
-	elseif ($settings_backup_fail)
771
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
790
+	if ($settings_not_writable) {
791
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
792
+	} elseif ($settings_backup_fail) {
793
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
794
+	}
772 795
 
773 796
 	// Fill the config array.
774 797
 	prepareServerSettingsContext($config_vars);
@@ -815,8 +838,9 @@  discard block
 block discarded – undo
815 838
 			'theme_dir' => $settings['default_theme_dir'],
816 839
 		),
817 840
 	);
818
-	while ($row = $smcFunc['db_fetch_assoc']($request))
819
-		$themes[$row['id_theme']][$row['variable']] = $row['value'];
841
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
842
+			$themes[$row['id_theme']][$row['variable']] = $row['value'];
843
+	}
820 844
 	$smcFunc['db_free_result']($request);
821 845
 
822 846
 	// This will be where we look
@@ -828,14 +852,16 @@  discard block
 block discarded – undo
828 852
 	// Check we have themes with a path and a name - just in case - and add the path.
829 853
 	foreach ($themes as $id => $data)
830 854
 	{
831
-		if (count($data) != 2)
832
-			unset($themes[$id]);
833
-		elseif (is_dir($data['theme_dir'] . '/languages'))
834
-			$lang_dirs[$id] = $data['theme_dir'] . '/languages';
855
+		if (count($data) != 2) {
856
+					unset($themes[$id]);
857
+		} elseif (is_dir($data['theme_dir'] . '/languages')) {
858
+					$lang_dirs[$id] = $data['theme_dir'] . '/languages';
859
+		}
835 860
 
836 861
 		// How about image directories?
837
-		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id']))
838
-			$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
862
+		if (is_dir($data['theme_dir'] . '/images/' . $context['lang_id'])) {
863
+					$images_dirs[$id] = $data['theme_dir'] . '/images/' . $context['lang_id'];
864
+		}
839 865
 	}
840 866
 
841 867
 	$current_file = $file_id ? $lang_dirs[$theme_id] . '/' . $file_id . '.' . $context['lang_id'] . '.php' : '';
@@ -849,15 +875,17 @@  discard block
 block discarded – undo
849 875
 		while ($entry = $dir->read())
850 876
 		{
851 877
 			// We're only after the files for this language.
852
-			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0)
853
-				continue;
878
+			if (preg_match('~^([A-Za-z]+)\.' . $context['lang_id'] . '\.php$~', $entry, $matches) == 0) {
879
+							continue;
880
+			}
854 881
 
855
-			if (!isset($context['possible_files'][$theme]))
856
-				$context['possible_files'][$theme] = array(
882
+			if (!isset($context['possible_files'][$theme])) {
883
+							$context['possible_files'][$theme] = array(
857 884
 					'id' => $theme,
858 885
 					'name' => $themes[$theme]['name'],
859 886
 					'files' => array(),
860 887
 				);
888
+			}
861 889
 
862 890
 			$context['possible_files'][$theme]['files'][] = array(
863 891
 				'id' => $matches[1],
@@ -886,31 +914,36 @@  discard block
 block discarded – undo
886 914
 		{
887 915
 			$_SESSION['last_backup_for'] = $context['lang_id'] . '$$$';
888 916
 			$result = package_create_backup('backup_lang_' . $context['lang_id']);
889
-			if (!$result)
890
-				fatal_lang_error('could_not_language_backup', false);
917
+			if (!$result) {
918
+							fatal_lang_error('could_not_language_backup', false);
919
+			}
891 920
 		}
892 921
 
893 922
 		// Second, loop through the array to remove the files.
894 923
 		foreach ($lang_dirs as $curPath)
895 924
 		{
896
-			foreach ($context['possible_files'][1]['files'] as $lang)
897
-				if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
925
+			foreach ($context['possible_files'][1]['files'] as $lang) {
926
+							if (file_exists($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php'))
898 927
 					unlink($curPath . '/' . $lang['id'] . '.' . $context['lang_id'] . '.php');
928
+			}
899 929
 
900 930
 			// Check for the email template.
901
-			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php'))
902
-				unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
931
+			if (file_exists($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php')) {
932
+							unlink($curPath . '/EmailTemplates.' . $context['lang_id'] . '.php');
933
+			}
903 934
 		}
904 935
 
905 936
 		// Third, the agreement file.
906
-		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt'))
907
-			unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
937
+		if (file_exists($boarddir . '/agreement.' . $context['lang_id'] . '.txt')) {
938
+					unlink($boarddir . '/agreement.' . $context['lang_id'] . '.txt');
939
+		}
908 940
 
909 941
 		// Fourth, a related images folder, if it exists...
910
-		if (!empty($images_dirs))
911
-			foreach ($images_dirs as $curPath)
942
+		if (!empty($images_dirs)) {
943
+					foreach ($images_dirs as $curPath)
912 944
 				if (is_dir($curPath))
913 945
 					deltree($curPath);
946
+		}
914 947
 
915 948
 		// Members can no longer use this language.
916 949
 		$smcFunc['db_query']('', '
@@ -995,8 +1028,9 @@  discard block
 block discarded – undo
995 1028
 		foreach ($_POST['entry'] as $k => $v)
996 1029
 		{
997 1030
 			// Only try to save if it's changed!
998
-			if ($_POST['entry'][$k] != $_POST['comp'][$k])
999
-				$save_strings[$k] = cleanLangString($v, false);
1031
+			if ($_POST['entry'][$k] != $_POST['comp'][$k]) {
1032
+							$save_strings[$k] = cleanLangString($v, false);
1033
+			}
1000 1034
 		}
1001 1035
 	}
1002 1036
 
@@ -1030,12 +1064,13 @@  discard block
 block discarded – undo
1030 1064
 		if ($multiline_cache)
1031 1065
 		{
1032 1066
 			preg_match('~\$(helptxt|txt|editortxt)\[\'(.+)\'\]\s?=\s?(.+);~ms', strtr($multiline_cache, array("\r" => '')), $matches);
1033
-			if (!empty($matches[3]))
1034
-				$entries[$matches[2]] = array(
1067
+			if (!empty($matches[3])) {
1068
+							$entries[$matches[2]] = array(
1035 1069
 					'type' => $matches[1],
1036 1070
 					'full' => $matches[0],
1037 1071
 					'entry' => $matches[3],
1038 1072
 				);
1073
+			}
1039 1074
 		}
1040 1075
 
1041 1076
 		// These are the entries we can definitely save.
@@ -1046,8 +1081,9 @@  discard block
 block discarded – undo
1046 1081
 		{
1047 1082
 			// Ignore some things we set separately.
1048 1083
 			$ignore_files = array('lang_character_set', 'lang_locale', 'lang_dictionary', 'lang_spelling', 'lang_rtl');
1049
-			if (in_array($entryKey, $ignore_files))
1050
-				continue;
1084
+			if (in_array($entryKey, $ignore_files)) {
1085
+							continue;
1086
+			}
1051 1087
 
1052 1088
 			// These are arrays that need breaking out.
1053 1089
 			$arrays = array('days', 'days_short', 'months', 'months_titles', 'months_short', 'happy_birthday_author', 'karlbenson1_author', 'nite0859_author', 'zwaldowski_author', 'geezmo_author', 'karlbenson2_author');
@@ -1080,9 +1116,9 @@  discard block
 block discarded – undo
1080 1116
 					{
1081 1117
 						$save_cache['entries'][$cur_index] = strtr($save_strings[$entryKey . '-+- ' . $cur_index], array('\'' => ''));
1082 1118
 						$save_cache['enabled'] = true;
1119
+					} else {
1120
+											$save_cache['entries'][$cur_index] = $subValue;
1083 1121
 					}
1084
-					else
1085
-						$save_cache['entries'][$cur_index] = $subValue;
1086 1122
 
1087 1123
 					$context['file_entries'][] = array(
1088 1124
 						'key' => $entryKey . '-+- ' . $cur_index,
@@ -1105,9 +1141,9 @@  discard block
 block discarded – undo
1105 1141
 						{
1106 1142
 							$items[] = $k2 . ' => \'' . $v2 . '\'';
1107 1143
 							$cur_index = $k2;
1144
+						} else {
1145
+													$items[] = '\'' . $v2 . '\'';
1108 1146
 						}
1109
-						else
1110
-							$items[] = '\'' . $v2 . '\'';
1111 1147
 
1112 1148
 						$cur_index++;
1113 1149
 					}
@@ -1117,15 +1153,15 @@  discard block
 block discarded – undo
1117 1153
 						'replace' => '$' . $entryValue['type'] . '[\'' . $entryKey . '\'] = array(' . implode(', ', $items) . ');',
1118 1154
 					);
1119 1155
 				}
1120
-			}
1121
-			else
1156
+			} else
1122 1157
 			{
1123 1158
 				// Saving?
1124 1159
 				if (isset($save_strings[$entryKey]) && $save_strings[$entryKey] != $entryValue['entry'])
1125 1160
 				{
1126 1161
 					// @todo Fix this properly.
1127
-					if ($save_strings[$entryKey] == '')
1128
-						$save_strings[$entryKey] = '\'\'';
1162
+					if ($save_strings[$entryKey] == '') {
1163
+											$save_strings[$entryKey] = '\'\'';
1164
+					}
1129 1165
 
1130 1166
 					// Set the new value.
1131 1167
 					$entryValue['entry'] = $save_strings[$entryKey];
@@ -1151,8 +1187,9 @@  discard block
 block discarded – undo
1151 1187
 			checkSession();
1152 1188
 
1153 1189
 			$file_contents = implode('', file($current_file));
1154
-			foreach ($final_saves as $save)
1155
-				$file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
1190
+			foreach ($final_saves as $save) {
1191
+							$file_contents = strtr($file_contents, array($save['find'] => $save['replace']));
1192
+			}
1156 1193
 
1157 1194
 			// Save the actual changes.
1158 1195
 			$fp = fopen($current_file, 'w+');
@@ -1167,8 +1204,9 @@  discard block
 block discarded – undo
1167 1204
 	}
1168 1205
 
1169 1206
 	// If we saved, redirect.
1170
-	if ($madeSave)
1171
-		redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
1207
+	if ($madeSave) {
1208
+			redirectexit('action=admin;area=languages;sa=editlang;lid=' . $context['lang_id']);
1209
+	}
1172 1210
 
1173 1211
 	createToken('admin-mlang');
1174 1212
 }
@@ -1200,8 +1238,9 @@  discard block
 block discarded – undo
1200 1238
 				// Toggle the escape.
1201 1239
 				$is_escape = !$is_escape;
1202 1240
 				// If we're now escaped don't add this string.
1203
-				if ($is_escape)
1204
-					continue;
1241
+				if ($is_escape) {
1242
+									continue;
1243
+				}
1205 1244
 			}
1206 1245
 			// Special case - parsed string with line break etc?
1207 1246
 			elseif (($string{$i} == 'n' || $string{$i} == 't') && $in_string == 2 && $is_escape)
@@ -1218,11 +1257,13 @@  discard block
 block discarded – undo
1218 1257
 				if ($in_string != 2 && ($in_string != 1 || !$is_escape))
1219 1258
 				{
1220 1259
 					// Is it the end of a single quote string?
1221
-					if ($in_string == 1)
1222
-						$in_string = 0;
1260
+					if ($in_string == 1) {
1261
+											$in_string = 0;
1262
+					}
1223 1263
 					// Otherwise it's the start!
1224
-					else
1225
-						$in_string = 1;
1264
+					else {
1265
+											$in_string = 1;
1266
+					}
1226 1267
 
1227 1268
 					// Don't actually include this character!
1228 1269
 					continue;
@@ -1235,19 +1276,22 @@  discard block
 block discarded – undo
1235 1276
 				if ($in_string != 1 && ($in_string != 2 || !$is_escape))
1236 1277
 				{
1237 1278
 					// Is it the end of a double quote string?
1238
-					if ($in_string == 2)
1239
-						$in_string = 0;
1279
+					if ($in_string == 2) {
1280
+											$in_string = 0;
1281
+					}
1240 1282
 					// Otherwise it's the start!
1241
-					else
1242
-						$in_string = 2;
1283
+					else {
1284
+											$in_string = 2;
1285
+					}
1243 1286
 
1244 1287
 					// Don't actually include this character!
1245 1288
 					continue;
1246 1289
 				}
1247 1290
 			}
1248 1291
 			// A join/space outside of a string is simply removed.
1249
-			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.'))
1250
-				continue;
1292
+			elseif ($in_string == 0 && (empty($string{$i}) || $string{$i} == '.')) {
1293
+							continue;
1294
+			}
1251 1295
 			// Start of a variable?
1252 1296
 			elseif ($in_string == 0 && $string{$i} == '$')
1253 1297
 			{
@@ -1281,8 +1325,7 @@  discard block
 block discarded – undo
1281 1325
 
1282 1326
 		// Unhtml then rehtml the whole thing!
1283 1327
 		$new_string = $smcFunc['htmlspecialchars'](un_htmlspecialchars($new_string));
1284
-	}
1285
-	else
1328
+	} else
1286 1329
 	{
1287 1330
 		// Keep track of what we're doing...
1288 1331
 		$in_string = 0;
@@ -1311,10 +1354,11 @@  discard block
 block discarded – undo
1311 1354
 				preg_match('~\{%([\$A-Za-z0-9\'\[\]_-]+)%\}~', substr($string, $i), $matches);
1312 1355
 				if (!empty($matches[1]))
1313 1356
 				{
1314
-					if ($in_string == 1)
1315
-						$new_string .= '\' . ';
1316
-					elseif ($new_string)
1317
-						$new_string .= ' . ';
1357
+					if ($in_string == 1) {
1358
+											$new_string .= '\' . ';
1359
+					} elseif ($new_string) {
1360
+											$new_string .= ' . ';
1361
+					}
1318 1362
 
1319 1363
 					$new_string .= $matches[1];
1320 1364
 					$i += strlen($matches[1]) + 3;
@@ -1327,8 +1371,9 @@  discard block
 block discarded – undo
1327 1371
 			elseif ($string{$i} == '<')
1328 1372
 			{
1329 1373
 				// Probably HTML?
1330
-				if ($string{$i + 1} != ' ')
1331
-					$in_html = true;
1374
+				if ($string{$i + 1} != ' ') {
1375
+									$in_html = true;
1376
+				}
1332 1377
 				// Assume we need an entity...
1333 1378
 				else
1334 1379
 				{
@@ -1340,8 +1385,9 @@  discard block
 block discarded – undo
1340 1385
 			elseif ($string{$i} == '>')
1341 1386
 			{
1342 1387
 				// Will it be HTML?
1343
-				if ($in_html)
1344
-					$in_html = false;
1388
+				if ($in_html) {
1389
+									$in_html = false;
1390
+				}
1345 1391
 				// Otherwise we need an entity...
1346 1392
 				else
1347 1393
 				{
@@ -1350,8 +1396,9 @@  discard block
 block discarded – undo
1350 1396
 				}
1351 1397
 			}
1352 1398
 			// Is it a slash? If so escape it...
1353
-			if ($string{$i} == '\\')
1354
-				$new_string .= '\\';
1399
+			if ($string{$i} == '\\') {
1400
+							$new_string .= '\\';
1401
+			}
1355 1402
 			// The infamous double quote?
1356 1403
 			elseif ($string{$i} == '"')
1357 1404
 			{
@@ -1374,10 +1421,11 @@  discard block
 block discarded – undo
1374 1421
 		}
1375 1422
 
1376 1423
 		// If we ended as a string then close it off.
1377
-		if ($in_string == 1)
1378
-			$new_string .= '\'';
1379
-		elseif ($in_string == 2)
1380
-			$new_string .= '"';
1424
+		if ($in_string == 1) {
1425
+					$new_string .= '\'';
1426
+		} elseif ($in_string == 2) {
1427
+					$new_string .= '"';
1428
+		}
1381 1429
 	}
1382 1430
 
1383 1431
 	return $new_string;
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1277 added lines, -949 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($type == 'int' && ($val === '+' || $val === '-'))
@@ -390,8 +399,9 @@  discard block
 block discarded – undo
390 399
 		{
391 400
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
392 401
 			{
393
-				if ($match[1] != '+ ')
394
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
402
+				if ($match[1] != '+ ') {
403
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
404
+				}
395 405
 				$type = 'raw';
396 406
 			}
397 407
 		}
@@ -412,8 +422,9 @@  discard block
 block discarded – undo
412 422
 	// Clear any caching?
413 423
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
414 424
 	{
415
-		if (!is_array($members))
416
-			$members = array($members);
425
+		if (!is_array($members)) {
426
+					$members = array($members);
427
+		}
417 428
 
418 429
 		foreach ($members as $member)
419 430
 		{
@@ -446,29 +457,32 @@  discard block
 block discarded – undo
446 457
 {
447 458
 	global $modSettings, $smcFunc;
448 459
 
449
-	if (empty($changeArray) || !is_array($changeArray))
450
-		return;
460
+	if (empty($changeArray) || !is_array($changeArray)) {
461
+			return;
462
+	}
451 463
 
452 464
 	$toRemove = array();
453 465
 
454 466
 	// Go check if there is any setting to be removed.
455
-	foreach ($changeArray as $k => $v)
456
-		if ($v === null)
467
+	foreach ($changeArray as $k => $v) {
468
+			if ($v === null)
457 469
 		{
458 470
 			// Found some, remove them from the original array and add them to ours.
459 471
 			unset($changeArray[$k]);
472
+	}
460 473
 			$toRemove[] = $k;
461 474
 		}
462 475
 
463 476
 	// Proceed with the deletion.
464
-	if (!empty($toRemove))
465
-		$smcFunc['db_query']('', '
477
+	if (!empty($toRemove)) {
478
+			$smcFunc['db_query']('', '
466 479
 			DELETE FROM {db_prefix}settings
467 480
 			WHERE variable IN ({array_string:remove})',
468 481
 			array(
469 482
 				'remove' => $toRemove,
470 483
 			)
471 484
 		);
485
+	}
472 486
 
473 487
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
474 488
 	if ($update)
@@ -497,19 +511,22 @@  discard block
 block discarded – undo
497 511
 	foreach ($changeArray as $variable => $value)
498 512
 	{
499 513
 		// Don't bother if it's already like that ;).
500
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
501
-			continue;
514
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
515
+					continue;
516
+		}
502 517
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
503
-		elseif (!isset($modSettings[$variable]) && empty($value))
504
-			continue;
518
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
519
+					continue;
520
+		}
505 521
 
506 522
 		$replaceArray[] = array($variable, $value);
507 523
 
508 524
 		$modSettings[$variable] = $value;
509 525
 	}
510 526
 
511
-	if (empty($replaceArray))
512
-		return;
527
+	if (empty($replaceArray)) {
528
+			return;
529
+	}
513 530
 
514 531
 	$smcFunc['db_insert']('replace',
515 532
 		'{db_prefix}settings',
@@ -555,14 +572,17 @@  discard block
 block discarded – undo
555 572
 	$start_invalid = $start < 0;
556 573
 
557 574
 	// Make sure $start is a proper variable - not less than 0.
558
-	if ($start_invalid)
559
-		$start = 0;
575
+	if ($start_invalid) {
576
+			$start = 0;
577
+	}
560 578
 	// Not greater than the upper bound.
561
-	elseif ($start >= $max_value)
562
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
579
+	elseif ($start >= $max_value) {
580
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
581
+	}
563 582
 	// And it has to be a multiple of $num_per_page!
564
-	else
565
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
583
+	else {
584
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
585
+	}
566 586
 
567 587
 	$context['current_page'] = $start / $num_per_page;
568 588
 
@@ -592,77 +612,87 @@  discard block
 block discarded – undo
592 612
 
593 613
 		// Show all the pages.
594 614
 		$display_page = 1;
595
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
596
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
615
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
616
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
617
+		}
597 618
 
598 619
 		// Show the right arrow.
599 620
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
600
-		if ($start != $counter - $max_value && !$start_invalid)
601
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
602
-	}
603
-	else
621
+		if ($start != $counter - $max_value && !$start_invalid) {
622
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
623
+		}
624
+	} else
604 625
 	{
605 626
 		// If they didn't enter an odd value, pretend they did.
606 627
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
607 628
 
608 629
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
609
-		if (!empty($start) && $show_prevnext)
610
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
611
-		else
612
-			$pageindex .= '';
630
+		if (!empty($start) && $show_prevnext) {
631
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
632
+		} else {
633
+					$pageindex .= '';
634
+		}
613 635
 
614 636
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
615
-		if ($start > $num_per_page * $PageContiguous)
616
-			$pageindex .= sprintf($base_link, 0, '1');
637
+		if ($start > $num_per_page * $PageContiguous) {
638
+					$pageindex .= sprintf($base_link, 0, '1');
639
+		}
617 640
 
618 641
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
619
-		if ($start > $num_per_page * ($PageContiguous + 1))
620
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
642
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
643
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
621 644
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
622 645
 				'{FIRST_PAGE}' => $num_per_page,
623 646
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
624 647
 				'{PER_PAGE}' => $num_per_page,
625 648
 			));
649
+		}
626 650
 
627 651
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
628
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
629
-			if ($start >= $num_per_page * $nCont)
652
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
653
+					if ($start >= $num_per_page * $nCont)
630 654
 			{
631 655
 				$tmpStart = $start - $num_per_page * $nCont;
656
+		}
632 657
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
633 658
 			}
634 659
 
635 660
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
636
-		if (!$start_invalid)
637
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
638
-		else
639
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
661
+		if (!$start_invalid) {
662
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
663
+		} else {
664
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
665
+		}
640 666
 
641 667
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
642 668
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
643
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
644
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
669
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
670
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
645 671
 			{
646 672
 				$tmpStart = $start + $num_per_page * $nCont;
673
+		}
647 674
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
648 675
 			}
649 676
 
650 677
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
651
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
652
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
678
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
679
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
653 680
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
654 681
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
655 682
 				'{LAST_PAGE}' => $tmpMaxPages,
656 683
 				'{PER_PAGE}' => $num_per_page,
657 684
 			));
685
+		}
658 686
 
659 687
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
660
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
661
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
688
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
689
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
690
+		}
662 691
 
663 692
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
664
-		if ($start != $tmpMaxPages && $show_prevnext)
665
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
693
+		if ($start != $tmpMaxPages && $show_prevnext) {
694
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
695
+		}
666 696
 	}
667 697
 	$pageindex .= $settings['page_index']['extra_after'];
668 698
 
@@ -688,8 +718,9 @@  discard block
 block discarded – undo
688 718
 	if ($decimal_separator === null)
689 719
 	{
690 720
 		// Not set for whatever reason?
691
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
692
-			return $number;
721
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
722
+					return $number;
723
+		}
693 724
 
694 725
 		// Cache these each load...
695 726
 		$thousands_separator = $matches[1];
@@ -721,17 +752,20 @@  discard block
 block discarded – undo
721 752
 	static $non_twelve_hour;
722 753
 
723 754
 	// Offset the time.
724
-	if (!$offset_type)
725
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
755
+	if (!$offset_type) {
756
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
757
+	}
726 758
 	// Just the forum offset?
727
-	elseif ($offset_type == 'forum')
728
-		$time = $log_time + $modSettings['time_offset'] * 3600;
729
-	else
730
-		$time = $log_time;
759
+	elseif ($offset_type == 'forum') {
760
+			$time = $log_time + $modSettings['time_offset'] * 3600;
761
+	} else {
762
+			$time = $log_time;
763
+	}
731 764
 
732 765
 	// We can't have a negative date (on Windows, at least.)
733
-	if ($log_time < 0)
734
-		$log_time = 0;
766
+	if ($log_time < 0) {
767
+			$log_time = 0;
768
+	}
735 769
 
736 770
 	// Today and Yesterday?
737 771
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -748,46 +782,53 @@  discard block
 block discarded – undo
748 782
 		{
749 783
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
750 784
 			$today_fmt = $h . ':%M' . $s . ' %p';
785
+		} else {
786
+					$today_fmt = '%H:%M' . $s;
751 787
 		}
752
-		else
753
-			$today_fmt = '%H:%M' . $s;
754 788
 
755 789
 		// Same day of the year, same year.... Today!
756
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
757
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
790
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
791
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
792
+		}
758 793
 
759 794
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
760
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
761
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
795
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
796
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
797
+		}
762 798
 	}
763 799
 
764 800
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
765 801
 
766 802
 	if (setlocale(LC_TIME, $txt['lang_locale']))
767 803
 	{
768
-		if (!isset($non_twelve_hour))
769
-			$non_twelve_hour = trim(strftime('%p')) === '';
770
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
771
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
804
+		if (!isset($non_twelve_hour)) {
805
+					$non_twelve_hour = trim(strftime('%p')) === '';
806
+		}
807
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
808
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
809
+		}
772 810
 
773
-		foreach (array('%a', '%A', '%b', '%B') as $token)
774
-			if (strpos($str, $token) !== false)
811
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
812
+					if (strpos($str, $token) !== false)
775 813
 				$str = str_replace($token, strftime($token, $time), $str);
776
-	}
777
-	else
814
+		}
815
+	} else
778 816
 	{
779 817
 		// Do-it-yourself time localization.  Fun.
780
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
781
-			if (strpos($str, $token) !== false)
818
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
819
+					if (strpos($str, $token) !== false)
782 820
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
821
+		}
783 822
 
784
-		if (strpos($str, '%p') !== false)
785
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
823
+		if (strpos($str, '%p') !== false) {
824
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
825
+		}
786 826
 	}
787 827
 
788 828
 	// Windows doesn't support %e; on some versions, strftime fails altogether if used, so let's prevent that.
789
-	if ($context['server']['is_windows'] && strpos($str, '%e') !== false)
790
-		$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
829
+	if ($context['server']['is_windows'] && strpos($str, '%e') !== false) {
830
+			$str = str_replace('%e', ltrim(strftime('%d', $time), '0'), $str);
831
+	}
791 832
 
792 833
 	// Format any other characters..
793 834
 	return strftime($str, $time);
@@ -809,16 +850,19 @@  discard block
 block discarded – undo
809 850
 	static $translation = array();
810 851
 
811 852
 	// Determine the character set... Default to UTF-8
812
-	if (empty($context['character_set']))
813
-		$charset = 'UTF-8';
853
+	if (empty($context['character_set'])) {
854
+			$charset = 'UTF-8';
855
+	}
814 856
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
815
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
816
-		$charset = 'ISO-8859-1';
817
-	else
818
-		$charset = $context['character_set'];
857
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
858
+			$charset = 'ISO-8859-1';
859
+	} else {
860
+			$charset = $context['character_set'];
861
+	}
819 862
 
820
-	if (empty($translation))
821
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
863
+	if (empty($translation)) {
864
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
865
+	}
822 866
 
823 867
 	return strtr($string, $translation);
824 868
 }
@@ -840,8 +884,9 @@  discard block
 block discarded – undo
840 884
 	global $smcFunc;
841 885
 
842 886
 	// It was already short enough!
843
-	if ($smcFunc['strlen']($subject) <= $len)
844
-		return $subject;
887
+	if ($smcFunc['strlen']($subject) <= $len) {
888
+			return $subject;
889
+	}
845 890
 
846 891
 	// Shorten it by the length it was too long, and strip off junk from the end.
847 892
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -860,10 +905,11 @@  discard block
 block discarded – undo
860 905
 {
861 906
 	global $user_info, $modSettings;
862 907
 
863
-	if ($timestamp === null)
864
-		$timestamp = time();
865
-	elseif ($timestamp == 0)
866
-		return 0;
908
+	if ($timestamp === null) {
909
+			$timestamp = time();
910
+	} elseif ($timestamp == 0) {
911
+			return 0;
912
+	}
867 913
 
868 914
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
869 915
 }
@@ -892,8 +938,9 @@  discard block
 block discarded – undo
892 938
 		$array[$i] = $array[$j];
893 939
 		$array[$j] = $temp;
894 940
 
895
-		for ($i = 1; $p[$i] == 0; $i++)
896
-			$p[$i] = 1;
941
+		for ($i = 1; $p[$i] == 0; $i++) {
942
+					$p[$i] = 1;
943
+		}
897 944
 
898 945
 		$orders[] = $array;
899 946
 	}
@@ -925,12 +972,14 @@  discard block
 block discarded – undo
925 972
 	static $disabled;
926 973
 
927 974
 	// Don't waste cycles
928
-	if ($message === '')
929
-		return '';
975
+	if ($message === '') {
976
+			return '';
977
+	}
930 978
 
931 979
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
932
-	if (!isset($context['utf8']))
933
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
980
+	if (!isset($context['utf8'])) {
981
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
982
+	}
934 983
 
935 984
 	// Clean up any cut/paste issues we may have
936 985
 	$message = sanitizeMSCutPaste($message);
@@ -942,13 +991,15 @@  discard block
 block discarded – undo
942 991
 		return $message;
943 992
 	}
944 993
 
945
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
946
-		$smileys = (bool) $smileys;
994
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
995
+			$smileys = (bool) $smileys;
996
+	}
947 997
 
948 998
 	if (empty($modSettings['enableBBC']) && $message !== false)
949 999
 	{
950
-		if ($smileys === true)
951
-			parsesmileys($message);
1000
+		if ($smileys === true) {
1001
+					parsesmileys($message);
1002
+		}
952 1003
 
953 1004
 		return $message;
954 1005
 	}
@@ -961,8 +1012,9 @@  discard block
 block discarded – undo
961 1012
 	}
962 1013
 
963 1014
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
964
-	if (!empty($modSettings['autoLinkUrls']))
965
-		set_tld_regex();
1015
+	if (!empty($modSettings['autoLinkUrls'])) {
1016
+			set_tld_regex();
1017
+	}
966 1018
 
967 1019
 	// Allow mods access before entering the main parse_bbc loop
968 1020
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -976,12 +1028,14 @@  discard block
 block discarded – undo
976 1028
 
977 1029
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
978 1030
 
979
-			foreach ($temp as $tag)
980
-				$disabled[trim($tag)] = true;
1031
+			foreach ($temp as $tag) {
1032
+							$disabled[trim($tag)] = true;
1033
+			}
981 1034
 		}
982 1035
 
983
-		if (empty($modSettings['enableEmbeddedFlash']))
984
-			$disabled['flash'] = true;
1036
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1037
+					$disabled['flash'] = true;
1038
+		}
985 1039
 
986 1040
 		/* The following bbc are formatted as an array, with keys as follows:
987 1041
 
@@ -1102,8 +1156,9 @@  discard block
 block discarded – undo
1102 1156
 					$returnContext = '';
1103 1157
 
1104 1158
 					// BBC or the entire attachments feature is disabled
1105
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1106
-						return $data;
1159
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1160
+											return $data;
1161
+					}
1107 1162
 
1108 1163
 					// Save the attach ID.
1109 1164
 					$attachID = $data;
@@ -1114,8 +1169,9 @@  discard block
 block discarded – undo
1114 1169
 					$currentAttachment = parseAttachBBC($attachID);
1115 1170
 
1116 1171
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1117
-					if (is_string($currentAttachment))
1118
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1172
+					if (is_string($currentAttachment)) {
1173
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1174
+					}
1119 1175
 
1120 1176
 					if (!empty($currentAttachment['is_image']))
1121 1177
 					{
@@ -1131,15 +1187,17 @@  discard block
 block discarded – undo
1131 1187
 							$height = ' height="' . $currentAttachment['height'] . '"';
1132 1188
 						}
1133 1189
 
1134
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1135
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>';
1136
-						else
1137
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>';
1190
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1191
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '"></a>';
1192
+						} else {
1193
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . '/>';
1194
+						}
1138 1195
 					}
1139 1196
 
1140 1197
 					// No image. Show a link.
1141
-					else
1142
-						$returnContext .= $currentAttachment['link'];
1198
+					else {
1199
+											$returnContext .= $currentAttachment['link'];
1200
+					}
1143 1201
 
1144 1202
 					// Gotta append what we just did.
1145 1203
 					$data = $returnContext;
@@ -1170,8 +1228,9 @@  discard block
 block discarded – undo
1170 1228
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1171 1229
 						{
1172 1230
 							// Do PHP code coloring?
1173
-							if ($php_parts[$php_i] != '&lt;?php')
1174
-								continue;
1231
+							if ($php_parts[$php_i] != '&lt;?php') {
1232
+															continue;
1233
+							}
1175 1234
 
1176 1235
 							$php_string = '';
1177 1236
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1188 1247
 
1189 1248
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1190
-						if ($context['browser']['is_opera'])
1191
-							$data .= '&nbsp;';
1249
+						if ($context['browser']['is_opera']) {
1250
+													$data .= '&nbsp;';
1251
+						}
1192 1252
 					}
1193 1253
 				},
1194 1254
 				'block_level' => true,
@@ -1207,8 +1267,9 @@  discard block
 block discarded – undo
1207 1267
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1208 1268
 						{
1209 1269
 							// Do PHP code coloring?
1210
-							if ($php_parts[$php_i] != '&lt;?php')
1211
-								continue;
1270
+							if ($php_parts[$php_i] != '&lt;?php') {
1271
+															continue;
1272
+							}
1212 1273
 
1213 1274
 							$php_string = '';
1214 1275
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1224,8 +1285,9 @@  discard block
 block discarded – undo
1224 1285
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1225 1286
 
1226 1287
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1227
-						if ($context['browser']['is_opera'])
1228
-							$data[0] .= '&nbsp;';
1288
+						if ($context['browser']['is_opera']) {
1289
+													$data[0] .= '&nbsp;';
1290
+						}
1229 1291
 					}
1230 1292
 				},
1231 1293
 				'block_level' => true,
@@ -1263,11 +1325,13 @@  discard block
 block discarded – undo
1263 1325
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1264 1326
 				'validate' => function (&$tag, &$data, $disabled)
1265 1327
 				{
1266
-					if (isset($disabled['url']))
1267
-						$tag['content'] = '$1';
1328
+					if (isset($disabled['url'])) {
1329
+											$tag['content'] = '$1';
1330
+					}
1268 1331
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1269
-					if (empty($scheme))
1270
-						$data[0] = '//' . ltrim($data[0], ':/');
1332
+					if (empty($scheme)) {
1333
+											$data[0] = '//' . ltrim($data[0], ':/');
1334
+					}
1271 1335
 				},
1272 1336
 				'disabled_content' => '<a href="$1" target="_blank" class="new_win">$1</a>',
1273 1337
 			),
@@ -1314,14 +1378,16 @@  discard block
 block discarded – undo
1314 1378
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1315 1379
 					if ($image_proxy_enabled)
1316 1380
 					{
1317
-						if (empty($scheme))
1318
-							$data = 'http://' . ltrim($data, ':/');
1381
+						if (empty($scheme)) {
1382
+													$data = 'http://' . ltrim($data, ':/');
1383
+						}
1319 1384
 
1320
-						if ($scheme != 'https')
1321
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1385
+						if ($scheme != 'https') {
1386
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1387
+						}
1388
+					} elseif (empty($scheme)) {
1389
+											$data = '//' . ltrim($data, ':/');
1322 1390
 					}
1323
-					elseif (empty($scheme))
1324
-						$data = '//' . ltrim($data, ':/');
1325 1391
 				},
1326 1392
 				'disabled_content' => '($1)',
1327 1393
 			),
@@ -1337,14 +1403,16 @@  discard block
 block discarded – undo
1337 1403
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1338 1404
 					if ($image_proxy_enabled)
1339 1405
 					{
1340
-						if (empty($scheme))
1341
-							$data = 'http://' . ltrim($data, ':/');
1406
+						if (empty($scheme)) {
1407
+													$data = 'http://' . ltrim($data, ':/');
1408
+						}
1342 1409
 
1343
-						if ($scheme != 'https')
1344
-							$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1410
+						if ($scheme != 'https') {
1411
+													$data = $boardurl . '/proxy.php?request=' . urlencode($data) . '&hash=' . md5($data . $image_proxy_secret);
1412
+						}
1413
+					} elseif (empty($scheme)) {
1414
+											$data = '//' . ltrim($data, ':/');
1345 1415
 					}
1346
-					elseif (empty($scheme))
1347
-						$data = '//' . ltrim($data, ':/');
1348 1416
 				},
1349 1417
 				'disabled_content' => '($1)',
1350 1418
 			),
@@ -1356,8 +1424,9 @@  discard block
 block discarded – undo
1356 1424
 				{
1357 1425
 					$data = strtr($data, array('<br>' => ''));
1358 1426
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1359
-					if (empty($scheme))
1360
-						$data = '//' . ltrim($data, ':/');
1427
+					if (empty($scheme)) {
1428
+											$data = '//' . ltrim($data, ':/');
1429
+					}
1361 1430
 				},
1362 1431
 			),
1363 1432
 			array(
@@ -1368,13 +1437,14 @@  discard block
 block discarded – undo
1368 1437
 				'after' => '</a>',
1369 1438
 				'validate' => function (&$tag, &$data, $disabled)
1370 1439
 				{
1371
-					if (substr($data, 0, 1) == '#')
1372
-						$data = '#post_' . substr($data, 1);
1373
-					else
1440
+					if (substr($data, 0, 1) == '#') {
1441
+											$data = '#post_' . substr($data, 1);
1442
+					} else
1374 1443
 					{
1375 1444
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1376
-						if (empty($scheme))
1377
-							$data = '//' . ltrim($data, ':/');
1445
+						if (empty($scheme)) {
1446
+													$data = '//' . ltrim($data, ':/');
1447
+						}
1378 1448
 					}
1379 1449
 				},
1380 1450
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1452,8 +1522,9 @@  discard block
 block discarded – undo
1452 1522
 					{
1453 1523
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1454 1524
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1455
-						if ($add_begin)
1456
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1525
+						if ($add_begin) {
1526
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1527
+						}
1457 1528
 					}
1458 1529
 				},
1459 1530
 				'block_level' => false,
@@ -1584,10 +1655,11 @@  discard block
 block discarded – undo
1584 1655
 				'content' => '$1',
1585 1656
 				'validate' => function (&$tag, &$data, $disabled)
1586 1657
 				{
1587
-					if (is_numeric($data))
1588
-						$data = timeformat($data);
1589
-					else
1590
-						$tag['content'] = '[time]$1[/time]';
1658
+					if (is_numeric($data)) {
1659
+											$data = timeformat($data);
1660
+					} else {
1661
+											$tag['content'] = '[time]$1[/time]';
1662
+					}
1591 1663
 				},
1592 1664
 			),
1593 1665
 			array(
@@ -1614,8 +1686,9 @@  discard block
 block discarded – undo
1614 1686
 				{
1615 1687
 					$data = strtr($data, array('<br>' => ''));
1616 1688
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1617
-					if (empty($scheme))
1618
-						$data = '//' . ltrim($data, ':/');
1689
+					if (empty($scheme)) {
1690
+											$data = '//' . ltrim($data, ':/');
1691
+					}
1619 1692
 				},
1620 1693
 			),
1621 1694
 			array(
@@ -1627,8 +1700,9 @@  discard block
 block discarded – undo
1627 1700
 				'validate' => function (&$tag, &$data, $disabled)
1628 1701
 				{
1629 1702
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1630
-					if (empty($scheme))
1631
-						$data = '//' . ltrim($data, ':/');
1703
+					if (empty($scheme)) {
1704
+											$data = '//' . ltrim($data, ':/');
1705
+					}
1632 1706
 				},
1633 1707
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1634 1708
 				'disabled_after' => ' ($1)',
@@ -1648,8 +1722,9 @@  discard block
 block discarded – undo
1648 1722
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1649 1723
 		if ($message === false)
1650 1724
 		{
1651
-			if (isset($temp_bbc))
1652
-				$bbc_codes = $temp_bbc;
1725
+			if (isset($temp_bbc)) {
1726
+							$bbc_codes = $temp_bbc;
1727
+			}
1653 1728
 			usort($codes, function ($a, $b) {
1654 1729
 				return strcmp($a['tag'], $b['tag']);
1655 1730
 			});
@@ -1669,8 +1744,9 @@  discard block
 block discarded – undo
1669 1744
 		);
1670 1745
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1671 1746
 		{
1672
-			foreach ($itemcodes as $c => $dummy)
1673
-				$bbc_codes[$c] = array();
1747
+			foreach ($itemcodes as $c => $dummy) {
1748
+							$bbc_codes[$c] = array();
1749
+			}
1674 1750
 		}
1675 1751
 
1676 1752
 		// Shhhh!
@@ -1691,12 +1767,14 @@  discard block
 block discarded – undo
1691 1767
 		foreach ($codes as $code)
1692 1768
 		{
1693 1769
 			// Make it easier to process parameters later
1694
-			if (!empty($code['parameters']))
1695
-				ksort($code['parameters'], SORT_STRING);
1770
+			if (!empty($code['parameters'])) {
1771
+							ksort($code['parameters'], SORT_STRING);
1772
+			}
1696 1773
 
1697 1774
 			// If we are not doing every tag only do ones we are interested in.
1698
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1699
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1775
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1776
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1777
+			}
1700 1778
 		}
1701 1779
 		$codes = null;
1702 1780
 	}
@@ -1707,8 +1785,9 @@  discard block
 block discarded – undo
1707 1785
 		// It's likely this will change if the message is modified.
1708 1786
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . json_encode($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1709 1787
 
1710
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1711
-			return $temp;
1788
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1789
+					return $temp;
1790
+		}
1712 1791
 
1713 1792
 		$cache_t = microtime();
1714 1793
 	}
@@ -1740,8 +1819,9 @@  discard block
 block discarded – undo
1740 1819
 		$disabled['flash'] = true;
1741 1820
 
1742 1821
 		// @todo Change maybe?
1743
-		if (!isset($_GET['images']))
1744
-			$disabled['img'] = true;
1822
+		if (!isset($_GET['images'])) {
1823
+					$disabled['img'] = true;
1824
+		}
1745 1825
 
1746 1826
 		// @todo Interface/setting to add more?
1747 1827
 	}
@@ -1767,8 +1847,9 @@  discard block
 block discarded – undo
1767 1847
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1768 1848
 
1769 1849
 		// Failsafe.
1770
-		if ($pos === false || $last_pos > $pos)
1771
-			$pos = strlen($message) + 1;
1850
+		if ($pos === false || $last_pos > $pos) {
1851
+					$pos = strlen($message) + 1;
1852
+		}
1772 1853
 
1773 1854
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1774 1855
 		if ($last_pos < $pos - 1)
@@ -1787,8 +1868,9 @@  discard block
 block discarded – undo
1787 1868
 
1788 1869
 				// <br> should be empty.
1789 1870
 				$empty_tags = array('br', 'hr');
1790
-				foreach ($empty_tags as $tag)
1791
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1871
+				foreach ($empty_tags as $tag) {
1872
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '[' . $tag . ' /]', $data);
1873
+				}
1792 1874
 
1793 1875
 				// b, u, i, s, pre... basic tags.
1794 1876
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote');
@@ -1797,8 +1879,9 @@  discard block
 block discarded – undo
1797 1879
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1798 1880
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1799 1881
 
1800
-					if ($diff > 0)
1801
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1882
+					if ($diff > 0) {
1883
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
1884
+					}
1802 1885
 				}
1803 1886
 
1804 1887
 				// Do <img ...> - with security... action= -> action-.
@@ -1811,8 +1894,9 @@  discard block
 block discarded – undo
1811 1894
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1812 1895
 
1813 1896
 						// Remove action= from the URL - no funny business, now.
1814
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1815
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1897
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
1898
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
1899
+						}
1816 1900
 
1817 1901
 						// Check if the image is larger than allowed.
1818 1902
 						if (!empty($modSettings['max_image_width']) && !empty($modSettings['max_image_height']))
@@ -1833,9 +1917,9 @@  discard block
 block discarded – undo
1833 1917
 
1834 1918
 							// Set the new image tag.
1835 1919
 							$replaces[$matches[0][$match]] = '[img width=' . $width . ' height=' . $height . $alt . ']' . $imgtag . '[/img]';
1920
+						} else {
1921
+													$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1836 1922
 						}
1837
-						else
1838
-							$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1839 1923
 					}
1840 1924
 
1841 1925
 					$data = strtr($data, $replaces);
@@ -1848,16 +1932,18 @@  discard block
 block discarded – undo
1848 1932
 				$no_autolink_area = false;
1849 1933
 				if (!empty($open_tags))
1850 1934
 				{
1851
-					foreach ($open_tags as $open_tag)
1852
-						if (in_array($open_tag['tag'], $no_autolink_tags))
1935
+					foreach ($open_tags as $open_tag) {
1936
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1853 1937
 							$no_autolink_area = true;
1938
+					}
1854 1939
 				}
1855 1940
 
1856 1941
 				// Don't go backwards.
1857 1942
 				// @todo Don't think is the real solution....
1858 1943
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1859
-				if ($pos < $lastAutoPos)
1860
-					$no_autolink_area = true;
1944
+				if ($pos < $lastAutoPos) {
1945
+									$no_autolink_area = true;
1946
+				}
1861 1947
 				$lastAutoPos = $pos;
1862 1948
 
1863 1949
 				if (!$no_autolink_area)
@@ -1966,17 +2052,19 @@  discard block
 block discarded – undo
1966 2052
 							if ($scheme == 'mailto')
1967 2053
 							{
1968 2054
 								$email_address = str_replace('mailto:', '', $url);
1969
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
1970
-									return '[email=' . $email_address . ']' . $url . '[/email]';
1971
-								else
1972
-									return $url;
2055
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2056
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2057
+								} else {
2058
+																	return $url;
2059
+								}
1973 2060
 							}
1974 2061
 
1975 2062
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
1976
-							if (empty($scheme))
1977
-								$fullUrl = '//' . ltrim($url, ':/');
1978
-							else
1979
-								$fullUrl = $url;
2063
+							if (empty($scheme)) {
2064
+															$fullUrl = '//' . ltrim($url, ':/');
2065
+							} else {
2066
+															$fullUrl = $url;
2067
+							}
1980 2068
 
1981 2069
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
1982 2070
 						}, $data);
@@ -2025,16 +2113,18 @@  discard block
 block discarded – undo
2025 2113
 		}
2026 2114
 
2027 2115
 		// Are we there yet?  Are we there yet?
2028
-		if ($pos >= strlen($message) - 1)
2029
-			break;
2116
+		if ($pos >= strlen($message) - 1) {
2117
+					break;
2118
+		}
2030 2119
 
2031 2120
 		$tags = strtolower($message[$pos + 1]);
2032 2121
 
2033 2122
 		if ($tags == '/' && !empty($open_tags))
2034 2123
 		{
2035 2124
 			$pos2 = strpos($message, ']', $pos + 1);
2036
-			if ($pos2 == $pos + 2)
2037
-				continue;
2125
+			if ($pos2 == $pos + 2) {
2126
+							continue;
2127
+			}
2038 2128
 
2039 2129
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2040 2130
 
@@ -2044,8 +2134,9 @@  discard block
 block discarded – undo
2044 2134
 			do
2045 2135
 			{
2046 2136
 				$tag = array_pop($open_tags);
2047
-				if (!$tag)
2048
-					break;
2137
+				if (!$tag) {
2138
+									break;
2139
+				}
2049 2140
 
2050 2141
 				if (!empty($tag['block_level']))
2051 2142
 				{
@@ -2059,10 +2150,11 @@  discard block
 block discarded – undo
2059 2150
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2060 2151
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2061 2152
 					{
2062
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2063
-							if ($temp['tag'] == $look_for)
2153
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2154
+													if ($temp['tag'] == $look_for)
2064 2155
 							{
2065 2156
 								$block_level = !empty($temp['block_level']);
2157
+						}
2066 2158
 								break;
2067 2159
 							}
2068 2160
 					}
@@ -2084,15 +2176,15 @@  discard block
 block discarded – undo
2084 2176
 			{
2085 2177
 				$open_tags = $to_close;
2086 2178
 				continue;
2087
-			}
2088
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2179
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2089 2180
 			{
2090 2181
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2091 2182
 				{
2092
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2093
-						if ($temp['tag'] == $look_for)
2183
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2184
+											if ($temp['tag'] == $look_for)
2094 2185
 						{
2095 2186
 							$block_level = !empty($temp['block_level']);
2187
+					}
2096 2188
 							break;
2097 2189
 						}
2098 2190
 				}
@@ -2100,8 +2192,9 @@  discard block
 block discarded – undo
2100 2192
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2101 2193
 				if (!$block_level)
2102 2194
 				{
2103
-					foreach ($to_close as $tag)
2104
-						array_push($open_tags, $tag);
2195
+					foreach ($to_close as $tag) {
2196
+											array_push($open_tags, $tag);
2197
+					}
2105 2198
 					continue;
2106 2199
 				}
2107 2200
 			}
@@ -2113,10 +2206,12 @@  discard block
 block discarded – undo
2113 2206
 				$pos2 = $pos - 1;
2114 2207
 
2115 2208
 				// See the comment at the end of the big loop - just eating whitespace ;).
2116
-				if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>')
2117
-					$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2118
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0)
2119
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2209
+				if (!empty($tag['block_level']) && substr($message, $pos, 4) == '<br>') {
2210
+									$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2211
+				}
2212
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0) {
2213
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2214
+				}
2120 2215
 			}
2121 2216
 
2122 2217
 			if (!empty($to_close))
@@ -2129,8 +2224,9 @@  discard block
 block discarded – undo
2129 2224
 		}
2130 2225
 
2131 2226
 		// No tags for this character, so just keep going (fastest possible course.)
2132
-		if (!isset($bbc_codes[$tags]))
2133
-			continue;
2227
+		if (!isset($bbc_codes[$tags])) {
2228
+					continue;
2229
+		}
2134 2230
 
2135 2231
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2136 2232
 		$tag = null;
@@ -2139,44 +2235,52 @@  discard block
 block discarded – undo
2139 2235
 			$pt_strlen = strlen($possible['tag']);
2140 2236
 
2141 2237
 			// Not a match?
2142
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2143
-				continue;
2238
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2239
+							continue;
2240
+			}
2144 2241
 
2145 2242
 			$next_c = $message[$pos + 1 + $pt_strlen];
2146 2243
 
2147 2244
 			// A test validation?
2148
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2149
-				continue;
2245
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2246
+							continue;
2247
+			}
2150 2248
 			// Do we want parameters?
2151 2249
 			elseif (!empty($possible['parameters']))
2152 2250
 			{
2153
-				if ($next_c != ' ')
2154
-					continue;
2155
-			}
2156
-			elseif (isset($possible['type']))
2251
+				if ($next_c != ' ') {
2252
+									continue;
2253
+				}
2254
+			} elseif (isset($possible['type']))
2157 2255
 			{
2158 2256
 				// Do we need an equal sign?
2159
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2160
-					continue;
2257
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2258
+									continue;
2259
+				}
2161 2260
 				// Maybe we just want a /...
2162
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2163
-					continue;
2261
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2262
+									continue;
2263
+				}
2164 2264
 				// An immediate ]?
2165
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2166
-					continue;
2265
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2266
+									continue;
2267
+				}
2167 2268
 			}
2168 2269
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2169
-			elseif ($next_c != ']')
2170
-				continue;
2270
+			elseif ($next_c != ']') {
2271
+							continue;
2272
+			}
2171 2273
 
2172 2274
 			// Check allowed tree?
2173
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2174
-				continue;
2175
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2176
-				continue;
2275
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2276
+							continue;
2277
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2278
+							continue;
2279
+			}
2177 2280
 			// If this is in the list of disallowed child tags, don't parse it.
2178
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2179
-				continue;
2281
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2282
+							continue;
2283
+			}
2180 2284
 
2181 2285
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2182 2286
 
@@ -2188,8 +2292,9 @@  discard block
 block discarded – undo
2188 2292
 				foreach ($open_tags as $open_quote)
2189 2293
 				{
2190 2294
 					// Every parent quote this quote has flips the styling
2191
-					if ($open_quote['tag'] == 'quote')
2192
-						$quote_alt = !$quote_alt;
2295
+					if ($open_quote['tag'] == 'quote') {
2296
+											$quote_alt = !$quote_alt;
2297
+					}
2193 2298
 				}
2194 2299
 				// Add a class to the quote to style alternating blockquotes
2195 2300
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2200,8 +2305,9 @@  discard block
 block discarded – undo
2200 2305
 			{
2201 2306
 				// Build a regular expression for each parameter for the current tag.
2202 2307
 				$preg = array();
2203
-				foreach ($possible['parameters'] as $p => $info)
2204
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2308
+				foreach ($possible['parameters'] as $p => $info) {
2309
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2310
+				}
2205 2311
 
2206 2312
 				// Extract the string that potentially holds our parameters.
2207 2313
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2221,24 +2327,27 @@  discard block
 block discarded – undo
2221 2327
 
2222 2328
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2223 2329
 
2224
-					if ($match)
2225
-						$blob_counter = count($blobs) + 1;
2330
+					if ($match) {
2331
+											$blob_counter = count($blobs) + 1;
2332
+					}
2226 2333
 				}
2227 2334
 
2228 2335
 				// Didn't match our parameter list, try the next possible.
2229
-				if (!$match)
2230
-					continue;
2336
+				if (!$match) {
2337
+									continue;
2338
+				}
2231 2339
 
2232 2340
 				$params = array();
2233 2341
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2234 2342
 				{
2235 2343
 					$key = strtok(ltrim($matches[$i]), '=');
2236
-					if (isset($possible['parameters'][$key]['value']))
2237
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2238
-					elseif (isset($possible['parameters'][$key]['validate']))
2239
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2240
-					else
2241
-						$params['{' . $key . '}'] = $matches[$i + 1];
2344
+					if (isset($possible['parameters'][$key]['value'])) {
2345
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2346
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2347
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2348
+					} else {
2349
+											$params['{' . $key . '}'] = $matches[$i + 1];
2350
+					}
2242 2351
 
2243 2352
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2244 2353
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2246,23 +2355,26 @@  discard block
 block discarded – undo
2246 2355
 
2247 2356
 				foreach ($possible['parameters'] as $p => $info)
2248 2357
 				{
2249
-					if (!isset($params['{' . $p . '}']))
2250
-						$params['{' . $p . '}'] = '';
2358
+					if (!isset($params['{' . $p . '}'])) {
2359
+											$params['{' . $p . '}'] = '';
2360
+					}
2251 2361
 				}
2252 2362
 
2253 2363
 				$tag = $possible;
2254 2364
 
2255 2365
 				// Put the parameters into the string.
2256
-				if (isset($tag['before']))
2257
-					$tag['before'] = strtr($tag['before'], $params);
2258
-				if (isset($tag['after']))
2259
-					$tag['after'] = strtr($tag['after'], $params);
2260
-				if (isset($tag['content']))
2261
-					$tag['content'] = strtr($tag['content'], $params);
2366
+				if (isset($tag['before'])) {
2367
+									$tag['before'] = strtr($tag['before'], $params);
2368
+				}
2369
+				if (isset($tag['after'])) {
2370
+									$tag['after'] = strtr($tag['after'], $params);
2371
+				}
2372
+				if (isset($tag['content'])) {
2373
+									$tag['content'] = strtr($tag['content'], $params);
2374
+				}
2262 2375
 
2263 2376
 				$pos1 += strlen($given_param_string);
2264
-			}
2265
-			else
2377
+			} else
2266 2378
 			{
2267 2379
 				$tag = $possible;
2268 2380
 				$params = array();
@@ -2273,8 +2385,9 @@  discard block
 block discarded – undo
2273 2385
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2274 2386
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2275 2387
 		{
2276
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2277
-				continue;
2388
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2389
+							continue;
2390
+			}
2278 2391
 
2279 2392
 			$tag = $itemcodes[$message[$pos + 1]];
2280 2393
 
@@ -2295,9 +2408,9 @@  discard block
 block discarded – undo
2295 2408
 			{
2296 2409
 				array_pop($open_tags);
2297 2410
 				$code = '</li>';
2411
+			} else {
2412
+							$code = '';
2298 2413
 			}
2299
-			else
2300
-				$code = '';
2301 2414
 
2302 2415
 			// Now we open a new tag.
2303 2416
 			$open_tags[] = array(
@@ -2344,12 +2457,14 @@  discard block
 block discarded – undo
2344 2457
 		}
2345 2458
 
2346 2459
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2347
-		if ($tag === null)
2348
-			continue;
2460
+		if ($tag === null) {
2461
+					continue;
2462
+		}
2349 2463
 
2350 2464
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2351
-		if (isset($inside['disallow_children']))
2352
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2465
+		if (isset($inside['disallow_children'])) {
2466
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2467
+		}
2353 2468
 
2354 2469
 		// Is this tag disabled?
2355 2470
 		if (isset($disabled[$tag['tag']]))
@@ -2359,14 +2474,13 @@  discard block
 block discarded – undo
2359 2474
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2360 2475
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2361 2476
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2362
-			}
2363
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2477
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2364 2478
 			{
2365 2479
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2366 2480
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2481
+			} else {
2482
+							$tag['content'] = $tag['disabled_content'];
2367 2483
 			}
2368
-			else
2369
-				$tag['content'] = $tag['disabled_content'];
2370 2484
 		}
2371 2485
 
2372 2486
 		// we use this a lot
@@ -2376,8 +2490,9 @@  discard block
 block discarded – undo
2376 2490
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2377 2491
 		{
2378 2492
 			$n = count($open_tags) - 1;
2379
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2380
-				$n--;
2493
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2494
+							$n--;
2495
+			}
2381 2496
 
2382 2497
 			// Close all the non block level tags so this tag isn't surrounded by them.
2383 2498
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2388,10 +2503,12 @@  discard block
 block discarded – undo
2388 2503
 				$pos1 += $ot_strlen + 2;
2389 2504
 
2390 2505
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2391
-				if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>')
2392
-					$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2393
-				if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0)
2394
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2506
+				if (!empty($open_tags[$i]['block_level']) && substr($message, $pos, 4) == '<br>') {
2507
+									$message = substr($message, 0, $pos) . substr($message, $pos + 4);
2508
+				}
2509
+				if (!empty($open_tags[$i]['trim']) && $tag['trim'] != 'inside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos), $matches) != 0) {
2510
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2511
+				}
2395 2512
 
2396 2513
 				array_pop($open_tags);
2397 2514
 			}
@@ -2409,16 +2526,19 @@  discard block
 block discarded – undo
2409 2526
 		elseif ($tag['type'] == 'unparsed_content')
2410 2527
 		{
2411 2528
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2412
-			if ($pos2 === false)
2413
-				continue;
2529
+			if ($pos2 === false) {
2530
+							continue;
2531
+			}
2414 2532
 
2415 2533
 			$data = substr($message, $pos1, $pos2 - $pos1);
2416 2534
 
2417
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2418
-				$data = substr($data, 4);
2535
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2536
+							$data = substr($data, 4);
2537
+			}
2419 2538
 
2420
-			if (isset($tag['validate']))
2421
-				$tag['validate']($tag, $data, $disabled, $params);
2539
+			if (isset($tag['validate'])) {
2540
+							$tag['validate']($tag, $data, $disabled, $params);
2541
+			}
2422 2542
 
2423 2543
 			$code = strtr($tag['content'], array('$1' => $data));
2424 2544
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2434,34 +2554,40 @@  discard block
 block discarded – undo
2434 2554
 			if (isset($tag['quoted']))
2435 2555
 			{
2436 2556
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2437
-				if ($tag['quoted'] != 'optional' && !$quoted)
2438
-					continue;
2557
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2558
+									continue;
2559
+				}
2439 2560
 
2440
-				if ($quoted)
2441
-					$pos1 += 6;
2561
+				if ($quoted) {
2562
+									$pos1 += 6;
2563
+				}
2564
+			} else {
2565
+							$quoted = false;
2442 2566
 			}
2443
-			else
2444
-				$quoted = false;
2445 2567
 
2446 2568
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2447
-			if ($pos2 === false)
2448
-				continue;
2569
+			if ($pos2 === false) {
2570
+							continue;
2571
+			}
2449 2572
 
2450 2573
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2451
-			if ($pos3 === false)
2452
-				continue;
2574
+			if ($pos3 === false) {
2575
+							continue;
2576
+			}
2453 2577
 
2454 2578
 			$data = array(
2455 2579
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2456 2580
 				substr($message, $pos1, $pos2 - $pos1)
2457 2581
 			);
2458 2582
 
2459
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2460
-				$data[0] = substr($data[0], 4);
2583
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2584
+							$data[0] = substr($data[0], 4);
2585
+			}
2461 2586
 
2462 2587
 			// Validation for my parking, please!
2463
-			if (isset($tag['validate']))
2464
-				$tag['validate']($tag, $data, $disabled, $params);
2588
+			if (isset($tag['validate'])) {
2589
+							$tag['validate']($tag, $data, $disabled, $params);
2590
+			}
2465 2591
 
2466 2592
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2467 2593
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2478,23 +2604,27 @@  discard block
 block discarded – undo
2478 2604
 		elseif ($tag['type'] == 'unparsed_commas_content')
2479 2605
 		{
2480 2606
 			$pos2 = strpos($message, ']', $pos1);
2481
-			if ($pos2 === false)
2482
-				continue;
2607
+			if ($pos2 === false) {
2608
+							continue;
2609
+			}
2483 2610
 
2484 2611
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2485
-			if ($pos3 === false)
2486
-				continue;
2612
+			if ($pos3 === false) {
2613
+							continue;
2614
+			}
2487 2615
 
2488 2616
 			// We want $1 to be the content, and the rest to be csv.
2489 2617
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2490 2618
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2491 2619
 
2492
-			if (isset($tag['validate']))
2493
-				$tag['validate']($tag, $data, $disabled, $params);
2620
+			if (isset($tag['validate'])) {
2621
+							$tag['validate']($tag, $data, $disabled, $params);
2622
+			}
2494 2623
 
2495 2624
 			$code = $tag['content'];
2496
-			foreach ($data as $k => $d)
2497
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2625
+			foreach ($data as $k => $d) {
2626
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2627
+			}
2498 2628
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2499 2629
 			$pos += strlen($code) - 1 + 2;
2500 2630
 		}
@@ -2502,24 +2632,28 @@  discard block
 block discarded – undo
2502 2632
 		elseif ($tag['type'] == 'unparsed_commas')
2503 2633
 		{
2504 2634
 			$pos2 = strpos($message, ']', $pos1);
2505
-			if ($pos2 === false)
2506
-				continue;
2635
+			if ($pos2 === false) {
2636
+							continue;
2637
+			}
2507 2638
 
2508 2639
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2509 2640
 
2510
-			if (isset($tag['validate']))
2511
-				$tag['validate']($tag, $data, $disabled, $params);
2641
+			if (isset($tag['validate'])) {
2642
+							$tag['validate']($tag, $data, $disabled, $params);
2643
+			}
2512 2644
 
2513 2645
 			// Fix after, for disabled code mainly.
2514
-			foreach ($data as $k => $d)
2515
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2646
+			foreach ($data as $k => $d) {
2647
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2648
+			}
2516 2649
 
2517 2650
 			$open_tags[] = $tag;
2518 2651
 
2519 2652
 			// Replace them out, $1, $2, $3, $4, etc.
2520 2653
 			$code = $tag['before'];
2521
-			foreach ($data as $k => $d)
2522
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2654
+			foreach ($data as $k => $d) {
2655
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2656
+			}
2523 2657
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2524 2658
 			$pos += strlen($code) - 1 + 2;
2525 2659
 		}
@@ -2530,28 +2664,33 @@  discard block
 block discarded – undo
2530 2664
 			if (isset($tag['quoted']))
2531 2665
 			{
2532 2666
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2533
-				if ($tag['quoted'] != 'optional' && !$quoted)
2534
-					continue;
2667
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2668
+									continue;
2669
+				}
2535 2670
 
2536
-				if ($quoted)
2537
-					$pos1 += 6;
2671
+				if ($quoted) {
2672
+									$pos1 += 6;
2673
+				}
2674
+			} else {
2675
+							$quoted = false;
2538 2676
 			}
2539
-			else
2540
-				$quoted = false;
2541 2677
 
2542 2678
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2543
-			if ($pos2 === false)
2544
-				continue;
2679
+			if ($pos2 === false) {
2680
+							continue;
2681
+			}
2545 2682
 
2546 2683
 			$data = substr($message, $pos1, $pos2 - $pos1);
2547 2684
 
2548 2685
 			// Validation for my parking, please!
2549
-			if (isset($tag['validate']))
2550
-				$tag['validate']($tag, $data, $disabled, $params);
2686
+			if (isset($tag['validate'])) {
2687
+							$tag['validate']($tag, $data, $disabled, $params);
2688
+			}
2551 2689
 
2552 2690
 			// For parsed content, we must recurse to avoid security problems.
2553
-			if ($tag['type'] != 'unparsed_equals')
2554
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2691
+			if ($tag['type'] != 'unparsed_equals') {
2692
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2693
+			}
2555 2694
 
2556 2695
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2557 2696
 
@@ -2563,34 +2702,40 @@  discard block
 block discarded – undo
2563 2702
 		}
2564 2703
 
2565 2704
 		// If this is block level, eat any breaks after it.
2566
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2567
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2705
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2706
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2707
+		}
2568 2708
 
2569 2709
 		// Are we trimming outside this tag?
2570
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2571
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2710
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2711
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2712
+		}
2572 2713
 	}
2573 2714
 
2574 2715
 	// Close any remaining tags.
2575
-	while ($tag = array_pop($open_tags))
2576
-		$message .= "\n" . $tag['after'] . "\n";
2716
+	while ($tag = array_pop($open_tags)) {
2717
+			$message .= "\n" . $tag['after'] . "\n";
2718
+	}
2577 2719
 
2578 2720
 	// Parse the smileys within the parts where it can be done safely.
2579 2721
 	if ($smileys === true)
2580 2722
 	{
2581 2723
 		$message_parts = explode("\n", $message);
2582
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2583
-			parsesmileys($message_parts[$i]);
2724
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2725
+					parsesmileys($message_parts[$i]);
2726
+		}
2584 2727
 
2585 2728
 		$message = implode('', $message_parts);
2586 2729
 	}
2587 2730
 
2588 2731
 	// No smileys, just get rid of the markers.
2589
-	else
2590
-		$message = strtr($message, array("\n" => ''));
2732
+	else {
2733
+			$message = strtr($message, array("\n" => ''));
2734
+	}
2591 2735
 
2592
-	if ($message !== '' && $message[0] === ' ')
2593
-		$message = '&nbsp;' . substr($message, 1);
2736
+	if ($message !== '' && $message[0] === ' ') {
2737
+			$message = '&nbsp;' . substr($message, 1);
2738
+	}
2594 2739
 
2595 2740
 	// Cleanup whitespace.
2596 2741
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2599,15 +2744,16 @@  discard block
 block discarded – undo
2599 2744
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2600 2745
 
2601 2746
 	// Cache the output if it took some time...
2602
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2603
-		cache_put_data($cache_key, $message, 240);
2747
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2748
+			cache_put_data($cache_key, $message, 240);
2749
+	}
2604 2750
 
2605 2751
 	// If this was a force parse revert if needed.
2606 2752
 	if (!empty($parse_tags))
2607 2753
 	{
2608
-		if (empty($temp_bbc))
2609
-			$bbc_codes = array();
2610
-		else
2754
+		if (empty($temp_bbc)) {
2755
+					$bbc_codes = array();
2756
+		} else
2611 2757
 		{
2612 2758
 			$bbc_codes = $temp_bbc;
2613 2759
 			unset($temp_bbc);
@@ -2634,8 +2780,9 @@  discard block
 block discarded – undo
2634 2780
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2635 2781
 
2636 2782
 	// No smiley set at all?!
2637
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2638
-		return;
2783
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2784
+			return;
2785
+	}
2639 2786
 
2640 2787
 	// If smileyPregSearch hasn't been set, do it now.
2641 2788
 	if (empty($smileyPregSearch))
@@ -2646,8 +2793,7 @@  discard block
 block discarded – undo
2646 2793
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2647 2794
 			$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
2648 2795
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2649
-		}
2650
-		else
2796
+		} else
2651 2797
 		{
2652 2798
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2653 2799
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2671,9 +2817,9 @@  discard block
 block discarded – undo
2671 2817
 				$smcFunc['db_free_result']($result);
2672 2818
 
2673 2819
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2820
+			} else {
2821
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2674 2822
 			}
2675
-			else
2676
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2677 2823
 		}
2678 2824
 
2679 2825
 		// The non-breaking-space is a complex thing...
@@ -2750,35 +2896,41 @@  discard block
 block discarded – undo
2750 2896
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2751 2897
 
2752 2898
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2753
-	if (!empty($context['flush_mail']))
2754
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2899
+	if (!empty($context['flush_mail'])) {
2900
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2755 2901
 		AddMailQueue(true);
2902
+	}
2756 2903
 
2757 2904
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2758 2905
 
2759
-	if ($add)
2760
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2906
+	if ($add) {
2907
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
2908
+	}
2761 2909
 
2762 2910
 	// Put the session ID in.
2763
-	if (defined('SID') && SID != '')
2764
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2911
+	if (defined('SID') && SID != '') {
2912
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
2913
+	}
2765 2914
 	// Keep that debug in their for template debugging!
2766
-	elseif (isset($_GET['debug']))
2767
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2915
+	elseif (isset($_GET['debug'])) {
2916
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
2917
+	}
2768 2918
 
2769 2919
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2770 2920
 	{
2771
-		if (defined('SID') && SID != '')
2772
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2921
+		if (defined('SID') && SID != '') {
2922
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2773 2923
 				function ($m) use ($scripturl)
2774 2924
 				{
2775 2925
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
2926
+		}
2776 2927
 				}, $setLocation);
2777
-		else
2778
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2928
+		else {
2929
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2779 2930
 				function ($m) use ($scripturl)
2780 2931
 				{
2781 2932
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
2933
+		}
2782 2934
 				}, $setLocation);
2783 2935
 	}
2784 2936
 
@@ -2789,8 +2941,9 @@  discard block
 block discarded – undo
2789 2941
 	header('Location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2790 2942
 
2791 2943
 	// Debugging.
2792
-	if (isset($db_show_debug) && $db_show_debug === true)
2793
-		$_SESSION['debug_redirect'] = $db_cache;
2944
+	if (isset($db_show_debug) && $db_show_debug === true) {
2945
+			$_SESSION['debug_redirect'] = $db_cache;
2946
+	}
2794 2947
 
2795 2948
 	obExit(false);
2796 2949
 }
@@ -2809,51 +2962,60 @@  discard block
 block discarded – undo
2809 2962
 
2810 2963
 	// Attempt to prevent a recursive loop.
2811 2964
 	++$level;
2812
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2813
-		exit;
2814
-	if ($from_fatal_error)
2815
-		$has_fatal_error = true;
2965
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
2966
+			exit;
2967
+	}
2968
+	if ($from_fatal_error) {
2969
+			$has_fatal_error = true;
2970
+	}
2816 2971
 
2817 2972
 	// Clear out the stat cache.
2818 2973
 	trackStats();
2819 2974
 
2820 2975
 	// If we have mail to send, send it.
2821
-	if (!empty($context['flush_mail']))
2822
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2976
+	if (!empty($context['flush_mail'])) {
2977
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2823 2978
 		AddMailQueue(true);
2979
+	}
2824 2980
 
2825 2981
 	$do_header = $header === null ? !$header_done : $header;
2826
-	if ($do_footer === null)
2827
-		$do_footer = $do_header;
2982
+	if ($do_footer === null) {
2983
+			$do_footer = $do_header;
2984
+	}
2828 2985
 
2829 2986
 	// Has the template/header been done yet?
2830 2987
 	if ($do_header)
2831 2988
 	{
2832 2989
 		// Was the page title set last minute? Also update the HTML safe one.
2833
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2834
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
2990
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
2991
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
2992
+		}
2835 2993
 
2836 2994
 		// Start up the session URL fixer.
2837 2995
 		ob_start('ob_sessrewrite');
2838 2996
 
2839
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2840
-			$buffers = explode(',', $settings['output_buffers']);
2841
-		elseif (!empty($settings['output_buffers']))
2842
-			$buffers = $settings['output_buffers'];
2843
-		else
2844
-			$buffers = array();
2997
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
2998
+					$buffers = explode(',', $settings['output_buffers']);
2999
+		} elseif (!empty($settings['output_buffers'])) {
3000
+					$buffers = $settings['output_buffers'];
3001
+		} else {
3002
+					$buffers = array();
3003
+		}
2845 3004
 
2846
-		if (isset($modSettings['integrate_buffer']))
2847
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3005
+		if (isset($modSettings['integrate_buffer'])) {
3006
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3007
+		}
2848 3008
 
2849
-		if (!empty($buffers))
2850
-			foreach ($buffers as $function)
3009
+		if (!empty($buffers)) {
3010
+					foreach ($buffers as $function)
2851 3011
 			{
2852 3012
 				$call = call_helper($function, true);
3013
+		}
2853 3014
 
2854 3015
 				// Is it valid?
2855
-				if (!empty($call))
2856
-					ob_start($call);
3016
+				if (!empty($call)) {
3017
+									ob_start($call);
3018
+				}
2857 3019
 			}
2858 3020
 
2859 3021
 		// Display the screen in the logical order.
@@ -2865,8 +3027,9 @@  discard block
 block discarded – undo
2865 3027
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
2866 3028
 
2867 3029
 		// Anything special to put out?
2868
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
2869
-			echo $context['insert_after_template'];
3030
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3031
+					echo $context['insert_after_template'];
3032
+		}
2870 3033
 
2871 3034
 		// Just so we don't get caught in an endless loop of errors from the footer...
2872 3035
 		if (!$footer_done)
@@ -2875,14 +3038,16 @@  discard block
 block discarded – undo
2875 3038
 			template_footer();
2876 3039
 
2877 3040
 			// (since this is just debugging... it's okay that it's after </html>.)
2878
-			if (!isset($_REQUEST['xml']))
2879
-				displayDebug();
3041
+			if (!isset($_REQUEST['xml'])) {
3042
+							displayDebug();
3043
+			}
2880 3044
 		}
2881 3045
 	}
2882 3046
 
2883 3047
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
2884
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
2885
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3048
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3049
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3050
+	}
2886 3051
 
2887 3052
 	// For session check verification.... don't switch browsers...
2888 3053
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -2891,9 +3056,10 @@  discard block
 block discarded – undo
2891 3056
 	call_integration_hook('integrate_exit', array($do_footer));
2892 3057
 
2893 3058
 	// Don't exit if we're coming from index.php; that will pass through normally.
2894
-	if (!$from_index)
2895
-		exit;
2896
-}
3059
+	if (!$from_index) {
3060
+			exit;
3061
+	}
3062
+	}
2897 3063
 
2898 3064
 /**
2899 3065
  * Get the size of a specified image with better error handling.
@@ -2912,8 +3078,9 @@  discard block
 block discarded – undo
2912 3078
 	$url = str_replace(' ', '%20', $url);
2913 3079
 
2914 3080
 	// Can we pull this from the cache... please please?
2915
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
2916
-		return $temp;
3081
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3082
+			return $temp;
3083
+	}
2917 3084
 	$t = microtime();
2918 3085
 
2919 3086
 	// Get the host to pester...
@@ -2923,12 +3090,10 @@  discard block
 block discarded – undo
2923 3090
 	if ($url == '' || $url == 'http://' || $url == 'https://')
2924 3091
 	{
2925 3092
 		return false;
2926
-	}
2927
-	elseif (!isset($match[1]))
3093
+	} elseif (!isset($match[1]))
2928 3094
 	{
2929 3095
 		$size = @getimagesize($url);
2930
-	}
2931
-	else
3096
+	} else
2932 3097
 	{
2933 3098
 		// Try to connect to the server... give it half a second.
2934 3099
 		$temp = 0;
@@ -2967,12 +3132,14 @@  discard block
 block discarded – undo
2967 3132
 	}
2968 3133
 
2969 3134
 	// If we didn't get it, we failed.
2970
-	if (!isset($size))
2971
-		$size = false;
3135
+	if (!isset($size)) {
3136
+			$size = false;
3137
+	}
2972 3138
 
2973 3139
 	// If this took a long time, we may never have to do it again, but then again we might...
2974
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
2975
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3140
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3141
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3142
+	}
2976 3143
 
2977 3144
 	// Didn't work.
2978 3145
 	return $size;
@@ -2990,8 +3157,9 @@  discard block
 block discarded – undo
2990 3157
 
2991 3158
 	// Under SSI this function can be called more then once.  That can cause some problems.
2992 3159
 	//   So only run the function once unless we are forced to run it again.
2993
-	if ($loaded && !$forceload)
2994
-		return;
3160
+	if ($loaded && !$forceload) {
3161
+			return;
3162
+	}
2995 3163
 
2996 3164
 	$loaded = true;
2997 3165
 
@@ -3003,14 +3171,16 @@  discard block
 block discarded – undo
3003 3171
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3004 3172
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3005 3173
 	{
3006
-		if (trim($context['news_lines'][$i]) == '')
3007
-			continue;
3174
+		if (trim($context['news_lines'][$i]) == '') {
3175
+					continue;
3176
+		}
3008 3177
 
3009 3178
 		// Clean it up for presentation ;).
3010 3179
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3011 3180
 	}
3012
-	if (!empty($context['news_lines']))
3013
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3181
+	if (!empty($context['news_lines'])) {
3182
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3183
+	}
3014 3184
 
3015 3185
 	if (!$user_info['is_guest'])
3016 3186
 	{
@@ -3019,40 +3189,48 @@  discard block
 block discarded – undo
3019 3189
 		$context['user']['alerts'] = &$user_info['alerts'];
3020 3190
 
3021 3191
 		// Personal message popup...
3022
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3023
-			$context['user']['popup_messages'] = true;
3024
-		else
3025
-			$context['user']['popup_messages'] = false;
3192
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3193
+					$context['user']['popup_messages'] = true;
3194
+		} else {
3195
+					$context['user']['popup_messages'] = false;
3196
+		}
3026 3197
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3027 3198
 
3028
-		if (allowedTo('moderate_forum'))
3029
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3199
+		if (allowedTo('moderate_forum')) {
3200
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3201
+		}
3030 3202
 
3031 3203
 		$context['user']['avatar'] = array();
3032 3204
 
3033 3205
 		// Check for gravatar first since we might be forcing them...
3034 3206
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3035 3207
 		{
3036
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3037
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3038
-			else
3039
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3208
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3209
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3210
+			} else {
3211
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3212
+			}
3040 3213
 		}
3041 3214
 		// Uploaded?
3042
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3043
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3215
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3216
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3217
+		}
3044 3218
 		// Full URL?
3045
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3046
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3219
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3220
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3221
+		}
3047 3222
 		// Otherwise we assume it's server stored.
3048
-		elseif ($user_info['avatar']['url'] != '')
3049
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3223
+		elseif ($user_info['avatar']['url'] != '') {
3224
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3225
+		}
3050 3226
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3051
-		else
3052
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3227
+		else {
3228
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3229
+		}
3053 3230
 
3054
-		if (!empty($context['user']['avatar']))
3055
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3231
+		if (!empty($context['user']['avatar'])) {
3232
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3233
+		}
3056 3234
 
3057 3235
 		// Figure out how long they've been logged in.
3058 3236
 		$context['user']['total_time_logged_in'] = array(
@@ -3060,8 +3238,7 @@  discard block
 block discarded – undo
3060 3238
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3061 3239
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3062 3240
 		);
3063
-	}
3064
-	else
3241
+	} else
3065 3242
 	{
3066 3243
 		$context['user']['messages'] = 0;
3067 3244
 		$context['user']['unread_messages'] = 0;
@@ -3069,12 +3246,14 @@  discard block
 block discarded – undo
3069 3246
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3070 3247
 		$context['user']['popup_messages'] = false;
3071 3248
 
3072
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3073
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3249
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3250
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3251
+		}
3074 3252
 
3075 3253
 		// If we've upgraded recently, go easy on the passwords.
3076
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3077
-			$context['disable_login_hashing'] = true;
3254
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3255
+					$context['disable_login_hashing'] = true;
3256
+		}
3078 3257
 	}
3079 3258
 
3080 3259
 	// Setup the main menu items.
@@ -3087,8 +3266,8 @@  discard block
 block discarded – undo
3087 3266
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3088 3267
 
3089 3268
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3090
-	if ($context['show_pm_popup'])
3091
-		addInlineJavaScript('
3269
+	if ($context['show_pm_popup']) {
3270
+			addInlineJavaScript('
3092 3271
 		jQuery(document).ready(function($) {
3093 3272
 			new smc_Popup({
3094 3273
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3096,15 +3275,17 @@  discard block
 block discarded – undo
3096 3275
 				icon_class: \'generic_icons mail_new\'
3097 3276
 			});
3098 3277
 		});');
3278
+	}
3099 3279
 
3100 3280
 	// Add a generic "Are you sure?" confirmation message.
3101 3281
 	addInlineJavaScript('
3102 3282
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3103 3283
 
3104 3284
 	// Now add the capping code for avatars.
3105
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3106
-		addInlineCss('
3285
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3286
+			addInlineCss('
3107 3287
 img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3288
+	}
3108 3289
 
3109 3290
 	// This looks weird, but it's because BoardIndex.php references the variable.
3110 3291
 	$context['common_stats']['latest_member'] = array(
@@ -3121,11 +3302,13 @@  discard block
 block discarded – undo
3121 3302
 	);
3122 3303
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3123 3304
 
3124
-	if (empty($settings['theme_version']))
3125
-		addJavaScriptVar('smf_scripturl', $scripturl);
3305
+	if (empty($settings['theme_version'])) {
3306
+			addJavaScriptVar('smf_scripturl', $scripturl);
3307
+	}
3126 3308
 
3127
-	if (!isset($context['page_title']))
3128
-		$context['page_title'] = '';
3309
+	if (!isset($context['page_title'])) {
3310
+			$context['page_title'] = '';
3311
+	}
3129 3312
 
3130 3313
 	// Set some specific vars.
3131 3314
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3135,21 +3318,23 @@  discard block
 block discarded – undo
3135 3318
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3136 3319
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3137 3320
 
3138
-	if (!empty($context['meta_keywords']))
3139
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3321
+	if (!empty($context['meta_keywords'])) {
3322
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3323
+	}
3140 3324
 
3141
-	if (!empty($context['canonical_url']))
3142
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3325
+	if (!empty($context['canonical_url'])) {
3326
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3327
+	}
3143 3328
 
3144
-	if (!empty($settings['og_image']))
3145
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3329
+	if (!empty($settings['og_image'])) {
3330
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3331
+	}
3146 3332
 
3147 3333
 	if (!empty($context['meta_description']))
3148 3334
 	{
3149 3335
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3150 3336
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3151
-	}
3152
-	else
3337
+	} else
3153 3338
 	{
3154 3339
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3155 3340
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3175,8 +3360,9 @@  discard block
 block discarded – undo
3175 3360
 	$memory_needed = memoryReturnBytes($needed);
3176 3361
 
3177 3362
 	// should we account for how much is currently being used?
3178
-	if ($in_use)
3179
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3363
+	if ($in_use) {
3364
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3365
+	}
3180 3366
 
3181 3367
 	// if more is needed, request it
3182 3368
 	if ($memory_current < $memory_needed)
@@ -3199,8 +3385,9 @@  discard block
 block discarded – undo
3199 3385
  */
3200 3386
 function memoryReturnBytes($val)
3201 3387
 {
3202
-	if (is_integer($val))
3203
-		return $val;
3388
+	if (is_integer($val)) {
3389
+			return $val;
3390
+	}
3204 3391
 
3205 3392
 	// Separate the number from the designator
3206 3393
 	$val = trim($val);
@@ -3236,10 +3423,11 @@  discard block
 block discarded – undo
3236 3423
 		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3237 3424
 
3238 3425
 		// Are we debugging the template/html content?
3239
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3240
-			header('Content-Type: application/xhtml+xml');
3241
-		elseif (!isset($_REQUEST['xml']))
3242
-			header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3426
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3427
+					header('Content-Type: application/xhtml+xml');
3428
+		} elseif (!isset($_REQUEST['xml'])) {
3429
+					header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3430
+		}
3243 3431
 	}
3244 3432
 
3245 3433
 	header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3248,8 +3436,9 @@  discard block
 block discarded – undo
3248 3436
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3249 3437
 	{
3250 3438
 		$position = array_search('body', $context['template_layers']);
3251
-		if ($position === false)
3252
-			$position = array_search('main', $context['template_layers']);
3439
+		if ($position === false) {
3440
+					$position = array_search('main', $context['template_layers']);
3441
+		}
3253 3442
 
3254 3443
 		if ($position !== false)
3255 3444
 		{
@@ -3277,15 +3466,15 @@  discard block
 block discarded – undo
3277 3466
 
3278 3467
 			foreach ($securityFiles as $i => $securityFile)
3279 3468
 			{
3280
-				if (!file_exists($boarddir . '/' . $securityFile))
3281
-					unset($securityFiles[$i]);
3469
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3470
+									unset($securityFiles[$i]);
3471
+				}
3282 3472
 			}
3283 3473
 
3284 3474
 			// We are already checking so many files...just few more doesn't make any difference! :P
3285
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3286
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3287
-
3288
-			else
3475
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3476
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3477
+			} else
3289 3478
 			{
3290 3479
 				$path = $modSettings['attachmentUploadDir'];
3291 3480
 				$id_folder_thumb = 1;
@@ -3294,8 +3483,9 @@  discard block
 block discarded – undo
3294 3483
 			secureDirectory($cachedir);
3295 3484
 
3296 3485
 			// If agreement is enabled, at least the english version shall exists
3297
-			if ($modSettings['requireAgreement'])
3298
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3486
+			if ($modSettings['requireAgreement']) {
3487
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3488
+			}
3299 3489
 
3300 3490
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3301 3491
 			{
@@ -3310,18 +3500,21 @@  discard block
 block discarded – undo
3310 3500
 					echo '
3311 3501
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3312 3502
 
3313
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3314
-						echo '
3503
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3504
+											echo '
3315 3505
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3506
+					}
3316 3507
 				}
3317 3508
 
3318
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3319
-					echo '
3509
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3510
+									echo '
3320 3511
 				<strong>', $txt['cache_writable'], '</strong><br>';
3512
+				}
3321 3513
 
3322
-				if (!empty($agreement))
3323
-					echo '
3514
+				if (!empty($agreement)) {
3515
+									echo '
3324 3516
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3517
+				}
3325 3518
 
3326 3519
 				echo '
3327 3520
 			</p>
@@ -3336,16 +3529,18 @@  discard block
 block discarded – undo
3336 3529
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3337 3530
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3338 3531
 
3339
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3340
-				echo '
3532
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3533
+							echo '
3341 3534
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3535
+			}
3342 3536
 
3343
-			if (!empty($_SESSION['ban']['expire_time']))
3344
-				echo '
3537
+			if (!empty($_SESSION['ban']['expire_time'])) {
3538
+							echo '
3345 3539
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3346
-			else
3347
-				echo '
3540
+			} else {
3541
+							echo '
3348 3542
 					<div>', $txt['your_ban_expires_never'], '</div>';
3543
+			}
3349 3544
 
3350 3545
 			echo '
3351 3546
 				</div>';
@@ -3361,8 +3556,9 @@  discard block
 block discarded – undo
3361 3556
 	global $forum_copyright, $software_year, $forum_version;
3362 3557
 
3363 3558
 	// Don't display copyright for things like SSI.
3364
-	if (!isset($forum_version) || !isset($software_year))
3365
-		return;
3559
+	if (!isset($forum_version) || !isset($software_year)) {
3560
+			return;
3561
+	}
3366 3562
 
3367 3563
 	// Put in the version...
3368 3564
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3380,9 +3576,10 @@  discard block
 block discarded – undo
3380 3576
 	$context['load_time'] = comma_format(round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3));
3381 3577
 	$context['load_queries'] = $db_count;
3382 3578
 
3383
-	foreach (array_reverse($context['template_layers']) as $layer)
3384
-		loadSubTemplate($layer . '_below', true);
3385
-}
3579
+	foreach (array_reverse($context['template_layers']) as $layer) {
3580
+			loadSubTemplate($layer . '_below', true);
3581
+	}
3582
+	}
3386 3583
 
3387 3584
 /**
3388 3585
  * Output the Javascript files
@@ -3413,8 +3610,7 @@  discard block
 block discarded – undo
3413 3610
 			{
3414 3611
 				echo '
3415 3612
 		var ', $key, ';';
3416
-			}
3417
-			else
3613
+			} else
3418 3614
 			{
3419 3615
 				echo '
3420 3616
 		var ', $key, ' = ', $value, ';';
@@ -3429,26 +3625,27 @@  discard block
 block discarded – undo
3429 3625
 	foreach ($context['javascript_files'] as $id => $js_file)
3430 3626
 	{
3431 3627
 		// Last minute call! allow theme authors to disable single files.
3432
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3433
-			continue;
3628
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3629
+					continue;
3630
+		}
3434 3631
 
3435 3632
 		// By default all files don't get minimized unless the file explicitly says so!
3436 3633
 		if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3437 3634
 		{
3438
-			if ($do_deferred && !empty($js_file['options']['defer']))
3439
-				$toMinifyDefer[] = $js_file;
3440
-
3441
-			elseif (!$do_deferred && empty($js_file['options']['defer']))
3442
-				$toMinify[] = $js_file;
3635
+			if ($do_deferred && !empty($js_file['options']['defer'])) {
3636
+							$toMinifyDefer[] = $js_file;
3637
+			} elseif (!$do_deferred && empty($js_file['options']['defer'])) {
3638
+							$toMinify[] = $js_file;
3639
+			}
3443 3640
 
3444 3641
 			// Grab a random seed.
3445
-			if (!isset($minSeed))
3446
-				$minSeed = $js_file['options']['seed'];
3447
-		}
3448
-
3449
-		elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer'])))
3450
-			echo '
3642
+			if (!isset($minSeed)) {
3643
+							$minSeed = $js_file['options']['seed'];
3644
+			}
3645
+		} elseif ((!$do_deferred && empty($js_file['options']['defer'])) || ($do_deferred && !empty($js_file['options']['defer']))) {
3646
+					echo '
3451 3647
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async="async"' : '', '></script>';
3648
+		}
3452 3649
 	}
3453 3650
 
3454 3651
 	if ((!$do_deferred && !empty($toMinify)) || ($do_deferred && !empty($toMinifyDefer)))
@@ -3456,14 +3653,14 @@  discard block
 block discarded – undo
3456 3653
 		$result = custMinify(($do_deferred ? $toMinifyDefer : $toMinify), 'js', $do_deferred);
3457 3654
 
3458 3655
 		// Minify process couldn't work, print each individual files.
3459
-		if (!empty($result) && is_array($result))
3460
-			foreach ($result as $minFailedFile)
3656
+		if (!empty($result) && is_array($result)) {
3657
+					foreach ($result as $minFailedFile)
3461 3658
 				echo '
3462 3659
 	<script src="', $minFailedFile['fileUrl'], '"', !empty($minFailedFile['options']['async']) ? ' async="async"' : '', '></script>';
3463
-
3464
-		else
3465
-			echo '
3660
+		} else {
3661
+					echo '
3466 3662
 	<script src="', $settings['theme_url'] ,'/scripts/minified', ($do_deferred ? '_deferred' : '') ,'.js', $minSeed ,'"></script>';
3663
+		}
3467 3664
 	}
3468 3665
 
3469 3666
 	// Inline JavaScript - Actually useful some times!
@@ -3474,8 +3671,9 @@  discard block
 block discarded – undo
3474 3671
 			echo '
3475 3672
 <script>';
3476 3673
 
3477
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3478
-				echo $js_code;
3674
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3675
+							echo $js_code;
3676
+			}
3479 3677
 
3480 3678
 			echo '
3481 3679
 </script>';
@@ -3486,8 +3684,9 @@  discard block
 block discarded – undo
3486 3684
 			echo '
3487 3685
 	<script>';
3488 3686
 
3489
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3490
-				echo $js_code;
3687
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3688
+							echo $js_code;
3689
+			}
3491 3690
 
3492 3691
 			echo '
3493 3692
 	</script>';
@@ -3512,8 +3711,9 @@  discard block
 block discarded – undo
3512 3711
 	foreach ($context['css_files'] as $id => $file)
3513 3712
 	{
3514 3713
 		// Last minute call! allow theme authors to disable single files.
3515
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3516
-			continue;
3714
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3715
+					continue;
3716
+		}
3517 3717
 
3518 3718
 		// By default all files don't get minimized unless the file explicitly says so!
3519 3719
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
@@ -3521,12 +3721,12 @@  discard block
 block discarded – undo
3521 3721
 			$toMinify[] = $file;
3522 3722
 
3523 3723
 			// Grab a random seed.
3524
-			if (!isset($minSeed))
3525
-				$minSeed = $file['options']['seed'];
3724
+			if (!isset($minSeed)) {
3725
+							$minSeed = $file['options']['seed'];
3726
+			}
3727
+		} else {
3728
+					$normal[] = $file['fileUrl'];
3526 3729
 		}
3527
-
3528
-		else
3529
-			$normal[] = $file['fileUrl'];
3530 3730
 	}
3531 3731
 
3532 3732
 	if (!empty($toMinify))
@@ -3534,28 +3734,30 @@  discard block
 block discarded – undo
3534 3734
 		$result = custMinify($toMinify, 'css');
3535 3735
 
3536 3736
 		// Minify process couldn't work, print each individual files.
3537
-		if (!empty($result) && is_array($result))
3538
-			foreach ($result as $minFailedFile)
3737
+		if (!empty($result) && is_array($result)) {
3738
+					foreach ($result as $minFailedFile)
3539 3739
 				echo '
3540 3740
 	<link rel="stylesheet" href="', $minFailedFile['fileUrl'], '">';
3541
-
3542
-		else
3543
-			echo '
3741
+		} else {
3742
+					echo '
3544 3743
 	<link rel="stylesheet" href="', $settings['theme_url'] ,'/css/minified.css', $minSeed ,'">';
3744
+		}
3545 3745
 	}
3546 3746
 
3547 3747
 	// Print the rest after the minified files.
3548
-	if (!empty($normal))
3549
-		foreach ($normal as $nf)
3748
+	if (!empty($normal)) {
3749
+			foreach ($normal as $nf)
3550 3750
 			echo '
3551 3751
 	<link rel="stylesheet" href="', $nf ,'">';
3752
+	}
3552 3753
 
3553 3754
 	if ($db_show_debug === true)
3554 3755
 	{
3555 3756
 		// Try to keep only what's useful.
3556 3757
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3557
-		foreach ($context['css_files'] as $file)
3558
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3758
+		foreach ($context['css_files'] as $file) {
3759
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3760
+		}
3559 3761
 	}
3560 3762
 
3561 3763
 	if (!empty($context['css_header']))
@@ -3563,9 +3765,10 @@  discard block
 block discarded – undo
3563 3765
 		echo '
3564 3766
 	<style>';
3565 3767
 
3566
-		foreach ($context['css_header'] as $css)
3567
-			echo $css .'
3768
+		foreach ($context['css_header'] as $css) {
3769
+					echo $css .'
3568 3770
 	';
3771
+		}
3569 3772
 
3570 3773
 		echo'
3571 3774
 	</style>';
@@ -3590,15 +3793,17 @@  discard block
 block discarded – undo
3590 3793
 	$data = !empty($data) ? $data : false;
3591 3794
 	$minFailed = array();
3592 3795
 
3593
-	if (empty($type) || empty($data))
3594
-		return false;
3796
+	if (empty($type) || empty($data)) {
3797
+			return false;
3798
+	}
3595 3799
 
3596 3800
 	// Did we already did this?
3597 3801
 	$toCache = cache_get_data('minimized_'. $settings['theme_id'] .'_'. $type, 86400);
3598 3802
 
3599 3803
 	// Already done?
3600
-	if (!empty($toCache))
3601
-		return true;
3804
+	if (!empty($toCache)) {
3805
+			return true;
3806
+	}
3602 3807
 
3603 3808
 	// Yep, need a bunch of files.
3604 3809
 	require_once($sourcedir . '/minify/src/Minify.php');
@@ -3686,8 +3891,9 @@  discard block
 block discarded – undo
3686 3891
 	global $modSettings, $smcFunc;
3687 3892
 
3688 3893
 	// Just make up a nice hash...
3689
-	if ($new)
3690
-		return sha1(md5($filename . time()) . mt_rand());
3894
+	if ($new) {
3895
+			return sha1(md5($filename . time()) . mt_rand());
3896
+	}
3691 3897
 
3692 3898
 	// Grab the file hash if it wasn't added.
3693 3899
 	// Left this for legacy.
@@ -3701,23 +3907,25 @@  discard block
 block discarded – undo
3701 3907
 				'id_attach' => $attachment_id,
3702 3908
 			));
3703 3909
 
3704
-		if ($smcFunc['db_num_rows']($request) === 0)
3705
-			return false;
3910
+		if ($smcFunc['db_num_rows']($request) === 0) {
3911
+					return false;
3912
+		}
3706 3913
 
3707 3914
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3708 3915
 		$smcFunc['db_free_result']($request);
3709 3916
 	}
3710 3917
 
3711 3918
 	// Still no hash? mmm...
3712
-	if (empty($file_hash))
3713
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
3919
+	if (empty($file_hash)) {
3920
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
3921
+	}
3714 3922
 
3715 3923
 	// Are we using multiple directories?
3716
-	if (!empty($modSettings['currentAttachmentUploadDir']))
3717
-		$path = $modSettings['attachmentUploadDir'][$dir];
3718
-
3719
-	else
3720
-		$path = $modSettings['attachmentUploadDir'];
3924
+	if (!empty($modSettings['currentAttachmentUploadDir'])) {
3925
+			$path = $modSettings['attachmentUploadDir'][$dir];
3926
+	} else {
3927
+			$path = $modSettings['attachmentUploadDir'];
3928
+	}
3721 3929
 
3722 3930
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3723 3931
 }
@@ -3732,8 +3940,9 @@  discard block
 block discarded – undo
3732 3940
 function ip2range($fullip)
3733 3941
 {
3734 3942
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3735
-	if ($fullip == 'unknown')
3736
-		$fullip = '255.255.255.255';
3943
+	if ($fullip == 'unknown') {
3944
+			$fullip = '255.255.255.255';
3945
+	}
3737 3946
 
3738 3947
 	$ip_parts = explode('-', $fullip);
3739 3948
 	$ip_array = array();
@@ -3757,10 +3966,11 @@  discard block
 block discarded – undo
3757 3966
 		$ip_array['low'] = $ip_parts[0];
3758 3967
 		$ip_array['high'] = $ip_parts[1];
3759 3968
 		return $ip_array;
3760
-	}
3761
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
3969
+	} elseif (count($ip_parts) == 2) {
3970
+		// if ip 22.22.*-22.22.*
3762 3971
 	{
3763 3972
 		$valid_low = isValidIP($ip_parts[0]);
3973
+	}
3764 3974
 		$valid_high = isValidIP($ip_parts[1]);
3765 3975
 		$count = 0;
3766 3976
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -3775,7 +3985,9 @@  discard block
 block discarded – undo
3775 3985
 				$ip_parts[0] .= $mode . $min;
3776 3986
 				$valid_low = isValidIP($ip_parts[0]);
3777 3987
 				$count++;
3778
-				if ($count > 9) break;
3988
+				if ($count > 9) {
3989
+					break;
3990
+				}
3779 3991
 			}
3780 3992
 		}
3781 3993
 
@@ -3789,7 +4001,9 @@  discard block
 block discarded – undo
3789 4001
 				$ip_parts[1] .= $mode . $max;
3790 4002
 				$valid_high = isValidIP($ip_parts[1]);
3791 4003
 				$count++;
3792
-				if ($count > 9) break;
4004
+				if ($count > 9) {
4005
+					break;
4006
+				}
3793 4007
 			}
3794 4008
 		}
3795 4009
 
@@ -3814,46 +4028,54 @@  discard block
 block discarded – undo
3814 4028
 {
3815 4029
 	global $modSettings;
3816 4030
 
3817
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
3818
-		return $host;
4031
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4032
+			return $host;
4033
+	}
3819 4034
 	$t = microtime();
3820 4035
 
3821 4036
 	// Try the Linux host command, perhaps?
3822 4037
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
3823 4038
 	{
3824
-		if (!isset($modSettings['host_to_dis']))
3825
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
3826
-		else
3827
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4039
+		if (!isset($modSettings['host_to_dis'])) {
4040
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4041
+		} else {
4042
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4043
+		}
3828 4044
 
3829 4045
 		// Did host say it didn't find anything?
3830
-		if (strpos($test, 'not found') !== false)
3831
-			$host = '';
4046
+		if (strpos($test, 'not found') !== false) {
4047
+					$host = '';
4048
+		}
3832 4049
 		// Invalid server option?
3833
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
3834
-			updateSettings(array('host_to_dis' => 1));
4050
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4051
+					updateSettings(array('host_to_dis' => 1));
4052
+		}
3835 4053
 		// Maybe it found something, after all?
3836
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
3837
-			$host = $match[1];
4054
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4055
+					$host = $match[1];
4056
+		}
3838 4057
 	}
3839 4058
 
3840 4059
 	// This is nslookup; usually only Windows, but possibly some Unix?
3841 4060
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
3842 4061
 	{
3843 4062
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
3844
-		if (strpos($test, 'Non-existent domain') !== false)
3845
-			$host = '';
3846
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
3847
-			$host = $match[1];
4063
+		if (strpos($test, 'Non-existent domain') !== false) {
4064
+					$host = '';
4065
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4066
+					$host = $match[1];
4067
+		}
3848 4068
 	}
3849 4069
 
3850 4070
 	// This is the last try :/.
3851
-	if (!isset($host) || $host === false)
3852
-		$host = @gethostbyaddr($ip);
4071
+	if (!isset($host) || $host === false) {
4072
+			$host = @gethostbyaddr($ip);
4073
+	}
3853 4074
 
3854 4075
 	// It took a long time, so let's cache it!
3855
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
3856
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4076
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4077
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4078
+	}
3857 4079
 
3858 4080
 	return $host;
3859 4081
 }
@@ -3889,20 +4111,21 @@  discard block
 block discarded – undo
3889 4111
 			{
3890 4112
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
3891 4113
 				$total = 0;
3892
-				for ($i = 0; $i < $max_chars; $i++)
3893
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4114
+				for ($i = 0; $i < $max_chars; $i++) {
4115
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4116
+				}
3894 4117
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
3895 4118
 			}
3896 4119
 		}
3897 4120
 		return array_unique($returned_ints);
3898
-	}
3899
-	else
4121
+	} else
3900 4122
 	{
3901 4123
 		// Trim characters before and after and add slashes for database insertion.
3902 4124
 		$returned_words = array();
3903
-		foreach ($words as $word)
3904
-			if (($word = trim($word, '-_\'')) !== '')
4125
+		foreach ($words as $word) {
4126
+					if (($word = trim($word, '-_\'')) !== '')
3905 4127
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4128
+		}
3906 4129
 
3907 4130
 		// Filter out all words that occur more than once.
3908 4131
 		return array_unique($returned_words);
@@ -3924,16 +4147,18 @@  discard block
 block discarded – undo
3924 4147
 	global $settings, $txt;
3925 4148
 
3926 4149
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
3927
-	if (function_exists('template_create_button') && !$force_use)
3928
-		return template_create_button($name, $alt, $label = '', $custom = '');
4150
+	if (function_exists('template_create_button') && !$force_use) {
4151
+			return template_create_button($name, $alt, $label = '', $custom = '');
4152
+	}
3929 4153
 
3930
-	if (!$settings['use_image_buttons'])
3931
-		return $txt[$alt];
3932
-	elseif (!empty($settings['use_buttons']))
3933
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
3934
-	else
3935
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
3936
-}
4154
+	if (!$settings['use_image_buttons']) {
4155
+			return $txt[$alt];
4156
+	} elseif (!empty($settings['use_buttons'])) {
4157
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4158
+	} else {
4159
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4160
+	}
4161
+	}
3937 4162
 
3938 4163
 /**
3939 4164
  * Sets up all of the top menu buttons
@@ -3976,9 +4201,10 @@  discard block
 block discarded – undo
3976 4201
 	var user_menus = new smc_PopupMenu();
3977 4202
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
3978 4203
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
3979
-		if ($context['allow_pm'])
3980
-			addInlineJavaScript('
4204
+		if ($context['allow_pm']) {
4205
+					addInlineJavaScript('
3981 4206
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4207
+		}
3982 4208
 
3983 4209
 		if (!empty($modSettings['enable_ajax_alerts']))
3984 4210
 		{
@@ -4138,88 +4364,96 @@  discard block
 block discarded – undo
4138 4364
 
4139 4365
 		// Now we put the buttons in the context so the theme can use them.
4140 4366
 		$menu_buttons = array();
4141
-		foreach ($buttons as $act => $button)
4142
-			if (!empty($button['show']))
4367
+		foreach ($buttons as $act => $button) {
4368
+					if (!empty($button['show']))
4143 4369
 			{
4144 4370
 				$button['active_button'] = false;
4371
+		}
4145 4372
 
4146 4373
 				// This button needs some action.
4147
-				if (isset($button['action_hook']))
4148
-					$needs_action_hook = true;
4374
+				if (isset($button['action_hook'])) {
4375
+									$needs_action_hook = true;
4376
+				}
4149 4377
 
4150 4378
 				// Make sure the last button truly is the last button.
4151 4379
 				if (!empty($button['is_last']))
4152 4380
 				{
4153
-					if (isset($last_button))
4154
-						unset($menu_buttons[$last_button]['is_last']);
4381
+					if (isset($last_button)) {
4382
+											unset($menu_buttons[$last_button]['is_last']);
4383
+					}
4155 4384
 					$last_button = $act;
4156 4385
 				}
4157 4386
 
4158 4387
 				// Go through the sub buttons if there are any.
4159
-				if (!empty($button['sub_buttons']))
4160
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4388
+				if (!empty($button['sub_buttons'])) {
4389
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4161 4390
 					{
4162 4391
 						if (empty($subbutton['show']))
4163 4392
 							unset($button['sub_buttons'][$key]);
4393
+				}
4164 4394
 
4165 4395
 						// 2nd level sub buttons next...
4166 4396
 						if (!empty($subbutton['sub_buttons']))
4167 4397
 						{
4168 4398
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4169 4399
 							{
4170
-								if (empty($sub_button2['show']))
4171
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4400
+								if (empty($sub_button2['show'])) {
4401
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4402
+								}
4172 4403
 							}
4173 4404
 						}
4174 4405
 					}
4175 4406
 
4176 4407
 				// Does this button have its own icon?
4177
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4178
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4179
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4180
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4181
-				elseif (isset($button['icon']))
4182
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4183
-				else
4184
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4408
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4409
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4410
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4411
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4412
+				} elseif (isset($button['icon'])) {
4413
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4414
+				} else {
4415
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4416
+				}
4185 4417
 
4186 4418
 				$menu_buttons[$act] = $button;
4187 4419
 			}
4188 4420
 
4189
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4190
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4421
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4422
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4423
+		}
4191 4424
 	}
4192 4425
 
4193 4426
 	$context['menu_buttons'] = $menu_buttons;
4194 4427
 
4195 4428
 	// Logging out requires the session id in the url.
4196
-	if (isset($context['menu_buttons']['logout']))
4197
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4429
+	if (isset($context['menu_buttons']['logout'])) {
4430
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4431
+	}
4198 4432
 
4199 4433
 	// Figure out which action we are doing so we can set the active tab.
4200 4434
 	// Default to home.
4201 4435
 	$current_action = 'home';
4202 4436
 
4203
-	if (isset($context['menu_buttons'][$context['current_action']]))
4204
-		$current_action = $context['current_action'];
4205
-	elseif ($context['current_action'] == 'search2')
4206
-		$current_action = 'search';
4207
-	elseif ($context['current_action'] == 'theme')
4208
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4209
-	elseif ($context['current_action'] == 'register2')
4210
-		$current_action = 'register';
4211
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4212
-		$current_action = 'login';
4213
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4214
-		$current_action = 'moderate';
4437
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4438
+			$current_action = $context['current_action'];
4439
+	} elseif ($context['current_action'] == 'search2') {
4440
+			$current_action = 'search';
4441
+	} elseif ($context['current_action'] == 'theme') {
4442
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4443
+	} elseif ($context['current_action'] == 'register2') {
4444
+			$current_action = 'register';
4445
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4446
+			$current_action = 'login';
4447
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4448
+			$current_action = 'moderate';
4449
+	}
4215 4450
 
4216 4451
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4217 4452
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4218 4453
 	{
4219 4454
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4220 4455
 		$context[$current_action] = true;
4221
-	}
4222
-	elseif ($context['current_action'] == 'pm')
4456
+	} elseif ($context['current_action'] == 'pm')
4223 4457
 	{
4224 4458
 		$current_action = 'self_pm';
4225 4459
 		$context['self_pm'] = true;
@@ -4262,12 +4496,14 @@  discard block
 block discarded – undo
4262 4496
 	}
4263 4497
 
4264 4498
 	// Not all actions are simple.
4265
-	if (!empty($needs_action_hook))
4266
-		call_integration_hook('integrate_current_action', array(&$current_action));
4499
+	if (!empty($needs_action_hook)) {
4500
+			call_integration_hook('integrate_current_action', array(&$current_action));
4501
+	}
4267 4502
 
4268
-	if (isset($context['menu_buttons'][$current_action]))
4269
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4270
-}
4503
+	if (isset($context['menu_buttons'][$current_action])) {
4504
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4505
+	}
4506
+	}
4271 4507
 
4272 4508
 /**
4273 4509
  * Generate a random seed and ensure it's stored in settings.
@@ -4291,16 +4527,19 @@  discard block
 block discarded – undo
4291 4527
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4292 4528
 	global $context, $txt;
4293 4529
 
4294
-	if ($db_show_debug === true)
4295
-		$context['debug']['hooks'][] = $hook;
4530
+	if ($db_show_debug === true) {
4531
+			$context['debug']['hooks'][] = $hook;
4532
+	}
4296 4533
 
4297 4534
 	// Need to have some control.
4298
-	if (!isset($context['instances']))
4299
-		$context['instances'] = array();
4535
+	if (!isset($context['instances'])) {
4536
+			$context['instances'] = array();
4537
+	}
4300 4538
 
4301 4539
 	$results = array();
4302
-	if (empty($modSettings[$hook]))
4303
-		return $results;
4540
+	if (empty($modSettings[$hook])) {
4541
+			return $results;
4542
+	}
4304 4543
 
4305 4544
 	// Define some needed vars.
4306 4545
 	$function = false;
@@ -4310,14 +4549,16 @@  discard block
 block discarded – undo
4310 4549
 	foreach ($functions as $function)
4311 4550
 	{
4312 4551
 		// Hook has been marked as "disabled". Skip it!
4313
-		if (strpos($function, '!') !== false)
4314
-			continue;
4552
+		if (strpos($function, '!') !== false) {
4553
+					continue;
4554
+		}
4315 4555
 
4316 4556
 		$call = call_helper($function, true);
4317 4557
 
4318 4558
 		// Is it valid?
4319
-		if (!empty($call))
4320
-			$results[$function] = call_user_func_array($call, $parameters);
4559
+		if (!empty($call)) {
4560
+					$results[$function] = call_user_func_array($call, $parameters);
4561
+		}
4321 4562
 
4322 4563
 		// Whatever it was suppose to call, it failed :(
4323 4564
 		elseif (!empty($function))
@@ -4333,8 +4574,9 @@  discard block
 block discarded – undo
4333 4574
 			}
4334 4575
 
4335 4576
 			// "Assume" the file resides on $boarddir somewhere...
4336
-			else
4337
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4577
+			else {
4578
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4579
+			}
4338 4580
 		}
4339 4581
 	}
4340 4582
 
@@ -4356,12 +4598,14 @@  discard block
 block discarded – undo
4356 4598
 	global $smcFunc, $modSettings;
4357 4599
 
4358 4600
 	// Any objects?
4359
-	if ($object)
4360
-		$function = $function . '#';
4601
+	if ($object) {
4602
+			$function = $function . '#';
4603
+	}
4361 4604
 
4362 4605
 	// Any files  to load?
4363
-	if (!empty($file) && is_string($file))
4364
-		$function = $file . (!empty($function) ? '|' . $function : '');
4606
+	if (!empty($file) && is_string($file)) {
4607
+			$function = $file . (!empty($function) ? '|' . $function : '');
4608
+	}
4365 4609
 
4366 4610
 	// Get the correct string.
4367 4611
 	$integration_call = $function;
@@ -4383,13 +4627,14 @@  discard block
 block discarded – undo
4383 4627
 		if (!empty($current_functions))
4384 4628
 		{
4385 4629
 			$current_functions = explode(',', $current_functions);
4386
-			if (in_array($integration_call, $current_functions))
4387
-				return;
4630
+			if (in_array($integration_call, $current_functions)) {
4631
+							return;
4632
+			}
4388 4633
 
4389 4634
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4635
+		} else {
4636
+					$permanent_functions = array($integration_call);
4390 4637
 		}
4391
-		else
4392
-			$permanent_functions = array($integration_call);
4393 4638
 
4394 4639
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4395 4640
 	}
@@ -4398,8 +4643,9 @@  discard block
 block discarded – undo
4398 4643
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4399 4644
 
4400 4645
 	// Do nothing, if it's already there.
4401
-	if (in_array($integration_call, $functions))
4402
-		return;
4646
+	if (in_array($integration_call, $functions)) {
4647
+			return;
4648
+	}
4403 4649
 
4404 4650
 	$functions[] = $integration_call;
4405 4651
 	$modSettings[$hook] = implode(',', $functions);
@@ -4422,12 +4668,14 @@  discard block
 block discarded – undo
4422 4668
 	global $smcFunc, $modSettings;
4423 4669
 
4424 4670
 	// Any objects?
4425
-	if ($object)
4426
-		$function = $function . '#';
4671
+	if ($object) {
4672
+			$function = $function . '#';
4673
+	}
4427 4674
 
4428 4675
 	// Any files  to load?
4429
-	if (!empty($file) && is_string($file))
4430
-		$function = $file . '|' . $function;
4676
+	if (!empty($file) && is_string($file)) {
4677
+			$function = $file . '|' . $function;
4678
+	}
4431 4679
 
4432 4680
 	// Get the correct string.
4433 4681
 	$integration_call = $function;
@@ -4448,16 +4696,18 @@  discard block
 block discarded – undo
4448 4696
 	{
4449 4697
 		$current_functions = explode(',', $current_functions);
4450 4698
 
4451
-		if (in_array($integration_call, $current_functions))
4452
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4699
+		if (in_array($integration_call, $current_functions)) {
4700
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4701
+		}
4453 4702
 	}
4454 4703
 
4455 4704
 	// Turn the function list into something usable.
4456 4705
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4457 4706
 
4458 4707
 	// You can only remove it if it's available.
4459
-	if (!in_array($integration_call, $functions))
4460
-		return;
4708
+	if (!in_array($integration_call, $functions)) {
4709
+			return;
4710
+	}
4461 4711
 
4462 4712
 	$functions = array_diff($functions, array($integration_call));
4463 4713
 	$modSettings[$hook] = implode(',', $functions);
@@ -4478,17 +4728,20 @@  discard block
 block discarded – undo
4478 4728
 	global $context, $smcFunc, $txt, $db_show_debug;
4479 4729
 
4480 4730
 	// Really?
4481
-	if (empty($string))
4482
-		return false;
4731
+	if (empty($string)) {
4732
+			return false;
4733
+	}
4483 4734
 
4484 4735
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4485 4736
 	// A closure? should be a callable one.
4486
-	if (is_array($string) || $string instanceof Closure)
4487
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4737
+	if (is_array($string) || $string instanceof Closure) {
4738
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
4739
+	}
4488 4740
 
4489 4741
 	// No full objects, sorry! pass a method or a property instead!
4490
-	if (is_object($string))
4491
-		return false;
4742
+	if (is_object($string)) {
4743
+			return false;
4744
+	}
4492 4745
 
4493 4746
 	// Stay vitaminized my friends...
4494 4747
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4500,8 +4753,9 @@  discard block
 block discarded – undo
4500 4753
 	$string = load_file($string);
4501 4754
 
4502 4755
 	// Loaded file failed
4503
-	if (empty($string))
4504
-		return false;
4756
+	if (empty($string)) {
4757
+			return false;
4758
+	}
4505 4759
 
4506 4760
 	// Found a method.
4507 4761
 	if (strpos($string, '::') !== false)
@@ -4522,8 +4776,9 @@  discard block
 block discarded – undo
4522 4776
 				// Add another one to the list.
4523 4777
 				if ($db_show_debug === true)
4524 4778
 				{
4525
-					if (!isset($context['debug']['instances']))
4526
-						$context['debug']['instances'] = array();
4779
+					if (!isset($context['debug']['instances'])) {
4780
+											$context['debug']['instances'] = array();
4781
+					}
4527 4782
 
4528 4783
 					$context['debug']['instances'][$class] = $class;
4529 4784
 				}
@@ -4533,13 +4788,15 @@  discard block
 block discarded – undo
4533 4788
 		}
4534 4789
 
4535 4790
 		// Right then. This is a call to a static method.
4536
-		else
4537
-			$func = array($class, $method);
4791
+		else {
4792
+					$func = array($class, $method);
4793
+		}
4538 4794
 	}
4539 4795
 
4540 4796
 	// Nope! just a plain regular function.
4541
-	else
4542
-		$func = $string;
4797
+	else {
4798
+			$func = $string;
4799
+	}
4543 4800
 
4544 4801
 	// Right, we got what we need, time to do some checks.
4545 4802
 	if (!is_callable($func, false, $callable_name))
@@ -4555,17 +4812,18 @@  discard block
 block discarded – undo
4555 4812
 	else
4556 4813
 	{
4557 4814
 		// What are we gonna do about it?
4558
-		if ($return)
4559
-			return $func;
4815
+		if ($return) {
4816
+					return $func;
4817
+		}
4560 4818
 
4561 4819
 		// If this is a plain function, avoid the heat of calling call_user_func().
4562 4820
 		else
4563 4821
 		{
4564
-			if (is_array($func))
4565
-				call_user_func($func);
4566
-
4567
-			else
4568
-				$func();
4822
+			if (is_array($func)) {
4823
+							call_user_func($func);
4824
+			} else {
4825
+							$func();
4826
+			}
4569 4827
 		}
4570 4828
 	}
4571 4829
 }
@@ -4582,31 +4840,34 @@  discard block
 block discarded – undo
4582 4840
 {
4583 4841
 	global $sourcedir, $txt, $boarddir, $settings;
4584 4842
 
4585
-	if (empty($string))
4586
-		return false;
4843
+	if (empty($string)) {
4844
+			return false;
4845
+	}
4587 4846
 
4588 4847
 	if (strpos($string, '|') !== false)
4589 4848
 	{
4590 4849
 		list ($file, $string) = explode('|', $string);
4591 4850
 
4592 4851
 		// Match the wildcards to their regular vars.
4593
-		if (empty($settings['theme_dir']))
4594
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4595
-
4596
-		else
4597
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4852
+		if (empty($settings['theme_dir'])) {
4853
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4854
+		} else {
4855
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
4856
+		}
4598 4857
 
4599 4858
 		// Load the file if it can be loaded.
4600
-		if (file_exists($absPath))
4601
-			require_once($absPath);
4859
+		if (file_exists($absPath)) {
4860
+					require_once($absPath);
4861
+		}
4602 4862
 
4603 4863
 		// No? try a fallback to $sourcedir
4604 4864
 		else
4605 4865
 		{
4606 4866
 			$absPath = $sourcedir .'/'. $file;
4607 4867
 
4608
-			if (file_exists($absPath))
4609
-				require_once($absPath);
4868
+			if (file_exists($absPath)) {
4869
+							require_once($absPath);
4870
+			}
4610 4871
 
4611 4872
 			// Sorry, can't do much for you at this point.
4612 4873
 			else
@@ -4633,8 +4894,9 @@  discard block
 block discarded – undo
4633 4894
 	global $user_info, $smcFunc;
4634 4895
 
4635 4896
 	// Make sure we have something to work with.
4636
-	if (empty($topic))
4637
-		return array();
4897
+	if (empty($topic)) {
4898
+			return array();
4899
+	}
4638 4900
 
4639 4901
 
4640 4902
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -4657,8 +4919,9 @@  discard block
 block discarded – undo
4657 4919
 				'topic' => $topic,
4658 4920
 			)
4659 4921
 		);
4660
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4661
-			$temp[] = (int) $row['content_id'];
4922
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4923
+					$temp[] = (int) $row['content_id'];
4924
+		}
4662 4925
 
4663 4926
 		cache_put_data($cache_key, $temp, $ttl);
4664 4927
 	}
@@ -4679,8 +4942,9 @@  discard block
 block discarded – undo
4679 4942
 {
4680 4943
 	global $context;
4681 4944
 
4682
-	if (empty($string))
4683
-		return $string;
4945
+	if (empty($string)) {
4946
+			return $string;
4947
+	}
4684 4948
 
4685 4949
 	// UTF-8 occurences of MS special characters
4686 4950
 	$findchars_utf8 = array(
@@ -4721,10 +4985,11 @@  discard block
 block discarded – undo
4721 4985
 		'--',	// &mdash;
4722 4986
 	);
4723 4987
 
4724
-	if ($context['utf8'])
4725
-		$string = str_replace($findchars_utf8, $replacechars, $string);
4726
-	else
4727
-		$string = str_replace($findchars_iso, $replacechars, $string);
4988
+	if ($context['utf8']) {
4989
+			$string = str_replace($findchars_utf8, $replacechars, $string);
4990
+	} else {
4991
+			$string = str_replace($findchars_iso, $replacechars, $string);
4992
+	}
4728 4993
 
4729 4994
 	return $string;
4730 4995
 }
@@ -4743,49 +5008,59 @@  discard block
 block discarded – undo
4743 5008
 {
4744 5009
 	global $context;
4745 5010
 
4746
-	if (!isset($matches[2]))
4747
-		return '';
5011
+	if (!isset($matches[2])) {
5012
+			return '';
5013
+	}
4748 5014
 
4749 5015
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4750 5016
 
4751 5017
 	// remove left to right / right to left overrides
4752
-	if ($num === 0x202D || $num === 0x202E)
4753
-		return '';
5018
+	if ($num === 0x202D || $num === 0x202E) {
5019
+			return '';
5020
+	}
4754 5021
 
4755 5022
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
4756
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
4757
-		return '&#' . $num . ';';
5023
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5024
+			return '&#' . $num . ';';
5025
+	}
4758 5026
 
4759 5027
 	if (empty($context['utf8']))
4760 5028
 	{
4761 5029
 		// no control characters
4762
-		if ($num < 0x20)
4763
-			return '';
5030
+		if ($num < 0x20) {
5031
+					return '';
5032
+		}
4764 5033
 		// text is text
4765
-		elseif ($num < 0x80)
4766
-			return chr($num);
5034
+		elseif ($num < 0x80) {
5035
+					return chr($num);
5036
+		}
4767 5037
 		// all others get html-ised
4768
-		else
4769
-			return '&#' . $matches[2] . ';';
4770
-	}
4771
-	else
5038
+		else {
5039
+					return '&#' . $matches[2] . ';';
5040
+		}
5041
+	} else
4772 5042
 	{
4773 5043
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
4774 5044
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
4775
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
4776
-			return '';
5045
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5046
+					return '';
5047
+		}
4777 5048
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4778
-		elseif ($num < 0x80)
4779
-			return chr($num);
5049
+		elseif ($num < 0x80) {
5050
+					return chr($num);
5051
+		}
4780 5052
 		// <0x800 (2048)
4781
-		elseif ($num < 0x800)
4782
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5053
+		elseif ($num < 0x800) {
5054
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5055
+		}
4783 5056
 		// < 0x10000 (65536)
4784
-		elseif ($num < 0x10000)
4785
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5057
+		elseif ($num < 0x10000) {
5058
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5059
+		}
4786 5060
 		// <= 0x10FFFF (1114111)
4787
-		else
4788
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5061
+		else {
5062
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5063
+		}
4789 5064
 	}
4790 5065
 }
4791 5066
 
@@ -4801,28 +5076,34 @@  discard block
 block discarded – undo
4801 5076
  */
4802 5077
 function fixchar__callback($matches)
4803 5078
 {
4804
-	if (!isset($matches[1]))
4805
-		return '';
5079
+	if (!isset($matches[1])) {
5080
+			return '';
5081
+	}
4806 5082
 
4807 5083
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
4808 5084
 
4809 5085
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
4810 5086
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
4811
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
4812
-		return '';
5087
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5088
+			return '';
5089
+	}
4813 5090
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
4814
-	elseif ($num < 0x80)
4815
-		return chr($num);
5091
+	elseif ($num < 0x80) {
5092
+			return chr($num);
5093
+	}
4816 5094
 	// <0x800 (2048)
4817
-	elseif ($num < 0x800)
4818
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5095
+	elseif ($num < 0x800) {
5096
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5097
+	}
4819 5098
 	// < 0x10000 (65536)
4820
-	elseif ($num < 0x10000)
4821
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5099
+	elseif ($num < 0x10000) {
5100
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5101
+	}
4822 5102
 	// <= 0x10FFFF (1114111)
4823
-	else
4824
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
4825
-}
5103
+	else {
5104
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5105
+	}
5106
+	}
4826 5107
 
4827 5108
 /**
4828 5109
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -4835,17 +5116,19 @@  discard block
 block discarded – undo
4835 5116
  */
4836 5117
 function entity_fix__callback($matches)
4837 5118
 {
4838
-	if (!isset($matches[2]))
4839
-		return '';
5119
+	if (!isset($matches[2])) {
5120
+			return '';
5121
+	}
4840 5122
 
4841 5123
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
4842 5124
 
4843 5125
 	// we don't allow control characters, characters out of range, byte markers, etc
4844
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
4845
-		return '';
4846
-	else
4847
-		return '&#' . $num . ';';
4848
-}
5126
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5127
+			return '';
5128
+	} else {
5129
+			return '&#' . $num . ';';
5130
+	}
5131
+	}
4849 5132
 
4850 5133
 /**
4851 5134
  * Return a Gravatar URL based on
@@ -4869,18 +5152,23 @@  discard block
 block discarded – undo
4869 5152
 		$ratings = array('G', 'PG', 'R', 'X');
4870 5153
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
4871 5154
 		$url_params = array();
4872
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
4873
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
4874
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
4875
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
4876
-		if (!empty($modSettings['avatar_max_width_external']))
4877
-			$size_string = (int) $modSettings['avatar_max_width_external'];
4878
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
4879
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5155
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5156
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5157
+		}
5158
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5159
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5160
+		}
5161
+		if (!empty($modSettings['avatar_max_width_external'])) {
5162
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5163
+		}
5164
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5165
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
4880 5166
 				$size_string = $modSettings['avatar_max_height_external'];
5167
+		}
4881 5168
 
4882
-		if (!empty($size_string))
4883
-			$url_params[] = 's=' . $size_string;
5169
+		if (!empty($size_string)) {
5170
+					$url_params[] = 's=' . $size_string;
5171
+		}
4884 5172
 	}
4885 5173
 	$http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www';
4886 5174
 
@@ -4899,22 +5187,26 @@  discard block
 block discarded – undo
4899 5187
 	static $timezones = null, $lastwhen = null;
4900 5188
 
4901 5189
 	// No point doing this over if we already did it once
4902
-	if (!empty($timezones) && $when == $lastwhen)
4903
-		return $timezones;
4904
-	else
4905
-		$lastwhen = $when;
5190
+	if (!empty($timezones) && $when == $lastwhen) {
5191
+			return $timezones;
5192
+	} else {
5193
+			$lastwhen = $when;
5194
+	}
4906 5195
 
4907 5196
 	// Parseable datetime string?
4908
-	if (is_int($timestamp = strtotime($when)))
4909
-		$when = $timestamp;
5197
+	if (is_int($timestamp = strtotime($when))) {
5198
+			$when = $timestamp;
5199
+	}
4910 5200
 
4911 5201
 	// A Unix timestamp?
4912
-	elseif (is_numeric($when))
4913
-		$when = intval($when);
5202
+	elseif (is_numeric($when)) {
5203
+			$when = intval($when);
5204
+	}
4914 5205
 
4915 5206
 	// Invalid value? Just get current Unix timestamp.
4916
-	else
4917
-		$when = time();
5207
+	else {
5208
+			$when = time();
5209
+	}
4918 5210
 
4919 5211
 	// We'll need this too
4920 5212
 	$later = (int) date_format(date_add(date_create('@' . $when), date_interval_create_from_date_string('1 year')), 'U');
@@ -4977,8 +5269,9 @@  discard block
 block discarded – undo
4977 5269
 	foreach ($priority_countries as $country)
4978 5270
 	{
4979 5271
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
4980
-		if (!empty($country_tzids))
4981
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5272
+		if (!empty($country_tzids)) {
5273
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5274
+		}
4982 5275
 	}
4983 5276
 
4984 5277
 	// Process the preferred timezones first, then the rest.
@@ -4988,8 +5281,9 @@  discard block
 block discarded – undo
4988 5281
 	foreach ($tzids as $tzid)
4989 5282
 	{
4990 5283
 		// We don't want UTC right now
4991
-		if ($tzid == 'UTC')
4992
-			continue;
5284
+		if ($tzid == 'UTC') {
5285
+					continue;
5286
+		}
4993 5287
 
4994 5288
 		// First, get the set of transition rules for this tzid
4995 5289
 		$tzinfo = timezone_transitions_get(timezone_open($tzid), $when, $later);
@@ -5000,8 +5294,9 @@  discard block
 block discarded – undo
5000 5294
 			$tz_location = timezone_location_get(timezone_open($tzid));
5001 5295
 
5002 5296
 			// Kazakstan
5003
-			if ($tz_location['country_code'] == 'KZ')
5004
-				$tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']);
5297
+			if ($tz_location['country_code'] == 'KZ') {
5298
+							$tzinfo[0]['abbr'] = str_replace(array('+05', '+06'), array('AQTT', 'ALMT'), $tzinfo[0]['abbr']);
5299
+			}
5005 5300
 
5006 5301
 			// Russia likes to experiment with time zones
5007 5302
 			if ($tz_location['country_code'] == 'RU')
@@ -5012,19 +5307,22 @@  discard block
 block discarded – undo
5012 5307
 			}
5013 5308
 
5014 5309
 			// Still no good? We'll just mark it as a UTC offset
5015
-			if (strspn($tzinfo[0]['abbr'], '+-') > 0)
5016
-				$tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr'];
5310
+			if (strspn($tzinfo[0]['abbr'], '+-') > 0) {
5311
+							$tzinfo[0]['abbr'] = 'UTC' . $tzinfo[0]['abbr'];
5312
+			}
5017 5313
 		}
5018 5314
 
5019 5315
 		$tzkey = serialize($tzinfo);
5020 5316
 
5021 5317
 		// Don't overwrite our preferred tzids
5022
-		if (empty($zones[$tzkey]['tzid']))
5023
-			$zones[$tzkey]['tzid'] = $tzid;
5318
+		if (empty($zones[$tzkey]['tzid'])) {
5319
+					$zones[$tzkey]['tzid'] = $tzid;
5320
+		}
5024 5321
 
5025 5322
 		// A time zone from a prioritized country?
5026
-		if (in_array($tzid, $priority_tzids))
5027
-			$priority_zones[$tzkey] = true;
5323
+		if (in_array($tzid, $priority_tzids)) {
5324
+					$priority_zones[$tzkey] = true;
5325
+		}
5028 5326
 
5029 5327
 		// Keep track of the location and offset for this tzid
5030 5328
 		$tzid_parts = explode('/', $tzid);
@@ -5042,15 +5340,17 @@  discard block
 block discarded – undo
5042 5340
 	{
5043 5341
 		$tzinfo = unserialize($tzkey);
5044 5342
 
5045
-		if (!empty($timezone_descriptions[$tzvalue['tzid']]))
5046
-			$desc = $timezone_descriptions[$tzvalue['tzid']];
5047
-		else
5048
-			$desc = implode(', ', array_unique($tzvalue['locations']));
5343
+		if (!empty($timezone_descriptions[$tzvalue['tzid']])) {
5344
+					$desc = $timezone_descriptions[$tzvalue['tzid']];
5345
+		} else {
5346
+					$desc = implode(', ', array_unique($tzvalue['locations']));
5347
+		}
5049 5348
 
5050
-		if (isset($priority_zones[$tzkey]))
5051
-			$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5052
-		else
5053
-			$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5349
+		if (isset($priority_zones[$tzkey])) {
5350
+					$priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5351
+		} else {
5352
+					$timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format(date_create($tzvalue['tzid']), 'P') . ']';
5353
+		}
5054 5354
 	}
5055 5355
 
5056 5356
 	$timezones = array_merge(
@@ -5068,8 +5368,9 @@  discard block
 block discarded – undo
5068 5368
  */
5069 5369
 function inet_ptod($ip_address)
5070 5370
 {
5071
-	if (!isValidIP($ip_address))
5072
-		return $ip_address;
5371
+	if (!isValidIP($ip_address)) {
5372
+			return $ip_address;
5373
+	}
5073 5374
 
5074 5375
 	$bin = inet_pton($ip_address);
5075 5376
 	return $bin;
@@ -5081,13 +5382,15 @@  discard block
 block discarded – undo
5081 5382
  */
5082 5383
 function inet_dtop($bin)
5083 5384
 {
5084
-	if(empty($bin))
5085
-		return '';
5385
+	if(empty($bin)) {
5386
+			return '';
5387
+	}
5086 5388
 
5087 5389
 	global $db_type;
5088 5390
 
5089
-	if ($db_type == 'postgresql')
5090
-		return $bin;
5391
+	if ($db_type == 'postgresql') {
5392
+			return $bin;
5393
+	}
5091 5394
 
5092 5395
 	$ip_address = inet_ntop($bin);
5093 5396
 
@@ -5112,26 +5415,32 @@  discard block
 block discarded – undo
5112 5415
  */
5113 5416
 function _safe_serialize($value)
5114 5417
 {
5115
-	if(is_null($value))
5116
-		return 'N;';
5418
+	if(is_null($value)) {
5419
+			return 'N;';
5420
+	}
5117 5421
 
5118
-	if(is_bool($value))
5119
-		return 'b:'. (int) $value .';';
5422
+	if(is_bool($value)) {
5423
+			return 'b:'. (int) $value .';';
5424
+	}
5120 5425
 
5121
-	if(is_int($value))
5122
-		return 'i:'. $value .';';
5426
+	if(is_int($value)) {
5427
+			return 'i:'. $value .';';
5428
+	}
5123 5429
 
5124
-	if(is_float($value))
5125
-		return 'd:'. str_replace(',', '.', $value) .';';
5430
+	if(is_float($value)) {
5431
+			return 'd:'. str_replace(',', '.', $value) .';';
5432
+	}
5126 5433
 
5127
-	if(is_string($value))
5128
-		return 's:'. strlen($value) .':"'. $value .'";';
5434
+	if(is_string($value)) {
5435
+			return 's:'. strlen($value) .':"'. $value .'";';
5436
+	}
5129 5437
 
5130 5438
 	if(is_array($value))
5131 5439
 	{
5132 5440
 		$out = '';
5133
-		foreach($value as $k => $v)
5134
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5441
+		foreach($value as $k => $v) {
5442
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5443
+		}
5135 5444
 
5136 5445
 		return 'a:'. count($value) .':{'. $out .'}';
5137 5446
 	}
@@ -5157,8 +5466,9 @@  discard block
 block discarded – undo
5157 5466
 
5158 5467
 	$out = _safe_serialize($value);
5159 5468
 
5160
-	if (isset($mbIntEnc))
5161
-		mb_internal_encoding($mbIntEnc);
5469
+	if (isset($mbIntEnc)) {
5470
+			mb_internal_encoding($mbIntEnc);
5471
+	}
5162 5472
 
5163 5473
 	return $out;
5164 5474
 }
@@ -5175,8 +5485,9 @@  discard block
 block discarded – undo
5175 5485
 function _safe_unserialize($str)
5176 5486
 {
5177 5487
 	// Input  is not a string.
5178
-	if(empty($str) || !is_string($str))
5179
-		return false;
5488
+	if(empty($str) || !is_string($str)) {
5489
+			return false;
5490
+	}
5180 5491
 
5181 5492
 	$stack = array();
5182 5493
 	$expected = array();
@@ -5192,43 +5503,38 @@  discard block
 block discarded – undo
5192 5503
 	while($state != 1)
5193 5504
 	{
5194 5505
 		$type = isset($str[0]) ? $str[0] : '';
5195
-		if($type == '}')
5196
-			$str = substr($str, 1);
5197
-
5198
-		else if($type == 'N' && $str[1] == ';')
5506
+		if($type == '}') {
5507
+					$str = substr($str, 1);
5508
+		} else if($type == 'N' && $str[1] == ';')
5199 5509
 		{
5200 5510
 			$value = null;
5201 5511
 			$str = substr($str, 2);
5202
-		}
5203
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5512
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5204 5513
 		{
5205 5514
 			$value = $matches[1] == '1' ? true : false;
5206 5515
 			$str = substr($str, 4);
5207
-		}
5208
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5516
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5209 5517
 		{
5210 5518
 			$value = (int)$matches[1];
5211 5519
 			$str = $matches[2];
5212
-		}
5213
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5520
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5214 5521
 		{
5215 5522
 			$value = (float)$matches[1];
5216 5523
 			$str = $matches[3];
5217
-		}
5218
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5524
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5219 5525
 		{
5220 5526
 			$value = substr($matches[2], 0, (int)$matches[1]);
5221 5527
 			$str = substr($matches[2], (int)$matches[1] + 2);
5222
-		}
5223
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5528
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5224 5529
 		{
5225 5530
 			$expectedLength = (int)$matches[1];
5226 5531
 			$str = $matches[2];
5227 5532
 		}
5228 5533
 
5229 5534
 		// Object or unknown/malformed type.
5230
-		else
5231
-			return false;
5535
+		else {
5536
+					return false;
5537
+		}
5232 5538
 
5233 5539
 		switch($state)
5234 5540
 		{
@@ -5256,8 +5562,9 @@  discard block
 block discarded – undo
5256 5562
 				if($type == '}')
5257 5563
 				{
5258 5564
 					// Array size is less than expected.
5259
-					if(count($list) < end($expected))
5260
-						return false;
5565
+					if(count($list) < end($expected)) {
5566
+											return false;
5567
+					}
5261 5568
 
5262 5569
 					unset($list);
5263 5570
 					$list = &$stack[count($stack)-1];
@@ -5266,8 +5573,9 @@  discard block
 block discarded – undo
5266 5573
 					// Go to terminal state if we're at the end of the root array.
5267 5574
 					array_pop($expected);
5268 5575
 
5269
-					if(count($expected) == 0)
5270
-						$state = 1;
5576
+					if(count($expected) == 0) {
5577
+											$state = 1;
5578
+					}
5271 5579
 
5272 5580
 					break;
5273 5581
 				}
@@ -5275,8 +5583,9 @@  discard block
 block discarded – undo
5275 5583
 				if($type == 'i' || $type == 's')
5276 5584
 				{
5277 5585
 					// Array size exceeds expected length.
5278
-					if(count($list) >= end($expected))
5279
-						return false;
5586
+					if(count($list) >= end($expected)) {
5587
+											return false;
5588
+					}
5280 5589
 
5281 5590
 					$key = $value;
5282 5591
 					$state = 3;
@@ -5310,8 +5619,9 @@  discard block
 block discarded – undo
5310 5619
 	}
5311 5620
 
5312 5621
 	// Trailing data in input.
5313
-	if(!empty($str))
5314
-		return false;
5622
+	if(!empty($str)) {
5623
+			return false;
5624
+	}
5315 5625
 
5316 5626
 	return $data;
5317 5627
 }
@@ -5334,8 +5644,9 @@  discard block
 block discarded – undo
5334 5644
 
5335 5645
 	$out = _safe_unserialize($str);
5336 5646
 
5337
-	if (isset($mbIntEnc))
5338
-		mb_internal_encoding($mbIntEnc);
5647
+	if (isset($mbIntEnc)) {
5648
+			mb_internal_encoding($mbIntEnc);
5649
+	}
5339 5650
 
5340 5651
 	return $out;
5341 5652
 }
@@ -5350,12 +5661,14 @@  discard block
 block discarded – undo
5350 5661
 function smf_chmod($file, $value = 0)
5351 5662
 {
5352 5663
 	// No file? no checks!
5353
-	if (empty($file))
5354
-		return false;
5664
+	if (empty($file)) {
5665
+			return false;
5666
+	}
5355 5667
 
5356 5668
 	// Already writable?
5357
-	if (is_writable($file))
5358
-		return true;
5669
+	if (is_writable($file)) {
5670
+			return true;
5671
+	}
5359 5672
 
5360 5673
 	// Do we have a file or a dir?
5361 5674
 	$isDir = is_dir($file);
@@ -5371,10 +5684,9 @@  discard block
 block discarded – undo
5371 5684
 		{
5372 5685
 			$isWritable = true;
5373 5686
 			break;
5687
+		} else {
5688
+					@chmod($file, $val);
5374 5689
 		}
5375
-
5376
-		else
5377
-			@chmod($file, $val);
5378 5690
 	}
5379 5691
 
5380 5692
 	return $isWritable;
@@ -5393,8 +5705,9 @@  discard block
 block discarded – undo
5393 5705
 	global $txt;
5394 5706
 
5395 5707
 	// Come on...
5396
-	if (empty($json) || !is_string($json))
5397
-		return array();
5708
+	if (empty($json) || !is_string($json)) {
5709
+			return array();
5710
+	}
5398 5711
 
5399 5712
 	$returnArray = array();
5400 5713
 	$jsonError = false;
@@ -5435,11 +5748,11 @@  discard block
 block discarded – undo
5435 5748
 		$jsonDebug = $jsonDebug[0];
5436 5749
 		loadLanguage('Errors');
5437 5750
 
5438
-		if (!empty($jsonDebug))
5439
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5440
-
5441
-		else
5442
-			log_error($txt['json_'. $jsonError], 'critical');
5751
+		if (!empty($jsonDebug)) {
5752
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5753
+		} else {
5754
+					log_error($txt['json_'. $jsonError], 'critical');
5755
+		}
5443 5756
 
5444 5757
 		// Everyone expects an array.
5445 5758
 		return array();
@@ -5469,8 +5782,9 @@  discard block
 block discarded – undo
5469 5782
 	global $db_show_debug, $modSettings;
5470 5783
 
5471 5784
 	// Defensive programming anyone?
5472
-	if (empty($data))
5473
-		return false;
5785
+	if (empty($data)) {
5786
+			return false;
5787
+	}
5474 5788
 
5475 5789
 	// Don't need extra stuff...
5476 5790
 	$db_show_debug = false;
@@ -5478,11 +5792,11 @@  discard block
 block discarded – undo
5478 5792
 	// Kill anything else.
5479 5793
 	ob_end_clean();
5480 5794
 
5481
-	if (!empty($modSettings['CompressedOutput']))
5482
-		@ob_start('ob_gzhandler');
5483
-
5484
-	else
5485
-		ob_start();
5795
+	if (!empty($modSettings['CompressedOutput'])) {
5796
+			@ob_start('ob_gzhandler');
5797
+	} else {
5798
+			ob_start();
5799
+	}
5486 5800
 
5487 5801
 	// Set the header.
5488 5802
 	header($type);
@@ -5514,8 +5828,9 @@  discard block
 block discarded – undo
5514 5828
 	static $done = false;
5515 5829
 
5516 5830
 	// If we don't need to do anything, don't
5517
-	if (!$update && $done)
5518
-		return;
5831
+	if (!$update && $done) {
5832
+			return;
5833
+	}
5519 5834
 
5520 5835
 	// Should we get a new copy of the official list of TLDs?
5521 5836
 	if ($update)
@@ -5536,10 +5851,11 @@  discard block
 block discarded – undo
5536 5851
 		// Clean $tlds and convert it to an array
5537 5852
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5538 5853
 			$line = trim($line);
5539
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5540
-				return false;
5541
-			else
5542
-				return true;
5854
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
5855
+							return false;
5856
+			} else {
5857
+							return true;
5858
+			}
5543 5859
 		});
5544 5860
 
5545 5861
 		// Convert Punycode to Unicode
@@ -5593,8 +5909,9 @@  discard block
 block discarded – undo
5593 5909
 						$idx += $digit * $w;
5594 5910
 						$t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias));
5595 5911
 
5596
-						if ($digit < $t)
5597
-							break;
5912
+						if ($digit < $t) {
5913
+													break;
5914
+						}
5598 5915
 
5599 5916
 						$w = (int) ($w * ($base - $t));
5600 5917
 					}
@@ -5603,8 +5920,9 @@  discard block
 block discarded – undo
5603 5920
 					$delta = intval($is_first ? ($delta / $damp) : ($delta / 2));
5604 5921
 					$delta += intval($delta / ($deco_len + 1));
5605 5922
 
5606
-					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base)
5607
-						$delta = intval($delta / ($base - $tmin));
5923
+					for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) {
5924
+											$delta = intval($delta / ($base - $tmin));
5925
+					}
5608 5926
 
5609 5927
 					$bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew));
5610 5928
 					$is_first = false;
@@ -5613,8 +5931,9 @@  discard block
 block discarded – undo
5613 5931
 
5614 5932
 					if ($deco_len > 0)
5615 5933
 					{
5616
-						for ($i = $deco_len; $i > $idx; $i--)
5617
-							$decoded[$i] = $decoded[($i - 1)];
5934
+						for ($i = $deco_len; $i > $idx; $i--) {
5935
+													$decoded[$i] = $decoded[($i - 1)];
5936
+						}
5618 5937
 					}
5619 5938
 					$decoded[$idx++] = $char;
5620 5939
 				}
@@ -5622,24 +5941,29 @@  discard block
 block discarded – undo
5622 5941
 				foreach ($decoded as $k => $v)
5623 5942
 				{
5624 5943
 					// 7bit are transferred literally
5625
-					if ($v < 128)
5626
-						$output .= chr($v);
5944
+					if ($v < 128) {
5945
+											$output .= chr($v);
5946
+					}
5627 5947
 
5628 5948
 					// 2 bytes
5629
-					elseif ($v < (1 << 11))
5630
-						$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5949
+					elseif ($v < (1 << 11)) {
5950
+											$output .= chr(192+($v >> 6)) . chr(128+($v & 63));
5951
+					}
5631 5952
 
5632 5953
 					// 3 bytes
5633
-					elseif ($v < (1 << 16))
5634
-						$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5954
+					elseif ($v < (1 << 16)) {
5955
+											$output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5956
+					}
5635 5957
 
5636 5958
 					// 4 bytes
5637
-					elseif ($v < (1 << 21))
5638
-						$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5959
+					elseif ($v < (1 << 21)) {
5960
+											$output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63));
5961
+					}
5639 5962
 
5640 5963
 					//  'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k
5641
-					else
5642
-						$output .= $safe_char;
5964
+					else {
5965
+											$output .= $safe_char;
5966
+					}
5643 5967
 				}
5644 5968
 
5645 5969
 				$output_parts[] = $output;
@@ -5734,8 +6058,7 @@  discard block
 block discarded – undo
5734 6058
 
5735 6059
 		$strlen = 'mb_strlen';
5736 6060
 		$substr = 'mb_substr';
5737
-	}
5738
-	else
6061
+	} else
5739 6062
 	{
5740 6063
 		$strlen = $smcFunc['strlen'];
5741 6064
 		$substr = $smcFunc['substr'];
@@ -5749,20 +6072,21 @@  discard block
 block discarded – undo
5749 6072
 
5750 6073
 		$first = $substr($string, 0, 1);
5751 6074
 
5752
-		if (empty($index[$first]))
5753
-			$index[$first] = array();
6075
+		if (empty($index[$first])) {
6076
+					$index[$first] = array();
6077
+		}
5754 6078
 
5755 6079
 		if ($strlen($string) > 1)
5756 6080
 		{
5757 6081
 			// Sanity check on recursion
5758
-			if ($depth > 99)
5759
-				$index[$first][$substr($string, 1)] = '';
5760
-
5761
-			else
5762
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6082
+			if ($depth > 99) {
6083
+							$index[$first][$substr($string, 1)] = '';
6084
+			} else {
6085
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6086
+			}
6087
+		} else {
6088
+					$index[$first][''] = '';
5763 6089
 		}
5764
-		else
5765
-			$index[$first][''] = '';
5766 6090
 
5767 6091
 		$depth--;
5768 6092
 		return $index;
@@ -5785,9 +6109,9 @@  discard block
 block discarded – undo
5785 6109
 			$key_regex = preg_quote($key, $delim);
5786 6110
 			$new_key = $key;
5787 6111
 
5788
-			if (empty($value))
5789
-				$sub_regex = '';
5790
-			else
6112
+			if (empty($value)) {
6113
+							$sub_regex = '';
6114
+			} else
5791 6115
 			{
5792 6116
 				$sub_regex = $index_to_regex($value, $delim);
5793 6117
 
@@ -5795,22 +6119,22 @@  discard block
 block discarded – undo
5795 6119
 				{
5796 6120
 					$new_key_array = explode('(?'.'>', $sub_regex);
5797 6121
 					$new_key .= $new_key_array[0];
6122
+				} else {
6123
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
5798 6124
 				}
5799
-				else
5800
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
5801 6125
 			}
5802 6126
 
5803
-			if ($depth > 1)
5804
-				$regex[$new_key] = $key_regex . $sub_regex;
5805
-			else
6127
+			if ($depth > 1) {
6128
+							$regex[$new_key] = $key_regex . $sub_regex;
6129
+			} else
5806 6130
 			{
5807 6131
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
5808 6132
 				{
5809 6133
 					$regex[$new_key] = $key_regex . $sub_regex;
5810 6134
 					unset($index[$key]);
6135
+				} else {
6136
+									break;
5811 6137
 				}
5812
-				else
5813
-					break;
5814 6138
 			}
5815 6139
 		}
5816 6140
 
@@ -5819,10 +6143,11 @@  discard block
 block discarded – undo
5819 6143
 			$l1 = $strlen($k1);
5820 6144
 			$l2 = $strlen($k2);
5821 6145
 
5822
-			if ($l1 == $l2)
5823
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
5824
-			else
5825
-				return $l1 > $l2 ? -1 : 1;
6146
+			if ($l1 == $l2) {
6147
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6148
+			} else {
6149
+							return $l1 > $l2 ? -1 : 1;
6150
+			}
5826 6151
 		});
5827 6152
 
5828 6153
 		$depth--;
@@ -5833,15 +6158,18 @@  discard block
 block discarded – undo
5833 6158
 	$index = array();
5834 6159
 	$regexes = array();
5835 6160
 
5836
-	foreach ($strings as $string)
5837
-		$index = $add_string_to_index($string, $index);
6161
+	foreach ($strings as $string) {
6162
+			$index = $add_string_to_index($string, $index);
6163
+	}
5838 6164
 
5839
-	while (!empty($index))
5840
-		$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6165
+	while (!empty($index)) {
6166
+			$regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6167
+	}
5841 6168
 
5842 6169
 	// Restore PHP's internal character encoding to whatever it was originally
5843
-	if (!empty($current_encoding))
5844
-		mb_internal_encoding($current_encoding);
6170
+	if (!empty($current_encoding)) {
6171
+			mb_internal_encoding($current_encoding);
6172
+	}
5845 6173
 
5846 6174
 	return $regexes;
5847 6175
 }
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +979 added lines, -717 removed lines patch added patch discarded remove patch
@@ -66,11 +66,14 @@  discard block
 block discarded – undo
66 66
 	ini_set('default_socket_timeout', 900);
67 67
 }
68 68
 // Clean the upgrade path if this is from the client.
69
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
70
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
69
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
70
+	for ($i = 1;
71
+}
72
+$i < $_SERVER['argc']; $i++)
71 73
 	{
72
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
73
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
74
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
75
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
76
+		}
74 77
 	}
75 78
 
76 79
 // Are we from the client?
@@ -78,9 +81,9 @@  discard block
 block discarded – undo
78 81
 {
79 82
 	$command_line = true;
80 83
 	$disable_security = 1;
81
-}
82
-else
84
+} else {
83 85
 	$command_line = false;
86
+}
84 87
 
85 88
 // Load this now just because we can.
86 89
 require_once($upgrade_path . '/Settings.php');
@@ -95,10 +98,12 @@  discard block
 block discarded – undo
95 98
 	$upcontext['user'] = unserialize(base64_decode($upgradeData));
96 99
 
97 100
 	// Check for sensible values.
98
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
99
-		$upcontext['user']['started'] = time();
100
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
101
-		$upcontext['user']['updated'] = 0;
101
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
102
+			$upcontext['user']['started'] = time();
103
+	}
104
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
105
+			$upcontext['user']['updated'] = 0;
106
+	}
102 107
 
103 108
 	$upcontext['started'] = $upcontext['user']['started'];
104 109
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -161,8 +166,9 @@  discard block
 block discarded – undo
161 166
 		{
162 167
 			$word = trim($word, '-_\'');
163 168
 
164
-			if ($word != '')
165
-				$returned_words[] = substr($word, 0, 20);
169
+			if ($word != '') {
170
+							$returned_words[] = substr($word, 0, 20);
171
+			}
166 172
 		}
167 173
 
168 174
 		return array_unique($returned_words);
@@ -189,8 +195,9 @@  discard block
 block discarded – undo
189 195
 {
190 196
 	function md5_hmac($data, $key)
191 197
 	{
192
-		if (strlen($key) > 64)
193
-			$key = pack('H*', md5($key));
198
+		if (strlen($key) > 64) {
199
+					$key = pack('H*', md5($key));
200
+		}
194 201
 		$key = str_pad($key, 64, chr(0x00));
195 202
 
196 203
 		$k_ipad = $key ^ str_repeat(chr(0x36), 64);
@@ -201,8 +208,9 @@  discard block
 block discarded – undo
201 208
 }
202 209
 
203 210
 // Don't do security check if on Yabbse
204
-if (!isset($modSettings['smfVersion']))
211
+if (!isset($modSettings['smfVersion'])) {
205 212
 	$disable_security = true;
213
+}
206 214
 
207 215
 // This only exists if we're on SMF ;)
208 216
 if (isset($modSettings['smfVersion']))
@@ -220,8 +228,9 @@  discard block
 block discarded – undo
220 228
 			'db_error_skip' => true,
221 229
 		)
222 230
 	);
223
-	while ($row = $smcFunc['db_fetch_assoc']($request))
224
-		$modSettings[$row['variable']] = $row['value'];
231
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
232
+			$modSettings[$row['variable']] = $row['value'];
233
+	}
225 234
 	$smcFunc['db_free_result']($request);
226 235
 }
227 236
 
@@ -231,10 +240,12 @@  discard block
 block discarded – undo
231 240
 	$modSettings['theme_url'] = 'Themes/default';
232 241
 	$modSettings['images_url'] = 'Themes/default/images';
233 242
 }
234
-if (!isset($settings['default_theme_url']))
243
+if (!isset($settings['default_theme_url'])) {
235 244
 	$settings['default_theme_url'] = $modSettings['theme_url'];
236
-if (!isset($settings['default_theme_dir']))
245
+}
246
+if (!isset($settings['default_theme_dir'])) {
237 247
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
248
+}
238 249
 
239 250
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
240 251
 // Default title...
@@ -252,13 +263,15 @@  discard block
 block discarded – undo
252 263
 	$support_js = $upcontext['upgrade_status']['js'];
253 264
 
254 265
 	// Only set this if the upgrader status says so.
255
-	if (empty($is_debug))
256
-		$is_debug = $upcontext['upgrade_status']['debug'];
266
+	if (empty($is_debug)) {
267
+			$is_debug = $upcontext['upgrade_status']['debug'];
268
+	}
257 269
 
258 270
 	// Load the language.
259
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
260
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
261
-}
271
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
272
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
273
+	}
274
+	}
262 275
 // Set the defaults.
263 276
 else
264 277
 {
@@ -276,15 +289,18 @@  discard block
 block discarded – undo
276 289
 }
277 290
 
278 291
 // If this isn't the first stage see whether they are logging in and resuming.
279
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
292
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
280 293
 	checkLogin();
294
+}
281 295
 
282
-if ($command_line)
296
+if ($command_line) {
283 297
 	cmdStep0();
298
+}
284 299
 
285 300
 // Don't error if we're using xml.
286
-if (isset($_GET['xml']))
301
+if (isset($_GET['xml'])) {
287 302
 	$upcontext['return_error'] = true;
303
+}
288 304
 
289 305
 // Loop through all the steps doing each one as required.
290 306
 $upcontext['overall_percent'] = 0;
@@ -305,10 +321,11 @@  discard block
 block discarded – undo
305 321
 		}
306 322
 
307 323
 		// Call the step and if it returns false that means pause!
308
-		if (function_exists($step[2]) && $step[2]() === false)
309
-			break;
310
-		elseif (function_exists($step[2]))
311
-			$upcontext['current_step']++;
324
+		if (function_exists($step[2]) && $step[2]() === false) {
325
+					break;
326
+		} elseif (function_exists($step[2])) {
327
+					$upcontext['current_step']++;
328
+		}
312 329
 	}
313 330
 	$upcontext['overall_percent'] += $step[3];
314 331
 }
@@ -347,17 +364,18 @@  discard block
 block discarded – undo
347 364
 		// This should not happen my dear... HELP ME DEVELOPERS!!
348 365
 		if (!empty($command_line))
349 366
 		{
350
-			if (function_exists('debug_print_backtrace'))
351
-				debug_print_backtrace();
367
+			if (function_exists('debug_print_backtrace')) {
368
+							debug_print_backtrace();
369
+			}
352 370
 
353 371
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
354 372
 			flush();
355 373
 			die();
356 374
 		}
357 375
 
358
-		if (!isset($_GET['xml']))
359
-			template_upgrade_above();
360
-		else
376
+		if (!isset($_GET['xml'])) {
377
+					template_upgrade_above();
378
+		} else
361 379
 		{
362 380
 			header('Content-Type: text/xml; charset=UTF-8');
363 381
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -379,21 +397,24 @@  discard block
 block discarded – undo
379 397
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(safe_serialize($upcontext['upgrade_status']));
380 398
 
381 399
 			// Custom stuff to pass back?
382
-			if (!empty($upcontext['query_string']))
383
-				$upcontext['form_url'] .= $upcontext['query_string'];
400
+			if (!empty($upcontext['query_string'])) {
401
+							$upcontext['form_url'] .= $upcontext['query_string'];
402
+			}
384 403
 
385 404
 			call_user_func('template_' . $upcontext['sub_template']);
386 405
 		}
387 406
 
388 407
 		// Was there an error?
389
-		if (!empty($upcontext['forced_error_message']))
390
-			echo $upcontext['forced_error_message'];
408
+		if (!empty($upcontext['forced_error_message'])) {
409
+					echo $upcontext['forced_error_message'];
410
+		}
391 411
 
392 412
 		// Show the footer.
393
-		if (!isset($_GET['xml']))
394
-			template_upgrade_below();
395
-		else
396
-			template_xml_below();
413
+		if (!isset($_GET['xml'])) {
414
+					template_upgrade_below();
415
+		} else {
416
+					template_xml_below();
417
+		}
397 418
 	}
398 419
 
399 420
 
@@ -405,15 +426,19 @@  discard block
 block discarded – undo
405 426
 		$seconds = intval($active % 60);
406 427
 
407 428
 		$totalTime = '';
408
-		if ($hours > 0)
409
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
410
-		if ($minutes > 0)
411
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
412
-		if ($seconds > 0)
413
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
429
+		if ($hours > 0) {
430
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
431
+		}
432
+		if ($minutes > 0) {
433
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
434
+		}
435
+		if ($seconds > 0) {
436
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
437
+		}
414 438
 
415
-		if (!empty($totalTime))
416
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
439
+		if (!empty($totalTime)) {
440
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
441
+		}
417 442
 	}
418 443
 
419 444
 	// Bang - gone!
@@ -426,8 +451,9 @@  discard block
 block discarded – undo
426 451
 	global $upgradeurl, $upcontext, $command_line;
427 452
 
428 453
 	// Command line users can't be redirected.
429
-	if ($command_line)
430
-		upgradeExit(true);
454
+	if ($command_line) {
455
+			upgradeExit(true);
456
+	}
431 457
 
432 458
 	// Are we providing the core info?
433 459
 	if ($addForm)
@@ -450,19 +476,22 @@  discard block
 block discarded – undo
450 476
 	global $modSettings, $sourcedir, $smcFunc;
451 477
 
452 478
 	// Do the non-SSI stuff...
453
-	if (function_exists('set_magic_quotes_runtime'))
454
-		@set_magic_quotes_runtime(0);
479
+	if (function_exists('set_magic_quotes_runtime')) {
480
+			@set_magic_quotes_runtime(0);
481
+	}
455 482
 
456 483
 	error_reporting(E_ALL);
457 484
 	define('SMF', 1);
458 485
 
459 486
 	// Start the session.
460
-	if (@ini_get('session.save_handler') == 'user')
461
-		@ini_set('session.save_handler', 'files');
487
+	if (@ini_get('session.save_handler') == 'user') {
488
+			@ini_set('session.save_handler', 'files');
489
+	}
462 490
 	@session_start();
463 491
 
464
-	if (empty($smcFunc))
465
-		$smcFunc = array();
492
+	if (empty($smcFunc)) {
493
+			$smcFunc = array();
494
+	}
466 495
 
467 496
 	// We need this for authentication and some upgrade code
468 497
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -475,8 +504,9 @@  discard block
 block discarded – undo
475 504
 	initialize_inputs();
476 505
 
477 506
 	// Get the database going!
478
-	if (empty($db_type))
479
-		$db_type = 'mysql';
507
+	if (empty($db_type)) {
508
+			$db_type = 'mysql';
509
+	}
480 510
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
481 511
 	{
482 512
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -485,17 +515,19 @@  discard block
 block discarded – undo
485 515
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
486 516
 
487 517
 		// Oh dear god!!
488
-		if ($db_connection === null)
489
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
518
+		if ($db_connection === null) {
519
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
520
+		}
490 521
 
491
-		if (($db_type == 'mysql' || $db_type == 'mysqli') && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
492
-			$smcFunc['db_query']('', '
522
+		if (($db_type == 'mysql' || $db_type == 'mysqli') && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
523
+					$smcFunc['db_query']('', '
493 524
 			SET NAMES {string:db_character_set}',
494 525
 			array(
495 526
 				'db_error_skip' => true,
496 527
 				'db_character_set' => $db_character_set,
497 528
 			)
498 529
 		);
530
+		}
499 531
 
500 532
 		// Load the modSettings data...
501 533
 		$request = $smcFunc['db_query']('', '
@@ -506,11 +538,11 @@  discard block
 block discarded – undo
506 538
 			)
507 539
 		);
508 540
 		$modSettings = array();
509
-		while ($row = $smcFunc['db_fetch_assoc']($request))
510
-			$modSettings[$row['variable']] = $row['value'];
541
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
542
+					$modSettings[$row['variable']] = $row['value'];
543
+		}
511 544
 		$smcFunc['db_free_result']($request);
512
-	}
513
-	else
545
+	} else
514 546
 	{
515 547
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
516 548
 	}
@@ -524,9 +556,10 @@  discard block
 block discarded – undo
524 556
 		cleanRequest();
525 557
 	}
526 558
 
527
-	if (!isset($_GET['substep']))
528
-		$_GET['substep'] = 0;
529
-}
559
+	if (!isset($_GET['substep'])) {
560
+			$_GET['substep'] = 0;
561
+	}
562
+	}
530 563
 
531 564
 function initialize_inputs()
532 565
 {
@@ -564,8 +597,9 @@  discard block
 block discarded – undo
564 597
 		$dh = opendir(dirname(__FILE__));
565 598
 		while ($file = readdir($dh))
566 599
 		{
567
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
568
-				@unlink(dirname(__FILE__) . '/' . $file);
600
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
601
+							@unlink(dirname(__FILE__) . '/' . $file);
602
+			}
569 603
 		}
570 604
 		closedir($dh);
571 605
 
@@ -595,8 +629,9 @@  discard block
 block discarded – undo
595 629
 	{
596 630
 		$upcontext['remote_files_available'] = false;
597 631
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
598
-		if ($test)
599
-			$upcontext['remote_files_available'] = true;
632
+		if ($test) {
633
+					$upcontext['remote_files_available'] = true;
634
+		}
600 635
 		@fclose($test);
601 636
 	}
602 637
 
@@ -604,8 +639,9 @@  discard block
 block discarded – undo
604 639
 	$temp = 'upgrade_php?step';
605 640
 	while (strlen($temp) > 4)
606 641
 	{
607
-		if (isset($_GET[$temp]))
608
-			unset($_GET[$temp]);
642
+		if (isset($_GET[$temp])) {
643
+					unset($_GET[$temp]);
644
+		}
609 645
 		$temp = substr($temp, 1);
610 646
 	}
611 647
 
@@ -634,29 +670,36 @@  discard block
 block discarded – undo
634 670
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $type . '.sql');
635 671
 
636 672
 	// Need legacy scripts?
637
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
638
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $type . '.sql');
639
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
640
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
641
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
642
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
673
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
674
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $type . '.sql');
675
+	}
676
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
677
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
678
+	}
679
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
680
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
681
+	}
643 682
 
644 683
 	// This needs to exist!
645
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
646
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
647
-	else
648
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
684
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
685
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
686
+	} else {
687
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
688
+	}
649 689
 
650
-	if (!$check)
651
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
690
+	if (!$check) {
691
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
652 692
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
693
+	}
653 694
 
654 695
 	// Do they meet the install requirements?
655
-	if (!php_version_check())
656
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
696
+	if (!php_version_check()) {
697
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
698
+	}
657 699
 
658
-	if (!db_version_check())
659
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
700
+	if (!db_version_check()) {
701
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
702
+	}
660 703
 
661 704
 	// Do some checks to make sure they have proper privileges
662 705
 	db_extend('packages');
@@ -671,14 +714,16 @@  discard block
 block discarded – undo
671 714
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
672 715
 
673 716
 	// Sorry... we need CREATE, ALTER and DROP
674
-	if (!$create || !$alter || !$drop)
675
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
717
+	if (!$create || !$alter || !$drop) {
718
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
719
+	}
676 720
 
677 721
 	// Do a quick version spot check.
678 722
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
679 723
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
680
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
681
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
724
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
725
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
726
+	}
682 727
 
683 728
 	// What absolutely needs to be writable?
684 729
 	$writable_files = array(
@@ -700,12 +745,13 @@  discard block
 block discarded – undo
700 745
 	quickFileWritable($custom_av_dir);
701 746
 
702 747
 	// Are we good now?
703
-	if (!is_writable($custom_av_dir))
704
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
705
-	elseif ($need_settings_update)
748
+	if (!is_writable($custom_av_dir)) {
749
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
750
+	} elseif ($need_settings_update)
706 751
 	{
707
-		if (!function_exists('cache_put_data'))
708
-			require_once($sourcedir . '/Load.php');
752
+		if (!function_exists('cache_put_data')) {
753
+					require_once($sourcedir . '/Load.php');
754
+		}
709 755
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
710 756
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
711 757
 	}
@@ -714,28 +760,33 @@  discard block
 block discarded – undo
714 760
 
715 761
 	// Check the cache directory.
716 762
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
717
-	if (!file_exists($cachedir_temp))
718
-		@mkdir($cachedir_temp);
719
-	if (!file_exists($cachedir_temp))
720
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
721
-
722
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
723
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
724
-	elseif (!isset($_GET['skiplang']))
763
+	if (!file_exists($cachedir_temp)) {
764
+			@mkdir($cachedir_temp);
765
+	}
766
+	if (!file_exists($cachedir_temp)) {
767
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
768
+	}
769
+
770
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
771
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
772
+	} elseif (!isset($_GET['skiplang']))
725 773
 	{
726 774
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
727 775
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
728 776
 
729
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
730
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
777
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
778
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
779
+		}
731 780
 	}
732 781
 
733
-	if (!makeFilesWritable($writable_files))
734
-		return false;
782
+	if (!makeFilesWritable($writable_files)) {
783
+			return false;
784
+	}
735 785
 
736 786
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
737
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
738
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
787
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
788
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
789
+	}
739 790
 
740 791
 	// Upgrade the agreement.
741 792
 	elseif (isset($modSettings['agreement']))
@@ -746,8 +797,8 @@  discard block
 block discarded – undo
746 797
 	}
747 798
 
748 799
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
749
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
750
-		$upcontext['warning'] = '
800
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
801
+			$upcontext['warning'] = '
751 802
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
752 803
 			<ul>
753 804
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -755,10 +806,12 @@  discard block
 block discarded – undo
755 806
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
756 807
 			</ul>
757 808
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="http://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
809
+	}
758 810
 
759 811
 	// Either we're logged in or we're going to present the login.
760
-	if (checkLogin())
761
-		return true;
812
+	if (checkLogin()) {
813
+			return true;
814
+	}
762 815
 
763 816
 	$upcontext += createToken('login');
764 817
 
@@ -772,15 +825,17 @@  discard block
 block discarded – undo
772 825
 	global $smcFunc, $db_type, $support_js;
773 826
 
774 827
 	// Don't bother if the security is disabled.
775
-	if ($disable_security)
776
-		return true;
828
+	if ($disable_security) {
829
+			return true;
830
+	}
777 831
 
778 832
 	// Are we trying to login?
779 833
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
780 834
 	{
781 835
 		// If we've disabled security pick a suitable name!
782
-		if (empty($_POST['user']))
783
-			$_POST['user'] = 'Administrator';
836
+		if (empty($_POST['user'])) {
837
+					$_POST['user'] = 'Administrator';
838
+		}
784 839
 
785 840
 		// Before 2.0 these column names were different!
786 841
 		$oldDB = false;
@@ -795,16 +850,17 @@  discard block
 block discarded – undo
795 850
 					'db_error_skip' => true,
796 851
 				)
797 852
 			);
798
-			if ($smcFunc['db_num_rows']($request) != 0)
799
-				$oldDB = true;
853
+			if ($smcFunc['db_num_rows']($request) != 0) {
854
+							$oldDB = true;
855
+			}
800 856
 			$smcFunc['db_free_result']($request);
801 857
 		}
802 858
 
803 859
 		// Get what we believe to be their details.
804 860
 		if (!$disable_security)
805 861
 		{
806
-			if ($oldDB)
807
-				$request = $smcFunc['db_query']('', '
862
+			if ($oldDB) {
863
+							$request = $smcFunc['db_query']('', '
808 864
 					SELECT id_member, memberName AS member_name, passwd, id_group,
809 865
 					additionalGroups AS additional_groups, lngfile
810 866
 					FROM {db_prefix}members
@@ -814,8 +870,8 @@  discard block
 block discarded – undo
814 870
 						'db_error_skip' => true,
815 871
 					)
816 872
 				);
817
-			else
818
-				$request = $smcFunc['db_query']('', '
873
+			} else {
874
+							$request = $smcFunc['db_query']('', '
819 875
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
820 876
 					FROM {db_prefix}members
821 877
 					WHERE member_name = {string:member_name}',
@@ -824,6 +880,7 @@  discard block
 block discarded – undo
824 880
 						'db_error_skip' => true,
825 881
 					)
826 882
 				);
883
+			}
827 884
 			if ($smcFunc['db_num_rows']($request) != 0)
828 885
 			{
829 886
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -831,13 +888,14 @@  discard block
 block discarded – undo
831 888
 				$groups = explode(',', $addGroups);
832 889
 				$groups[] = $id_group;
833 890
 
834
-				foreach ($groups as $k => $v)
835
-					$groups[$k] = (int) $v;
891
+				foreach ($groups as $k => $v) {
892
+									$groups[$k] = (int) $v;
893
+				}
836 894
 
837 895
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
896
+			} else {
897
+							$upcontext['username_incorrect'] = true;
838 898
 			}
839
-			else
840
-				$upcontext['username_incorrect'] = true;
841 899
 			$smcFunc['db_free_result']($request);
842 900
 		}
843 901
 		$upcontext['username'] = $_POST['user'];
@@ -847,13 +905,14 @@  discard block
 block discarded – undo
847 905
 		{
848 906
 			$upcontext['upgrade_status']['js'] = 1;
849 907
 			$support_js = 1;
908
+		} else {
909
+					$support_js = 0;
850 910
 		}
851
-		else
852
-			$support_js = 0;
853 911
 
854 912
 		// Note down the version we are coming from.
855
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
856
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
913
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
914
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
915
+		}
857 916
 
858 917
 		// Didn't get anywhere?
859 918
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -887,15 +946,15 @@  discard block
 block discarded – undo
887 946
 							'db_error_skip' => true,
888 947
 						)
889 948
 					);
890
-					if ($smcFunc['db_num_rows']($request) == 0)
891
-						return throw_error('You need to be an admin to perform an upgrade!');
949
+					if ($smcFunc['db_num_rows']($request) == 0) {
950
+											return throw_error('You need to be an admin to perform an upgrade!');
951
+					}
892 952
 					$smcFunc['db_free_result']($request);
893 953
 				}
894 954
 
895 955
 				$upcontext['user']['id'] = $id_member;
896 956
 				$upcontext['user']['name'] = $name;
897
-			}
898
-			else
957
+			} else
899 958
 			{
900 959
 				$upcontext['user']['id'] = 1;
901 960
 				$upcontext['user']['name'] = 'Administrator';
@@ -911,11 +970,11 @@  discard block
 block discarded – undo
911 970
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
912 971
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
913 972
 
914
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
915
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
916
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
917
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
918
-				else
973
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
974
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
975
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
976
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
977
+				} else
919 978
 				{
920 979
 					// Set this as the new language.
921 980
 					$upcontext['language'] = $user_language;
@@ -959,15 +1018,17 @@  discard block
 block discarded – undo
959 1018
 	unset($member_columns);
960 1019
 
961 1020
 	// If we've not submitted then we're done.
962
-	if (empty($_POST['upcont']))
963
-		return false;
1021
+	if (empty($_POST['upcont'])) {
1022
+			return false;
1023
+	}
964 1024
 
965 1025
 	require_once($sourcedir . '/Subs-Admin.php');
966 1026
 	updateSettingsFile(array('image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\''));
967 1027
 
968 1028
 	// Should we update the $db_type value?
969
-	if ($upcontext['update_db_type_to_mysqli'])
970
-		updateSettingsFile(array('db_type' => '\'mysqli\''));
1029
+	if ($upcontext['update_db_type_to_mysqli']) {
1030
+			updateSettingsFile(array('db_type' => '\'mysqli\''));
1031
+	}
971 1032
 
972 1033
 	// Firstly, if they're enabling SM stat collection just do it.
973 1034
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
@@ -982,25 +1043,26 @@  discard block
 block discarded – undo
982 1043
 			fwrite($fp, $out);
983 1044
 
984 1045
 			$return_data = '';
985
-			while (!feof($fp))
986
-				$return_data .= fgets($fp, 128);
1046
+			while (!feof($fp)) {
1047
+							$return_data .= fgets($fp, 128);
1048
+			}
987 1049
 
988 1050
 			fclose($fp);
989 1051
 
990 1052
 			// Get the unique site ID.
991 1053
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
992 1054
 
993
-			if (!empty($ID[1]))
994
-				$smcFunc['db_insert']('replace',
1055
+			if (!empty($ID[1])) {
1056
+							$smcFunc['db_insert']('replace',
995 1057
 					$db_prefix . 'settings',
996 1058
 					array('variable' => 'string', 'value' => 'string'),
997 1059
 					array('allow_sm_stats', $ID[1]),
998 1060
 					array('variable')
999 1061
 				);
1062
+			}
1000 1063
 		}
1001
-	}
1002
-	else
1003
-		$smcFunc['db_query']('', '
1064
+	} else {
1065
+			$smcFunc['db_query']('', '
1004 1066
 			DELETE FROM {db_prefix}settings
1005 1067
 			WHERE variable = {string:allow_sm_stats}',
1006 1068
 			array(
@@ -1008,6 +1070,7 @@  discard block
 block discarded – undo
1008 1070
 				'db_error_skip' => true,
1009 1071
 			)
1010 1072
 		);
1073
+	}
1011 1074
 
1012 1075
 	// Deleting old karma stuff?
1013 1076
 	if (!empty($_POST['delete_karma']))
@@ -1022,20 +1085,22 @@  discard block
 block discarded – undo
1022 1085
 		);
1023 1086
 
1024 1087
 		// Cleaning up old karma member settings.
1025
-		if ($upcontext['karma_installed']['good'])
1026
-			$smcFunc['db_query']('', '
1088
+		if ($upcontext['karma_installed']['good']) {
1089
+					$smcFunc['db_query']('', '
1027 1090
 				ALTER TABLE {db_prefix}members
1028 1091
 				DROP karma_good',
1029 1092
 				array()
1030 1093
 			);
1094
+		}
1031 1095
 
1032 1096
 		// Does karma bad was enable?
1033
-		if ($upcontext['karma_installed']['bad'])
1034
-			$smcFunc['db_query']('', '
1097
+		if ($upcontext['karma_installed']['bad']) {
1098
+					$smcFunc['db_query']('', '
1035 1099
 				ALTER TABLE {db_prefix}members
1036 1100
 				DROP karma_bad',
1037 1101
 				array()
1038 1102
 			);
1103
+		}
1039 1104
 
1040 1105
 		// Cleaning up old karma permissions.
1041 1106
 		$smcFunc['db_query']('', '
@@ -1048,18 +1113,20 @@  discard block
 block discarded – undo
1048 1113
 	}
1049 1114
 
1050 1115
 	// Emptying the error log?
1051
-	if (!empty($_POST['empty_error']))
1052
-		$smcFunc['db_query']('truncate_table', '
1116
+	if (!empty($_POST['empty_error'])) {
1117
+			$smcFunc['db_query']('truncate_table', '
1053 1118
 			TRUNCATE {db_prefix}log_errors',
1054 1119
 			array(
1055 1120
 			)
1056 1121
 		);
1122
+	}
1057 1123
 
1058 1124
 	$changes = array();
1059 1125
 
1060 1126
 	// If we're overriding the language follow it through.
1061
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1062
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1127
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1128
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1129
+	}
1063 1130
 
1064 1131
 	if (!empty($_POST['maint']))
1065 1132
 	{
@@ -1071,37 +1138,42 @@  discard block
 block discarded – undo
1071 1138
 		{
1072 1139
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1073 1140
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1074
-		}
1075
-		else
1141
+		} else
1076 1142
 		{
1077 1143
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1078 1144
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1079 1145
 		}
1080 1146
 	}
1081 1147
 
1082
-	if ($command_line)
1083
-		echo ' * Updating Settings.php...';
1148
+	if ($command_line) {
1149
+			echo ' * Updating Settings.php...';
1150
+	}
1084 1151
 
1085 1152
 	// Backup the current one first.
1086 1153
 	copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
1087 1154
 
1088 1155
 	// Fix some old paths.
1089
-	if (substr($boarddir, 0, 1) == '.')
1090
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1156
+	if (substr($boarddir, 0, 1) == '.') {
1157
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1158
+	}
1091 1159
 
1092
-	if (substr($sourcedir, 0, 1) == '.')
1093
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1160
+	if (substr($sourcedir, 0, 1) == '.') {
1161
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1162
+	}
1094 1163
 
1095
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1096
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1164
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1165
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1166
+	}
1097 1167
 
1098 1168
 	// Not had the database type added before?
1099
-	if (empty($db_type))
1100
-		$changes['db_type'] = 'mysql';
1169
+	if (empty($db_type)) {
1170
+			$changes['db_type'] = 'mysql';
1171
+	}
1101 1172
 
1102 1173
 	// For now we offer a option, this may change in future versions when mysql is completely removed.
1103
-	if (!empty($_POST['convertMysql']) && $db_type == 'mysql')
1104
-		$changes['db_type'] = '\'mysqli\'';
1174
+	if (!empty($_POST['convertMysql']) && $db_type == 'mysql') {
1175
+			$changes['db_type'] = '\'mysqli\'';
1176
+	}
1105 1177
 
1106 1178
 	// If they have a "host:port" setup for the host, split that into separate values
1107 1179
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1112,28 +1184,31 @@  discard block
 block discarded – undo
1112 1184
 		$changes['db_server'] = '\'' . $db_server . '\'';
1113 1185
 
1114 1186
 		// Only set this if we're not using the default port
1115
-		if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port'))
1116
-			$changes['db_port'] = (int) $db_port;
1117
-	}
1118
-	elseif (!empty($db_port))
1187
+		if ($db_port != ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) {
1188
+					$changes['db_port'] = (int) $db_port;
1189
+		}
1190
+	} elseif (!empty($db_port))
1119 1191
 	{
1120 1192
 		// If db_port is set and is the same as the default, set it to ''
1121 1193
 		if ($db_type == 'mysql' || $db_type == 'mysqli')
1122 1194
 		{
1123
-			if ($db_port == ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port'))
1124
-				$changes['db_port'] = '\'\'';
1125
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1126
-				$changes['db_port'] = '\'\'';
1195
+			if ($db_port == ini_get('mysql' . ($db_type == 'mysqli' || !empty($_POST['convertMysql']) ? 'i' : '') . '.default_port')) {
1196
+							$changes['db_port'] = '\'\'';
1197
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1198
+							$changes['db_port'] = '\'\'';
1199
+			}
1127 1200
 		}
1128 1201
 	}
1129 1202
 
1130 1203
 	// Maybe we haven't had this option yet?
1131
-	if (empty($packagesdir))
1132
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1204
+	if (empty($packagesdir)) {
1205
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1206
+	}
1133 1207
 
1134 1208
 	// Add support for $tasksdir var.
1135
-	if (empty($tasksdir))
1136
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1209
+	if (empty($tasksdir)) {
1210
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1211
+	}
1137 1212
 
1138 1213
 	// @todo Maybe change the cookie name if going to 1.1, too?
1139 1214
 
@@ -1178,8 +1253,7 @@  discard block
 block discarded – undo
1178 1253
 			$found_old = true;
1179 1254
 			// Replace the old line with the new code
1180 1255
 			$settings_file = str_replace('$db_last_error = ' . $db_last_error . ';', $error_catching_header . $error_catching, $settings_file);
1181
-		}
1182
-		else
1256
+		} else
1183 1257
 		{
1184 1258
 			$found_old = false;
1185 1259
 			// We want the comments as well as the code...
@@ -1210,8 +1284,9 @@  discard block
 block discarded – undo
1210 1284
 		fclose($file);
1211 1285
 	}
1212 1286
 
1213
-	if ($command_line)
1214
-		echo ' Successful.' . "\n";
1287
+	if ($command_line) {
1288
+			echo ' Successful.' . "\n";
1289
+	}
1215 1290
 
1216 1291
 	// Are we doing debug?
1217 1292
 	if (isset($_POST['debug']))
@@ -1221,8 +1296,9 @@  discard block
 block discarded – undo
1221 1296
 	}
1222 1297
 
1223 1298
 	// If we're not backing up then jump one.
1224
-	if (empty($_POST['backup']))
1225
-		$upcontext['current_step']++;
1299
+	if (empty($_POST['backup'])) {
1300
+			$upcontext['current_step']++;
1301
+	}
1226 1302
 
1227 1303
 	// If we've got here then let's proceed to the next step!
1228 1304
 	return true;
@@ -1237,8 +1313,9 @@  discard block
 block discarded – undo
1237 1313
 	$upcontext['page_title'] = 'Backup Database';
1238 1314
 
1239 1315
 	// Done it already - js wise?
1240
-	if (!empty($_POST['backup_done']))
1241
-		return true;
1316
+	if (!empty($_POST['backup_done'])) {
1317
+			return true;
1318
+	}
1242 1319
 
1243 1320
 	// Some useful stuff here.
1244 1321
 	db_extend();
@@ -1252,9 +1329,10 @@  discard block
 block discarded – undo
1252 1329
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1253 1330
 
1254 1331
 	$table_names = array();
1255
-	foreach ($tables as $table)
1256
-		if (substr($table, 0, 7) !== 'backup_')
1332
+	foreach ($tables as $table) {
1333
+			if (substr($table, 0, 7) !== 'backup_')
1257 1334
 			$table_names[] = $table;
1335
+	}
1258 1336
 
1259 1337
 	$upcontext['table_count'] = count($table_names);
1260 1338
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1264,12 +1342,14 @@  discard block
 block discarded – undo
1264 1342
 	$file_steps = $upcontext['table_count'];
1265 1343
 
1266 1344
 	// What ones have we already done?
1267
-	foreach ($table_names as $id => $table)
1268
-		if ($id < $_GET['substep'])
1345
+	foreach ($table_names as $id => $table) {
1346
+			if ($id < $_GET['substep'])
1269 1347
 			$upcontext['previous_tables'][] = $table;
1348
+	}
1270 1349
 
1271
-	if ($command_line)
1272
-		echo 'Backing Up Tables.';
1350
+	if ($command_line) {
1351
+			echo 'Backing Up Tables.';
1352
+	}
1273 1353
 
1274 1354
 	// If we don't support javascript we backup here.
1275 1355
 	if (!$support_js || isset($_GET['xml']))
@@ -1288,8 +1368,9 @@  discard block
 block discarded – undo
1288 1368
 			backupTable($table_names[$substep]);
1289 1369
 
1290 1370
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1291
-			if (isset($_GET['xml']))
1292
-				return upgradeExit();
1371
+			if (isset($_GET['xml'])) {
1372
+							return upgradeExit();
1373
+			}
1293 1374
 		}
1294 1375
 
1295 1376
 		if ($command_line)
@@ -1322,9 +1403,10 @@  discard block
 block discarded – undo
1322 1403
 
1323 1404
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1324 1405
 
1325
-	if ($command_line)
1326
-		echo ' done.';
1327
-}
1406
+	if ($command_line) {
1407
+			echo ' done.';
1408
+	}
1409
+	}
1328 1410
 
1329 1411
 // Step 2: Everything.
1330 1412
 function DatabaseChanges()
@@ -1333,8 +1415,9 @@  discard block
 block discarded – undo
1333 1415
 	global $upcontext, $support_js, $db_type;
1334 1416
 
1335 1417
 	// Have we just completed this?
1336
-	if (!empty($_POST['database_done']))
1337
-		return true;
1418
+	if (!empty($_POST['database_done'])) {
1419
+			return true;
1420
+	}
1338 1421
 
1339 1422
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1340 1423
 	$upcontext['page_title'] = 'Database Changes';
@@ -1351,15 +1434,16 @@  discard block
 block discarded – undo
1351 1434
 	);
1352 1435
 
1353 1436
 	// How many files are there in total?
1354
-	if (isset($_GET['filecount']))
1355
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1356
-	else
1437
+	if (isset($_GET['filecount'])) {
1438
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1439
+	} else
1357 1440
 	{
1358 1441
 		$upcontext['file_count'] = 0;
1359 1442
 		foreach ($files as $file)
1360 1443
 		{
1361
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1362
-				$upcontext['file_count']++;
1444
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1445
+							$upcontext['file_count']++;
1446
+			}
1363 1447
 		}
1364 1448
 	}
1365 1449
 
@@ -1369,9 +1453,9 @@  discard block
 block discarded – undo
1369 1453
 	$upcontext['cur_file_num'] = 0;
1370 1454
 	foreach ($files as $file)
1371 1455
 	{
1372
-		if ($did_not_do)
1373
-			$did_not_do--;
1374
-		else
1456
+		if ($did_not_do) {
1457
+					$did_not_do--;
1458
+		} else
1375 1459
 		{
1376 1460
 			$upcontext['cur_file_num']++;
1377 1461
 			$upcontext['cur_file_name'] = $file[0];
@@ -1398,12 +1482,13 @@  discard block
 block discarded – undo
1398 1482
 					// Flag to move on to the next.
1399 1483
 					$upcontext['completed_step'] = true;
1400 1484
 					// Did we complete the whole file?
1401
-					if ($nextFile)
1402
-						$upcontext['current_debug_item_num'] = -1;
1485
+					if ($nextFile) {
1486
+											$upcontext['current_debug_item_num'] = -1;
1487
+					}
1403 1488
 					return upgradeExit();
1489
+				} elseif ($support_js) {
1490
+									break;
1404 1491
 				}
1405
-				elseif ($support_js)
1406
-					break;
1407 1492
 			}
1408 1493
 			// Set the progress bar to be right as if we had - even if we hadn't...
1409 1494
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1428,8 +1513,9 @@  discard block
 block discarded – undo
1428 1513
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1429 1514
 
1430 1515
 	// Now it's nice to have some of the basic SMF source files.
1431
-	if (!isset($_GET['ssi']) && !$command_line)
1432
-		redirectLocation('&ssi=1');
1516
+	if (!isset($_GET['ssi']) && !$command_line) {
1517
+			redirectLocation('&ssi=1');
1518
+	}
1433 1519
 
1434 1520
 	$upcontext['sub_template'] = 'upgrade_complete';
1435 1521
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1445,14 +1531,16 @@  discard block
 block discarded – undo
1445 1531
 	// Are we in maintenance mode?
1446 1532
 	if (isset($upcontext['user']['main']))
1447 1533
 	{
1448
-		if ($command_line)
1449
-			echo ' * ';
1534
+		if ($command_line) {
1535
+					echo ' * ';
1536
+		}
1450 1537
 		$upcontext['removed_maintenance'] = true;
1451 1538
 		$changes['maintenance'] = $upcontext['user']['main'];
1452 1539
 	}
1453 1540
 	// Otherwise if somehow we are in 2 let's go to 1.
1454
-	elseif (!empty($maintenance) && $maintenance == 2)
1455
-		$changes['maintenance'] = 1;
1541
+	elseif (!empty($maintenance) && $maintenance == 2) {
1542
+			$changes['maintenance'] = 1;
1543
+	}
1456 1544
 
1457 1545
 	// Wipe this out...
1458 1546
 	$upcontext['user'] = array();
@@ -1468,9 +1556,9 @@  discard block
 block discarded – undo
1468 1556
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1469 1557
 
1470 1558
 	// Now is the perfect time to fetch the SM files.
1471
-	if ($command_line)
1472
-		cli_scheduled_fetchSMfiles();
1473
-	else
1559
+	if ($command_line) {
1560
+			cli_scheduled_fetchSMfiles();
1561
+	} else
1474 1562
 	{
1475 1563
 		require_once($sourcedir . '/ScheduledTasks.php');
1476 1564
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1478,8 +1566,9 @@  discard block
 block discarded – undo
1478 1566
 	}
1479 1567
 
1480 1568
 	// Log what we've done.
1481
-	if (empty($user_info['id']))
1482
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1569
+	if (empty($user_info['id'])) {
1570
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1571
+	}
1483 1572
 
1484 1573
 	// Log the action manually, so CLI still works.
1485 1574
 	$smcFunc['db_insert']('',
@@ -1498,8 +1587,9 @@  discard block
 block discarded – undo
1498 1587
 
1499 1588
 	// Save the current database version.
1500 1589
 	$server_version = $smcFunc['db_server_info']();
1501
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1502
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1590
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1591
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1592
+	}
1503 1593
 
1504 1594
 	if ($command_line)
1505 1595
 	{
@@ -1511,8 +1601,9 @@  discard block
 block discarded – undo
1511 1601
 
1512 1602
 	// Make sure it says we're done.
1513 1603
 	$upcontext['overall_percent'] = 100;
1514
-	if (isset($upcontext['step_progress']))
1515
-		unset($upcontext['step_progress']);
1604
+	if (isset($upcontext['step_progress'])) {
1605
+			unset($upcontext['step_progress']);
1606
+	}
1516 1607
 
1517 1608
 	$_GET['substep'] = 0;
1518 1609
 	return false;
@@ -1523,8 +1614,9 @@  discard block
 block discarded – undo
1523 1614
 {
1524 1615
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1525 1616
 
1526
-	if (empty($modSettings['time_format']))
1527
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1617
+	if (empty($modSettings['time_format'])) {
1618
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1619
+	}
1528 1620
 
1529 1621
 	// What files do we want to get
1530 1622
 	$request = $smcFunc['db_query']('', '
@@ -1558,8 +1650,9 @@  discard block
 block discarded – undo
1558 1650
 		$file_data = fetch_web_data($url);
1559 1651
 
1560 1652
 		// If we got an error - give up - the site might be down.
1561
-		if ($file_data === false)
1562
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1653
+		if ($file_data === false) {
1654
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1655
+		}
1563 1656
 
1564 1657
 		// Save the file to the database.
1565 1658
 		$smcFunc['db_query']('substring', '
@@ -1601,8 +1694,9 @@  discard block
 block discarded – undo
1601 1694
 	$themeData = array();
1602 1695
 	foreach ($values as $variable => $value)
1603 1696
 	{
1604
-		if (!isset($value) || $value === null)
1605
-			$value = 0;
1697
+		if (!isset($value) || $value === null) {
1698
+					$value = 0;
1699
+		}
1606 1700
 
1607 1701
 		$themeData[] = array(0, 1, $variable, $value);
1608 1702
 	}
@@ -1631,8 +1725,9 @@  discard block
 block discarded – undo
1631 1725
 
1632 1726
 	foreach ($values as $variable => $value)
1633 1727
 	{
1634
-		if (empty($modSettings[$value[0]]))
1635
-			continue;
1728
+		if (empty($modSettings[$value[0]])) {
1729
+					continue;
1730
+		}
1636 1731
 
1637 1732
 		$smcFunc['db_query']('', '
1638 1733
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1665,8 +1760,9 @@  discard block
 block discarded – undo
1665 1760
 
1666 1761
 	$settingsArray = file($boarddir . '/Settings_bak.php');
1667 1762
 
1668
-	if (count($settingsArray) == 1)
1669
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1763
+	if (count($settingsArray) == 1) {
1764
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1765
+	}
1670 1766
 
1671 1767
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1672 1768
 	{
@@ -1679,9 +1775,9 @@  discard block
 block discarded – undo
1679 1775
 			{
1680 1776
 				if (isset($settingsArray[$i]) && strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1681 1777
 				{
1682
-					if ($val == '#remove#')
1683
-						unset($settingsArray[$i]);
1684
-					else
1778
+					if ($val == '#remove#') {
1779
+											unset($settingsArray[$i]);
1780
+					} else
1685 1781
 					{
1686 1782
 						$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
1687 1783
 						$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment != '' ? "\t\t" . $comment : "\n");
@@ -1693,22 +1789,25 @@  discard block
 block discarded – undo
1693 1789
 		}
1694 1790
 		if (isset($settingsArray[$i]))
1695 1791
 		{
1696
-			if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>')
1697
-				$end = $i;
1792
+			if (trim(substr($settingsArray[$i], 0, 2)) == '?' . '>') {
1793
+							$end = $i;
1794
+			}
1698 1795
 		}
1699 1796
 	}
1700 1797
 
1701 1798
 	// Assume end-of-file if the end wasn't found.
1702
-	if (empty($end) || $end < 10)
1703
-		$end = count($settingsArray);
1799
+	if (empty($end) || $end < 10) {
1800
+			$end = count($settingsArray);
1801
+	}
1704 1802
 
1705 1803
 	if (!empty($config_vars))
1706 1804
 	{
1707 1805
 		$settingsArray[$end++] = '';
1708 1806
 		foreach ($config_vars as $var => $val)
1709 1807
 		{
1710
-			if ($val != '#remove#')
1711
-				$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
1808
+			if ($val != '#remove#') {
1809
+							$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
1810
+			}
1712 1811
 		}
1713 1812
 	}
1714 1813
 	// This should be the last line and even last bytes of the file.
@@ -1721,8 +1820,9 @@  discard block
 block discarded – undo
1721 1820
 	$fp = fopen($boarddir . '/Settings.php', 'r+');
1722 1821
 	for ($i = 0; $i < $end; $i++)
1723 1822
 	{
1724
-		if (isset($settingsArray[$i]))
1725
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1823
+		if (isset($settingsArray[$i])) {
1824
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1825
+		}
1726 1826
 	}
1727 1827
 	fwrite($fp, rtrim($settingsArray[$i]));
1728 1828
 	fclose($fp);
@@ -1753,8 +1853,9 @@  discard block
 block discarded – undo
1753 1853
 	global $smcFunc;
1754 1854
 	static $member_groups = array();
1755 1855
 
1756
-	if (!empty($member_groups))
1757
-		return $member_groups;
1856
+	if (!empty($member_groups)) {
1857
+			return $member_groups;
1858
+	}
1758 1859
 
1759 1860
 	$request = $smcFunc['db_query']('', '
1760 1861
 		SELECT group_name, id_group
@@ -1779,8 +1880,9 @@  discard block
 block discarded – undo
1779 1880
 			)
1780 1881
 		);
1781 1882
 	}
1782
-	while ($row = $smcFunc['db_fetch_row']($request))
1783
-		$member_groups[trim($row[0])] = $row[1];
1883
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1884
+			$member_groups[trim($row[0])] = $row[1];
1885
+	}
1784 1886
 	$smcFunc['db_free_result']($request);
1785 1887
 
1786 1888
 	return $member_groups;
@@ -1833,10 +1935,11 @@  discard block
 block discarded – undo
1833 1935
 		{
1834 1936
 			global $support_js;
1835 1937
 
1836
-			if ($support_js)
1837
-				return true;
1838
-			else
1839
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1938
+			if ($support_js) {
1939
+							return true;
1940
+			} else {
1941
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1942
+			}
1840 1943
 		}
1841 1944
 	}
1842 1945
 
@@ -1854,8 +1957,9 @@  discard block
 block discarded – undo
1854 1957
 				'db_error_skip' => true,
1855 1958
 			)
1856 1959
 		);
1857
-		if ($smcFunc['db_num_rows']($request) === 0)
1858
-			die('Unable to find members table!');
1960
+		if ($smcFunc['db_num_rows']($request) === 0) {
1961
+					die('Unable to find members table!');
1962
+		}
1859 1963
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1860 1964
 		$smcFunc['db_free_result']($request);
1861 1965
 
@@ -1870,17 +1974,20 @@  discard block
 block discarded – undo
1870 1974
 				)
1871 1975
 			);
1872 1976
 			// Got something?
1873
-			if ($smcFunc['db_num_rows']($request) !== 0)
1874
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1977
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1978
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1979
+			}
1875 1980
 			$smcFunc['db_free_result']($request);
1876 1981
 
1877 1982
 			// Excellent!
1878
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1879
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1983
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1984
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1985
+			}
1880 1986
 		}
1881 1987
 	}
1882
-	if (empty($db_collation))
1883
-		$db_collation = '';
1988
+	if (empty($db_collation)) {
1989
+			$db_collation = '';
1990
+	}
1884 1991
 
1885 1992
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1886 1993
 
@@ -1892,8 +1999,9 @@  discard block
 block discarded – undo
1892 1999
 	$last_step = '';
1893 2000
 
1894 2001
 	// Make sure all newly created tables will have the proper characters set.
1895
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1896
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
2002
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
2003
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
2004
+	}
1897 2005
 
1898 2006
 	// Count the total number of steps within this file - for progress.
1899 2007
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1913,15 +2021,18 @@  discard block
 block discarded – undo
1913 2021
 		$do_current = $substep >= $_GET['substep'];
1914 2022
 
1915 2023
 		// Get rid of any comments in the beginning of the line...
1916
-		if (substr(trim($line), 0, 2) === '/*')
1917
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
2024
+		if (substr(trim($line), 0, 2) === '/*') {
2025
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
2026
+		}
1918 2027
 
1919 2028
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1920
-		if ($is_debug && !$support_js && $command_line)
1921
-			flush();
2029
+		if ($is_debug && !$support_js && $command_line) {
2030
+					flush();
2031
+		}
1922 2032
 
1923
-		if (trim($line) === '')
1924
-			continue;
2033
+		if (trim($line) === '') {
2034
+					continue;
2035
+		}
1925 2036
 
1926 2037
 		if (trim(substr($line, 0, 3)) === '---')
1927 2038
 		{
@@ -1931,8 +2042,9 @@  discard block
 block discarded – undo
1931 2042
 			if (trim($current_data) != '' && $type !== '}')
1932 2043
 			{
1933 2044
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1934
-				if ($command_line)
1935
-					echo $upcontext['error_message'];
2045
+				if ($command_line) {
2046
+									echo $upcontext['error_message'];
2047
+				}
1936 2048
 			}
1937 2049
 
1938 2050
 			if ($type == ' ')
@@ -1950,17 +2062,18 @@  discard block
 block discarded – undo
1950 2062
 				if ($do_current)
1951 2063
 				{
1952 2064
 					$upcontext['actioned_items'][] = $last_step;
1953
-					if ($command_line)
1954
-						echo ' * ';
2065
+					if ($command_line) {
2066
+											echo ' * ';
2067
+					}
1955 2068
 				}
1956
-			}
1957
-			elseif ($type == '#')
2069
+			} elseif ($type == '#')
1958 2070
 			{
1959 2071
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1960 2072
 
1961 2073
 				$upcontext['current_debug_item_num']++;
1962
-				if (trim($line) != '---#')
1963
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
2074
+				if (trim($line) != '---#') {
2075
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
2076
+				}
1964 2077
 
1965 2078
 				// Have we already done something?
1966 2079
 				if (isset($_GET['xml']) && $done_something)
@@ -1971,34 +2084,36 @@  discard block
 block discarded – undo
1971 2084
 
1972 2085
 				if ($do_current)
1973 2086
 				{
1974
-					if (trim($line) == '---#' && $command_line)
1975
-						echo ' done.', $endl;
1976
-					elseif ($command_line)
1977
-						echo ' +++ ', rtrim(substr($line, 4));
1978
-					elseif (trim($line) != '---#')
2087
+					if (trim($line) == '---#' && $command_line) {
2088
+											echo ' done.', $endl;
2089
+					} elseif ($command_line) {
2090
+											echo ' +++ ', rtrim(substr($line, 4));
2091
+					} elseif (trim($line) != '---#')
1979 2092
 					{
1980
-						if ($is_debug)
1981
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2093
+						if ($is_debug) {
2094
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2095
+						}
1982 2096
 					}
1983 2097
 				}
1984 2098
 
1985 2099
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1986 2100
 				{
1987
-					if ($command_line)
1988
-						echo ' * ';
1989
-					else
1990
-						$upcontext['actioned_items'][] = $last_step;
2101
+					if ($command_line) {
2102
+											echo ' * ';
2103
+					} else {
2104
+											$upcontext['actioned_items'][] = $last_step;
2105
+					}
1991 2106
 				}
1992 2107
 
1993 2108
 				// Small step - only if we're actually doing stuff.
1994
-				if ($do_current)
1995
-					nextSubstep(++$substep);
1996
-				else
1997
-					$substep++;
1998
-			}
1999
-			elseif ($type == '{')
2000
-				$current_type = 'code';
2001
-			elseif ($type == '}')
2109
+				if ($do_current) {
2110
+									nextSubstep(++$substep);
2111
+				} else {
2112
+									$substep++;
2113
+				}
2114
+			} elseif ($type == '{') {
2115
+							$current_type = 'code';
2116
+			} elseif ($type == '}')
2002 2117
 			{
2003 2118
 				$current_type = 'sql';
2004 2119
 
@@ -2011,8 +2126,9 @@  discard block
 block discarded – undo
2011 2126
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
2012 2127
 				{
2013 2128
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
2014
-					if ($command_line)
2015
-						echo $upcontext['error_message'];
2129
+					if ($command_line) {
2130
+											echo $upcontext['error_message'];
2131
+					}
2016 2132
 				}
2017 2133
 
2018 2134
 				// Done with code!
@@ -2092,8 +2208,9 @@  discard block
 block discarded – undo
2092 2208
 	$db_unbuffered = false;
2093 2209
 
2094 2210
 	// Failure?!
2095
-	if ($result !== false)
2096
-		return $result;
2211
+	if ($result !== false) {
2212
+			return $result;
2213
+	}
2097 2214
 
2098 2215
 	$db_error_message = $smcFunc['db_error']($db_connection);
2099 2216
 	// If MySQL we do something more clever.
@@ -2121,54 +2238,61 @@  discard block
 block discarded – undo
2121 2238
 			{
2122 2239
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2123 2240
 				$result = mysqli_query($db_connection, $string);
2124
-				if ($result !== false)
2125
-					return $result;
2241
+				if ($result !== false) {
2242
+									return $result;
2243
+				}
2126 2244
 			}
2127
-		}
2128
-		elseif ($mysqli_errno == 2013)
2245
+		} elseif ($mysqli_errno == 2013)
2129 2246
 		{
2130 2247
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2131 2248
 			mysqli_select_db($db_connection, $db_name);
2132 2249
 			if ($db_connection)
2133 2250
 			{
2134 2251
 				$result = mysqli_query($db_connection, $string);
2135
-				if ($result !== false)
2136
-					return $result;
2252
+				if ($result !== false) {
2253
+									return $result;
2254
+				}
2137 2255
 			}
2138 2256
 		}
2139 2257
 		// Duplicate column name... should be okay ;).
2140
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2141
-			return false;
2258
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2259
+					return false;
2260
+		}
2142 2261
 		// Duplicate insert... make sure it's the proper type of query ;).
2143
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2144
-			return false;
2262
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2263
+					return false;
2264
+		}
2145 2265
 		// Creating an index on a non-existent column.
2146
-		elseif ($mysqli_errno == 1072)
2147
-			return false;
2148
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2149
-			return false;
2266
+		elseif ($mysqli_errno == 1072) {
2267
+					return false;
2268
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2269
+					return false;
2270
+		}
2150 2271
 	}
2151 2272
 	// If a table already exists don't go potty.
2152 2273
 	else
2153 2274
 	{
2154 2275
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2155 2276
 		{
2156
-			if (strpos($db_error_message, 'exist') !== false)
2157
-				return true;
2158
-		}
2159
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2277
+			if (strpos($db_error_message, 'exist') !== false) {
2278
+							return true;
2279
+			}
2280
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2160 2281
 		{
2161
-			if (strpos($db_error_message, 'duplicate') !== false)
2162
-				return true;
2282
+			if (strpos($db_error_message, 'duplicate') !== false) {
2283
+							return true;
2284
+			}
2163 2285
 		}
2164 2286
 	}
2165 2287
 
2166 2288
 	// Get the query string so we pass everything.
2167 2289
 	$query_string = '';
2168
-	foreach ($_GET as $k => $v)
2169
-		$query_string .= ';' . $k . '=' . $v;
2170
-	if (strlen($query_string) != 0)
2171
-		$query_string = '?' . substr($query_string, 1);
2290
+	foreach ($_GET as $k => $v) {
2291
+			$query_string .= ';' . $k . '=' . $v;
2292
+	}
2293
+	if (strlen($query_string) != 0) {
2294
+			$query_string = '?' . substr($query_string, 1);
2295
+	}
2172 2296
 
2173 2297
 	if ($command_line)
2174 2298
 	{
@@ -2254,16 +2378,18 @@  discard block
 block discarded – undo
2254 2378
 			{
2255 2379
 				$found |= 1;
2256 2380
 				// Do some checks on the data if we have it set.
2257
-				if (isset($change['col_type']))
2258
-					$found &= $change['col_type'] === $column['type'];
2259
-				if (isset($change['null_allowed']))
2260
-					$found &= $column['null'] == $change['null_allowed'];
2261
-				if (isset($change['default']))
2262
-					$found &= $change['default'] === $column['default'];
2381
+				if (isset($change['col_type'])) {
2382
+									$found &= $change['col_type'] === $column['type'];
2383
+				}
2384
+				if (isset($change['null_allowed'])) {
2385
+									$found &= $column['null'] == $change['null_allowed'];
2386
+				}
2387
+				if (isset($change['default'])) {
2388
+									$found &= $change['default'] === $column['default'];
2389
+				}
2263 2390
 			}
2264 2391
 		}
2265
-	}
2266
-	elseif ($change['type'] === 'index')
2392
+	} elseif ($change['type'] === 'index')
2267 2393
 	{
2268 2394
 		$request = upgrade_query('
2269 2395
 			SHOW INDEX
@@ -2272,9 +2398,10 @@  discard block
 block discarded – undo
2272 2398
 		{
2273 2399
 			$cur_index = array();
2274 2400
 
2275
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2276
-				if ($row['Key_name'] === $change['name'])
2401
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2402
+							if ($row['Key_name'] === $change['name'])
2277 2403
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2404
+			}
2278 2405
 
2279 2406
 			ksort($cur_index, SORT_NUMERIC);
2280 2407
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2284,14 +2411,17 @@  discard block
 block discarded – undo
2284 2411
 	}
2285 2412
 
2286 2413
 	// If we're trying to add and it's added, we're done.
2287
-	if ($found && in_array($change['method'], array('add', 'change')))
2288
-		return true;
2414
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2415
+			return true;
2416
+	}
2289 2417
 	// Otherwise if we're removing and it wasn't found we're also done.
2290
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2291
-		return true;
2418
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2419
+			return true;
2420
+	}
2292 2421
 	// Otherwise is it just a test?
2293
-	elseif ($is_test)
2294
-		return false;
2422
+	elseif ($is_test) {
2423
+			return false;
2424
+	}
2295 2425
 
2296 2426
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2297 2427
 	$running = false;
@@ -2302,8 +2432,9 @@  discard block
 block discarded – undo
2302 2432
 			SHOW FULL PROCESSLIST');
2303 2433
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2304 2434
 		{
2305
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2306
-				$found = true;
2435
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2436
+							$found = true;
2437
+			}
2307 2438
 		}
2308 2439
 
2309 2440
 		// Can't find it? Then we need to run it fools!
@@ -2315,8 +2446,9 @@  discard block
 block discarded – undo
2315 2446
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2316 2447
 				' . $change['text'], true) !== false;
2317 2448
 
2318
-			if (!$success)
2319
-				return false;
2449
+			if (!$success) {
2450
+							return false;
2451
+			}
2320 2452
 
2321 2453
 			// Return
2322 2454
 			$running = true;
@@ -2349,8 +2481,7 @@  discard block
 block discarded – undo
2349 2481
 	{
2350 2482
 		$column_fix = true;
2351 2483
 		$null_fix = !$change['null_allowed'];
2352
-	}
2353
-	else
2484
+	} else
2354 2485
 	{
2355 2486
 		$request = $smcFunc['db_query']('', '
2356 2487
 			SHOW FULL COLUMNS
@@ -2361,8 +2492,9 @@  discard block
 block discarded – undo
2361 2492
 				'db_error_skip' => true,
2362 2493
 			)
2363 2494
 		);
2364
-		if ($smcFunc['db_num_rows']($request) === 0)
2365
-			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2495
+		if ($smcFunc['db_num_rows']($request) === 0) {
2496
+					die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2497
+		}
2366 2498
 		$table_row = $smcFunc['db_fetch_assoc']($request);
2367 2499
 		$smcFunc['db_free_result']($request);
2368 2500
 
@@ -2384,10 +2516,11 @@  discard block
 block discarded – undo
2384 2516
 				)
2385 2517
 			);
2386 2518
 			// No results? Just forget it all together.
2387
-			if ($smcFunc['db_num_rows']($request) === 0)
2388
-				unset($table_row['Collation']);
2389
-			else
2390
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
2519
+			if ($smcFunc['db_num_rows']($request) === 0) {
2520
+							unset($table_row['Collation']);
2521
+			} else {
2522
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
2523
+			}
2391 2524
 			$smcFunc['db_free_result']($request);
2392 2525
 		}
2393 2526
 	}
@@ -2395,8 +2528,8 @@  discard block
 block discarded – undo
2395 2528
 	if ($column_fix)
2396 2529
 	{
2397 2530
 		// Make sure there are no NULL's left.
2398
-		if ($null_fix)
2399
-			$smcFunc['db_query']('', '
2531
+		if ($null_fix) {
2532
+					$smcFunc['db_query']('', '
2400 2533
 				UPDATE {db_prefix}' . $change['table'] . '
2401 2534
 				SET ' . $change['column'] . ' = {string:default}
2402 2535
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2405,6 +2538,7 @@  discard block
 block discarded – undo
2405 2538
 					'db_error_skip' => true,
2406 2539
 				)
2407 2540
 			);
2541
+		}
2408 2542
 
2409 2543
 		// Do the actual alteration.
2410 2544
 		$smcFunc['db_query']('', '
@@ -2433,8 +2567,9 @@  discard block
 block discarded – undo
2433 2567
 	}
2434 2568
 
2435 2569
 	// Not a column we need to check on?
2436
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2437
-		return;
2570
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2571
+			return;
2572
+	}
2438 2573
 
2439 2574
 	// Break it up you (six|seven).
2440 2575
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2453,13 +2588,13 @@  discard block
 block discarded – undo
2453 2588
 				'new_name' => $temp[2],
2454 2589
 		));
2455 2590
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2456
-		if ($smcFunc['db_num_rows'] != 1)
2457
-			return;
2591
+		if ($smcFunc['db_num_rows'] != 1) {
2592
+					return;
2593
+		}
2458 2594
 
2459 2595
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2460 2596
 		$smcFunc['db_free_result']($request);
2461
-	}
2462
-	else
2597
+	} else
2463 2598
 	{
2464 2599
 		// Do this the old fashion, sure method way.
2465 2600
 		$request = $smcFunc['db_query']('', '
@@ -2470,21 +2605,24 @@  discard block
 block discarded – undo
2470 2605
 		));
2471 2606
 		// Mayday!
2472 2607
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2473
-		if ($smcFunc['db_num_rows'] == 0)
2474
-			return;
2608
+		if ($smcFunc['db_num_rows'] == 0) {
2609
+					return;
2610
+		}
2475 2611
 
2476 2612
 		// Oh where, oh where has my little field gone. Oh where can it be...
2477
-		while ($row = $smcFunc['db_query']($request))
2478
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2613
+		while ($row = $smcFunc['db_query']($request)) {
2614
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2479 2615
 			{
2480 2616
 				$current_type = $row['Type'];
2617
+		}
2481 2618
 				break;
2482 2619
 			}
2483 2620
 	}
2484 2621
 
2485 2622
 	// If this doesn't match, the column may of been altered for a reason.
2486
-	if (trim($current_type) != trim($temp[3]))
2487
-		$temp[3] = $current_type;
2623
+	if (trim($current_type) != trim($temp[3])) {
2624
+			$temp[3] = $current_type;
2625
+	}
2488 2626
 
2489 2627
 	// Piece this back together.
2490 2628
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2496,8 +2634,9 @@  discard block
 block discarded – undo
2496 2634
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2497 2635
 	global $step_progress, $is_debug, $upcontext;
2498 2636
 
2499
-	if ($_GET['substep'] < $substep)
2500
-		$_GET['substep'] = $substep;
2637
+	if ($_GET['substep'] < $substep) {
2638
+			$_GET['substep'] = $substep;
2639
+	}
2501 2640
 
2502 2641
 	if ($command_line)
2503 2642
 	{
@@ -2510,29 +2649,33 @@  discard block
 block discarded – undo
2510 2649
 	}
2511 2650
 
2512 2651
 	@set_time_limit(300);
2513
-	if (function_exists('apache_reset_timeout'))
2514
-		@apache_reset_timeout();
2652
+	if (function_exists('apache_reset_timeout')) {
2653
+			@apache_reset_timeout();
2654
+	}
2515 2655
 
2516
-	if (time() - $start_time <= $timeLimitThreshold)
2517
-		return;
2656
+	if (time() - $start_time <= $timeLimitThreshold) {
2657
+			return;
2658
+	}
2518 2659
 
2519 2660
 	// Do we have some custom step progress stuff?
2520 2661
 	if (!empty($step_progress))
2521 2662
 	{
2522 2663
 		$upcontext['substep_progress'] = 0;
2523 2664
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2524
-		if ($step_progress['current'] > $step_progress['total'])
2525
-			$upcontext['substep_progress'] = 99.9;
2526
-		else
2527
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2665
+		if ($step_progress['current'] > $step_progress['total']) {
2666
+					$upcontext['substep_progress'] = 99.9;
2667
+		} else {
2668
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2669
+		}
2528 2670
 
2529 2671
 		// Make it nicely rounded.
2530 2672
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2531 2673
 	}
2532 2674
 
2533 2675
 	// If this is XML we just exit right away!
2534
-	if (isset($_GET['xml']))
2535
-		return upgradeExit();
2676
+	if (isset($_GET['xml'])) {
2677
+			return upgradeExit();
2678
+	}
2536 2679
 
2537 2680
 	// We're going to pause after this!
2538 2681
 	$upcontext['pause'] = true;
@@ -2540,13 +2683,15 @@  discard block
 block discarded – undo
2540 2683
 	$upcontext['query_string'] = '';
2541 2684
 	foreach ($_GET as $k => $v)
2542 2685
 	{
2543
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2544
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2686
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2687
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2688
+		}
2545 2689
 	}
2546 2690
 
2547 2691
 	// Custom warning?
2548
-	if (!empty($custom_warning))
2549
-		$upcontext['custom_warning'] = $custom_warning;
2692
+	if (!empty($custom_warning)) {
2693
+			$upcontext['custom_warning'] = $custom_warning;
2694
+	}
2550 2695
 
2551 2696
 	upgradeExit();
2552 2697
 }
@@ -2561,25 +2706,26 @@  discard block
 block discarded – undo
2561 2706
 	ob_implicit_flush(true);
2562 2707
 	@set_time_limit(600);
2563 2708
 
2564
-	if (!isset($_SERVER['argv']))
2565
-		$_SERVER['argv'] = array();
2709
+	if (!isset($_SERVER['argv'])) {
2710
+			$_SERVER['argv'] = array();
2711
+	}
2566 2712
 	$_GET['maint'] = 1;
2567 2713
 
2568 2714
 	foreach ($_SERVER['argv'] as $i => $arg)
2569 2715
 	{
2570
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2571
-			$_GET['lang'] = $match[1];
2572
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2573
-			continue;
2574
-		elseif ($arg == '--no-maintenance')
2575
-			$_GET['maint'] = 0;
2576
-		elseif ($arg == '--debug')
2577
-			$is_debug = true;
2578
-		elseif ($arg == '--backup')
2579
-			$_POST['backup'] = 1;
2580
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2581
-			$_GET['conv'] = 1;
2582
-		elseif ($i != 0)
2716
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2717
+					$_GET['lang'] = $match[1];
2718
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2719
+					continue;
2720
+		} elseif ($arg == '--no-maintenance') {
2721
+					$_GET['maint'] = 0;
2722
+		} elseif ($arg == '--debug') {
2723
+					$is_debug = true;
2724
+		} elseif ($arg == '--backup') {
2725
+					$_POST['backup'] = 1;
2726
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2727
+					$_GET['conv'] = 1;
2728
+		} elseif ($i != 0)
2583 2729
 		{
2584 2730
 			echo 'SMF Command-line Upgrader
2585 2731
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2593,10 +2739,12 @@  discard block
 block discarded – undo
2593 2739
 		}
2594 2740
 	}
2595 2741
 
2596
-	if (!php_version_check())
2597
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2598
-	if (!db_version_check())
2599
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2742
+	if (!php_version_check()) {
2743
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2744
+	}
2745
+	if (!db_version_check()) {
2746
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2747
+	}
2600 2748
 
2601 2749
 	// Do some checks to make sure they have proper privileges
2602 2750
 	db_extend('packages');
@@ -2611,34 +2759,39 @@  discard block
 block discarded – undo
2611 2759
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2612 2760
 
2613 2761
 	// Sorry... we need CREATE, ALTER and DROP
2614
-	if (!$create || !$alter || !$drop)
2615
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2762
+	if (!$create || !$alter || !$drop) {
2763
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2764
+	}
2616 2765
 
2617 2766
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2618 2767
 		&& @file_exists($sourcedir . '/QueryString.php')
2619 2768
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2620
-	if (!$check && !isset($modSettings['smfVersion']))
2621
-		print_error('Error: Some files are missing or out-of-date.', true);
2769
+	if (!$check && !isset($modSettings['smfVersion'])) {
2770
+			print_error('Error: Some files are missing or out-of-date.', true);
2771
+	}
2622 2772
 
2623 2773
 	// Do a quick version spot check.
2624 2774
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2625 2775
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2626
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2627
-		print_error('Error: Some files have not yet been updated properly.');
2776
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2777
+			print_error('Error: Some files have not yet been updated properly.');
2778
+	}
2628 2779
 
2629 2780
 	// Make sure Settings.php is writable.
2630 2781
 		quickFileWritable($boarddir . '/Settings.php');
2631
-	if (!is_writable($boarddir . '/Settings.php'))
2632
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2782
+	if (!is_writable($boarddir . '/Settings.php')) {
2783
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2784
+	}
2633 2785
 
2634 2786
 	// Make sure Settings_bak.php is writable.
2635 2787
 		quickFileWritable($boarddir . '/Settings_bak.php');
2636
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2637
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2788
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2789
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2790
+	}
2638 2791
 
2639
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2640
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2641
-	elseif (isset($modSettings['agreement']))
2792
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2793
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2794
+	} elseif (isset($modSettings['agreement']))
2642 2795
 	{
2643 2796
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2644 2797
 		fwrite($fp, $modSettings['agreement']);
@@ -2648,31 +2801,36 @@  discard block
 block discarded – undo
2648 2801
 	// Make sure Themes is writable.
2649 2802
 	quickFileWritable($modSettings['theme_dir']);
2650 2803
 
2651
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2652
-		print_error('Error: Unable to obtain write access to "Themes".');
2804
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2805
+			print_error('Error: Unable to obtain write access to "Themes".');
2806
+	}
2653 2807
 
2654 2808
 	// Make sure cache directory exists and is writable!
2655 2809
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2656
-	if (!file_exists($cachedir_temp))
2657
-		@mkdir($cachedir_temp);
2810
+	if (!file_exists($cachedir_temp)) {
2811
+			@mkdir($cachedir_temp);
2812
+	}
2658 2813
 
2659 2814
 	// Make sure the cache temp dir is writable.
2660 2815
 	quickFileWritable($cachedir_temp);
2661 2816
 
2662
-	if (!is_writable($cachedir_temp))
2663
-		print_error('Error: Unable to obtain write access to "cache".', true);
2817
+	if (!is_writable($cachedir_temp)) {
2818
+			print_error('Error: Unable to obtain write access to "cache".', true);
2819
+	}
2664 2820
 
2665
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2666
-		print_error('Error: Unable to find language files!', true);
2667
-	else
2821
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2822
+			print_error('Error: Unable to find language files!', true);
2823
+	} else
2668 2824
 	{
2669 2825
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2670 2826
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2671 2827
 
2672
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2673
-			print_error('Error: Language files out of date.', true);
2674
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2675
-			print_error('Error: Install language is missing for selected language.', true);
2828
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2829
+					print_error('Error: Language files out of date.', true);
2830
+		}
2831
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2832
+					print_error('Error: Install language is missing for selected language.', true);
2833
+		}
2676 2834
 
2677 2835
 		// Otherwise include it!
2678 2836
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2687,14 +2845,16 @@  discard block
 block discarded – undo
2687 2845
 {
2688 2846
 	static $fp = null;
2689 2847
 
2690
-	if ($fp === null)
2691
-		$fp = fopen('php://stderr', 'wb');
2848
+	if ($fp === null) {
2849
+			$fp = fopen('php://stderr', 'wb');
2850
+	}
2692 2851
 
2693 2852
 	fwrite($fp, $message . "\n");
2694 2853
 
2695
-	if ($fatal)
2696
-		exit;
2697
-}
2854
+	if ($fatal) {
2855
+			exit;
2856
+	}
2857
+	}
2698 2858
 
2699 2859
 function throw_error($message)
2700 2860
 {
@@ -2711,8 +2871,9 @@  discard block
 block discarded – undo
2711 2871
 {
2712 2872
 	global $upcontext, $boarddir;
2713 2873
 
2714
-	if (empty($files))
2715
-		return true;
2874
+	if (empty($files)) {
2875
+			return true;
2876
+	}
2716 2877
 
2717 2878
 	$failure = false;
2718 2879
 	// On linux, it's easy - just use is_writable!
@@ -2727,14 +2888,16 @@  discard block
 block discarded – undo
2727 2888
 				@chmod($file, 0755);
2728 2889
 
2729 2890
 				// Well, 755 hopefully worked... if not, try 777.
2730
-				if (!is_writable($file) && !@chmod($file, 0777))
2731
-					$failure = true;
2891
+				if (!is_writable($file) && !@chmod($file, 0777)) {
2892
+									$failure = true;
2893
+				}
2732 2894
 				// Otherwise remove it as it's good!
2733
-				else
2734
-					unset($files[$k]);
2895
+				else {
2896
+									unset($files[$k]);
2897
+				}
2898
+			} else {
2899
+							unset($files[$k]);
2735 2900
 			}
2736
-			else
2737
-				unset($files[$k]);
2738 2901
 		}
2739 2902
 	}
2740 2903
 	// Windows is trickier.  Let's try opening for r+...
@@ -2745,30 +2908,35 @@  discard block
 block discarded – undo
2745 2908
 		foreach ($files as $k => $file)
2746 2909
 		{
2747 2910
 			// Folders can't be opened for write... but the index.php in them can ;).
2748
-			if (is_dir($file))
2749
-				$file .= '/index.php';
2911
+			if (is_dir($file)) {
2912
+							$file .= '/index.php';
2913
+			}
2750 2914
 
2751 2915
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
2752 2916
 			@chmod($file, 0777);
2753 2917
 			$fp = @fopen($file, 'r+');
2754 2918
 
2755 2919
 			// Hmm, okay, try just for write in that case...
2756
-			if (!$fp)
2757
-				$fp = @fopen($file, 'w');
2920
+			if (!$fp) {
2921
+							$fp = @fopen($file, 'w');
2922
+			}
2758 2923
 
2759
-			if (!$fp)
2760
-				$failure = true;
2761
-			else
2762
-				unset($files[$k]);
2924
+			if (!$fp) {
2925
+							$failure = true;
2926
+			} else {
2927
+							unset($files[$k]);
2928
+			}
2763 2929
 			@fclose($fp);
2764 2930
 		}
2765 2931
 	}
2766 2932
 
2767
-	if (empty($files))
2768
-		return true;
2933
+	if (empty($files)) {
2934
+			return true;
2935
+	}
2769 2936
 
2770
-	if (!isset($_SERVER))
2771
-		return !$failure;
2937
+	if (!isset($_SERVER)) {
2938
+			return !$failure;
2939
+	}
2772 2940
 
2773 2941
 	// What still needs to be done?
2774 2942
 	$upcontext['chmod']['files'] = $files;
@@ -2819,36 +2987,40 @@  discard block
 block discarded – undo
2819 2987
 
2820 2988
 		if (!isset($ftp) || $ftp->error !== false)
2821 2989
 		{
2822
-			if (!isset($ftp))
2823
-				$ftp = new ftp_connection(null);
2990
+			if (!isset($ftp)) {
2991
+							$ftp = new ftp_connection(null);
2992
+			}
2824 2993
 			// Save the error so we can mess with listing...
2825
-			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error']))
2826
-				$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
2994
+			elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) {
2995
+							$upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message;
2996
+			}
2827 2997
 
2828 2998
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
2829 2999
 
2830
-			if ($found_path || !isset($upcontext['chmod']['path']))
2831
-				$upcontext['chmod']['path'] = $detect_path;
3000
+			if ($found_path || !isset($upcontext['chmod']['path'])) {
3001
+							$upcontext['chmod']['path'] = $detect_path;
3002
+			}
2832 3003
 
2833
-			if (!isset($upcontext['chmod']['username']))
2834
-				$upcontext['chmod']['username'] = $username;
3004
+			if (!isset($upcontext['chmod']['username'])) {
3005
+							$upcontext['chmod']['username'] = $username;
3006
+			}
2835 3007
 
2836 3008
 			// Don't forget the login token.
2837 3009
 			$upcontext += createToken('login');
2838 3010
 
2839 3011
 			return false;
2840
-		}
2841
-		else
3012
+		} else
2842 3013
 		{
2843 3014
 			// We want to do a relative path for FTP.
2844 3015
 			if (!in_array($upcontext['chmod']['path'], array('', '/')))
2845 3016
 			{
2846 3017
 				$ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => ''));
2847
-				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/'))
2848
-				$ftp_root = substr($ftp_root, 0, -1);
3018
+				if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) {
3019
+								$ftp_root = substr($ftp_root, 0, -1);
3020
+				}
3021
+			} else {
3022
+							$ftp_root = $boarddir;
2849 3023
 			}
2850
-			else
2851
-				$ftp_root = $boarddir;
2852 3024
 
2853 3025
 			// Save the info for next time!
2854 3026
 			$_SESSION['installer_temp_ftp'] = array(
@@ -2862,10 +3034,12 @@  discard block
 block discarded – undo
2862 3034
 
2863 3035
 			foreach ($files as $k => $file)
2864 3036
 			{
2865
-				if (!is_writable($file))
2866
-					$ftp->chmod($file, 0755);
2867
-				if (!is_writable($file))
2868
-					$ftp->chmod($file, 0777);
3037
+				if (!is_writable($file)) {
3038
+									$ftp->chmod($file, 0755);
3039
+				}
3040
+				if (!is_writable($file)) {
3041
+									$ftp->chmod($file, 0777);
3042
+				}
2869 3043
 
2870 3044
 				// Assuming that didn't work calculate the path without the boarddir.
2871 3045
 				if (!is_writable($file))
@@ -2874,19 +3048,23 @@  discard block
 block discarded – undo
2874 3048
 					{
2875 3049
 						$ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => ''));
2876 3050
 						$ftp->chmod($ftp_file, 0755);
2877
-						if (!is_writable($file))
2878
-							$ftp->chmod($ftp_file, 0777);
3051
+						if (!is_writable($file)) {
3052
+													$ftp->chmod($ftp_file, 0777);
3053
+						}
2879 3054
 						// Sometimes an extra slash can help...
2880 3055
 						$ftp_file = '/' . $ftp_file;
2881
-						if (!is_writable($file))
2882
-							$ftp->chmod($ftp_file, 0755);
2883
-						if (!is_writable($file))
2884
-							$ftp->chmod($ftp_file, 0777);
3056
+						if (!is_writable($file)) {
3057
+													$ftp->chmod($ftp_file, 0755);
3058
+						}
3059
+						if (!is_writable($file)) {
3060
+													$ftp->chmod($ftp_file, 0777);
3061
+						}
2885 3062
 					}
2886 3063
 				}
2887 3064
 
2888
-				if (is_writable($file))
2889
-					unset($files[$k]);
3065
+				if (is_writable($file)) {
3066
+									unset($files[$k]);
3067
+				}
2890 3068
 			}
2891 3069
 
2892 3070
 			$ftp->close();
@@ -2896,16 +3074,18 @@  discard block
 block discarded – undo
2896 3074
 	// What remains?
2897 3075
 	$upcontext['chmod']['files'] = $files;
2898 3076
 
2899
-	if (empty($files))
2900
-		return true;
3077
+	if (empty($files)) {
3078
+			return true;
3079
+	}
2901 3080
 
2902 3081
 	return false;
2903 3082
 }
2904 3083
 
2905 3084
 function quickFileWritable($file)
2906 3085
 {
2907
-	if (is_writable($file))
2908
-		return true;
3086
+	if (is_writable($file)) {
3087
+			return true;
3088
+	}
2909 3089
 
2910 3090
 	@chmod($file, 0755);
2911 3091
 
@@ -2915,17 +3095,19 @@  discard block
 block discarded – undo
2915 3095
 	foreach ($chmod_values as $val)
2916 3096
 	{
2917 3097
 		// If it's writable, break out of the loop
2918
-		if (is_writable($file))
2919
-			break;
2920
-		else
2921
-			@chmod($file, $val);
3098
+		if (is_writable($file)) {
3099
+					break;
3100
+		} else {
3101
+					@chmod($file, $val);
3102
+		}
2922 3103
 	}
2923 3104
 }
2924 3105
 function smf_strtolower($string)
2925 3106
 {
2926 3107
 	global $sourcedir;
2927
-	if (function_exists('mb_strtolower'))
2928
-		return mb_strtolower($string, 'UTF-8');
3108
+	if (function_exists('mb_strtolower')) {
3109
+			return mb_strtolower($string, 'UTF-8');
3110
+	}
2929 3111
 	require_once($sourcedir . '/Subs-Charset.php');
2930 3112
 	return utf8_strtolower($string);
2931 3113
 }
@@ -2948,8 +3130,7 @@  discard block
 block discarded – undo
2948 3130
 		);
2949 3131
 		
2950 3132
 		return true;
2951
-	}
2952
-	else
3133
+	} else
2953 3134
 	{
2954 3135
 		$upcontext['page_title'] = 'Converting to UTF8';
2955 3136
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2993,8 +3174,9 @@  discard block
 block discarded – undo
2993 3174
 			)
2994 3175
 		);
2995 3176
 		$db_charsets = array();
2996
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2997
-			$db_charsets[] = $row['Charset'];
3177
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3178
+					$db_charsets[] = $row['Charset'];
3179
+		}
2998 3180
 
2999 3181
 		$smcFunc['db_free_result']($request);
3000 3182
 
@@ -3030,13 +3212,15 @@  discard block
 block discarded – undo
3030 3212
 		// If there's a fulltext index, we need to drop it first...
3031 3213
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
3032 3214
 		{
3033
-			while ($row = $smcFunc['db_fetch_assoc']($request))
3034
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
3215
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
3216
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
3035 3217
 					$upcontext['fulltext_index'][] = $row['Key_name'];
3218
+			}
3036 3219
 			$smcFunc['db_free_result']($request);
3037 3220
 
3038
-			if (isset($upcontext['fulltext_index']))
3039
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
3221
+			if (isset($upcontext['fulltext_index'])) {
3222
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
3223
+			}
3040 3224
 		}
3041 3225
 
3042 3226
 		// Drop it and make a note...
@@ -3226,8 +3410,9 @@  discard block
 block discarded – undo
3226 3410
 			$replace = '%field%';
3227 3411
 
3228 3412
 			// Build a huge REPLACE statement...
3229
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
3230
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3413
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3414
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3415
+			}
3231 3416
 		}
3232 3417
 
3233 3418
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -3260,8 +3445,9 @@  discard block
 block discarded – undo
3260 3445
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3261 3446
 
3262 3447
 			// Just to make sure it doesn't time out.
3263
-			if (function_exists('apache_reset_timeout'))
3264
-				@apache_reset_timeout();
3448
+			if (function_exists('apache_reset_timeout')) {
3449
+							@apache_reset_timeout();
3450
+			}
3265 3451
 
3266 3452
 			$table_charsets = array();
3267 3453
 
@@ -3282,8 +3468,9 @@  discard block
 block discarded – undo
3282 3468
 					{
3283 3469
 						list($charset) = explode('_', $collation);
3284 3470
 
3285
-						if (!isset($table_charsets[$charset]))
3286
-							$table_charsets[$charset] = array();
3471
+						if (!isset($table_charsets[$charset])) {
3472
+													$table_charsets[$charset] = array();
3473
+						}
3287 3474
 
3288 3475
 						$table_charsets[$charset][] = $column_info;
3289 3476
 					}
@@ -3323,10 +3510,11 @@  discard block
 block discarded – undo
3323 3510
 				if (isset($translation_tables[$upcontext['charset_detected']]))
3324 3511
 				{
3325 3512
 					$update = '';
3326
-					foreach ($table_charsets as $charset => $columns)
3327
-						foreach ($columns as $column)
3513
+					foreach ($table_charsets as $charset => $columns) {
3514
+											foreach ($columns as $column)
3328 3515
 							$update .= '
3329 3516
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3517
+					}
3330 3518
 
3331 3519
 					$smcFunc['db_query']('', '
3332 3520
 						UPDATE {raw:table_name}
@@ -3351,8 +3539,9 @@  discard block
 block discarded – undo
3351 3539
 			// Now do the actual conversion (if still needed).
3352 3540
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
3353 3541
 			{
3354
-				if ($command_line)
3355
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3542
+				if ($command_line) {
3543
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3544
+				}
3356 3545
 
3357 3546
 				$smcFunc['db_query']('', '
3358 3547
 					ALTER TABLE {raw:table_name}
@@ -3362,8 +3551,9 @@  discard block
 block discarded – undo
3362 3551
 						)
3363 3552
 				);
3364 3553
 
3365
-				if ($command_line)
3366
-					echo " done.\n";
3554
+				if ($command_line) {
3555
+									echo " done.\n";
3556
+				}
3367 3557
 			}
3368 3558
 		}
3369 3559
 
@@ -3393,8 +3583,8 @@  discard block
 block discarded – undo
3393 3583
 		);
3394 3584
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3395 3585
 		{
3396
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
3397
-				$smcFunc['db_query']('', '
3586
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3587
+							$smcFunc['db_query']('', '
3398 3588
 					UPDATE {db_prefix}log_actions
3399 3589
 					SET extra = {string:extra}
3400 3590
 					WHERE id_action = {int:current_action}',
@@ -3403,6 +3593,7 @@  discard block
 block discarded – undo
3403 3593
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3404 3594
 					)
3405 3595
 				);
3596
+			}
3406 3597
 		}
3407 3598
 		$smcFunc['db_free_result']($request);
3408 3599
 
@@ -3424,15 +3615,17 @@  discard block
 block discarded – undo
3424 3615
 	// First thing's first - did we already do this?
3425 3616
 	if (!empty($modSettings['json_done']))
3426 3617
 	{
3427
-		if ($command_line)
3428
-			return DeleteUpgrade();
3429
-		else
3430
-			return true;
3618
+		if ($command_line) {
3619
+					return DeleteUpgrade();
3620
+		} else {
3621
+					return true;
3622
+		}
3431 3623
 	}
3432 3624
 
3433 3625
 	// Done it already - js wise?
3434
-	if (!empty($_POST['json_done']))
3435
-		return true;
3626
+	if (!empty($_POST['json_done'])) {
3627
+			return true;
3628
+	}
3436 3629
 
3437 3630
 	// List of tables affected by this function
3438 3631
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3463,12 +3656,14 @@  discard block
 block discarded – undo
3463 3656
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3464 3657
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3465 3658
 
3466
-	foreach ($keys as $id => $table)
3467
-		if ($id < $_GET['substep'])
3659
+	foreach ($keys as $id => $table) {
3660
+			if ($id < $_GET['substep'])
3468 3661
 			$upcontext['previous_tables'][] = $table;
3662
+	}
3469 3663
 
3470
-	if ($command_line)
3471
-		echo 'Converting data from serialize() to json_encode().';
3664
+	if ($command_line) {
3665
+			echo 'Converting data from serialize() to json_encode().';
3666
+	}
3472 3667
 
3473 3668
 	if (!$support_js || isset($_GET['xml']))
3474 3669
 	{
@@ -3508,8 +3703,9 @@  discard block
 block discarded – undo
3508 3703
 
3509 3704
 				// Loop through and fix these...
3510 3705
 				$new_settings = array();
3511
-				if ($command_line)
3512
-					echo "\n" . 'Fixing some settings...';
3706
+				if ($command_line) {
3707
+									echo "\n" . 'Fixing some settings...';
3708
+				}
3513 3709
 
3514 3710
 				foreach ($serialized_settings as $var)
3515 3711
 				{
@@ -3517,22 +3713,24 @@  discard block
 block discarded – undo
3517 3713
 					{
3518 3714
 						// Attempt to unserialize the setting
3519 3715
 						$temp = @safe_unserialize($modSettings[$var]);
3520
-						if (!$temp && $command_line)
3521
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3522
-						elseif ($temp !== false)
3523
-							$new_settings[$var] = json_encode($temp);
3716
+						if (!$temp && $command_line) {
3717
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3718
+						} elseif ($temp !== false) {
3719
+													$new_settings[$var] = json_encode($temp);
3720
+						}
3524 3721
 					}
3525 3722
 				}
3526 3723
 
3527 3724
 				// Update everything at once
3528
-				if (!function_exists('cache_put_data'))
3529
-					require_once($sourcedir . '/Load.php');
3725
+				if (!function_exists('cache_put_data')) {
3726
+									require_once($sourcedir . '/Load.php');
3727
+				}
3530 3728
 				updateSettings($new_settings, true);
3531 3729
 
3532
-				if ($command_line)
3533
-					echo ' done.';
3534
-			}
3535
-			elseif ($table == 'themes')
3730
+				if ($command_line) {
3731
+									echo ' done.';
3732
+				}
3733
+			} elseif ($table == 'themes')
3536 3734
 			{
3537 3735
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3538 3736
 				$query = $smcFunc['db_query']('', '
@@ -3551,10 +3749,11 @@  discard block
 block discarded – undo
3551 3749
 
3552 3750
 						if ($command_line)
3553 3751
 						{
3554
-							if ($temp === false)
3555
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3556
-							else
3557
-								echo "\n" . 'Fixing admin preferences...';
3752
+							if ($temp === false) {
3753
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3754
+							} else {
3755
+															echo "\n" . 'Fixing admin preferences...';
3756
+							}
3558 3757
 						}
3559 3758
 
3560 3759
 						if ($temp !== false)
@@ -3574,15 +3773,15 @@  discard block
 block discarded – undo
3574 3773
 								)
3575 3774
 							);
3576 3775
 
3577
-							if ($command_line)
3578
-								echo ' done.';
3776
+							if ($command_line) {
3777
+															echo ' done.';
3778
+							}
3579 3779
 						}
3580 3780
 					}
3581 3781
 
3582 3782
 					$smcFunc['db_free_result']($query);
3583 3783
 				}
3584
-			}
3585
-			else
3784
+			} else
3586 3785
 			{
3587 3786
 				// First item is always the key...
3588 3787
 				$key = $info[0];
@@ -3593,8 +3792,7 @@  discard block
 block discarded – undo
3593 3792
 				{
3594 3793
 					$col_select = $info[1];
3595 3794
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3596
-				}
3597
-				else
3795
+				} else
3598 3796
 				{
3599 3797
 					$col_select = implode(', ', $info);
3600 3798
 				}
@@ -3627,8 +3825,7 @@  discard block
 block discarded – undo
3627 3825
 								if ($temp === false && $command_line)
3628 3826
 								{
3629 3827
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3630
-								}
3631
-								else
3828
+								} else
3632 3829
 								{
3633 3830
 									$row[$col] = json_encode($temp);
3634 3831
 
@@ -3653,16 +3850,18 @@  discard block
 block discarded – undo
3653 3850
 						}
3654 3851
 					}
3655 3852
 
3656
-					if ($command_line)
3657
-						echo ' done.';
3853
+					if ($command_line) {
3854
+											echo ' done.';
3855
+					}
3658 3856
 
3659 3857
 					// Free up some memory...
3660 3858
 					$smcFunc['db_free_result']($query);
3661 3859
 				}
3662 3860
 			}
3663 3861
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3664
-			if (isset($_GET['xml']))
3665
-				return upgradeExit();
3862
+			if (isset($_GET['xml'])) {
3863
+							return upgradeExit();
3864
+			}
3666 3865
 		}
3667 3866
 
3668 3867
 		if ($command_line)
@@ -3677,8 +3876,9 @@  discard block
 block discarded – undo
3677 3876
 
3678 3877
 		$_GET['substep'] = 0;
3679 3878
 		// Make sure we move on!
3680
-		if ($command_line)
3681
-			return DeleteUpgrade();
3879
+		if ($command_line) {
3880
+					return DeleteUpgrade();
3881
+		}
3682 3882
 
3683 3883
 		return true;
3684 3884
 	}
@@ -3698,14 +3898,16 @@  discard block
 block discarded – undo
3698 3898
 	global $upcontext, $txt, $settings;
3699 3899
 
3700 3900
 	// Don't call me twice!
3701
-	if (!empty($upcontext['chmod_called']))
3702
-		return;
3901
+	if (!empty($upcontext['chmod_called'])) {
3902
+			return;
3903
+	}
3703 3904
 
3704 3905
 	$upcontext['chmod_called'] = true;
3705 3906
 
3706 3907
 	// Nothing?
3707
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3708
-		return;
3908
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3909
+			return;
3910
+	}
3709 3911
 
3710 3912
 	// Was it a problem with Windows?
3711 3913
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3737,11 +3939,12 @@  discard block
 block discarded – undo
3737 3939
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3738 3940
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3739 3941
 
3740
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3741
-		echo '
3942
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3943
+			echo '
3742 3944
 					content.write(\'<hr>\n\t\t\t\');
3743 3945
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3744 3946
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3947
+	}
3745 3948
 
3746 3949
 	echo '
3747 3950
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3749,17 +3952,19 @@  discard block
 block discarded – undo
3749 3952
 				}
3750 3953
 		</script>';
3751 3954
 
3752
-	if (!empty($upcontext['chmod']['ftp_error']))
3753
-		echo '
3955
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3956
+			echo '
3754 3957
 			<div class="error_message red">
3755 3958
 				The following error was encountered when trying to connect:<br><br>
3756 3959
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3757 3960
 			</div>
3758 3961
 			<br>';
3962
+	}
3759 3963
 
3760
-	if (empty($upcontext['chmod_in_form']))
3761
-		echo '
3964
+	if (empty($upcontext['chmod_in_form'])) {
3965
+			echo '
3762 3966
 	<form action="', $upcontext['form_url'], '" method="post">';
3967
+	}
3763 3968
 
3764 3969
 	echo '
3765 3970
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3794,10 +3999,11 @@  discard block
 block discarded – undo
3794 3999
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3795 4000
 	</div>';
3796 4001
 
3797
-	if (empty($upcontext['chmod_in_form']))
3798
-		echo '
4002
+	if (empty($upcontext['chmod_in_form'])) {
4003
+			echo '
3799 4004
 	</form>';
3800
-}
4005
+	}
4006
+	}
3801 4007
 
3802 4008
 function template_upgrade_above()
3803 4009
 {
@@ -3857,9 +4063,10 @@  discard block
 block discarded – undo
3857 4063
 				<h2>', $txt['upgrade_progress'], '</h2>
3858 4064
 				<ul>';
3859 4065
 
3860
-	foreach ($upcontext['steps'] as $num => $step)
3861
-		echo '
4066
+	foreach ($upcontext['steps'] as $num => $step) {
4067
+			echo '
3862 4068
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
4069
+	}
3863 4070
 
3864 4071
 	echo '
3865 4072
 					</ul>
@@ -3872,8 +4079,8 @@  discard block
 block discarded – undo
3872 4079
 				</div>
3873 4080
 			</div>';
3874 4081
 
3875
-	if (isset($upcontext['step_progress']))
3876
-		echo '
4082
+	if (isset($upcontext['step_progress'])) {
4083
+			echo '
3877 4084
 				<br>
3878 4085
 				<br>
3879 4086
 				<div id="progress_bar_step">
@@ -3882,6 +4089,7 @@  discard block
 block discarded – undo
3882 4089
 						<span>', $txt['upgrade_step_progress'], '</span>
3883 4090
 					</div>
3884 4091
 				</div>';
4092
+	}
3885 4093
 
3886 4094
 	echo '
3887 4095
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3912,32 +4120,36 @@  discard block
 block discarded – undo
3912 4120
 {
3913 4121
 	global $upcontext, $txt;
3914 4122
 
3915
-	if (!empty($upcontext['pause']))
3916
-		echo '
4123
+	if (!empty($upcontext['pause'])) {
4124
+			echo '
3917 4125
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3918 4126
 
3919 4127
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3920 4128
 								<h3>
3921 4129
 									', $txt['upgrade_paused_overload'], '
3922 4130
 								</h3>';
4131
+	}
3923 4132
 
3924
-	if (!empty($upcontext['custom_warning']))
3925
-		echo '
4133
+	if (!empty($upcontext['custom_warning'])) {
4134
+			echo '
3926 4135
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3927 4136
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3928 4137
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3929 4138
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3930 4139
 								</div>';
4140
+	}
3931 4141
 
3932 4142
 	echo '
3933 4143
 								<div class="righttext" style="margin: 1ex;">';
3934 4144
 
3935
-	if (!empty($upcontext['continue']))
3936
-		echo '
4145
+	if (!empty($upcontext['continue'])) {
4146
+			echo '
3937 4147
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3938
-	if (!empty($upcontext['skip']))
3939
-		echo '
4148
+	}
4149
+	if (!empty($upcontext['skip'])) {
4150
+			echo '
3940 4151
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
4152
+	}
3941 4153
 
3942 4154
 	echo '
3943 4155
 								</div>
@@ -3987,11 +4199,12 @@  discard block
 block discarded – undo
3987 4199
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3988 4200
 	<smf>';
3989 4201
 
3990
-	if (!empty($upcontext['get_data']))
3991
-		foreach ($upcontext['get_data'] as $k => $v)
4202
+	if (!empty($upcontext['get_data'])) {
4203
+			foreach ($upcontext['get_data'] as $k => $v)
3992 4204
 			echo '
3993 4205
 		<get key="', $k, '">', $v, '</get>';
3994
-}
4206
+	}
4207
+	}
3995 4208
 
3996 4209
 function template_xml_below()
3997 4210
 {
@@ -4032,8 +4245,8 @@  discard block
 block discarded – undo
4032 4245
 	template_chmod();
4033 4246
 
4034 4247
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
4035
-	if ($upcontext['is_large_forum'])
4036
-		echo '
4248
+	if ($upcontext['is_large_forum']) {
4249
+			echo '
4037 4250
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
4038 4251
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
4039 4252
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -4041,10 +4254,11 @@  discard block
 block discarded – undo
4041 4254
 				', $txt['upgrade_warning_lots_data'], '
4042 4255
 			</div>
4043 4256
 		</div>';
4257
+	}
4044 4258
 
4045 4259
 	// A warning message?
4046
-	if (!empty($upcontext['warning']))
4047
-		echo '
4260
+	if (!empty($upcontext['warning'])) {
4261
+			echo '
4048 4262
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
4049 4263
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
4050 4264
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -4052,6 +4266,7 @@  discard block
 block discarded – undo
4052 4266
 				', $upcontext['warning'], '
4053 4267
 			</div>
4054 4268
 		</div>';
4269
+	}
4055 4270
 
4056 4271
 	// Paths are incorrect?
4057 4272
 	echo '
@@ -4067,20 +4282,22 @@  discard block
 block discarded – undo
4067 4282
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
4068 4283
 	{
4069 4284
 		$ago = time() - $upcontext['started'];
4070
-		if ($ago < 60)
4071
-			$ago = $ago . ' seconds';
4072
-		elseif ($ago < 3600)
4073
-			$ago = (int) ($ago / 60) . ' minutes';
4074
-		else
4075
-			$ago = (int) ($ago / 3600) . ' hours';
4285
+		if ($ago < 60) {
4286
+					$ago = $ago . ' seconds';
4287
+		} elseif ($ago < 3600) {
4288
+					$ago = (int) ($ago / 60) . ' minutes';
4289
+		} else {
4290
+					$ago = (int) ($ago / 3600) . ' hours';
4291
+		}
4076 4292
 
4077 4293
 		$active = time() - $upcontext['updated'];
4078
-		if ($active < 60)
4079
-			$updated = $active . ' seconds';
4080
-		elseif ($active < 3600)
4081
-			$updated = (int) ($active / 60) . ' minutes';
4082
-		else
4083
-			$updated = (int) ($active / 3600) . ' hours';
4294
+		if ($active < 60) {
4295
+					$updated = $active . ' seconds';
4296
+		} elseif ($active < 3600) {
4297
+					$updated = (int) ($active / 60) . ' minutes';
4298
+		} else {
4299
+					$updated = (int) ($active / 3600) . ' hours';
4300
+		}
4084 4301
 
4085 4302
 		echo '
4086 4303
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -4089,16 +4306,18 @@  discard block
 block discarded – undo
4089 4306
 			<div style="padding-left: 6ex;">
4090 4307
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
4091 4308
 
4092
-		if ($active < 600)
4093
-			echo '
4309
+		if ($active < 600) {
4310
+					echo '
4094 4311
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
4312
+		}
4095 4313
 
4096
-		if ($active > $upcontext['inactive_timeout'])
4097
-			echo '
4314
+		if ($active > $upcontext['inactive_timeout']) {
4315
+					echo '
4098 4316
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
4099
-		else
4100
-			echo '
4317
+		} else {
4318
+					echo '
4101 4319
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
4320
+		}
4102 4321
 
4103 4322
 		echo '
4104 4323
 			</div>
@@ -4114,9 +4333,10 @@  discard block
 block discarded – undo
4114 4333
 					<td>
4115 4334
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
4116 4335
 
4117
-	if (!empty($upcontext['username_incorrect']))
4118
-		echo '
4336
+	if (!empty($upcontext['username_incorrect'])) {
4337
+			echo '
4119 4338
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
4339
+	}
4120 4340
 
4121 4341
 	echo '
4122 4342
 					</td>
@@ -4127,9 +4347,10 @@  discard block
 block discarded – undo
4127 4347
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
4128 4348
 						<input type="hidden" name="hash_passwrd" value="">';
4129 4349
 
4130
-	if (!empty($upcontext['password_failed']))
4131
-		echo '
4350
+	if (!empty($upcontext['password_failed'])) {
4351
+			echo '
4132 4352
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
4353
+	}
4133 4354
 
4134 4355
 	echo '
4135 4356
 					</td>
@@ -4200,8 +4421,8 @@  discard block
 block discarded – undo
4200 4421
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
4201 4422
 
4202 4423
 	// Warning message?
4203
-	if (!empty($upcontext['upgrade_options_warning']))
4204
-		echo '
4424
+	if (!empty($upcontext['upgrade_options_warning'])) {
4425
+			echo '
4205 4426
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
4206 4427
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
4207 4428
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -4209,6 +4430,7 @@  discard block
 block discarded – undo
4209 4430
 				', $upcontext['upgrade_options_warning'], '
4210 4431
 			</div>
4211 4432
 		</div>';
4433
+	}
4212 4434
 
4213 4435
 	echo '
4214 4436
 				<table>
@@ -4236,8 +4458,8 @@  discard block
 block discarded – undo
4236 4458
 					</tr>';
4237 4459
 
4238 4460
 	// Offer mysql users to switch to mysqli
4239
-	if ($db_type == 'mysql' && function_exists('mysqli_query'))
4240
-		echo '
4461
+	if ($db_type == 'mysql' && function_exists('mysqli_query')) {
4462
+			echo '
4241 4463
 					<tr valign="top">
4242 4464
 						<td width="2%">
4243 4465
 							<input type="checkbox" name="convertMysql" id="convertMysql" value="1" checked class="input_check">
@@ -4247,6 +4469,7 @@  discard block
 block discarded – undo
4247 4469
 							<strong class="smalltext"><a href="http://wiki.simplemachines.org/smf/Upgrading-MySQLi-Functionality" target="_blank">More information about MySQLi</a></strong><br>
4248 4470
 						</td>
4249 4471
 					</tr>';
4472
+	}
4250 4473
 
4251 4474
 	echo '
4252 4475
 					<tr valign="top">
@@ -4266,8 +4489,8 @@  discard block
 block discarded – undo
4266 4489
 						</td>
4267 4490
 					</tr>';
4268 4491
 
4269
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
4270
-		echo '
4492
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4493
+			echo '
4271 4494
 					<tr valign="top">
4272 4495
 						<td width="2%">
4273 4496
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -4276,6 +4499,7 @@  discard block
 block discarded – undo
4276 4499
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
4277 4500
 						</td>
4278 4501
 					</tr>';
4502
+	}
4279 4503
 
4280 4504
 	echo '
4281 4505
 					<tr valign="top">
@@ -4311,10 +4535,11 @@  discard block
 block discarded – undo
4311 4535
 			<span id="debuginfo"></span>';
4312 4536
 
4313 4537
 	// Dont any tables so far?
4314
-	if (!empty($upcontext['previous_tables']))
4315
-		foreach ($upcontext['previous_tables'] as $table)
4538
+	if (!empty($upcontext['previous_tables'])) {
4539
+			foreach ($upcontext['previous_tables'] as $table)
4316 4540
 			echo '
4317 4541
 			<br>Completed Table: &quot;', $table, '&quot;.';
4542
+	}
4318 4543
 
4319 4544
 	echo '
4320 4545
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -4351,12 +4576,13 @@  discard block
 block discarded – undo
4351 4576
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4352 4577
 
4353 4578
 		// If debug flood the screen.
4354
-		if ($is_debug)
4355
-			echo '
4579
+		if ($is_debug) {
4580
+					echo '
4356 4581
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4357 4582
 
4358 4583
 				if (document.getElementById(\'debuginfo\').scrollHeight)
4359 4584
 					document.getElementById(\'debuginfo\').scrollTop = document.getElementById(\'debuginfo\').scrollHeight;';
4585
+		}
4360 4586
 
4361 4587
 		echo '
4362 4588
 				// Get the next update...
@@ -4388,8 +4614,9 @@  discard block
 block discarded – undo
4388 4614
 {
4389 4615
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
4390 4616
 
4391
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4392
-		$is_debug = true;
4617
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4618
+			$is_debug = true;
4619
+	}
4393 4620
 
4394 4621
 	echo '
4395 4622
 		<h3>Executing database changes</h3>
@@ -4404,8 +4631,9 @@  discard block
 block discarded – undo
4404 4631
 	{
4405 4632
 		foreach ($upcontext['actioned_items'] as $num => $item)
4406 4633
 		{
4407
-			if ($num != 0)
4408
-				echo ' Successful!';
4634
+			if ($num != 0) {
4635
+							echo ' Successful!';
4636
+			}
4409 4637
 			echo '<br>' . $item;
4410 4638
 		}
4411 4639
 		if (!empty($upcontext['changes_complete']))
@@ -4418,28 +4646,32 @@  discard block
 block discarded – undo
4418 4646
 				$seconds = intval($active % 60);
4419 4647
 
4420 4648
 				$totalTime = '';
4421
-				if ($hours > 0)
4422
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4423
-				if ($minutes > 0)
4424
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4425
-				if ($seconds > 0)
4426
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4649
+				if ($hours > 0) {
4650
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4651
+				}
4652
+				if ($minutes > 0) {
4653
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4654
+				}
4655
+				if ($seconds > 0) {
4656
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4657
+				}
4427 4658
 			}
4428 4659
 
4429
-			if ($is_debug && !empty($totalTime))
4430
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
4431
-			else
4432
-				echo ' Successful!<br><br>';
4660
+			if ($is_debug && !empty($totalTime)) {
4661
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4662
+			} else {
4663
+							echo ' Successful!<br><br>';
4664
+			}
4433 4665
 
4434 4666
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
4435 4667
 		}
4436
-	}
4437
-	else
4668
+	} else
4438 4669
 	{
4439 4670
 		// Tell them how many files we have in total.
4440
-		if ($upcontext['file_count'] > 1)
4441
-			echo '
4671
+		if ($upcontext['file_count'] > 1) {
4672
+					echo '
4442 4673
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4674
+		}
4443 4675
 
4444 4676
 		echo '
4445 4677
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -4455,19 +4687,23 @@  discard block
 block discarded – undo
4455 4687
 				$seconds = intval($active % 60);
4456 4688
 
4457 4689
 				$totalTime = '';
4458
-				if ($hours > 0)
4459
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4460
-				if ($minutes > 0)
4461
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4462
-				if ($seconds > 0)
4463
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4690
+				if ($hours > 0) {
4691
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4692
+				}
4693
+				if ($minutes > 0) {
4694
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4695
+				}
4696
+				if ($seconds > 0) {
4697
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4698
+				}
4464 4699
 			}
4465 4700
 
4466 4701
 			echo '
4467 4702
 			<br><span id="upgradeCompleted">';
4468 4703
 
4469
-			if (!empty($totalTime))
4470
-				echo 'Completed in ', $totalTime, '<br>';
4704
+			if (!empty($totalTime)) {
4705
+							echo 'Completed in ', $totalTime, '<br>';
4706
+			}
4471 4707
 
4472 4708
 			echo '</span>
4473 4709
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -4504,9 +4740,10 @@  discard block
 block discarded – undo
4504 4740
 			var getData = "";
4505 4741
 			var debugItems = ', $upcontext['debug_items'], ';';
4506 4742
 
4507
-		if ($is_debug)
4508
-			echo '
4743
+		if ($is_debug) {
4744
+					echo '
4509 4745
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4746
+		}
4510 4747
 
4511 4748
 		echo '
4512 4749
 			function getNextItem()
@@ -4546,9 +4783,10 @@  discard block
 block discarded – undo
4546 4783
 						document.getElementById("error_block").style.display = "";
4547 4784
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4548 4785
 
4549
-	if ($is_debug)
4550
-		echo '
4786
+	if ($is_debug) {
4787
+			echo '
4551 4788
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4789
+	}
4552 4790
 
4553 4791
 	echo '
4554 4792
 					}
@@ -4569,9 +4807,10 @@  discard block
 block discarded – undo
4569 4807
 						document.getElementById("error_block").style.display = "";
4570 4808
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4571 4809
 
4572
-	if ($is_debug)
4573
-		echo '
4810
+	if ($is_debug) {
4811
+			echo '
4574 4812
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4813
+	}
4575 4814
 
4576 4815
 	echo '
4577 4816
 					}
@@ -4630,8 +4869,8 @@  discard block
 block discarded – undo
4630 4869
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4631 4870
 				{';
4632 4871
 
4633
-		if ($is_debug)
4634
-			echo '
4872
+		if ($is_debug) {
4873
+					echo '
4635 4874
 					document.getElementById(\'debug_section\').style.display = "none";
4636 4875
 
4637 4876
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4649,6 +4888,7 @@  discard block
 block discarded – undo
4649 4888
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4650 4889
 
4651 4890
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4891
+		}
4652 4892
 
4653 4893
 		echo '
4654 4894
 
@@ -4656,9 +4896,10 @@  discard block
 block discarded – undo
4656 4896
 					document.getElementById(\'contbutt\').disabled = 0;
4657 4897
 					document.getElementById(\'database_done\').value = 1;';
4658 4898
 
4659
-		if ($upcontext['file_count'] > 1)
4660
-			echo '
4899
+		if ($upcontext['file_count'] > 1) {
4900
+					echo '
4661 4901
 					document.getElementById(\'info1\').style.display = "none";';
4902
+		}
4662 4903
 
4663 4904
 		echo '
4664 4905
 					document.getElementById(\'info2\').style.display = "none";
@@ -4671,9 +4912,10 @@  discard block
 block discarded – undo
4671 4912
 					lastItem = 0;
4672 4913
 					prevFile = curFile;';
4673 4914
 
4674
-		if ($is_debug)
4675
-			echo '
4915
+		if ($is_debug) {
4916
+					echo '
4676 4917
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4918
+		}
4677 4919
 
4678 4920
 		echo '
4679 4921
 					getNextItem();
@@ -4681,8 +4923,8 @@  discard block
 block discarded – undo
4681 4923
 				}';
4682 4924
 
4683 4925
 		// If debug scroll the screen.
4684
-		if ($is_debug)
4685
-			echo '
4926
+		if ($is_debug) {
4927
+					echo '
4686 4928
 				if (iLastSubStepProgress == -1)
4687 4929
 				{
4688 4930
 					// Give it consistent dots.
@@ -4701,6 +4943,7 @@  discard block
 block discarded – undo
4701 4943
 
4702 4944
 				if (document.getElementById(\'debug_section\').scrollHeight)
4703 4945
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4946
+		}
4704 4947
 
4705 4948
 		echo '
4706 4949
 				// Update the page.
@@ -4761,9 +5004,10 @@  discard block
 block discarded – undo
4761 5004
 			}';
4762 5005
 
4763 5006
 		// Start things off assuming we've not errored.
4764
-		if (empty($upcontext['error_message']))
4765
-			echo '
5007
+		if (empty($upcontext['error_message'])) {
5008
+					echo '
4766 5009
 			getNextItem();';
5010
+		}
4767 5011
 
4768 5012
 		echo '
4769 5013
 		</script>';
@@ -4780,18 +5024,21 @@  discard block
 block discarded – undo
4780 5024
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4781 5025
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4782 5026
 
4783
-	if (!empty($upcontext['error_message']))
4784
-		echo '
5027
+	if (!empty($upcontext['error_message'])) {
5028
+			echo '
4785 5029
 	<error>', $upcontext['error_message'], '</error>';
5030
+	}
4786 5031
 
4787
-	if (!empty($upcontext['error_string']))
4788
-		echo '
5032
+	if (!empty($upcontext['error_string'])) {
5033
+			echo '
4789 5034
 	<sql>', $upcontext['error_string'], '</sql>';
5035
+	}
4790 5036
 
4791
-	if ($is_debug)
4792
-		echo '
5037
+	if ($is_debug) {
5038
+			echo '
4793 5039
 	<curtime>', time(), '</curtime>';
4794
-}
5040
+	}
5041
+	}
4795 5042
 
4796 5043
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4797 5044
 function template_convert_utf8()
@@ -4808,18 +5055,20 @@  discard block
 block discarded – undo
4808 5055
 			<span id="debuginfo"></span>';
4809 5056
 
4810 5057
 	// Done any tables so far?
4811
-	if (!empty($upcontext['previous_tables']))
4812
-		foreach ($upcontext['previous_tables'] as $table)
5058
+	if (!empty($upcontext['previous_tables'])) {
5059
+			foreach ($upcontext['previous_tables'] as $table)
4813 5060
 			echo '
4814 5061
 			<br>Completed Table: &quot;', $table, '&quot;.';
5062
+	}
4815 5063
 
4816 5064
 	echo '
4817 5065
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4818 5066
 
4819 5067
 	// If we dropped their index, let's let them know
4820
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4821
-		echo '
5068
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
5069
+			echo '
4822 5070
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
5071
+	}
4823 5072
 
4824 5073
 	echo '
4825 5074
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>';
@@ -4855,9 +5104,10 @@  discard block
 block discarded – undo
4855 5104
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4856 5105
 
4857 5106
 		// If debug flood the screen.
4858
-		if ($is_debug)
4859
-			echo '
5107
+		if ($is_debug) {
5108
+					echo '
4860 5109
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
5110
+		}
4861 5111
 
4862 5112
 		echo '
4863 5113
 				// Get the next update...
@@ -4899,19 +5149,21 @@  discard block
 block discarded – undo
4899 5149
 			<span id="debuginfo"></span>';
4900 5150
 
4901 5151
 	// Dont any tables so far?
4902
-	if (!empty($upcontext['previous_tables']))
4903
-		foreach ($upcontext['previous_tables'] as $table)
5152
+	if (!empty($upcontext['previous_tables'])) {
5153
+			foreach ($upcontext['previous_tables'] as $table)
4904 5154
 			echo '
4905 5155
 			<br>Completed Table: &quot;', $table, '&quot;.';
5156
+	}
4906 5157
 
4907 5158
 	echo '
4908 5159
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4909 5160
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4910 5161
 
4911 5162
 	// Try to make sure substep was reset.
4912
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4913
-		echo '
5163
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
5164
+			echo '
4914 5165
 			<input type="hidden" name="substep" id="substep" value="0">';
5166
+	}
4915 5167
 
4916 5168
 	// Continue please!
4917 5169
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4944,9 +5196,10 @@  discard block
 block discarded – undo
4944 5196
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4945 5197
 
4946 5198
 		// If debug flood the screen.
4947
-		if ($is_debug)
4948
-			echo '
5199
+		if ($is_debug) {
5200
+					echo '
4949 5201
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
5202
+		}
4950 5203
 
4951 5204
 		echo '
4952 5205
 				// Get the next update...
@@ -4981,8 +5234,8 @@  discard block
 block discarded – undo
4981 5234
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4982 5235
 	<form action="', $boardurl, '/index.php">';
4983 5236
 
4984
-	if (!empty($upcontext['can_delete_script']))
4985
-		echo '
5237
+	if (!empty($upcontext['can_delete_script'])) {
5238
+			echo '
4986 5239
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4987 5240
 			<script>
4988 5241
 				function doTheDelete(theCheck)
@@ -4994,6 +5247,7 @@  discard block
 block discarded – undo
4994 5247
 				}
4995 5248
 			</script>
4996 5249
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
5250
+	}
4997 5251
 
4998 5252
 	$active = time() - $upcontext['started'];
4999 5253
 	$hours = floor($active / 3600);
@@ -5003,16 +5257,20 @@  discard block
 block discarded – undo
5003 5257
 	if ($is_debug)
5004 5258
 	{
5005 5259
 		$totalTime = '';
5006
-		if ($hours > 0)
5007
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
5008
-		if ($minutes > 0)
5009
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
5010
-		if ($seconds > 0)
5011
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
5260
+		if ($hours > 0) {
5261
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
5262
+		}
5263
+		if ($minutes > 0) {
5264
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
5265
+		}
5266
+		if ($seconds > 0) {
5267
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
5268
+		}
5012 5269
 	}
5013 5270
 
5014
-	if ($is_debug && !empty($totalTime))
5015
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
5271
+	if ($is_debug && !empty($totalTime)) {
5272
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
5273
+	}
5016 5274
 
5017 5275
 	echo '<br>
5018 5276
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -5079,16 +5337,19 @@  discard block
 block discarded – undo
5079 5337
 				'empty' => '',
5080 5338
 				'limit' => $limit,
5081 5339
 		));
5082
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5083
-			$arIp[] = $row[$oldCol];
5340
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5341
+					$arIp[] = $row[$oldCol];
5342
+		}
5084 5343
 		$smcFunc['db_free_result']($request);
5085 5344
 
5086 5345
 		// Special case, null ip could keep us in a loop.
5087
-		if (is_null($arIp[0]))
5088
-			unset($arIp[0]);
5346
+		if (is_null($arIp[0])) {
5347
+					unset($arIp[0]);
5348
+		}
5089 5349
 
5090
-		if (empty($arIp))
5091
-			$is_done = true;
5350
+		if (empty($arIp)) {
5351
+					$is_done = true;
5352
+		}
5092 5353
 
5093 5354
 		$updates = array();
5094 5355
 		$cases = array();
@@ -5097,16 +5358,18 @@  discard block
 block discarded – undo
5097 5358
 		{
5098 5359
 			$arIp[$i] = trim($arIp[$i]);
5099 5360
 
5100
-			if (empty($arIp[$i]))
5101
-				continue;
5361
+			if (empty($arIp[$i])) {
5362
+							continue;
5363
+			}
5102 5364
 
5103 5365
 			$updates['ip' . $i] = $arIp[$i];
5104 5366
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
5105 5367
 
5106 5368
 			if ($setSize > 0 && $i % $setSize === 0)
5107 5369
 			{
5108
-				if (count($updates) == 1)
5109
-					continue;
5370
+				if (count($updates) == 1) {
5371
+									continue;
5372
+				}
5110 5373
 
5111 5374
 				$updates['whereSet'] = array_values($updates);
5112 5375
 				$smcFunc['db_query']('', '
@@ -5140,8 +5403,7 @@  discard block
 block discarded – undo
5140 5403
 							'ip' => $ip
5141 5404
 					));
5142 5405
 				}
5143
-			}
5144
-			else
5406
+			} else
5145 5407
 			{
5146 5408
 				$updates['whereSet'] = array_values($updates);
5147 5409
 				$smcFunc['db_query']('', '
@@ -5155,9 +5417,9 @@  discard block
 block discarded – undo
5155 5417
 					$updates
5156 5418
 				);
5157 5419
 			}
5420
+		} else {
5421
+					$is_done = true;
5158 5422
 		}
5159
-		else
5160
-			$is_done = true;
5161 5423
 
5162 5424
 		$_GET['a'] += $limit;
5163 5425
 		$step_progress['current'] = $_GET['a'];
Please login to merge, or discard this patch.