Completed
Push — release-2.1 ( 3bcfde...9b1f72 )
by Michael
18:23 queued 11:46
created
Sources/Post.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -259,8 +259,8 @@
 block discarded – undo
259 259
 			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
260 260
 
261 261
 		$js_time_string = str_replace(
262
-			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
263
-			array('H',  'G',  'h',  'g',  'i',  'A',  'a',  'h:i:s A', 'H:i', 's',  'H:i:s', 'H:i:s'),
262
+			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'),
263
+			array('H', 'G', 'h', 'g', 'i', 'A', 'a', 'h:i:s A', 'H:i', 's', 'H:i:s', 'H:i:s'),
264 264
 			$time_string
265 265
 		);
266 266
 
Please login to merge, or discard this patch.
Braces   +664 added lines, -515 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * 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']);
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	$context['auto_notify'] = !empty($context['notify_prefs']['msg_auto_notify']);
56 59
 
57 60
 	// You must be posting to *some* board.
58
-	if (empty($board) && !$context['make_event'])
59
-		fatal_lang_error('no_board', false);
61
+	if (empty($board) && !$context['make_event']) {
62
+			fatal_lang_error('no_board', false);
63
+	}
60 64
 
61 65
 	require_once($sourcedir . '/Subs-Post.php');
62 66
 
@@ -79,10 +83,11 @@  discard block
 block discarded – undo
79 83
 			array(
80 84
 				'msg' => (int) $_REQUEST['msg'],
81 85
 		));
82
-		if ($smcFunc['db_num_rows']($request) != 1)
83
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
84
-		else
85
-			list ($topic) = $smcFunc['db_fetch_row']($request);
86
+		if ($smcFunc['db_num_rows']($request) != 1) {
87
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
88
+		} else {
89
+					list ($topic) = $smcFunc['db_fetch_row']($request);
90
+		}
86 91
 		$smcFunc['db_free_result']($request);
87 92
 	}
88 93
 
@@ -109,33 +114,36 @@  discard block
 block discarded – undo
109 114
 		$smcFunc['db_free_result']($request);
110 115
 
111 116
 		// If this topic already has a poll, they sure can't add another.
112
-		if (isset($_REQUEST['poll']) && $pollID > 0)
113
-			unset($_REQUEST['poll']);
117
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
118
+					unset($_REQUEST['poll']);
119
+		}
114 120
 
115 121
 		if (empty($_REQUEST['msg']))
116 122
 		{
117
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
118
-				is_not_guest();
123
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
124
+							is_not_guest();
125
+			}
119 126
 
120 127
 			// By default the reply will be approved...
121 128
 			$context['becomes_approved'] = true;
122 129
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
123 130
 			{
124
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
125
-					$context['becomes_approved'] = false;
126
-				else
127
-					isAllowedTo('post_reply_any');
128
-			}
129
-			elseif (!allowedTo('post_reply_any'))
131
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
132
+									$context['becomes_approved'] = false;
133
+				} else {
134
+									isAllowedTo('post_reply_any');
135
+				}
136
+			} elseif (!allowedTo('post_reply_any'))
130 137
 			{
131
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
132
-					$context['becomes_approved'] = false;
133
-				else
134
-					isAllowedTo('post_reply_own');
138
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
139
+									$context['becomes_approved'] = false;
140
+				} else {
141
+									isAllowedTo('post_reply_own');
142
+				}
135 143
 			}
144
+		} else {
145
+					$context['becomes_approved'] = true;
136 146
 		}
137
-		else
138
-			$context['becomes_approved'] = true;
139 147
 
140 148
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
141 149
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -147,18 +155,19 @@  discard block
 block discarded – undo
147 155
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
148 156
 
149 157
 		// Check whether this is a really old post being bumped...
150
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
151
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
152
-	}
153
-	else
158
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
159
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
160
+		}
161
+	} else
154 162
 	{
155 163
 		$context['becomes_approved'] = true;
156 164
 		if ((!$context['make_event'] || !empty($board)))
157 165
 		{
158
-			if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
159
-				$context['becomes_approved'] = false;
160
-			else
161
-				isAllowedTo('post_new');
166
+			if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
167
+							$context['becomes_approved'] = false;
168
+			} else {
169
+							isAllowedTo('post_new');
170
+			}
162 171
 		}
163 172
 
164 173
 		$locked = 0;
@@ -196,20 +205,24 @@  discard block
 block discarded – undo
196 205
 	}
197 206
 
198 207
 	// Don't allow a post if it's locked and you aren't all powerful.
199
-	if ($locked && !allowedTo('moderate_board'))
200
-		fatal_lang_error('topic_locked', false);
208
+	if ($locked && !allowedTo('moderate_board')) {
209
+			fatal_lang_error('topic_locked', false);
210
+	}
201 211
 	// Check the users permissions - is the user allowed to add or post a poll?
202 212
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
203 213
 	{
204 214
 		// New topic, new poll.
205
-		if (empty($topic))
206
-			isAllowedTo('poll_post');
215
+		if (empty($topic)) {
216
+					isAllowedTo('poll_post');
217
+		}
207 218
 		// This is an old topic - but it is yours!  Can you add to it?
208
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
209
-			isAllowedTo('poll_add_own');
219
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
220
+					isAllowedTo('poll_add_own');
221
+		}
210 222
 		// If you're not the owner, can you add to any poll?
211
-		else
212
-			isAllowedTo('poll_add_any');
223
+		else {
224
+					isAllowedTo('poll_add_any');
225
+		}
213 226
 
214 227
 		require_once($sourcedir . '/Subs-Members.php');
215 228
 		$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
@@ -238,8 +251,9 @@  discard block
 block discarded – undo
238 251
 	if ($context['make_event'])
239 252
 	{
240 253
 		// They might want to pick a board.
241
-		if (!isset($context['current_board']))
242
-			$context['current_board'] = 0;
254
+		if (!isset($context['current_board'])) {
255
+					$context['current_board'] = 0;
256
+		}
243 257
 
244 258
 		// Start loading up the event info.
245 259
 		$context['event'] = array();
@@ -253,10 +267,11 @@  discard block
 block discarded – undo
253 267
 		isAllowedTo('calendar_post');
254 268
 
255 269
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
256
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
257
-			$time_string = '%k:%M';
258
-		else
259
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
270
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
271
+					$time_string = '%k:%M';
272
+		} else {
273
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
274
+		}
260 275
 
261 276
 		$js_time_string = str_replace(
262 277
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -278,8 +293,7 @@  discard block
 block discarded – undo
278 293
 			require_once($sourcedir . '/Subs-Calendar.php');
279 294
 			$eventProperties = getEventProperties($context['event']['id']);
280 295
 			$context['event'] = array_merge($context['event'], $eventProperties);
281
-		}
282
-		else
296
+		} else
283 297
 		{
284 298
 			// Get the current event information.
285 299
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -287,15 +301,18 @@  discard block
 block discarded – undo
287 301
 			$context['event'] = array_merge($context['event'], $eventProperties);
288 302
 
289 303
 			// Make sure the year and month are in the valid range.
290
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
291
-				fatal_lang_error('invalid_month', false);
292
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
293
-				fatal_lang_error('invalid_year', false);
304
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
305
+							fatal_lang_error('invalid_month', false);
306
+			}
307
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
308
+							fatal_lang_error('invalid_year', false);
309
+			}
294 310
 
295 311
 			// Get a list of boards they can post in.
296 312
 			$boards = boardsAllowedTo('post_new');
297
-			if (empty($boards))
298
-				fatal_lang_error('cannot_post_new', 'user');
313
+			if (empty($boards)) {
314
+							fatal_lang_error('cannot_post_new', 'user');
315
+			}
299 316
 
300 317
 			// Load a list of boards for this event in the context.
301 318
 			require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -414,10 +431,11 @@  discard block
 block discarded – undo
414 431
 
415 432
 			if (!empty($context['new_replies']))
416 433
 			{
417
-				if ($context['new_replies'] == 1)
418
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
419
-				else
420
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
434
+				if ($context['new_replies'] == 1) {
435
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
436
+				} else {
437
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
438
+				}
421 439
 
422 440
 				$post_errors[] = 'new_replies';
423 441
 
@@ -429,9 +447,9 @@  discard block
 block discarded – undo
429 447
 	// Get a response prefix (like 'Re:') in the default forum language.
430 448
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
431 449
 	{
432
-		if ($language === $user_info['language'])
433
-			$context['response_prefix'] = $txt['response_prefix'];
434
-		else
450
+		if ($language === $user_info['language']) {
451
+					$context['response_prefix'] = $txt['response_prefix'];
452
+		} else
435 453
 		{
436 454
 			loadLanguage('index', $language, false);
437 455
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -444,8 +462,9 @@  discard block
 block discarded – undo
444 462
 	// Do we have a body, but an error happened.
445 463
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
446 464
 	{
447
-		if (isset($_REQUEST['quickReply']))
448
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
465
+		if (isset($_REQUEST['quickReply'])) {
466
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
467
+		}
449 468
 
450 469
 		// Validate inputs.
451 470
 		if (empty($context['post_error']))
@@ -453,15 +472,17 @@  discard block
 block discarded – undo
453 472
 			// This means they didn't click Post and get an error.
454 473
 			$really_previewing = true;
455 474
 
456
-		}
457
-		else
475
+		} else
458 476
 		{
459
-			if (!isset($_REQUEST['subject']))
460
-				$_REQUEST['subject'] = '';
461
-			if (!isset($_REQUEST['message']))
462
-				$_REQUEST['message'] = '';
463
-			if (!isset($_REQUEST['icon']))
464
-				$_REQUEST['icon'] = 'xx';
477
+			if (!isset($_REQUEST['subject'])) {
478
+							$_REQUEST['subject'] = '';
479
+			}
480
+			if (!isset($_REQUEST['message'])) {
481
+							$_REQUEST['message'] = '';
482
+			}
483
+			if (!isset($_REQUEST['icon'])) {
484
+							$_REQUEST['icon'] = 'xx';
485
+			}
465 486
 
466 487
 			// They are previewing if they asked to preview (i.e. came from quick reply).
467 488
 			$really_previewing = !empty($_POST['preview']);
@@ -477,8 +498,9 @@  discard block
 block discarded – undo
477 498
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
478 499
 
479 500
 		// Make sure the subject isn't too long - taking into account special characters.
480
-		if ($smcFunc['strlen']($form_subject) > 100)
481
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
501
+		if ($smcFunc['strlen']($form_subject) > 100) {
502
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
503
+		}
482 504
 
483 505
 		if (isset($_REQUEST['poll']))
484 506
 		{
@@ -490,8 +512,9 @@  discard block
 block discarded – undo
490 512
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
491 513
 			foreach ($_POST['options'] as $option)
492 514
 			{
493
-				if (trim($option) == '')
494
-					continue;
515
+				if (trim($option) == '') {
516
+									continue;
517
+				}
495 518
 
496 519
 				$context['choices'][] = array(
497 520
 					'id' => $choice_id++,
@@ -553,13 +576,14 @@  discard block
 block discarded – undo
553 576
 				$context['preview_subject'] = $form_subject;
554 577
 
555 578
 				censorText($context['preview_subject']);
579
+			} else {
580
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
556 581
 			}
557
-			else
558
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
559 582
 
560 583
 			// Protect any CDATA blocks.
561
-			if (isset($_REQUEST['xml']))
562
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
584
+			if (isset($_REQUEST['xml'])) {
585
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
586
+			}
563 587
 		}
564 588
 
565 589
 		// Set up the checkboxes.
@@ -598,29 +622,32 @@  discard block
 block discarded – undo
598 622
 			);
599 623
 			// The message they were trying to edit was most likely deleted.
600 624
 			// @todo Change this error message?
601
-			if ($smcFunc['db_num_rows']($request) == 0)
602
-				fatal_lang_error('no_board', false);
625
+			if ($smcFunc['db_num_rows']($request) == 0) {
626
+							fatal_lang_error('no_board', false);
627
+			}
603 628
 			$row = $smcFunc['db_fetch_assoc']($request);
604 629
 
605 630
 			$attachment_stuff = array($row);
606
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
607
-				$attachment_stuff[] = $row2;
631
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
632
+							$attachment_stuff[] = $row2;
633
+			}
608 634
 			$smcFunc['db_free_result']($request);
609 635
 
610 636
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
611 637
 			{
612 638
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
613
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
614
-					fatal_lang_error('modify_post_time_passed', false);
615
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
616
-					isAllowedTo('modify_replies');
617
-				else
618
-					isAllowedTo('modify_own');
639
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
640
+									fatal_lang_error('modify_post_time_passed', false);
641
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
642
+									isAllowedTo('modify_replies');
643
+				} else {
644
+									isAllowedTo('modify_own');
645
+				}
646
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
647
+							isAllowedTo('modify_replies');
648
+			} else {
649
+							isAllowedTo('modify_any');
619 650
 			}
620
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
621
-				isAllowedTo('modify_replies');
622
-			else
623
-				isAllowedTo('modify_any');
624 651
 
625 652
 			if ($context['can_announce'] && !empty($row['id_action']))
626 653
 			{
@@ -644,8 +671,9 @@  discard block
 block discarded – undo
644 671
 
645 672
 				while ($row = $smcFunc['db_fetch_assoc']($request))
646 673
 				{
647
-					if ($row['filesize'] <= 0)
648
-						continue;
674
+					if ($row['filesize'] <= 0) {
675
+											continue;
676
+					}
649 677
 					$context['current_attachments'][$row['id_attach']] = array(
650 678
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
651 679
 						'size' => $row['filesize'],
@@ -715,29 +743,32 @@  discard block
 block discarded – undo
715 743
 			)
716 744
 		);
717 745
 		// The message they were trying to edit was most likely deleted.
718
-		if ($smcFunc['db_num_rows']($request) == 0)
719
-			fatal_lang_error('no_message', false);
746
+		if ($smcFunc['db_num_rows']($request) == 0) {
747
+					fatal_lang_error('no_message', false);
748
+		}
720 749
 		$row = $smcFunc['db_fetch_assoc']($request);
721 750
 
722 751
 		$attachment_stuff = array($row);
723
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
724
-			$attachment_stuff[] = $row2;
752
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
753
+					$attachment_stuff[] = $row2;
754
+		}
725 755
 		$smcFunc['db_free_result']($request);
726 756
 
727 757
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
728 758
 		{
729 759
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
730
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
731
-				fatal_lang_error('modify_post_time_passed', false);
732
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
733
-				isAllowedTo('modify_replies');
734
-			else
735
-				isAllowedTo('modify_own');
760
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
761
+							fatal_lang_error('modify_post_time_passed', false);
762
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
763
+							isAllowedTo('modify_replies');
764
+			} else {
765
+							isAllowedTo('modify_own');
766
+			}
767
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
768
+					isAllowedTo('modify_replies');
769
+		} else {
770
+					isAllowedTo('modify_any');
736 771
 		}
737
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
738
-			isAllowedTo('modify_replies');
739
-		else
740
-			isAllowedTo('modify_any');
741 772
 
742 773
 		if ($context['can_announce'] && !empty($row['id_action']))
743 774
 		{
@@ -764,15 +795,17 @@  discard block
 block discarded – undo
764 795
 		$context['icon'] = $row['icon'];
765 796
 
766 797
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
767
-		if (!$row['approved'] && !$context['show_approval'])
768
-			$context['show_approval'] = allowedTo('approve_posts');
798
+		if (!$row['approved'] && !$context['show_approval']) {
799
+					$context['show_approval'] = allowedTo('approve_posts');
800
+		}
769 801
 
770 802
 		// Sort the attachments so they are in the order saved
771 803
 		$temp = array();
772 804
 		foreach ($attachment_stuff as $attachment)
773 805
 		{
774
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
775
-				$temp[$attachment['id_attach']] = $attachment;
806
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
807
+							$temp[$attachment['id_attach']] = $attachment;
808
+			}
776 809
 
777 810
 		}
778 811
 		ksort($temp);
@@ -834,14 +867,16 @@  discard block
 block discarded – undo
834 867
 					'is_approved' => 1,
835 868
 				)
836 869
 			);
837
-			if ($smcFunc['db_num_rows']($request) == 0)
838
-				fatal_lang_error('quoted_post_deleted', false);
870
+			if ($smcFunc['db_num_rows']($request) == 0) {
871
+							fatal_lang_error('quoted_post_deleted', false);
872
+			}
839 873
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
840 874
 			$smcFunc['db_free_result']($request);
841 875
 
842 876
 			// Add 'Re: ' to the front of the quoted subject.
843
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
844
-				$form_subject = $context['response_prefix'] . $form_subject;
877
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
878
+							$form_subject = $context['response_prefix'] . $form_subject;
879
+			}
845 880
 
846 881
 			// Censor the message and subject.
847 882
 			censorText($form_message);
@@ -854,10 +889,11 @@  discard block
 block discarded – undo
854 889
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
855 890
 				{
856 891
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
857
-					if ($i % 4 == 0)
858
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
892
+					if ($i % 4 == 0) {
893
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
859 894
 						{
860 895
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
896
+					}
861 897
 						}, $parts[$i]);
862 898
 				}
863 899
 				$form_message = implode('', $parts);
@@ -866,8 +902,9 @@  discard block
 block discarded – undo
866 902
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
867 903
 
868 904
 			// Remove any nested quotes, if necessary.
869
-			if (!empty($modSettings['removeNestedQuotes']))
870
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
905
+			if (!empty($modSettings['removeNestedQuotes'])) {
906
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
907
+			}
871 908
 
872 909
 			// Add a quote string on the front and end.
873 910
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -879,15 +916,15 @@  discard block
 block discarded – undo
879 916
 			$form_subject = $first_subject;
880 917
 
881 918
 			// Add 'Re: ' to the front of the subject.
882
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
883
-				$form_subject = $context['response_prefix'] . $form_subject;
919
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
920
+							$form_subject = $context['response_prefix'] . $form_subject;
921
+			}
884 922
 
885 923
 			// Censor the subject.
886 924
 			censorText($form_subject);
887 925
 
888 926
 			$form_message = '';
889
-		}
890
-		else
927
+		} else
891 928
 		{
892 929
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
893 930
 			$form_message = '';
@@ -905,13 +942,15 @@  discard block
 block discarded – undo
905 942
 		if (isset($_REQUEST['msg']))
906 943
 		{
907 944
 			$context['attachments']['quantity'] = count($context['current_attachments']);
908
-			foreach ($context['current_attachments'] as $attachment)
909
-				$context['attachments']['total_size'] += $attachment['size'];
945
+			foreach ($context['current_attachments'] as $attachment) {
946
+							$context['attachments']['total_size'] += $attachment['size'];
947
+			}
910 948
 		}
911 949
 
912 950
 		// A bit of house keeping first.
913
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
914
-			unset($_SESSION['temp_attachments']);
951
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
952
+					unset($_SESSION['temp_attachments']);
953
+		}
915 954
 
916 955
 		if (!empty($_SESSION['temp_attachments']))
917 956
 		{
@@ -920,9 +959,10 @@  discard block
 block discarded – undo
920 959
 			{
921 960
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
922 961
 				{
923
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
924
-						if (file_exists($attachment['tmp_name']))
962
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
963
+											if (file_exists($attachment['tmp_name']))
925 964
 							unlink($attachment['tmp_name']);
965
+					}
926 966
 				}
927 967
 				$post_errors[] = 'temp_attachments_gone';
928 968
 				$_SESSION['temp_attachments'] = array();
@@ -936,8 +976,9 @@  discard block
 block discarded – undo
936 976
 					// See if any files still exist before showing the warning message and the files attached.
937 977
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
938 978
 					{
939
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
940
-							continue;
979
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
980
+													continue;
981
+						}
941 982
 
942 983
 						if (file_exists($attachment['tmp_name']))
943 984
 						{
@@ -947,20 +988,21 @@  discard block
 block discarded – undo
947 988
 							break;
948 989
 						}
949 990
 					}
950
-				}
951
-				else
991
+				} else
952 992
 				{
953 993
 					// Since, they don't belong here. Let's inform the user that they exist..
954
-					if (!empty($topic))
955
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
956
-					else
957
-						$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
994
+					if (!empty($topic)) {
995
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
996
+					} else {
997
+											$delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp';
998
+					}
958 999
 
959 1000
 					// Compile a list of the files to show the user.
960 1001
 					$file_list = array();
961
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
962
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1002
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1003
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
963 1004
 							$file_list[] = $attachment['name'];
1005
+					}
964 1006
 
965 1007
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
966 1008
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -972,8 +1014,7 @@  discard block
 block discarded – undo
972 1014
 
973 1015
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
974 1016
 						$context['ignore_temp_attachments'] = true;
975
-					}
976
-					else
1017
+					} else
977 1018
 					{
978 1019
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
979 1020
 						$context['ignore_temp_attachments'] = true;
@@ -981,16 +1022,19 @@  discard block
 block discarded – undo
981 1022
 				}
982 1023
 			}
983 1024
 
984
-			if (!empty($context['we_are_history']))
985
-				$post_errors[] = $context['we_are_history'];
1025
+			if (!empty($context['we_are_history'])) {
1026
+							$post_errors[] = $context['we_are_history'];
1027
+			}
986 1028
 
987 1029
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
988 1030
 			{
989
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
990
-					break;
1031
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1032
+									break;
1033
+				}
991 1034
 
992
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
993
-					continue;
1035
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1036
+									continue;
1037
+				}
994 1038
 
995 1039
 				if ($attachID == 'initial_error')
996 1040
 				{
@@ -1005,15 +1049,17 @@  discard block
 block discarded – undo
1005 1049
 				{
1006 1050
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1007 1051
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1008
-					foreach ($attachment['errors'] as $error)
1009
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1052
+					foreach ($attachment['errors'] as $error) {
1053
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1054
+					}
1010 1055
 					$txt['error_attach_errors'] .= '</div>';
1011 1056
 					$post_errors[] = 'attach_errors';
1012 1057
 
1013 1058
 					// Take out the trash.
1014 1059
 					unset($_SESSION['temp_attachments'][$attachID]);
1015
-					if (file_exists($attachment['tmp_name']))
1016
-						unlink($attachment['tmp_name']);
1060
+					if (file_exists($attachment['tmp_name'])) {
1061
+											unlink($attachment['tmp_name']);
1062
+					}
1017 1063
 					continue;
1018 1064
 				}
1019 1065
 
@@ -1026,8 +1072,9 @@  discard block
 block discarded – undo
1026 1072
 
1027 1073
 				$context['attachments']['quantity']++;
1028 1074
 				$context['attachments']['total_size'] += $attachment['size'];
1029
-				if (!isset($context['files_in_session_warning']))
1030
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1075
+				if (!isset($context['files_in_session_warning'])) {
1076
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1077
+				}
1031 1078
 
1032 1079
 				$context['current_attachments'][$attachID] = array(
1033 1080
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1055,8 +1102,9 @@  discard block
 block discarded – undo
1055 1102
 	}
1056 1103
 
1057 1104
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1058
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1059
-		$post_errors[] = 'need_qr_verification';
1105
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1106
+			$post_errors[] = 'need_qr_verification';
1107
+	}
1060 1108
 
1061 1109
 	/*
1062 1110
 	 * There are two error types: serious and minor. Serious errors
@@ -1073,52 +1121,56 @@  discard block
 block discarded – undo
1073 1121
 	{
1074 1122
 		loadLanguage('Errors');
1075 1123
 		$context['error_type'] = 'minor';
1076
-		foreach ($post_errors as $post_error)
1077
-			if (is_array($post_error))
1124
+		foreach ($post_errors as $post_error) {
1125
+					if (is_array($post_error))
1078 1126
 			{
1079 1127
 				$post_error_id = $post_error[0];
1128
+		}
1080 1129
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1081 1130
 
1082 1131
 				// If it's not a minor error flag it as such.
1083
-				if (!in_array($post_error_id, $minor_errors))
1084
-					$context['error_type'] = 'serious';
1085
-			}
1086
-			else
1132
+				if (!in_array($post_error_id, $minor_errors)) {
1133
+									$context['error_type'] = 'serious';
1134
+				}
1135
+			} else
1087 1136
 			{
1088 1137
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1089 1138
 
1090 1139
 				// If it's not a minor error flag it as such.
1091
-				if (!in_array($post_error, $minor_errors))
1092
-					$context['error_type'] = 'serious';
1140
+				if (!in_array($post_error, $minor_errors)) {
1141
+									$context['error_type'] = 'serious';
1142
+				}
1093 1143
 			}
1094 1144
 	}
1095 1145
 
1096 1146
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1097
-	if (isset($_REQUEST['poll']))
1098
-		$context['page_title'] = $txt['new_poll'];
1099
-	elseif ($context['make_event'])
1100
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1101
-	elseif (isset($_REQUEST['msg']))
1102
-		$context['page_title'] = $txt['modify_msg'];
1103
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1104
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1105
-	elseif (empty($topic))
1106
-		$context['page_title'] = $txt['start_new_topic'];
1107
-	else
1108
-		$context['page_title'] = $txt['post_reply'];
1147
+	if (isset($_REQUEST['poll'])) {
1148
+			$context['page_title'] = $txt['new_poll'];
1149
+	} elseif ($context['make_event']) {
1150
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1151
+	} elseif (isset($_REQUEST['msg'])) {
1152
+			$context['page_title'] = $txt['modify_msg'];
1153
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1154
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1155
+	} elseif (empty($topic)) {
1156
+			$context['page_title'] = $txt['start_new_topic'];
1157
+	} else {
1158
+			$context['page_title'] = $txt['post_reply'];
1159
+	}
1109 1160
 
1110 1161
 	// Build the link tree.
1111
-	if (empty($topic))
1112
-		$context['linktree'][] = array(
1162
+	if (empty($topic)) {
1163
+			$context['linktree'][] = array(
1113 1164
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1114 1165
 		);
1115
-	else
1116
-		$context['linktree'][] = array(
1166
+	} else {
1167
+			$context['linktree'][] = array(
1117 1168
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1118 1169
 			'name' => $form_subject,
1119 1170
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1120 1171
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1121 1172
 		);
1173
+	}
1122 1174
 
1123 1175
 	$context['subject'] = addcslashes($form_subject, '"');
1124 1176
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1162,8 +1214,9 @@  discard block
 block discarded – undo
1162 1214
 	// Message icons - customized icons are off?
1163 1215
 	$context['icons'] = getMessageIcons($board);
1164 1216
 
1165
-	if (!empty($context['icons']))
1166
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1217
+	if (!empty($context['icons'])) {
1218
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1219
+	}
1167 1220
 
1168 1221
 	// Are we starting a poll? if set the poll icon as selected if its available
1169 1222
 	if (isset($_REQUEST['poll']))
@@ -1183,8 +1236,9 @@  discard block
 block discarded – undo
1183 1236
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1184 1237
 	{
1185 1238
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1186
-		if ($context['icons'][$i]['selected'])
1187
-			$context['icon_url'] = $context['icons'][$i]['url'];
1239
+		if ($context['icons'][$i]['selected']) {
1240
+					$context['icon_url'] = $context['icons'][$i]['url'];
1241
+		}
1188 1242
 	}
1189 1243
 	if (empty($context['icon_url']))
1190 1244
 	{
@@ -1198,8 +1252,9 @@  discard block
 block discarded – undo
1198 1252
 		));
1199 1253
 	}
1200 1254
 
1201
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1202
-		getTopic();
1255
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1256
+			getTopic();
1257
+	}
1203 1258
 
1204 1259
 	// If the user can post attachments prepare the warning labels.
1205 1260
 	if ($context['can_post_attachment'])
@@ -1210,15 +1265,17 @@  discard block
 block discarded – undo
1210 1265
 		$context['attachment_restrictions'] = array();
1211 1266
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1212 1267
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1213
-		foreach ($attachmentRestrictionTypes as $type)
1214
-			if (!empty($modSettings[$type]))
1268
+		foreach ($attachmentRestrictionTypes as $type) {
1269
+					if (!empty($modSettings[$type]))
1215 1270
 			{
1216 1271
 				$context['attachment_restrictions'][] = sprintf($txt['attach_restrict_' . $type . ($modSettings[$type] >= 1024 ? '_MB' : '')], comma_format($modSettings[$type], 0));
1272
+		}
1217 1273
 				// Show some numbers. If they exist.
1218
-				if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0)
1219
-					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1220
-				elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0)
1221
-					$context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0));
1274
+				if ($type == 'attachmentNumPerPostLimit' && $context['attachments']['quantity'] > 0) {
1275
+									$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1276
+				} elseif ($type == 'attachmentPostLimit' && $context['attachments']['total_size'] > 0) {
1277
+									$context['attachment_restrictions'][] = sprintf($txt['attach_available'], comma_format(round(max($modSettings['attachmentPostLimit'] - ($context['attachments']['total_size'] / 1024), 0)), 0));
1278
+				}
1222 1279
 			}
1223 1280
 	}
1224 1281
 
@@ -1252,8 +1309,8 @@  discard block
 block discarded – undo
1252 1309
 
1253 1310
 	if (!empty($context['current_attachments']))
1254 1311
 	{
1255
-		foreach ($context['current_attachments'] as $key => $mock)
1256
-			addInlineJavaScript('
1312
+		foreach ($context['current_attachments'] as $key => $mock) {
1313
+					addInlineJavaScript('
1257 1314
 	current_attachments.push({
1258 1315
 		name: '. JavaScriptEscape($mock['name']) . ',
1259 1316
 		size: '. $mock['size'] . ',
@@ -1262,6 +1319,7 @@  discard block
 block discarded – undo
1262 1319
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1263 1320
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1264 1321
 	});', true);
1322
+		}
1265 1323
 	}
1266 1324
 
1267 1325
 	// File Upload.
@@ -1306,8 +1364,9 @@  discard block
 block discarded – undo
1306 1364
 	var current_board = '. (empty($context['current_board']) ? 'null' : $context['current_board']) . ';', false);
1307 1365
 
1308 1366
 	// Finally, load the template.
1309
-	if (!isset($_REQUEST['xml']))
1310
-		loadTemplate('Post');
1367
+	if (!isset($_REQUEST['xml'])) {
1368
+			loadTemplate('Post');
1369
+	}
1311 1370
 
1312 1371
 	call_integration_hook('integrate_post_end');
1313 1372
 }
@@ -1328,13 +1387,14 @@  discard block
 block discarded – undo
1328 1387
 	// Sneaking off, are we?
1329 1388
 	if (empty($_POST) && empty($topic))
1330 1389
 	{
1331
-		if (empty($_SERVER['CONTENT_LENGTH']))
1332
-			redirectexit('action=post;board=' . $board . '.0');
1333
-		else
1334
-			fatal_lang_error('post_upload_error', false);
1390
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1391
+					redirectexit('action=post;board=' . $board . '.0');
1392
+		} else {
1393
+					fatal_lang_error('post_upload_error', false);
1394
+		}
1395
+	} elseif (empty($_POST) && !empty($topic)) {
1396
+			redirectexit('action=post;topic=' . $topic . '.0');
1335 1397
 	}
1336
-	elseif (empty($_POST) && !empty($topic))
1337
-		redirectexit('action=post;topic=' . $topic . '.0');
1338 1398
 
1339 1399
 	// No need!
1340 1400
 	$context['robot_no_index'] = true;
@@ -1346,8 +1406,9 @@  discard block
 block discarded – undo
1346 1406
 	$post_errors = array();
1347 1407
 
1348 1408
 	// If the session has timed out, let the user re-submit their form.
1349
-	if (checkSession('post', '', false) != '')
1350
-		$post_errors[] = 'session_timeout';
1409
+	if (checkSession('post', '', false) != '') {
1410
+			$post_errors[] = 'session_timeout';
1411
+	}
1351 1412
 
1352 1413
 	// Wrong verification code?
1353 1414
 	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)))
@@ -1357,33 +1418,38 @@  discard block
 block discarded – undo
1357 1418
 			'id' => 'post',
1358 1419
 		);
1359 1420
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1360
-		if (is_array($context['require_verification']))
1361
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1421
+		if (is_array($context['require_verification'])) {
1422
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1423
+		}
1362 1424
 	}
1363 1425
 
1364 1426
 	require_once($sourcedir . '/Subs-Post.php');
1365 1427
 	loadLanguage('Post');
1366 1428
 
1367 1429
 	// Drafts enabled and needed?
1368
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1369
-		require_once($sourcedir . '/Drafts.php');
1430
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1431
+			require_once($sourcedir . '/Drafts.php');
1432
+	}
1370 1433
 
1371 1434
 	// First check to see if they are trying to delete any current attachments.
1372 1435
 	if (isset($_POST['attach_del']))
1373 1436
 	{
1374 1437
 		$keep_temp = array();
1375 1438
 		$keep_ids = array();
1376
-		foreach ($_POST['attach_del'] as $dummy)
1377
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1439
+		foreach ($_POST['attach_del'] as $dummy) {
1440
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1378 1441
 				$keep_temp[] = $dummy;
1379
-			else
1380
-				$keep_ids[] = (int) $dummy;
1442
+		}
1443
+			else {
1444
+							$keep_ids[] = (int) $dummy;
1445
+			}
1381 1446
 
1382
-		if (isset($_SESSION['temp_attachments']))
1383
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1447
+		if (isset($_SESSION['temp_attachments'])) {
1448
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1384 1449
 			{
1385 1450
 				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)
1386 1451
 					continue;
1452
+		}
1387 1453
 
1388 1454
 				unset($_SESSION['temp_attachments'][$attachID]);
1389 1455
 				unlink($attachment['tmp_name']);
@@ -1425,24 +1491,28 @@  discard block
 block discarded – undo
1425 1491
 		$smcFunc['db_free_result']($request);
1426 1492
 
1427 1493
 		// Though the topic should be there, it might have vanished.
1428
-		if (!is_array($topic_info))
1429
-			fatal_lang_error('topic_doesnt_exist', 404);
1494
+		if (!is_array($topic_info)) {
1495
+					fatal_lang_error('topic_doesnt_exist', 404);
1496
+		}
1430 1497
 
1431 1498
 		// Did this topic suddenly move? Just checking...
1432
-		if ($topic_info['id_board'] != $board)
1433
-			fatal_lang_error('not_a_topic');
1499
+		if ($topic_info['id_board'] != $board) {
1500
+					fatal_lang_error('not_a_topic');
1501
+		}
1434 1502
 	}
1435 1503
 
1436 1504
 	// Replying to a topic?
1437 1505
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1438 1506
 	{
1439 1507
 		// Don't allow a post if it's locked.
1440
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1441
-			fatal_lang_error('topic_locked', false);
1508
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1509
+					fatal_lang_error('topic_locked', false);
1510
+		}
1442 1511
 
1443 1512
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1444
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1445
-			unset($_REQUEST['poll']);
1513
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1514
+					unset($_REQUEST['poll']);
1515
+		}
1446 1516
 
1447 1517
 		// Do the permissions and approval stuff...
1448 1518
 		$becomesApproved = true;
@@ -1458,44 +1528,43 @@  discard block
 block discarded – undo
1458 1528
 
1459 1529
 			// Set a nice session var...
1460 1530
 			$_SESSION['becomesUnapproved'] = true;
1461
-		}
1462
-
1463
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1531
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1464 1532
 		{
1465
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1466
-				$becomesApproved = false;
1467
-
1468
-			else
1469
-				isAllowedTo('post_reply_any');
1470
-		}
1471
-		elseif (!allowedTo('post_reply_any'))
1533
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1534
+							$becomesApproved = false;
1535
+			} else {
1536
+							isAllowedTo('post_reply_any');
1537
+			}
1538
+		} elseif (!allowedTo('post_reply_any'))
1472 1539
 		{
1473
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1474
-				$becomesApproved = false;
1475
-
1476
-			else
1477
-				isAllowedTo('post_reply_own');
1540
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1541
+							$becomesApproved = false;
1542
+			} else {
1543
+							isAllowedTo('post_reply_own');
1544
+			}
1478 1545
 		}
1479 1546
 
1480 1547
 		if (isset($_POST['lock']))
1481 1548
 		{
1482 1549
 			// Nothing is changed to the lock.
1483
-			if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1484
-				unset($_POST['lock']);
1550
+			if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1551
+							unset($_POST['lock']);
1552
+			}
1485 1553
 
1486 1554
 			// You're have no permission to lock this topic.
1487
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1488
-				unset($_POST['lock']);
1555
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1556
+							unset($_POST['lock']);
1557
+			}
1489 1558
 
1490 1559
 			// You are allowed to (un)lock your own topic only.
1491 1560
 			elseif (!allowedTo('lock_any'))
1492 1561
 			{
1493 1562
 				// You cannot override a moderator lock.
1494
-				if ($topic_info['locked'] == 1)
1495
-					unset($_POST['lock']);
1496
-
1497
-				else
1498
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1563
+				if ($topic_info['locked'] == 1) {
1564
+									unset($_POST['lock']);
1565
+				} else {
1566
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1567
+				}
1499 1568
 			}
1500 1569
 			// Hail mighty moderator, (un)lock this topic immediately.
1501 1570
 			else
@@ -1503,19 +1572,21 @@  discard block
 block discarded – undo
1503 1572
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1504 1573
 
1505 1574
 				// Did someone (un)lock this while you were posting?
1506
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1507
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1575
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1576
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1577
+				}
1508 1578
 			}
1509 1579
 		}
1510 1580
 
1511 1581
 		// So you wanna (un)sticky this...let's see.
1512
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1513
-			unset($_POST['sticky']);
1514
-		elseif (isset($_POST['sticky']))
1582
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1583
+					unset($_POST['sticky']);
1584
+		} elseif (isset($_POST['sticky']))
1515 1585
 		{
1516 1586
 			// Did someone (un)sticky this while you were posting?
1517
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1518
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1587
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1588
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1589
+			}
1519 1590
 		}
1520 1591
 
1521 1592
 		// If drafts are enabled, then pass this off
@@ -1542,26 +1613,31 @@  discard block
 block discarded – undo
1542 1613
 
1543 1614
 		// Do like, the permissions, for safety and stuff...
1544 1615
 		$becomesApproved = true;
1545
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1546
-			$becomesApproved = false;
1547
-		else
1548
-			isAllowedTo('post_new');
1616
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1617
+					$becomesApproved = false;
1618
+		} else {
1619
+					isAllowedTo('post_new');
1620
+		}
1549 1621
 
1550 1622
 		if (isset($_POST['lock']))
1551 1623
 		{
1552 1624
 			// New topics are by default not locked.
1553
-			if (empty($_POST['lock']))
1554
-				unset($_POST['lock']);
1625
+			if (empty($_POST['lock'])) {
1626
+							unset($_POST['lock']);
1627
+			}
1555 1628
 			// Besides, you need permission.
1556
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1557
-				unset($_POST['lock']);
1629
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1630
+							unset($_POST['lock']);
1631
+			}
1558 1632
 			// A moderator-lock (1) can override a user-lock (2).
1559
-			else
1560
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1633
+			else {
1634
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1635
+			}
1561 1636
 		}
1562 1637
 
1563
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1564
-			unset($_POST['sticky']);
1638
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1639
+					unset($_POST['sticky']);
1640
+		}
1565 1641
 
1566 1642
 		// Saving your new topic as a draft first?
1567 1643
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1586,31 +1662,37 @@  discard block
 block discarded – undo
1586 1662
 				'id_msg' => $_REQUEST['msg'],
1587 1663
 			)
1588 1664
 		);
1589
-		if ($smcFunc['db_num_rows']($request) == 0)
1590
-			fatal_lang_error('cant_find_messages', false);
1665
+		if ($smcFunc['db_num_rows']($request) == 0) {
1666
+					fatal_lang_error('cant_find_messages', false);
1667
+		}
1591 1668
 		$row = $smcFunc['db_fetch_assoc']($request);
1592 1669
 		$smcFunc['db_free_result']($request);
1593 1670
 
1594
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1595
-			fatal_lang_error('topic_locked', false);
1671
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1672
+					fatal_lang_error('topic_locked', false);
1673
+		}
1596 1674
 
1597 1675
 		if (isset($_POST['lock']))
1598 1676
 		{
1599 1677
 			// Nothing changes to the lock status.
1600
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1601
-				unset($_POST['lock']);
1678
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1679
+							unset($_POST['lock']);
1680
+			}
1602 1681
 			// You're simply not allowed to (un)lock this.
1603
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1604
-				unset($_POST['lock']);
1682
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1683
+							unset($_POST['lock']);
1684
+			}
1605 1685
 			// You're only allowed to lock your own topics.
1606 1686
 			elseif (!allowedTo('lock_any'))
1607 1687
 			{
1608 1688
 				// You're not allowed to break a moderator's lock.
1609
-				if ($topic_info['locked'] == 1)
1610
-					unset($_POST['lock']);
1689
+				if ($topic_info['locked'] == 1) {
1690
+									unset($_POST['lock']);
1691
+				}
1611 1692
 				// Lock it with a soft lock or unlock it.
1612
-				else
1613
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1693
+				else {
1694
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1695
+				}
1614 1696
 			}
1615 1697
 			// You must be the moderator.
1616 1698
 			else
@@ -1618,44 +1700,46 @@  discard block
 block discarded – undo
1618 1700
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1619 1701
 
1620 1702
 				// Did someone (un)lock this while you were posting?
1621
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1622
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1703
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1704
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1705
+				}
1623 1706
 			}
1624 1707
 		}
1625 1708
 
1626 1709
 		// Change the sticky status of this topic?
1627
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1628
-			unset($_POST['sticky']);
1629
-		elseif (isset($_POST['sticky']))
1710
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1711
+					unset($_POST['sticky']);
1712
+		} elseif (isset($_POST['sticky']))
1630 1713
 		{
1631 1714
 			// Did someone (un)sticky this while you were posting?
1632
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1633
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1715
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1716
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1717
+			}
1634 1718
 		}
1635 1719
 
1636 1720
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1637 1721
 		{
1638
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1639
-				fatal_lang_error('modify_post_time_passed', false);
1640
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1641
-				isAllowedTo('modify_replies');
1642
-			else
1643
-				isAllowedTo('modify_own');
1644
-		}
1645
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1722
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1723
+							fatal_lang_error('modify_post_time_passed', false);
1724
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1725
+							isAllowedTo('modify_replies');
1726
+			} else {
1727
+							isAllowedTo('modify_own');
1728
+			}
1729
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1646 1730
 		{
1647 1731
 			isAllowedTo('modify_replies');
1648 1732
 
1649 1733
 			// If you're modifying a reply, I say it better be logged...
1650 1734
 			$moderationAction = true;
1651
-		}
1652
-		else
1735
+		} else
1653 1736
 		{
1654 1737
 			isAllowedTo('modify_any');
1655 1738
 
1656 1739
 			// Log it, assuming you're not modifying your own post.
1657
-			if ($row['id_member'] != $user_info['id'])
1658
-				$moderationAction = true;
1740
+			if ($row['id_member'] != $user_info['id']) {
1741
+							$moderationAction = true;
1742
+			}
1659 1743
 		}
1660 1744
 
1661 1745
 		// If drafts are enabled, then lets send this off to save
@@ -1692,20 +1776,24 @@  discard block
 block discarded – undo
1692 1776
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1693 1777
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1694 1778
 
1695
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1696
-			$post_errors[] = 'no_name';
1697
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1698
-			$post_errors[] = 'long_name';
1779
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1780
+					$post_errors[] = 'no_name';
1781
+		}
1782
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1783
+					$post_errors[] = 'long_name';
1784
+		}
1699 1785
 
1700 1786
 		if (empty($modSettings['guest_post_no_email']))
1701 1787
 		{
1702 1788
 			// Only check if they changed it!
1703 1789
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1704 1790
 			{
1705
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1706
-					$post_errors[] = 'no_email';
1707
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1708
-					$post_errors[] = 'bad_email';
1791
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1792
+									$post_errors[] = 'no_email';
1793
+				}
1794
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1795
+									$post_errors[] = 'bad_email';
1796
+				}
1709 1797
 			}
1710 1798
 
1711 1799
 			// Now make sure this email address is not banned from posting.
@@ -1721,75 +1809,89 @@  discard block
 block discarded – undo
1721 1809
 	}
1722 1810
 
1723 1811
 	// Coming from the quickReply?
1724
-	if (isset($_POST['quickReply']))
1725
-		$_POST['message'] = $_POST['quickReply'];
1812
+	if (isset($_POST['quickReply'])) {
1813
+			$_POST['message'] = $_POST['quickReply'];
1814
+	}
1726 1815
 
1727 1816
 	// Check the subject and message.
1728
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1729
-		$post_errors[] = 'no_subject';
1730
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1731
-		$post_errors[] = 'no_message';
1732
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1733
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1734
-	else
1817
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1818
+			$post_errors[] = 'no_subject';
1819
+	}
1820
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1821
+			$post_errors[] = 'no_message';
1822
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1823
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1824
+	} else
1735 1825
 	{
1736 1826
 		// Prepare the message a bit for some additional testing.
1737 1827
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1738 1828
 
1739 1829
 		// Preparse code. (Zef)
1740
-		if ($user_info['is_guest'])
1741
-			$user_info['name'] = $_POST['guestname'];
1830
+		if ($user_info['is_guest']) {
1831
+					$user_info['name'] = $_POST['guestname'];
1832
+		}
1742 1833
 		preparsecode($_POST['message']);
1743 1834
 
1744 1835
 		// Let's see if there's still some content left without the tags.
1745
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1746
-			$post_errors[] = 'no_message';
1836
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1837
+					$post_errors[] = 'no_message';
1838
+		}
1839
+	}
1840
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1841
+			$post_errors[] = 'no_event';
1747 1842
 	}
1748
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1749
-		$post_errors[] = 'no_event';
1750 1843
 	// You are not!
1751
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1752
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1844
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1845
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1846
+	}
1753 1847
 
1754 1848
 	// Validate the poll...
1755 1849
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1756 1850
 	{
1757
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1758
-			fatal_lang_error('no_access', false);
1851
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1852
+					fatal_lang_error('no_access', false);
1853
+		}
1759 1854
 
1760 1855
 		// This is a new topic... so it's a new poll.
1761
-		if (empty($topic))
1762
-			isAllowedTo('poll_post');
1856
+		if (empty($topic)) {
1857
+					isAllowedTo('poll_post');
1858
+		}
1763 1859
 		// Can you add to your own topics?
1764
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1765
-			isAllowedTo('poll_add_own');
1860
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1861
+					isAllowedTo('poll_add_own');
1862
+		}
1766 1863
 		// Can you add polls to any topic, then?
1767
-		else
1768
-			isAllowedTo('poll_add_any');
1864
+		else {
1865
+					isAllowedTo('poll_add_any');
1866
+		}
1769 1867
 
1770
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1771
-			$post_errors[] = 'no_question';
1868
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1869
+					$post_errors[] = 'no_question';
1870
+		}
1772 1871
 
1773 1872
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1774 1873
 
1775 1874
 		// Get rid of empty ones.
1776
-		foreach ($_POST['options'] as $k => $option)
1777
-			if ($option == '')
1875
+		foreach ($_POST['options'] as $k => $option) {
1876
+					if ($option == '')
1778 1877
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1878
+		}
1779 1879
 
1780 1880
 		// What are you going to vote between with one choice?!?
1781
-		if (count($_POST['options']) < 2)
1782
-			$post_errors[] = 'poll_few';
1783
-		elseif (count($_POST['options']) > 256)
1784
-			$post_errors[] = 'poll_many';
1881
+		if (count($_POST['options']) < 2) {
1882
+					$post_errors[] = 'poll_few';
1883
+		} elseif (count($_POST['options']) > 256) {
1884
+					$post_errors[] = 'poll_many';
1885
+		}
1785 1886
 	}
1786 1887
 
1787 1888
 	if ($posterIsGuest)
1788 1889
 	{
1789 1890
 		// If user is a guest, make sure the chosen name isn't taken.
1790 1891
 		require_once($sourcedir . '/Subs-Members.php');
1791
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1792
-			$post_errors[] = 'bad_name';
1892
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
1893
+					$post_errors[] = 'bad_name';
1894
+		}
1793 1895
 	}
1794 1896
 	// If the user isn't a guest, get his or her name and email.
1795 1897
 	elseif (!isset($_REQUEST['msg']))
@@ -1820,8 +1922,9 @@  discard block
 block discarded – undo
1820 1922
 	}
1821 1923
 
1822 1924
 	// Make sure the user isn't spamming the board.
1823
-	if (!isset($_REQUEST['msg']))
1824
-		spamProtection('post');
1925
+	if (!isset($_REQUEST['msg'])) {
1926
+			spamProtection('post');
1927
+	}
1825 1928
 
1826 1929
 	// At about this point, we're posting and that's that.
1827 1930
 	ignore_user_abort(true);
@@ -1834,32 +1937,36 @@  discard block
 block discarded – undo
1834 1937
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1835 1938
 
1836 1939
 	// At this point, we want to make sure the subject isn't too long.
1837
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1838
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
1940
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
1941
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
1942
+	}
1839 1943
 
1840 1944
 	// Same with the "why did you edit this" text.
1841
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1842
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
1945
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
1946
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
1947
+	}
1843 1948
 
1844 1949
 	// Make the poll...
1845 1950
 	if (isset($_REQUEST['poll']))
1846 1951
 	{
1847 1952
 		// Make sure that the user has not entered a ridiculous number of options..
1848
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1849
-			$_POST['poll_max_votes'] = 1;
1850
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1851
-			$_POST['poll_max_votes'] = count($_POST['options']);
1852
-		else
1853
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
1953
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
1954
+					$_POST['poll_max_votes'] = 1;
1955
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
1956
+					$_POST['poll_max_votes'] = count($_POST['options']);
1957
+		} else {
1958
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
1959
+		}
1854 1960
 
1855 1961
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1856 1962
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1857 1963
 
1858 1964
 		// Just set it to zero if it's not there..
1859
-		if (!isset($_POST['poll_hide']))
1860
-			$_POST['poll_hide'] = 0;
1861
-		else
1862
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
1965
+		if (!isset($_POST['poll_hide'])) {
1966
+					$_POST['poll_hide'] = 0;
1967
+		} else {
1968
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
1969
+		}
1863 1970
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1864 1971
 
1865 1972
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1868,16 +1975,19 @@  discard block
 block discarded – undo
1868 1975
 		{
1869 1976
 			require_once($sourcedir . '/Subs-Members.php');
1870 1977
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1871
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1872
-				$_POST['poll_guest_vote'] = 0;
1978
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
1979
+							$_POST['poll_guest_vote'] = 0;
1980
+			}
1873 1981
 		}
1874 1982
 
1875 1983
 		// If the user tries to set the poll too far in advance, don't let them.
1876
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1877
-			fatal_lang_error('poll_range_error', false);
1984
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
1985
+					fatal_lang_error('poll_range_error', false);
1986
+		}
1878 1987
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1879
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1880
-			$_POST['poll_hide'] = 1;
1988
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
1989
+					$_POST['poll_hide'] = 1;
1990
+		}
1881 1991
 
1882 1992
 		// Clean up the question and answers.
1883 1993
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1891,13 +2001,15 @@  discard block
 block discarded – undo
1891 2001
 	{
1892 2002
 		$attachIDs = array();
1893 2003
 		$attach_errors = array();
1894
-		if (!empty($context['we_are_history']))
1895
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2004
+		if (!empty($context['we_are_history'])) {
2005
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2006
+		}
1896 2007
 
1897 2008
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
1898 2009
 		{
1899
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1900
-				continue;
2010
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2011
+							continue;
2012
+			}
1901 2013
 
1902 2014
 			// If there was an initial error just show that message.
1903 2015
 			if ($attachID == 'initial_error')
@@ -1926,12 +2038,13 @@  discard block
 block discarded – undo
1926 2038
 				if (createAttachment($attachmentOptions))
1927 2039
 				{
1928 2040
 					$attachIDs[] = $attachmentOptions['id'];
1929
-					if (!empty($attachmentOptions['thumb']))
1930
-						$attachIDs[] = $attachmentOptions['thumb'];
2041
+					if (!empty($attachmentOptions['thumb'])) {
2042
+											$attachIDs[] = $attachmentOptions['thumb'];
2043
+					}
1931 2044
 				}
2045
+			} else {
2046
+							$attach_errors[] = '<dt>&nbsp;</dt>';
1932 2047
 			}
1933
-			else
1934
-				$attach_errors[] = '<dt>&nbsp;</dt>';
1935 2048
 
1936 2049
 			if (!empty($attachmentOptions['errors']))
1937 2050
 			{
@@ -1943,14 +2056,16 @@  discard block
 block discarded – undo
1943 2056
 					if (!is_array($error))
1944 2057
 					{
1945 2058
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
1946
-						if (in_array($error, $log_these))
1947
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2059
+						if (in_array($error, $log_these)) {
2060
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2061
+						}
2062
+					} else {
2063
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
1948 2064
 					}
1949
-					else
1950
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
1951 2065
 				}
1952
-				if (file_exists($attachment['tmp_name']))
1953
-					unlink($attachment['tmp_name']);
2066
+				if (file_exists($attachment['tmp_name'])) {
2067
+									unlink($attachment['tmp_name']);
2068
+				}
1954 2069
 			}
1955 2070
 		}
1956 2071
 		unset($_SESSION['temp_attachments']);
@@ -1991,24 +2106,24 @@  discard block
 block discarded – undo
1991 2106
 		);
1992 2107
 
1993 2108
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2109
+	} else {
2110
+			$id_poll = 0;
1994 2111
 	}
1995
-	else
1996
-		$id_poll = 0;
1997 2112
 
1998 2113
 	// Creating a new topic?
1999 2114
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2000 2115
 
2001 2116
 	// Check the icon.
2002
-	if (!isset($_POST['icon']))
2003
-		$_POST['icon'] = 'xx';
2004
-
2005
-	else
2117
+	if (!isset($_POST['icon'])) {
2118
+			$_POST['icon'] = 'xx';
2119
+	} else
2006 2120
 	{
2007 2121
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2008 2122
 
2009 2123
 		// Need to figure it out if this is a valid icon name.
2010
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2011
-			$_POST['icon'] = 'xx';
2124
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2125
+					$_POST['icon'] = 'xx';
2126
+		}
2012 2127
 	}
2013 2128
 
2014 2129
 	// Collect all parameters for the creation or modification of a post.
@@ -2049,8 +2164,9 @@  discard block
 block discarded – undo
2049 2164
 		}
2050 2165
 
2051 2166
 		// This will save some time...
2052
-		if (empty($approve_has_changed))
2053
-			unset($msgOptions['approved']);
2167
+		if (empty($approve_has_changed)) {
2168
+					unset($msgOptions['approved']);
2169
+		}
2054 2170
 
2055 2171
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2056 2172
 	}
@@ -2059,8 +2175,9 @@  discard block
 block discarded – undo
2059 2175
 	{
2060 2176
 		createPost($msgOptions, $topicOptions, $posterOptions);
2061 2177
 
2062
-		if (isset($topicOptions['id']))
2063
-			$topic = $topicOptions['id'];
2178
+		if (isset($topicOptions['id'])) {
2179
+					$topic = $topicOptions['id'];
2180
+		}
2064 2181
 	}
2065 2182
 
2066 2183
 	// Assign the previously uploaded attachments to the brand new message.
@@ -2072,8 +2189,9 @@  discard block
 block discarded – undo
2072 2189
 	}
2073 2190
 
2074 2191
 	// If we had a draft for this, its time to remove it since it was just posted
2075
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2076
-		DeleteDraft($_POST['id_draft']);
2192
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2193
+			DeleteDraft($_POST['id_draft']);
2194
+	}
2077 2195
 
2078 2196
 	// Editing or posting an event?
2079 2197
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2092,8 +2210,7 @@  discard block
 block discarded – undo
2092 2210
 			'member' => $user_info['id'],
2093 2211
 		);
2094 2212
 		insertEvent($eventOptions);
2095
-	}
2096
-	elseif (isset($_POST['calendar']))
2213
+	} elseif (isset($_POST['calendar']))
2097 2214
 	{
2098 2215
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2099 2216
 
@@ -2121,14 +2238,15 @@  discard block
 block discarded – undo
2121 2238
 		}
2122 2239
 
2123 2240
 		// Delete it?
2124
-		if (isset($_REQUEST['deleteevent']))
2125
-			$smcFunc['db_query']('', '
2241
+		if (isset($_REQUEST['deleteevent'])) {
2242
+					$smcFunc['db_query']('', '
2126 2243
 				DELETE FROM {db_prefix}calendar
2127 2244
 				WHERE id_event = {int:id_event}',
2128 2245
 				array(
2129 2246
 					'id_event' => $_REQUEST['eventid'],
2130 2247
 				)
2131 2248
 			);
2249
+		}
2132 2250
 		// ... or just update it?
2133 2251
 		else
2134 2252
 		{
@@ -2170,9 +2288,8 @@  discard block
 block discarded – undo
2170 2288
 			array($user_info['id'], $topic, 0),
2171 2289
 			array('id_member', 'id_topic', 'id_board')
2172 2290
 		);
2173
-	}
2174
-	elseif (!$newTopic)
2175
-		$smcFunc['db_query']('', '
2291
+	} elseif (!$newTopic) {
2292
+			$smcFunc['db_query']('', '
2176 2293
 			DELETE FROM {db_prefix}log_notify
2177 2294
 			WHERE id_member = {int:current_member}
2178 2295
 				AND id_topic = {int:current_topic}',
@@ -2181,16 +2298,20 @@  discard block
 block discarded – undo
2181 2298
 				'current_topic' => $topic,
2182 2299
 			)
2183 2300
 		);
2301
+	}
2184 2302
 
2185 2303
 	// Log an act of moderation - modifying.
2186
-	if (!empty($moderationAction))
2187
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2304
+	if (!empty($moderationAction)) {
2305
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2306
+	}
2188 2307
 
2189
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2190
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2308
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2309
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2310
+	}
2191 2311
 
2192
-	if (isset($_POST['sticky']))
2193
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2312
+	if (isset($_POST['sticky'])) {
2313
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2314
+	}
2194 2315
 
2195 2316
 	// Returning to the topic?
2196 2317
 	if (!empty($_REQUEST['goback']))
@@ -2209,26 +2330,31 @@  discard block
 block discarded – undo
2209 2330
 		);
2210 2331
 	}
2211 2332
 
2212
-	if ($board_info['num_topics'] == 0)
2213
-		cache_put_data('board-' . $board, null, 120);
2333
+	if ($board_info['num_topics'] == 0) {
2334
+			cache_put_data('board-' . $board, null, 120);
2335
+	}
2214 2336
 
2215 2337
 	call_integration_hook('integrate_post2_end');
2216 2338
 
2217
-	if (!empty($_POST['announce_topic']))
2218
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2339
+	if (!empty($_POST['announce_topic'])) {
2340
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2341
+	}
2219 2342
 
2220
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2221
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2343
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2344
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2345
+	}
2222 2346
 
2223 2347
 	// Return to post if the mod is on.
2224
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2225
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2226
-	elseif (!empty($_REQUEST['goback']))
2227
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2348
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2349
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2350
+	} elseif (!empty($_REQUEST['goback'])) {
2351
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2352
+	}
2228 2353
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2229
-	else
2230
-		redirectexit('board=' . $board . '.0');
2231
-}
2354
+	else {
2355
+			redirectexit('board=' . $board . '.0');
2356
+	}
2357
+	}
2232 2358
 
2233 2359
 /**
2234 2360
  * Handle the announce topic function (action=announce).
@@ -2246,8 +2372,9 @@  discard block
 block discarded – undo
2246 2372
 
2247 2373
 	validateSession();
2248 2374
 
2249
-	if (empty($topic))
2250
-		fatal_lang_error('topic_gone', false);
2375
+	if (empty($topic)) {
2376
+			fatal_lang_error('topic_gone', false);
2377
+	}
2251 2378
 
2252 2379
 	loadLanguage('Post');
2253 2380
 	loadTemplate('Post');
@@ -2274,8 +2401,9 @@  discard block
 block discarded – undo
2274 2401
 	global $txt, $context, $topic, $board, $board_info, $smcFunc;
2275 2402
 
2276 2403
 	$groups = array_merge($board_info['groups'], array(1));
2277
-	foreach ($groups as $id => $group)
2278
-		$groups[$id] = (int) $group;
2404
+	foreach ($groups as $id => $group) {
2405
+			$groups[$id] = (int) $group;
2406
+	}
2279 2407
 
2280 2408
 	$context['groups'] = array();
2281 2409
 	if (in_array(0, $groups))
@@ -2318,8 +2446,9 @@  discard block
 block discarded – undo
2318 2446
 			'group_list' => $groups,
2319 2447
 		)
2320 2448
 	);
2321
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2322
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2449
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2450
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2451
+	}
2323 2452
 	$smcFunc['db_free_result']($request);
2324 2453
 
2325 2454
 	// Get the subject of the topic we're about to announce.
@@ -2361,16 +2490,19 @@  discard block
 block discarded – undo
2361 2490
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2362 2491
 	$groups = array_merge($board_info['groups'], array(1));
2363 2492
 
2364
-	if (isset($_POST['membergroups']))
2365
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2493
+	if (isset($_POST['membergroups'])) {
2494
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2495
+	}
2366 2496
 
2367 2497
 	// Check whether at least one membergroup was selected.
2368
-	if (empty($_POST['who']))
2369
-		fatal_lang_error('no_membergroup_selected');
2498
+	if (empty($_POST['who'])) {
2499
+			fatal_lang_error('no_membergroup_selected');
2500
+	}
2370 2501
 
2371 2502
 	// Make sure all membergroups are integers and can access the board of the announcement.
2372
-	foreach ($_POST['who'] as $id => $mg)
2373
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2503
+	foreach ($_POST['who'] as $id => $mg) {
2504
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2505
+	}
2374 2506
 
2375 2507
 	// Get the topic subject and censor it.
2376 2508
 	$request = $smcFunc['db_query']('', '
@@ -2416,12 +2548,13 @@  discard block
 block discarded – undo
2416 2548
 	if ($smcFunc['db_num_rows']($request) == 0)
2417 2549
 	{
2418 2550
 		logAction('announce_topic', array('topic' => $topic), 'user');
2419
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2420
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2421
-		elseif (!empty($_REQUEST['goback']))
2422
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2423
-		else
2424
-			redirectexit('board=' . $board . '.0');
2551
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2552
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2553
+		} elseif (!empty($_REQUEST['goback'])) {
2554
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2555
+		} else {
2556
+					redirectexit('board=' . $board . '.0');
2557
+		}
2425 2558
 	}
2426 2559
 
2427 2560
 	$announcements = array();
@@ -2440,8 +2573,9 @@  discard block
 block discarded – undo
2440 2573
 	foreach ($rows as $row)
2441 2574
 	{
2442 2575
 		// Force them to have it?
2443
-		if (empty($prefs[$row['id_member']]['announcements']))
2444
-			continue;
2576
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2577
+					continue;
2578
+		}
2445 2579
 
2446 2580
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2447 2581
 
@@ -2469,8 +2603,9 @@  discard block
 block discarded – undo
2469 2603
 	}
2470 2604
 
2471 2605
 	// For each language send a different mail - low priority...
2472
-	foreach ($announcements as $lang => $mail)
2473
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2606
+	foreach ($announcements as $lang => $mail) {
2607
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2608
+	}
2474 2609
 
2475 2610
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2476 2611
 
@@ -2480,9 +2615,10 @@  discard block
 block discarded – undo
2480 2615
 	$context['sub_template'] = 'announcement_send';
2481 2616
 
2482 2617
 	// Go back to the correct language for the user ;).
2483
-	if (!empty($modSettings['userLanguage']))
2484
-		loadLanguage('Post');
2485
-}
2618
+	if (!empty($modSettings['userLanguage'])) {
2619
+			loadLanguage('Post');
2620
+	}
2621
+	}
2486 2622
 
2487 2623
 /**
2488 2624
  * Get the topic for display purposes.
@@ -2495,12 +2631,13 @@  discard block
 block discarded – undo
2495 2631
 {
2496 2632
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2497 2633
 
2498
-	if (isset($_REQUEST['xml']))
2499
-		$limit = '
2634
+	if (isset($_REQUEST['xml'])) {
2635
+			$limit = '
2500 2636
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2501
-	else
2502
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2637
+	} else {
2638
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2503 2639
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2640
+	}
2504 2641
 
2505 2642
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2506 2643
 	$request = $smcFunc['db_query']('', '
@@ -2538,8 +2675,9 @@  discard block
 block discarded – undo
2538 2675
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2539 2676
 		);
2540 2677
 
2541
-		if (!empty($context['new_replies']))
2542
-			$context['new_replies']--;
2678
+		if (!empty($context['new_replies'])) {
2679
+					$context['new_replies']--;
2680
+		}
2543 2681
 	}
2544 2682
 	$smcFunc['db_free_result']($request);
2545 2683
 }
@@ -2556,8 +2694,9 @@  discard block
 block discarded – undo
2556 2694
 	global $sourcedir, $smcFunc;
2557 2695
 
2558 2696
 	loadLanguage('Post');
2559
-	if (!isset($_REQUEST['xml']))
2560
-		loadTemplate('Post');
2697
+	if (!isset($_REQUEST['xml'])) {
2698
+			loadTemplate('Post');
2699
+	}
2561 2700
 
2562 2701
 	include_once($sourcedir . '/Subs-Post.php');
2563 2702
 
@@ -2588,8 +2727,9 @@  discard block
 block discarded – undo
2588 2727
 	$smcFunc['db_free_result']($request);
2589 2728
 
2590 2729
 	$context['sub_template'] = 'quotefast';
2591
-	if (!empty($row))
2592
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2730
+	if (!empty($row)) {
2731
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2732
+	}
2593 2733
 
2594 2734
 	if (!empty($can_view_post))
2595 2735
 	{
@@ -2622,8 +2762,9 @@  discard block
 block discarded – undo
2622 2762
 		}
2623 2763
 
2624 2764
 		// Remove any nested quotes.
2625
-		if (!empty($modSettings['removeNestedQuotes']))
2626
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2765
+		if (!empty($modSettings['removeNestedQuotes'])) {
2766
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2767
+		}
2627 2768
 
2628 2769
 		$lb = "\n";
2629 2770
 
@@ -2649,14 +2790,14 @@  discard block
 block discarded – undo
2649 2790
 				'time' => '',
2650 2791
 			),
2651 2792
 		);
2652
-	}
2653
-	else
2654
-		$context['quote'] = array(
2793
+	} else {
2794
+			$context['quote'] = array(
2655 2795
 			'xml' => '',
2656 2796
 			'mozilla' => '',
2657 2797
 			'text' => '',
2658 2798
 		);
2659
-}
2799
+	}
2800
+	}
2660 2801
 
2661 2802
 /**
2662 2803
  * Used to edit the body or subject of a message inline
@@ -2668,8 +2809,9 @@  discard block
 block discarded – undo
2668 2809
 	global $user_info, $context, $smcFunc, $language, $board_info;
2669 2810
 
2670 2811
 	// We have to have a topic!
2671
-	if (empty($topic))
2672
-		obExit(false);
2812
+	if (empty($topic)) {
2813
+			obExit(false);
2814
+	}
2673 2815
 
2674 2816
 	checkSession('get');
2675 2817
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2695,31 +2837,35 @@  discard block
 block discarded – undo
2695 2837
 			'guest_id' => 0,
2696 2838
 		)
2697 2839
 	);
2698
-	if ($smcFunc['db_num_rows']($request) == 0)
2699
-		fatal_lang_error('no_board', false);
2840
+	if ($smcFunc['db_num_rows']($request) == 0) {
2841
+			fatal_lang_error('no_board', false);
2842
+	}
2700 2843
 	$row = $smcFunc['db_fetch_assoc']($request);
2701 2844
 	$smcFunc['db_free_result']($request);
2702 2845
 
2703 2846
 	// Change either body or subject requires permissions to modify messages.
2704 2847
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2705 2848
 	{
2706
-		if (!empty($row['locked']))
2707
-			isAllowedTo('moderate_board');
2849
+		if (!empty($row['locked'])) {
2850
+					isAllowedTo('moderate_board');
2851
+		}
2708 2852
 
2709 2853
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2710 2854
 		{
2711
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2712
-				fatal_lang_error('modify_post_time_passed', false);
2713
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2714
-				isAllowedTo('modify_replies');
2715
-			else
2716
-				isAllowedTo('modify_own');
2855
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2856
+							fatal_lang_error('modify_post_time_passed', false);
2857
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2858
+							isAllowedTo('modify_replies');
2859
+			} else {
2860
+							isAllowedTo('modify_own');
2861
+			}
2717 2862
 		}
2718 2863
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2719
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2720
-			isAllowedTo('modify_replies');
2721
-		else
2722
-			isAllowedTo('modify_any');
2864
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2865
+					isAllowedTo('modify_replies');
2866
+		} else {
2867
+					isAllowedTo('modify_any');
2868
+		}
2723 2869
 
2724 2870
 		// Only log this action if it wasn't your message.
2725 2871
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2731,10 +2877,10 @@  discard block
 block discarded – undo
2731 2877
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2732 2878
 
2733 2879
 		// Maximum number of characters.
2734
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2735
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2736
-	}
2737
-	elseif (isset($_POST['subject']))
2880
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2881
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2882
+		}
2883
+	} elseif (isset($_POST['subject']))
2738 2884
 	{
2739 2885
 		$post_errors[] = 'no_subject';
2740 2886
 		unset($_POST['subject']);
@@ -2746,13 +2892,11 @@  discard block
 block discarded – undo
2746 2892
 		{
2747 2893
 			$post_errors[] = 'no_message';
2748 2894
 			unset($_POST['message']);
2749
-		}
2750
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2895
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2751 2896
 		{
2752 2897
 			$post_errors[] = 'long_message';
2753 2898
 			unset($_POST['message']);
2754
-		}
2755
-		else
2899
+		} else
2756 2900
 		{
2757 2901
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2758 2902
 
@@ -2768,31 +2912,34 @@  discard block
 block discarded – undo
2768 2912
 
2769 2913
 	if (isset($_POST['lock']))
2770 2914
 	{
2771
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2772
-			unset($_POST['lock']);
2773
-		elseif (!allowedTo('lock_any'))
2915
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
2916
+					unset($_POST['lock']);
2917
+		} elseif (!allowedTo('lock_any'))
2774 2918
 		{
2775
-			if ($row['locked'] == 1)
2776
-				unset($_POST['lock']);
2777
-			else
2778
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
2919
+			if ($row['locked'] == 1) {
2920
+							unset($_POST['lock']);
2921
+			} else {
2922
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
2923
+			}
2924
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
2925
+					unset($_POST['lock']);
2926
+		} else {
2927
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2779 2928
 		}
2780
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2781
-			unset($_POST['lock']);
2782
-		else
2783
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2784 2929
 	}
2785 2930
 
2786
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2787
-		unset($_POST['sticky']);
2931
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
2932
+			unset($_POST['sticky']);
2933
+	}
2788 2934
 
2789 2935
 	if (isset($_POST['modify_reason']))
2790 2936
 	{
2791 2937
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2792 2938
 
2793 2939
 		// Maximum number of characters.
2794
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2795
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2940
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2941
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2942
+		}
2796 2943
 	}
2797 2944
 
2798 2945
 	if (empty($post_errors))
@@ -2829,8 +2976,9 @@  discard block
 block discarded – undo
2829 2976
 			}
2830 2977
 		}
2831 2978
 		// If nothing was changed there's no need to add an entry to the moderation log.
2832
-		else
2833
-			$moderationAction = false;
2979
+		else {
2980
+					$moderationAction = false;
2981
+		}
2834 2982
 
2835 2983
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2836 2984
 
@@ -2848,9 +2996,9 @@  discard block
 block discarded – undo
2848 2996
 			// Get the proper (default language) response prefix first.
2849 2997
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2850 2998
 			{
2851
-				if ($language === $user_info['language'])
2852
-					$context['response_prefix'] = $txt['response_prefix'];
2853
-				else
2999
+				if ($language === $user_info['language']) {
3000
+									$context['response_prefix'] = $txt['response_prefix'];
3001
+				} else
2854 3002
 				{
2855 3003
 					loadLanguage('index', $language, false);
2856 3004
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2872,8 +3020,9 @@  discard block
 block discarded – undo
2872 3020
 			);
2873 3021
 		}
2874 3022
 
2875
-		if (!empty($moderationAction))
2876
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3023
+		if (!empty($moderationAction)) {
3024
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3025
+		}
2877 3026
 	}
2878 3027
 
2879 3028
 	if (isset($_REQUEST['xml']))
@@ -2914,8 +3063,7 @@  discard block
 block discarded – undo
2914 3063
 			);
2915 3064
 
2916 3065
 			censorText($context['message']['subject']);
2917
-		}
2918
-		else
3066
+		} else
2919 3067
 		{
2920 3068
 			$context['message'] = array(
2921 3069
 				'id' => $row['id_msg'],
@@ -2927,15 +3075,16 @@  discard block
 block discarded – undo
2927 3075
 			loadLanguage('Errors');
2928 3076
 			foreach ($post_errors as $post_error)
2929 3077
 			{
2930
-				if ($post_error == 'long_message')
2931
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
2932
-				else
2933
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3078
+				if ($post_error == 'long_message') {
3079
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3080
+				} else {
3081
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3082
+				}
2934 3083
 			}
2935 3084
 		}
3085
+	} else {
3086
+			obExit(false);
3087
+	}
2936 3088
 	}
2937
-	else
2938
-		obExit(false);
2939
-}
2940 3089
 
2941 3090
 ?>
2942 3091
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +164 added lines, -128 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -102,19 +106,20 @@  discard block
 block discarded – undo
102 106
 			list (,, $timeout) = smf_json_decode($_COOKIE[$cookiename], true);
103 107
 
104 108
 			// That didn't work... Maybe it's using serialize?
105
-			if (is_null($timeout))
106
-				list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
107
-		}
108
-		elseif (isset($_SESSION['login_' . $cookiename]))
109
+			if (is_null($timeout)) {
110
+							list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
111
+			}
112
+		} elseif (isset($_SESSION['login_' . $cookiename]))
109 113
 		{
110 114
 			list (,, $timeout) = smf_json_decode($_SESSION['login_' . $cookiename]);
111 115
 
112 116
 			// Try for old format
113
-			if (is_null($timeout))
114
-				list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
117
+			if (is_null($timeout)) {
118
+							list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
119
+			}
120
+		} else {
121
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
115 122
 		}
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
118 123
 
119 124
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 125
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -125,16 +130,18 @@  discard block
 block discarded – undo
125 130
 			$tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
126 131
 
127 132
 			// If that didn't work, try unserialize instead...
128
-			if (is_null($tfadata))
129
-				$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
133
+			if (is_null($tfadata)) {
134
+							$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
135
+			}
130 136
 
131 137
 			list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
132 138
 
133 139
 			// If we're preserving the cookie, reset it with updated salt
134
-			if ($preserve && time() < $exp)
135
-				setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
136
-			else
137
-				setTFACookie(-3600, 0, '');
140
+			if ($preserve && time() < $exp) {
141
+							setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
142
+			} else {
143
+							setTFACookie(-3600, 0, '');
144
+			}
138 145
 		}
139 146
 
140 147
 		setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
@@ -145,20 +152,20 @@  discard block
 block discarded – undo
145 152
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
146 153
 	{
147 154
 		// Strike!  You're outta there!
148
-		if ($_GET['member'] != $user_info['id'])
149
-			fatal_lang_error('login_cookie_error', false);
155
+		if ($_GET['member'] != $user_info['id']) {
156
+					fatal_lang_error('login_cookie_error', false);
157
+		}
150 158
 
151 159
 		$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']))));
152 160
 
153 161
 		// Some whitelisting for login_url...
154
-		if (empty($_SESSION['login_url']))
155
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
156
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
162
+		if (empty($_SESSION['login_url'])) {
163
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
164
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
157 165
 		{
158 166
 			unset ($_SESSION['login_url']);
159 167
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
160
-		}
161
-		else
168
+		} else
162 169
 		{
163 170
 			// Best not to clutter the session data too much...
164 171
 			$temp = $_SESSION['login_url'];
@@ -169,8 +176,9 @@  discard block
 block discarded – undo
169 176
 	}
170 177
 
171 178
 	// Beyond this point you are assumed to be a guest trying to login.
172
-	if (!$user_info['is_guest'])
173
-		redirectexit();
179
+	if (!$user_info['is_guest']) {
180
+			redirectexit();
181
+	}
174 182
 
175 183
 	// Are you guessing with a script?
176 184
 	checkSession();
@@ -178,18 +186,21 @@  discard block
 block discarded – undo
178 186
 	spamProtection('login');
179 187
 
180 188
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
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'];
189
+	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)) {
190
+			$_SESSION['login_url'] = $_SESSION['old_url'];
191
+	}
183 192
 
184 193
 	// Been guessing a lot, haven't we?
185
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
186
-		fatal_lang_error('login_threshold_fail', 'critical');
194
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
195
+			fatal_lang_error('login_threshold_fail', 'critical');
196
+	}
187 197
 
188 198
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
189
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
190
-		$modSettings['cookieTime'] = 3153600;
191
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
192
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
199
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
200
+			$modSettings['cookieTime'] = 3153600;
201
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
202
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
203
+	}
193 204
 
194 205
 	loadLanguage('Login');
195 206
 	// Load the template stuff.
@@ -309,8 +320,9 @@  discard block
 block discarded – undo
309 320
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
310 321
 
311 322
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
312
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
313
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
323
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
324
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
325
+			}
314 326
 
315 327
 			// phpBB3 users new hashing.  We now support it as well ;).
316 328
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -330,27 +342,29 @@  discard block
 block discarded – undo
330 342
 			// Some common md5 ones.
331 343
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
332 344
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
333
-		}
334
-		elseif (strlen($user_settings['passwd']) == 40)
345
+		} elseif (strlen($user_settings['passwd']) == 40)
335 346
 		{
336 347
 			// Maybe they are using a hash from before the password fix.
337 348
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
338 349
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
339 350
 
340 351
 			// BurningBoard3 style of hashing.
341
-			if (!empty($modSettings['enable_password_conversion']))
342
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
352
+			if (!empty($modSettings['enable_password_conversion'])) {
353
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
354
+			}
343 355
 
344 356
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
345 357
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
346 358
 			{
347 359
 				// Try iconv first, for no particular reason.
348
-				if (function_exists('iconv'))
349
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
360
+				if (function_exists('iconv')) {
361
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
362
+				}
350 363
 
351 364
 				// Say it aint so, iconv failed!
352
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
353
-					$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'])));
365
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
366
+									$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'])));
367
+				}
354 368
 			}
355 369
 		}
356 370
 
@@ -380,8 +394,9 @@  discard block
 block discarded – undo
380 394
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
381 395
 
382 396
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
383
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
384
-				redirectexit('action=reminder');
397
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
398
+							redirectexit('action=reminder');
399
+			}
385 400
 			// We'll give you another chance...
386 401
 			else
387 402
 			{
@@ -392,8 +407,7 @@  discard block
 block discarded – undo
392 407
 				return;
393 408
 			}
394 409
 		}
395
-	}
396
-	elseif (!empty($user_settings['passwd_flood']))
410
+	} elseif (!empty($user_settings['passwd_flood']))
397 411
 	{
398 412
 		// Let's be sure they weren't a little hacker.
399 413
 		validatePasswordFlood($user_settings['id_member'], $user_settings['passwd_flood'], true);
@@ -410,8 +424,9 @@  discard block
 block discarded – undo
410 424
 	}
411 425
 
412 426
 	// Check their activation status.
413
-	if (!checkActivation())
414
-		return;
427
+	if (!checkActivation()) {
428
+			return;
429
+	}
415 430
 
416 431
 	DoLogin();
417 432
 }
@@ -423,8 +438,9 @@  discard block
 block discarded – undo
423 438
 {
424 439
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
425 440
 
426
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
427
-		fatal_lang_error('no_access', false);
441
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
442
+			fatal_lang_error('no_access', false);
443
+	}
428 444
 
429 445
 	loadLanguage('Profile');
430 446
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -432,8 +448,9 @@  discard block
 block discarded – undo
432 448
 	$member = $context['tfa_member'];
433 449
 
434 450
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
435
-	if (time() - $member['last_login'] < 120)
436
-		fatal_lang_error('tfa_wait', false);
451
+	if (time() - $member['last_login'] < 120) {
452
+			fatal_lang_error('tfa_wait', false);
453
+	}
437 454
 
438 455
 	$totp = new \TOTP\Auth($member['tfa_secret']);
439 456
 	$totp->setRange(1);
@@ -447,8 +464,9 @@  discard block
 block discarded – undo
447 464
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
448 465
 	{
449 466
 		// Check to ensure we're forcing SSL for authentication
450
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
451
-			fatal_lang_error('login_ssl_required');
467
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
468
+					fatal_lang_error('login_ssl_required');
469
+		}
452 470
 
453 471
 		$code = $_POST['tfa_code'];
454 472
 
@@ -458,20 +476,19 @@  discard block
 block discarded – undo
458 476
 
459 477
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve']));
460 478
 			redirectexit();
461
-		}
462
-		else
479
+		} else
463 480
 		{
464 481
 			validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true);
465 482
 
466 483
 			$context['tfa_error'] = true;
467 484
 			$context['tfa_value'] = $_POST['tfa_code'];
468 485
 		}
469
-	}
470
-	elseif (!empty($_POST['tfa_backup']))
486
+	} elseif (!empty($_POST['tfa_backup']))
471 487
 	{
472 488
 		// Check to ensure we're forcing SSL for authentication
473
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
474
-			fatal_lang_error('login_ssl_required');
489
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
490
+					fatal_lang_error('login_ssl_required');
491
+		}
475 492
 
476 493
 		$backup = $_POST['tfa_backup'];
477 494
 
@@ -485,8 +502,7 @@  discard block
 block discarded – undo
485 502
 			));
486 503
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
487 504
 			redirectexit('action=profile;area=tfasetup;backup');
488
-		}
489
-		else
505
+		} else
490 506
 		{
491 507
 			validatePasswordFlood($member['id_member'], $member['passwd_flood'], false, true);
492 508
 
@@ -509,8 +525,9 @@  discard block
 block discarded – undo
509 525
 {
510 526
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
511 527
 
512
-	if (!isset($context['login_errors']))
513
-		$context['login_errors'] = array();
528
+	if (!isset($context['login_errors'])) {
529
+			$context['login_errors'] = array();
530
+	}
514 531
 
515 532
 	// What is the true activation status of this account?
516 533
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -522,8 +539,9 @@  discard block
 block discarded – undo
522 539
 		return false;
523 540
 	}
524 541
 	// Awaiting approval still?
525
-	elseif ($activation_status == 3)
526
-		fatal_lang_error('still_awaiting_approval', 'user');
542
+	elseif ($activation_status == 3) {
543
+			fatal_lang_error('still_awaiting_approval', 'user');
544
+	}
527 545
 	// Awaiting deletion, changed their mind?
528 546
 	elseif ($activation_status == 4)
529 547
 	{
@@ -531,8 +549,7 @@  discard block
 block discarded – undo
531 549
 		{
532 550
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
533 551
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
534
-		}
535
-		else
552
+		} else
536 553
 		{
537 554
 			$context['disable_login_hashing'] = true;
538 555
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -573,8 +590,9 @@  discard block
 block discarded – undo
573 590
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
574 591
 
575 592
 	// Reset the login threshold.
576
-	if (isset($_SESSION['failed_login']))
577
-		unset($_SESSION['failed_login']);
593
+	if (isset($_SESSION['failed_login'])) {
594
+			unset($_SESSION['failed_login']);
595
+	}
578 596
 
579 597
 	$user_info['is_guest'] = false;
580 598
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -596,16 +614,18 @@  discard block
 block discarded – undo
596 614
 			'id_member' => $user_info['id'],
597 615
 		)
598 616
 	);
599
-	if ($smcFunc['db_num_rows']($request) == 1)
600
-		$_SESSION['first_login'] = true;
601
-	else
602
-		unset($_SESSION['first_login']);
617
+	if ($smcFunc['db_num_rows']($request) == 1) {
618
+			$_SESSION['first_login'] = true;
619
+	} else {
620
+			unset($_SESSION['first_login']);
621
+	}
603 622
 	$smcFunc['db_free_result']($request);
604 623
 
605 624
 	// You've logged in, haven't you?
606 625
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
607
-	if (empty($user_settings['tfa_secret']))
608
-		$update['last_login'] = time();
626
+	if (empty($user_settings['tfa_secret'])) {
627
+			$update['last_login'] = time();
628
+	}
609 629
 	updateMemberData($user_info['id'], $update);
610 630
 
611 631
 	// Get rid of the online entry for that old guest....
@@ -619,8 +639,8 @@  discard block
 block discarded – undo
619 639
 	$_SESSION['log_time'] = 0;
620 640
 
621 641
 	// Log this entry, only if we have it enabled.
622
-	if (!empty($modSettings['loginHistoryDays']))
623
-		$smcFunc['db_insert']('insert',
642
+	if (!empty($modSettings['loginHistoryDays'])) {
643
+			$smcFunc['db_insert']('insert',
624 644
 			'{db_prefix}member_logins',
625 645
 			array(
626 646
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -632,13 +652,15 @@  discard block
 block discarded – undo
632 652
 				'id_member', 'time'
633 653
 			)
634 654
 		);
655
+	}
635 656
 
636 657
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
637
-	if (empty($maintenance) || allowedTo('admin_forum'))
638
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
639
-	else
640
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
641
-}
658
+	if (empty($maintenance) || allowedTo('admin_forum')) {
659
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
660
+	} else {
661
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
662
+	}
663
+	}
642 664
 
643 665
 /**
644 666
  * Logs the current user out of their account.
@@ -654,13 +676,15 @@  discard block
 block discarded – undo
654 676
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
655 677
 
656 678
 	// Make sure they aren't being auto-logged out.
657
-	if (!$internal)
658
-		checkSession('get');
679
+	if (!$internal) {
680
+			checkSession('get');
681
+	}
659 682
 
660 683
 	require_once($sourcedir . '/Subs-Auth.php');
661 684
 
662
-	if (isset($_SESSION['pack_ftp']))
663
-		$_SESSION['pack_ftp'] = null;
685
+	if (isset($_SESSION['pack_ftp'])) {
686
+			$_SESSION['pack_ftp'] = null;
687
+	}
664 688
 
665 689
 	// It won't be first login anymore.
666 690
 	unset($_SESSION['first_login']);
@@ -688,24 +712,27 @@  discard block
 block discarded – undo
688 712
 
689 713
 	// And some other housekeeping while we're at it.
690 714
 	$salt = substr(md5(mt_rand()), 0, 4);
691
-	if (!empty($user_info['id']))
692
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
715
+	if (!empty($user_info['id'])) {
716
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
717
+	}
693 718
 
694 719
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
695 720
 	{
696 721
 		$tfadata = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
697 722
 
698 723
 		// If that failed, try the old method
699
-		if (is_null($tfadata))
700
-			$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
724
+		if (is_null($tfadata)) {
725
+					$tfadata = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
726
+		}
701 727
 
702 728
 		list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
703 729
 
704 730
 		// If we're preserving the cookie, reset it with updated salt
705
-		if ($preserve && time() < $exp)
706
-			setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
707
-		else
708
-			setTFACookie(-3600, 0, '');
731
+		if ($preserve && time() < $exp) {
732
+					setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
733
+		} else {
734
+					setTFACookie(-3600, 0, '');
735
+		}
709 736
 	}
710 737
 
711 738
 	session_destroy();
@@ -713,14 +740,13 @@  discard block
 block discarded – undo
713 740
 	// Off to the merry board index we go!
714 741
 	if ($redirect)
715 742
 	{
716
-		if (empty($_SESSION['logout_url']))
717
-			redirectexit('', $context['server']['needs_login_fix']);
718
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
743
+		if (empty($_SESSION['logout_url'])) {
744
+					redirectexit('', $context['server']['needs_login_fix']);
745
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
719 746
 		{
720 747
 			unset ($_SESSION['logout_url']);
721 748
 			redirectexit();
722
-		}
723
-		else
749
+		} else
724 750
 		{
725 751
 			$temp = $_SESSION['logout_url'];
726 752
 			unset($_SESSION['logout_url']);
@@ -753,8 +779,9 @@  discard block
 block discarded – undo
753 779
 function phpBB3_password_check($passwd, $passwd_hash)
754 780
 {
755 781
 	// Too long or too short?
756
-	if (strlen($passwd_hash) != 34)
757
-		return;
782
+	if (strlen($passwd_hash) != 34) {
783
+			return;
784
+	}
758 785
 
759 786
 	// Range of characters allowed.
760 787
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -766,8 +793,9 @@  discard block
 block discarded – undo
766 793
 	$salt = substr($passwd_hash, 4, 8);
767 794
 
768 795
 	$hash = md5($salt . $passwd, true);
769
-	for (; $count != 0; --$count)
770
-		$hash = md5($hash . $passwd, true);
796
+	for (; $count != 0; --$count) {
797
+			$hash = md5($hash . $passwd, true);
798
+	}
771 799
 
772 800
 	$output = substr($passwd_hash, 0, 12);
773 801
 	$i = 0;
@@ -776,21 +804,25 @@  discard block
 block discarded – undo
776 804
 		$value = ord($hash[$i++]);
777 805
 		$output .= $range[$value & 0x3f];
778 806
 
779
-		if ($i < 16)
780
-			$value |= ord($hash[$i]) << 8;
807
+		if ($i < 16) {
808
+					$value |= ord($hash[$i]) << 8;
809
+		}
781 810
 
782 811
 		$output .= $range[($value >> 6) & 0x3f];
783 812
 
784
-		if ($i++ >= 16)
785
-			break;
813
+		if ($i++ >= 16) {
814
+					break;
815
+		}
786 816
 
787
-		if ($i < 16)
788
-			$value |= ord($hash[$i]) << 16;
817
+		if ($i < 16) {
818
+					$value |= ord($hash[$i]) << 16;
819
+		}
789 820
 
790 821
 		$output .= $range[($value >> 12) & 0x3f];
791 822
 
792
-		if ($i++ >= 16)
793
-			break;
823
+		if ($i++ >= 16) {
824
+					break;
825
+		}
794 826
 
795 827
 		$output .= $range[($value >> 18) & 0x3f];
796 828
 	}
@@ -821,8 +853,9 @@  discard block
 block discarded – undo
821 853
 		require_once($sourcedir . '/Subs-Auth.php');
822 854
 		setLoginCookie(-3600, 0);
823 855
 
824
-		if (isset($_SESSION['login_' . $cookiename]))
825
-			unset($_SESSION['login_' . $cookiename]);
856
+		if (isset($_SESSION['login_' . $cookiename])) {
857
+					unset($_SESSION['login_' . $cookiename]);
858
+		}
826 859
 	}
827 860
 
828 861
 	// We need a member!
@@ -836,8 +869,9 @@  discard block
 block discarded – undo
836 869
 	}
837 870
 
838 871
 	// Right, have we got a flood value?
839
-	if ($password_flood_value !== false)
840
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
872
+	if ($password_flood_value !== false) {
873
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
874
+	}
841 875
 
842 876
 	// Timestamp or number of tries invalid?
843 877
 	if (empty($number_tries) || empty($time_stamp))
@@ -853,15 +887,17 @@  discard block
 block discarded – undo
853 887
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
854 888
 
855 889
 		// They are trying too fast, make them wait longer
856
-		if ($time_stamp < time() - 10)
857
-			$time_stamp = time();
890
+		if ($time_stamp < time() - 10) {
891
+					$time_stamp = time();
892
+		}
858 893
 	}
859 894
 
860 895
 	$number_tries++;
861 896
 
862 897
 	// Broken the law?
863
-	if ($number_tries > 5)
864
-		fatal_lang_error('login_threshold_brute_fail', 'critical');
898
+	if ($number_tries > 5) {
899
+			fatal_lang_error('login_threshold_brute_fail', 'critical');
900
+	}
865 901
 
866 902
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
867 903
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/ManageSearch.php 1 patch
Braces   +109 added lines, -90 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Main entry point for the admin search settings screen.
@@ -107,11 +108,13 @@  discard block
 block discarded – undo
107 108
 	// Perhaps the search method wants to add some settings?
108 109
 	require_once($sourcedir . '/Search.php');
109 110
 	$searchAPI = findSearchAPI();
110
-	if (is_callable(array($searchAPI, 'searchSettings')))
111
-		call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
111
+	if (is_callable(array($searchAPI, 'searchSettings'))) {
112
+			call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars));
113
+	}
112 114
 
113
-	if ($return_config)
114
-		return $config_vars;
115
+	if ($return_config) {
116
+			return $config_vars;
117
+	}
115 118
 
116 119
 	$context['page_title'] = $txt['search_settings_title'];
117 120
 	$context['sub_template'] = 'show_settings';
@@ -126,8 +129,9 @@  discard block
 block discarded – undo
126 129
 
127 130
 		call_integration_hook('integrate_save_search_settings');
128 131
 
129
-		if (empty($_POST['search_results_per_page']))
130
-			$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
132
+		if (empty($_POST['search_results_per_page'])) {
133
+					$_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages'];
134
+		}
131 135
 		saveDBSettings($config_vars);
132 136
 		$_SESSION['adm-save'] = true;
133 137
 		redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']);
@@ -177,17 +181,20 @@  discard block
 block discarded – undo
177 181
 		call_integration_hook('integrate_save_search_weights');
178 182
 
179 183
 		$changes = array();
180
-		foreach ($factors as $factor)
181
-			$changes[$factor] = (int) $_POST[$factor];
184
+		foreach ($factors as $factor) {
185
+					$changes[$factor] = (int) $_POST[$factor];
186
+		}
182 187
 		updateSettings($changes);
183 188
 	}
184 189
 
185 190
 	$context['relative_weights'] = array('total' => 0);
186
-	foreach ($factors as $factor)
187
-		$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
191
+	foreach ($factors as $factor) {
192
+			$context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0;
193
+	}
188 194
 
189
-	foreach ($factors as $factor)
190
-		$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
195
+	foreach ($factors as $factor) {
196
+			$context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1);
197
+	}
191 198
 
192 199
 	createToken('admin-msw');
193 200
 }
@@ -215,8 +222,9 @@  discard block
 block discarded – undo
215 222
 	$context['search_apis'] = loadSearchAPIs();
216 223
 
217 224
 	// Detect whether a fulltext index is set.
218
-	if ($context['supports_fulltext'])
219
-		detectFulltextIndex();
225
+	if ($context['supports_fulltext']) {
226
+			detectFulltextIndex();
227
+	}
220 228
 
221 229
 	if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext')
222 230
 	{
@@ -252,8 +260,7 @@  discard block
 block discarded – undo
252 260
 					'language' => $language_ftx
253 261
 				)
254 262
 			);
255
-		}
256
-		else
263
+		} else
257 264
 		{
258 265
 			// Make sure it's gone before creating it.
259 266
 			$smcFunc['db_query']('', '
@@ -273,8 +280,7 @@  discard block
 block discarded – undo
273 280
 		}
274 281
 
275 282
 		$context['fulltext_index'] = 'body';
276
-	}
277
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
283
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
278 284
 	{
279 285
 		checkSession('get');
280 286
 		validateToken('admin-msm', 'get');
@@ -291,12 +297,12 @@  discard block
 block discarded – undo
291 297
 		$context['fulltext_index'] = '';
292 298
 
293 299
 		// Go back to the default search method.
294
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext')
295
-			updateSettings(array(
300
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') {
301
+					updateSettings(array(
296 302
 				'search_index' => '',
297 303
 			));
298
-	}
299
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
304
+		}
305
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
300 306
 	{
301 307
 		checkSession('get');
302 308
 		validateToken('admin-msm', 'get');
@@ -318,12 +324,12 @@  discard block
 block discarded – undo
318 324
 		));
319 325
 
320 326
 		// Go back to the default search method.
321
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
322
-			updateSettings(array(
327
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
328
+					updateSettings(array(
323 329
 				'search_index' => '',
324 330
 			));
325
-	}
326
-	elseif (isset($_POST['save']))
331
+		}
332
+	} elseif (isset($_POST['save']))
327 333
 	{
328 334
 		checkSession();
329 335
 		validateToken('admin-msmpost');
@@ -345,8 +351,8 @@  discard block
 block discarded – undo
345 351
 	// Get some info about the messages table, to show its size and index size.
346 352
 	if ($db_type == 'mysql' || $db_type == 'mysqli')
347 353
 	{
348
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
349
-			$request = $smcFunc['db_query']('', '
354
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
355
+					$request = $smcFunc['db_query']('', '
350 356
 				SHOW TABLE STATUS
351 357
 				FROM {string:database_name}
352 358
 				LIKE {string:table_name}',
@@ -355,14 +361,15 @@  discard block
 block discarded – undo
355 361
 					'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
356 362
 				)
357 363
 			);
358
-		else
359
-			$request = $smcFunc['db_query']('', '
364
+		} else {
365
+					$request = $smcFunc['db_query']('', '
360 366
 				SHOW TABLE STATUS
361 367
 				LIKE {string:table_name}',
362 368
 				array(
363 369
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
364 370
 				)
365 371
 			);
372
+		}
366 373
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
367 374
 		{
368 375
 			// Only do this if the user has permission to execute this query.
@@ -374,8 +381,8 @@  discard block
 block discarded – undo
374 381
 		}
375 382
 
376 383
 		// Now check the custom index table, if it exists at all.
377
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
378
-			$request = $smcFunc['db_query']('', '
384
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
385
+					$request = $smcFunc['db_query']('', '
379 386
 				SHOW TABLE STATUS
380 387
 				FROM {string:database_name}
381 388
 				LIKE {string:table_name}',
@@ -384,14 +391,15 @@  discard block
 block discarded – undo
384 391
 					'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words',
385 392
 				)
386 393
 			);
387
-		else
388
-			$request = $smcFunc['db_query']('', '
394
+		} else {
395
+					$request = $smcFunc['db_query']('', '
389 396
 				SHOW TABLE STATUS
390 397
 				LIKE {string:table_name}',
391 398
 				array(
392 399
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words',
393 400
 				)
394 401
 			);
402
+		}
395 403
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
396 404
 		{
397 405
 			// Only do this if the user has permission to execute this query.
@@ -400,8 +408,7 @@  discard block
 block discarded – undo
400 408
 			$context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length'];
401 409
 			$smcFunc['db_free_result']($request);
402 410
 		}
403
-	}
404
-	elseif ($db_type == 'postgresql')
411
+	} elseif ($db_type == 'postgresql')
405 412
 	{
406 413
 		// In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using.
407 414
 		//db_extend();
@@ -443,38 +450,38 @@  discard block
 block discarded – undo
443 450
 					$context['table_info']['data_length'] = (int) $row['table_size'];
444 451
 					$context['table_info']['index_length'] = (int) $row['index_size'];
445 452
 					$context['table_info']['fulltext_length'] = (int) $row['index_size'];
446
-				}
447
-				elseif ($row['indexname'] == $db_prefix . 'log_search_words')
453
+				} elseif ($row['indexname'] == $db_prefix . 'log_search_words')
448 454
 				{
449 455
 					$context['table_info']['index_length'] = (int) $row['index_size'];
450 456
 					$context['table_info']['custom_index_length'] = (int) $row['index_size'];
451 457
 				}
452 458
 			}
453 459
 			$smcFunc['db_free_result']($request);
454
-		}
455
-		else
456
-			// Didn't work for some reason...
460
+		} else {
461
+					// Didn't work for some reason...
457 462
 			$context['table_info'] = array(
458 463
 				'data_length' => $txt['not_applicable'],
459 464
 				'index_length' => $txt['not_applicable'],
460 465
 				'fulltext_length' => $txt['not_applicable'],
461 466
 				'custom_index_length' => $txt['not_applicable'],
462 467
 			);
463
-	}
464
-	else
465
-		$context['table_info'] = array(
468
+		}
469
+	} else {
470
+			$context['table_info'] = array(
466 471
 			'data_length' => $txt['not_applicable'],
467 472
 			'index_length' => $txt['not_applicable'],
468 473
 			'fulltext_length' => $txt['not_applicable'],
469 474
 			'custom_index_length' => $txt['not_applicable'],
470 475
 		);
476
+	}
471 477
 
472 478
 	// Format the data and index length in kilobytes.
473 479
 	foreach ($context['table_info'] as $type => $size)
474 480
 	{
475 481
 		// If it's not numeric then just break.  This database engine doesn't support size.
476
-		if (!is_numeric($size))
477
-			break;
482
+		if (!is_numeric($size)) {
483
+					break;
484
+		}
478 485
 
479 486
 		$context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes'];
480 487
 	}
@@ -503,8 +510,9 @@  discard block
 block discarded – undo
503 510
 
504 511
 	// Scotty, we need more time...
505 512
 	@set_time_limit(600);
506
-	if (function_exists('apache_reset_timeout'))
507
-		@apache_reset_timeout();
513
+	if (function_exists('apache_reset_timeout')) {
514
+			@apache_reset_timeout();
515
+	}
508 516
 
509 517
 	$context[$context['admin_menu_name']]['current_subsection'] = 'method';
510 518
 	$context['page_title'] = $txt['search_index_custom'];
@@ -534,8 +542,7 @@  discard block
 block discarded – undo
534 542
 		$context['start'] = (int) $context['index_settings']['resume_at'];
535 543
 		unset($context['index_settings']['resume_at']);
536 544
 		$context['step'] = 1;
537
-	}
538
-	else
545
+	} else
539 546
 	{
540 547
 		$context['index_settings'] = array(
541 548
 			'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2,
@@ -544,12 +551,14 @@  discard block
 block discarded – undo
544 551
 		$context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
545 552
 
546 553
 		// admin timeouts are painful when building these long indexes - but only if we actually have such things enabled
547
-		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1)
548
-			$_SESSION['admin_time'] = time();
554
+		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) {
555
+					$_SESSION['admin_time'] = time();
556
+		}
549 557
 	}
550 558
 
551
-	if ($context['step'] !== 0)
552
-		checkSession('request');
559
+	if ($context['step'] !== 0) {
560
+			checkSession('request');
561
+	}
553 562
 
554 563
 	// Step 0: let the user determine how they like their index.
555 564
 	if ($context['step'] === 0)
@@ -578,12 +587,14 @@  discard block
 block discarded – undo
578 587
 			$smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']);
579 588
 
580 589
 			// Temporarily switch back to not using a search index.
581
-			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
582
-				updateSettings(array('search_index' => ''));
590
+			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
591
+							updateSettings(array('search_index' => ''));
592
+			}
583 593
 
584 594
 			// Don't let simultanious processes be updating the search index.
585
-			if (!empty($modSettings['search_custom_index_config']))
586
-				updateSettings(array('search_custom_index_config' => ''));
595
+			if (!empty($modSettings['search_custom_index_config'])) {
596
+							updateSettings(array('search_custom_index_config' => ''));
597
+			}
587 598
 		}
588 599
 
589 600
 		$num_messages = array(
@@ -599,16 +610,16 @@  discard block
 block discarded – undo
599 610
 				'starting_id' => $context['start'],
600 611
 			)
601 612
 		);
602
-		while ($row = $smcFunc['db_fetch_assoc']($request))
603
-			$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
613
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
614
+					$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
615
+		}
604 616
 
605 617
 		if (empty($num_messages['todo']))
606 618
 		{
607 619
 			$context['step'] = 2;
608 620
 			$context['percentage'] = 80;
609 621
 			$context['start'] = 0;
610
-		}
611
-		else
622
+		} else
612 623
 		{
613 624
 			// Number of seconds before the next step.
614 625
 			$stop = time() + 3;
@@ -649,21 +660,22 @@  discard block
 block discarded – undo
649 660
 
650 661
 				$context['start'] += $forced_break ? $number_processed : $messages_per_batch;
651 662
 
652
-				if (!empty($inserts))
653
-					$smcFunc['db_insert']('ignore',
663
+				if (!empty($inserts)) {
664
+									$smcFunc['db_insert']('ignore',
654 665
 						'{db_prefix}log_search_words',
655 666
 						array('id_word' => 'int', 'id_msg' => 'int'),
656 667
 						$inserts,
657 668
 						array('id_word', 'id_msg')
658 669
 					);
670
+				}
659 671
 				if ($num_messages['todo'] === 0)
660 672
 				{
661 673
 					$context['step'] = 2;
662 674
 					$context['start'] = 0;
663 675
 					break;
676
+				} else {
677
+									updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
664 678
 				}
665
-				else
666
-					updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
667 679
 			}
668 680
 
669 681
 			// Since there are still two steps to go, 80% is the maximum here.
@@ -674,9 +686,9 @@  discard block
 block discarded – undo
674 686
 	// Step 2: removing the words that occur too often and are of no use.
675 687
 	elseif ($context['step'] === 2)
676 688
 	{
677
-		if ($context['index_settings']['bytes_per_word'] < 4)
678
-			$context['step'] = 3;
679
-		else
689
+		if ($context['index_settings']['bytes_per_word'] < 4) {
690
+					$context['step'] = 3;
691
+		} else
680 692
 		{
681 693
 			$stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']);
682 694
 			$stop = time() + 3;
@@ -697,20 +709,22 @@  discard block
 block discarded – undo
697 709
 						'minimum_messages' => $max_messages,
698 710
 					)
699 711
 				);
700
-				while ($row = $smcFunc['db_fetch_assoc']($request))
701
-					$stop_words[] = $row['id_word'];
712
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
713
+									$stop_words[] = $row['id_word'];
714
+				}
702 715
 				$smcFunc['db_free_result']($request);
703 716
 
704 717
 				updateSettings(array('search_stopwords' => implode(',', $stop_words)));
705 718
 
706
-				if (!empty($stop_words))
707
-					$smcFunc['db_query']('', '
719
+				if (!empty($stop_words)) {
720
+									$smcFunc['db_query']('', '
708 721
 						DELETE FROM {db_prefix}log_search_words
709 722
 						WHERE id_word in ({array_int:stop_words})',
710 723
 						array(
711 724
 							'stop_words' => $stop_words,
712 725
 						)
713 726
 					);
727
+				}
714 728
 
715 729
 				$context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size'];
716 730
 				if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size'])
@@ -771,8 +785,9 @@  discard block
 block discarded – undo
771 785
 					$searchAPI = new $search_class_name();
772 786
 
773 787
 					// No Support?  NEXT!
774
-					if (!$searchAPI->is_supported)
775
-						continue;
788
+					if (!$searchAPI->is_supported) {
789
+											continue;
790
+					}
776 791
 
777 792
 					$apis[$index_name] = array(
778 793
 						'filename' => $file,
@@ -819,10 +834,10 @@  discard block
 block discarded – undo
819 834
 				'messages_ftx' => $db_prefix . 'messages_ftx',
820 835
 			)
821 836
 		);
822
-		while ($row = $smcFunc['db_fetch_assoc']($request))
823
-			$context['fulltext_index'][] = $row['indexname'];
824
-	}
825
-	else
837
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
838
+					$context['fulltext_index'][] = $row['indexname'];
839
+		}
840
+	} else
826 841
 	{
827 842
 		$request = $smcFunc['db_query']('', '
828 843
 			SHOW INDEX
@@ -833,17 +848,19 @@  discard block
 block discarded – undo
833 848
 		$context['fulltext_index'] = '';
834 849
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
835 850
 		{
836
-			while ($row = $smcFunc['db_fetch_assoc']($request))
837
-			if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
851
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
852
+						if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
838 853
 				$context['fulltext_index'][] = $row['Key_name'];
854
+			}
839 855
 			$smcFunc['db_free_result']($request);
840 856
 
841
-			if (is_array($context['fulltext_index']))
842
-				$context['fulltext_index'] = array_unique($context['fulltext_index']);
857
+			if (is_array($context['fulltext_index'])) {
858
+							$context['fulltext_index'] = array_unique($context['fulltext_index']);
859
+			}
843 860
 		}
844 861
 
845
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
846
-			$request = $smcFunc['db_query']('', '
862
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
863
+					$request = $smcFunc['db_query']('', '
847 864
 			SHOW TABLE STATUS
848 865
 			FROM {string:database_name}
849 866
 			LIKE {string:table_name}',
@@ -852,20 +869,22 @@  discard block
 block discarded – undo
852 869
 				'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
853 870
 			)
854 871
 			);
855
-		else
856
-			$request = $smcFunc['db_query']('', '
872
+		} else {
873
+					$request = $smcFunc['db_query']('', '
857 874
 			SHOW TABLE STATUS
858 875
 			LIKE {string:table_name}',
859 876
 			array(
860 877
 				'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
861 878
 			)
862 879
 			);
880
+		}
863 881
 
864 882
 		if ($request !== false)
865 883
 		{
866
-			while ($row = $smcFunc['db_fetch_assoc']($request))
867
-			if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>=')))
884
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
885
+						if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>=')))
868 886
 				$context['cannot_create_fulltext'] = true;
887
+			}
869 888
 			$smcFunc['db_free_result']($request);
870 889
 		}
871 890
 	}
Please login to merge, or discard this patch.
Sources/DbExtra-mysql.php 1 patch
Braces   +66 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the functions implemented in this file to the $smcFunc array.
@@ -23,8 +24,8 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') {
28
+			$smcFunc += array(
28 29
 			'db_backup_table' => 'smf_db_backup_table',
29 30
 			'db_optimize_table' => 'smf_db_optimize_table',
30 31
 			'db_table_sql' => 'smf_db_table_sql',
@@ -32,7 +33,8 @@  discard block
 block discarded – undo
32 33
 			'db_get_version' => 'smf_db_get_version',
33 34
 			'db_get_engine' => 'smf_db_get_engine',
34 35
 		);
35
-}
36
+	}
37
+	}
36 38
 
37 39
 /**
38 40
  * Backup $table to $backup_table.
@@ -74,8 +76,9 @@  discard block
 block discarded – undo
74 76
 			));
75 77
 
76 78
 		// Old school or no school?
77
-		if ($request)
78
-			return $request;
79
+		if ($request) {
80
+					return $request;
81
+		}
79 82
 	}
80 83
 
81 84
 	// At this point, the quick method failed.
@@ -99,8 +102,9 @@  discard block
 block discarded – undo
99 102
 	foreach ($create as $k => $l)
100 103
 	{
101 104
 		// Get the name of the auto_increment column.
102
-		if (strpos($l, 'auto_increment'))
103
-			$auto_inc = trim($l);
105
+		if (strpos($l, 'auto_increment')) {
106
+					$auto_inc = trim($l);
107
+		}
104 108
 
105 109
 		// For the engine type, see if we can work out what it is.
106 110
 		if (strpos($l, 'ENGINE') !== false || strpos($l, 'TYPE') !== false)
@@ -108,30 +112,36 @@  discard block
 block discarded – undo
108 112
 			// Extract the engine type.
109 113
 			preg_match('~(ENGINE|TYPE)=(\w+)(\sDEFAULT)?(\sCHARSET=(\w+))?(\sCOLLATE=(\w+))?~', $l, $match);
110 114
 
111
-			if (!empty($match[1]))
112
-				$engine = $match[1];
115
+			if (!empty($match[1])) {
116
+							$engine = $match[1];
117
+			}
113 118
 
114
-			if (!empty($match[2]))
115
-				$engine = $match[2];
119
+			if (!empty($match[2])) {
120
+							$engine = $match[2];
121
+			}
116 122
 
117
-			if (!empty($match[5]))
118
-				$charset = $match[5];
123
+			if (!empty($match[5])) {
124
+							$charset = $match[5];
125
+			}
119 126
 
120
-			if (!empty($match[7]))
121
-				$collate = $match[7];
127
+			if (!empty($match[7])) {
128
+							$collate = $match[7];
129
+			}
122 130
 		}
123 131
 
124 132
 		// Skip everything but keys...
125
-		if (strpos($l, 'KEY') === false)
126
-			unset($create[$k]);
133
+		if (strpos($l, 'KEY') === false) {
134
+					unset($create[$k]);
135
+		}
127 136
 	}
128 137
 
129
-	if (!empty($create))
130
-		$create = '(
138
+	if (!empty($create)) {
139
+			$create = '(
131 140
 			' . implode('
132 141
 			', $create) . ')';
133
-	else
134
-		$create = '';
142
+	} else {
143
+			$create = '';
144
+	}
135 145
 
136 146
 	$request = $smcFunc['db_query']('', '
137 147
 		CREATE TABLE {raw:backup_table} {raw:create}
@@ -150,8 +160,9 @@  discard block
 block discarded – undo
150 160
 
151 161
 	if ($auto_inc != '')
152 162
 	{
153
-		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',')
154
-			$auto_inc = substr($auto_inc, 0, -1);
163
+		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') {
164
+					$auto_inc = substr($auto_inc, 0, -1);
165
+		}
155 166
 
156 167
 		$smcFunc['db_query']('', '
157 168
 			ALTER TABLE {raw:backup_table}
@@ -195,8 +206,9 @@  discard block
 block discarded – undo
195 206
 				'table' => $table,
196 207
 			)
197 208
 		);
198
-	if (!$request)
199
-		return -1;
209
+	if (!$request) {
210
+			return -1;
211
+	}
200 212
 
201 213
 	// How much left?
202 214
 	$request = $smcFunc['db_query']('', '
@@ -239,8 +251,9 @@  discard block
 block discarded – undo
239 251
 		)
240 252
 	);
241 253
 	$tables = array();
242
-	while ($row = $smcFunc['db_fetch_row']($request))
243
-		$tables[] = $row[0];
254
+	while ($row = $smcFunc['db_fetch_row']($request)) {
255
+			$tables[] = $row[0];
256
+	}
244 257
 	$smcFunc['db_free_result']($request);
245 258
 
246 259
 	return $tables;
@@ -284,8 +297,9 @@  discard block
 block discarded – undo
284 297
 		if (!empty($row['Default']) || $row['Null'] !== 'YES')
285 298
 		{
286 299
 			// Make a special case of auto-timestamp.
287
-			if ($row['Default'] == 'CURRENT_TIMESTAMP')
288
-				$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
300
+			if ($row['Default'] == 'CURRENT_TIMESTAMP') {
301
+							$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
302
+			}
289 303
 			// Text shouldn't have a default.
290 304
 			elseif ($row['Default'] !== null)
291 305
 			{
@@ -320,14 +334,16 @@  discard block
 block discarded – undo
320 334
 		$row['Key_name'] = $row['Key_name'] == 'PRIMARY' ? 'PRIMARY KEY' : (empty($row['Non_unique']) ? 'UNIQUE ' : ($row['Comment'] == 'FULLTEXT' || (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') ? 'FULLTEXT ' : 'KEY ')) . '`' . $row['Key_name'] . '`';
321 335
 
322 336
 		// Is this the first column in the index?
323
-		if (empty($indexes[$row['Key_name']]))
324
-			$indexes[$row['Key_name']] = array();
337
+		if (empty($indexes[$row['Key_name']])) {
338
+					$indexes[$row['Key_name']] = array();
339
+		}
325 340
 
326 341
 		// A sub part, like only indexing 15 characters of a varchar.
327
-		if (!empty($row['Sub_part']))
328
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
329
-		else
330
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
342
+		if (!empty($row['Sub_part'])) {
343
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
344
+		} else {
345
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
346
+		}
331 347
 	}
332 348
 	$smcFunc['db_free_result']($result);
333 349
 
@@ -365,8 +381,9 @@  discard block
 block discarded – undo
365 381
 {
366 382
 	static $ver;
367 383
 
368
-	if (!empty($ver))
369
-		return $ver;
384
+	if (!empty($ver)) {
385
+			return $ver;
386
+	}
370 387
 
371 388
 	global $smcFunc;
372 389
 
@@ -391,8 +408,9 @@  discard block
 block discarded – undo
391 408
 	global $smcFunc;
392 409
 	static $db_type;
393 410
 
394
-	if (!empty($db_type))
395
-		return $db_type;
411
+	if (!empty($db_type)) {
412
+			return $db_type;
413
+	}
396 414
 
397 415
 	$request = $smcFunc['db_query']('', 'SELECT @@version_comment');
398 416
 	list ($comment) = $smcFunc['db_fetch_row']($request);
@@ -401,13 +419,15 @@  discard block
 block discarded – undo
401 419
 	// Skip these if we don't have a comment.
402 420
 	if (!empty($comment))
403 421
 	{
404
-		if (stripos($comment, 'percona') !== false)
405
-			return 'Percona';
406
-		if (stripos($comment, 'mariadb') !== false)
407
-			return 'MariaDB';
422
+		if (stripos($comment, 'percona') !== false) {
423
+					return 'Percona';
424
+		}
425
+		if (stripos($comment, 'mariadb') !== false) {
426
+					return 'MariaDB';
427
+		}
428
+	} else {
429
+			return 'fail';
408 430
 	}
409
-	else
410
-		return 'fail';
411 431
 
412 432
 	return 'MySQL';
413 433
 }
Please login to merge, or discard this patch.
Sources/DbPackages-mysql.php 1 patch
Braces   +127 added lines, -101 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the file functions to the $smcFunc array.
@@ -52,8 +53,9 @@  discard block
 block discarded – undo
52 53
 		'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages',
53 54
 		'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys',
54 55
 		'themes', 'topics');
55
-	foreach ($reservedTables as $k => $table_name)
56
-		$reservedTables[$k] = strtolower($db_prefix . $table_name);
56
+	foreach ($reservedTables as $k => $table_name) {
57
+			$reservedTables[$k] = strtolower($db_prefix . $table_name);
58
+	}
57 59
 
58 60
 	// We in turn may need the extra stuff.
59 61
 	db_extend('extra');
@@ -105,8 +107,9 @@  discard block
 block discarded – undo
105 107
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
106 108
 
107 109
 	// First - no way do we touch SMF tables.
108
-	if (in_array(strtolower($table_name), $reservedTables))
109
-		return false;
110
+	if (in_array(strtolower($table_name), $reservedTables)) {
111
+			return false;
112
+	}
110 113
 
111 114
 	// Log that we'll want to remove this on uninstall.
112 115
 	$db_package_log[] = array('remove_table', $table_name);
@@ -116,16 +119,18 @@  discard block
 block discarded – undo
116 119
 	if (in_array($full_table_name, $tables))
117 120
 	{
118 121
 		// This is a sad day... drop the table? If not, return false (error) by default.
119
-		if ($if_exists == 'overwrite')
120
-			$smcFunc['db_drop_table']($table_name);
121
-		else
122
-			return $if_exists == 'ignore';
122
+		if ($if_exists == 'overwrite') {
123
+					$smcFunc['db_drop_table']($table_name);
124
+		} else {
125
+					return $if_exists == 'ignore';
126
+		}
123 127
 	}
124 128
 
125 129
 	// Righty - let's do the damn thing!
126 130
 	$table_query = 'CREATE TABLE ' . $table_name . "\n" . '(';
127
-	foreach ($columns as $column)
128
-		$table_query .= "\n\t" . smf_db_create_query_column($column) . ',';
131
+	foreach ($columns as $column) {
132
+			$table_query .= "\n\t" . smf_db_create_query_column($column) . ',';
133
+	}
129 134
 
130 135
 	// Loop through the indexes next...
131 136
 	foreach ($indexes as $index)
@@ -133,19 +138,21 @@  discard block
 block discarded – undo
133 138
 		$columns = implode(',', $index['columns']);
134 139
 
135 140
 		// Is it the primary?
136
-		if (isset($index['type']) && $index['type'] == 'primary')
137
-			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
138
-		else
141
+		if (isset($index['type']) && $index['type'] == 'primary') {
142
+					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
143
+		} else
139 144
 		{
140
-			if (empty($index['name']))
141
-				$index['name'] = implode('_', $index['columns']);
145
+			if (empty($index['name'])) {
146
+							$index['name'] = implode('_', $index['columns']);
147
+			}
142 148
 			$table_query .= "\n\t" . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : 'KEY') . ' ' . $index['name'] . ' (' . $columns . '),';
143 149
 		}
144 150
 	}
145 151
 
146 152
 	// No trailing commas!
147
-	if (substr($table_query, -1) == ',')
148
-		$table_query = substr($table_query, 0, -1);
153
+	if (substr($table_query, -1) == ',') {
154
+			$table_query = substr($table_query, 0, -1);
155
+	}
149 156
 
150 157
 	// Which engine do we want here?
151 158
 	if (empty($engines))
@@ -155,8 +162,9 @@  discard block
 block discarded – undo
155 162
 
156 163
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
157 164
 		{
158
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
159
-				$engines[] = $row['Engine'];
165
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
166
+							$engines[] = $row['Engine'];
167
+			}
160 168
 		}
161 169
 
162 170
 		$smcFunc['db_free_result']($get_engines);
@@ -170,8 +178,9 @@  discard block
 block discarded – undo
170 178
 	}
171 179
 
172 180
 	$table_query .= ') ENGINE=' . $parameters['engine'];
173
-	if (!empty($db_character_set) && $db_character_set == 'utf8')
174
-		$table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
181
+	if (!empty($db_character_set) && $db_character_set == 'utf8') {
182
+			$table_query .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
183
+	}
175 184
 
176 185
 	// Create the table!
177 186
 	$smcFunc['db_query']('', $table_query,
@@ -203,8 +212,9 @@  discard block
 block discarded – undo
203 212
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
204 213
 
205 214
 	// God no - dropping one of these = bad.
206
-	if (in_array(strtolower($table_name), $reservedTables))
207
-		return false;
215
+	if (in_array(strtolower($table_name), $reservedTables)) {
216
+			return false;
217
+	}
208 218
 
209 219
 	// Does it exist?
210 220
 	if (in_array($full_table_name, $smcFunc['db_list_tables']()))
@@ -245,14 +255,16 @@  discard block
 block discarded – undo
245 255
 
246 256
 	// Does it exist - if so don't add it again!
247 257
 	$columns = $smcFunc['db_list_columns']($table_name, false);
248
-	foreach ($columns as $column)
249
-		if ($column == $column_info['name'])
258
+	foreach ($columns as $column) {
259
+			if ($column == $column_info['name'])
250 260
 		{
251 261
 			// If we're going to overwrite then use change column.
252 262
 			if ($if_exists == 'update')
253 263
 				return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
254
-			else
255
-				return false;
264
+	}
265
+			else {
266
+							return false;
267
+			}
256 268
 		}
257 269
 
258 270
 	// Get the specifics...
@@ -262,8 +274,9 @@  discard block
 block discarded – undo
262 274
 	// Allow unsigned integers (mysql only)
263 275
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : '';
264 276
 
265
-	if ($size !== null)
266
-		$type = $type . '(' . $size . ')';
277
+	if ($size !== null) {
278
+			$type = $type . '(' . $size . ')';
279
+	}
267 280
 
268 281
 	// Now add the thing!
269 282
 	$query = '
@@ -295,8 +308,8 @@  discard block
 block discarded – undo
295 308
 
296 309
 	// Does it exist?
297 310
 	$columns = $smcFunc['db_list_columns']($table_name, true);
298
-	foreach ($columns as $column)
299
-		if ($column['name'] == $column_name)
311
+	foreach ($columns as $column) {
312
+			if ($column['name'] == $column_name)
300 313
 		{
301 314
 			$smcFunc['db_query']('', '
302 315
 				ALTER TABLE ' . $table_name . '
@@ -305,6 +318,7 @@  discard block
 block discarded – undo
305 318
 					'security_override' => true,
306 319
 				)
307 320
 			);
321
+	}
308 322
 
309 323
 			return true;
310 324
 		}
@@ -331,37 +345,47 @@  discard block
 block discarded – undo
331 345
 	// Check it does exist!
332 346
 	$columns = $smcFunc['db_list_columns']($table_name, true);
333 347
 	$old_info = null;
334
-	foreach ($columns as $column)
335
-		if ($column['name'] == $old_column)
348
+	foreach ($columns as $column) {
349
+			if ($column['name'] == $old_column)
336 350
 			$old_info = $column;
351
+	}
337 352
 
338 353
 	// Nothing?
339
-	if ($old_info == null)
340
-		return false;
354
+	if ($old_info == null) {
355
+			return false;
356
+	}
341 357
 
342 358
 	// Get the right bits.
343
-	if (!isset($column_info['name']))
344
-		$column_info['name'] = $old_column;
345
-	if (!isset($column_info['default']))
346
-		$column_info['default'] = $old_info['default'];
347
-	if (!isset($column_info['null']))
348
-		$column_info['null'] = $old_info['null'];
349
-	if (!isset($column_info['auto']))
350
-		$column_info['auto'] = $old_info['auto'];
351
-	if (!isset($column_info['type']))
352
-		$column_info['type'] = $old_info['type'];
353
-	if (!isset($column_info['size']) || !is_numeric($column_info['size']))
354
-		$column_info['size'] = $old_info['size'];
355
-	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')))
356
-		$column_info['unsigned'] = '';
359
+	if (!isset($column_info['name'])) {
360
+			$column_info['name'] = $old_column;
361
+	}
362
+	if (!isset($column_info['default'])) {
363
+			$column_info['default'] = $old_info['default'];
364
+	}
365
+	if (!isset($column_info['null'])) {
366
+			$column_info['null'] = $old_info['null'];
367
+	}
368
+	if (!isset($column_info['auto'])) {
369
+			$column_info['auto'] = $old_info['auto'];
370
+	}
371
+	if (!isset($column_info['type'])) {
372
+			$column_info['type'] = $old_info['type'];
373
+	}
374
+	if (!isset($column_info['size']) || !is_numeric($column_info['size'])) {
375
+			$column_info['size'] = $old_info['size'];
376
+	}
377
+	if (!isset($column_info['unsigned']) || !in_array($column_info['type'], array('int', 'tinyint', 'smallint', 'mediumint', 'bigint'))) {
378
+			$column_info['unsigned'] = '';
379
+	}
357 380
 
358 381
 	list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
359 382
 
360 383
 	// Allow for unsigned integers (mysql only)
361 384
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column_info['unsigned']) ? 'unsigned ' : '';
362 385
 
363
-	if ($size !== null)
364
-		$type = $type . '(' . $size . ')';
386
+	if ($size !== null) {
387
+			$type = $type . '(' . $size . ')';
388
+	}
365 389
 
366 390
 	$smcFunc['db_query']('', '
367 391
 		ALTER TABLE ' . $table_name . '
@@ -391,21 +415,23 @@  discard block
 block discarded – undo
391 415
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
392 416
 
393 417
 	// No columns = no index.
394
-	if (empty($index_info['columns']))
395
-		return false;
418
+	if (empty($index_info['columns'])) {
419
+			return false;
420
+	}
396 421
 	$columns = implode(',', $index_info['columns']);
397 422
 
398 423
 	// No name - make it up!
399 424
 	if (empty($index_info['name']))
400 425
 	{
401 426
 		// No need for primary.
402
-		if (isset($index_info['type']) && $index_info['type'] == 'primary')
403
-			$index_info['name'] = '';
404
-		else
405
-			$index_info['name'] = implode('_', $index_info['columns']);
427
+		if (isset($index_info['type']) && $index_info['type'] == 'primary') {
428
+					$index_info['name'] = '';
429
+		} else {
430
+					$index_info['name'] = implode('_', $index_info['columns']);
431
+		}
432
+	} else {
433
+			$index_info['name'] = $index_info['name'];
406 434
 	}
407
-	else
408
-		$index_info['name'] = $index_info['name'];
409 435
 
410 436
 	// Log that we are going to want to remove this!
411 437
 	$db_package_log[] = array('remove_index', $table_name, $index_info['name']);
@@ -418,10 +444,11 @@  discard block
 block discarded – undo
418 444
 		if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary'))
419 445
 		{
420 446
 			// If we want to overwrite simply remove the current one then continue.
421
-			if ($if_exists != 'update' || $index['type'] == 'primary')
422
-				return false;
423
-			else
424
-				$smcFunc['db_remove_index']($table_name, $index_info['name']);
447
+			if ($if_exists != 'update' || $index['type'] == 'primary') {
448
+							return false;
449
+			} else {
450
+							$smcFunc['db_remove_index']($table_name, $index_info['name']);
451
+			}
425 452
 		}
426 453
 	}
427 454
 
@@ -435,8 +462,7 @@  discard block
 block discarded – undo
435 462
 				'security_override' => true,
436 463
 			)
437 464
 		);
438
-	}
439
-	else
465
+	} else
440 466
 	{
441 467
 		$smcFunc['db_query']('', '
442 468
 			ALTER TABLE ' . $table_name . '
@@ -520,8 +546,7 @@  discard block
 block discarded – undo
520 546
 		$types = array(
521 547
 			'inet' => 'varbinary',
522 548
 		);
523
-	}
524
-	else
549
+	} else
525 550
 	{
526 551
 		$types = array(
527 552
 			'varbinary' => 'inet',
@@ -535,16 +560,15 @@  discard block
 block discarded – undo
535 560
 		{
536 561
 			$type_size = 16;
537 562
 			$type_name = 'varbinary';
538
-		}
539
-		elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)
563
+		} elseif ($type_name == 'varbinary' && $reverse && $type_size == 16)
540 564
 		{
541 565
 			$type_name = 'inet';
542 566
 			$type_size = null;
567
+		} elseif ($type_name == 'varbinary') {
568
+					$type_name = 'varbinary';
569
+		} else {
570
+					$type_name = $types[$type_name];
543 571
 		}
544
-		elseif ($type_name == 'varbinary')
545
-			$type_name = 'varbinary';
546
-		else
547
-			$type_name = $types[$type_name];
548 572
 	}
549 573
 
550 574
 	return array($type_name, $type_size);
@@ -612,8 +636,7 @@  discard block
 block discarded – undo
612 636
 		if (!$detail)
613 637
 		{
614 638
 			$columns[] = $row['Field'];
615
-		}
616
-		else
639
+		} else
617 640
 		{
618 641
 			// Is there an auto_increment?
619 642
 			$auto = strpos($row['Extra'], 'auto_increment') !== false ? true : false;
@@ -623,10 +646,10 @@  discard block
 block discarded – undo
623 646
 			{
624 647
 				$type = $matches[1];
625 648
 				$size = $matches[2];
626
-				if (!empty($matches[3]) && $matches[3] == 'unsigned')
627
-					$unsigned = true;
628
-			}
629
-			else
649
+				if (!empty($matches[3]) && $matches[3] == 'unsigned') {
650
+									$unsigned = true;
651
+				}
652
+			} else
630 653
 			{
631 654
 				$type = $row['Type'];
632 655
 				$size = null;
@@ -677,19 +700,20 @@  discard block
 block discarded – undo
677 700
 	$indexes = array();
678 701
 	while ($row = $smcFunc['db_fetch_assoc']($result))
679 702
 	{
680
-		if (!$detail)
681
-			$indexes[] = $row['Key_name'];
682
-		else
703
+		if (!$detail) {
704
+					$indexes[] = $row['Key_name'];
705
+		} else
683 706
 		{
684 707
 			// What is the type?
685
-			if ($row['Key_name'] == 'PRIMARY')
686
-				$type = 'primary';
687
-			elseif (empty($row['Non_unique']))
688
-				$type = 'unique';
689
-			elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT')
690
-				$type = 'fulltext';
691
-			else
692
-				$type = 'index';
708
+			if ($row['Key_name'] == 'PRIMARY') {
709
+							$type = 'primary';
710
+			} elseif (empty($row['Non_unique'])) {
711
+							$type = 'unique';
712
+			} elseif (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') {
713
+							$type = 'fulltext';
714
+			} else {
715
+							$type = 'index';
716
+			}
693 717
 
694 718
 			// This is the first column we've seen?
695 719
 			if (empty($indexes[$row['Key_name']]))
@@ -702,10 +726,11 @@  discard block
 block discarded – undo
702 726
 			}
703 727
 
704 728
 			// Is it a partial index?
705
-			if (!empty($row['Sub_part']))
706
-				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')';
707
-			else
708
-				$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
729
+			if (!empty($row['Sub_part'])) {
730
+							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'] . '(' . $row['Sub_part'] . ')';
731
+			} else {
732
+							$indexes[$row['Key_name']]['columns'][] = $row['Column_name'];
733
+			}
709 734
 		}
710 735
 	}
711 736
 	$smcFunc['db_free_result']($result);
@@ -727,11 +752,11 @@  discard block
 block discarded – undo
727 752
 	if (!empty($column['auto']))
728 753
 	{
729 754
 		$default = 'auto_increment';
755
+	} elseif (isset($column['default']) && $column['default'] !== null) {
756
+			$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
757
+	} else {
758
+			$default = '';
730 759
 	}
731
-	elseif (isset($column['default']) && $column['default'] !== null)
732
-		$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
733
-	else
734
-		$default = '';
735 760
 
736 761
 	// Sort out the size... and stuff...
737 762
 	$column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
@@ -740,8 +765,9 @@  discard block
 block discarded – undo
740 765
 	// Allow unsigned integers (mysql only)
741 766
 	$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : '';
742 767
 
743
-	if ($size !== null)
744
-		$type = $type . '(' . $size . ')';
768
+	if ($size !== null) {
769
+			$type = $type . '(' . $size . ')';
770
+	}
745 771
 
746 772
 	// Now just put it together!
747 773
 	return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default;
Please login to merge, or discard this patch.
Sources/Subs-Themes.php 1 patch
Braces   +67 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Gets a single theme's info.
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 	global $smcFunc, $modSettings;
28 29
 
29 30
 	// No data, no fun!
30
-	if (empty($id))
31
-		return false;
31
+	if (empty($id)) {
32
+			return false;
33
+	}
32 34
 
33 35
 	// Make sure $id is an int.
34 36
 	$id = (int) $id;
@@ -171,8 +173,9 @@  discard block
 block discarded – undo
171 173
 	global $sourcedir, $forum_version, $txt, $scripturl, $context;
172 174
 	global $explicit_images;
173 175
 
174
-	if (empty($path))
175
-		return false;
176
+	if (empty($path)) {
177
+			return false;
178
+	}
176 179
 
177 180
 	$xml_data = array();
178 181
 	$explicit_images = false;
@@ -229,9 +232,10 @@  discard block
 block discarded – undo
229 232
 	);
230 233
 
231 234
 	// Assign the values to be stored.
232
-	foreach ($xml_elements as $var => $name)
233
-		if (!empty($theme_info_xml[$name]))
235
+	foreach ($xml_elements as $var => $name) {
236
+			if (!empty($theme_info_xml[$name]))
234 237
 			$xml_data[$var] = $theme_info_xml[$name];
238
+	}
235 239
 
236 240
 	// Add the supported versions.
237 241
 	$xml_data['install_for'] = $install_versions;
@@ -243,8 +247,9 @@  discard block
 block discarded – undo
243 247
 		$explicit_images = true;
244 248
 	}
245 249
 
246
-	if (!empty($theme_info_xml['extra']))
247
-		$xml_data += smf_json_decode($theme_info_xml['extra'], true);
250
+	if (!empty($theme_info_xml['extra'])) {
251
+			$xml_data += smf_json_decode($theme_info_xml['extra'], true);
252
+	}
248 253
 
249 254
 	return $xml_data;
250 255
 }
@@ -262,12 +267,14 @@  discard block
 block discarded – undo
262 267
 	global $settings, $explicit_images;
263 268
 
264 269
 	// External use? no problem!
265
-	if ($to_install)
266
-		$context['to_install'] = $to_install;
270
+	if ($to_install) {
271
+			$context['to_install'] = $to_install;
272
+	}
267 273
 
268 274
 	// One last check.
269
-	if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes')
270
-		fatal_lang_error('theme_install_invalid_dir', false);
275
+	if (empty($context['to_install']['theme_dir']) || basename($context['to_install']['theme_dir']) == 'Themes') {
276
+			fatal_lang_error('theme_install_invalid_dir', false);
277
+	}
271 278
 
272 279
 	// OK, is this a newer version of an already installed theme?
273 280
 	if (!empty($context['to_install']['version']))
@@ -292,8 +299,8 @@  discard block
 block discarded – undo
292 299
 		$smcFunc['db_free_result']($request);
293 300
 
294 301
 		// Got something, lets figure it out what to do next.
295
-		if (!empty($to_update) && !empty($to_update['version']))
296
-			switch (compareVersions($context['to_install']['version'], $to_update['version']))
302
+		if (!empty($to_update) && !empty($to_update['version'])) {
303
+					switch (compareVersions($context['to_install']['version'], $to_update['version']))
297 304
 			{
298 305
 				case 1: // Got a newer version, update the old entry.
299 306
 					$smcFunc['db_query']('', '
@@ -307,6 +314,7 @@  discard block
 block discarded – undo
307 314
 							'id_theme' => $to_update['id_theme'],
308 315
 						)
309 316
 					);
317
+		}
310 318
 
311 319
 					// Done with the update, tell the user about it.
312 320
 					$context['to_install']['updated'] = true;
@@ -372,13 +380,15 @@  discard block
 block discarded – undo
372 380
 				$context['to_install']['base_theme_url'] = $temp['theme_url'];
373 381
 				$context['to_install']['base_theme_dir'] = $temp['theme_dir'];
374 382
 
375
-				if (empty($explicit_images) && !empty($context['to_install']['base_theme_url']))
376
-					$context['to_install']['theme_url'] = $context['to_install']['base_theme_url'];
383
+				if (empty($explicit_images) && !empty($context['to_install']['base_theme_url'])) {
384
+									$context['to_install']['theme_url'] = $context['to_install']['base_theme_url'];
385
+				}
377 386
 			}
378 387
 
379 388
 			// Nope, sorry, couldn't find any theme already installed.
380
-			else
381
-				fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']);
389
+			else {
390
+							fatal_lang_error('package_get_error_theme_no_based_on_found', false, $context['to_install']['based_on']);
391
+			}
382 392
 		}
383 393
 
384 394
 		unset($context['to_install']['based_on']);
@@ -401,16 +411,18 @@  discard block
 block discarded – undo
401 411
 	call_integration_hook('integrate_theme_install', array(&$context['to_install'], $id_theme));
402 412
 
403 413
 	$inserts = array();
404
-	foreach ($context['to_install'] as $var => $val)
405
-		$inserts[] = array($id_theme, $var, $val);
414
+	foreach ($context['to_install'] as $var => $val) {
415
+			$inserts[] = array($id_theme, $var, $val);
416
+	}
406 417
 
407
-	if (!empty($inserts))
408
-		$smcFunc['db_insert']('insert',
418
+	if (!empty($inserts)) {
419
+			$smcFunc['db_insert']('insert',
409 420
 			'{db_prefix}themes',
410 421
 			array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
411 422
 			$inserts,
412 423
 			array('id_theme', 'variable')
413 424
 		);
425
+	}
414 426
 
415 427
 	// Update the known and enable Theme's settings.
416 428
 	$known = strtr($modSettings['knownThemes'] . ',' . $id_theme, array(',,' => ','));
@@ -429,21 +441,24 @@  discard block
 block discarded – undo
429 441
  */
430 442
 function remove_dir($path)
431 443
 {
432
-	if (empty($path))
433
-		return false;
444
+	if (empty($path)) {
445
+			return false;
446
+	}
434 447
 
435 448
 	if (is_dir($path))
436 449
 	{
437 450
 		$objects = scandir($path);
438 451
 
439
-		foreach ($objects as $object)
440
-			if ($object != '.' && $object != '..')
452
+		foreach ($objects as $object) {
453
+					if ($object != '.' && $object != '..')
441 454
 			{
442 455
 				if (filetype($path . '/' . $object) == 'dir')
443 456
 					remove_dir($path . '/' . $object);
457
+		}
444 458
 
445
-				else
446
-					unlink($path . '/' . $object);
459
+				else {
460
+									unlink($path . '/' . $object);
461
+				}
447 462
 			}
448 463
 	}
449 464
 
@@ -462,8 +477,9 @@  discard block
 block discarded – undo
462 477
 	global $smcFunc, $modSettings;
463 478
 
464 479
 	// Can't delete the default theme, sorry!
465
-	if (empty($themeID) || $themeID == 1)
466
-		return false;
480
+	if (empty($themeID) || $themeID == 1) {
481
+			return false;
482
+	}
467 483
 
468 484
 	$known = explode(',', $modSettings['knownThemes']);
469 485
 	$enable = explode(',', $modSettings['enableThemes']);
@@ -513,8 +529,9 @@  discard block
 block discarded – undo
513 529
 	updateSettings(array('enableThemes' => $enable, 'knownThemes' => $known));
514 530
 
515 531
 	// Fix it if the theme was the overall default theme.
516
-	if ($modSettings['theme_guests'] == $themeID)
517
-		updateSettings(array('theme_guests' => '1'));
532
+	if ($modSettings['theme_guests'] == $themeID) {
533
+			updateSettings(array('theme_guests' => '1'));
534
+	}
518 535
 
519 536
 	return true;
520 537
 }
@@ -531,13 +548,15 @@  discard block
 block discarded – undo
531 548
 	global $scripturl, $txt, $context;
532 549
 
533 550
 	// Is it even a directory?
534
-	if (!is_dir($path))
535
-		fatal_lang_error('error_invalid_dir', 'critical');
551
+	if (!is_dir($path)) {
552
+			fatal_lang_error('error_invalid_dir', 'critical');
553
+	}
536 554
 
537 555
 	$dir = dir($path);
538 556
 	$entries = array();
539
-	while ($entry = $dir->read())
540
-		$entries[] = $entry;
557
+	while ($entry = $dir->read()) {
558
+			$entries[] = $entry;
559
+	}
541 560
 	$dir->close();
542 561
 
543 562
 	natcasesort($entries);
@@ -548,11 +567,12 @@  discard block
 block discarded – undo
548 567
 	foreach ($entries as $entry)
549 568
 	{
550 569
 		// Skip all dot files, including .htaccess.
551
-		if (substr($entry, 0, 1) == '.' || $entry == 'CVS')
552
-			continue;
570
+		if (substr($entry, 0, 1) == '.' || $entry == 'CVS') {
571
+					continue;
572
+		}
553 573
 
554
-		if (is_dir($path . '/' . $entry))
555
-			$listing1[] = array(
574
+		if (is_dir($path . '/' . $entry)) {
575
+					$listing1[] = array(
556 576
 				'filename' => $entry,
557 577
 				'is_writable' => is_writable($path . '/' . $entry),
558 578
 				'is_directory' => true,
@@ -562,13 +582,14 @@  discard block
 block discarded – undo
562 582
 				'href' => $scripturl . '?action=admin;area=theme;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=edit;directory=' . $relative . $entry,
563 583
 				'size' => '',
564 584
 			);
565
-		else
585
+		} else
566 586
 		{
567 587
 			$size = filesize($path . '/' . $entry);
568
-			if ($size > 2048 || $size == 1024)
569
-				$size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes'];
570
-			else
571
-				$size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes'];
588
+			if ($size > 2048 || $size == 1024) {
589
+							$size = comma_format($size / 1024) . ' ' . $txt['themeadmin_edit_kilobytes'];
590
+			} else {
591
+							$size = comma_format($size) . ' ' . $txt['themeadmin_edit_bytes'];
592
+			}
572 593
 
573 594
 			$listing2[] = array(
574 595
 				'filename' => $entry,
Please login to merge, or discard this patch.
Sources/ReportedContent.php 1 patch
Braces   +61 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Sets and call a function based on the given subaction. Acts as a dispatcher function.
@@ -54,8 +55,9 @@  discard block
 block discarded – undo
54 55
 	);
55 56
 
56 57
 	// This comes under the umbrella of moderating posts.
57
-	if ($context['report_type'] == 'members' || $user_info['mod_cache']['bq'] == '0=1')
58
-		isAllowedTo('moderate_forum');
58
+	if ($context['report_type'] == 'members' || $user_info['mod_cache']['bq'] == '0=1') {
59
+			isAllowedTo('moderate_forum');
60
+	}
59 61
 
60 62
 	$subActions = array(
61 63
 		'show' => 'ShowReports',
@@ -70,11 +72,11 @@  discard block
 block discarded – undo
70 72
 	call_integration_hook('integrate_reported_' . $context['report_type'], array(&$subActions));
71 73
 
72 74
 	// By default we call the open sub-action.
73
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
74
-		$context['sub_action'] = $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_REQUEST['sa']), ENT_QUOTES);
75
-
76
-	else
77
-		$context['sub_action'] = 'show';
75
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
76
+			$context['sub_action'] = $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_REQUEST['sa']), ENT_QUOTES);
77
+	} else {
78
+			$context['sub_action'] = 'show';
79
+	}
78 80
 
79 81
 	// Hi Ho Silver Away!
80 82
 	call_helper($subActions[$context['sub_action']]);
@@ -116,11 +118,13 @@  discard block
 block discarded – undo
116 118
 
117 119
 		// All the ones to update...
118 120
 		$toClose = array();
119
-		foreach ($_POST['close'] as $rid)
120
-			$toClose[] = (int) $rid;
121
+		foreach ($_POST['close'] as $rid) {
122
+					$toClose[] = (int) $rid;
123
+		}
121 124
 
122
-		if (!empty($toClose))
123
-			updateReport('closed', 1, $toClose);
125
+		if (!empty($toClose)) {
126
+					updateReport('closed', 1, $toClose);
127
+		}
124 128
 
125 129
 		// Set the confirmation message.
126 130
 		$_SESSION['rc_confirmation'] = 'close_all';
@@ -178,8 +182,9 @@  discard block
 block discarded – undo
178 182
 	$reportComments = array();
179 183
 
180 184
 	// Have to at least give us something to work with.
181
-	if (empty($_REQUEST['rid']))
182
-		fatal_lang_error('mc_reportedp_none_found');
185
+	if (empty($_REQUEST['rid'])) {
186
+			fatal_lang_error('mc_reportedp_none_found');
187
+	}
183 188
 
184 189
 	// Integers only please
185 190
 	$report_id = (int) $_REQUEST['rid'];
@@ -187,8 +192,9 @@  discard block
 block discarded – undo
187 192
 	// Get the report details.
188 193
 	$report = getReportDetails($report_id);
189 194
 
190
-	if (!$report)
191
-		fatal_lang_error('mc_no_modreport_found');
195
+	if (!$report) {
196
+			fatal_lang_error('mc_no_modreport_found');
197
+	}
192 198
 
193 199
 	// Build the report data - basic details first, then extra stuff based on the type
194 200
 	$context['report'] = array(
@@ -214,8 +220,7 @@  discard block
 block discarded – undo
214 220
 				'href' => $scripturl . '?action=profile;u=' . $report['id_user'],
215 221
 			),
216 222
 		);
217
-	}
218
-	else
223
+	} else
219 224
 	{
220 225
 		$extraDetails = array(
221 226
 			'topic_id' => $report['id_topic'],
@@ -238,8 +243,9 @@  discard block
 block discarded – undo
238 243
 
239 244
 	$reportComments = getReportComments($report_id);
240 245
 
241
-	if (!empty($reportComments))
242
-		$context['report'] = array_merge($context['report'], $reportComments);
246
+	if (!empty($reportComments)) {
247
+			$context['report'] = array_merge($context['report'], $reportComments);
248
+	}
243 249
 
244 250
 	// What have the other moderators done to this message?
245 251
 	require_once($sourcedir . '/Modlog.php');
@@ -260,8 +266,7 @@  discard block
 block discarded – undo
260 266
 			1,
261 267
 			true,
262 268
 		);
263
-	}
264
-	else
269
+	} else
265 270
 	{
266 271
 		$params = array(
267 272
 			'lm.id_topic = {int:id_topic}
@@ -361,16 +366,16 @@  discard block
 block discarded – undo
361 366
 	createList($listOptions);
362 367
 
363 368
 	// Make sure to get the correct tab selected.
364
-	if ($context['report']['closed'])
365
-		$context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
369
+	if ($context['report']['closed']) {
370
+			$context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
371
+	}
366 372
 
367 373
 	// Finally we are done :P
368 374
 	if ($context['report_type'] == 'members')
369 375
 	{
370 376
 		$context['page_title'] = sprintf($txt['mc_viewmemberreport'], $context['report']['user']['name']);
371 377
 		$context['sub_template'] = 'viewmemberreport';
372
-	}
373
-	else
378
+	} else
374 379
 	{
375 380
 		$context['page_title'] = sprintf($txt['mc_viewmodreport'], $context['report']['subject'], $context['report']['author']['name']);
376 381
 		$context['sub_template'] = 'viewmodreport';
@@ -395,8 +400,9 @@  discard block
 block discarded – undo
395 400
 	$comment = array();
396 401
 
397 402
 	// The report ID is a must.
398
-	if (empty($_REQUEST['rid']))
399
-		fatal_lang_error('mc_reportedp_none_found');
403
+	if (empty($_REQUEST['rid'])) {
404
+			fatal_lang_error('mc_reportedp_none_found');
405
+	}
400 406
 
401 407
 	// Integers only please.
402 408
 	$report_id = (int) $_REQUEST['rid'];
@@ -421,8 +427,9 @@  discard block
 block discarded – undo
421 427
 		checkSession('get');
422 428
 		validateToken('mod-reportC-delete', 'get');
423 429
 
424
-		if (empty($_REQUEST['mid']))
425
-			fatal_lang_error('mc_reportedp_comment_none_found');
430
+		if (empty($_REQUEST['mid'])) {
431
+					fatal_lang_error('mc_reportedp_comment_none_found');
432
+		}
426 433
 
427 434
 		$comment_id = (int) $_REQUEST['mid'];
428 435
 
@@ -430,15 +437,17 @@  discard block
 block discarded – undo
430 437
 		$comment = getCommentModDetails($comment_id);
431 438
 
432 439
 		// Perhaps somebody else already deleted this fine gem...
433
-		if (empty($comment))
434
-			fatal_lang_error('report_action_message_delete_issue');
440
+		if (empty($comment)) {
441
+					fatal_lang_error('report_action_message_delete_issue');
442
+		}
435 443
 
436 444
 		// Can you actually do this?
437 445
 		$comment_owner = $user_info['id'] == $comment['id_member'];
438 446
 
439 447
 		// Nope! sorry.
440
-		if (!allowedTo('admin_forum') && !$comment_owner)
441
-			fatal_lang_error('report_action_message_delete_cannot');
448
+		if (!allowedTo('admin_forum') && !$comment_owner) {
449
+					fatal_lang_error('report_action_message_delete_cannot');
450
+		}
442 451
 
443 452
 		// All good!
444 453
 		deleteModComment($comment_id);
@@ -465,11 +474,13 @@  discard block
 block discarded – undo
465 474
 	checkSession(isset($_REQUEST['save']) ? 'post' : 'get');
466 475
 
467 476
 	// The report ID is a must.
468
-	if (empty($_REQUEST['rid']))
469
-		fatal_lang_error('mc_reportedp_none_found');
477
+	if (empty($_REQUEST['rid'])) {
478
+			fatal_lang_error('mc_reportedp_none_found');
479
+	}
470 480
 
471
-	if (empty($_REQUEST['mid']))
472
-		fatal_lang_error('mc_reportedp_comment_none_found');
481
+	if (empty($_REQUEST['mid'])) {
482
+			fatal_lang_error('mc_reportedp_comment_none_found');
483
+	}
473 484
 
474 485
 	// Integers only please.
475 486
 	$context['report_id'] = (int) $_REQUEST['rid'];
@@ -477,8 +488,9 @@  discard block
 block discarded – undo
477 488
 
478 489
 	$context['comment'] = getCommentModDetails($context['comment_id']);
479 490
 
480
-	if (empty($context['comment']))
481
-		fatal_lang_error('mc_reportedp_comment_none_found');
491
+	if (empty($context['comment'])) {
492
+			fatal_lang_error('mc_reportedp_comment_none_found');
493
+	}
482 494
 
483 495
 	// Set up the comforting bits...
484 496
 	$context['page_title'] = $txt['mc_reported_posts'];
@@ -489,15 +501,17 @@  discard block
 block discarded – undo
489 501
 		validateToken('mod-reportC-edit');
490 502
 
491 503
 		// Make sure there is some data to edit on the DB.
492
-		if (empty($context['comment']))
493
-			fatal_lang_error('report_action_message_edit_issue');
504
+		if (empty($context['comment'])) {
505
+					fatal_lang_error('report_action_message_edit_issue');
506
+		}
494 507
 
495 508
 		// Still there, good, now lets see if you can actually edit it...
496 509
 		$comment_owner = $user_info['id'] == $context['comment']['id_member'];
497 510
 
498 511
 		// So, you aren't neither an admin or the comment owner huh? that's too bad.
499
-		if (!allowedTo('admin_forum') && !$comment_owner)
500
-			fatal_lang_error('report_action_message_edit_cannot');
512
+		if (!allowedTo('admin_forum') && !$comment_owner) {
513
+					fatal_lang_error('report_action_message_edit_cannot');
514
+		}
501 515
 
502 516
 		// All good!
503 517
 		$edited_comment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment']));
@@ -523,8 +537,9 @@  discard block
 block discarded – undo
523 537
 	checkSession('get');
524 538
 
525 539
 	// We need to do something!
526
-	if (empty($_GET['rid']) && (!isset($_GET['ignore']) || !isset($_GET['closed'])))
527
-		fatal_lang_error('mc_reportedp_none_found');
540
+	if (empty($_GET['rid']) && (!isset($_GET['ignore']) || !isset($_GET['closed']))) {
541
+			fatal_lang_error('mc_reportedp_none_found');
542
+	}
528 543
 
529 544
 	// What are we gonna do?
530 545
 	$action = isset($_GET['ignore']) ? 'ignore' : 'closed';
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +798 added lines, -602 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * 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,27 +48,35 @@  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
-		if (!is_array($modSettings['attachmentUploadDir']))
66
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
73
+		if (!is_array($modSettings['attachmentUploadDir'])) {
74
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
75
+		}
67 76
 
68
-		if (!empty($cache_enable))
69
-			cache_put_data('modSettings', $modSettings, 90);
77
+		if (!empty($cache_enable)) {
78
+					cache_put_data('modSettings', $modSettings, 90);
79
+		}
70 80
 	}
71 81
 
72 82
 	$modSettings['cache_enable'] = $cache_enable;
@@ -86,8 +96,9 @@  discard block
 block discarded – undo
86 96
 		};
87 97
 	$fix_utf8mb4 = function($string) use ($utf8)
88 98
 	{
89
-		if (!$utf8)
90
-			return $string;
99
+		if (!$utf8) {
100
+					return $string;
101
+		}
91 102
 
92 103
 		$i = 0;
93 104
 		$len = strlen($string);
@@ -99,18 +110,15 @@  discard block
 block discarded – undo
99 110
 			{
100 111
 				$new_string .= $string[$i];
101 112
 				$i++;
102
-			}
103
-			elseif ($ord < 224)
113
+			} elseif ($ord < 224)
104 114
 			{
105 115
 				$new_string .= $string[$i] . $string[$i + 1];
106 116
 				$i += 2;
107
-			}
108
-			elseif ($ord < 240)
117
+			} elseif ($ord < 240)
109 118
 			{
110 119
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
111 120
 				$i += 3;
112
-			}
113
-			elseif ($ord < 248)
121
+			} elseif ($ord < 248)
114 122
 			{
115 123
 				// Magic happens.
116 124
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -154,8 +162,7 @@  discard block
 block discarded – undo
154 162
 			{
155 163
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
156 164
 				return is_int($result) ? $result + $offset : false;
157
-			}
158
-			else
165
+			} else
159 166
 			{
160 167
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
161 168
 				$needle_size = count($needle_arr);
@@ -164,8 +171,9 @@  discard block
 block discarded – undo
164 171
 				while ((int) $result === $result)
165 172
 				{
166 173
 					$offset += $result;
167
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
168
-						return $offset;
174
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
175
+											return $offset;
176
+					}
169 177
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
170 178
 				}
171 179
 				return false;
@@ -203,8 +211,9 @@  discard block
 block discarded – undo
203 211
 			$string = $ent_check($string);
204 212
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
205 213
 			$string = $matches[0];
206
-			while (strlen($string) > $length)
207
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
214
+			while (strlen($string) > $length) {
215
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
216
+			}
208 217
 			return $string;
209 218
 		},
210 219
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -214,23 +223,25 @@  discard block
 block discarded – undo
214 223
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
215 224
 		{
216 225
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
217
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
218
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
226
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
227
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
228
+			}
219 229
 			return implode('', $words);
220 230
 		} : 'ucwords',
221 231
 	);
222 232
 
223 233
 	// Setting the timezone is a requirement for some functions.
224
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
225
-		date_default_timezone_set($modSettings['default_timezone']);
226
-	else
234
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
235
+			date_default_timezone_set($modSettings['default_timezone']);
236
+	} else
227 237
 	{
228 238
 		// Get PHP's default timezone, if set
229 239
 		$ini_tz = ini_get('date.timezone');
230
-		if (!empty($ini_tz))
231
-			$modSettings['default_timezone'] = $ini_tz;
232
-		else
233
-			$modSettings['default_timezone'] = '';
240
+		if (!empty($ini_tz)) {
241
+					$modSettings['default_timezone'] = $ini_tz;
242
+		} else {
243
+					$modSettings['default_timezone'] = '';
244
+		}
234 245
 
235 246
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
236 247
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -248,22 +259,26 @@  discard block
 block discarded – undo
248 259
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
249 260
 		{
250 261
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
251
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
252
-				$modSettings['load_average'] = (float) $matches[1];
253
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
254
-				$modSettings['load_average'] = (float) $matches[1];
255
-			else
256
-				unset($modSettings['load_average']);
262
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
263
+							$modSettings['load_average'] = (float) $matches[1];
264
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
265
+							$modSettings['load_average'] = (float) $matches[1];
266
+			} else {
267
+							unset($modSettings['load_average']);
268
+			}
257 269
 
258
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
259
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
270
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
271
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
272
+			}
260 273
 		}
261 274
 
262
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
263
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
275
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
276
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
277
+		}
264 278
 
265
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
266
-			display_loadavg_error();
279
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
280
+					display_loadavg_error();
281
+		}
267 282
 	}
268 283
 
269 284
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -284,8 +299,9 @@  discard block
 block discarded – undo
284 299
 	if (defined('SMF_INTEGRATION_SETTINGS'))
285 300
 	{
286 301
 		$integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true);
287
-		foreach ($integration_settings as $hook => $function)
288
-			add_integration_function($hook, $function, '', false);
302
+		foreach ($integration_settings as $hook => $function) {
303
+					add_integration_function($hook, $function, '', false);
304
+		}
289 305
 	}
290 306
 
291 307
 	// Any files to pre include?
@@ -295,8 +311,9 @@  discard block
 block discarded – undo
295 311
 		foreach ($pre_includes as $include)
296 312
 		{
297 313
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
298
-			if (file_exists($include))
299
-				require_once($include);
314
+			if (file_exists($include)) {
315
+							require_once($include);
316
+			}
300 317
 		}
301 318
 	}
302 319
 
@@ -400,27 +417,28 @@  discard block
 block discarded – undo
400 417
 				break;
401 418
 			}
402 419
 		}
420
+	} else {
421
+			$id_member = 0;
403 422
 	}
404
-	else
405
-		$id_member = 0;
406 423
 
407 424
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
408 425
 	{
409 426
 		$cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false);
410 427
 
411
-		if (empty($cookie_data))
412
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
428
+		if (empty($cookie_data)) {
429
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
430
+		}
413 431
 
414 432
 		list ($id_member, $password) = $cookie_data;
415 433
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
434
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 435
 	{
419 436
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 437
 		$cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]);
421 438
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
439
+		if (empty($cookie_data)) {
440
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
441
+		}
424 442
 
425 443
 		list ($id_member, $password, $login_span) = $cookie_data;
426 444
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +463,34 @@  discard block
 block discarded – undo
445 463
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 464
 			$smcFunc['db_free_result']($request);
447 465
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
449
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
466
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
467
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
468
+			}
450 469
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
470
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
471
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
472
+			}
453 473
 		}
454 474
 
455 475
 		// Did we find 'im?  If not, junk it.
456 476
 		if (!empty($user_settings))
457 477
 		{
458 478
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
479
+			if (!empty($already_verified) && $already_verified === true) {
480
+							$check = true;
481
+			}
461 482
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
483
+			elseif (strlen($password) == 128) {
484
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
485
+			} else {
486
+							$check = false;
487
+			}
466 488
 
467 489
 			// Wrong password or not activated - either way, you're going nowhere.
468 490
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
491
+		} else {
492
+					$id_member = 0;
469 493
 		}
470
-		else
471
-			$id_member = 0;
472 494
 
473 495
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 496
 		if (!$id_member)
@@ -490,13 +512,15 @@  discard block
 block discarded – undo
490 512
 				{
491 513
 					$tfa_data = smf_json_decode($_COOKIE[$tfacookie]);
492 514
 
493
-					if (is_null($tfa_data))
494
-						$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
515
+					if (is_null($tfa_data)) {
516
+											$tfa_data = safe_unserialize($_COOKIE[$tfacookie]);
517
+					}
495 518
 
496 519
 					list ($tfamember, $tfasecret) = $tfa_data;
497 520
 
498
-					if ((int) $tfamember != $id_member)
499
-						$tfasecret = null;
521
+					if ((int) $tfamember != $id_member) {
522
+											$tfasecret = null;
523
+					}
500 524
 				}
501 525
 
502 526
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -516,10 +540,12 @@  discard block
 block discarded – undo
516 540
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
517 541
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
518 542
 		{
519
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
543
+			if ($modSettings['tfa_mode'] == 2) {
544
+				//only do this if we are just forcing SOME membergroups
520 545
 			{
521 546
 				//Build an array of ALL user membergroups.
522 547
 				$full_groups = array($user_settings['id_group']);
548
+			}
523 549
 				if (!empty($user_settings['additional_groups']))
524 550
 				{
525 551
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -539,15 +565,17 @@  discard block
 block discarded – undo
539 565
 				);
540 566
 				$row = $smcFunc['db_fetch_assoc']($request);
541 567
 				$smcFunc['db_free_result']($request);
568
+			} else {
569
+							$row['total'] = 1;
542 570
 			}
543
-			else
544
-				$row['total'] = 1; //simplifies logics in the next "if"
571
+			//simplifies logics in the next "if"
545 572
 
546 573
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
547 574
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
548 575
 
549
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
550
-				redirectexit('action=profile;area=tfasetup;forced');
576
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
577
+							redirectexit('action=profile;area=tfasetup;forced');
578
+			}
551 579
 		}
552 580
 	}
553 581
 
@@ -584,33 +612,37 @@  discard block
 block discarded – undo
584 612
 				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']));
585 613
 				$user_settings['last_login'] = time();
586 614
 
587
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
588
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
615
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
616
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
617
+				}
589 618
 
590
-				if (!empty($modSettings['cache_enable']))
591
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
619
+				if (!empty($modSettings['cache_enable'])) {
620
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
621
+				}
592 622
 			}
623
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
624
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
593 625
 		}
594
-		elseif (empty($_SESSION['id_msg_last_visit']))
595
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
596 626
 
597 627
 		$username = $user_settings['member_name'];
598 628
 
599
-		if (empty($user_settings['additional_groups']))
600
-			$user_info = array(
629
+		if (empty($user_settings['additional_groups'])) {
630
+					$user_info = array(
601 631
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
602 632
 			);
603
-		else
604
-			$user_info = array(
633
+		} else {
634
+					$user_info = array(
605 635
 				'groups' => array_merge(
606 636
 					array($user_settings['id_group'], $user_settings['id_post_group']),
607 637
 					explode(',', $user_settings['additional_groups'])
608 638
 				)
609 639
 			);
640
+		}
610 641
 
611 642
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
612
-		foreach ($user_info['groups'] as $k => $v)
613
-			$user_info['groups'][$k] = (int) $v;
643
+		foreach ($user_info['groups'] as $k => $v) {
644
+					$user_info['groups'][$k] = (int) $v;
645
+		}
614 646
 
615 647
 		// This is a logged in user, so definitely not a spider.
616 648
 		$user_info['possibly_robot'] = false;
@@ -624,8 +656,7 @@  discard block
 block discarded – undo
624 656
 			$time_system = new DateTime('now', $tz_system);
625 657
 			$time_user = new DateTime('now', $tz_user);
626 658
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
627
-		}
628
-		else
659
+		} else
629 660
 		{
630 661
 			// !!! Compatibility.
631 662
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -639,16 +670,18 @@  discard block
 block discarded – undo
639 670
 		$user_info = array('groups' => array(-1));
640 671
 		$user_settings = array();
641 672
 
642
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
643
-			$_COOKIE[$cookiename] = '';
673
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
674
+					$_COOKIE[$cookiename] = '';
675
+		}
644 676
 
645 677
 		// Expire the 2FA cookie
646 678
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
647 679
 		{
648 680
 			$tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true);
649 681
 
650
-			if (is_null($tfa_data))
651
-				$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
682
+			if (is_null($tfa_data)) {
683
+							$tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']);
684
+			}
652 685
 
653 686
 			list ($id, $user, $exp, $state, $preserve) = $tfa_data;
654 687
 
@@ -660,19 +693,20 @@  discard block
 block discarded – undo
660 693
 		}
661 694
 
662 695
 		// Create a login token if it doesn't exist yet.
663
-		if (!isset($_SESSION['token']['post-login']))
664
-			createToken('login');
665
-		else
666
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
696
+		if (!isset($_SESSION['token']['post-login'])) {
697
+					createToken('login');
698
+		} else {
699
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
700
+		}
667 701
 
668 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
669 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
670 704
 		{
671 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
672 706
 			$user_info['possibly_robot'] = SpiderCheck();
707
+		} elseif (!empty($modSettings['spider_mode'])) {
708
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
673 709
 		}
674
-		elseif (!empty($modSettings['spider_mode']))
675
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
676 710
 		// If we haven't turned on proper spider hunts then have a guess!
677 711
 		else
678 712
 		{
@@ -720,8 +754,9 @@  discard block
 block discarded – undo
720 754
 	$user_info['groups'] = array_unique($user_info['groups']);
721 755
 
722 756
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
723
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
724
-		unset($user_info['ignoreboards'][$tmp]);
757
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
758
+			unset($user_info['ignoreboards'][$tmp]);
759
+	}
725 760
 
726 761
 	// Allow the user to change their language.
727 762
 	if (!empty($modSettings['userLanguage']))
@@ -734,31 +769,36 @@  discard block
 block discarded – undo
734 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
735 770
 
736 771
 			// Make it permanent for members.
737
-			if (!empty($user_info['id']))
738
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
739
-			else
740
-				$_SESSION['language'] = $user_info['language'];
772
+			if (!empty($user_info['id'])) {
773
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
774
+			} else {
775
+							$_SESSION['language'] = $user_info['language'];
776
+			}
777
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
778
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
741 779
 		}
742
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
743
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
744 780
 	}
745 781
 
746 782
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
747
-	if ($user_info['is_admin'])
748
-		$user_info['query_see_board'] = '1=1';
783
+	if ($user_info['is_admin']) {
784
+			$user_info['query_see_board'] = '1=1';
785
+	}
749 786
 	// Otherwise just the groups in $user_info['groups'].
750
-	else
751
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
787
+	else {
788
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
789
+	}
752 790
 
753 791
 	// Build the list of boards they WANT to see.
754 792
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
755 793
 
756 794
 	// If they aren't ignoring any boards then they want to see all the boards they can see
757
-	if (empty($user_info['ignoreboards']))
758
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
795
+	if (empty($user_info['ignoreboards'])) {
796
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
797
+	}
759 798
 	// Ok I guess they don't want to see all the boards
760
-	else
761
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
799
+	else {
800
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
801
+	}
762 802
 
763 803
 	call_integration_hook('integrate_user_info');
764 804
 }
@@ -816,9 +856,9 @@  discard block
 block discarded – undo
816 856
 		}
817 857
 
818 858
 		// Remember redirection is the key to avoiding fallout from your bosses.
819
-		if (!empty($topic))
820
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
821
-		else
859
+		if (!empty($topic)) {
860
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
861
+		} else
822 862
 		{
823 863
 			loadPermissions();
824 864
 			loadTheme();
@@ -836,10 +876,11 @@  discard block
 block discarded – undo
836 876
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
837 877
 	{
838 878
 		// @todo SLOW?
839
-		if (!empty($topic))
840
-			$temp = cache_get_data('topic_board-' . $topic, 120);
841
-		else
842
-			$temp = cache_get_data('board-' . $board, 120);
879
+		if (!empty($topic)) {
880
+					$temp = cache_get_data('topic_board-' . $topic, 120);
881
+		} else {
882
+					$temp = cache_get_data('board-' . $board, 120);
883
+		}
843 884
 
844 885
 		if (!empty($temp))
845 886
 		{
@@ -877,8 +918,9 @@  discard block
 block discarded – undo
877 918
 			$row = $smcFunc['db_fetch_assoc']($request);
878 919
 
879 920
 			// Set the current board.
880
-			if (!empty($row['id_board']))
881
-				$board = $row['id_board'];
921
+			if (!empty($row['id_board'])) {
922
+							$board = $row['id_board'];
923
+			}
882 924
 
883 925
 			// Basic operating information. (globals... :/)
884 926
 			$board_info = array(
@@ -914,21 +956,23 @@  discard block
 block discarded – undo
914 956
 
915 957
 			do
916 958
 			{
917
-				if (!empty($row['id_moderator']))
918
-					$board_info['moderators'][$row['id_moderator']] = array(
959
+				if (!empty($row['id_moderator'])) {
960
+									$board_info['moderators'][$row['id_moderator']] = array(
919 961
 						'id' => $row['id_moderator'],
920 962
 						'name' => $row['real_name'],
921 963
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
922 964
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
923 965
 					);
966
+				}
924 967
 
925
-				if (!empty($row['id_moderator_group']))
926
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
968
+				if (!empty($row['id_moderator_group'])) {
969
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
927 970
 						'id' => $row['id_moderator_group'],
928 971
 						'name' => $row['group_name'],
929 972
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
930 973
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
931 974
 					);
975
+				}
932 976
 			}
933 977
 			while ($row = $smcFunc['db_fetch_assoc']($request));
934 978
 
@@ -960,12 +1004,12 @@  discard block
 block discarded – undo
960 1004
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
961 1005
 			{
962 1006
 				// @todo SLOW?
963
-				if (!empty($topic))
964
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1007
+				if (!empty($topic)) {
1008
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1009
+				}
965 1010
 				cache_put_data('board-' . $board, $board_info, 120);
966 1011
 			}
967
-		}
968
-		else
1012
+		} else
969 1013
 		{
970 1014
 			// Otherwise the topic is invalid, there are no moderators, etc.
971 1015
 			$board_info = array(
@@ -979,8 +1023,9 @@  discard block
 block discarded – undo
979 1023
 		$smcFunc['db_free_result']($request);
980 1024
 	}
981 1025
 
982
-	if (!empty($topic))
983
-		$_GET['board'] = (int) $board;
1026
+	if (!empty($topic)) {
1027
+			$_GET['board'] = (int) $board;
1028
+	}
984 1029
 
985 1030
 	if (!empty($board))
986 1031
 	{
@@ -990,10 +1035,12 @@  discard block
 block discarded – undo
990 1035
 		// Now check if the user is a moderator.
991 1036
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
992 1037
 
993
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
995
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
996
-			$board_info['error'] = 'access';
1038
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1039
+					$board_info['error'] = 'access';
1040
+		}
1041
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1042
+					$board_info['error'] = 'access';
1043
+		}
997 1044
 
998 1045
 		// Build up the linktree.
999 1046
 		$context['linktree'] = array_merge(
@@ -1016,8 +1063,9 @@  discard block
 block discarded – undo
1016 1063
 	$context['current_board'] = $board;
1017 1064
 
1018 1065
 	// No posting in redirection boards!
1019
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1020
-		$board_info['error'] == 'post_in_redirect';
1066
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1067
+			$board_info['error'] == 'post_in_redirect';
1068
+	}
1021 1069
 
1022 1070
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1023 1071
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1043,24 +1091,23 @@  discard block
 block discarded – undo
1043 1091
 			ob_end_clean();
1044 1092
 			header('HTTP/1.1 403 Forbidden');
1045 1093
 			die;
1046
-		}
1047
-		elseif ($board_info['error'] == 'post_in_redirect')
1094
+		} elseif ($board_info['error'] == 'post_in_redirect')
1048 1095
 		{
1049 1096
 			// Slightly different error message here...
1050 1097
 			fatal_lang_error('cannot_post_redirect', false);
1051
-		}
1052
-		elseif ($user_info['is_guest'])
1098
+		} elseif ($user_info['is_guest'])
1053 1099
 		{
1054 1100
 			loadLanguage('Errors');
1055 1101
 			is_not_guest($txt['topic_gone']);
1102
+		} else {
1103
+					fatal_lang_error('topic_gone', false);
1056 1104
 		}
1057
-		else
1058
-			fatal_lang_error('topic_gone', false);
1059 1105
 	}
1060 1106
 
1061
-	if ($user_info['is_mod'])
1062
-		$user_info['groups'][] = 3;
1063
-}
1107
+	if ($user_info['is_mod']) {
1108
+			$user_info['groups'][] = 3;
1109
+	}
1110
+	}
1064 1111
 
1065 1112
 /**
1066 1113
  * Load this user's permissions.
@@ -1081,8 +1128,9 @@  discard block
 block discarded – undo
1081 1128
 		asort($cache_groups);
1082 1129
 		$cache_groups = implode(',', $cache_groups);
1083 1130
 		// If it's a spider then cache it different.
1084
-		if ($user_info['possibly_robot'])
1085
-			$cache_groups .= '-spider';
1131
+		if ($user_info['possibly_robot']) {
1132
+					$cache_groups .= '-spider';
1133
+		}
1086 1134
 
1087 1135
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1088 1136
 		{
@@ -1090,9 +1138,9 @@  discard block
 block discarded – undo
1090 1138
 			banPermissions();
1091 1139
 
1092 1140
 			return;
1141
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1142
+					list ($user_info['permissions'], $removals) = $temp;
1093 1143
 		}
1094
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1095
-			list ($user_info['permissions'], $removals) = $temp;
1096 1144
 	}
1097 1145
 
1098 1146
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1114,23 +1162,26 @@  discard block
 block discarded – undo
1114 1162
 		$removals = array();
1115 1163
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1116 1164
 		{
1117
-			if (empty($row['add_deny']))
1118
-				$removals[] = $row['permission'];
1119
-			else
1120
-				$user_info['permissions'][] = $row['permission'];
1165
+			if (empty($row['add_deny'])) {
1166
+							$removals[] = $row['permission'];
1167
+			} else {
1168
+							$user_info['permissions'][] = $row['permission'];
1169
+			}
1121 1170
 		}
1122 1171
 		$smcFunc['db_free_result']($request);
1123 1172
 
1124
-		if (isset($cache_groups))
1125
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1173
+		if (isset($cache_groups)) {
1174
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1175
+		}
1126 1176
 	}
1127 1177
 
1128 1178
 	// Get the board permissions.
1129 1179
 	if (!empty($board))
1130 1180
 	{
1131 1181
 		// Make sure the board (if any) has been loaded by loadBoard().
1132
-		if (!isset($board_info['profile']))
1133
-			fatal_lang_error('no_board');
1182
+		if (!isset($board_info['profile'])) {
1183
+					fatal_lang_error('no_board');
1184
+		}
1134 1185
 
1135 1186
 		$request = $smcFunc['db_query']('', '
1136 1187
 			SELECT permission, add_deny
@@ -1146,20 +1197,23 @@  discard block
 block discarded – undo
1146 1197
 		);
1147 1198
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1148 1199
 		{
1149
-			if (empty($row['add_deny']))
1150
-				$removals[] = $row['permission'];
1151
-			else
1152
-				$user_info['permissions'][] = $row['permission'];
1200
+			if (empty($row['add_deny'])) {
1201
+							$removals[] = $row['permission'];
1202
+			} else {
1203
+							$user_info['permissions'][] = $row['permission'];
1204
+			}
1153 1205
 		}
1154 1206
 		$smcFunc['db_free_result']($request);
1155 1207
 	}
1156 1208
 
1157 1209
 	// Remove all the permissions they shouldn't have ;).
1158
-	if (!empty($modSettings['permission_enable_deny']))
1159
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1210
+	if (!empty($modSettings['permission_enable_deny'])) {
1211
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1212
+	}
1160 1213
 
1161
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1162
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1214
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1215
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1216
+	}
1163 1217
 
1164 1218
 	// Banned?  Watch, don't touch..
1165 1219
 	banPermissions();
@@ -1171,17 +1225,18 @@  discard block
 block discarded – undo
1171 1225
 		{
1172 1226
 			require_once($sourcedir . '/Subs-Auth.php');
1173 1227
 			rebuildModCache();
1228
+		} else {
1229
+					$user_info['mod_cache'] = $_SESSION['mc'];
1174 1230
 		}
1175
-		else
1176
-			$user_info['mod_cache'] = $_SESSION['mc'];
1177 1231
 
1178 1232
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1179 1233
 		// For example this drastically simplifies certain changes to the profile area.
1180 1234
 		$user_info['permissions'][] = 'is_not_guest';
1181 1235
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1182 1236
 		$user_info['permissions'][] = 'profile_view_own';
1183
-		if (in_array('profile_view', $user_info['permissions']))
1184
-			$user_info['permissions'][] = 'profile_view_any';
1237
+		if (in_array('profile_view', $user_info['permissions'])) {
1238
+					$user_info['permissions'][] = 'profile_view_any';
1239
+		}
1185 1240
 	}
1186 1241
 }
1187 1242
 
@@ -1199,8 +1254,9 @@  discard block
 block discarded – undo
1199 1254
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1200 1255
 
1201 1256
 	// Can't just look for no users :P.
1202
-	if (empty($users))
1203
-		return array();
1257
+	if (empty($users)) {
1258
+			return array();
1259
+	}
1204 1260
 
1205 1261
 	// Pass the set value
1206 1262
 	$context['loadMemberContext_set'] = $set;
@@ -1215,8 +1271,9 @@  discard block
 block discarded – undo
1215 1271
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1216 1272
 		{
1217 1273
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1218
-			if ($data == null)
1219
-				continue;
1274
+			if ($data == null) {
1275
+							continue;
1276
+			}
1220 1277
 
1221 1278
 			$loaded_ids[] = $data['id_member'];
1222 1279
 			$user_profile[$data['id_member']] = $data;
@@ -1280,13 +1337,16 @@  discard block
 block discarded – undo
1280 1337
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1281 1338
 		{
1282 1339
 			// Take care of proxying avatar if required, do this here for maximum reach
1283
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1284
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1340
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1341
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1342
+			}
1285 1343
 
1286
-			if (isset($row['member_ip']))
1287
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1288
-			if (isset($row['member_ip2']))
1289
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1344
+			if (isset($row['member_ip'])) {
1345
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1346
+			}
1347
+			if (isset($row['member_ip2'])) {
1348
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1349
+			}
1290 1350
 			$new_loaded_ids[] = $row['id_member'];
1291 1351
 			$loaded_ids[] = $row['id_member'];
1292 1352
 			$row['options'] = array();
@@ -1305,8 +1365,9 @@  discard block
 block discarded – undo
1305 1365
 				'loaded_ids' => $new_loaded_ids,
1306 1366
 			)
1307 1367
 		);
1308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1309
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1368
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1369
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1370
+		}
1310 1371
 		$smcFunc['db_free_result']($request);
1311 1372
 	}
1312 1373
 
@@ -1317,10 +1378,11 @@  discard block
 block discarded – undo
1317 1378
 	{
1318 1379
 		foreach ($loaded_ids as $a_member)
1319 1380
 		{
1320
-			if (!empty($user_profile[$a_member]['additional_groups']))
1321
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1322
-			else
1323
-				$groups = array($user_profile[$a_member]['id_group']);
1381
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1382
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1383
+			} else {
1384
+							$groups = array($user_profile[$a_member]['id_group']);
1385
+			}
1324 1386
 
1325 1387
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1326 1388
 
@@ -1333,8 +1395,9 @@  discard block
 block discarded – undo
1333 1395
 
1334 1396
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1335 1397
 	{
1336
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1337
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1398
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1399
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1400
+		}
1338 1401
 	}
1339 1402
 
1340 1403
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1360,14 +1423,17 @@  discard block
 block discarded – undo
1360 1423
 		foreach ($temp_mods as $id)
1361 1424
 		{
1362 1425
 			// By popular demand, don't show admins or global moderators as moderators.
1363
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1364
-				$user_profile[$id]['member_group'] = $row['member_group'];
1426
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1427
+							$user_profile[$id]['member_group'] = $row['member_group'];
1428
+			}
1365 1429
 
1366 1430
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1367
-			if (!empty($row['icons']))
1368
-				$user_profile[$id]['icons'] = $row['icons'];
1369
-			if (!empty($row['member_group_color']))
1370
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1431
+			if (!empty($row['icons'])) {
1432
+							$user_profile[$id]['icons'] = $row['icons'];
1433
+			}
1434
+			if (!empty($row['member_group_color'])) {
1435
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1436
+			}
1371 1437
 		}
1372 1438
 	}
1373 1439
 
@@ -1389,12 +1455,14 @@  discard block
 block discarded – undo
1389 1455
 	static $loadedLanguages = array();
1390 1456
 
1391 1457
 	// If this person's data is already loaded, skip it.
1392
-	if (isset($dataLoaded[$user]))
1393
-		return true;
1458
+	if (isset($dataLoaded[$user])) {
1459
+			return true;
1460
+	}
1394 1461
 
1395 1462
 	// We can't load guests or members not loaded by loadMemberData()!
1396
-	if ($user == 0)
1397
-		return false;
1463
+	if ($user == 0) {
1464
+			return false;
1465
+	}
1398 1466
 	if (!isset($user_profile[$user]))
1399 1467
 	{
1400 1468
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1420,12 +1488,16 @@  discard block
 block discarded – undo
1420 1488
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1421 1489
 
1422 1490
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1423
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1491
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1492
+		//icon is set and exists
1424 1493
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1425
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1494
+	} elseif (isset($profile['icons'][1])) {
1495
+		//icon is set and doesn't exist, fallback to default
1426 1496
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1427
-	else //not set, bye bye
1497
+	} else {
1498
+		//not set, bye bye
1428 1499
 		$group_icon_url = '';
1500
+	}
1429 1501
 
1430 1502
 	// These minimal values are always loaded
1431 1503
 	$memberContext[$user] = array(
@@ -1444,8 +1516,9 @@  discard block
 block discarded – undo
1444 1516
 	if ($context['loadMemberContext_set'] != 'minimal')
1445 1517
 	{
1446 1518
 		// Go the extra mile and load the user's native language name.
1447
-		if (empty($loadedLanguages))
1448
-			$loadedLanguages = getLanguages();
1519
+		if (empty($loadedLanguages)) {
1520
+					$loadedLanguages = getLanguages();
1521
+		}
1449 1522
 
1450 1523
 		$memberContext[$user] += array(
1451 1524
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1499,31 +1572,33 @@  discard block
 block discarded – undo
1499 1572
 	{
1500 1573
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1501 1574
 		{
1502
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1503
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1504
-			else
1505
-				$image = get_gravatar_url($profile['email_address']);
1506
-		}
1507
-		else
1575
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1576
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1577
+			} else {
1578
+							$image = get_gravatar_url($profile['email_address']);
1579
+			}
1580
+		} else
1508 1581
 		{
1509 1582
 			// So it's stored in the member table?
1510 1583
 			if (!empty($profile['avatar']))
1511 1584
 			{
1512 1585
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1586
+			} elseif (!empty($profile['filename'])) {
1587
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1513 1588
 			}
1514
-			elseif (!empty($profile['filename']))
1515
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1516 1589
 			// Right... no avatar...use the default one
1517
-			else
1518
-				$image = $modSettings['avatar_url'] . '/default.png';
1590
+			else {
1591
+							$image = $modSettings['avatar_url'] . '/default.png';
1592
+			}
1519 1593
 		}
1520
-		if (!empty($image))
1521
-			$memberContext[$user]['avatar'] = array(
1594
+		if (!empty($image)) {
1595
+					$memberContext[$user]['avatar'] = array(
1522 1596
 				'name' => $profile['avatar'],
1523 1597
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1524 1598
 				'href' => $image,
1525 1599
 				'url' => $image,
1526 1600
 			);
1601
+		}
1527 1602
 	}
1528 1603
 
1529 1604
 	// Are we also loading the members custom fields into context?
@@ -1531,35 +1606,41 @@  discard block
 block discarded – undo
1531 1606
 	{
1532 1607
 		$memberContext[$user]['custom_fields'] = array();
1533 1608
 
1534
-		if (!isset($context['display_fields']))
1535
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1609
+		if (!isset($context['display_fields'])) {
1610
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1611
+		}
1536 1612
 
1537 1613
 		foreach ($context['display_fields'] as $custom)
1538 1614
 		{
1539
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1540
-				continue;
1615
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1616
+							continue;
1617
+			}
1541 1618
 
1542 1619
 			$value = $profile['options'][$custom['col_name']];
1543 1620
 
1544 1621
 			// Don't show the "disabled" option for the "gender" field.
1545
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1546
-				continue;
1622
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1623
+							continue;
1624
+			}
1547 1625
 
1548 1626
 			// BBC?
1549
-			if ($custom['bbc'])
1550
-				$value = parse_bbc($value);
1627
+			if ($custom['bbc']) {
1628
+							$value = parse_bbc($value);
1629
+			}
1551 1630
 			// ... or checkbox?
1552
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1553
-				$value = $value ? $txt['yes'] : $txt['no'];
1631
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1632
+							$value = $value ? $txt['yes'] : $txt['no'];
1633
+			}
1554 1634
 
1555 1635
 			// Enclosing the user input within some other text?
1556
-			if (!empty($custom['enclose']))
1557
-				$value = strtr($custom['enclose'], array(
1636
+			if (!empty($custom['enclose'])) {
1637
+							$value = strtr($custom['enclose'], array(
1558 1638
 					'{SCRIPTURL}' => $scripturl,
1559 1639
 					'{IMAGES_URL}' => $settings['images_url'],
1560 1640
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1561 1641
 					'{INPUT}' => $value,
1562 1642
 				));
1643
+			}
1563 1644
 
1564 1645
 			$memberContext[$user]['custom_fields'][] = array(
1565 1646
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1586,8 +1667,9 @@  discard block
 block discarded – undo
1586 1667
 	global $smcFunc, $txt, $scripturl, $settings;
1587 1668
 
1588 1669
 	// Do not waste my time...
1589
-	if (empty($users) || empty($params))
1590
-		return false;
1670
+	if (empty($users) || empty($params)) {
1671
+			return false;
1672
+	}
1591 1673
 
1592 1674
 	// Make sure it's an array.
1593 1675
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1611,31 +1693,36 @@  discard block
 block discarded – undo
1611 1693
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1612 1694
 	{
1613 1695
 		// BBC?
1614
-		if (!empty($row['bbc']))
1615
-			$row['value'] = parse_bbc($row['value']);
1696
+		if (!empty($row['bbc'])) {
1697
+					$row['value'] = parse_bbc($row['value']);
1698
+		}
1616 1699
 
1617 1700
 		// ... or checkbox?
1618
-		elseif (isset($row['type']) && $row['type'] == 'check')
1619
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1701
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1702
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1703
+		}
1620 1704
 
1621 1705
 		// Enclosing the user input within some other text?
1622
-		if (!empty($row['enclose']))
1623
-			$row['value'] = strtr($row['enclose'], array(
1706
+		if (!empty($row['enclose'])) {
1707
+					$row['value'] = strtr($row['enclose'], array(
1624 1708
 				'{SCRIPTURL}' => $scripturl,
1625 1709
 				'{IMAGES_URL}' => $settings['images_url'],
1626 1710
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1627 1711
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1628 1712
 			));
1713
+		}
1629 1714
 
1630 1715
 		// Send a simple array if there is just 1 param
1631
-		if (count($params) == 1)
1632
-			$return[$row['id_member']] = $row;
1716
+		if (count($params) == 1) {
1717
+					$return[$row['id_member']] = $row;
1718
+		}
1633 1719
 
1634 1720
 		// More than 1? knock yourself out...
1635 1721
 		else
1636 1722
 		{
1637
-			if (!isset($return[$row['id_member']]))
1638
-				$return[$row['id_member']] = array();
1723
+			if (!isset($return[$row['id_member']])) {
1724
+							$return[$row['id_member']] = array();
1725
+			}
1639 1726
 
1640 1727
 			$return[$row['id_member']][$row['variable']] = $row;
1641 1728
 		}
@@ -1669,8 +1756,9 @@  discard block
 block discarded – undo
1669 1756
 	global $context;
1670 1757
 
1671 1758
 	// Don't know any browser!
1672
-	if (empty($context['browser']))
1673
-		detectBrowser();
1759
+	if (empty($context['browser'])) {
1760
+			detectBrowser();
1761
+	}
1674 1762
 
1675 1763
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1676 1764
 }
@@ -1688,8 +1776,9 @@  discard block
 block discarded – undo
1688 1776
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1689 1777
 
1690 1778
 	// The theme was specified by parameter.
1691
-	if (!empty($id_theme))
1692
-		$id_theme = (int) $id_theme;
1779
+	if (!empty($id_theme)) {
1780
+			$id_theme = (int) $id_theme;
1781
+	}
1693 1782
 	// The theme was specified by REQUEST.
1694 1783
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1695 1784
 	{
@@ -1697,51 +1786,58 @@  discard block
 block discarded – undo
1697 1786
 		$_SESSION['id_theme'] = $id_theme;
1698 1787
 	}
1699 1788
 	// The theme was specified by REQUEST... previously.
1700
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1701
-		$id_theme = (int) $_SESSION['id_theme'];
1789
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1790
+			$id_theme = (int) $_SESSION['id_theme'];
1791
+	}
1702 1792
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1703
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1704
-		$id_theme = $user_info['theme'];
1793
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1794
+			$id_theme = $user_info['theme'];
1795
+	}
1705 1796
 	// The theme was specified by the board.
1706
-	elseif (!empty($board_info['theme']))
1707
-		$id_theme = $board_info['theme'];
1797
+	elseif (!empty($board_info['theme'])) {
1798
+			$id_theme = $board_info['theme'];
1799
+	}
1708 1800
 	// The theme is the forum's default.
1709
-	else
1710
-		$id_theme = $modSettings['theme_guests'];
1801
+	else {
1802
+			$id_theme = $modSettings['theme_guests'];
1803
+	}
1711 1804
 
1712 1805
 	// Verify the id_theme... no foul play.
1713 1806
 	// Always allow the board specific theme, if they are overriding.
1714
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1715
-		$id_theme = $board_info['theme'];
1807
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1808
+			$id_theme = $board_info['theme'];
1809
+	}
1716 1810
 	// If they have specified a particular theme to use with SSI allow it to be used.
1717
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1718
-		$id_theme = (int) $id_theme;
1719
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1811
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1812
+			$id_theme = (int) $id_theme;
1813
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1720 1814
 	{
1721 1815
 		$themes = explode(',', $modSettings['enableThemes']);
1722
-		if (!in_array($id_theme, $themes))
1723
-			$id_theme = $modSettings['theme_guests'];
1724
-		else
1816
+		if (!in_array($id_theme, $themes)) {
1817
+					$id_theme = $modSettings['theme_guests'];
1818
+		} else {
1819
+					$id_theme = (int) $id_theme;
1820
+		}
1821
+	} else {
1725 1822
 			$id_theme = (int) $id_theme;
1726 1823
 	}
1727
-	else
1728
-		$id_theme = (int) $id_theme;
1729 1824
 
1730 1825
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1731 1826
 
1732 1827
 	// Disable image proxy if we don't have SSL enabled
1733
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1734
-		$image_proxy_enabled = false;
1828
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1829
+			$image_proxy_enabled = false;
1830
+	}
1735 1831
 
1736 1832
 	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'])
1737 1833
 	{
1738 1834
 		$themeData = $temp;
1739 1835
 		$flag = true;
1836
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1837
+			$themeData = $temp + array($member => array());
1838
+	} else {
1839
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1740 1840
 	}
1741
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1742
-		$themeData = $temp + array($member => array());
1743
-	else
1744
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1745 1841
 
1746 1842
 	if (empty($flag))
1747 1843
 	{
@@ -1760,31 +1856,37 @@  discard block
 block discarded – undo
1760 1856
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1761 1857
 		{
1762 1858
 			// There are just things we shouldn't be able to change as members.
1763
-			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')))
1764
-				continue;
1859
+			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'))) {
1860
+							continue;
1861
+			}
1765 1862
 
1766 1863
 			// If this is the theme_dir of the default theme, store it.
1767
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1768
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1864
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1865
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1866
+			}
1769 1867
 
1770 1868
 			// If this isn't set yet, is a theme option, or is not the default theme..
1771
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1772
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1869
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1870
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1871
+			}
1773 1872
 		}
1774 1873
 		$smcFunc['db_free_result']($result);
1775 1874
 
1776
-		if (!empty($themeData[-1]))
1777
-			foreach ($themeData[-1] as $k => $v)
1875
+		if (!empty($themeData[-1])) {
1876
+					foreach ($themeData[-1] as $k => $v)
1778 1877
 			{
1779 1878
 				if (!isset($themeData[$member][$k]))
1780 1879
 					$themeData[$member][$k] = $v;
1880
+		}
1781 1881
 			}
1782 1882
 
1783
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1784
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1883
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1884
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1885
+		}
1785 1886
 		// Only if we didn't already load that part of the cache...
1786
-		elseif (!isset($temp))
1787
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1887
+		elseif (!isset($temp)) {
1888
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1889
+		}
1788 1890
 	}
1789 1891
 
1790 1892
 	$settings = $themeData[0];
@@ -1801,20 +1903,24 @@  discard block
 block discarded – undo
1801 1903
 	$settings['template_dirs'][] = $settings['theme_dir'];
1802 1904
 
1803 1905
 	// Based on theme (if there is one).
1804
-	if (!empty($settings['base_theme_dir']))
1805
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1906
+	if (!empty($settings['base_theme_dir'])) {
1907
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1908
+	}
1806 1909
 
1807 1910
 	// Lastly the default theme.
1808
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1809
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1911
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1912
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1913
+	}
1810 1914
 
1811
-	if (!$initialize)
1812
-		return;
1915
+	if (!$initialize) {
1916
+			return;
1917
+	}
1813 1918
 
1814 1919
 	// Check to see if we're forcing SSL
1815 1920
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1816
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1817
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1921
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1922
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1923
+	}
1818 1924
 
1819 1925
 	// Check to see if they're accessing it from the wrong place.
1820 1926
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1822,8 +1928,9 @@  discard block
 block discarded – undo
1822 1928
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1823 1929
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1824 1930
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1825
-		if ($temp != '/')
1826
-			$detected_url .= $temp;
1931
+		if ($temp != '/') {
1932
+					$detected_url .= $temp;
1933
+		}
1827 1934
 	}
1828 1935
 	if (isset($detected_url) && $detected_url != $boardurl)
1829 1936
 	{
@@ -1835,8 +1942,9 @@  discard block
 block discarded – undo
1835 1942
 			foreach ($aliases as $alias)
1836 1943
 			{
1837 1944
 				// Rip off all the boring parts, spaces, etc.
1838
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1839
-					$do_fix = true;
1945
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1946
+									$do_fix = true;
1947
+				}
1840 1948
 			}
1841 1949
 		}
1842 1950
 
@@ -1844,20 +1952,22 @@  discard block
 block discarded – undo
1844 1952
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1845 1953
 		{
1846 1954
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1847
-			if (empty($_GET))
1848
-				redirectexit('wwwRedirect');
1849
-			else
1955
+			if (empty($_GET)) {
1956
+							redirectexit('wwwRedirect');
1957
+			} else
1850 1958
 			{
1851 1959
 				list ($k, $v) = each($_GET);
1852 1960
 
1853
-				if ($k != 'wwwRedirect')
1854
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1961
+				if ($k != 'wwwRedirect') {
1962
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1963
+				}
1855 1964
 			}
1856 1965
 		}
1857 1966
 
1858 1967
 		// #3 is just a check for SSL...
1859
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1860
-			$do_fix = true;
1968
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1969
+					$do_fix = true;
1970
+		}
1861 1971
 
1862 1972
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1863 1973
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1891,8 +2001,9 @@  discard block
 block discarded – undo
1891 2001
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1892 2002
 				}
1893 2003
 			}
1894
-			foreach ($context['linktree'] as $k => $dummy)
1895
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2004
+			foreach ($context['linktree'] as $k => $dummy) {
2005
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2006
+			}
1896 2007
 		}
1897 2008
 	}
1898 2009
 	// Set up the contextual user array.
@@ -1911,16 +2022,16 @@  discard block
 block discarded – undo
1911 2022
 			'email' => $user_info['email'],
1912 2023
 			'ignoreusers' => $user_info['ignoreusers'],
1913 2024
 		);
1914
-		if (!$context['user']['is_guest'])
1915
-			$context['user']['name'] = $user_info['name'];
1916
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1917
-			$context['user']['name'] = $txt['guest_title'];
2025
+		if (!$context['user']['is_guest']) {
2026
+					$context['user']['name'] = $user_info['name'];
2027
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2028
+					$context['user']['name'] = $txt['guest_title'];
2029
+		}
1918 2030
 
1919 2031
 		// Determine the current smiley set.
1920 2032
 		$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'];
1921 2033
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1922
-	}
1923
-	else
2034
+	} else
1924 2035
 	{
1925 2036
 		$context['user'] = array(
1926 2037
 			'id' => -1,
@@ -1936,18 +2047,24 @@  discard block
 block discarded – undo
1936 2047
 	}
1937 2048
 
1938 2049
 	// Some basic information...
1939
-	if (!isset($context['html_headers']))
1940
-		$context['html_headers'] = '';
1941
-	if (!isset($context['javascript_files']))
1942
-		$context['javascript_files'] = array();
1943
-	if (!isset($context['css_files']))
1944
-		$context['css_files'] = array();
1945
-	if (!isset($context['css_header']))
1946
-		$context['css_header'] = array();
1947
-	if (!isset($context['javascript_inline']))
1948
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1949
-	if (!isset($context['javascript_vars']))
1950
-		$context['javascript_vars'] = array();
2050
+	if (!isset($context['html_headers'])) {
2051
+			$context['html_headers'] = '';
2052
+	}
2053
+	if (!isset($context['javascript_files'])) {
2054
+			$context['javascript_files'] = array();
2055
+	}
2056
+	if (!isset($context['css_files'])) {
2057
+			$context['css_files'] = array();
2058
+	}
2059
+	if (!isset($context['css_header'])) {
2060
+			$context['css_header'] = array();
2061
+	}
2062
+	if (!isset($context['javascript_inline'])) {
2063
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2064
+	}
2065
+	if (!isset($context['javascript_vars'])) {
2066
+			$context['javascript_vars'] = array();
2067
+	}
1951 2068
 
1952 2069
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1953 2070
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1959,8 +2076,9 @@  discard block
 block discarded – undo
1959 2076
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1960 2077
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1961 2078
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1962
-	if (isset($modSettings['load_average']))
1963
-		$context['load_average'] = $modSettings['load_average'];
2079
+	if (isset($modSettings['load_average'])) {
2080
+			$context['load_average'] = $modSettings['load_average'];
2081
+	}
1964 2082
 
1965 2083
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1966 2084
 	detectBrowser();
@@ -1974,8 +2092,9 @@  discard block
 block discarded – undo
1974 2092
 	// This allows sticking some HTML on the page output - useful for controls.
1975 2093
 	$context['insert_after_template'] = '';
1976 2094
 
1977
-	if (!isset($txt))
1978
-		$txt = array();
2095
+	if (!isset($txt)) {
2096
+			$txt = array();
2097
+	}
1979 2098
 
1980 2099
 	$simpleActions = array(
1981 2100
 		'findmember',
@@ -2021,9 +2140,10 @@  discard block
 block discarded – undo
2021 2140
 
2022 2141
 	// See if theres any extra param to check.
2023 2142
 	$requiresXML = false;
2024
-	foreach ($extraParams as $key => $extra)
2025
-		if (isset($_REQUEST[$extra]))
2143
+	foreach ($extraParams as $key => $extra) {
2144
+			if (isset($_REQUEST[$extra]))
2026 2145
 			$requiresXML = true;
2146
+	}
2027 2147
 
2028 2148
 	// Output is fully XML, so no need for the index template.
2029 2149
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2038,37 +2158,39 @@  discard block
 block discarded – undo
2038 2158
 	{
2039 2159
 		loadLanguage('index+Modifications');
2040 2160
 		$context['template_layers'] = array();
2041
-	}
2042
-
2043
-	else
2161
+	} else
2044 2162
 	{
2045 2163
 		// Custom templates to load, or just default?
2046
-		if (isset($settings['theme_templates']))
2047
-			$templates = explode(',', $settings['theme_templates']);
2048
-		else
2049
-			$templates = array('index');
2164
+		if (isset($settings['theme_templates'])) {
2165
+					$templates = explode(',', $settings['theme_templates']);
2166
+		} else {
2167
+					$templates = array('index');
2168
+		}
2050 2169
 
2051 2170
 		// Load each template...
2052
-		foreach ($templates as $template)
2053
-			loadTemplate($template);
2171
+		foreach ($templates as $template) {
2172
+					loadTemplate($template);
2173
+		}
2054 2174
 
2055 2175
 		// ...and attempt to load their associated language files.
2056 2176
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2057 2177
 		loadLanguage($required_files, '', false);
2058 2178
 
2059 2179
 		// Custom template layers?
2060
-		if (isset($settings['theme_layers']))
2061
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2062
-		else
2063
-			$context['template_layers'] = array('html', 'body');
2180
+		if (isset($settings['theme_layers'])) {
2181
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2182
+		} else {
2183
+					$context['template_layers'] = array('html', 'body');
2184
+		}
2064 2185
 	}
2065 2186
 
2066 2187
 	// Initialize the theme.
2067 2188
 	loadSubTemplate('init', 'ignore');
2068 2189
 
2069 2190
 	// Allow overriding the board wide time/number formats.
2070
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2071
-		$user_info['time_format'] = $txt['time_format'];
2191
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2192
+			$user_info['time_format'] = $txt['time_format'];
2193
+	}
2072 2194
 
2073 2195
 	// Set the character set from the template.
2074 2196
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2076,12 +2198,14 @@  discard block
 block discarded – undo
2076 2198
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2077 2199
 
2078 2200
 	// Guests may still need a name.
2079
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2080
-		$context['user']['name'] = $txt['guest_title'];
2201
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2202
+			$context['user']['name'] = $txt['guest_title'];
2203
+	}
2081 2204
 
2082 2205
 	// Any theme-related strings that need to be loaded?
2083
-	if (!empty($settings['require_theme_strings']))
2084
-		loadLanguage('ThemeStrings', '', false);
2206
+	if (!empty($settings['require_theme_strings'])) {
2207
+			loadLanguage('ThemeStrings', '', false);
2208
+	}
2085 2209
 
2086 2210
 	// Make a special URL for the language.
2087 2211
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2092,8 +2216,9 @@  discard block
 block discarded – undo
2092 2216
 	// Here is my luvly Responsive CSS
2093 2217
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2094 2218
 
2095
-	if ($context['right_to_left'])
2096
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2219
+	if ($context['right_to_left']) {
2220
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2221
+	}
2097 2222
 
2098 2223
 	// We allow theme variants, because we're cool.
2099 2224
 	$context['theme_variant'] = '';
@@ -2101,14 +2226,17 @@  discard block
 block discarded – undo
2101 2226
 	if (!empty($settings['theme_variants']))
2102 2227
 	{
2103 2228
 		// Overriding - for previews and that ilk.
2104
-		if (!empty($_REQUEST['variant']))
2105
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2229
+		if (!empty($_REQUEST['variant'])) {
2230
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2231
+		}
2106 2232
 		// User selection?
2107
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2108
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2233
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2234
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2235
+		}
2109 2236
 		// If not a user variant, select the default.
2110
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2111
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2237
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2238
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2239
+		}
2112 2240
 
2113 2241
 		// Do this to keep things easier in the templates.
2114 2242
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2117,20 +2245,23 @@  discard block
 block discarded – undo
2117 2245
 		if (!empty($context['theme_variant']))
2118 2246
 		{
2119 2247
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2120
-			if ($context['right_to_left'])
2121
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2248
+			if ($context['right_to_left']) {
2249
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2250
+			}
2122 2251
 		}
2123 2252
 	}
2124 2253
 
2125 2254
 	// Let's be compatible with old themes!
2126
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2127
-		$context['template_layers'] = array('main');
2255
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2256
+			$context['template_layers'] = array('main');
2257
+	}
2128 2258
 
2129 2259
 	$context['tabindex'] = 1;
2130 2260
 
2131 2261
 	// Compatibility.
2132
-	if (!isset($settings['theme_version']))
2133
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2262
+	if (!isset($settings['theme_version'])) {
2263
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2264
+	}
2134 2265
 
2135 2266
 	// Default JS variables for use in every theme
2136 2267
 	$context['javascript_vars'] = array(
@@ -2149,18 +2280,18 @@  discard block
 block discarded – undo
2149 2280
 	);
2150 2281
 
2151 2282
 	// Add the JQuery library to the list of files to load.
2152
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2153
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2154
-
2155
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2156
-		loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2157
-
2158
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2159
-		loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2283
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2284
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2285
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2286
+			loadJavaScriptFile('jquery-2.1.4.min.js', array('seed' => false), 'smf_jquery');
2287
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2288
+			loadJavaScriptFile($modSettings['jquery_custom'], array(), 'smf_jquery');
2289
+	}
2160 2290
 
2161 2291
 	// Auto loading? template_javascript() will take care of the local half of this.
2162
-	else
2163
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2292
+	else {
2293
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js', array('external' => true), 'smf_jquery');
2294
+	}
2164 2295
 
2165 2296
 	// Queue our JQuery plugins!
2166 2297
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2183,12 +2314,12 @@  discard block
 block discarded – undo
2183 2314
 			require_once($sourcedir . '/ScheduledTasks.php');
2184 2315
 
2185 2316
 			// What to do, what to do?!
2186
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2187
-				AutoTask();
2188
-			else
2189
-				ReduceMailQueue();
2190
-		}
2191
-		else
2317
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2318
+							AutoTask();
2319
+			} else {
2320
+							ReduceMailQueue();
2321
+			}
2322
+		} else
2192 2323
 		{
2193 2324
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2194 2325
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2239,8 +2370,9 @@  discard block
 block discarded – undo
2239 2370
 		foreach ($theme_includes as $include)
2240 2371
 		{
2241 2372
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2242
-			if (file_exists($include))
2243
-				require_once($include);
2373
+			if (file_exists($include)) {
2374
+							require_once($include);
2375
+			}
2244 2376
 		}
2245 2377
 	}
2246 2378
 
@@ -2270,16 +2402,19 @@  discard block
 block discarded – undo
2270 2402
 	// Do any style sheets first, cause we're easy with those.
2271 2403
 	if (!empty($style_sheets))
2272 2404
 	{
2273
-		if (!is_array($style_sheets))
2274
-			$style_sheets = array($style_sheets);
2405
+		if (!is_array($style_sheets)) {
2406
+					$style_sheets = array($style_sheets);
2407
+		}
2275 2408
 
2276
-		foreach ($style_sheets as $sheet)
2277
-			loadCSSFile($sheet . '.css', array(), $sheet);
2409
+		foreach ($style_sheets as $sheet) {
2410
+					loadCSSFile($sheet . '.css', array(), $sheet);
2411
+		}
2278 2412
 	}
2279 2413
 
2280 2414
 	// No template to load?
2281
-	if ($template_name === false)
2282
-		return true;
2415
+	if ($template_name === false) {
2416
+			return true;
2417
+	}
2283 2418
 
2284 2419
 	$loaded = false;
2285 2420
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2294,12 +2429,14 @@  discard block
 block discarded – undo
2294 2429
 
2295 2430
 	if ($loaded)
2296 2431
 	{
2297
-		if ($db_show_debug === true)
2298
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2432
+		if ($db_show_debug === true) {
2433
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2434
+		}
2299 2435
 
2300 2436
 		// If they have specified an initialization function for this template, go ahead and call it now.
2301
-		if (function_exists('template_' . $template_name . '_init'))
2302
-			call_user_func('template_' . $template_name . '_init');
2437
+		if (function_exists('template_' . $template_name . '_init')) {
2438
+					call_user_func('template_' . $template_name . '_init');
2439
+		}
2303 2440
 	}
2304 2441
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2305 2442
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2319,13 +2456,14 @@  discard block
 block discarded – undo
2319 2456
 		loadTemplate($template_name);
2320 2457
 	}
2321 2458
 	// Cause an error otherwise.
2322
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2323
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2324
-	elseif ($fatal)
2325
-		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'));
2326
-	else
2327
-		return false;
2328
-}
2459
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2460
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2461
+	} elseif ($fatal) {
2462
+			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'));
2463
+	} else {
2464
+			return false;
2465
+	}
2466
+	}
2329 2467
 
2330 2468
 /**
2331 2469
  * Load a sub-template.
@@ -2343,17 +2481,19 @@  discard block
 block discarded – undo
2343 2481
 {
2344 2482
 	global $context, $txt, $db_show_debug;
2345 2483
 
2346
-	if ($db_show_debug === true)
2347
-		$context['debug']['sub_templates'][] = $sub_template_name;
2484
+	if ($db_show_debug === true) {
2485
+			$context['debug']['sub_templates'][] = $sub_template_name;
2486
+	}
2348 2487
 
2349 2488
 	// Figure out what the template function is named.
2350 2489
 	$theme_function = 'template_' . $sub_template_name;
2351
-	if (function_exists($theme_function))
2352
-		$theme_function();
2353
-	elseif ($fatal === false)
2354
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2355
-	elseif ($fatal !== 'ignore')
2356
-		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'));
2490
+	if (function_exists($theme_function)) {
2491
+			$theme_function();
2492
+	} elseif ($fatal === false) {
2493
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2494
+	} elseif ($fatal !== 'ignore') {
2495
+			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'));
2496
+	}
2357 2497
 
2358 2498
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2359 2499
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2390,8 +2530,9 @@  discard block
 block discarded – undo
2390 2530
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2391 2531
 
2392 2532
 	// If this is an external file, automatically set this to false.
2393
-	if (!empty($params['external']))
2394
-		$params['minimize'] = false;
2533
+	if (!empty($params['external'])) {
2534
+			$params['minimize'] = false;
2535
+	}
2395 2536
 
2396 2537
 	// Account for shorthand like admin.css?alp21 filenames
2397 2538
 	$has_seed = strpos($fileName, '.css?');
@@ -2408,13 +2549,10 @@  discard block
 block discarded – undo
2408 2549
 			{
2409 2550
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2410 2551
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2552
+			} else {
2553
+							$fileUrl = false;
2411 2554
 			}
2412
-
2413
-			else
2414
-				$fileUrl = false;
2415
-		}
2416
-
2417
-		else
2555
+		} else
2418 2556
 		{
2419 2557
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2420 2558
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2429,12 +2567,14 @@  discard block
 block discarded – undo
2429 2567
 	}
2430 2568
 
2431 2569
 	// Add it to the array for use in the template
2432
-	if (!empty($fileName))
2433
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2570
+	if (!empty($fileName)) {
2571
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2572
+	}
2434 2573
 
2435
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2436
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2437
-}
2574
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2575
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2576
+	}
2577
+	}
2438 2578
 
2439 2579
 /**
2440 2580
  * Add a block of inline css code to be executed later
@@ -2451,8 +2591,9 @@  discard block
 block discarded – undo
2451 2591
 	global $context;
2452 2592
 
2453 2593
 	// Gotta add something...
2454
-	if (empty($css))
2455
-		return false;
2594
+	if (empty($css)) {
2595
+			return false;
2596
+	}
2456 2597
 
2457 2598
 	$context['css_header'][] = $css;
2458 2599
 }
@@ -2487,8 +2628,9 @@  discard block
 block discarded – undo
2487 2628
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2488 2629
 
2489 2630
 	// If this is an external file, automatically set this to false.
2490
-	if (!empty($params['external']))
2491
-		$params['minimize'] = false;
2631
+	if (!empty($params['external'])) {
2632
+			$params['minimize'] = false;
2633
+	}
2492 2634
 
2493 2635
 	// Account for shorthand like admin.js?alp21 filenames
2494 2636
 	$has_seed = strpos($fileName, '.js?');
@@ -2505,16 +2647,12 @@  discard block
 block discarded – undo
2505 2647
 			{
2506 2648
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2507 2649
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2508
-			}
2509
-
2510
-			else
2650
+			} else
2511 2651
 			{
2512 2652
 				$fileUrl = false;
2513 2653
 				$filePath = false;
2514 2654
 			}
2515
-		}
2516
-
2517
-		else
2655
+		} else
2518 2656
 		{
2519 2657
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2520 2658
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2529,9 +2667,10 @@  discard block
 block discarded – undo
2529 2667
 	}
2530 2668
 
2531 2669
 	// Add it to the array for use in the template
2532
-	if (!empty($fileName))
2533
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2534
-}
2670
+	if (!empty($fileName)) {
2671
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2672
+	}
2673
+	}
2535 2674
 
2536 2675
 /**
2537 2676
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2545,9 +2684,10 @@  discard block
 block discarded – undo
2545 2684
 {
2546 2685
 	global $context;
2547 2686
 
2548
-	if (!empty($key) && (!empty($value) || $value === '0'))
2549
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2550
-}
2687
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2688
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2689
+	}
2690
+	}
2551 2691
 
2552 2692
 /**
2553 2693
  * Add a block of inline Javascript code to be executed later
@@ -2564,8 +2704,9 @@  discard block
 block discarded – undo
2564 2704
 {
2565 2705
 	global $context;
2566 2706
 
2567
-	if (empty($javascript))
2568
-		return false;
2707
+	if (empty($javascript)) {
2708
+			return false;
2709
+	}
2569 2710
 
2570 2711
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2571 2712
 }
@@ -2586,15 +2727,18 @@  discard block
 block discarded – undo
2586 2727
 	static $already_loaded = array();
2587 2728
 
2588 2729
 	// Default to the user's language.
2589
-	if ($lang == '')
2590
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2730
+	if ($lang == '') {
2731
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2732
+	}
2591 2733
 
2592 2734
 	// Do we want the English version of language file as fallback?
2593
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2594
-		loadLanguage($template_name, 'english', false);
2735
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2736
+			loadLanguage($template_name, 'english', false);
2737
+	}
2595 2738
 
2596
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2597
-		return $lang;
2739
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2740
+			return $lang;
2741
+	}
2598 2742
 
2599 2743
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2600 2744
 	if (empty($settings['default_theme_dir']))
@@ -2605,8 +2749,9 @@  discard block
 block discarded – undo
2605 2749
 
2606 2750
 	// What theme are we in?
2607 2751
 	$theme_name = basename($settings['theme_url']);
2608
-	if (empty($theme_name))
2609
-		$theme_name = 'unknown';
2752
+	if (empty($theme_name)) {
2753
+			$theme_name = 'unknown';
2754
+	}
2610 2755
 
2611 2756
 	// For each file open it up and write it out!
2612 2757
 	foreach (explode('+', $template_name) as $template)
@@ -2685,8 +2830,9 @@  discard block
 block discarded – undo
2685 2830
 	}
2686 2831
 
2687 2832
 	// Keep track of what we're up to soldier.
2688
-	if ($db_show_debug === true)
2689
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2833
+	if ($db_show_debug === true) {
2834
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2835
+	}
2690 2836
 
2691 2837
 	// Remember what we have loaded, and in which language.
2692 2838
 	$already_loaded[$template_name] = $lang;
@@ -2732,8 +2878,9 @@  discard block
 block discarded – undo
2732 2878
 				)
2733 2879
 			);
2734 2880
 			// In the EXTREMELY unlikely event this happens, give an error message.
2735
-			if ($smcFunc['db_num_rows']($result) == 0)
2736
-				fatal_lang_error('parent_not_found', 'critical');
2881
+			if ($smcFunc['db_num_rows']($result) == 0) {
2882
+							fatal_lang_error('parent_not_found', 'critical');
2883
+			}
2737 2884
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2738 2885
 			{
2739 2886
 				if (!isset($boards[$row['id_board']]))
@@ -2750,8 +2897,8 @@  discard block
 block discarded – undo
2750 2897
 					);
2751 2898
 				}
2752 2899
 				// If a moderator exists for this board, add that moderator for all children too.
2753
-				if (!empty($row['id_moderator']))
2754
-					foreach ($boards as $id => $dummy)
2900
+				if (!empty($row['id_moderator'])) {
2901
+									foreach ($boards as $id => $dummy)
2755 2902
 					{
2756 2903
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2757 2904
 							'id' => $row['id_moderator'],
@@ -2759,11 +2906,12 @@  discard block
 block discarded – undo
2759 2906
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2760 2907
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2761 2908
 						);
2909
+				}
2762 2910
 					}
2763 2911
 
2764 2912
 				// If a moderator group exists for this board, add that moderator group for all children too
2765
-				if (!empty($row['id_moderator_group']))
2766
-					foreach ($boards as $id => $dummy)
2913
+				if (!empty($row['id_moderator_group'])) {
2914
+									foreach ($boards as $id => $dummy)
2767 2915
 					{
2768 2916
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2769 2917
 							'id' => $row['id_moderator_group'],
@@ -2771,6 +2919,7 @@  discard block
 block discarded – undo
2771 2919
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2772 2920
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2773 2921
 						);
2922
+				}
2774 2923
 					}
2775 2924
 			}
2776 2925
 			$smcFunc['db_free_result']($result);
@@ -2798,23 +2947,27 @@  discard block
 block discarded – undo
2798 2947
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages' . ($favor_utf8 ? '' : '_all'), !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2799 2948
 	{
2800 2949
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2801
-		if (empty($smcFunc['ucwords']))
2802
-			reloadSettings();
2950
+		if (empty($smcFunc['ucwords'])) {
2951
+					reloadSettings();
2952
+		}
2803 2953
 
2804 2954
 		// If we don't have our theme information yet, let's get it.
2805
-		if (empty($settings['default_theme_dir']))
2806
-			loadTheme(0, false);
2955
+		if (empty($settings['default_theme_dir'])) {
2956
+					loadTheme(0, false);
2957
+		}
2807 2958
 
2808 2959
 		// Default language directories to try.
2809 2960
 		$language_directories = array(
2810 2961
 			$settings['default_theme_dir'] . '/languages',
2811 2962
 		);
2812
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2813
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2963
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2964
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2965
+		}
2814 2966
 
2815 2967
 		// We possibly have a base theme directory.
2816
-		if (!empty($settings['base_theme_dir']))
2817
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2968
+		if (!empty($settings['base_theme_dir'])) {
2969
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2970
+		}
2818 2971
 
2819 2972
 		// Remove any duplicates.
2820 2973
 		$language_directories = array_unique($language_directories);
@@ -2828,20 +2981,21 @@  discard block
 block discarded – undo
2828 2981
 		foreach ($language_directories as $language_dir)
2829 2982
 		{
2830 2983
 			// Can't look in here... doesn't exist!
2831
-			if (!file_exists($language_dir))
2832
-				continue;
2984
+			if (!file_exists($language_dir)) {
2985
+							continue;
2986
+			}
2833 2987
 
2834 2988
 			$dir = dir($language_dir);
2835 2989
 			while ($entry = $dir->read())
2836 2990
 			{
2837 2991
 				// Look for the index language file....
2838
-				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches))
2839
-					continue;
2840
-
2841
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2842
-					$langName = $langList[$matches[1]];
2992
+				if (!preg_match('~^index\.(.+)\.php$~', $entry, $matches)) {
2993
+									continue;
2994
+				}
2843 2995
 
2844
-				else
2996
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
2997
+									$langName = $langList[$matches[1]];
2998
+				} else
2845 2999
 				{
2846 3000
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2847 3001
 
@@ -2884,20 +3038,23 @@  discard block
 block discarded – undo
2884 3038
 		}
2885 3039
 
2886 3040
 		// Do we need to store the lang list?
2887
-		if (empty($langList))
2888
-			updateSettings(array('langList' => json_encode($catchLang)));
3041
+		if (empty($langList)) {
3042
+					updateSettings(array('langList' => json_encode($catchLang)));
3043
+		}
2889 3044
 
2890 3045
 		// Favoring UTF8? Then prevent us from selecting non-UTF8 versions.
2891 3046
 		if ($favor_utf8)
2892 3047
 		{
2893
-			foreach ($context['languages'] as $lang)
2894
-				if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
3048
+			foreach ($context['languages'] as $lang) {
3049
+							if (substr($lang['filename'], strlen($lang['filename']) - 5, 5) != '-utf8' && isset($context['languages'][$lang['filename'] . '-utf8']))
2895 3050
 					unset($context['languages'][$lang['filename']]);
3051
+			}
2896 3052
 		}
2897 3053
 
2898 3054
 		// Let's cash in on this deal.
2899
-		if (!empty($modSettings['cache_enable']))
2900
-			cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3055
+		if (!empty($modSettings['cache_enable'])) {
3056
+					cache_put_data('known_languages' . ($favor_utf8 ? '' : '_all'), $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3057
+		}
2901 3058
 	}
2902 3059
 
2903 3060
 	return $context['languages'];
@@ -2920,8 +3077,9 @@  discard block
 block discarded – undo
2920 3077
 	global $modSettings, $options, $txt;
2921 3078
 	static $censor_vulgar = null, $censor_proper;
2922 3079
 
2923
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2924
-		return $text;
3080
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3081
+			return $text;
3082
+	}
2925 3083
 
2926 3084
 	// If they haven't yet been loaded, load them.
2927 3085
 	if ($censor_vulgar == null)
@@ -2949,9 +3107,9 @@  discard block
 block discarded – undo
2949 3107
 	{
2950 3108
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2951 3109
 		$text = $func($censor_vulgar, $censor_proper, $text);
3110
+	} else {
3111
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2952 3112
 	}
2953
-	else
2954
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2955 3113
 
2956 3114
 	return $text;
2957 3115
 }
@@ -2977,38 +3135,42 @@  discard block
 block discarded – undo
2977 3135
 	@ini_set('track_errors', '1');
2978 3136
 
2979 3137
 	// Don't include the file more than once, if $once is true.
2980
-	if ($once && in_array($filename, $templates))
2981
-		return;
3138
+	if ($once && in_array($filename, $templates)) {
3139
+			return;
3140
+	}
2982 3141
 	// Add this file to the include list, whether $once is true or not.
2983
-	else
2984
-		$templates[] = $filename;
3142
+	else {
3143
+			$templates[] = $filename;
3144
+	}
2985 3145
 
2986 3146
 	// Are we going to use eval?
2987 3147
 	if (empty($modSettings['disableTemplateEval']))
2988 3148
 	{
2989 3149
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2990 3150
 		$settings['current_include_filename'] = $filename;
2991
-	}
2992
-	else
3151
+	} else
2993 3152
 	{
2994 3153
 		$file_found = file_exists($filename);
2995 3154
 
2996
-		if ($once && $file_found)
2997
-			require_once($filename);
2998
-		elseif ($file_found)
2999
-			require($filename);
3155
+		if ($once && $file_found) {
3156
+					require_once($filename);
3157
+		} elseif ($file_found) {
3158
+					require($filename);
3159
+		}
3000 3160
 	}
3001 3161
 
3002 3162
 	if ($file_found !== true)
3003 3163
 	{
3004 3164
 		ob_end_clean();
3005
-		if (!empty($modSettings['enableCompressedOutput']))
3006
-			@ob_start('ob_gzhandler');
3007
-		else
3008
-			ob_start();
3165
+		if (!empty($modSettings['enableCompressedOutput'])) {
3166
+					@ob_start('ob_gzhandler');
3167
+		} else {
3168
+					ob_start();
3169
+		}
3009 3170
 
3010
-		if (isset($_GET['debug']))
3011
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3171
+		if (isset($_GET['debug'])) {
3172
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3173
+		}
3012 3174
 
3013 3175
 		// Don't cache error pages!!
3014 3176
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3027,12 +3189,13 @@  discard block
 block discarded – undo
3027 3189
 		echo '<!DOCTYPE html>
3028 3190
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3029 3191
 	<head>';
3030
-		if (isset($context['character_set']))
3031
-			echo '
3192
+		if (isset($context['character_set'])) {
3193
+					echo '
3032 3194
 		<meta charset="', $context['character_set'], '">';
3195
+		}
3033 3196
 
3034
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3035
-			echo '
3197
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3198
+					echo '
3036 3199
 		<title>', $mtitle, '</title>
3037 3200
 	</head>
3038 3201
 	<body>
@@ -3040,8 +3203,8 @@  discard block
 block discarded – undo
3040 3203
 		', $mmessage, '
3041 3204
 	</body>
3042 3205
 </html>';
3043
-		elseif (!allowedTo('admin_forum'))
3044
-			echo '
3206
+		} elseif (!allowedTo('admin_forum')) {
3207
+					echo '
3045 3208
 		<title>', $txt['template_parse_error'], '</title>
3046 3209
 	</head>
3047 3210
 	<body>
@@ -3049,15 +3212,17 @@  discard block
 block discarded – undo
3049 3212
 		', $txt['template_parse_error_message'], '
3050 3213
 	</body>
3051 3214
 </html>';
3052
-		else
3215
+		} else
3053 3216
 		{
3054 3217
 			require_once($sourcedir . '/Subs-Package.php');
3055 3218
 
3056 3219
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3057
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3058
-				$error = $php_errormsg;
3059
-			if (empty($error))
3060
-				$error = $txt['template_parse_errmsg'];
3220
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3221
+							$error = $php_errormsg;
3222
+			}
3223
+			if (empty($error)) {
3224
+							$error = $txt['template_parse_errmsg'];
3225
+			}
3061 3226
 
3062 3227
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3063 3228
 
@@ -3068,11 +3233,12 @@  discard block
 block discarded – undo
3068 3233
 		<h3>', $txt['template_parse_error'], '</h3>
3069 3234
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3070 3235
 
3071
-			if (!empty($error))
3072
-				echo '
3236
+			if (!empty($error)) {
3237
+							echo '
3073 3238
 		<hr>
3074 3239
 
3075 3240
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3241
+			}
3076 3242
 
3077 3243
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3078 3244
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3082,10 +3248,11 @@  discard block
 block discarded – undo
3082 3248
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3083 3249
 
3084 3250
 				// Fix the PHP code stuff...
3085
-				if (!isBrowser('gecko'))
3086
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3087
-				else
3088
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3251
+				if (!isBrowser('gecko')) {
3252
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3253
+				} else {
3254
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3255
+				}
3089 3256
 
3090 3257
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3091 3258
 				$j = -1;
@@ -3093,8 +3260,9 @@  discard block
 block discarded – undo
3093 3260
 				{
3094 3261
 					$j++;
3095 3262
 
3096
-					if (substr_count($line, '<br>') == 0)
3097
-						continue;
3263
+					if (substr_count($line, '<br>') == 0) {
3264
+											continue;
3265
+					}
3098 3266
 
3099 3267
 					$n = substr_count($line, '<br>');
3100 3268
 					for ($i = 0; $i < $n; $i++)
@@ -3113,38 +3281,42 @@  discard block
 block discarded – undo
3113 3281
 				// Figure out what the color coding was before...
3114 3282
 				$line = max($match[1] - 9, 1);
3115 3283
 				$last_line = '';
3116
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3117
-					if (strpos($data2[$line2], '<') !== false)
3284
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3285
+									if (strpos($data2[$line2], '<') !== false)
3118 3286
 					{
3119 3287
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3120 3288
 							$last_line = $color_match[1];
3289
+				}
3121 3290
 						break;
3122 3291
 					}
3123 3292
 
3124 3293
 				// Show the relevant lines...
3125 3294
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3126 3295
 				{
3127
-					if ($line == $match[1])
3128
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3296
+					if ($line == $match[1]) {
3297
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3298
+					}
3129 3299
 
3130 3300
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3131
-					if (isset($data2[$line]) && $data2[$line] != '')
3132
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3301
+					if (isset($data2[$line]) && $data2[$line] != '') {
3302
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3303
+					}
3133 3304
 
3134 3305
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3135 3306
 					{
3136 3307
 						$last_line = $color_match[1];
3137 3308
 						echo '</', substr($last_line, 1, 4), '>';
3309
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3310
+											$last_line = '';
3311
+					} elseif ($last_line != '' && $data2[$line] != '') {
3312
+											echo '</', substr($last_line, 1, 4), '>';
3138 3313
 					}
3139
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3140
-						$last_line = '';
3141
-					elseif ($last_line != '' && $data2[$line] != '')
3142
-						echo '</', substr($last_line, 1, 4), '>';
3143 3314
 
3144
-					if ($line == $match[1])
3145
-						echo '</pre></div><pre style="margin: 0;">';
3146
-					else
3147
-						echo "\n";
3315
+					if ($line == $match[1]) {
3316
+											echo '</pre></div><pre style="margin: 0;">';
3317
+					} else {
3318
+											echo "\n";
3319
+					}
3148 3320
 				}
3149 3321
 
3150 3322
 				echo '</pre></div>';
@@ -3168,8 +3340,9 @@  discard block
 block discarded – undo
3168 3340
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3169 3341
 
3170 3342
 	// Figure out what type of database we are using.
3171
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3172
-		$db_type = 'mysql';
3343
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3344
+			$db_type = 'mysql';
3345
+	}
3173 3346
 
3174 3347
 	// Load the file for the database.
3175 3348
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3177,8 +3350,9 @@  discard block
 block discarded – undo
3177 3350
 	$db_options = array();
3178 3351
 
3179 3352
 	// Add in the port if needed
3180
-	if (!empty($db_port))
3181
-		$db_options['port'] = $db_port;
3353
+	if (!empty($db_port)) {
3354
+			$db_options['port'] = $db_port;
3355
+	}
3182 3356
 
3183 3357
 	// 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.
3184 3358
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3197,13 +3371,15 @@  discard block
 block discarded – undo
3197 3371
 	}
3198 3372
 
3199 3373
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3200
-	if (!$db_connection)
3201
-		display_db_error();
3374
+	if (!$db_connection) {
3375
+			display_db_error();
3376
+	}
3202 3377
 
3203 3378
 	// If in SSI mode fix up the prefix.
3204
-	if (SMF == 'SSI')
3205
-		db_fix_prefix($db_prefix, $db_name);
3206
-}
3379
+	if (SMF == 'SSI') {
3380
+			db_fix_prefix($db_prefix, $db_name);
3381
+	}
3382
+	}
3207 3383
 
3208 3384
 /**
3209 3385
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3217,10 +3393,11 @@  discard block
 block discarded – undo
3217 3393
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3218 3394
 
3219 3395
 	// Not overriding this and we have a cacheAPI, send it back.
3220
-	if (empty($overrideCache) && is_object($cacheAPI))
3221
-		return $cacheAPI;
3222
-	elseif (is_null($cacheAPI))
3223
-		$cacheAPI = false;
3396
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3397
+			return $cacheAPI;
3398
+	} elseif (is_null($cacheAPI)) {
3399
+			$cacheAPI = false;
3400
+	}
3224 3401
 
3225 3402
 	// Make sure our class is in session.
3226 3403
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3241,8 +3418,9 @@  discard block
 block discarded – undo
3241 3418
 		if (!$testAPI->isSupported())
3242 3419
 		{
3243 3420
 			// Can we save ourselves?
3244
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3245
-				return loadCacheAccelerator(null, false);
3421
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3422
+							return loadCacheAccelerator(null, false);
3423
+			}
3246 3424
 			return false;
3247 3425
 		}
3248 3426
 
@@ -3254,9 +3432,9 @@  discard block
 block discarded – undo
3254 3432
 		{
3255 3433
 			$cacheAPI = $testAPI;
3256 3434
 			return $cacheAPI;
3435
+		} else {
3436
+					return $testAPI;
3257 3437
 		}
3258
-		else
3259
-			return $testAPI;
3260 3438
 	}
3261 3439
 }
3262 3440
 
@@ -3276,8 +3454,9 @@  discard block
 block discarded – undo
3276 3454
 
3277 3455
 	// @todo Why are we doing this if caching is disabled?
3278 3456
 
3279
-	if (function_exists('call_integration_hook'))
3280
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3457
+	if (function_exists('call_integration_hook')) {
3458
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3459
+	}
3281 3460
 
3282 3461
 	/* Refresh the cache if either:
3283 3462
 		1. Caching is disabled.
@@ -3291,16 +3470,19 @@  discard block
 block discarded – undo
3291 3470
 		require_once($sourcedir . '/' . $file);
3292 3471
 		$cache_block = call_user_func_array($function, $params);
3293 3472
 
3294
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3295
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3473
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3474
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3475
+		}
3296 3476
 	}
3297 3477
 
3298 3478
 	// Some cached data may need a freshening up after retrieval.
3299
-	if (!empty($cache_block['post_retri_eval']))
3300
-		eval($cache_block['post_retri_eval']);
3479
+	if (!empty($cache_block['post_retri_eval'])) {
3480
+			eval($cache_block['post_retri_eval']);
3481
+	}
3301 3482
 
3302
-	if (function_exists('call_integration_hook'))
3303
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3483
+	if (function_exists('call_integration_hook')) {
3484
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3485
+	}
3304 3486
 
3305 3487
 	return $cache_block['data'];
3306 3488
 }
@@ -3327,8 +3509,9 @@  discard block
 block discarded – undo
3327 3509
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3328 3510
 	global $cache_hits, $cache_count, $db_show_debug;
3329 3511
 
3330
-	if (empty($cache_enable) || empty($cacheAPI))
3331
-		return;
3512
+	if (empty($cache_enable) || empty($cacheAPI)) {
3513
+			return;
3514
+	}
3332 3515
 
3333 3516
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3334 3517
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3341,12 +3524,14 @@  discard block
 block discarded – undo
3341 3524
 	$value = $value === null ? null : json_encode($value);
3342 3525
 	$cacheAPI->putData($key, $value, $ttl);
3343 3526
 
3344
-	if (function_exists('call_integration_hook'))
3345
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3527
+	if (function_exists('call_integration_hook')) {
3528
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3529
+	}
3346 3530
 
3347
-	if (isset($db_show_debug) && $db_show_debug === true)
3348
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3349
-}
3531
+	if (isset($db_show_debug) && $db_show_debug === true) {
3532
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3533
+	}
3534
+	}
3350 3535
 
3351 3536
 /**
3352 3537
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3362,8 +3547,9 @@  discard block
 block discarded – undo
3362 3547
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3363 3548
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3364 3549
 
3365
-	if (empty($cache_enable) || empty($cacheAPI))
3366
-		return;
3550
+	if (empty($cache_enable) || empty($cacheAPI)) {
3551
+			return;
3552
+	}
3367 3553
 
3368 3554
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3369 3555
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3383,16 +3569,18 @@  discard block
 block discarded – undo
3383 3569
 
3384 3570
 		if (empty($value))
3385 3571
 		{
3386
-			if (!is_array($cache_misses))
3387
-				$cache_misses = array();
3572
+			if (!is_array($cache_misses)) {
3573
+							$cache_misses = array();
3574
+			}
3388 3575
 
3389 3576
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3390 3577
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3391 3578
 		}
3392 3579
 	}
3393 3580
 
3394
-	if (function_exists('call_integration_hook') && isset($value))
3395
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3581
+	if (function_exists('call_integration_hook') && isset($value)) {
3582
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3583
+	}
3396 3584
 
3397 3585
 	return empty($value) ? null : smf_json_decode($value, true);
3398 3586
 }
@@ -3414,8 +3602,9 @@  discard block
 block discarded – undo
3414 3602
 	global $cachedir, $sourcedir, $modSettings, $cacheAPI;
3415 3603
 
3416 3604
 	// If we can't get to the API, can't do this.
3417
-	if (empty($cacheAPI))
3418
-		return false;
3605
+	if (empty($cacheAPI)) {
3606
+			return false;
3607
+	}
3419 3608
 
3420 3609
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3421 3610
 	$value = $cacheAPI->cleanCache($type);
@@ -3440,8 +3629,9 @@  discard block
 block discarded – undo
3440 3629
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3441 3630
 
3442 3631
 	// Come on!
3443
-	if (empty($data))
3444
-		return array();
3632
+	if (empty($data)) {
3633
+			return array();
3634
+	}
3445 3635
 
3446 3636
 	// Set a nice default var.
3447 3637
 	$image = '';
@@ -3449,11 +3639,11 @@  discard block
 block discarded – undo
3449 3639
 	// Gravatar has been set as mandatory!
3450 3640
 	if (!empty($modSettings['gravatarOverride']))
3451 3641
 	{
3452
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3453
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3454
-
3455
-		else if (!empty($data['email']))
3456
-			$image = get_gravatar_url($data['email']);
3642
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3643
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3644
+		} else if (!empty($data['email'])) {
3645
+					$image = get_gravatar_url($data['email']);
3646
+		}
3457 3647
 	}
3458 3648
 
3459 3649
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3465,54 +3655,60 @@  discard block
 block discarded – undo
3465 3655
 			// Gravatar.
3466 3656
 			if (stristr($data['avatar'], 'gravatar://'))
3467 3657
 			{
3468
-				if ($data['avatar'] == 'gravatar://')
3469
-					$image = get_gravatar_url($data['email']);
3470
-
3471
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3472
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3658
+				if ($data['avatar'] == 'gravatar://') {
3659
+									$image = get_gravatar_url($data['email']);
3660
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3661
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3662
+				}
3473 3663
 			}
3474 3664
 
3475 3665
 			// External url.
3476 3666
 			else
3477 3667
 			{
3478 3668
 				// Using ssl?
3479
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3480
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3669
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3670
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3671
+				}
3481 3672
 
3482 3673
 				// Just a plain external url.
3483
-				else
3484
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3674
+				else {
3675
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3676
+				}
3485 3677
 			}
3486 3678
 		}
3487 3679
 
3488 3680
 		// Perhaps this user has an attachment as avatar...
3489
-		else if (!empty($data['filename']))
3490
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3681
+		else if (!empty($data['filename'])) {
3682
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3683
+		}
3491 3684
 
3492 3685
 		// Right... no avatar... use our default image.
3493
-		else
3494
-			$image = $modSettings['avatar_url'] . '/default.png';
3686
+		else {
3687
+					$image = $modSettings['avatar_url'] . '/default.png';
3688
+		}
3495 3689
 	}
3496 3690
 
3497 3691
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3498 3692
 
3499 3693
 	// 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.
3500
-	if (!empty($image))
3501
-		return array(
3694
+	if (!empty($image)) {
3695
+			return array(
3502 3696
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3503 3697
 			'image' => '<img class="avatar" src="' . $image . '" />',
3504 3698
 			'href' => $image,
3505 3699
 			'url' => $image,
3506 3700
 		);
3701
+	}
3507 3702
 
3508 3703
 	// Fallback to make life easier for everyone...
3509
-	else
3510
-		return array(
3704
+	else {
3705
+			return array(
3511 3706
 			'name' => '',
3512 3707
 			'image' => '',
3513 3708
 			'href' => '',
3514 3709
 			'url' => '',
3515 3710
 		);
3516
-}
3711
+	}
3712
+	}
3517 3713
 
3518 3714
 ?>
3519 3715
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Attachments.php 1 patch
Braces   +294 added lines, -222 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 3
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the current directory is still valid or not.
@@ -28,22 +29,24 @@  discard block
 block discarded – undo
28 29
 	global $boarddir, $modSettings, $context;
29 30
 
30 31
 	// Not pretty, but since we don't want folders created for every post. It'll do unless a better solution can be found.
31
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin')
32
-		$doit = true;
33
-	elseif (empty($modSettings['automanage_attachments']))
34
-		return;
35
-	elseif (!isset($_FILES))
36
-		return;
37
-	elseif (isset($_FILES['attachment']))
38
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
32
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'admin') {
33
+			$doit = true;
34
+	} elseif (empty($modSettings['automanage_attachments'])) {
35
+			return;
36
+	} elseif (!isset($_FILES)) {
37
+			return;
38
+	} elseif (isset($_FILES['attachment'])) {
39
+			foreach ($_FILES['attachment']['tmp_name'] as $dummy)
39 40
 			if (!empty($dummy))
40 41
 			{
41 42
 				$doit = true;
43
+	}
42 44
 				break;
43 45
 			}
44 46
 
45
-	if (!isset($doit))
46
-		return;
47
+	if (!isset($doit)) {
48
+			return;
49
+	}
47 50
 
48 51
 	$year = date('Y');
49 52
 	$month = date('m');
@@ -55,21 +58,25 @@  discard block
 block discarded – undo
55 58
 
56 59
 	if (!empty($modSettings['attachment_basedirectories']) && !empty($modSettings['use_subdirectories_for_attachments']))
57 60
 	{
58
-			if (!is_array($modSettings['attachment_basedirectories']))
59
-				$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
61
+			if (!is_array($modSettings['attachment_basedirectories'])) {
62
+							$modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true);
63
+			}
60 64
 			$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
65
+	} else {
66
+			$base_dir = 0;
61 67
 	}
62
-	else
63
-		$base_dir = 0;
64 68
 
65 69
 	if ($modSettings['automanage_attachments'] == 1)
66 70
 	{
67
-		if (!isset($modSettings['last_attachments_directory']))
68
-			$modSettings['last_attachments_directory'] = array();
69
-		if (!is_array($modSettings['last_attachments_directory']))
70
-			$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
71
-		if (!isset($modSettings['last_attachments_directory'][$base_dir]))
72
-			$modSettings['last_attachments_directory'][$base_dir] = 0;
71
+		if (!isset($modSettings['last_attachments_directory'])) {
72
+					$modSettings['last_attachments_directory'] = array();
73
+		}
74
+		if (!is_array($modSettings['last_attachments_directory'])) {
75
+					$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
76
+		}
77
+		if (!isset($modSettings['last_attachments_directory'][$base_dir])) {
78
+					$modSettings['last_attachments_directory'][$base_dir] = 0;
79
+		}
73 80
 	}
74 81
 
75 82
 	$basedirectory = (!empty($modSettings['use_subdirectories_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir);
@@ -98,12 +105,14 @@  discard block
 block discarded – undo
98 105
 			$updir = '';
99 106
 	}
100 107
 
101
-	if (!is_array($modSettings['attachmentUploadDir']))
102
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
103
-	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir))
104
-		$outputCreation = automanage_attachments_create_directory($updir);
105
-	elseif (in_array($updir, $modSettings['attachmentUploadDir']))
106
-		$outputCreation = true;
108
+	if (!is_array($modSettings['attachmentUploadDir'])) {
109
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
110
+	}
111
+	if (!in_array($updir, $modSettings['attachmentUploadDir']) && !empty($updir)) {
112
+			$outputCreation = automanage_attachments_create_directory($updir);
113
+	} elseif (in_array($updir, $modSettings['attachmentUploadDir'])) {
114
+			$outputCreation = true;
115
+	}
107 116
 
108 117
 	if ($outputCreation)
109 118
 	{
@@ -140,8 +149,9 @@  discard block
 block discarded – undo
140 149
 		$count = count($tree);
141 150
 
142 151
 		$directory = attachments_init_dir($tree, $count);
143
-		if ($directory === false)
144
-			return false;
152
+		if ($directory === false) {
153
+					return false;
154
+		}
145 155
 	}
146 156
 
147 157
 	$directory .= DIRECTORY_SEPARATOR . array_shift($tree);
@@ -169,8 +179,9 @@  discard block
 block discarded – undo
169 179
 	}
170 180
 
171 181
 	// Everything seems fine...let's create the .htaccess
172
-	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess'))
173
-		secureDirectory($updir, true);
182
+	if (!file_exists($directory . DIRECTORY_SEPARATOR . '.htaccess')) {
183
+			secureDirectory($updir, true);
184
+	}
174 185
 
175 186
 	$sep = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\/' : DIRECTORY_SEPARATOR;
176 187
 	$updir = rtrim($updir, $sep);
@@ -202,8 +213,9 @@  discard block
 block discarded – undo
202 213
 {
203 214
 	global $modSettings, $boarddir;
204 215
 
205
-	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1))
206
-		return;
216
+	if (!isset($modSettings['automanage_attachments']) || (!empty($modSettings['automanage_attachments']) && $modSettings['automanage_attachments'] != 1)) {
217
+			return;
218
+	}
207 219
 
208 220
 	$basedirectory = !empty($modSettings['use_subdirectories_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : $boarddir;
209 221
 	// Just to be sure: I don't want directory separators at the end
@@ -215,13 +227,14 @@  discard block
 block discarded – undo
215 227
 	{
216 228
 		$base_dir = array_search($modSettings['basedirectory_for_attachments'], $modSettings['attachment_basedirectories']);
217 229
 		$base_dir = !empty($modSettings['automanage_attachments']) ? $base_dir : 0;
230
+	} else {
231
+			$base_dir = 0;
218 232
 	}
219
-	else
220
-		$base_dir = 0;
221 233
 
222 234
 	// Get the last attachment directory for that base directory
223
-	if (empty($modSettings['last_attachments_directory'][$base_dir]))
224
-		$modSettings['last_attachments_directory'][$base_dir] = 0;
235
+	if (empty($modSettings['last_attachments_directory'][$base_dir])) {
236
+			$modSettings['last_attachments_directory'][$base_dir] = 0;
237
+	}
225 238
 	// And increment it.
226 239
 	$modSettings['last_attachments_directory'][$base_dir]++;
227 240
 
@@ -236,10 +249,10 @@  discard block
 block discarded – undo
236 249
 		$modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true);
237 250
 
238 251
 		return true;
252
+	} else {
253
+			return false;
254
+	}
239 255
 	}
240
-	else
241
-		return false;
242
-}
243 256
 
244 257
 /**
245 258
  * Split a path into a list of all directories and subdirectories
@@ -257,12 +270,13 @@  discard block
 block discarded – undo
257 270
 			* in Windows we need to explode for both \ and /
258 271
 			* while in linux should be safe to explode only for / (aka DIRECTORY_SEPARATOR)
259 272
 	*/
260
-	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
261
-		$tree = preg_split('#[\\\/]#', $directory);
262
-	else
273
+	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
274
+			$tree = preg_split('#[\\\/]#', $directory);
275
+	} else
263 276
 	{
264
-		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR)
265
-			return false;
277
+		if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
278
+					return false;
279
+		}
266 280
 
267 281
 		$tree = explode(DIRECTORY_SEPARATOR, trim($directory, DIRECTORY_SEPARATOR));
268 282
 	}
@@ -286,10 +300,11 @@  discard block
 block discarded – undo
286 300
 		 //Better be sure that the first part of the path is actually a drive letter...
287 301
 		 //...even if, I should check this in the admin page...isn't it?
288 302
 		 //...NHAAA Let's leave space for users' complains! :P
289
-		if (preg_match('/^[a-z]:$/i', $tree[0]))
290
-			$directory = array_shift($tree);
291
-		else
292
-			return false;
303
+		if (preg_match('/^[a-z]:$/i', $tree[0])) {
304
+					$directory = array_shift($tree);
305
+		} else {
306
+					return false;
307
+		}
293 308
 
294 309
 		$count--;
295 310
 	}
@@ -304,18 +319,20 @@  discard block
 block discarded – undo
304 319
 	global $context, $modSettings, $smcFunc, $txt, $user_info;
305 320
 
306 321
 	// Make sure we're uploading to the right place.
307
-	if (!empty($modSettings['automanage_attachments']))
308
-		automanage_attachments_check_directory();
322
+	if (!empty($modSettings['automanage_attachments'])) {
323
+			automanage_attachments_check_directory();
324
+	}
309 325
 
310
-	if (!is_array($modSettings['attachmentUploadDir']))
311
-		$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
326
+	if (!is_array($modSettings['attachmentUploadDir'])) {
327
+			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
328
+	}
312 329
 
313 330
 	$context['attach_dir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
314 331
 
315 332
 	// Is the attachments folder actualy there?
316
-	if (!empty($context['dir_creation_error']))
317
-		$initial_error = $context['dir_creation_error'];
318
-	elseif (!is_dir($context['attach_dir']))
333
+	if (!empty($context['dir_creation_error'])) {
334
+			$initial_error = $context['dir_creation_error'];
335
+	} elseif (!is_dir($context['attach_dir']))
319 336
 	{
320 337
 		$initial_error = 'attach_folder_warning';
321 338
 		log_error(sprintf($txt['attach_folder_admin_warning'], $context['attach_dir']), 'critical');
@@ -338,12 +355,12 @@  discard block
 block discarded – undo
338 355
 			);
339 356
 			list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request);
340 357
 			$smcFunc['db_free_result']($request);
341
-		}
342
-		else
343
-			$context['attachments'] = array(
358
+		} else {
359
+					$context['attachments'] = array(
344 360
 				'quantity' => 0,
345 361
 				'total_size' => 0,
346 362
 			);
363
+		}
347 364
 	}
348 365
 
349 366
 	// Hmm. There are still files in session.
@@ -353,39 +370,44 @@  discard block
 block discarded – undo
353 370
 		// Let's try to keep them. But...
354 371
 		$ignore_temp = true;
355 372
 		// If new files are being added. We can't ignore those
356
-		foreach ($_FILES['attachment']['tmp_name'] as $dummy)
357
-			if (!empty($dummy))
373
+		foreach ($_FILES['attachment']['tmp_name'] as $dummy) {
374
+					if (!empty($dummy))
358 375
 			{
359 376
 				$ignore_temp = false;
377
+		}
360 378
 				break;
361 379
 			}
362 380
 
363 381
 		// Need to make space for the new files. So, bye bye.
364 382
 		if (!$ignore_temp)
365 383
 		{
366
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
367
-				if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
384
+			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
385
+							if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
368 386
 					unlink($attachment['tmp_name']);
387
+			}
369 388
 
370 389
 			$context['we_are_history'] = $txt['error_temp_attachments_flushed'];
371 390
 			$_SESSION['temp_attachments'] = array();
372 391
 		}
373 392
 	}
374 393
 
375
-	if (!isset($_FILES['attachment']['name']))
376
-		$_FILES['attachment']['tmp_name'] = array();
394
+	if (!isset($_FILES['attachment']['name'])) {
395
+			$_FILES['attachment']['tmp_name'] = array();
396
+	}
377 397
 
378
-	if (!isset($_SESSION['temp_attachments']))
379
-		$_SESSION['temp_attachments'] = array();
398
+	if (!isset($_SESSION['temp_attachments'])) {
399
+			$_SESSION['temp_attachments'] = array();
400
+	}
380 401
 
381 402
 	// Remember where we are at. If it's anywhere at all.
382
-	if (!$ignore_temp)
383
-		$_SESSION['temp_attachments']['post'] = array(
403
+	if (!$ignore_temp) {
404
+			$_SESSION['temp_attachments']['post'] = array(
384 405
 			'msg' => !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : 0,
385 406
 			'last_msg' => !empty($_REQUEST['last_msg']) ? $_REQUEST['last_msg'] : 0,
386 407
 			'topic' => !empty($topic) ? $topic : 0,
387 408
 			'board' => !empty($board) ? $board : 0,
388 409
 		);
410
+	}
389 411
 
390 412
 	// If we have an initial error, lets just display it.
391 413
 	if (!empty($initial_error))
@@ -393,9 +415,10 @@  discard block
 block discarded – undo
393 415
 		$_SESSION['temp_attachments']['initial_error'] = $initial_error;
394 416
 
395 417
 		// And delete the files 'cos they ain't going nowhere.
396
-		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
397
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
418
+		foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) {
419
+					if (file_exists($_FILES['attachment']['tmp_name'][$n]))
398 420
 				unlink($_FILES['attachment']['tmp_name'][$n]);
421
+		}
399 422
 
400 423
 		$_FILES['attachment']['tmp_name'] = array();
401 424
 	}
@@ -403,21 +426,24 @@  discard block
 block discarded – undo
403 426
 	// Loop through $_FILES['attachment'] array and move each file to the current attachments folder.
404 427
 	foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
405 428
 	{
406
-		if ($_FILES['attachment']['name'][$n] == '')
407
-			continue;
429
+		if ($_FILES['attachment']['name'][$n] == '') {
430
+					continue;
431
+		}
408 432
 
409 433
 		// First, let's first check for PHP upload errors.
410 434
 		$errors = array();
411 435
 		if (!empty($_FILES['attachment']['error'][$n]))
412 436
 		{
413
-			if ($_FILES['attachment']['error'][$n] == 2)
414
-				$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
415
-			elseif ($_FILES['attachment']['error'][$n] == 6)
416
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
417
-			else
418
-				log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
419
-			if (empty($errors))
420
-				$errors[] = 'attach_php_error';
437
+			if ($_FILES['attachment']['error'][$n] == 2) {
438
+							$errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit']));
439
+			} elseif ($_FILES['attachment']['error'][$n] == 6) {
440
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical');
441
+			} else {
442
+							log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]);
443
+			}
444
+			if (empty($errors)) {
445
+							$errors[] = 'attach_php_error';
446
+			}
421 447
 		}
422 448
 
423 449
 		// Try to move and rename the file before doing any more checks on it.
@@ -435,16 +461,16 @@  discard block
 block discarded – undo
435 461
 			);
436 462
 
437 463
 			// Move the file to the attachments folder with a temp name for now.
438
-			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName))
439
-				smf_chmod($destName, 0644);
440
-			else
464
+			if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) {
465
+							smf_chmod($destName, 0644);
466
+			} else
441 467
 			{
442 468
 				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout';
443
-				if (file_exists($_FILES['attachment']['tmp_name'][$n]))
444
-					unlink($_FILES['attachment']['tmp_name'][$n]);
469
+				if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
470
+									unlink($_FILES['attachment']['tmp_name'][$n]);
471
+				}
445 472
 			}
446
-		}
447
-		else
473
+		} else
448 474
 		{
449 475
 			$_SESSION['temp_attachments'][$attachID] = array(
450 476
 				'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])),
@@ -452,12 +478,14 @@  discard block
 block discarded – undo
452 478
 				'errors' => $errors,
453 479
 			);
454 480
 
455
-			if (file_exists($_FILES['attachment']['tmp_name'][$n]))
456
-				unlink($_FILES['attachment']['tmp_name'][$n]);
481
+			if (file_exists($_FILES['attachment']['tmp_name'][$n])) {
482
+							unlink($_FILES['attachment']['tmp_name'][$n]);
483
+			}
457 484
 		}
458 485
 		// If there's no errors to this point. We still do need to apply some additional checks before we are finished.
459
-		if (empty($_SESSION['temp_attachments'][$attachID]['errors']))
460
-			attachmentChecks($attachID);
486
+		if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) {
487
+					attachmentChecks($attachID);
488
+		}
461 489
 	}
462 490
 	// Mod authors, finally a hook to hang an alternate attachment upload system upon
463 491
 	// Upload to the current attachment folder with the file name $attachID or 'post_tmp_' . $user_info['id'] . '_' . md5(mt_rand())
@@ -484,21 +512,20 @@  discard block
 block discarded – undo
484 512
 	global $modSettings, $context, $sourcedir, $smcFunc;
485 513
 
486 514
 	// No data or missing data .... Not necessarily needed, but in case a mod author missed something.
487
-	if (empty($_SESSION['temp_attachments'][$attachID]))
488
-		$error = '$_SESSION[\'temp_attachments\'][$attachID]';
489
-
490
-	elseif (empty($attachID))
491
-		$error = '$attachID';
492
-
493
-	elseif (empty($context['attachments']))
494
-		$error = '$context[\'attachments\']';
495
-
496
-	elseif (empty($context['attach_dir']))
497
-		$error = '$context[\'attach_dir\']';
515
+	if (empty($_SESSION['temp_attachments'][$attachID])) {
516
+			$error = '$_SESSION[\'temp_attachments\'][$attachID]';
517
+	} elseif (empty($attachID)) {
518
+			$error = '$attachID';
519
+	} elseif (empty($context['attachments'])) {
520
+			$error = '$context[\'attachments\']';
521
+	} elseif (empty($context['attach_dir'])) {
522
+			$error = '$context[\'attach_dir\']';
523
+	}
498 524
 
499 525
 	// Let's get their attention.
500
-	if (!empty($error))
501
-		fatal_lang_error('attach_check_nag', 'debug', array($error));
526
+	if (!empty($error)) {
527
+			fatal_lang_error('attach_check_nag', 'debug', array($error));
528
+	}
502 529
 
503 530
 	// Just in case this slipped by the first checks, we stop it here and now
504 531
 	if ($_SESSION['temp_attachments'][$attachID]['size'] == 0)
@@ -527,8 +554,9 @@  discard block
 block discarded – undo
527 554
 			$size = @getimagesize($_SESSION['temp_attachments'][$attachID]['tmp_name']);
528 555
 			if (!(empty($size)) && ($size[2] != $old_format))
529 556
 			{
530
-				if (isset($context['validImageTypes'][$size[2]]))
531
-					$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
557
+				if (isset($context['validImageTypes'][$size[2]])) {
558
+									$_SESSION['temp_attachments'][$attachID]['type'] = 'image/' . $context['validImageTypes'][$size[2]];
559
+				}
532 560
 			}
533 561
 		}
534 562
 	}
@@ -582,42 +610,48 @@  discard block
 block discarded – undo
582 610
 				// Or, let the user know that it ain't gonna happen.
583 611
 				else
584 612
 				{
585
-					if (isset($context['dir_creation_error']))
586
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
587
-					else
588
-						$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
613
+					if (isset($context['dir_creation_error'])) {
614
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = $context['dir_creation_error'];
615
+					} else {
616
+											$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
617
+					}
589 618
 				}
619
+			} else {
620
+							$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
590 621
 			}
591
-			else
592
-				$_SESSION['temp_attachments'][$attachID]['errors'][] = 'ran_out_of_space';
593 622
 		}
594 623
 	}
595 624
 
596 625
 	// Is the file too big?
597 626
 	$context['attachments']['total_size'] += $_SESSION['temp_attachments'][$attachID]['size'];
598
-	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024)
599
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
627
+	if (!empty($modSettings['attachmentSizeLimit']) && $_SESSION['temp_attachments'][$attachID]['size'] > $modSettings['attachmentSizeLimit'] * 1024) {
628
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('file_too_big', array(comma_format($modSettings['attachmentSizeLimit'], 0)));
629
+	}
600 630
 
601 631
 	// Check the total upload size for this post...
602
-	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024)
603
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
632
+	if (!empty($modSettings['attachmentPostLimit']) && $context['attachments']['total_size'] > $modSettings['attachmentPostLimit'] * 1024) {
633
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attach_max_total_file_size', array(comma_format($modSettings['attachmentPostLimit'], 0), comma_format($modSettings['attachmentPostLimit'] - (($context['attachments']['total_size'] - $_SESSION['temp_attachments'][$attachID]['size']) / 1024), 0)));
634
+	}
604 635
 
605 636
 	// Have we reached the maximum number of files we are allowed?
606 637
 	$context['attachments']['quantity']++;
607 638
 
608 639
 	// Set a max limit if none exists
609
-	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50)
610
-		$modSettings['attachmentNumPerPostLimit'] = 50;
640
+	if (empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] >= 50) {
641
+			$modSettings['attachmentNumPerPostLimit'] = 50;
642
+	}
611 643
 
612
-	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit'])
613
-		$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
644
+	if (!empty($modSettings['attachmentNumPerPostLimit']) && $context['attachments']['quantity'] > $modSettings['attachmentNumPerPostLimit']) {
645
+			$_SESSION['temp_attachments'][$attachID]['errors'][] = array('attachments_limit_per_post', array($modSettings['attachmentNumPerPostLimit']));
646
+	}
614 647
 
615 648
 	// File extension check
616 649
 	if (!empty($modSettings['attachmentCheckExtensions']))
617 650
 	{
618 651
 		$allowed = explode(',', strtolower($modSettings['attachmentExtensions']));
619
-		foreach ($allowed as $k => $dummy)
620
-			$allowed[$k] = trim($dummy);
652
+		foreach ($allowed as $k => $dummy) {
653
+					$allowed[$k] = trim($dummy);
654
+		}
621 655
 
622 656
 		if (!in_array(strtolower(substr(strrchr($_SESSION['temp_attachments'][$attachID]['name'], '.'), 1)), $allowed))
623 657
 		{
@@ -629,10 +663,12 @@  discard block
 block discarded – undo
629 663
 	// Undo the math if there's an error
630 664
 	if (!empty($_SESSION['temp_attachments'][$attachID]['errors']))
631 665
 	{
632
-		if (isset($context['dir_size']))
633
-			$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
634
-		if (isset($context['dir_files']))
635
-			$context['dir_files']--;
666
+		if (isset($context['dir_size'])) {
667
+					$context['dir_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
668
+		}
669
+		if (isset($context['dir_files'])) {
670
+					$context['dir_files']--;
671
+		}
636 672
 		$context['attachments']['total_size'] -= $_SESSION['temp_attachments'][$attachID]['size'];
637 673
 		$context['attachments']['quantity']--;
638 674
 		return false;
@@ -664,12 +700,14 @@  discard block
 block discarded – undo
664 700
 	if (empty($attachmentOptions['mime_type']) && $attachmentOptions['width'])
665 701
 	{
666 702
 		// Got a proper mime type?
667
-		if (!empty($size['mime']))
668
-			$attachmentOptions['mime_type'] = $size['mime'];
703
+		if (!empty($size['mime'])) {
704
+					$attachmentOptions['mime_type'] = $size['mime'];
705
+		}
669 706
 
670 707
 		// Otherwise a valid one?
671
-		elseif (isset($context['validImageTypes'][$size[2]]))
672
-			$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
708
+		elseif (isset($context['validImageTypes'][$size[2]])) {
709
+					$attachmentOptions['mime_type'] = 'image/' . $context['validImageTypes'][$size[2]];
710
+		}
673 711
 	}
674 712
 
675 713
 	// It is possible we might have a MIME type that isn't actually an image but still have a size.
@@ -681,15 +719,17 @@  discard block
 block discarded – undo
681 719
 	}
682 720
 
683 721
 	// Get the hash if no hash has been given yet.
684
-	if (empty($attachmentOptions['file_hash']))
685
-		$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
722
+	if (empty($attachmentOptions['file_hash'])) {
723
+			$attachmentOptions['file_hash'] = getAttachmentFilename($attachmentOptions['name'], false, null, true);
724
+	}
686 725
 
687 726
 	// Assuming no-one set the extension let's take a look at it.
688 727
 	if (empty($attachmentOptions['fileext']))
689 728
 	{
690 729
 		$attachmentOptions['fileext'] = strtolower(strrpos($attachmentOptions['name'], '.') !== false ? substr($attachmentOptions['name'], strrpos($attachmentOptions['name'], '.') + 1) : '');
691
-		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name'])
692
-			$attachmentOptions['fileext'] = '';
730
+		if (strlen($attachmentOptions['fileext']) > 8 || '.' . $attachmentOptions['fileext'] == $attachmentOptions['name']) {
731
+					$attachmentOptions['fileext'] = '';
732
+		}
693 733
 	}
694 734
 
695 735
 	// Last chance to change stuff!
@@ -698,8 +738,9 @@  discard block
 block discarded – undo
698 738
 	// Make sure the folder is valid...
699 739
 	$tmp = is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'] : smf_json_decode($modSettings['attachmentUploadDir'], true);
700 740
 	$folders = array_keys($tmp);
701
-	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders))
702
-		$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
741
+	if (empty($attachmentOptions['id_folder']) || !in_array($attachmentOptions['id_folder'], $folders)) {
742
+			$attachmentOptions['id_folder'] = $modSettings['currentAttachmentUploadDir'];
743
+	}
703 744
 
704 745
 	$smcFunc['db_insert']('',
705 746
 		'{db_prefix}attachments',
@@ -730,8 +771,8 @@  discard block
 block discarded – undo
730 771
 	rename($attachmentOptions['tmp_name'], $attachmentOptions['destination']);
731 772
 
732 773
 	// If it's not approved then add to the approval queue.
733
-	if (!$attachmentOptions['approved'])
734
-		$smcFunc['db_insert']('',
774
+	if (!$attachmentOptions['approved']) {
775
+			$smcFunc['db_insert']('',
735 776
 			'{db_prefix}approval_queue',
736 777
 			array(
737 778
 				'id_attach' => 'int', 'id_msg' => 'int',
@@ -741,9 +782,11 @@  discard block
 block discarded – undo
741 782
 			),
742 783
 			array()
743 784
 		);
785
+	}
744 786
 
745
-	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height'])))
746
-		return true;
787
+	if (empty($modSettings['attachmentThumbnails']) || (empty($attachmentOptions['width']) && empty($attachmentOptions['height']))) {
788
+			return true;
789
+	}
747 790
 
748 791
 	// Like thumbnails, do we?
749 792
 	if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && ($attachmentOptions['width'] > $modSettings['attachmentThumbWidth'] || $attachmentOptions['height'] > $modSettings['attachmentThumbHeight']))
@@ -754,13 +797,15 @@  discard block
 block discarded – undo
754 797
 			$size = @getimagesize($attachmentOptions['destination'] . '_thumb');
755 798
 			list ($thumb_width, $thumb_height) = $size;
756 799
 
757
-			if (!empty($size['mime']))
758
-				$thumb_mime = $size['mime'];
759
-			elseif (isset($context['validImageTypes'][$size[2]]))
760
-				$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
800
+			if (!empty($size['mime'])) {
801
+							$thumb_mime = $size['mime'];
802
+			} elseif (isset($context['validImageTypes'][$size[2]])) {
803
+							$thumb_mime = 'image/' . $context['validImageTypes'][$size[2]];
804
+			}
761 805
 			// Lord only knows how this happened...
762
-			else
763
-				$thumb_mime = '';
806
+			else {
807
+							$thumb_mime = '';
808
+			}
764 809
 
765 810
 			$thumb_filename = $attachmentOptions['name'] . '_thumb';
766 811
 			$thumb_size = filesize($attachmentOptions['destination'] . '_thumb');
@@ -840,15 +885,17 @@  discard block
 block discarded – undo
840 885
 	global $smcFunc;
841 886
 
842 887
 	// Oh, come on!
843
-	if (empty($attachIDs) || empty($msgID))
844
-		return false;
888
+	if (empty($attachIDs) || empty($msgID)) {
889
+			return false;
890
+	}
845 891
 
846 892
 	// "I see what is right and approve, but I do what is wrong."
847 893
 	call_integration_hook('integrate_assign_attachments', array(&$attachIDs, &$msgID));
848 894
 
849 895
 	// One last check
850
-	if (empty($attachIDs))
851
-		return false;
896
+	if (empty($attachIDs)) {
897
+			return false;
898
+	}
852 899
 
853 900
 	// Perform.
854 901
 	$smcFunc['db_query']('', '
@@ -880,8 +927,9 @@  discard block
 block discarded – undo
880 927
 	$externalParse = false;
881 928
 
882 929
 	// Meh...
883
-	if (empty($attachID))
884
-		return 'attachments_no_data_loaded';
930
+	if (empty($attachID)) {
931
+			return 'attachments_no_data_loaded';
932
+	}
885 933
 
886 934
 	// Make it easy.
887 935
 	$msgID = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
@@ -890,20 +938,23 @@  discard block
 block discarded – undo
890 938
 	$externalParse = call_integration_hook('integrate_pre_parseAttachBBC', array($attachID, $msgID));
891 939
 
892 940
 	// "I am innocent of the blood of this just person: see ye to it."
893
-	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse)))
894
-		return $externalParse;
941
+	if (!empty($externalParse) && (is_string($externalParse) || is_array($externalParse))) {
942
+			return $externalParse;
943
+	}
895 944
 
896 945
 	//Are attachments enable?
897
-	if (empty($modSettings['attachmentEnable']))
898
-		return 'attachments_not_enable';
946
+	if (empty($modSettings['attachmentEnable'])) {
947
+			return 'attachments_not_enable';
948
+	}
899 949
 
900 950
 	// Previewing much? no msg ID has been set yet.
901 951
 	if (!empty($context['preview_message']))
902 952
 	{
903 953
 		$allAttachments = getAttachsByMsg(0);
904 954
 
905
-		if (empty($allAttachments[0][$attachID]))
906
-			return 'attachments_no_data_loaded';
955
+		if (empty($allAttachments[0][$attachID])) {
956
+					return 'attachments_no_data_loaded';
957
+		}
907 958
 
908 959
 		$attachContext = $allAttachments[0][$attachID];
909 960
 		$attachLoaded = loadAttachmentContext(0, $allAttachments);
@@ -916,57 +967,66 @@  discard block
 block discarded – undo
916 967
 		$attachContext['link'] = '<a href="' . $scripturl . '?action=dlattach;attach=' . $attachID . ';type=preview' . (empty($attachContext['is_image']) ? ';file' : '') . '">' . $smcFunc['htmlspecialchars']($attachContext['name']) . '</a>';
917 968
 
918 969
 		// Fix the thumbnail too, if the image has one.
919
-		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb']))
920
-			$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
970
+		if (!empty($attachContext['thumbnail']) && !empty($attachContext['thumbnail']['has_thumb'])) {
971
+					$attachContext['thumbnail']['href'] = $scripturl . '?action=dlattach;attach=' . $attachContext['thumbnail']['id'] . ';image;type=preview';
972
+		}
921 973
 
922 974
 		return $attachContext;
923 975
 	}
924 976
 
925 977
 	// There is always the chance someone else has already done our dirty work...
926 978
 	// If so, all pertinent checks were already done. Hopefully...
927
-	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID]))
928
-		return $context['current_attachments'][$attachID];
979
+	if (!empty($context['current_attachments']) && !empty($context['current_attachments'][$attachID])) {
980
+			return $context['current_attachments'][$attachID];
981
+	}
929 982
 
930 983
 	// If we are lucky enough to be in $board's scope then check it!
931
-	if (!empty($board) && !allowedTo('view_attachments', $board))
932
-		return 'attachments_not_allowed_to_see';
984
+	if (!empty($board) && !allowedTo('view_attachments', $board)) {
985
+			return 'attachments_not_allowed_to_see';
986
+	}
933 987
 
934 988
 	// Get the message info associated with this particular attach ID.
935 989
 	$attachInfo = getAttachMsgInfo($attachID);
936 990
 
937 991
 	// There is always the chance this attachment no longer exists or isn't associated to a message anymore...
938
-	if (empty($attachInfo) || empty($attachInfo['msg']))
939
-		return 'attachments_no_msg_associated';
992
+	if (empty($attachInfo) || empty($attachInfo['msg'])) {
993
+			return 'attachments_no_msg_associated';
994
+	}
940 995
 
941 996
 	// Hold it! got the info now check if you can see this attachment.
942
-	if (!allowedTo('view_attachments', $attachInfo['board']))
943
-		return 'attachments_not_allowed_to_see';
997
+	if (!allowedTo('view_attachments', $attachInfo['board'])) {
998
+			return 'attachments_not_allowed_to_see';
999
+	}
944 1000
 
945 1001
 	$allAttachments = getAttachsByMsg($attachInfo['msg']);
946 1002
 	$attachContext = $allAttachments[$attachInfo['msg']][$attachID];
947 1003
 
948 1004
 	// No point in keep going further.
949
-	if (!allowedTo('view_attachments', $attachContext['board']))
950
-		return 'attachments_not_allowed_to_see';
1005
+	if (!allowedTo('view_attachments', $attachContext['board'])) {
1006
+			return 'attachments_not_allowed_to_see';
1007
+	}
951 1008
 
952 1009
 	// Load this particular attach's context.
953
-	if (!empty($attachContext))
954
-		$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1010
+	if (!empty($attachContext)) {
1011
+			$attachLoaded = loadAttachmentContext($attachContext['id_msg'], $allAttachments);
1012
+	}
955 1013
 
956 1014
 	// One last check, you know, gotta be paranoid...
957
-	else
958
-		return 'attachments_no_data_loaded';
1015
+	else {
1016
+			return 'attachments_no_data_loaded';
1017
+	}
959 1018
 
960 1019
 	// This is the last "if" I promise!
961
-	if (empty($attachLoaded))
962
-		return 'attachments_no_data_loaded';
963
-
964
-	else
965
-		$attachContext = $attachLoaded[$attachID];
1020
+	if (empty($attachLoaded)) {
1021
+			return 'attachments_no_data_loaded';
1022
+	} else {
1023
+			$attachContext = $attachLoaded[$attachID];
1024
+	}
966 1025
 
967 1026
 	// You may or may not want to show this under the post.
968
-	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID]))
969
-		$context['show_attach_under_post'][$attachID] = $attachID;
1027
+	if (!empty($modSettings['dont_show_attach_under_post']) && !isset($context['show_attach_under_post'][$attachID])) {
1028
+			$context['show_attach_under_post'][$attachID] = $attachID;
1029
+	}
970 1030
 
971 1031
 	// Last minute changes?
972 1032
 	call_integration_hook('integrate_post_parseAttachBBC', array(&$attachContext));
@@ -986,8 +1046,9 @@  discard block
 block discarded – undo
986 1046
 {
987 1047
 	global $smcFunc, $modSettings;
988 1048
 
989
-	if (empty($attachIDs))
990
-		return array();
1049
+	if (empty($attachIDs)) {
1050
+			return array();
1051
+	}
991 1052
 
992 1053
 	$return = array();
993 1054
 
@@ -1003,11 +1064,12 @@  discard block
 block discarded – undo
1003 1064
 		)
1004 1065
 	);
1005 1066
 
1006
-	if ($smcFunc['db_num_rows']($request) != 1)
1007
-		return array();
1067
+	if ($smcFunc['db_num_rows']($request) != 1) {
1068
+			return array();
1069
+	}
1008 1070
 
1009
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1010
-		$return[$row['id_attach']] = array(
1071
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1072
+			$return[$row['id_attach']] = array(
1011 1073
 			'name' => $smcFunc['htmlspecialchars']($row['filename']),
1012 1074
 			'size' => $row['size'],
1013 1075
 			'attachID' => $row['id_attach'],
@@ -1016,6 +1078,7 @@  discard block
 block discarded – undo
1016 1078
 			'mime_type' => $row['mime_type'],
1017 1079
 			'thumb' => $row['id_thumb'],
1018 1080
 		);
1081
+	}
1019 1082
 	$smcFunc['db_free_result']($request);
1020 1083
 
1021 1084
 	return $return;
@@ -1032,8 +1095,9 @@  discard block
 block discarded – undo
1032 1095
 {
1033 1096
 	global $smcFunc;
1034 1097
 
1035
-	if (empty($attachID))
1036
-		return array();
1098
+	if (empty($attachID)) {
1099
+			return array();
1100
+	}
1037 1101
 
1038 1102
 	$request = $smcFunc['db_query']('', '
1039 1103
 		SELECT a.id_msg AS msg, m.id_topic AS topic, m.id_board AS board
@@ -1046,8 +1110,9 @@  discard block
 block discarded – undo
1046 1110
 		)
1047 1111
 	);
1048 1112
 
1049
-	if ($smcFunc['db_num_rows']($request) != 1)
1050
-		return array();
1113
+	if ($smcFunc['db_num_rows']($request) != 1) {
1114
+			return array();
1115
+	}
1051 1116
 
1052 1117
 	$row = $smcFunc['db_fetch_assoc']($request);
1053 1118
 	$smcFunc['db_free_result']($request);
@@ -1088,8 +1153,9 @@  discard block
 block discarded – undo
1088 1153
 		$temp = array();
1089 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1090 1155
 		{
1091
-			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1092
-				continue;
1156
+			if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1157
+							continue;
1158
+			}
1093 1159
 
1094 1160
 			$temp[$row['id_attach']] = $row;
1095 1161
 		}
@@ -1118,8 +1184,9 @@  discard block
 block discarded – undo
1118 1184
 {
1119 1185
 	global $modSettings, $txt, $scripturl, $sourcedir, $smcFunc;
1120 1186
 
1121
-	if (empty($attachments) || empty($attachments[$id_msg]))
1122
-		return array();
1187
+	if (empty($attachments) || empty($attachments[$id_msg])) {
1188
+			return array();
1189
+	}
1123 1190
 
1124 1191
 	// Set up the attachment info - based on code by Meriadoc.
1125 1192
 	$attachmentData = array();
@@ -1143,11 +1210,13 @@  discard block
 block discarded – undo
1143 1210
 			);
1144 1211
 
1145 1212
 			// If something is unapproved we'll note it so we can sort them.
1146
-			if (!$attachment['approved'])
1147
-				$have_unapproved = true;
1213
+			if (!$attachment['approved']) {
1214
+							$have_unapproved = true;
1215
+			}
1148 1216
 
1149
-			if (!$attachmentData[$i]['is_image'])
1150
-				continue;
1217
+			if (!$attachmentData[$i]['is_image']) {
1218
+							continue;
1219
+			}
1151 1220
 
1152 1221
 			$attachmentData[$i]['real_width'] = $attachment['width'];
1153 1222
 			$attachmentData[$i]['width'] = $attachment['width'];
@@ -1168,12 +1237,12 @@  discard block
 block discarded – undo
1168 1237
 						// So what folder are we putting this image in?
1169 1238
 						if (!empty($modSettings['currentAttachmentUploadDir']))
1170 1239
 						{
1171
-							if (!is_array($modSettings['attachmentUploadDir']))
1172
-								$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1240
+							if (!is_array($modSettings['attachmentUploadDir'])) {
1241
+															$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
1242
+							}
1173 1243
 							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
1174 1244
 							$id_folder_thumb = $modSettings['currentAttachmentUploadDir'];
1175
-						}
1176
-						else
1245
+						} else
1177 1246
 						{
1178 1247
 							$path = $modSettings['attachmentUploadDir'];
1179 1248
 							$id_folder_thumb = 1;
@@ -1188,10 +1257,11 @@  discard block
 block discarded – undo
1188 1257
 						$thumb_ext = isset($context['validImageTypes'][$size[2]]) ? $context['validImageTypes'][$size[2]] : '';
1189 1258
 
1190 1259
 						// Figure out the mime type.
1191
-						if (!empty($size['mime']))
1192
-							$thumb_mime = $size['mime'];
1193
-						else
1194
-							$thumb_mime = 'image/' . $thumb_ext;
1260
+						if (!empty($size['mime'])) {
1261
+													$thumb_mime = $size['mime'];
1262
+						} else {
1263
+													$thumb_mime = 'image/' . $thumb_ext;
1264
+						}
1195 1265
 
1196 1266
 						$thumb_filename = $attachment['filename'] . '_thumb';
1197 1267
 						$thumb_hash = getAttachmentFilename($thumb_filename, false, null, true);
@@ -1238,11 +1308,12 @@  discard block
 block discarded – undo
1238 1308
 				}
1239 1309
 			}
1240 1310
 
1241
-			if (!empty($attachment['id_thumb']))
1242
-				$attachmentData[$i]['thumbnail'] = array(
1311
+			if (!empty($attachment['id_thumb'])) {
1312
+							$attachmentData[$i]['thumbnail'] = array(
1243 1313
 					'id' => $attachment['id_thumb'],
1244 1314
 					'href' => $scripturl . '?action=dlattach;topic=' . $attachment['topic'] . '.0;attach=' . $attachment['id_thumb'] . ';image',
1245 1315
 				);
1316
+			}
1246 1317
 			$attachmentData[$i]['thumbnail']['has_thumb'] = !empty($attachment['id_thumb']);
1247 1318
 
1248 1319
 			// If thumbnails are disabled, check the maximum size of the image.
@@ -1252,30 +1323,31 @@  discard block
 block discarded – undo
1252 1323
 				{
1253 1324
 					$attachmentData[$i]['width'] = $modSettings['max_image_width'];
1254 1325
 					$attachmentData[$i]['height'] = floor($attachment['height'] * $modSettings['max_image_width'] / $attachment['width']);
1255
-				}
1256
-				elseif (!empty($modSettings['max_image_width']))
1326
+				} elseif (!empty($modSettings['max_image_width']))
1257 1327
 				{
1258 1328
 					$attachmentData[$i]['width'] = floor($attachment['width'] * $modSettings['max_image_height'] / $attachment['height']);
1259 1329
 					$attachmentData[$i]['height'] = $modSettings['max_image_height'];
1260 1330
 				}
1261
-			}
1262
-			elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1331
+			} elseif ($attachmentData[$i]['thumbnail']['has_thumb'])
1263 1332
 			{
1264 1333
 				// If the image is too large to show inline, make it a popup.
1265
-				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height'])))
1266
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1267
-				else
1268
-					$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1334
+				if (((!empty($modSettings['max_image_width']) && $attachmentData[$i]['real_width'] > $modSettings['max_image_width']) || (!empty($modSettings['max_image_height']) && $attachmentData[$i]['real_height'] > $modSettings['max_image_height']))) {
1335
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return reqWin(\'' . $attachmentData[$i]['href'] . ';image\', ' . ($attachment['width'] + 20) . ', ' . ($attachment['height'] + 20) . ', true);';
1336
+				} else {
1337
+									$attachmentData[$i]['thumbnail']['javascript'] = 'return expandThumb(' . $attachment['id_attach'] . ');';
1338
+				}
1269 1339
 			}
1270 1340
 
1271
-			if (!$attachmentData[$i]['thumbnail']['has_thumb'])
1272
-				$attachmentData[$i]['downloads']++;
1341
+			if (!$attachmentData[$i]['thumbnail']['has_thumb']) {
1342
+							$attachmentData[$i]['downloads']++;
1343
+			}
1273 1344
 		}
1274 1345
 	}
1275 1346
 
1276 1347
 	// Do we need to instigate a sort?
1277
-	if ($have_unapproved)
1278
-		usort($attachmentData, 'approved_attach_sort');
1348
+	if ($have_unapproved) {
1349
+			usort($attachmentData, 'approved_attach_sort');
1350
+	}
1279 1351
 
1280 1352
 	return $attachmentData;
1281 1353
 }
Please login to merge, or discard this patch.