Completed
Push — release-2.1 ( 05ee2b...a9fbda )
by Jeremy
14s
created
Sources/RemoveTopic.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1491,7 +1491,7 @@
 block discarded – undo
1491 1491
 
1492 1492
 /**
1493 1493
  * Try to determine if the topic has already been deleted by another user.
1494
- * @return bool False if it can't be deleted (recycling not enabled or no recycling board set), true if we've confirmed it can be deleted. Dies with an error if it's already been deleted.
1494
+ * @return boolean|null False if it can't be deleted (recycling not enabled or no recycling board set), true if we've confirmed it can be deleted. Dies with an error if it's already been deleted.
1495 1495
  */
1496 1496
 function removeDeleteConcurrence()
1497 1497
 {
Please login to merge, or discard this patch.
Braces   +267 added lines, -200 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
 /*	The contents of this file handle the deletion of topics, posts, and related
21 22
 	paraphernalia.  It has the following functions:
@@ -37,8 +38,9 @@  discard block
 block discarded – undo
37 38
 	require_once($sourcedir . '/Subs-Post.php');
38 39
 
39 40
 	// Trying to fool us around, are we?
40
-	if (empty($topic))
41
-		redirectexit();
41
+	if (empty($topic)) {
42
+			redirectexit();
43
+	}
42 44
 
43 45
 	removeDeleteConcurrence();
44 46
 
@@ -55,20 +57,23 @@  discard block
 block discarded – undo
55 57
 	list ($starter, $subject, $approved, $locked) = $smcFunc['db_fetch_row']($request);
56 58
 	$smcFunc['db_free_result']($request);
57 59
 
58
-	if ($starter == $user_info['id'] && !allowedTo('remove_any'))
59
-		isAllowedTo('remove_own');
60
-	else
61
-		isAllowedTo('remove_any');
60
+	if ($starter == $user_info['id'] && !allowedTo('remove_any')) {
61
+			isAllowedTo('remove_own');
62
+	} else {
63
+			isAllowedTo('remove_any');
64
+	}
62 65
 
63 66
 	// Can they see the topic?
64
-	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id'])
65
-		isAllowedTo('approve_posts');
67
+	if ($modSettings['postmod_active'] && !$approved && $starter != $user_info['id']) {
68
+			isAllowedTo('approve_posts');
69
+	}
66 70
 
67 71
 	// Ok, we got that far, but is it locked?
68 72
 	if ($locked)
69 73
 	{
70
-		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any')))
71
-			fatal_lang_error('cannot_remove_locked', 'user');
74
+		if (!($locked == 1 && $starter == $user_info['id'] || allowedTo('lock_any'))) {
75
+					fatal_lang_error('cannot_remove_locked', 'user');
76
+		}
72 77
 	}
73 78
 
74 79
 	// Notify people that this topic has been removed.
@@ -77,8 +82,9 @@  discard block
 block discarded – undo
77 82
 	removeTopics($topic);
78 83
 
79 84
 	// Note, only log topic ID in native form if it's not gone forever.
80
-	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id']))
81
-		logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
85
+	if (allowedTo('remove_any') || (allowedTo('remove_own') && $starter == $user_info['id'])) {
86
+			logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $board ? 'topic' : 'old_topic_id') => $topic, 'subject' => $subject, 'member' => $starter, 'board' => $board));
87
+	}
82 88
 
83 89
 	redirectexit('board=' . $board . '.0');
84 90
 }
@@ -96,8 +102,9 @@  discard block
 block discarded – undo
96 102
 	$_REQUEST['msg'] = (int) $_REQUEST['msg'];
97 103
 
98 104
 	// Is $topic set?
99
-	if (empty($topic) && isset($_REQUEST['topic']))
100
-		$topic = (int) $_REQUEST['topic'];
105
+	if (empty($topic) && isset($_REQUEST['topic'])) {
106
+			$topic = (int) $_REQUEST['topic'];
107
+	}
101 108
 
102 109
 	removeDeleteConcurrence();
103 110
 
@@ -116,44 +123,48 @@  discard block
 block discarded – undo
116 123
 	$smcFunc['db_free_result']($request);
117 124
 
118 125
 	// Verify they can see this!
119
-	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id'])
120
-		isAllowedTo('approve_posts');
126
+	if ($modSettings['postmod_active'] && !$approved && !empty($poster) && $poster != $user_info['id']) {
127
+			isAllowedTo('approve_posts');
128
+	}
121 129
 
122 130
 	if ($poster == $user_info['id'])
123 131
 	{
124 132
 		if (!allowedTo('delete_own'))
125 133
 		{
126
-			if ($starter == $user_info['id'] && !allowedTo('delete_any'))
127
-				isAllowedTo('delete_replies');
128
-			elseif (!allowedTo('delete_any'))
129
-				isAllowedTo('delete_own');
134
+			if ($starter == $user_info['id'] && !allowedTo('delete_any')) {
135
+							isAllowedTo('delete_replies');
136
+			} elseif (!allowedTo('delete_any')) {
137
+							isAllowedTo('delete_own');
138
+			}
139
+		} elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time()) {
140
+					fatal_lang_error('modify_post_time_passed', false);
130 141
 		}
131
-		elseif (!allowedTo('delete_any') && ($starter != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $post_time + $modSettings['edit_disable_time'] * 60 < time())
132
-			fatal_lang_error('modify_post_time_passed', false);
142
+	} elseif ($starter == $user_info['id'] && !allowedTo('delete_any')) {
143
+			isAllowedTo('delete_replies');
144
+	} else {
145
+			isAllowedTo('delete_any');
133 146
 	}
134
-	elseif ($starter == $user_info['id'] && !allowedTo('delete_any'))
135
-		isAllowedTo('delete_replies');
136
-	else
137
-		isAllowedTo('delete_any');
138 147
 
139 148
 	// If the full topic was removed go back to the board.
140 149
 	$full_topic = removeMessage($_REQUEST['msg']);
141 150
 
142
-	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id']))
143
-		logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
151
+	if (allowedTo('delete_any') && (!allowedTo('delete_own') || $poster != $user_info['id'])) {
152
+			logAction('delete', array('topic' => $topic, 'subject' => $subject, 'member' => $poster, 'board' => $board));
153
+	}
144 154
 
145 155
 	// We want to redirect back to recent action.
146
-	if (isset($_REQUEST['modcenter']))
147
-		redirectexit('action=moderate;area=reportedposts;done');
148
-	elseif (isset($_REQUEST['recent']))
149
-		redirectexit('action=recent');
150
-	elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u']))
151
-		redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
152
-	elseif ($full_topic)
153
-		redirectexit('board=' . $board . '.0');
154
-	else
155
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
156
-}
156
+	if (isset($_REQUEST['modcenter'])) {
157
+			redirectexit('action=moderate;area=reportedposts;done');
158
+	} elseif (isset($_REQUEST['recent'])) {
159
+			redirectexit('action=recent');
160
+	} elseif (isset($_REQUEST['profile'], $_REQUEST['start'], $_REQUEST['u'])) {
161
+			redirectexit('action=profile;u=' . $_REQUEST['u'] . ';area=showposts;start=' . $_REQUEST['start']);
162
+	} elseif ($full_topic) {
163
+			redirectexit('board=' . $board . '.0');
164
+	} else {
165
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
166
+	}
167
+	}
157 168
 
158 169
 /**
159 170
  * So long as you are sure... all old posts will be gone.
@@ -167,8 +178,9 @@  discard block
 block discarded – undo
167 178
 	checkSession('post', 'admin');
168 179
 
169 180
 	// No boards at all?  Forget it then :/.
170
-	if (empty($_POST['boards']))
171
-		redirectexit('action=admin;area=maintain;sa=topics');
181
+	if (empty($_POST['boards'])) {
182
+			redirectexit('action=admin;area=maintain;sa=topics');
183
+	}
172 184
 
173 185
 	// This should exist, but we can make sure.
174 186
 	$_POST['delete_type'] = isset($_POST['delete_type']) ? $_POST['delete_type'] : 'nothing';
@@ -222,8 +234,9 @@  discard block
 block discarded – undo
222 234
 		$condition_params
223 235
 	);
224 236
 	$topics = array();
225
-	while ($row = $smcFunc['db_fetch_assoc']($request))
226
-		$topics[] = $row['id_topic'];
237
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
238
+			$topics[] = $row['id_topic'];
239
+	}
227 240
 	$smcFunc['db_free_result']($request);
228 241
 
229 242
 	removeTopics($topics, false, true);
@@ -247,11 +260,13 @@  discard block
 block discarded – undo
247 260
 	global $sourcedir, $modSettings, $smcFunc;
248 261
 
249 262
 	// Nothing to do?
250
-	if (empty($topics))
251
-		return;
263
+	if (empty($topics)) {
264
+			return;
265
+	}
252 266
 	// Only a single topic.
253
-	if (is_numeric($topics))
254
-		$topics = array($topics);
267
+	if (is_numeric($topics)) {
268
+			$topics = array($topics);
269
+	}
255 270
 
256 271
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
257 272
 
@@ -276,8 +291,9 @@  discard block
 block discarded – undo
276 291
 		);
277 292
 		if ($smcFunc['db_num_rows']($requestMembers) > 0)
278 293
 		{
279
-			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers))
280
-				updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
294
+			while ($rowMembers = $smcFunc['db_fetch_assoc']($requestMembers)) {
295
+							updateMemberData($rowMembers['id_member'], array('posts' => 'posts - ' . $rowMembers['posts']));
296
+			}
281 297
 		}
282 298
 		$smcFunc['db_free_result']($requestMembers);
283 299
 	}
@@ -303,8 +319,9 @@  discard block
 block discarded – undo
303 319
 			$recycleTopics = array();
304 320
 			while ($row = $smcFunc['db_fetch_assoc']($request))
305 321
 			{
306
-				if (function_exists('apache_reset_timeout'))
307
-					@apache_reset_timeout();
322
+				if (function_exists('apache_reset_timeout')) {
323
+									@apache_reset_timeout();
324
+				}
308 325
 
309 326
 				$recycleTopics[] = $row['id_topic'];
310 327
 
@@ -346,20 +363,22 @@  discard block
 block discarded – undo
346 363
 
347 364
 			// Topics that were recycled don't need to be deleted, so subtract them.
348 365
 			$topics = array_diff($topics, $recycleTopics);
366
+		} else {
367
+					$smcFunc['db_free_result']($request);
349 368
 		}
350
-		else
351
-			$smcFunc['db_free_result']($request);
352 369
 	}
353 370
 
354 371
 	// Still topics left to delete?
355
-	if (empty($topics))
356
-		return;
372
+	if (empty($topics)) {
373
+			return;
374
+	}
357 375
 
358 376
 	// Callback for search APIs to do their thing
359 377
 	require_once($sourcedir . '/Search.php');
360 378
 	$searchAPI = findSearchAPI();
361
-	if ($searchAPI->supportsMethod('topicsRemoved'))
362
-		$searchAPI->topicsRemoved($topics);
379
+	if ($searchAPI->supportsMethod('topicsRemoved')) {
380
+			$searchAPI->topicsRemoved($topics);
381
+	}
363 382
 
364 383
 	$adjustBoards = array();
365 384
 
@@ -391,10 +410,11 @@  discard block
 block discarded – undo
391 410
 		$adjustBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
392 411
 
393 412
 		// Add the topics to the right type.
394
-		if ($row['approved'])
395
-			$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
396
-		else
397
-			$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
413
+		if ($row['approved']) {
414
+					$adjustBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
415
+		} else {
416
+					$adjustBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
417
+		}
398 418
 	}
399 419
 	$smcFunc['db_free_result']($request);
400 420
 
@@ -403,8 +423,9 @@  discard block
 block discarded – undo
403 423
 		// Decrease the posts/topics...
404 424
 		foreach ($adjustBoards as $stats)
405 425
 		{
406
-			if (function_exists('apache_reset_timeout'))
407
-				@apache_reset_timeout();
426
+			if (function_exists('apache_reset_timeout')) {
427
+							@apache_reset_timeout();
428
+			}
408 429
 
409 430
 			$smcFunc['db_query']('', '
410 431
 				UPDATE {db_prefix}boards
@@ -438,8 +459,9 @@  discard block
 block discarded – undo
438 459
 		)
439 460
 	);
440 461
 	$polls = array();
441
-	while ($row = $smcFunc['db_fetch_assoc']($request))
442
-		$polls[] = $row['id_poll'];
462
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
463
+			$polls[] = $row['id_poll'];
464
+	}
443 465
 	$smcFunc['db_free_result']($request);
444 466
 
445 467
 	if (!empty($polls))
@@ -492,8 +514,9 @@  discard block
 block discarded – undo
492 514
 		);
493 515
 		while ($row = $smcFunc['db_fetch_assoc']($request))
494 516
 		{
495
-			if (function_exists('apache_reset_timeout'))
496
-				@apache_reset_timeout();
517
+			if (function_exists('apache_reset_timeout')) {
518
+							@apache_reset_timeout();
519
+			}
497 520
 
498 521
 			$words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true));
499 522
 			$messages[] = $row['id_msg'];
@@ -501,8 +524,8 @@  discard block
 block discarded – undo
501 524
 		$smcFunc['db_free_result']($request);
502 525
 		$words = array_unique($words);
503 526
 
504
-		if (!empty($words) && !empty($messages))
505
-			$smcFunc['db_query']('', '
527
+		if (!empty($words) && !empty($messages)) {
528
+					$smcFunc['db_query']('', '
506 529
 				DELETE FROM {db_prefix}log_search_words
507 530
 				WHERE id_word IN ({array_int:word_list})
508 531
 					AND id_msg IN ({array_int:message_list})',
@@ -511,6 +534,7 @@  discard block
 block discarded – undo
511 534
 					'message_list' => $messages,
512 535
 				)
513 536
 			);
537
+		}
514 538
 	}
515 539
 
516 540
 	// Delete anything related to the topic.
@@ -569,8 +593,9 @@  discard block
 block discarded – undo
569 593
 
570 594
 	require_once($sourcedir . '/Subs-Post.php');
571 595
 	$updates = array();
572
-	foreach ($adjustBoards as $stats)
573
-		$updates[] = $stats['id_board'];
596
+	foreach ($adjustBoards as $stats) {
597
+			$updates[] = $stats['id_board'];
598
+	}
574 599
 	updateLastMessages($updates);
575 600
 }
576 601
 
@@ -587,8 +612,9 @@  discard block
 block discarded – undo
587 612
 {
588 613
 	global $board, $sourcedir, $modSettings, $user_info, $smcFunc;
589 614
 
590
-	if (empty($message) || !is_numeric($message))
591
-		return false;
615
+	if (empty($message) || !is_numeric($message)) {
616
+			return false;
617
+	}
592 618
 
593 619
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
594 620
 
@@ -607,8 +633,9 @@  discard block
 block discarded – undo
607 633
 			'id_msg' => $message,
608 634
 		)
609 635
 	);
610
-	if ($smcFunc['db_num_rows']($request) == 0)
611
-		return false;
636
+	if ($smcFunc['db_num_rows']($request) == 0) {
637
+			return false;
638
+	}
612 639
 	$row = $smcFunc['db_fetch_assoc']($request);
613 640
 	$smcFunc['db_free_result']($request);
614 641
 
@@ -629,54 +656,57 @@  discard block
 block discarded – undo
629 656
 				{
630 657
 					if ($row['id_member_poster'] == $user_info['id'])
631 658
 					{
632
-						if (!$delete_replies)
633
-							fatal_lang_error('cannot_delete_replies', 'permission');
659
+						if (!$delete_replies) {
660
+													fatal_lang_error('cannot_delete_replies', 'permission');
661
+						}
662
+					} else {
663
+											fatal_lang_error('cannot_delete_own', 'permission');
634 664
 					}
635
-					else
636
-						fatal_lang_error('cannot_delete_own', 'permission');
665
+				} elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
666
+									fatal_lang_error('modify_post_time_passed', false);
637 667
 				}
638
-				elseif (($row['id_member_poster'] != $user_info['id'] || !$delete_replies) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
639
-					fatal_lang_error('modify_post_time_passed', false);
640
-			}
641
-			elseif ($row['id_member_poster'] == $user_info['id'])
668
+			} elseif ($row['id_member_poster'] == $user_info['id'])
642 669
 			{
643
-				if (!$delete_replies)
644
-					fatal_lang_error('cannot_delete_replies', 'permission');
670
+				if (!$delete_replies) {
671
+									fatal_lang_error('cannot_delete_replies', 'permission');
672
+				}
673
+			} else {
674
+							fatal_lang_error('cannot_delete_any', 'permission');
645 675
 			}
646
-			else
647
-				fatal_lang_error('cannot_delete_any', 'permission');
648 676
 		}
649 677
 
650 678
 		// Can't delete an unapproved message, if you can't see it!
651 679
 		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !(in_array(0, $delete_any) || in_array($row['id_board'], $delete_any)))
652 680
 		{
653 681
 			$approve_posts = boardsAllowedTo('approve_posts');
654
-			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts))
655
-				return false;
682
+			if (!in_array(0, $approve_posts) && !in_array($row['id_board'], $approve_posts)) {
683
+							return false;
684
+			}
656 685
 		}
657
-	}
658
-	else
686
+	} else
659 687
 	{
660 688
 		// Check permissions to delete this message.
661 689
 		if ($row['id_member'] == $user_info['id'])
662 690
 		{
663 691
 			if (!allowedTo('delete_own'))
664 692
 			{
665
-				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
666
-					isAllowedTo('delete_replies');
667
-				elseif (!allowedTo('delete_any'))
668
-					isAllowedTo('delete_own');
693
+				if ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
694
+									isAllowedTo('delete_replies');
695
+				} elseif (!allowedTo('delete_any')) {
696
+									isAllowedTo('delete_own');
697
+				}
698
+			} elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
699
+							fatal_lang_error('modify_post_time_passed', false);
669 700
 			}
670
-			elseif (!allowedTo('delete_any') && ($row['id_member_poster'] != $user_info['id'] || !allowedTo('delete_replies')) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
671
-				fatal_lang_error('modify_post_time_passed', false);
701
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any')) {
702
+					isAllowedTo('delete_replies');
703
+		} else {
704
+					isAllowedTo('delete_any');
672 705
 		}
673
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('delete_any'))
674
-			isAllowedTo('delete_replies');
675
-		else
676
-			isAllowedTo('delete_any');
677 706
 
678
-		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own'))
679
-			isAllowedTo('approve_posts');
707
+		if ($modSettings['postmod_active'] && !$row['approved'] && $row['id_member'] != $user_info['id'] && !allowedTo('delete_own')) {
708
+					isAllowedTo('approve_posts');
709
+		}
680 710
 	}
681 711
 
682 712
 	// Delete the *whole* topic, but only if the topic consists of one message.
@@ -692,31 +722,34 @@  discard block
 block discarded – undo
692 722
 				$remove_own = in_array(0, $remove_own) || in_array($row['id_board'], $remove_own);
693 723
 			}
694 724
 
695
-			if ($row['id_member'] != $user_info['id'] && !$remove_any)
696
-				fatal_lang_error('cannot_remove_any', 'permission');
697
-			elseif (!$remove_any && !$remove_own)
698
-				fatal_lang_error('cannot_remove_own', 'permission');
699
-		}
700
-		else
725
+			if ($row['id_member'] != $user_info['id'] && !$remove_any) {
726
+							fatal_lang_error('cannot_remove_any', 'permission');
727
+			} elseif (!$remove_any && !$remove_own) {
728
+							fatal_lang_error('cannot_remove_own', 'permission');
729
+			}
730
+		} else
701 731
 		{
702 732
 			// Check permissions to delete a whole topic.
703
-			if ($row['id_member'] != $user_info['id'])
704
-				isAllowedTo('remove_any');
705
-			elseif (!allowedTo('remove_any'))
706
-				isAllowedTo('remove_own');
733
+			if ($row['id_member'] != $user_info['id']) {
734
+							isAllowedTo('remove_any');
735
+			} elseif (!allowedTo('remove_any')) {
736
+							isAllowedTo('remove_own');
737
+			}
707 738
 		}
708 739
 
709 740
 		// ...if there is only one post.
710
-		if (!empty($row['num_replies']))
711
-			fatal_lang_error('delFirstPost', false);
741
+		if (!empty($row['num_replies'])) {
742
+					fatal_lang_error('delFirstPost', false);
743
+		}
712 744
 
713 745
 		removeTopics($row['id_topic']);
714 746
 		return true;
715 747
 	}
716 748
 
717 749
 	// Deleting a recycled message can not lower anyone's post count.
718
-	if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
719
-		$decreasePostCount = false;
750
+	if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
751
+			$decreasePostCount = false;
752
+	}
720 753
 
721 754
 	// This is the last post, update the last post on the board.
722 755
 	if ($row['id_last_msg'] == $message)
@@ -755,8 +788,8 @@  discard block
 block discarded – undo
755 788
 		);
756 789
 	}
757 790
 	// Only decrease post counts.
758
-	else
759
-		$smcFunc['db_query']('', '
791
+	else {
792
+			$smcFunc['db_query']('', '
760 793
 			UPDATE {db_prefix}topics
761 794
 			SET ' . ($row['approved'] ? '
762 795
 				num_replies = CASE WHEN num_replies = {int:no_replies} THEN 0 ELSE num_replies - 1 END' : '
@@ -768,6 +801,7 @@  discard block
 block discarded – undo
768 801
 				'id_topic' => $row['id_topic'],
769 802
 			)
770 803
 		);
804
+	}
771 805
 
772 806
 	// Default recycle to false.
773 807
 	$recycle = false;
@@ -787,8 +821,9 @@  discard block
 block discarded – undo
787 821
 				'recycle_board' => $modSettings['recycle_board'],
788 822
 			)
789 823
 		);
790
-		if ($smcFunc['db_num_rows']($request) == 0)
791
-			fatal_lang_error('recycle_no_valid_board');
824
+		if ($smcFunc['db_num_rows']($request) == 0) {
825
+					fatal_lang_error('recycle_no_valid_board');
826
+		}
792 827
 		list ($isRead, $last_board_msg) = $smcFunc['db_fetch_row']($request);
793 828
 		$smcFunc['db_free_result']($request);
794 829
 
@@ -807,8 +842,8 @@  discard block
 block discarded – undo
807 842
 		$smcFunc['db_free_result']($request);
808 843
 
809 844
 		// Insert a new topic in the recycle board if $id_recycle_topic is empty.
810
-		if (empty($id_recycle_topic))
811
-			$id_topic = $smcFunc['db_insert']('',
845
+		if (empty($id_recycle_topic)) {
846
+					$id_topic = $smcFunc['db_insert']('',
812 847
 				'{db_prefix}topics',
813 848
 				array(
814 849
 					'id_board' => 'int', 'id_member_started' => 'int', 'id_member_updated' => 'int', 'id_first_msg' => 'int',
@@ -821,6 +856,7 @@  discard block
 block discarded – undo
821 856
 				array('id_topic'),
822 857
 				1
823 858
 			);
859
+		}
824 860
 
825 861
 		// Capture the ID of the new topic...
826 862
 		$topicID = empty($id_recycle_topic) ? $id_topic : $id_recycle_topic;
@@ -858,22 +894,24 @@  discard block
 block discarded – undo
858 894
 			);
859 895
 
860 896
 			// Mark recycled topic as read.
861
-			if (!$user_info['is_guest'])
862
-				$smcFunc['db_insert']('replace',
897
+			if (!$user_info['is_guest']) {
898
+							$smcFunc['db_insert']('replace',
863 899
 					'{db_prefix}log_topics',
864 900
 					array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'),
865 901
 					array($topicID, $user_info['id'], $modSettings['maxMsgID'], 0),
866 902
 					array('id_topic', 'id_member')
867 903
 				);
904
+			}
868 905
 
869 906
 			// Mark recycle board as seen, if it was marked as seen before.
870
-			if (!empty($isRead) && !$user_info['is_guest'])
871
-				$smcFunc['db_insert']('replace',
907
+			if (!empty($isRead) && !$user_info['is_guest']) {
908
+							$smcFunc['db_insert']('replace',
872 909
 					'{db_prefix}log_boards',
873 910
 					array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'),
874 911
 					array($modSettings['recycle_board'], $user_info['id'], $modSettings['maxMsgID']),
875 912
 					array('id_board', 'id_member')
876 913
 				);
914
+			}
877 915
 
878 916
 			// Add one topic and post to the recycle bin board.
879 917
 			$smcFunc['db_query']('', '
@@ -891,8 +929,8 @@  discard block
 block discarded – undo
891 929
 			);
892 930
 
893 931
 			// Lets increase the num_replies, and the first/last message ID as appropriate.
894
-			if (!empty($id_recycle_topic))
895
-				$smcFunc['db_query']('', '
932
+			if (!empty($id_recycle_topic)) {
933
+							$smcFunc['db_query']('', '
896 934
 					UPDATE {db_prefix}topics
897 935
 					SET num_replies = num_replies + 1' .
898 936
 						($message > $last_topic_msg ? ', id_last_msg = {int:id_merged_msg}' : '') .
@@ -903,6 +941,7 @@  discard block
 block discarded – undo
903 941
 						'id_merged_msg' => $message,
904 942
 					)
905 943
 				);
944
+			}
906 945
 
907 946
 			// Make sure this message isn't getting deleted later on.
908 947
 			$recycle = true;
@@ -912,8 +951,8 @@  discard block
 block discarded – undo
912 951
 		}
913 952
 
914 953
 		// If it wasn't approved don't keep it in the queue.
915
-		if (!$row['approved'])
916
-			$smcFunc['db_query']('', '
954
+		if (!$row['approved']) {
955
+					$smcFunc['db_query']('', '
917 956
 				DELETE FROM {db_prefix}approval_queue
918 957
 				WHERE id_msg = {int:id_msg}
919 958
 					AND id_attach = {int:id_attach}',
@@ -922,6 +961,7 @@  discard block
 block discarded – undo
922 961
 					'id_attach' => 0,
923 962
 				)
924 963
 			);
964
+		}
925 965
 	}
926 966
 
927 967
 	$smcFunc['db_query']('', '
@@ -939,8 +979,9 @@  discard block
 block discarded – undo
939 979
 
940 980
 	// If the poster was registered and the board this message was on incremented
941 981
 	// the member's posts when it was posted, decrease his or her post count.
942
-	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved'])
943
-		updateMemberData($row['id_member'], array('posts' => '-'));
982
+	if (!empty($row['id_member']) && $decreasePostCount && empty($row['count_posts']) && $row['approved']) {
983
+			updateMemberData($row['id_member'], array('posts' => '-'));
984
+	}
944 985
 
945 986
 	// Only remove posts if they're not recycled.
946 987
 	if (!$recycle)
@@ -948,8 +989,9 @@  discard block
 block discarded – undo
948 989
 		// Callback for search APIs to do their thing
949 990
 		require_once($sourcedir . '/Search.php');
950 991
 		$searchAPI = findSearchAPI();
951
-		if ($searchAPI->supportsMethod('postRemoved'))
952
-			$searchAPI->postRemoved($message);
992
+		if ($searchAPI->supportsMethod('postRemoved')) {
993
+					$searchAPI->postRemoved($message);
994
+		}
953 995
 
954 996
 		// Remove the message!
955 997
 		$smcFunc['db_query']('', '
@@ -964,8 +1006,8 @@  discard block
 block discarded – undo
964 1006
 		{
965 1007
 			$customIndexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true);
966 1008
 			$words = text2words($row['body'], $customIndexSettings['bytes_per_word'], true);
967
-			if (!empty($words))
968
-				$smcFunc['db_query']('', '
1009
+			if (!empty($words)) {
1010
+							$smcFunc['db_query']('', '
969 1011
 					DELETE FROM {db_prefix}log_search_words
970 1012
 					WHERE id_word IN ({array_int:word_list})
971 1013
 						AND id_msg = {int:id_msg}',
@@ -974,6 +1016,7 @@  discard block
 block discarded – undo
974 1016
 						'id_msg' => $message,
975 1017
 					)
976 1018
 				);
1019
+			}
977 1020
 		}
978 1021
 
979 1022
 		// Delete attachment(s) if they exist.
@@ -997,10 +1040,11 @@  discard block
 block discarded – undo
997 1040
 
998 1041
 	// And now to update the last message of each board we messed with.
999 1042
 	require_once($sourcedir . '/Subs-Post.php');
1000
-	if ($recycle)
1001
-		updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1002
-	else
1003
-		updateLastMessages($row['id_board']);
1043
+	if ($recycle) {
1044
+			updateLastMessages(array($row['id_board'], $modSettings['recycle_board']));
1045
+	} else {
1046
+			updateLastMessages($row['id_board']);
1047
+	}
1004 1048
 
1005 1049
 	// Close any moderation reports for this message.
1006 1050
 	$smcFunc['db_query']('', '
@@ -1033,8 +1077,9 @@  discard block
 block discarded – undo
1033 1077
 	checkSession('get');
1034 1078
 
1035 1079
 	// Is recycled board enabled?
1036
-	if (empty($modSettings['recycle_enable']))
1037
-		fatal_lang_error('restored_disabled', 'critical');
1080
+	if (empty($modSettings['recycle_enable'])) {
1081
+			fatal_lang_error('restored_disabled', 'critical');
1082
+	}
1038 1083
 
1039 1084
 	// Can we be in here?
1040 1085
 	isAllowedTo('move_any', $modSettings['recycle_board']);
@@ -1049,8 +1094,9 @@  discard block
 block discarded – undo
1049 1094
 	if (!empty($_REQUEST['msgs']))
1050 1095
 	{
1051 1096
 		$msgs = explode(',', $_REQUEST['msgs']);
1052
-		foreach ($msgs as $k => $msg)
1053
-			$msgs[$k] = (int) $msg;
1097
+		foreach ($msgs as $k => $msg) {
1098
+					$msgs[$k] = (int) $msg;
1099
+		}
1054 1100
 
1055 1101
 		// Get the id_previous_board and id_previous_topic.
1056 1102
 		$request = $smcFunc['db_query']('', '
@@ -1084,8 +1130,8 @@  discard block
 block discarded – undo
1084 1130
 			}
1085 1131
 
1086 1132
 			$previous_topics[] = $row['id_previous_topic'];
1087
-			if (empty($actioned_messages[$row['id_previous_topic']]))
1088
-				$actioned_messages[$row['id_previous_topic']] = array(
1133
+			if (empty($actioned_messages[$row['id_previous_topic']])) {
1134
+							$actioned_messages[$row['id_previous_topic']] = array(
1089 1135
 					'msgs' => array(),
1090 1136
 					'count_posts' => $row['count_posts'],
1091 1137
 					'subject' => $row['subject'],
@@ -1095,17 +1141,20 @@  discard block
 block discarded – undo
1095 1141
 					'current_board' => $row['id_board'],
1096 1142
 					'members' => array(),
1097 1143
 				);
1144
+			}
1098 1145
 
1099 1146
 			$actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject'];
1100
-			if ($row['id_member'])
1101
-				$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1147
+			if ($row['id_member']) {
1148
+							$actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
1149
+			}
1102 1150
 		}
1103 1151
 		$smcFunc['db_free_result']($request);
1104 1152
 
1105 1153
 		// Check for topics we are going to fully restore.
1106
-		foreach ($actioned_messages as $topic => $data)
1107
-			if (in_array($topic, $topics_to_restore))
1154
+		foreach ($actioned_messages as $topic => $data) {
1155
+					if (in_array($topic, $topics_to_restore))
1108 1156
 				unset($actioned_messages[$topic]);
1157
+		}
1109 1158
 
1110 1159
 		// Load any previous topics to check they exist.
1111 1160
 		if (!empty($previous_topics))
@@ -1120,11 +1169,12 @@  discard block
 block discarded – undo
1120 1169
 				)
1121 1170
 			);
1122 1171
 			$previous_topics = array();
1123
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1124
-				$previous_topics[$row['id_topic']] = array(
1172
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1173
+							$previous_topics[$row['id_topic']] = array(
1125 1174
 					'board' => $row['id_board'],
1126 1175
 					'subject' => $row['subject'],
1127 1176
 				);
1177
+			}
1128 1178
 			$smcFunc['db_free_result']($request);
1129 1179
 		}
1130 1180
 
@@ -1146,11 +1196,11 @@  discard block
 block discarded – undo
1146 1196
 				// Log em.
1147 1197
 				logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board']));
1148 1198
 				$messages = array_merge(array_keys($data['msgs']), $messages);
1149
-			}
1150
-			else
1199
+			} else
1151 1200
 			{
1152
-				foreach ($data['msgs'] as $msg)
1153
-					$unfound_messages[$msg['id']] = $msg['subject'];
1201
+				foreach ($data['msgs'] as $msg) {
1202
+									$unfound_messages[$msg['id']] = $msg['subject'];
1203
+				}
1154 1204
 			}
1155 1205
 		}
1156 1206
 	}
@@ -1159,8 +1209,9 @@  discard block
 block discarded – undo
1159 1209
 	if (!empty($_REQUEST['topics']))
1160 1210
 	{
1161 1211
 		$topics = explode(',', $_REQUEST['topics']);
1162
-		foreach ($topics as $id)
1163
-			$topics_to_restore[] = (int) $id;
1212
+		foreach ($topics as $id) {
1213
+					$topics_to_restore[] = (int) $id;
1214
+		}
1164 1215
 	}
1165 1216
 
1166 1217
 	if (!empty($topics_to_restore))
@@ -1214,8 +1265,9 @@  discard block
 block discarded – undo
1214 1265
 					)
1215 1266
 				);
1216 1267
 
1217
-				while ($member = $smcFunc['db_fetch_assoc']($request2))
1218
-					updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1268
+				while ($member = $smcFunc['db_fetch_assoc']($request2)) {
1269
+									updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
1270
+				}
1219 1271
 				$smcFunc['db_free_result']($request2);
1220 1272
 			}
1221 1273
 
@@ -1226,8 +1278,9 @@  discard block
 block discarded – undo
1226 1278
 	}
1227 1279
 
1228 1280
 	// Didn't find some things?
1229
-	if (!empty($unfound_messages))
1230
-		fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1281
+	if (!empty($unfound_messages)) {
1282
+			fatal_lang_error('restore_not_found', false, array(implode('<br>', $unfound_messages)));
1283
+	}
1231 1284
 
1232 1285
 	// Just send them to the index if they get here.
1233 1286
 	redirectexit();
@@ -1247,12 +1300,14 @@  discard block
 block discarded – undo
1247 1300
 	//!!! This really needs to be rewritten to take a load of messages from ANY topic, it's also inefficient.
1248 1301
 
1249 1302
 	// Is it an array?
1250
-	if (!is_array($msgs))
1251
-		$msgs = array($msgs);
1303
+	if (!is_array($msgs)) {
1304
+			$msgs = array($msgs);
1305
+	}
1252 1306
 
1253 1307
 	// Lets make sure they are int.
1254
-	foreach ($msgs as $key => $msg)
1255
-		$msgs[$key] = (int) $msg;
1308
+	foreach ($msgs as $key => $msg) {
1309
+			$msgs[$key] = (int) $msg;
1310
+	}
1256 1311
 
1257 1312
 	// Get the source information.
1258 1313
 	$request = $smcFunc['db_query']('', '
@@ -1295,8 +1350,9 @@  discard block
 block discarded – undo
1295 1350
 			)
1296 1351
 		);
1297 1352
 
1298
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1299
-			updateMemberData($row['id_member'], array('posts' => '+'));
1353
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1354
+					updateMemberData($row['id_member'], array('posts' => '+'));
1355
+		}
1300 1356
 	}
1301 1357
 
1302 1358
 	// Time to move the messages.
@@ -1332,13 +1388,15 @@  discard block
 block discarded – undo
1332 1388
 	);
1333 1389
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1334 1390
 	{
1335
-		if ($row['id_first_msg'] < $target_topic_data['id_first_msg'])
1336
-			$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1391
+		if ($row['id_first_msg'] < $target_topic_data['id_first_msg']) {
1392
+					$target_topic_data['id_first_msg'] = $row['id_first_msg'];
1393
+		}
1337 1394
 		$target_topic_data['id_last_msg'] = $row['id_last_msg'];
1338
-		if (!$row['approved'])
1339
-			$target_topic_data['unapproved_posts'] = $row['message_count'];
1340
-		else
1341
-			$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1395
+		if (!$row['approved']) {
1396
+					$target_topic_data['unapproved_posts'] = $row['message_count'];
1397
+		} else {
1398
+					$target_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1399
+		}
1342 1400
 	}
1343 1401
 	$smcFunc['db_free_result']($request);
1344 1402
 
@@ -1397,13 +1455,15 @@  discard block
 block discarded – undo
1397 1455
 		);
1398 1456
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1399 1457
 		{
1400
-			if ($row['id_first_msg'] < $source_topic_data['id_first_msg'])
1401
-				$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1458
+			if ($row['id_first_msg'] < $source_topic_data['id_first_msg']) {
1459
+							$source_topic_data['id_first_msg'] = $row['id_first_msg'];
1460
+			}
1402 1461
 			$source_topic_data['id_last_msg'] = $row['id_last_msg'];
1403
-			if (!$row['approved'])
1404
-				$source_topic_data['unapproved_posts'] = $row['message_count'];
1405
-			else
1406
-				$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1462
+			if (!$row['approved']) {
1463
+							$source_topic_data['unapproved_posts'] = $row['message_count'];
1464
+			} else {
1465
+							$source_topic_data['num_replies'] = max(0, $row['message_count'] - 1);
1466
+			}
1407 1467
 		}
1408 1468
 		$smcFunc['db_free_result']($request);
1409 1469
 
@@ -1467,10 +1527,12 @@  discard block
 block discarded – undo
1467 1527
 
1468 1528
 	// Subject cache?
1469 1529
 	$cache_updates = array();
1470
-	if ($target_first_msg != $target_topic_data['id_first_msg'])
1471
-		$cache_updates[] = $target_topic_data['id_first_msg'];
1472
-	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg'])
1473
-		$cache_updates[] = $source_topic_data['id_first_msg'];
1530
+	if ($target_first_msg != $target_topic_data['id_first_msg']) {
1531
+			$cache_updates[] = $target_topic_data['id_first_msg'];
1532
+	}
1533
+	if (!empty($source_topic_data['id_first_msg']) && $from_first_msg != $source_topic_data['id_first_msg']) {
1534
+			$cache_updates[] = $source_topic_data['id_first_msg'];
1535
+	}
1474 1536
 
1475 1537
 	if (!empty($cache_updates))
1476 1538
 	{
@@ -1482,8 +1544,9 @@  discard block
 block discarded – undo
1482 1544
 				'first_messages' => $cache_updates,
1483 1545
 			)
1484 1546
 		);
1485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1486
-			updateStats('subject', $row['id_topic'], $row['subject']);
1547
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1548
+					updateStats('subject', $row['id_topic'], $row['subject']);
1549
+		}
1487 1550
 		$smcFunc['db_free_result']($request);
1488 1551
 	}
1489 1552
 
@@ -1499,22 +1562,26 @@  discard block
 block discarded – undo
1499 1562
 	global $modSettings, $board, $scripturl, $context;
1500 1563
 
1501 1564
 	// No recycle no need to go further
1502
-	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board']))
1503
-		return false;
1565
+	if (empty($modSettings['recycle_enable']) || empty($modSettings['recycle_board'])) {
1566
+			return false;
1567
+	}
1504 1568
 
1505 1569
 	// If it's confirmed go on and delete (from recycle)
1506
-	if (isset($_GET['confirm_delete']))
1507
-		return true;
1570
+	if (isset($_GET['confirm_delete'])) {
1571
+			return true;
1572
+	}
1508 1573
 
1509
-	if (empty($board))
1510
-		return false;
1574
+	if (empty($board)) {
1575
+			return false;
1576
+	}
1511 1577
 
1512
-	if ($modSettings['recycle_board'] != $board)
1513
-		return true;
1514
-	elseif (isset($_REQUEST['msg']))
1515
-		$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1516
-	else
1517
-		$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1578
+	if ($modSettings['recycle_board'] != $board) {
1579
+			return true;
1580
+	} elseif (isset($_REQUEST['msg'])) {
1581
+			$confirm_url = $scripturl . '?action=deletemsg;confirm_delete;topic=' . $context['current_topic'] . '.0;msg=' . $_REQUEST['msg'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1582
+	} else {
1583
+			$confirm_url = $scripturl . '?action=removetopic2;confirm_delete;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id'];
1584
+	}
1518 1585
 
1519 1586
 	fatal_lang_error('post_already_deleted', false, array($confirm_url));
1520 1587
 }
Please login to merge, or discard this patch.
Sources/Reports.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1013,7 +1013,7 @@
 block discarded – undo
1013 1013
  * @param string $title The title of the separator
1014 1014
  * @param null|string $custom_table The ID of the custom table
1015 1015
  *
1016
- * @return void|bool Returns false if there are no tables
1016
+ * @return null|false Returns false if there are no tables
1017 1017
  */
1018 1018
 function addSeparator($title = '', $custom_table = null)
1019 1019
 {
Please login to merge, or discard this patch.
Braces   +199 added lines, -148 removed lines patch added patch discarded remove patch
@@ -21,8 +21,9 @@  discard block
 block discarded – undo
21 21
  * @version 2.1 Beta 4
22 22
  */
23 23
 
24
-if (!defined('SMF'))
24
+if (!defined('SMF')) {
25 25
 	die('No direct access...');
26
+}
26 27
 
27 28
 /**
28 29
  * Handling function for generating reports.
@@ -69,14 +70,15 @@  discard block
 block discarded – undo
69 70
 	);
70 71
 
71 72
 	$is_first = 0;
72
-	foreach ($context['report_types'] as $k => $temp)
73
-		$context['report_types'][$k] = array(
73
+	foreach ($context['report_types'] as $k => $temp) {
74
+			$context['report_types'][$k] = array(
74 75
 			'id' => $k,
75 76
 			'title' => isset($txt['gr_type_' . $k]) ? $txt['gr_type_' . $k] : $k,
76 77
 			'description' => isset($txt['gr_type_desc_' . $k]) ? $txt['gr_type_desc_' . $k] : null,
77 78
 			'function' => $temp,
78 79
 			'is_first' => $is_first++ == 0,
79 80
 		);
81
+	}
80 82
 
81 83
 	// If they haven't chosen a report type which is valid, send them off to the report type chooser!
82 84
 	if (empty($_REQUEST['rt']) || !isset($context['report_types'][$_REQUEST['rt']]))
@@ -102,8 +104,9 @@  discard block
 block discarded – undo
102 104
 		$context['sub_template'] = $_REQUEST['st'];
103 105
 
104 106
 		// Are we disabling the other layers - print friendly for example?
105
-		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null)
106
-			$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
107
+		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null) {
108
+					$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
109
+		}
107 110
 	}
108 111
 
109 112
 	// Make the page title more descriptive.
@@ -151,8 +154,9 @@  discard block
 block discarded – undo
151 154
 		)
152 155
 	);
153 156
 	$moderators = array();
154
-	while ($row = $smcFunc['db_fetch_assoc']($request))
155
-		$moderators[$row['id_board']][] = $row['real_name'];
157
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
158
+			$moderators[$row['id_board']][] = $row['real_name'];
159
+	}
156 160
 	$smcFunc['db_free_result']($request);
157 161
 
158 162
 	// Get every moderator gruop.
@@ -164,8 +168,9 @@  discard block
 block discarded – undo
164 168
 		)
165 169
 	);
166 170
 	$moderator_groups = array();
167
-	while ($row = $smcFunc['db_fetch_assoc']($request))
168
-		$moderator_groups[$row['id_board']][] = $row['group_name'];
171
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
172
+			$moderator_groups[$row['id_board']][] = $row['group_name'];
173
+	}
169 174
 	$smcFunc['db_free_result']($request);
170 175
 
171 176
 	// Get all the possible membergroups!
@@ -176,8 +181,9 @@  discard block
 block discarded – undo
176 181
 		)
177 182
 	);
178 183
 	$groups = array(-1 => $txt['guest_title'], 0 => $txt['full_member']);
179
-	while ($row = $smcFunc['db_fetch_assoc']($request))
180
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
184
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
186
+	}
181 187
 	$smcFunc['db_free_result']($request);
182 188
 
183 189
 	// All the fields we'll show.
@@ -195,8 +201,9 @@  discard block
 block discarded – undo
195 201
 		'moderator_groups' => $txt['board_moderator_groups'],
196 202
 		'groups' => $txt['board_groups'],
197 203
 	);
198
-	if (!empty($modSettings['deny_boards_access']))
199
-		$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
204
+	if (!empty($modSettings['deny_boards_access'])) {
205
+			$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
206
+	}
200 207
 
201 208
 	// Do it in columns, it's just easier.
202 209
 	setKeys('cols');
@@ -222,8 +229,9 @@  discard block
 block discarded – undo
222 229
 		newTable($row['name'], '', 'left', 'auto', 'left', 200, 'left');
223 230
 
224 231
 		$this_boardSettings = $boardSettings;
225
-		if (empty($row['redirect']))
226
-			unset($this_boardSettings['redirect']);
232
+		if (empty($row['redirect'])) {
233
+					unset($this_boardSettings['redirect']);
234
+		}
227 235
 
228 236
 		// First off, add in the side key.
229 237
 		addData($this_boardSettings);
@@ -250,10 +258,11 @@  discard block
 block discarded – undo
250 258
 		$allowedGroups = explode(',', $row['member_groups']);
251 259
 		foreach ($allowedGroups as $key => $group)
252 260
 		{
253
-			if (isset($groups[$group]))
254
-				$allowedGroups[$key] = $groups[$group];
255
-			else
256
-				unset($allowedGroups[$key]);
261
+			if (isset($groups[$group])) {
262
+							$allowedGroups[$key] = $groups[$group];
263
+			} else {
264
+							unset($allowedGroups[$key]);
265
+			}
257 266
 		}
258 267
 		$boardData['groups'] = implode(', ', $allowedGroups);
259 268
 		if (!empty($modSettings['deny_boards_access']))
@@ -261,16 +270,18 @@  discard block
 block discarded – undo
261 270
 			$disallowedGroups = explode(',', $row['deny_member_groups']);
262 271
 			foreach ($disallowedGroups as $key => $group)
263 272
 			{
264
-				if (isset($groups[$group]))
265
-					$disallowedGroups[$key] = $groups[$group];
266
-				else
267
-					unset($disallowedGroups[$key]);
273
+				if (isset($groups[$group])) {
274
+									$disallowedGroups[$key] = $groups[$group];
275
+				} else {
276
+									unset($disallowedGroups[$key]);
277
+				}
268 278
 			}
269 279
 			$boardData['disallowed_groups'] = implode(', ', $disallowedGroups);
270 280
 		}
271 281
 
272
-		if (empty($row['redirect']))
273
-			unset ($boardData['redirect']);
282
+		if (empty($row['redirect'])) {
283
+					unset ($boardData['redirect']);
284
+		}
274 285
 
275 286
 		// Next add the main data.
276 287
 		addData($boardData);
@@ -295,27 +306,31 @@  discard block
 block discarded – undo
295 306
 
296 307
 	if (isset($_REQUEST['boards']))
297 308
 	{
298
-		if (!is_array($_REQUEST['boards']))
299
-			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
300
-		foreach ($_REQUEST['boards'] as $k => $dummy)
301
-			$_REQUEST['boards'][$k] = (int) $dummy;
309
+		if (!is_array($_REQUEST['boards'])) {
310
+					$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
311
+		}
312
+		foreach ($_REQUEST['boards'] as $k => $dummy) {
313
+					$_REQUEST['boards'][$k] = (int) $dummy;
314
+		}
302 315
 
303 316
 		$board_clause = 'id_board IN ({array_int:boards})';
317
+	} else {
318
+			$board_clause = '1=1';
304 319
 	}
305
-	else
306
-		$board_clause = '1=1';
307 320
 
308 321
 	if (isset($_REQUEST['groups']))
309 322
 	{
310
-		if (!is_array($_REQUEST['groups']))
311
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
312
-		foreach ($_REQUEST['groups'] as $k => $dummy)
313
-			$_REQUEST['groups'][$k] = (int) $dummy;
323
+		if (!is_array($_REQUEST['groups'])) {
324
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
325
+		}
326
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
327
+					$_REQUEST['groups'][$k] = (int) $dummy;
328
+		}
314 329
 
315 330
 		$group_clause = 'id_group IN ({array_int:groups})';
331
+	} else {
332
+			$group_clause = '1=1';
316 333
 	}
317
-	else
318
-		$group_clause = '1=1';
319 334
 
320 335
 	// Fetch all the board names.
321 336
 	$request = $smcFunc['db_query']('', '
@@ -369,12 +384,14 @@  discard block
 block discarded – undo
369 384
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
370 385
 		)
371 386
 	);
372
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
373
-		$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
374
-	else
375
-		$member_groups = array('col' => '');
376
-	while ($row = $smcFunc['db_fetch_assoc']($request))
377
-		$member_groups[$row['id_group']] = $row['group_name'];
387
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
388
+			$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
389
+	} else {
390
+			$member_groups = array('col' => '');
391
+	}
392
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
393
+			$member_groups[$row['id_group']] = $row['group_name'];
394
+	}
378 395
 	$smcFunc['db_free_result']($request);
379 396
 
380 397
 	// Make sure that every group is represented - plus in rows!
@@ -411,12 +428,14 @@  discard block
 block discarded – undo
411 428
 	);
412 429
 	while ($row = $smcFunc['db_fetch_assoc']($request))
413 430
 	{
414
-		if (in_array($row['permission'], $disabled_permissions))
415
-			continue;
431
+		if (in_array($row['permission'], $disabled_permissions)) {
432
+					continue;
433
+		}
416 434
 
417
-		foreach ($boards as $id => $board)
418
-			if ($board['profile'] == $row['id_profile'])
435
+		foreach ($boards as $id => $board) {
436
+					if ($board['profile'] == $row['id_profile'])
419 437
 				$board_permissions[$id][$row['id_group']][$row['permission']] = $row['add_deny'];
438
+		}
420 439
 
421 440
 		// Make sure we get every permission.
422 441
 		if (!isset($permissions[$row['permission']]))
@@ -451,8 +470,9 @@  discard block
 block discarded – undo
451 470
 			foreach ($member_groups as $id_group => $name)
452 471
 			{
453 472
 				// Don't overwrite the key column!
454
-				if ($id_group === 'col')
455
-					continue;
473
+				if ($id_group === 'col') {
474
+									continue;
475
+				}
456 476
 
457 477
 				$group_permissions = isset($groups[$id_group]) ? $groups[$id_group] : array();
458 478
 
@@ -474,16 +494,18 @@  discard block
 block discarded – undo
474 494
 				}
475 495
 
476 496
 				// Now actually make the data for the group look right.
477
-				if (empty($curData[$id_group]))
478
-					$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
479
-				elseif ($curData[$id_group] == 1)
480
-					$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
481
-				else
482
-					$curData[$id_group] = 'x';
497
+				if (empty($curData[$id_group])) {
498
+									$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
499
+				} elseif ($curData[$id_group] == 1) {
500
+									$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
501
+				} else {
502
+									$curData[$id_group] = 'x';
503
+				}
483 504
 
484 505
 				// Embolden those permissions different from global (makes it a lot easier!)
485
-				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM])
486
-					$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
506
+				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM]) {
507
+									$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
508
+				}
487 509
 			}
488 510
 
489 511
 			// Now add the data for this permission.
@@ -513,15 +535,17 @@  discard block
 block discarded – undo
513 535
 	);
514 536
 	while ($row = $smcFunc['db_fetch_assoc']($request))
515 537
 	{
516
-		if (trim($row['member_groups']) == '')
517
-			$groups = array(1);
518
-		else
519
-			$groups = array_merge(array(1), explode(',', $row['member_groups']));
538
+		if (trim($row['member_groups']) == '') {
539
+					$groups = array(1);
540
+		} else {
541
+					$groups = array_merge(array(1), explode(',', $row['member_groups']));
542
+		}
520 543
 
521
-		if (trim($row['deny_member_groups']) == '')
522
-			$denyGroups = array();
523
-		else
524
-			$denyGroups = explode(',', $row['deny_member_groups']);
544
+		if (trim($row['deny_member_groups']) == '') {
545
+					$denyGroups = array();
546
+		} else {
547
+					$denyGroups = explode(',', $row['deny_member_groups']);
548
+		}
525 549
 
526 550
 		$boards[$row['id_board']] = array(
527 551
 			'id' => $row['id_board'],
@@ -545,8 +569,9 @@  discard block
 block discarded – undo
545 569
 	);
546 570
 
547 571
 	// Add on the boards!
548
-	foreach ($boards as $board)
549
-		$mgSettings['board_' . $board['id']] = $board['name'];
572
+	foreach ($boards as $board) {
573
+			$mgSettings['board_' . $board['id']] = $board['name'];
574
+	}
550 575
 
551 576
 	// Add all the membergroup settings, plus we'll be adding in columns!
552 577
 	setKeys('cols', $mgSettings);
@@ -591,8 +616,9 @@  discard block
 block discarded – undo
591 616
 			'icons' => ''
592 617
 		),
593 618
 	);
594
-	while ($row = $smcFunc['db_fetch_assoc']($request))
595
-		$rows[] = $row;
619
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
620
+			$rows[] = $row;
621
+	}
596 622
 	$smcFunc['db_free_result']($request);
597 623
 
598 624
 	foreach ($rows as $row)
@@ -608,8 +634,9 @@  discard block
 block discarded – undo
608 634
 		);
609 635
 
610 636
 		// Board permissions.
611
-		foreach ($boards as $board)
612
-			$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
637
+		foreach ($boards as $board) {
638
+					$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
639
+		}
613 640
 
614 641
 		addData($group);
615 642
 	}
@@ -629,16 +656,18 @@  discard block
 block discarded – undo
629 656
 
630 657
 	if (isset($_REQUEST['groups']))
631 658
 	{
632
-		if (!is_array($_REQUEST['groups']))
633
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
634
-		foreach ($_REQUEST['groups'] as $k => $dummy)
635
-			$_REQUEST['groups'][$k] = (int) $dummy;
659
+		if (!is_array($_REQUEST['groups'])) {
660
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
661
+		}
662
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
663
+					$_REQUEST['groups'][$k] = (int) $dummy;
664
+		}
636 665
 		$_REQUEST['groups'] = array_diff($_REQUEST['groups'], array(3));
637 666
 
638 667
 		$clause = 'id_group IN ({array_int:groups})';
668
+	} else {
669
+			$clause = 'id_group != {int:moderator_group}';
639 670
 	}
640
-	else
641
-		$clause = 'id_group != {int:moderator_group}';
642 671
 
643 672
 	// Get all the possible membergroups, except admin!
644 673
 	$request = $smcFunc['db_query']('', '
@@ -656,12 +685,14 @@  discard block
 block discarded – undo
656 685
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
657 686
 		)
658 687
 	);
659
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
660
-		$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
661
-	else
662
-		$groups = array('col' => '');
663
-	while ($row = $smcFunc['db_fetch_assoc']($request))
664
-		$groups[$row['id_group']] = $row['group_name'];
688
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
689
+			$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
690
+	} else {
691
+			$groups = array('col' => '');
692
+	}
693
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
694
+			$groups[$row['id_group']] = $row['group_name'];
695
+	}
665 696
 	$smcFunc['db_free_result']($request);
666 697
 
667 698
 	// Make sure that every group is represented!
@@ -685,8 +716,9 @@  discard block
 block discarded – undo
685 716
 		$disabled_permissions[] = 'calendar_edit_own';
686 717
 		$disabled_permissions[] = 'calendar_edit_any';
687 718
 	}
688
-	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0)
689
-		$disabled_permissions[] = 'issue_warning';
719
+	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0) {
720
+			$disabled_permissions[] = 'issue_warning';
721
+	}
690 722
 
691 723
 	call_integration_hook('integrate_reports_groupperm', array(&$disabled_permissions));
692 724
 
@@ -707,15 +739,17 @@  discard block
 block discarded – undo
707 739
 	$curData = array();
708 740
 	while ($row = $smcFunc['db_fetch_assoc']($request))
709 741
 	{
710
-		if (in_array($row['permission'], $disabled_permissions))
711
-			continue;
742
+		if (in_array($row['permission'], $disabled_permissions)) {
743
+					continue;
744
+		}
712 745
 
713 746
 		// If this is a new permission flush the last row.
714 747
 		if ($row['permission'] != $lastPermission)
715 748
 		{
716 749
 			// Send the data!
717
-			if ($lastPermission !== null)
718
-				addData($curData);
750
+			if ($lastPermission !== null) {
751
+							addData($curData);
752
+			}
719 753
 
720 754
 			// Add the permission name in the left column.
721 755
 			$curData = array('col' => isset($txt['group_perms_name_' . $row['permission']]) ? $txt['group_perms_name_' . $row['permission']] : $row['permission']);
@@ -724,10 +758,11 @@  discard block
 block discarded – undo
724 758
 		}
725 759
 
726 760
 		// Good stuff - add the permission to the list!
727
-		if ($row['add_deny'])
728
-			$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
729
-		else
730
-			$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
761
+		if ($row['add_deny']) {
762
+					$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
763
+		} else {
764
+					$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
765
+		}
731 766
 	}
732 767
 	$smcFunc['db_free_result']($request);
733 768
 
@@ -757,8 +792,9 @@  discard block
 block discarded – undo
757 792
 		)
758 793
 	);
759 794
 	$boards = array();
760
-	while ($row = $smcFunc['db_fetch_assoc']($request))
761
-		$boards[$row['id_board']] = $row['name'];
795
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
796
+			$boards[$row['id_board']] = $row['name'];
797
+	}
762 798
 	$smcFunc['db_free_result']($request);
763 799
 
764 800
 	// Get every moderator.
@@ -790,12 +826,14 @@  discard block
 block discarded – undo
790 826
 	while ($row = $smcFunc['db_fetch_assoc']($request))
791 827
 	{
792 828
 		// Either we don't have them as a moderator at all or at least not as a moderator of this board
793
-		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']]))
794
-			$moderators[$row['id_member']][] = $row['id_board'];
829
+		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']])) {
830
+					$moderators[$row['id_member']][] = $row['id_board'];
831
+		}
795 832
 
796 833
 		// We don't have them listed as a moderator yet
797
-		if (!array_key_exists($row['id_member'], $local_mods))
798
-			$local_mods[$row['id_member']] = $row['id_member'];
834
+		if (!array_key_exists($row['id_member'], $local_mods)) {
835
+					$local_mods[$row['id_member']] = $row['id_member'];
836
+		}
799 837
 	}
800 838
 
801 839
 	// Get a list of global moderators (i.e. members with moderation powers).
@@ -808,8 +846,9 @@  discard block
 block discarded – undo
808 846
 	$allStaff = array_unique($allStaff);
809 847
 
810 848
 	// This is a bit of a cop out - but we're protecting their forum, really!
811
-	if (count($allStaff) > 300)
812
-		fatal_lang_error('report_error_too_many_staff');
849
+	if (count($allStaff) > 300) {
850
+			fatal_lang_error('report_error_too_many_staff');
851
+	}
813 852
 
814 853
 	// Get all the possible membergroups!
815 854
 	$request = $smcFunc['db_query']('', '
@@ -819,8 +858,9 @@  discard block
 block discarded – undo
819 858
 		)
820 859
 	);
821 860
 	$groups = array(0 => $txt['full_member']);
822
-	while ($row = $smcFunc['db_fetch_assoc']($request))
823
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
861
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
862
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
863
+	}
824 864
 	$smcFunc['db_free_result']($request);
825 865
 
826 866
 	// All the fields we'll show.
@@ -861,19 +901,20 @@  discard block
 block discarded – undo
861 901
 		);
862 902
 
863 903
 		// What do they moderate?
864
-		if (in_array($row['id_member'], $global_mods))
865
-			$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
866
-		elseif (isset($moderators[$row['id_member']]))
904
+		if (in_array($row['id_member'], $global_mods)) {
905
+					$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
906
+		} elseif (isset($moderators[$row['id_member']]))
867 907
 		{
868 908
 			// Get the names
869
-			foreach ($moderators[$row['id_member']] as $board)
870
-				if (isset($boards[$board]))
909
+			foreach ($moderators[$row['id_member']] as $board) {
910
+							if (isset($boards[$board]))
871 911
 					$staffData['moderates'][] = $boards[$board];
912
+			}
872 913
 
873 914
 			$staffData['moderates'] = implode(', ', $staffData['moderates']);
915
+		} else {
916
+					$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
874 917
 		}
875
-		else
876
-			$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
877 918
 
878 919
 		// Next add the main data.
879 920
 		addData($staffData);
@@ -901,8 +942,9 @@  discard block
 block discarded – undo
901 942
 	global $context;
902 943
 
903 944
 	// Set the table count if needed.
904
-	if (empty($context['table_count']))
905
-		$context['table_count'] = 0;
945
+	if (empty($context['table_count'])) {
946
+			$context['table_count'] = 0;
947
+	}
906 948
 
907 949
 	// Create the table!
908 950
 	$context['tables'][$context['table_count']] = array(
@@ -952,16 +994,18 @@  discard block
 block discarded – undo
952 994
 	global $context;
953 995
 
954 996
 	// No tables? Create one even though we are probably already in a bad state!
955
-	if (empty($context['table_count']))
956
-		newTable();
997
+	if (empty($context['table_count'])) {
998
+			newTable();
999
+	}
957 1000
 
958 1001
 	// Specific table?
959
-	if ($custom_table !== null && !isset($context['tables'][$custom_table]))
960
-		return false;
961
-	elseif ($custom_table !== null)
962
-		$table = $custom_table;
963
-	else
964
-		$table = $context['current_table'];
1002
+	if ($custom_table !== null && !isset($context['tables'][$custom_table])) {
1003
+			return false;
1004
+	} elseif ($custom_table !== null) {
1005
+			$table = $custom_table;
1006
+	} else {
1007
+			$table = $context['current_table'];
1008
+	}
965 1009
 
966 1010
 	// If we have keys, sanitise the data...
967 1011
 	if (!empty($context['keys']))
@@ -973,11 +1017,11 @@  discard block
 block discarded – undo
973 1017
 				'v' => empty($inc_data[$key]) ? $context['tables'][$table]['default_value'] : $inc_data[$key],
974 1018
 			);
975 1019
 			// Special "hack" the adding separators when doing data by column.
976
-			if (substr($key, 0, 5) == '#sep#')
977
-				$data[$key]['separator'] = true;
1020
+			if (substr($key, 0, 5) == '#sep#') {
1021
+							$data[$key]['separator'] = true;
1022
+			}
978 1023
 		}
979
-	}
980
-	else
1024
+	} else
981 1025
 	{
982 1026
 		$data = $inc_data;
983 1027
 		foreach ($data as $key => $value)
@@ -985,8 +1029,9 @@  discard block
 block discarded – undo
985 1029
 			$data[$key] = array(
986 1030
 				'v' => $value,
987 1031
 			);
988
-			if (substr($key, 0, 5) == '#sep#')
989
-				$data[$key]['separator'] = true;
1032
+			if (substr($key, 0, 5) == '#sep#') {
1033
+							$data[$key]['separator'] = true;
1034
+			}
990 1035
 		}
991 1036
 	}
992 1037
 
@@ -999,8 +1044,9 @@  discard block
 block discarded – undo
999 1044
 	// Otherwise, tricky!
1000 1045
 	else
1001 1046
 	{
1002
-		foreach ($data as $key => $item)
1003
-			$context['tables'][$table]['data'][$key][] = $item;
1047
+		foreach ($data as $key => $item) {
1048
+					$context['tables'][$table]['data'][$key][] = $item;
1049
+		}
1004 1050
 	}
1005 1051
 }
1006 1052
 
@@ -1017,16 +1063,18 @@  discard block
 block discarded – undo
1017 1063
 	global $context;
1018 1064
 
1019 1065
 	// No tables - return?
1020
-	if (empty($context['table_count']))
1021
-		return;
1066
+	if (empty($context['table_count'])) {
1067
+			return;
1068
+	}
1022 1069
 
1023 1070
 	// Specific table?
1024
-	if ($custom_table !== null && !isset($context['tables'][$table]))
1025
-		return false;
1026
-	elseif ($custom_table !== null)
1027
-		$table = $custom_table;
1028
-	else
1029
-		$table = $context['current_table'];
1071
+	if ($custom_table !== null && !isset($context['tables'][$table])) {
1072
+			return false;
1073
+	} elseif ($custom_table !== null) {
1074
+			$table = $custom_table;
1075
+	} else {
1076
+			$table = $context['current_table'];
1077
+	}
1030 1078
 
1031 1079
 	// Plumb in the separator
1032 1080
 	$context['tables'][$table]['data'][] = array(0 => array(
@@ -1047,8 +1095,9 @@  discard block
 block discarded – undo
1047 1095
 {
1048 1096
 	global $context;
1049 1097
 
1050
-	if (empty($context['tables']))
1051
-		return;
1098
+	if (empty($context['tables'])) {
1099
+			return;
1100
+	}
1052 1101
 
1053 1102
 	// Loop through each table counting up some basic values, to help with the templating.
1054 1103
 	foreach ($context['tables'] as $id => $table)
@@ -1059,12 +1108,13 @@  discard block
 block discarded – undo
1059 1108
 		$context['tables'][$id]['column_count'] = count($curElement);
1060 1109
 
1061 1110
 		// Work out the rough width - for templates like the print template. Without this we might get funny tables.
1062
-		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto')
1063
-			$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1064
-		elseif ($table['width']['normal'] != 'auto')
1065
-			$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1066
-		else
1067
-			$context['tables'][$id]['max_width'] = 'auto';
1111
+		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto') {
1112
+					$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1113
+		} elseif ($table['width']['normal'] != 'auto') {
1114
+					$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1115
+		} else {
1116
+					$context['tables'][$id]['max_width'] = 'auto';
1117
+		}
1068 1118
 	}
1069 1119
 }
1070 1120
 
@@ -1089,10 +1139,11 @@  discard block
 block discarded – undo
1089 1139
 	global $context;
1090 1140
 
1091 1141
 	// Do we want to use the keys of the keys as the keys? :P
1092
-	if ($reverse)
1093
-		$context['keys'] = array_flip($keys);
1094
-	else
1095
-		$context['keys'] = $keys;
1142
+	if ($reverse) {
1143
+			$context['keys'] = array_flip($keys);
1144
+	} else {
1145
+			$context['keys'] = $keys;
1146
+	}
1096 1147
 
1097 1148
 	// Rows or columns?
1098 1149
 	$context['key_method'] = $method == 'rows' ? 'rows' : 'cols';
Please login to merge, or discard this patch.
Sources/ScheduledTasks.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -807,7 +807,7 @@
 block discarded – undo
807 807
 /**
808 808
  * Send a group of emails from the mail queue.
809 809
  *
810
- * @param bool|int $number The number to send each loop through or false to use the standard limits
810
+ * @param integer $number The number to send each loop through or false to use the standard limits
811 811
  * @param bool $override_limit Whether to bypass the limit
812 812
  * @param bool $force_send Whether to forcibly send the messages now (useful when using cron jobs)
813 813
  * @return bool Whether things were sent
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -384,7 +384,7 @@
 block discarded – undo
384 384
 	clean_cache();
385 385
 
386 386
 	// If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level.
387
-	list (, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
387
+	list (,, $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
388 388
 	if ($modSettings['warning_decrement'])
389 389
 	{
390 390
 		// Find every member who has a warning level...
Please login to merge, or discard this patch.
Braces   +280 added lines, -203 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
  * This function works out what to do!
@@ -24,9 +25,9 @@  discard block
 block discarded – undo
24 25
 	global $time_start, $smcFunc;
25 26
 
26 27
 	// Special case for doing the mail queue.
27
-	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq')
28
-		ReduceMailQueue();
29
-	else
28
+	if (isset($_GET['scheduled']) && $_GET['scheduled'] == 'mailq') {
29
+			ReduceMailQueue();
30
+	} else
30 31
 	{
31 32
 		$task_string = '';
32 33
 
@@ -53,18 +54,20 @@  discard block
 block discarded – undo
53 54
 
54 55
 			// How long in seconds it the gap?
55 56
 			$duration = $row['time_regularity'];
56
-			if ($row['time_unit'] == 'm')
57
-				$duration *= 60;
58
-			elseif ($row['time_unit'] == 'h')
59
-				$duration *= 3600;
60
-			elseif ($row['time_unit'] == 'd')
61
-				$duration *= 86400;
62
-			elseif ($row['time_unit'] == 'w')
63
-				$duration *= 604800;
57
+			if ($row['time_unit'] == 'm') {
58
+							$duration *= 60;
59
+			} elseif ($row['time_unit'] == 'h') {
60
+							$duration *= 3600;
61
+			} elseif ($row['time_unit'] == 'd') {
62
+							$duration *= 86400;
63
+			} elseif ($row['time_unit'] == 'w') {
64
+							$duration *= 604800;
65
+			}
64 66
 
65 67
 			// If we were really late running this task actually skip the next one.
66
-			if (time() + ($duration / 2) > $next_time)
67
-				$next_time += $duration;
68
+			if (time() + ($duration / 2) > $next_time) {
69
+							$next_time += $duration;
70
+			}
68 71
 
69 72
 			// Update it now, so no others run this!
70 73
 			$smcFunc['db_query']('', '
@@ -81,16 +84,19 @@  discard block
 block discarded – undo
81 84
 			$affected_rows = $smcFunc['db_affected_rows']();
82 85
 
83 86
 			// What kind of task are we handling?
84
-			if (!empty($row['callable']))
85
-				$task_string = $row['callable'];
87
+			if (!empty($row['callable'])) {
88
+							$task_string = $row['callable'];
89
+			}
86 90
 
87 91
 			// Default SMF task or old mods?
88
-			elseif (function_exists('scheduled_' . $row['task']))
89
-				$task_string = 'scheduled_' . $row['task'];
92
+			elseif (function_exists('scheduled_' . $row['task'])) {
93
+							$task_string = 'scheduled_' . $row['task'];
94
+			}
90 95
 
91 96
 			// One last resource, the task name.
92
-			elseif (!empty($row['task']))
93
-				$task_string = $row['task'];
97
+			elseif (!empty($row['task'])) {
98
+							$task_string = $row['task'];
99
+			}
94 100
 
95 101
 			// The function must exist or we are wasting our time, plus do some timestamp checking, and database check!
96 102
 			if (!empty($task_string) && (!isset($_GET['ts']) || $_GET['ts'] == $row['next_time']) && $affected_rows)
@@ -101,11 +107,11 @@  discard block
 block discarded – undo
101 107
 				$callable_task = call_helper($task_string, true);
102 108
 
103 109
 				// Perform the task.
104
-				if (!empty($callable_task))
105
-					$completed = call_user_func($callable_task);
106
-
107
-				else
108
-					$completed = false;
110
+				if (!empty($callable_task)) {
111
+									$completed = call_user_func($callable_task);
112
+				} else {
113
+									$completed = false;
114
+				}
109 115
 
110 116
 				// Log that we did it ;)
111 117
 				if ($completed)
@@ -138,18 +144,20 @@  discard block
 block discarded – undo
138 144
 			)
139 145
 		);
140 146
 		// No new task scheduled yet?
141
-		if ($smcFunc['db_num_rows']($request) === 0)
142
-			$nextEvent = time() + 86400;
143
-		else
144
-			list ($nextEvent) = $smcFunc['db_fetch_row']($request);
147
+		if ($smcFunc['db_num_rows']($request) === 0) {
148
+					$nextEvent = time() + 86400;
149
+		} else {
150
+					list ($nextEvent) = $smcFunc['db_fetch_row']($request);
151
+		}
145 152
 		$smcFunc['db_free_result']($request);
146 153
 
147 154
 		updateSettings(array('next_task_time' => $nextEvent));
148 155
 	}
149 156
 
150 157
 	// Shall we return?
151
-	if (!isset($_GET['scheduled']))
152
-		return true;
158
+	if (!isset($_GET['scheduled'])) {
159
+			return true;
160
+	}
153 161
 
154 162
 	// Finally, send some stuff...
155 163
 	header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -181,16 +189,18 @@  discard block
 block discarded – undo
181 189
 	while ($row = $smcFunc['db_fetch_assoc']($request))
182 190
 	{
183 191
 		// If this is no longer around we'll ignore it.
184
-		if (empty($row['id_topic']))
185
-			continue;
192
+		if (empty($row['id_topic'])) {
193
+					continue;
194
+		}
186 195
 
187 196
 		// What type is it?
188
-		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg'])
189
-			$type = 'topic';
190
-		elseif ($row['id_attach'])
191
-			$type = 'attach';
192
-		else
193
-			$type = 'msg';
197
+		if ($row['id_first_msg'] && $row['id_first_msg'] == $row['id_msg']) {
198
+					$type = 'topic';
199
+		} elseif ($row['id_attach']) {
200
+					$type = 'attach';
201
+		} else {
202
+					$type = 'msg';
203
+		}
194 204
 
195 205
 		// Add it to the array otherwise.
196 206
 		$notices[$row['id_board']][$type][] = array(
@@ -211,8 +221,9 @@  discard block
 block discarded – undo
211 221
 	);
212 222
 
213 223
 	// If nothing quit now.
214
-	if (empty($notices))
215
-		return true;
224
+	if (empty($notices)) {
225
+			return true;
226
+	}
216 227
 
217 228
 	// Now we need to think about finding out *who* can approve - this is hard!
218 229
 
@@ -231,14 +242,16 @@  discard block
 block discarded – undo
231 242
 	while ($row = $smcFunc['db_fetch_assoc']($request))
232 243
 	{
233 244
 		// Sorry guys, but we have to ignore guests AND members - it would be too many otherwise.
234
-		if ($row['id_group'] < 2)
235
-			continue;
245
+		if ($row['id_group'] < 2) {
246
+					continue;
247
+		}
236 248
 
237 249
 		$perms[$row['id_profile']][$row['add_deny'] ? 'add' : 'deny'][] = $row['id_group'];
238 250
 
239 251
 		// Anyone who can access has to be considered.
240
-		if ($row['add_deny'])
241
-			$addGroups[] = $row['id_group'];
252
+		if ($row['add_deny']) {
253
+					$addGroups[] = $row['id_group'];
254
+		}
242 255
 	}
243 256
 	$smcFunc['db_free_result']($request);
244 257
 
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 		if (!empty($row['mod_prefs']))
284 297
 		{
285 298
 			list(,, $pref_binary) = explode('|', $row['mod_prefs']);
286
-			if (!($pref_binary & 4))
287
-				continue;
299
+			if (!($pref_binary & 4)) {
300
+							continue;
301
+			}
288 302
 		}
289 303
 
290 304
 		$members[$row['id_member']] = array(
@@ -309,8 +323,9 @@  discard block
 block discarded – undo
309 323
 		$emailbody = '';
310 324
 
311 325
 		// Load the language file as required.
312
-		if (empty($current_language) || $current_language != $member['language'])
313
-			$current_language = loadLanguage('EmailTemplates', $member['language'], false);
326
+		if (empty($current_language) || $current_language != $member['language']) {
327
+					$current_language = loadLanguage('EmailTemplates', $member['language'], false);
328
+		}
314 329
 
315 330
 		// Loop through each notice...
316 331
 		foreach ($notices as $board => $notice)
@@ -318,29 +333,34 @@  discard block
 block discarded – undo
318 333
 			$access = false;
319 334
 
320 335
 			// Can they mod in this board?
321
-			if (isset($mods[$id][$board]))
322
-				$access = true;
336
+			if (isset($mods[$id][$board])) {
337
+							$access = true;
338
+			}
323 339
 
324 340
 			// Do the group check...
325 341
 			if (!$access && isset($perms[$profiles[$board]]['add']))
326 342
 			{
327 343
 				// They can access?!
328
-				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups']))
329
-					$access = true;
344
+				if (array_intersect($perms[$profiles[$board]]['add'], $member['groups'])) {
345
+									$access = true;
346
+				}
330 347
 
331 348
 				// If they have deny rights don't consider them!
332
-				if (isset($perms[$profiles[$board]]['deny']))
333
-					if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
349
+				if (isset($perms[$profiles[$board]]['deny'])) {
350
+									if (array_intersect($perms[$profiles[$board]]['deny'], $member['groups']))
334 351
 						$access = false;
352
+				}
335 353
 			}
336 354
 
337 355
 			// Finally, fix it for admins!
338
-			if (in_array(1, $member['groups']))
339
-				$access = true;
356
+			if (in_array(1, $member['groups'])) {
357
+							$access = true;
358
+			}
340 359
 
341 360
 			// If they can't access it then give it a break!
342
-			if (!$access)
343
-				continue;
361
+			if (!$access) {
362
+							continue;
363
+			}
344 364
 
345 365
 			foreach ($notice as $type => $items)
346 366
 			{
@@ -348,15 +368,17 @@  discard block
 block discarded – undo
348 368
 				$emailbody .= $txt['scheduled_approval_email_' . $type] . "\n" .
349 369
 					'------------------------------------------------------' . "\n";
350 370
 
351
-				foreach ($items as $item)
352
-					$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
371
+				foreach ($items as $item) {
372
+									$emailbody .= $item['subject'] . ' - ' . $item['href'] . "\n";
373
+				}
353 374
 
354 375
 				$emailbody .= "\n";
355 376
 			}
356 377
 		}
357 378
 
358
-		if ($emailbody == '')
359
-			continue;
379
+		if ($emailbody == '') {
380
+					continue;
381
+		}
360 382
 
361 383
 		$replacements = array(
362 384
 			'REALNAME' => $member['name'],
@@ -397,8 +419,9 @@  discard block
 block discarded – undo
397 419
 			)
398 420
 		);
399 421
 		$members = array();
400
-		while ($row = $smcFunc['db_fetch_assoc']($request))
401
-			$members[$row['id_member']] = $row['warning'];
422
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
423
+					$members[$row['id_member']] = $row['warning'];
424
+		}
402 425
 		$smcFunc['db_free_result']($request);
403 426
 
404 427
 		// Have some members to check?
@@ -420,17 +443,18 @@  discard block
 block discarded – undo
420 443
 			while ($row = $smcFunc['db_fetch_assoc']($request))
421 444
 			{
422 445
 				// More than 24 hours ago?
423
-				if ($row['last_warning'] <= time() - 86400)
424
-					$member_changes[] = array(
446
+				if ($row['last_warning'] <= time() - 86400) {
447
+									$member_changes[] = array(
425 448
 						'id' => $row['id_recipient'],
426 449
 						'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0,
427 450
 					);
451
+				}
428 452
 			}
429 453
 			$smcFunc['db_free_result']($request);
430 454
 
431 455
 			// Have some members to change?
432
-			if (!empty($member_changes))
433
-				foreach ($member_changes as $change)
456
+			if (!empty($member_changes)) {
457
+							foreach ($member_changes as $change)
434 458
 					$smcFunc['db_query']('', '
435 459
 						UPDATE {db_prefix}members
436 460
 						SET warning = {int:warning}
@@ -440,6 +464,7 @@  discard block
 block discarded – undo
440 464
 							'id_member' => $change['id'],
441 465
 						)
442 466
 					);
467
+			}
443 468
 		}
444 469
 	}
445 470
 
@@ -519,15 +544,17 @@  discard block
 block discarded – undo
519 544
 
520 545
 		// Store this useful data!
521 546
 		$boards[$row['id_board']] = $row['id_board'];
522
-		if ($row['id_topic'])
523
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
524
-		else
525
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
547
+		if ($row['id_topic']) {
548
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
549
+		} else {
550
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
551
+		}
526 552
 	}
527 553
 	$smcFunc['db_free_result']($request);
528 554
 
529
-	if (empty($boards))
530
-		return true;
555
+	if (empty($boards)) {
556
+			return true;
557
+	}
531 558
 
532 559
 	// Just get the board names.
533 560
 	$request = $smcFunc['db_query']('', '
@@ -539,12 +566,14 @@  discard block
 block discarded – undo
539 566
 		)
540 567
 	);
541 568
 	$boards = array();
542
-	while ($row = $smcFunc['db_fetch_assoc']($request))
543
-		$boards[$row['id_board']] = $row['name'];
569
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
570
+			$boards[$row['id_board']] = $row['name'];
571
+	}
544 572
 	$smcFunc['db_free_result']($request);
545 573
 
546
-	if (empty($boards))
547
-		return true;
574
+	if (empty($boards)) {
575
+			return true;
576
+	}
548 577
 
549 578
 	// Get the actual topics...
550 579
 	$request = $smcFunc['db_query']('', '
@@ -564,52 +593,57 @@  discard block
 block discarded – undo
564 593
 	$types = array();
565 594
 	while ($row = $smcFunc['db_fetch_assoc']($request))
566 595
 	{
567
-		if (!isset($types[$row['note_type']][$row['id_board']]))
568
-			$types[$row['note_type']][$row['id_board']] = array(
596
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
597
+					$types[$row['note_type']][$row['id_board']] = array(
569 598
 				'lines' => array(),
570 599
 				'name' => $row['board_name'],
571 600
 				'id' => $row['id_board'],
572 601
 			);
602
+		}
573 603
 
574 604
 		if ($row['note_type'] == 'reply')
575 605
 		{
576
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
577
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
578
-			else
579
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
606
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
607
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
608
+			} else {
609
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
580 610
 					'id' => $row['id_topic'],
581 611
 					'subject' => un_htmlspecialchars($row['subject']),
582 612
 					'count' => 1,
583 613
 				);
584
-		}
585
-		elseif ($row['note_type'] == 'topic')
614
+			}
615
+		} elseif ($row['note_type'] == 'topic')
586 616
 		{
587
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
588
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
617
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
618
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
589 619
 					'id' => $row['id_topic'],
590 620
 					'subject' => un_htmlspecialchars($row['subject']),
591 621
 				);
592
-		}
593
-		else
622
+			}
623
+		} else
594 624
 		{
595
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
596
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
625
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
626
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
597 627
 					'id' => $row['id_topic'],
598 628
 					'subject' => un_htmlspecialchars($row['subject']),
599 629
 					'starter' => $row['id_member_started'],
600 630
 				);
631
+			}
601 632
 		}
602 633
 
603 634
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
604
-		if (!empty($notify['topics'][$row['id_topic']]))
605
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
606
-		if (!empty($notify['boards'][$row['id_board']]))
607
-			$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
635
+		if (!empty($notify['topics'][$row['id_topic']])) {
636
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['topics'][$row['id_topic']]);
637
+		}
638
+		if (!empty($notify['boards'][$row['id_board']])) {
639
+					$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array_merge($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'], $notify['boards'][$row['id_board']]);
640
+		}
608 641
 	}
609 642
 	$smcFunc['db_free_result']($request);
610 643
 
611
-	if (empty($types))
612
-		return true;
644
+	if (empty($types)) {
645
+			return true;
646
+	}
613 647
 
614 648
 	// Let's load all the languages into a cache thingy.
615 649
 	$langtxt = array();
@@ -651,8 +685,9 @@  discard block
 block discarded – undo
651 685
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
652 686
 
653 687
 		// Did they not elect to choose this?
654
-		if ($frequency < 3 || $frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
655
-			continue;
688
+		if ($frequency < 3 || $frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
689
+					continue;
690
+		}
656 691
 
657 692
 		// Right character set!
658 693
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -668,39 +703,43 @@  discard block
 block discarded – undo
668 703
 		if (isset($types['topic']))
669 704
 		{
670 705
 			$titled = false;
671
-			foreach ($types['topic'] as $id => $board)
672
-				foreach ($board['lines'] as $topic)
706
+			foreach ($types['topic'] as $id => $board) {
707
+							foreach ($board['lines'] as $topic)
673 708
 					if (in_array($mid, $topic['members']))
674 709
 					{
675 710
 						if (!$titled)
676 711
 						{
677 712
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
713
+			}
678 714
 							$titled = true;
679 715
 						}
680 716
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
681 717
 					}
682
-			if ($titled)
683
-				$email['body'] .= "\n";
718
+			if ($titled) {
719
+							$email['body'] .= "\n";
720
+			}
684 721
 		}
685 722
 
686 723
 		// What about replies?
687 724
 		if (isset($types['reply']))
688 725
 		{
689 726
 			$titled = false;
690
-			foreach ($types['reply'] as $id => $board)
691
-				foreach ($board['lines'] as $topic)
727
+			foreach ($types['reply'] as $id => $board) {
728
+							foreach ($board['lines'] as $topic)
692 729
 					if (in_array($mid, $topic['members']))
693 730
 					{
694 731
 						if (!$titled)
695 732
 						{
696 733
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
734
+			}
697 735
 							$titled = true;
698 736
 						}
699 737
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
700 738
 					}
701 739
 
702
-			if ($titled)
703
-				$email['body'] .= "\n";
740
+			if ($titled) {
741
+							$email['body'] .= "\n";
742
+			}
704 743
 		}
705 744
 
706 745
 		// Finally, moderation actions!
@@ -709,24 +748,27 @@  discard block
 block discarded – undo
709 748
 			$titled = false;
710 749
 			foreach ($types as $note_type => $type)
711 750
 			{
712
-				if ($note_type == 'topic' || $note_type == 'reply')
713
-					continue;
751
+				if ($note_type == 'topic' || $note_type == 'reply') {
752
+									continue;
753
+				}
714 754
 
715
-				foreach ($type as $id => $board)
716
-					foreach ($board['lines'] as $topic)
755
+				foreach ($type as $id => $board) {
756
+									foreach ($board['lines'] as $topic)
717 757
 						if (in_array($mid, $topic['members']))
718 758
 						{
719 759
 							if (!$titled)
720 760
 							{
721 761
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
762
+				}
722 763
 								$titled = true;
723 764
 							}
724 765
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
725 766
 						}
726 767
 			}
727 768
 		}
728
-		if ($titled)
729
-			$email['body'] .= "\n";
769
+		if ($titled) {
770
+					$email['body'] .= "\n";
771
+		}
730 772
 
731 773
 		// Then just say our goodbyes!
732 774
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -756,8 +798,7 @@  discard block
 block discarded – undo
756 798
 				'not_daily' => 0,
757 799
 			)
758 800
 		);
759
-	}
760
-	else
801
+	} else
761 802
 	{
762 803
 		// Clear any only weekly ones, and stop us from sending daily again.
763 804
 		$smcFunc['db_query']('', '
@@ -821,16 +862,19 @@  discard block
 block discarded – undo
821 862
 	global $modSettings, $smcFunc, $sourcedir;
822 863
 
823 864
 	// Are we intending another script to be sending out the queue?
824
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
825
-		return false;
865
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
866
+			return false;
867
+	}
826 868
 
827 869
 	// By default send 5 at once.
828
-	if (!$number)
829
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
870
+	if (!$number) {
871
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
872
+	}
830 873
 
831 874
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
832
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
833
-		return false;
875
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
876
+			return false;
877
+	}
834 878
 
835 879
 	// By default move the next sending on by 10 seconds, and require an affected row.
836 880
 	if (!$override_limit)
@@ -847,8 +891,9 @@  discard block
 block discarded – undo
847 891
 				'last_send' => $modSettings['mail_next_send'],
848 892
 			)
849 893
 		);
850
-		if ($smcFunc['db_affected_rows']() == 0)
851
-			return false;
894
+		if ($smcFunc['db_affected_rows']() == 0) {
895
+					return false;
896
+		}
852 897
 		$modSettings['mail_next_send'] = time() + $delay;
853 898
 	}
854 899
 
@@ -869,8 +914,9 @@  discard block
 block discarded – undo
869 914
 			$mn += $number;
870 915
 		}
871 916
 		// No more I'm afraid, return!
872
-		else
873
-			return false;
917
+		else {
918
+					return false;
919
+		}
874 920
 
875 921
 		// Reflect that we're about to send some, do it now to be safe.
876 922
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -905,14 +951,15 @@  discard block
 block discarded – undo
905 951
 	$smcFunc['db_free_result']($request);
906 952
 
907 953
 	// Delete, delete, delete!!!
908
-	if (!empty($ids))
909
-		$smcFunc['db_query']('', '
954
+	if (!empty($ids)) {
955
+			$smcFunc['db_query']('', '
910 956
 			DELETE FROM {db_prefix}mail_queue
911 957
 			WHERE id_mail IN ({array_int:mail_list})',
912 958
 			array(
913 959
 				'mail_list' => $ids,
914 960
 			)
915 961
 		);
962
+	}
916 963
 
917 964
 	// Don't believe we have any left?
918 965
 	if (count($ids) < $number)
@@ -930,11 +977,13 @@  discard block
 block discarded – undo
930 977
 		);
931 978
 	}
932 979
 
933
-	if (empty($ids))
934
-		return false;
980
+	if (empty($ids)) {
981
+			return false;
982
+	}
935 983
 
936
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
937
-		require_once($sourcedir . '/Subs-Post.php');
984
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
985
+			require_once($sourcedir . '/Subs-Post.php');
986
+	}
938 987
 
939 988
 	// Send each email, yea!
940 989
 	$failed_emails = array();
@@ -954,15 +1003,17 @@  discard block
 block discarded – undo
954 1003
 
955 1004
 			// Try to stop a timeout, this would be bad...
956 1005
 			@set_time_limit(300);
957
-			if (function_exists('apache_reset_timeout'))
958
-				@apache_reset_timeout();
1006
+			if (function_exists('apache_reset_timeout')) {
1007
+							@apache_reset_timeout();
1008
+			}
1009
+		} else {
1010
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
959 1011
 		}
960
-		else
961
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
962 1012
 
963 1013
 		// Hopefully it sent?
964
-		if (!$result)
965
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1014
+		if (!$result) {
1015
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1016
+		}
966 1017
 	}
967 1018
 
968 1019
 	// Any emails that didn't send?
@@ -977,8 +1028,8 @@  discard block
 block discarded – undo
977 1028
 		);
978 1029
 
979 1030
 		// If we have failed to many times, tell mail to wait a bit and try again.
980
-		if ($modSettings['mail_failed_attempts'] > 5)
981
-			$smcFunc['db_query']('', '
1031
+		if ($modSettings['mail_failed_attempts'] > 5) {
1032
+					$smcFunc['db_query']('', '
982 1033
 				UPDATE {db_prefix}settings
983 1034
 				SET value = {string:next_mail_send}
984 1035
 				WHERE variable = {literal:mail_next_send}
@@ -987,6 +1038,7 @@  discard block
 block discarded – undo
987 1038
 					'next_mail_send' => time() + 60,
988 1039
 					'last_send' => $modSettings['mail_next_send'],
989 1040
 			));
1041
+		}
990 1042
 
991 1043
 		// Add our email back to the queue, manually.
992 1044
 		$smcFunc['db_insert']('insert',
@@ -999,8 +1051,8 @@  discard block
 block discarded – undo
999 1051
 		return false;
1000 1052
 	}
1001 1053
 	// We where unable to send the email, clear our failed attempts.
1002
-	elseif (!empty($modSettings['mail_failed_attempts']))
1003
-		$smcFunc['db_query']('', '
1054
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1055
+			$smcFunc['db_query']('', '
1004 1056
 			UPDATE {db_prefix}settings
1005 1057
 			SET value = {string:zero}
1006 1058
 			WHERE variable = {string:mail_failed_attempts}',
@@ -1008,6 +1060,7 @@  discard block
 block discarded – undo
1008 1060
 				'zero' => '0',
1009 1061
 				'mail_failed_attempts' => 'mail_failed_attempts',
1010 1062
 		));
1063
+	}
1011 1064
 
1012 1065
 	// Had something to send...
1013 1066
 	return true;
@@ -1024,16 +1077,18 @@  discard block
 block discarded – undo
1024 1077
 	global $modSettings, $smcFunc;
1025 1078
 
1026 1079
 	$task_query = '';
1027
-	if (!is_array($tasks))
1028
-		$tasks = array($tasks);
1080
+	if (!is_array($tasks)) {
1081
+			$tasks = array($tasks);
1082
+	}
1029 1083
 
1030 1084
 	// Actually have something passed?
1031 1085
 	if (!empty($tasks))
1032 1086
 	{
1033
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1034
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1035
-		else
1036
-			$task_query = ' AND task IN ({array_string:tasks})';
1087
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1088
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1089
+		} else {
1090
+					$task_query = ' AND task IN ({array_string:tasks})';
1091
+		}
1037 1092
 	}
1038 1093
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1039 1094
 
@@ -1054,20 +1109,22 @@  discard block
 block discarded – undo
1054 1109
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1055 1110
 
1056 1111
 		// Only bother moving the task if it's out of place or we're forcing it!
1057
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1058
-			$tasks[$row['id_task']] = $next_time;
1059
-		else
1060
-			$next_time = $row['next_time'];
1112
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1113
+					$tasks[$row['id_task']] = $next_time;
1114
+		} else {
1115
+					$next_time = $row['next_time'];
1116
+		}
1061 1117
 
1062 1118
 		// If this is sooner than the current next task, make this the next task.
1063
-		if ($next_time < $nextTaskTime)
1064
-			$nextTaskTime = $next_time;
1119
+		if ($next_time < $nextTaskTime) {
1120
+					$nextTaskTime = $next_time;
1121
+		}
1065 1122
 	}
1066 1123
 	$smcFunc['db_free_result']($request);
1067 1124
 
1068 1125
 	// Now make the changes!
1069
-	foreach ($tasks as $id => $time)
1070
-		$smcFunc['db_query']('', '
1126
+	foreach ($tasks as $id => $time) {
1127
+			$smcFunc['db_query']('', '
1071 1128
 			UPDATE {db_prefix}scheduled_tasks
1072 1129
 			SET next_time = {int:next_time}
1073 1130
 			WHERE id_task = {int:id_task}',
@@ -1076,11 +1133,13 @@  discard block
 block discarded – undo
1076 1133
 				'id_task' => $id,
1077 1134
 			)
1078 1135
 		);
1136
+	}
1079 1137
 
1080 1138
 	// If the next task is now different update.
1081
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1082
-		updateSettings(array('next_task_time' => $nextTaskTime));
1083
-}
1139
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1140
+			updateSettings(array('next_task_time' => $nextTaskTime));
1141
+	}
1142
+	}
1084 1143
 
1085 1144
 /**
1086 1145
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1093,8 +1152,9 @@  discard block
 block discarded – undo
1093 1152
 function next_time($regularity, $unit, $offset)
1094 1153
 {
1095 1154
 	// Just in case!
1096
-	if ($regularity == 0)
1097
-		$regularity = 2;
1155
+	if ($regularity == 0) {
1156
+			$regularity = 2;
1157
+	}
1098 1158
 
1099 1159
 	$curMin = date('i', time());
1100 1160
 
@@ -1104,15 +1164,16 @@  discard block
 block discarded – undo
1104 1164
 		$off = date('i', $offset);
1105 1165
 
1106 1166
 		// If it's now just pretend it ain't,
1107
-		if ($off == $curMin)
1108
-			$next_time = time() + $regularity;
1109
-		else
1167
+		if ($off == $curMin) {
1168
+					$next_time = time() + $regularity;
1169
+		} else
1110 1170
 		{
1111 1171
 			// Make sure that the offset is always in the past.
1112 1172
 			$off = $off > $curMin ? $off - 60 : $off;
1113 1173
 
1114
-			while ($off <= $curMin)
1115
-				$off += $regularity;
1174
+			while ($off <= $curMin) {
1175
+							$off += $regularity;
1176
+			}
1116 1177
 
1117 1178
 			// Now we know when the time should be!
1118 1179
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1132,11 +1193,13 @@  discard block
 block discarded – undo
1132 1193
 		// Default we'll jump in hours.
1133 1194
 		$applyOffset = 3600;
1134 1195
 		// 24 hours = 1 day.
1135
-		if ($unit == 'd')
1136
-			$applyOffset = 86400;
1196
+		if ($unit == 'd') {
1197
+					$applyOffset = 86400;
1198
+		}
1137 1199
 		// Otherwise a week.
1138
-		if ($unit == 'w')
1139
-			$applyOffset = 604800;
1200
+		if ($unit == 'w') {
1201
+					$applyOffset = 604800;
1202
+		}
1140 1203
 
1141 1204
 		$applyOffset *= $regularity;
1142 1205
 
@@ -1173,8 +1236,9 @@  discard block
 block discarded – undo
1173 1236
 		$settings[$row['variable']] = $row['value'];
1174 1237
 
1175 1238
 		// Is this the default theme?
1176
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1177
-			$settings['default_' . $row['variable']] = $row['value'];
1239
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1240
+					$settings['default_' . $row['variable']] = $row['value'];
1241
+		}
1178 1242
 	}
1179 1243
 	$smcFunc['db_free_result']($result);
1180 1244
 
@@ -1184,12 +1248,14 @@  discard block
 block discarded – undo
1184 1248
 		$settings['template_dirs'] = array($settings['theme_dir']);
1185 1249
 
1186 1250
 		// Based on theme (if there is one).
1187
-		if (!empty($settings['base_theme_dir']))
1188
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1251
+		if (!empty($settings['base_theme_dir'])) {
1252
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1253
+		}
1189 1254
 
1190 1255
 		// Lastly the default theme.
1191
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1192
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1256
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1257
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1258
+		}
1193 1259
 	}
1194 1260
 
1195 1261
 	// Assume we want this.
@@ -1333,8 +1399,9 @@  discard block
 block discarded – undo
1333 1399
 	// Ok should we prune the logs?
1334 1400
 	if (!empty($modSettings['pruningOptions']))
1335 1401
 	{
1336
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1337
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1402
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1403
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1404
+		}
1338 1405
 
1339 1406
 		if (!empty($modSettings['pruneErrorLog']))
1340 1407
 		{
@@ -1400,8 +1467,9 @@  discard block
 block discarded – undo
1400 1467
 				)
1401 1468
 			);
1402 1469
 
1403
-			while ($row = $smcFunc['db_fetch_row']($result))
1404
-				$reports[] = $row[0];
1470
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1471
+							$reports[] = $row[0];
1472
+			}
1405 1473
 
1406 1474
 			$smcFunc['db_free_result']($result);
1407 1475
 
@@ -1486,8 +1554,9 @@  discard block
 block discarded – undo
1486 1554
 	);
1487 1555
 
1488 1556
 	// Run Cache housekeeping
1489
-	if (!empty($cache_enable) && !empty($cacheAPI))
1490
-		$cacheAPI->housekeeping();
1557
+	if (!empty($cache_enable) && !empty($cacheAPI)) {
1558
+			$cacheAPI->housekeeping();
1559
+	}
1491 1560
 
1492 1561
 	// Prevent stale minimized CSS and JavaScript from cluttering up the theme directories
1493 1562
 	deleteAllMinified();
@@ -1570,8 +1639,9 @@  discard block
 block discarded – undo
1570 1639
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1571 1640
 
1572 1641
 		// Send the actual email.
1573
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1574
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1642
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1643
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1644
+		}
1575 1645
 
1576 1646
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1577 1647
 		{
@@ -1594,18 +1664,19 @@  discard block
 block discarded – undo
1594 1664
 	}
1595 1665
 
1596 1666
 	// Insert the alerts if any
1597
-	if (!empty($alert_rows))
1598
-		$smcFunc['db_insert']('',
1667
+	if (!empty($alert_rows)) {
1668
+			$smcFunc['db_insert']('',
1599 1669
 			'{db_prefix}user_alerts',
1600 1670
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1601 1671
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1602 1672
 			$alert_rows,
1603 1673
 			array()
1604 1674
 		);
1675
+	}
1605 1676
 
1606 1677
 	// Mark the reminder as sent.
1607
-	if (!empty($subs_reminded))
1608
-		$smcFunc['db_query']('', '
1678
+	if (!empty($subs_reminded)) {
1679
+			$smcFunc['db_query']('', '
1609 1680
 			UPDATE {db_prefix}log_subscribed
1610 1681
 			SET reminder_sent = {int:reminder_sent}
1611 1682
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1614,6 +1685,7 @@  discard block
 block discarded – undo
1614 1685
 				'reminder_sent' => 1,
1615 1686
 			)
1616 1687
 		);
1688
+	}
1617 1689
 
1618 1690
 	return true;
1619 1691
 }
@@ -1629,13 +1701,13 @@  discard block
 block discarded – undo
1629 1701
 	// We need to know where this thing is going.
1630 1702
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1631 1703
 	{
1632
-		if (!is_array($modSettings['attachmentUploadDir']))
1633
-			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1704
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1705
+					$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1706
+		}
1634 1707
 
1635 1708
 		// Just use the current path for temp files.
1636 1709
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1637
-	}
1638
-	else
1710
+	} else
1639 1711
 	{
1640 1712
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1641 1713
 	}
@@ -1654,14 +1726,16 @@  discard block
 block discarded – undo
1654 1726
 
1655 1727
 		while ($file = readdir($dir))
1656 1728
 		{
1657
-			if ($file == '.' || $file == '..')
1658
-				continue;
1729
+			if ($file == '.' || $file == '..') {
1730
+							continue;
1731
+			}
1659 1732
 
1660 1733
 			if (strpos($file, 'post_tmp_') !== false)
1661 1734
 			{
1662 1735
 				// Temp file is more than 5 hours old!
1663
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1664
-					@unlink($attach_dir . '/' . $file);
1736
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1737
+									@unlink($attach_dir . '/' . $file);
1738
+				}
1665 1739
 			}
1666 1740
 		}
1667 1741
 		closedir($dir);
@@ -1694,8 +1768,9 @@  discard block
 block discarded – undo
1694 1768
 		)
1695 1769
 	);
1696 1770
 
1697
-	while ($row = $smcFunc['db_fetch_row']($request))
1698
-		$topics[] = $row[0];
1771
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1772
+			$topics[] = $row[0];
1773
+	}
1699 1774
 	$smcFunc['db_free_result']($request);
1700 1775
 
1701 1776
 	// Zap, your gone
@@ -1715,8 +1790,9 @@  discard block
 block discarded – undo
1715 1790
 {
1716 1791
 	global $smcFunc, $sourcedir, $modSettings;
1717 1792
 
1718
-	if (empty($modSettings['drafts_keep_days']))
1719
-		return true;
1793
+	if (empty($modSettings['drafts_keep_days'])) {
1794
+			return true;
1795
+	}
1720 1796
 
1721 1797
 	// init
1722 1798
 	$drafts = array();
@@ -1734,8 +1810,9 @@  discard block
 block discarded – undo
1734 1810
 		)
1735 1811
 	);
1736 1812
 
1737
-	while ($row = $smcFunc['db_fetch_row']($request))
1738
-		$drafts[] = (int) $row[0];
1813
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1814
+			$drafts[] = (int) $row[0];
1815
+	}
1739 1816
 	$smcFunc['db_free_result']($request);
1740 1817
 
1741 1818
 	// If we have old one, remove them
Please login to merge, or discard this patch.
Sources/Subs-Admin.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
 
19 19
 /**
20 20
  * Get a list of versions that are currently installed on the server.
21
- * @param array $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server'
21
+ * @param string[] $checkFor An array of what to check versions for - can contain one or more of 'gd', 'imagemagick', 'db_server', 'phpa', 'memcache', 'xcache', 'apc', 'php' or 'server'
22 22
  * @return array An array of versions (keys are same as what was in $checkFor, values are the versions)
23 23
  */
24 24
 function getServerVersions($checkFor)
Please login to merge, or discard this patch.
Braces   +124 added lines, -89 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 a list of versions that are currently installed on the server.
@@ -45,8 +46,7 @@  discard block
 block discarded – undo
45 46
 			$temp2 = $temp->getVersion();
46 47
 			$im_version = $temp2['versionString'];
47 48
 			$extension_version = 'Imagick ' . phpversion('Imagick');
48
-		}
49
-		else
49
+		} else
50 50
 		{
51 51
 			$im_version = MagickGetVersionString();
52 52
 			$extension_version = 'MagickWand ' . phpversion('MagickWand');
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	if (in_array('db_server', $checkFor))
62 62
 	{
63 63
 		db_extend();
64
-		if (!isset($db_connection) || $db_connection === false)
65
-			trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
-		else
64
+		if (!isset($db_connection) || $db_connection === false) {
65
+					trigger_error('getServerVersions(): you need to be connected to the database in order to get its server version', E_USER_NOTICE);
66
+		} else
67 67
 		{
68 68
 			$versions['db_engine'] = array('title' => sprintf($txt['support_versions_db_engine'], $smcFunc['db_title']), 'version' => '');
69 69
 			$versions['db_engine']['version'] = $smcFunc['db_get_vendor']();
@@ -75,24 +75,31 @@  discard block
 block discarded – undo
75 75
 
76 76
 	// If we're using memcache we need the server info.
77 77
 	$memcache_version = '???';
78
-	if (!empty($cache_accelerator) && ($cache_accelerator == 'memcached' || $cache_accelerator == 'memcache') && !empty($cache_memcached) && !empty($cacheAPI))
79
-		$memcache_version = $cacheAPI->getVersion();
78
+	if (!empty($cache_accelerator) && ($cache_accelerator == 'memcached' || $cache_accelerator == 'memcache') && !empty($cache_memcached) && !empty($cacheAPI)) {
79
+			$memcache_version = $cacheAPI->getVersion();
80
+	}
80 81
 
81 82
 	// Check to see if we have any accelerators installed...
82
-	if (in_array('phpa', $checkFor) && isset($_PHPA))
83
-		$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
84
-	if (in_array('apc', $checkFor) && extension_loaded('apc'))
85
-		$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
86
-	if (in_array('memcache', $checkFor) && function_exists('memcache_set'))
87
-		$versions['memcache'] = array('title' => 'Memcached', 'version' => $memcache_version);
88
-	if (in_array('xcache', $checkFor) && function_exists('xcache_set'))
89
-		$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
83
+	if (in_array('phpa', $checkFor) && isset($_PHPA)) {
84
+			$versions['phpa'] = array('title' => 'ionCube PHP-Accelerator', 'version' => $_PHPA['VERSION']);
85
+	}
86
+	if (in_array('apc', $checkFor) && extension_loaded('apc')) {
87
+			$versions['apc'] = array('title' => 'Alternative PHP Cache', 'version' => phpversion('apc'));
88
+	}
89
+	if (in_array('memcache', $checkFor) && function_exists('memcache_set')) {
90
+			$versions['memcache'] = array('title' => 'Memcached', 'version' => $memcache_version);
91
+	}
92
+	if (in_array('xcache', $checkFor) && function_exists('xcache_set')) {
93
+			$versions['xcache'] = array('title' => 'XCache', 'version' => XCACHE_VERSION);
94
+	}
90 95
 
91
-	if (in_array('php', $checkFor))
92
-		$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
96
+	if (in_array('php', $checkFor)) {
97
+			$versions['php'] = array('title' => 'PHP', 'version' => PHP_VERSION, 'more' => '?action=admin;area=serversettings;sa=phpinfo');
98
+	}
93 99
 
94
-	if (in_array('server', $checkFor))
95
-		$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
100
+	if (in_array('server', $checkFor)) {
101
+			$versions['server'] = array('title' => $txt['support_versions_server'], 'version' => $_SERVER['SERVER_SOFTWARE']);
102
+	}
96 103
 
97 104
 	return $versions;
98 105
 }
@@ -132,11 +139,13 @@  discard block
 block discarded – undo
132 139
 		fclose($fp);
133 140
 
134 141
 		// The comment looks rougly like... that.
135
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
136
-			$version_info['file_versions']['SSI.php'] = $match[1];
142
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
143
+					$version_info['file_versions']['SSI.php'] = $match[1];
144
+		}
137 145
 		// Not found!  This is bad.
138
-		else
139
-			$version_info['file_versions']['SSI.php'] = '??';
146
+		else {
147
+					$version_info['file_versions']['SSI.php'] = '??';
148
+		}
140 149
 	}
141 150
 
142 151
 	// Do the paid subscriptions handler?
@@ -147,11 +156,13 @@  discard block
 block discarded – undo
147 156
 		fclose($fp);
148 157
 
149 158
 		// Found it?
150
-		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
151
-			$version_info['file_versions']['subscriptions.php'] = $match[1];
159
+		if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
160
+					$version_info['file_versions']['subscriptions.php'] = $match[1];
161
+		}
152 162
 		// If we haven't how do we all get paid?
153
-		else
154
-			$version_info['file_versions']['subscriptions.php'] = '??';
163
+		else {
164
+					$version_info['file_versions']['subscriptions.php'] = '??';
165
+		}
155 166
 	}
156 167
 
157 168
 	// Load all the files in the Sources directory, except this file and the redirect.
@@ -166,11 +177,13 @@  discard block
 block discarded – undo
166 177
 			fclose($fp);
167 178
 
168 179
 			// Look for the version comment in the file header.
169
-			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
170
-				$version_info['file_versions'][$entry] = $match[1];
180
+			if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
181
+							$version_info['file_versions'][$entry] = $match[1];
182
+			}
171 183
 			// It wasn't found, but the file was... show a '??'.
172
-			else
173
-				$version_info['file_versions'][$entry] = '??';
184
+			else {
185
+							$version_info['file_versions'][$entry] = '??';
186
+			}
174 187
 		}
175 188
 	}
176 189
 	$sources_dir->close();
@@ -189,11 +202,13 @@  discard block
 block discarded – undo
189 202
 				fclose($fp);
190 203
 
191 204
 				// Look for the version comment in the file header.
192
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
193
-					$version_info['tasks_versions'][$entry] = $match[1];
205
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
206
+									$version_info['tasks_versions'][$entry] = $match[1];
207
+				}
194 208
 				// It wasn't found, but the file was... show a '??'.
195
-				else
196
-					$version_info['tasks_versions'][$entry] = '??';
209
+				else {
210
+									$version_info['tasks_versions'][$entry] = '??';
211
+				}
197 212
 			}
198 213
 		}
199 214
 		$tasks_dir->close();
@@ -201,8 +216,9 @@  discard block
 block discarded – undo
201 216
 
202 217
 	// Load all the files in the default template directory - and the current theme if applicable.
203 218
 	$directories = array('default_template_versions' => $settings['default_theme_dir']);
204
-	if ($settings['theme_id'] != 1)
205
-		$directories += array('template_versions' => $settings['theme_dir']);
219
+	if ($settings['theme_id'] != 1) {
220
+			$directories += array('template_versions' => $settings['theme_dir']);
221
+	}
206 222
 
207 223
 	foreach ($directories as $type => $dirname)
208 224
 	{
@@ -217,11 +233,13 @@  discard block
 block discarded – undo
217 233
 				fclose($fp);
218 234
 
219 235
 				// Look for the version comment in the file header.
220
-				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1)
221
-					$version_info[$type][$entry] = $match[1];
236
+				if (preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $header, $match) == 1) {
237
+									$version_info[$type][$entry] = $match[1];
238
+				}
222 239
 				// It wasn't found, but the file was... show a '??'.
223
-				else
224
-					$version_info[$type][$entry] = '??';
240
+				else {
241
+									$version_info[$type][$entry] = '??';
242
+				}
225 243
 			}
226 244
 		}
227 245
 		$this_dir->close();
@@ -242,11 +260,13 @@  discard block
 block discarded – undo
242 260
 			list ($name, $language) = explode('.', $entry);
243 261
 
244 262
 			// Look for the version comment in the file header.
245
-			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1)
246
-				$version_info['default_language_versions'][$language][$name] = $match[1];
263
+			if (preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*' . preg_quote($name, '~') . '(?:[\s]{2}|\*/)~i', $header, $match) == 1) {
264
+							$version_info['default_language_versions'][$language][$name] = $match[1];
265
+			}
247 266
 			// It wasn't found, but the file was... show a '??'.
248
-			else
249
-				$version_info['default_language_versions'][$language][$name] = '??';
267
+			else {
268
+							$version_info['default_language_versions'][$language][$name] = '??';
269
+			}
250 270
 		}
251 271
 	}
252 272
 	$this_dir->close();
@@ -261,8 +281,9 @@  discard block
 block discarded – undo
261 281
 		ksort($version_info['tasks_versions']);
262 282
 
263 283
 		// For languages sort each language too.
264
-		foreach ($version_info['default_language_versions'] as $language => $dummy)
265
-			ksort($version_info['default_language_versions'][$language]);
284
+		foreach ($version_info['default_language_versions'] as $language => $dummy) {
285
+					ksort($version_info['default_language_versions'][$language]);
286
+		}
266 287
 	}
267 288
 	return $version_info;
268 289
 }
@@ -304,27 +325,31 @@  discard block
 block discarded – undo
304 325
 	$settingsArray = trim(file_get_contents($boarddir . '/Settings.php'));
305 326
 
306 327
 	// Break it up based on \r or \n, and then clean out extra characters.
307
-	if (strpos($settingsArray, "\n") !== false)
308
-		$settingsArray = explode("\n", $settingsArray);
309
-	elseif (strpos($settingsArray, "\r") !== false)
310
-		$settingsArray = explode("\r", $settingsArray);
311
-	else
312
-		return;
328
+	if (strpos($settingsArray, "\n") !== false) {
329
+			$settingsArray = explode("\n", $settingsArray);
330
+	} elseif (strpos($settingsArray, "\r") !== false) {
331
+			$settingsArray = explode("\r", $settingsArray);
332
+	} else {
333
+			return;
334
+	}
313 335
 
314 336
 	// Presumably, the file has to have stuff in it for this function to be called :P.
315
-	if (count($settingsArray) < 10)
316
-		return;
337
+	if (count($settingsArray) < 10) {
338
+			return;
339
+	}
317 340
 
318 341
 	// remove any /r's that made there way in here
319
-	foreach ($settingsArray as $k => $dummy)
320
-		$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
342
+	foreach ($settingsArray as $k => $dummy) {
343
+			$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
344
+	}
321 345
 
322 346
 	// go line by line and see whats changing
323 347
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
324 348
 	{
325 349
 		// Don't trim or bother with it if it's not a variable.
326
-		if (substr($settingsArray[$i], 0, 1) != '$')
327
-			continue;
350
+		if (substr($settingsArray[$i], 0, 1) != '$') {
351
+					continue;
352
+		}
328 353
 
329 354
 		$settingsArray[$i] = trim($settingsArray[$i]) . "\n";
330 355
 
@@ -336,8 +361,7 @@  discard block
 block discarded – undo
336 361
 			{
337 362
 				updateDbLastError($val);
338 363
 				unset($config_vars[$var]);
339
-			}
340
-			elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
364
+			} elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
341 365
 			{
342 366
 				$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
343 367
 				$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n";
@@ -348,34 +372,39 @@  discard block
 block discarded – undo
348 372
 		}
349 373
 
350 374
 		// End of the file ... maybe
351
-		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>')
352
-			$end = $i;
375
+		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') {
376
+					$end = $i;
377
+		}
353 378
 	}
354 379
 
355 380
 	// This should never happen, but apparently it is happening.
356
-	if (empty($end) || $end < 10)
357
-		$end = count($settingsArray) - 1;
381
+	if (empty($end) || $end < 10) {
382
+			$end = count($settingsArray) - 1;
383
+	}
358 384
 
359 385
 	// Still more variables to go?  Then lets add them at the end.
360 386
 	if (!empty($config_vars))
361 387
 	{
362
-		if (trim($settingsArray[$end]) == '?' . '>')
363
-			$settingsArray[$end++] = '';
364
-		else
365
-			$end++;
388
+		if (trim($settingsArray[$end]) == '?' . '>') {
389
+					$settingsArray[$end++] = '';
390
+		} else {
391
+					$end++;
392
+		}
366 393
 
367 394
 		// Add in any newly defined vars that were passed
368
-		foreach ($config_vars as $var => $val)
369
-			$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
395
+		foreach ($config_vars as $var => $val) {
396
+					$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
397
+		}
370 398
 
371 399
 		$settingsArray[$end] = '?' . '>';
400
+	} else {
401
+			$settingsArray[$end] = trim($settingsArray[$end]);
372 402
 	}
373
-	else
374
-		$settingsArray[$end] = trim($settingsArray[$end]);
375 403
 
376 404
 	// Sanity error checking: the file needs to be at least 12 lines.
377
-	if (count($settingsArray) < 12)
378
-		return;
405
+	if (count($settingsArray) < 12) {
406
+			return;
407
+	}
379 408
 
380 409
 	// Try to avoid a few pitfalls:
381 410
 	//  - like a possible race condition,
@@ -383,8 +412,9 @@  discard block
 block discarded – undo
383 412
 	//
384 413
 	// Check before you act: if cache is enabled, we can do a simple write test
385 414
 	// to validate that we even write things on this filesystem.
386
-	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
387
-		$cachedir = $boarddir . '/cache';
415
+	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
416
+			$cachedir = $boarddir . '/cache';
417
+	}
388 418
 
389 419
 	$test_fp = @fopen($cachedir . '/settings_update.tmp', "w+");
390 420
 	if ($test_fp)
@@ -419,16 +449,18 @@  discard block
 block discarded – undo
419 449
 			// Well this is not good at all, lets see if we can save this
420 450
 			$context['settings_message'] = 'settings_error';
421 451
 
422
-			if (file_exists($boarddir . '/Settings_bak.php'))
423
-				@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
452
+			if (file_exists($boarddir . '/Settings_bak.php')) {
453
+							@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
454
+			}
424 455
 		}
425 456
 	}
426 457
 
427 458
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
428 459
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
429
-	if (function_exists('opcache_invalidate'))
430
-		opcache_invalidate($boarddir . '/Settings.php', true);
431
-}
460
+	if (function_exists('opcache_invalidate')) {
461
+			opcache_invalidate($boarddir . '/Settings.php', true);
462
+	}
463
+	}
432 464
 
433 465
 /**
434 466
  * Saves the time of the last db error for the error log
@@ -454,8 +486,9 @@  discard block
 block discarded – undo
454 486
 	global $options, $context, $smcFunc, $settings, $user_info;
455 487
 
456 488
 	// This must exist!
457
-	if (!isset($context['admin_preferences']))
458
-		return false;
489
+	if (!isset($context['admin_preferences'])) {
490
+			return false;
491
+	}
459 492
 
460 493
 	// This is what we'll be saving.
461 494
 	$options['admin_preferences'] = $smcFunc['json_encode']($context['admin_preferences']);
@@ -519,8 +552,9 @@  discard block
 block discarded – undo
519 552
 	$emails_sent = array();
520 553
 	while ($row = $smcFunc['db_fetch_assoc']($request))
521 554
 	{
522
-		if (empty($prefs[$row['id_member']]['announcements']))
523
-			continue;
555
+		if (empty($prefs[$row['id_member']]['announcements'])) {
556
+					continue;
557
+		}
524 558
 
525 559
 		// Stick their particulars in the replacement data.
526 560
 		$replacements['IDMEMBER'] = $row['id_member'];
@@ -539,11 +573,12 @@  discard block
 block discarded – undo
539 573
 	$smcFunc['db_free_result']($request);
540 574
 
541 575
 	// Any additional users we must email this to?
542
-	if (!empty($additional_recipients))
543
-		foreach ($additional_recipients as $recipient)
576
+	if (!empty($additional_recipients)) {
577
+			foreach ($additional_recipients as $recipient)
544 578
 		{
545 579
 			if (in_array($recipient['email'], $emails_sent))
546 580
 				continue;
581
+	}
547 582
 
548 583
 			$replacements['IDMEMBER'] = $recipient['id'];
549 584
 			$replacements['REALNAME'] = $recipient['name'];
Please login to merge, or discard this patch.
Sources/Subs-Graphics.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -170,7 +170,7 @@
 block discarded – undo
170 170
  *
171 171
  * @param string $fileName The path to the file
172 172
  * @param int $preferred_format The preferred format - 0 to automatically determine, 1 for gif, 2 for jpg, 3 for png, 6 for bmp and 15 for wbmp
173
- * @return boolean Whether the reencoding was successful
173
+ * @return false|null Whether the reencoding was successful
174 174
  */
175 175
 function reencodeImage($fileName, $preferred_format = 0)
176 176
 {
Please login to merge, or discard this patch.
Indentation   -2 removed lines patch added patch discarded remove patch
@@ -523,7 +523,6 @@  discard block
 block discarded – undo
523 523
 /**
524 524
  * Copy image.
525 525
  * Used when imagecopyresample() is not available.
526
-
527 526
  * @param resource $dst_img The destination image - a GD image resource
528 527
  * @param resource $src_img The source image - a GD image resource
529 528
  * @param int $dst_x The "x" coordinate of the destination image
@@ -754,7 +753,6 @@  discard block
 block discarded – undo
754 753
 
755 754
 /**
756 755
  * Writes a gif file to disk as a png file.
757
-
758 756
  * @param resource $gif A gif image resource
759 757
  * @param string $lpszFileName The name of the file
760 758
  * @param int $background_color The background color
Please login to merge, or discard this patch.
Braces   +240 added lines, -196 removed lines patch added patch discarded remove patch
@@ -18,8 +18,9 @@  discard block
 block discarded – undo
18 18
  * @version 2.1 Beta 4
19 19
  */
20 20
 
21
-if (!defined('SMF'))
21
+if (!defined('SMF')) {
22 22
 	die('No direct access...');
23
+}
23 24
 
24 25
 /**
25 26
  * downloads a file from a url and stores it locally for avatar use by id_member.
@@ -44,8 +45,9 @@  discard block
 block discarded – undo
44 45
 	$destName = 'avatar_' . $memID . '_' . time() . '.' . $ext;
45 46
 
46 47
 	// Just making sure there is a non-zero member.
47
-	if (empty($memID))
48
-		return false;
48
+	if (empty($memID)) {
49
+			return false;
50
+	}
49 51
 
50 52
 	require_once($sourcedir . '/ManageAttachments.php');
51 53
 	removeAttachments(array('id_member' => $memID));
@@ -76,10 +78,11 @@  discard block
 block discarded – undo
76 78
 	$destName = $modSettings['custom_avatar_dir'] . '/' . $destName . '.tmp';
77 79
 
78 80
 	// Resize it.
79
-	if (!empty($modSettings['avatar_download_png']))
80
-		$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
81
-	else
82
-		$success = resizeImageFile($url, $destName, $max_width, $max_height);
81
+	if (!empty($modSettings['avatar_download_png'])) {
82
+			$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
83
+	} else {
84
+			$success = resizeImageFile($url, $destName, $max_width, $max_height);
85
+	}
83 86
 
84 87
 	// Remove the .tmp extension.
85 88
 	$destName = substr($destName, 0, -4);
@@ -108,11 +111,10 @@  discard block
 block discarded – undo
108 111
 				)
109 112
 			);
110 113
 			return true;
114
+		} else {
115
+					return false;
111 116
 		}
112
-		else
113
-			return false;
114
-	}
115
-	else
117
+	} else
116 118
 	{
117 119
 		$smcFunc['db_query']('', '
118 120
 			DELETE FROM {db_prefix}attachments
@@ -144,17 +146,18 @@  discard block
 block discarded – undo
144 146
 	$destName = $source . '_thumb.tmp';
145 147
 
146 148
 	// Do the actual resize.
147
-	if (!empty($modSettings['attachment_thumb_png']))
148
-		$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
149
-	else
150
-		$success = resizeImageFile($source, $destName, $max_width, $max_height);
149
+	if (!empty($modSettings['attachment_thumb_png'])) {
150
+			$success = resizeImageFile($source, $destName, $max_width, $max_height, 3);
151
+	} else {
152
+			$success = resizeImageFile($source, $destName, $max_width, $max_height);
153
+	}
151 154
 
152 155
 	// Okay, we're done with the temporary stuff.
153 156
 	$destName = substr($destName, 0, -4);
154 157
 
155
-	if ($success && @rename($destName . '.tmp', $destName))
156
-		return true;
157
-	else
158
+	if ($success && @rename($destName . '.tmp', $destName)) {
159
+			return true;
160
+	} else
158 161
 	{
159 162
 		@unlink($destName . '.tmp');
160 163
 		@touch($destName);
@@ -176,18 +179,21 @@  discard block
 block discarded – undo
176 179
 {
177 180
 	if (!resizeImageFile($fileName, $fileName . '.tmp', null, null, $preferred_format))
178 181
 	{
179
-		if (file_exists($fileName . '.tmp'))
180
-			unlink($fileName . '.tmp');
182
+		if (file_exists($fileName . '.tmp')) {
183
+					unlink($fileName . '.tmp');
184
+		}
181 185
 
182 186
 		return false;
183 187
 	}
184 188
 
185
-	if (!unlink($fileName))
186
-		return false;
189
+	if (!unlink($fileName)) {
190
+			return false;
191
+	}
187 192
 
188
-	if (!rename($fileName . '.tmp', $fileName))
189
-		return false;
190
-}
193
+	if (!rename($fileName . '.tmp', $fileName)) {
194
+			return false;
195
+	}
196
+	}
191 197
 
192 198
 /**
193 199
  * Searches through the file to see if there's potentially harmful non-binary content.
@@ -200,8 +206,9 @@  discard block
 block discarded – undo
200 206
 function checkImageContents($fileName, $extensiveCheck = false)
201 207
 {
202 208
 	$fp = fopen($fileName, 'rb');
203
-	if (!$fp)
204
-		fatal_lang_error('attach_timeout');
209
+	if (!$fp) {
210
+			fatal_lang_error('attach_timeout');
211
+	}
205 212
 
206 213
 	$prev_chunk = '';
207 214
 	while (!feof($fp))
@@ -218,8 +225,7 @@  discard block
 block discarded – undo
218 225
 				fclose($fp);
219 226
 				return false;
220 227
 			}
221
-		}
222
-		else
228
+		} else
223 229
 		{
224 230
 			// Check for potential infection - focus on clues for inline php & flash.
225 231
 			// Will result in significantly fewer false positives than the paranoid check.
@@ -247,8 +253,9 @@  discard block
 block discarded – undo
247 253
 	global $gd2;
248 254
 
249 255
 	// Check to see if GD is installed and what version.
250
-	if (($extensionFunctions = get_extension_funcs('gd')) === false)
251
-		return false;
256
+	if (($extensionFunctions = get_extension_funcs('gd')) === false) {
257
+			return false;
258
+	}
252 259
 
253 260
 	// Also determine if GD2 is installed and store it in a global.
254 261
 	$gd2 = in_array('imagecreatetruecolor', $extensionFunctions) && function_exists('imagecreatetruecolor');
@@ -320,8 +327,9 @@  discard block
 block discarded – undo
320 327
 	global $sourcedir;
321 328
 
322 329
 	// Nothing to do without GD or IM/MW
323
-	if (!checkGD() && !checkImagick() && !checkMagickWand())
324
-		return false;
330
+	if (!checkGD() && !checkImagick() && !checkMagickWand()) {
331
+			return false;
332
+	}
325 333
 
326 334
 	static $default_formats = array(
327 335
 		'1' => 'gif',
@@ -341,38 +349,39 @@  discard block
 block discarded – undo
341 349
 		fclose($fp_destination);
342 350
 
343 351
 		$sizes = @getimagesize($destination);
344
-	}
345
-	elseif ($fp_destination)
352
+	} elseif ($fp_destination)
346 353
 	{
347 354
 		$sizes = @getimagesize($source);
348 355
 
349 356
 		$fp_source = fopen($source, 'rb');
350 357
 		if ($fp_source !== false)
351 358
 		{
352
-			while (!feof($fp_source))
353
-				fwrite($fp_destination, fread($fp_source, 8192));
359
+			while (!feof($fp_source)) {
360
+							fwrite($fp_destination, fread($fp_source, 8192));
361
+			}
354 362
 			fclose($fp_source);
363
+		} else {
364
+					$sizes = array(-1, -1, -1);
355 365
 		}
356
-		else
357
-			$sizes = array(-1, -1, -1);
358 366
 		fclose($fp_destination);
359 367
 	}
360 368
 	// We can't get to the file.
361
-	else
362
-		$sizes = array(-1, -1, -1);
369
+	else {
370
+			$sizes = array(-1, -1, -1);
371
+	}
363 372
 
364 373
 	// See if we have -or- can get the needed memory for this operation
365 374
 	// ImageMagick isn't subject to PHP's memory limits :)
366
-	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes))
367
-		return false;
375
+	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) {
376
+			return false;
377
+	}
368 378
 
369 379
 	// A known and supported format?
370 380
 	// @todo test PSD and gif.
371 381
 	if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]]))
372 382
 	{
373 383
 		return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format);
374
-	}
375
-	elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
384
+	} elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
376 385
 	{
377 386
 		$imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
378 387
 		if ($src_img = @$imagecreatefrom($destination))
@@ -425,14 +434,14 @@  discard block
 block discarded – undo
425 434
 			$dest_width = empty($max_width) ? $src_width : $max_width;
426 435
 			$dest_height = empty($max_height) ? $src_height : $max_height;
427 436
 
428
-			if ($default_formats[$preferred_format] == 'jpeg')
429
-				$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
437
+			if ($default_formats[$preferred_format] == 'jpeg') {
438
+							$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
439
+			}
430 440
 
431 441
 			$imagick->setImageFormat($default_formats[$preferred_format]);
432 442
 			$imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true);
433 443
 			$success = $imagick->writeImage($destName);
434
-		}
435
-		else
444
+		} else
436 445
 		{
437 446
 			$magick_wand = newMagickWand();
438 447
 			MagickReadImage($magick_wand, $destName);
@@ -441,8 +450,9 @@  discard block
 block discarded – undo
441 450
 			$dest_width = empty($max_width) ? $src_width : $max_width;
442 451
 			$dest_height = empty($max_height) ? $src_height : $max_height;
443 452
 
444
-			if ($default_formats[$preferred_format] == 'jpeg')
445
-				MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
453
+			if ($default_formats[$preferred_format] == 'jpeg') {
454
+							MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
455
+			}
446 456
 
447 457
 			MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]);
448 458
 			MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true);
@@ -450,8 +460,7 @@  discard block
 block discarded – undo
450 460
 		}
451 461
 
452 462
 		return !empty($success);
453
-	}
454
-	elseif (checkGD())
463
+	} elseif (checkGD())
455 464
 	{
456 465
 		$success = false;
457 466
 
@@ -462,8 +471,7 @@  discard block
 block discarded – undo
462 471
 			{
463 472
 				$dst_width = $max_width;
464 473
 				$dst_height = round($src_height * $max_width / $src_width);
465
-			}
466
-			elseif (!empty($max_height))
474
+			} elseif (!empty($max_height))
467 475
 			{
468 476
 				$dst_width = round($src_width * $max_height / $src_height);
469 477
 				$dst_height = $max_height;
@@ -481,44 +489,48 @@  discard block
 block discarded – undo
481 489
 					if ((!empty($preferred_format)) && ($preferred_format == 3))
482 490
 					{
483 491
 						imagealphablending($dst_img, false);
484
-						if (function_exists('imagesavealpha'))
485
-							imagesavealpha($dst_img, true);
492
+						if (function_exists('imagesavealpha')) {
493
+													imagesavealpha($dst_img, true);
494
+						}
486 495
 					}
496
+				} else {
497
+									$dst_img = imagecreate($dst_width, $dst_height);
487 498
 				}
488
-				else
489
-					$dst_img = imagecreate($dst_width, $dst_height);
490 499
 
491 500
 				// Resize it!
492
-				if ($gd2)
493
-					imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
494
-				else
495
-					imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
501
+				if ($gd2) {
502
+									imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
503
+				} else {
504
+									imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
505
+				}
506
+			} else {
507
+							$dst_img = $src_img;
496 508
 			}
497
-			else
498
-				$dst_img = $src_img;
509
+		} else {
510
+					$dst_img = $src_img;
499 511
 		}
500
-		else
501
-			$dst_img = $src_img;
502 512
 
503 513
 		// Save the image as ...
504
-		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng'))
505
-			$success = imagepng($dst_img, $destName);
506
-		elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif'))
507
-			$success = imagegif($dst_img, $destName);
508
-		elseif (function_exists('imagejpeg'))
509
-			$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
514
+		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) {
515
+					$success = imagepng($dst_img, $destName);
516
+		} elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) {
517
+					$success = imagegif($dst_img, $destName);
518
+		} elseif (function_exists('imagejpeg')) {
519
+					$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
520
+		}
510 521
 
511 522
 		// Free the memory.
512 523
 		imagedestroy($src_img);
513
-		if ($dst_img != $src_img)
514
-			imagedestroy($dst_img);
524
+		if ($dst_img != $src_img) {
525
+					imagedestroy($dst_img);
526
+		}
515 527
 
516 528
 		return $success;
517
-	}
518
-	else
519
-		// Without GD, no image resizing at all.
529
+	} else {
530
+			// Without GD, no image resizing at all.
520 531
 		return false;
521
-}
532
+	}
533
+	}
522 534
 
523 535
 /**
524 536
  * Copy image.
@@ -572,8 +584,9 @@  discard block
 block discarded – undo
572 584
 			$color = imagecolorresolve($dst_img, $red, $green, $blue);
573 585
 			if ($color == -1)
574 586
 			{
575
-				if ($palsize++ < 256)
576
-					imagecolorallocate($dst_img, $red, $green, $blue);
587
+				if ($palsize++ < 256) {
588
+									imagecolorallocate($dst_img, $red, $green, $blue);
589
+				}
577 590
 				$color = imagecolorclosest($dst_img, $red, $green, $blue);
578 591
 			}
579 592
 
@@ -603,13 +616,15 @@  discard block
 block discarded – undo
603 616
 		$header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14));
604 617
 		$info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40));
605 618
 
606
-		if ($header['type'] != 0x4D42)
607
-			return false;
619
+		if ($header['type'] != 0x4D42) {
620
+					return false;
621
+		}
608 622
 
609
-		if ($gd2)
610
-			$dst_img = imagecreatetruecolor($info['width'], $info['height']);
611
-		else
612
-			$dst_img = imagecreate($info['width'], $info['height']);
623
+		if ($gd2) {
624
+					$dst_img = imagecreatetruecolor($info['width'], $info['height']);
625
+		} else {
626
+					$dst_img = imagecreate($info['width'], $info['height']);
627
+		}
613 628
 
614 629
 		$palette_size = $header['offset'] - 54;
615 630
 		$info['ncolor'] = $palette_size / 4;
@@ -635,8 +650,9 @@  discard block
 block discarded – undo
635 650
 			fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l);
636 651
 			$scan_line = fread($fp, $scan_line_size);
637 652
 
638
-			if (strlen($scan_line) < $scan_line_size)
639
-				continue;
653
+			if (strlen($scan_line) < $scan_line_size) {
654
+							continue;
655
+			}
640 656
 
641 657
 			if ($info['bits'] == 32)
642 658
 			{
@@ -654,14 +670,14 @@  discard block
 block discarded – undo
654 670
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
655 671
 
656 672
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
657
-						if ($color == -1)
658
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
673
+						if ($color == -1) {
674
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
675
+						}
659 676
 					}
660 677
 
661 678
 					imagesetpixel($dst_img, $x, $y, $color);
662 679
 				}
663
-			}
664
-			elseif ($info['bits'] == 24)
680
+			} elseif ($info['bits'] == 24)
665 681
 			{
666 682
 				$x = 0;
667 683
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -676,14 +692,14 @@  discard block
 block discarded – undo
676 692
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
677 693
 
678 694
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
679
-						if ($color == -1)
680
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
695
+						if ($color == -1) {
696
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
697
+						}
681 698
 					}
682 699
 
683 700
 					imagesetpixel($dst_img, $x, $y, $color);
684 701
 				}
685
-			}
686
-			elseif ($info['bits'] == 16)
702
+			} elseif ($info['bits'] == 16)
687 703
 			{
688 704
 				$x = 0;
689 705
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -704,20 +720,20 @@  discard block
 block discarded – undo
704 720
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
705 721
 
706 722
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
707
-						if ($color == -1)
708
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
723
+						if ($color == -1) {
724
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
725
+						}
709 726
 					}
710 727
 
711 728
 					imagesetpixel($dst_img, $x, $y, $color);
712 729
 				}
713
-			}
714
-			elseif ($info['bits'] == 8)
730
+			} elseif ($info['bits'] == 8)
715 731
 			{
716 732
 				$x = 0;
717
-				for ($j = 0; $j < $scan_line_size; $x++)
718
-					imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
719
-			}
720
-			elseif ($info['bits'] == 4)
733
+				for ($j = 0; $j < $scan_line_size; $x++) {
734
+									imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
735
+				}
736
+			} elseif ($info['bits'] == 4)
721 737
 			{
722 738
 				$x = 0;
723 739
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -726,11 +742,11 @@  discard block
 block discarded – undo
726 742
 
727 743
 					imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]);
728 744
 
729
-					if (++$x < $info['width'])
730
-						imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
745
+					if (++$x < $info['width']) {
746
+											imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
747
+					}
731 748
 				}
732
-			}
733
-			elseif ($info['bits'] == 1)
749
+			} elseif ($info['bits'] == 1)
734 750
 			{
735 751
 				$x = 0;
736 752
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -741,8 +757,9 @@  discard block
 block discarded – undo
741 757
 
742 758
 					for ($shift = 1; $shift < 8; $shift++)
743 759
 					{
744
-						if (++$x < $info['width'])
745
-							imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
760
+						if (++$x < $info['width']) {
761
+													imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
762
+						}
746 763
 					}
747 764
 				}
748 765
 			}
@@ -766,15 +783,18 @@  discard block
 block discarded – undo
766 783
  */
767 784
 function gif_outputAsPng($gif, $lpszFileName, $background_color = -1)
768 785
 {
769
-	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '')
770
-		return false;
786
+	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') {
787
+			return false;
788
+	}
771 789
 
772 790
 	$fd = $gif->get_png_data($background_color);
773
-	if (strlen($fd) <= 0)
774
-		return false;
791
+	if (strlen($fd) <= 0) {
792
+			return false;
793
+	}
775 794
 
776
-	if (!($fh = @fopen($lpszFileName, 'wb')))
777
-		return false;
795
+	if (!($fh = @fopen($lpszFileName, 'wb'))) {
796
+			return false;
797
+	}
778 798
 
779 799
 	@fwrite($fh, $fd, strlen($fd));
780 800
 	@fflush($fh);
@@ -801,8 +821,9 @@  discard block
 block discarded – undo
801 821
 	// What type are we going to be doing?
802 822
 	$imageType = $modSettings['visual_verification_type'];
803 823
 	// Special case to allow the admin center to show samples.
804
-	if ($user_info['is_admin'] && isset($_GET['type']))
805
-		$imageType = (int) $_GET['type'];
824
+	if ($user_info['is_admin'] && isset($_GET['type'])) {
825
+			$imageType = (int) $_GET['type'];
826
+	}
806 827
 
807 828
 	// Some quick references for what we do.
808 829
 	// Do we show no, low or high noise?
@@ -836,25 +857,28 @@  discard block
 block discarded – undo
836 857
 	$character_spacing = 1;
837 858
 
838 859
 	// What color is the background - generally white unless we're on "hard".
839
-	if ($simpleBGColor)
840
-		$background_color = array(255, 255, 255);
841
-	else
842
-		$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
860
+	if ($simpleBGColor) {
861
+			$background_color = array(255, 255, 255);
862
+	} else {
863
+			$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
864
+	}
843 865
 
844 866
 	// The color of the characters shown (red, green, blue).
845
-	if ($simpleFGColor)
846
-		$foreground_color = array(0, 0, 0);
847
-	else
867
+	if ($simpleFGColor) {
868
+			$foreground_color = array(0, 0, 0);
869
+	} else
848 870
 	{
849 871
 		$foreground_color = array(64, 101, 136);
850 872
 
851 873
 		// Has the theme author requested a custom color?
852
-		if (isset($settings['verification_foreground']))
853
-			$foreground_color = $settings['verification_foreground'];
874
+		if (isset($settings['verification_foreground'])) {
875
+					$foreground_color = $settings['verification_foreground'];
876
+		}
854 877
 	}
855 878
 
856
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
857
-		return false;
879
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
880
+			return false;
881
+	}
858 882
 
859 883
 	// Get a list of the available fonts.
860 884
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
@@ -865,25 +889,28 @@  discard block
 block discarded – undo
865 889
 	{
866 890
 		if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1)
867 891
 		{
868
-			if ($endian ^ (strpos($entry, '_end.gdf') === false))
869
-				$font_list[] = $entry;
892
+			if ($endian ^ (strpos($entry, '_end.gdf') === false)) {
893
+							$font_list[] = $entry;
894
+			}
895
+		} elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) {
896
+					$ttfont_list[] = $entry;
870 897
 		}
871
-		elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1)
872
-			$ttfont_list[] = $entry;
873 898
 	}
874 899
 
875
-	if (empty($font_list))
876
-		return false;
900
+	if (empty($font_list)) {
901
+			return false;
902
+	}
877 903
 
878 904
 	// For non-hard things don't even change fonts.
879 905
 	if (!$varyFonts)
880 906
 	{
881 907
 		$font_list = array($font_list[0]);
882 908
 		// Try use Screenge if we can - it looks good!
883
-		if (in_array('AnonymousPro.ttf', $ttfont_list))
884
-			$ttfont_list = array('AnonymousPro.ttf');
885
-		else
886
-			$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
909
+		if (in_array('AnonymousPro.ttf', $ttfont_list)) {
910
+					$ttfont_list = array('AnonymousPro.ttf');
911
+		} else {
912
+					$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
913
+		}
887 914
 	}
888 915
 
889 916
 	// Create a list of characters to be shown.
@@ -900,14 +927,16 @@  discard block
 block discarded – undo
900 927
 	}
901 928
 
902 929
 	// Load all fonts and determine the maximum font height.
903
-	foreach ($loaded_fonts as $font_index => $dummy)
904
-		$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
930
+	foreach ($loaded_fonts as $font_index => $dummy) {
931
+			$loaded_fonts[$font_index] = imageloadfont($settings['default_theme_dir'] . '/fonts/' . $font_list[$font_index]);
932
+	}
905 933
 
906 934
 	// Determine the dimensions of each character.
907
-	if ($imageType == 4 || $imageType == 5)
908
-		$extra = 80;
909
-	else
910
-		$extra = 45;
935
+	if ($imageType == 4 || $imageType == 5) {
936
+			$extra = 80;
937
+	} else {
938
+			$extra = 45;
939
+	}
911 940
 
912 941
 	$total_width = $character_spacing * strlen($code) + $extra;
913 942
 	$max_height = 0;
@@ -928,13 +957,15 @@  discard block
 block discarded – undo
928 957
 	imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color);
929 958
 
930 959
 	// Randomize the foreground color a little.
931
-	for ($i = 0; $i < 3; $i++)
932
-		$foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
960
+	for ($i = 0; $i < 3; $i++) {
961
+			$foreground_color[$i] = mt_rand(max($foreground_color[$i] - 3, 0), min($foreground_color[$i] + 3, 255));
962
+	}
933 963
 	$fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
934 964
 
935 965
 	// Color for the dots.
936
-	for ($i = 0; $i < 3; $i++)
937
-		$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255);
966
+	for ($i = 0; $i < 3; $i++) {
967
+			$dotbgcolor[$i] = $background_color[$i] < $foreground_color[$i] ? mt_rand(0, max($foreground_color[$i] - 20, 0)) : mt_rand(min($foreground_color[$i] + 20, 255), 255);
968
+	}
938 969
 	$randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]);
939 970
 
940 971
 	// Some squares/rectanges for new extreme level
@@ -960,10 +991,11 @@  discard block
 block discarded – undo
960 991
 			$can_do_ttf = function_exists('imagettftext');
961 992
 
962 993
 			// How much rotation will we give?
963
-			if ($rotationType == 'none')
964
-				$angle = 0;
965
-			else
966
-				$angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10);
994
+			if ($rotationType == 'none') {
995
+							$angle = 0;
996
+			} else {
997
+							$angle = mt_rand(-100, 100) / ($rotationType == 'high' ? 6 : 10);
998
+			}
967 999
 
968 1000
 			// What color shall we do it?
969 1001
 			if ($fontColorType == 'cyclic')
@@ -977,51 +1009,56 @@  discard block
 block discarded – undo
977 1009
 					array(0, 0, 0),
978 1010
 					array(143, 39, 31),
979 1011
 				);
980
-				if (!isset($last_index))
981
-					$last_index = -1;
1012
+				if (!isset($last_index)) {
1013
+									$last_index = -1;
1014
+				}
982 1015
 				$new_index = $last_index;
983
-				while ($last_index == $new_index)
984
-					$new_index = mt_rand(0, count($colors) - 1);
1016
+				while ($last_index == $new_index) {
1017
+									$new_index = mt_rand(0, count($colors) - 1);
1018
+				}
985 1019
 				$char_fg_color = $colors[$new_index];
986 1020
 				$last_index = $new_index;
1021
+			} elseif ($fontColorType == 'random') {
1022
+							$char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2]));
1023
+			} else {
1024
+							$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
987 1025
 			}
988
-			elseif ($fontColorType == 'random')
989
-				$char_fg_color = array(mt_rand(max($foreground_color[0] - 2, 0), $foreground_color[0]), mt_rand(max($foreground_color[1] - 2, 0), $foreground_color[1]), mt_rand(max($foreground_color[2] - 2, 0), $foreground_color[2]));
990
-			else
991
-				$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
992 1026
 
993 1027
 			if (!empty($can_do_ttf))
994 1028
 			{
995 1029
 				// GD2 handles font size differently.
996
-				if ($fontSizeRandom)
997
-					$font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25);
998
-				else
999
-					$font_size = $gd2 ? 18 : 24;
1030
+				if ($fontSizeRandom) {
1031
+									$font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25);
1032
+				} else {
1033
+									$font_size = $gd2 ? 18 : 24;
1034
+				}
1000 1035
 
1001 1036
 				// Work out the sizes - also fix the character width cause TTF not quite so wide!
1002 1037
 				$font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5;
1003 1038
 				$font_y = $max_height - ($fontVerPos == 'vrandom' ? mt_rand(2, 8) : ($fontVerPos == 'random' ? mt_rand(3, 5) : 5));
1004 1039
 
1005 1040
 				// What font face?
1006
-				if (!empty($ttfont_list))
1007
-					$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)];
1041
+				if (!empty($ttfont_list)) {
1042
+									$fontface = $settings['default_theme_dir'] . '/fonts/' . $ttfont_list[mt_rand(0, count($ttfont_list) - 1)];
1043
+				}
1008 1044
 
1009 1045
 				// What color are we to do it in?
1010 1046
 				$is_reverse = $showReverseChars ? mt_rand(0, 1) : false;
1011 1047
 				$char_color = function_exists('imagecolorallocatealpha') && $fontTrans ? imagecolorallocatealpha($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2], 50) : imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]);
1012 1048
 
1013 1049
 				$fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']);
1014
-				if (empty($fontcord))
1015
-					$can_do_ttf = false;
1016
-				elseif ($is_reverse)
1050
+				if (empty($fontcord)) {
1051
+									$can_do_ttf = false;
1052
+				} elseif ($is_reverse)
1017 1053
 				{
1018 1054
 					imagefilledpolygon($code_image, $fontcord, 4, $fg_color);
1019 1055
 					// Put the character back!
1020 1056
 					imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']);
1021 1057
 				}
1022 1058
 
1023
-				if ($can_do_ttf)
1024
-					$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1059
+				if ($can_do_ttf) {
1060
+									$cur_x = max($fontcord[2], $fontcord[4]) + ($angle == 0 ? 0 : 3);
1061
+				}
1025 1062
 			}
1026 1063
 
1027 1064
 			if (!$can_do_ttf)
@@ -1040,8 +1077,9 @@  discard block
 block discarded – undo
1040 1077
 				}
1041 1078
 
1042 1079
 				// Sorry, no rotation available.
1043
-				else
1044
-					imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1080
+				else {
1081
+									imagechar($code_image, $loaded_fonts[$character['font']], $cur_x, floor(($max_height - $character['height']) / 2), $character['id'], imagecolorallocate($code_image, $char_fg_color[0], $char_fg_color[1], $char_fg_color[2]));
1082
+				}
1045 1083
 				$cur_x += $character['width'] + $character_spacing;
1046 1084
 			}
1047 1085
 		}
@@ -1054,17 +1092,22 @@  discard block
 block discarded – undo
1054 1092
 	}
1055 1093
 
1056 1094
 	// Make the background color transparent on the hard image.
1057
-	if (!$simpleBGColor)
1058
-		imagecolortransparent($code_image, $bg_color);
1059
-	if ($hasBorder)
1060
-		imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1095
+	if (!$simpleBGColor) {
1096
+			imagecolortransparent($code_image, $bg_color);
1097
+	}
1098
+	if ($hasBorder) {
1099
+			imagerectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $fg_color);
1100
+	}
1061 1101
 
1062 1102
 	// Add some noise to the background?
1063 1103
 	if ($noiseType != 'none')
1064 1104
 	{
1065
-		for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2))
1066
-			for ($j = mt_rand(0, 10); $j < $total_width; $j += mt_rand(1, 10))
1067
-				imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color);
1105
+		for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2)) {
1106
+					for ($j = mt_rand(0, 10);
1107
+		}
1108
+		$j < $total_width; $j += mt_rand(1, 10)) {
1109
+							imagesetpixel($code_image, $j, $i, mt_rand(0, 1) ? $fg_color : $randomness_color);
1110
+			}
1068 1111
 
1069 1112
 		// Put in some lines too?
1070 1113
 		if ($noiseType != 'extreme')
@@ -1077,8 +1120,7 @@  discard block
 block discarded – undo
1077 1120
 					$x1 = mt_rand(0, $total_width);
1078 1121
 					$x2 = mt_rand(0, $total_width);
1079 1122
 					$y1 = 0; $y2 = $max_height;
1080
-				}
1081
-				else
1123
+				} else
1082 1124
 				{
1083 1125
 					$y1 = mt_rand(0, $max_height);
1084 1126
 					$y2 = mt_rand(0, $max_height);
@@ -1087,8 +1129,7 @@  discard block
 block discarded – undo
1087 1129
 				imagesetthickness($code_image, mt_rand(1, 2));
1088 1130
 				imageline($code_image, $x1, $y1, $x2, $y2, mt_rand(0, 1) ? $fg_color : $randomness_color);
1089 1131
 			}
1090
-		}
1091
-		else
1132
+		} else
1092 1133
 		{
1093 1134
 			// Put in some ellipse
1094 1135
 			$num_ellipse = $noiseType == 'extreme' ? mt_rand(6, 12) : mt_rand(2, 6);
@@ -1108,8 +1149,7 @@  discard block
 block discarded – undo
1108 1149
 	{
1109 1150
 		header('content-type: image/gif');
1110 1151
 		imagegif($code_image);
1111
-	}
1112
-	else
1152
+	} else
1113 1153
 	{
1114 1154
 		header('content-type: image/png');
1115 1155
 		imagepng($code_image);
@@ -1132,25 +1172,29 @@  discard block
 block discarded – undo
1132 1172
 {
1133 1173
 	global $settings;
1134 1174
 
1135
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
1136
-		return false;
1175
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
1176
+			return false;
1177
+	}
1137 1178
 
1138 1179
 	// Get a list of the available font directories.
1139 1180
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
1140 1181
 	$font_list = array();
1141
-	while ($entry = $font_dir->read())
1142
-		if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1182
+	while ($entry = $font_dir->read()) {
1183
+			if ($entry[0] !== '.' && is_dir($settings['default_theme_dir'] . '/fonts/' . $entry) && file_exists($settings['default_theme_dir'] . '/fonts/' . $entry . '.gdf'))
1143 1184
 			$font_list[] = $entry;
1185
+	}
1144 1186
 
1145
-	if (empty($font_list))
1146
-		return false;
1187
+	if (empty($font_list)) {
1188
+			return false;
1189
+	}
1147 1190
 
1148 1191
 	// Pick a random font.
1149 1192
 	$random_font = $font_list[array_rand($font_list)];
1150 1193
 
1151 1194
 	// Check if the given letter exists.
1152
-	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png'))
1153
-		return false;
1195
+	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) {
1196
+			return false;
1197
+	}
1154 1198
 
1155 1199
 	// Include it!
1156 1200
 	header('content-type: image/png');
Please login to merge, or discard this patch.
Sources/Subs-Membergroups.php 2 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -243,6 +243,7 @@
 block discarded – undo
243 243
  * @param null|array The groups to remove the member(s) from. If null, the specified members are stripped from all their membergroups.
244 244
  * @param bool $permissionCheckDone Whether we've already checked permissions prior to calling this function
245 245
  * @param bool $ignoreProtected Whether to ignore protected groups
246
+ * @param integer $groups
246 247
  * @return bool Whether the operation was successful
247 248
  */
248 249
 function removeMembersFromGroups($members, $groups = null, $permissionCheckDone = false, $ignoreProtected = false)
Please login to merge, or discard this patch.
Braces   +149 added lines, -112 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
  * Delete one of more membergroups.
@@ -31,15 +32,16 @@  discard block
 block discarded – undo
31 32
 	global $smcFunc, $modSettings, $txt;
32 33
 
33 34
 	// Make sure it's an array.
34
-	if (!is_array($groups))
35
-		$groups = array((int) $groups);
36
-	else
35
+	if (!is_array($groups)) {
36
+			$groups = array((int) $groups);
37
+	} else
37 38
 	{
38 39
 		$groups = array_unique($groups);
39 40
 
40 41
 		// Make sure all groups are integer.
41
-		foreach ($groups as $key => $value)
42
-			$groups[$key] = (int) $value;
42
+		foreach ($groups as $key => $value) {
43
+					$groups[$key] = (int) $value;
44
+		}
43 45
 	}
44 46
 
45 47
 	// Some groups are protected (guests, administrators, moderators, newbies).
@@ -56,15 +58,17 @@  discard block
 block discarded – undo
56 58
 				'is_protected' => 1,
57 59
 			)
58 60
 		);
59
-		while ($row = $smcFunc['db_fetch_assoc']($request))
60
-			$protected_groups[] = $row['id_group'];
61
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
62
+					$protected_groups[] = $row['id_group'];
63
+		}
61 64
 		$smcFunc['db_free_result']($request);
62 65
 	}
63 66
 
64 67
 	// Make sure they don't delete protected groups!
65 68
 	$groups = array_diff($groups, array_unique($protected_groups));
66
-	if (empty($groups))
67
-		return 'no_group_found';
69
+	if (empty($groups)) {
70
+			return 'no_group_found';
71
+	}
68 72
 
69 73
 	// Make sure they don't try to delete a group attached to a paid subscription.
70 74
 	$subscriptions = array();
@@ -74,13 +78,14 @@  discard block
 block discarded – undo
74 78
 		ORDER BY name');
75 79
 	while ($row = $smcFunc['db_fetch_assoc']($request))
76 80
 	{
77
-		if (in_array($row['id_group'], $groups))
78
-			$subscriptions[] = $row['name'];
79
-		else
81
+		if (in_array($row['id_group'], $groups)) {
82
+					$subscriptions[] = $row['name'];
83
+		} else
80 84
 		{
81 85
 			$add_groups = explode(',', $row['add_groups']);
82
-			if (count(array_intersect($add_groups, $groups)) != 0)
83
-				$subscriptions[] = $row['name'];
86
+			if (count(array_intersect($add_groups, $groups)) != 0) {
87
+							$subscriptions[] = $row['name'];
88
+			}
84 89
 		}
85 90
 	}
86 91
 	$smcFunc['db_free_result']($request);
@@ -101,8 +106,9 @@  discard block
 block discarded – undo
101 106
 			'group_list' => $groups,
102 107
 		)
103 108
 	);
104
-	while ($row = $smcFunc['db_fetch_assoc']($request))
105
-		logAction('delete_group', array('group' => $row['group_name']), 'admin');
109
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
110
+			logAction('delete_group', array('group' => $row['group_name']), 'admin');
111
+	}
106 112
 	$smcFunc['db_free_result']($request);
107 113
 
108 114
 	call_integration_hook('integrate_delete_membergroups', array($groups));
@@ -187,12 +193,14 @@  discard block
 block discarded – undo
187 193
 		)
188 194
 	);
189 195
 	$updates = array();
190
-	while ($row = $smcFunc['db_fetch_assoc']($request))
191
-		$updates[$row['additional_groups']][] = $row['id_member'];
196
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
197
+			$updates[$row['additional_groups']][] = $row['id_member'];
198
+	}
192 199
 	$smcFunc['db_free_result']($request);
193 200
 
194
-	foreach ($updates as $additional_groups => $memberArray)
195
-		updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups))));
201
+	foreach ($updates as $additional_groups => $memberArray) {
202
+			updateMemberData($memberArray, array('additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups))));
203
+	}
196 204
 
197 205
 	// No boards can provide access to these membergroups anymore.
198 206
 	$request = $smcFunc['db_query']('', '
@@ -204,12 +212,13 @@  discard block
 block discarded – undo
204 212
 		)
205 213
 	);
206 214
 	$updates = array();
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$updates[$row['member_groups']][] = $row['id_board'];
215
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
216
+			$updates[$row['member_groups']][] = $row['id_board'];
217
+	}
209 218
 	$smcFunc['db_free_result']($request);
210 219
 
211
-	foreach ($updates as $member_groups => $boardArray)
212
-		$smcFunc['db_query']('', '
220
+	foreach ($updates as $member_groups => $boardArray) {
221
+			$smcFunc['db_query']('', '
213 222
 			UPDATE {db_prefix}boards
214 223
 			SET member_groups = {string:member_groups}
215 224
 			WHERE id_board IN ({array_int:board_lists})',
@@ -218,6 +227,7 @@  discard block
 block discarded – undo
218 227
 				'member_groups' => implode(',', array_diff(explode(',', $member_groups), $groups)),
219 228
 			)
220 229
 		);
230
+	}
221 231
 
222 232
 	// Recalculate the post groups, as they likely changed.
223 233
 	updateStats('postgroups');
@@ -225,8 +235,9 @@  discard block
 block discarded – undo
225 235
 	// Make a note of the fact that the cache may be wrong.
226 236
 	$settings_update = array('settings_updated' => time());
227 237
 	// Have we deleted the spider group?
228
-	if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups))
229
-		$settings_update['spider_group'] = 0;
238
+	if (isset($modSettings['spider_group']) && in_array($modSettings['spider_group'], $groups)) {
239
+			$settings_update['spider_group'] = 0;
240
+	}
230 241
 
231 242
 	updateSettings($settings_update);
232 243
 
@@ -250,22 +261,24 @@  discard block
 block discarded – undo
250 261
 	global $smcFunc, $modSettings, $sourcedir;
251 262
 
252 263
 	// You're getting nowhere without this permission, unless of course you are the group's moderator.
253
-	if (!$permissionCheckDone)
254
-		isAllowedTo('manage_membergroups');
264
+	if (!$permissionCheckDone) {
265
+			isAllowedTo('manage_membergroups');
266
+	}
255 267
 
256 268
 	// Assume something will happen.
257 269
 	updateSettings(array('settings_updated' => time()));
258 270
 
259 271
 	// Cleaning the input.
260
-	if (!is_array($members))
261
-		$members = array((int) $members);
262
-	else
272
+	if (!is_array($members)) {
273
+			$members = array((int) $members);
274
+	} else
263 275
 	{
264 276
 		$members = array_unique($members);
265 277
 
266 278
 		// Cast the members to integer.
267
-		foreach ($members as $key => $value)
268
-			$members[$key] = (int) $value;
279
+		foreach ($members as $key => $value) {
280
+					$members[$key] = (int) $value;
281
+		}
269 282
 	}
270 283
 
271 284
 	// Before we get started, let's check we won't leave the admin group empty!
@@ -277,14 +290,15 @@  discard block
 block discarded – undo
277 290
 		// Remove any admins if there are too many.
278 291
 		$non_changing_admins = array_diff(array_keys($admins), $members);
279 292
 
280
-		if (empty($non_changing_admins))
281
-			$members = array_diff($members, array_keys($admins));
293
+		if (empty($non_changing_admins)) {
294
+					$members = array_diff($members, array_keys($admins));
295
+		}
282 296
 	}
283 297
 
284 298
 	// Just in case.
285
-	if (empty($members))
286
-		return false;
287
-	elseif ($groups === null)
299
+	if (empty($members)) {
300
+			return false;
301
+	} elseif ($groups === null)
288 302
 	{
289 303
 		// Wanna remove all groups from these members? That's easy.
290 304
 		$smcFunc['db_query']('', '
@@ -306,20 +320,21 @@  discard block
 block discarded – undo
306 320
 		updateStats('postgroups', $members);
307 321
 
308 322
 		// Log what just happened.
309
-		foreach ($members as $member)
310
-			logAction('removed_all_groups', array('member' => $member), 'admin');
323
+		foreach ($members as $member) {
324
+					logAction('removed_all_groups', array('member' => $member), 'admin');
325
+		}
311 326
 
312 327
 		return true;
313
-	}
314
-	elseif (!is_array($groups))
315
-		$groups = array((int) $groups);
316
-	else
328
+	} elseif (!is_array($groups)) {
329
+			$groups = array((int) $groups);
330
+	} else
317 331
 	{
318 332
 		$groups = array_unique($groups);
319 333
 
320 334
 		// Make sure all groups are integer.
321
-		foreach ($groups as $key => $value)
322
-			$groups[$key] = (int) $value;
335
+		foreach ($groups as $key => $value) {
336
+					$groups[$key] = (int) $value;
337
+		}
323 338
 	}
324 339
 
325 340
 	// Fetch a list of groups members cannot be assigned to explicitly, and the group names of the ones we want.
@@ -335,10 +350,11 @@  discard block
 block discarded – undo
335 350
 	$group_names = array();
336 351
 	while ($row = $smcFunc['db_fetch_assoc']($request))
337 352
 	{
338
-		if ($row['min_posts'] != -1)
339
-			$implicitGroups[] = $row['id_group'];
340
-		else
341
-			$group_names[$row['id_group']] = $row['group_name'];
353
+		if ($row['min_posts'] != -1) {
354
+					$implicitGroups[] = $row['id_group'];
355
+		} else {
356
+					$group_names[$row['id_group']] = $row['group_name'];
357
+		}
342 358
 	}
343 359
 	$smcFunc['db_free_result']($request);
344 360
 
@@ -357,8 +373,9 @@  discard block
 block discarded – undo
357 373
 			)
358 374
 		);
359 375
 		$protected_groups = array(1);
360
-		while ($row = $smcFunc['db_fetch_assoc']($request))
361
-			$protected_groups[] = $row['id_group'];
376
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
377
+					$protected_groups[] = $row['id_group'];
378
+		}
362 379
 		$smcFunc['db_free_result']($request);
363 380
 
364 381
 		// If you're not an admin yourself, you can't touch protected groups!
@@ -366,8 +383,9 @@  discard block
 block discarded – undo
366 383
 	}
367 384
 
368 385
 	// Only continue if there are still groups and members left.
369
-	if (empty($groups) || empty($members))
370
-		return false;
386
+	if (empty($groups) || empty($members)) {
387
+			return false;
388
+	}
371 389
 
372 390
 	// First, reset those who have this as their primary group - this is the easy one.
373 391
 	$log_inserts = array();
@@ -381,8 +399,9 @@  discard block
 block discarded – undo
381 399
 			'member_list' => $members,
382 400
 		)
383 401
 	);
384
-	while ($row = $smcFunc['db_fetch_assoc']($request))
385
-		$log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']);
402
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
403
+			$log_inserts[] = array('group' => $group_names[$row['id_group']], 'member' => $row['id_member']);
404
+	}
386 405
 	$smcFunc['db_free_result']($request);
387 406
 
388 407
 	$smcFunc['db_query']('', '
@@ -414,16 +433,17 @@  discard block
 block discarded – undo
414 433
 	while ($row = $smcFunc['db_fetch_assoc']($request))
415 434
 	{
416 435
 		// What log entries must we make for this one, eh?
417
-		foreach (explode(',', $row['additional_groups']) as $group)
418
-			if (in_array($group, $groups))
436
+		foreach (explode(',', $row['additional_groups']) as $group) {
437
+					if (in_array($group, $groups))
419 438
 				$log_inserts[] = array('group' => $group_names[$group], 'member' => $row['id_member']);
439
+		}
420 440
 
421 441
 		$updates[$row['additional_groups']][] = $row['id_member'];
422 442
 	}
423 443
 	$smcFunc['db_free_result']($request);
424 444
 
425
-	foreach ($updates as $additional_groups => $memberArray)
426
-		$smcFunc['db_query']('', '
445
+	foreach ($updates as $additional_groups => $memberArray) {
446
+			$smcFunc['db_query']('', '
427 447
 			UPDATE {db_prefix}members
428 448
 			SET additional_groups = {string:additional_groups}
429 449
 			WHERE id_member IN ({array_int:member_list})',
@@ -432,6 +452,7 @@  discard block
 block discarded – undo
432 452
 				'additional_groups' => implode(',', array_diff(explode(',', $additional_groups), $groups)),
433 453
 			)
434 454
 		);
455
+	}
435 456
 
436 457
 	// Their post groups may have changed now...
437 458
 	updateStats('postgroups', $members);
@@ -440,8 +461,9 @@  discard block
 block discarded – undo
440 461
 	if (!empty($log_inserts) && !empty($modSettings['modlog_enabled']))
441 462
 	{
442 463
 		require_once($sourcedir . '/Logging.php');
443
-		foreach ($log_inserts as $extra)
444
-			logAction('removed_from_group', $extra, 'admin');
464
+		foreach ($log_inserts as $extra) {
465
+					logAction('removed_from_group', $extra, 'admin');
466
+		}
445 467
 	}
446 468
 
447 469
 	// Mission successful.
@@ -477,21 +499,23 @@  discard block
 block discarded – undo
477 499
 	global $smcFunc, $sourcedir;
478 500
 
479 501
 	// Show your licence, but only if it hasn't been done yet.
480
-	if (!$permissionCheckDone)
481
-		isAllowedTo('manage_membergroups');
502
+	if (!$permissionCheckDone) {
503
+			isAllowedTo('manage_membergroups');
504
+	}
482 505
 
483 506
 	// Make sure we don't keep old stuff cached.
484 507
 	updateSettings(array('settings_updated' => time()));
485 508
 
486
-	if (!is_array($members))
487
-		$members = array((int) $members);
488
-	else
509
+	if (!is_array($members)) {
510
+			$members = array((int) $members);
511
+	} else
489 512
 	{
490 513
 		$members = array_unique($members);
491 514
 
492 515
 		// Make sure all members are integer.
493
-		foreach ($members as $key => $value)
494
-			$members[$key] = (int) $value;
516
+		foreach ($members as $key => $value) {
517
+					$members[$key] = (int) $value;
518
+		}
495 519
 	}
496 520
 	$group = (int) $group;
497 521
 
@@ -508,20 +532,23 @@  discard block
 block discarded – undo
508 532
 	$group_names = array();
509 533
 	while ($row = $smcFunc['db_fetch_assoc']($request))
510 534
 	{
511
-		if ($row['min_posts'] != -1)
512
-			$implicitGroups[] = $row['id_group'];
513
-		else
514
-			$group_names[$row['id_group']] = $row['group_name'];
535
+		if ($row['min_posts'] != -1) {
536
+					$implicitGroups[] = $row['id_group'];
537
+		} else {
538
+					$group_names[$row['id_group']] = $row['group_name'];
539
+		}
515 540
 	}
516 541
 	$smcFunc['db_free_result']($request);
517 542
 
518 543
 	// Sorry, you can't join an implicit group.
519
-	if (in_array($group, $implicitGroups) || empty($members))
520
-		return false;
544
+	if (in_array($group, $implicitGroups) || empty($members)) {
545
+			return false;
546
+	}
521 547
 
522 548
 	// Only admins can add admins...
523
-	if (!allowedTo('admin_forum') && $group == 1)
524
-		return false;
549
+	if (!allowedTo('admin_forum') && $group == 1) {
550
+			return false;
551
+	}
525 552
 	// ... and assign protected groups!
526 553
 	elseif (!allowedTo('admin_forum') && !$ignoreProtected)
527 554
 	{
@@ -539,13 +566,14 @@  discard block
 block discarded – undo
539 566
 		$smcFunc['db_free_result']($request);
540 567
 
541 568
 		// Is it protected?
542
-		if ($is_protected == 1)
543
-			return false;
569
+		if ($is_protected == 1) {
570
+					return false;
571
+		}
544 572
 	}
545 573
 
546 574
 	// Do the actual updates.
547
-	if ($type == 'only_additional')
548
-		$smcFunc['db_query']('', '
575
+	if ($type == 'only_additional') {
576
+			$smcFunc['db_query']('', '
549 577
 			UPDATE {db_prefix}members
550 578
 			SET additional_groups = CASE WHEN additional_groups = {string:blank_string} THEN {string:id_group_string} ELSE CONCAT(additional_groups, {string:id_group_string_extend}) END
551 579
 			WHERE id_member IN ({array_int:member_list})
@@ -559,8 +587,8 @@  discard block
 block discarded – undo
559 587
 				'blank_string' => '',
560 588
 			)
561 589
 		);
562
-	elseif ($type == 'only_primary' || $type == 'force_primary')
563
-		$smcFunc['db_query']('', '
590
+	} elseif ($type == 'only_primary' || $type == 'force_primary') {
591
+			$smcFunc['db_query']('', '
564 592
 			UPDATE {db_prefix}members
565 593
 			SET id_group = {int:id_group}
566 594
 			WHERE id_member IN ({array_int:member_list})' . ($type == 'force_primary' ? '' : '
@@ -572,8 +600,8 @@  discard block
 block discarded – undo
572 600
 				'regular_group' => 0,
573 601
 			)
574 602
 		);
575
-	elseif ($type == 'auto')
576
-		$smcFunc['db_query']('', '
603
+	} elseif ($type == 'auto') {
604
+			$smcFunc['db_query']('', '
577 605
 			UPDATE {db_prefix}members
578 606
 			SET
579 607
 				id_group = CASE WHEN id_group = {int:regular_group} THEN {int:id_group} ELSE id_group END,
@@ -592,9 +620,11 @@  discard block
 block discarded – undo
592 620
 				'id_group_string_extend' => ',' . $group,
593 621
 			)
594 622
 		);
623
+	}
595 624
 	// Ack!!?  What happened?
596
-	else
597
-		trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING);
625
+	else {
626
+			trigger_error('addMembersToGroup(): Unknown type \'' . $type . '\'', E_USER_WARNING);
627
+	}
598 628
 
599 629
 	call_integration_hook('integrate_add_members_to_group', array($members, $group, &$group_names));
600 630
 
@@ -603,8 +633,9 @@  discard block
 block discarded – undo
603 633
 
604 634
 	// Log the data.
605 635
 	require_once($sourcedir . '/Logging.php');
606
-	foreach ($members as $member)
607
-		logAction('added_to_group', array('group' => $group_names[$group], 'member_affected' => $member), 'admin');
636
+	foreach ($members as $member) {
637
+			logAction('added_to_group', array('group' => $group_names[$group], 'member_affected' => $member), 'admin');
638
+	}
608 639
 
609 640
 	return true;
610 641
 }
@@ -632,8 +663,9 @@  discard block
 block discarded – undo
632 663
 		)
633 664
 	);
634 665
 	$members = array();
635
-	while ($row = $smcFunc['db_fetch_assoc']($request))
636
-		$members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
666
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
667
+			$members[$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
668
+	}
637 669
 	$smcFunc['db_free_result']($request);
638 670
 
639 671
 	// If there are more than $limit members, add a 'more' link.
@@ -641,10 +673,10 @@  discard block
 block discarded – undo
641 673
 	{
642 674
 		array_pop($members);
643 675
 		return true;
676
+	} else {
677
+			return false;
678
+	}
644 679
 	}
645
-	else
646
-		return false;
647
-}
648 680
 
649 681
 /**
650 682
  * Retrieve a list of (visible) membergroups used by the cache.
@@ -669,8 +701,9 @@  discard block
 block discarded – undo
669 701
 		)
670 702
 	);
671 703
 	$groupCache = array();
672
-	while ($row = $smcFunc['db_fetch_assoc']($request))
673
-		$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
704
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
705
+			$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
706
+	}
674 707
 	$smcFunc['db_free_result']($request);
675 708
 
676 709
 	return array(
@@ -716,8 +749,9 @@  discard block
 block discarded – undo
716 749
 	while ($row = $smcFunc['db_fetch_assoc']($request))
717 750
 	{
718 751
 		// We only list the groups they can see.
719
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
720
-			continue;
752
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
753
+					continue;
754
+		}
721 755
 
722 756
 		$row['icons'] = explode('#', $row['icons']);
723 757
 
@@ -752,12 +786,11 @@  discard block
 block discarded – undo
752 786
 					'group_list' => $group_ids,
753 787
 				)
754 788
 			);
755
-			while ($row = $smcFunc['db_fetch_assoc']($query))
756
-				$groups[$row['id_group']]['num_members'] += $row['num_members'];
789
+			while ($row = $smcFunc['db_fetch_assoc']($query)) {
790
+							$groups[$row['id_group']]['num_members'] += $row['num_members'];
791
+			}
757 792
 			$smcFunc['db_free_result']($query);
758
-		}
759
-
760
-		else
793
+		} else
761 794
 		{
762 795
 			$query = $smcFunc['db_query']('', '
763 796
 				SELECT id_group, COUNT(*) AS num_members
@@ -768,8 +801,9 @@  discard block
 block discarded – undo
768 801
 					'group_list' => $group_ids,
769 802
 				)
770 803
 			);
771
-			while ($row = $smcFunc['db_fetch_assoc']($query))
772
-				$groups[$row['id_group']]['num_members'] += $row['num_members'];
804
+			while ($row = $smcFunc['db_fetch_assoc']($query)) {
805
+							$groups[$row['id_group']]['num_members'] += $row['num_members'];
806
+			}
773 807
 			$smcFunc['db_free_result']($query);
774 808
 
775 809
 			// Only do additional groups if we can moderate...
@@ -788,8 +822,9 @@  discard block
 block discarded – undo
788 822
 						'blank_string' => '',
789 823
 					)
790 824
 				);
791
-				while ($row = $smcFunc['db_fetch_assoc']($query))
792
-					$groups[$row['id_group']]['num_members'] += $row['num_members'];
825
+				while ($row = $smcFunc['db_fetch_assoc']($query)) {
826
+									$groups[$row['id_group']]['num_members'] += $row['num_members'];
827
+				}
793 828
 				$smcFunc['db_free_result']($query);
794 829
 			}
795 830
 		}
@@ -803,8 +838,9 @@  discard block
 block discarded – undo
803 838
 				'group_list' => $group_ids,
804 839
 			)
805 840
 		);
806
-		while ($row = $smcFunc['db_fetch_assoc']($query))
807
-			$groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
841
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
842
+					$groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
843
+		}
808 844
 		$smcFunc['db_free_result']($query);
809 845
 	}
810 846
 
@@ -813,8 +849,9 @@  discard block
 block discarded – undo
813 849
 	{
814 850
 		$sort_ascending = strpos($sort, 'DESC') === false;
815 851
 
816
-		foreach ($groups as $group)
817
-			$sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1;
852
+		foreach ($groups as $group) {
853
+					$sort_array[] = $group['id_group'] != 3 ? (int) $group['num_members'] : -1;
854
+		}
818 855
 
819 856
 		array_multisort($sort_array, $sort_ascending ? SORT_ASC : SORT_DESC, SORT_REGULAR, $groups);
820 857
 	}
Please login to merge, or discard this patch.
Sources/Subs-Menu.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -286,7 +286,7 @@
 block discarded – undo
286 286
 /**
287 287
  * Delete a menu.
288 288
  * @param string $menu_id The ID of the menu to destroy or 'last' for the most recent one
289
- * @return bool|void False if the menu doesn't exist, nothing otherwise
289
+ * @return false|null False if the menu doesn't exist, nothing otherwise
290 290
  */
291 291
 function destroyMenu($menu_id = 'last')
292 292
 {
Please login to merge, or discard this patch.
Braces   +75 added lines, -57 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
  * Create a menu.
@@ -64,22 +65,26 @@  discard block
 block discarded – undo
64 65
 	$menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action'];
65 66
 
66 67
 	// Allow extend *any* menu with a single hook
67
-	if (!empty($menu_context['current_action']))
68
-		call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
68
+	if (!empty($menu_context['current_action'])) {
69
+			call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
70
+	}
69 71
 
70 72
 	// What is the current area selected?
71
-	if (isset($menuOptions['current_area']) || isset($_GET['area']))
72
-		$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
73
+	if (isset($menuOptions['current_area']) || isset($_GET['area'])) {
74
+			$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
75
+	}
73 76
 
74 77
 	// Build a list of additional parameters that should go in the URL.
75 78
 	$menu_context['extra_parameters'] = '';
76
-	if (!empty($menuOptions['extra_url_parameters']))
77
-		foreach ($menuOptions['extra_url_parameters'] as $key => $value)
79
+	if (!empty($menuOptions['extra_url_parameters'])) {
80
+			foreach ($menuOptions['extra_url_parameters'] as $key => $value)
78 81
 			$menu_context['extra_parameters'] .= ';' . $key . '=' . $value;
82
+	}
79 83
 
80 84
 	// Only include the session ID in the URL if it's strictly necessary.
81
-	if (empty($menuOptions['disable_url_session_check']))
82
-		$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
85
+	if (empty($menuOptions['disable_url_session_check'])) {
86
+			$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
87
+	}
83 88
 
84 89
 	$include_data = array();
85 90
 
@@ -87,8 +92,9 @@  discard block
 block discarded – undo
87 92
 	foreach ($menuData as $section_id => $section)
88 93
 	{
89 94
 		// Is this enabled - or has as permission check - which fails?
90
-		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission'])))
91
-			continue;
95
+		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) {
96
+					continue;
97
+		}
92 98
 
93 99
 		// Now we cycle through the sections to pick the right area.
94 100
 		foreach ($section['areas'] as $area_id => $area)
@@ -110,59 +116,57 @@  discard block
 block discarded – undo
110 116
 					if (empty($area['hidden']))
111 117
 					{
112 118
 						// First time this section?
113
-						if (!isset($menu_context['sections'][$section_id]))
114
-							$menu_context['sections'][$section_id]['title'] = $section['title'];
119
+						if (!isset($menu_context['sections'][$section_id])) {
120
+													$menu_context['sections'][$section_id]['title'] = $section['title'];
121
+						}
115 122
 
116 123
 						$menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]);
117 124
 						// We'll need the ID as well...
118 125
 						$menu_context['sections'][$section_id]['id'] = $section_id;
119 126
 						// Does it have a custom URL?
120
-						if (isset($area['custom_url']))
121
-							$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
127
+						if (isset($area['custom_url'])) {
128
+													$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
129
+						}
122 130
 
123 131
 						// Does this area have its own icon?
124 132
 						if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa')
125 133
 						{
126 134
 							$menu_context['sections'][$section_id]['areas'][$area_id] = $smcFunc['json_decode'](base64_decode('eyJsYWJlbCI6Ik9vbXBhIExvb21wYSIsInVybCI6Imh0dHBzOlwvXC9lbi53aWtpcGVkaWEub3JnXC93aWtpXC9Pb21wYV9Mb29tcGFzPyIsImljb24iOiI8aW1nIHNyYz1cImh0dHBzOlwvXC93d3cuc2ltcGxlbWFjaGluZXMub3JnXC9pbWFnZXNcL29vbXBhLmdpZlwiIGFsdD1cIkknbSBhbiBPb21wYSBMb29tcGFcIiBcLz4ifQ=='), true);
127
-						}
128
-						elseif (isset($area['icon']))
135
+						} elseif (isset($area['icon']))
129 136
 						{
130 137
 							if (file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon']))
131 138
 							{
132 139
 								$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">';
133
-							}
134
-							elseif (file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon']))
140
+							} elseif (file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon']))
135 141
 							{
136 142
 								$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">';
143
+							} else {
144
+															$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
137 145
 							}
138
-							else
139
-								$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
146
+						} else {
147
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
140 148
 						}
141
-						else
142
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
143 149
 
144 150
 						if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon']))
145 151
 						{
146 152
 							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class'];
147
-						}
148
-						elseif (isset($area['icon']))
153
+						} elseif (isset($area['icon']))
149 154
 						{
150 155
 							if (substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif')
151 156
 							{
152 157
 								if (file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon']))
153 158
 								{
154 159
 									$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon'];
155
-								}
156
-								elseif (file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
160
+								} elseif (file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
157 161
 								{
158 162
 									$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon'];
159 163
 								}
160 164
 							}
161 165
 
162 166
 							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']);
167
+						} else {
168
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
163 169
 						}
164
-						else
165
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
166 170
 
167 171
 						// This is a shortcut for Font-Icon users so they don't have to re-do whole CSS.
168 172
 						$menu_context['sections'][$section_id]['areas'][$area_id]['plain_class'] = !empty($area['icon']) ? $area['icon'] : '';
@@ -179,35 +183,41 @@  discard block
 block discarded – undo
179 183
 							{
180 184
 								if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled'])))
181 185
 								{
182
-									if ($first_sa == null)
183
-										$first_sa = $sa;
186
+									if ($first_sa == null) {
187
+																			$first_sa = $sa;
188
+									}
184 189
 
185 190
 									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]);
186 191
 									// Custom URL?
187
-									if (isset($sub['url']))
188
-										$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
192
+									if (isset($sub['url'])) {
193
+																			$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
194
+									}
189 195
 
190 196
 									// A bit complicated - but is this set?
191 197
 									if ($menu_context['current_area'] == $area_id)
192 198
 									{
193 199
 										// Save which is the first...
194
-										if (empty($first_sa))
195
-											$first_sa = $sa;
200
+										if (empty($first_sa)) {
201
+																					$first_sa = $sa;
202
+										}
196 203
 
197 204
 										// Is this the current subsection?
198
-										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa)
199
-											$menu_context['current_subsection'] = $sa;
205
+										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) {
206
+																					$menu_context['current_subsection'] = $sa;
207
+										}
200 208
 										// Otherwise is it the default?
201
-										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2]))
202
-											$menu_context['current_subsection'] = $sa;
209
+										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) {
210
+																					$menu_context['current_subsection'] = $sa;
211
+										}
203 212
 									}
204 213
 
205 214
 									// Let's assume this is the last, for now.
206 215
 									$last_sa = $sa;
207 216
 								}
208 217
 								// Mark it as disabled...
209
-								else
210
-									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
218
+								else {
219
+																	$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
220
+								}
211 221
 							}
212 222
 
213 223
 							// Set which one is first, last and selected in the group.
@@ -216,8 +226,9 @@  discard block
 block discarded – undo
216 226
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true;
217 227
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true;
218 228
 
219
-								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection']))
220
-									$menu_context['current_subsection'] = $first_sa;
229
+								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) {
230
+																	$menu_context['current_subsection'] = $first_sa;
231
+								}
221 232
 							}
222 233
 						}
223 234
 					}
@@ -251,23 +262,26 @@  discard block
 block discarded – undo
251 262
 	$menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action'];
252 263
 
253 264
 	// If we didn't find the area we were looking for go to a default one.
254
-	if (isset($backup_area) && empty($found_section))
255
-		$menu_context['current_area'] = $backup_area;
265
+	if (isset($backup_area) && empty($found_section)) {
266
+			$menu_context['current_area'] = $backup_area;
267
+	}
256 268
 
257 269
 	// If there are sections quickly goes through all the sections to check if the base menu has an url
258 270
 	if (!empty($menu_context['current_section']))
259 271
 	{
260 272
 		$menu_context['sections'][$menu_context['current_section']]['selected'] = true;
261 273
 		$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true;
262
-		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]))
263
-			$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
274
+		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) {
275
+					$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
276
+		}
264 277
 
265
-		foreach ($menu_context['sections'] as $section_id => $section)
266
-			foreach ($section['areas'] as $area_id => $area)
278
+		foreach ($menu_context['sections'] as $section_id => $section) {
279
+					foreach ($section['areas'] as $area_id => $area)
267 280
 			{
268 281
 				if (!isset($menu_context['sections'][$section_id]['url']))
269 282
 				{
270 283
 					$menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id;
284
+		}
271 285
 					break;
272 286
 				}
273 287
 			}
@@ -278,8 +292,9 @@  discard block
 block discarded – undo
278 292
 	{
279 293
 		// Never happened!
280 294
 		$context['max_menu_id']--;
281
-		if ($context['max_menu_id'] == 0)
282
-			unset($context['max_menu_id']);
295
+		if ($context['max_menu_id'] == 0) {
296
+					unset($context['max_menu_id']);
297
+		}
283 298
 
284 299
 		return false;
285 300
 	}
@@ -290,8 +305,9 @@  discard block
 block discarded – undo
290 305
 	$context['template_layers'][] = $menu_context['layer_name'];
291 306
 
292 307
 	// Check we had something - for sanity sake.
293
-	if (empty($include_data))
294
-		return false;
308
+	if (empty($include_data)) {
309
+			return false;
310
+	}
295 311
 
296 312
 	// Finally - return information on the selected item.
297 313
 	$include_data += array(
@@ -314,12 +330,14 @@  discard block
 block discarded – undo
314 330
 	global $context;
315 331
 
316 332
 	$menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id;
317
-	if (!isset($context[$menu_name]))
318
-		return false;
333
+	if (!isset($context[$menu_name])) {
334
+			return false;
335
+	}
319 336
 
320 337
 	$layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']);
321
-	if ($layer_index !== false)
322
-		unset($context['template_layers'][$layer_index]);
338
+	if ($layer_index !== false) {
339
+			unset($context['template_layers'][$layer_index]);
340
+	}
323 341
 
324 342
 	unset($context[$menu_name]);
325 343
 }
Please login to merge, or discard this patch.
Sources/Subs-Post.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
  * @param resource $socket Socket to send on
1452 1452
  * @param string $code The expected response code
1453 1453
  * @param string $response The response from the SMTP server
1454
- * @return bool Whether it responded as such.
1454
+ * @return string|boolean Whether it responded as such.
1455 1455
  */
1456 1456
 function server_parse($message, $socket, $code, &$response = null)
1457 1457
 {
@@ -2265,7 +2265,7 @@  discard block
 block discarded – undo
2265 2265
  * @param array $msgs Array of message ids
2266 2266
  * @param bool $approve Whether to approve the posts (if false, posts are unapproved)
2267 2267
  * @param bool $notify Whether to notify users
2268
- * @return bool Whether the operation was successful
2268
+ * @return null|boolean Whether the operation was successful
2269 2269
  */
2270 2270
 function approvePosts($msgs, $approve = true, $notify = true)
2271 2271
 {
@@ -2518,7 +2518,7 @@  discard block
 block discarded – undo
2518 2518
  *
2519 2519
  * @param array $topics Array of topic ids
2520 2520
  * @param bool $approve Whether to approve the topics. If false, unapproves them instead
2521
- * @return bool Whether the operation was successful
2521
+ * @return null|boolean Whether the operation was successful
2522 2522
  */
2523 2523
 function approveTopics($topics, $approve = true)
2524 2524
 {
@@ -2908,7 +2908,7 @@  discard block
 block discarded – undo
2908 2908
  *
2909 2909
  * @param resource $dict An enchant or pspell dictionary resource set up by {@link spell_init()}
2910 2910
  * @param string $word A word to check the spelling of
2911
- * @return bool Whether or not the specified word is spelled properly
2911
+ * @return boolean|null Whether or not the specified word is spelled properly
2912 2912
  */
2913 2913
 function spell_check($dict, $word)
2914 2914
 {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -704,7 +704,7 @@
 block discarded – undo
704 704
 					$mail_result = false;
705 705
 				}
706 706
 			}
707
-			catch(ErrorException $e)
707
+			catch (ErrorException $e)
708 708
 			{
709 709
 				log_error($e->getMessage(), 'general', $e->getFile(), $e->getLine());
710 710
 				log_error(sprintf($txt['mail_send_unable'], $to));
Please login to merge, or discard this patch.
Braces   +526 added lines, -393 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 	global $user_info, $modSettings, $context, $sourcedir;
32 33
 
33 34
 	// This line makes all languages *theoretically* work even with the wrong charset ;).
34
-	if (empty($context['utf8']))
35
-		$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
35
+	if (empty($context['utf8'])) {
36
+			$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
37
+	}
36 38
 
37 39
 	// Clean up after nobbc ;).
38 40
 	$message = preg_replace_callback('~\[nobbc\](.+?)\[/nobbc\]~is', function($a)
@@ -47,17 +49,19 @@  discard block
 block discarded – undo
47 49
 	$message = preg_replace('~\.{100,}~', '...', $message);
48 50
 
49 51
 	// Trim off trailing quotes - these often happen by accident.
50
-	while (substr($message, -7) == '[quote]')
51
-		$message = substr($message, 0, -7);
52
-	while (substr($message, 0, 8) == '[/quote]')
53
-		$message = substr($message, 8);
52
+	while (substr($message, -7) == '[quote]') {
53
+			$message = substr($message, 0, -7);
54
+	}
55
+	while (substr($message, 0, 8) == '[/quote]') {
56
+			$message = substr($message, 8);
57
+	}
54 58
 
55 59
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
56 60
 	$in_tag = false;
57 61
 	$had_tag = false;
58 62
 	$codeopen = 0;
59
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
60
-		foreach ($matches[0] as $index => $dummy)
63
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
64
+			foreach ($matches[0] as $index => $dummy)
61 65
 		{
62 66
 			// Closing?
63 67
 			if (!empty($matches[2][$index]))
@@ -65,6 +69,7 @@  discard block
 block discarded – undo
65 69
 				// If it's closing and we're not in a tag we need to open it...
66 70
 				if (!$in_tag)
67 71
 					$codeopen = true;
72
+	}
68 73
 				// Either way we ain't in one any more.
69 74
 				$in_tag = false;
70 75
 			}
@@ -73,17 +78,20 @@  discard block
 block discarded – undo
73 78
 			{
74 79
 				$had_tag = true;
75 80
 				// If we're in a tag don't do nought!
76
-				if (!$in_tag)
77
-					$in_tag = true;
81
+				if (!$in_tag) {
82
+									$in_tag = true;
83
+				}
78 84
 			}
79 85
 		}
80 86
 
81 87
 	// If we have an open tag, close it.
82
-	if ($in_tag)
83
-		$message .= '[/code]';
88
+	if ($in_tag) {
89
+			$message .= '[/code]';
90
+	}
84 91
 	// Open any ones that need to be open, only if we've never had a tag.
85
-	if ($codeopen && !$had_tag)
86
-		$message = '[code]' . $message;
92
+	if ($codeopen && !$had_tag) {
93
+			$message = '[code]' . $message;
94
+	}
87 95
 
88 96
 	// Replace code BBC with placeholders. We'll restore them at the end.
89 97
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -108,23 +116,26 @@  discard block
 block discarded – undo
108 116
 	fixTags($message);
109 117
 
110 118
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
111
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
112
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
113
-	else
114
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
119
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
120
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
121
+	} else {
122
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
123
+	}
115 124
 
116 125
 	if (!$previewing && strpos($message, '[html]') !== false)
117 126
 	{
118
-		if (allowedTo('admin_forum'))
119
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
127
+		if (allowedTo('admin_forum')) {
128
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
120 129
 				return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => '&#13;', '  ' => ' &#32;', '[' => '&#91;', ']' => '&#93;')) . '[/html]';
130
+		}
121 131
 			}, $message);
122 132
 
123 133
 		// We should edit them out, or else if an admin edits the message they will get shown...
124 134
 		else
125 135
 		{
126
-			while (strpos($message, '[html]') !== false)
127
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
136
+			while (strpos($message, '[html]') !== false) {
137
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
138
+			}
128 139
 		}
129 140
 	}
130 141
 
@@ -146,10 +157,12 @@  discard block
 block discarded – undo
146 157
 
147 158
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
148 159
 	$list_close = substr_count($message, '[/list]');
149
-	if ($list_close - $list_open > 0)
150
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
151
-	if ($list_open - $list_close > 0)
152
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
160
+	if ($list_close - $list_open > 0) {
161
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
162
+	}
163
+	if ($list_open - $list_close > 0) {
164
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
165
+	}
153 166
 
154 167
 	$mistake_fixes = array(
155 168
 		// Find [table]s not followed by [tr].
@@ -198,8 +211,9 @@  discard block
 block discarded – undo
198 211
 	);
199 212
 
200 213
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
201
-	for ($j = 0; $j < 3; $j++)
202
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
214
+	for ($j = 0; $j < 3; $j++) {
215
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
216
+	}
203 217
 
204 218
 	// Remove empty bbc from the sections outside the code tags
205 219
 	$allowedEmpty = array(
@@ -210,24 +224,28 @@  discard block
 block discarded – undo
210 224
 	require_once($sourcedir . '/Subs.php');
211 225
 
212 226
 	$alltags = array();
213
-	foreach (($codes = parse_bbc(false)) as $code)
214
-		if (!in_array($code['tag'], $allowedEmpty))
227
+	foreach (($codes = parse_bbc(false)) as $code) {
228
+			if (!in_array($code['tag'], $allowedEmpty))
215 229
 			$alltags[] = $code['tag'];
230
+	}
216 231
 
217 232
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
218 233
 
219
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
220
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
235
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
236
+	}
221 237
 
222 238
 	// Restore code blocks
223
-	if (!empty($code_tags))
224
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	if (!empty($code_tags)) {
240
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
241
+	}
225 242
 
226 243
 	// Restore white space entities
227
-	if (!$previewing)
228
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
229
-	else
230
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	if (!$previewing) {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	} else {
247
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
248
+	}
231 249
 
232 250
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
233 251
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -270,8 +288,9 @@  discard block
 block discarded – undo
270 288
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
271 289
 	}, $message);
272 290
 
273
-	if (!empty($code_tags))
274
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	if (!empty($code_tags)) {
292
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
293
+	}
275 294
 
276 295
 	// Change breaks back to \n's and &nsbp; back to spaces.
277 296
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -352,8 +371,9 @@  discard block
 block discarded – undo
352 371
 	);
353 372
 
354 373
 	// Fix each type of tag.
355
-	foreach ($fixArray as $param)
356
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	foreach ($fixArray as $param) {
375
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
376
+	}
357 377
 
358 378
 	// Now fix possible security problems with images loading links automatically...
359 379
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -378,10 +398,11 @@  discard block
 block discarded – undo
378 398
 {
379 399
 	global $boardurl, $scripturl;
380 400
 
381
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
382
-		$domain_url = $match[1];
383
-	else
384
-		$domain_url = $boardurl . '/';
401
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
402
+			$domain_url = $match[1];
403
+	} else {
404
+			$domain_url = $boardurl . '/';
405
+	}
385 406
 
386 407
 	$replaces = array();
387 408
 
@@ -389,11 +410,11 @@  discard block
 block discarded – undo
389 410
 	{
390 411
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
391 412
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
413
+	} elseif ($hasEqualSign) {
414
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
415
+	} else {
416
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
392 417
 	}
393
-	elseif ($hasEqualSign)
394
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
395
-	else
396
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
397 418
 
398 419
 	foreach ($matches[0] as $k => $dummy)
399 420
 	{
@@ -406,49 +427,53 @@  discard block
 block discarded – undo
406 427
 		foreach ($protocols as $protocol)
407 428
 		{
408 429
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
409
-			if ($found)
410
-				break;
430
+			if ($found) {
431
+							break;
432
+			}
411 433
 		}
412 434
 
413 435
 		if (!$found && $protocols[0] == 'http')
414 436
 		{
415
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
416
-				$replace = $domain_url . $replace;
417
-			elseif (substr($replace, 0, 1) == '?')
418
-				$replace = $scripturl . $replace;
419
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
437
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
438
+							$replace = $domain_url . $replace;
439
+			} elseif (substr($replace, 0, 1) == '?') {
440
+							$replace = $scripturl . $replace;
441
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
420 442
 			{
421 443
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
422 444
 				$this_tag = 'iurl';
423 445
 				$this_close = 'iurl';
446
+			} elseif (substr($replace, 0, 2) != '//') {
447
+							$replace = $protocols[0] . '://' . $replace;
424 448
 			}
425
-			elseif (substr($replace, 0, 2) != '//')
426
-				$replace = $protocols[0] . '://' . $replace;
427
-		}
428
-		elseif (!$found && $protocols[0] == 'ftp')
429
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
430
-		elseif (!$found)
431
-			$replace = $protocols[0] . '://' . $replace;
432
-
433
-		if ($hasEqualSign && $embeddedUrl)
434
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
435
-		elseif ($hasEqualSign)
436
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
437
-		elseif ($embeddedUrl)
438
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
439
-		else
440
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
449
+		} elseif (!$found && $protocols[0] == 'ftp') {
450
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
451
+		} elseif (!$found) {
452
+					$replace = $protocols[0] . '://' . $replace;
453
+		}
454
+
455
+		if ($hasEqualSign && $embeddedUrl) {
456
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
457
+		} elseif ($hasEqualSign) {
458
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
459
+		} elseif ($embeddedUrl) {
460
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
461
+		} else {
462
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
463
+		}
441 464
 	}
442 465
 
443 466
 	foreach ($replaces as $k => $v)
444 467
 	{
445
-		if ($k == $v)
446
-			unset($replaces[$k]);
468
+		if ($k == $v) {
469
+					unset($replaces[$k]);
470
+		}
447 471
 	}
448 472
 
449
-	if (!empty($replaces))
450
-		$message = strtr($message, $replaces);
451
-}
473
+	if (!empty($replaces)) {
474
+			$message = strtr($message, $replaces);
475
+	}
476
+	}
452 477
 
453 478
 /**
454 479
  * This function sends an email to the specified recipient(s).
@@ -492,8 +517,9 @@  discard block
 block discarded – undo
492 517
 	}
493 518
 
494 519
 	// Nothing left? Nothing else to do
495
-	if (empty($to_array))
496
-		return true;
520
+	if (empty($to_array)) {
521
+			return true;
522
+	}
497 523
 
498 524
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
499 525
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -510,15 +536,17 @@  discard block
 block discarded – undo
510 536
 		}
511 537
 
512 538
 		// Call this function recursively for the hotmail addresses.
513
-		if (!empty($hotmail_to))
514
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
539
+		if (!empty($hotmail_to)) {
540
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
541
+		}
515 542
 
516 543
 		// The remaining addresses no longer need the fix.
517 544
 		$hotmail_fix = false;
518 545
 
519 546
 		// No other addresses left? Return instantly.
520
-		if (empty($to_array))
521
-			return $mail_result;
547
+		if (empty($to_array)) {
548
+					return $mail_result;
549
+		}
522 550
 	}
523 551
 
524 552
 	// Get rid of entities.
@@ -543,13 +571,15 @@  discard block
 block discarded – undo
543 571
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
544 572
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
545 573
 
546
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
547
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
574
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
575
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
576
+	}
548 577
 	$headers .= 'X-Mailer: SMF' . $line_break;
549 578
 
550 579
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
551
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
552
-		return false;
580
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
581
+			return false;
582
+	}
553 583
 
554 584
 	// Save the original message...
555 585
 	$orig_message = $message;
@@ -598,17 +628,19 @@  discard block
 block discarded – undo
598 628
 	}
599 629
 
600 630
 	// Are we using the mail queue, if so this is where we butt in...
601
-	if ($priority != 0)
602
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
631
+	if ($priority != 0) {
632
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
633
+	}
603 634
 
604 635
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
605 636
 	elseif (!empty($modSettings['mail_limit']))
606 637
 	{
607 638
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
608
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
609
-			$new_queue_stat = time() . '|' . 1;
610
-		else
611
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
639
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
640
+					$new_queue_stat = time() . '|' . 1;
641
+		} else {
642
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
643
+		}
612 644
 
613 645
 		updateSettings(array('mail_recent' => $new_queue_stat));
614 646
 	}
@@ -642,8 +674,7 @@  discard block
 block discarded – undo
642 674
 					log_error(sprintf($txt['mail_send_unable'], $to));
643 675
 					$mail_result = false;
644 676
 				}
645
-			}
646
-			catch(ErrorException $e)
677
+			} catch(ErrorException $e)
647 678
 			{
648 679
 				log_error($e->getMessage(), 'general', $e->getFile(), $e->getLine());
649 680
 				log_error(sprintf($txt['mail_send_unable'], $to));
@@ -653,12 +684,13 @@  discard block
 block discarded – undo
653 684
 
654 685
 			// Wait, wait, I'm still sending here!
655 686
 			@set_time_limit(300);
656
-			if (function_exists('apache_reset_timeout'))
657
-				@apache_reset_timeout();
687
+			if (function_exists('apache_reset_timeout')) {
688
+							@apache_reset_timeout();
689
+			}
658 690
 		}
691
+	} else {
692
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
659 693
 	}
660
-	else
661
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
662 694
 
663 695
 	// Everything go smoothly?
664 696
 	return $mail_result;
@@ -684,8 +716,9 @@  discard block
 block discarded – undo
684 716
 	static $cur_insert = array();
685 717
 	static $cur_insert_len = 0;
686 718
 
687
-	if ($cur_insert_len == 0)
688
-		$cur_insert = array();
719
+	if ($cur_insert_len == 0) {
720
+			$cur_insert = array();
721
+	}
689 722
 
690 723
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
691 724
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -760,8 +793,9 @@  discard block
 block discarded – undo
760 793
 	}
761 794
 
762 795
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
763
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
764
-		return AddMailQueue(true);
796
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
797
+			return AddMailQueue(true);
798
+	}
765 799
 
766 800
 	return true;
767 801
 }
@@ -792,23 +826,26 @@  discard block
 block discarded – undo
792 826
 		'sent' => array()
793 827
 	);
794 828
 
795
-	if ($from === null)
796
-		$from = array(
829
+	if ($from === null) {
830
+			$from = array(
797 831
 			'id' => $user_info['id'],
798 832
 			'name' => $user_info['name'],
799 833
 			'username' => $user_info['username']
800 834
 		);
835
+	}
801 836
 
802 837
 	// This is the one that will go in their inbox.
803 838
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
804 839
 	preparsecode($htmlmessage);
805 840
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
806
-	if ($smcFunc['strlen']($htmlsubject) > 100)
807
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
841
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
842
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
843
+	}
808 844
 
809 845
 	// Make sure is an array
810
-	if (!is_array($recipients))
811
-		$recipients = array($recipients);
846
+	if (!is_array($recipients)) {
847
+			$recipients = array($recipients);
848
+	}
812 849
 
813 850
 	// Integrated PMs
814 851
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -836,21 +873,23 @@  discard block
 block discarded – undo
836 873
 				'usernames' => array_keys($usernames),
837 874
 			)
838 875
 		);
839
-		while ($row = $smcFunc['db_fetch_assoc']($request))
840
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
876
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
877
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
841 878
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
879
+		}
842 880
 		$smcFunc['db_free_result']($request);
843 881
 
844 882
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
845
-		foreach ($recipients as $rec_type => $rec)
846
-			foreach ($rec as $id => $member)
883
+		foreach ($recipients as $rec_type => $rec) {
884
+					foreach ($rec as $id => $member)
847 885
 			{
848 886
 				if (is_numeric($recipients[$rec_type][$id]))
849 887
 					continue;
888
+		}
850 889
 
851
-				if (!empty($usernames[$member]))
852
-					$recipients[$rec_type][$id] = $usernames[$member];
853
-				else
890
+				if (!empty($usernames[$member])) {
891
+									$recipients[$rec_type][$id] = $usernames[$member];
892
+				} else
854 893
 				{
855 894
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
856 895
 					unset($recipients[$rec_type][$id]);
@@ -888,8 +927,9 @@  discard block
 block discarded – undo
888 927
 		$delete = false;
889 928
 		foreach ($criteria as $criterium)
890 929
 		{
891
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
892
-				$delete = true;
930
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
931
+							$delete = true;
932
+			}
893 933
 			// If we're adding and one criteria don't match then we stop!
894 934
 			elseif (!$row['is_or'])
895 935
 			{
@@ -897,8 +937,9 @@  discard block
 block discarded – undo
897 937
 				break;
898 938
 			}
899 939
 		}
900
-		if ($delete)
901
-			$deletes[$row['id_member']] = 1;
940
+		if ($delete) {
941
+					$deletes[$row['id_member']] = 1;
942
+		}
902 943
 	}
903 944
 	$smcFunc['db_free_result']($request);
904 945
 
@@ -913,8 +954,9 @@  discard block
 block discarded – undo
913 954
 			array(
914 955
 			)
915 956
 		);
916
-		while ($row = $smcFunc['db_fetch_assoc']($request))
917
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
957
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
958
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
959
+		}
918 960
 		$smcFunc['db_free_result']($request);
919 961
 	}
920 962
 
@@ -922,8 +964,9 @@  discard block
 block discarded – undo
922 964
 	require_once($sourcedir . '/Subs-Members.php');
923 965
 	$pmReadGroups = groupsAllowedTo('pm_read');
924 966
 
925
-	if (empty($modSettings['permission_enable_deny']))
926
-		$pmReadGroups['denied'] = array();
967
+	if (empty($modSettings['permission_enable_deny'])) {
968
+			$pmReadGroups['denied'] = array();
969
+	}
927 970
 
928 971
 	// Load their alert preferences
929 972
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -955,8 +998,9 @@  discard block
 block discarded – undo
955 998
 	while ($row = $smcFunc['db_fetch_assoc']($request))
956 999
 	{
957 1000
 		// Don't do anything for members to be deleted!
958
-		if (isset($deletes[$row['id_member']]))
959
-			continue;
1001
+		if (isset($deletes[$row['id_member']])) {
1002
+					continue;
1003
+		}
960 1004
 
961 1005
 		// Load the preferences for this member (if any)
962 1006
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -977,8 +1021,9 @@  discard block
 block discarded – undo
977 1021
 		{
978 1022
 			foreach ($groups as $id)
979 1023
 			{
980
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
981
-					$message_limit = $message_limit_cache[$id];
1024
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1025
+									$message_limit = $message_limit_cache[$id];
1026
+				}
982 1027
 			}
983 1028
 
984 1029
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1026,8 +1071,9 @@  discard block
 block discarded – undo
1026 1071
 	$smcFunc['db_free_result']($request);
1027 1072
 
1028 1073
 	// Only 'send' the message if there are any recipients left.
1029
-	if (empty($all_to))
1030
-		return $log;
1074
+	if (empty($all_to)) {
1075
+			return $log;
1076
+	}
1031 1077
 
1032 1078
 	// Insert the message itself and then grab the last insert id.
1033 1079
 	$id_pm = $smcFunc['db_insert']('',
@@ -1048,8 +1094,8 @@  discard block
 block discarded – undo
1048 1094
 	if (!empty($id_pm))
1049 1095
 	{
1050 1096
 		// If this is new we need to set it part of it's own conversation.
1051
-		if (empty($pm_head))
1052
-			$smcFunc['db_query']('', '
1097
+		if (empty($pm_head)) {
1098
+					$smcFunc['db_query']('', '
1053 1099
 				UPDATE {db_prefix}personal_messages
1054 1100
 				SET id_pm_head = {int:id_pm_head}
1055 1101
 				WHERE id_pm = {int:id_pm_head}',
@@ -1057,6 +1103,7 @@  discard block
 block discarded – undo
1057 1103
 					'id_pm_head' => $id_pm,
1058 1104
 				)
1059 1105
 			);
1106
+		}
1060 1107
 
1061 1108
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1062 1109
 		$smcFunc['db_query']('', '
@@ -1072,8 +1119,9 @@  discard block
 block discarded – undo
1072 1119
 		foreach ($all_to as $to)
1073 1120
 		{
1074 1121
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1075
-			if (!in_array($to, $recipients['bcc']))
1076
-				$to_list[] = $to;
1122
+			if (!in_array($to, $recipients['bcc'])) {
1123
+							$to_list[] = $to;
1124
+			}
1077 1125
 		}
1078 1126
 
1079 1127
 		$smcFunc['db_insert']('insert',
@@ -1091,9 +1139,9 @@  discard block
 block discarded – undo
1091 1139
 	{
1092 1140
 		censorText($message);
1093 1141
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1142
+	} else {
1143
+			$message = '';
1094 1144
 	}
1095
-	else
1096
-		$message = '';
1097 1145
 
1098 1146
 	$to_names = array();
1099 1147
 	if (count($to_list) > 1)
@@ -1106,8 +1154,9 @@  discard block
 block discarded – undo
1106 1154
 				'to_members' => $to_list,
1107 1155
 			)
1108 1156
 		);
1109
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1110
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1157
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1158
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1159
+		}
1111 1160
 		$smcFunc['db_free_result']($request);
1112 1161
 	}
1113 1162
 	$replacements = array(
@@ -1135,11 +1184,13 @@  discard block
 block discarded – undo
1135 1184
 	loadLanguage('index+PersonalMessage');
1136 1185
 
1137 1186
 	// Add one to their unread and read message counts.
1138
-	foreach ($all_to as $k => $id)
1139
-		if (isset($deletes[$id]))
1187
+	foreach ($all_to as $k => $id) {
1188
+			if (isset($deletes[$id]))
1140 1189
 			unset($all_to[$k]);
1141
-	if (!empty($all_to))
1142
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1190
+	}
1191
+	if (!empty($all_to)) {
1192
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1193
+	}
1143 1194
 
1144 1195
 	return $log;
1145 1196
 }
@@ -1169,15 +1220,17 @@  discard block
 block discarded – undo
1169 1220
 		// Let's, for now, assume there are only &#021;'ish characters.
1170 1221
 		$simple = true;
1171 1222
 
1172
-		foreach ($matches[1] as $entity)
1173
-			if ($entity > 128)
1223
+		foreach ($matches[1] as $entity) {
1224
+					if ($entity > 128)
1174 1225
 				$simple = false;
1226
+		}
1175 1227
 		unset($matches);
1176 1228
 
1177
-		if ($simple)
1178
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1229
+		if ($simple) {
1230
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1179 1231
 			{
1180 1232
 				return chr("$m[1]");
1233
+		}
1181 1234
 			}, $string);
1182 1235
 		else
1183 1236
 		{
@@ -1185,8 +1238,9 @@  discard block
 block discarded – undo
1185 1238
 			if (!$context['utf8'] && function_exists('iconv'))
1186 1239
 			{
1187 1240
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1188
-				if ($newstring)
1189
-					$string = $newstring;
1241
+				if ($newstring) {
1242
+									$string = $newstring;
1243
+				}
1190 1244
 			}
1191 1245
 
1192 1246
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1202,23 +1256,25 @@  discard block
 block discarded – undo
1202 1256
 		if (!$context['utf8'] && function_exists('iconv'))
1203 1257
 		{
1204 1258
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1205
-			if ($newstring)
1206
-				$string = $newstring;
1259
+			if ($newstring) {
1260
+							$string = $newstring;
1261
+			}
1207 1262
 		}
1208 1263
 
1209 1264
 		$entityConvert = function($m)
1210 1265
 		{
1211 1266
 			$c = $m[1];
1212
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1213
-				return $c;
1214
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1215
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1216
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1217
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1218
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1219
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1220
-			else
1221
-				return "";
1267
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1268
+							return $c;
1269
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1270
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1271
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1272
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1273
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1274
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1275
+			} else {
1276
+							return "";
1277
+			}
1222 1278
 		};
1223 1279
 
1224 1280
 		// Convert all 'special' characters to HTML entities.
@@ -1232,19 +1288,20 @@  discard block
 block discarded – undo
1232 1288
 		$string = base64_encode($string);
1233 1289
 
1234 1290
 		// Show the characterset and the transfer-encoding for header strings.
1235
-		if ($with_charset)
1236
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1291
+		if ($with_charset) {
1292
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1293
+		}
1237 1294
 
1238 1295
 		// Break it up in lines (mail body).
1239
-		else
1240
-			$string = chunk_split($string, 76, $line_break);
1296
+		else {
1297
+					$string = chunk_split($string, 76, $line_break);
1298
+		}
1241 1299
 
1242 1300
 		return array($charset, $string, 'base64');
1301
+	} else {
1302
+			return array($charset, $string, '7bit');
1303
+	}
1243 1304
 	}
1244
-
1245
-	else
1246
-		return array($charset, $string, '7bit');
1247
-}
1248 1305
 
1249 1306
 /**
1250 1307
  * Sends mail, like mail() but over SMTP.
@@ -1268,8 +1325,9 @@  discard block
 block discarded – undo
1268 1325
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1269 1326
 	{
1270 1327
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1271
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1272
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1328
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1329
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1330
+		}
1273 1331
 
1274 1332
 		if ($socket)
1275 1333
 		{
@@ -1291,11 +1349,13 @@  discard block
 block discarded – undo
1291 1349
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1292 1350
 		{
1293 1351
 			// ssl:hostname can cause fsocketopen to fail with a lookup failure, ensure it exists for this test.
1294
-			if (substr($modSettings['smtp_host'], 0, 6) != 'ssl://')
1295
-				$modSettings['smtp_host'] = str_replace('ssl:', 'ss://', $modSettings['smtp_host']);
1352
+			if (substr($modSettings['smtp_host'], 0, 6) != 'ssl://') {
1353
+							$modSettings['smtp_host'] = str_replace('ssl:', 'ss://', $modSettings['smtp_host']);
1354
+			}
1296 1355
 
1297
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1298
-				log_error($txt['smtp_port_ssl']);
1356
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1357
+							log_error($txt['smtp_port_ssl']);
1358
+			}
1299 1359
 		}
1300 1360
 
1301 1361
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1307,20 +1367,23 @@  discard block
 block discarded – undo
1307 1367
 	}
1308 1368
 
1309 1369
 	// Wait for a response of 220, without "-" continuer.
1310
-	if (!server_parse(null, $socket, '220'))
1311
-		return false;
1370
+	if (!server_parse(null, $socket, '220')) {
1371
+			return false;
1372
+	}
1312 1373
 
1313 1374
 	// Try and determine the servers name, fall back to the mail servers if not found
1314 1375
 	$helo = false;
1315
-	if (function_exists('gethostname') && gethostname() !== false)
1316
-		$helo = gethostname();
1317
-	elseif (function_exists('php_uname'))
1318
-		$helo = php_uname('n');
1319
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1320
-		$helo = $_SERVER['SERVER_NAME'];
1376
+	if (function_exists('gethostname') && gethostname() !== false) {
1377
+			$helo = gethostname();
1378
+	} elseif (function_exists('php_uname')) {
1379
+			$helo = php_uname('n');
1380
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1381
+			$helo = $_SERVER['SERVER_NAME'];
1382
+	}
1321 1383
 
1322
-	if (empty($helo))
1323
-		$helo = $modSettings['smtp_host'];
1384
+	if (empty($helo)) {
1385
+			$helo = $modSettings['smtp_host'];
1386
+	}
1324 1387
 
1325 1388
 	// SMTP = 1, SMTP - STARTTLS = 2
1326 1389
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1332,33 +1395,39 @@  discard block
 block discarded – undo
1332 1395
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1333 1396
 			{
1334 1397
 				// Send STARTTLS to enable encryption
1335
-				if (!server_parse('STARTTLS', $socket, '220'))
1336
-					return false;
1398
+				if (!server_parse('STARTTLS', $socket, '220')) {
1399
+									return false;
1400
+				}
1337 1401
 				// Enable the encryption
1338
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1339
-					return false;
1402
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1403
+									return false;
1404
+				}
1340 1405
 				// Send the EHLO command again
1341
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1342
-					return false;
1406
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1407
+									return false;
1408
+				}
1343 1409
 			}
1344 1410
 
1345
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1346
-				return false;
1411
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1412
+							return false;
1413
+			}
1347 1414
 			// Send the username and password, encoded.
1348
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1349
-				return false;
1415
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1416
+							return false;
1417
+			}
1350 1418
 			// The password is already encoded ;)
1351
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1352
-				return false;
1419
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1420
+							return false;
1421
+			}
1422
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1423
+					return false;
1353 1424
 		}
1354
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1355
-			return false;
1356
-	}
1357
-	else
1425
+	} else
1358 1426
 	{
1359 1427
 		// Just say "helo".
1360
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1361
-			return false;
1428
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1429
+					return false;
1430
+		}
1362 1431
 	}
1363 1432
 
1364 1433
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1371,31 +1440,38 @@  discard block
 block discarded – undo
1371 1440
 		// Reset the connection to send another email.
1372 1441
 		if ($i != 0)
1373 1442
 		{
1374
-			if (!server_parse('RSET', $socket, '250'))
1375
-				return false;
1443
+			if (!server_parse('RSET', $socket, '250')) {
1444
+							return false;
1445
+			}
1376 1446
 		}
1377 1447
 
1378 1448
 		// From, to, and then start the data...
1379
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1380
-			return false;
1381
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1382
-			return false;
1383
-		if (!server_parse('DATA', $socket, '354'))
1384
-			return false;
1449
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1450
+					return false;
1451
+		}
1452
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1453
+					return false;
1454
+		}
1455
+		if (!server_parse('DATA', $socket, '354')) {
1456
+					return false;
1457
+		}
1385 1458
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1386
-		if (strlen($mail_to) > 0)
1387
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1459
+		if (strlen($mail_to) > 0) {
1460
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1461
+		}
1388 1462
 		fputs($socket, $headers . "\r\n\r\n");
1389 1463
 		fputs($socket, $message . "\r\n");
1390 1464
 
1391 1465
 		// Send a ., or in other words "end of data".
1392
-		if (!server_parse('.', $socket, '250'))
1393
-			return false;
1466
+		if (!server_parse('.', $socket, '250')) {
1467
+					return false;
1468
+		}
1394 1469
 
1395 1470
 		// Almost done, almost done... don't stop me just yet!
1396 1471
 		@set_time_limit(300);
1397
-		if (function_exists('apache_reset_timeout'))
1398
-			@apache_reset_timeout();
1472
+		if (function_exists('apache_reset_timeout')) {
1473
+					@apache_reset_timeout();
1474
+		}
1399 1475
 	}
1400 1476
 	fputs($socket, 'QUIT' . "\r\n");
1401 1477
 	fclose($socket);
@@ -1419,8 +1495,9 @@  discard block
 block discarded – undo
1419 1495
 {
1420 1496
 	global $txt;
1421 1497
 
1422
-	if ($message !== null)
1423
-		fputs($socket, $message . "\r\n");
1498
+	if ($message !== null) {
1499
+			fputs($socket, $message . "\r\n");
1500
+	}
1424 1501
 
1425 1502
 	// No response yet.
1426 1503
 	$server_response = '';
@@ -1436,8 +1513,9 @@  discard block
 block discarded – undo
1436 1513
 		$response .= $server_response;
1437 1514
 	}
1438 1515
 
1439
-	if ($code === null)
1440
-		return substr($server_response, 0, 3);
1516
+	if ($code === null) {
1517
+			return substr($server_response, 0, 3);
1518
+	}
1441 1519
 
1442 1520
 	if (substr($server_response, 0, 3) != $code)
1443 1521
 	{
@@ -1467,8 +1545,9 @@  discard block
 block discarded – undo
1467 1545
 	// Create a pspell or enchant dictionary resource
1468 1546
 	$dict = spell_init();
1469 1547
 
1470
-	if (!isset($_POST['spellstring']) || !$dict)
1471
-		die;
1548
+	if (!isset($_POST['spellstring']) || !$dict) {
1549
+			die;
1550
+	}
1472 1551
 
1473 1552
 	// Construct a bit of Javascript code.
1474 1553
 	$context['spell_js'] = '
@@ -1486,8 +1565,9 @@  discard block
 block discarded – undo
1486 1565
 		$check_word = explode('|', $alphas[$i]);
1487 1566
 
1488 1567
 		// If the word is a known word, or spelled right...
1489
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1490
-			continue;
1568
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1569
+					continue;
1570
+		}
1491 1571
 
1492 1572
 		// Find the word, and move up the "last occurrence" to here.
1493 1573
 		$found_words = true;
@@ -1501,20 +1581,23 @@  discard block
 block discarded – undo
1501 1581
 		if (!empty($suggestions))
1502 1582
 		{
1503 1583
 			// But first check they aren't going to be censored - no naughty words!
1504
-			foreach ($suggestions as $k => $word)
1505
-				if ($suggestions[$k] != censorText($word))
1584
+			foreach ($suggestions as $k => $word) {
1585
+							if ($suggestions[$k] != censorText($word))
1506 1586
 					unset($suggestions[$k]);
1587
+			}
1507 1588
 
1508
-			if (!empty($suggestions))
1509
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1589
+			if (!empty($suggestions)) {
1590
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1591
+			}
1510 1592
 		}
1511 1593
 
1512 1594
 		$context['spell_js'] .= ']),';
1513 1595
 	}
1514 1596
 
1515 1597
 	// If words were found, take off the last comma.
1516
-	if ($found_words)
1517
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1598
+	if ($found_words) {
1599
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1600
+	}
1518 1601
 
1519 1602
 	$context['spell_js'] .= '
1520 1603
 		);';
@@ -1549,11 +1632,13 @@  discard block
 block discarded – undo
1549 1632
 	global $user_info, $smcFunc;
1550 1633
 
1551 1634
 	// Can't do it if there's no topics.
1552
-	if (empty($topics))
1553
-		return;
1635
+	if (empty($topics)) {
1636
+			return;
1637
+	}
1554 1638
 	// It must be an array - it must!
1555
-	if (!is_array($topics))
1556
-		$topics = array($topics);
1639
+	if (!is_array($topics)) {
1640
+			$topics = array($topics);
1641
+	}
1557 1642
 
1558 1643
 	// Get the subject and body...
1559 1644
 	$result = $smcFunc['db_query']('', '
@@ -1601,14 +1686,15 @@  discard block
 block discarded – undo
1601 1686
 	}
1602 1687
 	$smcFunc['db_free_result']($result);
1603 1688
 
1604
-	if (!empty($task_rows))
1605
-		$smcFunc['db_insert']('',
1689
+	if (!empty($task_rows)) {
1690
+			$smcFunc['db_insert']('',
1606 1691
 			'{db_prefix}background_tasks',
1607 1692
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1608 1693
 			$task_rows,
1609 1694
 			array('id_task')
1610 1695
 		);
1611
-}
1696
+	}
1697
+	}
1612 1698
 
1613 1699
 /**
1614 1700
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1646,9 +1732,9 @@  discard block
 block discarded – undo
1646 1732
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1647 1733
 
1648 1734
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1649
-	if (!$modSettings['postmod_active'])
1650
-		$topicOptions['is_approved'] = true;
1651
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1735
+	if (!$modSettings['postmod_active']) {
1736
+			$topicOptions['is_approved'] = true;
1737
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1652 1738
 	{
1653 1739
 		$request = $smcFunc['db_query']('', '
1654 1740
 			SELECT approved
@@ -1671,8 +1757,7 @@  discard block
 block discarded – undo
1671 1757
 			$posterOptions['id'] = 0;
1672 1758
 			$posterOptions['name'] = $txt['guest_title'];
1673 1759
 			$posterOptions['email'] = '';
1674
-		}
1675
-		elseif ($posterOptions['id'] != $user_info['id'])
1760
+		} elseif ($posterOptions['id'] != $user_info['id'])
1676 1761
 		{
1677 1762
 			$request = $smcFunc['db_query']('', '
1678 1763
 				SELECT member_name, email_address
@@ -1690,12 +1775,11 @@  discard block
 block discarded – undo
1690 1775
 				$posterOptions['id'] = 0;
1691 1776
 				$posterOptions['name'] = $txt['guest_title'];
1692 1777
 				$posterOptions['email'] = '';
1778
+			} else {
1779
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1693 1780
 			}
1694
-			else
1695
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1696 1781
 			$smcFunc['db_free_result']($request);
1697
-		}
1698
-		else
1782
+		} else
1699 1783
 		{
1700 1784
 			$posterOptions['name'] = $user_info['name'];
1701 1785
 			$posterOptions['email'] = $user_info['email'];
@@ -1705,8 +1789,9 @@  discard block
 block discarded – undo
1705 1789
 	if (!empty($modSettings['enable_mentions']))
1706 1790
 	{
1707 1791
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1708
-		if (!empty($msgOptions['mentioned_members']))
1709
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1792
+		if (!empty($msgOptions['mentioned_members'])) {
1793
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1794
+		}
1710 1795
 	}
1711 1796
 
1712 1797
 	// It's do or die time: forget any user aborts!
@@ -1739,12 +1824,13 @@  discard block
 block discarded – undo
1739 1824
 	);
1740 1825
 
1741 1826
 	// Something went wrong creating the message...
1742
-	if (empty($msgOptions['id']))
1743
-		return false;
1827
+	if (empty($msgOptions['id'])) {
1828
+			return false;
1829
+	}
1744 1830
 
1745 1831
 	// Fix the attachments.
1746
-	if (!empty($msgOptions['attachments']))
1747
-		$smcFunc['db_query']('', '
1832
+	if (!empty($msgOptions['attachments'])) {
1833
+			$smcFunc['db_query']('', '
1748 1834
 			UPDATE {db_prefix}attachments
1749 1835
 			SET id_msg = {int:id_msg}
1750 1836
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1753,6 +1839,7 @@  discard block
 block discarded – undo
1753 1839
 				'id_msg' => $msgOptions['id'],
1754 1840
 			)
1755 1841
 		);
1842
+	}
1756 1843
 
1757 1844
 	// What if we want to export new posts out to a CMS?
1758 1845
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1829,20 +1916,23 @@  discard block
 block discarded – undo
1829 1916
 			'id_topic' => $topicOptions['id'],
1830 1917
 			'counter_increment' => 1,
1831 1918
 		);
1832
-		if ($msgOptions['approved'])
1833
-			$topics_columns = array(
1919
+		if ($msgOptions['approved']) {
1920
+					$topics_columns = array(
1834 1921
 				'id_member_updated = {int:poster_id}',
1835 1922
 				'id_last_msg = {int:id_msg}',
1836 1923
 				'num_replies = num_replies + {int:counter_increment}',
1837 1924
 			);
1838
-		else
1839
-			$topics_columns = array(
1925
+		} else {
1926
+					$topics_columns = array(
1840 1927
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1841 1928
 			);
1842
-		if ($topicOptions['lock_mode'] !== null)
1843
-			$topics_columns[] = 'locked = {int:locked}';
1844
-		if ($topicOptions['sticky_mode'] !== null)
1845
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1929
+		}
1930
+		if ($topicOptions['lock_mode'] !== null) {
1931
+					$topics_columns[] = 'locked = {int:locked}';
1932
+		}
1933
+		if ($topicOptions['sticky_mode'] !== null) {
1934
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1935
+		}
1846 1936
 
1847 1937
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1848 1938
 
@@ -1871,8 +1961,8 @@  discard block
 block discarded – undo
1871 1961
 	);
1872 1962
 
1873 1963
 	// Increase the number of posts and topics on the board.
1874
-	if ($msgOptions['approved'])
1875
-		$smcFunc['db_query']('', '
1964
+	if ($msgOptions['approved']) {
1965
+			$smcFunc['db_query']('', '
1876 1966
 			UPDATE {db_prefix}boards
1877 1967
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1878 1968
 			WHERE id_board = {int:id_board}',
@@ -1880,7 +1970,7 @@  discard block
 block discarded – undo
1880 1970
 				'id_board' => $topicOptions['board'],
1881 1971
 			)
1882 1972
 		);
1883
-	else
1973
+	} else
1884 1974
 	{
1885 1975
 		$smcFunc['db_query']('', '
1886 1976
 			UPDATE {db_prefix}boards
@@ -1950,8 +2040,8 @@  discard block
 block discarded – undo
1950 2040
 		}
1951 2041
 	}
1952 2042
 
1953
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1954
-		$smcFunc['db_insert']('',
2043
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2044
+			$smcFunc['db_insert']('',
1955 2045
 			'{db_prefix}background_tasks',
1956 2046
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1957 2047
 			array(
@@ -1963,19 +2053,22 @@  discard block
 block discarded – undo
1963 2053
 			),
1964 2054
 			array('id_task')
1965 2055
 		);
2056
+	}
1966 2057
 
1967 2058
 	// If there's a custom search index, it may need updating...
1968 2059
 	require_once($sourcedir . '/Search.php');
1969 2060
 	$searchAPI = findSearchAPI();
1970
-	if (is_callable(array($searchAPI, 'postCreated')))
1971
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2061
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2062
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2063
+	}
1972 2064
 
1973 2065
 	// Increase the post counter for the user that created the post.
1974 2066
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
1975 2067
 	{
1976 2068
 		// Are you the one that happened to create this post?
1977
-		if ($user_info['id'] == $posterOptions['id'])
1978
-			$user_info['posts']++;
2069
+		if ($user_info['id'] == $posterOptions['id']) {
2070
+					$user_info['posts']++;
2071
+		}
1979 2072
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
1980 2073
 	}
1981 2074
 
@@ -1983,19 +2076,21 @@  discard block
 block discarded – undo
1983 2076
 	$_SESSION['last_read_topic'] = 0;
1984 2077
 
1985 2078
 	// Better safe than sorry.
1986
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
1987
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2079
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2080
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2081
+	}
1988 2082
 
1989 2083
 	// Update all the stats so everyone knows about this new topic and message.
1990 2084
 	updateStats('message', true, $msgOptions['id']);
1991 2085
 
1992 2086
 	// Update the last message on the board assuming it's approved AND the topic is.
1993
-	if ($msgOptions['approved'])
1994
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2087
+	if ($msgOptions['approved']) {
2088
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2089
+	}
1995 2090
 
1996 2091
 	// Queue createPost background notification
1997
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
1998
-		$smcFunc['db_insert']('',
2092
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2093
+			$smcFunc['db_insert']('',
1999 2094
 			'{db_prefix}background_tasks',
2000 2095
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2001 2096
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
@@ -2006,6 +2101,7 @@  discard block
 block discarded – undo
2006 2101
 			)), 0),
2007 2102
 			array('id_task')
2008 2103
 		);
2104
+	}
2009 2105
 
2010 2106
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2011 2107
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2032,14 +2128,18 @@  discard block
 block discarded – undo
2032 2128
 
2033 2129
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2034 2130
 	$messages_columns = array();
2035
-	if (isset($posterOptions['name']))
2036
-		$messages_columns['poster_name'] = $posterOptions['name'];
2037
-	if (isset($posterOptions['email']))
2038
-		$messages_columns['poster_email'] = $posterOptions['email'];
2039
-	if (isset($msgOptions['icon']))
2040
-		$messages_columns['icon'] = $msgOptions['icon'];
2041
-	if (isset($msgOptions['subject']))
2042
-		$messages_columns['subject'] = $msgOptions['subject'];
2131
+	if (isset($posterOptions['name'])) {
2132
+			$messages_columns['poster_name'] = $posterOptions['name'];
2133
+	}
2134
+	if (isset($posterOptions['email'])) {
2135
+			$messages_columns['poster_email'] = $posterOptions['email'];
2136
+	}
2137
+	if (isset($msgOptions['icon'])) {
2138
+			$messages_columns['icon'] = $msgOptions['icon'];
2139
+	}
2140
+	if (isset($msgOptions['subject'])) {
2141
+			$messages_columns['subject'] = $msgOptions['subject'];
2142
+	}
2043 2143
 	if (isset($msgOptions['body']))
2044 2144
 	{
2045 2145
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2066,8 +2166,9 @@  discard block
 block discarded – undo
2066 2166
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2067 2167
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2068 2168
 	}
2069
-	if (isset($msgOptions['smileys_enabled']))
2070
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2169
+	if (isset($msgOptions['smileys_enabled'])) {
2170
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2171
+	}
2071 2172
 
2072 2173
 	// Which columns need to be ints?
2073 2174
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2078,8 +2179,9 @@  discard block
 block discarded – undo
2078 2179
 	// Update search api
2079 2180
 	require_once($sourcedir . '/Search.php');
2080 2181
 	$searchAPI = findSearchAPI();
2081
-	if ($searchAPI->supportsMethod('postRemoved'))
2082
-		$searchAPI->postRemoved($msgOptions['id']);
2182
+	if ($searchAPI->supportsMethod('postRemoved')) {
2183
+			$searchAPI->postRemoved($msgOptions['id']);
2184
+	}
2083 2185
 
2084 2186
 	if (!empty($modSettings['enable_mentions']) && isset($msgOptions['body']))
2085 2187
 	{
@@ -2091,23 +2193,27 @@  discard block
 block discarded – undo
2091 2193
 		{
2092 2194
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2093 2195
 
2094
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2095
-				foreach ($match[1] as $i => $oldID)
2196
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2197
+							foreach ($match[1] as $i => $oldID)
2096 2198
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2199
+			}
2097 2200
 
2098
-			if (empty($modSettings['search_custom_index_config']))
2099
-				unset($msgOptions['old_body']);
2201
+			if (empty($modSettings['search_custom_index_config'])) {
2202
+							unset($msgOptions['old_body']);
2203
+			}
2100 2204
 		}
2101 2205
 
2102 2206
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2103 2207
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2104 2208
 
2105 2209
 		// Remove the poster.
2106
-		if (isset($mentions[$user_info['id']]))
2107
-			unset($mentions[$user_info['id']]);
2210
+		if (isset($mentions[$user_info['id']])) {
2211
+					unset($mentions[$user_info['id']]);
2212
+		}
2108 2213
 
2109
-		if (isset($oldmentions[$user_info['id']]))
2110
-			unset($oldmentions[$user_info['id']]);
2214
+		if (isset($oldmentions[$user_info['id']])) {
2215
+					unset($oldmentions[$user_info['id']]);
2216
+		}
2111 2217
 
2112 2218
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2113 2219
 		{
@@ -2137,8 +2243,9 @@  discard block
 block discarded – undo
2137 2243
 	}
2138 2244
 
2139 2245
 	// Nothing to do?
2140
-	if (empty($messages_columns))
2141
-		return true;
2246
+	if (empty($messages_columns)) {
2247
+			return true;
2248
+	}
2142 2249
 
2143 2250
 	// Change the post.
2144 2251
 	$smcFunc['db_query']('', '
@@ -2199,8 +2306,9 @@  discard block
 block discarded – undo
2199 2306
 	// If there's a custom search index, it needs to be modified...
2200 2307
 	require_once($sourcedir . '/Search.php');
2201 2308
 	$searchAPI = findSearchAPI();
2202
-	if (is_callable(array($searchAPI, 'postModified')))
2203
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2309
+	if (is_callable(array($searchAPI, 'postModified'))) {
2310
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2311
+	}
2204 2312
 
2205 2313
 	if (isset($msgOptions['subject']))
2206 2314
 	{
@@ -2214,14 +2322,16 @@  discard block
 block discarded – undo
2214 2322
 				'id_first_msg' => $msgOptions['id'],
2215 2323
 			)
2216 2324
 		);
2217
-		if ($smcFunc['db_num_rows']($request) == 1)
2218
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2325
+		if ($smcFunc['db_num_rows']($request) == 1) {
2326
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2327
+		}
2219 2328
 		$smcFunc['db_free_result']($request);
2220 2329
 	}
2221 2330
 
2222 2331
 	// Finally, if we are setting the approved state we need to do much more work :(
2223
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2224
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2332
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2333
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2334
+	}
2225 2335
 
2226 2336
 	return true;
2227 2337
 }
@@ -2238,11 +2348,13 @@  discard block
 block discarded – undo
2238 2348
 {
2239 2349
 	global $smcFunc;
2240 2350
 
2241
-	if (!is_array($msgs))
2242
-		$msgs = array($msgs);
2351
+	if (!is_array($msgs)) {
2352
+			$msgs = array($msgs);
2353
+	}
2243 2354
 
2244
-	if (empty($msgs))
2245
-		return false;
2355
+	if (empty($msgs)) {
2356
+			return false;
2357
+	}
2246 2358
 
2247 2359
 	// May as well start at the beginning, working out *what* we need to change.
2248 2360
 	$request = $smcFunc['db_query']('', '
@@ -2274,20 +2386,22 @@  discard block
 block discarded – undo
2274 2386
 		$topics[] = $row['id_topic'];
2275 2387
 
2276 2388
 		// Ensure our change array exists already.
2277
-		if (!isset($topic_changes[$row['id_topic']]))
2278
-			$topic_changes[$row['id_topic']] = array(
2389
+		if (!isset($topic_changes[$row['id_topic']])) {
2390
+					$topic_changes[$row['id_topic']] = array(
2279 2391
 				'id_last_msg' => $row['id_last_msg'],
2280 2392
 				'approved' => $row['topic_approved'],
2281 2393
 				'replies' => 0,
2282 2394
 				'unapproved_posts' => 0,
2283 2395
 			);
2284
-		if (!isset($board_changes[$row['id_board']]))
2285
-			$board_changes[$row['id_board']] = array(
2396
+		}
2397
+		if (!isset($board_changes[$row['id_board']])) {
2398
+					$board_changes[$row['id_board']] = array(
2286 2399
 				'posts' => 0,
2287 2400
 				'topics' => 0,
2288 2401
 				'unapproved_posts' => 0,
2289 2402
 				'unapproved_topics' => 0,
2290 2403
 			);
2404
+		}
2291 2405
 
2292 2406
 		// If it's the first message then the topic state changes!
2293 2407
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2308,14 +2422,13 @@  discard block
 block discarded – undo
2308 2422
 				'poster' => $row['id_member'],
2309 2423
 				'new_topic' => true,
2310 2424
 			);
2311
-		}
2312
-		else
2425
+		} else
2313 2426
 		{
2314 2427
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2315 2428
 
2316 2429
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2317
-			if ($row['id_msg'] > $row['id_last_msg'])
2318
-				$notification_posts[$row['id_topic']] = array(
2430
+			if ($row['id_msg'] > $row['id_last_msg']) {
2431
+							$notification_posts[$row['id_topic']] = array(
2319 2432
 					'id' => $row['id_msg'],
2320 2433
 					'body' => $row['body'],
2321 2434
 					'subject' => $row['subject'],
@@ -2326,28 +2439,33 @@  discard block
 block discarded – undo
2326 2439
 					'new_topic' => false,
2327 2440
 					'msg' => $row['id_msg'],
2328 2441
 				);
2442
+			}
2329 2443
 		}
2330 2444
 
2331 2445
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2332
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2333
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2446
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2447
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2448
+		}
2334 2449
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2335
-		elseif (!$approve)
2336
-			// Default to the first message and then we'll override in a bit ;)
2450
+		elseif (!$approve) {
2451
+					// Default to the first message and then we'll override in a bit ;)
2337 2452
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2453
+		}
2338 2454
 
2339 2455
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2340 2456
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2341 2457
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2342 2458
 
2343 2459
 		// Post count for the user?
2344
-		if ($row['id_member'] && empty($row['count_posts']))
2345
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2460
+		if ($row['id_member'] && empty($row['count_posts'])) {
2461
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2462
+		}
2346 2463
 	}
2347 2464
 	$smcFunc['db_free_result']($request);
2348 2465
 
2349
-	if (empty($msgs))
2350
-		return;
2466
+	if (empty($msgs)) {
2467
+			return;
2468
+	}
2351 2469
 
2352 2470
 	// Now we have the differences make the changes, first the easy one.
2353 2471
 	$smcFunc['db_query']('', '
@@ -2374,14 +2492,15 @@  discard block
 block discarded – undo
2374 2492
 				'approved' => 1,
2375 2493
 			)
2376 2494
 		);
2377
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2378
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2495
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2496
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2497
+		}
2379 2498
 		$smcFunc['db_free_result']($request);
2380 2499
 	}
2381 2500
 
2382 2501
 	// ... next the topics...
2383
-	foreach ($topic_changes as $id => $changes)
2384
-		$smcFunc['db_query']('', '
2502
+	foreach ($topic_changes as $id => $changes) {
2503
+			$smcFunc['db_query']('', '
2385 2504
 			UPDATE {db_prefix}topics
2386 2505
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2387 2506
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2394,10 +2513,11 @@  discard block
 block discarded – undo
2394 2513
 				'id_topic' => $id,
2395 2514
 			)
2396 2515
 		);
2516
+	}
2397 2517
 
2398 2518
 	// ... finally the boards...
2399
-	foreach ($board_changes as $id => $changes)
2400
-		$smcFunc['db_query']('', '
2519
+	foreach ($board_changes as $id => $changes) {
2520
+			$smcFunc['db_query']('', '
2401 2521
 			UPDATE {db_prefix}boards
2402 2522
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2403 2523
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2410,13 +2530,14 @@  discard block
 block discarded – undo
2410 2530
 				'id_board' => $id,
2411 2531
 			)
2412 2532
 		);
2533
+	}
2413 2534
 
2414 2535
 	// Finally, least importantly, notifications!
2415 2536
 	if ($approve)
2416 2537
 	{
2417 2538
 		$task_rows = array();
2418
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2419
-			$task_rows[] = array(
2539
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2540
+					$task_rows[] = array(
2420 2541
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
2421 2542
 					'msgOptions' => array(
2422 2543
 						'id' => $topic['msg'],
@@ -2434,14 +2555,16 @@  discard block
 block discarded – undo
2434 2555
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2435 2556
 				)), 0
2436 2557
 			);
2558
+		}
2437 2559
 
2438
-		if ($notify)
2439
-			$smcFunc['db_insert']('',
2560
+		if ($notify) {
2561
+					$smcFunc['db_insert']('',
2440 2562
 				'{db_prefix}background_tasks',
2441 2563
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2442 2564
 				$task_rows,
2443 2565
 				array('id_task')
2444 2566
 			);
2567
+		}
2445 2568
 
2446 2569
 		$smcFunc['db_query']('', '
2447 2570
 			DELETE FROM {db_prefix}approval_queue
@@ -2457,8 +2580,9 @@  discard block
 block discarded – undo
2457 2580
 	else
2458 2581
 	{
2459 2582
 		$msgInserts = array();
2460
-		foreach ($msgs as $msg)
2461
-			$msgInserts[] = array($msg);
2583
+		foreach ($msgs as $msg) {
2584
+					$msgInserts[] = array($msg);
2585
+		}
2462 2586
 
2463 2587
 		$smcFunc['db_insert']('ignore',
2464 2588
 			'{db_prefix}approval_queue',
@@ -2472,9 +2596,10 @@  discard block
 block discarded – undo
2472 2596
 	updateLastMessages(array_keys($board_changes));
2473 2597
 
2474 2598
 	// Post count for the members?
2475
-	if (!empty($member_post_changes))
2476
-		foreach ($member_post_changes as $id_member => $count_change)
2599
+	if (!empty($member_post_changes)) {
2600
+			foreach ($member_post_changes as $id_member => $count_change)
2477 2601
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2602
+	}
2478 2603
 
2479 2604
 	return true;
2480 2605
 }
@@ -2491,11 +2616,13 @@  discard block
 block discarded – undo
2491 2616
 {
2492 2617
 	global $smcFunc;
2493 2618
 
2494
-	if (!is_array($topics))
2495
-		$topics = array($topics);
2619
+	if (!is_array($topics)) {
2620
+			$topics = array($topics);
2621
+	}
2496 2622
 
2497
-	if (empty($topics))
2498
-		return false;
2623
+	if (empty($topics)) {
2624
+			return false;
2625
+	}
2499 2626
 
2500 2627
 	$approve_type = $approve ? 0 : 1;
2501 2628
 
@@ -2511,8 +2638,9 @@  discard block
 block discarded – undo
2511 2638
 		)
2512 2639
 	);
2513 2640
 	$msgs = array();
2514
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2515
-		$msgs[] = $row['id_msg'];
2641
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2642
+			$msgs[] = $row['id_msg'];
2643
+	}
2516 2644
 	$smcFunc['db_free_result']($request);
2517 2645
 
2518 2646
 	return approvePosts($msgs, $approve);
@@ -2535,11 +2663,13 @@  discard block
 block discarded – undo
2535 2663
 	global $board_info, $board, $smcFunc;
2536 2664
 
2537 2665
 	// Please - let's be sane.
2538
-	if (empty($setboards))
2539
-		return false;
2666
+	if (empty($setboards)) {
2667
+			return false;
2668
+	}
2540 2669
 
2541
-	if (!is_array($setboards))
2542
-		$setboards = array($setboards);
2670
+	if (!is_array($setboards)) {
2671
+			$setboards = array($setboards);
2672
+	}
2543 2673
 
2544 2674
 	// If we don't know the id_msg we need to find it.
2545 2675
 	if (!$id_msg)
@@ -2557,15 +2687,16 @@  discard block
 block discarded – undo
2557 2687
 			)
2558 2688
 		);
2559 2689
 		$lastMsg = array();
2560
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2561
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2690
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2691
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2692
+		}
2562 2693
 		$smcFunc['db_free_result']($request);
2563
-	}
2564
-	else
2694
+	} else
2565 2695
 	{
2566 2696
 		// Just to note - there should only be one board passed if we are doing this.
2567
-		foreach ($setboards as $id_board)
2568
-			$lastMsg[$id_board] = $id_msg;
2697
+		foreach ($setboards as $id_board) {
2698
+					$lastMsg[$id_board] = $id_msg;
2699
+		}
2569 2700
 	}
2570 2701
 
2571 2702
 	$parent_boards = array();
@@ -2580,10 +2711,11 @@  discard block
 block discarded – undo
2580 2711
 			$lastModified[$id_board] = 0;
2581 2712
 		}
2582 2713
 
2583
-		if (!empty($board) && $id_board == $board)
2584
-			$parents = $board_info['parent_boards'];
2585
-		else
2586
-			$parents = getBoardParents($id_board);
2714
+		if (!empty($board) && $id_board == $board) {
2715
+					$parents = $board_info['parent_boards'];
2716
+		} else {
2717
+					$parents = getBoardParents($id_board);
2718
+		}
2587 2719
 
2588 2720
 		// Ignore any parents on the top child level.
2589 2721
 		// @todo Why?
@@ -2592,10 +2724,11 @@  discard block
 block discarded – undo
2592 2724
 			if ($parent['level'] != 0)
2593 2725
 			{
2594 2726
 				// If we're already doing this one as a board, is this a higher last modified?
2595
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2596
-					$lastModified[$id] = $lastModified[$id_board];
2597
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2598
-					$parent_boards[$id] = $lastModified[$id_board];
2727
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2728
+									$lastModified[$id] = $lastModified[$id_board];
2729
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2730
+									$parent_boards[$id] = $lastModified[$id_board];
2731
+				}
2599 2732
 			}
2600 2733
 		}
2601 2734
 	}
@@ -2608,23 +2741,24 @@  discard block
 block discarded – undo
2608 2741
 	// Finally, to save on queries make the changes...
2609 2742
 	foreach ($parent_boards as $id => $msg)
2610 2743
 	{
2611
-		if (!isset($parent_updates[$msg]))
2612
-			$parent_updates[$msg] = array($id);
2613
-		else
2614
-			$parent_updates[$msg][] = $id;
2744
+		if (!isset($parent_updates[$msg])) {
2745
+					$parent_updates[$msg] = array($id);
2746
+		} else {
2747
+					$parent_updates[$msg][] = $id;
2748
+		}
2615 2749
 	}
2616 2750
 
2617 2751
 	foreach ($lastMsg as $id => $msg)
2618 2752
 	{
2619
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2620
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2753
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2754
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2621 2755
 				'id' => $msg,
2622 2756
 				'updated' => $lastModified[$id],
2623 2757
 				'boards' => array($id)
2624 2758
 			);
2625
-
2626
-		else
2627
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2759
+		} else {
2760
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2761
+		}
2628 2762
 	}
2629 2763
 
2630 2764
 	// Now commit the changes!
@@ -2716,11 +2850,13 @@  discard block
 block discarded – undo
2716 2850
 	global $txt, $mbname, $scripturl, $settings;
2717 2851
 
2718 2852
 	// First things first, load up the email templates language file, if we need to.
2719
-	if ($loadLang)
2720
-		loadLanguage('EmailTemplates', $lang);
2853
+	if ($loadLang) {
2854
+			loadLanguage('EmailTemplates', $lang);
2855
+	}
2721 2856
 
2722
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2723
-		fatal_lang_error('email_no_template', 'template', array($template));
2857
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2858
+			fatal_lang_error('email_no_template', 'template', array($template));
2859
+	}
2724 2860
 
2725 2861
 	$ret = array(
2726 2862
 		'subject' => $txt[$template . '_subject'],
@@ -2770,17 +2906,18 @@  discard block
 block discarded – undo
2770 2906
 function user_info_callback($matches)
2771 2907
 {
2772 2908
 	global $user_info;
2773
-	if (empty($matches[1]))
2774
-		return '';
2909
+	if (empty($matches[1])) {
2910
+			return '';
2911
+	}
2775 2912
 
2776 2913
 	$use_ref = true;
2777 2914
 	$ref = &$user_info;
2778 2915
 
2779 2916
 	foreach (explode('.', $matches[1]) as $index)
2780 2917
 	{
2781
-		if ($use_ref && isset($ref[$index]))
2782
-			$ref = &$ref[$index];
2783
-		else
2918
+		if ($use_ref && isset($ref[$index])) {
2919
+					$ref = &$ref[$index];
2920
+		} else
2784 2921
 		{
2785 2922
 			$use_ref = false;
2786 2923
 			break;
@@ -2817,8 +2954,7 @@  discard block
 block discarded – undo
2817 2954
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2818 2955
 		{
2819 2956
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2820
-		}
2821
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2957
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2822 2958
 		{
2823 2959
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2824 2960
 		}
@@ -2828,8 +2964,7 @@  discard block
 block discarded – undo
2828 2964
 		{
2829 2965
 			$context['provider'] = 'enchant';
2830 2966
 			return $enchant_link;
2831
-		}
2832
-		else
2967
+		} else
2833 2968
 		{
2834 2969
 			// Free up any resources used...
2835 2970
 			@enchant_broker_free($context['enchant_broker']);
@@ -2850,8 +2985,9 @@  discard block
 block discarded – undo
2850 2985
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2851 2986
 
2852 2987
 		// Most people don't have anything but English installed... So we use English as a last resort.
2853
-		if (!$pspell_link)
2854
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
2988
+		if (!$pspell_link) {
2989
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
2990
+		}
2855 2991
 
2856 2992
 		error_reporting($old);
2857 2993
 		ob_end_clean();
@@ -2891,8 +3027,7 @@  discard block
 block discarded – undo
2891 3027
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2892 3028
 		}
2893 3029
 		return enchant_dict_check($dict, $word);
2894
-	}
2895
-	elseif ($context['provider'] == 'pspell')
3030
+	} elseif ($context['provider'] == 'pspell')
2896 3031
 	{
2897 3032
 		return pspell_check($dict, $word);
2898 3033
 	}
@@ -2928,13 +3063,11 @@  discard block
 block discarded – undo
2928 3063
 			}
2929 3064
 
2930 3065
 			return $suggestions;
2931
-		}
2932
-		else
3066
+		} else
2933 3067
 		{
2934 3068
 			return enchant_dict_suggest($dict, $word);
2935 3069
 		}
2936
-	}
2937
-	elseif ($context['provider'] == 'pspell')
3070
+	} elseif ($context['provider'] == 'pspell')
2938 3071
 	{
2939 3072
 		return pspell_suggest($dict, $word);
2940 3073
 	}
Please login to merge, or discard this patch.
Sources/Subs-Sound.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
  * Used by VerificationCode() (Register.php).
25 25
  *
26 26
  * @param string $word
27
- * @return boolean false on failure
27
+ * @return null|false false on failure
28 28
  */
29 29
 
30 30
 function createWaveFile($word)
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
 	cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20);
39 39
 
40 40
 	// Fixate randomization for this word.
41
-    $tmp = unpack('n', md5($word . session_id()));
41
+	$tmp = unpack('n', md5($word . session_id()));
42 42
 	mt_srand(end($tmp));
43 43
 
44 44
 	// Try to see if there's a sound font in the user's language.
Please login to merge, or discard this patch.
Braces   +32 added lines, -20 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Creates a wave file that spells the letters of $word.
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	global $settings, $user_info;
33 34
 
34 35
 	// Allow max 2 requests per 20 seconds.
35
-	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2)
36
-		die(header('HTTP/1.1 400 Bad Request'));
36
+	if (($ip = cache_get_data('wave_file/' . $user_info['ip'], 20)) > 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) {
37
+			die(header('HTTP/1.1 400 Bad Request'));
38
+	}
37 39
 	cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20);
38 40
 	cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20);
39 41
 
@@ -42,16 +44,19 @@  discard block
 block discarded – undo
42 44
 	mt_srand(end($tmp));
43 45
 
44 46
 	// Try to see if there's a sound font in the user's language.
45
-	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav'))
46
-		$sound_language = $user_info['language'];
47
+	if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) {
48
+			$sound_language = $user_info['language'];
49
+	}
47 50
 
48 51
 	// English should be there.
49
-	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav'))
50
-		$sound_language = 'english';
52
+	elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) {
53
+			$sound_language = 'english';
54
+	}
51 55
 
52 56
 	// Guess not...
53
-	else
54
-		return false;
57
+	else {
58
+			return false;
59
+	}
55 60
 
56 61
 	// File names are in lower case so lets make sure that we are only using a lower case string
57 62
 	$word = strtolower($word);
@@ -61,20 +66,25 @@  discard block
 block discarded – undo
61 66
 	for ($i = 0; $i < strlen($word); $i++)
62 67
 	{
63 68
 		$sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav'));
64
-		if (strpos($sound_letter, 'data') === false)
65
-			return false;
69
+		if (strpos($sound_letter, 'data') === false) {
70
+					return false;
71
+		}
66 72
 
67 73
 		$sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8);
68 74
 		switch ($word{$i} === 's' ? 0 : mt_rand(0, 2))
69 75
 		{
70
-			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
71
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
72
-						$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
76
+			case 0 : for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) {
77
+								for ($k = 0, $m = round(mt_rand(15, 25) / 10);
78
+			}
79
+			$k < $m; $k++) {
80
+											$sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF)));
81
+					}
73 82
 			break;
74 83
 
75 84
 			case 1:
76
-				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2)
77
-					$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
85
+				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) {
86
+									$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : '');
87
+				}
78 88
 				$sound_word .= str_repeat($sound_letter{$n}, 2);
79 89
 			break;
80 90
 
@@ -82,10 +92,12 @@  discard block
 block discarded – undo
82 92
 				$shift = 0;
83 93
 				for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
84 94
 				{
85
-					if (mt_rand(0, 10) === 0)
86
-						$shift += mt_rand(-3, 3);
87
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
88
-						$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
95
+					if (mt_rand(0, 10) === 0) {
96
+											$shift += mt_rand(-3, 3);
97
+					}
98
+					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) {
99
+											$sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF));
100
+					}
89 101
 				}
90 102
 			break;
91 103
 		}
Please login to merge, or discard this patch.