Completed
Push — release-2.1 ( 1c80d3...447e69 )
by Colin
09:55
created
Sources/Profile-View.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2605,7 +2605,7 @@
 block discarded – undo
2605 2605
  * @param int $start Which item to start with (for pagination purposes)
2606 2606
  * @param int $items_per_page How many items to show on each page
2607 2607
  * @param string $sort A string indicating how to sort the results
2608
- * @param int $memID The ID of the member
2608
+ * @param string $memID The ID of the member
2609 2609
  * @return array An array of information about the user's group requests
2610 2610
  */
2611 2611
 function list_getGroupRequests($start, $items_per_page, $sort, $memID)
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	}
251 251
 	$smcFunc['db_free_result']($request);
252 252
 
253
-	if($withSender)
253
+	if ($withSender)
254 254
 	{
255 255
 		$senders = loadMemberData($senders);
256 256
 		foreach ($senders as $member)
@@ -1896,7 +1896,7 @@  discard block
 block discarded – undo
1896 1896
 	if (count($context['ip']) !== 2)
1897 1897
 		fatal_lang_error('invalid_tracking_ip', false);
1898 1898
 
1899
-	$ip_string = array('{inet:ip_address_low}','{inet:ip_address_high}');
1899
+	$ip_string = array('{inet:ip_address_low}', '{inet:ip_address_high}');
1900 1900
 	$fields = array(
1901 1901
 			'ip_address_low' => $context['ip']['low'],
1902 1902
 			'ip_address_high' => $context['ip']['high'],
@@ -1904,7 +1904,7 @@  discard block
 block discarded – undo
1904 1904
 
1905 1905
 	$ip_var = $context['ip'];
1906 1906
 
1907
-	if ($context['ip']['low'] !==  $context['ip']['high'])
1907
+	if ($context['ip']['low'] !== $context['ip']['high'])
1908 1908
 		$context['ip'] = $context['ip']['low'] . ' - ' . $context['ip']['high'];
1909 1909
 	else
1910 1910
 		$context['ip'] = $context['ip']['low'];
Please login to merge, or discard this patch.
Braces   +310 added lines, -227 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 4
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * View a summary.
@@ -23,8 +24,9 @@  discard block
 block discarded – undo
23 24
 	global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
24 25
 
25 26
 	// Attempt to load the member's profile data.
26
-	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
27
-		fatal_lang_error('not_a_user', false, 404);
27
+	if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
28
+			fatal_lang_error('not_a_user', false, 404);
29
+	}
28 30
 
29 31
 	// Set up the stuff and load the user.
30 32
 	$context += array(
@@ -49,19 +51,21 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// See if they have broken any warning levels...
51 53
 	list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
52
-	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
53
-		$context['warning_status'] = $txt['profile_warning_is_muted'];
54
-	elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
55
-		$context['warning_status'] = $txt['profile_warning_is_moderation'];
56
-	elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
57
-		$context['warning_status'] = $txt['profile_warning_is_watch'];
54
+	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
55
+			$context['warning_status'] = $txt['profile_warning_is_muted'];
56
+	} elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
57
+			$context['warning_status'] = $txt['profile_warning_is_moderation'];
58
+	} elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
59
+			$context['warning_status'] = $txt['profile_warning_is_watch'];
60
+	}
58 61
 
59 62
 	// They haven't even been registered for a full day!?
60 63
 	$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
61
-	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
62
-		$context['member']['posts_per_day'] = $txt['not_applicable'];
63
-	else
64
-		$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
64
+	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
65
+			$context['member']['posts_per_day'] = $txt['not_applicable'];
66
+	} else {
67
+			$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
68
+	}
65 69
 
66 70
 	// Set the age...
67 71
 	if (empty($context['member']['birth_date']) || substr($context['member']['birth_date'], 0, 4) < 1002)
@@ -70,8 +74,7 @@  discard block
 block discarded – undo
70 74
 			'age' => $txt['not_applicable'],
71 75
 			'today_is_birthday' => false
72 76
 		);
73
-	}
74
-	else
77
+	} else
75 78
 	{
76 79
 		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
77 80
 		$datearray = getdate(forum_time());
@@ -84,15 +87,16 @@  discard block
 block discarded – undo
84 87
 	if (allowedTo('moderate_forum'))
85 88
 	{
86 89
 		// Make sure it's a valid ip address; otherwise, don't bother...
87
-		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
88
-			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
89
-		else
90
-			$context['member']['hostname'] = '';
90
+		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
91
+					$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
92
+		} else {
93
+					$context['member']['hostname'] = '';
94
+		}
91 95
 
92 96
 		$context['can_see_ip'] = true;
97
+	} else {
98
+			$context['can_see_ip'] = false;
93 99
 	}
94
-	else
95
-		$context['can_see_ip'] = false;
96 100
 
97 101
 	// Are they hidden?
98 102
 	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
@@ -103,8 +107,9 @@  discard block
 block discarded – undo
103 107
 		include_once($sourcedir . '/Who.php');
104 108
 		$action = determineActions($user_profile[$memID]['url']);
105 109
 
106
-		if ($action !== false)
107
-			$context['member']['action'] = $action;
110
+		if ($action !== false) {
111
+					$context['member']['action'] = $action;
112
+		}
108 113
 	}
109 114
 
110 115
 	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
@@ -167,13 +172,15 @@  discard block
 block discarded – undo
167 172
 		{
168 173
 			// Work out what restrictions we actually have.
169 174
 			$ban_restrictions = array();
170
-			foreach (array('access', 'login', 'post') as $type)
171
-				if ($row['cannot_' . $type])
175
+			foreach (array('access', 'login', 'post') as $type) {
176
+							if ($row['cannot_' . $type])
172 177
 					$ban_restrictions[] = $txt['ban_type_' . $type];
178
+			}
173 179
 
174 180
 			// No actual ban in place?
175
-			if (empty($ban_restrictions))
176
-				continue;
181
+			if (empty($ban_restrictions)) {
182
+							continue;
183
+			}
177 184
 
178 185
 			// Prepare the link for context.
179 186
 			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
@@ -195,9 +202,10 @@  discard block
 block discarded – undo
195 202
 	$context['print_custom_fields'] = array();
196 203
 
197 204
 	// Any custom profile fields?
198
-	if (!empty($context['custom_fields']))
199
-		foreach ($context['custom_fields'] as $custom)
205
+	if (!empty($context['custom_fields'])) {
206
+			foreach ($context['custom_fields'] as $custom)
200 207
 			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
208
+	}
201 209
 
202 210
 }
203 211
 
@@ -222,8 +230,9 @@  discard block
 block discarded – undo
222 230
 	if (empty($user_info) || $user_info['id'] !== $memID)
223 231
 	{
224 232
 		$user_old = !empty($user_info) ? $user_info : null;
225
-		if (empty($user_profile[$memID]))
226
-			loadMemberData($memID, false, 'profile');
233
+		if (empty($user_profile[$memID])) {
234
+					loadMemberData($memID, false, 'profile');
235
+		}
227 236
 		$user_info = $user_profile[$memID];
228 237
 	}
229 238
 
@@ -254,16 +263,18 @@  discard block
 block discarded – undo
254 263
 		$row['extra'] = !empty($row['extra']) ? $smcFunc['json_decode']($row['extra'], true) : array();
255 264
 		$alerts[$id_alert] = $row;
256 265
 
257
-		if (!empty($row['sender_id']))
258
-			$senders[] = $row['sender_id'];
266
+		if (!empty($row['sender_id'])) {
267
+					$senders[] = $row['sender_id'];
268
+		}
259 269
 	}
260 270
 	$smcFunc['db_free_result']($request);
261 271
 
262 272
 	if($withSender)
263 273
 	{
264 274
 		$senders = loadMemberData($senders);
265
-		foreach ($senders as $member)
266
-			loadMemberContext($member);
275
+		foreach ($senders as $member) {
276
+					loadMemberContext($member);
277
+		}
267 278
 	}
268 279
 
269 280
 	// Now go through and actually make with the text.
@@ -278,12 +289,15 @@  discard block
 block discarded – undo
278 289
 	$msgs = array();
279 290
 	foreach ($alerts as $id_alert => $alert)
280 291
 	{
281
-		if (isset($alert['extra']['board']))
282
-			$boards[$alert['extra']['board']] = $txt['board_na'];
283
-		if (isset($alert['extra']['topic']))
284
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
285
-		if ($alert['content_type'] == 'msg')
286
-			$msgs[$alert['content_id']] = $txt['topic_na'];
292
+		if (isset($alert['extra']['board'])) {
293
+					$boards[$alert['extra']['board']] = $txt['board_na'];
294
+		}
295
+		if (isset($alert['extra']['topic'])) {
296
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
297
+		}
298
+		if ($alert['content_type'] == 'msg') {
299
+					$msgs[$alert['content_id']] = $txt['topic_na'];
300
+		}
287 301
 	}
288 302
 
289 303
 	// Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up.
@@ -298,8 +312,9 @@  discard block
 block discarded – undo
298 312
 				'boards' => array_keys($boards),
299 313
 			)
300 314
 		);
301
-		while ($row = $smcFunc['db_fetch_assoc']($request))
302
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
315
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
316
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
317
+		}
303 318
 	}
304 319
 	if (!empty($topics))
305 320
 	{
@@ -314,8 +329,9 @@  discard block
 block discarded – undo
314 329
 				'topics' => array_keys($topics),
315 330
 			)
316 331
 		);
317
-		while ($row = $smcFunc['db_fetch_assoc']($request))
318
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
332
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
333
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
334
+		}
319 335
 	}
320 336
 	if (!empty($msgs))
321 337
 	{
@@ -330,44 +346,51 @@  discard block
 block discarded – undo
330 346
 				'msgs' => array_keys($msgs),
331 347
 			)
332 348
 		);
333
-		while ($row = $smcFunc['db_fetch_assoc']($request))
334
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
349
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
350
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
351
+		}
335 352
 	}
336 353
 
337 354
 	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
338 355
 	foreach ($alerts as $id_alert => $alert)
339 356
 	{
340
-		if (!empty($alert['text']))
341
-			continue;
342
-		if (isset($alert['extra']['board']))
343
-			if ($boards[$alert['extra']['board']] == $txt['board_na'])
357
+		if (!empty($alert['text'])) {
358
+					continue;
359
+		}
360
+		if (isset($alert['extra']['board'])) {
361
+					if ($boards[$alert['extra']['board']] == $txt['board_na'])
344 362
 			{
345 363
 				unset($alerts[$id_alert]);
364
+		}
346 365
 				continue;
366
+			} else {
367
+							$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
347 368
 			}
348
-			else
349
-				$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
350
-		if (isset($alert['extra']['topic']))
351
-			if ($alert['extra']['topic'] == $txt['topic_na'])
369
+		if (isset($alert['extra']['topic'])) {
370
+					if ($alert['extra']['topic'] == $txt['topic_na'])
352 371
 			{
353 372
 				unset($alerts[$id_alert]);
373
+		}
354 374
 				continue;
375
+			} else {
376
+							$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
355 377
 			}
356
-			else
357
-				$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
358
-		if ($alert['content_type'] == 'msg')
359
-			if ($msgs[$alert['content_id']] == $txt['topic_na'])
378
+		if ($alert['content_type'] == 'msg') {
379
+					if ($msgs[$alert['content_id']] == $txt['topic_na'])
360 380
 			{
361 381
 				unset($alerts[$id_alert]);
382
+		}
362 383
 				continue;
384
+			} else {
385
+							$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
363 386
 			}
364
-			else
365
-				$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
366
-		if ($alert['content_type'] == 'profile')
367
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
387
+		if ($alert['content_type'] == 'profile') {
388
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
389
+		}
368 390
 
369
-		if (!empty($memberContext[$alert['sender_id']]))
370
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
391
+		if (!empty($memberContext[$alert['sender_id']])) {
392
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
393
+		}
371 394
 
372 395
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
373 396
 		if (isset($txt[$string]))
@@ -417,8 +440,8 @@  discard block
 block discarded – undo
417 440
 	$context['pagination'] = constructPageIndex($scripturl . '?action=profile;area=showalerts;u=' . $memID, $start, $count, $maxIndex, false);
418 441
 
419 442
 	// Set some JavaScript for checking all alerts at once.
420
-	if ($context['showCheckboxes'])
421
-		addInlineJavaScript('
443
+	if ($context['showCheckboxes']) {
444
+			addInlineJavaScript('
422 445
 		$(function(){
423 446
 			$(\'#select_all\').on(\'change\', function() {
424 447
 				var checkboxes = $(\'ul.quickbuttons\').find(\':checkbox\');
@@ -430,6 +453,7 @@  discard block
 block discarded – undo
430 453
 				}
431 454
 			});
432 455
 		});', true);
456
+	}
433 457
 
434 458
 	// Set a nice message.
435 459
 	if (!empty($_SESSION['update_message']))
@@ -461,11 +485,11 @@  discard block
 block discarded – undo
461 485
 		checkSession('request');
462 486
 
463 487
 		// Call it!
464
-		if ($action == 'remove')
465
-			alert_delete($toMark, $memID);
466
-
467
-		else
468
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
488
+		if ($action == 'remove') {
489
+					alert_delete($toMark, $memID);
490
+		} else {
491
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
492
+		}
469 493
 
470 494
 		// Set a nice update message.
471 495
 		$_SESSION['update_message'] = true;
@@ -515,23 +539,27 @@  discard block
 block discarded – undo
515 539
 	);
516 540
 
517 541
 	// Set the page title
518
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
519
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
520
-	else
521
-		$context['page_title'] = $txt['showPosts'];
542
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
543
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
544
+	} else {
545
+			$context['page_title'] = $txt['showPosts'];
546
+	}
522 547
 
523 548
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
524 549
 
525 550
 	// Is the load average too high to allow searching just now?
526
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
527
-		fatal_lang_error('loadavg_show_posts_disabled', false);
551
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
552
+			fatal_lang_error('loadavg_show_posts_disabled', false);
553
+	}
528 554
 
529 555
 	// If we're specifically dealing with attachments use that function!
530
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
531
-		return showAttachments($memID);
556
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
557
+			return showAttachments($memID);
558
+	}
532 559
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
533
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
534
-		return showUnwatched($memID);
560
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
561
+			return showUnwatched($memID);
562
+	}
535 563
 
536 564
 	// Are we just viewing topics?
537 565
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -554,27 +582,30 @@  discard block
 block discarded – undo
554 582
 		$smcFunc['db_free_result']($request);
555 583
 
556 584
 		// Trying to remove a message that doesn't exist.
557
-		if (empty($info))
558
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
585
+		if (empty($info)) {
586
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
587
+		}
559 588
 
560 589
 		// We can be lazy, since removeMessage() will check the permissions for us.
561 590
 		require_once($sourcedir . '/RemoveTopic.php');
562 591
 		removeMessage((int) $_GET['delete']);
563 592
 
564 593
 		// Add it to the mod log.
565
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
566
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
594
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
595
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
596
+		}
567 597
 
568 598
 		// Back to... where we are now ;).
569 599
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
570 600
 	}
571 601
 
572 602
 	// Default to 10.
573
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
574
-		$_REQUEST['viewscount'] = '10';
603
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
604
+			$_REQUEST['viewscount'] = '10';
605
+	}
575 606
 
576
-	if ($context['is_topics'])
577
-		$request = $smcFunc['db_query']('', '
607
+	if ($context['is_topics']) {
608
+			$request = $smcFunc['db_query']('', '
578 609
 			SELECT COUNT(*)
579 610
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
580 611
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -587,8 +618,8 @@  discard block
 block discarded – undo
587 618
 				'board' => $board,
588 619
 			)
589 620
 		);
590
-	else
591
-		$request = $smcFunc['db_query']('', '
621
+	} else {
622
+			$request = $smcFunc['db_query']('', '
592 623
 			SELECT COUNT(*)
593 624
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
594 625
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -601,6 +632,7 @@  discard block
 block discarded – undo
601 632
 				'board' => $board,
602 633
 			)
603 634
 		);
635
+	}
604 636
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
605 637
 	$smcFunc['db_free_result']($request);
606 638
 
@@ -621,10 +653,11 @@  discard block
 block discarded – undo
621 653
 
622 654
 	$range_limit = '';
623 655
 
624
-	if ($context['is_topics'])
625
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
626
-	else
627
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
656
+	if ($context['is_topics']) {
657
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
658
+	} else {
659
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
660
+	}
628 661
 
629 662
 	$maxIndex = $maxPerPage;
630 663
 
@@ -650,9 +683,9 @@  discard block
 block discarded – undo
650 683
 		{
651 684
 			$margin *= 5;
652 685
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
686
+		} else {
687
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
653 688
 		}
654
-		else
655
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
656 689
 	}
657 690
 
658 691
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -684,8 +717,7 @@  discard block
 block discarded – undo
684 717
 					'max' => $maxIndex,
685 718
 				)
686 719
 			);
687
-		}
688
-		else
720
+		} else
689 721
 		{
690 722
 			$request = $smcFunc['db_query']('', '
691 723
 				SELECT
@@ -714,8 +746,9 @@  discard block
 block discarded – undo
714 746
 		}
715 747
 
716 748
 		// Make sure we quit this loop.
717
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '')
718
-			break;
749
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '') {
750
+					break;
751
+		}
719 752
 		$looped = true;
720 753
 		$range_limit = '';
721 754
 	}
@@ -759,19 +792,21 @@  discard block
 block discarded – undo
759 792
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
760 793
 		);
761 794
 
762
-		if ($user_info['id'] == $row['id_member_started'])
763
-			$board_ids['own'][$row['id_board']][] = $counter;
795
+		if ($user_info['id'] == $row['id_member_started']) {
796
+					$board_ids['own'][$row['id_board']][] = $counter;
797
+		}
764 798
 		$board_ids['any'][$row['id_board']][] = $counter;
765 799
 	}
766 800
 	$smcFunc['db_free_result']($request);
767 801
 
768 802
 	// All posts were retrieved in reverse order, get them right again.
769
-	if ($reverse)
770
-		$context['posts'] = array_reverse($context['posts'], true);
803
+	if ($reverse) {
804
+			$context['posts'] = array_reverse($context['posts'], true);
805
+	}
771 806
 
772 807
 	// These are all the permissions that are different from board to board..
773
-	if ($context['is_topics'])
774
-		$permissions = array(
808
+	if ($context['is_topics']) {
809
+			$permissions = array(
775 810
 			'own' => array(
776 811
 				'post_reply_own' => 'can_reply',
777 812
 			),
@@ -779,8 +814,8 @@  discard block
 block discarded – undo
779 814
 				'post_reply_any' => 'can_reply',
780 815
 			)
781 816
 		);
782
-	else
783
-		$permissions = array(
817
+	} else {
818
+			$permissions = array(
784 819
 			'own' => array(
785 820
 				'post_reply_own' => 'can_reply',
786 821
 				'delete_own' => 'can_delete',
@@ -790,6 +825,7 @@  discard block
 block discarded – undo
790 825
 				'delete_any' => 'can_delete',
791 826
 			)
792 827
 		);
828
+	}
793 829
 
794 830
 	// For every permission in the own/any lists...
795 831
 	foreach ($permissions as $type => $list)
@@ -800,19 +836,22 @@  discard block
 block discarded – undo
800 836
 			$boards = boardsAllowedTo($permission);
801 837
 
802 838
 			// Hmm, they can do it on all boards, can they?
803
-			if (!empty($boards) && $boards[0] == 0)
804
-				$boards = array_keys($board_ids[$type]);
839
+			if (!empty($boards) && $boards[0] == 0) {
840
+							$boards = array_keys($board_ids[$type]);
841
+			}
805 842
 
806 843
 			// Now go through each board they can do the permission on.
807 844
 			foreach ($boards as $board_id)
808 845
 			{
809 846
 				// There aren't any posts displayed from this board.
810
-				if (!isset($board_ids[$type][$board_id]))
811
-					continue;
847
+				if (!isset($board_ids[$type][$board_id])) {
848
+									continue;
849
+				}
812 850
 
813 851
 				// Set the permission to true ;).
814
-				foreach ($board_ids[$type][$board_id] as $counter)
815
-					$context['posts'][$counter][$allowed] = true;
852
+				foreach ($board_ids[$type][$board_id] as $counter) {
853
+									$context['posts'][$counter][$allowed] = true;
854
+				}
816 855
 			}
817 856
 		}
818 857
 	}
@@ -843,8 +882,9 @@  discard block
 block discarded – undo
843 882
 	$boardsAllowed = boardsAllowedTo('view_attachments');
844 883
 
845 884
 	// Make sure we can't actually see anything...
846
-	if (empty($boardsAllowed))
847
-		$boardsAllowed = array(-1);
885
+	if (empty($boardsAllowed)) {
886
+			$boardsAllowed = array(-1);
887
+	}
848 888
 
849 889
 	require_once($sourcedir . '/Subs-List.php');
850 890
 
@@ -995,8 +1035,8 @@  discard block
 block discarded – undo
995 1035
 		)
996 1036
 	);
997 1037
 	$attachments = array();
998
-	while ($row = $smcFunc['db_fetch_assoc']($request))
999
-		$attachments[] = array(
1038
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1039
+			$attachments[] = array(
1000 1040
 			'id' => $row['id_attach'],
1001 1041
 			'filename' => $row['filename'],
1002 1042
 			'downloads' => $row['downloads'],
@@ -1008,6 +1048,7 @@  discard block
 block discarded – undo
1008 1048
 			'board_name' => $row['name'],
1009 1049
 			'approved' => $row['approved'],
1010 1050
 		);
1051
+	}
1011 1052
 
1012 1053
 	$smcFunc['db_free_result']($request);
1013 1054
 
@@ -1062,8 +1103,9 @@  discard block
 block discarded – undo
1062 1103
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1063 1104
 
1064 1105
 	// Only the owner can see the list (if the function is enabled of course)
1065
-	if ($user_info['id'] != $memID)
1066
-		return;
1106
+	if ($user_info['id'] != $memID) {
1107
+			return;
1108
+	}
1067 1109
 
1068 1110
 	require_once($sourcedir . '/Subs-List.php');
1069 1111
 
@@ -1209,8 +1251,9 @@  discard block
 block discarded – undo
1209 1251
 	);
1210 1252
 
1211 1253
 	$topics = array();
1212
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1213
-		$topics[] = $row['id_topic'];
1254
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1255
+			$topics[] = $row['id_topic'];
1256
+	}
1214 1257
 
1215 1258
 	$smcFunc['db_free_result']($request);
1216 1259
 
@@ -1230,8 +1273,9 @@  discard block
 block discarded – undo
1230 1273
 				'topics' => $topics,
1231 1274
 			)
1232 1275
 		);
1233
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1234
-			$topicsInfo[] = $row;
1276
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1277
+					$topicsInfo[] = $row;
1278
+		}
1235 1279
 		$smcFunc['db_free_result']($request);
1236 1280
 	}
1237 1281
 
@@ -1279,8 +1323,9 @@  discard block
 block discarded – undo
1279 1323
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1280 1324
 
1281 1325
 	// Is the load average too high to allow searching just now?
1282
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1283
-		fatal_lang_error('loadavg_userstats_disabled', false);
1326
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1327
+			fatal_lang_error('loadavg_userstats_disabled', false);
1328
+	}
1284 1329
 
1285 1330
 	// General user statistics.
1286 1331
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1423,11 +1468,13 @@  discard block
 block discarded – undo
1423 1468
 	}
1424 1469
 	$smcFunc['db_free_result']($result);
1425 1470
 
1426
-	if ($maxPosts > 0)
1427
-		for ($hour = 0; $hour < 24; $hour++)
1471
+	if ($maxPosts > 0) {
1472
+			for ($hour = 0;
1473
+	}
1474
+	$hour < 24; $hour++)
1428 1475
 		{
1429
-			if (!isset($context['posts_by_time'][$hour]))
1430
-				$context['posts_by_time'][$hour] = array(
1476
+			if (!isset($context['posts_by_time'][$hour])) {
1477
+							$context['posts_by_time'][$hour] = array(
1431 1478
 					'hour' => $hour,
1432 1479
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1433 1480
 					'posts' => 0,
@@ -1435,7 +1482,7 @@  discard block
 block discarded – undo
1435 1482
 					'relative_percent' => 0,
1436 1483
 					'is_last' => $hour == 23,
1437 1484
 				);
1438
-			else
1485
+			} else
1439 1486
 			{
1440 1487
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1441 1488
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1468,8 +1515,9 @@  discard block
 block discarded – undo
1468 1515
 
1469 1516
 	foreach ($subActions as $sa => $action)
1470 1517
 	{
1471
-		if (!allowedTo($action[2]))
1472
-			unset($subActions[$sa]);
1518
+		if (!allowedTo($action[2])) {
1519
+					unset($subActions[$sa]);
1520
+		}
1473 1521
 	}
1474 1522
 
1475 1523
 	// Create the tabs for the template.
@@ -1487,15 +1535,18 @@  discard block
 block discarded – undo
1487 1535
 	);
1488 1536
 
1489 1537
 	// Moderation must be on to track edits.
1490
-	if (empty($modSettings['userlog_enabled']))
1491
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1538
+	if (empty($modSettings['userlog_enabled'])) {
1539
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1540
+	}
1492 1541
 
1493 1542
 	// Group requests must be active to show it...
1494
-	if (empty($modSettings['show_group_membership']))
1495
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1543
+	if (empty($modSettings['show_group_membership'])) {
1544
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1545
+	}
1496 1546
 
1497
-	if (empty($subActions))
1498
-		fatal_lang_error('no_access', false);
1547
+	if (empty($subActions)) {
1548
+			fatal_lang_error('no_access', false);
1549
+	}
1499 1550
 
1500 1551
 	$keys = array_keys($subActions);
1501 1552
 	$default = array_shift($keys);
@@ -1508,9 +1559,10 @@  discard block
 block discarded – undo
1508 1559
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1509 1560
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1510 1561
 
1511
-	if (!empty($call))
1512
-		call_user_func($call, $memID);
1513
-}
1562
+	if (!empty($call)) {
1563
+			call_user_func($call, $memID);
1564
+	}
1565
+	}
1514 1566
 
1515 1567
 /**
1516 1568
  * Handles tracking a user's activity
@@ -1526,8 +1578,9 @@  discard block
 block discarded – undo
1526 1578
 	isAllowedTo('moderate_forum');
1527 1579
 
1528 1580
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1529
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1530
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1581
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1582
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1583
+	}
1531 1584
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1532 1585
 
1533 1586
 	// Set the options for the list component.
@@ -1694,8 +1747,9 @@  discard block
 block discarded – undo
1694 1747
 			)
1695 1748
 		);
1696 1749
 		$message_members = array();
1697
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1698
-			$message_members[] = $row['id_member'];
1750
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1751
+					$message_members[] = $row['id_member'];
1752
+		}
1699 1753
 		$smcFunc['db_free_result']($request);
1700 1754
 
1701 1755
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1710,8 +1764,9 @@  discard block
 block discarded – undo
1710 1764
 					'ip_list' => $ips,
1711 1765
 				)
1712 1766
 			);
1713
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1714
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1767
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1768
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1769
+			}
1715 1770
 			$smcFunc['db_free_result']($request);
1716 1771
 		}
1717 1772
 
@@ -1725,8 +1780,9 @@  discard block
 block discarded – undo
1725 1780
 				'ip_list' => $ips,
1726 1781
 			)
1727 1782
 		);
1728
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1729
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1783
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1784
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1785
+		}
1730 1786
 		$smcFunc['db_free_result']($request);
1731 1787
 	}
1732 1788
 }
@@ -1786,8 +1842,8 @@  discard block
 block discarded – undo
1786 1842
 		))
1787 1843
 	);
1788 1844
 	$error_messages = array();
1789
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1790
-		$error_messages[] = array(
1845
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1846
+			$error_messages[] = array(
1791 1847
 			'ip' => inet_dtop($row['ip']),
1792 1848
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1793 1849
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1795,6 +1851,7 @@  discard block
 block discarded – undo
1795 1851
 			'time' => timeformat($row['log_time']),
1796 1852
 			'timestamp' => forum_time(true, $row['log_time']),
1797 1853
 		);
1854
+	}
1798 1855
 	$smcFunc['db_free_result']($request);
1799 1856
 
1800 1857
 	return $error_messages;
@@ -1857,8 +1914,8 @@  discard block
 block discarded – undo
1857 1914
 		))
1858 1915
 	);
1859 1916
 	$messages = array();
1860
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1861
-		$messages[] = array(
1917
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1918
+			$messages[] = array(
1862 1919
 			'ip' => inet_dtop($row['poster_ip']),
1863 1920
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1864 1921
 			'board' => array(
@@ -1871,6 +1928,7 @@  discard block
 block discarded – undo
1871 1928
 			'time' => timeformat($row['poster_time']),
1872 1929
 			'timestamp' => forum_time(true, $row['poster_time'])
1873 1930
 		);
1931
+	}
1874 1932
 	$smcFunc['db_free_result']($request);
1875 1933
 
1876 1934
 	return $messages;
@@ -1897,19 +1955,20 @@  discard block
 block discarded – undo
1897 1955
 		$context['sub_template'] = 'trackIP';
1898 1956
 		$context['page_title'] = $txt['profile'];
1899 1957
 		$context['base_url'] = $scripturl . '?action=trackip';
1900
-	}
1901
-	else
1958
+	} else
1902 1959
 	{
1903 1960
 		$context['ip'] = ip2range($user_profile[$memID]['member_ip']);
1904 1961
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1905 1962
 	}
1906 1963
 
1907 1964
 	// Searching?
1908
-	if (isset($_REQUEST['searchip']))
1909
-		$context['ip'] = ip2range(trim($_REQUEST['searchip']));
1965
+	if (isset($_REQUEST['searchip'])) {
1966
+			$context['ip'] = ip2range(trim($_REQUEST['searchip']));
1967
+	}
1910 1968
 
1911
-	if (count($context['ip']) !== 2)
1912
-		fatal_lang_error('invalid_tracking_ip', false);
1969
+	if (count($context['ip']) !== 2) {
1970
+			fatal_lang_error('invalid_tracking_ip', false);
1971
+	}
1913 1972
 
1914 1973
 	$ip_string = array('{inet:ip_address_low}','{inet:ip_address_high}');
1915 1974
 	$fields = array(
@@ -1919,13 +1978,15 @@  discard block
 block discarded – undo
1919 1978
 
1920 1979
 	$ip_var = $context['ip'];
1921 1980
 
1922
-	if ($context['ip']['low'] !==  $context['ip']['high'])
1923
-		$context['ip'] = $context['ip']['low'] . ' - ' . $context['ip']['high'];
1924
-	else
1925
-		$context['ip'] = $context['ip']['low'];
1981
+	if ($context['ip']['low'] !==  $context['ip']['high']) {
1982
+			$context['ip'] = $context['ip']['low'] . ' - ' . $context['ip']['high'];
1983
+	} else {
1984
+			$context['ip'] = $context['ip']['low'];
1985
+	}
1926 1986
 
1927
-	if (empty($context['tracking_area']))
1928
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1987
+	if (empty($context['tracking_area'])) {
1988
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1989
+	}
1929 1990
 
1930 1991
 	$request = $smcFunc['db_query']('', '
1931 1992
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1934,8 +1995,9 @@  discard block
 block discarded – undo
1934 1995
 		$fields
1935 1996
 	);
1936 1997
 	$context['ips'] = array();
1937
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1938
-		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1998
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1999
+			$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
2000
+	}
1939 2001
 	$smcFunc['db_free_result']($request);
1940 2002
 
1941 2003
 	ksort($context['ips']);
@@ -2165,10 +2227,11 @@  discard block
 block discarded – undo
2165 2227
 	// Gonna want this for the list.
2166 2228
 	require_once($sourcedir . '/Subs-List.php');
2167 2229
 
2168
-	if ($memID == 0)
2169
-		$context['base_url'] = $scripturl . '?action=trackip';
2170
-	else
2171
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2230
+	if ($memID == 0) {
2231
+			$context['base_url'] = $scripturl . '?action=trackip';
2232
+	} else {
2233
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2234
+	}
2172 2235
 
2173 2236
 	// Start with the user messages.
2174 2237
 	$listOptions = array(
@@ -2278,12 +2341,13 @@  discard block
 block discarded – undo
2278 2341
 		)
2279 2342
 	);
2280 2343
 	$logins = array();
2281
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2282
-		$logins[] = array(
2344
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2345
+			$logins[] = array(
2283 2346
 			'time' => timeformat($row['time']),
2284 2347
 			'ip' => inet_dtop($row['ip']),
2285 2348
 			'ip2' => inet_dtop($row['ip2']),
2286 2349
 		);
2350
+	}
2287 2351
 	$smcFunc['db_free_result']($request);
2288 2352
 
2289 2353
 	return $logins;
@@ -2308,11 +2372,12 @@  discard block
 block discarded – undo
2308 2372
 		)
2309 2373
 	);
2310 2374
 	$context['custom_field_titles'] = array();
2311
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2312
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2375
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2376
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2313 2377
 			'title' => $row['field_name'],
2314 2378
 			'parse_bbc' => $row['bbc'],
2315 2379
 		);
2380
+	}
2316 2381
 	$smcFunc['db_free_result']($request);
2317 2382
 
2318 2383
 	// Set the options for the error lists.
@@ -2451,19 +2516,22 @@  discard block
 block discarded – undo
2451 2516
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2452 2517
 	{
2453 2518
 		$extra = $smcFunc['json_decode']($row['extra'], true);
2454
-		if (!empty($extra['applicator']))
2455
-			$members[] = $extra['applicator'];
2519
+		if (!empty($extra['applicator'])) {
2520
+					$members[] = $extra['applicator'];
2521
+		}
2456 2522
 
2457 2523
 		// Work out what the name of the action is.
2458
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2459
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2460
-		elseif (isset($txt[$row['action']]))
2461
-			$action_text = $txt[$row['action']];
2524
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2525
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2526
+		} elseif (isset($txt[$row['action']])) {
2527
+					$action_text = $txt[$row['action']];
2528
+		}
2462 2529
 		// Custom field?
2463
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2464
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2465
-		else
2466
-			$action_text = $row['action'];
2530
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2531
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2532
+		} else {
2533
+					$action_text = $row['action'];
2534
+		}
2467 2535
 
2468 2536
 		// Parse BBC?
2469 2537
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2495,13 +2563,15 @@  discard block
 block discarded – undo
2495 2563
 			)
2496 2564
 		);
2497 2565
 		$members = array();
2498
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2499
-			$members[$row['id_member']] = $row['real_name'];
2566
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2567
+					$members[$row['id_member']] = $row['real_name'];
2568
+		}
2500 2569
 		$smcFunc['db_free_result']($request);
2501 2570
 
2502
-		foreach ($edits as $key => $value)
2503
-			if (isset($members[$value['id_member']]))
2571
+		foreach ($edits as $key => $value) {
2572
+					if (isset($members[$value['id_member']]))
2504 2573
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2574
+		}
2505 2575
 	}
2506 2576
 
2507 2577
 	return $edits;
@@ -2702,10 +2772,11 @@  discard block
 block discarded – undo
2702 2772
 	$context['board'] = $board;
2703 2773
 
2704 2774
 	// Determine which groups this user is in.
2705
-	if (empty($user_profile[$memID]['additional_groups']))
2706
-		$curGroups = array();
2707
-	else
2708
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2775
+	if (empty($user_profile[$memID]['additional_groups'])) {
2776
+			$curGroups = array();
2777
+	} else {
2778
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2779
+	}
2709 2780
 	$curGroups[] = $user_profile[$memID]['id_group'];
2710 2781
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2711 2782
 
@@ -2725,28 +2796,30 @@  discard block
 block discarded – undo
2725 2796
 	$context['no_access_boards'] = array();
2726 2797
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2727 2798
 	{
2728
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2729
-			$context['no_access_boards'][] = array(
2799
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2800
+					$context['no_access_boards'][] = array(
2730 2801
 				'id' => $row['id_board'],
2731 2802
 				'name' => $row['name'],
2732 2803
 				'is_last' => false,
2733 2804
 			);
2734
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2735
-			$context['boards'][$row['id_board']] = array(
2805
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2806
+					$context['boards'][$row['id_board']] = array(
2736 2807
 				'id' => $row['id_board'],
2737 2808
 				'name' => $row['name'],
2738 2809
 				'selected' => $board == $row['id_board'],
2739 2810
 				'profile' => $row['id_profile'],
2740 2811
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2741 2812
 			);
2813
+		}
2742 2814
 	}
2743 2815
 	$smcFunc['db_free_result']($request);
2744 2816
 
2745 2817
 	require_once($sourcedir . '/Subs-Boards.php');
2746 2818
 	sortBoards($context['boards']);
2747 2819
 
2748
-	if (!empty($context['no_access_boards']))
2749
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2820
+	if (!empty($context['no_access_boards'])) {
2821
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2822
+	}
2750 2823
 
2751 2824
 	$context['member']['permissions'] = array(
2752 2825
 		'general' => array(),
@@ -2755,8 +2828,9 @@  discard block
 block discarded – undo
2755 2828
 
2756 2829
 	// If you're an admin we know you can do everything, we might as well leave.
2757 2830
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2758
-	if ($context['member']['has_all_permissions'])
2759
-		return;
2831
+	if ($context['member']['has_all_permissions']) {
2832
+			return;
2833
+	}
2760 2834
 
2761 2835
 	$denied = array();
2762 2836
 
@@ -2775,21 +2849,24 @@  discard block
 block discarded – undo
2775 2849
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2776 2850
 	{
2777 2851
 		// We don't know about this permission, it doesn't exist :P.
2778
-		if (!isset($txt['permissionname_' . $row['permission']]))
2779
-			continue;
2852
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2853
+					continue;
2854
+		}
2780 2855
 
2781
-		if (empty($row['add_deny']))
2782
-			$denied[] = $row['permission'];
2856
+		if (empty($row['add_deny'])) {
2857
+					$denied[] = $row['permission'];
2858
+		}
2783 2859
 
2784 2860
 		// Permissions that end with _own or _any consist of two parts.
2785
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2786
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2787
-		else
2788
-			$name = $txt['permissionname_' . $row['permission']];
2861
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2862
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2863
+		} else {
2864
+					$name = $txt['permissionname_' . $row['permission']];
2865
+		}
2789 2866
 
2790 2867
 		// Add this permission if it doesn't exist yet.
2791
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2792
-			$context['member']['permissions']['general'][$row['permission']] = array(
2868
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2869
+					$context['member']['permissions']['general'][$row['permission']] = array(
2793 2870
 				'id' => $row['permission'],
2794 2871
 				'groups' => array(
2795 2872
 					'allowed' => array(),
@@ -2799,6 +2876,7 @@  discard block
 block discarded – undo
2799 2876
 				'is_denied' => false,
2800 2877
 				'is_global' => true,
2801 2878
 			);
2879
+		}
2802 2880
 
2803 2881
 		// Add the membergroup to either the denied or the allowed groups.
2804 2882
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2832,18 +2910,20 @@  discard block
 block discarded – undo
2832 2910
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2833 2911
 	{
2834 2912
 		// We don't know about this permission, it doesn't exist :P.
2835
-		if (!isset($txt['permissionname_' . $row['permission']]))
2836
-			continue;
2913
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2914
+					continue;
2915
+		}
2837 2916
 
2838 2917
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2839
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2840
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2841
-		else
2842
-			$name = $txt['permissionname_' . $row['permission']];
2918
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2919
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2920
+		} else {
2921
+					$name = $txt['permissionname_' . $row['permission']];
2922
+		}
2843 2923
 
2844 2924
 		// Create the structure for this permission.
2845
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2846
-			$context['member']['permissions']['board'][$row['permission']] = array(
2925
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2926
+					$context['member']['permissions']['board'][$row['permission']] = array(
2847 2927
 				'id' => $row['permission'],
2848 2928
 				'groups' => array(
2849 2929
 					'allowed' => array(),
@@ -2853,6 +2933,7 @@  discard block
 block discarded – undo
2853 2933
 				'is_denied' => false,
2854 2934
 				'is_global' => empty($board),
2855 2935
 			);
2936
+		}
2856 2937
 
2857 2938
 		$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
2858 2939
 
@@ -2871,8 +2952,9 @@  discard block
 block discarded – undo
2871 2952
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2872 2953
 
2873 2954
 	// Firstly, can we actually even be here?
2874
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2875
-		fatal_lang_error('no_access', false);
2955
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2956
+			fatal_lang_error('no_access', false);
2957
+	}
2876 2958
 
2877 2959
 	// Make sure things which are disabled stay disabled.
2878 2960
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2959,9 +3041,10 @@  discard block
 block discarded – undo
2959 3041
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2960 3042
 	);
2961 3043
 	$context['current_level'] = 0;
2962
-	foreach ($context['level_effects'] as $limit => $dummy)
2963
-		if ($context['member']['warning'] >= $limit)
3044
+	foreach ($context['level_effects'] as $limit => $dummy) {
3045
+			if ($context['member']['warning'] >= $limit)
2964 3046
 			$context['current_level'] = $limit;
2965
-}
3047
+	}
3048
+	}
2966 3049
 
2967 3050
 ?>
2968 3051
\ No newline at end of file
Please login to merge, or discard this patch.
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();
@@ -650,8 +684,9 @@  discard block
 block discarded – undo
650 684
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
651 685
 
652 686
 		// Did they not elect to choose this?
653
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
654
-			continue;
687
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
688
+					continue;
689
+		}
655 690
 
656 691
 		// Right character set!
657 692
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -667,39 +702,43 @@  discard block
 block discarded – undo
667 702
 		if (isset($types['topic']))
668 703
 		{
669 704
 			$titled = false;
670
-			foreach ($types['topic'] as $id => $board)
671
-				foreach ($board['lines'] as $topic)
705
+			foreach ($types['topic'] as $id => $board) {
706
+							foreach ($board['lines'] as $topic)
672 707
 					if (in_array($mid, $topic['members']))
673 708
 					{
674 709
 						if (!$titled)
675 710
 						{
676 711
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
712
+			}
677 713
 							$titled = true;
678 714
 						}
679 715
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
680 716
 					}
681
-			if ($titled)
682
-				$email['body'] .= "\n";
717
+			if ($titled) {
718
+							$email['body'] .= "\n";
719
+			}
683 720
 		}
684 721
 
685 722
 		// What about replies?
686 723
 		if (isset($types['reply']))
687 724
 		{
688 725
 			$titled = false;
689
-			foreach ($types['reply'] as $id => $board)
690
-				foreach ($board['lines'] as $topic)
726
+			foreach ($types['reply'] as $id => $board) {
727
+							foreach ($board['lines'] as $topic)
691 728
 					if (in_array($mid, $topic['members']))
692 729
 					{
693 730
 						if (!$titled)
694 731
 						{
695 732
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
733
+			}
696 734
 							$titled = true;
697 735
 						}
698 736
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
699 737
 					}
700 738
 
701
-			if ($titled)
702
-				$email['body'] .= "\n";
739
+			if ($titled) {
740
+							$email['body'] .= "\n";
741
+			}
703 742
 		}
704 743
 
705 744
 		// Finally, moderation actions!
@@ -708,24 +747,27 @@  discard block
 block discarded – undo
708 747
 			$titled = false;
709 748
 			foreach ($types as $note_type => $type)
710 749
 			{
711
-				if ($note_type == 'topic' || $note_type == 'reply')
712
-					continue;
750
+				if ($note_type == 'topic' || $note_type == 'reply') {
751
+									continue;
752
+				}
713 753
 
714
-				foreach ($type as $id => $board)
715
-					foreach ($board['lines'] as $topic)
754
+				foreach ($type as $id => $board) {
755
+									foreach ($board['lines'] as $topic)
716 756
 						if (in_array($mid, $topic['members']))
717 757
 						{
718 758
 							if (!$titled)
719 759
 							{
720 760
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
761
+				}
721 762
 								$titled = true;
722 763
 							}
723 764
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
724 765
 						}
725 766
 			}
726 767
 		}
727
-		if ($titled)
728
-			$email['body'] .= "\n";
768
+		if ($titled) {
769
+					$email['body'] .= "\n";
770
+		}
729 771
 
730 772
 		// Then just say our goodbyes!
731 773
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -753,8 +795,7 @@  discard block
 block discarded – undo
753 795
 				'not_daily' => 0,
754 796
 			)
755 797
 		);
756
-	}
757
-	else
798
+	} else
758 799
 	{
759 800
 		// Clear any only weekly ones, and stop us from sending daily again.
760 801
 		$smcFunc['db_query']('', '
@@ -816,16 +857,19 @@  discard block
 block discarded – undo
816 857
 	global $modSettings, $smcFunc, $sourcedir;
817 858
 
818 859
 	// Are we intending another script to be sending out the queue?
819
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
820
-		return false;
860
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
861
+			return false;
862
+	}
821 863
 
822 864
 	// By default send 5 at once.
823
-	if (!$number)
824
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
865
+	if (!$number) {
866
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
867
+	}
825 868
 
826 869
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
827
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
828
-		return false;
870
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
871
+			return false;
872
+	}
829 873
 
830 874
 	// By default move the next sending on by 10 seconds, and require an affected row.
831 875
 	if (!$override_limit)
@@ -842,8 +886,9 @@  discard block
 block discarded – undo
842 886
 				'last_send' => $modSettings['mail_next_send'],
843 887
 			)
844 888
 		);
845
-		if ($smcFunc['db_affected_rows']() == 0)
846
-			return false;
889
+		if ($smcFunc['db_affected_rows']() == 0) {
890
+					return false;
891
+		}
847 892
 		$modSettings['mail_next_send'] = time() + $delay;
848 893
 	}
849 894
 
@@ -864,8 +909,9 @@  discard block
 block discarded – undo
864 909
 			$mn += $number;
865 910
 		}
866 911
 		// No more I'm afraid, return!
867
-		else
868
-			return false;
912
+		else {
913
+					return false;
914
+		}
869 915
 
870 916
 		// Reflect that we're about to send some, do it now to be safe.
871 917
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -900,14 +946,15 @@  discard block
 block discarded – undo
900 946
 	$smcFunc['db_free_result']($request);
901 947
 
902 948
 	// Delete, delete, delete!!!
903
-	if (!empty($ids))
904
-		$smcFunc['db_query']('', '
949
+	if (!empty($ids)) {
950
+			$smcFunc['db_query']('', '
905 951
 			DELETE FROM {db_prefix}mail_queue
906 952
 			WHERE id_mail IN ({array_int:mail_list})',
907 953
 			array(
908 954
 				'mail_list' => $ids,
909 955
 			)
910 956
 		);
957
+	}
911 958
 
912 959
 	// Don't believe we have any left?
913 960
 	if (count($ids) < $number)
@@ -925,11 +972,13 @@  discard block
 block discarded – undo
925 972
 		);
926 973
 	}
927 974
 
928
-	if (empty($ids))
929
-		return false;
975
+	if (empty($ids)) {
976
+			return false;
977
+	}
930 978
 
931
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
932
-		require_once($sourcedir . '/Subs-Post.php');
979
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
980
+			require_once($sourcedir . '/Subs-Post.php');
981
+	}
933 982
 
934 983
 	// Send each email, yea!
935 984
 	$failed_emails = array();
@@ -949,15 +998,17 @@  discard block
 block discarded – undo
949 998
 
950 999
 			// Try to stop a timeout, this would be bad...
951 1000
 			@set_time_limit(300);
952
-			if (function_exists('apache_reset_timeout'))
953
-				@apache_reset_timeout();
1001
+			if (function_exists('apache_reset_timeout')) {
1002
+							@apache_reset_timeout();
1003
+			}
1004
+		} else {
1005
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
954 1006
 		}
955
-		else
956
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
957 1007
 
958 1008
 		// Hopefully it sent?
959
-		if (!$result)
960
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1009
+		if (!$result) {
1010
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
1011
+		}
961 1012
 	}
962 1013
 
963 1014
 	// Any emails that didn't send?
@@ -972,8 +1023,8 @@  discard block
 block discarded – undo
972 1023
 		);
973 1024
 
974 1025
 		// If we have failed to many times, tell mail to wait a bit and try again.
975
-		if ($modSettings['mail_failed_attempts'] > 5)
976
-			$smcFunc['db_query']('', '
1026
+		if ($modSettings['mail_failed_attempts'] > 5) {
1027
+					$smcFunc['db_query']('', '
977 1028
 				UPDATE {db_prefix}settings
978 1029
 				SET value = {string:next_mail_send}
979 1030
 				WHERE variable = {literal:mail_next_send}
@@ -982,6 +1033,7 @@  discard block
 block discarded – undo
982 1033
 					'next_mail_send' => time() + 60,
983 1034
 					'last_send' => $modSettings['mail_next_send'],
984 1035
 			));
1036
+		}
985 1037
 
986 1038
 		// Add our email back to the queue, manually.
987 1039
 		$smcFunc['db_insert']('insert',
@@ -994,8 +1046,8 @@  discard block
 block discarded – undo
994 1046
 		return false;
995 1047
 	}
996 1048
 	// We where unable to send the email, clear our failed attempts.
997
-	elseif (!empty($modSettings['mail_failed_attempts']))
998
-		$smcFunc['db_query']('', '
1049
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1050
+			$smcFunc['db_query']('', '
999 1051
 			UPDATE {db_prefix}settings
1000 1052
 			SET value = {string:zero}
1001 1053
 			WHERE variable = {string:mail_failed_attempts}',
@@ -1003,6 +1055,7 @@  discard block
 block discarded – undo
1003 1055
 				'zero' => '0',
1004 1056
 				'mail_failed_attempts' => 'mail_failed_attempts',
1005 1057
 		));
1058
+	}
1006 1059
 
1007 1060
 	// Had something to send...
1008 1061
 	return true;
@@ -1019,16 +1072,18 @@  discard block
 block discarded – undo
1019 1072
 	global $modSettings, $smcFunc;
1020 1073
 
1021 1074
 	$task_query = '';
1022
-	if (!is_array($tasks))
1023
-		$tasks = array($tasks);
1075
+	if (!is_array($tasks)) {
1076
+			$tasks = array($tasks);
1077
+	}
1024 1078
 
1025 1079
 	// Actually have something passed?
1026 1080
 	if (!empty($tasks))
1027 1081
 	{
1028
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1029
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1030
-		else
1031
-			$task_query = ' AND task IN ({array_string:tasks})';
1082
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1083
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1084
+		} else {
1085
+					$task_query = ' AND task IN ({array_string:tasks})';
1086
+		}
1032 1087
 	}
1033 1088
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1034 1089
 
@@ -1049,20 +1104,22 @@  discard block
 block discarded – undo
1049 1104
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1050 1105
 
1051 1106
 		// Only bother moving the task if it's out of place or we're forcing it!
1052
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1053
-			$tasks[$row['id_task']] = $next_time;
1054
-		else
1055
-			$next_time = $row['next_time'];
1107
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1108
+					$tasks[$row['id_task']] = $next_time;
1109
+		} else {
1110
+					$next_time = $row['next_time'];
1111
+		}
1056 1112
 
1057 1113
 		// If this is sooner than the current next task, make this the next task.
1058
-		if ($next_time < $nextTaskTime)
1059
-			$nextTaskTime = $next_time;
1114
+		if ($next_time < $nextTaskTime) {
1115
+					$nextTaskTime = $next_time;
1116
+		}
1060 1117
 	}
1061 1118
 	$smcFunc['db_free_result']($request);
1062 1119
 
1063 1120
 	// Now make the changes!
1064
-	foreach ($tasks as $id => $time)
1065
-		$smcFunc['db_query']('', '
1121
+	foreach ($tasks as $id => $time) {
1122
+			$smcFunc['db_query']('', '
1066 1123
 			UPDATE {db_prefix}scheduled_tasks
1067 1124
 			SET next_time = {int:next_time}
1068 1125
 			WHERE id_task = {int:id_task}',
@@ -1071,11 +1128,13 @@  discard block
 block discarded – undo
1071 1128
 				'id_task' => $id,
1072 1129
 			)
1073 1130
 		);
1131
+	}
1074 1132
 
1075 1133
 	// If the next task is now different update.
1076
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1077
-		updateSettings(array('next_task_time' => $nextTaskTime));
1078
-}
1134
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1135
+			updateSettings(array('next_task_time' => $nextTaskTime));
1136
+	}
1137
+	}
1079 1138
 
1080 1139
 /**
1081 1140
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1088,8 +1147,9 @@  discard block
 block discarded – undo
1088 1147
 function next_time($regularity, $unit, $offset)
1089 1148
 {
1090 1149
 	// Just in case!
1091
-	if ($regularity == 0)
1092
-		$regularity = 2;
1150
+	if ($regularity == 0) {
1151
+			$regularity = 2;
1152
+	}
1093 1153
 
1094 1154
 	$curMin = date('i', time());
1095 1155
 
@@ -1099,15 +1159,16 @@  discard block
 block discarded – undo
1099 1159
 		$off = date('i', $offset);
1100 1160
 
1101 1161
 		// If it's now just pretend it ain't,
1102
-		if ($off == $curMin)
1103
-			$next_time = time() + $regularity;
1104
-		else
1162
+		if ($off == $curMin) {
1163
+					$next_time = time() + $regularity;
1164
+		} else
1105 1165
 		{
1106 1166
 			// Make sure that the offset is always in the past.
1107 1167
 			$off = $off > $curMin ? $off - 60 : $off;
1108 1168
 
1109
-			while ($off <= $curMin)
1110
-				$off += $regularity;
1169
+			while ($off <= $curMin) {
1170
+							$off += $regularity;
1171
+			}
1111 1172
 
1112 1173
 			// Now we know when the time should be!
1113 1174
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1127,11 +1188,13 @@  discard block
 block discarded – undo
1127 1188
 		// Default we'll jump in hours.
1128 1189
 		$applyOffset = 3600;
1129 1190
 		// 24 hours = 1 day.
1130
-		if ($unit == 'd')
1131
-			$applyOffset = 86400;
1191
+		if ($unit == 'd') {
1192
+					$applyOffset = 86400;
1193
+		}
1132 1194
 		// Otherwise a week.
1133
-		if ($unit == 'w')
1134
-			$applyOffset = 604800;
1195
+		if ($unit == 'w') {
1196
+					$applyOffset = 604800;
1197
+		}
1135 1198
 
1136 1199
 		$applyOffset *= $regularity;
1137 1200
 
@@ -1168,8 +1231,9 @@  discard block
 block discarded – undo
1168 1231
 		$settings[$row['variable']] = $row['value'];
1169 1232
 
1170 1233
 		// Is this the default theme?
1171
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1172
-			$settings['default_' . $row['variable']] = $row['value'];
1234
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1235
+					$settings['default_' . $row['variable']] = $row['value'];
1236
+		}
1173 1237
 	}
1174 1238
 	$smcFunc['db_free_result']($result);
1175 1239
 
@@ -1179,12 +1243,14 @@  discard block
 block discarded – undo
1179 1243
 		$settings['template_dirs'] = array($settings['theme_dir']);
1180 1244
 
1181 1245
 		// Based on theme (if there is one).
1182
-		if (!empty($settings['base_theme_dir']))
1183
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1246
+		if (!empty($settings['base_theme_dir'])) {
1247
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1248
+		}
1184 1249
 
1185 1250
 		// Lastly the default theme.
1186
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1187
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1251
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1252
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1253
+		}
1188 1254
 	}
1189 1255
 
1190 1256
 	// Assume we want this.
@@ -1328,8 +1394,9 @@  discard block
 block discarded – undo
1328 1394
 	// Ok should we prune the logs?
1329 1395
 	if (!empty($modSettings['pruningOptions']))
1330 1396
 	{
1331
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1332
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1397
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1398
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1399
+		}
1333 1400
 
1334 1401
 		if (!empty($modSettings['pruneErrorLog']))
1335 1402
 		{
@@ -1395,8 +1462,9 @@  discard block
 block discarded – undo
1395 1462
 				)
1396 1463
 			);
1397 1464
 
1398
-			while ($row = $smcFunc['db_fetch_row']($result))
1399
-				$reports[] = $row[0];
1465
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1466
+							$reports[] = $row[0];
1467
+			}
1400 1468
 
1401 1469
 			$smcFunc['db_free_result']($result);
1402 1470
 
@@ -1481,8 +1549,9 @@  discard block
 block discarded – undo
1481 1549
 	);
1482 1550
 
1483 1551
 	// Run Cache housekeeping
1484
-	if (!empty($cache_enable) && !empty($cacheAPI))
1485
-		$cacheAPI->housekeeping();
1552
+	if (!empty($cache_enable) && !empty($cacheAPI)) {
1553
+			$cacheAPI->housekeeping();
1554
+	}
1486 1555
 
1487 1556
 	// Prevent stale minimized CSS and JavaScript from cluttering up the theme directories
1488 1557
 	deleteAllMinified();
@@ -1565,8 +1634,9 @@  discard block
 block discarded – undo
1565 1634
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1566 1635
 
1567 1636
 		// Send the actual email.
1568
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1569
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1637
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1638
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1639
+		}
1570 1640
 
1571 1641
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1572 1642
 		{
@@ -1589,18 +1659,19 @@  discard block
 block discarded – undo
1589 1659
 	}
1590 1660
 
1591 1661
 	// Insert the alerts if any
1592
-	if (!empty($alert_rows))
1593
-		$smcFunc['db_insert']('',
1662
+	if (!empty($alert_rows)) {
1663
+			$smcFunc['db_insert']('',
1594 1664
 			'{db_prefix}user_alerts',
1595 1665
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1596 1666
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1597 1667
 			$alert_rows,
1598 1668
 			array()
1599 1669
 		);
1670
+	}
1600 1671
 
1601 1672
 	// Mark the reminder as sent.
1602
-	if (!empty($subs_reminded))
1603
-		$smcFunc['db_query']('', '
1673
+	if (!empty($subs_reminded)) {
1674
+			$smcFunc['db_query']('', '
1604 1675
 			UPDATE {db_prefix}log_subscribed
1605 1676
 			SET reminder_sent = {int:reminder_sent}
1606 1677
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1609,6 +1680,7 @@  discard block
 block discarded – undo
1609 1680
 				'reminder_sent' => 1,
1610 1681
 			)
1611 1682
 		);
1683
+	}
1612 1684
 
1613 1685
 	return true;
1614 1686
 }
@@ -1624,13 +1696,13 @@  discard block
 block discarded – undo
1624 1696
 	// We need to know where this thing is going.
1625 1697
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1626 1698
 	{
1627
-		if (!is_array($modSettings['attachmentUploadDir']))
1628
-			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1699
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1700
+					$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1701
+		}
1629 1702
 
1630 1703
 		// Just use the current path for temp files.
1631 1704
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1632
-	}
1633
-	else
1705
+	} else
1634 1706
 	{
1635 1707
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1636 1708
 	}
@@ -1649,14 +1721,16 @@  discard block
 block discarded – undo
1649 1721
 
1650 1722
 		while ($file = readdir($dir))
1651 1723
 		{
1652
-			if ($file == '.' || $file == '..')
1653
-				continue;
1724
+			if ($file == '.' || $file == '..') {
1725
+							continue;
1726
+			}
1654 1727
 
1655 1728
 			if (strpos($file, 'post_tmp_') !== false)
1656 1729
 			{
1657 1730
 				// Temp file is more than 5 hours old!
1658
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1659
-					@unlink($attach_dir . '/' . $file);
1731
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1732
+									@unlink($attach_dir . '/' . $file);
1733
+				}
1660 1734
 			}
1661 1735
 		}
1662 1736
 		closedir($dir);
@@ -1689,8 +1763,9 @@  discard block
 block discarded – undo
1689 1763
 		)
1690 1764
 	);
1691 1765
 
1692
-	while ($row = $smcFunc['db_fetch_row']($request))
1693
-		$topics[] = $row[0];
1766
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1767
+			$topics[] = $row[0];
1768
+	}
1694 1769
 	$smcFunc['db_free_result']($request);
1695 1770
 
1696 1771
 	// Zap, your gone
@@ -1710,8 +1785,9 @@  discard block
 block discarded – undo
1710 1785
 {
1711 1786
 	global $smcFunc, $sourcedir, $modSettings;
1712 1787
 
1713
-	if (empty($modSettings['drafts_keep_days']))
1714
-		return true;
1788
+	if (empty($modSettings['drafts_keep_days'])) {
1789
+			return true;
1790
+	}
1715 1791
 
1716 1792
 	// init
1717 1793
 	$drafts = array();
@@ -1729,8 +1805,9 @@  discard block
 block discarded – undo
1729 1805
 		)
1730 1806
 	);
1731 1807
 
1732
-	while ($row = $smcFunc['db_fetch_row']($request))
1733
-		$drafts[] = (int) $row[0];
1808
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1809
+			$drafts[] = (int) $row[0];
1810
+	}
1734 1811
 	$smcFunc['db_free_result']($request);
1735 1812
 
1736 1813
 	// 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   +523 added lines, -391 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
 		{
@@ -1290,8 +1348,9 @@  discard block
 block discarded – undo
1290 1348
 		// Maybe we can still save this?  The port might be wrong.
1291 1349
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1292 1350
 		{
1293
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1294
-				log_error($txt['smtp_port_ssl']);
1351
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1352
+							log_error($txt['smtp_port_ssl']);
1353
+			}
1295 1354
 		}
1296 1355
 
1297 1356
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1303,20 +1362,23 @@  discard block
 block discarded – undo
1303 1362
 	}
1304 1363
 
1305 1364
 	// Wait for a response of 220, without "-" continuer.
1306
-	if (!server_parse(null, $socket, '220'))
1307
-		return false;
1365
+	if (!server_parse(null, $socket, '220')) {
1366
+			return false;
1367
+	}
1308 1368
 
1309 1369
 	// Try and determine the servers name, fall back to the mail servers if not found
1310 1370
 	$helo = false;
1311
-	if (function_exists('gethostname') && gethostname() !== false)
1312
-		$helo = gethostname();
1313
-	elseif (function_exists('php_uname'))
1314
-		$helo = php_uname('n');
1315
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1316
-		$helo = $_SERVER['SERVER_NAME'];
1371
+	if (function_exists('gethostname') && gethostname() !== false) {
1372
+			$helo = gethostname();
1373
+	} elseif (function_exists('php_uname')) {
1374
+			$helo = php_uname('n');
1375
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1376
+			$helo = $_SERVER['SERVER_NAME'];
1377
+	}
1317 1378
 
1318
-	if (empty($helo))
1319
-		$helo = $modSettings['smtp_host'];
1379
+	if (empty($helo)) {
1380
+			$helo = $modSettings['smtp_host'];
1381
+	}
1320 1382
 
1321 1383
 	// SMTP = 1, SMTP - STARTTLS = 2
1322 1384
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1328,33 +1390,39 @@  discard block
 block discarded – undo
1328 1390
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1329 1391
 			{
1330 1392
 				// Send STARTTLS to enable encryption
1331
-				if (!server_parse('STARTTLS', $socket, '220'))
1332
-					return false;
1393
+				if (!server_parse('STARTTLS', $socket, '220')) {
1394
+									return false;
1395
+				}
1333 1396
 				// Enable the encryption
1334
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1335
-					return false;
1397
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1398
+									return false;
1399
+				}
1336 1400
 				// Send the EHLO command again
1337
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1338
-					return false;
1401
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1402
+									return false;
1403
+				}
1339 1404
 			}
1340 1405
 
1341
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1342
-				return false;
1406
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1407
+							return false;
1408
+			}
1343 1409
 			// Send the username and password, encoded.
1344
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1345
-				return false;
1410
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1411
+							return false;
1412
+			}
1346 1413
 			// The password is already encoded ;)
1347
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1348
-				return false;
1414
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1415
+							return false;
1416
+			}
1417
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1418
+					return false;
1349 1419
 		}
1350
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1351
-			return false;
1352
-	}
1353
-	else
1420
+	} else
1354 1421
 	{
1355 1422
 		// Just say "helo".
1356
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1357
-			return false;
1423
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1424
+					return false;
1425
+		}
1358 1426
 	}
1359 1427
 
1360 1428
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1367,31 +1435,38 @@  discard block
 block discarded – undo
1367 1435
 		// Reset the connection to send another email.
1368 1436
 		if ($i != 0)
1369 1437
 		{
1370
-			if (!server_parse('RSET', $socket, '250'))
1371
-				return false;
1438
+			if (!server_parse('RSET', $socket, '250')) {
1439
+							return false;
1440
+			}
1372 1441
 		}
1373 1442
 
1374 1443
 		// From, to, and then start the data...
1375
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1376
-			return false;
1377
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1378
-			return false;
1379
-		if (!server_parse('DATA', $socket, '354'))
1380
-			return false;
1444
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1445
+					return false;
1446
+		}
1447
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1448
+					return false;
1449
+		}
1450
+		if (!server_parse('DATA', $socket, '354')) {
1451
+					return false;
1452
+		}
1381 1453
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1382
-		if (strlen($mail_to) > 0)
1383
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1454
+		if (strlen($mail_to) > 0) {
1455
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1456
+		}
1384 1457
 		fputs($socket, $headers . "\r\n\r\n");
1385 1458
 		fputs($socket, $message . "\r\n");
1386 1459
 
1387 1460
 		// Send a ., or in other words "end of data".
1388
-		if (!server_parse('.', $socket, '250'))
1389
-			return false;
1461
+		if (!server_parse('.', $socket, '250')) {
1462
+					return false;
1463
+		}
1390 1464
 
1391 1465
 		// Almost done, almost done... don't stop me just yet!
1392 1466
 		@set_time_limit(300);
1393
-		if (function_exists('apache_reset_timeout'))
1394
-			@apache_reset_timeout();
1467
+		if (function_exists('apache_reset_timeout')) {
1468
+					@apache_reset_timeout();
1469
+		}
1395 1470
 	}
1396 1471
 	fputs($socket, 'QUIT' . "\r\n");
1397 1472
 	fclose($socket);
@@ -1415,8 +1490,9 @@  discard block
 block discarded – undo
1415 1490
 {
1416 1491
 	global $txt;
1417 1492
 
1418
-	if ($message !== null)
1419
-		fputs($socket, $message . "\r\n");
1493
+	if ($message !== null) {
1494
+			fputs($socket, $message . "\r\n");
1495
+	}
1420 1496
 
1421 1497
 	// No response yet.
1422 1498
 	$server_response = '';
@@ -1432,8 +1508,9 @@  discard block
 block discarded – undo
1432 1508
 		$response .= $server_response;
1433 1509
 	}
1434 1510
 
1435
-	if ($code === null)
1436
-		return substr($server_response, 0, 3);
1511
+	if ($code === null) {
1512
+			return substr($server_response, 0, 3);
1513
+	}
1437 1514
 
1438 1515
 	if (substr($server_response, 0, 3) != $code)
1439 1516
 	{
@@ -1463,8 +1540,9 @@  discard block
 block discarded – undo
1463 1540
 	// Create a pspell or enchant dictionary resource
1464 1541
 	$dict = spell_init();
1465 1542
 
1466
-	if (!isset($_POST['spellstring']) || !$dict)
1467
-		die;
1543
+	if (!isset($_POST['spellstring']) || !$dict) {
1544
+			die;
1545
+	}
1468 1546
 
1469 1547
 	// Construct a bit of Javascript code.
1470 1548
 	$context['spell_js'] = '
@@ -1482,8 +1560,9 @@  discard block
 block discarded – undo
1482 1560
 		$check_word = explode('|', $alphas[$i]);
1483 1561
 
1484 1562
 		// If the word is a known word, or spelled right...
1485
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1486
-			continue;
1563
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1564
+					continue;
1565
+		}
1487 1566
 
1488 1567
 		// Find the word, and move up the "last occurrence" to here.
1489 1568
 		$found_words = true;
@@ -1497,20 +1576,23 @@  discard block
 block discarded – undo
1497 1576
 		if (!empty($suggestions))
1498 1577
 		{
1499 1578
 			// But first check they aren't going to be censored - no naughty words!
1500
-			foreach ($suggestions as $k => $word)
1501
-				if ($suggestions[$k] != censorText($word))
1579
+			foreach ($suggestions as $k => $word) {
1580
+							if ($suggestions[$k] != censorText($word))
1502 1581
 					unset($suggestions[$k]);
1582
+			}
1503 1583
 
1504
-			if (!empty($suggestions))
1505
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1584
+			if (!empty($suggestions)) {
1585
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1586
+			}
1506 1587
 		}
1507 1588
 
1508 1589
 		$context['spell_js'] .= ']),';
1509 1590
 	}
1510 1591
 
1511 1592
 	// If words were found, take off the last comma.
1512
-	if ($found_words)
1513
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1593
+	if ($found_words) {
1594
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1595
+	}
1514 1596
 
1515 1597
 	$context['spell_js'] .= '
1516 1598
 		);';
@@ -1545,11 +1627,13 @@  discard block
 block discarded – undo
1545 1627
 	global $user_info, $smcFunc;
1546 1628
 
1547 1629
 	// Can't do it if there's no topics.
1548
-	if (empty($topics))
1549
-		return;
1630
+	if (empty($topics)) {
1631
+			return;
1632
+	}
1550 1633
 	// It must be an array - it must!
1551
-	if (!is_array($topics))
1552
-		$topics = array($topics);
1634
+	if (!is_array($topics)) {
1635
+			$topics = array($topics);
1636
+	}
1553 1637
 
1554 1638
 	// Get the subject and body...
1555 1639
 	$result = $smcFunc['db_query']('', '
@@ -1597,14 +1681,15 @@  discard block
 block discarded – undo
1597 1681
 	}
1598 1682
 	$smcFunc['db_free_result']($result);
1599 1683
 
1600
-	if (!empty($task_rows))
1601
-		$smcFunc['db_insert']('',
1684
+	if (!empty($task_rows)) {
1685
+			$smcFunc['db_insert']('',
1602 1686
 			'{db_prefix}background_tasks',
1603 1687
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1604 1688
 			$task_rows,
1605 1689
 			array('id_task')
1606 1690
 		);
1607
-}
1691
+	}
1692
+	}
1608 1693
 
1609 1694
 /**
1610 1695
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1642,9 +1727,9 @@  discard block
 block discarded – undo
1642 1727
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1643 1728
 
1644 1729
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1645
-	if (!$modSettings['postmod_active'])
1646
-		$topicOptions['is_approved'] = true;
1647
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1730
+	if (!$modSettings['postmod_active']) {
1731
+			$topicOptions['is_approved'] = true;
1732
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1648 1733
 	{
1649 1734
 		$request = $smcFunc['db_query']('', '
1650 1735
 			SELECT approved
@@ -1667,8 +1752,7 @@  discard block
 block discarded – undo
1667 1752
 			$posterOptions['id'] = 0;
1668 1753
 			$posterOptions['name'] = $txt['guest_title'];
1669 1754
 			$posterOptions['email'] = '';
1670
-		}
1671
-		elseif ($posterOptions['id'] != $user_info['id'])
1755
+		} elseif ($posterOptions['id'] != $user_info['id'])
1672 1756
 		{
1673 1757
 			$request = $smcFunc['db_query']('', '
1674 1758
 				SELECT member_name, email_address
@@ -1686,12 +1770,11 @@  discard block
 block discarded – undo
1686 1770
 				$posterOptions['id'] = 0;
1687 1771
 				$posterOptions['name'] = $txt['guest_title'];
1688 1772
 				$posterOptions['email'] = '';
1773
+			} else {
1774
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1689 1775
 			}
1690
-			else
1691
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1692 1776
 			$smcFunc['db_free_result']($request);
1693
-		}
1694
-		else
1777
+		} else
1695 1778
 		{
1696 1779
 			$posterOptions['name'] = $user_info['name'];
1697 1780
 			$posterOptions['email'] = $user_info['email'];
@@ -1701,8 +1784,9 @@  discard block
 block discarded – undo
1701 1784
 	if (!empty($modSettings['enable_mentions']))
1702 1785
 	{
1703 1786
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1704
-		if (!empty($msgOptions['mentioned_members']))
1705
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1787
+		if (!empty($msgOptions['mentioned_members'])) {
1788
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1789
+		}
1706 1790
 	}
1707 1791
 
1708 1792
 	// It's do or die time: forget any user aborts!
@@ -1735,12 +1819,13 @@  discard block
 block discarded – undo
1735 1819
 	);
1736 1820
 
1737 1821
 	// Something went wrong creating the message...
1738
-	if (empty($msgOptions['id']))
1739
-		return false;
1822
+	if (empty($msgOptions['id'])) {
1823
+			return false;
1824
+	}
1740 1825
 
1741 1826
 	// Fix the attachments.
1742
-	if (!empty($msgOptions['attachments']))
1743
-		$smcFunc['db_query']('', '
1827
+	if (!empty($msgOptions['attachments'])) {
1828
+			$smcFunc['db_query']('', '
1744 1829
 			UPDATE {db_prefix}attachments
1745 1830
 			SET id_msg = {int:id_msg}
1746 1831
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1749,6 +1834,7 @@  discard block
 block discarded – undo
1749 1834
 				'id_msg' => $msgOptions['id'],
1750 1835
 			)
1751 1836
 		);
1837
+	}
1752 1838
 
1753 1839
 	// What if we want to export new posts out to a CMS?
1754 1840
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1825,20 +1911,23 @@  discard block
 block discarded – undo
1825 1911
 			'id_topic' => $topicOptions['id'],
1826 1912
 			'counter_increment' => 1,
1827 1913
 		);
1828
-		if ($msgOptions['approved'])
1829
-			$topics_columns = array(
1914
+		if ($msgOptions['approved']) {
1915
+					$topics_columns = array(
1830 1916
 				'id_member_updated = {int:poster_id}',
1831 1917
 				'id_last_msg = {int:id_msg}',
1832 1918
 				'num_replies = num_replies + {int:counter_increment}',
1833 1919
 			);
1834
-		else
1835
-			$topics_columns = array(
1920
+		} else {
1921
+					$topics_columns = array(
1836 1922
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1837 1923
 			);
1838
-		if ($topicOptions['lock_mode'] !== null)
1839
-			$topics_columns[] = 'locked = {int:locked}';
1840
-		if ($topicOptions['sticky_mode'] !== null)
1841
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1924
+		}
1925
+		if ($topicOptions['lock_mode'] !== null) {
1926
+					$topics_columns[] = 'locked = {int:locked}';
1927
+		}
1928
+		if ($topicOptions['sticky_mode'] !== null) {
1929
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1930
+		}
1842 1931
 
1843 1932
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1844 1933
 
@@ -1867,8 +1956,8 @@  discard block
 block discarded – undo
1867 1956
 	);
1868 1957
 
1869 1958
 	// Increase the number of posts and topics on the board.
1870
-	if ($msgOptions['approved'])
1871
-		$smcFunc['db_query']('', '
1959
+	if ($msgOptions['approved']) {
1960
+			$smcFunc['db_query']('', '
1872 1961
 			UPDATE {db_prefix}boards
1873 1962
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1874 1963
 			WHERE id_board = {int:id_board}',
@@ -1876,7 +1965,7 @@  discard block
 block discarded – undo
1876 1965
 				'id_board' => $topicOptions['board'],
1877 1966
 			)
1878 1967
 		);
1879
-	else
1968
+	} else
1880 1969
 	{
1881 1970
 		$smcFunc['db_query']('', '
1882 1971
 			UPDATE {db_prefix}boards
@@ -1946,8 +2035,8 @@  discard block
 block discarded – undo
1946 2035
 		}
1947 2036
 	}
1948 2037
 
1949
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1950
-		$smcFunc['db_insert']('',
2038
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2039
+			$smcFunc['db_insert']('',
1951 2040
 			'{db_prefix}background_tasks',
1952 2041
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1953 2042
 			array(
@@ -1959,19 +2048,22 @@  discard block
 block discarded – undo
1959 2048
 			),
1960 2049
 			array('id_task')
1961 2050
 		);
2051
+	}
1962 2052
 
1963 2053
 	// If there's a custom search index, it may need updating...
1964 2054
 	require_once($sourcedir . '/Search.php');
1965 2055
 	$searchAPI = findSearchAPI();
1966
-	if (is_callable(array($searchAPI, 'postCreated')))
1967
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2056
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2057
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2058
+	}
1968 2059
 
1969 2060
 	// Increase the post counter for the user that created the post.
1970 2061
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
1971 2062
 	{
1972 2063
 		// Are you the one that happened to create this post?
1973
-		if ($user_info['id'] == $posterOptions['id'])
1974
-			$user_info['posts']++;
2064
+		if ($user_info['id'] == $posterOptions['id']) {
2065
+					$user_info['posts']++;
2066
+		}
1975 2067
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
1976 2068
 	}
1977 2069
 
@@ -1979,19 +2071,21 @@  discard block
 block discarded – undo
1979 2071
 	$_SESSION['last_read_topic'] = 0;
1980 2072
 
1981 2073
 	// Better safe than sorry.
1982
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
1983
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2074
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2075
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2076
+	}
1984 2077
 
1985 2078
 	// Update all the stats so everyone knows about this new topic and message.
1986 2079
 	updateStats('message', true, $msgOptions['id']);
1987 2080
 
1988 2081
 	// Update the last message on the board assuming it's approved AND the topic is.
1989
-	if ($msgOptions['approved'])
1990
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2082
+	if ($msgOptions['approved']) {
2083
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2084
+	}
1991 2085
 
1992 2086
 	// Queue createPost background notification
1993
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
1994
-		$smcFunc['db_insert']('',
2087
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2088
+			$smcFunc['db_insert']('',
1995 2089
 			'{db_prefix}background_tasks',
1996 2090
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1997 2091
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
@@ -2002,6 +2096,7 @@  discard block
 block discarded – undo
2002 2096
 			)), 0),
2003 2097
 			array('id_task')
2004 2098
 		);
2099
+	}
2005 2100
 
2006 2101
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2007 2102
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2028,14 +2123,18 @@  discard block
 block discarded – undo
2028 2123
 
2029 2124
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2030 2125
 	$messages_columns = array();
2031
-	if (isset($posterOptions['name']))
2032
-		$messages_columns['poster_name'] = $posterOptions['name'];
2033
-	if (isset($posterOptions['email']))
2034
-		$messages_columns['poster_email'] = $posterOptions['email'];
2035
-	if (isset($msgOptions['icon']))
2036
-		$messages_columns['icon'] = $msgOptions['icon'];
2037
-	if (isset($msgOptions['subject']))
2038
-		$messages_columns['subject'] = $msgOptions['subject'];
2126
+	if (isset($posterOptions['name'])) {
2127
+			$messages_columns['poster_name'] = $posterOptions['name'];
2128
+	}
2129
+	if (isset($posterOptions['email'])) {
2130
+			$messages_columns['poster_email'] = $posterOptions['email'];
2131
+	}
2132
+	if (isset($msgOptions['icon'])) {
2133
+			$messages_columns['icon'] = $msgOptions['icon'];
2134
+	}
2135
+	if (isset($msgOptions['subject'])) {
2136
+			$messages_columns['subject'] = $msgOptions['subject'];
2137
+	}
2039 2138
 	if (isset($msgOptions['body']))
2040 2139
 	{
2041 2140
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2062,8 +2161,9 @@  discard block
 block discarded – undo
2062 2161
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2063 2162
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2064 2163
 	}
2065
-	if (isset($msgOptions['smileys_enabled']))
2066
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2164
+	if (isset($msgOptions['smileys_enabled'])) {
2165
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2166
+	}
2067 2167
 
2068 2168
 	// Which columns need to be ints?
2069 2169
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2074,8 +2174,9 @@  discard block
 block discarded – undo
2074 2174
 	// Update search api
2075 2175
 	require_once($sourcedir . '/Search.php');
2076 2176
 	$searchAPI = findSearchAPI();
2077
-	if ($searchAPI->supportsMethod('postRemoved'))
2078
-		$searchAPI->postRemoved($msgOptions['id']);
2177
+	if ($searchAPI->supportsMethod('postRemoved')) {
2178
+			$searchAPI->postRemoved($msgOptions['id']);
2179
+	}
2079 2180
 
2080 2181
 	if (!empty($modSettings['enable_mentions']) && isset($msgOptions['body']))
2081 2182
 	{
@@ -2087,23 +2188,27 @@  discard block
 block discarded – undo
2087 2188
 		{
2088 2189
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2089 2190
 
2090
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2091
-				foreach ($match[1] as $i => $oldID)
2191
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2192
+							foreach ($match[1] as $i => $oldID)
2092 2193
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2194
+			}
2093 2195
 
2094
-			if (empty($modSettings['search_custom_index_config']))
2095
-				unset($msgOptions['old_body']);
2196
+			if (empty($modSettings['search_custom_index_config'])) {
2197
+							unset($msgOptions['old_body']);
2198
+			}
2096 2199
 		}
2097 2200
 
2098 2201
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2099 2202
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2100 2203
 
2101 2204
 		// Remove the poster.
2102
-		if (isset($mentions[$user_info['id']]))
2103
-			unset($mentions[$user_info['id']]);
2205
+		if (isset($mentions[$user_info['id']])) {
2206
+					unset($mentions[$user_info['id']]);
2207
+		}
2104 2208
 
2105
-		if (isset($oldmentions[$user_info['id']]))
2106
-			unset($oldmentions[$user_info['id']]);
2209
+		if (isset($oldmentions[$user_info['id']])) {
2210
+					unset($oldmentions[$user_info['id']]);
2211
+		}
2107 2212
 
2108 2213
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2109 2214
 		{
@@ -2133,8 +2238,9 @@  discard block
 block discarded – undo
2133 2238
 	}
2134 2239
 
2135 2240
 	// Nothing to do?
2136
-	if (empty($messages_columns))
2137
-		return true;
2241
+	if (empty($messages_columns)) {
2242
+			return true;
2243
+	}
2138 2244
 
2139 2245
 	// Change the post.
2140 2246
 	$smcFunc['db_query']('', '
@@ -2195,8 +2301,9 @@  discard block
 block discarded – undo
2195 2301
 	// If there's a custom search index, it needs to be modified...
2196 2302
 	require_once($sourcedir . '/Search.php');
2197 2303
 	$searchAPI = findSearchAPI();
2198
-	if (is_callable(array($searchAPI, 'postModified')))
2199
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2304
+	if (is_callable(array($searchAPI, 'postModified'))) {
2305
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2306
+	}
2200 2307
 
2201 2308
 	if (isset($msgOptions['subject']))
2202 2309
 	{
@@ -2210,14 +2317,16 @@  discard block
 block discarded – undo
2210 2317
 				'id_first_msg' => $msgOptions['id'],
2211 2318
 			)
2212 2319
 		);
2213
-		if ($smcFunc['db_num_rows']($request) == 1)
2214
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2320
+		if ($smcFunc['db_num_rows']($request) == 1) {
2321
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2322
+		}
2215 2323
 		$smcFunc['db_free_result']($request);
2216 2324
 	}
2217 2325
 
2218 2326
 	// Finally, if we are setting the approved state we need to do much more work :(
2219
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2220
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2327
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2328
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2329
+	}
2221 2330
 
2222 2331
 	return true;
2223 2332
 }
@@ -2234,11 +2343,13 @@  discard block
 block discarded – undo
2234 2343
 {
2235 2344
 	global $smcFunc;
2236 2345
 
2237
-	if (!is_array($msgs))
2238
-		$msgs = array($msgs);
2346
+	if (!is_array($msgs)) {
2347
+			$msgs = array($msgs);
2348
+	}
2239 2349
 
2240
-	if (empty($msgs))
2241
-		return false;
2350
+	if (empty($msgs)) {
2351
+			return false;
2352
+	}
2242 2353
 
2243 2354
 	// May as well start at the beginning, working out *what* we need to change.
2244 2355
 	$request = $smcFunc['db_query']('', '
@@ -2270,20 +2381,22 @@  discard block
 block discarded – undo
2270 2381
 		$topics[] = $row['id_topic'];
2271 2382
 
2272 2383
 		// Ensure our change array exists already.
2273
-		if (!isset($topic_changes[$row['id_topic']]))
2274
-			$topic_changes[$row['id_topic']] = array(
2384
+		if (!isset($topic_changes[$row['id_topic']])) {
2385
+					$topic_changes[$row['id_topic']] = array(
2275 2386
 				'id_last_msg' => $row['id_last_msg'],
2276 2387
 				'approved' => $row['topic_approved'],
2277 2388
 				'replies' => 0,
2278 2389
 				'unapproved_posts' => 0,
2279 2390
 			);
2280
-		if (!isset($board_changes[$row['id_board']]))
2281
-			$board_changes[$row['id_board']] = array(
2391
+		}
2392
+		if (!isset($board_changes[$row['id_board']])) {
2393
+					$board_changes[$row['id_board']] = array(
2282 2394
 				'posts' => 0,
2283 2395
 				'topics' => 0,
2284 2396
 				'unapproved_posts' => 0,
2285 2397
 				'unapproved_topics' => 0,
2286 2398
 			);
2399
+		}
2287 2400
 
2288 2401
 		// If it's the first message then the topic state changes!
2289 2402
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2304,14 +2417,13 @@  discard block
 block discarded – undo
2304 2417
 				'poster' => $row['id_member'],
2305 2418
 				'new_topic' => true,
2306 2419
 			);
2307
-		}
2308
-		else
2420
+		} else
2309 2421
 		{
2310 2422
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2311 2423
 
2312 2424
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2313
-			if ($row['id_msg'] > $row['id_last_msg'])
2314
-				$notification_posts[$row['id_topic']] = array(
2425
+			if ($row['id_msg'] > $row['id_last_msg']) {
2426
+							$notification_posts[$row['id_topic']] = array(
2315 2427
 					'id' => $row['id_msg'],
2316 2428
 					'body' => $row['body'],
2317 2429
 					'subject' => $row['subject'],
@@ -2322,28 +2434,33 @@  discard block
 block discarded – undo
2322 2434
 					'new_topic' => false,
2323 2435
 					'msg' => $row['id_msg'],
2324 2436
 				);
2437
+			}
2325 2438
 		}
2326 2439
 
2327 2440
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2328
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2329
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2441
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2442
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2443
+		}
2330 2444
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2331
-		elseif (!$approve)
2332
-			// Default to the first message and then we'll override in a bit ;)
2445
+		elseif (!$approve) {
2446
+					// Default to the first message and then we'll override in a bit ;)
2333 2447
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2448
+		}
2334 2449
 
2335 2450
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2336 2451
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2337 2452
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2338 2453
 
2339 2454
 		// Post count for the user?
2340
-		if ($row['id_member'] && empty($row['count_posts']))
2341
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2455
+		if ($row['id_member'] && empty($row['count_posts'])) {
2456
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2457
+		}
2342 2458
 	}
2343 2459
 	$smcFunc['db_free_result']($request);
2344 2460
 
2345
-	if (empty($msgs))
2346
-		return;
2461
+	if (empty($msgs)) {
2462
+			return;
2463
+	}
2347 2464
 
2348 2465
 	// Now we have the differences make the changes, first the easy one.
2349 2466
 	$smcFunc['db_query']('', '
@@ -2370,14 +2487,15 @@  discard block
 block discarded – undo
2370 2487
 				'approved' => 1,
2371 2488
 			)
2372 2489
 		);
2373
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2374
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2490
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2491
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2492
+		}
2375 2493
 		$smcFunc['db_free_result']($request);
2376 2494
 	}
2377 2495
 
2378 2496
 	// ... next the topics...
2379
-	foreach ($topic_changes as $id => $changes)
2380
-		$smcFunc['db_query']('', '
2497
+	foreach ($topic_changes as $id => $changes) {
2498
+			$smcFunc['db_query']('', '
2381 2499
 			UPDATE {db_prefix}topics
2382 2500
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2383 2501
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2390,10 +2508,11 @@  discard block
 block discarded – undo
2390 2508
 				'id_topic' => $id,
2391 2509
 			)
2392 2510
 		);
2511
+	}
2393 2512
 
2394 2513
 	// ... finally the boards...
2395
-	foreach ($board_changes as $id => $changes)
2396
-		$smcFunc['db_query']('', '
2514
+	foreach ($board_changes as $id => $changes) {
2515
+			$smcFunc['db_query']('', '
2397 2516
 			UPDATE {db_prefix}boards
2398 2517
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2399 2518
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2406,13 +2525,14 @@  discard block
 block discarded – undo
2406 2525
 				'id_board' => $id,
2407 2526
 			)
2408 2527
 		);
2528
+	}
2409 2529
 
2410 2530
 	// Finally, least importantly, notifications!
2411 2531
 	if ($approve)
2412 2532
 	{
2413 2533
 		$task_rows = array();
2414
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2415
-			$task_rows[] = array(
2534
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2535
+					$task_rows[] = array(
2416 2536
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
2417 2537
 					'msgOptions' => array(
2418 2538
 						'id' => $topic['msg'],
@@ -2430,14 +2550,16 @@  discard block
 block discarded – undo
2430 2550
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2431 2551
 				)), 0
2432 2552
 			);
2553
+		}
2433 2554
 
2434
-		if ($notify)
2435
-			$smcFunc['db_insert']('',
2555
+		if ($notify) {
2556
+					$smcFunc['db_insert']('',
2436 2557
 				'{db_prefix}background_tasks',
2437 2558
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2438 2559
 				$task_rows,
2439 2560
 				array('id_task')
2440 2561
 			);
2562
+		}
2441 2563
 
2442 2564
 		$smcFunc['db_query']('', '
2443 2565
 			DELETE FROM {db_prefix}approval_queue
@@ -2453,8 +2575,9 @@  discard block
 block discarded – undo
2453 2575
 	else
2454 2576
 	{
2455 2577
 		$msgInserts = array();
2456
-		foreach ($msgs as $msg)
2457
-			$msgInserts[] = array($msg);
2578
+		foreach ($msgs as $msg) {
2579
+					$msgInserts[] = array($msg);
2580
+		}
2458 2581
 
2459 2582
 		$smcFunc['db_insert']('ignore',
2460 2583
 			'{db_prefix}approval_queue',
@@ -2468,9 +2591,10 @@  discard block
 block discarded – undo
2468 2591
 	updateLastMessages(array_keys($board_changes));
2469 2592
 
2470 2593
 	// Post count for the members?
2471
-	if (!empty($member_post_changes))
2472
-		foreach ($member_post_changes as $id_member => $count_change)
2594
+	if (!empty($member_post_changes)) {
2595
+			foreach ($member_post_changes as $id_member => $count_change)
2473 2596
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2597
+	}
2474 2598
 
2475 2599
 	return true;
2476 2600
 }
@@ -2487,11 +2611,13 @@  discard block
 block discarded – undo
2487 2611
 {
2488 2612
 	global $smcFunc;
2489 2613
 
2490
-	if (!is_array($topics))
2491
-		$topics = array($topics);
2614
+	if (!is_array($topics)) {
2615
+			$topics = array($topics);
2616
+	}
2492 2617
 
2493
-	if (empty($topics))
2494
-		return false;
2618
+	if (empty($topics)) {
2619
+			return false;
2620
+	}
2495 2621
 
2496 2622
 	$approve_type = $approve ? 0 : 1;
2497 2623
 
@@ -2507,8 +2633,9 @@  discard block
 block discarded – undo
2507 2633
 		)
2508 2634
 	);
2509 2635
 	$msgs = array();
2510
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2511
-		$msgs[] = $row['id_msg'];
2636
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2637
+			$msgs[] = $row['id_msg'];
2638
+	}
2512 2639
 	$smcFunc['db_free_result']($request);
2513 2640
 
2514 2641
 	return approvePosts($msgs, $approve);
@@ -2531,11 +2658,13 @@  discard block
 block discarded – undo
2531 2658
 	global $board_info, $board, $smcFunc;
2532 2659
 
2533 2660
 	// Please - let's be sane.
2534
-	if (empty($setboards))
2535
-		return false;
2661
+	if (empty($setboards)) {
2662
+			return false;
2663
+	}
2536 2664
 
2537
-	if (!is_array($setboards))
2538
-		$setboards = array($setboards);
2665
+	if (!is_array($setboards)) {
2666
+			$setboards = array($setboards);
2667
+	}
2539 2668
 
2540 2669
 	// If we don't know the id_msg we need to find it.
2541 2670
 	if (!$id_msg)
@@ -2553,15 +2682,16 @@  discard block
 block discarded – undo
2553 2682
 			)
2554 2683
 		);
2555 2684
 		$lastMsg = array();
2556
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2557
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2685
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2686
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2687
+		}
2558 2688
 		$smcFunc['db_free_result']($request);
2559
-	}
2560
-	else
2689
+	} else
2561 2690
 	{
2562 2691
 		// Just to note - there should only be one board passed if we are doing this.
2563
-		foreach ($setboards as $id_board)
2564
-			$lastMsg[$id_board] = $id_msg;
2692
+		foreach ($setboards as $id_board) {
2693
+					$lastMsg[$id_board] = $id_msg;
2694
+		}
2565 2695
 	}
2566 2696
 
2567 2697
 	$parent_boards = array();
@@ -2576,10 +2706,11 @@  discard block
 block discarded – undo
2576 2706
 			$lastModified[$id_board] = 0;
2577 2707
 		}
2578 2708
 
2579
-		if (!empty($board) && $id_board == $board)
2580
-			$parents = $board_info['parent_boards'];
2581
-		else
2582
-			$parents = getBoardParents($id_board);
2709
+		if (!empty($board) && $id_board == $board) {
2710
+					$parents = $board_info['parent_boards'];
2711
+		} else {
2712
+					$parents = getBoardParents($id_board);
2713
+		}
2583 2714
 
2584 2715
 		// Ignore any parents on the top child level.
2585 2716
 		// @todo Why?
@@ -2588,10 +2719,11 @@  discard block
 block discarded – undo
2588 2719
 			if ($parent['level'] != 0)
2589 2720
 			{
2590 2721
 				// If we're already doing this one as a board, is this a higher last modified?
2591
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2592
-					$lastModified[$id] = $lastModified[$id_board];
2593
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2594
-					$parent_boards[$id] = $lastModified[$id_board];
2722
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2723
+									$lastModified[$id] = $lastModified[$id_board];
2724
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2725
+									$parent_boards[$id] = $lastModified[$id_board];
2726
+				}
2595 2727
 			}
2596 2728
 		}
2597 2729
 	}
@@ -2604,23 +2736,24 @@  discard block
 block discarded – undo
2604 2736
 	// Finally, to save on queries make the changes...
2605 2737
 	foreach ($parent_boards as $id => $msg)
2606 2738
 	{
2607
-		if (!isset($parent_updates[$msg]))
2608
-			$parent_updates[$msg] = array($id);
2609
-		else
2610
-			$parent_updates[$msg][] = $id;
2739
+		if (!isset($parent_updates[$msg])) {
2740
+					$parent_updates[$msg] = array($id);
2741
+		} else {
2742
+					$parent_updates[$msg][] = $id;
2743
+		}
2611 2744
 	}
2612 2745
 
2613 2746
 	foreach ($lastMsg as $id => $msg)
2614 2747
 	{
2615
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2616
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2748
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2749
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2617 2750
 				'id' => $msg,
2618 2751
 				'updated' => $lastModified[$id],
2619 2752
 				'boards' => array($id)
2620 2753
 			);
2621
-
2622
-		else
2623
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2754
+		} else {
2755
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2756
+		}
2624 2757
 	}
2625 2758
 
2626 2759
 	// Now commit the changes!
@@ -2712,11 +2845,13 @@  discard block
 block discarded – undo
2712 2845
 	global $txt, $mbname, $scripturl, $settings;
2713 2846
 
2714 2847
 	// First things first, load up the email templates language file, if we need to.
2715
-	if ($loadLang)
2716
-		loadLanguage('EmailTemplates', $lang);
2848
+	if ($loadLang) {
2849
+			loadLanguage('EmailTemplates', $lang);
2850
+	}
2717 2851
 
2718
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2719
-		fatal_lang_error('email_no_template', 'template', array($template));
2852
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2853
+			fatal_lang_error('email_no_template', 'template', array($template));
2854
+	}
2720 2855
 
2721 2856
 	$ret = array(
2722 2857
 		'subject' => $txt[$template . '_subject'],
@@ -2766,17 +2901,18 @@  discard block
 block discarded – undo
2766 2901
 function user_info_callback($matches)
2767 2902
 {
2768 2903
 	global $user_info;
2769
-	if (empty($matches[1]))
2770
-		return '';
2904
+	if (empty($matches[1])) {
2905
+			return '';
2906
+	}
2771 2907
 
2772 2908
 	$use_ref = true;
2773 2909
 	$ref = &$user_info;
2774 2910
 
2775 2911
 	foreach (explode('.', $matches[1]) as $index)
2776 2912
 	{
2777
-		if ($use_ref && isset($ref[$index]))
2778
-			$ref = &$ref[$index];
2779
-		else
2913
+		if ($use_ref && isset($ref[$index])) {
2914
+					$ref = &$ref[$index];
2915
+		} else
2780 2916
 		{
2781 2917
 			$use_ref = false;
2782 2918
 			break;
@@ -2813,8 +2949,7 @@  discard block
 block discarded – undo
2813 2949
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2814 2950
 		{
2815 2951
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2816
-		}
2817
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2952
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2818 2953
 		{
2819 2954
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2820 2955
 		}
@@ -2824,8 +2959,7 @@  discard block
 block discarded – undo
2824 2959
 		{
2825 2960
 			$context['provider'] = 'enchant';
2826 2961
 			return $enchant_link;
2827
-		}
2828
-		else
2962
+		} else
2829 2963
 		{
2830 2964
 			// Free up any resources used...
2831 2965
 			@enchant_broker_free($context['enchant_broker']);
@@ -2846,8 +2980,9 @@  discard block
 block discarded – undo
2846 2980
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2847 2981
 
2848 2982
 		// Most people don't have anything but English installed... So we use English as a last resort.
2849
-		if (!$pspell_link)
2850
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
2983
+		if (!$pspell_link) {
2984
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
2985
+		}
2851 2986
 
2852 2987
 		error_reporting($old);
2853 2988
 		ob_end_clean();
@@ -2887,8 +3022,7 @@  discard block
 block discarded – undo
2887 3022
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2888 3023
 		}
2889 3024
 		return enchant_dict_check($dict, $word);
2890
-	}
2891
-	elseif ($context['provider'] == 'pspell')
3025
+	} elseif ($context['provider'] == 'pspell')
2892 3026
 	{
2893 3027
 		return pspell_check($dict, $word);
2894 3028
 	}
@@ -2924,13 +3058,11 @@  discard block
 block discarded – undo
2924 3058
 			}
2925 3059
 
2926 3060
 			return $suggestions;
2927
-		}
2928
-		else
3061
+		} else
2929 3062
 		{
2930 3063
 			return enchant_dict_suggest($dict, $word);
2931 3064
 		}
2932
-	}
2933
-	elseif ($context['provider'] == 'pspell')
3065
+	} elseif ($context['provider'] == 'pspell')
2934 3066
 	{
2935 3067
 		return pspell_suggest($dict, $word);
2936 3068
 	}
Please login to merge, or discard this patch.