Completed
Pull Request — release-2.1 (#4446)
by Mathias
12:43
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   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -247,7 +247,7 @@
 block discarded – undo
247 247
 	}
248 248
 	$smcFunc['db_free_result']($request);
249 249
 
250
-	if($withSender)
250
+	if ($withSender)
251 251
 	{
252 252
 		$senders = loadMemberData($senders);
253 253
 		foreach ($senders as $member)
Please login to merge, or discard this patch.
Braces   +302 added lines, -221 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
 
@@ -245,16 +253,18 @@  discard block
 block discarded – undo
245 253
 		$row['extra'] = !empty($row['extra']) ? $smcFunc['json_decode']($row['extra'], true) : array();
246 254
 		$alerts[$id_alert] = $row;
247 255
 
248
-		if (!empty($row['sender_id']))
249
-			$senders[] = $row['sender_id'];
256
+		if (!empty($row['sender_id'])) {
257
+					$senders[] = $row['sender_id'];
258
+		}
250 259
 	}
251 260
 	$smcFunc['db_free_result']($request);
252 261
 
253 262
 	if($withSender)
254 263
 	{
255 264
 		$senders = loadMemberData($senders);
256
-		foreach ($senders as $member)
257
-			loadMemberContext($member);
265
+		foreach ($senders as $member) {
266
+					loadMemberContext($member);
267
+		}
258 268
 	}
259 269
 
260 270
 	// Now go through and actually make with the text.
@@ -269,12 +279,15 @@  discard block
 block discarded – undo
269 279
 	$msgs = array();
270 280
 	foreach ($alerts as $id_alert => $alert)
271 281
 	{
272
-		if (isset($alert['extra']['board']))
273
-			$boards[$alert['extra']['board']] = $txt['board_na'];
274
-		if (isset($alert['extra']['topic']))
275
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
276
-		if ($alert['content_type'] == 'msg')
277
-			$msgs[$alert['content_id']] = $txt['topic_na'];
282
+		if (isset($alert['extra']['board'])) {
283
+					$boards[$alert['extra']['board']] = $txt['board_na'];
284
+		}
285
+		if (isset($alert['extra']['topic'])) {
286
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
287
+		}
288
+		if ($alert['content_type'] == 'msg') {
289
+					$msgs[$alert['content_id']] = $txt['topic_na'];
290
+		}
278 291
 	}
279 292
 
280 293
 	// 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.
@@ -289,8 +302,9 @@  discard block
 block discarded – undo
289 302
 				'boards' => array_keys($boards),
290 303
 			)
291 304
 		);
292
-		while ($row = $smcFunc['db_fetch_assoc']($request))
293
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
305
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
306
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
307
+		}
294 308
 	}
295 309
 	if (!empty($topics))
296 310
 	{
@@ -305,8 +319,9 @@  discard block
 block discarded – undo
305 319
 				'topics' => array_keys($topics),
306 320
 			)
307 321
 		);
308
-		while ($row = $smcFunc['db_fetch_assoc']($request))
309
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
322
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
323
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
324
+		}
310 325
 	}
311 326
 	if (!empty($msgs))
312 327
 	{
@@ -321,44 +336,51 @@  discard block
 block discarded – undo
321 336
 				'msgs' => array_keys($msgs),
322 337
 			)
323 338
 		);
324
-		while ($row = $smcFunc['db_fetch_assoc']($request))
325
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
339
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
340
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
341
+		}
326 342
 	}
327 343
 
328 344
 	// 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)
329 345
 	foreach ($alerts as $id_alert => $alert)
330 346
 	{
331
-		if (!empty($alert['text']))
332
-			continue;
333
-		if (isset($alert['extra']['board']))
334
-			if ($boards[$alert['extra']['board']] == $txt['board_na'])
347
+		if (!empty($alert['text'])) {
348
+					continue;
349
+		}
350
+		if (isset($alert['extra']['board'])) {
351
+					if ($boards[$alert['extra']['board']] == $txt['board_na'])
335 352
 			{
336 353
 				unset($alerts[$id_alert]);
354
+		}
337 355
 				continue;
356
+			} else {
357
+							$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
338 358
 			}
339
-			else
340
-				$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
341
-		if (isset($alert['extra']['topic']))
342
-			if ($alert['extra']['topic'] == $txt['topic_na'])
359
+		if (isset($alert['extra']['topic'])) {
360
+					if ($alert['extra']['topic'] == $txt['topic_na'])
343 361
 			{
344 362
 				unset($alerts[$id_alert]);
363
+		}
345 364
 				continue;
365
+			} else {
366
+							$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
346 367
 			}
347
-			else
348
-				$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
349
-		if ($alert['content_type'] == 'msg')
350
-			if ($msgs[$alert['content_id']] == $txt['topic_na'])
368
+		if ($alert['content_type'] == 'msg') {
369
+					if ($msgs[$alert['content_id']] == $txt['topic_na'])
351 370
 			{
352 371
 				unset($alerts[$id_alert]);
372
+		}
353 373
 				continue;
374
+			} else {
375
+							$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
354 376
 			}
355
-			else
356
-				$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
357
-		if ($alert['content_type'] == 'profile')
358
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
377
+		if ($alert['content_type'] == 'profile') {
378
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
379
+		}
359 380
 
360
-		if (!empty($memberContext[$alert['sender_id']]))
361
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
381
+		if (!empty($memberContext[$alert['sender_id']])) {
382
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
383
+		}
362 384
 
363 385
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
364 386
 		if (isset($txt[$string]))
@@ -446,11 +468,11 @@  discard block
 block discarded – undo
446 468
 		checkSession('request');
447 469
 
448 470
 		// Call it!
449
-		if ($action == 'remove')
450
-			alert_delete($toMark, $memID);
451
-
452
-		else
453
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
471
+		if ($action == 'remove') {
472
+					alert_delete($toMark, $memID);
473
+		} else {
474
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
475
+		}
454 476
 
455 477
 		// Set a nice update message.
456 478
 		$_SESSION['update_message'] = true;
@@ -500,23 +522,27 @@  discard block
 block discarded – undo
500 522
 	);
501 523
 
502 524
 	// Set the page title
503
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
504
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
505
-	else
506
-		$context['page_title'] = $txt['showPosts'];
525
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
526
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
527
+	} else {
528
+			$context['page_title'] = $txt['showPosts'];
529
+	}
507 530
 
508 531
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
509 532
 
510 533
 	// Is the load average too high to allow searching just now?
511
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
512
-		fatal_lang_error('loadavg_show_posts_disabled', false);
534
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
535
+			fatal_lang_error('loadavg_show_posts_disabled', false);
536
+	}
513 537
 
514 538
 	// If we're specifically dealing with attachments use that function!
515
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
516
-		return showAttachments($memID);
539
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
540
+			return showAttachments($memID);
541
+	}
517 542
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
518
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
519
-		return showUnwatched($memID);
543
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
544
+			return showUnwatched($memID);
545
+	}
520 546
 
521 547
 	// Are we just viewing topics?
522 548
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -539,27 +565,30 @@  discard block
 block discarded – undo
539 565
 		$smcFunc['db_free_result']($request);
540 566
 
541 567
 		// Trying to remove a message that doesn't exist.
542
-		if (empty($info))
543
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
568
+		if (empty($info)) {
569
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
570
+		}
544 571
 
545 572
 		// We can be lazy, since removeMessage() will check the permissions for us.
546 573
 		require_once($sourcedir . '/RemoveTopic.php');
547 574
 		removeMessage((int) $_GET['delete']);
548 575
 
549 576
 		// Add it to the mod log.
550
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
551
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
577
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
578
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
579
+		}
552 580
 
553 581
 		// Back to... where we are now ;).
554 582
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
555 583
 	}
556 584
 
557 585
 	// Default to 10.
558
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
559
-		$_REQUEST['viewscount'] = '10';
586
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
587
+			$_REQUEST['viewscount'] = '10';
588
+	}
560 589
 
561
-	if ($context['is_topics'])
562
-		$request = $smcFunc['db_query']('', '
590
+	if ($context['is_topics']) {
591
+			$request = $smcFunc['db_query']('', '
563 592
 			SELECT COUNT(*)
564 593
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
565 594
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -572,8 +601,8 @@  discard block
 block discarded – undo
572 601
 				'board' => $board,
573 602
 			)
574 603
 		);
575
-	else
576
-		$request = $smcFunc['db_query']('', '
604
+	} else {
605
+			$request = $smcFunc['db_query']('', '
577 606
 			SELECT COUNT(*)
578 607
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
579 608
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -586,6 +615,7 @@  discard block
 block discarded – undo
586 615
 				'board' => $board,
587 616
 			)
588 617
 		);
618
+	}
589 619
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
590 620
 	$smcFunc['db_free_result']($request);
591 621
 
@@ -606,10 +636,11 @@  discard block
 block discarded – undo
606 636
 
607 637
 	$range_limit = '';
608 638
 
609
-	if ($context['is_topics'])
610
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
611
-	else
612
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
639
+	if ($context['is_topics']) {
640
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
641
+	} else {
642
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
643
+	}
613 644
 
614 645
 	$maxIndex = $maxPerPage;
615 646
 
@@ -635,9 +666,9 @@  discard block
 block discarded – undo
635 666
 		{
636 667
 			$margin *= 5;
637 668
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
669
+		} else {
670
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
638 671
 		}
639
-		else
640
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
641 672
 	}
642 673
 
643 674
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -669,8 +700,7 @@  discard block
 block discarded – undo
669 700
 					'max' => $maxIndex,
670 701
 				)
671 702
 			);
672
-		}
673
-		else
703
+		} else
674 704
 		{
675 705
 			$request = $smcFunc['db_query']('', '
676 706
 				SELECT
@@ -699,8 +729,9 @@  discard block
 block discarded – undo
699 729
 		}
700 730
 
701 731
 		// Make sure we quit this loop.
702
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '')
703
-			break;
732
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '') {
733
+					break;
734
+		}
704 735
 		$looped = true;
705 736
 		$range_limit = '';
706 737
 	}
@@ -744,19 +775,21 @@  discard block
 block discarded – undo
744 775
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
745 776
 		);
746 777
 
747
-		if ($user_info['id'] == $row['id_member_started'])
748
-			$board_ids['own'][$row['id_board']][] = $counter;
778
+		if ($user_info['id'] == $row['id_member_started']) {
779
+					$board_ids['own'][$row['id_board']][] = $counter;
780
+		}
749 781
 		$board_ids['any'][$row['id_board']][] = $counter;
750 782
 	}
751 783
 	$smcFunc['db_free_result']($request);
752 784
 
753 785
 	// All posts were retrieved in reverse order, get them right again.
754
-	if ($reverse)
755
-		$context['posts'] = array_reverse($context['posts'], true);
786
+	if ($reverse) {
787
+			$context['posts'] = array_reverse($context['posts'], true);
788
+	}
756 789
 
757 790
 	// These are all the permissions that are different from board to board..
758
-	if ($context['is_topics'])
759
-		$permissions = array(
791
+	if ($context['is_topics']) {
792
+			$permissions = array(
760 793
 			'own' => array(
761 794
 				'post_reply_own' => 'can_reply',
762 795
 			),
@@ -764,8 +797,8 @@  discard block
 block discarded – undo
764 797
 				'post_reply_any' => 'can_reply',
765 798
 			)
766 799
 		);
767
-	else
768
-		$permissions = array(
800
+	} else {
801
+			$permissions = array(
769 802
 			'own' => array(
770 803
 				'post_reply_own' => 'can_reply',
771 804
 				'delete_own' => 'can_delete',
@@ -775,6 +808,7 @@  discard block
 block discarded – undo
775 808
 				'delete_any' => 'can_delete',
776 809
 			)
777 810
 		);
811
+	}
778 812
 
779 813
 	// For every permission in the own/any lists...
780 814
 	foreach ($permissions as $type => $list)
@@ -785,19 +819,22 @@  discard block
 block discarded – undo
785 819
 			$boards = boardsAllowedTo($permission);
786 820
 
787 821
 			// Hmm, they can do it on all boards, can they?
788
-			if (!empty($boards) && $boards[0] == 0)
789
-				$boards = array_keys($board_ids[$type]);
822
+			if (!empty($boards) && $boards[0] == 0) {
823
+							$boards = array_keys($board_ids[$type]);
824
+			}
790 825
 
791 826
 			// Now go through each board they can do the permission on.
792 827
 			foreach ($boards as $board_id)
793 828
 			{
794 829
 				// There aren't any posts displayed from this board.
795
-				if (!isset($board_ids[$type][$board_id]))
796
-					continue;
830
+				if (!isset($board_ids[$type][$board_id])) {
831
+									continue;
832
+				}
797 833
 
798 834
 				// Set the permission to true ;).
799
-				foreach ($board_ids[$type][$board_id] as $counter)
800
-					$context['posts'][$counter][$allowed] = true;
835
+				foreach ($board_ids[$type][$board_id] as $counter) {
836
+									$context['posts'][$counter][$allowed] = true;
837
+				}
801 838
 			}
802 839
 		}
803 840
 	}
@@ -828,8 +865,9 @@  discard block
 block discarded – undo
828 865
 	$boardsAllowed = boardsAllowedTo('view_attachments');
829 866
 
830 867
 	// Make sure we can't actually see anything...
831
-	if (empty($boardsAllowed))
832
-		$boardsAllowed = array(-1);
868
+	if (empty($boardsAllowed)) {
869
+			$boardsAllowed = array(-1);
870
+	}
833 871
 
834 872
 	require_once($sourcedir . '/Subs-List.php');
835 873
 
@@ -980,8 +1018,8 @@  discard block
 block discarded – undo
980 1018
 		)
981 1019
 	);
982 1020
 	$attachments = array();
983
-	while ($row = $smcFunc['db_fetch_assoc']($request))
984
-		$attachments[] = array(
1021
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1022
+			$attachments[] = array(
985 1023
 			'id' => $row['id_attach'],
986 1024
 			'filename' => $row['filename'],
987 1025
 			'downloads' => $row['downloads'],
@@ -993,6 +1031,7 @@  discard block
 block discarded – undo
993 1031
 			'board_name' => $row['name'],
994 1032
 			'approved' => $row['approved'],
995 1033
 		);
1034
+	}
996 1035
 
997 1036
 	$smcFunc['db_free_result']($request);
998 1037
 
@@ -1047,8 +1086,9 @@  discard block
 block discarded – undo
1047 1086
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1048 1087
 
1049 1088
 	// Only the owner can see the list (if the function is enabled of course)
1050
-	if ($user_info['id'] != $memID)
1051
-		return;
1089
+	if ($user_info['id'] != $memID) {
1090
+			return;
1091
+	}
1052 1092
 
1053 1093
 	require_once($sourcedir . '/Subs-List.php');
1054 1094
 
@@ -1194,8 +1234,9 @@  discard block
 block discarded – undo
1194 1234
 	);
1195 1235
 
1196 1236
 	$topics = array();
1197
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1198
-		$topics[] = $row['id_topic'];
1237
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1238
+			$topics[] = $row['id_topic'];
1239
+	}
1199 1240
 
1200 1241
 	$smcFunc['db_free_result']($request);
1201 1242
 
@@ -1215,8 +1256,9 @@  discard block
 block discarded – undo
1215 1256
 				'topics' => $topics,
1216 1257
 			)
1217 1258
 		);
1218
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1219
-			$topicsInfo[] = $row;
1259
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1260
+					$topicsInfo[] = $row;
1261
+		}
1220 1262
 		$smcFunc['db_free_result']($request);
1221 1263
 	}
1222 1264
 
@@ -1264,8 +1306,9 @@  discard block
 block discarded – undo
1264 1306
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1265 1307
 
1266 1308
 	// Is the load average too high to allow searching just now?
1267
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1268
-		fatal_lang_error('loadavg_userstats_disabled', false);
1309
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1310
+			fatal_lang_error('loadavg_userstats_disabled', false);
1311
+	}
1269 1312
 
1270 1313
 	// General user statistics.
1271 1314
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1408,11 +1451,13 @@  discard block
 block discarded – undo
1408 1451
 	}
1409 1452
 	$smcFunc['db_free_result']($result);
1410 1453
 
1411
-	if ($maxPosts > 0)
1412
-		for ($hour = 0; $hour < 24; $hour++)
1454
+	if ($maxPosts > 0) {
1455
+			for ($hour = 0;
1456
+	}
1457
+	$hour < 24; $hour++)
1413 1458
 		{
1414
-			if (!isset($context['posts_by_time'][$hour]))
1415
-				$context['posts_by_time'][$hour] = array(
1459
+			if (!isset($context['posts_by_time'][$hour])) {
1460
+							$context['posts_by_time'][$hour] = array(
1416 1461
 					'hour' => $hour,
1417 1462
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1418 1463
 					'posts' => 0,
@@ -1420,7 +1465,7 @@  discard block
 block discarded – undo
1420 1465
 					'relative_percent' => 0,
1421 1466
 					'is_last' => $hour == 23,
1422 1467
 				);
1423
-			else
1468
+			} else
1424 1469
 			{
1425 1470
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1426 1471
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1453,8 +1498,9 @@  discard block
 block discarded – undo
1453 1498
 
1454 1499
 	foreach ($subActions as $sa => $action)
1455 1500
 	{
1456
-		if (!allowedTo($action[2]))
1457
-			unset($subActions[$sa]);
1501
+		if (!allowedTo($action[2])) {
1502
+					unset($subActions[$sa]);
1503
+		}
1458 1504
 	}
1459 1505
 
1460 1506
 	// Create the tabs for the template.
@@ -1472,15 +1518,18 @@  discard block
 block discarded – undo
1472 1518
 	);
1473 1519
 
1474 1520
 	// Moderation must be on to track edits.
1475
-	if (empty($modSettings['userlog_enabled']))
1476
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1521
+	if (empty($modSettings['userlog_enabled'])) {
1522
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1523
+	}
1477 1524
 
1478 1525
 	// Group requests must be active to show it...
1479
-	if (empty($modSettings['show_group_membership']))
1480
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1526
+	if (empty($modSettings['show_group_membership'])) {
1527
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1528
+	}
1481 1529
 
1482
-	if (empty($subActions))
1483
-		fatal_lang_error('no_access', false);
1530
+	if (empty($subActions)) {
1531
+			fatal_lang_error('no_access', false);
1532
+	}
1484 1533
 
1485 1534
 	$keys = array_keys($subActions);
1486 1535
 	$default = array_shift($keys);
@@ -1493,9 +1542,10 @@  discard block
 block discarded – undo
1493 1542
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1494 1543
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1495 1544
 
1496
-	if (!empty($call))
1497
-		call_user_func($call, $memID);
1498
-}
1545
+	if (!empty($call)) {
1546
+			call_user_func($call, $memID);
1547
+	}
1548
+	}
1499 1549
 
1500 1550
 /**
1501 1551
  * Handles tracking a user's activity
@@ -1511,8 +1561,9 @@  discard block
 block discarded – undo
1511 1561
 	isAllowedTo('moderate_forum');
1512 1562
 
1513 1563
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1514
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1515
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1564
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1565
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1566
+	}
1516 1567
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1517 1568
 
1518 1569
 	// Set the options for the list component.
@@ -1679,8 +1730,9 @@  discard block
 block discarded – undo
1679 1730
 			)
1680 1731
 		);
1681 1732
 		$message_members = array();
1682
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1683
-			$message_members[] = $row['id_member'];
1733
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1734
+					$message_members[] = $row['id_member'];
1735
+		}
1684 1736
 		$smcFunc['db_free_result']($request);
1685 1737
 
1686 1738
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1695,8 +1747,9 @@  discard block
 block discarded – undo
1695 1747
 					'ip_list' => $ips,
1696 1748
 				)
1697 1749
 			);
1698
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1699
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1750
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1751
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1752
+			}
1700 1753
 			$smcFunc['db_free_result']($request);
1701 1754
 		}
1702 1755
 
@@ -1710,8 +1763,9 @@  discard block
 block discarded – undo
1710 1763
 				'ip_list' => $ips,
1711 1764
 			)
1712 1765
 		);
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>';
1766
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1767
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1768
+		}
1715 1769
 		$smcFunc['db_free_result']($request);
1716 1770
 	}
1717 1771
 }
@@ -1771,8 +1825,8 @@  discard block
 block discarded – undo
1771 1825
 		))
1772 1826
 	);
1773 1827
 	$error_messages = array();
1774
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1775
-		$error_messages[] = array(
1828
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1829
+			$error_messages[] = array(
1776 1830
 			'ip' => inet_dtop($row['ip']),
1777 1831
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1778 1832
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1780,6 +1834,7 @@  discard block
 block discarded – undo
1780 1834
 			'time' => timeformat($row['log_time']),
1781 1835
 			'timestamp' => forum_time(true, $row['log_time']),
1782 1836
 		);
1837
+	}
1783 1838
 	$smcFunc['db_free_result']($request);
1784 1839
 
1785 1840
 	return $error_messages;
@@ -1842,8 +1897,8 @@  discard block
 block discarded – undo
1842 1897
 		))
1843 1898
 	);
1844 1899
 	$messages = array();
1845
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1846
-		$messages[] = array(
1900
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1901
+			$messages[] = array(
1847 1902
 			'ip' => inet_dtop($row['poster_ip']),
1848 1903
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1849 1904
 			'board' => array(
@@ -1856,6 +1911,7 @@  discard block
 block discarded – undo
1856 1911
 			'time' => timeformat($row['poster_time']),
1857 1912
 			'timestamp' => forum_time(true, $row['poster_time'])
1858 1913
 		);
1914
+	}
1859 1915
 	$smcFunc['db_free_result']($request);
1860 1916
 
1861 1917
 	return $messages;
@@ -1882,19 +1938,20 @@  discard block
 block discarded – undo
1882 1938
 		$context['sub_template'] = 'trackIP';
1883 1939
 		$context['page_title'] = $txt['profile'];
1884 1940
 		$context['base_url'] = $scripturl . '?action=trackip';
1885
-	}
1886
-	else
1941
+	} else
1887 1942
 	{
1888 1943
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1889 1944
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1890 1945
 	}
1891 1946
 
1892 1947
 	// Searching?
1893
-	if (isset($_REQUEST['searchip']))
1894
-		$context['ip'] = trim($_REQUEST['searchip']);
1948
+	if (isset($_REQUEST['searchip'])) {
1949
+			$context['ip'] = trim($_REQUEST['searchip']);
1950
+	}
1895 1951
 
1896
-	if (isValidIP($context['ip']) === false)
1897
-		fatal_lang_error('invalid_tracking_ip', false);
1952
+	if (isValidIP($context['ip']) === false) {
1953
+			fatal_lang_error('invalid_tracking_ip', false);
1954
+	}
1898 1955
 
1899 1956
 	//mysql didn't support like search with varbinary
1900 1957
 	//$ip_var = str_replace('*', '%', $context['ip']);
@@ -1902,8 +1959,9 @@  discard block
 block discarded – undo
1902 1959
 	$ip_var = $context['ip'];
1903 1960
 	$ip_string = '= {inet:ip_address}';
1904 1961
 
1905
-	if (empty($context['tracking_area']))
1906
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1962
+	if (empty($context['tracking_area'])) {
1963
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1964
+	}
1907 1965
 
1908 1966
 	$request = $smcFunc['db_query']('', '
1909 1967
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1914,8 +1972,9 @@  discard block
 block discarded – undo
1914 1972
 		)
1915 1973
 	);
1916 1974
 	$context['ips'] = array();
1917
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1918
-		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1975
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1976
+			$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1977
+	}
1919 1978
 	$smcFunc['db_free_result']($request);
1920 1979
 
1921 1980
 	ksort($context['ips']);
@@ -2144,8 +2203,9 @@  discard block
 block discarded – undo
2144 2203
 		foreach ($context['whois_servers'] as $whois)
2145 2204
 		{
2146 2205
 			// Strip off the "decimal point" and anything following...
2147
-			if (in_array((int) $context['ip'], $whois['range']))
2148
-				$context['auto_whois_server'] = $whois;
2206
+			if (in_array((int) $context['ip'], $whois['range'])) {
2207
+							$context['auto_whois_server'] = $whois;
2208
+			}
2149 2209
 		}
2150 2210
 	}
2151 2211
 }
@@ -2162,10 +2222,11 @@  discard block
 block discarded – undo
2162 2222
 	// Gonna want this for the list.
2163 2223
 	require_once($sourcedir . '/Subs-List.php');
2164 2224
 
2165
-	if ($memID == 0)
2166
-		$context['base_url'] = $scripturl . '?action=trackip';
2167
-	else
2168
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2225
+	if ($memID == 0) {
2226
+			$context['base_url'] = $scripturl . '?action=trackip';
2227
+	} else {
2228
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2229
+	}
2169 2230
 
2170 2231
 	// Start with the user messages.
2171 2232
 	$listOptions = array(
@@ -2275,12 +2336,13 @@  discard block
 block discarded – undo
2275 2336
 		)
2276 2337
 	);
2277 2338
 	$logins = array();
2278
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2279
-		$logins[] = array(
2339
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2340
+			$logins[] = array(
2280 2341
 			'time' => timeformat($row['time']),
2281 2342
 			'ip' => inet_dtop($row['ip']),
2282 2343
 			'ip2' => inet_dtop($row['ip2']),
2283 2344
 		);
2345
+	}
2284 2346
 	$smcFunc['db_free_result']($request);
2285 2347
 
2286 2348
 	return $logins;
@@ -2305,11 +2367,12 @@  discard block
 block discarded – undo
2305 2367
 		)
2306 2368
 	);
2307 2369
 	$context['custom_field_titles'] = array();
2308
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2309
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2370
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2371
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2310 2372
 			'title' => $row['field_name'],
2311 2373
 			'parse_bbc' => $row['bbc'],
2312 2374
 		);
2375
+	}
2313 2376
 	$smcFunc['db_free_result']($request);
2314 2377
 
2315 2378
 	// Set the options for the error lists.
@@ -2448,19 +2511,22 @@  discard block
 block discarded – undo
2448 2511
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2449 2512
 	{
2450 2513
 		$extra = $smcFunc['json_decode']($row['extra'], true);
2451
-		if (!empty($extra['applicator']))
2452
-			$members[] = $extra['applicator'];
2514
+		if (!empty($extra['applicator'])) {
2515
+					$members[] = $extra['applicator'];
2516
+		}
2453 2517
 
2454 2518
 		// Work out what the name of the action is.
2455
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2456
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2457
-		elseif (isset($txt[$row['action']]))
2458
-			$action_text = $txt[$row['action']];
2519
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2520
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2521
+		} elseif (isset($txt[$row['action']])) {
2522
+					$action_text = $txt[$row['action']];
2523
+		}
2459 2524
 		// Custom field?
2460
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2461
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2462
-		else
2463
-			$action_text = $row['action'];
2525
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2526
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2527
+		} else {
2528
+					$action_text = $row['action'];
2529
+		}
2464 2530
 
2465 2531
 		// Parse BBC?
2466 2532
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2492,13 +2558,15 @@  discard block
 block discarded – undo
2492 2558
 			)
2493 2559
 		);
2494 2560
 		$members = array();
2495
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2496
-			$members[$row['id_member']] = $row['real_name'];
2561
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2562
+					$members[$row['id_member']] = $row['real_name'];
2563
+		}
2497 2564
 		$smcFunc['db_free_result']($request);
2498 2565
 
2499
-		foreach ($edits as $key => $value)
2500
-			if (isset($members[$value['id_member']]))
2566
+		foreach ($edits as $key => $value) {
2567
+					if (isset($members[$value['id_member']]))
2501 2568
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2569
+		}
2502 2570
 	}
2503 2571
 
2504 2572
 	return $edits;
@@ -2699,10 +2767,11 @@  discard block
 block discarded – undo
2699 2767
 	$context['board'] = $board;
2700 2768
 
2701 2769
 	// Determine which groups this user is in.
2702
-	if (empty($user_profile[$memID]['additional_groups']))
2703
-		$curGroups = array();
2704
-	else
2705
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2770
+	if (empty($user_profile[$memID]['additional_groups'])) {
2771
+			$curGroups = array();
2772
+	} else {
2773
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2774
+	}
2706 2775
 	$curGroups[] = $user_profile[$memID]['id_group'];
2707 2776
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2708 2777
 
@@ -2722,28 +2791,30 @@  discard block
 block discarded – undo
2722 2791
 	$context['no_access_boards'] = array();
2723 2792
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2724 2793
 	{
2725
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2726
-			$context['no_access_boards'][] = array(
2794
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2795
+					$context['no_access_boards'][] = array(
2727 2796
 				'id' => $row['id_board'],
2728 2797
 				'name' => $row['name'],
2729 2798
 				'is_last' => false,
2730 2799
 			);
2731
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2732
-			$context['boards'][$row['id_board']] = array(
2800
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2801
+					$context['boards'][$row['id_board']] = array(
2733 2802
 				'id' => $row['id_board'],
2734 2803
 				'name' => $row['name'],
2735 2804
 				'selected' => $board == $row['id_board'],
2736 2805
 				'profile' => $row['id_profile'],
2737 2806
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2738 2807
 			);
2808
+		}
2739 2809
 	}
2740 2810
 	$smcFunc['db_free_result']($request);
2741 2811
 
2742 2812
 	require_once($sourcedir . '/Subs-Boards.php');
2743 2813
 	sortBoards($context['boards']);
2744 2814
 
2745
-	if (!empty($context['no_access_boards']))
2746
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2815
+	if (!empty($context['no_access_boards'])) {
2816
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2817
+	}
2747 2818
 
2748 2819
 	$context['member']['permissions'] = array(
2749 2820
 		'general' => array(),
@@ -2752,8 +2823,9 @@  discard block
 block discarded – undo
2752 2823
 
2753 2824
 	// If you're an admin we know you can do everything, we might as well leave.
2754 2825
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2755
-	if ($context['member']['has_all_permissions'])
2756
-		return;
2826
+	if ($context['member']['has_all_permissions']) {
2827
+			return;
2828
+	}
2757 2829
 
2758 2830
 	$denied = array();
2759 2831
 
@@ -2772,21 +2844,24 @@  discard block
 block discarded – undo
2772 2844
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2773 2845
 	{
2774 2846
 		// We don't know about this permission, it doesn't exist :P.
2775
-		if (!isset($txt['permissionname_' . $row['permission']]))
2776
-			continue;
2847
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2848
+					continue;
2849
+		}
2777 2850
 
2778
-		if (empty($row['add_deny']))
2779
-			$denied[] = $row['permission'];
2851
+		if (empty($row['add_deny'])) {
2852
+					$denied[] = $row['permission'];
2853
+		}
2780 2854
 
2781 2855
 		// Permissions that end with _own or _any consist of two parts.
2782
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2783
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2784
-		else
2785
-			$name = $txt['permissionname_' . $row['permission']];
2856
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2857
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2858
+		} else {
2859
+					$name = $txt['permissionname_' . $row['permission']];
2860
+		}
2786 2861
 
2787 2862
 		// Add this permission if it doesn't exist yet.
2788
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2789
-			$context['member']['permissions']['general'][$row['permission']] = array(
2863
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2864
+					$context['member']['permissions']['general'][$row['permission']] = array(
2790 2865
 				'id' => $row['permission'],
2791 2866
 				'groups' => array(
2792 2867
 					'allowed' => array(),
@@ -2796,6 +2871,7 @@  discard block
 block discarded – undo
2796 2871
 				'is_denied' => false,
2797 2872
 				'is_global' => true,
2798 2873
 			);
2874
+		}
2799 2875
 
2800 2876
 		// Add the membergroup to either the denied or the allowed groups.
2801 2877
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2829,18 +2905,20 @@  discard block
 block discarded – undo
2829 2905
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2830 2906
 	{
2831 2907
 		// We don't know about this permission, it doesn't exist :P.
2832
-		if (!isset($txt['permissionname_' . $row['permission']]))
2833
-			continue;
2908
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2909
+					continue;
2910
+		}
2834 2911
 
2835 2912
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2836
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2837
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2838
-		else
2839
-			$name = $txt['permissionname_' . $row['permission']];
2913
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2914
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2915
+		} else {
2916
+					$name = $txt['permissionname_' . $row['permission']];
2917
+		}
2840 2918
 
2841 2919
 		// Create the structure for this permission.
2842
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2843
-			$context['member']['permissions']['board'][$row['permission']] = array(
2920
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2921
+					$context['member']['permissions']['board'][$row['permission']] = array(
2844 2922
 				'id' => $row['permission'],
2845 2923
 				'groups' => array(
2846 2924
 					'allowed' => array(),
@@ -2850,6 +2928,7 @@  discard block
 block discarded – undo
2850 2928
 				'is_denied' => false,
2851 2929
 				'is_global' => empty($board),
2852 2930
 			);
2931
+		}
2853 2932
 
2854 2933
 		$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'];
2855 2934
 
@@ -2868,8 +2947,9 @@  discard block
 block discarded – undo
2868 2947
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2869 2948
 
2870 2949
 	// Firstly, can we actually even be here?
2871
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2872
-		fatal_lang_error('no_access', false);
2950
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2951
+			fatal_lang_error('no_access', false);
2952
+	}
2873 2953
 
2874 2954
 	// Make sure things which are disabled stay disabled.
2875 2955
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2956,9 +3036,10 @@  discard block
 block discarded – undo
2956 3036
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2957 3037
 	);
2958 3038
 	$context['current_level'] = 0;
2959
-	foreach ($context['level_effects'] as $limit => $dummy)
2960
-		if ($context['member']['warning'] >= $limit)
3039
+	foreach ($context['level_effects'] as $limit => $dummy) {
3040
+			if ($context['member']['warning'] >= $limit)
2961 3041
 			$context['current_level'] = $limit;
2962
-}
3042
+	}
3043
+	}
2963 3044
 
2964 3045
 ?>
2965 3046
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/QueryString.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@
 block discarded – undo
325 325
  * Validates a IPv6 address. returns true if it is ipv6.
326 326
  *
327 327
  * @param string $ip The ip address to be validated
328
- * @return boolean Whether the specified IP is a valid IPv6 address
328
+ * @return false|string Whether the specified IP is a valid IPv6 address
329 329
  */
330 330
 function isValidIPv6($ip)
331 331
 {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -426,8 +426,8 @@
 block discarded – undo
426 426
 */
427 427
 function matchIPtoCIDR($ip_address, $cidr_address)
428 428
 {
429
-    list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
430
-    return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
429
+	list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address);
430
+	return (ip2long($ip_address) & (~((1 << (32 - $cidr_subnetmask)) - 1))) == ip2long($cidr_network);
431 431
 }
432 432
 
433 433
 /**
Please login to merge, or discard this patch.
Braces   +187 added lines, -132 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Clean the request variables - add html entities to GET and slashes if magic_quotes_gpc is Off.
@@ -44,22 +45,26 @@  discard block
 block discarded – undo
44 45
 	unset($GLOBALS['HTTP_POST_FILES'], $GLOBALS['HTTP_POST_FILES']);
45 46
 
46 47
 	// These keys shouldn't be set...ever.
47
-	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
48
-		die('Invalid request variable.');
48
+	if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
49
+			die('Invalid request variable.');
50
+	}
49 51
 
50 52
 	// Same goes for numeric keys.
51
-	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key)
52
-		if (is_numeric($key))
53
+	foreach (array_merge(array_keys($_POST), array_keys($_GET), array_keys($_FILES)) as $key) {
54
+			if (is_numeric($key))
53 55
 			die('Numeric request keys are invalid.');
56
+	}
54 57
 
55 58
 	// Numeric keys in cookies are less of a problem. Just unset those.
56
-	foreach ($_COOKIE as $key => $value)
57
-		if (is_numeric($key))
59
+	foreach ($_COOKIE as $key => $value) {
60
+			if (is_numeric($key))
58 61
 			unset($_COOKIE[$key]);
62
+	}
59 63
 
60 64
 	// Get the correct query string.  It may be in an environment variable...
61
-	if (!isset($_SERVER['QUERY_STRING']))
62
-		$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
65
+	if (!isset($_SERVER['QUERY_STRING'])) {
66
+			$_SERVER['QUERY_STRING'] = getenv('QUERY_STRING');
67
+	}
63 68
 
64 69
 	// It seems that sticking a URL after the query string is mighty common, well, it's evil - don't.
65 70
 	if (strpos($_SERVER['QUERY_STRING'], 'http') === 0)
@@ -83,13 +88,14 @@  discard block
 block discarded – undo
83 88
 		parse_str(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr($_SERVER['QUERY_STRING'], array(';?' => '&', ';' => '&', '%00' => '', "\0" => ''))), $_GET);
84 89
 
85 90
 		// Magic quotes still applies with parse_str - so clean it up.
86
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
87
-			$_GET = $removeMagicQuoteFunction($_GET);
88
-	}
89
-	elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
91
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
92
+					$_GET = $removeMagicQuoteFunction($_GET);
93
+		}
94
+	} elseif (strpos(ini_get('arg_separator.input'), ';') !== false)
90 95
 	{
91
-		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
92
-			$_GET = $removeMagicQuoteFunction($_GET);
96
+		if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
97
+					$_GET = $removeMagicQuoteFunction($_GET);
98
+		}
93 99
 
94 100
 		// Search engines will send action=profile%3Bu=1, which confuses PHP.
95 101
 		foreach ($_GET as $k => $v)
@@ -102,8 +108,9 @@  discard block
 block discarded – undo
102 108
 				for ($i = 1, $n = count($temp); $i < $n; $i++)
103 109
 				{
104 110
 					@list ($key, $val) = @explode('=', $temp[$i], 2);
105
-					if (!isset($_GET[$key]))
106
-						$_GET[$key] = $val;
111
+					if (!isset($_GET[$key])) {
112
+											$_GET[$key] = $val;
113
+					}
107 114
 				}
108 115
 			}
109 116
 
@@ -120,18 +127,20 @@  discard block
 block discarded – undo
120 127
 	if (!empty($_SERVER['REQUEST_URI']))
121 128
 	{
122 129
 		// Remove the .html, assuming there is one.
123
-		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm')
124
-			$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
125
-		else
126
-			$request = $_SERVER['REQUEST_URI'];
130
+		if (substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '.'), 4) == '.htm') {
131
+					$request = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '.'));
132
+		} else {
133
+					$request = $_SERVER['REQUEST_URI'];
134
+		}
127 135
 
128 136
 		// @todo smflib.
129 137
 		// Replace 'index.php/a,b,c/d/e,f' with 'a=b,c&d=&e=f' and parse it into $_GET.
130 138
 		if (strpos($request, basename($scripturl) . '/') !== false)
131 139
 		{
132 140
 			parse_str(substr(preg_replace('/&(\w+)(?=&|$)/', '&$1=', strtr(preg_replace('~/([^,/]+),~', '/$1=', substr($request, strpos($request, basename($scripturl)) + strlen(basename($scripturl)))), '/', '&')), 1), $temp);
133
-			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes']))
134
-				$temp = $removeMagicQuoteFunction($temp);
141
+			if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() != 0 && empty($modSettings['integrate_magic_quotes'])) {
142
+							$temp = $removeMagicQuoteFunction($temp);
143
+			}
135 144
 			$_GET += $temp;
136 145
 		}
137 146
 	}
@@ -142,9 +151,10 @@  discard block
 block discarded – undo
142 151
 		$_ENV = $removeMagicQuoteFunction($_ENV);
143 152
 		$_POST = $removeMagicQuoteFunction($_POST);
144 153
 		$_COOKIE = $removeMagicQuoteFunction($_COOKIE);
145
-		foreach ($_FILES as $k => $dummy)
146
-			if (isset($_FILES[$k]['name']))
154
+		foreach ($_FILES as $k => $dummy) {
155
+					if (isset($_FILES[$k]['name']))
147 156
 				$_FILES[$k]['name'] = $removeMagicQuoteFunction($_FILES[$k]['name']);
157
+		}
148 158
 	}
149 159
 
150 160
 	// Add entities to GET.  This is kinda like the slashes on everything else.
@@ -160,11 +170,13 @@  discard block
 block discarded – undo
160 170
 		$_REQUEST['board'] = (string) $_REQUEST['board'];
161 171
 
162 172
 		// If there's a slash in it, we've got a start value! (old, compatible links.)
163
-		if (strpos($_REQUEST['board'], '/') !== false)
164
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
173
+		if (strpos($_REQUEST['board'], '/') !== false) {
174
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('/', $_REQUEST['board']);
175
+		}
165 176
 		// Same idea, but dots.  This is the currently used format - ?board=1.0...
166
-		elseif (strpos($_REQUEST['board'], '.') !== false)
167
-			list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
177
+		elseif (strpos($_REQUEST['board'], '.') !== false) {
178
+					list ($_REQUEST['board'], $_REQUEST['start']) = explode('.', $_REQUEST['board']);
179
+		}
168 180
 		// Now make absolutely sure it's a number.
169 181
 		$board = (int) $_REQUEST['board'];
170 182
 		$_REQUEST['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
@@ -173,12 +185,14 @@  discard block
 block discarded – undo
173 185
 		$_GET['board'] = $board;
174 186
 	}
175 187
 	// Well, $board is going to be a number no matter what.
176
-	else
177
-		$board = 0;
188
+	else {
189
+			$board = 0;
190
+	}
178 191
 
179 192
 	// If there's a threadid, it's probably an old YaBB SE link.  Flow with it.
180
-	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic']))
181
-		$_REQUEST['topic'] = $_REQUEST['threadid'];
193
+	if (isset($_REQUEST['threadid']) && !isset($_REQUEST['topic'])) {
194
+			$_REQUEST['topic'] = $_REQUEST['threadid'];
195
+	}
182 196
 
183 197
 	// We've got topic!
184 198
 	if (isset($_REQUEST['topic']))
@@ -187,11 +201,13 @@  discard block
 block discarded – undo
187 201
 		$_REQUEST['topic'] = (string) $_REQUEST['topic'];
188 202
 
189 203
 		// Slash means old, beta style, formatting.  That's okay though, the link should still work.
190
-		if (strpos($_REQUEST['topic'], '/') !== false)
191
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
204
+		if (strpos($_REQUEST['topic'], '/') !== false) {
205
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('/', $_REQUEST['topic']);
206
+		}
192 207
 		// Dots are useful and fun ;).  This is ?topic=1.15.
193
-		elseif (strpos($_REQUEST['topic'], '.') !== false)
194
-			list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
208
+		elseif (strpos($_REQUEST['topic'], '.') !== false) {
209
+					list ($_REQUEST['topic'], $_REQUEST['start']) = explode('.', $_REQUEST['topic']);
210
+		}
195 211
 
196 212
 		// Topic should always be an integer
197 213
 		$topic = $_GET['topic'] = $_REQUEST['topic'] = (int) $_REQUEST['topic'];
@@ -220,21 +236,25 @@  discard block
 block discarded – undo
220 236
 			$_REQUEST['start'] = $timestamp === 0 ? 0 : 'from' . $timestamp;
221 237
 		}
222 238
 		// ... or something invalid, in which case we reset it to 0.
223
-		else
224
-			$_REQUEST['start'] = 0;
239
+		else {
240
+					$_REQUEST['start'] = 0;
241
+		}
242
+	} else {
243
+			$topic = 0;
225 244
 	}
226
-	else
227
-		$topic = 0;
228 245
 
229 246
 	// There should be a $_REQUEST['start'], some at least.  If you need to default to other than 0, use $_GET['start'].
230
-	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647)
231
-		$_REQUEST['start'] = 0;
247
+	if (empty($_REQUEST['start']) || $_REQUEST['start'] < 0 || (int) $_REQUEST['start'] > 2147473647) {
248
+			$_REQUEST['start'] = 0;
249
+	}
232 250
 
233 251
 	// The action needs to be a string and not an array or anything else
234
-	if (isset($_REQUEST['action']))
235
-		$_REQUEST['action'] = (string) $_REQUEST['action'];
236
-	if (isset($_GET['action']))
237
-		$_GET['action'] = (string) $_GET['action'];
252
+	if (isset($_REQUEST['action'])) {
253
+			$_REQUEST['action'] = (string) $_REQUEST['action'];
254
+	}
255
+	if (isset($_GET['action'])) {
256
+			$_GET['action'] = (string) $_GET['action'];
257
+	}
238 258
 
239 259
 	// Some mail providers like to encode semicolons in activation URLs...
240 260
 	if (!empty($_REQUEST['action']) && substr($_SERVER['QUERY_STRING'], 0, 18) == 'action=activate%3b')
@@ -260,29 +280,33 @@  discard block
 block discarded – undo
260 280
 	$_SERVER['BAN_CHECK_IP'] = $_SERVER['REMOTE_ADDR'];
261 281
 
262 282
 	// If we haven't specified how to handle Reverse Proxy IP headers, lets do what we always used to do.
263
-	if (!isset($modSettings['proxy_ip_header']))
264
-		$modSettings['proxy_ip_header'] = 'autodetect';
283
+	if (!isset($modSettings['proxy_ip_header'])) {
284
+			$modSettings['proxy_ip_header'] = 'autodetect';
285
+	}
265 286
 
266 287
 	// Which headers are we going to check for Reverse Proxy IP headers?
267
-	if ($modSettings['proxy_ip_header'] == 'disabled')
268
-		$reverseIPheaders = array();
269
-	elseif ($modSettings['proxy_ip_header'] == 'autodetect')
270
-		$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
271
-	else
272
-		$reverseIPheaders = array($modSettings['proxy_ip_header']);
288
+	if ($modSettings['proxy_ip_header'] == 'disabled') {
289
+			$reverseIPheaders = array();
290
+	} elseif ($modSettings['proxy_ip_header'] == 'autodetect') {
291
+			$reverseIPheaders = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
292
+	} else {
293
+			$reverseIPheaders = array($modSettings['proxy_ip_header']);
294
+	}
273 295
 
274 296
 	// Find the user's IP address. (but don't let it give you 'unknown'!)
275 297
 	foreach ($reverseIPheaders as $proxyIPheader)
276 298
 	{
277 299
 		// Ignore if this is not set.
278
-		if (!isset($_SERVER[$proxyIPheader]))
279
-			continue;
300
+		if (!isset($_SERVER[$proxyIPheader])) {
301
+					continue;
302
+		}
280 303
 
281 304
 		if (!empty($modSettings['proxy_ip_servers']))
282 305
 		{
283
-			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy)
284
-				if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
306
+			foreach (explode(',', $modSettings['proxy_ip_servers']) as $proxy) {
307
+							if ($proxy == $_SERVER['REMOTE_ADDR'] || matchIPtoCIDR($_SERVER['REMOTE_ADDR'], $proxy))
285 308
 					continue;
309
+			}
286 310
 		}
287 311
 
288 312
 		// If there are commas, get the last one.. probably.
@@ -302,8 +326,9 @@  discard block
 block discarded – undo
302 326
 
303 327
 						// Just incase we have a legacy IPv4 address.
304 328
 						// @ TODO: Convert to IPv6.
305
-						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
306
-							continue;
329
+						if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
330
+													continue;
331
+						}
307 332
 					}
308 333
 
309 334
 					continue;
@@ -315,36 +340,40 @@  discard block
 block discarded – undo
315 340
 			}
316 341
 		}
317 342
 		// Otherwise just use the only one.
318
-		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0)
319
-			$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
320
-		elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
343
+		elseif (preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER[$proxyIPheader]) == 0 || preg_match('~^((0|10|172\.(1[6-9]|2[0-9]|3[01])|192\.168|255|127)\.|unknown|::1|fe80::|fc00::)~', $_SERVER['REMOTE_ADDR']) != 0) {
344
+					$_SERVER['BAN_CHECK_IP'] = $_SERVER[$proxyIPheader];
345
+		} elseif (!isValidIPv6($_SERVER[$proxyIPheader]) || preg_match('~::ffff:\d+\.\d+\.\d+\.\d+~', $_SERVER[$proxyIPheader]) !== 0)
321 346
 		{
322 347
 			$_SERVER[$proxyIPheader] = preg_replace('~^::ffff:(\d+\.\d+\.\d+\.\d+)~', '\1', $_SERVER[$proxyIPheader]);
323 348
 
324 349
 			// Just incase we have a legacy IPv4 address.
325 350
 			// @ TODO: Convert to IPv6.
326
-			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0)
327
-				continue;
351
+			if (preg_match('~^((([1]?\d)?\d|2[0-4]\d|25[0-5])\.){3}(([1]?\d)?\d|2[0-4]\d|25[0-5])$~', $_SERVER[$proxyIPheader]) === 0) {
352
+							continue;
353
+			}
328 354
 		}
329 355
 	}
330 356
 
331 357
 	// Make sure we know the URL of the current request.
332
-	if (empty($_SERVER['REQUEST_URI']))
333
-		$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
334
-	elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1)
335
-		$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
336
-	else
337
-		$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
358
+	if (empty($_SERVER['REQUEST_URI'])) {
359
+			$_SERVER['REQUEST_URL'] = $scripturl . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
360
+	} elseif (preg_match('~^([^/]+//[^/]+)~', $scripturl, $match) == 1) {
361
+			$_SERVER['REQUEST_URL'] = $match[1] . $_SERVER['REQUEST_URI'];
362
+	} else {
363
+			$_SERVER['REQUEST_URL'] = $_SERVER['REQUEST_URI'];
364
+	}
338 365
 
339 366
 	// And make sure HTTP_USER_AGENT is set.
340 367
 	$_SERVER['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES) : htmlspecialchars($smcFunc['db_unescape_string']($_SERVER['HTTP_USER_AGENT']), ENT_QUOTES)) : '';
341 368
 
342 369
 	// Some final checking.
343
-	if (!isValidIP($_SERVER['BAN_CHECK_IP']))
344
-		$_SERVER['BAN_CHECK_IP'] = '';
345
-	if ($_SERVER['REMOTE_ADDR'] == 'unknown')
346
-		$_SERVER['REMOTE_ADDR'] = '';
347
-}
370
+	if (!isValidIP($_SERVER['BAN_CHECK_IP'])) {
371
+			$_SERVER['BAN_CHECK_IP'] = '';
372
+	}
373
+	if ($_SERVER['REMOTE_ADDR'] == 'unknown') {
374
+			$_SERVER['REMOTE_ADDR'] = '';
375
+	}
376
+	}
348 377
 
349 378
 /**
350 379
  * Validates a IPv6 address. returns true if it is ipv6.
@@ -355,8 +384,9 @@  discard block
 block discarded – undo
355 384
 function isValidIPv6($ip)
356 385
 {
357 386
 	//looking for :
358
-	if (strpos($ip, ':') === false)
359
-		return false;
387
+	if (strpos($ip, ':') === false) {
388
+			return false;
389
+	}
360 390
 
361 391
 	//check valid address
362 392
 	return inet_pton($ip);
@@ -373,15 +403,17 @@  discard block
 block discarded – undo
373 403
 	static $expanded = array();
374 404
 
375 405
 	// Check if we have done this already.
376
-	if (isset($expanded[$ip]))
377
-		return $expanded[$ip];
406
+	if (isset($expanded[$ip])) {
407
+			return $expanded[$ip];
408
+	}
378 409
 
379 410
 	// Expand the IP out.
380 411
 	$expanded_ip = explode(':', expandIPv6($ip));
381 412
 
382 413
 	$new_ip = array();
383
-	foreach ($expanded_ip as $int)
384
-		$new_ip[] = hexdec($int);
414
+	foreach ($expanded_ip as $int) {
415
+			$new_ip[] = hexdec($int);
416
+	}
385 417
 
386 418
 	// Save this incase of repeated use.
387 419
 	$expanded[$ip] = $new_ip;
@@ -401,8 +433,9 @@  discard block
 block discarded – undo
401 433
 	static $converted = array();
402 434
 
403 435
 	// Check if we have done this already.
404
-	if (isset($converted[$addr]))
405
-		return $converted[$addr];
436
+	if (isset($converted[$addr])) {
437
+			return $converted[$addr];
438
+	}
406 439
 
407 440
 	// Check if there are segments missing, insert if necessary.
408 441
 	if (strpos($addr, '::') !== false)
@@ -412,18 +445,20 @@  discard block
 block discarded – undo
412 445
 		$part[1] = explode(':', $part[1]);
413 446
 		$missing = array();
414 447
 
415
-		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
416
-			array_push($missing, '0000');
448
+		for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
449
+					array_push($missing, '0000');
450
+		}
417 451
 
418 452
 		$part = array_merge($part[0], $missing, $part[1]);
453
+	} else {
454
+			$part = explode(':', $addr);
419 455
 	}
420
-	else
421
-		$part = explode(':', $addr);
422 456
 
423 457
 	// Pad each segment until it has 4 digits.
424
-	foreach ($part as &$p)
425
-		while (strlen($p) < 4)
458
+	foreach ($part as &$p) {
459
+			while (strlen($p) < 4)
426 460
 			$p = '0' . $p;
461
+	}
427 462
 
428 463
 	unset($p);
429 464
 
@@ -434,11 +469,12 @@  discard block
 block discarded – undo
434 469
 	$converted[$addr] = $result;
435 470
 
436 471
 	// Quick check to make sure the length is as expected.
437
-	if (!$strict_check || strlen($result) == 39)
438
-		return $result;
439
-	else
440
-		return false;
441
-}
472
+	if (!$strict_check || strlen($result) == 39) {
473
+			return $result;
474
+	} else {
475
+			return false;
476
+	}
477
+	}
442 478
 
443 479
 
444 480
 /**
@@ -469,15 +505,17 @@  discard block
 block discarded – undo
469 505
 {
470 506
 	global $smcFunc;
471 507
 
472
-	if (!is_array($var))
473
-		return $smcFunc['db_escape_string']($var);
508
+	if (!is_array($var)) {
509
+			return $smcFunc['db_escape_string']($var);
510
+	}
474 511
 
475 512
 	// Reindex the array with slashes.
476 513
 	$new_var = array();
477 514
 
478 515
 	// Add slashes to every element, even the indexes!
479
-	foreach ($var as $k => $v)
480
-		$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
516
+	foreach ($var as $k => $v) {
517
+			$new_var[$smcFunc['db_escape_string']($k)] = escapestring__recursive($v);
518
+	}
481 519
 
482 520
 	return $new_var;
483 521
 }
@@ -497,12 +535,14 @@  discard block
 block discarded – undo
497 535
 {
498 536
 	global $smcFunc;
499 537
 
500
-	if (!is_array($var))
501
-		return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
538
+	if (!is_array($var)) {
539
+			return isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($var, ENT_QUOTES) : htmlspecialchars($var, ENT_QUOTES);
540
+	}
502 541
 
503 542
 	// Add the htmlspecialchars to every element.
504
-	foreach ($var as $k => $v)
505
-		$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
543
+	foreach ($var as $k => $v) {
544
+			$var[$k] = $level > 25 ? null : htmlspecialchars__recursive($v, $level + 1);
545
+	}
506 546
 
507 547
 	return $var;
508 548
 }
@@ -520,15 +560,17 @@  discard block
 block discarded – undo
520 560
  */
521 561
 function urldecode__recursive($var, $level = 0)
522 562
 {
523
-	if (!is_array($var))
524
-		return urldecode($var);
563
+	if (!is_array($var)) {
564
+			return urldecode($var);
565
+	}
525 566
 
526 567
 	// Reindex the array...
527 568
 	$new_var = array();
528 569
 
529 570
 	// Add the htmlspecialchars to every element.
530
-	foreach ($var as $k => $v)
531
-		$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
571
+	foreach ($var as $k => $v) {
572
+			$new_var[urldecode($k)] = $level > 25 ? null : urldecode__recursive($v, $level + 1);
573
+	}
532 574
 
533 575
 	return $new_var;
534 576
 }
@@ -546,15 +588,17 @@  discard block
 block discarded – undo
546 588
 {
547 589
 	global $smcFunc;
548 590
 
549
-	if (!is_array($var))
550
-		return $smcFunc['db_unescape_string']($var);
591
+	if (!is_array($var)) {
592
+			return $smcFunc['db_unescape_string']($var);
593
+	}
551 594
 
552 595
 	// Reindex the array without slashes, this time.
553 596
 	$new_var = array();
554 597
 
555 598
 	// Strip the slashes from every element.
556
-	foreach ($var as $k => $v)
557
-		$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
599
+	foreach ($var as $k => $v) {
600
+			$new_var[$smcFunc['db_unescape_string']($k)] = unescapestring__recursive($v);
601
+	}
558 602
 
559 603
 	return $new_var;
560 604
 }
@@ -572,15 +616,17 @@  discard block
 block discarded – undo
572 616
  */
573 617
 function stripslashes__recursive($var, $level = 0)
574 618
 {
575
-	if (!is_array($var))
576
-		return stripslashes($var);
619
+	if (!is_array($var)) {
620
+			return stripslashes($var);
621
+	}
577 622
 
578 623
 	// Reindex the array without slashes, this time.
579 624
 	$new_var = array();
580 625
 
581 626
 	// Strip the slashes from every element.
582
-	foreach ($var as $k => $v)
583
-		$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
627
+	foreach ($var as $k => $v) {
628
+			$new_var[stripslashes($k)] = $level > 25 ? null : stripslashes__recursive($v, $level + 1);
629
+	}
584 630
 
585 631
 	return $new_var;
586 632
 }
@@ -601,12 +647,14 @@  discard block
 block discarded – undo
601 647
 	global $smcFunc;
602 648
 
603 649
 	// Remove spaces (32), tabs (9), returns (13, 10, and 11), nulls (0), and hard spaces. (160)
604
-	if (!is_array($var))
605
-		return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
650
+	if (!is_array($var)) {
651
+			return isset($smcFunc) ? $smcFunc['htmltrim']($var) : trim($var, ' ' . "\t\n\r\x0B" . '\0' . "\xA0");
652
+	}
606 653
 
607 654
 	// Go through all the elements and remove the whitespace.
608
-	foreach ($var as $k => $v)
609
-		$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
655
+	foreach ($var as $k => $v) {
656
+			$var[$k] = $level > 25 ? null : htmltrim__recursive($v, $level + 1);
657
+	}
610 658
 
611 659
 	return $var;
612 660
 }
@@ -671,30 +719,37 @@  discard block
 block discarded – undo
671 719
 	global $scripturl, $modSettings, $context;
672 720
 
673 721
 	// If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
674
-	if ($scripturl == '' || !defined('SID'))
675
-		return $buffer;
722
+	if ($scripturl == '' || !defined('SID')) {
723
+			return $buffer;
724
+	}
676 725
 
677 726
 	// Do nothing if the session is cookied, or they are a crawler - guests are caught by redirectexit().  This doesn't work below PHP 4.3.0, because it makes the output buffer bigger.
678 727
 	// @todo smflib
679
-	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot'))
680
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
728
+	if (empty($_COOKIE) && SID != '' && !isBrowser('possibly_robot')) {
729
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&amp;', $buffer);
730
+	}
681 731
 	// Debugging templates, are we?
682
-	elseif (isset($_GET['debug']))
683
-		$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
732
+	elseif (isset($_GET['debug'])) {
733
+			$buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
734
+	}
684 735
 
685 736
 	// This should work even in 4.2.x, just not CGI without cgi.fix_pathinfo.
686 737
 	if (!empty($modSettings['queryless_urls']) && (!$context['server']['is_cgi'] || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && ($context['server']['is_apache'] || $context['server']['is_lighttpd'] || $context['server']['is_litespeed']))
687 738
 	{
688 739
 		// Let's do something special for session ids!
689
-		if (defined('SID') && SID != '')
690
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
740
+		if (defined('SID') && SID != '') {
741
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
691 742
 			{
692
-				global $scripturl; return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
743
+				global $scripturl;
744
+		}
745
+		return '"' . $scripturl . "/" . strtr("$m[1]", '&;=', '//,') . ".html?" . SID . (isset($m[2]) ? $m[2] : "") . '"';
693 746
 			}, $buffer);
694
-		else
695
-			$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
747
+		else {
748
+					$buffer = preg_replace_callback('~"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"~', function($m)
696 749
 			{
697
-				global $scripturl; return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
750
+				global $scripturl;
751
+		}
752
+		return '"' . $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? $m[2] : "") . '"';
698 753
 			}, $buffer);
699 754
 	}
700 755
 
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   +277 added lines, -201 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
 
@@ -506,15 +531,17 @@  discard block
 block discarded – undo
506 531
 
507 532
 		// Store this useful data!
508 533
 		$boards[$row['id_board']] = $row['id_board'];
509
-		if ($row['id_topic'])
510
-			$notify['topics'][$row['id_topic']][] = $row['id_member'];
511
-		else
512
-			$notify['boards'][$row['id_board']][] = $row['id_member'];
534
+		if ($row['id_topic']) {
535
+					$notify['topics'][$row['id_topic']][] = $row['id_member'];
536
+		} else {
537
+					$notify['boards'][$row['id_board']][] = $row['id_member'];
538
+		}
513 539
 	}
514 540
 	$smcFunc['db_free_result']($request);
515 541
 
516
-	if (empty($boards))
517
-		return true;
542
+	if (empty($boards)) {
543
+			return true;
544
+	}
518 545
 
519 546
 	// Just get the board names.
520 547
 	$request = $smcFunc['db_query']('', '
@@ -526,12 +553,14 @@  discard block
 block discarded – undo
526 553
 		)
527 554
 	);
528 555
 	$boards = array();
529
-	while ($row = $smcFunc['db_fetch_assoc']($request))
530
-		$boards[$row['id_board']] = $row['name'];
556
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
557
+			$boards[$row['id_board']] = $row['name'];
558
+	}
531 559
 	$smcFunc['db_free_result']($request);
532 560
 
533
-	if (empty($boards))
534
-		return true;
561
+	if (empty($boards)) {
562
+			return true;
563
+	}
535 564
 
536 565
 	// Get the actual topics...
537 566
 	$request = $smcFunc['db_query']('', '
@@ -551,52 +580,57 @@  discard block
 block discarded – undo
551 580
 	$types = array();
552 581
 	while ($row = $smcFunc['db_fetch_assoc']($request))
553 582
 	{
554
-		if (!isset($types[$row['note_type']][$row['id_board']]))
555
-			$types[$row['note_type']][$row['id_board']] = array(
583
+		if (!isset($types[$row['note_type']][$row['id_board']])) {
584
+					$types[$row['note_type']][$row['id_board']] = array(
556 585
 				'lines' => array(),
557 586
 				'name' => $row['board_name'],
558 587
 				'id' => $row['id_board'],
559 588
 			);
589
+		}
560 590
 
561 591
 		if ($row['note_type'] == 'reply')
562 592
 		{
563
-			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
564
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
565
-			else
566
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
593
+			if (isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
594
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['count']++;
595
+			} else {
596
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
567 597
 					'id' => $row['id_topic'],
568 598
 					'subject' => un_htmlspecialchars($row['subject']),
569 599
 					'count' => 1,
570 600
 				);
571
-		}
572
-		elseif ($row['note_type'] == 'topic')
601
+			}
602
+		} elseif ($row['note_type'] == 'topic')
573 603
 		{
574
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
575
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
604
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
605
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
576 606
 					'id' => $row['id_topic'],
577 607
 					'subject' => un_htmlspecialchars($row['subject']),
578 608
 				);
579
-		}
580
-		else
609
+			}
610
+		} else
581 611
 		{
582
-			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]))
583
-				$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
612
+			if (!isset($types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']])) {
613
+							$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']] = array(
584 614
 					'id' => $row['id_topic'],
585 615
 					'subject' => un_htmlspecialchars($row['subject']),
586 616
 					'starter' => $row['id_member_started'],
587 617
 				);
618
+			}
588 619
 		}
589 620
 
590 621
 		$types[$row['note_type']][$row['id_board']]['lines'][$row['id_topic']]['members'] = array();
591
-		if (!empty($notify['topics'][$row['id_topic']]))
592
-			$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']]);
593
-		if (!empty($notify['boards'][$row['id_board']]))
594
-			$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']]);
622
+		if (!empty($notify['topics'][$row['id_topic']])) {
623
+					$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']]);
624
+		}
625
+		if (!empty($notify['boards'][$row['id_board']])) {
626
+					$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']]);
627
+		}
595 628
 	}
596 629
 	$smcFunc['db_free_result']($request);
597 630
 
598
-	if (empty($types))
599
-		return true;
631
+	if (empty($types)) {
632
+			return true;
633
+	}
600 634
 
601 635
 	// Let's load all the languages into a cache thingy.
602 636
 	$langtxt = array();
@@ -637,8 +671,9 @@  discard block
 block discarded – undo
637 671
 		$notify_types = !empty($prefs[$mid]['msg_notify_type']) ? $prefs[$mid]['msg_notify_type'] : 1;
638 672
 
639 673
 		// Did they not elect to choose this?
640
-		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4)
641
-			continue;
674
+		if ($frequency == 4 && !$is_weekly || $frequency == 3 && $is_weekly || $notify_types == 4) {
675
+					continue;
676
+		}
642 677
 
643 678
 		// Right character set!
644 679
 		$context['character_set'] = empty($modSettings['global_character_set']) ? $langtxt[$lang]['char_set'] : $modSettings['global_character_set'];
@@ -654,39 +689,43 @@  discard block
 block discarded – undo
654 689
 		if (isset($types['topic']))
655 690
 		{
656 691
 			$titled = false;
657
-			foreach ($types['topic'] as $id => $board)
658
-				foreach ($board['lines'] as $topic)
692
+			foreach ($types['topic'] as $id => $board) {
693
+							foreach ($board['lines'] as $topic)
659 694
 					if (in_array($mid, $topic['members']))
660 695
 					{
661 696
 						if (!$titled)
662 697
 						{
663 698
 							$email['body'] .= "\n" . $langtxt[$lang]['new_topics'] . ':' . "\n" . '-----------------------------------------------';
699
+			}
664 700
 							$titled = true;
665 701
 						}
666 702
 						$email['body'] .= "\n" . sprintf($langtxt[$lang]['topic_lines'], $topic['subject'], $board['name']);
667 703
 					}
668
-			if ($titled)
669
-				$email['body'] .= "\n";
704
+			if ($titled) {
705
+							$email['body'] .= "\n";
706
+			}
670 707
 		}
671 708
 
672 709
 		// What about replies?
673 710
 		if (isset($types['reply']))
674 711
 		{
675 712
 			$titled = false;
676
-			foreach ($types['reply'] as $id => $board)
677
-				foreach ($board['lines'] as $topic)
713
+			foreach ($types['reply'] as $id => $board) {
714
+							foreach ($board['lines'] as $topic)
678 715
 					if (in_array($mid, $topic['members']))
679 716
 					{
680 717
 						if (!$titled)
681 718
 						{
682 719
 							$email['body'] .= "\n" . $langtxt[$lang]['new_replies'] . ':' . "\n" . '-----------------------------------------------';
720
+			}
683 721
 							$titled = true;
684 722
 						}
685 723
 						$email['body'] .= "\n" . ($topic['count'] == 1 ? sprintf($langtxt[$lang]['replies_one'], $topic['subject']) : sprintf($langtxt[$lang]['replies_many'], $topic['count'], $topic['subject']));
686 724
 					}
687 725
 
688
-			if ($titled)
689
-				$email['body'] .= "\n";
726
+			if ($titled) {
727
+							$email['body'] .= "\n";
728
+			}
690 729
 		}
691 730
 
692 731
 		// Finally, moderation actions!
@@ -695,24 +734,27 @@  discard block
 block discarded – undo
695 734
 			$titled = false;
696 735
 			foreach ($types as $note_type => $type)
697 736
 			{
698
-				if ($note_type == 'topic' || $note_type == 'reply')
699
-					continue;
737
+				if ($note_type == 'topic' || $note_type == 'reply') {
738
+									continue;
739
+				}
700 740
 
701
-				foreach ($type as $id => $board)
702
-					foreach ($board['lines'] as $topic)
741
+				foreach ($type as $id => $board) {
742
+									foreach ($board['lines'] as $topic)
703 743
 						if (in_array($mid, $topic['members']))
704 744
 						{
705 745
 							if (!$titled)
706 746
 							{
707 747
 								$email['body'] .= "\n" . $langtxt[$lang]['mod_actions'] . ':' . "\n" . '-----------------------------------------------';
748
+				}
708 749
 								$titled = true;
709 750
 							}
710 751
 							$email['body'] .= "\n" . sprintf($langtxt[$lang][$note_type], $topic['subject']);
711 752
 						}
712 753
 			}
713 754
 		}
714
-		if ($titled)
715
-			$email['body'] .= "\n";
755
+		if ($titled) {
756
+					$email['body'] .= "\n";
757
+		}
716 758
 
717 759
 		// Then just say our goodbyes!
718 760
 		$email['body'] .= "\n\n" . $txt['regards_team'];
@@ -740,8 +782,7 @@  discard block
 block discarded – undo
740 782
 				'not_daily' => 0,
741 783
 			)
742 784
 		);
743
-	}
744
-	else
785
+	} else
745 786
 	{
746 787
 		// Clear any only weekly ones, and stop us from sending daily again.
747 788
 		$smcFunc['db_query']('', '
@@ -803,16 +844,19 @@  discard block
 block discarded – undo
803 844
 	global $modSettings, $smcFunc, $sourcedir;
804 845
 
805 846
 	// Are we intending another script to be sending out the queue?
806
-	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
807
-		return false;
847
+	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send)) {
848
+			return false;
849
+	}
808 850
 
809 851
 	// By default send 5 at once.
810
-	if (!$number)
811
-		$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
852
+	if (!$number) {
853
+			$number = empty($modSettings['mail_quantity']) ? 5 : $modSettings['mail_quantity'];
854
+	}
812 855
 
813 856
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
814
-	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
815
-		return false;
857
+	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send)) {
858
+			return false;
859
+	}
816 860
 
817 861
 	// By default move the next sending on by 10 seconds, and require an affected row.
818 862
 	if (!$override_limit)
@@ -829,8 +873,9 @@  discard block
 block discarded – undo
829 873
 				'last_send' => $modSettings['mail_next_send'],
830 874
 			)
831 875
 		);
832
-		if ($smcFunc['db_affected_rows']() == 0)
833
-			return false;
876
+		if ($smcFunc['db_affected_rows']() == 0) {
877
+					return false;
878
+		}
834 879
 		$modSettings['mail_next_send'] = time() + $delay;
835 880
 	}
836 881
 
@@ -851,8 +896,9 @@  discard block
 block discarded – undo
851 896
 			$mn += $number;
852 897
 		}
853 898
 		// No more I'm afraid, return!
854
-		else
855
-			return false;
899
+		else {
900
+					return false;
901
+		}
856 902
 
857 903
 		// Reflect that we're about to send some, do it now to be safe.
858 904
 		updateSettings(array('mail_recent' => $mt . '|' . $mn));
@@ -887,14 +933,15 @@  discard block
 block discarded – undo
887 933
 	$smcFunc['db_free_result']($request);
888 934
 
889 935
 	// Delete, delete, delete!!!
890
-	if (!empty($ids))
891
-		$smcFunc['db_query']('', '
936
+	if (!empty($ids)) {
937
+			$smcFunc['db_query']('', '
892 938
 			DELETE FROM {db_prefix}mail_queue
893 939
 			WHERE id_mail IN ({array_int:mail_list})',
894 940
 			array(
895 941
 				'mail_list' => $ids,
896 942
 			)
897 943
 		);
944
+	}
898 945
 
899 946
 	// Don't believe we have any left?
900 947
 	if (count($ids) < $number)
@@ -912,11 +959,13 @@  discard block
 block discarded – undo
912 959
 		);
913 960
 	}
914 961
 
915
-	if (empty($ids))
916
-		return false;
962
+	if (empty($ids)) {
963
+			return false;
964
+	}
917 965
 
918
-	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '')
919
-		require_once($sourcedir . '/Subs-Post.php');
966
+	if (!empty($modSettings['mail_type']) && $modSettings['smtp_host'] != '') {
967
+			require_once($sourcedir . '/Subs-Post.php');
968
+	}
920 969
 
921 970
 	// Send each email, yea!
922 971
 	$failed_emails = array();
@@ -936,15 +985,17 @@  discard block
 block discarded – undo
936 985
 
937 986
 			// Try to stop a timeout, this would be bad...
938 987
 			@set_time_limit(300);
939
-			if (function_exists('apache_reset_timeout'))
940
-				@apache_reset_timeout();
988
+			if (function_exists('apache_reset_timeout')) {
989
+							@apache_reset_timeout();
990
+			}
991
+		} else {
992
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
941 993
 		}
942
-		else
943
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers']);
944 994
 
945 995
 		// Hopefully it sent?
946
-		if (!$result)
947
-			$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
996
+		if (!$result) {
997
+					$failed_emails[] = array($email['to'], $email['body'], $email['subject'], $email['headers'], $email['send_html'], $email['time_sent'], $email['private']);
998
+		}
948 999
 	}
949 1000
 
950 1001
 	// Any emails that didn't send?
@@ -959,8 +1010,8 @@  discard block
 block discarded – undo
959 1010
 		);
960 1011
 
961 1012
 		// If we have failed to many times, tell mail to wait a bit and try again.
962
-		if ($modSettings['mail_failed_attempts'] > 5)
963
-			$smcFunc['db_query']('', '
1013
+		if ($modSettings['mail_failed_attempts'] > 5) {
1014
+					$smcFunc['db_query']('', '
964 1015
 				UPDATE {db_prefix}settings
965 1016
 				SET value = {string:next_mail_send}
966 1017
 				WHERE variable = {literal:mail_next_send}
@@ -969,6 +1020,7 @@  discard block
 block discarded – undo
969 1020
 					'next_mail_send' => time() + 60,
970 1021
 					'last_send' => $modSettings['mail_next_send'],
971 1022
 			));
1023
+		}
972 1024
 
973 1025
 		// Add our email back to the queue, manually.
974 1026
 		$smcFunc['db_insert']('insert',
@@ -981,8 +1033,8 @@  discard block
 block discarded – undo
981 1033
 		return false;
982 1034
 	}
983 1035
 	// We where unable to send the email, clear our failed attempts.
984
-	elseif (!empty($modSettings['mail_failed_attempts']))
985
-		$smcFunc['db_query']('', '
1036
+	elseif (!empty($modSettings['mail_failed_attempts'])) {
1037
+			$smcFunc['db_query']('', '
986 1038
 			UPDATE {db_prefix}settings
987 1039
 			SET value = {string:zero}
988 1040
 			WHERE variable = {string:mail_failed_attempts}',
@@ -990,6 +1042,7 @@  discard block
 block discarded – undo
990 1042
 				'zero' => '0',
991 1043
 				'mail_failed_attempts' => 'mail_failed_attempts',
992 1044
 		));
1045
+	}
993 1046
 
994 1047
 	// Had something to send...
995 1048
 	return true;
@@ -1006,16 +1059,18 @@  discard block
 block discarded – undo
1006 1059
 	global $modSettings, $smcFunc;
1007 1060
 
1008 1061
 	$task_query = '';
1009
-	if (!is_array($tasks))
1010
-		$tasks = array($tasks);
1062
+	if (!is_array($tasks)) {
1063
+			$tasks = array($tasks);
1064
+	}
1011 1065
 
1012 1066
 	// Actually have something passed?
1013 1067
 	if (!empty($tasks))
1014 1068
 	{
1015
-		if (!isset($tasks[0]) || is_numeric($tasks[0]))
1016
-			$task_query = ' AND id_task IN ({array_int:tasks})';
1017
-		else
1018
-			$task_query = ' AND task IN ({array_string:tasks})';
1069
+		if (!isset($tasks[0]) || is_numeric($tasks[0])) {
1070
+					$task_query = ' AND id_task IN ({array_int:tasks})';
1071
+		} else {
1072
+					$task_query = ' AND task IN ({array_string:tasks})';
1073
+		}
1019 1074
 	}
1020 1075
 	$nextTaskTime = empty($tasks) ? time() + 86400 : $modSettings['next_task_time'];
1021 1076
 
@@ -1036,20 +1091,22 @@  discard block
 block discarded – undo
1036 1091
 		$next_time = next_time($row['time_regularity'], $row['time_unit'], $row['time_offset']);
1037 1092
 
1038 1093
 		// Only bother moving the task if it's out of place or we're forcing it!
1039
-		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time())
1040
-			$tasks[$row['id_task']] = $next_time;
1041
-		else
1042
-			$next_time = $row['next_time'];
1094
+		if ($forceUpdate || $next_time < $row['next_time'] || $row['next_time'] < time()) {
1095
+					$tasks[$row['id_task']] = $next_time;
1096
+		} else {
1097
+					$next_time = $row['next_time'];
1098
+		}
1043 1099
 
1044 1100
 		// If this is sooner than the current next task, make this the next task.
1045
-		if ($next_time < $nextTaskTime)
1046
-			$nextTaskTime = $next_time;
1101
+		if ($next_time < $nextTaskTime) {
1102
+					$nextTaskTime = $next_time;
1103
+		}
1047 1104
 	}
1048 1105
 	$smcFunc['db_free_result']($request);
1049 1106
 
1050 1107
 	// Now make the changes!
1051
-	foreach ($tasks as $id => $time)
1052
-		$smcFunc['db_query']('', '
1108
+	foreach ($tasks as $id => $time) {
1109
+			$smcFunc['db_query']('', '
1053 1110
 			UPDATE {db_prefix}scheduled_tasks
1054 1111
 			SET next_time = {int:next_time}
1055 1112
 			WHERE id_task = {int:id_task}',
@@ -1058,11 +1115,13 @@  discard block
 block discarded – undo
1058 1115
 				'id_task' => $id,
1059 1116
 			)
1060 1117
 		);
1118
+	}
1061 1119
 
1062 1120
 	// If the next task is now different update.
1063
-	if ($modSettings['next_task_time'] != $nextTaskTime)
1064
-		updateSettings(array('next_task_time' => $nextTaskTime));
1065
-}
1121
+	if ($modSettings['next_task_time'] != $nextTaskTime) {
1122
+			updateSettings(array('next_task_time' => $nextTaskTime));
1123
+	}
1124
+	}
1066 1125
 
1067 1126
 /**
1068 1127
  * Simply returns a time stamp of the next instance of these time parameters.
@@ -1075,8 +1134,9 @@  discard block
 block discarded – undo
1075 1134
 function next_time($regularity, $unit, $offset)
1076 1135
 {
1077 1136
 	// Just in case!
1078
-	if ($regularity == 0)
1079
-		$regularity = 2;
1137
+	if ($regularity == 0) {
1138
+			$regularity = 2;
1139
+	}
1080 1140
 
1081 1141
 	$curMin = date('i', time());
1082 1142
 
@@ -1086,15 +1146,16 @@  discard block
 block discarded – undo
1086 1146
 		$off = date('i', $offset);
1087 1147
 
1088 1148
 		// If it's now just pretend it ain't,
1089
-		if ($off == $curMin)
1090
-			$next_time = time() + $regularity;
1091
-		else
1149
+		if ($off == $curMin) {
1150
+					$next_time = time() + $regularity;
1151
+		} else
1092 1152
 		{
1093 1153
 			// Make sure that the offset is always in the past.
1094 1154
 			$off = $off > $curMin ? $off - 60 : $off;
1095 1155
 
1096
-			while ($off <= $curMin)
1097
-				$off += $regularity;
1156
+			while ($off <= $curMin) {
1157
+							$off += $regularity;
1158
+			}
1098 1159
 
1099 1160
 			// Now we know when the time should be!
1100 1161
 			$next_time = time() + 60 * ($off - $curMin);
@@ -1114,11 +1175,13 @@  discard block
 block discarded – undo
1114 1175
 		// Default we'll jump in hours.
1115 1176
 		$applyOffset = 3600;
1116 1177
 		// 24 hours = 1 day.
1117
-		if ($unit == 'd')
1118
-			$applyOffset = 86400;
1178
+		if ($unit == 'd') {
1179
+					$applyOffset = 86400;
1180
+		}
1119 1181
 		// Otherwise a week.
1120
-		if ($unit == 'w')
1121
-			$applyOffset = 604800;
1182
+		if ($unit == 'w') {
1183
+					$applyOffset = 604800;
1184
+		}
1122 1185
 
1123 1186
 		$applyOffset *= $regularity;
1124 1187
 
@@ -1155,8 +1218,9 @@  discard block
 block discarded – undo
1155 1218
 		$settings[$row['variable']] = $row['value'];
1156 1219
 
1157 1220
 		// Is this the default theme?
1158
-		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1')
1159
-			$settings['default_' . $row['variable']] = $row['value'];
1221
+		if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1') {
1222
+					$settings['default_' . $row['variable']] = $row['value'];
1223
+		}
1160 1224
 	}
1161 1225
 	$smcFunc['db_free_result']($result);
1162 1226
 
@@ -1166,12 +1230,14 @@  discard block
 block discarded – undo
1166 1230
 		$settings['template_dirs'] = array($settings['theme_dir']);
1167 1231
 
1168 1232
 		// Based on theme (if there is one).
1169
-		if (!empty($settings['base_theme_dir']))
1170
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1233
+		if (!empty($settings['base_theme_dir'])) {
1234
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1235
+		}
1171 1236
 
1172 1237
 		// Lastly the default theme.
1173
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1174
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1238
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1239
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1240
+		}
1175 1241
 	}
1176 1242
 
1177 1243
 	// Assume we want this.
@@ -1318,8 +1384,9 @@  discard block
 block discarded – undo
1318 1384
 	// Ok should we prune the logs?
1319 1385
 	if (!empty($modSettings['pruningOptions']))
1320 1386
 	{
1321
-		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false)
1322
-			list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1387
+		if (!empty($modSettings['pruningOptions']) && strpos($modSettings['pruningOptions'], ',') !== false) {
1388
+					list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
1389
+		}
1323 1390
 
1324 1391
 		if (!empty($modSettings['pruneErrorLog']))
1325 1392
 		{
@@ -1385,8 +1452,9 @@  discard block
 block discarded – undo
1385 1452
 				)
1386 1453
 			);
1387 1454
 
1388
-			while ($row = $smcFunc['db_fetch_row']($result))
1389
-				$reports[] = $row[0];
1455
+			while ($row = $smcFunc['db_fetch_row']($result)) {
1456
+							$reports[] = $row[0];
1457
+			}
1390 1458
 
1391 1459
 			$smcFunc['db_free_result']($result);
1392 1460
 
@@ -1548,8 +1616,9 @@  discard block
 block discarded – undo
1548 1616
 		$emaildata = loadEmailTemplate('paid_subscription_reminder', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
1549 1617
 
1550 1618
 		// Send the actual email.
1551
-		if ($notifyPrefs[$row['id_member']] & 0x02)
1552
-			sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1619
+		if ($notifyPrefs[$row['id_member']] & 0x02) {
1620
+					sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, 'paid_sub_remind', $emaildata['is_html'], 2);
1621
+		}
1553 1622
 
1554 1623
 		if ($notifyPrefs[$row['id_member']] & 0x01)
1555 1624
 		{
@@ -1572,18 +1641,19 @@  discard block
 block discarded – undo
1572 1641
 	}
1573 1642
 
1574 1643
 	// Insert the alerts if any
1575
-	if (!empty($alert_rows))
1576
-		$smcFunc['db_insert']('',
1644
+	if (!empty($alert_rows)) {
1645
+			$smcFunc['db_insert']('',
1577 1646
 			'{db_prefix}user_alerts',
1578 1647
 			array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
1579 1648
 				'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
1580 1649
 			$alert_rows,
1581 1650
 			array()
1582 1651
 		);
1652
+	}
1583 1653
 
1584 1654
 	// Mark the reminder as sent.
1585
-	if (!empty($subs_reminded))
1586
-		$smcFunc['db_query']('', '
1655
+	if (!empty($subs_reminded)) {
1656
+			$smcFunc['db_query']('', '
1587 1657
 			UPDATE {db_prefix}log_subscribed
1588 1658
 			SET reminder_sent = {int:reminder_sent}
1589 1659
 			WHERE id_sublog IN ({array_int:subscription_list})',
@@ -1592,6 +1662,7 @@  discard block
 block discarded – undo
1592 1662
 				'reminder_sent' => 1,
1593 1663
 			)
1594 1664
 		);
1665
+	}
1595 1666
 
1596 1667
 	return true;
1597 1668
 }
@@ -1607,13 +1678,13 @@  discard block
 block discarded – undo
1607 1678
 	// We need to know where this thing is going.
1608 1679
 	if (!empty($modSettings['currentAttachmentUploadDir']))
1609 1680
 	{
1610
-		if (!is_array($modSettings['attachmentUploadDir']))
1611
-			$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1681
+		if (!is_array($modSettings['attachmentUploadDir'])) {
1682
+					$modSettings['attachmentUploadDir'] = $smcFunc['json_decode']($modSettings['attachmentUploadDir'], true);
1683
+		}
1612 1684
 
1613 1685
 		// Just use the current path for temp files.
1614 1686
 		$attach_dirs = $modSettings['attachmentUploadDir'];
1615
-	}
1616
-	else
1687
+	} else
1617 1688
 	{
1618 1689
 		$attach_dirs = array($modSettings['attachmentUploadDir']);
1619 1690
 	}
@@ -1632,14 +1703,16 @@  discard block
 block discarded – undo
1632 1703
 
1633 1704
 		while ($file = readdir($dir))
1634 1705
 		{
1635
-			if ($file == '.' || $file == '..')
1636
-				continue;
1706
+			if ($file == '.' || $file == '..') {
1707
+							continue;
1708
+			}
1637 1709
 
1638 1710
 			if (strpos($file, 'post_tmp_') !== false)
1639 1711
 			{
1640 1712
 				// Temp file is more than 5 hours old!
1641
-				if (filemtime($attach_dir . '/' . $file) < time() - 18000)
1642
-					@unlink($attach_dir . '/' . $file);
1713
+				if (filemtime($attach_dir . '/' . $file) < time() - 18000) {
1714
+									@unlink($attach_dir . '/' . $file);
1715
+				}
1643 1716
 			}
1644 1717
 		}
1645 1718
 		closedir($dir);
@@ -1672,8 +1745,9 @@  discard block
 block discarded – undo
1672 1745
 		)
1673 1746
 	);
1674 1747
 
1675
-	while ($row = $smcFunc['db_fetch_row']($request))
1676
-		$topics[] = $row[0];
1748
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1749
+			$topics[] = $row[0];
1750
+	}
1677 1751
 	$smcFunc['db_free_result']($request);
1678 1752
 
1679 1753
 	// Zap, your gone
@@ -1693,8 +1767,9 @@  discard block
 block discarded – undo
1693 1767
 {
1694 1768
 	global $smcFunc, $sourcedir, $modSettings;
1695 1769
 
1696
-	if (empty($modSettings['drafts_keep_days']))
1697
-		return true;
1770
+	if (empty($modSettings['drafts_keep_days'])) {
1771
+			return true;
1772
+	}
1698 1773
 
1699 1774
 	// init
1700 1775
 	$drafts = array();
@@ -1712,8 +1787,9 @@  discard block
 block discarded – undo
1712 1787
 		)
1713 1788
 	);
1714 1789
 
1715
-	while ($row = $smcFunc['db_fetch_row']($request))
1716
-		$drafts[] = (int) $row[0];
1790
+	while ($row = $smcFunc['db_fetch_row']($request)) {
1791
+			$drafts[] = (int) $row[0];
1792
+	}
1717 1793
 	$smcFunc['db_free_result']($request);
1718 1794
 
1719 1795
 	// 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, -195 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',
@@ -343,38 +351,39 @@  discard block
 block discarded – undo
343 351
 		fclose($fp_destination);
344 352
 
345 353
 		$sizes = @getimagesize($destination);
346
-	}
347
-	elseif ($fp_destination)
354
+	} elseif ($fp_destination)
348 355
 	{
349 356
 		$sizes = @getimagesize($source);
350 357
 
351 358
 		$fp_source = fopen($source, 'rb');
352 359
 		if ($fp_source !== false)
353 360
 		{
354
-			while (!feof($fp_source))
355
-				fwrite($fp_destination, fread($fp_source, 8192));
361
+			while (!feof($fp_source)) {
362
+							fwrite($fp_destination, fread($fp_source, 8192));
363
+			}
356 364
 			fclose($fp_source);
365
+		} else {
366
+					$sizes = array(-1, -1, -1);
357 367
 		}
358
-		else
359
-			$sizes = array(-1, -1, -1);
360 368
 		fclose($fp_destination);
361 369
 	}
362 370
 	// We can't get to the file.
363
-	else
364
-		$sizes = array(-1, -1, -1);
371
+	else {
372
+			$sizes = array(-1, -1, -1);
373
+	}
365 374
 
366 375
 	// See if we have -or- can get the needed memory for this operation
367 376
 	// ImageMagick isn't subject to PHP's memory limits :)
368
-	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes))
369
-		return false;
377
+	if (!(checkIMagick() || checkMagickWand()) && checkGD() && !imageMemoryCheck($sizes)) {
378
+			return false;
379
+	}
370 380
 
371 381
 	// A known and supported format?
372 382
 	// @todo test PSD and gif.
373 383
 	if ((checkImagick() || checkMagickWand()) && isset($default_formats[$sizes[2]]))
374 384
 	{
375 385
 		return resizeImage(null, $destination, null, null, $max_width, $max_height, true, $preferred_format);
376
-	}
377
-	elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
386
+	} elseif (checkGD() && isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
378 387
 	{
379 388
 		$imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
380 389
 		if ($src_img = @$imagecreatefrom($destination))
@@ -427,14 +436,14 @@  discard block
 block discarded – undo
427 436
 			$dest_width = empty($max_width) ? $src_width : $max_width;
428 437
 			$dest_height = empty($max_height) ? $src_height : $max_height;
429 438
 
430
-			if ($default_formats[$preferred_format] == 'jpeg')
431
-				$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
439
+			if ($default_formats[$preferred_format] == 'jpeg') {
440
+							$imagick->setCompressionQuality(!empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
441
+			}
432 442
 
433 443
 			$imagick->setImageFormat($default_formats[$preferred_format]);
434 444
 			$imagick->resizeImage($dest_width, $dest_height, Imagick::FILTER_LANCZOS, 1, true);
435 445
 			$success = $imagick->writeImage($destName);
436
-		}
437
-		else
446
+		} else
438 447
 		{
439 448
 			$magick_wand = newMagickWand();
440 449
 			MagickReadImage($magick_wand, $destName);
@@ -443,8 +452,9 @@  discard block
 block discarded – undo
443 452
 			$dest_width = empty($max_width) ? $src_width : $max_width;
444 453
 			$dest_height = empty($max_height) ? $src_height : $max_height;
445 454
 
446
-			if ($default_formats[$preferred_format] == 'jpeg')
447
-				MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
455
+			if ($default_formats[$preferred_format] == 'jpeg') {
456
+							MagickSetCompressionQuality($magick_wand, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
457
+			}
448 458
 
449 459
 			MagickSetImageFormat($magick_wand, $default_formats[$preferred_format]);
450 460
 			MagickResizeImage($magick_wand, $dest_width, $dest_height, MW_LanczosFilter, 1, true);
@@ -452,8 +462,7 @@  discard block
 block discarded – undo
452 462
 		}
453 463
 
454 464
 		return !empty($success);
455
-	}
456
-	elseif (checkGD())
465
+	} elseif (checkGD())
457 466
 	{
458 467
 		$success = false;
459 468
 
@@ -464,8 +473,7 @@  discard block
 block discarded – undo
464 473
 			{
465 474
 				$dst_width = $max_width;
466 475
 				$dst_height = round($src_height * $max_width / $src_width);
467
-			}
468
-			elseif (!empty($max_height))
476
+			} elseif (!empty($max_height))
469 477
 			{
470 478
 				$dst_width = round($src_width * $max_height / $src_height);
471 479
 				$dst_height = $max_height;
@@ -483,44 +491,48 @@  discard block
 block discarded – undo
483 491
 					if ((!empty($preferred_format)) && ($preferred_format == 3))
484 492
 					{
485 493
 						imagealphablending($dst_img, false);
486
-						if (function_exists('imagesavealpha'))
487
-							imagesavealpha($dst_img, true);
494
+						if (function_exists('imagesavealpha')) {
495
+													imagesavealpha($dst_img, true);
496
+						}
488 497
 					}
498
+				} else {
499
+									$dst_img = imagecreate($dst_width, $dst_height);
489 500
 				}
490
-				else
491
-					$dst_img = imagecreate($dst_width, $dst_height);
492 501
 
493 502
 				// Resize it!
494
-				if ($gd2)
495
-					imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
496
-				else
497
-					imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
503
+				if ($gd2) {
504
+									imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
505
+				} else {
506
+									imagecopyresamplebicubic($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
507
+				}
508
+			} else {
509
+							$dst_img = $src_img;
498 510
 			}
499
-			else
500
-				$dst_img = $src_img;
511
+		} else {
512
+					$dst_img = $src_img;
501 513
 		}
502
-		else
503
-			$dst_img = $src_img;
504 514
 
505 515
 		// Save the image as ...
506
-		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng'))
507
-			$success = imagepng($dst_img, $destName);
508
-		elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif'))
509
-			$success = imagegif($dst_img, $destName);
510
-		elseif (function_exists('imagejpeg'))
511
-			$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
516
+		if (!empty($preferred_format) && ($preferred_format == 3) && function_exists('imagepng')) {
517
+					$success = imagepng($dst_img, $destName);
518
+		} elseif (!empty($preferred_format) && ($preferred_format == 1) && function_exists('imagegif')) {
519
+					$success = imagegif($dst_img, $destName);
520
+		} elseif (function_exists('imagejpeg')) {
521
+					$success = imagejpeg($dst_img, $destName, !empty($modSettings['avatar_jpeg_quality']) ? $modSettings['avatar_jpeg_quality'] : 82);
522
+		}
512 523
 
513 524
 		// Free the memory.
514 525
 		imagedestroy($src_img);
515
-		if ($dst_img != $src_img)
516
-			imagedestroy($dst_img);
526
+		if ($dst_img != $src_img) {
527
+					imagedestroy($dst_img);
528
+		}
517 529
 
518 530
 		return $success;
519
-	}
520
-	else
521
-		// Without GD, no image resizing at all.
531
+	} else {
532
+			// Without GD, no image resizing at all.
522 533
 		return false;
523
-}
534
+	}
535
+	}
524 536
 
525 537
 /**
526 538
  * Copy image.
@@ -574,8 +586,9 @@  discard block
 block discarded – undo
574 586
 			$color = imagecolorresolve($dst_img, $red, $green, $blue);
575 587
 			if ($color == -1)
576 588
 			{
577
-				if ($palsize++ < 256)
578
-					imagecolorallocate($dst_img, $red, $green, $blue);
589
+				if ($palsize++ < 256) {
590
+									imagecolorallocate($dst_img, $red, $green, $blue);
591
+				}
579 592
 				$color = imagecolorclosest($dst_img, $red, $green, $blue);
580 593
 			}
581 594
 
@@ -605,13 +618,15 @@  discard block
 block discarded – undo
605 618
 		$header = unpack('vtype/Vsize/Vreserved/Voffset', fread($fp, 14));
606 619
 		$info = unpack('Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vcolorimportant', fread($fp, 40));
607 620
 
608
-		if ($header['type'] != 0x4D42)
609
-			return false;
621
+		if ($header['type'] != 0x4D42) {
622
+					return false;
623
+		}
610 624
 
611
-		if ($gd2)
612
-			$dst_img = imagecreatetruecolor($info['width'], $info['height']);
613
-		else
614
-			$dst_img = imagecreate($info['width'], $info['height']);
625
+		if ($gd2) {
626
+					$dst_img = imagecreatetruecolor($info['width'], $info['height']);
627
+		} else {
628
+					$dst_img = imagecreate($info['width'], $info['height']);
629
+		}
615 630
 
616 631
 		$palette_size = $header['offset'] - 54;
617 632
 		$info['ncolor'] = $palette_size / 4;
@@ -637,8 +652,9 @@  discard block
 block discarded – undo
637 652
 			fseek($fp, $header['offset'] + ($scan_line_size + $scan_line_align) * $l);
638 653
 			$scan_line = fread($fp, $scan_line_size);
639 654
 
640
-			if (strlen($scan_line) < $scan_line_size)
641
-				continue;
655
+			if (strlen($scan_line) < $scan_line_size) {
656
+							continue;
657
+			}
642 658
 
643 659
 			if ($info['bits'] == 32)
644 660
 			{
@@ -656,14 +672,14 @@  discard block
 block discarded – undo
656 672
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
657 673
 
658 674
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
659
-						if ($color == -1)
660
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
675
+						if ($color == -1) {
676
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
677
+						}
661 678
 					}
662 679
 
663 680
 					imagesetpixel($dst_img, $x, $y, $color);
664 681
 				}
665
-			}
666
-			elseif ($info['bits'] == 24)
682
+			} elseif ($info['bits'] == 24)
667 683
 			{
668 684
 				$x = 0;
669 685
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -678,14 +694,14 @@  discard block
 block discarded – undo
678 694
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
679 695
 
680 696
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
681
-						if ($color == -1)
682
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
697
+						if ($color == -1) {
698
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
699
+						}
683 700
 					}
684 701
 
685 702
 					imagesetpixel($dst_img, $x, $y, $color);
686 703
 				}
687
-			}
688
-			elseif ($info['bits'] == 16)
704
+			} elseif ($info['bits'] == 16)
689 705
 			{
690 706
 				$x = 0;
691 707
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -706,20 +722,20 @@  discard block
 block discarded – undo
706 722
 						$color = imagecolorallocate($dst_img, $r, $g, $b);
707 723
 
708 724
 						// Gah!  Out of colors?  Stupid GD 1... try anyhow.
709
-						if ($color == -1)
710
-							$color = imagecolorclosest($dst_img, $r, $g, $b);
725
+						if ($color == -1) {
726
+													$color = imagecolorclosest($dst_img, $r, $g, $b);
727
+						}
711 728
 					}
712 729
 
713 730
 					imagesetpixel($dst_img, $x, $y, $color);
714 731
 				}
715
-			}
716
-			elseif ($info['bits'] == 8)
732
+			} elseif ($info['bits'] == 8)
717 733
 			{
718 734
 				$x = 0;
719
-				for ($j = 0; $j < $scan_line_size; $x++)
720
-					imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
721
-			}
722
-			elseif ($info['bits'] == 4)
735
+				for ($j = 0; $j < $scan_line_size; $x++) {
736
+									imagesetpixel($dst_img, $x, $y, $palette[ord($scan_line{$j++})]);
737
+				}
738
+			} elseif ($info['bits'] == 4)
723 739
 			{
724 740
 				$x = 0;
725 741
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -727,11 +743,11 @@  discard block
 block discarded – undo
727 743
 					$byte = ord($scan_line{$j++});
728 744
 
729 745
 					imagesetpixel($dst_img, $x, $y, $palette[(int) ($byte / 16)]);
730
-					if (++$x < $info['width'])
731
-						imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
746
+					if (++$x < $info['width']) {
747
+											imagesetpixel($dst_img, $x, $y, $palette[$byte & 15]);
748
+					}
732 749
 				}
733
-			}
734
-			elseif ($info['bits'] == 1)
750
+			} elseif ($info['bits'] == 1)
735 751
 			{
736 752
 				$x = 0;
737 753
 				for ($j = 0; $j < $scan_line_size; $x++)
@@ -740,7 +756,9 @@  discard block
 block discarded – undo
740 756
 
741 757
 					imagesetpixel($dst_img, $x, $y, $palette[(($byte) & 128) != 0]);
742 758
 					for ($shift = 1; $shift < 8; $shift++) {
743
-						if (++$x < $info['width']) imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
759
+						if (++$x < $info['width']) {
760
+							imagesetpixel($dst_img, $x, $y, $palette[(($byte << $shift) & 128) != 0]);
761
+						}
744 762
 					}
745 763
 				}
746 764
 			}
@@ -764,15 +782,18 @@  discard block
 block discarded – undo
764 782
  */
765 783
 function gif_outputAsPng($gif, $lpszFileName, $background_color = -1)
766 784
 {
767
-	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '')
768
-		return false;
785
+	if (!isset($gif) || @get_class($gif) != 'cgif' || !$gif->loaded || $lpszFileName == '') {
786
+			return false;
787
+	}
769 788
 
770 789
 	$fd = $gif->get_png_data($background_color);
771
-	if (strlen($fd) <= 0)
772
-		return false;
790
+	if (strlen($fd) <= 0) {
791
+			return false;
792
+	}
773 793
 
774
-	if (!($fh = @fopen($lpszFileName, 'wb')))
775
-		return false;
794
+	if (!($fh = @fopen($lpszFileName, 'wb'))) {
795
+			return false;
796
+	}
776 797
 
777 798
 	@fwrite($fh, $fd, strlen($fd));
778 799
 	@fflush($fh);
@@ -799,8 +820,9 @@  discard block
 block discarded – undo
799 820
 	// What type are we going to be doing?
800 821
 	$imageType = $modSettings['visual_verification_type'];
801 822
 	// Special case to allow the admin center to show samples.
802
-	if ($user_info['is_admin'] && isset($_GET['type']))
803
-		$imageType = (int) $_GET['type'];
823
+	if ($user_info['is_admin'] && isset($_GET['type'])) {
824
+			$imageType = (int) $_GET['type'];
825
+	}
804 826
 
805 827
 	// Some quick references for what we do.
806 828
 	// Do we show no, low or high noise?
@@ -834,25 +856,28 @@  discard block
 block discarded – undo
834 856
 	$character_spacing = 1;
835 857
 
836 858
 	// What color is the background - generally white unless we're on "hard".
837
-	if ($simpleBGColor)
838
-		$background_color = array(255, 255, 255);
839
-	else
840
-		$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
859
+	if ($simpleBGColor) {
860
+			$background_color = array(255, 255, 255);
861
+	} else {
862
+			$background_color = isset($settings['verification_background']) ? $settings['verification_background'] : array(236, 237, 243);
863
+	}
841 864
 
842 865
 	// The color of the characters shown (red, green, blue).
843
-	if ($simpleFGColor)
844
-		$foreground_color = array(0, 0, 0);
845
-	else
866
+	if ($simpleFGColor) {
867
+			$foreground_color = array(0, 0, 0);
868
+	} else
846 869
 	{
847 870
 		$foreground_color = array(64, 101, 136);
848 871
 
849 872
 		// Has the theme author requested a custom color?
850
-		if (isset($settings['verification_foreground']))
851
-			$foreground_color = $settings['verification_foreground'];
873
+		if (isset($settings['verification_foreground'])) {
874
+					$foreground_color = $settings['verification_foreground'];
875
+		}
852 876
 	}
853 877
 
854
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
855
-		return false;
878
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
879
+			return false;
880
+	}
856 881
 
857 882
 	// Get a list of the available fonts.
858 883
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
@@ -863,25 +888,28 @@  discard block
 block discarded – undo
863 888
 	{
864 889
 		if (preg_match('~^(.+)\.gdf$~', $entry, $matches) === 1)
865 890
 		{
866
-			if ($endian ^ (strpos($entry, '_end.gdf') === false))
867
-				$font_list[] = $entry;
891
+			if ($endian ^ (strpos($entry, '_end.gdf') === false)) {
892
+							$font_list[] = $entry;
893
+			}
894
+		} elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1) {
895
+					$ttfont_list[] = $entry;
868 896
 		}
869
-		elseif (preg_match('~^(.+)\.ttf$~', $entry, $matches) === 1)
870
-			$ttfont_list[] = $entry;
871 897
 	}
872 898
 
873
-	if (empty($font_list))
874
-		return false;
899
+	if (empty($font_list)) {
900
+			return false;
901
+	}
875 902
 
876 903
 	// For non-hard things don't even change fonts.
877 904
 	if (!$varyFonts)
878 905
 	{
879 906
 		$font_list = array($font_list[0]);
880 907
 		// Try use Screenge if we can - it looks good!
881
-		if (in_array('AnonymousPro.ttf', $ttfont_list))
882
-			$ttfont_list = array('AnonymousPro.ttf');
883
-		else
884
-			$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
908
+		if (in_array('AnonymousPro.ttf', $ttfont_list)) {
909
+					$ttfont_list = array('AnonymousPro.ttf');
910
+		} else {
911
+					$ttfont_list = empty($ttfont_list) ? array() : array($ttfont_list[0]);
912
+		}
885 913
 
886 914
 	}
887 915
 
@@ -899,14 +927,16 @@  discard block
 block discarded – undo
899 927
 	}
900 928
 
901 929
 	// Load all fonts and determine the maximum font height.
902
-	foreach ($loaded_fonts as $font_index => $dummy)
903
-		$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
+	}
904 933
 
905 934
 	// Determine the dimensions of each character.
906
-	if ($imageType == 4 || $imageType == 5)
907
-		$extra = 80;
908
-	else
909
-		$extra = 45;
935
+	if ($imageType == 4 || $imageType == 5) {
936
+			$extra = 80;
937
+	} else {
938
+			$extra = 45;
939
+	}
910 940
 
911 941
 	$total_width = $character_spacing * strlen($code) + $extra;
912 942
 	$max_height = 0;
@@ -927,13 +957,15 @@  discard block
 block discarded – undo
927 957
 	imagefilledrectangle($code_image, 0, 0, $total_width - 1, $max_height - 1, $bg_color);
928 958
 
929 959
 	// Randomize the foreground color a little.
930
-	for ($i = 0; $i < 3; $i++)
931
-		$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
+	}
932 963
 	$fg_color = imagecolorallocate($code_image, $foreground_color[0], $foreground_color[1], $foreground_color[2]);
933 964
 
934 965
 	// Color for the dots.
935
-	for ($i = 0; $i < 3; $i++)
936
-		$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
+	}
937 969
 	$randomness_color = imagecolorallocate($code_image, $dotbgcolor[0], $dotbgcolor[1], $dotbgcolor[2]);
938 970
 
939 971
 	// Some squares/rectanges for new extreme level
@@ -959,10 +991,11 @@  discard block
 block discarded – undo
959 991
 			$can_do_ttf = function_exists('imagettftext');
960 992
 
961 993
 			// How much rotation will we give?
962
-			if ($rotationType == 'none')
963
-				$angle = 0;
964
-			else
965
-				$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
+			}
966 999
 
967 1000
 			// What color shall we do it?
968 1001
 			if ($fontColorType == 'cyclic')
@@ -976,51 +1009,56 @@  discard block
 block discarded – undo
976 1009
 					array(0, 0, 0),
977 1010
 					array(143, 39, 31),
978 1011
 				);
979
-				if (!isset($last_index))
980
-					$last_index = -1;
1012
+				if (!isset($last_index)) {
1013
+									$last_index = -1;
1014
+				}
981 1015
 				$new_index = $last_index;
982
-				while ($last_index == $new_index)
983
-					$new_index = mt_rand(0, count($colors) - 1);
1016
+				while ($last_index == $new_index) {
1017
+									$new_index = mt_rand(0, count($colors) - 1);
1018
+				}
984 1019
 				$char_fg_color = $colors[$new_index];
985 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]);
986 1025
 			}
987
-			elseif ($fontColorType == 'random')
988
-				$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]));
989
-			else
990
-				$char_fg_color = array($foreground_color[0], $foreground_color[1], $foreground_color[2]);
991 1026
 
992 1027
 			if (!empty($can_do_ttf))
993 1028
 			{
994 1029
 				// GD2 handles font size differently.
995
-				if ($fontSizeRandom)
996
-					$font_size = $gd2 ? mt_rand(17, 19) : mt_rand(18, 25);
997
-				else
998
-					$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
+				}
999 1035
 
1000 1036
 				// Work out the sizes - also fix the character width cause TTF not quite so wide!
1001 1037
 				$font_x = $fontHorSpace == 'minus' && $cur_x > 0 ? $cur_x - 3 : $cur_x + 5;
1002 1038
 				$font_y = $max_height - ($fontVerPos == 'vrandom' ? mt_rand(2, 8) : ($fontVerPos == 'random' ? mt_rand(3, 5) : 5));
1003 1039
 
1004 1040
 				// What font face?
1005
-				if (!empty($ttfont_list))
1006
-					$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
+				}
1007 1044
 
1008 1045
 				// What color are we to do it in?
1009 1046
 				$is_reverse = $showReverseChars ? mt_rand(0, 1) : false;
1010 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]);
1011 1048
 
1012 1049
 				$fontcord = @imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $char_color, $fontface, $character['id']);
1013
-				if (empty($fontcord))
1014
-					$can_do_ttf = false;
1015
-				elseif ($is_reverse)
1050
+				if (empty($fontcord)) {
1051
+									$can_do_ttf = false;
1052
+				} elseif ($is_reverse)
1016 1053
 				{
1017 1054
 					imagefilledpolygon($code_image, $fontcord, 4, $fg_color);
1018 1055
 					// Put the character back!
1019 1056
 					imagettftext($code_image, $font_size, $angle, $font_x, $font_y, $randomness_color, $fontface, $character['id']);
1020 1057
 				}
1021 1058
 
1022
-				if ($can_do_ttf)
1023
-					$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
+				}
1024 1062
 			}
1025 1063
 
1026 1064
 			if (!$can_do_ttf)
@@ -1039,8 +1077,9 @@  discard block
 block discarded – undo
1039 1077
 				}
1040 1078
 
1041 1079
 				// Sorry, no rotation available.
1042
-				else
1043
-					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
+				}
1044 1083
 				$cur_x += $character['width'] + $character_spacing;
1045 1084
 			}
1046 1085
 		}
@@ -1053,17 +1092,22 @@  discard block
 block discarded – undo
1053 1092
 	}
1054 1093
 
1055 1094
 	// Make the background color transparent on the hard image.
1056
-	if (!$simpleBGColor)
1057
-		imagecolortransparent($code_image, $bg_color);
1058
-	if ($hasBorder)
1059
-		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
+	}
1060 1101
 
1061 1102
 	// Add some noise to the background?
1062 1103
 	if ($noiseType != 'none')
1063 1104
 	{
1064
-		for ($i = mt_rand(0, 2); $i < $max_height; $i += mt_rand(1, 2))
1065
-			for ($j = mt_rand(0, 10); $j < $total_width; $j += mt_rand(1, 10))
1066
-				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
+			}
1067 1111
 
1068 1112
 		// Put in some lines too?
1069 1113
 		if ($noiseType != 'extreme')
@@ -1076,8 +1120,7 @@  discard block
 block discarded – undo
1076 1120
 					$x1 = mt_rand(0, $total_width);
1077 1121
 					$x2 = mt_rand(0, $total_width);
1078 1122
 					$y1 = 0; $y2 = $max_height;
1079
-				}
1080
-				else
1123
+				} else
1081 1124
 				{
1082 1125
 					$y1 = mt_rand(0, $max_height);
1083 1126
 					$y2 = mt_rand(0, $max_height);
@@ -1086,8 +1129,7 @@  discard block
 block discarded – undo
1086 1129
 				imagesetthickness($code_image, mt_rand(1, 2));
1087 1130
 				imageline($code_image, $x1, $y1, $x2, $y2, mt_rand(0, 1) ? $fg_color : $randomness_color);
1088 1131
 			}
1089
-		}
1090
-		else
1132
+		} else
1091 1133
 		{
1092 1134
 			// Put in some ellipse
1093 1135
 			$num_ellipse = $noiseType == 'extreme' ? mt_rand(6, 12) : mt_rand(2, 6);
@@ -1107,8 +1149,7 @@  discard block
 block discarded – undo
1107 1149
 	{
1108 1150
 		header('Content-type: image/gif');
1109 1151
 		imagegif($code_image);
1110
-	}
1111
-	else
1152
+	} else
1112 1153
 	{
1113 1154
 		header('Content-type: image/png');
1114 1155
 		imagepng($code_image);
@@ -1131,25 +1172,29 @@  discard block
 block discarded – undo
1131 1172
 {
1132 1173
 	global $settings;
1133 1174
 
1134
-	if (!is_dir($settings['default_theme_dir'] . '/fonts'))
1135
-		return false;
1175
+	if (!is_dir($settings['default_theme_dir'] . '/fonts')) {
1176
+			return false;
1177
+	}
1136 1178
 
1137 1179
 	// Get a list of the available font directories.
1138 1180
 	$font_dir = dir($settings['default_theme_dir'] . '/fonts');
1139 1181
 	$font_list = array();
1140
-	while ($entry = $font_dir->read())
1141
-		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'))
1142 1184
 			$font_list[] = $entry;
1185
+	}
1143 1186
 
1144
-	if (empty($font_list))
1145
-		return false;
1187
+	if (empty($font_list)) {
1188
+			return false;
1189
+	}
1146 1190
 
1147 1191
 	// Pick a random font.
1148 1192
 	$random_font = $font_list[array_rand($font_list)];
1149 1193
 
1150 1194
 	// Check if the given letter exists.
1151
-	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png'))
1152
-		return false;
1195
+	if (!file_exists($settings['default_theme_dir'] . '/fonts/' . $random_font . '/' . $letter . '.png')) {
1196
+			return false;
1197
+	}
1153 1198
 
1154 1199
 	// Include it!
1155 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' => $member), 'admin');
636
+	foreach ($members as $member) {
637
+			logAction('added_to_group', array('group' => $group_names[$group], 'member' => $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.