Completed
Pull Request — release-2.1 (#4156)
by 01
13:04 queued 03:20
created
Sources/MoveTopic.php 1 patch
Braces   +101 added lines, -72 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * This function allows to move a topic, making sure to ask the moderator
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 {
33 34
 	global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir;
34 35
 
35
-	if (empty($topic))
36
-		fatal_lang_error('no_access', false);
36
+	if (empty($topic)) {
37
+			fatal_lang_error('no_access', false);
38
+	}
37 39
 
38 40
 	$request = $smcFunc['db_query']('', '
39 41
 		SELECT t.id_member_started, ms.subject, t.approved
@@ -49,8 +51,9 @@  discard block
 block discarded – undo
49 51
 	$smcFunc['db_free_result']($request);
50 52
 
51 53
 	// Can they see it - if not approved?
52
-	if ($modSettings['postmod_active'] && !$context['is_approved'])
53
-		isAllowedTo('approve_posts');
54
+	if ($modSettings['postmod_active'] && !$context['is_approved']) {
55
+			isAllowedTo('approve_posts');
56
+	}
54 57
 
55 58
 	// Permission check!
56 59
 	// @todo
@@ -59,9 +62,9 @@  discard block
 block discarded – undo
59 62
 		if ($id_member_started == $user_info['id'])
60 63
 		{
61 64
 			isAllowedTo('move_own');
65
+		} else {
66
+					isAllowedTo('move_any');
62 67
 		}
63
-		else
64
-			isAllowedTo('move_any');
65 68
 	}
66 69
 
67 70
 	$context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any'];
@@ -83,11 +86,13 @@  discard block
 block discarded – undo
83 86
 		'not_redirection' => true,
84 87
 	);
85 88
 
86
-	if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board)
87
-		$options['selected_board'] = $_SESSION['move_to_topic'];
89
+	if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) {
90
+			$options['selected_board'] = $_SESSION['move_to_topic'];
91
+	}
88 92
 
89
-	if (!$context['move_any'])
90
-		$options['included_boards'] = $boards;
93
+	if (!$context['move_any']) {
94
+			$options['included_boards'] = $boards;
95
+	}
91 96
 
92 97
 	require_once($sourcedir . '/Subs-MessageIndex.php');
93 98
 	$context['categories'] = getBoardList($options);
@@ -138,12 +143,14 @@  discard block
 block discarded – undo
138 143
 	global $txt, $topic, $scripturl, $sourcedir, $context;
139 144
 	global $board, $language, $user_info, $smcFunc;
140 145
 
141
-	if (empty($topic))
142
-		fatal_lang_error('no_access', false);
146
+	if (empty($topic)) {
147
+			fatal_lang_error('no_access', false);
148
+	}
143 149
 
144 150
 	// You can't choose to have a redirection topic and use an empty reason.
145
-	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == ''))
146
-		fatal_lang_error('movetopic_no_reason', false);
151
+	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) {
152
+			fatal_lang_error('movetopic_no_reason', false);
153
+	}
147 154
 
148 155
 	moveTopicConcurrence();
149 156
 
@@ -163,16 +170,18 @@  discard block
 block discarded – undo
163 170
 	$smcFunc['db_free_result']($request);
164 171
 
165 172
 	// Can they see it?
166
-	if (!$context['is_approved'])
167
-		isAllowedTo('approve_posts');
173
+	if (!$context['is_approved']) {
174
+			isAllowedTo('approve_posts');
175
+	}
168 176
 
169 177
 	// Can they move topics on this board?
170 178
 	if (!allowedTo('move_any'))
171 179
 	{
172
-		if ($id_member_started == $user_info['id'])
173
-			isAllowedTo('move_own');
174
-		else
175
-			isAllowedTo('move_any');
180
+		if ($id_member_started == $user_info['id']) {
181
+					isAllowedTo('move_own');
182
+		} else {
183
+					isAllowedTo('move_any');
184
+		}
176 185
 	}
177 186
 
178 187
 	checkSession();
@@ -197,8 +206,9 @@  discard block
 block discarded – undo
197 206
 			'blank_redirect' => '',
198 207
 		)
199 208
 	);
200
-	if ($smcFunc['db_num_rows']($request) == 0)
201
-		fatal_lang_error('no_board');
209
+	if ($smcFunc['db_num_rows']($request) == 0) {
210
+			fatal_lang_error('no_board');
211
+	}
202 212
 	list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request);
203 213
 	$smcFunc['db_free_result']($request);
204 214
 
@@ -210,8 +220,9 @@  discard block
 block discarded – undo
210 220
 	{
211 221
 		$_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => ''));
212 222
 		// Keep checking the length.
213
-		if ($smcFunc['strlen']($_POST['custom_subject']) > 100)
214
-			$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
223
+		if ($smcFunc['strlen']($_POST['custom_subject']) > 100) {
224
+					$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
225
+		}
215 226
 
216 227
 		// If it's still valid move onwards and upwards.
217 228
 		if ($_POST['custom_subject'] != '')
@@ -221,9 +232,9 @@  discard block
 block discarded – undo
221 232
 				// Get a response prefix, but in the forum's default language.
222 233
 				if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
223 234
 				{
224
-					if ($language === $user_info['language'])
225
-						$context['response_prefix'] = $txt['response_prefix'];
226
-					else
235
+					if ($language === $user_info['language']) {
236
+											$context['response_prefix'] = $txt['response_prefix'];
237
+					} else
227 238
 					{
228 239
 						loadLanguage('index', $language, false);
229 240
 						$context['response_prefix'] = $txt['response_prefix'];
@@ -263,8 +274,9 @@  discard block
 block discarded – undo
263 274
 	if (isset($_POST['postRedirect']))
264 275
 	{
265 276
 		// Should be in the boardwide language.
266
-		if ($user_info['language'] != $language)
267
-			loadLanguage('index', $language);
277
+		if ($user_info['language'] != $language) {
278
+					loadLanguage('index', $language);
279
+		}
268 280
 
269 281
 		$_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES);
270 282
 		preparsecode($_POST['reason']);
@@ -328,8 +340,9 @@  discard block
 block discarded – undo
328 340
 		$posters = array();
329 341
 		while ($row = $smcFunc['db_fetch_assoc']($request))
330 342
 		{
331
-			if (!isset($posters[$row['id_member']]))
332
-				$posters[$row['id_member']] = 0;
343
+			if (!isset($posters[$row['id_member']])) {
344
+							$posters[$row['id_member']] = 0;
345
+			}
333 346
 
334 347
 			$posters[$row['id_member']]++;
335 348
 		}
@@ -338,11 +351,13 @@  discard block
 block discarded – undo
338 351
 		foreach ($posters as $id_member => $posts)
339 352
 		{
340 353
 			// The board we're moving from counted posts, but not to.
341
-			if (empty($pcounter_from))
342
-				updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
354
+			if (empty($pcounter_from)) {
355
+							updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
356
+			}
343 357
 			// The reverse: from didn't, to did.
344
-			else
345
-				updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
358
+			else {
359
+							updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
360
+			}
346 361
 		}
347 362
 	}
348 363
 
@@ -350,17 +365,19 @@  discard block
 block discarded – undo
350 365
 	moveTopics($topic, $_POST['toboard']);
351 366
 
352 367
 	// Log that they moved this topic.
353
-	if (!allowedTo('move_own') || $id_member_started != $user_info['id'])
354
-		logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
368
+	if (!allowedTo('move_own') || $id_member_started != $user_info['id']) {
369
+			logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
370
+	}
355 371
 	// Notify people that this topic has been moved?
356 372
 	sendNotifications($topic, 'move');
357 373
 
358 374
 	// Why not go back to the original board in case they want to keep moving?
359
-	if (!isset($_REQUEST['goback']))
360
-		redirectexit('board=' . $board . '.0');
361
-	else
362
-		redirectexit('topic=' . $topic . '.0');
363
-}
375
+	if (!isset($_REQUEST['goback'])) {
376
+			redirectexit('board=' . $board . '.0');
377
+	} else {
378
+			redirectexit('topic=' . $topic . '.0');
379
+	}
380
+	}
364 381
 
365 382
 /**
366 383
  * Moves one or more topics to a specific board. (doesn't check permissions.)
@@ -376,18 +393,21 @@  discard block
 block discarded – undo
376 393
 	global $sourcedir, $user_info, $modSettings, $smcFunc;
377 394
 
378 395
 	// Empty array?
379
-	if (empty($topics))
380
-		return;
396
+	if (empty($topics)) {
397
+			return;
398
+	}
381 399
 
382 400
 	// Only a single topic.
383
-	if (is_numeric($topics))
384
-		$topics = array($topics);
401
+	if (is_numeric($topics)) {
402
+			$topics = array($topics);
403
+	}
385 404
 
386 405
 	$fromBoards = array();
387 406
 
388 407
 	// Destination board empty or equal to 0?
389
-	if (empty($toBoard))
390
-		return;
408
+	if (empty($toBoard)) {
409
+			return;
410
+	}
391 411
 
392 412
 	// Are we moving to the recycle board?
393 413
 	$isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard;
@@ -395,8 +415,9 @@  discard block
 block discarded – undo
395 415
 	// Callback for search APIs to do their thing
396 416
 	require_once($sourcedir . '/Search.php');
397 417
 	$searchAPI = findSearchAPI();
398
-	if ($searchAPI->supportsMethod('topicsMoved'))
399
-		$searchAPI->topicsMoved($topics, $toBoard);
418
+	if ($searchAPI->supportsMethod('topicsMoved')) {
419
+			$searchAPI->topicsMoved($topics, $toBoard);
420
+	}
400 421
 
401 422
 	// Determine the source boards...
402 423
 	$request = $smcFunc['db_query']('', '
@@ -410,8 +431,9 @@  discard block
 block discarded – undo
410 431
 		)
411 432
 	);
412 433
 	// Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards.
413
-	if ($smcFunc['db_num_rows']($request) == 0)
414
-		return;
434
+	if ($smcFunc['db_num_rows']($request) == 0) {
435
+			return;
436
+	}
415 437
 	while ($row = $smcFunc['db_fetch_assoc']($request))
416 438
 	{
417 439
 		if (!isset($fromBoards[$row['id_board']]['num_posts']))
@@ -429,10 +451,11 @@  discard block
 block discarded – undo
429 451
 		$fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
430 452
 
431 453
 		// Add the topics to the right type.
432
-		if ($row['approved'])
433
-			$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
434
-		else
435
-			$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
454
+		if ($row['approved']) {
455
+					$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
456
+		} else {
457
+					$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
458
+		}
436 459
 	}
437 460
 	$smcFunc['db_free_result']($request);
438 461
 
@@ -558,13 +581,14 @@  discard block
 block discarded – undo
558 581
 			)
559 582
 		);
560 583
 		$approval_msgs = array();
561
-		while ($row = $smcFunc['db_fetch_assoc']($request))
562
-			$approval_msgs[] = $row['id_msg'];
584
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
585
+					$approval_msgs[] = $row['id_msg'];
586
+		}
563 587
 		$smcFunc['db_free_result']($request);
564 588
 
565 589
 		// Empty the approval queue for these, as we're going to approve them next.
566
-		if (!empty($approval_msgs))
567
-			$smcFunc['db_query']('', '
590
+		if (!empty($approval_msgs)) {
591
+					$smcFunc['db_query']('', '
568 592
 				DELETE FROM {db_prefix}approval_queue
569 593
 				WHERE id_msg IN ({array_int:message_list})
570 594
 					AND id_attach = {int:id_attach}',
@@ -573,6 +597,7 @@  discard block
 block discarded – undo
573 597
 					'id_attach' => 0,
574 598
 				)
575 599
 			);
600
+		}
576 601
 
577 602
 		// Get all the current max and mins.
578 603
 		$request = $smcFunc['db_query']('', '
@@ -606,8 +631,8 @@  discard block
 block discarded – undo
606 631
 		while ($row = $smcFunc['db_fetch_assoc']($request))
607 632
 		{
608 633
 			// If not, update.
609
-			if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max'])
610
-				$smcFunc['db_query']('', '
634
+			if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) {
635
+							$smcFunc['db_query']('', '
611 636
 					UPDATE {db_prefix}topics
612 637
 					SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg}
613 638
 					WHERE id_topic = {int:selected_topic}',
@@ -617,6 +642,7 @@  discard block
 block discarded – undo
617 642
 						'selected_topic' => $row['id_topic'],
618 643
 					)
619 644
 				);
645
+			}
620 646
 		}
621 647
 		$smcFunc['db_free_result']($request);
622 648
 	}
@@ -675,9 +701,10 @@  discard block
 block discarded – undo
675 701
 	}
676 702
 
677 703
 	// Update the cache?
678
-	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
679
-		foreach ($topics as $topic_id)
704
+	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) {
705
+			foreach ($topics as $topic_id)
680 706
 			cache_put_data('topic_board-' . $topic_id, null, 120);
707
+	}
681 708
 
682 709
 	require_once($sourcedir . '/Subs-Post.php');
683 710
 
@@ -701,15 +728,17 @@  discard block
 block discarded – undo
701 728
 {
702 729
 	global $board, $topic, $smcFunc, $scripturl;
703 730
 
704
-	if (isset($_GET['current_board']))
705
-		$move_from = (int) $_GET['current_board'];
731
+	if (isset($_GET['current_board'])) {
732
+			$move_from = (int) $_GET['current_board'];
733
+	}
706 734
 
707
-	if (empty($move_from) || empty($board) || empty($topic))
708
-		return true;
735
+	if (empty($move_from) || empty($board) || empty($topic)) {
736
+			return true;
737
+	}
709 738
 
710
-	if ($move_from == $board)
711
-		return true;
712
-	else
739
+	if ($move_from == $board) {
740
+			return true;
741
+	} else
713 742
 	{
714 743
 		$request = $smcFunc['db_query']('', '
715 744
 			SELECT m.subject, b.name
Please login to merge, or discard this patch.
Sources/Display.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 		call_integration_hook('integrate_poll_buttons');
825 825
 	}
826 826
 	
827
-	if(!empty($_REQUEST['page_id']))
827
+	if (!empty($_REQUEST['page_id']))
828 828
 		$start_char = substr($_REQUEST['page_id'], 0, 1);
829 829
 	else
830 830
 		$start_char = null;
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 			SELECT id_msg, id_member, approved
887 887
 			FROM {db_prefix}messages
888 888
 			WHERE id_topic = {int:current_topic} 
889
-			AND id_msg '. $page_operator . ' {int:page_id}'. (!$modSettings['postmod_active'] || $approve_posts ? '' : '
889
+			AND id_msg '. $page_operator . ' {int:page_id}' . (!$modSettings['postmod_active'] || $approve_posts ? '' : '
890 890
 			AND (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . '
891 891
 			ORDER BY id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '
892 892
 			LIMIT {int:limit}'),
Please login to merge, or discard this patch.
Braces   +349 added lines, -263 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -394,21 +399,25 @@  discard block
 block discarded – undo
394 399
 		);
395 400
 		while ($row = $smcFunc['db_fetch_assoc']($request))
396 401
 		{
397
-			if (empty($row['id_member']))
398
-				continue;
402
+			if (empty($row['id_member'])) {
403
+							continue;
404
+			}
399 405
 
400
-			if (!empty($row['online_color']))
401
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
402
-			else
403
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
406
+			if (!empty($row['online_color'])) {
407
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
408
+			} else {
409
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
410
+			}
404 411
 
405 412
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
406
-			if ($is_buddy)
407
-				$link = '<strong>' . $link . '</strong>';
413
+			if ($is_buddy) {
414
+							$link = '<strong>' . $link . '</strong>';
415
+			}
408 416
 
409 417
 			// Add them both to the list and to the more detailed list.
410
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
411
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
418
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
419
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
420
+			}
412 421
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
413 422
 				'id' => $row['id_member'],
414 423
 				'username' => $row['member_name'],
@@ -420,8 +429,9 @@  discard block
 block discarded – undo
420 429
 				'hidden' => empty($row['show_online']),
421 430
 			);
422 431
 
423
-			if (empty($row['show_online']))
424
-				$context['view_num_hidden']++;
432
+			if (empty($row['show_online'])) {
433
+							$context['view_num_hidden']++;
434
+			}
425 435
 		}
426 436
 
427 437
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -435,11 +445,13 @@  discard block
 block discarded – undo
435 445
 
436 446
 	// If all is set, but not allowed... just unset it.
437 447
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
438
-	if (isset($_REQUEST['all']) && !$can_show_all)
439
-		unset($_REQUEST['all']);
448
+	if (isset($_REQUEST['all']) && !$can_show_all) {
449
+			unset($_REQUEST['all']);
450
+	}
440 451
 	// Otherwise, it must be allowed... so pretend start was -1.
441
-	elseif (isset($_REQUEST['all']))
442
-		$_REQUEST['start'] = -1;
452
+	elseif (isset($_REQUEST['all'])) {
453
+			$_REQUEST['start'] = -1;
454
+	}
443 455
 
444 456
 	// Construct allowing for the .START method...
445 457
 	$context['start'] = $_REQUEST['start'];
@@ -475,14 +487,16 @@  discard block
 block discarded – undo
475 487
 	if (!empty($board_info['moderators']))
476 488
 	{
477 489
 		// Add a link for each moderator...
478
-		foreach ($board_info['moderators'] as $mod)
479
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
490
+		foreach ($board_info['moderators'] as $mod) {
491
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
492
+		}
480 493
 	}
481 494
 	if (!empty($board_info['moderator_groups']))
482 495
 	{
483 496
 		// Add a link for each moderator group as well...
484
-		foreach ($board_info['moderator_groups'] as $mod_group)
485
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
497
+		foreach ($board_info['moderator_groups'] as $mod_group) {
498
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
499
+		}
486 500
 	}
487 501
 
488 502
 	if (!empty($context['link_moderators']))
@@ -513,9 +527,9 @@  discard block
 block discarded – undo
513 527
 	// For quick reply we need a response prefix in the default forum language.
514 528
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
515 529
 	{
516
-		if ($language === $user_info['language'])
517
-			$context['response_prefix'] = $txt['response_prefix'];
518
-		else
530
+		if ($language === $user_info['language']) {
531
+					$context['response_prefix'] = $txt['response_prefix'];
532
+		} else
519 533
 		{
520 534
 			loadLanguage('index', $language, false);
521 535
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -547,8 +561,9 @@  discard block
 block discarded – undo
547 561
 			list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
548 562
 
549 563
 			// Sanity check
550
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
551
-				continue;
564
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
565
+							continue;
566
+			}
552 567
 
553 568
 			$linked_calendar_event = array(
554 569
 				'id' => $row['id_event'],
@@ -597,8 +612,9 @@  discard block
 block discarded – undo
597 612
 		}
598 613
 		$smcFunc['db_free_result']($request);
599 614
 
600
-		if (!empty($context['linked_calendar_events']))
601
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
615
+		if (!empty($context['linked_calendar_events'])) {
616
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
617
+		}
602 618
 	}
603 619
 
604 620
 	// Create the poll info if it exists.
@@ -661,8 +677,9 @@  discard block
 block discarded – undo
661 677
 		$smcFunc['db_free_result']($request);
662 678
 		
663 679
 		// Got we multi choice?
664
-		if ($pollinfo['max_votes'] > 1)
665
-			$realtotal = $pollinfo['total'];
680
+		if ($pollinfo['max_votes'] > 1) {
681
+					$realtotal = $pollinfo['total'];
682
+		}
666 683
 
667 684
 		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
668 685
 		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
@@ -675,20 +692,21 @@  discard block
 block discarded – undo
675 692
 				foreach ($guestinfo as $i => $guestvoted)
676 693
 				{
677 694
 					$guestvoted = explode(',', $guestvoted);
678
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
679
-						break;
695
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
696
+											break;
697
+					}
680 698
 				}
681 699
 				// Has the poll been reset since guest voted?
682 700
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
683 701
 				{
684 702
 					// Remove the poll info from the cookie to allow guest to vote again
685 703
 					unset($guestinfo[$i]);
686
-					if (!empty($guestinfo))
687
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
688
-					else
689
-						unset($_COOKIE['guest_poll_vote']);
690
-				}
691
-				else
704
+					if (!empty($guestinfo)) {
705
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
706
+					} else {
707
+											unset($_COOKIE['guest_poll_vote']);
708
+					}
709
+				} else
692 710
 				{
693 711
 					// What did they vote for?
694 712
 					unset($guestvoted[0], $guestvoted[1]);
@@ -802,35 +820,43 @@  discard block
 block discarded – undo
802 820
 		// Build the poll moderation button array.
803 821
 		$context['poll_buttons'] = array();
804 822
 
805
-		if ($context['allow_return_vote'])
806
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
823
+		if ($context['allow_return_vote']) {
824
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
825
+		}
807 826
 
808
-		if ($context['show_view_results_button'])
809
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
827
+		if ($context['show_view_results_button']) {
828
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
829
+		}
810 830
 
811
-		if ($context['allow_change_vote'])
812
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
831
+		if ($context['allow_change_vote']) {
832
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
833
+		}
813 834
 
814
-		if ($context['allow_lock_poll'])
815
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
835
+		if ($context['allow_lock_poll']) {
836
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
837
+		}
816 838
 
817
-		if ($context['allow_edit_poll'])
818
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
839
+		if ($context['allow_edit_poll']) {
840
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
841
+		}
819 842
 
820
-		if ($context['can_remove_poll'])
821
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
843
+		if ($context['can_remove_poll']) {
844
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
845
+		}
822 846
 
823 847
 		// Allow mods to add additional buttons here
824 848
 		call_integration_hook('integrate_poll_buttons');
825 849
 	}
826 850
 	
827
-	if(!empty($_REQUEST['page_id']))
828
-		$start_char = substr($_REQUEST['page_id'], 0, 1);
829
-	else
830
-		$start_char = null;
851
+	if(!empty($_REQUEST['page_id'])) {
852
+			$start_char = substr($_REQUEST['page_id'], 0, 1);
853
+	} else {
854
+			$start_char = null;
855
+	}
831 856
 
832
-	if ($start_char === 'M' || $start_char === 'L')
833
-		$page_id = substr($_REQUEST['page_id'], 1);
857
+	if ($start_char === 'M' || $start_char === 'L') {
858
+			$page_id = substr($_REQUEST['page_id'], 1);
859
+	}
834 860
 
835 861
 	$limit = $context['messages_per_page'];
836 862
  
@@ -866,8 +892,7 @@  discard block
 block discarded – undo
866 892
 				'max' => $limit,
867 893
 			)
868 894
 		);
869
-	}
870
-	else //next or before page
895
+	} else //next or before page
871 896
 	{
872 897
 		$firstIndex = 0;
873 898
 		
@@ -875,8 +900,7 @@  discard block
 block discarded – undo
875 900
 		{
876 901
 			$ascending = true;
877 902
 			$page_operator = '>';
878
-		}
879
-		else
903
+		} else
880 904
 		{
881 905
 			$ascending = false;
882 906
 			$page_operator = '<';
@@ -906,14 +930,16 @@  discard block
 block discarded – undo
906 930
 	$all_posters = array();
907 931
 	while ($row = $smcFunc['db_fetch_assoc']($request))
908 932
 	{
909
-		if (!empty($row['id_member']))
910
-			$all_posters[$row['id_msg']] = $row['id_member'];
933
+		if (!empty($row['id_member'])) {
934
+					$all_posters[$row['id_msg']] = $row['id_member'];
935
+		}
911 936
 		$messages[] = $row['id_msg'];
912 937
 	}
913 938
 	
914 939
 	// Before Page bring in the right order
915
-	if (!empty($start_char) && $start_char === 'L')
916
-		krsort($messages);
940
+	if (!empty($start_char) && $start_char === 'L') {
941
+			krsort($messages);
942
+	}
917 943
 	
918 944
 	// Construct the page index, allowing for the .START method...
919 945
 	$page_options = array(
@@ -935,8 +961,9 @@  discard block
 block discarded – undo
935 961
 			$_REQUEST['start'] = 0;
936 962
 		}
937 963
 		// They aren't using it, but the *option* is there, at least.
938
-		else
939
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
964
+		else {
965
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
966
+		}
940 967
 	}
941 968
 	
942 969
 	$smcFunc['db_free_result']($request);
@@ -948,8 +975,9 @@  discard block
 block discarded – undo
948 975
 	if (!$user_info['is_guest'] && !empty($messages))
949 976
 	{
950 977
 		$mark_at_msg = max($messages);
951
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
952
-			$mark_at_msg = $modSettings['maxMsgID'];
978
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
979
+					$mark_at_msg = $modSettings['maxMsgID'];
980
+		}
953 981
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
954 982
 		{
955 983
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -981,8 +1009,9 @@  discard block
 block discarded – undo
981 1009
 		while ($row = $smcFunc['db_fetch_assoc']($request))
982 1010
 		{
983 1011
 			// Find if this topic is marked for notification...
984
-			if (!empty($row['id_topic']))
985
-				$context['is_marked_notify'] = true;
1012
+			if (!empty($row['id_topic'])) {
1013
+							$context['is_marked_notify'] = true;
1014
+			}
986 1015
 
987 1016
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
988 1017
 			if (!empty($row['sent']) && $do_once)
@@ -1004,8 +1033,9 @@  discard block
 block discarded – undo
1004 1033
 		}
1005 1034
 
1006 1035
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
1007
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
1008
-			$_SESSION['topicseen_cache'][$board]--;
1036
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
1037
+					$_SESSION['topicseen_cache'][$board]--;
1038
+		}
1009 1039
 		// Mark board as seen if this is the only new topic.
1010 1040
 		elseif (isset($_REQUEST['topicseen']))
1011 1041
 		{
@@ -1029,14 +1059,16 @@  discard block
 block discarded – undo
1029 1059
 			$smcFunc['db_free_result']($request);
1030 1060
 
1031 1061
 			// If there're no real new topics in this board, mark the board as seen.
1032
-			if (empty($numNewTopics))
1033
-				$_REQUEST['boardseen'] = true;
1034
-			else
1035
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1062
+			if (empty($numNewTopics)) {
1063
+							$_REQUEST['boardseen'] = true;
1064
+			} else {
1065
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1066
+			}
1036 1067
 		}
1037 1068
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
1038
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
1039
-			$_SESSION['topicseen_cache'][$board]--;
1069
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1070
+					$_SESSION['topicseen_cache'][$board]--;
1071
+		}
1040 1072
 
1041 1073
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
1042 1074
 		if (isset($_REQUEST['boardseen']))
@@ -1093,23 +1125,26 @@  discard block
 block discarded – undo
1093 1125
 			$temp = array();
1094 1126
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1095 1127
 			{
1096
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1097
-					continue;
1128
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1129
+									continue;
1130
+				}
1098 1131
 
1099 1132
 				$temp[$row['id_attach']] = $row;
1100 1133
 				$temp[$row['id_attach']]['topic'] = $topic;
1101 1134
 				$temp[$row['id_attach']]['board'] = $board;
1102 1135
 
1103
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1104
-					$context['loaded_attachments'][$row['id_msg']] = array();
1136
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1137
+									$context['loaded_attachments'][$row['id_msg']] = array();
1138
+				}
1105 1139
 			}
1106 1140
 			$smcFunc['db_free_result']($request);
1107 1141
 
1108 1142
 			// This is better than sorting it with the query...
1109 1143
 			ksort($temp);
1110 1144
 
1111
-			foreach ($temp as $row)
1112
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1145
+			foreach ($temp as $row) {
1146
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1147
+			}
1113 1148
 		}
1114 1149
 
1115 1150
 		$msg_parameters = array(
@@ -1136,21 +1171,23 @@  discard block
 block discarded – undo
1136 1171
 		);
1137 1172
 
1138 1173
 		// And the likes
1139
-		if (!empty($modSettings['enable_likes']))
1140
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1174
+		if (!empty($modSettings['enable_likes'])) {
1175
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1176
+		}
1141 1177
 
1142 1178
 		// Go to the last message if the given time is beyond the time of the last message.
1143
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1144
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1179
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1180
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1181
+		}
1145 1182
 
1146 1183
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1147 1184
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1148
-		if (empty($options['view_newest_first']))
1149
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1150
-		else
1151
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1152
-	}
1153
-	else
1185
+		if (empty($options['view_newest_first'])) {
1186
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1187
+		} else {
1188
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1189
+		}
1190
+	} else
1154 1191
 	{
1155 1192
 		$messages_request = false;
1156 1193
 		$context['first_message'] = 0;
@@ -1186,8 +1223,9 @@  discard block
 block discarded – undo
1186 1223
 		'can_see_likes' => 'likes_view',
1187 1224
 		'can_like' => 'likes_like',
1188 1225
 	);
1189
-	foreach ($common_permissions as $contextual => $perm)
1190
-		$context[$contextual] = allowedTo($perm);
1226
+	foreach ($common_permissions as $contextual => $perm) {
1227
+			$context[$contextual] = allowedTo($perm);
1228
+	}
1191 1229
 
1192 1230
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1193 1231
 	$anyown_permissions = array(
@@ -1200,8 +1238,9 @@  discard block
 block discarded – undo
1200 1238
 		'can_reply_unapproved' => 'post_unapproved_replies',
1201 1239
 		'can_view_warning' => 'profile_warning',
1202 1240
 	);
1203
-	foreach ($anyown_permissions as $contextual => $perm)
1204
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1241
+	foreach ($anyown_permissions as $contextual => $perm) {
1242
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1243
+	}
1205 1244
 
1206 1245
 	if (!$user_info['is_admin'] && !$modSettings['topic_move_any'])
1207 1246
 	{
@@ -1247,8 +1286,9 @@  discard block
 block discarded – undo
1247 1286
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1248 1287
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1249 1288
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1250
-	if (!empty($context['drafts_save']))
1251
-		loadLanguage('Drafts');
1289
+	if (!empty($context['drafts_save'])) {
1290
+			loadLanguage('Drafts');
1291
+	}
1252 1292
 
1253 1293
 	// When was the last time this topic was replied to?  Should we warn them about it?
1254 1294
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1309,26 +1349,31 @@  discard block
 block discarded – undo
1309 1349
 	// Message icons - customized icons are off?
1310 1350
 	$context['icons'] = getMessageIcons($board);
1311 1351
 
1312
-	if (!empty($context['icons']))
1313
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1352
+	if (!empty($context['icons'])) {
1353
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1354
+	}
1314 1355
 
1315 1356
 	// Build the normal button array.
1316 1357
 	$context['normal_buttons'] = array();
1317 1358
 
1318
-	if ($context['can_reply'])
1319
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1359
+	if ($context['can_reply']) {
1360
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1361
+	}
1320 1362
 
1321
-	if ($context['can_add_poll'])
1322
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1363
+	if ($context['can_add_poll']) {
1364
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1365
+	}
1323 1366
 
1324
-	if ($context['can_mark_unread'])
1325
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1367
+	if ($context['can_mark_unread']) {
1368
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1369
+	}
1326 1370
 
1327
-	if ($context['can_print'])
1328
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1371
+	if ($context['can_print']) {
1372
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1373
+	}
1329 1374
 
1330
-	if ($context['can_set_notify'])
1331
-		$context['normal_buttons']['notify'] = array(
1375
+	if ($context['can_set_notify']) {
1376
+			$context['normal_buttons']['notify'] = array(
1332 1377
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1333 1378
 			'sub_buttons' => array(
1334 1379
 				array(
@@ -1350,38 +1395,47 @@  discard block
 block discarded – undo
1350 1395
 				),
1351 1396
 			),
1352 1397
 		);
1398
+	}
1353 1399
 
1354 1400
 	// Build the mod button array
1355 1401
 	$context['mod_buttons'] = array();
1356 1402
 
1357
-	if ($context['can_move'])
1358
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1403
+	if ($context['can_move']) {
1404
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1405
+	}
1359 1406
 
1360
-	if ($context['can_delete'])
1361
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1407
+	if ($context['can_delete']) {
1408
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1409
+	}
1362 1410
 
1363
-	if ($context['can_lock'])
1364
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1411
+	if ($context['can_lock']) {
1412
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1413
+	}
1365 1414
 
1366
-	if ($context['can_sticky'])
1367
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1415
+	if ($context['can_sticky']) {
1416
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1417
+	}
1368 1418
 
1369
-	if ($context['can_merge'])
1370
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1419
+	if ($context['can_merge']) {
1420
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1421
+	}
1371 1422
 
1372
-	if ($context['calendar_post'])
1373
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1423
+	if ($context['calendar_post']) {
1424
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1425
+	}
1374 1426
 
1375 1427
 	// Restore topic. eh?  No monkey business.
1376
-	if ($context['can_restore_topic'])
1377
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1428
+	if ($context['can_restore_topic']) {
1429
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1430
+	}
1378 1431
 
1379 1432
 	// Show a message in case a recently posted message became unapproved.
1380 1433
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1381 1434
 
1382 1435
 	// Don't want to show this forever...
1383
-	if ($context['becomesUnapproved'])
1384
-		unset($_SESSION['becomesUnapproved']);
1436
+	if ($context['becomesUnapproved']) {
1437
+			unset($_SESSION['becomesUnapproved']);
1438
+	}
1385 1439
 
1386 1440
 	// Allow adding new mod buttons easily.
1387 1441
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1390,12 +1444,14 @@  discard block
 block discarded – undo
1390 1444
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1391 1445
 
1392 1446
 	// Load the drafts js file
1393
-	if ($context['drafts_autosave'])
1394
-		loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1447
+	if ($context['drafts_autosave']) {
1448
+			loadJavaScriptFile('drafts.js', array('defer' => false), 'smf_drafts');
1449
+	}
1395 1450
 
1396 1451
 	// Spellcheck
1397
-	if ($context['show_spellchecking'])
1398
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1452
+	if ($context['show_spellchecking']) {
1453
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
1454
+	}
1399 1455
 
1400 1456
 	// topic.js
1401 1457
 	loadJavaScriptFile('topic.js', array('defer' => false), 'smf_topic');
@@ -1429,16 +1485,19 @@  discard block
 block discarded – undo
1429 1485
 	static $counter = null;
1430 1486
 
1431 1487
 	// If the query returned false, bail.
1432
-	if ($messages_request == false)
1433
-		return false;
1488
+	if ($messages_request == false) {
1489
+			return false;
1490
+	}
1434 1491
 
1435 1492
 	// Remember which message this is.  (ie. reply #83)
1436
-	if ($counter === null || $reset)
1437
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1493
+	if ($counter === null || $reset) {
1494
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1495
+	}
1438 1496
 
1439 1497
 	// Start from the beginning...
1440
-	if ($reset)
1441
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1498
+	if ($reset) {
1499
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1500
+	}
1442 1501
 
1443 1502
 	// Attempt to get the next message.
1444 1503
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1452,19 +1511,21 @@  discard block
 block discarded – undo
1452 1511
 	if (empty($context['icon_sources']))
1453 1512
 	{
1454 1513
 		$context['icon_sources'] = array();
1455
-		foreach ($context['stable_icons'] as $icon)
1456
-			$context['icon_sources'][$icon] = 'images_url';
1514
+		foreach ($context['stable_icons'] as $icon) {
1515
+					$context['icon_sources'][$icon] = 'images_url';
1516
+		}
1457 1517
 	}
1458 1518
 
1459 1519
 	// Message Icon Management... check the images exist.
1460 1520
 	if (empty($modSettings['messageIconChecks_disable']))
1461 1521
 	{
1462 1522
 		// If the current icon isn't known, then we need to do something...
1463
-		if (!isset($context['icon_sources'][$message['icon']]))
1464
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1523
+		if (!isset($context['icon_sources'][$message['icon']])) {
1524
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1525
+		}
1526
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1527
+			$context['icon_sources'][$message['icon']] = 'images_url';
1465 1528
 	}
1466
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1467
-		$context['icon_sources'][$message['icon']] = 'images_url';
1468 1529
 
1469 1530
 	// If you're a lazy bum, you probably didn't give a subject...
1470 1531
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1489,8 +1550,7 @@  discard block
 block discarded – undo
1489 1550
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1490 1551
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1491 1552
 		$memberContext[$message['id_member']]['is_guest'] = true;
1492
-	}
1493
-	else
1553
+	} else
1494 1554
 	{
1495 1555
 		// Define this here to make things a bit more readable
1496 1556
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1513,8 +1573,9 @@  discard block
 block discarded – undo
1513 1573
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1514 1574
 
1515 1575
 	// If it's in the recycle bin we need to override whatever icon we did have.
1516
-	if (!empty($board_info['recycle']))
1517
-		$message['icon'] = 'recycled';
1576
+	if (!empty($board_info['recycle'])) {
1577
+			$message['icon'] = 'recycled';
1578
+	}
1518 1579
 
1519 1580
 	require_once($sourcedir . '/Subs-Attachments.php');
1520 1581
 
@@ -1558,32 +1619,36 @@  discard block
 block discarded – undo
1558 1619
 	}
1559 1620
 
1560 1621
 	// Are likes enable?
1561
-	if (!empty($modSettings['enable_likes']))
1562
-		$output['likes'] = array(
1622
+	if (!empty($modSettings['enable_likes'])) {
1623
+			$output['likes'] = array(
1563 1624
 			'count' => $message['likes'],
1564 1625
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1565 1626
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1566 1627
 		);
1628
+	}
1567 1629
 
1568 1630
 	// Is this user the message author?
1569 1631
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1570
-	if (!empty($output['modified']['name']))
1571
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1632
+	if (!empty($output['modified']['name'])) {
1633
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1634
+	}
1572 1635
 
1573 1636
 	// Did they give a reason for editing?
1574
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1575
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1637
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1638
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1639
+	}
1576 1640
 
1577 1641
 	// Any custom profile fields?
1578
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1579
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1642
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1643
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1580 1644
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1645
+	}
1581 1646
 
1582
-	if (empty($options['view_newest_first']))
1583
-		$counter++;
1584
-
1585
-	else
1586
-		$counter--;
1647
+	if (empty($options['view_newest_first'])) {
1648
+			$counter++;
1649
+	} else {
1650
+			$counter--;
1651
+	}
1587 1652
 
1588 1653
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1589 1654
 
@@ -1609,21 +1674,23 @@  discard block
 block discarded – undo
1609 1674
 	$context['no_last_modified'] = true;
1610 1675
 
1611 1676
 	// Prevent a preview image from being displayed twice.
1612
-	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview'))
1613
-		return;
1677
+	if (isset($_GET['action']) && $_GET['action'] == 'dlattach' && isset($_GET['type']) && ($_GET['type'] == 'avatar' || $_GET['type'] == 'preview')) {
1678
+			return;
1679
+	}
1614 1680
 
1615 1681
 	// Make sure some attachment was requested!
1616
-	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id']))
1617
-		fatal_lang_error('no_access', false);
1682
+	if (!isset($_REQUEST['attach']) && !isset($_REQUEST['id'])) {
1683
+			fatal_lang_error('no_access', false);
1684
+	}
1618 1685
 
1619 1686
 	$_REQUEST['attach'] = isset($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : (int) $_REQUEST['id'];
1620 1687
 
1621 1688
 	// Do we have a hook wanting to use our attachment system? We use $attachRequest to prevent accidental usage of $request.
1622 1689
 	$attachRequest = null;
1623 1690
 	call_integration_hook('integrate_download_request', array(&$attachRequest));
1624
-	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest))
1625
-		$request = $attachRequest;
1626
-	else
1691
+	if (!is_null($attachRequest) && $smcFunc['db_is_resource']($attachRequest)) {
1692
+			$request = $attachRequest;
1693
+	} else
1627 1694
 	{
1628 1695
 		// This checks only the current board for $board/$topic's permissions.
1629 1696
 		isAllowedTo('view_attachments');
@@ -1644,19 +1711,21 @@  discard block
 block discarded – undo
1644 1711
 		);
1645 1712
 	}
1646 1713
 
1647
-	if ($smcFunc['db_num_rows']($request) == 0)
1648
-		fatal_lang_error('no_access', false);
1714
+	if ($smcFunc['db_num_rows']($request) == 0) {
1715
+			fatal_lang_error('no_access', false);
1716
+	}
1649 1717
 
1650 1718
 	list ($id_folder, $real_filename, $file_hash, $file_ext, $id_attach, $attachment_type, $mime_type, $is_approved, $id_member) = $smcFunc['db_fetch_row']($request);
1651 1719
 	$smcFunc['db_free_result']($request);
1652 1720
 
1653 1721
 	// If it isn't yet approved, do they have permission to view it?
1654
-	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3))
1655
-		isAllowedTo('approve_posts');
1722
+	if (!$is_approved && ($id_member == 0 || $user_info['id'] != $id_member) && ($attachment_type == 0 || $attachment_type == 3)) {
1723
+			isAllowedTo('approve_posts');
1724
+	}
1656 1725
 
1657 1726
 	// Update the download counter (unless it's a thumbnail).
1658
-	if ($attachment_type != 3)
1659
-		$smcFunc['db_query']('attach_download_increase', '
1727
+	if ($attachment_type != 3) {
1728
+			$smcFunc['db_query']('attach_download_increase', '
1660 1729
 			UPDATE LOW_PRIORITY {db_prefix}attachments
1661 1730
 			SET downloads = downloads + 1
1662 1731
 			WHERE id_attach = {int:id_attach}',
@@ -1664,15 +1733,15 @@  discard block
 block discarded – undo
1664 1733
 				'id_attach' => $id_attach,
1665 1734
 			)
1666 1735
 		);
1736
+	}
1667 1737
 
1668 1738
 	$filename = getAttachmentFilename($real_filename, $_REQUEST['attach'], $id_folder, false, $file_hash);
1669 1739
 
1670 1740
 	// This is done to clear any output that was made before now.
1671 1741
 	ob_end_clean();
1672
-	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java')))
1673
-		@ob_start('ob_gzhandler');
1674
-
1675
-	else
1742
+	if (!empty($modSettings['enableCompressedOutput']) && @filesize($filename) <= 4194304 && in_array($file_ext, array('txt', 'html', 'htm', 'js', 'doc', 'docx', 'rtf', 'css', 'php', 'log', 'xml', 'sql', 'c', 'java'))) {
1743
+			@ob_start('ob_gzhandler');
1744
+	} else
1676 1745
 	{
1677 1746
 		ob_start();
1678 1747
 		header('Content-Encoding: none');
@@ -1715,8 +1784,9 @@  discard block
 block discarded – undo
1715 1784
 	// Send the attachment headers.
1716 1785
 	header('Pragma: ');
1717 1786
 
1718
-	if (!isBrowser('gecko'))
1719
-		header('Content-Transfer-Encoding: binary');
1787
+	if (!isBrowser('gecko')) {
1788
+			header('Content-Transfer-Encoding: binary');
1789
+	}
1720 1790
 
1721 1791
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT');
1722 1792
 	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT');
@@ -1725,18 +1795,19 @@  discard block
 block discarded – undo
1725 1795
 	header('ETag: ' . $eTag);
1726 1796
 
1727 1797
 	// Make sure the mime type warrants an inline display.
1728
-	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0)
1729
-		unset($_REQUEST['image']);
1798
+	if (isset($_REQUEST['image']) && !empty($mime_type) && strpos($mime_type, 'image/') !== 0) {
1799
+			unset($_REQUEST['image']);
1800
+	}
1730 1801
 
1731 1802
 	// Does this have a mime type?
1732
-	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff'))))
1733
-		header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1734
-
1735
-	else
1803
+	elseif (!empty($mime_type) && (isset($_REQUEST['image']) || !in_array($file_ext, array('jpg', 'gif', 'jpeg', 'x-ms-bmp', 'png', 'psd', 'tiff', 'iff')))) {
1804
+			header('Content-Type: ' . strtr($mime_type, array('image/bmp' => 'image/x-ms-bmp')));
1805
+	} else
1736 1806
 	{
1737 1807
 		header('Content-Type: ' . (isBrowser('ie') || isBrowser('opera') ? 'application/octetstream' : 'application/octet-stream'));
1738
-		if (isset($_REQUEST['image']))
1739
-			unset($_REQUEST['image']);
1808
+		if (isset($_REQUEST['image'])) {
1809
+					unset($_REQUEST['image']);
1810
+		}
1740 1811
 	}
1741 1812
 
1742 1813
 	// Convert the file to UTF-8, cuz most browsers dig that.
@@ -1744,23 +1815,22 @@  discard block
 block discarded – undo
1744 1815
 	$disposition = !isset($_REQUEST['image']) ? 'attachment' : 'inline';
1745 1816
 
1746 1817
 	// Different browsers like different standards...
1747
-	if (isBrowser('firefox'))
1748
-		header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1749
-
1750
-	elseif (isBrowser('opera'))
1751
-		header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1752
-
1753
-	elseif (isBrowser('ie'))
1754
-		header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1755
-
1756
-	else
1757
-		header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1818
+	if (isBrowser('firefox')) {
1819
+			header('Content-Disposition: ' . $disposition . '; filename*=UTF-8\'\'' . rawurlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)));
1820
+	} elseif (isBrowser('opera')) {
1821
+			header('Content-Disposition: ' . $disposition . '; filename="' . preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name) . '"');
1822
+	} elseif (isBrowser('ie')) {
1823
+			header('Content-Disposition: ' . $disposition . '; filename="' . urlencode(preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $utf8name)) . '"');
1824
+	} else {
1825
+			header('Content-Disposition: ' . $disposition . '; filename="' . $utf8name . '"');
1826
+	}
1758 1827
 
1759 1828
 	// If this has an "image extension" - but isn't actually an image - then ensure it isn't cached cause of silly IE.
1760
-	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff')))
1761
-		header('Cache-Control: no-cache');
1762
-	else
1763
-		header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1829
+	if (!isset($_REQUEST['image']) && in_array($file_ext, array('gif', 'jpg', 'bmp', 'png', 'jpeg', 'tiff'))) {
1830
+			header('Cache-Control: no-cache');
1831
+	} else {
1832
+			header('Cache-Control: max-age=' . (525600 * 60) . ', private');
1833
+	}
1764 1834
 
1765 1835
 	header('Content-Length: ' . filesize($filename));
1766 1836
 
@@ -1770,20 +1840,23 @@  discard block
 block discarded – undo
1770 1840
 	// Recode line endings for text files, if enabled.
1771 1841
 	if (!empty($modSettings['attachmentRecodeLineEndings']) && !isset($_REQUEST['image']) && in_array($file_ext, array('txt', 'css', 'htm', 'html', 'php', 'xml')))
1772 1842
 	{
1773
-		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false)
1774
-			$callback = function($buffer)
1843
+		if (strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') !== false) {
1844
+					$callback = function($buffer)
1775 1845
 			{
1776 1846
 				return preg_replace('~[\r]?\n~', "\r\n", $buffer);
1847
+		}
1777 1848
 			};
1778
-		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false)
1779
-			$callback = function($buffer)
1849
+		elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) {
1850
+					$callback = function($buffer)
1780 1851
 			{
1781 1852
 				return preg_replace('~[\r]?\n~', "\r", $buffer);
1853
+		}
1782 1854
 			};
1783
-		else
1784
-			$callback = function($buffer)
1855
+		else {
1856
+					$callback = function($buffer)
1785 1857
 			{
1786 1858
 				return preg_replace('~[\r]?\n~', "\n", $buffer);
1859
+		}
1787 1860
 			};
1788 1861
 	}
1789 1862
 
@@ -1791,23 +1864,26 @@  discard block
 block discarded – undo
1791 1864
 	if (filesize($filename) > 4194304)
1792 1865
 	{
1793 1866
 		// Forcibly end any output buffering going on.
1794
-		while (@ob_get_level() > 0)
1795
-			@ob_end_clean();
1867
+		while (@ob_get_level() > 0) {
1868
+					@ob_end_clean();
1869
+		}
1796 1870
 
1797 1871
 		$fp = fopen($filename, 'rb');
1798 1872
 		while (!feof($fp))
1799 1873
 		{
1800
-			if (isset($callback))
1801
-				echo $callback(fread($fp, 8192));
1802
-			else
1803
-				echo fread($fp, 8192);
1874
+			if (isset($callback)) {
1875
+							echo $callback(fread($fp, 8192));
1876
+			} else {
1877
+							echo fread($fp, 8192);
1878
+			}
1804 1879
 			flush();
1805 1880
 		}
1806 1881
 		fclose($fp);
1807 1882
 	}
1808 1883
 	// On some of the less-bright hosts, readfile() is disabled.  It's just a faster, more byte safe, version of what's in the if.
1809
-	elseif (isset($callback) || @readfile($filename) === null)
1810
-		echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1884
+	elseif (isset($callback) || @readfile($filename) === null) {
1885
+			echo isset($callback) ? $callback(file_get_contents($filename)) : file_get_contents($filename);
1886
+	}
1811 1887
 
1812 1888
 	obExit(false);
1813 1889
 }
@@ -1820,8 +1896,9 @@  discard block
 block discarded – undo
1820 1896
  */
1821 1897
 function approved_attach_sort($a, $b)
1822 1898
 {
1823
-	if ($a['is_approved'] == $b['is_approved'])
1824
-		return 0;
1899
+	if ($a['is_approved'] == $b['is_approved']) {
1900
+			return 0;
1901
+	}
1825 1902
 
1826 1903
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1827 1904
 }
@@ -1838,16 +1915,19 @@  discard block
 block discarded – undo
1838 1915
 
1839 1916
 	require_once($sourcedir . '/RemoveTopic.php');
1840 1917
 
1841
-	if (empty($_REQUEST['msgs']))
1842
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1918
+	if (empty($_REQUEST['msgs'])) {
1919
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1920
+	}
1843 1921
 
1844 1922
 	$messages = array();
1845
-	foreach ($_REQUEST['msgs'] as $dummy)
1846
-		$messages[] = (int) $dummy;
1923
+	foreach ($_REQUEST['msgs'] as $dummy) {
1924
+			$messages[] = (int) $dummy;
1925
+	}
1847 1926
 
1848 1927
 	// We are restoring messages. We handle this in another place.
1849
-	if (isset($_REQUEST['restore_selected']))
1850
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1928
+	if (isset($_REQUEST['restore_selected'])) {
1929
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1930
+	}
1851 1931
 	if (isset($_REQUEST['split_selection']))
1852 1932
 	{
1853 1933
 		$request = $smcFunc['db_query']('', '
@@ -1866,8 +1946,9 @@  discard block
 block discarded – undo
1866 1946
 	}
1867 1947
 
1868 1948
 	// Allowed to delete any message?
1869
-	if (allowedTo('delete_any'))
1870
-		$allowed_all = true;
1949
+	if (allowedTo('delete_any')) {
1950
+			$allowed_all = true;
1951
+	}
1871 1952
 	// Allowed to delete replies to their messages?
1872 1953
 	elseif (allowedTo('delete_replies'))
1873 1954
 	{
@@ -1884,13 +1965,14 @@  discard block
 block discarded – undo
1884 1965
 		$smcFunc['db_free_result']($request);
1885 1966
 
1886 1967
 		$allowed_all = $starter == $user_info['id'];
1968
+	} else {
1969
+			$allowed_all = false;
1887 1970
 	}
1888
-	else
1889
-		$allowed_all = false;
1890 1971
 
1891 1972
 	// Make sure they're allowed to delete their own messages, if not any.
1892
-	if (!$allowed_all)
1893
-		isAllowedTo('delete_own');
1973
+	if (!$allowed_all) {
1974
+			isAllowedTo('delete_own');
1975
+	}
1894 1976
 
1895 1977
 	// Allowed to remove which messages?
1896 1978
 	$request = $smcFunc['db_query']('', '
@@ -1910,8 +1992,9 @@  discard block
 block discarded – undo
1910 1992
 	$messages = array();
1911 1993
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1912 1994
 	{
1913
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1914
-			continue;
1995
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1996
+					continue;
1997
+		}
1915 1998
 
1916 1999
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1917 2000
 	}
@@ -1934,17 +2017,20 @@  discard block
 block discarded – undo
1934 2017
 	foreach ($messages as $message => $info)
1935 2018
 	{
1936 2019
 		// Just skip the first message - if it's not the last.
1937
-		if ($message == $first_message && $message != $last_message)
1938
-			continue;
2020
+		if ($message == $first_message && $message != $last_message) {
2021
+					continue;
2022
+		}
1939 2023
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1940
-		elseif ($message == $first_message)
1941
-			$topicGone = true;
2024
+		elseif ($message == $first_message) {
2025
+					$topicGone = true;
2026
+		}
1942 2027
 
1943 2028
 		removeMessage($message);
1944 2029
 
1945 2030
 		// Log this moderation action ;).
1946
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1947
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
2031
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
2032
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
2033
+		}
1948 2034
 	}
1949 2035
 
1950 2036
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Sources/Security.php 1 patch
Braces   +255 added lines, -197 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type . '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -297,14 +314,15 @@  discard block
 block discarded – undo
297 314
 	if (isset($_SESSION['ban']['cannot_access']))
298 315
 	{
299 316
 		// We don't wanna see you!
300
-		if (!$user_info['is_guest'])
301
-			$smcFunc['db_query']('', '
317
+		if (!$user_info['is_guest']) {
318
+					$smcFunc['db_query']('', '
302 319
 				DELETE FROM {db_prefix}log_online
303 320
 				WHERE id_member = {int:current_member}',
304 321
 				array(
305 322
 					'current_member' => $user_info['id'],
306 323
 				)
307 324
 			);
325
+		}
308 326
 
309 327
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
310 328
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -390,9 +408,10 @@  discard block
 block discarded – undo
390 408
 	}
391 409
 
392 410
 	// Fix up the banning permissions.
393
-	if (isset($user_info['permissions']))
394
-		banPermissions();
395
-}
411
+	if (isset($user_info['permissions'])) {
412
+			banPermissions();
413
+	}
414
+	}
396 415
 
397 416
 /**
398 417
  * Fix permissions according to ban status.
@@ -403,8 +422,9 @@  discard block
 block discarded – undo
403 422
 	global $user_info, $sourcedir, $modSettings, $context;
404 423
 
405 424
 	// Somehow they got here, at least take away all permissions...
406
-	if (isset($_SESSION['ban']['cannot_access']))
407
-		$user_info['permissions'] = array();
425
+	if (isset($_SESSION['ban']['cannot_access'])) {
426
+			$user_info['permissions'] = array();
427
+	}
408 428
 	// Okay, well, you can watch, but don't touch a thing.
409 429
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
410 430
 	{
@@ -446,19 +466,20 @@  discard block
 block discarded – undo
446 466
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
447 467
 		foreach ($permission_change as $old => $new)
448 468
 		{
449
-			if (!in_array($old, $user_info['permissions']))
450
-				unset($permission_change[$old]);
451
-			else
452
-				$user_info['permissions'][] = $new;
469
+			if (!in_array($old, $user_info['permissions'])) {
470
+							unset($permission_change[$old]);
471
+			} else {
472
+							$user_info['permissions'][] = $new;
473
+			}
453 474
 		}
454 475
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
455 476
 	}
456 477
 
457 478
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
458 479
 	// Finally, some bits we cache in the session because it saves queries.
459
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
460
-		$user_info['mod_cache'] = $_SESSION['mc'];
461
-	else
480
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
481
+			$user_info['mod_cache'] = $_SESSION['mc'];
482
+	} else
462 483
 	{
463 484
 		require_once($sourcedir . '/Subs-Auth.php');
464 485
 		rebuildModCache();
@@ -469,14 +490,12 @@  discard block
 block discarded – undo
469 490
 	{
470 491
 		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
471 492
 		$context['open_member_reports'] = $_SESSION['rc']['member_reports'];
472
-	}
473
-	elseif ($_SESSION['mc']['bq'] != '0=1')
493
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
474 494
 	{
475 495
 		require_once($sourcedir . '/Subs-ReportedContent.php');
476 496
 		$context['open_mod_reports'] = recountOpenReports('posts');
477 497
 		$context['open_member_reports'] = recountOpenReports('members');
478
-	}
479
-	else
498
+	} else
480 499
 	{
481 500
 		$context['open_mod_reports'] = 0;
482 501
 		$context['open_member_reports'] = 0;
@@ -497,8 +516,9 @@  discard block
 block discarded – undo
497 516
 	global $user_info, $smcFunc;
498 517
 
499 518
 	// Don't log web accelerators, it's very confusing...
500
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
501
-		return;
519
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
520
+			return;
521
+	}
502 522
 
503 523
 	$smcFunc['db_insert']('',
504 524
 		'{db_prefix}log_banned',
@@ -508,8 +528,8 @@  discard block
 block discarded – undo
508 528
 	);
509 529
 
510 530
 	// One extra point for these bans.
511
-	if (!empty($ban_ids))
512
-		$smcFunc['db_query']('', '
531
+	if (!empty($ban_ids)) {
532
+			$smcFunc['db_query']('', '
513 533
 			UPDATE {db_prefix}ban_items
514 534
 			SET hits = hits + 1
515 535
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -517,7 +537,8 @@  discard block
 block discarded – undo
517 537
 				'ban_ids' => $ban_ids,
518 538
 			)
519 539
 		);
520
-}
540
+	}
541
+	}
521 542
 
522 543
 /**
523 544
  * Checks if a given email address might be banned.
@@ -533,8 +554,9 @@  discard block
 block discarded – undo
533 554
 	global $txt, $smcFunc;
534 555
 
535 556
 	// Can't ban an empty email
536
-	if (empty($email) || trim($email) == '')
537
-		return;
557
+	if (empty($email) || trim($email) == '') {
558
+			return;
559
+	}
538 560
 
539 561
 	// Let's start with the bans based on your IP/hostname/memberID...
540 562
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -607,16 +629,18 @@  discard block
 block discarded – undo
607 629
 	if ($type == 'post')
608 630
 	{
609 631
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
610
-		if ($check !== $sc)
611
-			$error = 'session_timeout';
632
+		if ($check !== $sc) {
633
+					$error = 'session_timeout';
634
+		}
612 635
 	}
613 636
 
614 637
 	// How about $_GET['sesc']?
615 638
 	elseif ($type == 'get')
616 639
 	{
617 640
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
618
-		if ($check !== $sc)
619
-			$error = 'session_verify_fail';
641
+		if ($check !== $sc) {
642
+					$error = 'session_verify_fail';
643
+		}
620 644
 	}
621 645
 
622 646
 	// Or can it be in either?
@@ -624,13 +648,15 @@  discard block
 block discarded – undo
624 648
 	{
625 649
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
626 650
 
627
-		if ($check !== $sc)
628
-			$error = 'session_verify_fail';
651
+		if ($check !== $sc) {
652
+					$error = 'session_verify_fail';
653
+		}
629 654
 	}
630 655
 
631 656
 	// Verify that they aren't changing user agents on us - that could be bad.
632
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
633
-		$error = 'session_verify_fail';
657
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
658
+			$error = 'session_verify_fail';
659
+	}
634 660
 
635 661
 	// Make sure a page with session check requirement is not being prefetched.
636 662
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -641,30 +667,35 @@  discard block
 block discarded – undo
641 667
 	}
642 668
 
643 669
 	// Check the referring site - it should be the same server at least!
644
-	if (isset($_SESSION['request_referer']))
645
-		$referrer = $_SESSION['request_referer'];
646
-	else
647
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
670
+	if (isset($_SESSION['request_referer'])) {
671
+			$referrer = $_SESSION['request_referer'];
672
+	} else {
673
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
674
+	}
648 675
 	if (!empty($referrer['host']))
649 676
 	{
650
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
651
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
652
-		else
653
-			$real_host = $_SERVER['HTTP_HOST'];
677
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
678
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
679
+		} else {
680
+					$real_host = $_SERVER['HTTP_HOST'];
681
+		}
654 682
 
655 683
 		$parsed_url = parse_url($boardurl);
656 684
 
657 685
 		// Are global cookies on?  If so, let's check them ;).
658 686
 		if (!empty($modSettings['globalCookies']))
659 687
 		{
660
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
661
-				$parsed_url['host'] = $parts[1];
688
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
689
+							$parsed_url['host'] = $parts[1];
690
+			}
662 691
 
663
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
664
-				$referrer['host'] = $parts[1];
692
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
693
+							$referrer['host'] = $parts[1];
694
+			}
665 695
 
666
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
667
-				$real_host = $parts[1];
696
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
697
+							$real_host = $parts[1];
698
+			}
668 699
 		}
669 700
 
670 701
 		// Okay: referrer must either match parsed_url or real_host.
@@ -682,12 +713,14 @@  discard block
 block discarded – undo
682 713
 		$log_error = true;
683 714
 	}
684 715
 
685
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
686
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
716
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
717
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
718
+	}
687 719
 
688 720
 	// Everything is ok, return an empty string.
689
-	if (!isset($error))
690
-		return '';
721
+	if (!isset($error)) {
722
+			return '';
723
+	}
691 724
 	// A session error occurred, show the error.
692 725
 	elseif ($is_fatal)
693 726
 	{
@@ -696,13 +729,14 @@  discard block
 block discarded – undo
696 729
 			ob_end_clean();
697 730
 			header('HTTP/1.1 403 Forbidden - Session timeout');
698 731
 			die;
732
+		} else {
733
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
699 734
 		}
700
-		else
701
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
702 735
 	}
703 736
 	// A session error occurred, return the error to the calling function.
704
-	else
705
-		return $error;
737
+	else {
738
+			return $error;
739
+	}
706 740
 
707 741
 	// We really should never fall through here, for very important reasons.  Let's make sure.
708 742
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -718,10 +752,9 @@  discard block
 block discarded – undo
718 752
 {
719 753
 	global $modSettings;
720 754
 
721
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
722
-		return true;
723
-
724
-	else
755
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
756
+			return true;
757
+	} else
725 758
 	{
726 759
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
727 760
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -772,9 +805,9 @@  discard block
 block discarded – undo
772 805
 			$return = $_SESSION['token'][$type . '-' . $action][3];
773 806
 			unset($_SESSION['token'][$type . '-' . $action]);
774 807
 			return $return;
808
+		} else {
809
+					return '';
775 810
 		}
776
-		else
777
-			return '';
778 811
 	}
779 812
 
780 813
 	// This nasty piece of code validates a token.
@@ -805,12 +838,14 @@  discard block
 block discarded – undo
805 838
 		fatal_lang_error('token_verify_fail', false);
806 839
 	}
807 840
 	// Remove this token as its useless
808
-	else
809
-		unset($_SESSION['token'][$type . '-' . $action]);
841
+	else {
842
+			unset($_SESSION['token'][$type . '-' . $action]);
843
+	}
810 844
 
811 845
 	// Randomly check if we should remove some older tokens.
812
-	if (mt_rand(0, 138) == 23)
813
-		cleanTokens();
846
+	if (mt_rand(0, 138) == 23) {
847
+			cleanTokens();
848
+	}
814 849
 
815 850
 	return false;
816 851
 }
@@ -825,14 +860,16 @@  discard block
 block discarded – undo
825 860
 function cleanTokens($complete = false)
826 861
 {
827 862
 	// We appreciate cleaning up after yourselves.
828
-	if (!isset($_SESSION['token']))
829
-		return;
863
+	if (!isset($_SESSION['token'])) {
864
+			return;
865
+	}
830 866
 
831 867
 	// Clean up tokens, trying to give enough time still.
832
-	foreach ($_SESSION['token'] as $key => $data)
833
-		if ($data[2] + 10800 < time() || $complete)
868
+	foreach ($_SESSION['token'] as $key => $data) {
869
+			if ($data[2] + 10800 < time() || $complete)
834 870
 			unset($_SESSION['token'][$key]);
835
-}
871
+	}
872
+	}
836 873
 
837 874
 /**
838 875
  * Check whether a form has been submitted twice.
@@ -850,37 +887,40 @@  discard block
 block discarded – undo
850 887
 {
851 888
 	global $context;
852 889
 
853
-	if (!isset($_SESSION['forms']))
854
-		$_SESSION['forms'] = array();
890
+	if (!isset($_SESSION['forms'])) {
891
+			$_SESSION['forms'] = array();
892
+	}
855 893
 
856 894
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
857 895
 	if ($action == 'register')
858 896
 	{
859 897
 		$context['form_sequence_number'] = 0;
860
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
861
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
898
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
899
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
900
+		}
862 901
 	}
863 902
 	// Check whether the submitted number can be found in the session.
864 903
 	elseif ($action == 'check')
865 904
 	{
866
-		if (!isset($_REQUEST['seqnum']))
867
-			return true;
868
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
905
+		if (!isset($_REQUEST['seqnum'])) {
906
+					return true;
907
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
869 908
 		{
870 909
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
871 910
 			return true;
911
+		} elseif ($is_fatal) {
912
+					fatal_lang_error('error_form_already_submitted', false);
913
+		} else {
914
+					return false;
872 915
 		}
873
-		elseif ($is_fatal)
874
-			fatal_lang_error('error_form_already_submitted', false);
875
-		else
876
-			return false;
877 916
 	}
878 917
 	// Don't check, just free the stack number.
879
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
880
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
881
-	elseif ($action != 'free')
882
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
883
-}
918
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
919
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
920
+	} elseif ($action != 'free') {
921
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
922
+	}
923
+	}
884 924
 
885 925
 /**
886 926
  * Check the user's permissions.
@@ -897,16 +937,19 @@  discard block
 block discarded – undo
897 937
 	global $user_info, $smcFunc;
898 938
 
899 939
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
900
-	if (empty($permission))
901
-		return true;
940
+	if (empty($permission)) {
941
+			return true;
942
+	}
902 943
 
903 944
 	// You're never allowed to do something if your data hasn't been loaded yet!
904
-	if (empty($user_info))
905
-		return false;
945
+	if (empty($user_info)) {
946
+			return false;
947
+	}
906 948
 
907 949
 	// Administrators are supermen :P.
908
-	if ($user_info['is_admin'])
909
-		return true;
950
+	if ($user_info['is_admin']) {
951
+			return true;
952
+	}
910 953
 
911 954
 	// Let's ensure this is an array.
912 955
 	$permission = (array) $permission;
@@ -914,14 +957,16 @@  discard block
 block discarded – undo
914 957
 	// Are we checking the _current_ board, or some other boards?
915 958
 	if ($boards === null)
916 959
 	{
917
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
918
-			return true;
960
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
961
+					return true;
962
+		}
919 963
 		// You aren't allowed, by default.
920
-		else
921
-			return false;
964
+		else {
965
+					return false;
966
+		}
967
+	} elseif (!is_array($boards)) {
968
+			$boards = array($boards);
922 969
 	}
923
-	elseif (!is_array($boards))
924
-		$boards = array($boards);
925 970
 
926 971
 	$request = $smcFunc['db_query']('', '
927 972
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -944,12 +989,14 @@  discard block
 block discarded – undo
944 989
 	);
945 990
 
946 991
 	// Make sure they can do it on all of the boards.
947
-	if ($smcFunc['db_num_rows']($request) != count($boards))
948
-		return false;
992
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
993
+			return false;
994
+	}
949 995
 
950 996
 	$result = true;
951
-	while ($row = $smcFunc['db_fetch_assoc']($request))
952
-		$result &= !empty($row['add_deny']);
997
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
998
+			$result &= !empty($row['add_deny']);
999
+	}
953 1000
 	$smcFunc['db_free_result']($request);
954 1001
 
955 1002
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1014,9 +1061,10 @@  discard block
 block discarded – undo
1014 1061
 
1015 1062
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1016 1063
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1017
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1018
-		validateSession();
1019
-}
1064
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1065
+			validateSession();
1066
+	}
1067
+	}
1020 1068
 
1021 1069
 /**
1022 1070
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1035,8 +1083,9 @@  discard block
 block discarded – undo
1035 1083
 	global $user_info, $smcFunc;
1036 1084
 
1037 1085
 	// Arrays are nice, most of the time.
1038
-	if (!is_array($permissions))
1039
-		$permissions = array($permissions);
1086
+	if (!is_array($permissions)) {
1087
+			$permissions = array($permissions);
1088
+	}
1040 1089
 
1041 1090
 	/*
1042 1091
 	 * Set $simple to true to use this function as it were in SMF 2.0.x.
@@ -1048,13 +1097,14 @@  discard block
 block discarded – undo
1048 1097
 	// Administrators are all powerful, sorry.
1049 1098
 	if ($user_info['is_admin'])
1050 1099
 	{
1051
-		if ($simple)
1052
-			return array(0);
1053
-		else
1100
+		if ($simple) {
1101
+					return array(0);
1102
+		} else
1054 1103
 		{
1055 1104
 			$boards = array();
1056
-			foreach ($permissions as $permission)
1057
-				$boards[$permission] = array(0);
1105
+			foreach ($permissions as $permission) {
1106
+							$boards[$permission] = array(0);
1107
+			}
1058 1108
 
1059 1109
 			return $boards;
1060 1110
 		}
@@ -1086,31 +1136,32 @@  discard block
 block discarded – undo
1086 1136
 	{
1087 1137
 		if ($simple)
1088 1138
 		{
1089
-			if (empty($row['add_deny']))
1090
-				$deny_boards[] = $row['id_board'];
1091
-			else
1092
-				$boards[] = $row['id_board'];
1093
-		}
1094
-		else
1139
+			if (empty($row['add_deny'])) {
1140
+							$deny_boards[] = $row['id_board'];
1141
+			} else {
1142
+							$boards[] = $row['id_board'];
1143
+			}
1144
+		} else
1095 1145
 		{
1096
-			if (empty($row['add_deny']))
1097
-				$deny_boards[$row['permission']][] = $row['id_board'];
1098
-			else
1099
-				$boards[$row['permission']][] = $row['id_board'];
1146
+			if (empty($row['add_deny'])) {
1147
+							$deny_boards[$row['permission']][] = $row['id_board'];
1148
+			} else {
1149
+							$boards[$row['permission']][] = $row['id_board'];
1150
+			}
1100 1151
 		}
1101 1152
 	}
1102 1153
 	$smcFunc['db_free_result']($request);
1103 1154
 
1104
-	if ($simple)
1105
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1106
-	else
1155
+	if ($simple) {
1156
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1157
+	} else
1107 1158
 	{
1108 1159
 		foreach ($permissions as $permission)
1109 1160
 		{
1110 1161
 			// never had it to start with
1111
-			if (empty($boards[$permission]))
1112
-				$boards[$permission] = array();
1113
-			else
1162
+			if (empty($boards[$permission])) {
1163
+							$boards[$permission] = array();
1164
+			} else
1114 1165
 			{
1115 1166
 				// Or it may have been removed
1116 1167
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1146,10 +1197,11 @@  discard block
 block discarded – undo
1146 1197
 
1147 1198
 
1148 1199
 	// Moderators are free...
1149
-	if (!allowedTo('moderate_board'))
1150
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1151
-	else
1152
-		$timeLimit = 2;
1200
+	if (!allowedTo('moderate_board')) {
1201
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1202
+	} else {
1203
+			$timeLimit = 2;
1204
+	}
1153 1205
 
1154 1206
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1155 1207
 
@@ -1176,8 +1228,9 @@  discard block
 block discarded – undo
1176 1228
 	if ($smcFunc['db_affected_rows']() != 1)
1177 1229
 	{
1178 1230
 		// Spammer!  You only have to wait a *few* seconds!
1179
-		if (!$only_return_result)
1180
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1231
+		if (!$only_return_result) {
1232
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1233
+		}
1181 1234
 
1182 1235
 		return true;
1183 1236
 	}
@@ -1195,11 +1248,13 @@  discard block
 block discarded – undo
1195 1248
  */
1196 1249
 function secureDirectory($path, $attachments = false)
1197 1250
 {
1198
-	if (empty($path))
1199
-		return 'empty_path';
1251
+	if (empty($path)) {
1252
+			return 'empty_path';
1253
+	}
1200 1254
 
1201
-	if (!is_writable($path))
1202
-		return 'path_not_writable';
1255
+	if (!is_writable($path)) {
1256
+			return 'path_not_writable';
1257
+	}
1203 1258
 
1204 1259
 	$directoryname = basename($path);
1205 1260
 
@@ -1211,9 +1266,9 @@  discard block
 block discarded – undo
1211 1266
 
1212 1267
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1213 1268
 
1214
-	if (file_exists($path . '/.htaccess'))
1215
-		$errors[] = 'htaccess_exists';
1216
-	else
1269
+	if (file_exists($path . '/.htaccess')) {
1270
+			$errors[] = 'htaccess_exists';
1271
+	} else
1217 1272
 	{
1218 1273
 		$fh = @fopen($path . '/.htaccess', 'w');
1219 1274
 		if ($fh) {
@@ -1225,9 +1280,9 @@  discard block
 block discarded – undo
1225 1280
 		$errors[] = 'htaccess_cannot_create_file';
1226 1281
 	}
1227 1282
 
1228
-	if (file_exists($path . '/index.php'))
1229
-		$errors[] = 'index-php_exists';
1230
-	else
1283
+	if (file_exists($path . '/index.php')) {
1284
+			$errors[] = 'index-php_exists';
1285
+	} else
1231 1286
 	{
1232 1287
 		$fh = @fopen($path . '/index.php', 'w');
1233 1288
 		if ($fh) {
@@ -1254,11 +1309,12 @@  discard block
 block discarded – undo
1254 1309
 		$errors[] = 'index-php_cannot_create_file';
1255 1310
 	}
1256 1311
 
1257
-	if (!empty($errors))
1258
-		return $errors;
1259
-	else
1260
-		return true;
1261
-}
1312
+	if (!empty($errors)) {
1313
+			return $errors;
1314
+	} else {
1315
+			return true;
1316
+	}
1317
+	}
1262 1318
 
1263 1319
 /**
1264 1320
 * This sets the X-Frame-Options header.
@@ -1271,14 +1327,16 @@  discard block
 block discarded – undo
1271 1327
 	global $modSettings;
1272 1328
 
1273 1329
 	$option = 'SAMEORIGIN';
1274
-	if (is_null($override) && !empty($modSettings['frame_security']))
1275
-		$option = $modSettings['frame_security'];
1276
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1277
-		$option = $override;
1330
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1331
+			$option = $modSettings['frame_security'];
1332
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1333
+			$option = $override;
1334
+	}
1278 1335
 
1279 1336
 	// Don't bother setting the header if we have disabled it.
1280
-	if ($option == 'DISABLE')
1281
-		return;
1337
+	if ($option == 'DISABLE') {
1338
+			return;
1339
+	}
1282 1340
 
1283 1341
 	// Finally set it.
1284 1342
 	header('X-Frame-Options: ' . $option);
Please login to merge, or discard this patch.
Sources/ManageCalendar.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 					'value' => $txt['date'],
137 137
 				),
138 138
 				'data' => array(
139
-					'function' => function ($rowData) use ($txt)
139
+					'function' => function($rowData) use ($txt)
140 140
 					{
141 141
 						// Recurring every year or just a single year?
142 142
 						$year = $rowData['year'] == '1004' ? sprintf('(%1$s)', $txt['every_year']) : $rowData['year'];
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 		checkSession();
219 219
 
220 220
 		// Not too long good sir?
221
-		$_REQUEST['title'] =  $smcFunc['substr']($_REQUEST['title'], 0, 60);
221
+		$_REQUEST['title'] = $smcFunc['substr']($_REQUEST['title'], 0, 60);
222 222
 		$_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0;
223 223
 
224 224
 		if (isset($_REQUEST['delete']))
Please login to merge, or discard this patch.
Braces   +37 added lines, -28 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main controlling function doesn't have much to do... yet.
@@ -43,8 +44,7 @@  discard block
 block discarded – undo
43 44
 			'settings' => 'ModifyCalendarSettings'
44 45
 		);
45 46
 		$default = 'holidays';
46
-	}
47
-	else
47
+	} else
48 48
 	{
49 49
 		$subActions = array(
50 50
 			'settings' => 'ModifyCalendarSettings'
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 		'help' => 'calendar',
61 61
 		'description' => $txt['calendar_settings_desc'],
62 62
 	);
63
-	if (!empty($modSettings['cal_enabled']))
64
-		$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
63
+	if (!empty($modSettings['cal_enabled'])) {
64
+			$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
65 65
 			'holidays' => array(
66 66
 				'description' => $txt['manage_holidays_desc'],
67 67
 			),
@@ -69,6 +69,7 @@  discard block
 block discarded – undo
69 69
 				'description' => $txt['calendar_settings_desc'],
70 70
 			),
71 71
 		);
72
+	}
72 73
 
73 74
 	call_integration_hook('integrate_manage_calendar', array(&$subActions));
74 75
 
@@ -88,8 +89,9 @@  discard block
 block discarded – undo
88 89
 		checkSession();
89 90
 		validateToken('admin-mc');
90 91
 
91
-		foreach ($_REQUEST['holiday'] as $id => $value)
92
-			$_REQUEST['holiday'][$id] = (int) $id;
92
+		foreach ($_REQUEST['holiday'] as $id => $value) {
93
+					$_REQUEST['holiday'][$id] = (int) $id;
94
+		}
93 95
 
94 96
 		// Now the IDs are "safe" do the delete...
95 97
 		require_once($sourcedir . '/Subs-Calendar.php');
@@ -209,8 +211,9 @@  discard block
 block discarded – undo
209 211
 	$context['sub_template'] = 'edit_holiday';
210 212
 
211 213
 	// Cast this for safety...
212
-	if (isset($_REQUEST['holiday']))
213
-		$_REQUEST['holiday'] = (int) $_REQUEST['holiday'];
214
+	if (isset($_REQUEST['holiday'])) {
215
+			$_REQUEST['holiday'] = (int) $_REQUEST['holiday'];
216
+	}
214 217
 
215 218
 	// Submitting?
216 219
 	if (isset($_POST[$context['session_var']]) && (isset($_REQUEST['delete']) || $_REQUEST['title'] != ''))
@@ -221,19 +224,19 @@  discard block
 block discarded – undo
221 224
 		$_REQUEST['title'] =  $smcFunc['substr']($_REQUEST['title'], 0, 60);
222 225
 		$_REQUEST['holiday'] = isset($_REQUEST['holiday']) ? (int) $_REQUEST['holiday'] : 0;
223 226
 
224
-		if (isset($_REQUEST['delete']))
225
-			$smcFunc['db_query']('', '
227
+		if (isset($_REQUEST['delete'])) {
228
+					$smcFunc['db_query']('', '
226 229
 				DELETE FROM {db_prefix}calendar_holidays
227 230
 				WHERE id_holiday = {int:selected_holiday}',
228 231
 				array(
229 232
 					'selected_holiday' => $_REQUEST['holiday'],
230 233
 				)
231 234
 			);
232
-		else
235
+		} else
233 236
 		{
234 237
 			$date = strftime($_REQUEST['year'] <= 1004 ? '1004-%m-%d' : '%Y-%m-%d', mktime(0, 0, 0, $_REQUEST['month'], $_REQUEST['day'], $_REQUEST['year']));
235
-			if (isset($_REQUEST['edit']))
236
-				$smcFunc['db_query']('', '
238
+			if (isset($_REQUEST['edit'])) {
239
+							$smcFunc['db_query']('', '
237 240
 					UPDATE {db_prefix}calendar_holidays
238 241
 					SET event_date = {date:holiday_date}, title = {string:holiday_title}
239 242
 					WHERE id_holiday = {int:selected_holiday}',
@@ -243,8 +246,8 @@  discard block
 block discarded – undo
243 246
 						'holiday_title' => $_REQUEST['title'],
244 247
 					)
245 248
 				);
246
-			else
247
-				$smcFunc['db_insert']('',
249
+			} else {
250
+							$smcFunc['db_insert']('',
248 251
 					'{db_prefix}calendar_holidays',
249 252
 					array(
250 253
 						'event_date' => 'date', 'title' => 'string-60',
@@ -254,6 +257,7 @@  discard block
 block discarded – undo
254 257
 					),
255 258
 					array('id_holiday')
256 259
 				);
260
+			}
257 261
 		}
258 262
 
259 263
 		updateSettings(array(
@@ -265,14 +269,15 @@  discard block
 block discarded – undo
265 269
 	}
266 270
 
267 271
 	// Default states...
268
-	if ($context['is_new'])
269
-		$context['holiday'] = array(
272
+	if ($context['is_new']) {
273
+			$context['holiday'] = array(
270 274
 			'id' => 0,
271 275
 			'day' => date('d'),
272 276
 			'month' => date('m'),
273 277
 			'year' => '0000',
274 278
 			'title' => ''
275 279
 		);
280
+	}
276 281
 	// If it's not new load the data.
277 282
 	else
278 283
 	{
@@ -285,14 +290,15 @@  discard block
 block discarded – undo
285 290
 				'selected_holiday' => $_REQUEST['holiday'],
286 291
 			)
287 292
 		);
288
-		while ($row = $smcFunc['db_fetch_assoc']($request))
289
-			$context['holiday'] = array(
293
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
294
+					$context['holiday'] = array(
290 295
 				'id' => $row['id_holiday'],
291 296
 				'day' => $row['day'],
292 297
 				'month' => $row['month'],
293 298
 				'year' => $row['year'] <= 4 ? 0 : $row['year'],
294 299
 				'title' => $row['title']
295 300
 			);
301
+		}
296 302
 		$smcFunc['db_free_result']($request);
297 303
 	}
298 304
 
@@ -319,16 +325,17 @@  discard block
 block discarded – undo
319 325
 		array(
320 326
 		)
321 327
 	);
322
-	while ($row = $smcFunc['db_fetch_assoc']($request))
323
-		$boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
328
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
329
+			$boards[$row['id_board']] = $row['cat_name'] . ' - ' . $row['board_name'];
330
+	}
324 331
 	$smcFunc['db_free_result']($request);
325 332
 
326 333
 	require_once($sourcedir . '/Subs-Boards.php');
327 334
 	sortBoards($boards);
328 335
 
329 336
 	// Look, all the calendar settings - of which there are many!
330
-	if (!empty($modSettings['cal_enabled']))
331
-		$config_vars = array(
337
+	if (!empty($modSettings['cal_enabled'])) {
338
+			$config_vars = array(
332 339
 				array('check', 'cal_enabled'),
333 340
 			'',
334 341
 				// All the permissions:
@@ -371,14 +378,16 @@  discard block
 block discarded – undo
371 378
 				array('check', 'cal_short_days'),
372 379
 				array('check', 'cal_short_months'),
373 380
 		);
374
-	else
375
-		$config_vars = array(
381
+	} else {
382
+			$config_vars = array(
376 383
 			array('check', 'cal_enabled'),
377 384
 		);
385
+	}
378 386
 
379 387
 	call_integration_hook('integrate_modify_calendar_settings', array(&$config_vars));
380
-	if ($return_config)
381
-		return $config_vars;
388
+	if ($return_config) {
389
+			return $config_vars;
390
+	}
382 391
 
383 392
 	// Get the settings template fired up.
384 393
 	require_once($sourcedir . '/ManageServer.php');
Please login to merge, or discard this patch.
Sources/Subs-Calendar.php 1 patch
Braces   +215 added lines, -157 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Get all birthdays within the given time range.
@@ -60,8 +61,7 @@  discard block
 block discarded – undo
60 61
 				'max_year' => $year_high,
61 62
 			)
62 63
 		);
63
-	}
64
-	else
64
+	} else
65 65
 	{
66 66
 		$result = $smcFunc['db_query']('birthday_array', '
67 67
 			SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate
@@ -91,10 +91,11 @@  discard block
 block discarded – undo
91 91
 	$bday = array();
92 92
 	while ($row = $smcFunc['db_fetch_assoc']($result))
93 93
 	{
94
-		if ($year_low != $year_high)
95
-			$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
-		else
97
-			$age_year = $year_low;
94
+		if ($year_low != $year_high) {
95
+					$age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low;
96
+		} else {
97
+					$age_year = $year_low;
98
+		}
98 99
 
99 100
 		$bday[$age_year . substr($row['birthdate'], 4)][] = array(
100 101
 			'id' => $row['id_member'],
@@ -108,8 +109,9 @@  discard block
 block discarded – undo
108 109
 	ksort($bday);
109 110
 
110 111
 	// Set is_last, so the themes know when to stop placing separators.
111
-	foreach ($bday as $mday => $array)
112
-		$bday[$mday][count($array) - 1]['is_last'] = true;
112
+	foreach ($bday as $mday => $array) {
113
+			$bday[$mday][count($array) - 1]['is_last'] = true;
114
+	}
113 115
 
114 116
 	return $bday;
115 117
 }
@@ -157,8 +159,9 @@  discard block
 block discarded – undo
157 159
 	while ($row = $smcFunc['db_fetch_assoc']($result))
158 160
 	{
159 161
 		// If the attached topic is not approved then for the moment pretend it doesn't exist
160
-		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved'])
161
-			continue;
162
+		if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) {
163
+					continue;
164
+		}
162 165
 
163 166
 		// Force a censor of the title - as often these are used by others.
164 167
 		censorText($row['title'], $use_permissions ? false : true);
@@ -167,8 +170,9 @@  discard block
 block discarded – undo
167 170
 		list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
168 171
 
169 172
 		// Sanity check
170
-		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
171
-			continue;
173
+		if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
174
+					continue;
175
+		}
172 176
 
173 177
 		// Get set up for the loop
174 178
 		$start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz));
@@ -232,8 +236,8 @@  discard block
 block discarded – undo
232 236
 			);
233 237
 
234 238
 			// If we're using permissions (calendar pages?) then just ouput normal contextual style information.
235
-			if ($use_permissions)
236
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
239
+			if ($use_permissions) {
240
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
237 241
 					'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
238 242
 					'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
239 243
 					'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')),
@@ -241,9 +245,10 @@  discard block
 block discarded – undo
241 245
 					'can_export' => !empty($modSettings['cal_export']) ? true : false,
242 246
 					'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'],
243 247
 				));
248
+			}
244 249
 			// Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info.
245
-			else
246
-				$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
250
+			else {
251
+							$events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array(
247 252
 					'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0',
248 253
 					'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>',
249 254
 					'can_edit' => false,
@@ -253,6 +258,7 @@  discard block
 block discarded – undo
253 258
 					'poster' => $row['id_member'],
254 259
 					'allowed_groups' => explode(',', $row['member_groups']),
255 260
 				));
261
+			}
256 262
 
257 263
 			date_add($cal_date, date_interval_create_from_date_string('1 day'));
258 264
 		}
@@ -262,8 +268,9 @@  discard block
 block discarded – undo
262 268
 	// If we're doing normal contextual data, go through and make things clear to the templates ;).
263 269
 	if ($use_permissions)
264 270
 	{
265
-		foreach ($events as $mday => $array)
266
-			$events[$mday][count($array) - 1]['is_last'] = true;
271
+		foreach ($events as $mday => $array) {
272
+					$events[$mday][count($array) - 1]['is_last'] = true;
273
+		}
267 274
 	}
268 275
 
269 276
 	ksort($events);
@@ -283,11 +290,12 @@  discard block
 block discarded – undo
283 290
 	global $smcFunc;
284 291
 
285 292
 	// Get the lowest and highest dates for "all years".
286
-	if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
287
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
293
+	if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
294
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec}
288 295
 			OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}';
289
-	else
290
-		$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
296
+	} else {
297
+			$allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}';
298
+	}
291 299
 
292 300
 	// Find some holidays... ;).
293 301
 	$result = $smcFunc['db_query']('', '
@@ -307,10 +315,11 @@  discard block
 block discarded – undo
307 315
 	$holidays = array();
308 316
 	while ($row = $smcFunc['db_fetch_assoc']($result))
309 317
 	{
310
-		if (substr($low_date, 0, 4) != substr($high_date, 0, 4))
311
-			$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
312
-		else
313
-			$event_year = substr($low_date, 0, 4);
318
+		if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) {
319
+					$event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4);
320
+		} else {
321
+					$event_year = substr($low_date, 0, 4);
322
+		}
314 323
 
315 324
 		$holidays[$event_year . substr($row['event_date'], 4)][] = $row['title'];
316 325
 	}
@@ -336,10 +345,12 @@  discard block
 block discarded – undo
336 345
 	isAllowedTo('calendar_post');
337 346
 
338 347
 	// No board?  No topic?!?
339
-	if (empty($board))
340
-		fatal_lang_error('missing_board_id', false);
341
-	if (empty($topic))
342
-		fatal_lang_error('missing_topic_id', false);
348
+	if (empty($board)) {
349
+			fatal_lang_error('missing_board_id', false);
350
+	}
351
+	if (empty($topic)) {
352
+			fatal_lang_error('missing_topic_id', false);
353
+	}
343 354
 
344 355
 	// Administrator, Moderator, or owner.  Period.
345 356
 	if (!allowedTo('admin_forum') && !allowedTo('moderate_board'))
@@ -357,12 +368,14 @@  discard block
 block discarded – undo
357 368
 		if ($row = $smcFunc['db_fetch_assoc']($result))
358 369
 		{
359 370
 			// Not the owner of the topic.
360
-			if ($row['id_member_started'] != $user_info['id'])
361
-				fatal_lang_error('not_your_topic', 'user');
371
+			if ($row['id_member_started'] != $user_info['id']) {
372
+							fatal_lang_error('not_your_topic', 'user');
373
+			}
362 374
 		}
363 375
 		// Topic/Board doesn't exist.....
364
-		else
365
-			fatal_lang_error('calendar_no_topic', 'general');
376
+		else {
377
+					fatal_lang_error('calendar_no_topic', 'general');
378
+		}
366 379
 		$smcFunc['db_free_result']($result);
367 380
 	}
368 381
 }
@@ -450,14 +463,16 @@  discard block
 block discarded – undo
450 463
 	if (!empty($calendarOptions['start_day']))
451 464
 	{
452 465
 		$nShift -= $calendarOptions['start_day'];
453
-		if ($nShift < 0)
454
-			$nShift = 7 + $nShift;
466
+		if ($nShift < 0) {
467
+					$nShift = 7 + $nShift;
468
+		}
455 469
 	}
456 470
 
457 471
 	// Number of rows required to fit the month.
458 472
 	$nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7);
459
-	if (($month_info['last_day']['day_of_month'] + $nShift) % 7)
460
-		$nRows++;
473
+	if (($month_info['last_day']['day_of_month'] + $nShift) % 7) {
474
+			$nRows++;
475
+	}
461 476
 
462 477
 	// Fetch the arrays for birthdays, posted events, and holidays.
463 478
 	$bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array();
@@ -470,8 +485,9 @@  discard block
 block discarded – undo
470 485
 	{
471 486
 		$calendarGrid['week_days'][] = $count;
472 487
 		$count++;
473
-		if ($count == 7)
474
-			$count = 0;
488
+		if ($count == 7) {
489
+					$count = 0;
490
+		}
475 491
 	}
476 492
 
477 493
 	// Iterate through each week.
@@ -488,8 +504,9 @@  discard block
 block discarded – undo
488 504
 		{
489 505
 			$nDay = ($nRow * 7) + $nCol - $nShift + 1;
490 506
 
491
-			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month'])
492
-				$nDay = 0;
507
+			if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) {
508
+							$nDay = 0;
509
+			}
493 510
 
494 511
 			$date = sprintf('%04d-%02d-%02d', $year, $month, $nDay);
495 512
 
@@ -507,8 +524,9 @@  discard block
 block discarded – undo
507 524
 	}
508 525
 
509 526
 	// What is the last day of the month?
510
-	if ($is_previous === true)
511
-		$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
527
+	if ($is_previous === true) {
528
+			$calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month'];
529
+	}
512 530
 
513 531
 	// We'll use the shift in the template.
514 532
 	$calendarGrid['shift'] = $nShift;
@@ -542,8 +560,9 @@  discard block
 block discarded – undo
542 560
 	{
543 561
 		// Here we offset accordingly to get things to the real start of a week.
544 562
 		$date_diff = $day_of_week - $calendarOptions['start_day'];
545
-		if ($date_diff < 0)
546
-			$date_diff += 7;
563
+		if ($date_diff < 0) {
564
+					$date_diff += 7;
565
+		}
547 566
 		$new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400;
548 567
 		$day = (int) strftime('%d', $new_timestamp);
549 568
 		$month = (int) strftime('%m', $new_timestamp);
@@ -673,18 +692,20 @@  discard block
 block discarded – undo
673 692
 	{
674 693
 		foreach ($date_events as $event_key => $event_val)
675 694
 		{
676
-			if (in_array($event_val['id'], $temp))
677
-				unset($calendarGrid['events'][$date][$event_key]);
678
-			else
679
-				$temp[] = $event_val['id'];
695
+			if (in_array($event_val['id'], $temp)) {
696
+							unset($calendarGrid['events'][$date][$event_key]);
697
+			} else {
698
+							$temp[] = $event_val['id'];
699
+			}
680 700
 		}
681 701
 	}
682 702
 
683 703
 	// Give birthdays and holidays a friendly format, without the year
684
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
685
-		$date_format = '%b %d';
686
-	else
687
-		$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
704
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
705
+			$date_format = '%b %d';
706
+	} else {
707
+			$date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]);
708
+	}
688 709
 
689 710
 	foreach (array('birthdays', 'holidays') as $type)
690 711
 	{
@@ -779,8 +800,9 @@  discard block
 block discarded – undo
779 800
 	// Holidays between now and now + days.
780 801
 	for ($i = $now; $i < $now + $days_for_index; $i += 86400)
781 802
 	{
782
-		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)]))
783
-			$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
803
+		if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) {
804
+					$return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]);
805
+		}
784 806
 	}
785 807
 
786 808
 	// Happy Birthday, guys and gals!
@@ -789,8 +811,9 @@  discard block
 block discarded – undo
789 811
 		$loop_date = strftime('%Y-%m-%d', $i);
790 812
 		if (isset($cached_data['birthdays'][$loop_date]))
791 813
 		{
792
-			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy)
793
-				$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
814
+			foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) {
815
+							$cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date'];
816
+			}
794 817
 			$return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]);
795 818
 		}
796 819
 	}
@@ -802,8 +825,9 @@  discard block
 block discarded – undo
802 825
 		$loop_date = strftime('%Y-%m-%d', $i);
803 826
 
804 827
 		// No events today? Check the next day.
805
-		if (empty($cached_data['events'][$loop_date]))
806
-			continue;
828
+		if (empty($cached_data['events'][$loop_date])) {
829
+					continue;
830
+		}
807 831
 
808 832
 		// Loop through all events to add a few last-minute values.
809 833
 		foreach ($cached_data['events'][$loop_date] as $ev => $event)
@@ -816,9 +840,9 @@  discard block
 block discarded – undo
816 840
 			{
817 841
 				unset($cached_data['events'][$loop_date][$ev]);
818 842
 				continue;
843
+			} else {
844
+							$duplicates[$this_event['topic'] . $this_event['title']] = true;
819 845
 			}
820
-			else
821
-				$duplicates[$this_event['topic'] . $this_event['title']] = true;
822 846
 
823 847
 			// Might be set to true afterwards, depending on the permissions.
824 848
 			$this_event['can_edit'] = false;
@@ -826,15 +850,18 @@  discard block
 block discarded – undo
826 850
 			$this_event['date'] = $loop_date;
827 851
 		}
828 852
 
829
-		if (!empty($cached_data['events'][$loop_date]))
830
-			$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
853
+		if (!empty($cached_data['events'][$loop_date])) {
854
+					$return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]);
855
+		}
831 856
 	}
832 857
 
833 858
 	// Mark the last item so that a list separator can be used in the template.
834
-	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++)
835
-		$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
836
-	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++)
837
-		$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
859
+	for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) {
860
+			$return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]);
861
+	}
862
+	for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) {
863
+			$return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]);
864
+	}
838 865
 
839 866
 	return array(
840 867
 		'data' => $return_data,
@@ -882,37 +909,46 @@  discard block
 block discarded – undo
882 909
 		if (isset($_POST['start_date']))
883 910
 		{
884 911
 			$d = date_parse($_POST['start_date']);
885
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
886
-				fatal_lang_error('invalid_date', false);
887
-			if (empty($d['year']))
888
-				fatal_lang_error('event_year_missing', false);
889
-			if (empty($d['month']))
890
-				fatal_lang_error('event_month_missing', false);
891
-		}
892
-		elseif (isset($_POST['start_datetime']))
912
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
913
+							fatal_lang_error('invalid_date', false);
914
+			}
915
+			if (empty($d['year'])) {
916
+							fatal_lang_error('event_year_missing', false);
917
+			}
918
+			if (empty($d['month'])) {
919
+							fatal_lang_error('event_month_missing', false);
920
+			}
921
+		} elseif (isset($_POST['start_datetime']))
893 922
 		{
894 923
 			$d = date_parse($_POST['start_datetime']);
895
-			if (!empty($d['error_count']) || !empty($d['warning_count']))
896
-				fatal_lang_error('invalid_date', false);
897
-			if (empty($d['year']))
898
-				fatal_lang_error('event_year_missing', false);
899
-			if (empty($d['month']))
900
-				fatal_lang_error('event_month_missing', false);
924
+			if (!empty($d['error_count']) || !empty($d['warning_count'])) {
925
+							fatal_lang_error('invalid_date', false);
926
+			}
927
+			if (empty($d['year'])) {
928
+							fatal_lang_error('event_year_missing', false);
929
+			}
930
+			if (empty($d['month'])) {
931
+							fatal_lang_error('event_month_missing', false);
932
+			}
901 933
 		}
902 934
 		// The 2.0 way
903 935
 		else
904 936
 		{
905 937
 			// No month?  No year?
906
-			if (!isset($_POST['month']))
907
-				fatal_lang_error('event_month_missing', false);
908
-			if (!isset($_POST['year']))
909
-				fatal_lang_error('event_year_missing', false);
938
+			if (!isset($_POST['month'])) {
939
+							fatal_lang_error('event_month_missing', false);
940
+			}
941
+			if (!isset($_POST['year'])) {
942
+							fatal_lang_error('event_year_missing', false);
943
+			}
910 944
 
911 945
 			// Check the month and year...
912
-			if ($_POST['month'] < 1 || $_POST['month'] > 12)
913
-				fatal_lang_error('invalid_month', false);
914
-			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear'])
915
-				fatal_lang_error('invalid_year', false);
946
+			if ($_POST['month'] < 1 || $_POST['month'] > 12) {
947
+							fatal_lang_error('invalid_month', false);
948
+			}
949
+			if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) {
950
+							fatal_lang_error('invalid_year', false);
951
+			}
916 952
 		}
917 953
 	}
918 954
 
@@ -922,8 +958,9 @@  discard block
 block discarded – undo
922 958
 	// If they want to us to calculate an end date, make sure it will fit in an acceptable range.
923 959
 	if (isset($_POST['span']))
924 960
 	{
925
-		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan']))
926
-			fatal_lang_error('invalid_days_numb', false);
961
+		if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) {
962
+					fatal_lang_error('invalid_days_numb', false);
963
+		}
927 964
 	}
928 965
 
929 966
 	// There is no need to validate the following values if we are just deleting the event.
@@ -933,24 +970,29 @@  discard block
 block discarded – undo
933 970
 		if (empty($_POST['start_date']) && empty($_POST['start_datetime']))
934 971
 		{
935 972
 			// No day?
936
-			if (!isset($_POST['day']))
937
-				fatal_lang_error('event_day_missing', false);
973
+			if (!isset($_POST['day'])) {
974
+							fatal_lang_error('event_day_missing', false);
975
+			}
938 976
 
939 977
 			// Bad day?
940
-			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year']))
941
-				fatal_lang_error('invalid_date', false);
978
+			if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) {
979
+							fatal_lang_error('invalid_date', false);
980
+			}
942 981
 		}
943 982
 
944
-		if (!isset($_POST['evtitle']) && !isset($_POST['subject']))
945
-			fatal_lang_error('event_title_missing', false);
946
-		elseif (!isset($_POST['evtitle']))
947
-			$_POST['evtitle'] = $_POST['subject'];
983
+		if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) {
984
+					fatal_lang_error('event_title_missing', false);
985
+		} elseif (!isset($_POST['evtitle'])) {
986
+					$_POST['evtitle'] = $_POST['subject'];
987
+		}
948 988
 
949 989
 		// No title?
950
-		if ($smcFunc['htmltrim']($_POST['evtitle']) === '')
951
-			fatal_lang_error('no_event_title', false);
952
-		if ($smcFunc['strlen']($_POST['evtitle']) > 100)
953
-			$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
990
+		if ($smcFunc['htmltrim']($_POST['evtitle']) === '') {
991
+					fatal_lang_error('no_event_title', false);
992
+		}
993
+		if ($smcFunc['strlen']($_POST['evtitle']) > 100) {
994
+					$_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100);
995
+		}
954 996
 		$_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']);
955 997
 	}
956 998
 }
@@ -977,8 +1019,9 @@  discard block
 block discarded – undo
977 1019
 	);
978 1020
 
979 1021
 	// No results, return false.
980
-	if ($smcFunc['db_num_rows'] === 0)
981
-		return false;
1022
+	if ($smcFunc['db_num_rows'] === 0) {
1023
+			return false;
1024
+	}
982 1025
 
983 1026
 	// Grab the results and return.
984 1027
 	list ($poster) = $smcFunc['db_fetch_row']($request);
@@ -1112,8 +1155,9 @@  discard block
 block discarded – undo
1112 1155
 	call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters));
1113 1156
 
1114 1157
 	$column_clauses = array();
1115
-	foreach ($event_columns as $col => $crit)
1116
-		$column_clauses[] = $col . ' = ' . $crit;
1158
+	foreach ($event_columns as $col => $crit) {
1159
+			$column_clauses[] = $col . ' = ' . $crit;
1160
+	}
1117 1161
 
1118 1162
 	$smcFunc['db_query']('', '
1119 1163
 		UPDATE {db_prefix}calendar
@@ -1198,8 +1242,9 @@  discard block
 block discarded – undo
1198 1242
 	);
1199 1243
 
1200 1244
 	// If nothing returned, we are in poo, poo.
1201
-	if ($smcFunc['db_num_rows']($request) === 0)
1202
-		return false;
1245
+	if ($smcFunc['db_num_rows']($request) === 0) {
1246
+			return false;
1247
+	}
1203 1248
 
1204 1249
 	$row = $smcFunc['db_fetch_assoc']($request);
1205 1250
 	$smcFunc['db_free_result']($request);
@@ -1207,8 +1252,9 @@  discard block
 block discarded – undo
1207 1252
 	list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
1208 1253
 
1209 1254
 	// Sanity check
1210
-	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
1211
-		return false;
1255
+	if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
1256
+			return false;
1257
+	}
1212 1258
 
1213 1259
 	$return_value = array(
1214 1260
 		'boards' => array(),
@@ -1345,24 +1391,27 @@  discard block
 block discarded – undo
1345 1391
 
1346 1392
 	// Set $span, in case we need it
1347 1393
 	$span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0);
1348
-	if ($span > 0)
1349
-		$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1394
+	if ($span > 0) {
1395
+			$span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1;
1396
+	}
1350 1397
 
1351 1398
 	// Define the timezone for this event, falling back to the default if not provided
1352
-	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1353
-		$tz = $eventOptions['tz'];
1354
-	elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1355
-		$tz = $_POST['tz'];
1356
-	else
1357
-		$tz = getUserTimezone();
1399
+	if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1400
+			$tz = $eventOptions['tz'];
1401
+	} elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1402
+			$tz = $_POST['tz'];
1403
+	} else {
1404
+			$tz = getUserTimezone();
1405
+	}
1358 1406
 
1359 1407
 	// Is this supposed to be an all day event, or should it have specific start and end times?
1360
-	if (isset($eventOptions['allday']))
1361
-		$allday = $eventOptions['allday'];
1362
-	elseif (empty($_POST['allday']))
1363
-		$allday = false;
1364
-	else
1365
-		$allday = true;
1408
+	if (isset($eventOptions['allday'])) {
1409
+			$allday = $eventOptions['allday'];
1410
+	} elseif (empty($_POST['allday'])) {
1411
+			$allday = false;
1412
+	} else {
1413
+			$allday = true;
1414
+	}
1366 1415
 
1367 1416
 	// Input might come as individual parameters...
1368 1417
 	$start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null);
@@ -1389,10 +1438,12 @@  discard block
 block discarded – undo
1389 1438
 	$end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null);
1390 1439
 
1391 1440
 	// If the date and time were given in separate strings, combine them
1392
-	if (empty($start_string) && isset($start_date_string))
1393
-		$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1394
-	if (empty($end_string) && isset($end_date_string))
1395
-		$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1441
+	if (empty($start_string) && isset($start_date_string)) {
1442
+			$start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : '');
1443
+	}
1444
+	if (empty($end_string) && isset($end_date_string)) {
1445
+			$end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : '');
1446
+	}
1396 1447
 
1397 1448
 	// If some form of string input was given, override individually defined options with it
1398 1449
 	if (isset($start_string))
@@ -1483,10 +1534,11 @@  discard block
 block discarded – undo
1483 1534
 	if ($start_object >= $end_object)
1484 1535
 	{
1485 1536
 		$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1486
-		if ($span > 0)
1487
-			date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1488
-		else
1489
-			date_add($end_object, date_interval_create_from_date_string('1 hour'));
1537
+		if ($span > 0) {
1538
+					date_add($end_object, date_interval_create_from_date_string($span . ' days'));
1539
+		} else {
1540
+					date_add($end_object, date_interval_create_from_date_string('1 hour'));
1541
+		}
1490 1542
 	}
1491 1543
 
1492 1544
 	// Is $end_object too late?
@@ -1499,9 +1551,9 @@  discard block
 block discarded – undo
1499 1551
 			{
1500 1552
 				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz);
1501 1553
 				date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days'));
1554
+			} else {
1555
+							$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1502 1556
 			}
1503
-			else
1504
-				$end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz);
1505 1557
 		}
1506 1558
 	}
1507 1559
 
@@ -1514,8 +1566,7 @@  discard block
 block discarded – undo
1514 1566
 		$start_time = null;
1515 1567
 		$end_time = null;
1516 1568
 		$tz = null;
1517
-	}
1518
-	else
1569
+	} else
1519 1570
 	{
1520 1571
 		$start_time = date_format($start_object, 'H:i:s');
1521 1572
 		$end_time = date_format($end_object, 'H:i:s');
@@ -1536,16 +1587,18 @@  discard block
 block discarded – undo
1536 1587
 	require_once($sourcedir . '/Subs.php');
1537 1588
 
1538 1589
 	// First, try to create a better date format, ignoring the "time" elements.
1539
-	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1540
-		$date_format = '%F';
1541
-	else
1542
-		$date_format = $matches[0];
1590
+	if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1591
+			$date_format = '%F';
1592
+	} else {
1593
+			$date_format = $matches[0];
1594
+	}
1543 1595
 
1544 1596
 	// We want a fairly compact version of the time, but as close as possible to the user's settings.
1545
-	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
1546
-		$time_format = '%k:%M';
1547
-	else
1548
-		$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1597
+	if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
1598
+			$time_format = '%k:%M';
1599
+	} else {
1600
+			$time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
1601
+	}
1549 1602
 
1550 1603
 	// Should this be an all day event?
1551 1604
 	$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
@@ -1554,8 +1607,9 @@  discard block
 block discarded – undo
1554 1607
 	$span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d');
1555 1608
 
1556 1609
 	// We need to have a defined timezone in the steps below
1557
-	if (empty($row['timezone']))
1558
-		$row['timezone'] = getUserTimezone();
1610
+	if (empty($row['timezone'])) {
1611
+			$row['timezone'] = getUserTimezone();
1612
+	}
1559 1613
 
1560 1614
 	// Get most of the standard date information for the start and end datetimes
1561 1615
 	$start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''));
@@ -1607,8 +1661,9 @@  discard block
 block discarded – undo
1607 1661
 	global $smcFunc, $context, $user_info, $modSettings, $user_settings;
1608 1662
 	static $member_cache = array();
1609 1663
 
1610
-	if (is_null($id_member) && $user_info['is_guest'] == false)
1611
-		$id_member = $context['user']['id'];
1664
+	if (is_null($id_member) && $user_info['is_guest'] == false) {
1665
+			$id_member = $context['user']['id'];
1666
+	}
1612 1667
 
1613 1668
 	//check if the cache got the data
1614 1669
 	if (isset($id_member) && isset($member_cache[$id_member]))
@@ -1637,11 +1692,13 @@  discard block
 block discarded – undo
1637 1692
 		$smcFunc['db_free_result']($request);
1638 1693
 	}
1639 1694
 
1640
-	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
1641
-		$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1695
+	if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) {
1696
+			$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();
1697
+	}
1642 1698
 
1643
-	if (isset($id_member))
1644
-		$member_cache[$id_member] = $timezone;
1699
+	if (isset($id_member)) {
1700
+			$member_cache[$id_member] = $timezone;
1701
+	}
1645 1702
 
1646 1703
 	return $timezone;
1647 1704
 }
@@ -1670,8 +1727,9 @@  discard block
 block discarded – undo
1670 1727
 		)
1671 1728
 	);
1672 1729
 	$holidays = array();
1673
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1674
-		$holidays[] = $row;
1730
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1731
+			$holidays[] = $row;
1732
+	}
1675 1733
 	$smcFunc['db_free_result']($request);
1676 1734
 
1677 1735
 	return $holidays;
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 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * 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
 	{
@@ -240,8 +248,7 @@  discard block
 block discarded – undo
240 248
 					'language' => $language_ftx
241 249
 				)
242 250
 			);
243
-		}
244
-		else
251
+		} else
245 252
 		{
246 253
 			// Make sure it's gone before creating it.
247 254
 			$smcFunc['db_query']('', '
@@ -259,8 +266,7 @@  discard block
 block discarded – undo
259 266
 				)
260 267
 			);
261 268
 		}
262
-	}
263
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
269
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index']))
264 270
 	{
265 271
 		checkSession('get');
266 272
 		validateToken('admin-msm', 'get');
@@ -277,12 +283,12 @@  discard block
 block discarded – undo
277 283
 		$context['fulltext_index'] = array();
278 284
 
279 285
 		// Go back to the default search method.
280
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext')
281
-			updateSettings(array(
286
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') {
287
+					updateSettings(array(
282 288
 				'search_index' => '',
283 289
 			));
284
-	}
285
-	elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
290
+		}
291
+	} elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom')
286 292
 	{
287 293
 		checkSession('get');
288 294
 		validateToken('admin-msm', 'get');
@@ -304,12 +310,12 @@  discard block
 block discarded – undo
304 310
 		));
305 311
 
306 312
 		// Go back to the default search method.
307
-		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
308
-			updateSettings(array(
313
+		if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
314
+					updateSettings(array(
309 315
 				'search_index' => '',
310 316
 			));
311
-	}
312
-	elseif (isset($_POST['save']))
317
+		}
318
+	} elseif (isset($_POST['save']))
313 319
 	{
314 320
 		checkSession();
315 321
 		validateToken('admin-msmpost');
@@ -331,8 +337,8 @@  discard block
 block discarded – undo
331 337
 	// Get some info about the messages table, to show its size and index size.
332 338
 	if ($db_type == 'mysql')
333 339
 	{
334
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
335
-			$request = $smcFunc['db_query']('', '
340
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
341
+					$request = $smcFunc['db_query']('', '
336 342
 				SHOW TABLE STATUS
337 343
 				FROM {string:database_name}
338 344
 				LIKE {string:table_name}',
@@ -341,14 +347,15 @@  discard block
 block discarded – undo
341 347
 					'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
342 348
 				)
343 349
 			);
344
-		else
345
-			$request = $smcFunc['db_query']('', '
350
+		} else {
351
+					$request = $smcFunc['db_query']('', '
346 352
 				SHOW TABLE STATUS
347 353
 				LIKE {string:table_name}',
348 354
 				array(
349 355
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
350 356
 				)
351 357
 			);
358
+		}
352 359
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
353 360
 		{
354 361
 			// Only do this if the user has permission to execute this query.
@@ -360,8 +367,8 @@  discard block
 block discarded – undo
360 367
 		}
361 368
 
362 369
 		// Now check the custom index table, if it exists at all.
363
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
364
-			$request = $smcFunc['db_query']('', '
370
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
371
+					$request = $smcFunc['db_query']('', '
365 372
 				SHOW TABLE STATUS
366 373
 				FROM {string:database_name}
367 374
 				LIKE {string:table_name}',
@@ -370,14 +377,15 @@  discard block
 block discarded – undo
370 377
 					'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words',
371 378
 				)
372 379
 			);
373
-		else
374
-			$request = $smcFunc['db_query']('', '
380
+		} else {
381
+					$request = $smcFunc['db_query']('', '
375 382
 				SHOW TABLE STATUS
376 383
 				LIKE {string:table_name}',
377 384
 				array(
378 385
 					'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words',
379 386
 				)
380 387
 			);
388
+		}
381 389
 		if ($request !== false && $smcFunc['db_num_rows']($request) == 1)
382 390
 		{
383 391
 			// Only do this if the user has permission to execute this query.
@@ -386,8 +394,7 @@  discard block
 block discarded – undo
386 394
 			$context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length'];
387 395
 			$smcFunc['db_free_result']($request);
388 396
 		}
389
-	}
390
-	elseif ($db_type == 'postgresql')
397
+	} elseif ($db_type == 'postgresql')
391 398
 	{
392 399
 		// In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using.
393 400
 		//db_extend();
@@ -429,38 +436,38 @@  discard block
 block discarded – undo
429 436
 					$context['table_info']['data_length'] = (int) $row['table_size'];
430 437
 					$context['table_info']['index_length'] = (int) $row['index_size'];
431 438
 					$context['table_info']['fulltext_length'] = (int) $row['index_size'];
432
-				}
433
-				elseif ($row['indexname'] == $db_prefix . 'log_search_words')
439
+				} elseif ($row['indexname'] == $db_prefix . 'log_search_words')
434 440
 				{
435 441
 					$context['table_info']['index_length'] = (int) $row['index_size'];
436 442
 					$context['table_info']['custom_index_length'] = (int) $row['index_size'];
437 443
 				}
438 444
 			}
439 445
 			$smcFunc['db_free_result']($request);
440
-		}
441
-		else
442
-			// Didn't work for some reason...
446
+		} else {
447
+					// Didn't work for some reason...
443 448
 			$context['table_info'] = array(
444 449
 				'data_length' => $txt['not_applicable'],
445 450
 				'index_length' => $txt['not_applicable'],
446 451
 				'fulltext_length' => $txt['not_applicable'],
447 452
 				'custom_index_length' => $txt['not_applicable'],
448 453
 			);
449
-	}
450
-	else
451
-		$context['table_info'] = array(
454
+		}
455
+	} else {
456
+			$context['table_info'] = array(
452 457
 			'data_length' => $txt['not_applicable'],
453 458
 			'index_length' => $txt['not_applicable'],
454 459
 			'fulltext_length' => $txt['not_applicable'],
455 460
 			'custom_index_length' => $txt['not_applicable'],
456 461
 		);
462
+	}
457 463
 
458 464
 	// Format the data and index length in kilobytes.
459 465
 	foreach ($context['table_info'] as $type => $size)
460 466
 	{
461 467
 		// If it's not numeric then just break.  This database engine doesn't support size.
462
-		if (!is_numeric($size))
463
-			break;
468
+		if (!is_numeric($size)) {
469
+					break;
470
+		}
464 471
 
465 472
 		$context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes'];
466 473
 	}
@@ -489,8 +496,9 @@  discard block
 block discarded – undo
489 496
 
490 497
 	// Scotty, we need more time...
491 498
 	@set_time_limit(600);
492
-	if (function_exists('apache_reset_timeout'))
493
-		@apache_reset_timeout();
499
+	if (function_exists('apache_reset_timeout')) {
500
+			@apache_reset_timeout();
501
+	}
494 502
 
495 503
 	$context[$context['admin_menu_name']]['current_subsection'] = 'method';
496 504
 	$context['page_title'] = $txt['search_index_custom'];
@@ -520,8 +528,7 @@  discard block
 block discarded – undo
520 528
 		$context['start'] = (int) $context['index_settings']['resume_at'];
521 529
 		unset($context['index_settings']['resume_at']);
522 530
 		$context['step'] = 1;
523
-	}
524
-	else
531
+	} else
525 532
 	{
526 533
 		$context['index_settings'] = array(
527 534
 			'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2,
@@ -530,12 +537,14 @@  discard block
 block discarded – undo
530 537
 		$context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
531 538
 
532 539
 		// admin timeouts are painful when building these long indexes - but only if we actually have such things enabled
533
-		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1)
534
-			$_SESSION['admin_time'] = time();
540
+		if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) {
541
+					$_SESSION['admin_time'] = time();
542
+		}
535 543
 	}
536 544
 
537
-	if ($context['step'] !== 0)
538
-		checkSession('request');
545
+	if ($context['step'] !== 0) {
546
+			checkSession('request');
547
+	}
539 548
 
540 549
 	// Step 0: let the user determine how they like their index.
541 550
 	if ($context['step'] === 0)
@@ -564,12 +573,14 @@  discard block
 block discarded – undo
564 573
 			$smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']);
565 574
 
566 575
 			// Temporarily switch back to not using a search index.
567
-			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom')
568
-				updateSettings(array('search_index' => ''));
576
+			if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') {
577
+							updateSettings(array('search_index' => ''));
578
+			}
569 579
 
570 580
 			// Don't let simultanious processes be updating the search index.
571
-			if (!empty($modSettings['search_custom_index_config']))
572
-				updateSettings(array('search_custom_index_config' => ''));
581
+			if (!empty($modSettings['search_custom_index_config'])) {
582
+							updateSettings(array('search_custom_index_config' => ''));
583
+			}
573 584
 		}
574 585
 
575 586
 		$num_messages = array(
@@ -585,16 +596,16 @@  discard block
 block discarded – undo
585 596
 				'starting_id' => $context['start'],
586 597
 			)
587 598
 		);
588
-		while ($row = $smcFunc['db_fetch_assoc']($request))
589
-			$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
599
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
600
+					$num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages'];
601
+		}
590 602
 
591 603
 		if (empty($num_messages['todo']))
592 604
 		{
593 605
 			$context['step'] = 2;
594 606
 			$context['percentage'] = 80;
595 607
 			$context['start'] = 0;
596
-		}
597
-		else
608
+		} else
598 609
 		{
599 610
 			// Number of seconds before the next step.
600 611
 			$stop = time() + 3;
@@ -635,21 +646,22 @@  discard block
 block discarded – undo
635 646
 
636 647
 				$context['start'] += $forced_break ? $number_processed : $messages_per_batch;
637 648
 
638
-				if (!empty($inserts))
639
-					$smcFunc['db_insert']('ignore',
649
+				if (!empty($inserts)) {
650
+									$smcFunc['db_insert']('ignore',
640 651
 						'{db_prefix}log_search_words',
641 652
 						array('id_word' => 'int', 'id_msg' => 'int'),
642 653
 						$inserts,
643 654
 						array('id_word', 'id_msg')
644 655
 					);
656
+				}
645 657
 				if ($num_messages['todo'] === 0)
646 658
 				{
647 659
 					$context['step'] = 2;
648 660
 					$context['start'] = 0;
649 661
 					break;
662
+				} else {
663
+									updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
650 664
 				}
651
-				else
652
-					updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start'])))));
653 665
 			}
654 666
 
655 667
 			// Since there are still two steps to go, 80% is the maximum here.
@@ -660,9 +672,9 @@  discard block
 block discarded – undo
660 672
 	// Step 2: removing the words that occur too often and are of no use.
661 673
 	elseif ($context['step'] === 2)
662 674
 	{
663
-		if ($context['index_settings']['bytes_per_word'] < 4)
664
-			$context['step'] = 3;
665
-		else
675
+		if ($context['index_settings']['bytes_per_word'] < 4) {
676
+					$context['step'] = 3;
677
+		} else
666 678
 		{
667 679
 			$stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']);
668 680
 			$stop = time() + 3;
@@ -683,20 +695,22 @@  discard block
 block discarded – undo
683 695
 						'minimum_messages' => $max_messages,
684 696
 					)
685 697
 				);
686
-				while ($row = $smcFunc['db_fetch_assoc']($request))
687
-					$stop_words[] = $row['id_word'];
698
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
699
+									$stop_words[] = $row['id_word'];
700
+				}
688 701
 				$smcFunc['db_free_result']($request);
689 702
 
690 703
 				updateSettings(array('search_stopwords' => implode(',', $stop_words)));
691 704
 
692
-				if (!empty($stop_words))
693
-					$smcFunc['db_query']('', '
705
+				if (!empty($stop_words)) {
706
+									$smcFunc['db_query']('', '
694 707
 						DELETE FROM {db_prefix}log_search_words
695 708
 						WHERE id_word in ({array_int:stop_words})',
696 709
 						array(
697 710
 							'stop_words' => $stop_words,
698 711
 						)
699 712
 					);
713
+				}
700 714
 
701 715
 				$context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size'];
702 716
 				if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size'])
@@ -757,8 +771,9 @@  discard block
 block discarded – undo
757 771
 					$searchAPI = new $search_class_name();
758 772
 
759 773
 					// No Support?  NEXT!
760
-					if (!$searchAPI->is_supported)
761
-						continue;
774
+					if (!$searchAPI->is_supported) {
775
+											continue;
776
+					}
762 777
 
763 778
 					$apis[$index_name] = array(
764 779
 						'filename' => $file,
@@ -805,10 +820,10 @@  discard block
 block discarded – undo
805 820
 				'messages_ftx' => $db_prefix . 'messages_ftx',
806 821
 			)
807 822
 		);
808
-		while ($row = $smcFunc['db_fetch_assoc']($request))
809
-			$context['fulltext_index'][] = $row['indexname'];
810
-	}
811
-	else
823
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
824
+					$context['fulltext_index'][] = $row['indexname'];
825
+		}
826
+	} else
812 827
 	{
813 828
 		$request = $smcFunc['db_query']('', '
814 829
 			SHOW INDEX
@@ -819,17 +834,19 @@  discard block
 block discarded – undo
819 834
 		$context['fulltext_index'] = array();
820 835
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
821 836
 		{
822
-			while ($row = $smcFunc['db_fetch_assoc']($request))
823
-			if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
837
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
838
+						if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
824 839
 				$context['fulltext_index'][] = $row['Key_name'];
840
+			}
825 841
 			$smcFunc['db_free_result']($request);
826 842
 
827
-			if (is_array($context['fulltext_index']))
828
-				$context['fulltext_index'] = array_unique($context['fulltext_index']);
843
+			if (is_array($context['fulltext_index'])) {
844
+							$context['fulltext_index'] = array_unique($context['fulltext_index']);
845
+			}
829 846
 		}
830 847
 
831
-		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0)
832
-			$request = $smcFunc['db_query']('', '
848
+		if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) {
849
+					$request = $smcFunc['db_query']('', '
833 850
 			SHOW TABLE STATUS
834 851
 			FROM {string:database_name}
835 852
 			LIKE {string:table_name}',
@@ -838,20 +855,22 @@  discard block
 block discarded – undo
838 855
 				'table_name' => str_replace('_', '\_', $match[2]) . 'messages',
839 856
 			)
840 857
 			);
841
-		else
842
-			$request = $smcFunc['db_query']('', '
858
+		} else {
859
+					$request = $smcFunc['db_query']('', '
843 860
 			SHOW TABLE STATUS
844 861
 			LIKE {string:table_name}',
845 862
 			array(
846 863
 				'table_name' => str_replace('_', '\_', $db_prefix) . 'messages',
847 864
 			)
848 865
 			);
866
+		}
849 867
 
850 868
 		if ($request !== false)
851 869
 		{
852
-			while ($row = $smcFunc['db_fetch_assoc']($request))
853
-			if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>=')))
870
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
871
+						if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>=')))
854 872
 				$context['cannot_create_fulltext'] = true;
873
+			}
855 874
 			$smcFunc['db_free_result']($request);
856 875
 		}
857 876
 	}
Please login to merge, or discard this patch.