Completed
Push — release-2.1 ( cfdc59...af3d3b )
by Jeremy
12:06 queued 05:35
created
Sources/Post.php 1 patch
Braces   +677 added lines, -523 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -60,12 +63,14 @@  discard block
 block discarded – undo
60 63
 	{
61 64
 		// Get ids of all the boards they can post in.
62 65
 		$post_permissions = array('post_new');
63
-		if ($modSettings['postmod_active'])
64
-			$post_permissions[] = 'post_unapproved_topics';
66
+		if ($modSettings['postmod_active']) {
67
+					$post_permissions[] = 'post_unapproved_topics';
68
+		}
65 69
 
66 70
 		$boards = boardsAllowedTo($post_permissions);
67
-		if (empty($boards))
68
-			fatal_lang_error('cannot_post_new', false);
71
+		if (empty($boards)) {
72
+					fatal_lang_error('cannot_post_new', false);
73
+		}
69 74
 
70 75
 		// Get a list of boards for the select menu
71 76
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -78,8 +83,9 @@  discard block
 block discarded – undo
78 83
 		$board_list = getBoardList($boardListOptions);
79 84
 	}
80 85
 	// Let's keep things simple for ourselves below
81
-	else
82
-		$boards = array($board);
86
+	else {
87
+			$boards = array($board);
88
+	}
83 89
 
84 90
 	require_once($sourcedir . '/Subs-Post.php');
85 91
 
@@ -102,10 +108,11 @@  discard block
 block discarded – undo
102 108
 			array(
103 109
 				'msg' => (int) $_REQUEST['msg'],
104 110
 		));
105
-		if ($smcFunc['db_num_rows']($request) != 1)
106
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
107
-		else
108
-			list ($topic) = $smcFunc['db_fetch_row']($request);
111
+		if ($smcFunc['db_num_rows']($request) != 1) {
112
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
113
+		} else {
114
+					list ($topic) = $smcFunc['db_fetch_row']($request);
115
+		}
109 116
 		$smcFunc['db_free_result']($request);
110 117
 	}
111 118
 
@@ -132,33 +139,36 @@  discard block
 block discarded – undo
132 139
 		$smcFunc['db_free_result']($request);
133 140
 
134 141
 		// If this topic already has a poll, they sure can't add another.
135
-		if (isset($_REQUEST['poll']) && $pollID > 0)
136
-			unset($_REQUEST['poll']);
142
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
143
+					unset($_REQUEST['poll']);
144
+		}
137 145
 
138 146
 		if (empty($_REQUEST['msg']))
139 147
 		{
140
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
141
-				is_not_guest();
148
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
149
+							is_not_guest();
150
+			}
142 151
 
143 152
 			// By default the reply will be approved...
144 153
 			$context['becomes_approved'] = true;
145 154
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
146 155
 			{
147
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
148
-					$context['becomes_approved'] = false;
149
-				else
150
-					isAllowedTo('post_reply_any');
151
-			}
152
-			elseif (!allowedTo('post_reply_any'))
156
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
157
+									$context['becomes_approved'] = false;
158
+				} else {
159
+									isAllowedTo('post_reply_any');
160
+				}
161
+			} elseif (!allowedTo('post_reply_any'))
153 162
 			{
154
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
155
-					$context['becomes_approved'] = false;
156
-				else
157
-					isAllowedTo('post_reply_own');
163
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
164
+									$context['becomes_approved'] = false;
165
+				} else {
166
+									isAllowedTo('post_reply_own');
167
+				}
158 168
 			}
169
+		} else {
170
+					$context['becomes_approved'] = true;
159 171
 		}
160
-		else
161
-			$context['becomes_approved'] = true;
162 172
 
163 173
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
164 174
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -173,17 +183,18 @@  discard block
 block discarded – undo
173 183
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
174 184
 
175 185
 		// Check whether this is a really old post being bumped...
176
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
177
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
178
-	}
179
-	else
186
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
187
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
188
+		}
189
+	} else
180 190
 	{
181 191
 		// @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu
182 192
 		$context['becomes_approved'] = true;
183
-		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true))
184
-			$context['becomes_approved'] = false;
185
-		else
186
-			isAllowedTo('post_new', $boards, true);
193
+		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) {
194
+					$context['becomes_approved'] = false;
195
+		} else {
196
+					isAllowedTo('post_new', $boards, true);
197
+		}
187 198
 
188 199
 		$locked = 0;
189 200
 		$context['already_locked'] = 0;
@@ -213,27 +224,32 @@  discard block
 block discarded – undo
213 224
 	if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached']))
214 225
 	{
215 226
 		require_once($sourcedir . '/ManageAttachments.php');
216
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
217
-			removeAttachments(array('id_attach' => $attachID));
227
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
228
+					removeAttachments(array('id_attach' => $attachID));
229
+		}
218 230
 
219 231
 		unset($_SESSION['already_attached']);
220 232
 	}
221 233
 
222 234
 	// Don't allow a post if it's locked and you aren't all powerful.
223
-	if ($locked && !allowedTo('moderate_board'))
224
-		fatal_lang_error('topic_locked', false);
235
+	if ($locked && !allowedTo('moderate_board')) {
236
+			fatal_lang_error('topic_locked', false);
237
+	}
225 238
 	// Check the users permissions - is the user allowed to add or post a poll?
226 239
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
227 240
 	{
228 241
 		// New topic, new poll.
229
-		if (empty($topic))
230
-			isAllowedTo('poll_post');
242
+		if (empty($topic)) {
243
+					isAllowedTo('poll_post');
244
+		}
231 245
 		// This is an old topic - but it is yours!  Can you add to it?
232
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
233
-			isAllowedTo('poll_add_own');
246
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
247
+					isAllowedTo('poll_add_own');
248
+		}
234 249
 		// If you're not the owner, can you add to any poll?
235
-		else
236
-			isAllowedTo('poll_add_any');
250
+		else {
251
+					isAllowedTo('poll_add_any');
252
+		}
237 253
 
238 254
 		if (!empty($board))
239 255
 		{
@@ -242,8 +258,9 @@  discard block
 block discarded – undo
242 258
 			$guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']);
243 259
 		}
244 260
 		// No board, so we'll have to check this again in Post2
245
-		else
246
-			$guest_vote_enabled = true;
261
+		else {
262
+					$guest_vote_enabled = true;
263
+		}
247 264
 
248 265
 		// Set up the poll options.
249 266
 		$context['poll_options'] = array(
@@ -269,8 +286,9 @@  discard block
 block discarded – undo
269 286
 	if ($context['make_event'])
270 287
 	{
271 288
 		// They might want to pick a board.
272
-		if (!isset($context['current_board']))
273
-			$context['current_board'] = 0;
289
+		if (!isset($context['current_board'])) {
290
+					$context['current_board'] = 0;
291
+		}
274 292
 
275 293
 		// Start loading up the event info.
276 294
 		$context['event'] = array();
@@ -284,10 +302,11 @@  discard block
 block discarded – undo
284 302
 		isAllowedTo('calendar_post');
285 303
 
286 304
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
287
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
288
-			$time_string = '%k:%M';
289
-		else
290
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
305
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
306
+					$time_string = '%k:%M';
307
+		} else {
308
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
309
+		}
291 310
 
292 311
 		$js_time_string = str_replace(
293 312
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -309,8 +328,7 @@  discard block
 block discarded – undo
309 328
 			require_once($sourcedir . '/Subs-Calendar.php');
310 329
 			$eventProperties = getEventProperties($context['event']['id']);
311 330
 			$context['event'] = array_merge($context['event'], $eventProperties);
312
-		}
313
-		else
331
+		} else
314 332
 		{
315 333
 			// Get the current event information.
316 334
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -318,10 +336,12 @@  discard block
 block discarded – undo
318 336
 			$context['event'] = array_merge($context['event'], $eventProperties);
319 337
 
320 338
 			// Make sure the year and month are in the valid range.
321
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
322
-				fatal_lang_error('invalid_month', false);
323
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
324
-				fatal_lang_error('invalid_year', false);
339
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
340
+							fatal_lang_error('invalid_month', false);
341
+			}
342
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
343
+							fatal_lang_error('invalid_year', false);
344
+			}
325 345
 
326 346
 			$context['event']['categories'] = $board_list;
327 347
 		}
@@ -432,10 +452,11 @@  discard block
 block discarded – undo
432 452
 
433 453
 			if (!empty($context['new_replies']))
434 454
 			{
435
-				if ($context['new_replies'] == 1)
436
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
437
-				else
438
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
455
+				if ($context['new_replies'] == 1) {
456
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
457
+				} else {
458
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
459
+				}
439 460
 
440 461
 				$post_errors[] = 'new_replies';
441 462
 
@@ -447,9 +468,9 @@  discard block
 block discarded – undo
447 468
 	// Get a response prefix (like 'Re:') in the default forum language.
448 469
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
449 470
 	{
450
-		if ($language === $user_info['language'])
451
-			$context['response_prefix'] = $txt['response_prefix'];
452
-		else
471
+		if ($language === $user_info['language']) {
472
+					$context['response_prefix'] = $txt['response_prefix'];
473
+		} else
453 474
 		{
454 475
 			loadLanguage('index', $language, false);
455 476
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -462,23 +483,26 @@  discard block
 block discarded – undo
462 483
 	// Do we have a body, but an error happened.
463 484
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
464 485
 	{
465
-		if (isset($_REQUEST['quickReply']))
466
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
486
+		if (isset($_REQUEST['quickReply'])) {
487
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
488
+		}
467 489
 
468 490
 		// Validate inputs.
469 491
 		if (empty($context['post_error']))
470 492
 		{
471 493
 			// This means they didn't click Post and get an error.
472 494
 			$really_previewing = true;
473
-		}
474
-		else
495
+		} else
475 496
 		{
476
-			if (!isset($_REQUEST['subject']))
477
-				$_REQUEST['subject'] = '';
478
-			if (!isset($_REQUEST['message']))
479
-				$_REQUEST['message'] = '';
480
-			if (!isset($_REQUEST['icon']))
481
-				$_REQUEST['icon'] = 'xx';
497
+			if (!isset($_REQUEST['subject'])) {
498
+							$_REQUEST['subject'] = '';
499
+			}
500
+			if (!isset($_REQUEST['message'])) {
501
+							$_REQUEST['message'] = '';
502
+			}
503
+			if (!isset($_REQUEST['icon'])) {
504
+							$_REQUEST['icon'] = 'xx';
505
+			}
482 506
 
483 507
 			// They are previewing if they asked to preview (i.e. came from quick reply).
484 508
 			$really_previewing = !empty($_POST['preview']);
@@ -494,8 +518,9 @@  discard block
 block discarded – undo
494 518
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
495 519
 
496 520
 		// Make sure the subject isn't too long - taking into account special characters.
497
-		if ($smcFunc['strlen']($form_subject) > 100)
498
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
521
+		if ($smcFunc['strlen']($form_subject) > 100) {
522
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
523
+		}
499 524
 
500 525
 		if (isset($_REQUEST['poll']))
501 526
 		{
@@ -507,8 +532,9 @@  discard block
 block discarded – undo
507 532
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
508 533
 			foreach ($_POST['options'] as $option)
509 534
 			{
510
-				if (trim($option) == '')
511
-					continue;
535
+				if (trim($option) == '') {
536
+									continue;
537
+				}
512 538
 
513 539
 				$context['choices'][] = array(
514 540
 					'id' => $choice_id++,
@@ -570,13 +596,14 @@  discard block
 block discarded – undo
570 596
 				$context['preview_subject'] = $form_subject;
571 597
 
572 598
 				censorText($context['preview_subject']);
599
+			} else {
600
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
573 601
 			}
574
-			else
575
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
576 602
 
577 603
 			// Protect any CDATA blocks.
578
-			if (isset($_REQUEST['xml']))
579
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
604
+			if (isset($_REQUEST['xml'])) {
605
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
606
+			}
580 607
 		}
581 608
 
582 609
 		// Set up the checkboxes.
@@ -615,29 +642,32 @@  discard block
 block discarded – undo
615 642
 			);
616 643
 			// The message they were trying to edit was most likely deleted.
617 644
 			// @todo Change this error message?
618
-			if ($smcFunc['db_num_rows']($request) == 0)
619
-				fatal_lang_error('no_board', false);
645
+			if ($smcFunc['db_num_rows']($request) == 0) {
646
+							fatal_lang_error('no_board', false);
647
+			}
620 648
 			$row = $smcFunc['db_fetch_assoc']($request);
621 649
 
622 650
 			$attachment_stuff = array($row);
623
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
624
-				$attachment_stuff[] = $row2;
651
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
652
+							$attachment_stuff[] = $row2;
653
+			}
625 654
 			$smcFunc['db_free_result']($request);
626 655
 
627 656
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
628 657
 			{
629 658
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
630
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
631
-					fatal_lang_error('modify_post_time_passed', false);
632
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
633
-					isAllowedTo('modify_replies');
634
-				else
635
-					isAllowedTo('modify_own');
659
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
660
+									fatal_lang_error('modify_post_time_passed', false);
661
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
662
+									isAllowedTo('modify_replies');
663
+				} else {
664
+									isAllowedTo('modify_own');
665
+				}
666
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
667
+							isAllowedTo('modify_replies');
668
+			} else {
669
+							isAllowedTo('modify_any');
636 670
 			}
637
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
638
-				isAllowedTo('modify_replies');
639
-			else
640
-				isAllowedTo('modify_any');
641 671
 
642 672
 			if ($context['can_announce'] && !empty($row['id_action']))
643 673
 			{
@@ -661,8 +691,9 @@  discard block
 block discarded – undo
661 691
 
662 692
 				while ($row = $smcFunc['db_fetch_assoc']($request))
663 693
 				{
664
-					if ($row['filesize'] <= 0)
665
-						continue;
694
+					if ($row['filesize'] <= 0) {
695
+											continue;
696
+					}
666 697
 					$context['current_attachments'][$row['id_attach']] = array(
667 698
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
668 699
 						'size' => $row['filesize'],
@@ -732,29 +763,32 @@  discard block
 block discarded – undo
732 763
 			)
733 764
 		);
734 765
 		// The message they were trying to edit was most likely deleted.
735
-		if ($smcFunc['db_num_rows']($request) == 0)
736
-			fatal_lang_error('no_message', false);
766
+		if ($smcFunc['db_num_rows']($request) == 0) {
767
+					fatal_lang_error('no_message', false);
768
+		}
737 769
 		$row = $smcFunc['db_fetch_assoc']($request);
738 770
 
739 771
 		$attachment_stuff = array($row);
740
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
741
-			$attachment_stuff[] = $row2;
772
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
773
+					$attachment_stuff[] = $row2;
774
+		}
742 775
 		$smcFunc['db_free_result']($request);
743 776
 
744 777
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
745 778
 		{
746 779
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
747
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
748
-				fatal_lang_error('modify_post_time_passed', false);
749
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
750
-				isAllowedTo('modify_replies');
751
-			else
752
-				isAllowedTo('modify_own');
780
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
781
+							fatal_lang_error('modify_post_time_passed', false);
782
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
783
+							isAllowedTo('modify_replies');
784
+			} else {
785
+							isAllowedTo('modify_own');
786
+			}
787
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
788
+					isAllowedTo('modify_replies');
789
+		} else {
790
+					isAllowedTo('modify_any');
753 791
 		}
754
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
755
-			isAllowedTo('modify_replies');
756
-		else
757
-			isAllowedTo('modify_any');
758 792
 
759 793
 		if ($context['can_announce'] && !empty($row['id_action']))
760 794
 		{
@@ -781,15 +815,17 @@  discard block
 block discarded – undo
781 815
 		$context['icon'] = $row['icon'];
782 816
 
783 817
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
784
-		if (!$row['approved'] && !$context['show_approval'])
785
-			$context['show_approval'] = allowedTo('approve_posts');
818
+		if (!$row['approved'] && !$context['show_approval']) {
819
+					$context['show_approval'] = allowedTo('approve_posts');
820
+		}
786 821
 
787 822
 		// Sort the attachments so they are in the order saved
788 823
 		$temp = array();
789 824
 		foreach ($attachment_stuff as $attachment)
790 825
 		{
791
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
792
-				$temp[$attachment['id_attach']] = $attachment;
826
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
827
+							$temp[$attachment['id_attach']] = $attachment;
828
+			}
793 829
 		}
794 830
 		ksort($temp);
795 831
 
@@ -850,14 +886,16 @@  discard block
 block discarded – undo
850 886
 					'is_approved' => 1,
851 887
 				)
852 888
 			);
853
-			if ($smcFunc['db_num_rows']($request) == 0)
854
-				fatal_lang_error('quoted_post_deleted', false);
889
+			if ($smcFunc['db_num_rows']($request) == 0) {
890
+							fatal_lang_error('quoted_post_deleted', false);
891
+			}
855 892
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
856 893
 			$smcFunc['db_free_result']($request);
857 894
 
858 895
 			// Add 'Re: ' to the front of the quoted subject.
859
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
860
-				$form_subject = $context['response_prefix'] . $form_subject;
896
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
897
+							$form_subject = $context['response_prefix'] . $form_subject;
898
+			}
861 899
 
862 900
 			// Censor the message and subject.
863 901
 			censorText($form_message);
@@ -870,10 +908,11 @@  discard block
 block discarded – undo
870 908
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
871 909
 				{
872 910
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
873
-					if ($i % 4 == 0)
874
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
911
+					if ($i % 4 == 0) {
912
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
875 913
 						{
876 914
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
915
+					}
877 916
 						}, $parts[$i]);
878 917
 				}
879 918
 				$form_message = implode('', $parts);
@@ -882,8 +921,9 @@  discard block
 block discarded – undo
882 921
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
883 922
 
884 923
 			// Remove any nested quotes, if necessary.
885
-			if (!empty($modSettings['removeNestedQuotes']))
886
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
924
+			if (!empty($modSettings['removeNestedQuotes'])) {
925
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
926
+			}
887 927
 
888 928
 			// Add a quote string on the front and end.
889 929
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -895,15 +935,15 @@  discard block
 block discarded – undo
895 935
 			$form_subject = $first_subject;
896 936
 
897 937
 			// Add 'Re: ' to the front of the subject.
898
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
899
-				$form_subject = $context['response_prefix'] . $form_subject;
938
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
939
+							$form_subject = $context['response_prefix'] . $form_subject;
940
+			}
900 941
 
901 942
 			// Censor the subject.
902 943
 			censorText($form_subject);
903 944
 
904 945
 			$form_message = '';
905
-		}
906
-		else
946
+		} else
907 947
 		{
908 948
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
909 949
 			$form_message = '';
@@ -922,13 +962,15 @@  discard block
 block discarded – undo
922 962
 		if (isset($_REQUEST['msg']))
923 963
 		{
924 964
 			$context['attachments']['quantity'] = count($context['current_attachments']);
925
-			foreach ($context['current_attachments'] as $attachment)
926
-				$context['attachments']['total_size'] += $attachment['size'];
965
+			foreach ($context['current_attachments'] as $attachment) {
966
+							$context['attachments']['total_size'] += $attachment['size'];
967
+			}
927 968
 		}
928 969
 
929 970
 		// A bit of house keeping first.
930
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
931
-			unset($_SESSION['temp_attachments']);
971
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
972
+					unset($_SESSION['temp_attachments']);
973
+		}
932 974
 
933 975
 		if (!empty($_SESSION['temp_attachments']))
934 976
 		{
@@ -937,9 +979,10 @@  discard block
 block discarded – undo
937 979
 			{
938 980
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
939 981
 				{
940
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
941
-						if (file_exists($attachment['tmp_name']))
982
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
983
+											if (file_exists($attachment['tmp_name']))
942 984
 							unlink($attachment['tmp_name']);
985
+					}
943 986
 				}
944 987
 				$post_errors[] = 'temp_attachments_gone';
945 988
 				$_SESSION['temp_attachments'] = array();
@@ -953,8 +996,9 @@  discard block
 block discarded – undo
953 996
 					// See if any files still exist before showing the warning message and the files attached.
954 997
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
955 998
 					{
956
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
957
-							continue;
999
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1000
+													continue;
1001
+						}
958 1002
 
959 1003
 						if (file_exists($attachment['tmp_name']))
960 1004
 						{
@@ -964,20 +1008,21 @@  discard block
 block discarded – undo
964 1008
 							break;
965 1009
 						}
966 1010
 					}
967
-				}
968
-				else
1011
+				} else
969 1012
 				{
970 1013
 					// Since, they don't belong here. Let's inform the user that they exist..
971
-					if (!empty($topic))
972
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
973
-					else
974
-						$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1014
+					if (!empty($topic)) {
1015
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
1016
+					} else {
1017
+											$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1018
+					}
975 1019
 
976 1020
 					// Compile a list of the files to show the user.
977 1021
 					$file_list = array();
978
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
979
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1022
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1023
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
980 1024
 							$file_list[] = $attachment['name'];
1025
+					}
981 1026
 
982 1027
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
983 1028
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -989,8 +1034,7 @@  discard block
 block discarded – undo
989 1034
 
990 1035
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
991 1036
 						$context['ignore_temp_attachments'] = true;
992
-					}
993
-					else
1037
+					} else
994 1038
 					{
995 1039
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
996 1040
 						$context['ignore_temp_attachments'] = true;
@@ -998,16 +1042,19 @@  discard block
 block discarded – undo
998 1042
 				}
999 1043
 			}
1000 1044
 
1001
-			if (!empty($context['we_are_history']))
1002
-				$post_errors[] = $context['we_are_history'];
1045
+			if (!empty($context['we_are_history'])) {
1046
+							$post_errors[] = $context['we_are_history'];
1047
+			}
1003 1048
 
1004 1049
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1005 1050
 			{
1006
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
1007
-					break;
1051
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1052
+									break;
1053
+				}
1008 1054
 
1009
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1010
-					continue;
1055
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1056
+									continue;
1057
+				}
1011 1058
 
1012 1059
 				if ($attachID == 'initial_error')
1013 1060
 				{
@@ -1022,15 +1069,17 @@  discard block
 block discarded – undo
1022 1069
 				{
1023 1070
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1024 1071
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1025
-					foreach ($attachment['errors'] as $error)
1026
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1072
+					foreach ($attachment['errors'] as $error) {
1073
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1074
+					}
1027 1075
 					$txt['error_attach_errors'] .= '</div>';
1028 1076
 					$post_errors[] = 'attach_errors';
1029 1077
 
1030 1078
 					// Take out the trash.
1031 1079
 					unset($_SESSION['temp_attachments'][$attachID]);
1032
-					if (file_exists($attachment['tmp_name']))
1033
-						unlink($attachment['tmp_name']);
1080
+					if (file_exists($attachment['tmp_name'])) {
1081
+											unlink($attachment['tmp_name']);
1082
+					}
1034 1083
 					continue;
1035 1084
 				}
1036 1085
 
@@ -1043,8 +1092,9 @@  discard block
 block discarded – undo
1043 1092
 
1044 1093
 				$context['attachments']['quantity']++;
1045 1094
 				$context['attachments']['total_size'] += $attachment['size'];
1046
-				if (!isset($context['files_in_session_warning']))
1047
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1095
+				if (!isset($context['files_in_session_warning'])) {
1096
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1097
+				}
1048 1098
 
1049 1099
 				$context['current_attachments'][$attachID] = array(
1050 1100
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1072,8 +1122,9 @@  discard block
 block discarded – undo
1072 1122
 	}
1073 1123
 
1074 1124
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1075
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1076
-		$post_errors[] = 'need_qr_verification';
1125
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1126
+			$post_errors[] = 'need_qr_verification';
1127
+	}
1077 1128
 
1078 1129
 	/*
1079 1130
 	 * There are two error types: serious and minor. Serious errors
@@ -1090,52 +1141,56 @@  discard block
 block discarded – undo
1090 1141
 	{
1091 1142
 		loadLanguage('Errors');
1092 1143
 		$context['error_type'] = 'minor';
1093
-		foreach ($post_errors as $post_error)
1094
-			if (is_array($post_error))
1144
+		foreach ($post_errors as $post_error) {
1145
+					if (is_array($post_error))
1095 1146
 			{
1096 1147
 				$post_error_id = $post_error[0];
1148
+		}
1097 1149
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1098 1150
 
1099 1151
 				// If it's not a minor error flag it as such.
1100
-				if (!in_array($post_error_id, $minor_errors))
1101
-					$context['error_type'] = 'serious';
1102
-			}
1103
-			else
1152
+				if (!in_array($post_error_id, $minor_errors)) {
1153
+									$context['error_type'] = 'serious';
1154
+				}
1155
+			} else
1104 1156
 			{
1105 1157
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1106 1158
 
1107 1159
 				// If it's not a minor error flag it as such.
1108
-				if (!in_array($post_error, $minor_errors))
1109
-					$context['error_type'] = 'serious';
1160
+				if (!in_array($post_error, $minor_errors)) {
1161
+									$context['error_type'] = 'serious';
1162
+				}
1110 1163
 			}
1111 1164
 	}
1112 1165
 
1113 1166
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1114
-	if (isset($_REQUEST['poll']))
1115
-		$context['page_title'] = $txt['new_poll'];
1116
-	elseif ($context['make_event'])
1117
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1118
-	elseif (isset($_REQUEST['msg']))
1119
-		$context['page_title'] = $txt['modify_msg'];
1120
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1121
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1122
-	elseif (empty($topic))
1123
-		$context['page_title'] = $txt['start_new_topic'];
1124
-	else
1125
-		$context['page_title'] = $txt['post_reply'];
1167
+	if (isset($_REQUEST['poll'])) {
1168
+			$context['page_title'] = $txt['new_poll'];
1169
+	} elseif ($context['make_event']) {
1170
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1171
+	} elseif (isset($_REQUEST['msg'])) {
1172
+			$context['page_title'] = $txt['modify_msg'];
1173
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1174
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1175
+	} elseif (empty($topic)) {
1176
+			$context['page_title'] = $txt['start_new_topic'];
1177
+	} else {
1178
+			$context['page_title'] = $txt['post_reply'];
1179
+	}
1126 1180
 
1127 1181
 	// Build the link tree.
1128
-	if (empty($topic))
1129
-		$context['linktree'][] = array(
1182
+	if (empty($topic)) {
1183
+			$context['linktree'][] = array(
1130 1184
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1131 1185
 		);
1132
-	else
1133
-		$context['linktree'][] = array(
1186
+	} else {
1187
+			$context['linktree'][] = array(
1134 1188
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1135 1189
 			'name' => $form_subject,
1136 1190
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1137 1191
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1138 1192
 		);
1193
+	}
1139 1194
 
1140 1195
 	$context['subject'] = addcslashes($form_subject, '"');
1141 1196
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1179,8 +1234,9 @@  discard block
 block discarded – undo
1179 1234
 	// Message icons - customized icons are off?
1180 1235
 	$context['icons'] = getMessageIcons(!empty($board) ? $board : 0);
1181 1236
 
1182
-	if (!empty($context['icons']))
1183
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1237
+	if (!empty($context['icons'])) {
1238
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1239
+	}
1184 1240
 
1185 1241
 	// Are we starting a poll? if set the poll icon as selected if its available
1186 1242
 	if (isset($_REQUEST['poll']))
@@ -1200,8 +1256,9 @@  discard block
 block discarded – undo
1200 1256
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1201 1257
 	{
1202 1258
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1203
-		if ($context['icons'][$i]['selected'])
1204
-			$context['icon_url'] = $context['icons'][$i]['url'];
1259
+		if ($context['icons'][$i]['selected']) {
1260
+					$context['icon_url'] = $context['icons'][$i]['url'];
1261
+		}
1205 1262
 	}
1206 1263
 	if (empty($context['icon_url']))
1207 1264
 	{
@@ -1215,8 +1272,9 @@  discard block
 block discarded – undo
1215 1272
 		));
1216 1273
 	}
1217 1274
 
1218
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1219
-		getTopic();
1275
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1276
+			getTopic();
1277
+	}
1220 1278
 
1221 1279
 	// If the user can post attachments prepare the warning labels.
1222 1280
 	if ($context['can_post_attachment'])
@@ -1227,12 +1285,13 @@  discard block
 block discarded – undo
1227 1285
 		$context['attachment_restrictions'] = array();
1228 1286
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1229 1287
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1230
-		foreach ($attachmentRestrictionTypes as $type)
1231
-			if (!empty($modSettings[$type]))
1288
+		foreach ($attachmentRestrictionTypes as $type) {
1289
+					if (!empty($modSettings[$type]))
1232 1290
 			{
1233 1291
 				// Show the max number of attachments if not 0.
1234 1292
 				if ($type == 'attachmentNumPerPostLimit')
1235 1293
 					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1294
+		}
1236 1295
 			}
1237 1296
 	}
1238 1297
 
@@ -1266,8 +1325,8 @@  discard block
 block discarded – undo
1266 1325
 
1267 1326
 	if (!empty($context['current_attachments']))
1268 1327
 	{
1269
-		foreach ($context['current_attachments'] as $key => $mock)
1270
-			addInlineJavaScript('
1328
+		foreach ($context['current_attachments'] as $key => $mock) {
1329
+					addInlineJavaScript('
1271 1330
 	current_attachments.push({
1272 1331
 		name: '. JavaScriptEscape($mock['name']) . ',
1273 1332
 		size: '. $mock['size'] . ',
@@ -1276,6 +1335,7 @@  discard block
 block discarded – undo
1276 1335
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1277 1336
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1278 1337
 	});');
1338
+		}
1279 1339
 	}
1280 1340
 
1281 1341
 	// File Upload.
@@ -1374,12 +1434,13 @@  discard block
 block discarded – undo
1374 1434
 		{
1375 1435
 			$context['posting_fields']['board']['input']['options'][$category['name']] = array('options' => array());
1376 1436
 
1377
-			foreach ($category['boards'] as $brd)
1378
-				$context['posting_fields']['board']['input']['options'][$category['name']]['options'][$brd['name']]['attributes'] = array(
1437
+			foreach ($category['boards'] as $brd) {
1438
+							$context['posting_fields']['board']['input']['options'][$category['name']]['options'][$brd['name']]['attributes'] = array(
1379 1439
 					'value' => $brd['id'],
1380 1440
 					'selected' => (bool) $brd['selected'],
1381 1441
 					'label' => ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=&gt;' : '') . ' ' . $brd['name'],
1382 1442
 				);
1443
+			}
1383 1444
 		}
1384 1445
 	}
1385 1446
 
@@ -1425,8 +1486,9 @@  discard block
 block discarded – undo
1425 1486
 
1426 1487
 
1427 1488
 	// Finally, load the template.
1428
-	if (!isset($_REQUEST['xml']))
1429
-		loadTemplate('Post');
1489
+	if (!isset($_REQUEST['xml'])) {
1490
+			loadTemplate('Post');
1491
+	}
1430 1492
 
1431 1493
 	call_integration_hook('integrate_post_end');
1432 1494
 }
@@ -1447,13 +1509,14 @@  discard block
 block discarded – undo
1447 1509
 	// Sneaking off, are we?
1448 1510
 	if (empty($_POST) && empty($topic))
1449 1511
 	{
1450
-		if (empty($_SERVER['CONTENT_LENGTH']))
1451
-			redirectexit('action=post;board=' . $board . '.0');
1452
-		else
1453
-			fatal_lang_error('post_upload_error', false);
1512
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1513
+					redirectexit('action=post;board=' . $board . '.0');
1514
+		} else {
1515
+					fatal_lang_error('post_upload_error', false);
1516
+		}
1517
+	} elseif (empty($_POST) && !empty($topic)) {
1518
+			redirectexit('action=post;topic=' . $topic . '.0');
1454 1519
 	}
1455
-	elseif (empty($_POST) && !empty($topic))
1456
-		redirectexit('action=post;topic=' . $topic . '.0');
1457 1520
 
1458 1521
 	// No need!
1459 1522
 	$context['robot_no_index'] = true;
@@ -1465,8 +1528,9 @@  discard block
 block discarded – undo
1465 1528
 	$post_errors = array();
1466 1529
 
1467 1530
 	// If the session has timed out, let the user re-submit their form.
1468
-	if (checkSession('post', '', false) != '')
1469
-		$post_errors[] = 'session_timeout';
1531
+	if (checkSession('post', '', false) != '') {
1532
+			$post_errors[] = 'session_timeout';
1533
+	}
1470 1534
 
1471 1535
 	// Wrong verification code?
1472 1536
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1476,8 +1540,9 @@  discard block
 block discarded – undo
1476 1540
 			'id' => 'post',
1477 1541
 		);
1478 1542
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1479
-		if (is_array($context['require_verification']))
1480
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1543
+		if (is_array($context['require_verification'])) {
1544
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1545
+		}
1481 1546
 	}
1482 1547
 
1483 1548
 	require_once($sourcedir . '/Subs-Post.php');
@@ -1486,25 +1551,29 @@  discard block
 block discarded – undo
1486 1551
 	call_integration_hook('integrate_post2_start');
1487 1552
 
1488 1553
 	// Drafts enabled and needed?
1489
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1490
-		require_once($sourcedir . '/Drafts.php');
1554
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1555
+			require_once($sourcedir . '/Drafts.php');
1556
+	}
1491 1557
 
1492 1558
 	// First check to see if they are trying to delete any current attachments.
1493 1559
 	if (isset($_POST['attach_del']))
1494 1560
 	{
1495 1561
 		$keep_temp = array();
1496 1562
 		$keep_ids = array();
1497
-		foreach ($_POST['attach_del'] as $dummy)
1498
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1563
+		foreach ($_POST['attach_del'] as $dummy) {
1564
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1499 1565
 				$keep_temp[] = $dummy;
1500
-			else
1501
-				$keep_ids[] = (int) $dummy;
1566
+		}
1567
+			else {
1568
+							$keep_ids[] = (int) $dummy;
1569
+			}
1502 1570
 
1503
-		if (isset($_SESSION['temp_attachments']))
1504
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1571
+		if (isset($_SESSION['temp_attachments'])) {
1572
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1505 1573
 			{
1506 1574
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1507 1575
 					continue;
1576
+		}
1508 1577
 
1509 1578
 				unset($_SESSION['temp_attachments'][$attachID]);
1510 1579
 				unlink($attachment['tmp_name']);
@@ -1536,8 +1605,9 @@  discard block
 block discarded – undo
1536 1605
 	{
1537 1606
 		require_once($sourcedir . '/ManageAttachments.php');
1538 1607
 
1539
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
1540
-			removeAttachments(array('id_attach' => $attachID));
1608
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
1609
+					removeAttachments(array('id_attach' => $attachID));
1610
+		}
1541 1611
 
1542 1612
 		unset($_SESSION['already_attached']);
1543 1613
 
@@ -1560,12 +1630,14 @@  discard block
 block discarded – undo
1560 1630
 		$smcFunc['db_free_result']($request);
1561 1631
 
1562 1632
 		// Though the topic should be there, it might have vanished.
1563
-		if (!is_array($topic_info))
1564
-			fatal_lang_error('topic_doesnt_exist', 404);
1633
+		if (!is_array($topic_info)) {
1634
+					fatal_lang_error('topic_doesnt_exist', 404);
1635
+		}
1565 1636
 
1566 1637
 		// Did this topic suddenly move? Just checking...
1567
-		if ($topic_info['id_board'] != $board)
1568
-			fatal_lang_error('not_a_topic');
1638
+		if ($topic_info['id_board'] != $board) {
1639
+					fatal_lang_error('not_a_topic');
1640
+		}
1569 1641
 
1570 1642
 		// Do the permissions and approval stuff...
1571 1643
 		$becomesApproved = true;
@@ -1588,49 +1660,50 @@  discard block
 block discarded – undo
1588 1660
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1589 1661
 	{
1590 1662
 		// Don't allow a post if it's locked.
1591
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1592
-			fatal_lang_error('topic_locked', false);
1663
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1664
+					fatal_lang_error('topic_locked', false);
1665
+		}
1593 1666
 
1594 1667
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1595
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1596
-			unset($_REQUEST['poll']);
1597
-
1598
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1599
-		{
1600
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1601
-				$becomesApproved = false;
1602
-
1603
-			else
1604
-				isAllowedTo('post_reply_any');
1605
-		}
1606
-		elseif (!allowedTo('post_reply_any'))
1668
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1669
+					unset($_REQUEST['poll']);
1670
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1671
+		{
1672
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1673
+							$becomesApproved = false;
1674
+			} else {
1675
+							isAllowedTo('post_reply_any');
1676
+			}
1677
+		} elseif (!allowedTo('post_reply_any'))
1607 1678
 		{
1608
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1609
-				$becomesApproved = false;
1610
-
1611
-			else
1612
-				isAllowedTo('post_reply_own');
1679
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1680
+							$becomesApproved = false;
1681
+			} else {
1682
+							isAllowedTo('post_reply_own');
1683
+			}
1613 1684
 		}
1614 1685
 
1615 1686
 		if (isset($_POST['lock']))
1616 1687
 		{
1617 1688
 			// Nothing is changed to the lock.
1618
-			if (empty($topic_info['locked']) == empty($_POST['lock']))
1619
-				unset($_POST['lock']);
1689
+			if (empty($topic_info['locked']) == empty($_POST['lock'])) {
1690
+							unset($_POST['lock']);
1691
+			}
1620 1692
 
1621 1693
 			// You're have no permission to lock this topic.
1622
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1623
-				unset($_POST['lock']);
1694
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1695
+							unset($_POST['lock']);
1696
+			}
1624 1697
 
1625 1698
 			// You are allowed to (un)lock your own topic only.
1626 1699
 			elseif (!allowedTo('lock_any'))
1627 1700
 			{
1628 1701
 				// You cannot override a moderator lock.
1629
-				if ($topic_info['locked'] == 1)
1630
-					unset($_POST['lock']);
1631
-
1632
-				else
1633
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1702
+				if ($topic_info['locked'] == 1) {
1703
+									unset($_POST['lock']);
1704
+				} else {
1705
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1706
+				}
1634 1707
 			}
1635 1708
 			// Hail mighty moderator, (un)lock this topic immediately.
1636 1709
 			else
@@ -1638,19 +1711,21 @@  discard block
 block discarded – undo
1638 1711
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1639 1712
 
1640 1713
 				// Did someone (un)lock this while you were posting?
1641
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1642
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1714
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1715
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1716
+				}
1643 1717
 			}
1644 1718
 		}
1645 1719
 
1646 1720
 		// So you wanna (un)sticky this...let's see.
1647
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1648
-			unset($_POST['sticky']);
1649
-		elseif (isset($_POST['sticky']))
1721
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1722
+					unset($_POST['sticky']);
1723
+		} elseif (isset($_POST['sticky']))
1650 1724
 		{
1651 1725
 			// Did someone (un)sticky this while you were posting?
1652
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1653
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1726
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1727
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1728
+			}
1654 1729
 		}
1655 1730
 
1656 1731
 		// If drafts are enabled, then pass this off
@@ -1677,26 +1752,31 @@  discard block
 block discarded – undo
1677 1752
 
1678 1753
 		// Do like, the permissions, for safety and stuff...
1679 1754
 		$becomesApproved = true;
1680
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1681
-			$becomesApproved = false;
1682
-		else
1683
-			isAllowedTo('post_new');
1755
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1756
+					$becomesApproved = false;
1757
+		} else {
1758
+					isAllowedTo('post_new');
1759
+		}
1684 1760
 
1685 1761
 		if (isset($_POST['lock']))
1686 1762
 		{
1687 1763
 			// New topics are by default not locked.
1688
-			if (empty($_POST['lock']))
1689
-				unset($_POST['lock']);
1764
+			if (empty($_POST['lock'])) {
1765
+							unset($_POST['lock']);
1766
+			}
1690 1767
 			// Besides, you need permission.
1691
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1692
-				unset($_POST['lock']);
1768
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1769
+							unset($_POST['lock']);
1770
+			}
1693 1771
 			// A moderator-lock (1) can override a user-lock (2).
1694
-			else
1695
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1772
+			else {
1773
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1774
+			}
1696 1775
 		}
1697 1776
 
1698
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1699
-			unset($_POST['sticky']);
1777
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1778
+					unset($_POST['sticky']);
1779
+		}
1700 1780
 
1701 1781
 		// Saving your new topic as a draft first?
1702 1782
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1721,31 +1801,37 @@  discard block
 block discarded – undo
1721 1801
 				'id_msg' => $_REQUEST['msg'],
1722 1802
 			)
1723 1803
 		);
1724
-		if ($smcFunc['db_num_rows']($request) == 0)
1725
-			fatal_lang_error('cant_find_messages', false);
1804
+		if ($smcFunc['db_num_rows']($request) == 0) {
1805
+					fatal_lang_error('cant_find_messages', false);
1806
+		}
1726 1807
 		$row = $smcFunc['db_fetch_assoc']($request);
1727 1808
 		$smcFunc['db_free_result']($request);
1728 1809
 
1729
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1730
-			fatal_lang_error('topic_locked', false);
1810
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1811
+					fatal_lang_error('topic_locked', false);
1812
+		}
1731 1813
 
1732 1814
 		if (isset($_POST['lock']))
1733 1815
 		{
1734 1816
 			// Nothing changes to the lock status.
1735
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1736
-				unset($_POST['lock']);
1817
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1818
+							unset($_POST['lock']);
1819
+			}
1737 1820
 			// You're simply not allowed to (un)lock this.
1738
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1739
-				unset($_POST['lock']);
1821
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1822
+							unset($_POST['lock']);
1823
+			}
1740 1824
 			// You're only allowed to lock your own topics.
1741 1825
 			elseif (!allowedTo('lock_any'))
1742 1826
 			{
1743 1827
 				// You're not allowed to break a moderator's lock.
1744
-				if ($topic_info['locked'] == 1)
1745
-					unset($_POST['lock']);
1828
+				if ($topic_info['locked'] == 1) {
1829
+									unset($_POST['lock']);
1830
+				}
1746 1831
 				// Lock it with a soft lock or unlock it.
1747
-				else
1748
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1832
+				else {
1833
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1834
+				}
1749 1835
 			}
1750 1836
 			// You must be the moderator.
1751 1837
 			else
@@ -1753,44 +1839,46 @@  discard block
 block discarded – undo
1753 1839
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1754 1840
 
1755 1841
 				// Did someone (un)lock this while you were posting?
1756
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1757
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1842
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1843
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1844
+				}
1758 1845
 			}
1759 1846
 		}
1760 1847
 
1761 1848
 		// Change the sticky status of this topic?
1762
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1763
-			unset($_POST['sticky']);
1764
-		elseif (isset($_POST['sticky']))
1849
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1850
+					unset($_POST['sticky']);
1851
+		} elseif (isset($_POST['sticky']))
1765 1852
 		{
1766 1853
 			// Did someone (un)sticky this while you were posting?
1767
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1768
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1854
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1855
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1856
+			}
1769 1857
 		}
1770 1858
 
1771 1859
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1772 1860
 		{
1773
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1774
-				fatal_lang_error('modify_post_time_passed', false);
1775
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1776
-				isAllowedTo('modify_replies');
1777
-			else
1778
-				isAllowedTo('modify_own');
1779
-		}
1780
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1861
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1862
+							fatal_lang_error('modify_post_time_passed', false);
1863
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1864
+							isAllowedTo('modify_replies');
1865
+			} else {
1866
+							isAllowedTo('modify_own');
1867
+			}
1868
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1781 1869
 		{
1782 1870
 			isAllowedTo('modify_replies');
1783 1871
 
1784 1872
 			// If you're modifying a reply, I say it better be logged...
1785 1873
 			$moderationAction = true;
1786
-		}
1787
-		else
1874
+		} else
1788 1875
 		{
1789 1876
 			isAllowedTo('modify_any');
1790 1877
 
1791 1878
 			// Log it, assuming you're not modifying your own post.
1792
-			if ($row['id_member'] != $user_info['id'])
1793
-				$moderationAction = true;
1879
+			if ($row['id_member'] != $user_info['id']) {
1880
+							$moderationAction = true;
1881
+			}
1794 1882
 		}
1795 1883
 
1796 1884
 		// If drafts are enabled, then lets send this off to save
@@ -1817,8 +1905,9 @@  discard block
 block discarded – undo
1817 1905
 		// Update search api
1818 1906
 		require_once($sourcedir . '/Search.php');
1819 1907
 		$searchAPI = findSearchAPI();
1820
-		if ($searchAPI->supportsMethod('postRemoved'))
1821
-			$searchAPI->postRemoved($_REQUEST['msg']);
1908
+		if ($searchAPI->supportsMethod('postRemoved')) {
1909
+					$searchAPI->postRemoved($_REQUEST['msg']);
1910
+		}
1822 1911
 
1823 1912
 	}
1824 1913
 
@@ -1836,20 +1925,24 @@  discard block
 block discarded – undo
1836 1925
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1837 1926
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1838 1927
 
1839
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1840
-			$post_errors[] = 'no_name';
1841
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1842
-			$post_errors[] = 'long_name';
1928
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1929
+					$post_errors[] = 'no_name';
1930
+		}
1931
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1932
+					$post_errors[] = 'long_name';
1933
+		}
1843 1934
 
1844 1935
 		if (empty($modSettings['guest_post_no_email']))
1845 1936
 		{
1846 1937
 			// Only check if they changed it!
1847 1938
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1848 1939
 			{
1849
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1850
-					$post_errors[] = 'no_email';
1851
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1852
-					$post_errors[] = 'bad_email';
1940
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1941
+									$post_errors[] = 'no_email';
1942
+				}
1943
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1944
+									$post_errors[] = 'bad_email';
1945
+				}
1853 1946
 			}
1854 1947
 
1855 1948
 			// Now make sure this email address is not banned from posting.
@@ -1865,76 +1958,90 @@  discard block
 block discarded – undo
1865 1958
 	}
1866 1959
 
1867 1960
 	// Coming from the quickReply?
1868
-	if (isset($_POST['quickReply']))
1869
-		$_POST['message'] = $_POST['quickReply'];
1961
+	if (isset($_POST['quickReply'])) {
1962
+			$_POST['message'] = $_POST['quickReply'];
1963
+	}
1870 1964
 
1871 1965
 	// Check the subject and message.
1872
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1873
-		$post_errors[] = 'no_subject';
1874
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1875
-		$post_errors[] = 'no_message';
1876
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1877
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1878
-	else
1966
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1967
+			$post_errors[] = 'no_subject';
1968
+	}
1969
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1970
+			$post_errors[] = 'no_message';
1971
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1972
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1973
+	} else
1879 1974
 	{
1880 1975
 		// Prepare the message a bit for some additional testing.
1881 1976
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1882 1977
 
1883 1978
 		// Preparse code. (Zef)
1884
-		if ($user_info['is_guest'])
1885
-			$user_info['name'] = $_POST['guestname'];
1979
+		if ($user_info['is_guest']) {
1980
+					$user_info['name'] = $_POST['guestname'];
1981
+		}
1886 1982
 		preparsecode($_POST['message']);
1887 1983
 
1888 1984
 		// Let's see if there's still some content left without the tags.
1889
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1890
-			$post_errors[] = 'no_message';
1985
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1986
+					$post_errors[] = 'no_message';
1987
+		}
1891 1988
 
1892 1989
 	}
1893
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1894
-		$post_errors[] = 'no_event';
1990
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1991
+			$post_errors[] = 'no_event';
1992
+	}
1895 1993
 	// You are not!
1896
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1897
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1994
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1995
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1996
+	}
1898 1997
 
1899 1998
 	// Validate the poll...
1900 1999
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1901 2000
 	{
1902
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1903
-			fatal_lang_error('no_access', false);
2001
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
2002
+					fatal_lang_error('no_access', false);
2003
+		}
1904 2004
 
1905 2005
 		// This is a new topic... so it's a new poll.
1906
-		if (empty($topic))
1907
-			isAllowedTo('poll_post');
2006
+		if (empty($topic)) {
2007
+					isAllowedTo('poll_post');
2008
+		}
1908 2009
 		// Can you add to your own topics?
1909
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1910
-			isAllowedTo('poll_add_own');
2010
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
2011
+					isAllowedTo('poll_add_own');
2012
+		}
1911 2013
 		// Can you add polls to any topic, then?
1912
-		else
1913
-			isAllowedTo('poll_add_any');
2014
+		else {
2015
+					isAllowedTo('poll_add_any');
2016
+		}
1914 2017
 
1915
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1916
-			$post_errors[] = 'no_question';
2018
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
2019
+					$post_errors[] = 'no_question';
2020
+		}
1917 2021
 
1918 2022
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1919 2023
 
1920 2024
 		// Get rid of empty ones.
1921
-		foreach ($_POST['options'] as $k => $option)
1922
-			if ($option == '')
2025
+		foreach ($_POST['options'] as $k => $option) {
2026
+					if ($option == '')
1923 2027
 				unset($_POST['options'][$k], $_POST['options'][$k]);
2028
+		}
1924 2029
 
1925 2030
 		// What are you going to vote between with one choice?!?
1926
-		if (count($_POST['options']) < 2)
1927
-			$post_errors[] = 'poll_few';
1928
-		elseif (count($_POST['options']) > 256)
1929
-			$post_errors[] = 'poll_many';
2031
+		if (count($_POST['options']) < 2) {
2032
+					$post_errors[] = 'poll_few';
2033
+		} elseif (count($_POST['options']) > 256) {
2034
+					$post_errors[] = 'poll_many';
2035
+		}
1930 2036
 	}
1931 2037
 
1932 2038
 	if ($posterIsGuest)
1933 2039
 	{
1934 2040
 		// If user is a guest, make sure the chosen name isn't taken.
1935 2041
 		require_once($sourcedir . '/Subs-Members.php');
1936
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1937
-			$post_errors[] = 'bad_name';
2042
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
2043
+					$post_errors[] = 'bad_name';
2044
+		}
1938 2045
 	}
1939 2046
 	// If the user isn't a guest, get his or her name and email.
1940 2047
 	elseif (!isset($_REQUEST['msg']))
@@ -1965,8 +2072,9 @@  discard block
 block discarded – undo
1965 2072
 	}
1966 2073
 
1967 2074
 	// Make sure the user isn't spamming the board.
1968
-	if (!isset($_REQUEST['msg']))
1969
-		spamProtection('post');
2075
+	if (!isset($_REQUEST['msg'])) {
2076
+			spamProtection('post');
2077
+	}
1970 2078
 
1971 2079
 	// At about this point, we're posting and that's that.
1972 2080
 	ignore_user_abort(true);
@@ -1979,32 +2087,36 @@  discard block
 block discarded – undo
1979 2087
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1980 2088
 
1981 2089
 	// At this point, we want to make sure the subject isn't too long.
1982
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1983
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2090
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
2091
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2092
+	}
1984 2093
 
1985 2094
 	// Same with the "why did you edit this" text.
1986
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1987
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2095
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2096
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2097
+	}
1988 2098
 
1989 2099
 	// Make the poll...
1990 2100
 	if (isset($_REQUEST['poll']))
1991 2101
 	{
1992 2102
 		// Make sure that the user has not entered a ridiculous number of options..
1993
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1994
-			$_POST['poll_max_votes'] = 1;
1995
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1996
-			$_POST['poll_max_votes'] = count($_POST['options']);
1997
-		else
1998
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2103
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
2104
+					$_POST['poll_max_votes'] = 1;
2105
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
2106
+					$_POST['poll_max_votes'] = count($_POST['options']);
2107
+		} else {
2108
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2109
+		}
1999 2110
 
2000 2111
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
2001 2112
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
2002 2113
 
2003 2114
 		// Just set it to zero if it's not there..
2004
-		if (!isset($_POST['poll_hide']))
2005
-			$_POST['poll_hide'] = 0;
2006
-		else
2007
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2115
+		if (!isset($_POST['poll_hide'])) {
2116
+					$_POST['poll_hide'] = 0;
2117
+		} else {
2118
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2119
+		}
2008 2120
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
2009 2121
 
2010 2122
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -2013,16 +2125,19 @@  discard block
 block discarded – undo
2013 2125
 		{
2014 2126
 			require_once($sourcedir . '/Subs-Members.php');
2015 2127
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
2016
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
2017
-				$_POST['poll_guest_vote'] = 0;
2128
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2129
+							$_POST['poll_guest_vote'] = 0;
2130
+			}
2018 2131
 		}
2019 2132
 
2020 2133
 		// If the user tries to set the poll too far in advance, don't let them.
2021
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
2022
-			fatal_lang_error('poll_range_error', false);
2134
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2135
+					fatal_lang_error('poll_range_error', false);
2136
+		}
2023 2137
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
2024
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
2025
-			$_POST['poll_hide'] = 1;
2138
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2139
+					$_POST['poll_hide'] = 1;
2140
+		}
2026 2141
 
2027 2142
 		// Clean up the question and answers.
2028 2143
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -2036,13 +2151,15 @@  discard block
 block discarded – undo
2036 2151
 	{
2037 2152
 		$attachIDs = array();
2038 2153
 		$attach_errors = array();
2039
-		if (!empty($context['we_are_history']))
2040
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2154
+		if (!empty($context['we_are_history'])) {
2155
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2156
+		}
2041 2157
 
2042 2158
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
2043 2159
 		{
2044
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
2045
-				continue;
2160
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2161
+							continue;
2162
+			}
2046 2163
 
2047 2164
 			// If there was an initial error just show that message.
2048 2165
 			if ($attachID == 'initial_error')
@@ -2071,12 +2188,13 @@  discard block
 block discarded – undo
2071 2188
 				if (createAttachment($attachmentOptions))
2072 2189
 				{
2073 2190
 					$attachIDs[] = $attachmentOptions['id'];
2074
-					if (!empty($attachmentOptions['thumb']))
2075
-						$attachIDs[] = $attachmentOptions['thumb'];
2191
+					if (!empty($attachmentOptions['thumb'])) {
2192
+											$attachIDs[] = $attachmentOptions['thumb'];
2193
+					}
2076 2194
 				}
2195
+			} else {
2196
+							$attach_errors[] = '<dt>&nbsp;</dt>';
2077 2197
 			}
2078
-			else
2079
-				$attach_errors[] = '<dt>&nbsp;</dt>';
2080 2198
 
2081 2199
 			if (!empty($attachmentOptions['errors']))
2082 2200
 			{
@@ -2088,14 +2206,16 @@  discard block
 block discarded – undo
2088 2206
 					if (!is_array($error))
2089 2207
 					{
2090 2208
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
2091
-						if (in_array($error, $log_these))
2092
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2209
+						if (in_array($error, $log_these)) {
2210
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2211
+						}
2212
+					} else {
2213
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2093 2214
 					}
2094
-					else
2095
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2096 2215
 				}
2097
-				if (file_exists($attachment['tmp_name']))
2098
-					unlink($attachment['tmp_name']);
2216
+				if (file_exists($attachment['tmp_name'])) {
2217
+									unlink($attachment['tmp_name']);
2218
+				}
2099 2219
 			}
2100 2220
 		}
2101 2221
 		unset($_SESSION['temp_attachments']);
@@ -2136,24 +2256,24 @@  discard block
 block discarded – undo
2136 2256
 		);
2137 2257
 
2138 2258
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2259
+	} else {
2260
+			$id_poll = 0;
2139 2261
 	}
2140
-	else
2141
-		$id_poll = 0;
2142 2262
 
2143 2263
 	// Creating a new topic?
2144 2264
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2145 2265
 
2146 2266
 	// Check the icon.
2147
-	if (!isset($_POST['icon']))
2148
-		$_POST['icon'] = 'xx';
2149
-
2150
-	else
2267
+	if (!isset($_POST['icon'])) {
2268
+			$_POST['icon'] = 'xx';
2269
+	} else
2151 2270
 	{
2152 2271
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2153 2272
 
2154 2273
 		// Need to figure it out if this is a valid icon name.
2155
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2156
-			$_POST['icon'] = 'xx';
2274
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2275
+					$_POST['icon'] = 'xx';
2276
+		}
2157 2277
 	}
2158 2278
 
2159 2279
 	// Collect all parameters for the creation or modification of a post.
@@ -2194,8 +2314,9 @@  discard block
 block discarded – undo
2194 2314
 		}
2195 2315
 
2196 2316
 		// This will save some time...
2197
-		if (empty($approve_has_changed))
2198
-			unset($msgOptions['approved']);
2317
+		if (empty($approve_has_changed)) {
2318
+					unset($msgOptions['approved']);
2319
+		}
2199 2320
 
2200 2321
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2201 2322
 	}
@@ -2204,8 +2325,9 @@  discard block
 block discarded – undo
2204 2325
 	{
2205 2326
 		createPost($msgOptions, $topicOptions, $posterOptions);
2206 2327
 
2207
-		if (isset($topicOptions['id']))
2208
-			$topic = $topicOptions['id'];
2328
+		if (isset($topicOptions['id'])) {
2329
+					$topic = $topicOptions['id'];
2330
+		}
2209 2331
 	}
2210 2332
 
2211 2333
 	// Are there attachments already uploaded and waiting to be assigned?
@@ -2217,8 +2339,9 @@  discard block
 block discarded – undo
2217 2339
 	}
2218 2340
 
2219 2341
 	// If we had a draft for this, its time to remove it since it was just posted
2220
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2221
-		DeleteDraft($_POST['id_draft']);
2342
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2343
+			DeleteDraft($_POST['id_draft']);
2344
+	}
2222 2345
 
2223 2346
 	// Editing or posting an event?
2224 2347
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2237,8 +2360,7 @@  discard block
 block discarded – undo
2237 2360
 			'member' => $user_info['id'],
2238 2361
 		);
2239 2362
 		insertEvent($eventOptions);
2240
-	}
2241
-	elseif (isset($_POST['calendar']))
2363
+	} elseif (isset($_POST['calendar']))
2242 2364
 	{
2243 2365
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2244 2366
 
@@ -2266,14 +2388,15 @@  discard block
 block discarded – undo
2266 2388
 		}
2267 2389
 
2268 2390
 		// Delete it?
2269
-		if (isset($_REQUEST['deleteevent']))
2270
-			$smcFunc['db_query']('', '
2391
+		if (isset($_REQUEST['deleteevent'])) {
2392
+					$smcFunc['db_query']('', '
2271 2393
 				DELETE FROM {db_prefix}calendar
2272 2394
 				WHERE id_event = {int:id_event}',
2273 2395
 				array(
2274 2396
 					'id_event' => $_REQUEST['eventid'],
2275 2397
 				)
2276 2398
 			);
2399
+		}
2277 2400
 		// ... or just update it?
2278 2401
 		else
2279 2402
 		{
@@ -2315,9 +2438,8 @@  discard block
 block discarded – undo
2315 2438
 			array($user_info['id'], $topic, 0),
2316 2439
 			array('id_member', 'id_topic', 'id_board')
2317 2440
 		);
2318
-	}
2319
-	elseif (!$newTopic)
2320
-		$smcFunc['db_query']('', '
2441
+	} elseif (!$newTopic) {
2442
+			$smcFunc['db_query']('', '
2321 2443
 			DELETE FROM {db_prefix}log_notify
2322 2444
 			WHERE id_member = {int:current_member}
2323 2445
 				AND id_topic = {int:current_topic}',
@@ -2326,16 +2448,20 @@  discard block
 block discarded – undo
2326 2448
 				'current_topic' => $topic,
2327 2449
 			)
2328 2450
 		);
2451
+	}
2329 2452
 
2330 2453
 	// Log an act of moderation - modifying.
2331
-	if (!empty($moderationAction))
2332
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2454
+	if (!empty($moderationAction)) {
2455
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2456
+	}
2333 2457
 
2334
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2335
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2458
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2459
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2460
+	}
2336 2461
 
2337
-	if (isset($_POST['sticky']))
2338
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2462
+	if (isset($_POST['sticky'])) {
2463
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2464
+	}
2339 2465
 
2340 2466
 	// Returning to the topic?
2341 2467
 	if (!empty($_REQUEST['goback']))
@@ -2354,26 +2480,31 @@  discard block
 block discarded – undo
2354 2480
 		);
2355 2481
 	}
2356 2482
 
2357
-	if ($board_info['num_topics'] == 0)
2358
-		cache_put_data('board-' . $board, null, 120);
2483
+	if ($board_info['num_topics'] == 0) {
2484
+			cache_put_data('board-' . $board, null, 120);
2485
+	}
2359 2486
 
2360 2487
 	call_integration_hook('integrate_post2_end');
2361 2488
 
2362
-	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic'))
2363
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2489
+	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) {
2490
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2491
+	}
2364 2492
 
2365
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2366
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2493
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2494
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2495
+	}
2367 2496
 
2368 2497
 	// Return to post if the mod is on.
2369
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2370
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2371
-	elseif (!empty($_REQUEST['goback']))
2372
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2498
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2499
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2500
+	} elseif (!empty($_REQUEST['goback'])) {
2501
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2502
+	}
2373 2503
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2374
-	else
2375
-		redirectexit('board=' . $board . '.0');
2376
-}
2504
+	else {
2505
+			redirectexit('board=' . $board . '.0');
2506
+	}
2507
+	}
2377 2508
 
2378 2509
 /**
2379 2510
  * Handle the announce topic function (action=announce).
@@ -2391,8 +2522,9 @@  discard block
 block discarded – undo
2391 2522
 
2392 2523
 	validateSession();
2393 2524
 
2394
-	if (empty($topic))
2395
-		fatal_lang_error('topic_gone', false);
2525
+	if (empty($topic)) {
2526
+			fatal_lang_error('topic_gone', false);
2527
+	}
2396 2528
 
2397 2529
 	loadLanguage('Post');
2398 2530
 	loadTemplate('Post');
@@ -2419,8 +2551,9 @@  discard block
 block discarded – undo
2419 2551
 	global $txt, $context, $topic, $board_info, $smcFunc;
2420 2552
 
2421 2553
 	$groups = array_merge($board_info['groups'], array(1));
2422
-	foreach ($groups as $id => $group)
2423
-		$groups[$id] = (int) $group;
2554
+	foreach ($groups as $id => $group) {
2555
+			$groups[$id] = (int) $group;
2556
+	}
2424 2557
 
2425 2558
 	$context['groups'] = array();
2426 2559
 	if (in_array(0, $groups))
@@ -2463,8 +2596,9 @@  discard block
 block discarded – undo
2463 2596
 			'group_list' => $groups,
2464 2597
 		)
2465 2598
 	);
2466
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2467
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2599
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2600
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2601
+	}
2468 2602
 	$smcFunc['db_free_result']($request);
2469 2603
 
2470 2604
 	// Get the subject of the topic we're about to announce.
@@ -2506,16 +2640,19 @@  discard block
 block discarded – undo
2506 2640
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2507 2641
 	$groups = array_merge($board_info['groups'], array(1));
2508 2642
 
2509
-	if (isset($_POST['membergroups']))
2510
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2643
+	if (isset($_POST['membergroups'])) {
2644
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2645
+	}
2511 2646
 
2512 2647
 	// Check whether at least one membergroup was selected.
2513
-	if (empty($_POST['who']))
2514
-		fatal_lang_error('no_membergroup_selected');
2648
+	if (empty($_POST['who'])) {
2649
+			fatal_lang_error('no_membergroup_selected');
2650
+	}
2515 2651
 
2516 2652
 	// Make sure all membergroups are integers and can access the board of the announcement.
2517
-	foreach ($_POST['who'] as $id => $mg)
2518
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2653
+	foreach ($_POST['who'] as $id => $mg) {
2654
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2655
+	}
2519 2656
 
2520 2657
 	// Get the topic subject and censor it.
2521 2658
 	$request = $smcFunc['db_query']('', '
@@ -2561,12 +2698,13 @@  discard block
 block discarded – undo
2561 2698
 	if ($smcFunc['db_num_rows']($request) == 0)
2562 2699
 	{
2563 2700
 		logAction('announce_topic', array('topic' => $topic), 'user');
2564
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2565
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2566
-		elseif (!empty($_REQUEST['goback']))
2567
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2568
-		else
2569
-			redirectexit('board=' . $board . '.0');
2701
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2702
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2703
+		} elseif (!empty($_REQUEST['goback'])) {
2704
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2705
+		} else {
2706
+					redirectexit('board=' . $board . '.0');
2707
+		}
2570 2708
 	}
2571 2709
 
2572 2710
 	$announcements = array();
@@ -2585,8 +2723,9 @@  discard block
 block discarded – undo
2585 2723
 	foreach ($rows as $row)
2586 2724
 	{
2587 2725
 		// Force them to have it?
2588
-		if (empty($prefs[$row['id_member']]['announcements']))
2589
-			continue;
2726
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2727
+					continue;
2728
+		}
2590 2729
 
2591 2730
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2592 2731
 
@@ -2614,8 +2753,9 @@  discard block
 block discarded – undo
2614 2753
 	}
2615 2754
 
2616 2755
 	// For each language send a different mail - low priority...
2617
-	foreach ($announcements as $lang => $mail)
2618
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2756
+	foreach ($announcements as $lang => $mail) {
2757
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2758
+	}
2619 2759
 
2620 2760
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2621 2761
 
@@ -2625,9 +2765,10 @@  discard block
 block discarded – undo
2625 2765
 	$context['sub_template'] = 'announcement_send';
2626 2766
 
2627 2767
 	// Go back to the correct language for the user ;).
2628
-	if (!empty($modSettings['userLanguage']))
2629
-		loadLanguage('Post');
2630
-}
2768
+	if (!empty($modSettings['userLanguage'])) {
2769
+			loadLanguage('Post');
2770
+	}
2771
+	}
2631 2772
 
2632 2773
 /**
2633 2774
  * Get the topic for display purposes.
@@ -2640,12 +2781,13 @@  discard block
 block discarded – undo
2640 2781
 {
2641 2782
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2642 2783
 
2643
-	if (isset($_REQUEST['xml']))
2644
-		$limit = '
2784
+	if (isset($_REQUEST['xml'])) {
2785
+			$limit = '
2645 2786
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2646
-	else
2647
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2787
+	} else {
2788
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2648 2789
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2790
+	}
2649 2791
 
2650 2792
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2651 2793
 	$request = $smcFunc['db_query']('', '
@@ -2683,8 +2825,9 @@  discard block
 block discarded – undo
2683 2825
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2684 2826
 		);
2685 2827
 
2686
-		if (!empty($context['new_replies']))
2687
-			$context['new_replies']--;
2828
+		if (!empty($context['new_replies'])) {
2829
+					$context['new_replies']--;
2830
+		}
2688 2831
 	}
2689 2832
 	$smcFunc['db_free_result']($request);
2690 2833
 }
@@ -2701,8 +2844,9 @@  discard block
 block discarded – undo
2701 2844
 	global $sourcedir, $smcFunc;
2702 2845
 
2703 2846
 	loadLanguage('Post');
2704
-	if (!isset($_REQUEST['xml']))
2705
-		loadTemplate('Post');
2847
+	if (!isset($_REQUEST['xml'])) {
2848
+			loadTemplate('Post');
2849
+	}
2706 2850
 
2707 2851
 	include_once($sourcedir . '/Subs-Post.php');
2708 2852
 
@@ -2733,8 +2877,9 @@  discard block
 block discarded – undo
2733 2877
 	$smcFunc['db_free_result']($request);
2734 2878
 
2735 2879
 	$context['sub_template'] = 'quotefast';
2736
-	if (!empty($row))
2737
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2880
+	if (!empty($row)) {
2881
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2882
+	}
2738 2883
 
2739 2884
 	if (!empty($can_view_post))
2740 2885
 	{
@@ -2767,8 +2912,9 @@  discard block
 block discarded – undo
2767 2912
 		}
2768 2913
 
2769 2914
 		// Remove any nested quotes.
2770
-		if (!empty($modSettings['removeNestedQuotes']))
2771
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2915
+		if (!empty($modSettings['removeNestedQuotes'])) {
2916
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2917
+		}
2772 2918
 
2773 2919
 		$lb = "\n";
2774 2920
 
@@ -2794,14 +2940,14 @@  discard block
 block discarded – undo
2794 2940
 				'time' => '',
2795 2941
 			),
2796 2942
 		);
2797
-	}
2798
-	else
2799
-		$context['quote'] = array(
2943
+	} else {
2944
+			$context['quote'] = array(
2800 2945
 			'xml' => '',
2801 2946
 			'mozilla' => '',
2802 2947
 			'text' => '',
2803 2948
 		);
2804
-}
2949
+	}
2950
+	}
2805 2951
 
2806 2952
 /**
2807 2953
  * Used to edit the body or subject of a message inline
@@ -2813,8 +2959,9 @@  discard block
 block discarded – undo
2813 2959
 	global $user_info, $context, $smcFunc, $language, $board_info;
2814 2960
 
2815 2961
 	// We have to have a topic!
2816
-	if (empty($topic))
2817
-		obExit(false);
2962
+	if (empty($topic)) {
2963
+			obExit(false);
2964
+	}
2818 2965
 
2819 2966
 	checkSession('get');
2820 2967
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2840,31 +2987,35 @@  discard block
 block discarded – undo
2840 2987
 			'guest_id' => 0,
2841 2988
 		)
2842 2989
 	);
2843
-	if ($smcFunc['db_num_rows']($request) == 0)
2844
-		fatal_lang_error('no_board', false);
2990
+	if ($smcFunc['db_num_rows']($request) == 0) {
2991
+			fatal_lang_error('no_board', false);
2992
+	}
2845 2993
 	$row = $smcFunc['db_fetch_assoc']($request);
2846 2994
 	$smcFunc['db_free_result']($request);
2847 2995
 
2848 2996
 	// Change either body or subject requires permissions to modify messages.
2849 2997
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2850 2998
 	{
2851
-		if (!empty($row['locked']))
2852
-			isAllowedTo('moderate_board');
2999
+		if (!empty($row['locked'])) {
3000
+					isAllowedTo('moderate_board');
3001
+		}
2853 3002
 
2854 3003
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2855 3004
 		{
2856
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2857
-				fatal_lang_error('modify_post_time_passed', false);
2858
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2859
-				isAllowedTo('modify_replies');
2860
-			else
2861
-				isAllowedTo('modify_own');
3005
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
3006
+							fatal_lang_error('modify_post_time_passed', false);
3007
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
3008
+							isAllowedTo('modify_replies');
3009
+			} else {
3010
+							isAllowedTo('modify_own');
3011
+			}
2862 3012
 		}
2863 3013
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2864
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2865
-			isAllowedTo('modify_replies');
2866
-		else
2867
-			isAllowedTo('modify_any');
3014
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
3015
+					isAllowedTo('modify_replies');
3016
+		} else {
3017
+					isAllowedTo('modify_any');
3018
+		}
2868 3019
 
2869 3020
 		// Only log this action if it wasn't your message.
2870 3021
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2876,10 +3027,10 @@  discard block
 block discarded – undo
2876 3027
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2877 3028
 
2878 3029
 		// Maximum number of characters.
2879
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2880
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2881
-	}
2882
-	elseif (isset($_POST['subject']))
3030
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
3031
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
3032
+		}
3033
+	} elseif (isset($_POST['subject']))
2883 3034
 	{
2884 3035
 		$post_errors[] = 'no_subject';
2885 3036
 		unset($_POST['subject']);
@@ -2891,13 +3042,11 @@  discard block
 block discarded – undo
2891 3042
 		{
2892 3043
 			$post_errors[] = 'no_message';
2893 3044
 			unset($_POST['message']);
2894
-		}
2895
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
3045
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2896 3046
 		{
2897 3047
 			$post_errors[] = 'long_message';
2898 3048
 			unset($_POST['message']);
2899
-		}
2900
-		else
3049
+		} else
2901 3050
 		{
2902 3051
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2903 3052
 
@@ -2913,31 +3062,34 @@  discard block
 block discarded – undo
2913 3062
 
2914 3063
 	if (isset($_POST['lock']))
2915 3064
 	{
2916
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2917
-			unset($_POST['lock']);
2918
-		elseif (!allowedTo('lock_any'))
3065
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
3066
+					unset($_POST['lock']);
3067
+		} elseif (!allowedTo('lock_any'))
2919 3068
 		{
2920
-			if ($row['locked'] == 1)
2921
-				unset($_POST['lock']);
2922
-			else
2923
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3069
+			if ($row['locked'] == 1) {
3070
+							unset($_POST['lock']);
3071
+			} else {
3072
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3073
+			}
3074
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
3075
+					unset($_POST['lock']);
3076
+		} else {
3077
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2924 3078
 		}
2925
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2926
-			unset($_POST['lock']);
2927
-		else
2928
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2929 3079
 	}
2930 3080
 
2931
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2932
-		unset($_POST['sticky']);
3081
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
3082
+			unset($_POST['sticky']);
3083
+	}
2933 3084
 
2934 3085
 	if (isset($_POST['modify_reason']))
2935 3086
 	{
2936 3087
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2937 3088
 
2938 3089
 		// Maximum number of characters.
2939
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2940
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3090
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
3091
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3092
+		}
2941 3093
 	}
2942 3094
 
2943 3095
 	if (empty($post_errors))
@@ -2974,8 +3126,9 @@  discard block
 block discarded – undo
2974 3126
 			}
2975 3127
 		}
2976 3128
 		// If nothing was changed there's no need to add an entry to the moderation log.
2977
-		else
2978
-			$moderationAction = false;
3129
+		else {
3130
+					$moderationAction = false;
3131
+		}
2979 3132
 
2980 3133
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2981 3134
 
@@ -2993,9 +3146,9 @@  discard block
 block discarded – undo
2993 3146
 			// Get the proper (default language) response prefix first.
2994 3147
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2995 3148
 			{
2996
-				if ($language === $user_info['language'])
2997
-					$context['response_prefix'] = $txt['response_prefix'];
2998
-				else
3149
+				if ($language === $user_info['language']) {
3150
+									$context['response_prefix'] = $txt['response_prefix'];
3151
+				} else
2999 3152
 				{
3000 3153
 					loadLanguage('index', $language, false);
3001 3154
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -3017,8 +3170,9 @@  discard block
 block discarded – undo
3017 3170
 			);
3018 3171
 		}
3019 3172
 
3020
-		if (!empty($moderationAction))
3021
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3173
+		if (!empty($moderationAction)) {
3174
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3175
+		}
3022 3176
 	}
3023 3177
 
3024 3178
 	if (isset($_REQUEST['xml']))
@@ -3059,8 +3213,7 @@  discard block
 block discarded – undo
3059 3213
 			);
3060 3214
 
3061 3215
 			censorText($context['message']['subject']);
3062
-		}
3063
-		else
3216
+		} else
3064 3217
 		{
3065 3218
 			$context['message'] = array(
3066 3219
 				'id' => $row['id_msg'],
@@ -3072,15 +3225,16 @@  discard block
 block discarded – undo
3072 3225
 			loadLanguage('Errors');
3073 3226
 			foreach ($post_errors as $post_error)
3074 3227
 			{
3075
-				if ($post_error == 'long_message')
3076
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3077
-				else
3078
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3228
+				if ($post_error == 'long_message') {
3229
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3230
+				} else {
3231
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3232
+				}
3079 3233
 			}
3080 3234
 		}
3235
+	} else {
3236
+			obExit(false);
3237
+	}
3081 3238
 	}
3082
-	else
3083
-		obExit(false);
3084
-}
3085 3239
 
3086 3240
 ?>
3087 3241
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +154 added lines, -121 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -98,23 +102,26 @@  discard block
 block discarded – undo
98 102
 	if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest'])
99 103
 	{
100 104
 		// First check for 2.1 json-format cookie in $_COOKIE
101
-		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1)
102
-			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
105
+		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) {
106
+					list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
107
+		}
103 108
 
104 109
 		// Try checking for 2.1 json-format cookie in $_SESSION
105
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1)
106
-			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
110
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) {
111
+					list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
112
+		}
107 113
 
108 114
 		// Next, try checking for 2.0 serialized string cookie in $_COOKIE
109
-		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1)
110
-			list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
115
+		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) {
116
+					list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
117
+		}
111 118
 
112 119
 		// Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION
113
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1)
114
-			list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
115
-
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
120
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) {
121
+					list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
122
+		} else {
123
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
124
+		}
118 125
 
119 126
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 127
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -134,24 +141,23 @@  discard block
 block discarded – undo
134 141
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
135 142
 	{
136 143
 		// Strike!  You're outta there!
137
-		if ($_GET['member'] != $user_info['id'])
138
-			fatal_lang_error('login_cookie_error', false);
144
+		if ($_GET['member'] != $user_info['id']) {
145
+					fatal_lang_error('login_cookie_error', false);
146
+		}
139 147
 
140 148
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
141 149
 
142 150
 		// Some whitelisting for login_url...
143
-		if (empty($_SESSION['login_url']))
144
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
145
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
151
+		if (empty($_SESSION['login_url'])) {
152
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
153
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
146 154
 		{
147 155
 			unset ($_SESSION['login_url']);
148 156
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
149
-		}
150
-		elseif (!empty($user_settings['tfa_secret']))
157
+		} elseif (!empty($user_settings['tfa_secret']))
151 158
 		{
152 159
 			redirectexit('action=logintfa');
153
-		}
154
-		else
160
+		} else
155 161
 		{
156 162
 			// Best not to clutter the session data too much...
157 163
 			$temp = $_SESSION['login_url'];
@@ -162,8 +168,9 @@  discard block
 block discarded – undo
162 168
 	}
163 169
 
164 170
 	// Beyond this point you are assumed to be a guest trying to login.
165
-	if (!$user_info['is_guest'])
166
-		redirectexit();
171
+	if (!$user_info['is_guest']) {
172
+			redirectexit();
173
+	}
167 174
 
168 175
 	// Are you guessing with a script?
169 176
 	checkSession();
@@ -171,18 +178,21 @@  discard block
 block discarded – undo
171 178
 	spamProtection('login');
172 179
 
173 180
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
174
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
175
-		$_SESSION['login_url'] = $_SESSION['old_url'];
181
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
182
+			$_SESSION['login_url'] = $_SESSION['old_url'];
183
+	}
176 184
 
177 185
 	// Been guessing a lot, haven't we?
178
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
179
-		fatal_lang_error('login_threshold_fail', 'login');
186
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
187
+			fatal_lang_error('login_threshold_fail', 'login');
188
+	}
180 189
 
181 190
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
182
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
183
-		$modSettings['cookieTime'] = 3153600;
184
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600))
185
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
191
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
192
+			$modSettings['cookieTime'] = 3153600;
193
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600)) {
194
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
195
+	}
186 196
 
187 197
 	loadLanguage('Login');
188 198
 	// Load the template stuff.
@@ -302,8 +312,9 @@  discard block
 block discarded – undo
302 312
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
303 313
 
304 314
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
305
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
306
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
315
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
316
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
317
+			}
307 318
 
308 319
 			// phpBB3 users new hashing.  We now support it as well ;).
309 320
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -323,27 +334,29 @@  discard block
 block discarded – undo
323 334
 			// Some common md5 ones.
324 335
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
325 336
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
326
-		}
327
-		elseif (strlen($user_settings['passwd']) == 40)
337
+		} elseif (strlen($user_settings['passwd']) == 40)
328 338
 		{
329 339
 			// Maybe they are using a hash from before the password fix.
330 340
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
331 341
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
332 342
 
333 343
 			// BurningBoard3 style of hashing.
334
-			if (!empty($modSettings['enable_password_conversion']))
335
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
344
+			if (!empty($modSettings['enable_password_conversion'])) {
345
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
346
+			}
336 347
 
337 348
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
338 349
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
339 350
 			{
340 351
 				// Try iconv first, for no particular reason.
341
-				if (function_exists('iconv'))
342
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
352
+				if (function_exists('iconv')) {
353
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
354
+				}
343 355
 
344 356
 				// Say it aint so, iconv failed!
345
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
346
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
357
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
358
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
359
+				}
347 360
 			}
348 361
 		}
349 362
 
@@ -373,8 +386,9 @@  discard block
 block discarded – undo
373 386
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
374 387
 
375 388
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
376
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
377
-				redirectexit('action=reminder');
389
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
390
+							redirectexit('action=reminder');
391
+			}
378 392
 			// We'll give you another chance...
379 393
 			else
380 394
 			{
@@ -385,8 +399,7 @@  discard block
 block discarded – undo
385 399
 				return;
386 400
 			}
387 401
 		}
388
-	}
389
-	elseif (!empty($user_settings['passwd_flood']))
402
+	} elseif (!empty($user_settings['passwd_flood']))
390 403
 	{
391 404
 		// Let's be sure they weren't a little hacker.
392 405
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -403,8 +416,9 @@  discard block
 block discarded – undo
403 416
 	}
404 417
 
405 418
 	// Check their activation status.
406
-	if (!checkActivation())
407
-		return;
419
+	if (!checkActivation()) {
420
+			return;
421
+	}
408 422
 
409 423
 	DoLogin();
410 424
 }
@@ -416,8 +430,9 @@  discard block
 block discarded – undo
416 430
 {
417 431
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
418 432
 
419
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
420
-		fatal_lang_error('no_access', false);
433
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
434
+			fatal_lang_error('no_access', false);
435
+	}
421 436
 
422 437
 	loadLanguage('Profile');
423 438
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -425,8 +440,9 @@  discard block
 block discarded – undo
425 440
 	$member = $context['tfa_member'];
426 441
 
427 442
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
428
-	if (time() - $member['last_login'] < 120)
429
-		fatal_lang_error('tfa_wait', false);
443
+	if (time() - $member['last_login'] < 120) {
444
+			fatal_lang_error('tfa_wait', false);
445
+	}
430 446
 
431 447
 	$totp = new \TOTP\Auth($member['tfa_secret']);
432 448
 	$totp->setRange(1);
@@ -440,8 +456,9 @@  discard block
 block discarded – undo
440 456
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
441 457
 	{
442 458
 		// Check to ensure we're forcing SSL for authentication
443
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
444
-			fatal_lang_error('login_ssl_required');
459
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
460
+					fatal_lang_error('login_ssl_required');
461
+		}
445 462
 
446 463
 		$code = $_POST['tfa_code'];
447 464
 
@@ -451,20 +468,19 @@  discard block
 block discarded – undo
451 468
 
452 469
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
453 470
 			redirectexit();
454
-		}
455
-		else
471
+		} else
456 472
 		{
457 473
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
458 474
 
459 475
 			$context['tfa_error'] = true;
460 476
 			$context['tfa_value'] = $_POST['tfa_code'];
461 477
 		}
462
-	}
463
-	elseif (!empty($_POST['tfa_backup']))
478
+	} elseif (!empty($_POST['tfa_backup']))
464 479
 	{
465 480
 		// Check to ensure we're forcing SSL for authentication
466
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
467
-			fatal_lang_error('login_ssl_required');
481
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
482
+					fatal_lang_error('login_ssl_required');
483
+		}
468 484
 
469 485
 		$backup = $_POST['tfa_backup'];
470 486
 
@@ -478,8 +494,7 @@  discard block
 block discarded – undo
478 494
 			));
479 495
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
480 496
 			redirectexit('action=profile;area=tfasetup;backup');
481
-		}
482
-		else
497
+		} else
483 498
 		{
484 499
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
485 500
 
@@ -502,8 +517,9 @@  discard block
 block discarded – undo
502 517
 {
503 518
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
504 519
 
505
-	if (!isset($context['login_errors']))
506
-		$context['login_errors'] = array();
520
+	if (!isset($context['login_errors'])) {
521
+			$context['login_errors'] = array();
522
+	}
507 523
 
508 524
 	// What is the true activation status of this account?
509 525
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -515,8 +531,9 @@  discard block
 block discarded – undo
515 531
 		return false;
516 532
 	}
517 533
 	// Awaiting approval still?
518
-	elseif ($activation_status == 3)
519
-		fatal_lang_error('still_awaiting_approval', 'user');
534
+	elseif ($activation_status == 3) {
535
+			fatal_lang_error('still_awaiting_approval', 'user');
536
+	}
520 537
 	// Awaiting deletion, changed their mind?
521 538
 	elseif ($activation_status == 4)
522 539
 	{
@@ -524,8 +541,7 @@  discard block
 block discarded – undo
524 541
 		{
525 542
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
526 543
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
527
-		}
528
-		else
544
+		} else
529 545
 		{
530 546
 			$context['disable_login_hashing'] = true;
531 547
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -565,8 +581,9 @@  discard block
 block discarded – undo
565 581
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
566 582
 
567 583
 	// Reset the login threshold.
568
-	if (isset($_SESSION['failed_login']))
569
-		unset($_SESSION['failed_login']);
584
+	if (isset($_SESSION['failed_login'])) {
585
+			unset($_SESSION['failed_login']);
586
+	}
570 587
 
571 588
 	$user_info['is_guest'] = false;
572 589
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -588,16 +605,18 @@  discard block
 block discarded – undo
588 605
 			'id_member' => $user_info['id'],
589 606
 		)
590 607
 	);
591
-	if ($smcFunc['db_num_rows']($request) == 1)
592
-		$_SESSION['first_login'] = true;
593
-	else
594
-		unset($_SESSION['first_login']);
608
+	if ($smcFunc['db_num_rows']($request) == 1) {
609
+			$_SESSION['first_login'] = true;
610
+	} else {
611
+			unset($_SESSION['first_login']);
612
+	}
595 613
 	$smcFunc['db_free_result']($request);
596 614
 
597 615
 	// You've logged in, haven't you?
598 616
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
599
-	if (empty($user_settings['tfa_secret']))
600
-		$update['last_login'] = time();
617
+	if (empty($user_settings['tfa_secret'])) {
618
+			$update['last_login'] = time();
619
+	}
601 620
 	updateMemberData($user_info['id'], $update);
602 621
 
603 622
 	// Get rid of the online entry for that old guest....
@@ -611,8 +630,8 @@  discard block
 block discarded – undo
611 630
 	$_SESSION['log_time'] = 0;
612 631
 
613 632
 	// Log this entry, only if we have it enabled.
614
-	if (!empty($modSettings['loginHistoryDays']))
615
-		$smcFunc['db_insert']('insert',
633
+	if (!empty($modSettings['loginHistoryDays'])) {
634
+			$smcFunc['db_insert']('insert',
616 635
 			'{db_prefix}member_logins',
617 636
 			array(
618 637
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -624,13 +643,15 @@  discard block
 block discarded – undo
624 643
 				'id_member', 'time'
625 644
 			)
626 645
 		);
646
+	}
627 647
 
628 648
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
629
-	if (empty($maintenance) || allowedTo('admin_forum'))
630
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
631
-	else
632
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
633
-}
649
+	if (empty($maintenance) || allowedTo('admin_forum')) {
650
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
651
+	} else {
652
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
653
+	}
654
+	}
634 655
 
635 656
 /**
636 657
  * Logs the current user out of their account.
@@ -646,13 +667,15 @@  discard block
 block discarded – undo
646 667
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
647 668
 
648 669
 	// Make sure they aren't being auto-logged out.
649
-	if (!$internal)
650
-		checkSession('get');
670
+	if (!$internal) {
671
+			checkSession('get');
672
+	}
651 673
 
652 674
 	require_once($sourcedir . '/Subs-Auth.php');
653 675
 
654
-	if (isset($_SESSION['pack_ftp']))
655
-		$_SESSION['pack_ftp'] = null;
676
+	if (isset($_SESSION['pack_ftp'])) {
677
+			$_SESSION['pack_ftp'] = null;
678
+	}
656 679
 
657 680
 	// It won't be first login anymore.
658 681
 	unset($_SESSION['first_login']);
@@ -680,8 +703,9 @@  discard block
 block discarded – undo
680 703
 
681 704
 	// And some other housekeeping while we're at it.
682 705
 	$salt = substr(md5(mt_rand()), 0, 4);
683
-	if (!empty($user_info['id']))
684
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
706
+	if (!empty($user_info['id'])) {
707
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
708
+	}
685 709
 
686 710
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
687 711
 	{
@@ -694,14 +718,13 @@  discard block
 block discarded – undo
694 718
 	// Off to the merry board index we go!
695 719
 	if ($redirect)
696 720
 	{
697
-		if (empty($_SESSION['logout_url']))
698
-			redirectexit('', $context['server']['needs_login_fix']);
699
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
721
+		if (empty($_SESSION['logout_url'])) {
722
+					redirectexit('', $context['server']['needs_login_fix']);
723
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
700 724
 		{
701 725
 			unset ($_SESSION['logout_url']);
702 726
 			redirectexit();
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			$temp = $_SESSION['logout_url'];
707 730
 			unset($_SESSION['logout_url']);
@@ -734,8 +757,9 @@  discard block
 block discarded – undo
734 757
 function phpBB3_password_check($passwd, $passwd_hash)
735 758
 {
736 759
 	// Too long or too short?
737
-	if (strlen($passwd_hash) != 34)
738
-		return;
760
+	if (strlen($passwd_hash) != 34) {
761
+			return;
762
+	}
739 763
 
740 764
 	// Range of characters allowed.
741 765
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -746,8 +770,9 @@  discard block
 block discarded – undo
746 770
 	$salt = substr($passwd_hash, 4, 8);
747 771
 
748 772
 	$hash = md5($salt . $passwd, true);
749
-	for (; $count != 0; --$count)
750
-		$hash = md5($hash . $passwd, true);
773
+	for (; $count != 0; --$count) {
774
+			$hash = md5($hash . $passwd, true);
775
+	}
751 776
 
752 777
 	$output = substr($passwd_hash, 0, 12);
753 778
 	$i = 0;
@@ -756,21 +781,25 @@  discard block
 block discarded – undo
756 781
 		$value = ord($hash[$i++]);
757 782
 		$output .= $range[$value & 0x3f];
758 783
 
759
-		if ($i < 16)
760
-			$value |= ord($hash[$i]) << 8;
784
+		if ($i < 16) {
785
+					$value |= ord($hash[$i]) << 8;
786
+		}
761 787
 
762 788
 		$output .= $range[($value >> 6) & 0x3f];
763 789
 
764
-		if ($i++ >= 16)
765
-			break;
790
+		if ($i++ >= 16) {
791
+					break;
792
+		}
766 793
 
767
-		if ($i < 16)
768
-			$value |= ord($hash[$i]) << 16;
794
+		if ($i < 16) {
795
+					$value |= ord($hash[$i]) << 16;
796
+		}
769 797
 
770 798
 		$output .= $range[($value >> 12) & 0x3f];
771 799
 
772
-		if ($i++ >= 16)
773
-			break;
800
+		if ($i++ >= 16) {
801
+					break;
802
+		}
774 803
 
775 804
 		$output .= $range[($value >> 18) & 0x3f];
776 805
 	}
@@ -802,8 +831,9 @@  discard block
 block discarded – undo
802 831
 		require_once($sourcedir . '/Subs-Auth.php');
803 832
 		setLoginCookie(-3600, 0);
804 833
 
805
-		if (isset($_SESSION['login_' . $cookiename]))
806
-			unset($_SESSION['login_' . $cookiename]);
834
+		if (isset($_SESSION['login_' . $cookiename])) {
835
+					unset($_SESSION['login_' . $cookiename]);
836
+		}
807 837
 	}
808 838
 
809 839
 	// We need a member!
@@ -817,8 +847,9 @@  discard block
 block discarded – undo
817 847
 	}
818 848
 
819 849
 	// Right, have we got a flood value?
820
-	if ($password_flood_value !== false)
821
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
850
+	if ($password_flood_value !== false) {
851
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
852
+	}
822 853
 
823 854
 	// Timestamp or number of tries invalid?
824 855
 	if (empty($number_tries) || empty($time_stamp))
@@ -834,15 +865,17 @@  discard block
 block discarded – undo
834 865
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
835 866
 
836 867
 		// They are trying too fast, make them wait longer
837
-		if ($time_stamp < time() - 10)
838
-			$time_stamp = time();
868
+		if ($time_stamp < time() - 10) {
869
+					$time_stamp = time();
870
+		}
839 871
 	}
840 872
 
841 873
 	$number_tries++;
842 874
 
843 875
 	// Broken the law?
844
-	if ($number_tries > 5)
845
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
876
+	if ($number_tries > 5) {
877
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
878
+	}
846 879
 
847 880
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
848 881
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +472 added lines, -350 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 
66
-			if ($charcode == 'UTF8')
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting for fatal errors.
154 160
 	error_reporting(E_ERROR | E_PARSE);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -230,10 +239,11 @@  discard block
 block discarded – undo
230 239
 		// Now just redirect to a blank.png...
231 240
 		$secure = false;
232 241
 
233
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
234
-			$secure = true;
235
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
236
-			$secure = true;
242
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
243
+					$secure = true;
244
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
245
+					$secure = true;
246
+		}
237 247
 
238 248
 		header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
239 249
 		exit;
@@ -244,10 +254,11 @@  discard block
 block discarded – undo
244 254
 	{
245 255
 		// Get PHP's default timezone, if set
246 256
 		$ini_tz = ini_get('date.timezone');
247
-		if (!empty($ini_tz))
248
-			$timezone_id = $ini_tz;
249
-		else
250
-			$timezone_id = '';
257
+		if (!empty($ini_tz)) {
258
+					$timezone_id = $ini_tz;
259
+		} else {
260
+					$timezone_id = '';
261
+		}
251 262
 
252 263
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
253 264
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -277,8 +288,9 @@  discard block
 block discarded – undo
277 288
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
278 289
 		while ($entry = $dir->read())
279 290
 		{
280
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
281
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
291
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
292
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
293
+			}
282 294
 		}
283 295
 		$dir->close();
284 296
 	}
@@ -325,10 +337,11 @@  discard block
 block discarded – undo
325 337
 	}
326 338
 
327 339
 	// Override the language file?
328
-	if (isset($_GET['lang_file']))
329
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
331
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
340
+	if (isset($_GET['lang_file'])) {
341
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
342
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
343
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
344
+	}
332 345
 
333 346
 	// Make sure it exists, if it doesn't reset it.
334 347
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -337,8 +350,9 @@  discard block
 block discarded – undo
337 350
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
338 351
 
339 352
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
340
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
341
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
353
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
354
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
355
+		}
342 356
 	}
343 357
 
344 358
 	// And now include the actual language file itself.
@@ -355,15 +369,18 @@  discard block
 block discarded – undo
355 369
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings, $db_port;
356 370
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist, $db_mb4;
357 371
 
358
-	if (empty($sourcedir))
359
-		$sourcedir = dirname(__FILE__) . '/Sources';
372
+	if (empty($sourcedir)) {
373
+			$sourcedir = dirname(__FILE__) . '/Sources';
374
+	}
360 375
 
361 376
 	// Need this to check whether we need the database password.
362 377
 	require(dirname(__FILE__) . '/Settings.php');
363
-	if (!defined('SMF'))
364
-		define('SMF', 1);
365
-	if (empty($smcFunc))
366
-		$smcFunc = array();
378
+	if (!defined('SMF')) {
379
+			define('SMF', 1);
380
+	}
381
+	if (empty($smcFunc)) {
382
+			$smcFunc = array();
383
+	}
367 384
 
368 385
 	$modSettings['disableQueryCheck'] = true;
369 386
 
@@ -374,14 +391,17 @@  discard block
 block discarded – undo
374 391
 
375 392
 		$options = array('persist' => $db_persist);
376 393
 
377
-		if (!empty($db_port))
378
-			$options['port'] = $db_port;
394
+		if (!empty($db_port)) {
395
+					$options['port'] = $db_port;
396
+		}
379 397
 
380
-		if (!empty($db_mb4))
381
-			$options['db_mb4'] = $db_mb4;
398
+		if (!empty($db_mb4)) {
399
+					$options['db_mb4'] = $db_mb4;
400
+		}
382 401
 
383
-		if (!$db_connection)
384
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
402
+		if (!$db_connection) {
403
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
404
+		}
385 405
 	}
386 406
 }
387 407
 
@@ -409,8 +429,9 @@  discard block
 block discarded – undo
409 429
 		// @todo REMOVE THIS!!
410 430
 		else
411 431
 		{
412
-			if (function_exists('doStep' . $_GET['step']))
413
-				call_user_func('doStep' . $_GET['step']);
432
+			if (function_exists('doStep' . $_GET['step'])) {
433
+							call_user_func('doStep' . $_GET['step']);
434
+			}
414 435
 		}
415 436
 		// Show the footer.
416 437
 		template_install_below();
@@ -428,8 +449,9 @@  discard block
 block discarded – undo
428 449
 	$incontext['sub_template'] = 'welcome_message';
429 450
 
430 451
 	// Done the submission?
431
-	if (isset($_POST['contbutt']))
432
-		return true;
452
+	if (isset($_POST['contbutt'])) {
453
+			return true;
454
+	}
433 455
 
434 456
 	// See if we think they have already installed it?
435 457
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -437,14 +459,17 @@  discard block
 block discarded – undo
437 459
 		$probably_installed = 0;
438 460
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
439 461
 		{
440
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
441
-				$probably_installed++;
442
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
443
-				$probably_installed++;
462
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
463
+							$probably_installed++;
464
+			}
465
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
466
+							$probably_installed++;
467
+			}
444 468
 		}
445 469
 
446
-		if ($probably_installed == 2)
447
-			$incontext['warning'] = $txt['error_already_installed'];
470
+		if ($probably_installed == 2) {
471
+					$incontext['warning'] = $txt['error_already_installed'];
472
+		}
448 473
 	}
449 474
 
450 475
 	// Is some database support even compiled in?
@@ -459,45 +484,54 @@  discard block
 block discarded – undo
459 484
 				$databases[$key]['supported'] = false;
460 485
 				$notFoundSQLFile = true;
461 486
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
487
+			} else {
488
+							$incontext['supported_databases'][] = $db;
462 489
 			}
463
-			else
464
-				$incontext['supported_databases'][] = $db;
465 490
 		}
466 491
 	}
467 492
 
468 493
 	// Check the PHP version.
469
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
470
-		$error = 'error_php_too_low';
494
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
495
+			$error = 'error_php_too_low';
496
+	}
471 497
 	// Make sure we have a supported database
472
-	elseif (empty($incontext['supported_databases']))
473
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
498
+	elseif (empty($incontext['supported_databases'])) {
499
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
500
+	}
474 501
 	// How about session support?  Some crazy sysadmin remove it?
475
-	elseif (!function_exists('session_start'))
476
-		$error = 'error_session_missing';
502
+	elseif (!function_exists('session_start')) {
503
+			$error = 'error_session_missing';
504
+	}
477 505
 	// Make sure they uploaded all the files.
478
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
479
-		$error = 'error_missing_files';
506
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
507
+			$error = 'error_missing_files';
508
+	}
480 509
 	// Very simple check on the session.save_path for Windows.
481 510
 	// @todo Move this down later if they don't use database-driven sessions?
482
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
483
-		$error = 'error_session_save_path';
511
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
512
+			$error = 'error_session_save_path';
513
+	}
484 514
 
485 515
 	// Since each of the three messages would look the same, anyway...
486
-	if (isset($error))
487
-		$incontext['error'] = $txt[$error];
516
+	if (isset($error)) {
517
+			$incontext['error'] = $txt[$error];
518
+	}
488 519
 
489 520
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
490
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
491
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
521
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
522
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
523
+	}
492 524
 
493 525
 	// Confirm mbstring is loaded...
494
-	if (!extension_loaded('mbstring'))
495
-		$incontext['error'] = $txt['install_no_mbstring'];
526
+	if (!extension_loaded('mbstring')) {
527
+			$incontext['error'] = $txt['install_no_mbstring'];
528
+	}
496 529
 
497 530
 	// Check for https stream support.
498 531
 	$supported_streams = stream_get_wrappers();
499
-	if (!in_array('https', $supported_streams))
500
-		$incontext['warning'] = $txt['install_no_https'];
532
+	if (!in_array('https', $supported_streams)) {
533
+			$incontext['warning'] = $txt['install_no_https'];
534
+	}
501 535
 
502 536
 	return false;
503 537
 }
@@ -522,12 +556,14 @@  discard block
 block discarded – undo
522 556
 		'Settings_bak.php',
523 557
 	);
524 558
 
525
-	foreach ($incontext['detected_languages'] as $lang => $temp)
526
-		$extra_files[] = 'Themes/default/languages/' . $lang;
559
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
560
+			$extra_files[] = 'Themes/default/languages/' . $lang;
561
+	}
527 562
 
528 563
 	// With mod_security installed, we could attempt to fix it with .htaccess.
529
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
530
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
564
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
565
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
566
+	}
531 567
 
532 568
 	$failed_files = array();
533 569
 
@@ -539,20 +575,23 @@  discard block
 block discarded – undo
539 575
 		foreach ($writable_files as $file)
540 576
 		{
541 577
 			// Some files won't exist, try to address up front
542
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
543
-				@touch(dirname(__FILE__) . '/' . $file);
578
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
579
+							@touch(dirname(__FILE__) . '/' . $file);
580
+			}
544 581
 			// NOW do the writable check...
545 582
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
546 583
 			{
547 584
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
548 585
 
549 586
 				// Well, 755 hopefully worked... if not, try 777.
550
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
551
-					$failed_files[] = $file;
587
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
588
+									$failed_files[] = $file;
589
+				}
552 590
 			}
553 591
 		}
554
-		foreach ($extra_files as $file)
555
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
592
+		foreach ($extra_files as $file) {
593
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
594
+		}
556 595
 	}
557 596
 	// Windows is trickier.  Let's try opening for r+...
558 597
 	else
@@ -562,30 +601,35 @@  discard block
 block discarded – undo
562 601
 		foreach ($writable_files as $file)
563 602
 		{
564 603
 			// Folders can't be opened for write... but the index.php in them can ;)
565
-			if (is_dir(dirname(__FILE__) . '/' . $file))
566
-				$file .= '/index.php';
604
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
605
+							$file .= '/index.php';
606
+			}
567 607
 
568 608
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
569 609
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
570 610
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
571 611
 
572 612
 			// Hmm, okay, try just for write in that case...
573
-			if (!is_resource($fp))
574
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
613
+			if (!is_resource($fp)) {
614
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
615
+			}
575 616
 
576
-			if (!is_resource($fp))
577
-				$failed_files[] = $file;
617
+			if (!is_resource($fp)) {
618
+							$failed_files[] = $file;
619
+			}
578 620
 
579 621
 			@fclose($fp);
580 622
 		}
581
-		foreach ($extra_files as $file)
582
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
623
+		foreach ($extra_files as $file) {
624
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
625
+		}
583 626
 	}
584 627
 
585 628
 	$failure = count($failed_files) >= 1;
586 629
 
587
-	if (!isset($_SERVER))
588
-		return !$failure;
630
+	if (!isset($_SERVER)) {
631
+			return !$failure;
632
+	}
589 633
 
590 634
 	// Put the list into context.
591 635
 	$incontext['failed_files'] = $failed_files;
@@ -633,19 +677,23 @@  discard block
 block discarded – undo
633 677
 
634 678
 		if (!isset($ftp) || $ftp->error !== false)
635 679
 		{
636
-			if (!isset($ftp))
637
-				$ftp = new ftp_connection(null);
680
+			if (!isset($ftp)) {
681
+							$ftp = new ftp_connection(null);
682
+			}
638 683
 			// Save the error so we can mess with listing...
639
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
640
-				$incontext['ftp_errors'][] = $ftp->last_message;
684
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
685
+							$incontext['ftp_errors'][] = $ftp->last_message;
686
+			}
641 687
 
642 688
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
643 689
 
644
-			if (empty($_POST['ftp_path']) && $found_path)
645
-				$_POST['ftp_path'] = $detect_path;
690
+			if (empty($_POST['ftp_path']) && $found_path) {
691
+							$_POST['ftp_path'] = $detect_path;
692
+			}
646 693
 
647
-			if (!isset($_POST['ftp_username']))
648
-				$_POST['ftp_username'] = $username;
694
+			if (!isset($_POST['ftp_username'])) {
695
+							$_POST['ftp_username'] = $username;
696
+			}
649 697
 
650 698
 			// Set the username etc, into context.
651 699
 			$incontext['ftp'] = array(
@@ -657,8 +705,7 @@  discard block
 block discarded – undo
657 705
 			);
658 706
 
659 707
 			return false;
660
-		}
661
-		else
708
+		} else
662 709
 		{
663 710
 			$_SESSION['installer_temp_ftp'] = array(
664 711
 				'server' => $_POST['ftp_server'],
@@ -672,10 +719,12 @@  discard block
 block discarded – undo
672 719
 
673 720
 			foreach ($failed_files as $file)
674 721
 			{
675
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
676
-					$ftp->chmod($file, 0755);
677
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
678
-					$ftp->chmod($file, 0777);
722
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
723
+									$ftp->chmod($file, 0755);
724
+				}
725
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
726
+									$ftp->chmod($file, 0777);
727
+				}
679 728
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
680 729
 				{
681 730
 					$failed_files_updated[] = $file;
@@ -731,15 +780,17 @@  discard block
 block discarded – undo
731 780
 
732 781
 			if (!$foundOne)
733 782
 			{
734
-				if (isset($db['default_host']))
735
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
783
+				if (isset($db['default_host'])) {
784
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
785
+				}
736 786
 				if (isset($db['default_user']))
737 787
 				{
738 788
 					$incontext['db']['user'] = ini_get($db['default_user']);
739 789
 					$incontext['db']['name'] = ini_get($db['default_user']);
740 790
 				}
741
-				if (isset($db['default_password']))
742
-					$incontext['db']['pass'] = ini_get($db['default_password']);
791
+				if (isset($db['default_password'])) {
792
+									$incontext['db']['pass'] = ini_get($db['default_password']);
793
+				}
743 794
 
744 795
 				// For simplicity and less confusion, leave the port blank by default
745 796
 				$incontext['db']['port'] = '';
@@ -758,10 +809,10 @@  discard block
 block discarded – undo
758 809
 		$incontext['db']['server'] = $_POST['db_server'];
759 810
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
760 811
 
761
-		if (!empty($_POST['db_port']))
762
-			$incontext['db']['port'] = $_POST['db_port'];
763
-	}
764
-	else
812
+		if (!empty($_POST['db_port'])) {
813
+					$incontext['db']['port'] = $_POST['db_port'];
814
+		}
815
+	} else
765 816
 	{
766 817
 		$incontext['db']['prefix'] = 'smf_';
767 818
 	}
@@ -797,10 +848,11 @@  discard block
 block discarded – undo
797 848
 		if (!empty($_POST['db_port']))
798 849
 		{
799 850
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
800
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
801
-				$vars['db_port'] = (int) $_POST['db_port'];
802
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
803
-				$vars['db_port'] = (int) $_POST['db_port'];
851
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
852
+							$vars['db_port'] = (int) $_POST['db_port'];
853
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
854
+							$vars['db_port'] = (int) $_POST['db_port'];
855
+			}
804 856
 		}
805 857
 
806 858
 		// God I hope it saved!
@@ -813,8 +865,9 @@  discard block
 block discarded – undo
813 865
 		// Make sure it works.
814 866
 		require(dirname(__FILE__) . '/Settings.php');
815 867
 
816
-		if (empty($sourcedir))
817
-			$sourcedir = dirname(__FILE__) . '/Sources';
868
+		if (empty($sourcedir)) {
869
+					$sourcedir = dirname(__FILE__) . '/Sources';
870
+		}
818 871
 
819 872
 		// Better find the database file!
820 873
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -824,12 +877,14 @@  discard block
 block discarded – undo
824 877
 		}
825 878
 
826 879
 		// Now include it for database functions!
827
-		if (!defined('SMF'))
828
-			define('SMF', 1);
880
+		if (!defined('SMF')) {
881
+					define('SMF', 1);
882
+		}
829 883
 
830 884
 		$modSettings['disableQueryCheck'] = true;
831
-		if (empty($smcFunc))
832
-			$smcFunc = array();
885
+		if (empty($smcFunc)) {
886
+					$smcFunc = array();
887
+		}
833 888
 
834 889
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
835 890
 
@@ -838,11 +893,13 @@  discard block
 block discarded – undo
838 893
 
839 894
 		$options = array('non_fatal' => true, 'dont_select_db' => !$needsDB);
840 895
 		// Add in the port if needed
841
-		if (!empty($db_port))
842
-			$options['port'] = $db_port;
896
+		if (!empty($db_port)) {
897
+					$options['port'] = $db_port;
898
+		}
843 899
 		
844
-		if (!empty($db_mb4))
845
-			$options['db_mb4'] = $db_mb4;
900
+		if (!empty($db_mb4)) {
901
+					$options['db_mb4'] = $db_mb4;
902
+		}
846 903
 
847 904
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
848 905
 
@@ -928,12 +985,14 @@  discard block
 block discarded – undo
928 985
 	$incontext['page_title'] = $txt['install_settings'];
929 986
 
930 987
 	// Let's see if we got the database type correct.
931
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
932
-		$db_type = $_POST['db_type'];
988
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
989
+			$db_type = $_POST['db_type'];
990
+	}
933 991
 
934 992
 	// Else we'd better be able to get the connection.
935
-	else
936
-		load_database();
993
+	else {
994
+			load_database();
995
+	}
937 996
 
938 997
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
939 998
 
@@ -942,10 +1001,11 @@  discard block
 block discarded – undo
942 1001
 
943 1002
 		$secure = false;
944 1003
 
945
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
946
-			$secure = true;
947
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
948
-			$secure = true;
1004
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1005
+					$secure = true;
1006
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
1007
+					$secure = true;
1008
+		}
949 1009
 
950 1010
 	// Now, to put what we've learned together... and add a path.
951 1011
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -977,18 +1037,21 @@  discard block
 block discarded – undo
977 1037
 	// Submitting?
978 1038
 	if (isset($_POST['boardurl']))
979 1039
 	{
980
-		if (substr($_POST['boardurl'], -10) == '/index.php')
981
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
982
-		elseif (substr($_POST['boardurl'], -1) == '/')
983
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
984
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
985
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1040
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1041
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1042
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1043
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1044
+		}
1045
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1046
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1047
+		}
986 1048
 
987 1049
 		//Make sure boardurl is aligned with ssl setting
988
-		if (empty($_POST['force_ssl']))
989
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
990
-		else
991
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1050
+		if (empty($_POST['force_ssl'])) {
1051
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1052
+		} else {
1053
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1054
+		}
992 1055
 
993 1056
 		// Save these variables.
994 1057
 		$vars = array(
@@ -1027,10 +1090,10 @@  discard block
 block discarded – undo
1027 1090
 			{
1028 1091
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1029 1092
 				return false;
1030
-			}
1031
-			else
1032
-				// Set the character set here.
1093
+			} else {
1094
+							// Set the character set here.
1033 1095
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1096
+			}
1034 1097
 		}
1035 1098
 
1036 1099
 		// Good, skip on.
@@ -1050,8 +1113,9 @@  discard block
 block discarded – undo
1050 1113
 	$incontext['continue'] = 1;
1051 1114
 
1052 1115
 	// Already done?
1053
-	if (isset($_POST['pop_done']))
1054
-		return true;
1116
+	if (isset($_POST['pop_done'])) {
1117
+			return true;
1118
+	}
1055 1119
 
1056 1120
 	// Reload settings.
1057 1121
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1069,8 +1133,9 @@  discard block
 block discarded – undo
1069 1133
 	$modSettings = array();
1070 1134
 	if ($result !== false)
1071 1135
 	{
1072
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1073
-			$modSettings[$row['variable']] = $row['value'];
1136
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1137
+					$modSettings[$row['variable']] = $row['value'];
1138
+		}
1074 1139
 		$smcFunc['db_free_result']($result);
1075 1140
 
1076 1141
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1083,20 +1148,22 @@  discard block
 block discarded – undo
1083 1148
 	$modSettings['disableQueryCheck'] = true;
1084 1149
 
1085 1150
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1086
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1087
-		$smcFunc['db_query']('', '
1151
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1152
+			$smcFunc['db_query']('', '
1088 1153
 			SET NAMES {string:utf8}',
1089 1154
 			array(
1090 1155
 				'db_error_skip' => true,
1091 1156
 				'utf8' => 'utf8',
1092 1157
 			)
1093 1158
 		);
1159
+	}
1094 1160
 
1095 1161
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1096
-	if (substr(__DIR__, -1) == '\\')
1097
-		$attachdir = __DIR__ . 'attachments';
1098
-	else
1099
-		$attachdir = __DIR__ . '/attachments';
1162
+	if (substr(__DIR__, -1) == '\\') {
1163
+			$attachdir = __DIR__ . 'attachments';
1164
+	} else {
1165
+			$attachdir = __DIR__ . '/attachments';
1166
+	}
1100 1167
 
1101 1168
 	$replaces = array(
1102 1169
 		'{$db_prefix}' => $db_prefix,
@@ -1113,8 +1180,9 @@  discard block
 block discarded – undo
1113 1180
 
1114 1181
 	foreach ($txt as $key => $value)
1115 1182
 	{
1116
-		if (substr($key, 0, 8) == 'default_')
1117
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1183
+		if (substr($key, 0, 8) == 'default_') {
1184
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1185
+		}
1118 1186
 	}
1119 1187
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1120 1188
 
@@ -1129,8 +1197,9 @@  discard block
 block discarded – undo
1129 1197
 
1130 1198
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1131 1199
 		{
1132
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1133
-				$engines[] = $row['Engine'];
1200
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1201
+							$engines[] = $row['Engine'];
1202
+			}
1134 1203
 		}
1135 1204
 
1136 1205
 		// Done with this now
@@ -1154,8 +1223,7 @@  discard block
 block discarded – undo
1154 1223
 			$replaces['START TRANSACTION;'] = '';
1155 1224
 			$replaces['COMMIT;'] = '';
1156 1225
 		}
1157
-	}
1158
-	else
1226
+	} else
1159 1227
 	{
1160 1228
 		$has_innodb = false;
1161 1229
 	}
@@ -1177,21 +1245,24 @@  discard block
 block discarded – undo
1177 1245
 	foreach ($sql_lines as $count => $line)
1178 1246
 	{
1179 1247
 		// No comments allowed!
1180
-		if (substr(trim($line), 0, 1) != '#')
1181
-			$current_statement .= "\n" . rtrim($line);
1248
+		if (substr(trim($line), 0, 1) != '#') {
1249
+					$current_statement .= "\n" . rtrim($line);
1250
+		}
1182 1251
 
1183 1252
 		// Is this the end of the query string?
1184
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1185
-			continue;
1253
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1254
+					continue;
1255
+		}
1186 1256
 
1187 1257
 		// Does this table already exist?  If so, don't insert more data into it!
1188 1258
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1189 1259
 		{
1190 1260
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1191
-			if (!empty($matches[0]))
1192
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1193
-			else
1194
-				$incontext['sql_results']['insert_dups']++;
1261
+			if (!empty($matches[0])) {
1262
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1263
+			} else {
1264
+							$incontext['sql_results']['insert_dups']++;
1265
+			}
1195 1266
 
1196 1267
 			$current_statement = '';
1197 1268
 			continue;
@@ -1200,8 +1271,9 @@  discard block
 block discarded – undo
1200 1271
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1201 1272
 		{
1202 1273
 			// Use the appropriate function based on the DB type
1203
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1204
-				$db_errorno = $db_type . '_errno';
1274
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1275
+							$db_errorno = $db_type . '_errno';
1276
+			}
1205 1277
 
1206 1278
 			// Error 1050: Table already exists!
1207 1279
 			// @todo Needs to be made better!
@@ -1216,18 +1288,18 @@  discard block
 block discarded – undo
1216 1288
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1217 1289
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1218 1290
 			}
1219
-		}
1220
-		else
1291
+		} else
1221 1292
 		{
1222
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1223
-				$incontext['sql_results']['tables']++;
1224
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1293
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1294
+							$incontext['sql_results']['tables']++;
1295
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1225 1296
 			{
1226 1297
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1227
-				if (!empty($matches[0]))
1228
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1229
-				else
1230
-					$incontext['sql_results']['inserts']++;
1298
+				if (!empty($matches[0])) {
1299
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1300
+				} else {
1301
+									$incontext['sql_results']['inserts']++;
1302
+				}
1231 1303
 			}
1232 1304
 		}
1233 1305
 
@@ -1240,15 +1312,17 @@  discard block
 block discarded – undo
1240 1312
 	// Sort out the context for the SQL.
1241 1313
 	foreach ($incontext['sql_results'] as $key => $number)
1242 1314
 	{
1243
-		if ($number == 0)
1244
-			unset($incontext['sql_results'][$key]);
1245
-		else
1246
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1315
+		if ($number == 0) {
1316
+					unset($incontext['sql_results'][$key]);
1317
+		} else {
1318
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1319
+		}
1247 1320
 	}
1248 1321
 
1249 1322
 	// Make sure UTF will be used globally.
1250
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1251
-		$newSettings[] = array('global_character_set', 'UTF-8');
1323
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1324
+			$newSettings[] = array('global_character_set', 'UTF-8');
1325
+	}
1252 1326
 
1253 1327
 	// Auto-detect local & global cookie settings
1254 1328
 	$url_parts = parse_url($boardurl);
@@ -1277,15 +1351,19 @@  discard block
 block discarded – undo
1277 1351
 
1278 1352
 		// Look for subfolder, if found, set localCookie
1279 1353
 		// Checking for len > 1 ensures you don't have just a slash...
1280
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1281
-			$localCookies = '1';
1354
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1355
+					$localCookies = '1';
1356
+		}
1282 1357
 
1283
-		if (isset($globalCookies))
1284
-			$newSettings[] = array('globalCookies', $globalCookies);
1285
-		if (isset($globalCookiesDomain))
1286
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1287
-		if (isset($localCookies))
1288
-			$newSettings[] = array('localCookies', $localCookies);
1358
+		if (isset($globalCookies)) {
1359
+					$newSettings[] = array('globalCookies', $globalCookies);
1360
+		}
1361
+		if (isset($globalCookiesDomain)) {
1362
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1363
+		}
1364
+		if (isset($localCookies)) {
1365
+					$newSettings[] = array('localCookies', $localCookies);
1366
+		}
1289 1367
 	}
1290 1368
 
1291 1369
 	// Are we allowing stat collection?
@@ -1303,16 +1381,17 @@  discard block
 block discarded – undo
1303 1381
 			fwrite($fp, $out);
1304 1382
 
1305 1383
 			$return_data = '';
1306
-			while (!feof($fp))
1307
-				$return_data .= fgets($fp, 128);
1384
+			while (!feof($fp)) {
1385
+							$return_data .= fgets($fp, 128);
1386
+			}
1308 1387
 
1309 1388
 			fclose($fp);
1310 1389
 
1311 1390
 			// Get the unique site ID.
1312 1391
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1313 1392
 
1314
-			if (!empty($ID[1]))
1315
-				$smcFunc['db_insert']('replace',
1393
+			if (!empty($ID[1])) {
1394
+							$smcFunc['db_insert']('replace',
1316 1395
 					$db_prefix . 'settings',
1317 1396
 					array('variable' => 'string', 'value' => 'string'),
1318 1397
 					array(
@@ -1321,11 +1400,12 @@  discard block
 block discarded – undo
1321 1400
 					),
1322 1401
 					array('variable')
1323 1402
 				);
1403
+			}
1324 1404
 		}
1325 1405
 	}
1326 1406
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1327
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1328
-		$smcFunc['db_query']('', '
1407
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1408
+			$smcFunc['db_query']('', '
1329 1409
 			DELETE FROM {db_prefix}settings
1330 1410
 			WHERE variable = {string:enable_sm_stats}',
1331 1411
 			array(
@@ -1333,20 +1413,23 @@  discard block
 block discarded – undo
1333 1413
 				'db_error_skip' => true,
1334 1414
 			)
1335 1415
 		);
1416
+	}
1336 1417
 
1337 1418
 	// Are we enabling SSL?
1338
-	if (!empty($_POST['force_ssl']))
1339
-		$newSettings[] = array('force_ssl', 1);
1419
+	if (!empty($_POST['force_ssl'])) {
1420
+			$newSettings[] = array('force_ssl', 1);
1421
+	}
1340 1422
 
1341 1423
 	// Setting a timezone is required.
1342 1424
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1343 1425
 	{
1344 1426
 		// Get PHP's default timezone, if set
1345 1427
 		$ini_tz = ini_get('date.timezone');
1346
-		if (!empty($ini_tz))
1347
-			$timezone_id = $ini_tz;
1348
-		else
1349
-			$timezone_id = '';
1428
+		if (!empty($ini_tz)) {
1429
+					$timezone_id = $ini_tz;
1430
+		} else {
1431
+					$timezone_id = '';
1432
+		}
1350 1433
 
1351 1434
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1352 1435
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1355,8 +1438,9 @@  discard block
 block discarded – undo
1355 1438
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1356 1439
 		}
1357 1440
 
1358
-		if (date_default_timezone_set($timezone_id))
1359
-			$newSettings[] = array('default_timezone', $timezone_id);
1441
+		if (date_default_timezone_set($timezone_id)) {
1442
+					$newSettings[] = array('default_timezone', $timezone_id);
1443
+		}
1360 1444
 	}
1361 1445
 
1362 1446
 	if (!empty($newSettings))
@@ -1387,16 +1471,18 @@  discard block
 block discarded – undo
1387 1471
 	}
1388 1472
 
1389 1473
 	// MySQL specific stuff
1390
-	if (substr($db_type, 0, 5) != 'mysql')
1391
-		return false;
1474
+	if (substr($db_type, 0, 5) != 'mysql') {
1475
+			return false;
1476
+	}
1392 1477
 
1393 1478
 	// Find database user privileges.
1394 1479
 	$privs = array();
1395 1480
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1396 1481
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1397 1482
 	{
1398
-		if ($row['Privilege'] == 'Alter')
1399
-			$privs[] = $row['Privilege'];
1483
+		if ($row['Privilege'] == 'Alter') {
1484
+					$privs[] = $row['Privilege'];
1485
+		}
1400 1486
 	}
1401 1487
 	$smcFunc['db_free_result']($get_privs);
1402 1488
 
@@ -1426,8 +1512,9 @@  discard block
 block discarded – undo
1426 1512
 	$incontext['continue'] = 1;
1427 1513
 
1428 1514
 	// Skipping?
1429
-	if (!empty($_POST['skip']))
1430
-		return true;
1515
+	if (!empty($_POST['skip'])) {
1516
+			return true;
1517
+	}
1431 1518
 
1432 1519
 	// Need this to check whether we need the database password.
1433 1520
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1444,18 +1531,22 @@  discard block
 block discarded – undo
1444 1531
 	// We need this to properly hash the password for Admin
1445 1532
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1446 1533
 			global $sourcedir;
1447
-			if (function_exists('mb_strtolower'))
1448
-				return mb_strtolower($string, 'UTF-8');
1534
+			if (function_exists('mb_strtolower')) {
1535
+							return mb_strtolower($string, 'UTF-8');
1536
+			}
1449 1537
 			require_once($sourcedir . '/Subs-Charset.php');
1450 1538
 			return utf8_strtolower($string);
1451 1539
 		};
1452 1540
 
1453
-	if (!isset($_POST['username']))
1454
-		$_POST['username'] = '';
1455
-	if (!isset($_POST['email']))
1456
-		$_POST['email'] = '';
1457
-	if (!isset($_POST['server_email']))
1458
-		$_POST['server_email'] = '';
1541
+	if (!isset($_POST['username'])) {
1542
+			$_POST['username'] = '';
1543
+	}
1544
+	if (!isset($_POST['email'])) {
1545
+			$_POST['email'] = '';
1546
+	}
1547
+	if (!isset($_POST['server_email'])) {
1548
+			$_POST['server_email'] = '';
1549
+	}
1459 1550
 
1460 1551
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1461 1552
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1474,8 +1565,9 @@  discard block
 block discarded – undo
1474 1565
 			'admin_group' => 1,
1475 1566
 		)
1476 1567
 	);
1477
-	if ($smcFunc['db_num_rows']($request) != 0)
1478
-		$incontext['skip'] = 1;
1568
+	if ($smcFunc['db_num_rows']($request) != 0) {
1569
+			$incontext['skip'] = 1;
1570
+	}
1479 1571
 	$smcFunc['db_free_result']($request);
1480 1572
 
1481 1573
 	// Trying to create an account?
@@ -1506,8 +1598,9 @@  discard block
 block discarded – undo
1506 1598
 		}
1507 1599
 
1508 1600
 		// Update the webmaster's email?
1509
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1510
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1601
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1602
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1603
+		}
1511 1604
 
1512 1605
 		// Work out whether we're going to have dodgy characters and remove them.
1513 1606
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1530,32 +1623,27 @@  discard block
 block discarded – undo
1530 1623
 			$smcFunc['db_free_result']($result);
1531 1624
 
1532 1625
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1533
-		}
1534
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1626
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1535 1627
 		{
1536 1628
 			// Try the previous step again.
1537 1629
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1538 1630
 			return false;
1539
-		}
1540
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1631
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1541 1632
 		{
1542 1633
 			// Try the previous step again.
1543 1634
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1544 1635
 			return false;
1545
-		}
1546
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1636
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1547 1637
 		{
1548 1638
 			// One step back, this time fill out a proper admin email address.
1549 1639
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1550 1640
 			return false;
1551
-		}
1552
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1641
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1553 1642
 		{
1554 1643
 			// One step back, this time fill out a proper admin email address.
1555 1644
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1556 1645
 			return false;
1557
-		}
1558
-		elseif ($_POST['username'] != '')
1646
+		} elseif ($_POST['username'] != '')
1559 1647
 		{
1560 1648
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1561 1649
 
@@ -1623,17 +1711,19 @@  discard block
 block discarded – undo
1623 1711
 	reloadSettings();
1624 1712
 
1625 1713
 	// Bring a warning over.
1626
-	if (!empty($incontext['account_existed']))
1627
-		$incontext['warning'] = $incontext['account_existed'];
1714
+	if (!empty($incontext['account_existed'])) {
1715
+			$incontext['warning'] = $incontext['account_existed'];
1716
+	}
1628 1717
 
1629
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1630
-		$smcFunc['db_query']('', '
1718
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1719
+			$smcFunc['db_query']('', '
1631 1720
 			SET NAMES {string:db_character_set}',
1632 1721
 			array(
1633 1722
 				'db_character_set' => $db_character_set,
1634 1723
 				'db_error_skip' => true,
1635 1724
 			)
1636 1725
 		);
1726
+	}
1637 1727
 
1638 1728
 	// As track stats is by default enabled let's add some activity.
1639 1729
 	$smcFunc['db_insert']('ignore',
@@ -1654,14 +1744,16 @@  discard block
 block discarded – undo
1654 1744
 	// Only proceed if we can load the data.
1655 1745
 	if ($request)
1656 1746
 	{
1657
-		while ($row = $smcFunc['db_fetch_row']($request))
1658
-			$modSettings[$row[0]] = $row[1];
1747
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1748
+					$modSettings[$row[0]] = $row[1];
1749
+		}
1659 1750
 		$smcFunc['db_free_result']($request);
1660 1751
 	}
1661 1752
 
1662 1753
 	// Automatically log them in ;)
1663
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1664
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1754
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1755
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1756
+	}
1665 1757
 
1666 1758
 	$result = $smcFunc['db_query']('', '
1667 1759
 		SELECT value
@@ -1672,13 +1764,14 @@  discard block
 block discarded – undo
1672 1764
 			'db_error_skip' => true,
1673 1765
 		)
1674 1766
 	);
1675
-	if ($smcFunc['db_num_rows']($result) != 0)
1676
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1767
+	if ($smcFunc['db_num_rows']($result) != 0) {
1768
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1769
+	}
1677 1770
 	$smcFunc['db_free_result']($result);
1678 1771
 
1679
-	if (empty($db_sessions))
1680
-		$_SESSION['admin_time'] = time();
1681
-	else
1772
+	if (empty($db_sessions)) {
1773
+			$_SESSION['admin_time'] = time();
1774
+	} else
1682 1775
 	{
1683 1776
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1684 1777
 
@@ -1702,8 +1795,9 @@  discard block
 block discarded – undo
1702 1795
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1703 1796
 		function($string){
1704 1797
 			global $sourcedir;
1705
-			if (function_exists('mb_strtolower'))
1706
-				return mb_strtolower($string, 'UTF-8');
1798
+			if (function_exists('mb_strtolower')) {
1799
+							return mb_strtolower($string, 'UTF-8');
1800
+			}
1707 1801
 			require_once($sourcedir . '/Subs-Charset.php');
1708 1802
 			return utf8_strtolower($string);
1709 1803
 		};
@@ -1719,8 +1813,9 @@  discard block
 block discarded – undo
1719 1813
 		)
1720 1814
 	);
1721 1815
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1722
-	if ($smcFunc['db_num_rows']($request) > 0)
1723
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1816
+	if ($smcFunc['db_num_rows']($request) > 0) {
1817
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1818
+	}
1724 1819
 	$smcFunc['db_free_result']($request);
1725 1820
 
1726 1821
 	// Now is the perfect time to fetch the SM files.
@@ -1739,8 +1834,9 @@  discard block
 block discarded – undo
1739 1834
 
1740 1835
 	// Check if we need some stupid MySQL fix.
1741 1836
 	$server_version = $smcFunc['db_server_info']();
1742
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1743
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1837
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1838
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1839
+	}
1744 1840
 
1745 1841
 	// Some final context for the template.
1746 1842
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1760,8 +1856,9 @@  discard block
 block discarded – undo
1760 1856
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1761 1857
 
1762 1858
 	// @todo Do we just want to read the file in clean, and split it this way always?
1763
-	if (count($settingsArray) == 1)
1764
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1859
+	if (count($settingsArray) == 1) {
1860
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1861
+	}
1765 1862
 
1766 1863
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1767 1864
 	{
@@ -1769,25 +1866,29 @@  discard block
 block discarded – undo
1769 1866
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1770 1867
 		{
1771 1868
 			// Set the ten lines to nothing.
1772
-			for ($j=0; $j < 10; $j++)
1773
-				$settingsArray[$i++] = '';
1869
+			for ($j=0; $j < 10; $j++) {
1870
+							$settingsArray[$i++] = '';
1871
+			}
1774 1872
 
1775 1873
 			continue;
1776 1874
 		}
1777 1875
 
1778
-		if (trim($settingsArray[$i]) == '?' . '>')
1779
-			$settingsArray[$i] = '';
1876
+		if (trim($settingsArray[$i]) == '?' . '>') {
1877
+					$settingsArray[$i] = '';
1878
+		}
1780 1879
 
1781 1880
 		// Don't trim or bother with it if it's not a variable.
1782
-		if (substr($settingsArray[$i], 0, 1) != '$')
1783
-			continue;
1881
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1882
+					continue;
1883
+		}
1784 1884
 
1785 1885
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1786 1886
 
1787
-		foreach ($vars as $var => $val)
1788
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1887
+		foreach ($vars as $var => $val) {
1888
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1789 1889
 			{
1790 1890
 				$comment = strstr($settingsArray[$i], '#');
1891
+		}
1791 1892
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1792 1893
 				unset($vars[$var]);
1793 1894
 			}
@@ -1797,36 +1898,41 @@  discard block
 block discarded – undo
1797 1898
 	if (!empty($vars))
1798 1899
 	{
1799 1900
 		$settingsArray[$i++] = '';
1800
-		foreach ($vars as $var => $val)
1801
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1901
+		foreach ($vars as $var => $val) {
1902
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1903
+		}
1802 1904
 	}
1803 1905
 
1804 1906
 	// Blank out the file - done to fix a oddity with some servers.
1805 1907
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1806
-	if (!$fp)
1807
-		return false;
1908
+	if (!$fp) {
1909
+			return false;
1910
+	}
1808 1911
 	fclose($fp);
1809 1912
 
1810 1913
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1811 1914
 
1812 1915
 	// Gotta have one of these ;)
1813
-	if (trim($settingsArray[0]) != '<?php')
1814
-		fwrite($fp, "<?php\n");
1916
+	if (trim($settingsArray[0]) != '<?php') {
1917
+			fwrite($fp, "<?php\n");
1918
+	}
1815 1919
 
1816 1920
 	$lines = count($settingsArray);
1817 1921
 	for ($i = 0; $i < $lines - 1; $i++)
1818 1922
 	{
1819 1923
 		// Don't just write a bunch of blank lines.
1820
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1821
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1924
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1925
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1926
+		}
1822 1927
 	}
1823 1928
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1824 1929
 	fclose($fp);
1825 1930
 
1826 1931
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1827 1932
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1828
-	if (function_exists('opcache_invalidate'))
1829
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1933
+	if (function_exists('opcache_invalidate')) {
1934
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1935
+	}
1830 1936
 
1831 1937
 	return true;
1832 1938
 }
@@ -1836,10 +1942,11 @@  discard block
 block discarded – undo
1836 1942
 	global $cachedir;
1837 1943
 
1838 1944
 	// Write out the db_last_error file with the error timestamp
1839
-	if (!empty($cachedir) && is_writable($cachedir))
1840
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1841
-	else
1842
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1945
+	if (!empty($cachedir) && is_writable($cachedir)) {
1946
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1947
+	} else {
1948
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1949
+	}
1843 1950
 
1844 1951
 	return true;
1845 1952
 }
@@ -1856,9 +1963,9 @@  discard block
 block discarded – undo
1856 1963
 	SecFilterScanPOST Off
1857 1964
 </IfModule>';
1858 1965
 
1859
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1860
-		return true;
1861
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1966
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1967
+			return true;
1968
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1862 1969
 	{
1863 1970
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1864 1971
 
@@ -1870,29 +1977,28 @@  discard block
 block discarded – undo
1870 1977
 				fwrite($ht_handle, $htaccess_addition);
1871 1978
 				fclose($ht_handle);
1872 1979
 				return true;
1980
+			} else {
1981
+							return false;
1873 1982
 			}
1874
-			else
1875
-				return false;
1983
+		} else {
1984
+					return true;
1876 1985
 		}
1877
-		else
1878
-			return true;
1879
-	}
1880
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1881
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1882
-	elseif (is_writable(dirname(__FILE__)))
1986
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1987
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1988
+	} elseif (is_writable(dirname(__FILE__)))
1883 1989
 	{
1884 1990
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1885 1991
 		{
1886 1992
 			fwrite($ht_handle, $htaccess_addition);
1887 1993
 			fclose($ht_handle);
1888 1994
 			return true;
1995
+		} else {
1996
+					return false;
1889 1997
 		}
1890
-		else
1998
+	} else {
1891 1999
 			return false;
1892 2000
 	}
1893
-	else
1894
-		return false;
1895
-}
2001
+	}
1896 2002
 
1897 2003
 function template_install_above()
1898 2004
 {
@@ -1931,9 +2037,10 @@  discard block
 block discarded – undo
1931 2037
 							<label for="installer_language">', $txt['installer_language'], ':</label>
1932 2038
 							<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1933 2039
 
1934
-		foreach ($incontext['detected_languages'] as $lang => $name)
1935
-			echo '
2040
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2041
+					echo '
1936 2042
 								<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2043
+		}
1937 2044
 
1938 2045
 		echo '
1939 2046
 							</select>
@@ -1953,9 +2060,10 @@  discard block
 block discarded – undo
1953 2060
 					<h2>', $txt['upgrade_progress'], '</h2>
1954 2061
 					<ul>';
1955 2062
 
1956
-	foreach ($incontext['steps'] as $num => $step)
1957
-		echo '
2063
+	foreach ($incontext['steps'] as $num => $step) {
2064
+			echo '
1958 2065
 						<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2066
+	}
1959 2067
 
1960 2068
 	echo '
1961 2069
 					</ul>
@@ -1981,20 +2089,23 @@  discard block
 block discarded – undo
1981 2089
 		echo '
1982 2090
 							<div class="floatright">';
1983 2091
 
1984
-		if (!empty($incontext['continue']))
1985
-			echo '
2092
+		if (!empty($incontext['continue'])) {
2093
+					echo '
1986 2094
 								<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">';
1987
-		if (!empty($incontext['skip']))
1988
-			echo '
2095
+		}
2096
+		if (!empty($incontext['skip'])) {
2097
+					echo '
1989 2098
 								<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">';
2099
+		}
1990 2100
 		echo '
1991 2101
 							</div>';
1992 2102
 	}
1993 2103
 
1994 2104
 	// Show the closing form tag and other data only if not in the last step
1995
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1996
-		echo '
2105
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2106
+			echo '
1997 2107
 						</form>';
2108
+	}
1998 2109
 
1999 2110
 	echo '
2000 2111
 					</div><!-- .panel -->
@@ -2027,13 +2138,15 @@  discard block
 block discarded – undo
2027 2138
 		</div>';
2028 2139
 
2029 2140
 	// Show the warnings, or not.
2030
-	if (template_warning_divs())
2031
-		echo '
2141
+	if (template_warning_divs()) {
2142
+			echo '
2032 2143
 		<h3>', $txt['install_all_lovely'], '</h3>';
2144
+	}
2033 2145
 
2034 2146
 	// Say we want the continue button!
2035
-	if (empty($incontext['error']))
2036
-		$incontext['continue'] = 1;
2147
+	if (empty($incontext['error'])) {
2148
+			$incontext['continue'] = 1;
2149
+	}
2037 2150
 
2038 2151
 	// For the latest version stuff.
2039 2152
 	echo '
@@ -2067,19 +2180,21 @@  discard block
 block discarded – undo
2067 2180
 	global $txt, $incontext;
2068 2181
 
2069 2182
 	// Errors are very serious..
2070
-	if (!empty($incontext['error']))
2071
-		echo '
2183
+	if (!empty($incontext['error'])) {
2184
+			echo '
2072 2185
 		<div class="errorbox">
2073 2186
 			<h3>', $txt['upgrade_critical_error'], '</h3>
2074 2187
 			', $incontext['error'], '
2075 2188
 		</div>';
2189
+	}
2076 2190
 	// A warning message?
2077
-	elseif (!empty($incontext['warning']))
2078
-		echo '
2191
+	elseif (!empty($incontext['warning'])) {
2192
+			echo '
2079 2193
 		<div class="errorbox">
2080 2194
 			<h3>', $txt['upgrade_warning'], '</h3>
2081 2195
 			', $incontext['warning'], '
2082 2196
 		</div>';
2197
+	}
2083 2198
 
2084 2199
 	return empty($incontext['error']) && empty($incontext['warning']);
2085 2200
 }
@@ -2095,26 +2210,29 @@  discard block
 block discarded – undo
2095 2210
 			<li>', $incontext['failed_files']), '</li>
2096 2211
 		</ul>';
2097 2212
 
2098
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2099
-		echo '
2213
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2214
+			echo '
2100 2215
 		<hr>
2101 2216
 		<p>', $txt['chmod_linux_info'], '</p>
2102 2217
 		<samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>';
2218
+	}
2103 2219
 
2104 2220
 	// This is serious!
2105
-	if (!template_warning_divs())
2106
-		return;
2221
+	if (!template_warning_divs()) {
2222
+			return;
2223
+	}
2107 2224
 
2108 2225
 	echo '
2109 2226
 		<hr>
2110 2227
 		<p>', $txt['ftp_setup_info'], '</p>';
2111 2228
 
2112
-	if (!empty($incontext['ftp_errors']))
2113
-		echo '
2229
+	if (!empty($incontext['ftp_errors'])) {
2230
+			echo '
2114 2231
 		<div class="error_message">
2115 2232
 			', $txt['error_ftp_no_connect'], '<br><br>
2116 2233
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2117 2234
 		</div>';
2235
+	}
2118 2236
 
2119 2237
 	echo '
2120 2238
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2183,16 +2301,16 @@  discard block
 block discarded – undo
2183 2301
 			<dd>
2184 2302
 				<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2185 2303
 
2186
-	foreach ($incontext['supported_databases'] as $key => $db)
2187
-			echo '
2304
+	foreach ($incontext['supported_databases'] as $key => $db) {
2305
+				echo '
2188 2306
 					<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2307
+	}
2189 2308
 
2190 2309
 	echo '
2191 2310
 				</select>
2192 2311
 				<div class="smalltext">', $txt['db_settings_type_info'], '</div>
2193 2312
 			</dd>';
2194
-	}
2195
-	else
2313
+	} else
2196 2314
 	{
2197 2315
 		echo '
2198 2316
 			<dd>
@@ -2360,9 +2478,10 @@  discard block
 block discarded – undo
2360 2478
 		<div class="red">', $txt['error_db_queries'], '</div>
2361 2479
 		<ul>';
2362 2480
 
2363
-		foreach ($incontext['failures'] as $line => $fail)
2364
-			echo '
2481
+		foreach ($incontext['failures'] as $line => $fail) {
2482
+					echo '
2365 2483
 			<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2484
+		}
2366 2485
 
2367 2486
 		echo '
2368 2487
 		</ul>';
@@ -2427,15 +2546,16 @@  discard block
 block discarded – undo
2427 2546
 			</dd>
2428 2547
 		</dl>';
2429 2548
 
2430
-	if ($incontext['require_db_confirm'])
2431
-		echo '
2549
+	if ($incontext['require_db_confirm']) {
2550
+			echo '
2432 2551
 		<h2>', $txt['user_settings_database'], '</h2>
2433 2552
 		<p>', $txt['user_settings_database_info'], '</p>
2434 2553
 
2435 2554
 		<div class="lefttext">
2436 2555
 			<input type="password" name="password3" size="30">
2437 2556
 		</div>';
2438
-}
2557
+	}
2558
+	}
2439 2559
 
2440 2560
 // Tell them it's done, and to delete.
2441 2561
 function template_delete_install()
@@ -2448,13 +2568,14 @@  discard block
 block discarded – undo
2448 2568
 	template_warning_divs();
2449 2569
 
2450 2570
 	// Install directory still writable?
2451
-	if ($incontext['dir_still_writable'])
2452
-		echo '
2571
+	if ($incontext['dir_still_writable']) {
2572
+			echo '
2453 2573
 		<p><em>', $txt['still_writable'], '</em></p>';
2574
+	}
2454 2575
 
2455 2576
 	// Don't show the box if it's like 99% sure it won't work :P.
2456
-	if ($incontext['probably_delete_install'])
2457
-		echo '
2577
+	if ($incontext['probably_delete_install']) {
2578
+			echo '
2458 2579
 		<label>
2459 2580
 			<input type="checkbox" id="delete_self" onclick="doTheDelete();">
2460 2581
 			<strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong>
@@ -2470,6 +2591,7 @@  discard block
 block discarded – undo
2470 2591
 				theCheck.disabled = true;
2471 2592
 			}
2472 2593
 		</script>';
2594
+	}
2473 2595
 
2474 2596
 	echo '
2475 2597
 		<p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p>
Please login to merge, or discard this patch.
Themes/default/GenericControls.template.php 1 patch
Braces   +74 added lines, -54 removed lines patch added patch discarded remove patch
@@ -23,11 +23,13 @@  discard block
 block discarded – undo
23 23
 
24 24
 	$editor_context = &$context['controls']['richedit'][$editor_id];
25 25
 
26
-	if ($smileyContainer === null)
27
-		$editor_context['sce_options']['emoticonsEnabled'] = false;
26
+	if ($smileyContainer === null) {
27
+			$editor_context['sce_options']['emoticonsEnabled'] = false;
28
+	}
28 29
 
29
-	if ($bbcContainer === null)
30
-		$editor_context['sce_options']['toolbar'] = '';
30
+	if ($bbcContainer === null) {
31
+			$editor_context['sce_options']['toolbar'] = '';
32
+	}
31 33
 
32 34
 	echo '
33 35
 		<textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" cols="600" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="', $context['tabindex']++, '" style="width: ', $editor_context['width'], '; height: ', $editor_context['height'], ';', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? 'border: 1px solid red;' : '', '"', !empty($context['editor']['required']) ? ' required' : '', '>', $editor_context['value'], '</textarea>
@@ -40,18 +42,21 @@  discard block
 block discarded – undo
40 42
 				var textarea = $("#', $editor_id, '").get(0);
41 43
 				sceditor.create(textarea, ', $smcFunc['json_encode']($editor_context['sce_options'], JSON_PRETTY_PRINT), ');';
42 44
 
43
-	if ($editor_context['sce_options']['emoticonsEnabled'])
44
-		echo '
45
+	if ($editor_context['sce_options']['emoticonsEnabled']) {
46
+			echo '
45 47
 				sceditor.instance(textarea).createPermanentDropDown();';
48
+	}
46 49
 
47
-	if (empty($editor_context['rich_active']))
48
-		echo '
50
+	if (empty($editor_context['rich_active'])) {
51
+			echo '
49 52
 				sceditor.instance(textarea).toggleSourceMode();';
53
+	}
50 54
 
51
-	if (isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']))
52
-		echo '
55
+	if (isset($context['post_error']['no_message']) || isset($context['post_error']['long_message'])) {
56
+			echo '
53 57
 				$(".sceditor-container").find("textarea").each(function() {$(this).css({border: "1px solid red"})});
54 58
 				$(".sceditor-container").find("iframe").each(function() {$(this).css({border: "1px solid red"})});';
59
+	}
55 60
 
56 61
 	echo '
57 62
 			});';
@@ -88,42 +93,47 @@  discard block
 block discarded – undo
88 93
 
89 94
 	$tempTab = $context['tabindex'];
90 95
 
91
-	if (!empty($context['drafts_pm_save']))
92
-		$tempTab++;
93
-	elseif (!empty($context['drafts_save']))
94
-		$tempTab++;
95
-	elseif ($editor_context['preview_type'])
96
-		$tempTab++;
97
-	elseif ($context['show_spellchecking'])
98
-		$tempTab++;
96
+	if (!empty($context['drafts_pm_save'])) {
97
+			$tempTab++;
98
+	} elseif (!empty($context['drafts_save'])) {
99
+			$tempTab++;
100
+	} elseif ($editor_context['preview_type']) {
101
+			$tempTab++;
102
+	} elseif ($context['show_spellchecking']) {
103
+			$tempTab++;
104
+	}
99 105
 
100 106
 	$tempTab++;
101 107
 	$context['tabindex'] = $tempTab;
102 108
 
103
-	if (!empty($context['drafts_pm_save']))
104
-		echo '
109
+	if (!empty($context['drafts_pm_save'])) {
110
+			echo '
105 111
 		<input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="submitThisOnce(this);" accesskey="d" class="button">
106 112
 		<input type="hidden" id="id_pm_draft" name="id_pm_draft" value="', empty($context['id_pm_draft']) ? 0 : $context['id_pm_draft'], '">';
113
+	}
107 114
 
108
-	if (!empty($context['drafts_save']))
109
-		echo '
115
+	if (!empty($context['drafts_save'])) {
116
+			echo '
110 117
 		<input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', --$tempTab, '" onclick="return confirm(' . JavaScriptEscape($txt['draft_save_note']) . ') && submitThisOnce(this);" accesskey="d" class="button">
111 118
 		<input type="hidden" id="id_draft" name="id_draft" value="', empty($context['id_draft']) ? 0 : $context['id_draft'], '">';
119
+	}
112 120
 
113
-	if ($context['show_spellchecking'])
114
-		echo '
121
+	if ($context['show_spellchecking']) {
122
+			echo '
115 123
 		<input type="button" value="', $txt['spell_check'], '" tabindex="', --$tempTab, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button">';
124
+	}
116 125
 
117
-	if ($editor_context['preview_type'])
118
-		echo '
126
+	if ($editor_context['preview_type']) {
127
+			echo '
119 128
 		<input type="submit" name="preview" value="', isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $txt['preview'], '" tabindex="', --$tempTab, '" onclick="', $editor_context['preview_type'] == 2 ? '' : 'return submitThisOnce(this);', '" accesskey="p" class="button">';
129
+	}
120 130
 
121 131
 	echo '
122 132
 		<input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['post'], '" name="post" tabindex="', --$tempTab, '" onclick="return submitThisOnce(this);" accesskey="s" class="button">';
123 133
 
124 134
 	// Load in the PM autosaver if it's enabled
125
-	if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave']))
126
-		echo '
135
+	if (!empty($context['drafts_pm_save']) && !empty($context['drafts_autosave'])) {
136
+			echo '
127 137
 		<span class="righttext padding" style="display: block">
128 138
 			<span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon"></span>
129 139
 			<span id="draft_lastautosave" ></span>
@@ -141,10 +151,11 @@  discard block
 block discarded – undo
141 151
 				iFreq: ', (empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000), '
142 152
 			});
143 153
 		</script>';
154
+	}
144 155
 
145 156
 	// Start an instance of the auto saver if its enabled
146
-	if (!empty($context['drafts_save']) && !empty($context['drafts_autosave']))
147
-		echo '
157
+	if (!empty($context['drafts_save']) && !empty($context['drafts_autosave'])) {
158
+			echo '
148 159
 		<span class="righttext padding" style="display: block">
149 160
 			<span id="throbber" style="display:none"><img src="', $settings['images_url'], '/loading_sm.gif" alt="" class="centericon"></span>
150 161
 			<span id="draft_lastautosave" ></span>
@@ -161,7 +172,8 @@  discard block
 block discarded – undo
161 172
 				iFreq: ', $context['drafts_autosave_frequency'], '
162 173
 			});
163 174
 		</script>';
164
-}
175
+	}
176
+	}
165 177
 
166 178
 /**
167 179
  * This template displays a verification form
@@ -178,51 +190,57 @@  discard block
 block discarded – undo
178 190
 	$verify_context = &$context['controls']['verification'][$verify_id];
179 191
 
180 192
 	// Keep track of where we are.
181
-	if (empty($verify_context['tracking']) || $reset)
182
-		$verify_context['tracking'] = 0;
193
+	if (empty($verify_context['tracking']) || $reset) {
194
+			$verify_context['tracking'] = 0;
195
+	}
183 196
 
184 197
 	// How many items are there to display in total.
185 198
 	$total_items = count($verify_context['questions']) + ($verify_context['show_visual'] || $verify_context['can_recaptcha'] ? 1 : 0);
186 199
 
187 200
 	// If we've gone too far, stop.
188
-	if ($verify_context['tracking'] > $total_items)
189
-		return false;
201
+	if ($verify_context['tracking'] > $total_items) {
202
+			return false;
203
+	}
190 204
 
191 205
 	// Loop through each item to show them.
192 206
 	for ($i = 0; $i < $total_items; $i++)
193 207
 	{
194 208
 		// If we're after a single item only show it if we're in the right place.
195
-		if ($display_type == 'single' && $verify_context['tracking'] != $i)
196
-			continue;
209
+		if ($display_type == 'single' && $verify_context['tracking'] != $i) {
210
+					continue;
211
+		}
197 212
 
198
-		if ($display_type != 'single')
199
-			echo '
213
+		if ($display_type != 'single') {
214
+					echo '
200 215
 			<div id="verification_control_', $i, '" class="verification_control">';
216
+		}
201 217
 
202 218
 		// Display empty field, but only if we have one, and it's the first time.
203
-		if ($verify_context['empty_field'] && empty($i))
204
-			echo '
219
+		if ($verify_context['empty_field'] && empty($i)) {
220
+					echo '
205 221
 				<div class="smalltext vv_special">
206 222
 					', $txt['visual_verification_hidden'], ':
207 223
 					<input type="text" name="', $_SESSION[$verify_id . '_vv']['empty_field'], '" autocomplete="off" size="30" value="">
208 224
 				</div>';
225
+		}
209 226
 
210 227
 		// Do the actual stuff
211 228
 		if ($i == 0 && ($verify_context['show_visual'] || $verify_context['can_recaptcha']))
212 229
 		{
213 230
 			if ($verify_context['show_visual'])
214 231
 			{
215
-				if ($context['use_graphic_library'])
216
-					echo '
232
+				if ($context['use_graphic_library']) {
233
+									echo '
217 234
 				<img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '">';
218
-				else
219
-					echo '
235
+				} else {
236
+									echo '
220 237
 				<img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1">
221 238
 				<img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2">
222 239
 				<img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3">
223 240
 				<img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4">
224 241
 				<img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5">
225 242
 				<img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6">';
243
+				}
226 244
 
227 245
 				echo '
228 246
 				<div class="smalltext" style="margin: 4px 0 8px 0;">
@@ -240,8 +258,7 @@  discard block
 block discarded – undo
240 258
 				<br>
241 259
 				<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl='.$lang.'"></script>';
242 260
 			}
243
-		}
244
-		else
261
+		} else
245 262
 		{
246 263
 			// Where in the question array is this question?
247 264
 			$qIndex = $verify_context['show_visual'] ? $i - 1 : $i;
@@ -253,21 +270,24 @@  discard block
 block discarded – undo
253 270
 				</div>';
254 271
 		}
255 272
 
256
-		if ($display_type != 'single')
257
-			echo '
273
+		if ($display_type != 'single') {
274
+					echo '
258 275
 			</div><!-- #verification_control_[i] -->';
276
+		}
259 277
 
260 278
 		// If we were displaying just one and we did it, break.
261
-		if ($display_type == 'single' && $verify_context['tracking'] == $i)
262
-			break;
279
+		if ($display_type == 'single' && $verify_context['tracking'] == $i) {
280
+					break;
281
+		}
263 282
 	}
264 283
 
265 284
 	// Assume we found something, always.
266 285
 	$verify_context['tracking']++;
267 286
 
268 287
 	// Tell something displaying piecemeal to keep going.
269
-	if ($display_type == 'single')
270
-		return true;
271
-}
288
+	if ($display_type == 'single') {
289
+			return true;
290
+	}
291
+	}
272 292
 
273 293
 ?>
274 294
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Post.template.php 1 patch
Braces   +184 added lines, -131 removed lines patch added patch discarded remove patch
@@ -22,24 +22,26 @@  discard block
 block discarded – undo
22 22
 		<script>';
23 23
 
24 24
 	// When using Go Back due to fatal_error, allow the form to be re-submitted with changes.
25
-	if (isBrowser('is_firefox'))
26
-		echo '
25
+	if (isBrowser('is_firefox')) {
26
+			echo '
27 27
 			window.addEventListener("pageshow", reActivate, false);';
28
+	}
28 29
 
29 30
 	// Start with message icons - and any missing from this theme.
30 31
 	echo '
31 32
 			var icon_urls = {';
32 33
 
33
-	foreach ($context['icons'] as $icon)
34
-		echo '
34
+	foreach ($context['icons'] as $icon) {
35
+			echo '
35 36
 				\'', $icon['value'], '\': \'', $icon['url'], '\'', $icon['is_last'] ? '' : ',';
37
+	}
36 38
 
37 39
 	echo '
38 40
 			};';
39 41
 
40 42
 	// If this is a poll - use some javascript to ensure the user doesn't create a poll with illegal option combinations.
41
-	if ($context['make_poll'])
42
-		echo '
43
+	if ($context['make_poll']) {
44
+			echo '
43 45
 			var pollOptionNum = 0, pollTabIndex;
44 46
 			var pollOptionId = ', $context['last_choice_id'], ';
45 47
 			function addPollOption()
@@ -58,11 +60,13 @@  discard block
 block discarded – undo
58 60
 
59 61
 				setOuterHTML(document.getElementById(\'pollMoreOptions\'), ', JavaScriptEscape('<dt><label for="options-'), ' + pollOptionId + ', JavaScriptEscape('">' . $txt['option'] . ' '), ' + pollOptionNum + ', JavaScriptEscape('</label>:</dt><dd><input type="text" name="options['), ' + pollOptionId + ', JavaScriptEscape(']" id="options-'), ' + pollOptionId + ', JavaScriptEscape('" value="" size="80" maxlength="255" tabindex="'), ' + pollTabIndex + ', JavaScriptEscape('"></dd><p id="pollMoreOptions"></p>'), ');
60 62
 			}';
63
+	}
61 64
 
62 65
 	// If we are making a calendar event we want to ensure we show the current days in a month etc... this is done here.
63
-	if ($context['make_event'])
64
-		echo '
66
+	if ($context['make_event']) {
67
+			echo '
65 68
 			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];';
69
+	}
66 70
 
67 71
 	// End of the javascript, start the form and display the link tree.
68 72
 	echo '
@@ -83,9 +87,10 @@  discard block
 block discarded – undo
83 87
 			</div>
84 88
 			<br>';
85 89
 
86
-	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board'])))
87
-		echo '
90
+	if ($context['make_event'] && (!$context['event']['new'] || !empty($context['current_board']))) {
91
+			echo '
88 92
 			<input type="hidden" name="eventid" value="', $context['event']['id'], '">';
93
+	}
89 94
 
90 95
 	// Start the main table.
91 96
 	echo '
@@ -110,26 +115,29 @@  discard block
 block discarded – undo
110 115
 					</div>';
111 116
 
112 117
 	// If this won't be approved let them know!
113
-	if (!$context['becomes_approved'])
114
-		echo '
118
+	if (!$context['becomes_approved']) {
119
+			echo '
115 120
 					<div class="noticebox">
116 121
 						<em>', $txt['wait_for_approval'], '</em>
117 122
 						<input type="hidden" name="not_approved" value="1">
118 123
 					</div>';
124
+	}
119 125
 
120 126
 	// If it's locked, show a message to warn the replier.
121
-	if (!empty($context['locked']))
122
-	echo '
127
+	if (!empty($context['locked'])) {
128
+		echo '
123 129
 					<div class="errorbox">
124 130
 						', $txt['topic_locked_no_reply'], '
125 131
 					</div>';
132
+	}
126 133
 
127
-	if (!empty($modSettings['drafts_post_enabled']))
128
-		echo '
134
+	if (!empty($modSettings['drafts_post_enabled'])) {
135
+			echo '
129 136
 					<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
130 137
 						sprintf($txt['draft_saved'], $scripturl . '?action=profile;u=' . $context['user']['id'] . ';area=showdrafts'), '
131 138
 						', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
132 139
 					</div>';
140
+	}
133 141
 
134 142
 	// The post header... important stuff
135 143
 	template_post_header();
@@ -162,9 +170,10 @@  discard block
 block discarded – undo
162 170
 				echo '
163 171
 										<optgroup label="', $category['name'], '">';
164 172
 
165
-				foreach ($category['boards'] as $board)
166
-					echo '
173
+				foreach ($category['boards'] as $board) {
174
+									echo '
167 175
 											<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
176
+				}
168 177
 				echo '
169 178
 										</optgroup>';
170 179
 			}
@@ -200,9 +209,10 @@  discard block
 block discarded – undo
200 209
 									<span class="label">', $txt['calendar_timezone'], '</span>
201 210
 									<select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>';
202 211
 
203
-		foreach ($context['all_timezones'] as $tz => $tzname)
204
-			echo '
212
+		foreach ($context['all_timezones'] as $tz => $tzname) {
213
+					echo '
205 214
 										<option', is_numeric($tz) ? ' value="" disabled' : ' value="' . $tz . '"', $tz === $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>';
215
+		}
206 216
 
207 217
 		echo '
208 218
 									</select>
@@ -231,14 +241,15 @@  discard block
 block discarded – undo
231 241
 								</dd>';
232 242
 
233 243
 		// Loop through all the choices and print them out.
234
-		foreach ($context['choices'] as $choice)
235
-			echo '
244
+		foreach ($context['choices'] as $choice) {
245
+					echo '
236 246
 								<dt>
237 247
 									<label for="options-', $choice['id'], '">', $txt['option'], ' ', $choice['number'], '</label>:
238 248
 								</dt>
239 249
 								<dd>
240 250
 									<input type="text" name="options[', $choice['id'], ']" id="options-', $choice['id'], '" value="', $choice['label'], '" tabindex="', $context['tabindex']++, '" size="80" maxlength="255">
241 251
 								</dd>';
252
+		}
242 253
 
243 254
 		echo '
244 255
 								<p id="pollMoreOptions"></p>
@@ -268,14 +279,15 @@  discard block
 block discarded – undo
268 279
 									<input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked' : '', '>
269 280
 								</dd>';
270 281
 
271
-		if ($context['poll_options']['guest_vote_enabled'])
272
-			echo '
282
+		if ($context['poll_options']['guest_vote_enabled']) {
283
+					echo '
273 284
 								<dt>
274 285
 									<label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
275 286
 								</dt>
276 287
 								<dd>
277 288
 									<input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll_options']['guest_vote']) ? ' checked' : '', '>
278 289
 								</dd>';
290
+		}
279 291
 
280 292
 		echo '
281 293
 								<dt>
@@ -296,8 +308,8 @@  discard block
 block discarded – undo
296 308
 					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
297 309
 
298 310
 	// If we're editing and displaying edit details, show a box where they can say why
299
-	if (isset($context['editing']) && $modSettings['show_modify'])
300
-		echo '
311
+	if (isset($context['editing']) && $modSettings['show_modify']) {
312
+			echo '
301 313
 					<dl>
302 314
 						<dt class="clear">
303 315
 							<span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span>
@@ -306,20 +318,23 @@  discard block
 block discarded – undo
306 318
 							<input type="text" name="modify_reason"', isset($context['last_modified_reason']) ? ' value="' . $context['last_modified_reason'] . '"' : '', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80">
307 319
 						</dd>
308 320
 					</dl>';
321
+	}
309 322
 
310 323
 	// If this message has been edited in the past - display when it was.
311
-	if (isset($context['last_modified']))
312
-		echo '
324
+	if (isset($context['last_modified'])) {
325
+			echo '
313 326
 					<div class="padding smalltext">
314 327
 						', $context['last_modified_text'], '
315 328
 					</div>';
329
+	}
316 330
 
317 331
 	// If the admin has enabled the hiding of the additional options - show a link and image for it.
318
-	if (!empty($modSettings['additional_options_collapsable']))
319
-		echo '
332
+	if (!empty($modSettings['additional_options_collapsable'])) {
333
+			echo '
320 334
 					<div id="postAdditionalOptionsHeader">
321 335
 						<strong><a href="#" id="postMoreExpandLink"> ', $context['can_post_attachment'] ? $txt['post_additionalopt_attach'] : $txt['post_additionalopt'], '</a></strong>
322 336
 					</div>';
337
+	}
323 338
 
324 339
 	echo '
325 340
 					<div id="postAdditionalOptions">';
@@ -352,19 +367,21 @@  discard block
 block discarded – undo
352 367
 								', $txt['uncheck_unwatchd_attach'], ':
353 368
 							</dd>';
354 369
 
355
-		foreach ($context['current_attachments'] as $attachment)
356
-			echo '
370
+		foreach ($context['current_attachments'] as $attachment) {
371
+					echo '
357 372
 							<dd class="smalltext">
358 373
 								<label for="attachment_', $attachment['attachID'], '"><input type="checkbox" id="attachment_', $attachment['attachID'], '" name="attach_del[]" value="', $attachment['attachID'], '"', empty($attachment['unchecked']) ? ' checked' : '', '> ', $attachment['name'], (empty($attachment['approved']) ? ' (' . $txt['awaiting_approval'] . ')' : ''),
359 374
 								!empty($modSettings['attachmentPostLimit']) || !empty($modSettings['attachmentSizeLimit']) ? sprintf($txt['attach_kb'], comma_format(round(max($attachment['size'], 1024) / 1024), 0)) : '', '</label>
360 375
 							</dd>';
376
+		}
361 377
 
362 378
 		echo '
363 379
 						</dl>';
364 380
 
365
-		if (!empty($context['files_in_session_warning']))
366
-			echo '
381
+		if (!empty($context['files_in_session_warning'])) {
382
+					echo '
367 383
 						<div class="smalltext">', $context['files_in_session_warning'], '</div>';
384
+		}
368 385
 	}
369 386
 
370 387
 	// Is the user allowed to post any additional ones? If so give them the boxes to do it!
@@ -429,13 +446,14 @@  discard block
 block discarded – undo
429 446
 									<div class="fallback">
430 447
 										<input type="file" multiple="multiple" name="attachment[]" id="attachment1" class="fallback"> (<a href="javascript:void(0);" onclick="cleanFileInput(\'attachment1\');">', $txt['clean_attach'], '</a>)';
431 448
 
432
-		if (!empty($modSettings['attachmentSizeLimit']))
433
-			echo '
449
+		if (!empty($modSettings['attachmentSizeLimit'])) {
450
+					echo '
434 451
 										<input type="hidden" name="MAX_FILE_SIZE" value="' . $modSettings['attachmentSizeLimit'] * 1024 . '">';
452
+		}
435 453
 
436 454
 		// Show more boxes if they aren't approaching that limit.
437
-		if ($context['num_allowed_attachments'] > 1)
438
-			echo '
455
+		if ($context['num_allowed_attachments'] > 1) {
456
+					echo '
439 457
 										<script>
440 458
 											var allowed_attachments = ', $context['num_allowed_attachments'], ';
441 459
 											var current_attachment = 1;
@@ -455,6 +473,7 @@  discard block
 block discarded – undo
455 473
 										<a href="#" onclick="addAttachment(); return false;">(', $txt['more_attachments'], ')</a>
456 474
 									</div><!-- .fallback -->
457 475
 								</div><!-- #attachUpload -->';
476
+		}
458 477
 
459 478
 		echo '
460 479
 							</dd>';
@@ -466,21 +485,25 @@  discard block
 block discarded – undo
466 485
 							<dd class="smalltext">';
467 486
 
468 487
 		// Show some useful information such as allowed extensions, maximum size and amount of attachments allowed.
469
-		if (!empty($modSettings['attachmentCheckExtensions']))
470
-			echo '
488
+		if (!empty($modSettings['attachmentCheckExtensions'])) {
489
+					echo '
471 490
 								', $txt['allowed_types'], ': ', $context['allowed_extensions'], '<br>';
491
+		}
472 492
 
473
-		if (!empty($context['attachment_restrictions']))
474
-			echo '
493
+		if (!empty($context['attachment_restrictions'])) {
494
+					echo '
475 495
 								', $txt['attach_restrictions'], ' ', implode(', ', $context['attachment_restrictions']), '<br>';
496
+		}
476 497
 
477
-		if ($context['num_allowed_attachments'] == 0)
478
-			echo '
498
+		if ($context['num_allowed_attachments'] == 0) {
499
+					echo '
479 500
 								', $txt['attach_limit_nag'], '<br>';
501
+		}
480 502
 
481
-		if (!$context['can_post_attachment_unapproved'])
482
-			echo '
503
+		if (!$context['can_post_attachment_unapproved']) {
504
+					echo '
483 505
 								<span class="alert">', $txt['attachment_requires_approval'], '</span>', '<br>';
506
+		}
484 507
 
485 508
 		echo '
486 509
 							</dd>
@@ -504,24 +527,26 @@  discard block
 block discarded – undo
504 527
 							<dt><strong>', $txt['subject'], '</strong></dt>
505 528
 							<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
506 529
 
507
-		foreach ($context['drafts'] as $draft)
508
-			echo '
530
+		foreach ($context['drafts'] as $draft) {
531
+					echo '
509 532
 							<dt>', $draft['link'], '</dt>
510 533
 							<dd>', $draft['poster_time'], '</dd>';
534
+		}
511 535
 		echo '
512 536
 						</dl>
513 537
 					</div>';
514 538
 	}
515 539
 
516 540
 	// Is visual verification enabled?
517
-	if ($context['require_verification'])
518
-		echo '
541
+	if ($context['require_verification']) {
542
+			echo '
519 543
 					<div class="post_verification">
520 544
 						<span', !empty($context['post_error']['need_qr_verification']) ? ' class="error"' : '', '>
521 545
 							<strong>', $txt['verification'], ':</strong>
522 546
 						</span>
523 547
 						', template_control_verification($context['visual_verification_id'], 'all'), '
524 548
 					</div>';
549
+	}
525 550
 
526 551
 	// Finally, the submit buttons.
527 552
 	echo '
@@ -530,9 +555,10 @@  discard block
 block discarded – undo
530 555
 						', template_control_richedit_buttons($context['post_box_name']);
531 556
 
532 557
 	// Option to delete an event if user is editing one.
533
-	if ($context['make_event'] && !$context['event']['new'])
534
-		echo '
558
+	if ($context['make_event'] && !$context['event']['new']) {
559
+			echo '
535 560
 						<input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['event_delete_confirm'] ,'" class="button you_sure">';
561
+	}
536 562
 
537 563
 	echo '
538 564
 					</span>
@@ -541,9 +567,10 @@  discard block
 block discarded – undo
541 567
 			<br class="clear">';
542 568
 
543 569
 	// Assuming this isn't a new topic pass across the last message id.
544
-	if (isset($context['topic_last_message']))
545
-		echo '
570
+	if (isset($context['topic_last_message'])) {
571
+			echo '
546 572
 			<input type="hidden" name="last_msg" value="', $context['topic_last_message'], '">';
573
+	}
547 574
 
548 575
 	echo '
549 576
 			<input type="hidden" name="additional_options" id="additional_options" value="', $context['show_additional_options'] ? '1' : '0', '">
@@ -564,13 +591,14 @@  discard block
 block discarded – undo
564 591
 			</h5>
565 592
 			&nbsp;-&nbsp;%PostTime%&nbsp;&#187; <span class="new_posts" id="image_new_%PostID%">' . $txt['new'] . '</span>';
566 593
 
567
-	if ($context['can_quote'])
568
-		$newPostsHTML .= '
594
+	if ($context['can_quote']) {
595
+			$newPostsHTML .= '
569 596
 			<ul class="quickbuttons sf-js-enabled sf-arrows" id="msg_%PostID%_quote" style="touch-action: pan-y;">
570 597
 				<li id="post_modify">
571 598
 					<a href="#postmodify" onclick="return insertQuoteFast(%PostID%);" class="quote_button"><span class="generic_icons quote"></span>' . $txt['quote'] . '</a>
572 599
 				</li>
573 600
 			</ul>';
601
+	}
574 602
 
575 603
 	$newPostsHTML .= '
576 604
 			<br class="clear">
@@ -596,16 +624,17 @@  discard block
 block discarded – undo
596 624
 				sSessionVar: ', JavaScriptEscape($context['session_var']), ',
597 625
 				newPostsTemplate:', JavaScriptEscape($newPostsHTML);
598 626
 
599
-	if (!empty($context['current_board']))
600
-		echo ',
627
+	if (!empty($context['current_board'])) {
628
+			echo ',
601 629
 				iCurrentBoard: ', $context['current_board'], '';
630
+	}
602 631
 
603 632
 	echo '
604 633
 			});';
605 634
 
606 635
 	// Code for showing and hiding additional options.
607
-	if (!empty($modSettings['additional_options_collapsable']))
608
-		echo '
636
+	if (!empty($modSettings['additional_options_collapsable'])) {
637
+			echo '
609 638
 			var oSwapAdditionalOptions = new smc_Toggle({
610 639
 				bToggleEnabled: true,
611 640
 				bCurrentlyCollapsed: ', $context['show_additional_options'] ? 'false' : 'true', ',
@@ -633,10 +662,11 @@  discard block
 block discarded – undo
633 662
 					}
634 663
 				]
635 664
 			});';
665
+	}
636 666
 
637 667
 	// Code for showing and hiding drafts
638
-	if (!empty($context['drafts']))
639
-		echo '
668
+	if (!empty($context['drafts'])) {
669
+			echo '
640 670
 			var oSwapDraftOptions = new smc_Toggle({
641 671
 				bToggleEnabled: true,
642 672
 				bCurrentlyCollapsed: true,
@@ -658,6 +688,7 @@  discard block
 block discarded – undo
658 688
 					}
659 689
 				]
660 690
 			});';
691
+	}
661 692
 
662 693
 	echo '
663 694
 			var oEditorID = "', $context['post_box_name'] ,'";
@@ -678,8 +709,9 @@  discard block
 block discarded – undo
678 709
 		foreach ($context['previous_posts'] as $post)
679 710
 		{
680 711
 			$ignoring = false;
681
-			if (!empty($post['is_ignored']))
682
-				$ignored_posts[] = $ignoring = $post['id'];
712
+			if (!empty($post['is_ignored'])) {
713
+							$ignored_posts[] = $ignoring = $post['id'];
714
+			}
683 715
 
684 716
 			echo '
685 717
 			<div class="windowbg">
@@ -689,22 +721,24 @@  discard block
 block discarded – undo
689 721
 					</h5>
690 722
 					&nbsp;-&nbsp;', $post['time'];
691 723
 
692
-			if ($context['can_quote'])
693
-				echo '
724
+			if ($context['can_quote']) {
725
+							echo '
694 726
 					<ul class="quickbuttons" id="msg_', $post['id'], '_quote">
695 727
 						<li style="display:none;" id="quoteSelected_', $post['id'], '" data-msgid="', $post['id'], '"><a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'] ,'</a></li>
696 728
 						<li id="post_modify"><a href="#postmodify" onclick="return insertQuoteFast(', $post['id'], ');"><span class="generic_icons quote"></span>', $txt['quote'], '</a></li>
697 729
 					</ul>';
730
+			}
698 731
 
699 732
 			echo '
700 733
 					<br class="clear">';
701 734
 
702
-			if ($ignoring)
703
-				echo '
735
+			if ($ignoring) {
736
+							echo '
704 737
 					<div id="msg_', $post['id'], '_ignored_prompt" class="smalltext">
705 738
 						', $txt['ignoring_user'], '
706 739
 						<a href="#" id="msg_', $post['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
707 740
 					</div>';
741
+			}
708 742
 
709 743
 			echo '
710 744
 					<div class="list_posts smalltext" id="msg_', $post['id'], '_body" data-msgid="', $post['id'], '">', $post['message'], '</div>
@@ -859,10 +893,10 @@  discard block
 block discarded – undo
859 893
 		<div id="temporary_posting_area" style="display: none;"></div>
860 894
 		<script>';
861 895
 
862
-	if ($context['close_window'])
863
-		echo '
896
+	if ($context['close_window']) {
897
+			echo '
864 898
 			window.close();';
865
-	else
899
+	} else
866 900
 	{
867 901
 		// Lucky for us, Internet Explorer has an "innerText" feature which basically converts entities <--> text. Use it if possible ;)
868 902
 		echo '
@@ -916,11 +950,12 @@  discard block
 block discarded – undo
916 950
 				</p>
917 951
 				<ul>';
918 952
 
919
-	foreach ($context['groups'] as $group)
920
-		echo '
953
+	foreach ($context['groups'] as $group) {
954
+			echo '
921 955
 					<li>
922 956
 						<label for="who_', $group['id'], '"><input type="checkbox" name="who[', $group['id'], ']" id="who_', $group['id'], '" value="', $group['id'], '" checked> ', $group['name'], '</label> <em>(', $group['member_count'], ')</em>
923 957
 					</li>';
958
+	}
924 959
 
925 960
 	echo '
926 961
 					<li>
@@ -1027,28 +1062,32 @@  discard block
 block discarded – undo
1027 1062
 	foreach ($context['posting_fields'] as $pfid => $pf)
1028 1063
 	{
1029 1064
 		// We need both a label and an input
1030
-		if (empty($pf['label']) || empty($pf['input']))
1031
-			continue;
1065
+		if (empty($pf['label']) || empty($pf['input'])) {
1066
+					continue;
1067
+		}
1032 1068
 
1033 1069
 		// The labels are pretty simple...
1034 1070
 		echo '
1035 1071
 						<dt class="clear pf_', $pfid, '">';
1036 1072
 
1037 1073
 		// Any leading HTML before the label
1038
-		if (!empty($pf['label']['before']))
1039
-			echo '
1074
+		if (!empty($pf['label']['before'])) {
1075
+					echo '
1040 1076
 							', $pf['label']['before'];
1077
+		}
1041 1078
 
1042
-		if (!empty($pf['label']['html']))
1043
-			echo $pf['label']['html'];
1044
-		else
1045
-			echo '
1079
+		if (!empty($pf['label']['html'])) {
1080
+					echo $pf['label']['html'];
1081
+		} else {
1082
+					echo '
1046 1083
 							<label for="', !empty($pf['input']['attributes']['name']) ? $pf['input']['attributes']['name'] : $pfid, '" id="caption_', $pfid, '"', !empty($pf['label']['class']) ? ' class="' . $pf['label']['class'] . '"' : '', '>', $pf['label']['text'], '</label>';
1084
+		}
1047 1085
 
1048 1086
 		// Any trailing HTML after the label
1049
-		if (!empty($pf['label']['after']))
1050
-			echo '
1087
+		if (!empty($pf['label']['after'])) {
1088
+					echo '
1051 1089
 							', $pf['label']['after'];
1090
+		}
1052 1091
 
1053 1092
 		echo '
1054 1093
 						</dt>';
@@ -1058,9 +1097,10 @@  discard block
 block discarded – undo
1058 1097
 						<dd class="pf_', $pfid, '">';
1059 1098
 
1060 1099
 		// Any leading HTML before the main input
1061
-		if (!empty($pf['input']['before']))
1062
-			echo '
1100
+		if (!empty($pf['input']['before'])) {
1101
+					echo '
1063 1102
 							', $pf['input']['before'];
1103
+		}
1064 1104
 
1065 1105
 		// If there is a literal HTML string already defined, just print it.
1066 1106
 		if (!empty($pf['input']['html']))
@@ -1073,17 +1113,19 @@  discard block
 block discarded – undo
1073 1113
 			echo '
1074 1114
 							<input type="', $pf['input']['type'], '"';
1075 1115
 
1076
-			if (empty($pf['input']['attributes']['name']))
1077
-				echo ' name="', $pfid, '"';
1116
+			if (empty($pf['input']['attributes']['name'])) {
1117
+							echo ' name="', $pfid, '"';
1118
+			}
1078 1119
 
1079 1120
 			if (!empty($pf['input']['attributes']) && is_array($pf['input']['attributes']))
1080 1121
 			{
1081 1122
 				foreach ($pf['input']['attributes'] as $attribute => $value)
1082 1123
 				{
1083
-					if (is_bool($value))
1084
-						echo $value ? ' ' . $attribute : '';
1085
-					else
1086
-						echo ' ', $attribute, '="', $value, '"';
1124
+					if (is_bool($value)) {
1125
+											echo $value ? ' ' . $attribute : '';
1126
+					} else {
1127
+											echo ' ', $attribute, '="', $value, '"';
1128
+					}
1087 1129
 				}
1088 1130
 			}
1089 1131
 
@@ -1095,19 +1137,21 @@  discard block
 block discarded – undo
1095 1137
 			echo '
1096 1138
 							<textarea';
1097 1139
 
1098
-			if (empty($pf['input']['attributes']['name']))
1099
-				echo ' name="', $pfid, '"';
1140
+			if (empty($pf['input']['attributes']['name'])) {
1141
+							echo ' name="', $pfid, '"';
1142
+			}
1100 1143
 
1101 1144
 			if (!empty($pf['input']['attributes']) && is_array($pf['input']['attributes']))
1102 1145
 			{
1103 1146
 				foreach ($pf['input']['attributes'] as $attribute => $value)
1104 1147
 				{
1105
-					if ($attribute === 'value')
1106
-						continue;
1107
-					elseif (is_bool($value))
1108
-						echo $value ? ' ' . $attribute : '';
1109
-					else
1110
-						echo ' ', $attribute, '="', $value, '"';
1148
+					if ($attribute === 'value') {
1149
+											continue;
1150
+					} elseif (is_bool($value)) {
1151
+											echo $value ? ' ' . $attribute : '';
1152
+					} else {
1153
+											echo ' ', $attribute, '="', $value, '"';
1154
+					}
1111 1155
 				}
1112 1156
 			}
1113 1157
 
@@ -1120,17 +1164,19 @@  discard block
 block discarded – undo
1120 1164
 			echo '
1121 1165
 							<select';
1122 1166
 
1123
-			if (empty($pf['input']['attributes']['name']))
1124
-				echo ' name="', $pfid, '"';
1167
+			if (empty($pf['input']['attributes']['name'])) {
1168
+							echo ' name="', $pfid, '"';
1169
+			}
1125 1170
 
1126 1171
 			if (!empty($pf['input']['attributes']) && is_array($pf['input']['attributes']))
1127 1172
 			{
1128 1173
 				foreach ($pf['input']['attributes'] as $attribute => $value)
1129 1174
 				{
1130
-					if (is_bool($value))
1131
-						echo $value ? ' ' . $attribute : '';
1132
-					else
1133
-						echo ' ', $attribute, '="', $value, '"';
1175
+					if (is_bool($value)) {
1176
+											echo $value ? ' ' . $attribute : '';
1177
+					} else {
1178
+											echo ' ', $attribute, '="', $value, '"';
1179
+					}
1134 1180
 				}
1135 1181
 			}
1136 1182
 
@@ -1145,17 +1191,19 @@  discard block
 block discarded – undo
1145 1191
 					echo '
1146 1192
 								<optgroup';
1147 1193
 
1148
-					if (empty($option['attributes']['label']))
1149
-						echo ' label="', $optlabel, '"';
1194
+					if (empty($option['attributes']['label'])) {
1195
+											echo ' label="', $optlabel, '"';
1196
+					}
1150 1197
 
1151 1198
 					if (!empty($option['attributes']) && is_array($option['attributes']))
1152 1199
 					{
1153 1200
 						foreach ($option['attributes'] as $attribute => $value)
1154 1201
 						{
1155
-							if (is_bool($value))
1156
-								echo $value ? ' ' . $attribute : '';
1157
-							else
1158
-								echo ' ', $attribute, '="', $value, '"';
1202
+							if (is_bool($value)) {
1203
+															echo $value ? ' ' . $attribute : '';
1204
+							} else {
1205
+															echo ' ', $attribute, '="', $value, '"';
1206
+							}
1159 1207
 						}
1160 1208
 					}
1161 1209
 
@@ -1168,10 +1216,11 @@  discard block
 block discarded – undo
1168 1216
 
1169 1217
 						foreach ($grouped_option['attributes'] as $attribute => $value)
1170 1218
 						{
1171
-							if (is_bool($value))
1172
-								echo $value ? ' ' . $attribute : '';
1173
-							else
1174
-								echo ' ', $attribute, '="', $value, '"';
1219
+							if (is_bool($value)) {
1220
+															echo $value ? ' ' . $attribute : '';
1221
+							} else {
1222
+															echo ' ', $attribute, '="', $value, '"';
1223
+							}
1175 1224
 						}
1176 1225
 
1177 1226
 						echo '>', $grouped_optlabel, '</option>';
@@ -1189,10 +1238,11 @@  discard block
 block discarded – undo
1189 1238
 
1190 1239
 					foreach ($option['attributes'] as $attribute => $value)
1191 1240
 					{
1192
-						if (is_bool($value))
1193
-							echo $value ? ' ' . $attribute : '';
1194
-						else
1195
-							echo ' ', $attribute, '="', $value, '"';
1241
+						if (is_bool($value)) {
1242
+													echo $value ? ' ' . $attribute : '';
1243
+						} else {
1244
+													echo ' ', $attribute, '="', $value, '"';
1245
+						}
1196 1246
 					}
1197 1247
 
1198 1248
 					echo '>', $optlabel, '</option>';
@@ -1213,12 +1263,13 @@  discard block
 block discarded – undo
1213 1263
 			{
1214 1264
 				foreach ($pf['input']['attributes'] as $attribute => $value)
1215 1265
 				{
1216
-					if ($attribute === 'name')
1217
-						continue;
1218
-					elseif (is_bool($value))
1219
-						echo $value ? ' ' . $attribute : '';
1220
-					else
1221
-						echo ' ', $attribute, '="', $value, '"';
1266
+					if ($attribute === 'name') {
1267
+											continue;
1268
+					} elseif (is_bool($value)) {
1269
+											echo $value ? ' ' . $attribute : '';
1270
+					} else {
1271
+											echo ' ', $attribute, '="', $value, '"';
1272
+					}
1222 1273
 				}
1223 1274
 			}
1224 1275
 
@@ -1231,10 +1282,11 @@  discard block
 block discarded – undo
1231 1282
 
1232 1283
 				foreach ($option['attributes'] as $attribute => $value)
1233 1284
 				{
1234
-					if (is_bool($value))
1235
-						echo $value ? ' ' . $attribute : '';
1236
-					else
1237
-						echo ' ', $attribute, '="', $value, '"';
1285
+					if (is_bool($value)) {
1286
+											echo $value ? ' ' . $attribute : '';
1287
+					} else {
1288
+											echo ' ', $attribute, '="', $value, '"';
1289
+					}
1238 1290
 				}
1239 1291
 
1240 1292
 				echo ' tabindex="', $context['tabindex']++, '">', $optlabel, '</input>';
@@ -1245,9 +1297,10 @@  discard block
 block discarded – undo
1245 1297
 		}
1246 1298
 
1247 1299
 		// Any trailing HTML after the main input
1248
-		if (!empty($pf['input']['after']))
1249
-			echo '
1300
+		if (!empty($pf['input']['after'])) {
1301
+					echo '
1250 1302
 							', $pf['input']['after'];
1303
+		}
1251 1304
 
1252 1305
 		echo '
1253 1306
 						</dd>';
Please login to merge, or discard this patch.
Sources/ManageMembers.php 1 patch
Braces   +165 added lines, -124 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main entrance point for the Manage Members screen.
@@ -109,12 +110,13 @@  discard block
 block discarded – undo
109 110
 	$context['tabs'][$context['last_tab']]['is_last'] = true;
110 111
 
111 112
 	// Find the active tab.
112
-	if (isset($context['tabs'][$context['current_subaction']]))
113
-		$context['tabs'][$context['current_subaction']]['is_selected'] = true;
114
-	elseif (isset($context['current_subaction']))
115
-		foreach ($context['tabs'] as $id_tab => $tab_data)
113
+	if (isset($context['tabs'][$context['current_subaction']])) {
114
+			$context['tabs'][$context['current_subaction']]['is_selected'] = true;
115
+	} elseif (isset($context['current_subaction'])) {
116
+			foreach ($context['tabs'] as $id_tab => $tab_data)
116 117
 			if (!empty($tab_data['selected_actions']) && in_array($context['current_subaction'], $tab_data['selected_actions']))
117 118
 				$context['tabs'][$id_tab]['is_selected'] = true;
119
+	}
118 120
 
119 121
 	call_helper($subActions[$context['current_subaction']][0]);
120 122
 }
@@ -144,8 +146,9 @@  discard block
 block discarded – undo
144 146
 		foreach ($_POST['delete'] as $key => $value)
145 147
 		{
146 148
 			// Don't delete yourself, idiot.
147
-			if ($value != $user_info['id'])
148
-				$delete[$key] = (int) $value;
149
+			if ($value != $user_info['id']) {
150
+							$delete[$key] = (int) $value;
151
+			}
149 152
 		}
150 153
 
151 154
 		if (!empty($delete))
@@ -181,17 +184,18 @@  discard block
 block discarded – undo
181 184
 		);
182 185
 		while ($row = $smcFunc['db_fetch_assoc']($request))
183 186
 		{
184
-			if ($row['min_posts'] == -1)
185
-				$context['membergroups'][] = array(
187
+			if ($row['min_posts'] == -1) {
188
+							$context['membergroups'][] = array(
186 189
 					'id' => $row['id_group'],
187 190
 					'name' => $row['group_name'],
188 191
 					'can_be_additional' => true
189 192
 				);
190
-			else
191
-				$context['postgroups'][] = array(
193
+			} else {
194
+							$context['postgroups'][] = array(
192 195
 					'id' => $row['id_group'],
193 196
 					'name' => $row['group_name']
194 197
 				);
198
+			}
195 199
 		}
196 200
 		$smcFunc['db_free_result']($request);
197 201
 
@@ -263,14 +267,15 @@  discard block
 block discarded – undo
263 267
 		call_integration_hook('integrate_view_members_params', array(&$params));
264 268
 
265 269
 		$search_params = array();
266
-		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types']))
267
-			$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
268
-		elseif (!empty($_POST))
270
+		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) {
271
+					$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
272
+		} elseif (!empty($_POST))
269 273
 		{
270 274
 			$search_params['types'] = $_POST['types'];
271
-			foreach ($params as $param_name => $param_info)
272
-				if (isset($_POST[$param_name]))
275
+			foreach ($params as $param_name => $param_info) {
276
+							if (isset($_POST[$param_name]))
273 277
 					$search_params[$param_name] = $_POST[$param_name];
278
+			}
274 279
 		}
275 280
 
276 281
 		$search_url_params = isset($search_params) ? base64_encode($smcFunc['json_encode']($search_params)) : null;
@@ -283,34 +288,38 @@  discard block
 block discarded – undo
283 288
 		foreach ($params as $param_name => $param_info)
284 289
 		{
285 290
 			// Not filled in?
286
-			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '')
287
-				continue;
291
+			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') {
292
+							continue;
293
+			}
288 294
 
289 295
 			// Make sure numeric values are really numeric.
290
-			if (in_array($param_info['type'], array('int', 'age')))
291
-				$search_params[$param_name] = (int) $search_params[$param_name];
296
+			if (in_array($param_info['type'], array('int', 'age'))) {
297
+							$search_params[$param_name] = (int) $search_params[$param_name];
298
+			}
292 299
 			// Date values have to match the specified format.
293 300
 			elseif ($param_info['type'] == 'date')
294 301
 			{
295 302
 				// Check if this date format is valid.
296
-				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
297
-					continue;
303
+				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) {
304
+									continue;
305
+				}
298 306
 
299 307
 				$search_params[$param_name] = strtotime($search_params[$param_name]);
300
-			}
301
-			elseif ($param_info['type'] == 'inet')
308
+			} elseif ($param_info['type'] == 'inet')
302 309
 			{
303 310
 				$search_params[$param_name] = ip2range($search_params[$param_name]);
304
-				if (empty($search_params[$param_name]))
305
-					continue;
311
+				if (empty($search_params[$param_name])) {
312
+									continue;
313
+				}
306 314
 			}
307 315
 
308 316
 			// Those values that are in some kind of range (<, <=, =, >=, >).
309 317
 			if (!empty($param_info['range']))
310 318
 			{
311 319
 				// Default to '=', just in case...
312
-				if (empty($range_trans[$search_params['types'][$param_name]]))
313
-					$search_params['types'][$param_name] = '=';
320
+				if (empty($range_trans[$search_params['types'][$param_name]])) {
321
+									$search_params['types'][$param_name] = '=';
322
+				}
314 323
 
315 324
 				// Handle special case 'age'.
316 325
 				if ($param_info['type'] == 'age')
@@ -338,16 +347,17 @@  discard block
 block discarded – undo
338 347
 				elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=')
339 348
 				{
340 349
 					$query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400);
350
+				} else {
351
+									$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
341 352
 				}
342
-				else
343
-					$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
344 353
 			}
345 354
 			// Checkboxes.
346 355
 			elseif ($param_info['type'] == 'checkbox')
347 356
 			{
348 357
 				// Each checkbox or no checkbox at all is checked -> ignore.
349
-				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values']))
350
-					continue;
358
+				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) {
359
+									continue;
360
+				}
351 361
 
352 362
 				$query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})';
353 363
 				$where_params[$param_name . '_check'] = $search_params[$param_name];
@@ -359,24 +369,23 @@  discard block
 block discarded – undo
359 369
 				{
360 370
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' = {inet:' . $param_name . '})';
361 371
 					$where_params[$param_name] = $search_params[$param_name][0];
362
-				}
363
-				elseif (count($search_params[$param_name]) === 2)
372
+				} elseif (count($search_params[$param_name]) === 2)
364 373
 				{
365 374
 					$query_parts[] = '(' . $param_info['db_fields'][0] . ' <= {inet:' . $param_name . '_high} and ' . $param_info['db_fields'][0] . ' >= {inet:' . $param_name . '_low})';
366 375
 					$where_params[$param_name.'_low'] = $search_params[$param_name]['low'];
367 376
 					$where_params[$param_name.'_high'] = $search_params[$param_name]['high'];
368 377
 				}
369 378
 				
370
-			}
371
-			elseif ($param_info['type'] != 'groups')
379
+			} elseif ($param_info['type'] != 'groups')
372 380
 			{
373 381
 				// Replace the wildcard characters ('*' and '?') into MySQL ones.
374 382
 				$parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')));
375 383
 
376
-				if ($smcFunc['db_case_sensitive'])
377
-					$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
378
-				else
379
-					$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
384
+				if ($smcFunc['db_case_sensitive']) {
385
+									$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
386
+				} else {
387
+									$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
388
+				}
380 389
 				$where_params[$param_name . '_normal'] = '%' . $parameter . '%';
381 390
 			}
382 391
 		}
@@ -392,16 +401,18 @@  discard block
 block discarded – undo
392 401
 		}
393 402
 
394 403
 		// Additional membergroups (these are only relevant if not all primary groups where selected!).
395
-		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1])))
396
-			foreach ($search_params['membergroups'][2] as $mg)
404
+		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) {
405
+					foreach ($search_params['membergroups'][2] as $mg)
397 406
 			{
398 407
 				$mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0';
408
+		}
399 409
 				$where_params['add_group_' . $mg] = $mg;
400 410
 			}
401 411
 
402 412
 		// Combine the one or two membergroup parts into one query part linked with an OR.
403
-		if (!empty($mg_query_parts))
404
-			$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
413
+		if (!empty($mg_query_parts)) {
414
+					$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
415
+		}
405 416
 
406 417
 		// Get all selected post count related membergroups.
407 418
 		if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups']))
@@ -413,9 +424,9 @@  discard block
 block discarded – undo
413 424
 		// Construct the where part of the query.
414 425
 		$where = empty($query_parts) ? '1=1' : implode('
415 426
 			AND ', $query_parts);
427
+	} else {
428
+			$search_url_params = null;
416 429
 	}
417
-	else
418
-		$search_url_params = null;
419 430
 
420 431
 	// Construct the additional URL part with the query info in it.
421 432
 	$context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : '';
@@ -538,28 +549,32 @@  discard block
 block discarded – undo
538 549
 					'function' => function($rowData) use ($txt)
539 550
 					{
540 551
 						// Calculate number of days since last online.
541
-						if (empty($rowData['last_login']))
542
-							$difference = $txt['never'];
543
-						else
552
+						if (empty($rowData['last_login'])) {
553
+													$difference = $txt['never'];
554
+						} else
544 555
 						{
545 556
 							$num_days_difference = jeffsdatediff($rowData['last_login']);
546 557
 
547 558
 							// Today.
548
-							if (empty($num_days_difference))
549
-								$difference = $txt['viewmembers_today'];
559
+							if (empty($num_days_difference)) {
560
+															$difference = $txt['viewmembers_today'];
561
+							}
550 562
 
551 563
 							// Yesterday.
552
-							elseif ($num_days_difference == 1)
553
-								$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
564
+							elseif ($num_days_difference == 1) {
565
+															$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
566
+							}
554 567
 
555 568
 							// X days ago.
556
-							else
557
-								$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
569
+							else {
570
+															$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
571
+							}
558 572
 						}
559 573
 
560 574
 						// Show it in italics if they're not activated...
561
-						if ($rowData['is_activated'] % 10 != 1)
562
-							$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
575
+						if ($rowData['is_activated'] % 10 != 1) {
576
+													$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
577
+						}
563 578
 
564 579
 						return $difference;
565 580
 					},
@@ -611,8 +626,9 @@  discard block
 block discarded – undo
611 626
 	);
612 627
 
613 628
 	// Without enough permissions, don't show 'delete members' checkboxes.
614
-	if (!allowedTo('profile_remove_any'))
615
-		unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
629
+	if (!allowedTo('profile_remove_any')) {
630
+			unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
631
+	}
616 632
 
617 633
 	require_once($sourcedir . '/Subs-List.php');
618 634
 	createList($listOptions);
@@ -655,17 +671,18 @@  discard block
 block discarded – undo
655 671
 	);
656 672
 	while ($row = $smcFunc['db_fetch_assoc']($request))
657 673
 	{
658
-		if ($row['min_posts'] == -1)
659
-			$context['membergroups'][] = array(
674
+		if ($row['min_posts'] == -1) {
675
+					$context['membergroups'][] = array(
660 676
 				'id' => $row['id_group'],
661 677
 				'name' => $row['group_name'],
662 678
 				'can_be_additional' => true
663 679
 			);
664
-		else
665
-			$context['postgroups'][] = array(
680
+		} else {
681
+					$context['postgroups'][] = array(
666 682
 				'id' => $row['id_group'],
667 683
 				'name' => $row['group_name']
668 684
 			);
685
+		}
669 686
 	}
670 687
 	$smcFunc['db_free_result']($request);
671 688
 
@@ -692,8 +709,9 @@  discard block
 block discarded – undo
692 709
 	$context['page_title'] = $txt['admin_members'];
693 710
 	$context['sub_template'] = 'admin_browse';
694 711
 	$context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
695
-	if (isset($context['tabs'][$context['browse_type']]))
696
-		$context['tabs'][$context['browse_type']]['is_selected'] = true;
712
+	if (isset($context['tabs'][$context['browse_type']])) {
713
+			$context['tabs'][$context['browse_type']]['is_selected'] = true;
714
+	}
697 715
 
698 716
 	// Allowed filters are those we can have, in theory.
699 717
 	$context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
@@ -704,18 +722,20 @@  discard block
 block discarded – undo
704 722
 	foreach ($context['activation_numbers'] as $type => $amount)
705 723
 	{
706 724
 		// We have some of these...
707
-		if (in_array($type, $context['allowed_filters']) && $amount > 0)
708
-			$context['available_filters'][] = array(
725
+		if (in_array($type, $context['allowed_filters']) && $amount > 0) {
726
+					$context['available_filters'][] = array(
709 727
 				'type' => $type,
710 728
 				'amount' => $amount,
711 729
 				'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
712 730
 				'selected' => $type == $context['current_filter']
713 731
 			);
732
+		}
714 733
 	}
715 734
 
716 735
 	// If the filter was not sent, set it to whatever has people in it!
717
-	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
718
-		$context['current_filter'] = $context['available_filters'][0]['type'];
736
+	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) {
737
+			$context['current_filter'] = $context['available_filters'][0]['type'];
738
+	}
719 739
 
720 740
 	// This little variable is used to determine if we should flag where we are looking.
721 741
 	$context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
@@ -730,44 +750,47 @@  discard block
 block discarded – undo
730 750
 	);
731 751
 
732 752
 	// Are we showing duplicate information?
733
-	if (isset($_GET['showdupes']))
734
-		$_SESSION['showdupes'] = (int) $_GET['showdupes'];
753
+	if (isset($_GET['showdupes'])) {
754
+			$_SESSION['showdupes'] = (int) $_GET['showdupes'];
755
+	}
735 756
 	$context['show_duplicates'] = !empty($_SESSION['showdupes']);
736 757
 
737 758
 	// Determine which actions we should allow on this page.
738 759
 	if ($context['browse_type'] == 'approve')
739 760
 	{
740 761
 		// If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
741
-		if ($context['current_filter'] == 4)
742
-			$context['allowed_actions'] = array(
762
+		if ($context['current_filter'] == 4) {
763
+					$context['allowed_actions'] = array(
743 764
 				'reject' => $txt['admin_browse_w_approve_deletion'],
744 765
 				'ok' => $txt['admin_browse_w_reject'],
745 766
 			);
746
-		else
747
-			$context['allowed_actions'] = array(
767
+		} else {
768
+					$context['allowed_actions'] = array(
748 769
 				'ok' => $txt['admin_browse_w_approve'],
749 770
 				'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
750 771
 				'require_activation' => $txt['admin_browse_w_approve_require_activate'],
751 772
 				'reject' => $txt['admin_browse_w_reject'],
752 773
 				'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
753 774
 			);
754
-	}
755
-	elseif ($context['browse_type'] == 'activate')
756
-		$context['allowed_actions'] = array(
775
+		}
776
+	} elseif ($context['browse_type'] == 'activate') {
777
+			$context['allowed_actions'] = array(
757 778
 			'ok' => $txt['admin_browse_w_activate'],
758 779
 			'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
759 780
 			'delete' => $txt['admin_browse_w_delete'],
760 781
 			'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
761 782
 			'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
762 783
 		);
784
+	}
763 785
 
764 786
 	// Create an option list for actions allowed to be done with selected members.
765 787
 	$allowed_actions = '
766 788
 			<option selected value="">' . $txt['admin_browse_with_selected'] . ':</option>
767 789
 			<option value="" disabled>-----------------------------</option>';
768
-	foreach ($context['allowed_actions'] as $key => $desc)
769
-		$allowed_actions .= '
790
+	foreach ($context['allowed_actions'] as $key => $desc) {
791
+			$allowed_actions .= '
770 792
 			<option value="' . $key . '">' . $desc . '</option>';
793
+	}
771 794
 
772 795
 	// Setup the Javascript function for selecting an action for the list.
773 796
 	$javascript = '
@@ -779,15 +802,16 @@  discard block
 block discarded – undo
779 802
 			var message = "";';
780 803
 
781 804
 	// We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
782
-	if ($context['current_filter'] == 4)
783
-		$javascript .= '
805
+	if ($context['current_filter'] == 4) {
806
+			$javascript .= '
784 807
 			if (document.forms.postForm.todo.value.indexOf("reject") != -1)
785 808
 				message = "' . $txt['admin_browse_w_delete'] . '";
786 809
 			else
787 810
 				message = "' . $txt['admin_browse_w_reject'] . '";';
811
+	}
788 812
 	// Otherwise a nice standard message.
789
-	else
790
-		$javascript .= '
813
+	else {
814
+			$javascript .= '
791 815
 			if (document.forms.postForm.todo.value.indexOf("delete") != -1)
792 816
 				message = "' . $txt['admin_browse_w_delete'] . '";
793 817
 			else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
@@ -796,6 +820,7 @@  discard block
 block discarded – undo
796 820
 				message = "' . $txt['admin_browse_w_remind'] . '";
797 821
 			else
798 822
 				message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
823
+	}
799 824
 	$javascript .= '
800 825
 			if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
801 826
 				document.forms.postForm.submit();
@@ -928,10 +953,11 @@  discard block
 block discarded – undo
928 953
 						$member_links = array();
929 954
 						foreach ($rowData['duplicate_members'] as $member)
930 955
 						{
931
-							if ($member['id'])
932
-								$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
933
-							else
934
-								$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
956
+							if ($member['id']) {
957
+															$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
958
+							} else {
959
+															$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
960
+							}
935 961
 						}
936 962
 						return implode(', ', $member_links);
937 963
 					},
@@ -980,14 +1006,16 @@  discard block
 block discarded – undo
980 1006
 	);
981 1007
 
982 1008
 	// Pick what column to actually include if we're showing duplicates.
983
-	if ($context['show_duplicates'])
984
-		unset($listOptions['columns']['email']);
985
-	else
986
-		unset($listOptions['columns']['duplicates']);
1009
+	if ($context['show_duplicates']) {
1010
+			unset($listOptions['columns']['email']);
1011
+	} else {
1012
+			unset($listOptions['columns']['duplicates']);
1013
+	}
987 1014
 
988 1015
 	// Only show hostname on duplicates as it takes a lot of time.
989
-	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
990
-		unset($listOptions['columns']['hostname']);
1016
+	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) {
1017
+			unset($listOptions['columns']['hostname']);
1018
+	}
991 1019
 
992 1020
 	// Is there any need to show filters?
993 1021
 	if (isset($context['available_filters']) && count($context['available_filters']) > 1)
@@ -995,9 +1023,10 @@  discard block
 block discarded – undo
995 1023
 		$filterOptions = '
996 1024
 			<strong>' . $txt['admin_browse_filter_by'] . ':</strong>
997 1025
 			<select name="filter" onchange="this.form.submit();">';
998
-		foreach ($context['available_filters'] as $filter)
999
-			$filterOptions .= '
1026
+		foreach ($context['available_filters'] as $filter) {
1027
+					$filterOptions .= '
1000 1028
 				<option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
1029
+		}
1001 1030
 		$filterOptions .= '
1002 1031
 			</select>
1003 1032
 			<noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button"></noscript>';
@@ -1009,12 +1038,13 @@  discard block
 block discarded – undo
1009 1038
 	}
1010 1039
 
1011 1040
 	// What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
1012
-	if (!empty($context['show_filter']) && !empty($context['available_filters']))
1013
-		$listOptions['additional_rows'][] = array(
1041
+	if (!empty($context['show_filter']) && !empty($context['available_filters'])) {
1042
+			$listOptions['additional_rows'][] = array(
1014 1043
 			'position' => 'above_column_headers',
1015 1044
 			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'],
1016 1045
 			'class' => 'smalltext floatright',
1017 1046
 		);
1047
+	}
1018 1048
 
1019 1049
 	// Now that we have all the options, create the list.
1020 1050
 	require_once($sourcedir . '/Subs-List.php');
@@ -1044,12 +1074,14 @@  discard block
 block discarded – undo
1044 1074
 	$current_filter = (int) $_REQUEST['orig_filter'];
1045 1075
 
1046 1076
 	// If we are applying a filter do just that - then redirect.
1047
-	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
1048
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1077
+	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) {
1078
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1079
+	}
1049 1080
 
1050 1081
 	// Nothing to do?
1051
-	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
1052
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1082
+	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) {
1083
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1084
+	}
1053 1085
 
1054 1086
 	// Are we dealing with members who have been waiting for > set amount of time?
1055 1087
 	if (isset($_POST['time_passed']))
@@ -1062,8 +1094,9 @@  discard block
 block discarded – undo
1062 1094
 	else
1063 1095
 	{
1064 1096
 		$members = array();
1065
-		foreach ($_POST['todoAction'] as $id)
1066
-			$members[] = (int) $id;
1097
+		foreach ($_POST['todoAction'] as $id) {
1098
+					$members[] = (int) $id;
1099
+		}
1067 1100
 		$condition = '
1068 1101
 			AND id_member IN ({array_int:members})';
1069 1102
 	}
@@ -1084,8 +1117,9 @@  discard block
 block discarded – undo
1084 1117
 	$member_count = $smcFunc['db_num_rows']($request);
1085 1118
 
1086 1119
 	// If no results then just return!
1087
-	if ($member_count == 0)
1088
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1120
+	if ($member_count == 0) {
1121
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1122
+	}
1089 1123
 
1090 1124
 	$member_info = array();
1091 1125
 	$members = array();
@@ -1124,8 +1158,9 @@  discard block
 block discarded – undo
1124 1158
 		// Do we have to let the integration code know about the activations?
1125 1159
 		if (!empty($modSettings['integrate_activate']))
1126 1160
 		{
1127
-			foreach ($member_info as $member)
1128
-				call_integration_hook('integrate_activate', array($member['username']));
1161
+			foreach ($member_info as $member) {
1162
+							call_integration_hook('integrate_activate', array($member['username']));
1163
+			}
1129 1164
 		}
1130 1165
 
1131 1166
 		// Check for email.
@@ -1255,20 +1290,23 @@  discard block
 block discarded – undo
1255 1290
 		$log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member';
1256 1291
 
1257 1292
 		require_once($sourcedir . '/Logging.php');
1258
-		foreach ($member_info as $member)
1259
-			logAction($log_action, array('member' => $member['id']), 'admin');
1293
+		foreach ($member_info as $member) {
1294
+					logAction($log_action, array('member' => $member['id']), 'admin');
1295
+		}
1260 1296
 	}
1261 1297
 
1262 1298
 	// Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
1263
-	if (in_array($current_filter, array(3, 4, 5)))
1264
-		updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1299
+	if (in_array($current_filter, array(3, 4, 5))) {
1300
+			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1301
+	}
1265 1302
 
1266 1303
 	// Update the member's stats. (but, we know the member didn't change their name.)
1267 1304
 	updateStats('member', false);
1268 1305
 
1269 1306
 	// If they haven't been deleted, update the post group statistics on them...
1270
-	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
1271
-		updateStats('postgroups', $members);
1307
+	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) {
1308
+			updateStats('postgroups', $members);
1309
+	}
1272 1310
 
1273 1311
 	redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1274 1312
 }
@@ -1293,10 +1331,11 @@  discard block
 block discarded – undo
1293 1331
 	$dis = time() - $old;
1294 1332
 
1295 1333
 	// Before midnight?
1296
-	if ($dis < $sinceMidnight)
1297
-		return 0;
1298
-	else
1299
-		$dis -= $sinceMidnight;
1334
+	if ($dis < $sinceMidnight) {
1335
+			return 0;
1336
+	} else {
1337
+			$dis -= $sinceMidnight;
1338
+	}
1300 1339
 
1301 1340
 	// Divide out the seconds in a day to get the number of days.
1302 1341
 	return ceil($dis / (24 * 60 * 60));
@@ -1323,16 +1362,18 @@  discard block
 block discarded – undo
1323 1362
 	$context['activation_numbers'] = array();
1324 1363
 	$context['awaiting_activation'] = 0;
1325 1364
 	$context['awaiting_approval'] = 0;
1326
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1327
-		$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
1365
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1366
+			$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
1367
+	}
1328 1368
 	$smcFunc['db_free_result']($request);
1329 1369
 
1330 1370
 	foreach ($context['activation_numbers'] as $activation_type => $total_members)
1331 1371
 	{
1332
-		if (in_array($activation_type, array(0, 2)))
1333
-			$context['awaiting_activation'] += $total_members;
1334
-		elseif (in_array($activation_type, array(3, 4, 5)))
1335
-			$context['awaiting_approval'] += $total_members;
1372
+		if (in_array($activation_type, array(0, 2))) {
1373
+					$context['awaiting_activation'] += $total_members;
1374
+		} elseif (in_array($activation_type, array(3, 4, 5))) {
1375
+					$context['awaiting_approval'] += $total_members;
1376
+		}
1336 1377
 	}
1337 1378
 
1338 1379
 }
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +792 added lines, -597 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We explicitly do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -410,9 +427,9 @@  discard block
 block discarded – undo
410 427
 				break;
411 428
 			}
412 429
 		}
430
+	} else {
431
+			$id_member = 0;
413 432
 	}
414
-	else
415
-		$id_member = 0;
416 433
 
417 434
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
418 435
 	{
@@ -420,8 +437,9 @@  discard block
 block discarded – undo
420 437
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
421 438
 
422 439
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
423
-		if (empty($cookie_data))
424
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
440
+		if (empty($cookie_data)) {
441
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
442
+		}
425 443
 
426 444
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
427 445
 
@@ -429,16 +447,17 @@  discard block
 block discarded – undo
429 447
 
430 448
 		// Make sure the cookie is set to the correct domain and path
431 449
 		require_once($sourcedir . '/Subs-Auth.php');
432
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
433
-			setLoginCookie((int) $login_span - time(), $id_member);
434
-	}
435
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
450
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
451
+					setLoginCookie((int) $login_span - time(), $id_member);
452
+		}
453
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
436 454
 	{
437 455
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
438 456
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
439 457
 
440
-		if (empty($cookie_data))
441
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
458
+		if (empty($cookie_data)) {
459
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
460
+		}
442 461
 
443 462
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
444 463
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -463,30 +482,34 @@  discard block
 block discarded – undo
463 482
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
464 483
 			$smcFunc['db_free_result']($request);
465 484
 
466
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
467
-				$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
485
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
486
+							$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
487
+			}
468 488
 
469
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
470
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
489
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
490
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
491
+			}
471 492
 		}
472 493
 
473 494
 		// Did we find 'im?  If not, junk it.
474 495
 		if (!empty($user_settings))
475 496
 		{
476 497
 			// As much as the password should be right, we can assume the integration set things up.
477
-			if (!empty($already_verified) && $already_verified === true)
478
-				$check = true;
498
+			if (!empty($already_verified) && $already_verified === true) {
499
+							$check = true;
500
+			}
479 501
 			// SHA-512 hash should be 128 characters long.
480
-			elseif (strlen($password) == 128)
481
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
482
-			else
483
-				$check = false;
502
+			elseif (strlen($password) == 128) {
503
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
504
+			} else {
505
+							$check = false;
506
+			}
484 507
 
485 508
 			// Wrong password or not activated - either way, you're going nowhere.
486 509
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
510
+		} else {
511
+					$id_member = 0;
487 512
 		}
488
-		else
489
-			$id_member = 0;
490 513
 
491 514
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
492 515
 		if (!$id_member)
@@ -515,8 +538,9 @@  discard block
 block discarded – undo
515 538
 
516 539
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
517 540
 
518
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
519
-						$tfasecret = null;
541
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
542
+											$tfasecret = null;
543
+					}
520 544
 				}
521 545
 
522 546
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -538,10 +562,12 @@  discard block
 block discarded – undo
538 562
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
539 563
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
540 564
 		{
541
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
565
+			if ($modSettings['tfa_mode'] == 2) {
566
+				//only do this if we are just forcing SOME membergroups
542 567
 			{
543 568
 				//Build an array of ALL user membergroups.
544 569
 				$full_groups = array($user_settings['id_group']);
570
+			}
545 571
 				if (!empty($user_settings['additional_groups']))
546 572
 				{
547 573
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -561,15 +587,17 @@  discard block
 block discarded – undo
561 587
 				);
562 588
 				$row = $smcFunc['db_fetch_assoc']($request);
563 589
 				$smcFunc['db_free_result']($request);
590
+			} else {
591
+							$row['total'] = 1;
564 592
 			}
565
-			else
566
-				$row['total'] = 1; //simplifies logics in the next "if"
593
+			//simplifies logics in the next "if"
567 594
 
568 595
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
569 596
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
570 597
 
571
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
572
-				redirectexit('action=profile;area=tfasetup;forced');
598
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
599
+							redirectexit('action=profile;area=tfasetup;forced');
600
+			}
573 601
 		}
574 602
 	}
575 603
 
@@ -606,29 +634,32 @@  discard block
 block discarded – undo
606 634
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
607 635
 				$user_settings['last_login'] = time();
608 636
 
609
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
610
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
637
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
638
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
639
+				}
611 640
 
612
-				if (!empty($modSettings['cache_enable']))
613
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
641
+				if (!empty($modSettings['cache_enable'])) {
642
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
643
+				}
614 644
 			}
645
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
646
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
615 647
 		}
616
-		elseif (empty($_SESSION['id_msg_last_visit']))
617
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
618 648
 
619 649
 		$username = $user_settings['member_name'];
620 650
 
621
-		if (empty($user_settings['additional_groups']))
622
-			$user_info = array(
651
+		if (empty($user_settings['additional_groups'])) {
652
+					$user_info = array(
623 653
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
624 654
 			);
625
-		else
626
-			$user_info = array(
655
+		} else {
656
+					$user_info = array(
627 657
 				'groups' => array_merge(
628 658
 					array($user_settings['id_group'], $user_settings['id_post_group']),
629 659
 					explode(',', $user_settings['additional_groups'])
630 660
 				)
631 661
 			);
662
+		}
632 663
 
633 664
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
634 665
 		$user_info['groups'] = array_map('intval', $user_info['groups']);
@@ -645,8 +676,7 @@  discard block
 block discarded – undo
645 676
 			$time_system = new DateTime('now', $tz_system);
646 677
 			$time_user = new DateTime('now', $tz_user);
647 678
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
648
-		}
649
-		else
679
+		} else
650 680
 		{
651 681
 			// !!! Compatibility.
652 682
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -660,8 +690,9 @@  discard block
 block discarded – undo
660 690
 		$user_info = array('groups' => array(-1));
661 691
 		$user_settings = array();
662 692
 
663
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
664
-			$_COOKIE[$cookiename] = '';
693
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
694
+					$_COOKIE[$cookiename] = '';
695
+		}
665 696
 
666 697
 		// Expire the 2FA cookie
667 698
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -678,19 +709,20 @@  discard block
 block discarded – undo
678 709
 		}
679 710
 
680 711
 		// Create a login token if it doesn't exist yet.
681
-		if (!isset($_SESSION['token']['post-login']))
682
-			createToken('login');
683
-		else
684
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
712
+		if (!isset($_SESSION['token']['post-login'])) {
713
+					createToken('login');
714
+		} else {
715
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
716
+		}
685 717
 
686 718
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
687 719
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
688 720
 		{
689 721
 			require_once($sourcedir . '/ManageSearchEngines.php');
690 722
 			$user_info['possibly_robot'] = SpiderCheck();
723
+		} elseif (!empty($modSettings['spider_mode'])) {
724
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
691 725
 		}
692
-		elseif (!empty($modSettings['spider_mode']))
693
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
694 726
 		// If we haven't turned on proper spider hunts then have a guess!
695 727
 		else
696 728
 		{
@@ -747,8 +779,9 @@  discard block
 block discarded – undo
747 779
 	$user_info['groups'] = array_unique($user_info['groups']);
748 780
 
749 781
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
750
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
751
-		unset($user_info['ignoreboards'][$tmp]);
782
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
783
+			unset($user_info['ignoreboards'][$tmp]);
784
+	}
752 785
 
753 786
 	// Allow the user to change their language.
754 787
 	if (!empty($modSettings['userLanguage']))
@@ -761,13 +794,14 @@  discard block
 block discarded – undo
761 794
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
762 795
 
763 796
 			// Make it permanent for members.
764
-			if (!empty($user_info['id']))
765
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
766
-			else
767
-				$_SESSION['language'] = $user_info['language'];
797
+			if (!empty($user_info['id'])) {
798
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
799
+			} else {
800
+							$_SESSION['language'] = $user_info['language'];
801
+			}
802
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
803
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
768 804
 		}
769
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
770
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
771 805
 	}
772 806
 
773 807
 	$temp = build_query_board($user_info['id']);
@@ -830,9 +864,9 @@  discard block
 block discarded – undo
830 864
 		}
831 865
 
832 866
 		// Remember redirection is the key to avoiding fallout from your bosses.
833
-		if (!empty($topic))
834
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
835
-		else
867
+		if (!empty($topic)) {
868
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
869
+		} else
836 870
 		{
837 871
 			loadPermissions();
838 872
 			loadTheme();
@@ -850,10 +884,11 @@  discard block
 block discarded – undo
850 884
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
851 885
 	{
852 886
 		// @todo SLOW?
853
-		if (!empty($topic))
854
-			$temp = cache_get_data('topic_board-' . $topic, 120);
855
-		else
856
-			$temp = cache_get_data('board-' . $board, 120);
887
+		if (!empty($topic)) {
888
+					$temp = cache_get_data('topic_board-' . $topic, 120);
889
+		} else {
890
+					$temp = cache_get_data('board-' . $board, 120);
891
+		}
857 892
 
858 893
 		if (!empty($temp))
859 894
 		{
@@ -891,8 +926,9 @@  discard block
 block discarded – undo
891 926
 			$row = $smcFunc['db_fetch_assoc']($request);
892 927
 
893 928
 			// Set the current board.
894
-			if (!empty($row['id_board']))
895
-				$board = $row['id_board'];
929
+			if (!empty($row['id_board'])) {
930
+							$board = $row['id_board'];
931
+			}
896 932
 
897 933
 			// Basic operating information. (globals... :/)
898 934
 			$board_info = array(
@@ -928,21 +964,23 @@  discard block
 block discarded – undo
928 964
 
929 965
 			do
930 966
 			{
931
-				if (!empty($row['id_moderator']))
932
-					$board_info['moderators'][$row['id_moderator']] = array(
967
+				if (!empty($row['id_moderator'])) {
968
+									$board_info['moderators'][$row['id_moderator']] = array(
933 969
 						'id' => $row['id_moderator'],
934 970
 						'name' => $row['real_name'],
935 971
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
936 972
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
937 973
 					);
974
+				}
938 975
 
939
-				if (!empty($row['id_moderator_group']))
940
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
976
+				if (!empty($row['id_moderator_group'])) {
977
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
941 978
 						'id' => $row['id_moderator_group'],
942 979
 						'name' => $row['group_name'],
943 980
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
944 981
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
945 982
 					);
983
+				}
946 984
 			}
947 985
 			while ($row = $smcFunc['db_fetch_assoc']($request));
948 986
 
@@ -974,12 +1012,12 @@  discard block
 block discarded – undo
974 1012
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
975 1013
 			{
976 1014
 				// @todo SLOW?
977
-				if (!empty($topic))
978
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1015
+				if (!empty($topic)) {
1016
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1017
+				}
979 1018
 				cache_put_data('board-' . $board, $board_info, 120);
980 1019
 			}
981
-		}
982
-		else
1020
+		} else
983 1021
 		{
984 1022
 			// Otherwise the topic is invalid, there are no moderators, etc.
985 1023
 			$board_info = array(
@@ -993,8 +1031,9 @@  discard block
 block discarded – undo
993 1031
 		$smcFunc['db_free_result']($request);
994 1032
 	}
995 1033
 
996
-	if (!empty($topic))
997
-		$_GET['board'] = (int) $board;
1034
+	if (!empty($topic)) {
1035
+			$_GET['board'] = (int) $board;
1036
+	}
998 1037
 
999 1038
 	if (!empty($board))
1000 1039
 	{
@@ -1004,10 +1043,12 @@  discard block
 block discarded – undo
1004 1043
 		// Now check if the user is a moderator.
1005 1044
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
1006 1045
 
1007
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
1008
-			$board_info['error'] = 'access';
1009
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
1010
-			$board_info['error'] = 'access';
1046
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1047
+					$board_info['error'] = 'access';
1048
+		}
1049
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1050
+					$board_info['error'] = 'access';
1051
+		}
1011 1052
 
1012 1053
 		// Build up the linktree.
1013 1054
 		$context['linktree'] = array_merge(
@@ -1030,8 +1071,9 @@  discard block
 block discarded – undo
1030 1071
 	$context['current_board'] = $board;
1031 1072
 
1032 1073
 	// No posting in redirection boards!
1033
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1034
-		$board_info['error'] == 'post_in_redirect';
1074
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1075
+			$board_info['error'] == 'post_in_redirect';
1076
+	}
1035 1077
 
1036 1078
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1037 1079
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1057,24 +1099,23 @@  discard block
 block discarded – undo
1057 1099
 			ob_end_clean();
1058 1100
 			send_http_status(403);
1059 1101
 			die;
1060
-		}
1061
-		elseif ($board_info['error'] == 'post_in_redirect')
1102
+		} elseif ($board_info['error'] == 'post_in_redirect')
1062 1103
 		{
1063 1104
 			// Slightly different error message here...
1064 1105
 			fatal_lang_error('cannot_post_redirect', false);
1065
-		}
1066
-		elseif ($user_info['is_guest'])
1106
+		} elseif ($user_info['is_guest'])
1067 1107
 		{
1068 1108
 			loadLanguage('Errors');
1069 1109
 			is_not_guest($txt['topic_gone']);
1110
+		} else {
1111
+					fatal_lang_error('topic_gone', false);
1070 1112
 		}
1071
-		else
1072
-			fatal_lang_error('topic_gone', false);
1073 1113
 	}
1074 1114
 
1075
-	if ($user_info['is_mod'])
1076
-		$user_info['groups'][] = 3;
1077
-}
1115
+	if ($user_info['is_mod']) {
1116
+			$user_info['groups'][] = 3;
1117
+	}
1118
+	}
1078 1119
 
1079 1120
 /**
1080 1121
  * Load this user's permissions.
@@ -1095,8 +1136,9 @@  discard block
 block discarded – undo
1095 1136
 		asort($cache_groups);
1096 1137
 		$cache_groups = implode(',', $cache_groups);
1097 1138
 		// If it's a spider then cache it different.
1098
-		if ($user_info['possibly_robot'])
1099
-			$cache_groups .= '-spider';
1139
+		if ($user_info['possibly_robot']) {
1140
+					$cache_groups .= '-spider';
1141
+		}
1100 1142
 
1101 1143
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1102 1144
 		{
@@ -1104,9 +1146,9 @@  discard block
 block discarded – undo
1104 1146
 			banPermissions();
1105 1147
 
1106 1148
 			return;
1149
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1150
+					list ($user_info['permissions'], $removals) = $temp;
1107 1151
 		}
1108
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1109
-			list ($user_info['permissions'], $removals) = $temp;
1110 1152
 	}
1111 1153
 
1112 1154
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1128,23 +1170,26 @@  discard block
 block discarded – undo
1128 1170
 		$removals = array();
1129 1171
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1130 1172
 		{
1131
-			if (empty($row['add_deny']))
1132
-				$removals[] = $row['permission'];
1133
-			else
1134
-				$user_info['permissions'][] = $row['permission'];
1173
+			if (empty($row['add_deny'])) {
1174
+							$removals[] = $row['permission'];
1175
+			} else {
1176
+							$user_info['permissions'][] = $row['permission'];
1177
+			}
1135 1178
 		}
1136 1179
 		$smcFunc['db_free_result']($request);
1137 1180
 
1138
-		if (isset($cache_groups))
1139
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1181
+		if (isset($cache_groups)) {
1182
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1183
+		}
1140 1184
 	}
1141 1185
 
1142 1186
 	// Get the board permissions.
1143 1187
 	if (!empty($board))
1144 1188
 	{
1145 1189
 		// Make sure the board (if any) has been loaded by loadBoard().
1146
-		if (!isset($board_info['profile']))
1147
-			fatal_lang_error('no_board');
1190
+		if (!isset($board_info['profile'])) {
1191
+					fatal_lang_error('no_board');
1192
+		}
1148 1193
 
1149 1194
 		$request = $smcFunc['db_query']('', '
1150 1195
 			SELECT permission, add_deny
@@ -1160,20 +1205,23 @@  discard block
 block discarded – undo
1160 1205
 		);
1161 1206
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1162 1207
 		{
1163
-			if (empty($row['add_deny']))
1164
-				$removals[] = $row['permission'];
1165
-			else
1166
-				$user_info['permissions'][] = $row['permission'];
1208
+			if (empty($row['add_deny'])) {
1209
+							$removals[] = $row['permission'];
1210
+			} else {
1211
+							$user_info['permissions'][] = $row['permission'];
1212
+			}
1167 1213
 		}
1168 1214
 		$smcFunc['db_free_result']($request);
1169 1215
 	}
1170 1216
 
1171 1217
 	// Remove all the permissions they shouldn't have ;).
1172
-	if (!empty($modSettings['permission_enable_deny']))
1173
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1218
+	if (!empty($modSettings['permission_enable_deny'])) {
1219
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1220
+	}
1174 1221
 
1175
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1176
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1222
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1223
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1224
+	}
1177 1225
 
1178 1226
 	// Banned?  Watch, don't touch..
1179 1227
 	banPermissions();
@@ -1185,17 +1233,18 @@  discard block
 block discarded – undo
1185 1233
 		{
1186 1234
 			require_once($sourcedir . '/Subs-Auth.php');
1187 1235
 			rebuildModCache();
1236
+		} else {
1237
+					$user_info['mod_cache'] = $_SESSION['mc'];
1188 1238
 		}
1189
-		else
1190
-			$user_info['mod_cache'] = $_SESSION['mc'];
1191 1239
 
1192 1240
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1193 1241
 		// For example this drastically simplifies certain changes to the profile area.
1194 1242
 		$user_info['permissions'][] = 'is_not_guest';
1195 1243
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1196 1244
 		$user_info['permissions'][] = 'profile_view_own';
1197
-		if (in_array('profile_view', $user_info['permissions']))
1198
-			$user_info['permissions'][] = 'profile_view_any';
1245
+		if (in_array('profile_view', $user_info['permissions'])) {
1246
+					$user_info['permissions'][] = 'profile_view_any';
1247
+		}
1199 1248
 	}
1200 1249
 }
1201 1250
 
@@ -1213,8 +1262,9 @@  discard block
 block discarded – undo
1213 1262
 	global $image_proxy_enabled, $user_info;
1214 1263
 
1215 1264
 	// Can't just look for no users :P.
1216
-	if (empty($users))
1217
-		return array();
1265
+	if (empty($users)) {
1266
+			return array();
1267
+	}
1218 1268
 
1219 1269
 	// Pass the set value
1220 1270
 	$context['loadMemberContext_set'] = $set;
@@ -1229,8 +1279,9 @@  discard block
 block discarded – undo
1229 1279
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1230 1280
 		{
1231 1281
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1232
-			if ($data == null)
1233
-				continue;
1282
+			if ($data == null) {
1283
+							continue;
1284
+			}
1234 1285
 
1235 1286
 			$loaded_ids[] = $data['id_member'];
1236 1287
 			$user_profile[$data['id_member']] = $data;
@@ -1297,16 +1348,19 @@  discard block
 block discarded – undo
1297 1348
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1298 1349
 
1299 1350
 			// Take care of proxying avatar if required, do this here for maximum reach
1300
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1301
-				$row['avatar'] = get_proxied_url($row['avatar']);
1351
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1352
+							$row['avatar'] = get_proxied_url($row['avatar']);
1353
+			}
1302 1354
 
1303 1355
 			// Keep track of the member's normal member group
1304 1356
 			$row['primary_group'] = !empty($row['member_group']) ? $row['member_group'] : '';
1305 1357
 
1306
-			if (isset($row['member_ip']))
1307
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1308
-			if (isset($row['member_ip2']))
1309
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1358
+			if (isset($row['member_ip'])) {
1359
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1360
+			}
1361
+			if (isset($row['member_ip2'])) {
1362
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1363
+			}
1310 1364
 			$row['id_member'] = (int) $row['id_member'];
1311 1365
 			$new_loaded_ids[] = $row['id_member'];
1312 1366
 			$loaded_ids[] = $row['id_member'];
@@ -1326,8 +1380,9 @@  discard block
 block discarded – undo
1326 1380
 				'loaded_ids' => $new_loaded_ids,
1327 1381
 			)
1328 1382
 		);
1329
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1330
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1383
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1384
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1385
+		}
1331 1386
 		$smcFunc['db_free_result']($request);
1332 1387
 	}
1333 1388
 
@@ -1338,10 +1393,11 @@  discard block
 block discarded – undo
1338 1393
 	{
1339 1394
 		foreach ($loaded_ids as $a_member)
1340 1395
 		{
1341
-			if (!empty($user_profile[$a_member]['additional_groups']))
1342
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1343
-			else
1344
-				$groups = array($user_profile[$a_member]['id_group']);
1396
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1397
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1398
+			} else {
1399
+							$groups = array($user_profile[$a_member]['id_group']);
1400
+			}
1345 1401
 
1346 1402
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1347 1403
 
@@ -1354,8 +1410,9 @@  discard block
 block discarded – undo
1354 1410
 
1355 1411
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1356 1412
 	{
1357
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1358
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1413
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1414
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1415
+		}
1359 1416
 	}
1360 1417
 
1361 1418
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1381,14 +1438,17 @@  discard block
 block discarded – undo
1381 1438
 		foreach ($temp_mods as $id)
1382 1439
 		{
1383 1440
 			// By popular demand, don't show admins or global moderators as moderators.
1384
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1385
-				$user_profile[$id]['member_group'] = $row['member_group'];
1441
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1442
+							$user_profile[$id]['member_group'] = $row['member_group'];
1443
+			}
1386 1444
 
1387 1445
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1388
-			if (!empty($row['icons']))
1389
-				$user_profile[$id]['icons'] = $row['icons'];
1390
-			if (!empty($row['member_group_color']))
1391
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1446
+			if (!empty($row['icons'])) {
1447
+							$user_profile[$id]['icons'] = $row['icons'];
1448
+			}
1449
+			if (!empty($row['member_group_color'])) {
1450
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1451
+			}
1392 1452
 		}
1393 1453
 	}
1394 1454
 
@@ -1410,12 +1470,14 @@  discard block
 block discarded – undo
1410 1470
 	static $loadedLanguages = array();
1411 1471
 
1412 1472
 	// If this person's data is already loaded, skip it.
1413
-	if (isset($dataLoaded[$user]))
1414
-		return true;
1473
+	if (isset($dataLoaded[$user])) {
1474
+			return true;
1475
+	}
1415 1476
 
1416 1477
 	// We can't load guests or members not loaded by loadMemberData()!
1417
-	if ($user == 0)
1418
-		return false;
1478
+	if ($user == 0) {
1479
+			return false;
1480
+	}
1419 1481
 	if (!isset($user_profile[$user]))
1420 1482
 	{
1421 1483
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1441,12 +1503,16 @@  discard block
 block discarded – undo
1441 1503
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1442 1504
 
1443 1505
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1444
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1506
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1507
+		//icon is set and exists
1445 1508
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1446
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1509
+	} elseif (isset($profile['icons'][1])) {
1510
+		//icon is set and doesn't exist, fallback to default
1447 1511
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1448
-	else //not set, bye bye
1512
+	} else {
1513
+		//not set, bye bye
1449 1514
 		$group_icon_url = '';
1515
+	}
1450 1516
 
1451 1517
 	// These minimal values are always loaded
1452 1518
 	$memberContext[$user] = array(
@@ -1465,8 +1531,9 @@  discard block
 block discarded – undo
1465 1531
 	if ($context['loadMemberContext_set'] != 'minimal')
1466 1532
 	{
1467 1533
 		// Go the extra mile and load the user's native language name.
1468
-		if (empty($loadedLanguages))
1469
-			$loadedLanguages = getLanguages();
1534
+		if (empty($loadedLanguages)) {
1535
+					$loadedLanguages = getLanguages();
1536
+		}
1470 1537
 
1471 1538
 		$memberContext[$user] += array(
1472 1539
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1521,31 +1588,33 @@  discard block
 block discarded – undo
1521 1588
 	{
1522 1589
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1523 1590
 		{
1524
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1525
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1526
-			else
1527
-				$image = get_gravatar_url($profile['email_address']);
1528
-		}
1529
-		else
1591
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1592
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1593
+			} else {
1594
+							$image = get_gravatar_url($profile['email_address']);
1595
+			}
1596
+		} else
1530 1597
 		{
1531 1598
 			// So it's stored in the member table?
1532 1599
 			if (!empty($profile['avatar']))
1533 1600
 			{
1534 1601
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1602
+			} elseif (!empty($profile['filename'])) {
1603
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1535 1604
 			}
1536
-			elseif (!empty($profile['filename']))
1537
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1538 1605
 			// Right... no avatar...use the default one
1539
-			else
1540
-				$image = $modSettings['avatar_url'] . '/default.png';
1606
+			else {
1607
+							$image = $modSettings['avatar_url'] . '/default.png';
1608
+			}
1541 1609
 		}
1542
-		if (!empty($image))
1543
-			$memberContext[$user]['avatar'] = array(
1610
+		if (!empty($image)) {
1611
+					$memberContext[$user]['avatar'] = array(
1544 1612
 				'name' => $profile['avatar'],
1545 1613
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1546 1614
 				'href' => $image,
1547 1615
 				'url' => $image,
1548 1616
 			);
1617
+		}
1549 1618
 	}
1550 1619
 
1551 1620
 	// Are we also loading the members custom fields into context?
@@ -1553,13 +1622,15 @@  discard block
 block discarded – undo
1553 1622
 	{
1554 1623
 		$memberContext[$user]['custom_fields'] = array();
1555 1624
 
1556
-		if (!isset($context['display_fields']))
1557
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1625
+		if (!isset($context['display_fields'])) {
1626
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1627
+		}
1558 1628
 
1559 1629
 		foreach ($context['display_fields'] as $custom)
1560 1630
 		{
1561
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1562
-				continue;
1631
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1632
+							continue;
1633
+			}
1563 1634
 
1564 1635
 			$value = $profile['options'][$custom['col_name']];
1565 1636
 
@@ -1567,31 +1638,36 @@  discard block
 block discarded – undo
1567 1638
 			$currentKey = 0;
1568 1639
 
1569 1640
 			// Create a key => value array for multiple options fields
1570
-			if (!empty($custom['options']))
1571
-				foreach ($custom['options'] as $k => $v)
1641
+			if (!empty($custom['options'])) {
1642
+							foreach ($custom['options'] as $k => $v)
1572 1643
 				{
1573 1644
 					$fieldOptions[] = $v;
1574
-					if (empty($currentKey))
1575
-						$currentKey = $v == $value ? $k : 0;
1645
+			}
1646
+					if (empty($currentKey)) {
1647
+											$currentKey = $v == $value ? $k : 0;
1648
+					}
1576 1649
 				}
1577 1650
 
1578 1651
 			// BBC?
1579
-			if ($custom['bbc'])
1580
-				$value = parse_bbc($value);
1652
+			if ($custom['bbc']) {
1653
+							$value = parse_bbc($value);
1654
+			}
1581 1655
 
1582 1656
 			// ... or checkbox?
1583
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1584
-				$value = $value ? $txt['yes'] : $txt['no'];
1657
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1658
+							$value = $value ? $txt['yes'] : $txt['no'];
1659
+			}
1585 1660
 
1586 1661
 			// Enclosing the user input within some other text?
1587
-			if (!empty($custom['enclose']))
1588
-				$value = strtr($custom['enclose'], array(
1662
+			if (!empty($custom['enclose'])) {
1663
+							$value = strtr($custom['enclose'], array(
1589 1664
 					'{SCRIPTURL}' => $scripturl,
1590 1665
 					'{IMAGES_URL}' => $settings['images_url'],
1591 1666
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1592 1667
 					'{INPUT}' => $value,
1593 1668
 					'{KEY}' => $currentKey,
1594 1669
 				));
1670
+			}
1595 1671
 
1596 1672
 			$memberContext[$user]['custom_fields'][] = array(
1597 1673
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1618,8 +1694,9 @@  discard block
 block discarded – undo
1618 1694
 	global $smcFunc, $txt, $scripturl, $settings;
1619 1695
 
1620 1696
 	// Do not waste my time...
1621
-	if (empty($users) || empty($params))
1622
-		return false;
1697
+	if (empty($users) || empty($params)) {
1698
+			return false;
1699
+	}
1623 1700
 
1624 1701
 	// Make sure it's an array.
1625 1702
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1646,41 +1723,48 @@  discard block
 block discarded – undo
1646 1723
 		$currentKey = 0;
1647 1724
 
1648 1725
 		// Create a key => value array for multiple options fields
1649
-		if (!empty($row['field_options']))
1650
-			foreach (explode(',', $row['field_options']) as $k => $v)
1726
+		if (!empty($row['field_options'])) {
1727
+					foreach (explode(',', $row['field_options']) as $k => $v)
1651 1728
 			{
1652 1729
 				$fieldOptions[] = $v;
1653
-				if (empty($currentKey))
1654
-					$currentKey = $v == $row['value'] ? $k : 0;
1730
+		}
1731
+				if (empty($currentKey)) {
1732
+									$currentKey = $v == $row['value'] ? $k : 0;
1733
+				}
1655 1734
 			}
1656 1735
 
1657 1736
 		// BBC?
1658
-		if (!empty($row['bbc']))
1659
-			$row['value'] = parse_bbc($row['value']);
1737
+		if (!empty($row['bbc'])) {
1738
+					$row['value'] = parse_bbc($row['value']);
1739
+		}
1660 1740
 
1661 1741
 		// ... or checkbox?
1662
-		elseif (isset($row['type']) && $row['type'] == 'check')
1663
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1742
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1743
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1744
+		}
1664 1745
 
1665 1746
 		// Enclosing the user input within some other text?
1666
-		if (!empty($row['enclose']))
1667
-			$row['value'] = strtr($row['enclose'], array(
1747
+		if (!empty($row['enclose'])) {
1748
+					$row['value'] = strtr($row['enclose'], array(
1668 1749
 				'{SCRIPTURL}' => $scripturl,
1669 1750
 				'{IMAGES_URL}' => $settings['images_url'],
1670 1751
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1671 1752
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1672 1753
 				'{KEY}' => $currentKey,
1673 1754
 			));
1755
+		}
1674 1756
 
1675 1757
 		// Send a simple array if there is just 1 param
1676
-		if (count($params) == 1)
1677
-			$return[$row['id_member']] = $row;
1758
+		if (count($params) == 1) {
1759
+					$return[$row['id_member']] = $row;
1760
+		}
1678 1761
 
1679 1762
 		// More than 1? knock yourself out...
1680 1763
 		else
1681 1764
 		{
1682
-			if (!isset($return[$row['id_member']]))
1683
-				$return[$row['id_member']] = array();
1765
+			if (!isset($return[$row['id_member']])) {
1766
+							$return[$row['id_member']] = array();
1767
+			}
1684 1768
 
1685 1769
 			$return[$row['id_member']][$row['variable']] = $row;
1686 1770
 		}
@@ -1714,8 +1798,9 @@  discard block
 block discarded – undo
1714 1798
 	global $context;
1715 1799
 
1716 1800
 	// Don't know any browser!
1717
-	if (empty($context['browser']))
1718
-		detectBrowser();
1801
+	if (empty($context['browser'])) {
1802
+			detectBrowser();
1803
+	}
1719 1804
 
1720 1805
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1721 1806
 }
@@ -1733,8 +1818,9 @@  discard block
 block discarded – undo
1733 1818
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1734 1819
 
1735 1820
 	// The theme was specified by parameter.
1736
-	if (!empty($id_theme))
1737
-		$id_theme = (int) $id_theme;
1821
+	if (!empty($id_theme)) {
1822
+			$id_theme = (int) $id_theme;
1823
+	}
1738 1824
 	// The theme was specified by REQUEST.
1739 1825
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1740 1826
 	{
@@ -1742,32 +1828,38 @@  discard block
 block discarded – undo
1742 1828
 		$_SESSION['id_theme'] = $id_theme;
1743 1829
 	}
1744 1830
 	// The theme was specified by REQUEST... previously.
1745
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1746
-		$id_theme = (int) $_SESSION['id_theme'];
1831
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1832
+			$id_theme = (int) $_SESSION['id_theme'];
1833
+	}
1747 1834
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1748
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1749
-		$id_theme = $user_info['theme'];
1835
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1836
+			$id_theme = $user_info['theme'];
1837
+	}
1750 1838
 	// The theme was specified by the board.
1751
-	elseif (!empty($board_info['theme']))
1752
-		$id_theme = $board_info['theme'];
1839
+	elseif (!empty($board_info['theme'])) {
1840
+			$id_theme = $board_info['theme'];
1841
+	}
1753 1842
 	// The theme is the forum's default.
1754
-	else
1755
-		$id_theme = $modSettings['theme_guests'];
1843
+	else {
1844
+			$id_theme = $modSettings['theme_guests'];
1845
+	}
1756 1846
 
1757 1847
 	// Verify the id_theme... no foul play.
1758 1848
 	// Always allow the board specific theme, if they are overriding.
1759
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1760
-		$id_theme = $board_info['theme'];
1849
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1850
+			$id_theme = $board_info['theme'];
1851
+	}
1761 1852
 	// If they have specified a particular theme to use with SSI allow it to be used.
1762
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1763
-		$id_theme = (int) $id_theme;
1764
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1853
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1854
+			$id_theme = (int) $id_theme;
1855
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1765 1856
 	{
1766 1857
 		$themes = explode(',', $modSettings['enableThemes']);
1767
-		if (!in_array($id_theme, $themes))
1768
-			$id_theme = $modSettings['theme_guests'];
1769
-		else
1770
-			$id_theme = (int) $id_theme;
1858
+		if (!in_array($id_theme, $themes)) {
1859
+					$id_theme = $modSettings['theme_guests'];
1860
+		} else {
1861
+					$id_theme = (int) $id_theme;
1862
+		}
1771 1863
 	}
1772 1864
 		
1773 1865
 	// Allow mod authors the option to override the theme id for custom page themes
@@ -1779,18 +1871,19 @@  discard block
 block discarded – undo
1779 1871
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1780 1872
 
1781 1873
 		// Disable image proxy if we don't have SSL enabled
1782
-		if (empty($modSettings['force_ssl']))
1783
-			$image_proxy_enabled = false;
1874
+		if (empty($modSettings['force_ssl'])) {
1875
+					$image_proxy_enabled = false;
1876
+		}
1784 1877
 
1785 1878
 		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1786 1879
 		{
1787 1880
 			$themeData = $temp;
1788 1881
 			$flag = true;
1882
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1883
+					$themeData = $temp + array($member => array());
1884
+		} else {
1885
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1789 1886
 		}
1790
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1791
-			$themeData = $temp + array($member => array());
1792
-		else
1793
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1794 1887
 
1795 1888
 		if (empty($flag))
1796 1889
 		{
@@ -1810,31 +1903,37 @@  discard block
 block discarded – undo
1810 1903
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1811 1904
 			{
1812 1905
 				// There are just things we shouldn't be able to change as members.
1813
-				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1814
-					continue;
1906
+				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1907
+									continue;
1908
+				}
1815 1909
 
1816 1910
 				// If this is the theme_dir of the default theme, store it.
1817
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1818
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1911
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1912
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1913
+				}
1819 1914
 
1820 1915
 				// If this isn't set yet, is a theme option, or is not the default theme..
1821
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1822
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1916
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1917
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1918
+				}
1823 1919
 			}
1824 1920
 			$smcFunc['db_free_result']($result);
1825 1921
 
1826
-			if (!empty($themeData[-1]))
1827
-				foreach ($themeData[-1] as $k => $v)
1922
+			if (!empty($themeData[-1])) {
1923
+							foreach ($themeData[-1] as $k => $v)
1828 1924
 				{
1829 1925
 					if (!isset($themeData[$member][$k]))
1830 1926
 						$themeData[$member][$k] = $v;
1927
+			}
1831 1928
 				}
1832 1929
 
1833
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1834
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1930
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1931
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1932
+			}
1835 1933
 			// Only if we didn't already load that part of the cache...
1836
-			elseif (!isset($temp))
1837
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1934
+			elseif (!isset($temp)) {
1935
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1936
+			}
1838 1937
 		}
1839 1938
 
1840 1939
 		$settings = $themeData[0];
@@ -1851,17 +1950,20 @@  discard block
 block discarded – undo
1851 1950
 		$settings['template_dirs'][] = $settings['theme_dir'];
1852 1951
 
1853 1952
 		// Based on theme (if there is one).
1854
-		if (!empty($settings['base_theme_dir']))
1855
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1953
+		if (!empty($settings['base_theme_dir'])) {
1954
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1955
+		}
1856 1956
 
1857 1957
 		// Lastly the default theme.
1858
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1859
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1958
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1959
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1960
+		}
1860 1961
 	}
1861 1962
 
1862 1963
 
1863
-	if (!$initialize)
1864
-		return;
1964
+	if (!$initialize) {
1965
+			return;
1966
+	}
1865 1967
 
1866 1968
 	// Check to see if we're forcing SSL
1867 1969
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1882,8 +1984,9 @@  discard block
 block discarded – undo
1882 1984
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1883 1985
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1884 1986
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1885
-		if ($temp != '/')
1886
-			$detected_url .= $temp;
1987
+		if ($temp != '/') {
1988
+					$detected_url .= $temp;
1989
+		}
1887 1990
 	}
1888 1991
 	if (isset($detected_url) && $detected_url != $boardurl)
1889 1992
 	{
@@ -1895,8 +1998,9 @@  discard block
 block discarded – undo
1895 1998
 			foreach ($aliases as $alias)
1896 1999
 			{
1897 2000
 				// Rip off all the boring parts, spaces, etc.
1898
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1899
-					$do_fix = true;
2001
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
2002
+									$do_fix = true;
2003
+				}
1900 2004
 			}
1901 2005
 		}
1902 2006
 
@@ -1904,21 +2008,23 @@  discard block
 block discarded – undo
1904 2008
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1905 2009
 		{
1906 2010
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1907
-			if (empty($_GET))
1908
-				redirectexit('wwwRedirect');
1909
-			else
2011
+			if (empty($_GET)) {
2012
+							redirectexit('wwwRedirect');
2013
+			} else
1910 2014
 			{
1911 2015
 				$k = key($_GET);
1912 2016
 				$v = current($_GET);
1913 2017
 
1914
-				if ($k != 'wwwRedirect')
1915
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
2018
+				if ($k != 'wwwRedirect') {
2019
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
2020
+				}
1916 2021
 			}
1917 2022
 		}
1918 2023
 
1919 2024
 		// #3 is just a check for SSL...
1920
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1921
-			$do_fix = true;
2025
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
2026
+					$do_fix = true;
2027
+		}
1922 2028
 
1923 2029
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1924 2030
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1953,8 +2059,9 @@  discard block
 block discarded – undo
1953 2059
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1954 2060
 				}
1955 2061
 			}
1956
-			foreach ($context['linktree'] as $k => $dummy)
1957
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2062
+			foreach ($context['linktree'] as $k => $dummy) {
2063
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2064
+			}
1958 2065
 		}
1959 2066
 	}
1960 2067
 	// Set up the contextual user array.
@@ -1973,16 +2080,16 @@  discard block
 block discarded – undo
1973 2080
 			'email' => $user_info['email'],
1974 2081
 			'ignoreusers' => $user_info['ignoreusers'],
1975 2082
 		);
1976
-		if (!$context['user']['is_guest'])
1977
-			$context['user']['name'] = $user_info['name'];
1978
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1979
-			$context['user']['name'] = $txt['guest_title'];
2083
+		if (!$context['user']['is_guest']) {
2084
+					$context['user']['name'] = $user_info['name'];
2085
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2086
+					$context['user']['name'] = $txt['guest_title'];
2087
+		}
1980 2088
 
1981 2089
 		// Determine the current smiley set.
1982 2090
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1983 2091
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1984
-	}
1985
-	else
2092
+	} else
1986 2093
 	{
1987 2094
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1988 2095
 		$context['user'] = array(
@@ -2016,18 +2123,24 @@  discard block
 block discarded – undo
2016 2123
 	}
2017 2124
 
2018 2125
 	// Some basic information...
2019
-	if (!isset($context['html_headers']))
2020
-		$context['html_headers'] = '';
2021
-	if (!isset($context['javascript_files']))
2022
-		$context['javascript_files'] = array();
2023
-	if (!isset($context['css_files']))
2024
-		$context['css_files'] = array();
2025
-	if (!isset($context['css_header']))
2026
-		$context['css_header'] = array();
2027
-	if (!isset($context['javascript_inline']))
2028
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2029
-	if (!isset($context['javascript_vars']))
2030
-		$context['javascript_vars'] = array();
2126
+	if (!isset($context['html_headers'])) {
2127
+			$context['html_headers'] = '';
2128
+	}
2129
+	if (!isset($context['javascript_files'])) {
2130
+			$context['javascript_files'] = array();
2131
+	}
2132
+	if (!isset($context['css_files'])) {
2133
+			$context['css_files'] = array();
2134
+	}
2135
+	if (!isset($context['css_header'])) {
2136
+			$context['css_header'] = array();
2137
+	}
2138
+	if (!isset($context['javascript_inline'])) {
2139
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2140
+	}
2141
+	if (!isset($context['javascript_vars'])) {
2142
+			$context['javascript_vars'] = array();
2143
+	}
2031 2144
 
2032 2145
 	$context['login_url'] =  $scripturl . '?action=login2';
2033 2146
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2039,16 +2152,18 @@  discard block
 block discarded – undo
2039 2152
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2040 2153
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2041 2154
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2042
-	if (isset($modSettings['load_average']))
2043
-		$context['load_average'] = $modSettings['load_average'];
2155
+	if (isset($modSettings['load_average'])) {
2156
+			$context['load_average'] = $modSettings['load_average'];
2157
+	}
2044 2158
 
2045 2159
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2046 2160
 	detectBrowser();
2047 2161
 
2048 2162
 	// Set the top level linktree up.
2049 2163
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2050
-	if (empty($context['linktree']))
2051
-		$context['linktree'] = array();
2164
+	if (empty($context['linktree'])) {
2165
+			$context['linktree'] = array();
2166
+	}
2052 2167
 	array_unshift($context['linktree'], array(
2053 2168
 		'url' => $scripturl,
2054 2169
 		'name' => $context['forum_name_html_safe']
@@ -2057,8 +2172,9 @@  discard block
 block discarded – undo
2057 2172
 	// This allows sticking some HTML on the page output - useful for controls.
2058 2173
 	$context['insert_after_template'] = '';
2059 2174
 
2060
-	if (!isset($txt))
2061
-		$txt = array();
2175
+	if (!isset($txt)) {
2176
+			$txt = array();
2177
+	}
2062 2178
 
2063 2179
 	$simpleActions = array(
2064 2180
 		'findmember',
@@ -2104,9 +2220,10 @@  discard block
 block discarded – undo
2104 2220
 
2105 2221
 	// See if theres any extra param to check.
2106 2222
 	$requiresXML = false;
2107
-	foreach ($extraParams as $key => $extra)
2108
-		if (isset($_REQUEST[$extra]))
2223
+	foreach ($extraParams as $key => $extra) {
2224
+			if (isset($_REQUEST[$extra]))
2109 2225
 			$requiresXML = true;
2226
+	}
2110 2227
 
2111 2228
 	// Output is fully XML, so no need for the index template.
2112 2229
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2121,37 +2238,39 @@  discard block
 block discarded – undo
2121 2238
 	{
2122 2239
 		loadLanguage('index+Modifications');
2123 2240
 		$context['template_layers'] = array();
2124
-	}
2125
-
2126
-	else
2241
+	} else
2127 2242
 	{
2128 2243
 		// Custom templates to load, or just default?
2129
-		if (isset($settings['theme_templates']))
2130
-			$templates = explode(',', $settings['theme_templates']);
2131
-		else
2132
-			$templates = array('index');
2244
+		if (isset($settings['theme_templates'])) {
2245
+					$templates = explode(',', $settings['theme_templates']);
2246
+		} else {
2247
+					$templates = array('index');
2248
+		}
2133 2249
 
2134 2250
 		// Load each template...
2135
-		foreach ($templates as $template)
2136
-			loadTemplate($template);
2251
+		foreach ($templates as $template) {
2252
+					loadTemplate($template);
2253
+		}
2137 2254
 
2138 2255
 		// ...and attempt to load their associated language files.
2139 2256
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2140 2257
 		loadLanguage($required_files, '', false);
2141 2258
 
2142 2259
 		// Custom template layers?
2143
-		if (isset($settings['theme_layers']))
2144
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2145
-		else
2146
-			$context['template_layers'] = array('html', 'body');
2260
+		if (isset($settings['theme_layers'])) {
2261
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2262
+		} else {
2263
+					$context['template_layers'] = array('html', 'body');
2264
+		}
2147 2265
 	}
2148 2266
 
2149 2267
 	// Initialize the theme.
2150 2268
 	loadSubTemplate('init', 'ignore');
2151 2269
 
2152 2270
 	// Allow overriding the board wide time/number formats.
2153
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2154
-		$user_info['time_format'] = $txt['time_format'];
2271
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2272
+			$user_info['time_format'] = $txt['time_format'];
2273
+	}
2155 2274
 
2156 2275
 	// Set the character set from the template.
2157 2276
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2159,12 +2278,14 @@  discard block
 block discarded – undo
2159 2278
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2160 2279
 
2161 2280
 	// Guests may still need a name.
2162
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2163
-		$context['user']['name'] = $txt['guest_title'];
2281
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2282
+			$context['user']['name'] = $txt['guest_title'];
2283
+	}
2164 2284
 
2165 2285
 	// Any theme-related strings that need to be loaded?
2166
-	if (!empty($settings['require_theme_strings']))
2167
-		loadLanguage('ThemeStrings', '', false);
2286
+	if (!empty($settings['require_theme_strings'])) {
2287
+			loadLanguage('ThemeStrings', '', false);
2288
+	}
2168 2289
 
2169 2290
 	// Make a special URL for the language.
2170 2291
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2175,8 +2296,9 @@  discard block
 block discarded – undo
2175 2296
 	// Here is my luvly Responsive CSS
2176 2297
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2177 2298
 
2178
-	if ($context['right_to_left'])
2179
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2299
+	if ($context['right_to_left']) {
2300
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2301
+	}
2180 2302
 
2181 2303
 	// We allow theme variants, because we're cool.
2182 2304
 	$context['theme_variant'] = '';
@@ -2184,14 +2306,17 @@  discard block
 block discarded – undo
2184 2306
 	if (!empty($settings['theme_variants']))
2185 2307
 	{
2186 2308
 		// Overriding - for previews and that ilk.
2187
-		if (!empty($_REQUEST['variant']))
2188
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2309
+		if (!empty($_REQUEST['variant'])) {
2310
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2311
+		}
2189 2312
 		// User selection?
2190
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2191
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2313
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2314
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2315
+		}
2192 2316
 		// If not a user variant, select the default.
2193
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2194
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2317
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2318
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2319
+		}
2195 2320
 
2196 2321
 		// Do this to keep things easier in the templates.
2197 2322
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2200,20 +2325,23 @@  discard block
 block discarded – undo
2200 2325
 		if (!empty($context['theme_variant']))
2201 2326
 		{
2202 2327
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2203
-			if ($context['right_to_left'])
2204
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2328
+			if ($context['right_to_left']) {
2329
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2330
+			}
2205 2331
 		}
2206 2332
 	}
2207 2333
 
2208 2334
 	// Let's be compatible with old themes!
2209
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2210
-		$context['template_layers'] = array('main');
2335
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2336
+			$context['template_layers'] = array('main');
2337
+	}
2211 2338
 
2212 2339
 	$context['tabindex'] = 1;
2213 2340
 
2214 2341
 	// Compatibility.
2215
-	if (!isset($settings['theme_version']))
2216
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2342
+	if (!isset($settings['theme_version'])) {
2343
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2344
+	}
2217 2345
 
2218 2346
 	// Default JS variables for use in every theme
2219 2347
 	$context['javascript_vars'] = array(
@@ -2234,18 +2362,18 @@  discard block
 block discarded – undo
2234 2362
 	);
2235 2363
 
2236 2364
 	// Add the JQuery library to the list of files to load.
2237
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2238
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2239
-
2240
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2241
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2242
-
2243
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2244
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2365
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2366
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2367
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2368
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2369
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2370
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2371
+	}
2245 2372
 
2246 2373
 	// Auto loading? template_javascript() will take care of the local half of this.
2247
-	else
2248
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2374
+	else {
2375
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2376
+	}
2249 2377
 
2250 2378
 	// Queue our JQuery plugins!
2251 2379
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2268,12 +2396,12 @@  discard block
 block discarded – undo
2268 2396
 			require_once($sourcedir . '/ScheduledTasks.php');
2269 2397
 
2270 2398
 			// What to do, what to do?!
2271
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2272
-				AutoTask();
2273
-			else
2274
-				ReduceMailQueue();
2275
-		}
2276
-		else
2399
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2400
+							AutoTask();
2401
+			} else {
2402
+							ReduceMailQueue();
2403
+			}
2404
+		} else
2277 2405
 		{
2278 2406
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2279 2407
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2324,8 +2452,9 @@  discard block
 block discarded – undo
2324 2452
 		foreach ($theme_includes as $include)
2325 2453
 		{
2326 2454
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2327
-			if (file_exists($include))
2328
-				require_once($include);
2455
+			if (file_exists($include)) {
2456
+							require_once($include);
2457
+			}
2329 2458
 		}
2330 2459
 	}
2331 2460
 
@@ -2355,16 +2484,19 @@  discard block
 block discarded – undo
2355 2484
 	// Do any style sheets first, cause we're easy with those.
2356 2485
 	if (!empty($style_sheets))
2357 2486
 	{
2358
-		if (!is_array($style_sheets))
2359
-			$style_sheets = array($style_sheets);
2487
+		if (!is_array($style_sheets)) {
2488
+					$style_sheets = array($style_sheets);
2489
+		}
2360 2490
 
2361
-		foreach ($style_sheets as $sheet)
2362
-			loadCSSFile($sheet . '.css', array(), $sheet);
2491
+		foreach ($style_sheets as $sheet) {
2492
+					loadCSSFile($sheet . '.css', array(), $sheet);
2493
+		}
2363 2494
 	}
2364 2495
 
2365 2496
 	// No template to load?
2366
-	if ($template_name === false)
2367
-		return true;
2497
+	if ($template_name === false) {
2498
+			return true;
2499
+	}
2368 2500
 
2369 2501
 	$loaded = false;
2370 2502
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2379,12 +2511,14 @@  discard block
 block discarded – undo
2379 2511
 
2380 2512
 	if ($loaded)
2381 2513
 	{
2382
-		if ($db_show_debug === true)
2383
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2514
+		if ($db_show_debug === true) {
2515
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2516
+		}
2384 2517
 
2385 2518
 		// If they have specified an initialization function for this template, go ahead and call it now.
2386
-		if (function_exists('template_' . $template_name . '_init'))
2387
-			call_user_func('template_' . $template_name . '_init');
2519
+		if (function_exists('template_' . $template_name . '_init')) {
2520
+					call_user_func('template_' . $template_name . '_init');
2521
+		}
2388 2522
 	}
2389 2523
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2390 2524
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2404,13 +2538,14 @@  discard block
 block discarded – undo
2404 2538
 		loadTemplate($template_name);
2405 2539
 	}
2406 2540
 	// Cause an error otherwise.
2407
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2408
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2409
-	elseif ($fatal)
2410
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2411
-	else
2412
-		return false;
2413
-}
2541
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2542
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2543
+	} elseif ($fatal) {
2544
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2545
+	} else {
2546
+			return false;
2547
+	}
2548
+	}
2414 2549
 
2415 2550
 /**
2416 2551
  * Load a sub-template.
@@ -2428,17 +2563,19 @@  discard block
 block discarded – undo
2428 2563
 {
2429 2564
 	global $context, $txt, $db_show_debug;
2430 2565
 
2431
-	if ($db_show_debug === true)
2432
-		$context['debug']['sub_templates'][] = $sub_template_name;
2566
+	if ($db_show_debug === true) {
2567
+			$context['debug']['sub_templates'][] = $sub_template_name;
2568
+	}
2433 2569
 
2434 2570
 	// Figure out what the template function is named.
2435 2571
 	$theme_function = 'template_' . $sub_template_name;
2436
-	if (function_exists($theme_function))
2437
-		$theme_function();
2438
-	elseif ($fatal === false)
2439
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2440
-	elseif ($fatal !== 'ignore')
2441
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2572
+	if (function_exists($theme_function)) {
2573
+			$theme_function();
2574
+	} elseif ($fatal === false) {
2575
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2576
+	} elseif ($fatal !== 'ignore') {
2577
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2578
+	}
2442 2579
 
2443 2580
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2444 2581
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2468,8 +2605,9 @@  discard block
 block discarded – undo
2468 2605
 {
2469 2606
 	global $settings, $context, $modSettings;
2470 2607
 
2471
-	if (empty($context['css_files_order']))
2472
-		$context['css_files_order'] = array();
2608
+	if (empty($context['css_files_order'])) {
2609
+			$context['css_files_order'] = array();
2610
+	}
2473 2611
 
2474 2612
 	$params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
2475 2613
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2480,8 +2618,9 @@  discard block
 block discarded – undo
2480 2618
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2481 2619
 
2482 2620
 	// If this is an external file, automatically set this to false.
2483
-	if (!empty($params['external']))
2484
-		$params['minimize'] = false;
2621
+	if (!empty($params['external'])) {
2622
+			$params['minimize'] = false;
2623
+	}
2485 2624
 
2486 2625
 	// Account for shorthand like admin.css?alp21 filenames
2487 2626
 	$has_seed = strpos($fileName, '.css?');
@@ -2498,16 +2637,12 @@  discard block
 block discarded – undo
2498 2637
 			{
2499 2638
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2500 2639
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2501
-			}
2502
-
2503
-			else
2640
+			} else
2504 2641
 			{
2505 2642
 				$fileUrl = false;
2506 2643
 				$filePath = false;
2507 2644
 			}
2508
-		}
2509
-
2510
-		else
2645
+		} else
2511 2646
 		{
2512 2647
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2513 2648
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2525,16 +2660,18 @@  discard block
 block discarded – undo
2525 2660
 	if (!empty($fileName))
2526 2661
 	{
2527 2662
 		// find a free number/position
2528
-		while (isset($context['css_files_order'][$params['order_pos']]))
2529
-			$params['order_pos']++;
2663
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2664
+					$params['order_pos']++;
2665
+		}
2530 2666
 		$context['css_files_order'][$params['order_pos']] = $id;
2531 2667
 
2532 2668
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2533 2669
 	}
2534 2670
 
2535
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2536
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2537
-}
2671
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2672
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2673
+	}
2674
+	}
2538 2675
 
2539 2676
 /**
2540 2677
  * Add a block of inline css code to be executed later
@@ -2551,8 +2688,9 @@  discard block
 block discarded – undo
2551 2688
 	global $context;
2552 2689
 
2553 2690
 	// Gotta add something...
2554
-	if (empty($css))
2555
-		return false;
2691
+	if (empty($css)) {
2692
+			return false;
2693
+	}
2556 2694
 
2557 2695
 	$context['css_header'][] = $css;
2558 2696
 }
@@ -2588,8 +2726,9 @@  discard block
 block discarded – undo
2588 2726
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2589 2727
 
2590 2728
 	// If this is an external file, automatically set this to false.
2591
-	if (!empty($params['external']))
2592
-		$params['minimize'] = false;
2729
+	if (!empty($params['external'])) {
2730
+			$params['minimize'] = false;
2731
+	}
2593 2732
 
2594 2733
 	// Account for shorthand like admin.js?alp21 filenames
2595 2734
 	$has_seed = strpos($fileName, '.js?');
@@ -2606,16 +2745,12 @@  discard block
 block discarded – undo
2606 2745
 			{
2607 2746
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2608 2747
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2609
-			}
2610
-
2611
-			else
2748
+			} else
2612 2749
 			{
2613 2750
 				$fileUrl = false;
2614 2751
 				$filePath = false;
2615 2752
 			}
2616
-		}
2617
-
2618
-		else
2753
+		} else
2619 2754
 		{
2620 2755
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2621 2756
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2630,9 +2765,10 @@  discard block
 block discarded – undo
2630 2765
 	}
2631 2766
 
2632 2767
 	// Add it to the array for use in the template
2633
-	if (!empty($fileName))
2634
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2635
-}
2768
+	if (!empty($fileName)) {
2769
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2770
+	}
2771
+	}
2636 2772
 
2637 2773
 /**
2638 2774
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2646,9 +2782,10 @@  discard block
 block discarded – undo
2646 2782
 {
2647 2783
 	global $context;
2648 2784
 
2649
-	if (!empty($key) && (!empty($value) || $value === '0'))
2650
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2651
-}
2785
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2786
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2787
+	}
2788
+	}
2652 2789
 
2653 2790
 /**
2654 2791
  * Add a block of inline Javascript code to be executed later
@@ -2665,8 +2802,9 @@  discard block
 block discarded – undo
2665 2802
 {
2666 2803
 	global $context;
2667 2804
 
2668
-	if (empty($javascript))
2669
-		return false;
2805
+	if (empty($javascript)) {
2806
+			return false;
2807
+	}
2670 2808
 
2671 2809
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2672 2810
 }
@@ -2687,15 +2825,18 @@  discard block
 block discarded – undo
2687 2825
 	static $already_loaded = array();
2688 2826
 
2689 2827
 	// Default to the user's language.
2690
-	if ($lang == '')
2691
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2828
+	if ($lang == '') {
2829
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2830
+	}
2692 2831
 
2693 2832
 	// Do we want the English version of language file as fallback?
2694
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2695
-		loadLanguage($template_name, 'english', false);
2833
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2834
+			loadLanguage($template_name, 'english', false);
2835
+	}
2696 2836
 
2697
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2698
-		return $lang;
2837
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2838
+			return $lang;
2839
+	}
2699 2840
 
2700 2841
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2701 2842
 	if (empty($settings['default_theme_dir']))
@@ -2706,8 +2847,9 @@  discard block
 block discarded – undo
2706 2847
 
2707 2848
 	// What theme are we in?
2708 2849
 	$theme_name = basename($settings['theme_url']);
2709
-	if (empty($theme_name))
2710
-		$theme_name = 'unknown';
2850
+	if (empty($theme_name)) {
2851
+			$theme_name = 'unknown';
2852
+	}
2711 2853
 
2712 2854
 	// For each file open it up and write it out!
2713 2855
 	foreach (explode('+', $template_name) as $template)
@@ -2749,8 +2891,9 @@  discard block
 block discarded – undo
2749 2891
 				$found = true;
2750 2892
 
2751 2893
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2752
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2753
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2894
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2895
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2896
+				}
2754 2897
 
2755 2898
 				break;
2756 2899
 			}
@@ -2790,8 +2933,9 @@  discard block
 block discarded – undo
2790 2933
 	}
2791 2934
 
2792 2935
 	// Keep track of what we're up to soldier.
2793
-	if ($db_show_debug === true)
2794
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2936
+	if ($db_show_debug === true) {
2937
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2938
+	}
2795 2939
 
2796 2940
 	// Remember what we have loaded, and in which language.
2797 2941
 	$already_loaded[$template_name] = $lang;
@@ -2837,8 +2981,9 @@  discard block
 block discarded – undo
2837 2981
 				)
2838 2982
 			);
2839 2983
 			// In the EXTREMELY unlikely event this happens, give an error message.
2840
-			if ($smcFunc['db_num_rows']($result) == 0)
2841
-				fatal_lang_error('parent_not_found', 'critical');
2984
+			if ($smcFunc['db_num_rows']($result) == 0) {
2985
+							fatal_lang_error('parent_not_found', 'critical');
2986
+			}
2842 2987
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2843 2988
 			{
2844 2989
 				if (!isset($boards[$row['id_board']]))
@@ -2855,8 +3000,8 @@  discard block
 block discarded – undo
2855 3000
 					);
2856 3001
 				}
2857 3002
 				// If a moderator exists for this board, add that moderator for all children too.
2858
-				if (!empty($row['id_moderator']))
2859
-					foreach ($boards as $id => $dummy)
3003
+				if (!empty($row['id_moderator'])) {
3004
+									foreach ($boards as $id => $dummy)
2860 3005
 					{
2861 3006
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2862 3007
 							'id' => $row['id_moderator'],
@@ -2864,11 +3009,12 @@  discard block
 block discarded – undo
2864 3009
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2865 3010
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2866 3011
 						);
3012
+				}
2867 3013
 					}
2868 3014
 
2869 3015
 				// If a moderator group exists for this board, add that moderator group for all children too
2870
-				if (!empty($row['id_moderator_group']))
2871
-					foreach ($boards as $id => $dummy)
3016
+				if (!empty($row['id_moderator_group'])) {
3017
+									foreach ($boards as $id => $dummy)
2872 3018
 					{
2873 3019
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2874 3020
 							'id' => $row['id_moderator_group'],
@@ -2876,6 +3022,7 @@  discard block
 block discarded – undo
2876 3022
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2877 3023
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2878 3024
 						);
3025
+				}
2879 3026
 					}
2880 3027
 			}
2881 3028
 			$smcFunc['db_free_result']($result);
@@ -2902,23 +3049,27 @@  discard block
 block discarded – undo
2902 3049
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2903 3050
 	{
2904 3051
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2905
-		if (empty($smcFunc['ucwords']))
2906
-			reloadSettings();
3052
+		if (empty($smcFunc['ucwords'])) {
3053
+					reloadSettings();
3054
+		}
2907 3055
 
2908 3056
 		// If we don't have our theme information yet, let's get it.
2909
-		if (empty($settings['default_theme_dir']))
2910
-			loadTheme(0, false);
3057
+		if (empty($settings['default_theme_dir'])) {
3058
+					loadTheme(0, false);
3059
+		}
2911 3060
 
2912 3061
 		// Default language directories to try.
2913 3062
 		$language_directories = array(
2914 3063
 			$settings['default_theme_dir'] . '/languages',
2915 3064
 		);
2916
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2917
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3065
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3066
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3067
+		}
2918 3068
 
2919 3069
 		// We possibly have a base theme directory.
2920
-		if (!empty($settings['base_theme_dir']))
2921
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3070
+		if (!empty($settings['base_theme_dir'])) {
3071
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3072
+		}
2922 3073
 
2923 3074
 		// Remove any duplicates.
2924 3075
 		$language_directories = array_unique($language_directories);
@@ -2932,20 +3083,21 @@  discard block
 block discarded – undo
2932 3083
 		foreach ($language_directories as $language_dir)
2933 3084
 		{
2934 3085
 			// Can't look in here... doesn't exist!
2935
-			if (!file_exists($language_dir))
2936
-				continue;
3086
+			if (!file_exists($language_dir)) {
3087
+							continue;
3088
+			}
2937 3089
 
2938 3090
 			$dir = dir($language_dir);
2939 3091
 			while ($entry = $dir->read())
2940 3092
 			{
2941 3093
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2942
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2943
-					continue;
2944
-
2945
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2946
-					$langName = $langList[$matches[1]];
3094
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3095
+									continue;
3096
+				}
2947 3097
 
2948
-				else
3098
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3099
+									$langName = $langList[$matches[1]];
3100
+				} else
2949 3101
 				{
2950 3102
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2951 3103
 
@@ -2986,12 +3138,14 @@  discard block
 block discarded – undo
2986 3138
 		}
2987 3139
 
2988 3140
 		// Do we need to store the lang list?
2989
-		if (empty($langList))
2990
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3141
+		if (empty($langList)) {
3142
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3143
+		}
2991 3144
 
2992 3145
 		// Let's cash in on this deal.
2993
-		if (!empty($modSettings['cache_enable']))
2994
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3146
+		if (!empty($modSettings['cache_enable'])) {
3147
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3148
+		}
2995 3149
 	}
2996 3150
 
2997 3151
 	return $context['languages'];
@@ -3014,8 +3168,9 @@  discard block
 block discarded – undo
3014 3168
 	global $modSettings, $options, $txt;
3015 3169
 	static $censor_vulgar = null, $censor_proper;
3016 3170
 
3017
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
3018
-		return $text;
3171
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3172
+			return $text;
3173
+	}
3019 3174
 
3020 3175
 	// If they haven't yet been loaded, load them.
3021 3176
 	if ($censor_vulgar == null)
@@ -3046,9 +3201,9 @@  discard block
 block discarded – undo
3046 3201
 	{
3047 3202
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3048 3203
 		$text = $func($censor_vulgar, $censor_proper, $text);
3204
+	} else {
3205
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3049 3206
 	}
3050
-	else
3051
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3052 3207
 
3053 3208
 	return $text;
3054 3209
 }
@@ -3074,30 +3229,35 @@  discard block
 block discarded – undo
3074 3229
 	@ini_set('track_errors', '1');
3075 3230
 
3076 3231
 	// Don't include the file more than once, if $once is true.
3077
-	if ($once && in_array($filename, $templates))
3078
-		return;
3232
+	if ($once && in_array($filename, $templates)) {
3233
+			return;
3234
+	}
3079 3235
 	// Add this file to the include list, whether $once is true or not.
3080
-	else
3081
-		$templates[] = $filename;
3236
+	else {
3237
+			$templates[] = $filename;
3238
+	}
3082 3239
 
3083 3240
 
3084 3241
 	$file_found = file_exists($filename);
3085 3242
 
3086
-	if ($once && $file_found)
3087
-		require_once($filename);
3088
-	elseif ($file_found)
3089
-		require($filename);
3243
+	if ($once && $file_found) {
3244
+			require_once($filename);
3245
+	} elseif ($file_found) {
3246
+			require($filename);
3247
+	}
3090 3248
 
3091 3249
 	if ($file_found !== true)
3092 3250
 	{
3093 3251
 		ob_end_clean();
3094
-		if (!empty($modSettings['enableCompressedOutput']))
3095
-			@ob_start('ob_gzhandler');
3096
-		else
3097
-			ob_start();
3252
+		if (!empty($modSettings['enableCompressedOutput'])) {
3253
+					@ob_start('ob_gzhandler');
3254
+		} else {
3255
+					ob_start();
3256
+		}
3098 3257
 
3099
-		if (isset($_GET['debug']))
3100
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3258
+		if (isset($_GET['debug'])) {
3259
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3260
+		}
3101 3261
 
3102 3262
 		// Don't cache error pages!!
3103 3263
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3116,12 +3276,13 @@  discard block
 block discarded – undo
3116 3276
 		echo '<!DOCTYPE html>
3117 3277
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3118 3278
 	<head>';
3119
-		if (isset($context['character_set']))
3120
-			echo '
3279
+		if (isset($context['character_set'])) {
3280
+					echo '
3121 3281
 		<meta charset="', $context['character_set'], '">';
3282
+		}
3122 3283
 
3123
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3124
-			echo '
3284
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3285
+					echo '
3125 3286
 		<title>', $mtitle, '</title>
3126 3287
 	</head>
3127 3288
 	<body>
@@ -3129,8 +3290,8 @@  discard block
 block discarded – undo
3129 3290
 		', $mmessage, '
3130 3291
 	</body>
3131 3292
 </html>';
3132
-		elseif (!allowedTo('admin_forum'))
3133
-			echo '
3293
+		} elseif (!allowedTo('admin_forum')) {
3294
+					echo '
3134 3295
 		<title>', $txt['template_parse_error'], '</title>
3135 3296
 	</head>
3136 3297
 	<body>
@@ -3138,14 +3299,16 @@  discard block
 block discarded – undo
3138 3299
 		', $txt['template_parse_error_message'], '
3139 3300
 	</body>
3140 3301
 </html>';
3141
-		else
3302
+		} else
3142 3303
 		{
3143 3304
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3144 3305
 			$error_array = error_get_last();
3145
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3146
-				$error = $error_array['message'];
3147
-			if (empty($error))
3148
-				$error = $txt['template_parse_errmsg'];
3306
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3307
+							$error = $error_array['message'];
3308
+			}
3309
+			if (empty($error)) {
3310
+							$error = $txt['template_parse_errmsg'];
3311
+			}
3149 3312
 
3150 3313
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3151 3314
 
@@ -3156,11 +3319,12 @@  discard block
 block discarded – undo
3156 3319
 		<h3>', $txt['template_parse_error'], '</h3>
3157 3320
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3158 3321
 
3159
-			if (!empty($error))
3160
-				echo '
3322
+			if (!empty($error)) {
3323
+							echo '
3161 3324
 		<hr>
3162 3325
 
3163 3326
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3327
+			}
3164 3328
 
3165 3329
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3166 3330
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3170,10 +3334,11 @@  discard block
 block discarded – undo
3170 3334
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3171 3335
 
3172 3336
 				// Fix the PHP code stuff...
3173
-				if (!isBrowser('gecko'))
3174
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3175
-				else
3176
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3337
+				if (!isBrowser('gecko')) {
3338
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3339
+				} else {
3340
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3341
+				}
3177 3342
 
3178 3343
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3179 3344
 				$j = -1;
@@ -3181,8 +3346,9 @@  discard block
 block discarded – undo
3181 3346
 				{
3182 3347
 					$j++;
3183 3348
 
3184
-					if (substr_count($line, '<br>') == 0)
3185
-						continue;
3349
+					if (substr_count($line, '<br>') == 0) {
3350
+											continue;
3351
+					}
3186 3352
 
3187 3353
 					$n = substr_count($line, '<br>');
3188 3354
 					for ($i = 0; $i < $n; $i++)
@@ -3201,38 +3367,42 @@  discard block
 block discarded – undo
3201 3367
 				// Figure out what the color coding was before...
3202 3368
 				$line = max($match[1] - 9, 1);
3203 3369
 				$last_line = '';
3204
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3205
-					if (strpos($data2[$line2], '<') !== false)
3370
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3371
+									if (strpos($data2[$line2], '<') !== false)
3206 3372
 					{
3207 3373
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3208 3374
 							$last_line = $color_match[1];
3375
+				}
3209 3376
 						break;
3210 3377
 					}
3211 3378
 
3212 3379
 				// Show the relevant lines...
3213 3380
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3214 3381
 				{
3215
-					if ($line == $match[1])
3216
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3382
+					if ($line == $match[1]) {
3383
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3384
+					}
3217 3385
 
3218 3386
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3219
-					if (isset($data2[$line]) && $data2[$line] != '')
3220
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3387
+					if (isset($data2[$line]) && $data2[$line] != '') {
3388
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3389
+					}
3221 3390
 
3222 3391
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3223 3392
 					{
3224 3393
 						$last_line = $color_match[1];
3225 3394
 						echo '</', substr($last_line, 1, 4), '>';
3395
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3396
+											$last_line = '';
3397
+					} elseif ($last_line != '' && $data2[$line] != '') {
3398
+											echo '</', substr($last_line, 1, 4), '>';
3226 3399
 					}
3227
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3228
-						$last_line = '';
3229
-					elseif ($last_line != '' && $data2[$line] != '')
3230
-						echo '</', substr($last_line, 1, 4), '>';
3231 3400
 
3232
-					if ($line == $match[1])
3233
-						echo '</pre></div><pre style="margin: 0;">';
3234
-					else
3235
-						echo "\n";
3401
+					if ($line == $match[1]) {
3402
+											echo '</pre></div><pre style="margin: 0;">';
3403
+					} else {
3404
+											echo "\n";
3405
+					}
3236 3406
 				}
3237 3407
 
3238 3408
 				echo '</pre></div>';
@@ -3256,8 +3426,9 @@  discard block
 block discarded – undo
3256 3426
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4;
3257 3427
 
3258 3428
 	// Figure out what type of database we are using.
3259
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3260
-		$db_type = 'mysql';
3429
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3430
+			$db_type = 'mysql';
3431
+	}
3261 3432
 
3262 3433
 	// Load the file for the database.
3263 3434
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3265,11 +3436,13 @@  discard block
 block discarded – undo
3265 3436
 	$db_options = array();
3266 3437
 
3267 3438
 	// Add in the port if needed
3268
-	if (!empty($db_port))
3269
-		$db_options['port'] = $db_port;
3439
+	if (!empty($db_port)) {
3440
+			$db_options['port'] = $db_port;
3441
+	}
3270 3442
 
3271
-	if (!empty($db_mb4))
3272
-		$db_options['db_mb4'] = $db_mb4;
3443
+	if (!empty($db_mb4)) {
3444
+			$db_options['db_mb4'] = $db_mb4;
3445
+	}
3273 3446
 
3274 3447
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3275 3448
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3288,13 +3461,15 @@  discard block
 block discarded – undo
3288 3461
 	}
3289 3462
 
3290 3463
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3291
-	if (!$db_connection)
3292
-		display_db_error();
3464
+	if (!$db_connection) {
3465
+			display_db_error();
3466
+	}
3293 3467
 
3294 3468
 	// If in SSI mode fix up the prefix.
3295
-	if (SMF == 'SSI')
3296
-		db_fix_prefix($db_prefix, $db_name);
3297
-}
3469
+	if (SMF == 'SSI') {
3470
+			db_fix_prefix($db_prefix, $db_name);
3471
+	}
3472
+	}
3298 3473
 
3299 3474
 /**
3300 3475
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3308,10 +3483,11 @@  discard block
 block discarded – undo
3308 3483
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3309 3484
 
3310 3485
 	// Not overriding this and we have a cacheAPI, send it back.
3311
-	if (empty($overrideCache) && is_object($cacheAPI))
3312
-		return $cacheAPI;
3313
-	elseif (is_null($cacheAPI))
3314
-		$cacheAPI = false;
3486
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3487
+			return $cacheAPI;
3488
+	} elseif (is_null($cacheAPI)) {
3489
+			$cacheAPI = false;
3490
+	}
3315 3491
 
3316 3492
 	// Make sure our class is in session.
3317 3493
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3332,8 +3508,9 @@  discard block
 block discarded – undo
3332 3508
 		if (!$testAPI->isSupported())
3333 3509
 		{
3334 3510
 			// Can we save ourselves?
3335
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3336
-				return loadCacheAccelerator(null, false);
3511
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3512
+							return loadCacheAccelerator(null, false);
3513
+			}
3337 3514
 			return false;
3338 3515
 		}
3339 3516
 
@@ -3345,9 +3522,9 @@  discard block
 block discarded – undo
3345 3522
 		{
3346 3523
 			$cacheAPI = $testAPI;
3347 3524
 			return $cacheAPI;
3525
+		} else {
3526
+					return $testAPI;
3348 3527
 		}
3349
-		else
3350
-			return $testAPI;
3351 3528
 	}
3352 3529
 }
3353 3530
 
@@ -3367,8 +3544,9 @@  discard block
 block discarded – undo
3367 3544
 
3368 3545
 	// @todo Why are we doing this if caching is disabled?
3369 3546
 
3370
-	if (function_exists('call_integration_hook'))
3371
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3547
+	if (function_exists('call_integration_hook')) {
3548
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3549
+	}
3372 3550
 
3373 3551
 	/* Refresh the cache if either:
3374 3552
 		1. Caching is disabled.
@@ -3382,16 +3560,19 @@  discard block
 block discarded – undo
3382 3560
 		require_once($sourcedir . '/' . $file);
3383 3561
 		$cache_block = call_user_func_array($function, $params);
3384 3562
 
3385
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3386
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3563
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3564
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3565
+		}
3387 3566
 	}
3388 3567
 
3389 3568
 	// Some cached data may need a freshening up after retrieval.
3390
-	if (!empty($cache_block['post_retri_eval']))
3391
-		eval($cache_block['post_retri_eval']);
3569
+	if (!empty($cache_block['post_retri_eval'])) {
3570
+			eval($cache_block['post_retri_eval']);
3571
+	}
3392 3572
 
3393
-	if (function_exists('call_integration_hook'))
3394
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3573
+	if (function_exists('call_integration_hook')) {
3574
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3575
+	}
3395 3576
 
3396 3577
 	return $cache_block['data'];
3397 3578
 }
@@ -3418,8 +3599,9 @@  discard block
 block discarded – undo
3418 3599
 	global $smcFunc, $cache_enable, $cacheAPI;
3419 3600
 	global $cache_hits, $cache_count, $db_show_debug;
3420 3601
 
3421
-	if (empty($cache_enable) || empty($cacheAPI))
3422
-		return;
3602
+	if (empty($cache_enable) || empty($cacheAPI)) {
3603
+			return;
3604
+	}
3423 3605
 
3424 3606
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3425 3607
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3432,12 +3614,14 @@  discard block
 block discarded – undo
3432 3614
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3433 3615
 	$cacheAPI->putData($key, $value, $ttl);
3434 3616
 
3435
-	if (function_exists('call_integration_hook'))
3436
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3617
+	if (function_exists('call_integration_hook')) {
3618
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3619
+	}
3437 3620
 
3438
-	if (isset($db_show_debug) && $db_show_debug === true)
3439
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3440
-}
3621
+	if (isset($db_show_debug) && $db_show_debug === true) {
3622
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3623
+	}
3624
+	}
3441 3625
 
3442 3626
 /**
3443 3627
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3453,8 +3637,9 @@  discard block
 block discarded – undo
3453 3637
 	global $smcFunc, $cache_enable, $cacheAPI;
3454 3638
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3455 3639
 
3456
-	if (empty($cache_enable) || empty($cacheAPI))
3457
-		return;
3640
+	if (empty($cache_enable) || empty($cacheAPI)) {
3641
+			return;
3642
+	}
3458 3643
 
3459 3644
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3460 3645
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3474,16 +3659,18 @@  discard block
 block discarded – undo
3474 3659
 
3475 3660
 		if (empty($value))
3476 3661
 		{
3477
-			if (!is_array($cache_misses))
3478
-				$cache_misses = array();
3662
+			if (!is_array($cache_misses)) {
3663
+							$cache_misses = array();
3664
+			}
3479 3665
 
3480 3666
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3481 3667
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3482 3668
 		}
3483 3669
 	}
3484 3670
 
3485
-	if (function_exists('call_integration_hook') && isset($value))
3486
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3671
+	if (function_exists('call_integration_hook') && isset($value)) {
3672
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3673
+	}
3487 3674
 
3488 3675
 	return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3489 3676
 }
@@ -3505,8 +3692,9 @@  discard block
 block discarded – undo
3505 3692
 	global $cacheAPI;
3506 3693
 
3507 3694
 	// If we can't get to the API, can't do this.
3508
-	if (empty($cacheAPI))
3509
-		return;
3695
+	if (empty($cacheAPI)) {
3696
+			return;
3697
+	}
3510 3698
 
3511 3699
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3512 3700
 	$cacheAPI->cleanCache($type);
@@ -3531,8 +3719,9 @@  discard block
 block discarded – undo
3531 3719
 	global $modSettings, $smcFunc, $image_proxy_enabled, $user_info;
3532 3720
 
3533 3721
 	// Come on!
3534
-	if (empty($data))
3535
-		return array();
3722
+	if (empty($data)) {
3723
+			return array();
3724
+	}
3536 3725
 
3537 3726
 	// Set a nice default var.
3538 3727
 	$image = '';
@@ -3540,11 +3729,11 @@  discard block
 block discarded – undo
3540 3729
 	// Gravatar has been set as mandatory!
3541 3730
 	if (!empty($modSettings['gravatarOverride']))
3542 3731
 	{
3543
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3544
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3545
-
3546
-		else if (!empty($data['email']))
3547
-			$image = get_gravatar_url($data['email']);
3732
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3733
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3734
+		} else if (!empty($data['email'])) {
3735
+					$image = get_gravatar_url($data['email']);
3736
+		}
3548 3737
 	}
3549 3738
 
3550 3739
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3556,54 +3745,60 @@  discard block
 block discarded – undo
3556 3745
 			// Gravatar.
3557 3746
 			if (stristr($data['avatar'], 'gravatar://'))
3558 3747
 			{
3559
-				if ($data['avatar'] == 'gravatar://')
3560
-					$image = get_gravatar_url($data['email']);
3561
-
3562
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3563
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3748
+				if ($data['avatar'] == 'gravatar://') {
3749
+									$image = get_gravatar_url($data['email']);
3750
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3751
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3752
+				}
3564 3753
 			}
3565 3754
 
3566 3755
 			// External url.
3567 3756
 			else
3568 3757
 			{
3569 3758
 				// Using ssl?
3570
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3571
-					$image = get_proxied_url($data['avatar']);
3759
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3760
+									$image = get_proxied_url($data['avatar']);
3761
+				}
3572 3762
 
3573 3763
 				// Just a plain external url.
3574
-				else
3575
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3764
+				else {
3765
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3766
+				}
3576 3767
 			}
3577 3768
 		}
3578 3769
 
3579 3770
 		// Perhaps this user has an attachment as avatar...
3580
-		else if (!empty($data['filename']))
3581
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3771
+		else if (!empty($data['filename'])) {
3772
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3773
+		}
3582 3774
 
3583 3775
 		// Right... no avatar... use our default image.
3584
-		else
3585
-			$image = $modSettings['avatar_url'] . '/default.png';
3776
+		else {
3777
+					$image = $modSettings['avatar_url'] . '/default.png';
3778
+		}
3586 3779
 	}
3587 3780
 
3588 3781
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3589 3782
 
3590 3783
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3591
-	if (!empty($image))
3592
-		return array(
3784
+	if (!empty($image)) {
3785
+			return array(
3593 3786
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3594 3787
 			'image' => '<img class="avatar" src="' . $image . '" />',
3595 3788
 			'href' => $image,
3596 3789
 			'url' => $image,
3597 3790
 		);
3791
+	}
3598 3792
 
3599 3793
 	// Fallback to make life easier for everyone...
3600
-	else
3601
-		return array(
3794
+	else {
3795
+			return array(
3602 3796
 			'name' => '',
3603 3797
 			'image' => '',
3604 3798
 			'href' => '',
3605 3799
 			'url' => '',
3606 3800
 		);
3607
-}
3801
+	}
3802
+	}
3608 3803
 
3609 3804
 ?>
3610 3805
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Themes.php 1 patch
Braces   +348 added lines, -271 removed lines patch added patch discarded remove patch
@@ -30,8 +30,9 @@  discard block
 block discarded – undo
30 30
  * @version 2.1 Beta 4
31 31
  */
32 32
 
33
-if (!defined('SMF'))
33
+if (!defined('SMF')) {
34 34
 	die('No direct access...');
35
+}
35 36
 
36 37
 /**
37 38
  * Subaction handler - manages the action and delegates control to the proper
@@ -103,12 +104,12 @@  discard block
 block discarded – undo
103 104
 	cache_put_data('minimized_css', null);
104 105
 
105 106
 	// Follow the sa or just go to administration.
106
-	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']]))
107
-		call_helper($subActions[$_GET['sa']]);
108
-
109
-	else
110
-		call_helper($subActions['admin']);
111
-}
107
+	if (isset($_GET['sa']) && !empty($subActions[$_GET['sa']])) {
108
+			call_helper($subActions[$_GET['sa']]);
109
+	} else {
110
+			call_helper($subActions['admin']);
111
+	}
112
+	}
112 113
 
113 114
 /**
114 115
  * This function allows administration of themes and their settings,
@@ -130,15 +131,16 @@  discard block
 block discarded – undo
130 131
 		checkSession();
131 132
 		validateToken('admin-tm');
132 133
 
133
-		if (isset($_POST['options']['known_themes']))
134
-			foreach ($_POST['options']['known_themes'] as $key => $id)
134
+		if (isset($_POST['options']['known_themes'])) {
135
+					foreach ($_POST['options']['known_themes'] as $key => $id)
135 136
 				$_POST['options']['known_themes'][$key] = (int) $id;
137
+		} else {
138
+					fatal_lang_error('themes_none_selectable', false);
139
+		}
136 140
 
137
-		else
138
-			fatal_lang_error('themes_none_selectable', false);
139
-
140
-		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes']))
141
-			fatal_lang_error('themes_default_selectable', false);
141
+		if (!in_array($_POST['options']['theme_guests'], $_POST['options']['known_themes'])) {
142
+					fatal_lang_error('themes_default_selectable', false);
143
+		}
142 144
 
143 145
 		// Commit the new settings.
144 146
 		updateSettings(array(
@@ -146,8 +148,9 @@  discard block
 block discarded – undo
146 148
 			'theme_guests' => $_POST['options']['theme_guests'],
147 149
 			'knownThemes' => implode(',', $_POST['options']['known_themes']),
148 150
 		));
149
-		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes']))
150
-			updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
151
+		if ((int) $_POST['theme_reset'] == 0 || in_array($_POST['theme_reset'], $_POST['options']['known_themes'])) {
152
+					updateMemberData(null, array('id_theme' => (int) $_POST['theme_reset']));
153
+		}
151 154
 
152 155
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=admin');
153 156
 	}
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	// Look for a non existent theme directory. (ie theme87.)
167 170
 	$theme_dir = $boarddir . '/Themes/theme';
168 171
 	$i = 1;
169
-	while (file_exists($theme_dir . $i))
170
-		$i++;
172
+	while (file_exists($theme_dir . $i)) {
173
+			$i++;
174
+	}
171 175
 
172 176
 	$context['new_theme_name'] = 'theme' . $i;
173 177
 
@@ -189,8 +193,9 @@  discard block
 block discarded – undo
189 193
 	loadLanguage('Admin');
190 194
 	isAllowedTo('admin_forum');
191 195
 
192
-	if (isset($_REQUEST['th']))
193
-		return SetThemeSettings();
196
+	if (isset($_REQUEST['th'])) {
197
+			return SetThemeSettings();
198
+	}
194 199
 
195 200
 	if (isset($_POST['save']))
196 201
 	{
@@ -274,12 +279,13 @@  discard block
 block discarded – undo
274 279
 		$context['themes'] = array();
275 280
 		while ($row = $smcFunc['db_fetch_assoc']($request))
276 281
 		{
277
-			if (!isset($context['themes'][$row['id_theme']]))
278
-				$context['themes'][$row['id_theme']] = array(
282
+			if (!isset($context['themes'][$row['id_theme']])) {
283
+							$context['themes'][$row['id_theme']] = array(
279 284
 					'id' => $row['id_theme'],
280 285
 					'num_default_options' => 0,
281 286
 					'num_members' => 0,
282 287
 				);
288
+			}
283 289
 			$context['themes'][$row['id_theme']][$row['variable']] = $row['value'];
284 290
 		}
285 291
 		$smcFunc['db_free_result']($request);
@@ -293,8 +299,9 @@  discard block
 block discarded – undo
293 299
 				'guest_member' => -1,
294 300
 			)
295 301
 		);
296
-		while ($row = $smcFunc['db_fetch_assoc']($request))
297
-			$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
302
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
303
+					$context['themes'][$row['id_theme']]['num_default_options'] = $row['value'];
304
+		}
298 305
 		$smcFunc['db_free_result']($request);
299 306
 
300 307
 		// Need to make sure we don't do custom fields.
@@ -305,8 +312,9 @@  discard block
 block discarded – undo
305 312
 			)
306 313
 		);
307 314
 		$customFields = array();
308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
309
-			$customFields[] = $row['col_name'];
315
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
316
+					$customFields[] = $row['col_name'];
317
+		}
310 318
 		$smcFunc['db_free_result']($request);
311 319
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
312 320
 
@@ -321,14 +329,16 @@  discard block
 block discarded – undo
321 329
 				'custom_fields' => empty($customFields) ? array() : $customFields,
322 330
 			)
323 331
 		);
324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
325
-			$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
332
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
333
+					$context['themes'][$row['id_theme']]['num_members'] = $row['value'];
334
+		}
326 335
 		$smcFunc['db_free_result']($request);
327 336
 
328 337
 		// There has to be a Settings template!
329
-		foreach ($context['themes'] as $k => $v)
330
-			if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
338
+		foreach ($context['themes'] as $k => $v) {
339
+					if (empty($v['theme_dir']) || (!file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])))
331 340
 				unset($context['themes'][$k]);
341
+		}
332 342
 
333 343
 		loadTemplate('Themes');
334 344
 		$context['sub_template'] = 'reset_list';
@@ -343,16 +353,19 @@  discard block
 block discarded – undo
343 353
 		checkSession();
344 354
 		validateToken('admin-sto');
345 355
 
346
-		if (empty($_POST['options']))
347
-			$_POST['options'] = array();
348
-		if (empty($_POST['default_options']))
349
-			$_POST['default_options'] = array();
356
+		if (empty($_POST['options'])) {
357
+					$_POST['options'] = array();
358
+		}
359
+		if (empty($_POST['default_options'])) {
360
+					$_POST['default_options'] = array();
361
+		}
350 362
 
351 363
 		// Set up the sql query.
352 364
 		$setValues = array();
353 365
 
354
-		foreach ($_POST['options'] as $opt => $val)
355
-			$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
366
+		foreach ($_POST['options'] as $opt => $val) {
367
+					$setValues[] = array(-1, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
368
+		}
356 369
 
357 370
 		$old_settings = array();
358 371
 		foreach ($_POST['default_options'] as $opt => $val)
@@ -366,8 +379,8 @@  discard block
 block discarded – undo
366 379
 		if (!empty($setValues))
367 380
 		{
368 381
 			// Are there options in non-default themes set that should be cleared?
369
-			if (!empty($old_settings))
370
-				$smcFunc['db_query']('', '
382
+			if (!empty($old_settings)) {
383
+							$smcFunc['db_query']('', '
371 384
 					DELETE FROM {db_prefix}themes
372 385
 					WHERE id_theme != {int:default_theme}
373 386
 						AND id_member = {int:guest_member}
@@ -378,6 +391,7 @@  discard block
 block discarded – undo
378 391
 						'old_settings' => $old_settings,
379 392
 					)
380 393
 				);
394
+			}
381 395
 
382 396
 			$smcFunc['db_insert']('replace',
383 397
 				'{db_prefix}themes',
@@ -391,8 +405,7 @@  discard block
 block discarded – undo
391 405
 		cache_put_data('theme_settings-1', null, 90);
392 406
 
393 407
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
394
-	}
395
-	elseif (isset($_POST['submit']) && $_POST['who'] == 1)
408
+	} elseif (isset($_POST['submit']) && $_POST['who'] == 1)
396 409
 	{
397 410
 		checkSession();
398 411
 		validateToken('admin-sto');
@@ -405,9 +418,9 @@  discard block
 block discarded – undo
405 418
 		$old_settings = array();
406 419
 		foreach ($_POST['default_options'] as $opt => $val)
407 420
 		{
408
-			if ($_POST['default_options_master'][$opt] == 0)
409
-				continue;
410
-			elseif ($_POST['default_options_master'][$opt] == 1)
421
+			if ($_POST['default_options_master'][$opt] == 0) {
422
+							continue;
423
+			} elseif ($_POST['default_options_master'][$opt] == 1)
411 424
 			{
412 425
 				// Delete then insert for ease of database compatibility!
413 426
 				$smcFunc['db_query']('substring', '
@@ -433,8 +446,7 @@  discard block
 block discarded – undo
433 446
 				);
434 447
 
435 448
 				$old_settings[] = $opt;
436
-			}
437
-			elseif ($_POST['default_options_master'][$opt] == 2)
449
+			} elseif ($_POST['default_options_master'][$opt] == 2)
438 450
 			{
439 451
 				$smcFunc['db_query']('', '
440 452
 					DELETE FROM {db_prefix}themes
@@ -449,8 +461,8 @@  discard block
 block discarded – undo
449 461
 		}
450 462
 
451 463
 		// Delete options from other themes.
452
-		if (!empty($old_settings))
453
-			$smcFunc['db_query']('', '
464
+		if (!empty($old_settings)) {
465
+					$smcFunc['db_query']('', '
454 466
 				DELETE FROM {db_prefix}themes
455 467
 				WHERE id_theme != {int:default_theme}
456 468
 					AND id_member > {int:no_member}
@@ -461,12 +473,13 @@  discard block
 block discarded – undo
461 473
 					'old_settings' => $old_settings,
462 474
 				)
463 475
 			);
476
+		}
464 477
 
465 478
 		foreach ($_POST['options'] as $opt => $val)
466 479
 		{
467
-			if ($_POST['options_master'][$opt] == 0)
468
-				continue;
469
-			elseif ($_POST['options_master'][$opt] == 1)
480
+			if ($_POST['options_master'][$opt] == 0) {
481
+							continue;
482
+			} elseif ($_POST['options_master'][$opt] == 1)
470 483
 			{
471 484
 				// Delete then insert for ease of database compatibility - again!
472 485
 				$smcFunc['db_query']('substring', '
@@ -491,8 +504,7 @@  discard block
 block discarded – undo
491 504
 						'value' => (is_array($val) ? implode(',', $val) : $val),
492 505
 					)
493 506
 				);
494
-			}
495
-			elseif ($_POST['options_master'][$opt] == 2)
507
+			} elseif ($_POST['options_master'][$opt] == 2)
496 508
 			{
497 509
 				$smcFunc['db_query']('', '
498 510
 					DELETE FROM {db_prefix}themes
@@ -509,8 +521,7 @@  discard block
 block discarded – undo
509 521
 		}
510 522
 
511 523
 		redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
512
-	}
513
-	elseif (!empty($_GET['who']) && $_GET['who'] == 2)
524
+	} elseif (!empty($_GET['who']) && $_GET['who'] == 2)
514 525
 	{
515 526
 		checkSession('get');
516 527
 		validateToken('admin-stor', 'request');
@@ -525,8 +536,9 @@  discard block
 block discarded – undo
525 536
 				)
526 537
 			);
527 538
 			$customFields = array();
528
-			while ($row = $smcFunc['db_fetch_assoc']($request))
529
-				$customFields[] = $row['col_name'];
539
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
540
+							$customFields[] = $row['col_name'];
541
+			}
530 542
 			$smcFunc['db_free_result']($request);
531 543
 		}
532 544
 		$customFieldsQuery = empty($customFields) ? '' : ('AND variable NOT IN ({array_string:custom_fields})');
@@ -581,13 +593,13 @@  discard block
 block discarded – undo
581 593
 			)
582 594
 		);
583 595
 		$context['theme_options'] = array();
584
-		while ($row = $smcFunc['db_fetch_assoc']($request))
585
-			$context['theme_options'][$row['variable']] = $row['value'];
596
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
597
+					$context['theme_options'][$row['variable']] = $row['value'];
598
+		}
586 599
 		$smcFunc['db_free_result']($request);
587 600
 
588 601
 		$context['theme_options_reset'] = false;
589
-	}
590
-	else
602
+	} else
591 603
 	{
592 604
 		$context['theme_options'] = array();
593 605
 		$context['theme_options_reset'] = true;
@@ -596,8 +608,9 @@  discard block
 block discarded – undo
596 608
 	foreach ($context['options'] as $i => $setting)
597 609
 	{
598 610
 		// Just skip separators
599
-		if (!is_array($setting))
600
-			continue;
611
+		if (!is_array($setting)) {
612
+					continue;
613
+		}
601 614
 
602 615
 		// Is this disabled?
603 616
 		if (isset($setting['enabled']) && $setting['enabled'] === false)
@@ -606,15 +619,17 @@  discard block
 block discarded – undo
606 619
 			continue;
607 620
 		}
608 621
 
609
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
610
-			$context['options'][$i]['type'] = 'checkbox';
611
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
612
-			$context['options'][$i]['type'] = 'number';
613
-		elseif ($setting['type'] == 'string')
614
-			$context['options'][$i]['type'] = 'text';
622
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
623
+					$context['options'][$i]['type'] = 'checkbox';
624
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
625
+					$context['options'][$i]['type'] = 'number';
626
+		} elseif ($setting['type'] == 'string') {
627
+					$context['options'][$i]['type'] = 'text';
628
+		}
615 629
 
616
-		if (isset($setting['options']))
617
-			$context['options'][$i]['type'] = 'list';
630
+		if (isset($setting['options'])) {
631
+					$context['options'][$i]['type'] = 'list';
632
+		}
618 633
 
619 634
 		$context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']];
620 635
 	}
@@ -639,8 +654,9 @@  discard block
 block discarded – undo
639 654
 {
640 655
 	global $txt, $context, $settings, $modSettings, $smcFunc;
641 656
 
642
-	if (empty($_GET['th']) && empty($_GET['id']))
643
-		return ThemeAdmin();
657
+	if (empty($_GET['th']) && empty($_GET['id'])) {
658
+			return ThemeAdmin();
659
+	}
644 660
 
645 661
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
646 662
 
@@ -651,8 +667,9 @@  discard block
 block discarded – undo
651 667
 	isAllowedTo('admin_forum');
652 668
 
653 669
 	// Validate inputs/user.
654
-	if (empty($_GET['th']))
655
-		fatal_lang_error('no_theme', false);
670
+	if (empty($_GET['th'])) {
671
+			fatal_lang_error('no_theme', false);
672
+	}
656 673
 
657 674
 	// Fetch the smiley sets...
658 675
 	$sets = explode(',', 'none,' . $modSettings['smiley_sets_known']);
@@ -660,8 +677,9 @@  discard block
 block discarded – undo
660 677
 	$context['smiley_sets'] = array(
661 678
 		'' => $txt['smileys_no_default']
662 679
 	);
663
-	foreach ($sets as $i => $set)
664
-		$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
680
+	foreach ($sets as $i => $set) {
681
+			$context['smiley_sets'][$set] = $smcFunc['htmlspecialchars']($set_names[$i]);
682
+	}
665 683
 
666 684
 	$old_id = $settings['theme_id'];
667 685
 	$old_settings = $settings;
@@ -686,8 +704,9 @@  discard block
 block discarded – undo
686 704
 	if (file_exists($settings['theme_dir'] . '/index.template.php'))
687 705
 	{
688 706
 		$file_contents = implode('', file($settings['theme_dir'] . '/index.template.php'));
689
-		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches))
690
-				eval('global $settings;' . $matches[0]);
707
+		if (preg_match('~\$settings\[\'theme_variants\'\]\s*=(.+?);~', $file_contents, $matches)) {
708
+						eval('global $settings;' . $matches[0]);
709
+		}
691 710
 	}
692 711
 
693 712
 	// Let mods hook into the theme settings.
@@ -699,37 +718,45 @@  discard block
 block discarded – undo
699 718
 		checkSession();
700 719
 		validateToken('admin-sts');
701 720
 
702
-		if (empty($_POST['options']))
703
-			$_POST['options'] = array();
704
-		if (empty($_POST['default_options']))
705
-			$_POST['default_options'] = array();
721
+		if (empty($_POST['options'])) {
722
+					$_POST['options'] = array();
723
+		}
724
+		if (empty($_POST['default_options'])) {
725
+					$_POST['default_options'] = array();
726
+		}
706 727
 
707 728
 		// Make sure items are cast correctly.
708 729
 		foreach ($context['theme_settings'] as $item)
709 730
 		{
710 731
 			// Disregard this item if this is just a separator.
711
-			if (!is_array($item))
712
-				continue;
732
+			if (!is_array($item)) {
733
+							continue;
734
+			}
713 735
 
714 736
 			foreach (array('options', 'default_options') as $option)
715 737
 			{
716
-				if (!isset($_POST[$option][$item['id']]))
717
-					continue;
738
+				if (!isset($_POST[$option][$item['id']])) {
739
+									continue;
740
+				}
718 741
 				// Checkbox.
719
-				elseif (empty($item['type']))
720
-					$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
742
+				elseif (empty($item['type'])) {
743
+									$_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
744
+				}
721 745
 				// Number
722
-				elseif ($item['type'] == 'number')
723
-					$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
746
+				elseif ($item['type'] == 'number') {
747
+									$_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
748
+				}
724 749
 			}
725 750
 		}
726 751
 
727 752
 		// Set up the sql query.
728 753
 		$inserts = array();
729
-		foreach ($_POST['options'] as $opt => $val)
730
-			$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
731
-		foreach ($_POST['default_options'] as $opt => $val)
732
-			$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
754
+		foreach ($_POST['options'] as $opt => $val) {
755
+					$inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
756
+		}
757
+		foreach ($_POST['default_options'] as $opt => $val) {
758
+					$inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
759
+		}
733 760
 		// If we're actually inserting something..
734 761
 		if (!empty($inserts))
735 762
 		{
@@ -755,8 +782,9 @@  discard block
 block discarded – undo
755 782
 
756 783
 	foreach ($settings as $setting => $dummy)
757 784
 	{
758
-		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs')))
759
-			$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
785
+		if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) {
786
+					$settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
787
+		}
760 788
 	}
761 789
 
762 790
 	$context['settings'] = $context['theme_settings'];
@@ -765,18 +793,21 @@  discard block
 block discarded – undo
765 793
 	foreach ($context['settings'] as $i => $setting)
766 794
 	{
767 795
 		// Separators are dummies, so leave them alone.
768
-		if (!is_array($setting))
769
-			continue;
796
+		if (!is_array($setting)) {
797
+					continue;
798
+		}
770 799
 
771
-		if (!isset($setting['type']) || $setting['type'] == 'bool')
772
-			$context['settings'][$i]['type'] = 'checkbox';
773
-		elseif ($setting['type'] == 'int' || $setting['type'] == 'integer')
774
-			$context['settings'][$i]['type'] = 'number';
775
-		elseif ($setting['type'] == 'string')
776
-			$context['settings'][$i]['type'] = 'text';
800
+		if (!isset($setting['type']) || $setting['type'] == 'bool') {
801
+					$context['settings'][$i]['type'] = 'checkbox';
802
+		} elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
803
+					$context['settings'][$i]['type'] = 'number';
804
+		} elseif ($setting['type'] == 'string') {
805
+					$context['settings'][$i]['type'] = 'text';
806
+		}
777 807
 
778
-		if (isset($setting['options']))
779
-			$context['settings'][$i]['type'] = 'list';
808
+		if (isset($setting['options'])) {
809
+					$context['settings'][$i]['type'] = 'list';
810
+		}
780 811
 
781 812
 		$context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']];
782 813
 	}
@@ -829,8 +860,9 @@  discard block
 block discarded – undo
829 860
 	$themeID = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
830 861
 
831 862
 	// You can't delete the default theme!
832
-	if ($themeID == 1)
833
-		fatal_lang_error('no_access', false);
863
+	if ($themeID == 1) {
864
+			fatal_lang_error('no_access', false);
865
+	}
834 866
 
835 867
 	$theme_info = get_single_theme($themeID);
836 868
 
@@ -838,8 +870,9 @@  discard block
 block discarded – undo
838 870
 	remove_theme($themeID);
839 871
 
840 872
 	// And remove all its files and folders too.
841
-	if (!empty($theme_info) && !empty($theme_info['theme_dir']))
842
-		remove_dir($theme_info['theme_dir']);
873
+	if (!empty($theme_info) && !empty($theme_info['theme_dir'])) {
874
+			remove_dir($theme_info['theme_dir']);
875
+	}
843 876
 
844 877
 	// Go back to the list page.
845 878
 	redirectexit('action=admin;area=theme;sa=list;' . $context['session_var'] . '=' . $context['session_id'] . ';done=removing');
@@ -864,12 +897,14 @@  discard block
 block discarded – undo
864 897
 	$enableThemes = explode(',', $modSettings['enableThemes']);
865 898
 
866 899
 	// Are we disabling it?
867
-	if (isset($_GET['disabled']))
868
-		$enableThemes = array_diff($enableThemes, array($themeID));
900
+	if (isset($_GET['disabled'])) {
901
+			$enableThemes = array_diff($enableThemes, array($themeID));
902
+	}
869 903
 
870 904
 	// Nope? then enable it!
871
-	else
872
-		$enableThemes[] = (string) $themeID;
905
+	else {
906
+			$enableThemes[] = (string) $themeID;
907
+	}
873 908
 
874 909
 	// Update the setting.
875 910
 	$enableThemes = strtr(implode(',', $enableThemes), array(',,' => ','));
@@ -904,18 +939,21 @@  discard block
 block discarded – undo
904 939
 
905 940
 	$_SESSION['id_theme'] = 0;
906 941
 
907
-	if (isset($_GET['id']))
908
-		$_GET['th'] = $_GET['id'];
942
+	if (isset($_GET['id'])) {
943
+			$_GET['th'] = $_GET['id'];
944
+	}
909 945
 
910 946
 	// Saving a variant cause JS doesn't work - pretend it did ;)
911 947
 	if (isset($_POST['save']))
912 948
 	{
913 949
 		// Which theme?
914
-		foreach ($_POST['save'] as $k => $v)
915
-			$_GET['th'] = (int) $k;
950
+		foreach ($_POST['save'] as $k => $v) {
951
+					$_GET['th'] = (int) $k;
952
+		}
916 953
 
917
-		if (isset($_POST['vrt'][$k]))
918
-			$_GET['vrt'] = $_POST['vrt'][$k];
954
+		if (isset($_POST['vrt'][$k])) {
955
+					$_GET['vrt'] = $_POST['vrt'][$k];
956
+		}
919 957
 	}
920 958
 
921 959
 	// Have we made a decision, or are we just browsing?
@@ -1004,10 +1042,10 @@  discard block
 block discarded – undo
1004 1042
 				);
1005 1043
 				cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90);
1006 1044
 
1007
-				if ($user_info['id'] == $_REQUEST['u'])
1008
-					$_SESSION['id_variant'] = 0;
1009
-			}
1010
-			elseif ($_GET['th'] == 0)
1045
+				if ($user_info['id'] == $_REQUEST['u']) {
1046
+									$_SESSION['id_variant'] = 0;
1047
+				}
1048
+			} elseif ($_GET['th'] == 0)
1011 1049
 			{
1012 1050
 				// Remove any custom variants.
1013 1051
 				$smcFunc['db_query']('', '
@@ -1088,12 +1126,13 @@  discard block
 block discarded – undo
1088 1126
 		);
1089 1127
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1090 1128
 		{
1091
-			if (!isset($context['available_themes'][$row['id_theme']]))
1092
-				$context['available_themes'][$row['id_theme']] = array(
1129
+			if (!isset($context['available_themes'][$row['id_theme']])) {
1130
+							$context['available_themes'][$row['id_theme']] = array(
1093 1131
 					'id' => $row['id_theme'],
1094 1132
 					'selected' => $context['current_theme'] == $row['id_theme'],
1095 1133
 					'num_users' => 0
1096 1134
 				);
1135
+			}
1097 1136
 			$context['available_themes'][$row['id_theme']][$row['variable']] = $row['value'];
1098 1137
 		}
1099 1138
 		$smcFunc['db_free_result']($request);
@@ -1106,9 +1145,9 @@  discard block
 block discarded – undo
1106 1145
 			'num_users' => 0
1107 1146
 		);
1108 1147
 		$guest_theme = 0;
1148
+	} else {
1149
+			$guest_theme = $modSettings['theme_guests'];
1109 1150
 	}
1110
-	else
1111
-		$guest_theme = $modSettings['theme_guests'];
1112 1151
 
1113 1152
 	$request = $smcFunc['db_query']('', '
1114 1153
 		SELECT id_theme, COUNT(*) AS the_count
@@ -1121,15 +1160,17 @@  discard block
 block discarded – undo
1121 1160
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1122 1161
 	{
1123 1162
 		// Figure out which theme it is they are REALLY using.
1124
-		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes'])))
1125
-			$row['id_theme'] = $guest_theme;
1126
-		elseif (empty($modSettings['theme_allow']))
1127
-			$row['id_theme'] = $guest_theme;
1163
+		if (!empty($modSettings['knownThemes']) && !in_array($row['id_theme'], explode(',', $modSettings['knownThemes']))) {
1164
+					$row['id_theme'] = $guest_theme;
1165
+		} elseif (empty($modSettings['theme_allow'])) {
1166
+					$row['id_theme'] = $guest_theme;
1167
+		}
1128 1168
 
1129
-		if (isset($context['available_themes'][$row['id_theme']]))
1130
-			$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1131
-		else
1132
-			$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1169
+		if (isset($context['available_themes'][$row['id_theme']])) {
1170
+					$context['available_themes'][$row['id_theme']]['num_users'] += $row['the_count'];
1171
+		} else {
1172
+					$context['available_themes'][$guest_theme]['num_users'] += $row['the_count'];
1173
+		}
1133 1174
 	}
1134 1175
 	$smcFunc['db_free_result']($request);
1135 1176
 
@@ -1148,8 +1189,9 @@  discard block
 block discarded – undo
1148 1189
 				'id_member' => isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? array(-1, $context['current_member']) : array(-1),
1149 1190
 			)
1150 1191
 		);
1151
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1152
-			$variant_preferences[$row['id_theme']] = $row['value'];
1192
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1193
+					$variant_preferences[$row['id_theme']] = $row['value'];
1194
+		}
1153 1195
 		$smcFunc['db_free_result']($request);
1154 1196
 	}
1155 1197
 
@@ -1160,17 +1202,18 @@  discard block
 block discarded – undo
1160 1202
 	foreach ($context['available_themes'] as $id_theme => $theme_data)
1161 1203
 	{
1162 1204
 		// Don't try to load the forum or board default theme's data... it doesn't have any!
1163
-		if ($id_theme == 0)
1164
-			continue;
1205
+		if ($id_theme == 0) {
1206
+					continue;
1207
+		}
1165 1208
 
1166 1209
 		// The thumbnail needs the correct path.
1167 1210
 		$settings['images_url'] = &$theme_data['images_url'];
1168 1211
 
1169
-		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php'))
1170
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1171
-		elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php'))
1172
-			include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1173
-		else
1212
+		if (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php')) {
1213
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $user_info['language'] . '.php');
1214
+		} elseif (file_exists($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php')) {
1215
+					include($theme_data['theme_dir'] . '/languages/Settings.' . $language . '.php');
1216
+		} else
1174 1217
 		{
1175 1218
 			$txt['theme_thumbnail_href'] = $theme_data['images_url'] . '/thumbnail.png';
1176 1219
 			$txt['theme_description'] = '';
@@ -1195,15 +1238,17 @@  discard block
 block discarded – undo
1195 1238
 					loadLanguage('Settings');
1196 1239
 
1197 1240
 					$context['available_themes'][$id_theme]['variants'] = array();
1198
-					foreach ($settings['theme_variants'] as $variant)
1199
-						$context['available_themes'][$id_theme]['variants'][$variant] = array(
1241
+					foreach ($settings['theme_variants'] as $variant) {
1242
+											$context['available_themes'][$id_theme]['variants'][$variant] = array(
1200 1243
 							'label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant,
1201 1244
 							'thumbnail' => !file_exists($theme_data['theme_dir'] . '/images/thumbnail.png') || file_exists($theme_data['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $theme_data['images_url'] . '/thumbnail_' . $variant . '.png' : ($theme_data['images_url'] . '/thumbnail.png'),
1202 1245
 						);
1246
+					}
1203 1247
 
1204 1248
 					$context['available_themes'][$id_theme]['selected_variant'] = isset($_GET['vrt']) ? $_GET['vrt'] : (!empty($variant_preferences[$id_theme]) ? $variant_preferences[$id_theme] : (!empty($settings['default_variant']) ? $settings['default_variant'] : $settings['theme_variants'][0]));
1205
-					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail']))
1206
-						$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1249
+					if (!isset($context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'])) {
1250
+											$context['available_themes'][$id_theme]['selected_variant'] = $settings['theme_variants'][0];
1251
+					}
1207 1252
 
1208 1253
 					$context['available_themes'][$id_theme]['thumbnail_href'] = $context['available_themes'][$id_theme]['variants'][$context['available_themes'][$id_theme]['selected_variant']]['thumbnail'];
1209 1254
 					// Allow themes to override the text.
@@ -1219,8 +1264,9 @@  discard block
 block discarded – undo
1219 1264
 	// As long as we're not doing the default theme...
1220 1265
 	if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0)
1221 1266
 	{
1222
-		if ($guest_theme != 0)
1223
-			$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1267
+		if ($guest_theme != 0) {
1268
+					$context['available_themes'][0] = $context['available_themes'][$guest_theme];
1269
+		}
1224 1270
 
1225 1271
 		$context['available_themes'][0]['id'] = 0;
1226 1272
 		$context['available_themes'][0]['name'] = $txt['theme_forum_default'];
@@ -1269,14 +1315,16 @@  discard block
 block discarded – undo
1269 1315
 		$action = $smcFunc['htmlspecialchars'](trim($_GET['do']));
1270 1316
 
1271 1317
 		// Got any info from the specific form?
1272
-		if (!isset($_POST['save_' . $action]))
1273
-			fatal_lang_error('theme_install_no_action', false);
1318
+		if (!isset($_POST['save_' . $action])) {
1319
+					fatal_lang_error('theme_install_no_action', false);
1320
+		}
1274 1321
 
1275 1322
 		validateToken('admin-t-' . $action);
1276 1323
 
1277 1324
 		// Hopefully the themes directory is writable, or we might have a problem.
1278
-		if (!is_writable($themedir))
1279
-			fatal_lang_error('theme_install_write_error', 'critical');
1325
+		if (!is_writable($themedir)) {
1326
+					fatal_lang_error('theme_install_write_error', 'critical');
1327
+		}
1280 1328
 
1281 1329
 		// Call the function and handle the result.
1282 1330
 		$result = $subActions[$action]();
@@ -1291,9 +1339,10 @@  discard block
 block discarded – undo
1291 1339
 	}
1292 1340
 
1293 1341
 	// Nope, show a nice error.
1294
-	else
1295
-		fatal_lang_error('theme_install_no_action', false);
1296
-}
1342
+	else {
1343
+			fatal_lang_error('theme_install_no_action', false);
1344
+	}
1345
+	}
1297 1346
 
1298 1347
 /**
1299 1348
  * Installs a theme from a theme package.
@@ -1309,8 +1358,9 @@  discard block
 block discarded – undo
1309 1358
 	$dirtemp = $themedir . '/temp';
1310 1359
 
1311 1360
 	// Make sure the temp dir doesn't already exist
1312
-	if (file_exists($dirtemp))
1313
-		remove_dir($dirtemp);
1361
+	if (file_exists($dirtemp)) {
1362
+			remove_dir($dirtemp);
1363
+	}
1314 1364
 
1315 1365
 	// Create the temp dir.
1316 1366
 	mkdir($dirtemp, 0777);
@@ -1322,17 +1372,20 @@  discard block
 block discarded – undo
1322 1372
 		smf_chmod($dirtemp, '0755');
1323 1373
 
1324 1374
 		// How about now?
1325
-		if (!is_writable($dirtemp))
1326
-			fatal_lang_error('theme_install_write_error', 'critical');
1375
+		if (!is_writable($dirtemp)) {
1376
+					fatal_lang_error('theme_install_write_error', 'critical');
1377
+		}
1327 1378
 	}
1328 1379
 
1329 1380
 	// This happens when the admin session is gone and the user has to login again.
1330
-	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz']))
1331
-		redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1381
+	if (!isset($_FILES) || !isset($_FILES['theme_gz']) || empty($_FILES['theme_gz'])) {
1382
+			redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
1383
+	}
1332 1384
 
1333 1385
 	// Another error check layer, something went wrong with the upload.
1334
-	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0)
1335
-		fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1386
+	if (isset($_FILES['theme_gz']['error']) && $_FILES['theme_gz']['error'] != 0) {
1387
+			fatal_lang_error('theme_install_error_file_' . $_FILES['theme_gz']['error'], false);
1388
+	}
1336 1389
 
1337 1390
 	// Get the theme's name.
1338 1391
 	$name = pathinfo($_FILES['theme_gz']['name'], PATHINFO_FILENAME);
@@ -1363,11 +1416,10 @@  discard block
 block discarded – undo
1363 1416
 
1364 1417
 		// return all the info.
1365 1418
 		return $context['to_install'];
1419
+	} else {
1420
+			fatal_lang_error('theme_install_error_title', false);
1421
+	}
1366 1422
 	}
1367
-
1368
-	else
1369
-		fatal_lang_error('theme_install_error_title', false);
1370
-}
1371 1423
 
1372 1424
 /**
1373 1425
  * Makes a copy from the default theme, assigns a name for it and installs it.
@@ -1381,15 +1433,17 @@  discard block
 block discarded – undo
1381 1433
 	global $forum_version;
1382 1434
 
1383 1435
 	// There's gotta be something to work with.
1384
-	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy']))
1385
-		fatal_lang_error('theme_install_error_title', false);
1436
+	if (!isset($_REQUEST['copy']) || empty($_REQUEST['copy'])) {
1437
+			fatal_lang_error('theme_install_error_title', false);
1438
+	}
1386 1439
 
1387 1440
 	// Get a cleaner version.
1388 1441
 	$name = preg_replace('~[^A-Za-z0-9_\- ]~', '', $_REQUEST['copy']);
1389 1442
 
1390 1443
 	// Is there a theme already named like this?
1391
-	if (file_exists($themedir . '/' . $name))
1392
-		fatal_lang_error('theme_install_already_dir', false);
1444
+	if (file_exists($themedir . '/' . $name)) {
1445
+			fatal_lang_error('theme_install_already_dir', false);
1446
+	}
1393 1447
 
1394 1448
 	// This is a brand new theme so set all possible values.
1395 1449
 	$context['to_install'] = array(
@@ -1409,8 +1463,9 @@  discard block
 block discarded – undo
1409 1463
 
1410 1464
 	// Buy some time.
1411 1465
 	@set_time_limit(600);
1412
-	if (function_exists('apache_reset_timeout'))
1413
-		@apache_reset_timeout();
1466
+	if (function_exists('apache_reset_timeout')) {
1467
+			@apache_reset_timeout();
1468
+	}
1414 1469
 
1415 1470
 	// Create subdirectories for css and javascript files.
1416 1471
 	mkdir($context['to_install']['theme_dir'] . '/css', 0777);
@@ -1446,12 +1501,13 @@  discard block
 block discarded – undo
1446 1501
 
1447 1502
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1448 1503
 	{
1449
-		if ($row['variable'] == 'theme_templates')
1450
-			$theme_templates = $row['value'];
1451
-		elseif ($row['variable'] == 'theme_layers')
1452
-			$theme_layers = $row['value'];
1453
-		else
1454
-			continue;
1504
+		if ($row['variable'] == 'theme_templates') {
1505
+					$theme_templates = $row['value'];
1506
+		} elseif ($row['variable'] == 'theme_layers') {
1507
+					$theme_layers = $row['value'];
1508
+		} else {
1509
+					continue;
1510
+		}
1455 1511
 	}
1456 1512
 
1457 1513
 	$smcFunc['db_free_result']($request);
@@ -1510,12 +1566,14 @@  discard block
 block discarded – undo
1510 1566
 	global $themedir, $themeurl, $context;
1511 1567
 
1512 1568
 	// Cannot use the theme dir as a theme dir.
1513
-	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir))
1514
-		fatal_lang_error('theme_install_invalid_dir', false);
1569
+	if (!isset($_REQUEST['theme_dir']) || empty($_REQUEST['theme_dir']) || rtrim(realpath($_REQUEST['theme_dir']), '/\\') == realpath($themedir)) {
1570
+			fatal_lang_error('theme_install_invalid_dir', false);
1571
+	}
1515 1572
 
1516 1573
 	// Check is there is "something" on the dir.
1517
-	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml'))
1518
-		fatal_lang_error('theme_install_error', false);
1574
+	elseif (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) {
1575
+			fatal_lang_error('theme_install_error', false);
1576
+	}
1519 1577
 
1520 1578
 	$name = basename($_REQUEST['theme_dir']);
1521 1579
 	$name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);
@@ -1559,24 +1617,27 @@  discard block
 block discarded – undo
1559 1617
 	}
1560 1618
 
1561 1619
 	// Any special layers?
1562
-	if (isset($settings['catch_action']['layers']))
1563
-		$context['template_layers'] = $settings['catch_action']['layers'];
1620
+	if (isset($settings['catch_action']['layers'])) {
1621
+			$context['template_layers'] = $settings['catch_action']['layers'];
1622
+	}
1564 1623
 
1565 1624
 	// Any function to call?
1566 1625
 	if (isset($settings['catch_action']['function']))
1567 1626
 	{
1568 1627
 		$hook = $settings['catch_action']['function'];
1569 1628
 
1570
-		if (!isset($settings['catch_action']['filename']))
1571
-			$settings['catch_action']['filename'] = '';
1629
+		if (!isset($settings['catch_action']['filename'])) {
1630
+					$settings['catch_action']['filename'] = '';
1631
+		}
1572 1632
 
1573 1633
 		add_integration_function('integrate_wrap_action', $hook, false, $settings['catch_action']['filename'], false);
1574 1634
 		call_integration_hook('integrate_wrap_action');
1575 1635
 	}
1576 1636
 	// And finally, the main sub template ;).
1577
-	if (isset($settings['catch_action']['sub_template']))
1578
-		$context['sub_template'] = $settings['catch_action']['sub_template'];
1579
-}
1637
+	if (isset($settings['catch_action']['sub_template'])) {
1638
+			$context['sub_template'] = $settings['catch_action']['sub_template'];
1639
+	}
1640
+	}
1580 1641
 
1581 1642
 /**
1582 1643
  * Set an option via javascript.
@@ -1595,12 +1656,14 @@  discard block
 block discarded – undo
1595 1656
 	checkSession('get');
1596 1657
 
1597 1658
 	// This good-for-nothing pixel is being used to keep the session alive.
1598
-	if (empty($_GET['var']) || !isset($_GET['val']))
1599
-		redirectexit($settings['images_url'] . '/blank.png');
1659
+	if (empty($_GET['var']) || !isset($_GET['val'])) {
1660
+			redirectexit($settings['images_url'] . '/blank.png');
1661
+	}
1600 1662
 
1601 1663
 	// Sorry, guests can't go any further than this.
1602
-	if ($user_info['is_guest'] || $user_info['id'] == 0)
1603
-		obExit(false);
1664
+	if ($user_info['is_guest'] || $user_info['id'] == 0) {
1665
+			obExit(false);
1666
+	}
1604 1667
 
1605 1668
 	$reservedVars = array(
1606 1669
 		'actual_theme_url',
@@ -1623,8 +1686,9 @@  discard block
 block discarded – undo
1623 1686
 	);
1624 1687
 
1625 1688
 	// Can't change reserved vars.
1626
-	if (in_array(strtolower($_GET['var']), $reservedVars))
1627
-		redirectexit($settings['images_url'] . '/blank.png');
1689
+	if (in_array(strtolower($_GET['var']), $reservedVars)) {
1690
+			redirectexit($settings['images_url'] . '/blank.png');
1691
+	}
1628 1692
 
1629 1693
 	// Use a specific theme?
1630 1694
 	if (isset($_GET['th']) || isset($_GET['id']))
@@ -1640,8 +1704,9 @@  discard block
 block discarded – undo
1640 1704
 	{
1641 1705
 		$options['admin_preferences'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array();
1642 1706
 		// New thingy...
1643
-		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5)
1644
-			$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1707
+		if (isset($_GET['admin_key']) && strlen($_GET['admin_key']) < 5) {
1708
+					$options['admin_preferences'][$_GET['admin_key']] = $_GET['val'];
1709
+		}
1645 1710
 
1646 1711
 		// Change the value to be something nice,
1647 1712
 		$_GET['val'] = $smcFunc['json_encode']($options['admin_preferences']);
@@ -1671,8 +1736,9 @@  discard block
 block discarded – undo
1671 1736
 	global $context, $scripturl, $boarddir, $smcFunc, $txt;
1672 1737
 
1673 1738
 	// @todo Should this be removed?
1674
-	if (isset($_REQUEST['preview']))
1675
-		die('die() with fire');
1739
+	if (isset($_REQUEST['preview'])) {
1740
+			die('die() with fire');
1741
+	}
1676 1742
 
1677 1743
 	isAllowedTo('admin_forum');
1678 1744
 	loadTemplate('Themes');
@@ -1686,11 +1752,11 @@  discard block
 block discarded – undo
1686 1752
 		foreach ($context['themes'] as $key => $theme)
1687 1753
 		{
1688 1754
 			// There has to be a Settings template!
1689
-			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css'))
1690
-				unset($context['themes'][$key]);
1691
-
1692
-			else
1693
-				$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1755
+			if (!file_exists($theme['theme_dir'] . '/index.template.php') && !file_exists($theme['theme_dir'] . '/css/index.css')) {
1756
+							unset($context['themes'][$key]);
1757
+			} else {
1758
+							$context['themes'][$key]['can_edit_style'] = file_exists($theme['theme_dir'] . '/css/index.css');
1759
+			}
1694 1760
 		}
1695 1761
 
1696 1762
 		$context['sub_template'] = 'edit_list';
@@ -1705,22 +1771,24 @@  discard block
 block discarded – undo
1705 1771
 	$context['theme_id'] = $currentTheme['id'];
1706 1772
 	$context['browse_title'] = sprintf($txt['themeadmin_browsing_theme'], $currentTheme['name']);
1707 1773
 
1708
-	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css'))
1709
-		fatal_lang_error('theme_edit_missing', false);
1774
+	if (!file_exists($currentTheme['theme_dir'] . '/index.template.php') && !file_exists($currentTheme['theme_dir'] . '/css/index.css')) {
1775
+			fatal_lang_error('theme_edit_missing', false);
1776
+	}
1710 1777
 
1711 1778
 	if (!isset($_REQUEST['filename']))
1712 1779
 	{
1713 1780
 		if (isset($_GET['directory']))
1714 1781
 		{
1715
-			if (substr($_GET['directory'], 0, 1) == '.')
1716
-				$_GET['directory'] = '';
1717
-			else
1782
+			if (substr($_GET['directory'], 0, 1) == '.') {
1783
+							$_GET['directory'] = '';
1784
+			} else
1718 1785
 			{
1719 1786
 				$_GET['directory'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_GET['directory']);
1720 1787
 
1721 1788
 				$temp = realpath($currentTheme['theme_dir'] . '/' . $_GET['directory']);
1722
-				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1723
-					$_GET['directory'] = '';
1789
+				if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1790
+									$_GET['directory'] = '';
1791
+				}
1724 1792
 			}
1725 1793
 		}
1726 1794
 
@@ -1739,44 +1807,47 @@  discard block
 block discarded – undo
1739 1807
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $temp,
1740 1808
 				'size' => '',
1741 1809
 			));
1810
+		} else {
1811
+					$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1742 1812
 		}
1743
-		else
1744
-			$context['theme_files'] = get_file_listing($currentTheme['theme_dir'], '');
1745 1813
 		
1746 1814
 		// Do not list minified_ files
1747 1815
 		foreach($context['theme_files'] as $key=>$file)
1748 1816
 		{
1749
-			if(strpos($file['filename'], 'minified_') !== FALSE)
1750
-				unset($context['theme_files'][$key]);
1817
+			if(strpos($file['filename'], 'minified_') !== FALSE) {
1818
+							unset($context['theme_files'][$key]);
1819
+			}
1751 1820
 		}
1752 1821
 
1753 1822
 		$context['sub_template'] = 'edit_browse';
1754 1823
 
1755 1824
 		return;
1756
-	}
1757
-	else
1825
+	} else
1758 1826
 	{
1759
-		if (substr($_REQUEST['filename'], 0, 1) == '.')
1760
-			$_REQUEST['filename'] = '';
1761
-		else
1827
+		if (substr($_REQUEST['filename'], 0, 1) == '.') {
1828
+					$_REQUEST['filename'] = '';
1829
+		} else
1762 1830
 		{
1763 1831
 			$_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']);
1764 1832
 
1765 1833
 			$temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1766
-			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
1767
-				$_REQUEST['filename'] = '';
1834
+			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir'])) {
1835
+							$_REQUEST['filename'] = '';
1836
+			}
1768 1837
 		}
1769 1838
 
1770
-		if (empty($_REQUEST['filename']))
1771
-			fatal_lang_error('theme_edit_missing', false);
1839
+		if (empty($_REQUEST['filename'])) {
1840
+					fatal_lang_error('theme_edit_missing', false);
1841
+		}
1772 1842
 	}
1773 1843
 
1774 1844
 	if (isset($_POST['save']))
1775 1845
 	{
1776 1846
 		if (checkSession('post', '', false) == '' && validateToken('admin-te-' . md5($_GET['th'] . '-' . $_REQUEST['filename']), 'post', false) == true)
1777 1847
 		{
1778
-			if (is_array($_POST['entire_file']))
1779
-				$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1848
+			if (is_array($_POST['entire_file'])) {
1849
+							$_POST['entire_file'] = implode("\n", $_POST['entire_file']);
1850
+			}
1780 1851
 
1781 1852
 			$_POST['entire_file'] = rtrim(strtr($_POST['entire_file'], array("\r" => '', '   ' => "\t")));
1782 1853
 
@@ -1788,10 +1859,11 @@  discard block
 block discarded – undo
1788 1859
 				fclose($fp);
1789 1860
 
1790 1861
 				$error = @file_get_contents($currentTheme['theme_url'] . '/tmp_' . session_id() . '.php');
1791
-				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0)
1792
-					$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1793
-				else
1794
-					unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1862
+				if (preg_match('~ <b>(\d+)</b><br( /)?' . '>$~i', $error) != 0) {
1863
+									$error_file = $currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php';
1864
+				} else {
1865
+									unlink($currentTheme['theme_dir'] . '/tmp_' . session_id() . '.php');
1866
+				}
1795 1867
 			}
1796 1868
 
1797 1869
 			if (!isset($error_file))
@@ -1812,10 +1884,11 @@  discard block
 block discarded – undo
1812 1884
 			$context['sub_template'] = 'edit_file';
1813 1885
 
1814 1886
 			// Recycle the submitted data.
1815
-			if (is_array($_POST['entire_file']))
1816
-				$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1817
-			else
1818
-				$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1887
+			if (is_array($_POST['entire_file'])) {
1888
+							$context['entire_file'] = $smcFunc['htmlspecialchars'](implode("\n", $_POST['entire_file']));
1889
+			} else {
1890
+							$context['entire_file'] = $smcFunc['htmlspecialchars']($_POST['entire_file']);
1891
+			}
1819 1892
 
1820 1893
 			$context['edit_filename'] = $smcFunc['htmlspecialchars']($_POST['filename']);
1821 1894
 
@@ -1838,17 +1911,17 @@  discard block
 block discarded – undo
1838 1911
 		$context['sub_template'] = 'edit_style';
1839 1912
 
1840 1913
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(file_get_contents($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']), array("\t" => '   ')));
1841
-	}
1842
-	elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1914
+	} elseif (substr($_REQUEST['filename'], -13) == '.template.php')
1843 1915
 	{
1844 1916
 		$context['sub_template'] = 'edit_template';
1845 1917
 
1846
-		if (!isset($error_file))
1847
-			$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1848
-		else
1918
+		if (!isset($error_file)) {
1919
+					$file_data = file($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
1920
+		} else
1849 1921
 		{
1850
-			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0)
1851
-				$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1922
+			if (preg_match('~(<b>.+?</b>:.+?<b>).+?(</b>.+?<b>\d+</b>)<br( /)?' . '>$~i', $error, $match) != 0) {
1923
+							$context['parse_error'] = $match[1] . $_REQUEST['filename'] . $match[2];
1924
+			}
1852 1925
 			$file_data = file($error_file);
1853 1926
 			unlink($error_file);
1854 1927
 		}
@@ -1862,8 +1935,9 @@  discard block
 block discarded – undo
1862 1935
 				// Try to format the functions a little nicer...
1863 1936
 				$context['file_parts'][$j]['data'] = trim($context['file_parts'][$j]['data']) . "\n";
1864 1937
 
1865
-				if (empty($context['file_parts'][$j]['lines']))
1866
-					unset($context['file_parts'][$j]);
1938
+				if (empty($context['file_parts'][$j]['lines'])) {
1939
+									unset($context['file_parts'][$j]);
1940
+				}
1867 1941
 				$context['file_parts'][++$j] = array('lines' => 0, 'line' => $i + 1, 'data' => '');
1868 1942
 			}
1869 1943
 
@@ -1872,8 +1946,7 @@  discard block
 block discarded – undo
1872 1946
 		}
1873 1947
 
1874 1948
 		$context['entire_file'] = $smcFunc['htmlspecialchars'](strtr(implode('', $file_data), array("\t" => '   ')));
1875
-	}
1876
-	else
1949
+	} else
1877 1950
 	{
1878 1951
 		$context['sub_template'] = 'edit_file';
1879 1952
 
@@ -1899,8 +1972,9 @@  discard block
 block discarded – undo
1899 1972
 
1900 1973
 	$_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
1901 1974
 
1902
-	if (empty($_GET['th']))
1903
-		fatal_lang_error('theme_install_invalid_id');
1975
+	if (empty($_GET['th'])) {
1976
+			fatal_lang_error('theme_install_invalid_id');
1977
+	}
1904 1978
 
1905 1979
 	// Get the theme info.
1906 1980
 	$theme = get_single_theme($_GET['th']);
@@ -1908,25 +1982,24 @@  discard block
 block discarded – undo
1908 1982
 
1909 1983
 	if (isset($_REQUEST['template']) && preg_match('~[\./\\\\:\0]~', $_REQUEST['template']) == 0)
1910 1984
 	{
1911
-		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'))
1912
-			$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1913
-
1914
-		else
1915
-			fatal_lang_error('no_access', false);
1985
+		if (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) {
1986
+					$filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php';
1987
+		} else {
1988
+					fatal_lang_error('no_access', false);
1989
+		}
1916 1990
 
1917 1991
 		$fp = fopen($theme['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w');
1918 1992
 		fwrite($fp, file_get_contents($filename));
1919 1993
 		fclose($fp);
1920 1994
 
1921 1995
 		redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy');
1922
-	}
1923
-	elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1996
+	} elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\./\\\\:\0]\.[^\./\\\\:\0]$~', $_REQUEST['lang_file']) != 0)
1924 1997
 	{
1925
-		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'))
1926
-			$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
1927
-
1928
-		else
1929
-			fatal_lang_error('no_access', false);
1998
+		if (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) {
1999
+					$filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php';
2000
+		} else {
2001
+					fatal_lang_error('no_access', false);
2002
+		}
1930 2003
 
1931 2004
 		$fp = fopen($theme['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w');
1932 2005
 		fwrite($fp, file_get_contents($filename));
@@ -1941,16 +2014,18 @@  discard block
 block discarded – undo
1941 2014
 	$dir = dir($settings['default_theme_dir']);
1942 2015
 	while ($entry = $dir->read())
1943 2016
 	{
1944
-		if (substr($entry, -13) == '.template.php')
1945
-			$templates[] = substr($entry, 0, -13);
2017
+		if (substr($entry, -13) == '.template.php') {
2018
+					$templates[] = substr($entry, 0, -13);
2019
+		}
1946 2020
 	}
1947 2021
 	$dir->close();
1948 2022
 
1949 2023
 	$dir = dir($settings['default_theme_dir'] . '/languages');
1950 2024
 	while ($entry = $dir->read())
1951 2025
 	{
1952
-		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches))
1953
-			$lang_files[] = $matches[1];
2026
+		if (preg_match('~^([^\.]+\.[^\.]+)\.php$~', $entry, $matches)) {
2027
+					$lang_files[] = $matches[1];
2028
+		}
1954 2029
 	}
1955 2030
 	$dir->close();
1956 2031
 
@@ -1958,21 +2033,23 @@  discard block
 block discarded – undo
1958 2033
 	natcasesort($lang_files);
1959 2034
 
1960 2035
 	$context['available_templates'] = array();
1961
-	foreach ($templates as $template)
1962
-		$context['available_templates'][$template] = array(
2036
+	foreach ($templates as $template) {
2037
+			$context['available_templates'][$template] = array(
1963 2038
 			'filename' => $template . '.template.php',
1964 2039
 			'value' => $template,
1965 2040
 			'already_exists' => false,
1966 2041
 			'can_copy' => is_writable($theme['theme_dir']),
1967 2042
 		);
2043
+	}
1968 2044
 	$context['available_language_files'] = array();
1969
-	foreach ($lang_files as $file)
1970
-		$context['available_language_files'][$file] = array(
2045
+	foreach ($lang_files as $file) {
2046
+			$context['available_language_files'][$file] = array(
1971 2047
 			'filename' => $file . '.php',
1972 2048
 			'value' => $file,
1973 2049
 			'already_exists' => false,
1974 2050
 			'can_copy' => file_exists($theme['theme_dir'] . '/languages') ? is_writable($theme['theme_dir'] . '/languages') : is_writable($theme['theme_dir']),
1975 2051
 		);
2052
+	}
1976 2053
 
1977 2054
 	$dir = dir($theme['theme_dir']);
1978 2055
 	while ($entry = $dir->read())
Please login to merge, or discard this patch.
Sources/PersonalMessage.php 1 patch
Braces   +633 added lines, -471 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This helps organize things...
@@ -37,13 +38,14 @@  discard block
 block discarded – undo
37 38
 
38 39
 	loadLanguage('PersonalMessage+Drafts');
39 40
 
40
-	if (!isset($_REQUEST['xml']))
41
-		loadTemplate('PersonalMessage');
41
+	if (!isset($_REQUEST['xml'])) {
42
+			loadTemplate('PersonalMessage');
43
+	}
42 44
 
43 45
 	// Load up the members maximum message capacity.
44
-	if ($user_info['is_admin'])
45
-		$context['message_limit'] = 0;
46
-	elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
46
+	if ($user_info['is_admin']) {
47
+			$context['message_limit'] = 0;
48
+	} elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
47 49
 	{
48 50
 		// @todo Why do we do this?  It seems like if they have any limit we should use it.
49 51
 		$request = $smcFunc['db_query']('', '
@@ -78,8 +80,9 @@  discard block
 block discarded – undo
78 80
 	}
79 81
 
80 82
 	// a previous message was sent successfully? show a small indication.
81
-	if (isset($_GET['done']) && ($_GET['done'] == 'sent'))
82
-		$context['pm_sent'] = true;
83
+	if (isset($_GET['done']) && ($_GET['done'] == 'sent')) {
84
+			$context['pm_sent'] = true;
85
+	}
83 86
 
84 87
 	$context['labels'] = array();
85 88
 
@@ -210,11 +213,11 @@  discard block
 block discarded – undo
210 213
 	{
211 214
 		$_REQUEST['sa'] = '';
212 215
 		MessageFolder();
213
-	}
214
-	else
216
+	} else
215 217
 	{
216
-		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup')
217
-			messageIndexBar($_REQUEST['sa']);
218
+		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') {
219
+					messageIndexBar($_REQUEST['sa']);
220
+		}
218 221
 
219 222
 		call_helper($subActions[$_REQUEST['sa']]);
220 223
 	}
@@ -297,15 +300,16 @@  discard block
 block discarded – undo
297 300
 	);
298 301
 
299 302
 	// Handle labels.
300
-	if (empty($context['currently_using_labels']))
301
-		unset($pm_areas['labels']);
302
-	else
303
+	if (empty($context['currently_using_labels'])) {
304
+			unset($pm_areas['labels']);
305
+	} else
303 306
 	{
304 307
 		// Note we send labels by id as it will have less problems in the querystring.
305 308
 		foreach ($context['labels'] as $label)
306 309
 		{
307
-			if ($label['id'] == -1)
308
-				continue;
310
+			if ($label['id'] == -1) {
311
+							continue;
312
+			}
309 313
 
310 314
 			// Count the amount of unread items in labels.
311 315
 			$pm_areas['labels']['amt'] += $label['unread_messages'];
@@ -356,8 +360,9 @@  discard block
 block discarded – undo
356 360
 	unset($pm_areas);
357 361
 
358 362
 	// No menu means no access.
359
-	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession()))
360
-		fatal_lang_error('no_access', false);
363
+	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) {
364
+			fatal_lang_error('no_access', false);
365
+	}
361 366
 
362 367
 	// Make a note of the Unique ID for this menu.
363 368
 	$context['pm_menu_id'] = $context['max_menu_id'];
@@ -368,9 +373,10 @@  discard block
 block discarded – undo
368 373
 	$context['menu_item_selected'] = $current_area;
369 374
 
370 375
 	// Set the template for this area and add the profile layer.
371
-	if (!isset($_REQUEST['xml']))
372
-		$context['template_layers'][] = 'pm';
373
-}
376
+	if (!isset($_REQUEST['xml'])) {
377
+			$context['template_layers'][] = 'pm';
378
+	}
379
+	}
374 380
 
375 381
 /**
376 382
  * The popup for when we ask for the popup from the user.
@@ -402,8 +408,9 @@  discard block
 block discarded – undo
402 408
 		)
403 409
 	);
404 410
 	$pms = array();
405
-	while ($row = $smcFunc['db_fetch_row']($request))
406
-		$pms[] = $row[0];
411
+	while ($row = $smcFunc['db_fetch_row']($request)) {
412
+			$pms[] = $row[0];
413
+	}
407 414
 	$smcFunc['db_free_result']($request);
408 415
 
409 416
 	if (!empty($pms))
@@ -431,8 +438,9 @@  discard block
 block discarded – undo
431 438
 		);
432 439
 		while ($row = $smcFunc['db_fetch_assoc']($request))
433 440
 		{
434
-			if (!empty($row['id_member_from']))
435
-				$senders[] = $row['id_member_from'];
441
+			if (!empty($row['id_member_from'])) {
442
+							$senders[] = $row['id_member_from'];
443
+			}
436 444
 
437 445
 			$row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head'];
438 446
 			$row['time'] = timeformat($row['timestamp']);
@@ -442,13 +450,15 @@  discard block
 block discarded – undo
442 450
 		$smcFunc['db_free_result']($request);
443 451
 
444 452
 		$senders = loadMemberData($senders);
445
-		foreach ($senders as $member)
446
-			loadMemberContext($member);
453
+		foreach ($senders as $member) {
454
+					loadMemberContext($member);
455
+		}
447 456
 
448 457
 		// Having loaded everyone, attach them to the PMs.
449
-		foreach ($context['unread_pms'] as $id_pm => $details)
450
-			if (!empty($memberContext[$details['id_member_from']]))
458
+		foreach ($context['unread_pms'] as $id_pm => $details) {
459
+					if (!empty($memberContext[$details['id_member_from']]))
451 460
 				$context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']];
461
+		}
452 462
 	}
453 463
 }
454 464
 
@@ -468,12 +478,13 @@  discard block
 block discarded – undo
468 478
 	}
469 479
 
470 480
 	// Make sure the starting location is valid.
471
-	if (isset($_GET['start']) && $_GET['start'] != 'new')
472
-		$_GET['start'] = (int) $_GET['start'];
473
-	elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first']))
474
-		$_GET['start'] = 0;
475
-	else
476
-		$_GET['start'] = 'new';
481
+	if (isset($_GET['start']) && $_GET['start'] != 'new') {
482
+			$_GET['start'] = (int) $_GET['start'];
483
+	} elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) {
484
+			$_GET['start'] = 0;
485
+	} else {
486
+			$_GET['start'] = 'new';
487
+	}
477 488
 
478 489
 	// Set up some basic theme stuff.
479 490
 	$context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to';
@@ -487,9 +498,10 @@  discard block
 block discarded – undo
487 498
 		list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
488 499
 		$sig_limits = explode(',', $sig_limits);
489 500
 
490
-		if (!empty($sig_limits[5]) || !empty($sig_limits[6]))
491
-			addInlineCss('
501
+		if (!empty($sig_limits[5]) || !empty($sig_limits[6])) {
502
+					addInlineCss('
492 503
 	.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}');
504
+		}
493 505
 	}
494 506
 
495 507
 	$labelJoin = '';
@@ -501,8 +513,7 @@  discard block
 block discarded – undo
501 513
 	{
502 514
 		$labelQuery = '
503 515
 			AND pmr.in_inbox = 1';
504
-	}
505
-	elseif ($context['folder'] != 'sent')
516
+	} elseif ($context['folder'] != 'sent')
506 517
 	{
507 518
 		$labelJoin = '
508 519
 			INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)';
@@ -544,22 +555,24 @@  discard block
 block discarded – undo
544 555
 	$txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']);
545 556
 
546 557
 	// Now, build the link tree!
547
-	if ($context['current_label_id'] == -1)
548
-		$context['linktree'][] = array(
558
+	if ($context['current_label_id'] == -1) {
559
+			$context['linktree'][] = array(
549 560
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'],
550 561
 			'name' => $pmbox
551 562
 		);
563
+	}
552 564
 
553 565
 	// Build it further for a label.
554
-	if ($context['current_label_id'] != -1)
555
-		$context['linktree'][] = array(
566
+	if ($context['current_label_id'] != -1) {
567
+			$context['linktree'][] = array(
556 568
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'],
557 569
 			'name' => $txt['pm_current_label'] . ': ' . $context['current_label']
558 570
 		);
571
+	}
559 572
 
560 573
 	// Figure out how many messages there are.
561
-	if ($context['folder'] == 'sent')
562
-		$request = $smcFunc['db_query']('', '
574
+	if ($context['folder'] == 'sent') {
575
+			$request = $smcFunc['db_query']('', '
563 576
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
564 577
 			FROM {db_prefix}personal_messages AS pm
565 578
 			WHERE pm.id_member_from = {int:current_member}
@@ -569,8 +582,8 @@  discard block
 block discarded – undo
569 582
 				'not_deleted' => 0,
570 583
 			)
571 584
 		);
572
-	else
573
-		$request = $smcFunc['db_query']('', '
585
+	} else {
586
+			$request = $smcFunc['db_query']('', '
574 587
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
575 588
 			FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
576 589
 				INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -581,6 +594,7 @@  discard block
 block discarded – undo
581 594
 				'not_deleted' => 0,
582 595
 			)
583 596
 		);
597
+	}
584 598
 	list ($max_messages) = $smcFunc['db_fetch_row']($request);
585 599
 	$smcFunc['db_free_result']($request);
586 600
 
@@ -589,10 +603,11 @@  discard block
 block discarded – undo
589 603
 	$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
590 604
 
591 605
 	// Start on the last page.
592
-	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages)
593
-		$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
594
-	elseif ($_GET['start'] < 0)
595
-		$_GET['start'] = 0;
606
+	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) {
607
+			$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
608
+	} elseif ($_GET['start'] < 0) {
609
+			$_GET['start'] = 0;
610
+	}
596 611
 
597 612
 	// ... but wait - what if we want to start from a specific message?
598 613
 	if (isset($_GET['pmid']))
@@ -600,19 +615,21 @@  discard block
 block discarded – undo
600 615
 		$pmID = (int) $_GET['pmid'];
601 616
 
602 617
 		// Make sure you have access to this PM.
603
-		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
604
-			fatal_lang_error('no_access', false);
618
+		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
619
+					fatal_lang_error('no_access', false);
620
+		}
605 621
 
606 622
 		$context['current_pm'] = $pmID;
607 623
 
608 624
 		// With only one page of PM's we're gonna want page 1.
609
-		if ($max_messages <= $maxPerPage)
610
-			$_GET['start'] = 0;
625
+		if ($max_messages <= $maxPerPage) {
626
+					$_GET['start'] = 0;
627
+		}
611 628
 		// If we pass kstart we assume we're in the right place.
612 629
 		elseif (!isset($_GET['kstart']))
613 630
 		{
614
-			if ($context['folder'] == 'sent')
615
-				$request = $smcFunc['db_query']('', '
631
+			if ($context['folder'] == 'sent') {
632
+							$request = $smcFunc['db_query']('', '
616 633
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
617 634
 					FROM {db_prefix}personal_messages
618 635
 					WHERE id_member_from = {int:current_member}
@@ -624,8 +641,8 @@  discard block
 block discarded – undo
624 641
 						'id_pm' => $pmID,
625 642
 					)
626 643
 				);
627
-			else
628
-				$request = $smcFunc['db_query']('', '
644
+			} else {
645
+							$request = $smcFunc['db_query']('', '
629 646
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
630 647
 					FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
631 648
 						INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -638,6 +655,7 @@  discard block
 block discarded – undo
638 655
 						'id_pm' => $pmID,
639 656
 					)
640 657
 				);
658
+			}
641 659
 
642 660
 			list ($_GET['start']) = $smcFunc['db_fetch_row']($request);
643 661
 			$smcFunc['db_free_result']($request);
@@ -652,8 +670,9 @@  discard block
 block discarded – undo
652 670
 	{
653 671
 		$pmsg = (int) $_GET['pmsg'];
654 672
 
655
-		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
656
-			fatal_lang_error('no_access', false);
673
+		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
674
+					fatal_lang_error('no_access', false);
675
+		}
657 676
 	}
658 677
 
659 678
 	// Set up the page index.
@@ -747,8 +766,9 @@  discard block
 block discarded – undo
747 766
 	{
748 767
 		if (!isset($recipients[$row['id_pm']]))
749 768
 		{
750
-			if (isset($row['id_member_from']))
751
-				$posters[$row['id_pm']] = $row['id_member_from'];
769
+			if (isset($row['id_member_from'])) {
770
+							$posters[$row['id_pm']] = $row['id_member_from'];
771
+			}
752 772
 			$pms[$row['id_pm']] = $row['id_pm'];
753 773
 			$recipients[$row['id_pm']] = array(
754 774
 				'to' => array(),
@@ -757,29 +777,33 @@  discard block
 block discarded – undo
757 777
 		}
758 778
 
759 779
 		// Keep track of the last message so we know what the head is without another query!
760
-		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm']))
761
-			$lastData = array(
780
+		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) {
781
+					$lastData = array(
762 782
 				'id' => $row['id_pm'],
763 783
 				'head' => $row['id_pm_head'],
764 784
 			);
785
+		}
765 786
 	}
766 787
 	$smcFunc['db_free_result']($request);
767 788
 
768 789
 	// Make sure that we have been given a correct head pm id!
769
-	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id'])
770
-		fatal_lang_error('no_access', false);
790
+	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) {
791
+			fatal_lang_error('no_access', false);
792
+	}
771 793
 
772 794
 	if (!empty($pms))
773 795
 	{
774 796
 		// Select the correct current message.
775
-		if (empty($pmID))
776
-			$context['current_pm'] = $lastData['id'];
797
+		if (empty($pmID)) {
798
+					$context['current_pm'] = $lastData['id'];
799
+		}
777 800
 
778 801
 		// This is a list of the pm's that are used for "full" display.
779
-		if ($context['display_mode'] == 0)
780
-			$display_pms = $pms;
781
-		else
782
-			$display_pms = array($context['current_pm']);
802
+		if ($context['display_mode'] == 0) {
803
+					$display_pms = $pms;
804
+		} else {
805
+					$display_pms = array($context['current_pm']);
806
+		}
783 807
 
784 808
 		// At this point we know the main id_pm's. But - if we are looking at conversations we need the others!
785 809
 		if ($context['display_mode'] == 2)
@@ -801,16 +825,18 @@  discard block
 block discarded – undo
801 825
 			while ($row = $smcFunc['db_fetch_assoc']($request))
802 826
 			{
803 827
 				// This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn!
804
-				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1)
805
-					continue;
806
-				elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1)
807
-					continue;
828
+				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) {
829
+									continue;
830
+				} elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) {
831
+									continue;
832
+				}
808 833
 
809
-				if (!isset($recipients[$row['id_pm']]))
810
-					$recipients[$row['id_pm']] = array(
834
+				if (!isset($recipients[$row['id_pm']])) {
835
+									$recipients[$row['id_pm']] = array(
811 836
 						'to' => array(),
812 837
 						'bcc' => array()
813 838
 					);
839
+				}
814 840
 				$display_pms[] = $row['id_pm'];
815 841
 				$posters[$row['id_pm']] = $row['id_member_from'];
816 842
 			}
@@ -861,8 +887,9 @@  discard block
 block discarded – undo
861 887
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
862 888
 				{
863 889
 					$l_id = $row2['id_label'];
864
-					if (isset($context['labels'][$l_id]))
865
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
890
+					if (isset($context['labels'][$l_id])) {
891
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
892
+					}
866 893
 				}
867 894
 
868 895
 				$smcFunc['db_free_result']($request2);
@@ -879,9 +906,10 @@  discard block
 block discarded – undo
879 906
 		// Make sure we don't load unnecessary data.
880 907
 		if ($context['display_mode'] == 1)
881 908
 		{
882
-			foreach ($posters as $k => $v)
883
-				if (!in_array($k, $display_pms))
909
+			foreach ($posters as $k => $v) {
910
+							if (!in_array($k, $display_pms))
884 911
 					unset($posters[$k]);
912
+			}
885 913
 		}
886 914
 
887 915
 		// Load any users....
@@ -892,8 +920,9 @@  discard block
 block discarded – undo
892 920
 		{
893 921
 			// Get the order right.
894 922
 			$orderBy = array();
895
-			foreach (array_reverse($pms) as $pm)
896
-				$orderBy[] = 'pm.id_pm = ' . $pm;
923
+			foreach (array_reverse($pms) as $pm) {
924
+							$orderBy[] = 'pm.id_pm = ' . $pm;
925
+			}
897 926
 
898 927
 			// Seperate query for these bits!
899 928
 			$subjects_request = $smcFunc['db_query']('', '
@@ -939,9 +968,9 @@  discard block
 block discarded – undo
939 968
 			// Allow mods to add additional buttons here
940 969
 			call_integration_hook('integrate_conversation_buttons');
941 970
 		}
971
+	} else {
972
+			$messages_request = false;
942 973
 	}
943
-	else
944
-		$messages_request = false;
945 974
 
946 975
 	$context['can_send_pm'] = allowedTo('pm_send');
947 976
 	$context['can_send_email'] = allowedTo('moderate_forum');
@@ -952,11 +981,13 @@  discard block
 block discarded – undo
952 981
 	if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages']))
953 982
 	{
954 983
 		// If the display mode is "old sk00l" do them all...
955
-		if ($context['display_mode'] == 0)
956
-			markMessages(null, $context['current_label_id']);
984
+		if ($context['display_mode'] == 0) {
985
+					markMessages(null, $context['current_label_id']);
986
+		}
957 987
 		// Otherwise do just the current one!
958
-		elseif (!empty($context['current_pm']))
959
-			markMessages($display_pms, $context['current_label_id']);
988
+		elseif (!empty($context['current_pm'])) {
989
+					markMessages($display_pms, $context['current_label_id']);
990
+		}
960 991
 	}
961 992
 }
962 993
 
@@ -974,8 +1005,9 @@  discard block
 block discarded – undo
974 1005
 
975 1006
 	// Count the current message number....
976 1007
 	static $counter = null;
977
-	if ($counter === null || $reset)
978
-		$counter = $context['start'];
1008
+	if ($counter === null || $reset) {
1009
+			$counter = $context['start'];
1010
+	}
979 1011
 
980 1012
 	static $temp_pm_selected = null;
981 1013
 	if ($temp_pm_selected === null)
@@ -1020,19 +1052,22 @@  discard block
 block discarded – undo
1020 1052
 	}
1021 1053
 
1022 1054
 	// Bail if it's false, ie. no messages.
1023
-	if ($messages_request == false)
1024
-		return false;
1055
+	if ($messages_request == false) {
1056
+			return false;
1057
+	}
1025 1058
 
1026 1059
 	// Reset the data?
1027
-	if ($reset == true)
1028
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1060
+	if ($reset == true) {
1061
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1062
+	}
1029 1063
 
1030 1064
 	// Get the next one... bail if anything goes wrong.
1031 1065
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1032 1066
 	if (!$message)
1033 1067
 	{
1034
-		if ($type != 'subject')
1035
-			$smcFunc['db_free_result']($messages_request);
1068
+		if ($type != 'subject') {
1069
+					$smcFunc['db_free_result']($messages_request);
1070
+		}
1036 1071
 
1037 1072
 		return false;
1038 1073
 	}
@@ -1052,8 +1087,7 @@  discard block
 block discarded – undo
1052 1087
 		$memberContext[$message['id_member_from']]['email'] = '';
1053 1088
 		$memberContext[$message['id_member_from']]['show_email'] = false;
1054 1089
 		$memberContext[$message['id_member_from']]['is_guest'] = true;
1055
-	}
1056
-	else
1090
+	} else
1057 1091
 	{
1058 1092
 		$memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']);
1059 1093
 		$memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id'])));
@@ -1094,9 +1128,10 @@  discard block
 block discarded – undo
1094 1128
 	$counter++;
1095 1129
 
1096 1130
 	// Any custom profile fields?
1097
-	if (!empty($memberContext[$message['id_member_from']]['custom_fields']))
1098
-		foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1131
+	if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) {
1132
+			foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1099 1133
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1134
+	}
1100 1135
 
1101 1136
 	call_integration_hook('integrate_prepare_pm_context', array(&$output, &$message, $counter));
1102 1137
 
@@ -1120,22 +1155,28 @@  discard block
 block discarded – undo
1120 1155
 			$context['search_params'][$k] = $v;
1121 1156
 		}
1122 1157
 	}
1123
-	if (isset($_REQUEST['search']))
1124
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1158
+	if (isset($_REQUEST['search'])) {
1159
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1160
+	}
1125 1161
 
1126
-	if (isset($context['search_params']['search']))
1127
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1128
-	if (isset($context['search_params']['userspec']))
1129
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1162
+	if (isset($context['search_params']['search'])) {
1163
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1164
+	}
1165
+	if (isset($context['search_params']['userspec'])) {
1166
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1167
+	}
1130 1168
 
1131
-	if (!empty($context['search_params']['searchtype']))
1132
-		$context['search_params']['searchtype'] = 2;
1169
+	if (!empty($context['search_params']['searchtype'])) {
1170
+			$context['search_params']['searchtype'] = 2;
1171
+	}
1133 1172
 
1134
-	if (!empty($context['search_params']['minage']))
1135
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1173
+	if (!empty($context['search_params']['minage'])) {
1174
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1175
+	}
1136 1176
 
1137
-	if (!empty($context['search_params']['maxage']))
1138
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1177
+	if (!empty($context['search_params']['maxage'])) {
1178
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1179
+	}
1139 1180
 
1140 1181
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
1141 1182
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
@@ -1162,8 +1203,9 @@  discard block
 block discarded – undo
1162 1203
 		$context['search_errors']['messages'] = array();
1163 1204
 		foreach ($context['search_errors'] as $search_error => $dummy)
1164 1205
 		{
1165
-			if ($search_error == 'messages')
1166
-				continue;
1206
+			if ($search_error == 'messages') {
1207
+							continue;
1208
+			}
1167 1209
 
1168 1210
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
1169 1211
 		}
@@ -1185,8 +1227,9 @@  discard block
 block discarded – undo
1185 1227
 	global $scripturl, $modSettings, $user_info, $context, $txt;
1186 1228
 	global $memberContext, $smcFunc;
1187 1229
 
1188
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
1189
-		fatal_lang_error('loadavg_search_disabled', false);
1230
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
1231
+			fatal_lang_error('loadavg_search_disabled', false);
1232
+	}
1190 1233
 
1191 1234
 	/**
1192 1235
 	 * @todo For the moment force the folder to the inbox.
@@ -1215,35 +1258,40 @@  discard block
 block discarded – undo
1215 1258
 	$context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1216 1259
 
1217 1260
 	// Store whether simple search was used (needed if the user wants to do another query).
1218
-	if (!isset($search_params['advanced']))
1219
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1261
+	if (!isset($search_params['advanced'])) {
1262
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1263
+	}
1220 1264
 
1221 1265
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
1222
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
1223
-		$search_params['searchtype'] = 2;
1266
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
1267
+			$search_params['searchtype'] = 2;
1268
+	}
1224 1269
 
1225 1270
 	// Minimum age of messages. Default to zero (don't set param in that case).
1226
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
1227
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1271
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
1272
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1273
+	}
1228 1274
 
1229 1275
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
1230
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999))
1231
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1276
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) {
1277
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1278
+	}
1232 1279
 
1233 1280
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
1234 1281
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
1235 1282
 
1236 1283
 	// Default the user name to a wildcard matching every user (*).
1237
-	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
1238
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1284
+	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
1285
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1286
+	}
1239 1287
 
1240 1288
 	// This will be full of all kinds of parameters!
1241 1289
 	$searchq_parameters = array();
1242 1290
 
1243 1291
 	// If there's no specific user, then don't mention it in the main query.
1244
-	if (empty($search_params['userspec']))
1245
-		$userQuery = '';
1246
-	else
1292
+	if (empty($search_params['userspec'])) {
1293
+			$userQuery = '';
1294
+	} else
1247 1295
 	{
1248 1296
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
1249 1297
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -1255,8 +1303,9 @@  discard block
 block discarded – undo
1255 1303
 		{
1256 1304
 			$possible_users[$k] = trim($possible_users[$k]);
1257 1305
 
1258
-			if (strlen($possible_users[$k]) == 0)
1259
-				unset($possible_users[$k]);
1306
+			if (strlen($possible_users[$k]) == 0) {
1307
+							unset($possible_users[$k]);
1308
+			}
1260 1309
 		}
1261 1310
 
1262 1311
 		if (!empty($possible_users))
@@ -1268,8 +1317,9 @@  discard block
 block discarded – undo
1268 1317
 			{
1269 1318
 				$where_params['name_' . $k] = $v;
1270 1319
 				$where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}';
1271
-				if (!isset($where_params['real_name']))
1272
-					$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1320
+				if (!isset($where_params['real_name'])) {
1321
+									$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1322
+				}
1273 1323
 			}
1274 1324
 
1275 1325
 			// Who matches those criteria?
@@ -1282,28 +1332,28 @@  discard block
 block discarded – undo
1282 1332
 			);
1283 1333
 
1284 1334
 			// Simply do nothing if there're too many members matching the criteria.
1285
-			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
1286
-				$userQuery = '';
1287
-			elseif ($smcFunc['db_num_rows']($request) == 0)
1335
+			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
1336
+							$userQuery = '';
1337
+			} elseif ($smcFunc['db_num_rows']($request) == 0)
1288 1338
 			{
1289 1339
 				$userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})';
1290 1340
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1291 1341
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1292
-			}
1293
-			else
1342
+			} else
1294 1343
 			{
1295 1344
 				$memberlist = array();
1296
-				while ($row = $smcFunc['db_fetch_assoc']($request))
1297
-					$memberlist[] = $row['id_member'];
1345
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
1346
+									$memberlist[] = $row['id_member'];
1347
+				}
1298 1348
 				$userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))';
1299 1349
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1300 1350
 				$searchq_parameters['member_list'] = $memberlist;
1301 1351
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1302 1352
 			}
1303 1353
 			$smcFunc['db_free_result']($request);
1354
+		} else {
1355
+					$userQuery = '';
1304 1356
 		}
1305
-		else
1306
-			$userQuery = '';
1307 1357
 	}
1308 1358
 
1309 1359
 	// Setup the sorting variables...
@@ -1311,8 +1361,9 @@  discard block
 block discarded – undo
1311 1361
 	$sort_columns = array(
1312 1362
 		'pm.id_pm',
1313 1363
 	);
1314
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
1315
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1364
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
1365
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1366
+	}
1316 1367
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';
1317 1368
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
1318 1369
 
@@ -1322,24 +1373,27 @@  discard block
 block discarded – undo
1322 1373
 	if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels'])
1323 1374
 	{
1324 1375
 		// Came here from pagination?  Put them back into $_REQUEST for sanitization.
1325
-		if (isset($search_params['labels']))
1326
-			$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1376
+		if (isset($search_params['labels'])) {
1377
+					$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1378
+		}
1327 1379
 
1328 1380
 		// Assuming we have some labels - make them all integers.
1329 1381
 		if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel']))
1330 1382
 		{
1331
-			foreach ($_REQUEST['searchlabel'] as $key => $id)
1332
-				$_REQUEST['searchlabel'][$key] = (int) $id;
1383
+			foreach ($_REQUEST['searchlabel'] as $key => $id) {
1384
+							$_REQUEST['searchlabel'][$key] = (int) $id;
1385
+			}
1386
+		} else {
1387
+					$_REQUEST['searchlabel'] = array();
1333 1388
 		}
1334
-		else
1335
-			$_REQUEST['searchlabel'] = array();
1336 1389
 
1337 1390
 		// Now that everything is cleaned up a bit, make the labels a param.
1338 1391
 		$search_params['labels'] = implode(',', $_REQUEST['searchlabel']);
1339 1392
 
1340 1393
 		// No labels selected? That must be an error!
1341
-		if (empty($_REQUEST['searchlabel']))
1342
-			$context['search_errors']['no_labels_selected'] = true;
1394
+		if (empty($_REQUEST['searchlabel'])) {
1395
+					$context['search_errors']['no_labels_selected'] = true;
1396
+		}
1343 1397
 		// Otherwise prepare the query!
1344 1398
 		elseif (count($_REQUEST['searchlabel']) != count($context['labels']))
1345 1399
 		{
@@ -1362,8 +1416,7 @@  discard block
 block discarded – undo
1362 1416
 					// Not searching the inbox - PM must be labeled
1363 1417
 					$labelQuery = ' AND pml.id_label IN ({array_int:labels})';
1364 1418
 					$labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)';
1365
-				}
1366
-				else
1419
+				} else
1367 1420
 				{
1368 1421
 					// Searching the inbox - PM doesn't have to be labeled
1369 1422
 					$labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))';
@@ -1378,8 +1431,9 @@  discard block
 block discarded – undo
1378 1431
 	// What are we actually searching for?
1379 1432
 	$search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');
1380 1433
 	// If we ain't got nothing - we should error!
1381
-	if (!isset($search_params['search']) || $search_params['search'] == '')
1382
-		$context['search_errors']['invalid_search_string'] = true;
1434
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
1435
+			$context['search_errors']['invalid_search_string'] = true;
1436
+	}
1383 1437
 
1384 1438
 	// Extract phrase parts first (e.g. some words "this is a phrase" some more words.)
1385 1439
 	preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER);
@@ -1392,12 +1446,14 @@  discard block
 block discarded – undo
1392 1446
 	$excludedWords = array();
1393 1447
 
1394 1448
 	// .. first, we check for things like -"some words", but not "-some words".
1395
-	foreach ($matches[1] as $index => $word)
1396
-		if ($word == '-')
1449
+	foreach ($matches[1] as $index => $word) {
1450
+			if ($word == '-')
1397 1451
 		{
1398 1452
 			$word = $smcFunc['strtolower'](trim($searchArray[$index]));
1399
-			if (strlen($word) > 0)
1400
-				$excludedWords[] = $word;
1453
+	}
1454
+			if (strlen($word) > 0) {
1455
+							$excludedWords[] = $word;
1456
+			}
1401 1457
 			unset($searchArray[$index]);
1402 1458
 		}
1403 1459
 
@@ -1407,8 +1463,9 @@  discard block
 block discarded – undo
1407 1463
 		if (strpos(trim($word), '-') === 0)
1408 1464
 		{
1409 1465
 			$word = substr($smcFunc['strtolower']($word), 1);
1410
-			if (strlen($word) > 0)
1411
-				$excludedWords[] = $word;
1466
+			if (strlen($word) > 0) {
1467
+							$excludedWords[] = $word;
1468
+			}
1412 1469
 			unset($tempSearch[$index]);
1413 1470
 		}
1414 1471
 	}
@@ -1419,9 +1476,9 @@  discard block
 block discarded – undo
1419 1476
 	foreach ($searchArray as $index => $value)
1420 1477
 	{
1421 1478
 		$searchArray[$index] = $smcFunc['strtolower'](trim($value));
1422
-		if ($searchArray[$index] == '')
1423
-			unset($searchArray[$index]);
1424
-		else
1479
+		if ($searchArray[$index] == '') {
1480
+					unset($searchArray[$index]);
1481
+		} else
1425 1482
 		{
1426 1483
 			// Sort out entities first.
1427 1484
 			$searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]);
@@ -1431,27 +1488,32 @@  discard block
 block discarded – undo
1431 1488
 
1432 1489
 	// Create an array of replacements for highlighting.
1433 1490
 	$context['mark'] = array();
1434
-	foreach ($searchArray as $word)
1435
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1491
+	foreach ($searchArray as $word) {
1492
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1493
+	}
1436 1494
 
1437 1495
 	// This contains *everything*
1438 1496
 	$searchWords = array_merge($searchArray, $excludedWords);
1439 1497
 
1440 1498
 	// Make sure at least one word is being searched for.
1441
-	if (empty($searchArray))
1442
-		$context['search_errors']['invalid_search_string'] = true;
1499
+	if (empty($searchArray)) {
1500
+			$context['search_errors']['invalid_search_string'] = true;
1501
+	}
1443 1502
 
1444 1503
 	// Sort out the search query so the user can edit it - if they want.
1445 1504
 	$context['search_params'] = $search_params;
1446
-	if (isset($context['search_params']['search']))
1447
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1448
-	if (isset($context['search_params']['userspec']))
1449
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1505
+	if (isset($context['search_params']['search'])) {
1506
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1507
+	}
1508
+	if (isset($context['search_params']['userspec'])) {
1509
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1510
+	}
1450 1511
 
1451 1512
 	// Now we have all the parameters, combine them together for pagination and the like...
1452 1513
 	$context['params'] = array();
1453
-	foreach ($search_params as $k => $v)
1454
-		$context['params'][] = $k . '|\'|' . $v;
1514
+	foreach ($search_params as $k => $v) {
1515
+			$context['params'][] = $k . '|\'|' . $v;
1516
+	}
1455 1517
 	$context['params'] = base64_encode(implode('|"|', $context['params']));
1456 1518
 
1457 1519
 	// Compile the subject query part.
@@ -1459,26 +1521,31 @@  discard block
 block discarded – undo
1459 1521
 
1460 1522
 	foreach ($searchWords as $index => $word)
1461 1523
 	{
1462
-		if ($word == '')
1463
-			continue;
1524
+		if ($word == '') {
1525
+					continue;
1526
+		}
1464 1527
 
1465
-		if ($search_params['subject_only'])
1466
-			$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1467
-		else
1468
-			$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1528
+		if ($search_params['subject_only']) {
1529
+					$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1530
+		} else {
1531
+					$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1532
+		}
1469 1533
 		$searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%';
1470 1534
 	}
1471 1535
 
1472 1536
 	$searchQuery = ' 1=1';
1473
-	if (!empty($andQueryParts))
1474
-		$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1537
+	if (!empty($andQueryParts)) {
1538
+			$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1539
+	}
1475 1540
 
1476 1541
 	// Age limits?
1477 1542
 	$timeQuery = '';
1478
-	if (!empty($search_params['minage']))
1479
-		$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1480
-	if (!empty($search_params['maxage']))
1481
-		$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1543
+	if (!empty($search_params['minage'])) {
1544
+			$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1545
+	}
1546
+	if (!empty($search_params['maxage'])) {
1547
+			$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1548
+	}
1482 1549
 
1483 1550
 	// If we have errors - return back to the first screen...
1484 1551
 	if (!empty($context['search_errors']))
@@ -1564,8 +1631,9 @@  discard block
 block discarded – undo
1564 1631
 			)
1565 1632
 		);
1566 1633
 		$real_pm_ids = array();
1567
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1568
-			$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1634
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1635
+					$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1636
+		}
1569 1637
 		$smcFunc['db_free_result']($request);
1570 1638
 	}
1571 1639
 
@@ -1595,8 +1663,9 @@  discard block
 block discarded – undo
1595 1663
 		);
1596 1664
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1597 1665
 		{
1598
-			if ($context['folder'] == 'sent' || empty($row['bcc']))
1599
-				$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1666
+			if ($context['folder'] == 'sent' || empty($row['bcc'])) {
1667
+							$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1668
+			}
1600 1669
 
1601 1670
 			if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
1602 1671
 			{
@@ -1617,12 +1686,14 @@  discard block
 block discarded – undo
1617 1686
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
1618 1687
 				{
1619 1688
 					$l_id = $row2['id_label'];
1620
-					if (isset($context['labels'][$l_id]))
1621
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1689
+					if (isset($context['labels'][$l_id])) {
1690
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1691
+					}
1622 1692
 
1623 1693
 					// Here we find the first label on a message - for linking to posts in results
1624
-					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1)
1625
-						$context['first_label'][$row['id_pm']] = $l_id;
1694
+					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) {
1695
+											$context['first_label'][$row['id_pm']] = $l_id;
1696
+					}
1626 1697
 				}
1627 1698
 
1628 1699
 				$smcFunc['db_free_result']($request2);
@@ -1749,8 +1820,9 @@  discard block
 block discarded – undo
1749 1820
 		list ($postCount) = $smcFunc['db_fetch_row']($request);
1750 1821
 		$smcFunc['db_free_result']($request);
1751 1822
 
1752
-		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
1753
-			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1823
+		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) {
1824
+					fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1825
+		}
1754 1826
 	}
1755 1827
 
1756 1828
 	// Quoting/Replying to a message?
@@ -1759,8 +1831,9 @@  discard block
 block discarded – undo
1759 1831
 		$pmsg = (int) $_REQUEST['pmsg'];
1760 1832
 
1761 1833
 		// Make sure this is yours.
1762
-		if (!isAccessiblePM($pmsg))
1763
-			fatal_lang_error('no_access', false);
1834
+		if (!isAccessiblePM($pmsg)) {
1835
+					fatal_lang_error('no_access', false);
1836
+		}
1764 1837
 
1765 1838
 		// Work out whether this is one you've received?
1766 1839
 		$request = $smcFunc['db_query']('', '
@@ -1797,8 +1870,9 @@  discard block
 block discarded – undo
1797 1870
 				'id_pm' => $pmsg,
1798 1871
 			)
1799 1872
 		);
1800
-		if ($smcFunc['db_num_rows']($request) == 0)
1801
-			fatal_lang_error('pm_not_yours', false);
1873
+		if ($smcFunc['db_num_rows']($request) == 0) {
1874
+					fatal_lang_error('pm_not_yours', false);
1875
+		}
1802 1876
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
1803 1877
 		$smcFunc['db_free_result']($request);
1804 1878
 
@@ -1809,9 +1883,9 @@  discard block
 block discarded – undo
1809 1883
 		// Add 'Re: ' to it....
1810 1884
 		if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
1811 1885
 		{
1812
-			if ($language === $user_info['language'])
1813
-				$context['response_prefix'] = $txt['response_prefix'];
1814
-			else
1886
+			if ($language === $user_info['language']) {
1887
+							$context['response_prefix'] = $txt['response_prefix'];
1888
+			} else
1815 1889
 			{
1816 1890
 				loadLanguage('index', $language, false);
1817 1891
 				$context['response_prefix'] = $txt['response_prefix'];
@@ -1820,22 +1894,25 @@  discard block
 block discarded – undo
1820 1894
 			cache_put_data('response_prefix', $context['response_prefix'], 600);
1821 1895
 		}
1822 1896
 		$form_subject = $row_quoted['subject'];
1823
-		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
1824
-			$form_subject = $context['response_prefix'] . $form_subject;
1897
+		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
1898
+					$form_subject = $context['response_prefix'] . $form_subject;
1899
+		}
1825 1900
 
1826 1901
 		if (isset($_REQUEST['quote']))
1827 1902
 		{
1828 1903
 			// Remove any nested quotes and <br>...
1829 1904
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']);
1830
-			if (!empty($modSettings['removeNestedQuotes']))
1831
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1832
-			if (empty($row_quoted['id_member']))
1833
-				$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1834
-			else
1835
-				$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1905
+			if (!empty($modSettings['removeNestedQuotes'])) {
1906
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1907
+			}
1908
+			if (empty($row_quoted['id_member'])) {
1909
+							$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1910
+			} else {
1911
+							$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1912
+			}
1913
+		} else {
1914
+					$form_message = '';
1836 1915
 		}
1837
-		else
1838
-			$form_message = '';
1839 1916
 
1840 1917
 		// Do the BBC thang on the message.
1841 1918
 		$row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);
@@ -1856,8 +1933,7 @@  discard block
 block discarded – undo
1856 1933
 			'timestamp' => forum_time(true, $row_quoted['msgtime']),
1857 1934
 			'body' => $row_quoted['body']
1858 1935
 		);
1859
-	}
1860
-	else
1936
+	} else
1861 1937
 	{
1862 1938
 		$context['quoted_message'] = false;
1863 1939
 		$form_subject = '';
@@ -1876,11 +1952,12 @@  discard block
 block discarded – undo
1876 1952
 		if ($_REQUEST['u'] == 'all' && isset($row_quoted))
1877 1953
 		{
1878 1954
 			// Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.
1879
-			if ($row_quoted['id_member'] != $user_info['id'])
1880
-				$context['recipients']['to'][] = array(
1955
+			if ($row_quoted['id_member'] != $user_info['id']) {
1956
+							$context['recipients']['to'][] = array(
1881 1957
 					'id' => $row_quoted['id_member'],
1882 1958
 					'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']),
1883 1959
 				);
1960
+			}
1884 1961
 
1885 1962
 			// Now to get the others.
1886 1963
 			$request = $smcFunc['db_query']('', '
@@ -1896,18 +1973,19 @@  discard block
 block discarded – undo
1896 1973
 					'not_bcc' => 0,
1897 1974
 				)
1898 1975
 			);
1899
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1900
-				$context['recipients']['to'][] = array(
1976
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1977
+							$context['recipients']['to'][] = array(
1901 1978
 					'id' => $row['id_member'],
1902 1979
 					'name' => $row['real_name'],
1903 1980
 				);
1981
+			}
1904 1982
 			$smcFunc['db_free_result']($request);
1905
-		}
1906
-		else
1983
+		} else
1907 1984
 		{
1908 1985
 			$_REQUEST['u'] = explode(',', $_REQUEST['u']);
1909
-			foreach ($_REQUEST['u'] as $key => $uID)
1910
-				$_REQUEST['u'][$key] = (int) $uID;
1986
+			foreach ($_REQUEST['u'] as $key => $uID) {
1987
+							$_REQUEST['u'][$key] = (int) $uID;
1988
+			}
1911 1989
 
1912 1990
 			$_REQUEST['u'] = array_unique($_REQUEST['u']);
1913 1991
 
@@ -1921,22 +1999,24 @@  discard block
 block discarded – undo
1921 1999
 					'limit' => count($_REQUEST['u']),
1922 2000
 				)
1923 2001
 			);
1924
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1925
-				$context['recipients']['to'][] = array(
2002
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2003
+							$context['recipients']['to'][] = array(
1926 2004
 					'id' => $row['id_member'],
1927 2005
 					'name' => $row['real_name'],
1928 2006
 				);
2007
+			}
1929 2008
 			$smcFunc['db_free_result']($request);
1930 2009
 		}
1931 2010
 
1932 2011
 		// Get a literal name list in case the user has JavaScript disabled.
1933 2012
 		$names = array();
1934
-		foreach ($context['recipients']['to'] as $to)
1935
-			$names[] = $to['name'];
2013
+		foreach ($context['recipients']['to'] as $to) {
2014
+					$names[] = $to['name'];
2015
+		}
1936 2016
 		$context['to_value'] = empty($names) ? '' : '&quot;' . implode('&quot;, &quot;', $names) . '&quot;';
2017
+	} else {
2018
+			$context['to_value'] = '';
1937 2019
 	}
1938
-	else
1939
-		$context['to_value'] = '';
1940 2020
 
1941 2021
 	// Set the defaults...
1942 2022
 	$context['subject'] = $form_subject;
@@ -2006,8 +2086,9 @@  discard block
 block discarded – undo
2006 2086
 
2007 2087
 	// validate with loadMemberData()
2008 2088
 	$memberResult = loadMemberData($user_info['id'], false);
2009
-	if (!$memberResult)
2010
-		fatal_lang_error('not_a_user', false);
2089
+	if (!$memberResult) {
2090
+			fatal_lang_error('not_a_user', false);
2091
+	}
2011 2092
 	list ($memID) = $memberResult;
2012 2093
 
2013 2094
 	// drafts is where the functions reside
@@ -2033,9 +2114,9 @@  discard block
 block discarded – undo
2033 2114
 		$context['sub_template'] = 'send';
2034 2115
 		loadJavaScriptFile('PersonalMessage.js', array('defer' => false, 'minimize' => true), 'smf_pms');
2035 2116
 		loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest');
2117
+	} else {
2118
+			$context['sub_template'] = 'pm';
2036 2119
 	}
2037
-	else
2038
-		$context['sub_template'] = 'pm';
2039 2120
 
2040 2121
 	$context['page_title'] = $txt['send_message'];
2041 2122
 
@@ -2096,10 +2177,11 @@  discard block
 block discarded – undo
2096 2177
 		);
2097 2178
 		if ($smcFunc['db_num_rows']($request) == 0)
2098 2179
 		{
2099
-			if (!isset($_REQUEST['xml']))
2100
-				fatal_lang_error('pm_not_yours', false);
2101
-			else
2102
-				$error_types[] = 'pm_not_yours';
2180
+			if (!isset($_REQUEST['xml'])) {
2181
+							fatal_lang_error('pm_not_yours', false);
2182
+			} else {
2183
+							$error_types[] = 'pm_not_yours';
2184
+			}
2103 2185
 		}
2104 2186
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
2105 2187
 		$smcFunc['db_free_result']($request);
@@ -2146,14 +2228,16 @@  discard block
 block discarded – undo
2146 2228
 		$context['post_error'][$error_type] = true;
2147 2229
 		if (isset($txt['error_' . $error_type]))
2148 2230
 		{
2149
-			if ($error_type == 'long_message')
2150
-				$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2231
+			if ($error_type == 'long_message') {
2232
+							$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2233
+			}
2151 2234
 			$context['post_error']['messages'][] = $txt['error_' . $error_type];
2152 2235
 		}
2153 2236
 
2154 2237
 		// If it's not a minor error flag it as such.
2155
-		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject')))
2156
-			$context['error_type'] = 'serious';
2238
+		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) {
2239
+					$context['error_type'] = 'serious';
2240
+		}
2157 2241
 	}
2158 2242
 
2159 2243
 	// We need to load the editor once more.
@@ -2211,8 +2295,9 @@  discard block
 block discarded – undo
2211 2295
 	require_once($sourcedir . '/Subs-Auth.php');
2212 2296
 
2213 2297
 	// PM Drafts enabled and needed?
2214
-	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft'])))
2215
-		require_once($sourcedir . '/Drafts.php');
2298
+	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) {
2299
+			require_once($sourcedir . '/Drafts.php');
2300
+	}
2216 2301
 
2217 2302
 	loadLanguage('PersonalMessage', '', false);
2218 2303
 
@@ -2242,24 +2327,27 @@  discard block
 block discarded – undo
2242 2327
 
2243 2328
 		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
2244 2329
 		{
2245
-			if (!isset($_REQUEST['xml']))
2246
-				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2247
-			else
2248
-				$post_errors[] = 'pm_too_many_per_hour';
2330
+			if (!isset($_REQUEST['xml'])) {
2331
+							fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2332
+			} else {
2333
+							$post_errors[] = 'pm_too_many_per_hour';
2334
+			}
2249 2335
 		}
2250 2336
 	}
2251 2337
 
2252 2338
 	// If your session timed out, show an error, but do allow to re-submit.
2253
-	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '')
2254
-		$post_errors[] = 'session_timeout';
2339
+	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') {
2340
+			$post_errors[] = 'session_timeout';
2341
+	}
2255 2342
 
2256 2343
 	$_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
2257 2344
 	$_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];
2258 2345
 	$_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];
2259 2346
 
2260 2347
 	// Route the input from the 'u' parameter to the 'to'-list.
2261
-	if (!empty($_POST['u']))
2262
-		$_POST['recipient_to'] = explode(',', $_POST['u']);
2348
+	if (!empty($_POST['u'])) {
2349
+			$_POST['recipient_to'] = explode(',', $_POST['u']);
2350
+	}
2263 2351
 
2264 2352
 	// Construct the list of recipients.
2265 2353
 	$recipientList = array();
@@ -2271,8 +2359,9 @@  discard block
 block discarded – undo
2271 2359
 		$recipientList[$recipientType] = array();
2272 2360
 		if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))
2273 2361
 		{
2274
-			foreach ($_POST['recipient_' . $recipientType] as $recipient)
2275
-				$recipientList[$recipientType][] = (int) $recipient;
2362
+			foreach ($_POST['recipient_' . $recipientType] as $recipient) {
2363
+							$recipientList[$recipientType][] = (int) $recipient;
2364
+			}
2276 2365
 		}
2277 2366
 
2278 2367
 		// Are there also literal names set?
@@ -2286,10 +2375,11 @@  discard block
 block discarded – undo
2286 2375
 
2287 2376
 			foreach ($namedRecipientList[$recipientType] as $index => $recipient)
2288 2377
 			{
2289
-				if (strlen(trim($recipient)) > 0)
2290
-					$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2291
-				else
2292
-					unset($namedRecipientList[$recipientType][$index]);
2378
+				if (strlen(trim($recipient)) > 0) {
2379
+									$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2380
+				} else {
2381
+									unset($namedRecipientList[$recipientType][$index]);
2382
+				}
2293 2383
 			}
2294 2384
 
2295 2385
 			if (!empty($namedRecipientList[$recipientType]))
@@ -2319,8 +2409,9 @@  discard block
 block discarded – undo
2319 2409
 		}
2320 2410
 
2321 2411
 		// Selected a recipient to be deleted? Remove them now.
2322
-		if (!empty($_POST['delete_recipient']))
2323
-			$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2412
+		if (!empty($_POST['delete_recipient'])) {
2413
+					$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2414
+		}
2324 2415
 
2325 2416
 		// Make sure we don't include the same name twice
2326 2417
 		$recipientList[$recipientType] = array_unique($recipientList[$recipientType]);
@@ -2330,8 +2421,9 @@  discard block
 block discarded – undo
2330 2421
 	$is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']);
2331 2422
 
2332 2423
 	// Check if there's at least one recipient.
2333
-	if (empty($recipientList['to']) && empty($recipientList['bcc']))
2334
-		$post_errors[] = 'no_to';
2424
+	if (empty($recipientList['to']) && empty($recipientList['bcc'])) {
2425
+			$post_errors[] = 'no_to';
2426
+	}
2335 2427
 
2336 2428
 	// Make sure that we remove the members who did get it from the screen.
2337 2429
 	if (!$is_recipient_change)
@@ -2345,28 +2437,31 @@  discard block
 block discarded – undo
2345 2437
 				// Since we already have a post error, remove the previous one.
2346 2438
 				$post_errors = array_diff($post_errors, array('no_to'));
2347 2439
 
2348
-				foreach ($namesNotFound[$recipientType] as $name)
2349
-					$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2440
+				foreach ($namesNotFound[$recipientType] as $name) {
2441
+									$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2442
+				}
2350 2443
 			}
2351 2444
 		}
2352 2445
 	}
2353 2446
 
2354 2447
 	// Did they make any mistakes?
2355
-	if ($_REQUEST['subject'] == '')
2356
-		$post_errors[] = 'no_subject';
2357
-	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '')
2358
-		$post_errors[] = 'no_message';
2359
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength'])
2360
-		$post_errors[] = 'long_message';
2361
-	else
2448
+	if ($_REQUEST['subject'] == '') {
2449
+			$post_errors[] = 'no_subject';
2450
+	}
2451
+	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
2452
+			$post_errors[] = 'no_message';
2453
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) {
2454
+			$post_errors[] = 'long_message';
2455
+	} else
2362 2456
 	{
2363 2457
 		// Preparse the message.
2364 2458
 		$message = $_REQUEST['message'];
2365 2459
 		preparsecode($message);
2366 2460
 
2367 2461
 		// Make sure there's still some content left without the tags.
2368
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false))
2369
-			$post_errors[] = 'no_message';
2462
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) {
2463
+					$post_errors[] = 'no_message';
2464
+		}
2370 2465
 	}
2371 2466
 
2372 2467
 	// Wrong verification code?
@@ -2378,13 +2473,15 @@  discard block
 block discarded – undo
2378 2473
 		);
2379 2474
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
2380 2475
 
2381
-		if (is_array($context['require_verification']))
2382
-			$post_errors = array_merge($post_errors, $context['require_verification']);
2476
+		if (is_array($context['require_verification'])) {
2477
+					$post_errors = array_merge($post_errors, $context['require_verification']);
2478
+		}
2383 2479
 	}
2384 2480
 
2385 2481
 	// If they did, give a chance to make ammends.
2386
-	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml']))
2387
-		return messagePostError($post_errors, $namedRecipientList, $recipientList);
2482
+	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) {
2483
+			return messagePostError($post_errors, $namedRecipientList, $recipientList);
2484
+	}
2388 2485
 
2389 2486
 	// Want to take a second glance before you send?
2390 2487
 	if (isset($_REQUEST['preview']))
@@ -2415,8 +2512,9 @@  discard block
 block discarded – undo
2415 2512
 		foreach ($namesNotFound as $recipientType => $names)
2416 2513
 		{
2417 2514
 			$post_errors[] = 'bad_' . $recipientType;
2418
-			foreach ($names as $name)
2419
-				$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2515
+			foreach ($names as $name) {
2516
+							$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2517
+			}
2420 2518
 		}
2421 2519
 
2422 2520
 		return messagePostError(array(), $namedRecipientList, $recipientList);
@@ -2446,13 +2544,14 @@  discard block
 block discarded – undo
2446 2544
 	checkSubmitOnce('check');
2447 2545
 
2448 2546
 	// Do the actual sending of the PM.
2449
-	if (!empty($recipientList['to']) || !empty($recipientList['bcc']))
2450
-		$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2451
-	else
2452
-		$context['send_log'] = array(
2547
+	if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) {
2548
+			$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2549
+	} else {
2550
+			$context['send_log'] = array(
2453 2551
 			'sent' => array(),
2454 2552
 			'failed' => array()
2455 2553
 		);
2554
+	}
2456 2555
 
2457 2556
 	// Mark the message as "replied to".
2458 2557
 	if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox')
@@ -2470,11 +2569,12 @@  discard block
 block discarded – undo
2470 2569
 	}
2471 2570
 
2472 2571
 	// If one or more of the recipient were invalid, go back to the post screen with the failed usernames.
2473
-	if (!empty($context['send_log']['failed']))
2474
-		return messagePostError($post_errors, $namesNotFound, array(
2572
+	if (!empty($context['send_log']['failed'])) {
2573
+			return messagePostError($post_errors, $namesNotFound, array(
2475 2574
 			'to' => array_intersect($recipientList['to'], $context['send_log']['failed']),
2476 2575
 			'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed'])
2477 2576
 		));
2577
+	}
2478 2578
 
2479 2579
 	// Message sent successfully?
2480 2580
 	if (!empty($context['send_log']) && empty($context['send_log']['failed']))
@@ -2482,8 +2582,9 @@  discard block
 block discarded – undo
2482 2582
 		$context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent';
2483 2583
 
2484 2584
 		// If we had a PM draft for this one, then its time to remove it since it was just sent
2485
-		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft']))
2486
-			DeleteDraft($_POST['id_pm_draft']);
2585
+		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) {
2586
+					DeleteDraft($_POST['id_pm_draft']);
2587
+		}
2487 2588
 	}
2488 2589
 
2489 2590
 	// Go back to the where they sent from, if possible...
@@ -2498,24 +2599,28 @@  discard block
 block discarded – undo
2498 2599
 
2499 2600
 	checkSession('request');
2500 2601
 
2501
-	if (isset($_REQUEST['del_selected']))
2502
-		$_REQUEST['pm_action'] = 'delete';
2602
+	if (isset($_REQUEST['del_selected'])) {
2603
+			$_REQUEST['pm_action'] = 'delete';
2604
+	}
2503 2605
 
2504 2606
 	if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms']))
2505 2607
 	{
2506
-		foreach ($_REQUEST['pms'] as $pm)
2507
-			$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2608
+		foreach ($_REQUEST['pms'] as $pm) {
2609
+					$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2610
+		}
2508 2611
 	}
2509 2612
 
2510
-	if (empty($_REQUEST['pm_actions']))
2511
-		redirectexit($context['current_label_redirect']);
2613
+	if (empty($_REQUEST['pm_actions'])) {
2614
+			redirectexit($context['current_label_redirect']);
2615
+	}
2512 2616
 
2513 2617
 	// If we are in conversation, we may need to apply this to every message in the conversation.
2514 2618
 	if ($context['display_mode'] == 2 && isset($_REQUEST['conversation']))
2515 2619
 	{
2516 2620
 		$id_pms = array();
2517
-		foreach ($_REQUEST['pm_actions'] as $pm => $dummy)
2518
-			$id_pms[] = (int) $pm;
2621
+		foreach ($_REQUEST['pm_actions'] as $pm => $dummy) {
2622
+					$id_pms[] = (int) $pm;
2623
+		}
2519 2624
 
2520 2625
 		$request = $smcFunc['db_query']('', '
2521 2626
 			SELECT id_pm_head, id_pm
@@ -2526,8 +2631,9 @@  discard block
 block discarded – undo
2526 2631
 			)
2527 2632
 		);
2528 2633
 		$pm_heads = array();
2529
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2530
-			$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2634
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2635
+					$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2636
+		}
2531 2637
 		$smcFunc['db_free_result']($request);
2532 2638
 
2533 2639
 		$request = $smcFunc['db_query']('', '
@@ -2541,8 +2647,9 @@  discard block
 block discarded – undo
2541 2647
 		// Copy the action from the single to PM to the others.
2542 2648
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2543 2649
 		{
2544
-			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]))
2545
-				$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2650
+			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) {
2651
+							$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2652
+			}
2546 2653
 		}
2547 2654
 		$smcFunc['db_free_result']($request);
2548 2655
 	}
@@ -2553,22 +2660,21 @@  discard block
 block discarded – undo
2553 2660
 	$labels = array();
2554 2661
 	foreach ($_REQUEST['pm_actions'] as $pm => $action)
2555 2662
 	{
2556
-		if ($action === 'delete')
2557
-			$to_delete[] = (int) $pm;
2558
-		else
2663
+		if ($action === 'delete') {
2664
+					$to_delete[] = (int) $pm;
2665
+		} else
2559 2666
 		{
2560 2667
 			if (substr($action, 0, 4) == 'add_')
2561 2668
 			{
2562 2669
 				$type = 'add';
2563 2670
 				$action = substr($action, 4);
2564
-			}
2565
-			elseif (substr($action, 0, 4) == 'rem_')
2671
+			} elseif (substr($action, 0, 4) == 'rem_')
2566 2672
 			{
2567 2673
 				$type = 'rem';
2568 2674
 				$action = substr($action, 4);
2675
+			} else {
2676
+							$type = 'unk';
2569 2677
 			}
2570
-			else
2571
-				$type = 'unk';
2572 2678
 
2573 2679
 			if ($action == '-1' || (int) $action > 0)
2574 2680
 			{
@@ -2579,8 +2685,9 @@  discard block
 block discarded – undo
2579 2685
 	}
2580 2686
 
2581 2687
 	// Deleting, it looks like?
2582
-	if (!empty($to_delete))
2583
-		deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2688
+	if (!empty($to_delete)) {
2689
+			deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2690
+	}
2584 2691
 
2585 2692
 	// Are we labeling anything?
2586 2693
 	if (!empty($to_label) && $context['folder'] == 'inbox')
@@ -2646,8 +2753,7 @@  discard block
 block discarded – undo
2646 2753
 				}
2647 2754
 
2648 2755
 				$smcFunc['db_free_result']($request2);
2649
-			}
2650
-			elseif ($type == 'rem')
2756
+			} elseif ($type == 'rem')
2651 2757
 			{
2652 2758
 				// If we're removing from the inbox, see if we have at least one other label.
2653 2759
 				// This query is faster than the one above
@@ -2679,21 +2785,25 @@  discard block
 block discarded – undo
2679 2785
 			if ($to_label[$row['id_pm']] != '-1')
2680 2786
 			{
2681 2787
 				// If this label is in the list and we're not adding it, remove it
2682
-				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add')
2683
-					unset($labels[$to_label[$row['id_pm']]]);
2684
-				else if ($type !== 'rem')
2685
-					$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2788
+				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') {
2789
+									unset($labels[$to_label[$row['id_pm']]]);
2790
+				} else if ($type !== 'rem') {
2791
+									$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2792
+				}
2686 2793
 			}
2687 2794
 
2688 2795
 			// Removing all labels or just removing the inbox label
2689
-			if ($type == 'rem' && empty($labels))
2690
-				$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2796
+			if ($type == 'rem' && empty($labels)) {
2797
+							$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2798
+			}
2691 2799
 			// Adding new labels, but removing inbox and applying new ones
2692
-			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels))
2693
-				$in_inbox = 0;
2800
+			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) {
2801
+							$in_inbox = 0;
2802
+			}
2694 2803
 			// Just adding it to the inbox
2695
-			else
2696
-				$in_inbox = 1;
2804
+			else {
2805
+							$in_inbox = 1;
2806
+			}
2697 2807
 
2698 2808
 			// Are we adding it to or removing it from the inbox?
2699 2809
 			if ($in_inbox != $row['in_inbox'])
@@ -2735,8 +2845,9 @@  discard block
 block discarded – undo
2735 2845
 			if (!empty($labels_to_apply))
2736 2846
 			{
2737 2847
 				$inserts = array();
2738
-				foreach ($labels_to_apply as $label)
2739
-					$inserts[] = array($row['id_pm'], $label);
2848
+				foreach ($labels_to_apply as $label) {
2849
+									$inserts[] = array($row['id_pm'], $label);
2850
+				}
2740 2851
 
2741 2852
 				$smcFunc['db_insert']('',
2742 2853
 					'{db_prefix}pm_labeled_messages',
@@ -2780,11 +2891,13 @@  discard block
 block discarded – undo
2780 2891
 	checkSession('get');
2781 2892
 
2782 2893
 	// If all then delete all messages the user has.
2783
-	if ($_REQUEST['f'] == 'all')
2784
-		deleteMessages(null, null);
2894
+	if ($_REQUEST['f'] == 'all') {
2895
+			deleteMessages(null, null);
2896
+	}
2785 2897
 	// Otherwise just the selected folder.
2786
-	else
2787
-		deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2898
+	else {
2899
+			deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2900
+	}
2788 2901
 
2789 2902
 	// Done... all gone.
2790 2903
 	redirectexit($context['current_label_redirect']);
@@ -2821,8 +2934,9 @@  discard block
 block discarded – undo
2821 2934
 				'msgtime' => $deleteTime,
2822 2935
 			)
2823 2936
 		);
2824
-		while ($row = $smcFunc['db_fetch_row']($request))
2825
-			$toDelete[] = $row[0];
2937
+		while ($row = $smcFunc['db_fetch_row']($request)) {
2938
+					$toDelete[] = $row[0];
2939
+		}
2826 2940
 		$smcFunc['db_free_result']($request);
2827 2941
 
2828 2942
 		// Select all messages in their inbox older than $deleteTime.
@@ -2839,8 +2953,9 @@  discard block
 block discarded – undo
2839 2953
 				'msgtime' => $deleteTime,
2840 2954
 			)
2841 2955
 		);
2842
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2843
-			$toDelete[] = $row['id_pm'];
2956
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2957
+					$toDelete[] = $row['id_pm'];
2958
+		}
2844 2959
 		$smcFunc['db_free_result']($request);
2845 2960
 
2846 2961
 		// Delete the actual messages.
@@ -2871,26 +2986,29 @@  discard block
 block discarded – undo
2871 2986
 {
2872 2987
 	global $user_info, $smcFunc;
2873 2988
 
2874
-	if ($owner === null)
2875
-		$owner = array($user_info['id']);
2876
-	elseif (empty($owner))
2877
-		return;
2878
-	elseif (!is_array($owner))
2879
-		$owner = array($owner);
2989
+	if ($owner === null) {
2990
+			$owner = array($user_info['id']);
2991
+	} elseif (empty($owner)) {
2992
+			return;
2993
+	} elseif (!is_array($owner)) {
2994
+			$owner = array($owner);
2995
+	}
2880 2996
 
2881 2997
 	if ($personal_messages !== null)
2882 2998
 	{
2883
-		if (empty($personal_messages) || !is_array($personal_messages))
2884
-			return;
2999
+		if (empty($personal_messages) || !is_array($personal_messages)) {
3000
+					return;
3001
+		}
2885 3002
 
2886
-		foreach ($personal_messages as $index => $delete_id)
2887
-			$personal_messages[$index] = (int) $delete_id;
3003
+		foreach ($personal_messages as $index => $delete_id) {
3004
+					$personal_messages[$index] = (int) $delete_id;
3005
+		}
2888 3006
 
2889 3007
 		$where = '
2890 3008
 				AND id_pm IN ({array_int:pm_list})';
3009
+	} else {
3010
+			$where = '';
2891 3011
 	}
2892
-	else
2893
-		$where = '';
2894 3012
 
2895 3013
 	if ($folder == 'sent' || $folder === null)
2896 3014
 	{
@@ -2925,17 +3043,19 @@  discard block
 block discarded – undo
2925 3043
 		// ...And update the statistics accordingly - now including unread messages!.
2926 3044
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2927 3045
 		{
2928
-			if ($row['is_read'])
2929
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
2930
-			else
2931
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3046
+			if ($row['is_read']) {
3047
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
3048
+			} else {
3049
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3050
+			}
2932 3051
 
2933 3052
 			// If this is the current member we need to make their message count correct.
2934 3053
 			if ($user_info['id'] == $row['id_member'])
2935 3054
 			{
2936 3055
 				$user_info['messages'] -= $row['num_deleted_messages'];
2937
-				if (!($row['is_read']))
2938
-					$user_info['unread_messages'] -= $row['num_deleted_messages'];
3056
+				if (!($row['is_read'])) {
3057
+									$user_info['unread_messages'] -= $row['num_deleted_messages'];
3058
+				}
2939 3059
 			}
2940 3060
 		}
2941 3061
 		$smcFunc['db_free_result']($request);
@@ -3003,8 +3123,9 @@  discard block
 block discarded – undo
3003 3123
 		)
3004 3124
 	);
3005 3125
 	$remove_pms = array();
3006
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3007
-		$remove_pms[] = $row['sender'];
3126
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3127
+			$remove_pms[] = $row['sender'];
3128
+	}
3008 3129
 	$smcFunc['db_free_result']($request);
3009 3130
 
3010 3131
 	if (!empty($remove_pms))
@@ -3049,8 +3170,9 @@  discard block
 block discarded – undo
3049 3170
 {
3050 3171
 	global $user_info, $context, $smcFunc;
3051 3172
 
3052
-	if ($owner === null)
3053
-		$owner = $user_info['id'];
3173
+	if ($owner === null) {
3174
+			$owner = $user_info['id'];
3175
+	}
3054 3176
 
3055 3177
 	$in_inbox = '';
3056 3178
 
@@ -3074,8 +3196,7 @@  discard block
 block discarded – undo
3074 3196
 		}
3075 3197
 
3076 3198
 		$smcFunc['db_free_result']($get_messages);
3077
-	}
3078
-	elseif ($label = '-1')
3199
+	} elseif ($label = '-1')
3079 3200
 	{
3080 3201
 		// Marking all PMs in your inbox read
3081 3202
 		$in_inbox = '
@@ -3100,8 +3221,9 @@  discard block
 block discarded – undo
3100 3221
 	{
3101 3222
 		if ($owner == $user_info['id'])
3102 3223
 		{
3103
-			foreach ($context['labels'] as $label)
3104
-				$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3224
+			foreach ($context['labels'] as $label) {
3225
+							$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3226
+			}
3105 3227
 		}
3106 3228
 
3107 3229
 		$result = $smcFunc['db_query']('', '
@@ -3121,8 +3243,9 @@  discard block
 block discarded – undo
3121 3243
 		{
3122 3244
 			$total_unread += $row['num'];
3123 3245
 
3124
-			if ($owner != $user_info['id'] || empty($row['id_pm']))
3125
-				continue;
3246
+			if ($owner != $user_info['id'] || empty($row['id_pm'])) {
3247
+							continue;
3248
+			}
3126 3249
 
3127 3250
 			$this_labels = array();
3128 3251
 
@@ -3146,11 +3269,13 @@  discard block
 block discarded – undo
3146 3269
 
3147 3270
 			$smcFunc['db_free_result']($result2);
3148 3271
 
3149
-			foreach ($this_labels as $this_label)
3150
-				$context['labels'][$this_label]['unread_messages'] += $row['num'];
3272
+			foreach ($this_labels as $this_label) {
3273
+							$context['labels'][$this_label]['unread_messages'] += $row['num'];
3274
+			}
3151 3275
 
3152
-			if ($row['in_inbox'] == 1)
3153
-				$context['labels'][-1]['unread_messages'] += $row['num'];
3276
+			if ($row['in_inbox'] == 1) {
3277
+							$context['labels'][-1]['unread_messages'] += $row['num'];
3278
+			}
3154 3279
 		}
3155 3280
 		$smcFunc['db_free_result']($result);
3156 3281
 
@@ -3159,8 +3284,9 @@  discard block
 block discarded – undo
3159 3284
 		updateMemberData($owner, array('unread_messages' => $total_unread));
3160 3285
 
3161 3286
 		// If it was for the current member, reflect this in the $user_info array too.
3162
-		if ($owner == $user_info['id'])
3163
-			$user_info['unread_messages'] = $total_unread;
3287
+		if ($owner == $user_info['id']) {
3288
+					$user_info['unread_messages'] = $total_unread;
3289
+		}
3164 3290
 	}
3165 3291
 }
3166 3292
 
@@ -3188,8 +3314,9 @@  discard block
 block discarded – undo
3188 3314
 	// Add all existing labels to the array to save, slashing them as necessary...
3189 3315
 	foreach ($context['labels'] as $label)
3190 3316
 	{
3191
-		if ($label['id'] != -1)
3192
-			$the_labels[$label['id']] = $label['name'];
3317
+		if ($label['id'] != -1) {
3318
+					$the_labels[$label['id']] = $label['name'];
3319
+		}
3193 3320
 	}
3194 3321
 
3195 3322
 	if (isset($_POST[$context['session_var']]))
@@ -3208,8 +3335,9 @@  discard block
 block discarded – undo
3208 3335
 		{
3209 3336
 			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => '&#044;'));
3210 3337
 
3211
-			if ($smcFunc['strlen']($_POST['label']) > 30)
3212
-				$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3338
+			if ($smcFunc['strlen']($_POST['label']) > 30) {
3339
+							$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3340
+			}
3213 3341
 			if ($_POST['label'] != '')
3214 3342
 			{
3215 3343
 				$the_labels[] = $_POST['label'];
@@ -3230,23 +3358,24 @@  discard block
 block discarded – undo
3230 3358
 		{
3231 3359
 			foreach ($the_labels as $id => $name)
3232 3360
 			{
3233
-				if ($id == -1)
3234
-					continue;
3235
-				elseif (isset($_POST['label_name'][$id]))
3361
+				if ($id == -1) {
3362
+									continue;
3363
+				} elseif (isset($_POST['label_name'][$id]))
3236 3364
 				{
3237 3365
 					$_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => '&#044;')));
3238 3366
 
3239
-					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30)
3240
-						$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3367
+					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) {
3368
+											$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3369
+					}
3241 3370
 					if ($_POST['label_name'][$id] != '')
3242 3371
 					{
3243 3372
 						// Changing the name of this label?
3244
-						if ($the_labels[$id] != $_POST['label_name'][$id])
3245
-							$label_updates[$id] = $_POST['label_name'][$id];
3373
+						if ($the_labels[$id] != $_POST['label_name'][$id]) {
3374
+													$label_updates[$id] = $_POST['label_name'][$id];
3375
+						}
3246 3376
 
3247 3377
 						$the_labels[(int) $id] = $_POST['label_name'][$id];
3248
-					}
3249
-					else
3378
+					} else
3250 3379
 					{
3251 3380
 						unset($the_labels[(int) $id]);
3252 3381
 						$labels_to_remove[] = $id;
@@ -3260,8 +3389,9 @@  discard block
 block discarded – undo
3260 3389
 		if (!empty($labels_to_add))
3261 3390
 		{
3262 3391
 			$inserts = array();
3263
-			foreach ($labels_to_add AS $label)
3264
-				$inserts[] = array($user_info['id'], $label);
3392
+			foreach ($labels_to_add AS $label) {
3393
+							$inserts[] = array($user_info['id'], $label);
3394
+			}
3265 3395
 
3266 3396
 			$smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
3267 3397
 		}
@@ -3351,8 +3481,9 @@  discard block
 block discarded – undo
3351 3481
 				// Each action...
3352 3482
 				foreach ($rule['actions'] as $k2 => $action)
3353 3483
 				{
3354
-					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove))
3355
-						continue;
3484
+					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) {
3485
+											continue;
3486
+					}
3356 3487
 
3357 3488
 					$rule_changes[] = $rule['id'];
3358 3489
 
@@ -3367,8 +3498,8 @@  discard block
 block discarded – undo
3367 3498
 		{
3368 3499
 			$rule_changes = array_unique($rule_changes);
3369 3500
 			// Update/delete as appropriate.
3370
-			foreach ($rule_changes as $k => $id)
3371
-				if (!empty($context['rules'][$id]['actions']))
3501
+			foreach ($rule_changes as $k => $id) {
3502
+							if (!empty($context['rules'][$id]['actions']))
3372 3503
 				{
3373 3504
 					$smcFunc['db_query']('', '
3374 3505
 						UPDATE {db_prefix}pm_rules
@@ -3381,12 +3512,13 @@  discard block
 block discarded – undo
3381 3512
 							'actions' => $smcFunc['json_encode']($context['rules'][$id]['actions']),
3382 3513
 						)
3383 3514
 					);
3515
+			}
3384 3516
 					unset($rule_changes[$k]);
3385 3517
 				}
3386 3518
 
3387 3519
 			// Anything left here means it's lost all actions...
3388
-			if (!empty($rule_changes))
3389
-				$smcFunc['db_query']('', '
3520
+			if (!empty($rule_changes)) {
3521
+							$smcFunc['db_query']('', '
3390 3522
 					DELETE FROM {db_prefix}pm_rules
3391 3523
 					WHERE id_rule IN ({array_int:rule_list})
3392 3524
 							AND id_member = {int:current_member}',
@@ -3395,6 +3527,7 @@  discard block
 block discarded – undo
3395 3527
 						'rule_list' => $rule_changes,
3396 3528
 					)
3397 3529
 				);
3530
+			}
3398 3531
 		}
3399 3532
 
3400 3533
 		// Make sure we're not caching this!
@@ -3464,8 +3597,9 @@  discard block
 block discarded – undo
3464 3597
 		// Save the fields.
3465 3598
 		saveProfileFields();
3466 3599
 
3467
-		if (!empty($profile_vars))
3468
-			updateMemberData($user_info['id'], $profile_vars);
3600
+		if (!empty($profile_vars)) {
3601
+					updateMemberData($user_info['id'], $profile_vars);
3602
+		}
3469 3603
 	}
3470 3604
 
3471 3605
 	setupProfileContext(
@@ -3490,13 +3624,15 @@  discard block
 block discarded – undo
3490 3624
 	global $user_info, $language, $modSettings, $smcFunc;
3491 3625
 
3492 3626
 	// Check that this feature is even enabled!
3493
-	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg']))
3494
-		fatal_lang_error('no_access', false);
3627
+	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) {
3628
+			fatal_lang_error('no_access', false);
3629
+	}
3495 3630
 
3496 3631
 	$pmsg = (int) $_REQUEST['pmsg'];
3497 3632
 
3498
-	if (!isAccessiblePM($pmsg, 'inbox'))
3499
-		fatal_lang_error('no_access', false);
3633
+	if (!isAccessiblePM($pmsg, 'inbox')) {
3634
+			fatal_lang_error('no_access', false);
3635
+	}
3500 3636
 
3501 3637
 	$context['pm_id'] = $pmsg;
3502 3638
 	$context['page_title'] = $txt['pm_report_title'];
@@ -3518,8 +3654,9 @@  discard block
 block discarded – undo
3518 3654
 			)
3519 3655
 		);
3520 3656
 		$context['admins'] = array();
3521
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3522
-			$context['admins'][$row['id_member']] = $row['real_name'];
3657
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3658
+					$context['admins'][$row['id_member']] = $row['real_name'];
3659
+		}
3523 3660
 		$smcFunc['db_free_result']($request);
3524 3661
 
3525 3662
 		// How many admins in total?
@@ -3548,8 +3685,9 @@  discard block
 block discarded – undo
3548 3685
 			)
3549 3686
 		);
3550 3687
 		// Can only be a hacker here!
3551
-		if ($smcFunc['db_num_rows']($request) == 0)
3552
-			fatal_lang_error('no_access', false);
3688
+		if ($smcFunc['db_num_rows']($request) == 0) {
3689
+					fatal_lang_error('no_access', false);
3690
+		}
3553 3691
 		list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);
3554 3692
 		$smcFunc['db_free_result']($request);
3555 3693
 
@@ -3573,15 +3711,17 @@  discard block
 block discarded – undo
3573 3711
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3574 3712
 		{
3575 3713
 			// If it's hidden still don't reveal their names - privacy after all ;)
3576
-			if ($row['bcc'])
3577
-				$hidden_recipients++;
3578
-			else
3579
-				$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3714
+			if ($row['bcc']) {
3715
+							$hidden_recipients++;
3716
+			} else {
3717
+							$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3718
+			}
3580 3719
 		}
3581 3720
 		$smcFunc['db_free_result']($request);
3582 3721
 
3583
-		if ($hidden_recipients)
3584
-			$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3722
+		if ($hidden_recipients) {
3723
+					$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3724
+		}
3585 3725
 
3586 3726
 		// Now let's get out and loop through the admins.
3587 3727
 		$request = $smcFunc['db_query']('', '
@@ -3597,8 +3737,9 @@  discard block
 block discarded – undo
3597 3737
 		);
3598 3738
 
3599 3739
 		// Maybe we shouldn't advertise this?
3600
-		if ($smcFunc['db_num_rows']($request) == 0)
3601
-			fatal_lang_error('no_access', false);
3740
+		if ($smcFunc['db_num_rows']($request) == 0) {
3741
+					fatal_lang_error('no_access', false);
3742
+		}
3602 3743
 
3603 3744
 		$memberFromName = un_htmlspecialchars($memberFromName);
3604 3745
 
@@ -3617,8 +3758,9 @@  discard block
 block discarded – undo
3617 3758
 				// Make the body.
3618 3759
 				$report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']);
3619 3760
 				$report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n";
3620
-				if (!empty($recipients))
3621
-					$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3761
+				if (!empty($recipients)) {
3762
+									$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3763
+				}
3622 3764
 				$report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '&quot;' . $memberFromName . '&quot;' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]';
3623 3765
 
3624 3766
 				// Plonk it in the array ;)
@@ -3638,12 +3780,14 @@  discard block
 block discarded – undo
3638 3780
 		$smcFunc['db_free_result']($request);
3639 3781
 
3640 3782
 		// Send a different email for each language.
3641
-		foreach ($messagesToSend as $lang => $message)
3642
-			sendpm($message['recipients'], $message['subject'], $message['body']);
3783
+		foreach ($messagesToSend as $lang => $message) {
3784
+					sendpm($message['recipients'], $message['subject'], $message['body']);
3785
+		}
3643 3786
 
3644 3787
 		// Give the user their own language back!
3645
-		if (!empty($modSettings['userLanguage']))
3646
-			loadLanguage('PersonalMessage', '', false);
3788
+		if (!empty($modSettings['userLanguage'])) {
3789
+					loadLanguage('PersonalMessage', '', false);
3790
+		}
3647 3791
 
3648 3792
 		// Leave them with a template.
3649 3793
 		$context['sub_template'] = 'report_message_complete';
@@ -3689,8 +3833,9 @@  discard block
 block discarded – undo
3689 3833
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3690 3834
 	{
3691 3835
 		// Hide hidden groups!
3692
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
3693
-			continue;
3836
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
3837
+					continue;
3838
+		}
3694 3839
 
3695 3840
 		$context['groups'][$row['id_group']] = $row['group_name'];
3696 3841
 	}
@@ -3716,9 +3861,10 @@  discard block
 block discarded – undo
3716 3861
 			$context['rule'] = $context['rules'][$context['rid']];
3717 3862
 			$members = array();
3718 3863
 			// Need to get member names!
3719
-			foreach ($context['rule']['criteria'] as $k => $criteria)
3720
-				if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3864
+			foreach ($context['rule']['criteria'] as $k => $criteria) {
3865
+							if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3721 3866
 					$members[(int) $criteria['v']] = $k;
3867
+			}
3722 3868
 
3723 3869
 			if (!empty($members))
3724 3870
 			{
@@ -3730,19 +3876,20 @@  discard block
 block discarded – undo
3730 3876
 						'member_list' => array_keys($members),
3731 3877
 					)
3732 3878
 				);
3733
-				while ($row = $smcFunc['db_fetch_assoc']($request))
3734
-					$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3879
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
3880
+									$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3881
+				}
3735 3882
 				$smcFunc['db_free_result']($request);
3736 3883
 			}
3737
-		}
3738
-		else
3739
-			$context['rule'] = array(
3884
+		} else {
3885
+					$context['rule'] = array(
3740 3886
 				'id' => '',
3741 3887
 				'name' => '',
3742 3888
 				'criteria' => array(),
3743 3889
 				'actions' => array(),
3744 3890
 				'logic' => 'and',
3745 3891
 			);
3892
+		}
3746 3893
 	}
3747 3894
 	// Saving?
3748 3895
 	elseif (isset($_GET['save']))
@@ -3752,22 +3899,25 @@  discard block
 block discarded – undo
3752 3899
 
3753 3900
 		// Name is easy!
3754 3901
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
3755
-		if (empty($ruleName))
3756
-			fatal_lang_error('pm_rule_no_name', false);
3902
+		if (empty($ruleName)) {
3903
+					fatal_lang_error('pm_rule_no_name', false);
3904
+		}
3757 3905
 
3758 3906
 		// Sanity check...
3759
-		if (empty($_POST['ruletype']) || empty($_POST['acttype']))
3760
-			fatal_lang_error('pm_rule_no_criteria', false);
3907
+		if (empty($_POST['ruletype']) || empty($_POST['acttype'])) {
3908
+					fatal_lang_error('pm_rule_no_criteria', false);
3909
+		}
3761 3910
 
3762 3911
 		// Let's do the criteria first - it's also hardest!
3763 3912
 		$criteria = array();
3764 3913
 		foreach ($_POST['ruletype'] as $ind => $type)
3765 3914
 		{
3766 3915
 			// Check everything is here...
3767
-			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]])))
3768
-				continue;
3769
-			elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind]))
3770
-				continue;
3916
+			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) {
3917
+							continue;
3918
+			} elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) {
3919
+							continue;
3920
+			}
3771 3921
 
3772 3922
 			// Members need to be found.
3773 3923
 			if ($type == 'mid')
@@ -3791,13 +3941,13 @@  discard block
 block discarded – undo
3791 3941
 				$smcFunc['db_free_result']($request);
3792 3942
 
3793 3943
 				$criteria[] = array('t' => 'mid', 'v' => $memID);
3944
+			} elseif ($type == 'bud') {
3945
+							$criteria[] = array('t' => 'bud', 'v' => 1);
3946
+			} elseif ($type == 'gid') {
3947
+							$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3948
+			} elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') {
3949
+							$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3794 3950
 			}
3795
-			elseif ($type == 'bud')
3796
-				$criteria[] = array('t' => 'bud', 'v' => 1);
3797
-			elseif ($type == 'gid')
3798
-				$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3799
-			elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '')
3800
-				$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3801 3951
 		}
3802 3952
 
3803 3953
 		// Also do the actions!
@@ -3807,26 +3957,29 @@  discard block
 block discarded – undo
3807 3957
 		foreach ($_POST['acttype'] as $ind => $type)
3808 3958
 		{
3809 3959
 			// Picking a valid label?
3810
-			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]])))
3811
-				continue;
3960
+			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) {
3961
+							continue;
3962
+			}
3812 3963
 
3813 3964
 			// Record what we're doing.
3814
-			if ($type == 'del')
3815
-				$doDelete = 1;
3816
-			elseif ($type == 'lab')
3817
-				$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3965
+			if ($type == 'del') {
3966
+							$doDelete = 1;
3967
+			} elseif ($type == 'lab') {
3968
+							$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3969
+			}
3818 3970
 		}
3819 3971
 
3820
-		if (empty($criteria) || (empty($actions) && !$doDelete))
3821
-			fatal_lang_error('pm_rule_no_criteria', false);
3972
+		if (empty($criteria) || (empty($actions) && !$doDelete)) {
3973
+					fatal_lang_error('pm_rule_no_criteria', false);
3974
+		}
3822 3975
 
3823 3976
 		// What are we storing?
3824 3977
 		$criteria = $smcFunc['json_encode']($criteria);
3825 3978
 		$actions = $smcFunc['json_encode']($actions);
3826 3979
 
3827 3980
 		// Create the rule?
3828
-		if (empty($context['rid']))
3829
-			$smcFunc['db_insert']('',
3981
+		if (empty($context['rid'])) {
3982
+					$smcFunc['db_insert']('',
3830 3983
 				'{db_prefix}pm_rules',
3831 3984
 				array(
3832 3985
 					'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string',
@@ -3837,8 +3990,8 @@  discard block
 block discarded – undo
3837 3990
 				),
3838 3991
 				array('id_rule')
3839 3992
 			);
3840
-		else
3841
-			$smcFunc['db_query']('', '
3993
+		} else {
3994
+					$smcFunc['db_query']('', '
3842 3995
 				UPDATE {db_prefix}pm_rules
3843 3996
 				SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions},
3844 3997
 					delete_pm = {int:delete_pm}, is_or = {int:is_or}
@@ -3854,6 +4007,7 @@  discard block
 block discarded – undo
3854 4007
 					'actions' => $actions,
3855 4008
 				)
3856 4009
 			);
4010
+		}
3857 4011
 
3858 4012
 		redirectexit('action=pm;sa=manrules');
3859 4013
 	}
@@ -3862,11 +4016,12 @@  discard block
 block discarded – undo
3862 4016
 	{
3863 4017
 		checkSession();
3864 4018
 		$toDelete = array();
3865
-		foreach ($_POST['delrule'] as $k => $v)
3866
-			$toDelete[] = (int) $k;
4019
+		foreach ($_POST['delrule'] as $k => $v) {
4020
+					$toDelete[] = (int) $k;
4021
+		}
3867 4022
 
3868
-		if (!empty($toDelete))
3869
-			$smcFunc['db_query']('', '
4023
+		if (!empty($toDelete)) {
4024
+					$smcFunc['db_query']('', '
3870 4025
 				DELETE FROM {db_prefix}pm_rules
3871 4026
 				WHERE id_rule IN ({array_int:delete_list})
3872 4027
 					AND id_member = {int:current_member}',
@@ -3875,6 +4030,7 @@  discard block
 block discarded – undo
3875 4030
 					'delete_list' => $toDelete,
3876 4031
 				)
3877 4032
 			);
4033
+		}
3878 4034
 
3879 4035
 		redirectexit('action=pm;sa=manrules');
3880 4036
 	}
@@ -3893,8 +4049,9 @@  discard block
 block discarded – undo
3893 4049
 	loadRules();
3894 4050
 
3895 4051
 	// No rules?
3896
-	if (empty($context['rules']))
3897
-		return;
4052
+	if (empty($context['rules'])) {
4053
+			return;
4054
+	}
3898 4055
 
3899 4056
 	// Just unread ones?
3900 4057
 	$ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1';
@@ -3924,8 +4081,9 @@  discard block
 block discarded – undo
3924 4081
 			// Loop through all the criteria hoping to make a match.
3925 4082
 			foreach ($rule['criteria'] as $criterium)
3926 4083
 			{
3927
-				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false))
3928
-					$match = true;
4084
+				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) {
4085
+									$match = true;
4086
+				}
3929 4087
 				// If we're adding and one criteria don't match then we stop!
3930 4088
 				elseif ($rule['logic'] == 'and')
3931 4089
 				{
@@ -3937,17 +4095,18 @@  discard block
 block discarded – undo
3937 4095
 			// If we have a match the rule must be true - act!
3938 4096
 			if ($match)
3939 4097
 			{
3940
-				if ($rule['delete'])
3941
-					$actions['deletes'][] = $row['id_pm'];
3942
-				else
4098
+				if ($rule['delete']) {
4099
+									$actions['deletes'][] = $row['id_pm'];
4100
+				} else
3943 4101
 				{
3944 4102
 					foreach ($rule['actions'] as $ruleAction)
3945 4103
 					{
3946 4104
 						if ($ruleAction['t'] == 'lab')
3947 4105
 						{
3948 4106
 							// Get a basic pot started!
3949
-							if (!isset($actions['labels'][$row['id_pm']]))
3950
-								$actions['labels'][$row['id_pm']] = array();
4107
+							if (!isset($actions['labels'][$row['id_pm']])) {
4108
+															$actions['labels'][$row['id_pm']] = array();
4109
+							}
3951 4110
 							$actions['labels'][$row['id_pm']][] = $ruleAction['v'];
3952 4111
 						}
3953 4112
 					}
@@ -3958,8 +4117,9 @@  discard block
 block discarded – undo
3958 4117
 	$smcFunc['db_free_result']($request);
3959 4118
 
3960 4119
 	// Deletes are easy!
3961
-	if (!empty($actions['deletes']))
3962
-		deleteMessages($actions['deletes']);
4120
+	if (!empty($actions['deletes'])) {
4121
+			deleteMessages($actions['deletes']);
4122
+	}
3963 4123
 
3964 4124
 	// Relabel?
3965 4125
 	if (!empty($actions['labels']))
@@ -3986,8 +4146,7 @@  discard block
 block discarded – undo
3986 4146
 								'current_member' => $user_info['id'],
3987 4147
 							)
3988 4148
 						);
3989
-					}
3990
-					else
4149
+					} else
3991 4150
 					{
3992 4151
 						$realLabels[] = $label['id'];
3993 4152
 					}
@@ -3996,8 +4155,9 @@  discard block
 block discarded – undo
3996 4155
 
3997 4156
 			$inserts = array();
3998 4157
 			// Now we insert the label info
3999
-			foreach ($realLabels as $a_label)
4000
-				$inserts[] = array($pm, $a_label);
4158
+			foreach ($realLabels as $a_label) {
4159
+							$inserts[] = array($pm, $a_label);
4160
+			}
4001 4161
 
4002 4162
 			$smcFunc['db_insert']('ignore',
4003 4163
 				'{db_prefix}pm_labeled_messages',
@@ -4018,8 +4178,9 @@  discard block
 block discarded – undo
4018 4178
 {
4019 4179
 	global $user_info, $context, $smcFunc;
4020 4180
 
4021
-	if (isset($context['rules']) && !$reload)
4022
-		return;
4181
+	if (isset($context['rules']) && !$reload) {
4182
+			return;
4183
+	}
4023 4184
 
4024 4185
 	$request = $smcFunc['db_query']('', '
4025 4186
 		SELECT
@@ -4043,8 +4204,9 @@  discard block
 block discarded – undo
4043 4204
 			'logic' => $row['is_or'] ? 'or' : 'and',
4044 4205
 		);
4045 4206
 
4046
-		if ($row['delete_pm'])
4047
-			$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4207
+		if ($row['delete_pm']) {
4208
+					$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4209
+		}
4048 4210
 	}
4049 4211
 	$smcFunc['db_free_result']($request);
4050 4212
 }
Please login to merge, or discard this patch.