Completed
Push — release-2.1 ( aa21c4...a79db9 )
by Colin
19:42 queued 09:42
created
Sources/ManagePermissions.php 1 patch
Braces   +312 added lines, -223 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
  * Dispatches to the right function based on the given subaction.
@@ -176,8 +177,9 @@  discard block
 block discarded – undo
176 177
 		// If it's inherited, just add it as a child.
177 178
 		if ($row['id_parent'] != -2)
178 179
 		{
179
-			if (isset($context['groups'][$row['id_parent']]))
180
-				$context['groups'][$row['id_parent']]['children'][$row['id_group']] = $row['group_name'];
180
+			if (isset($context['groups'][$row['id_parent']])) {
181
+							$context['groups'][$row['id_parent']]['children'][$row['id_group']] = $row['group_name'];
182
+			}
181 183
 			continue;
182 184
 		}
183 185
 
@@ -202,10 +204,11 @@  discard block
 block discarded – undo
202 204
 			'access' => false,
203 205
 		);
204 206
 
205
-		if ($row['min_posts'] == -1)
206
-			$normalGroups[$row['id_group']] = $row['id_group'];
207
-		else
208
-			$postGroups[$row['id_group']] = $row['id_group'];
207
+		if ($row['min_posts'] == -1) {
208
+					$normalGroups[$row['id_group']] = $row['id_group'];
209
+		} else {
210
+					$postGroups[$row['id_group']] = $row['id_group'];
211
+		}
209 212
 	}
210 213
 	$smcFunc['db_free_result']($query);
211 214
 
@@ -221,8 +224,9 @@  discard block
 block discarded – undo
221 224
 				'post_group_list' => $postGroups,
222 225
 			)
223 226
 		);
224
-		while ($row = $smcFunc['db_fetch_assoc']($query))
225
-			$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
227
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
228
+					$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
229
+		}
226 230
 		$smcFunc['db_free_result']($query);
227 231
 	}
228 232
 
@@ -238,8 +242,9 @@  discard block
 block discarded – undo
238 242
 				'normal_group_list' => $normalGroups,
239 243
 			)
240 244
 		);
241
-		while ($row = $smcFunc['db_fetch_assoc']($query))
242
-			$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
245
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
246
+					$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
247
+		}
243 248
 		$smcFunc['db_free_result']($query);
244 249
 
245 250
 		// This one is slower, but it's okay... careful not to count twice!
@@ -256,15 +261,17 @@  discard block
 block discarded – undo
256 261
 				'blank_string' => '',
257 262
 			)
258 263
 		);
259
-		while ($row = $smcFunc['db_fetch_assoc']($query))
260
-			$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
264
+		while ($row = $smcFunc['db_fetch_assoc']($query)) {
265
+					$context['groups'][$row['id_group']]['num_members'] += $row['num_members'];
266
+		}
261 267
 		$smcFunc['db_free_result']($query);
262 268
 	}
263 269
 
264 270
 	foreach ($context['groups'] as $id => $data)
265 271
 	{
266
-		if ($data['href'] != '')
267
-			$context['groups'][$id]['link'] = '<a href="' . $data['href'] . '">' . $data['num_members'] . '</a>';
272
+		if ($data['href'] != '') {
273
+					$context['groups'][$id]['link'] = '<a href="' . $data['href'] . '">' . $data['num_members'] . '</a>';
274
+		}
268 275
 	}
269 276
 
270 277
 	if (empty($_REQUEST['pid']))
@@ -278,9 +285,10 @@  discard block
 block discarded – undo
278 285
 				'hidden_permissions' => !empty($context['hidden_permissions']) ? $context['hidden_permissions'] : array(),
279 286
 			)
280 287
 		);
281
-		while ($row = $smcFunc['db_fetch_assoc']($request))
282
-			if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1))
288
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
289
+					if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1))
283 290
 				$context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] = $row['num_permissions'];
291
+		}
284 292
 		$smcFunc['db_free_result']($request);
285 293
 
286 294
 		// Get the "default" profile permissions too.
@@ -297,17 +305,18 @@  discard block
 block discarded – undo
297 305
 		);
298 306
 		while ($row = $smcFunc['db_fetch_assoc']($request))
299 307
 		{
300
-			if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1))
301
-				$context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions'];
308
+			if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) {
309
+							$context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions'];
310
+			}
302 311
 		}
303 312
 		$smcFunc['db_free_result']($request);
304
-	}
305
-	else
313
+	} else
306 314
 	{
307 315
 		$_REQUEST['pid'] = (int) $_REQUEST['pid'];
308 316
 
309
-		if (!isset($context['profiles'][$_REQUEST['pid']]))
310
-			fatal_lang_error('no_access', false);
317
+		if (!isset($context['profiles'][$_REQUEST['pid']])) {
318
+					fatal_lang_error('no_access', false);
319
+		}
311 320
 
312 321
 		// Change the selected tab to better reflect that this really is a board profile.
313 322
 		$context[$context['admin_menu_name']]['current_subsection'] = 'profiles';
@@ -323,8 +332,9 @@  discard block
 block discarded – undo
323 332
 		);
324 333
 		while ($row = $smcFunc['db_fetch_assoc']($request))
325 334
 		{
326
-			if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1))
327
-				$context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions'];
335
+			if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) {
336
+							$context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions'];
337
+			}
328 338
 		}
329 339
 		$smcFunc['db_free_result']($request);
330 340
 
@@ -366,8 +376,8 @@  discard block
 block discarded – undo
366 376
 
367 377
 		if (!empty($changes))
368 378
 		{
369
-			foreach ($changes as $profile => $boards)
370
-				$smcFunc['db_query']('', '
379
+			foreach ($changes as $profile => $boards) {
380
+							$smcFunc['db_query']('', '
371 381
 					UPDATE {db_prefix}boards
372 382
 					SET id_profile = {int:current_profile}
373 383
 					WHERE id_board IN ({array_int:board_list})',
@@ -376,6 +386,7 @@  discard block
 block discarded – undo
376 386
 						'current_profile' => $profile,
377 387
 					)
378 388
 				);
389
+			}
379 390
 		}
380 391
 
381 392
 		$context['edit_all'] = false;
@@ -400,8 +411,9 @@  discard block
 block discarded – undo
400 411
 		);
401 412
 		foreach ($boardList[$catid] as $boardid)
402 413
 		{
403
-			if (!isset($context['profiles'][$boards[$boardid]['profile']]))
404
-				$boards[$boardid]['profile'] = 1;
414
+			if (!isset($context['profiles'][$boards[$boardid]['profile']])) {
415
+							$boards[$boardid]['profile'] = 1;
416
+			}
405 417
 
406 418
 			$context['categories'][$catid]['boards'][$boardid] = array(
407 419
 				'id' => &$boards[$boardid]['id'],
@@ -433,64 +445,74 @@  discard block
 block discarded – undo
433 445
 	loadIllegalGuestPermissions();
434 446
 
435 447
 	// Make sure only one of the quick options was selected.
436
-	if ((!empty($_POST['predefined']) && ((isset($_POST['copy_from']) && $_POST['copy_from'] != 'empty') || !empty($_POST['permissions']))) || (!empty($_POST['copy_from']) && $_POST['copy_from'] != 'empty' && !empty($_POST['permissions'])))
437
-		fatal_lang_error('permissions_only_one_option', false);
448
+	if ((!empty($_POST['predefined']) && ((isset($_POST['copy_from']) && $_POST['copy_from'] != 'empty') || !empty($_POST['permissions']))) || (!empty($_POST['copy_from']) && $_POST['copy_from'] != 'empty' && !empty($_POST['permissions']))) {
449
+			fatal_lang_error('permissions_only_one_option', false);
450
+	}
438 451
 
439
-	if (empty($_POST['group']) || !is_array($_POST['group']))
440
-		$_POST['group'] = array();
452
+	if (empty($_POST['group']) || !is_array($_POST['group'])) {
453
+			$_POST['group'] = array();
454
+	}
441 455
 
442 456
 	// Only accept numeric values for selected membergroups.
443
-	foreach ($_POST['group'] as $id => $group_id)
444
-		$_POST['group'][$id] = (int) $group_id;
457
+	foreach ($_POST['group'] as $id => $group_id) {
458
+			$_POST['group'][$id] = (int) $group_id;
459
+	}
445 460
 	$_POST['group'] = array_unique($_POST['group']);
446 461
 
447
-	if (empty($_REQUEST['pid']))
448
-		$_REQUEST['pid'] = 0;
449
-	else
450
-		$_REQUEST['pid'] = (int) $_REQUEST['pid'];
462
+	if (empty($_REQUEST['pid'])) {
463
+			$_REQUEST['pid'] = 0;
464
+	} else {
465
+			$_REQUEST['pid'] = (int) $_REQUEST['pid'];
466
+	}
451 467
 
452 468
 	// Fix up the old global to the new default!
453 469
 	$bid = max(1, $_REQUEST['pid']);
454 470
 
455 471
 	// No modifying the predefined profiles.
456
-	if ($_REQUEST['pid'] > 1 && $_REQUEST['pid'] < 5)
457
-		fatal_lang_error('no_access', false);
472
+	if ($_REQUEST['pid'] > 1 && $_REQUEST['pid'] < 5) {
473
+			fatal_lang_error('no_access', false);
474
+	}
458 475
 
459 476
 	// Clear out any cached authority.
460 477
 	updateSettings(array('settings_updated' => time()));
461 478
 
462 479
 	// No groups where selected.
463
-	if (empty($_POST['group']))
464
-		redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
480
+	if (empty($_POST['group'])) {
481
+			redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
482
+	}
465 483
 
466 484
 	// Set a predefined permission profile.
467 485
 	if (!empty($_POST['predefined']))
468 486
 	{
469 487
 		// Make sure it's a predefined permission set we expect.
470
-		if (!in_array($_POST['predefined'], array('restrict', 'standard', 'moderator', 'maintenance')))
471
-			redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
488
+		if (!in_array($_POST['predefined'], array('restrict', 'standard', 'moderator', 'maintenance'))) {
489
+					redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
490
+		}
472 491
 
473 492
 		foreach ($_POST['group'] as $group_id)
474 493
 		{
475
-			if (!empty($_REQUEST['pid']))
476
-				setPermissionLevel($_POST['predefined'], $group_id, $_REQUEST['pid']);
477
-			else
478
-				setPermissionLevel($_POST['predefined'], $group_id);
494
+			if (!empty($_REQUEST['pid'])) {
495
+							setPermissionLevel($_POST['predefined'], $group_id, $_REQUEST['pid']);
496
+			} else {
497
+							setPermissionLevel($_POST['predefined'], $group_id);
498
+			}
479 499
 		}
480 500
 	}
481 501
 	// Set a permission profile based on the permissions of a selected group.
482 502
 	elseif ($_POST['copy_from'] != 'empty')
483 503
 	{
484 504
 		// Just checking the input.
485
-		if (!is_numeric($_POST['copy_from']))
486
-			redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
505
+		if (!is_numeric($_POST['copy_from'])) {
506
+					redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
507
+		}
487 508
 
488 509
 		// Make sure the group we're copying to is never included.
489 510
 		$_POST['group'] = array_diff($_POST['group'], array($_POST['copy_from']));
490 511
 
491 512
 		// No groups left? Too bad.
492
-		if (empty($_POST['group']))
493
-			redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
513
+		if (empty($_POST['group'])) {
514
+					redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
515
+		}
494 516
 
495 517
 		if (empty($_REQUEST['pid']))
496 518
 		{
@@ -504,22 +526,26 @@  discard block
 block discarded – undo
504 526
 				)
505 527
 			);
506 528
 			$target_perm = array();
507
-			while ($row = $smcFunc['db_fetch_assoc']($request))
508
-				$target_perm[$row['permission']] = $row['add_deny'];
529
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
530
+							$target_perm[$row['permission']] = $row['add_deny'];
531
+			}
509 532
 			$smcFunc['db_free_result']($request);
510 533
 
511 534
 			$inserts = array();
512
-			foreach ($_POST['group'] as $group_id)
513
-				foreach ($target_perm as $perm => $add_deny)
535
+			foreach ($_POST['group'] as $group_id) {
536
+							foreach ($target_perm as $perm => $add_deny)
514 537
 				{
515 538
 					// No dodgy permissions please!
516 539
 					if (!empty($context['illegal_permissions']) && in_array($perm, $context['illegal_permissions']))
517 540
 						continue;
518
-					if ($group_id == -1 && in_array($perm, $context['non_guest_permissions']))
519
-						continue;
541
+			}
542
+					if ($group_id == -1 && in_array($perm, $context['non_guest_permissions'])) {
543
+											continue;
544
+					}
520 545
 
521
-					if ($group_id != 1 && $group_id != 3)
522
-						$inserts[] = array($perm, $group_id, $add_deny);
546
+					if ($group_id != 1 && $group_id != 3) {
547
+											$inserts[] = array($perm, $group_id, $add_deny);
548
+					}
523 549
 				}
524 550
 
525 551
 			// Delete the previous permissions...
@@ -559,17 +585,19 @@  discard block
 block discarded – undo
559 585
 			)
560 586
 		);
561 587
 		$target_perm = array();
562
-		while ($row = $smcFunc['db_fetch_assoc']($request))
563
-			$target_perm[$row['permission']] = $row['add_deny'];
588
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
589
+					$target_perm[$row['permission']] = $row['add_deny'];
590
+		}
564 591
 		$smcFunc['db_free_result']($request);
565 592
 
566 593
 		$inserts = array();
567
-		foreach ($_POST['group'] as $group_id)
568
-			foreach ($target_perm as $perm => $add_deny)
594
+		foreach ($_POST['group'] as $group_id) {
595
+					foreach ($target_perm as $perm => $add_deny)
569 596
 			{
570 597
 				// Are these for guests?
571 598
 				if ($group_id == -1 && in_array($perm, $context['non_guest_permissions']))
572 599
 					continue;
600
+		}
573 601
 
574 602
 				$inserts[] = array($perm, $group_id, $bid, $add_deny);
575 603
 			}
@@ -607,13 +635,14 @@  discard block
 block discarded – undo
607 635
 		list ($permissionType, $permission) = explode('/', $_POST['permissions']);
608 636
 
609 637
 		// Check whether our input is within expected range.
610
-		if (!in_array($_POST['add_remove'], array('add', 'clear', 'deny')) || !in_array($permissionType, array('membergroup', 'board')))
611
-			redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
638
+		if (!in_array($_POST['add_remove'], array('add', 'clear', 'deny')) || !in_array($permissionType, array('membergroup', 'board'))) {
639
+					redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']);
640
+		}
612 641
 
613 642
 		if ($_POST['add_remove'] == 'clear')
614 643
 		{
615
-			if ($permissionType == 'membergroup')
616
-				$smcFunc['db_query']('', '
644
+			if ($permissionType == 'membergroup') {
645
+							$smcFunc['db_query']('', '
617 646
 					DELETE FROM {db_prefix}permissions
618 647
 					WHERE id_group IN ({array_int:current_group_list})
619 648
 						AND permission = {string:current_permission}
@@ -624,8 +653,8 @@  discard block
 block discarded – undo
624 653
 						'illegal_permissions' => !empty($context['illegal_permissions']) ? $context['illegal_permissions'] : array(),
625 654
 					)
626 655
 				);
627
-			else
628
-				$smcFunc['db_query']('', '
656
+			} else {
657
+							$smcFunc['db_query']('', '
629 658
 					DELETE FROM {db_prefix}board_permissions
630 659
 					WHERE id_group IN ({array_int:current_group_list})
631 660
 						AND id_profile = {int:current_profile}
@@ -636,6 +665,7 @@  discard block
 block discarded – undo
636 665
 						'current_permission' => $permission,
637 666
 					)
638 667
 				);
668
+			}
639 669
 		}
640 670
 		// Add a permission (either 'set' or 'deny').
641 671
 		else
@@ -644,32 +674,36 @@  discard block
 block discarded – undo
644 674
 			$permChange = array();
645 675
 			foreach ($_POST['group'] as $groupID)
646 676
 			{
647
-				if ($groupID == -1 && in_array($permission, $context['non_guest_permissions']))
648
-					continue;
677
+				if ($groupID == -1 && in_array($permission, $context['non_guest_permissions'])) {
678
+									continue;
679
+				}
649 680
 
650
-				if ($permissionType == 'membergroup' && $groupID != 1 && $groupID != 3 && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions'])))
651
-					$permChange[] = array($permission, $groupID, $add_deny);
652
-				elseif ($permissionType != 'membergroup')
653
-					$permChange[] = array($permission, $groupID, $bid, $add_deny);
681
+				if ($permissionType == 'membergroup' && $groupID != 1 && $groupID != 3 && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions']))) {
682
+									$permChange[] = array($permission, $groupID, $add_deny);
683
+				} elseif ($permissionType != 'membergroup') {
684
+									$permChange[] = array($permission, $groupID, $bid, $add_deny);
685
+				}
654 686
 			}
655 687
 
656 688
 			if (!empty($permChange))
657 689
 			{
658
-				if ($permissionType == 'membergroup')
659
-					$smcFunc['db_insert']('replace',
690
+				if ($permissionType == 'membergroup') {
691
+									$smcFunc['db_insert']('replace',
660 692
 						'{db_prefix}permissions',
661 693
 						array('permission' => 'string', 'id_group' => 'int', 'add_deny' => 'int'),
662 694
 						$permChange,
663 695
 						array('permission', 'id_group')
664 696
 					);
697
+				}
665 698
 				// Board permissions go into the other table.
666
-				else
667
-					$smcFunc['db_insert']('replace',
699
+				else {
700
+									$smcFunc['db_insert']('replace',
668 701
 						'{db_prefix}board_permissions',
669 702
 						array('permission' => 'string', 'id_group' => 'int', 'id_profile' => 'int', 'add_deny' => 'int'),
670 703
 						$permChange,
671 704
 						array('permission', 'id_group', 'id_profile')
672 705
 					);
706
+				}
673 707
 			}
674 708
 		}
675 709
 
@@ -687,14 +721,16 @@  discard block
 block discarded – undo
687 721
 {
688 722
 	global $context, $txt, $smcFunc, $modSettings;
689 723
 
690
-	if (!isset($_GET['group']))
691
-		fatal_lang_error('no_access', false);
724
+	if (!isset($_GET['group'])) {
725
+			fatal_lang_error('no_access', false);
726
+	}
692 727
 
693 728
 	$context['group']['id'] = (int) $_GET['group'];
694 729
 
695 730
 	// It's not likely you'd end up here with this setting disabled.
696
-	if ($_GET['group'] == 1)
697
-		redirectexit('action=admin;area=permissions');
731
+	if ($_GET['group'] == 1) {
732
+			redirectexit('action=admin;area=permissions');
733
+	}
698 734
 
699 735
 	loadAllPermissions();
700 736
 	loadPermissionProfiles();
@@ -715,13 +751,14 @@  discard block
 block discarded – undo
715 751
 		$smcFunc['db_free_result']($result);
716 752
 
717 753
 		// Cannot edit an inherited group!
718
-		if ($parent != -2)
719
-			fatal_lang_error('cannot_edit_permissions_inherited');
754
+		if ($parent != -2) {
755
+					fatal_lang_error('cannot_edit_permissions_inherited');
756
+		}
757
+	} elseif ($context['group']['id'] == -1) {
758
+			$context['group']['name'] = $txt['membergroups_guests'];
759
+	} else {
760
+			$context['group']['name'] = $txt['membergroups_members'];
720 761
 	}
721
-	elseif ($context['group']['id'] == -1)
722
-		$context['group']['name'] = $txt['membergroups_guests'];
723
-	else
724
-		$context['group']['name'] = $txt['membergroups_members'];
725 762
 
726 763
 	$context['profile']['id'] = empty($_GET['pid']) ? 0 : (int) $_GET['pid'];
727 764
 
@@ -767,8 +804,9 @@  discard block
 block discarded – undo
767 804
 				'current_group' => $_GET['group'],
768 805
 			)
769 806
 		);
770
-		while ($row = $smcFunc['db_fetch_assoc']($result))
771
-			$permissions['membergroup'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission'];
807
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
808
+					$permissions['membergroup'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission'];
809
+		}
772 810
 		$smcFunc['db_free_result']($result);
773 811
 	}
774 812
 
@@ -783,8 +821,9 @@  discard block
 block discarded – undo
783 821
 			'current_profile' => $context['permission_type'] == 'membergroup' ? 1 : $context['profile']['id'],
784 822
 		)
785 823
 	);
786
-	while ($row = $smcFunc['db_fetch_assoc']($result))
787
-		$permissions['board'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission'];
824
+	while ($row = $smcFunc['db_fetch_assoc']($result)) {
825
+			$permissions['board'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission'];
826
+	}
788 827
 	$smcFunc['db_free_result']($result);
789 828
 
790 829
 	// Loop through each permission and set whether it's checked.
@@ -803,9 +842,9 @@  discard block
 block discarded – undo
803 842
 					{
804 843
 						$curPerm['any']['select'] = in_array($perm['id'] . '_any', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_any', $permissions[$permissionType]['denied']) ? 'deny' : 'off');
805 844
 						$curPerm['own']['select'] = in_array($perm['id'] . '_own', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_own', $permissions[$permissionType]['denied']) ? 'deny' : 'off');
845
+					} else {
846
+											$curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'deny' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off');
806 847
 					}
807
-					else
808
-						$curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'deny' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off');
809 848
 
810 849
 						// Keep the last value if it's hidden.
811 850
 						if ($perm['hidden'] || $permissionArray['hidden'])
@@ -822,13 +861,13 @@  discard block
 block discarded – undo
822 861
 									$perm['any']['id'],
823 862
 									$curPerm['any']['select'] == 'deny' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $curPerm['any']['select'],
824 863
 								);
825
-							}
826
-							else
827
-								$context['hidden_perms'][] = array(
864
+							} else {
865
+															$context['hidden_perms'][] = array(
828 866
 									$permissionType,
829 867
 									$perm['id'],
830 868
 									$curPerm['select'] == 'deny' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $curPerm['select'],
831 869
 								);
870
+							}
832 871
 						}
833 872
 				}
834 873
 			}
@@ -856,13 +895,14 @@  discard block
 block discarded – undo
856 895
 	$_GET['pid'] = (int) $_GET['pid'];
857 896
 
858 897
 	// Cannot modify predefined profiles.
859
-	if ($_GET['pid'] > 1 && $_GET['pid'] < 5)
860
-		fatal_lang_error('no_access', false);
898
+	if ($_GET['pid'] > 1 && $_GET['pid'] < 5) {
899
+			fatal_lang_error('no_access', false);
900
+	}
861 901
 
862 902
 	// Verify this isn't inherited.
863
-	if ($_GET['group'] == -1 || $_GET['group'] == 0)
864
-		$parent = -2;
865
-	else
903
+	if ($_GET['group'] == -1 || $_GET['group'] == 0) {
904
+			$parent = -2;
905
+	} else
866 906
 	{
867 907
 		$result = $smcFunc['db_query']('', '
868 908
 			SELECT id_parent
@@ -877,8 +917,9 @@  discard block
 block discarded – undo
877 917
 		$smcFunc['db_free_result']($result);
878 918
 	}
879 919
 
880
-	if ($parent != -2)
881
-		fatal_lang_error('cannot_edit_permissions_inherited');
920
+	if ($parent != -2) {
921
+			fatal_lang_error('cannot_edit_permissions_inherited');
922
+	}
882 923
 
883 924
 	$givePerms = array('membergroup' => array(), 'board' => array());
884 925
 
@@ -896,12 +937,13 @@  discard block
 block discarded – undo
896 937
 		{
897 938
 			if (is_array($perm_array))
898 939
 			{
899
-				foreach ($perm_array as $permission => $value)
900
-					if ($value == 'on' || $value == 'deny')
940
+				foreach ($perm_array as $permission => $value) {
941
+									if ($value == 'on' || $value == 'deny')
901 942
 					{
902 943
 						// Don't allow people to escalate themselves!
903 944
 						if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions']))
904 945
 							continue;
946
+				}
905 947
 
906 948
 						$givePerms[$perm_type][] = array($_GET['group'], $permission, $value == 'deny' ? 0 : 1);
907 949
 					}
@@ -946,8 +988,9 @@  discard block
 block discarded – undo
946 988
 	);
947 989
 	if (!empty($givePerms['board']))
948 990
 	{
949
-		foreach ($givePerms['board'] as $k => $v)
950
-			$givePerms['board'][$k][] = $profileid;
991
+		foreach ($givePerms['board'] as $k => $v) {
992
+					$givePerms['board'][$k][] = $profileid;
993
+		}
951 994
 		$smcFunc['db_insert']('replace',
952 995
 			'{db_prefix}board_permissions',
953 996
 			array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int', 'id_profile' => 'int'),
@@ -988,8 +1031,9 @@  discard block
 block discarded – undo
988 1031
 
989 1032
 	call_integration_hook('integrate_modify_permission_settings', array(&$config_vars));
990 1033
 
991
-	if ($return_config)
992
-		return $config_vars;
1034
+	if ($return_config) {
1035
+			return $config_vars;
1036
+	}
993 1037
 
994 1038
 	$context['page_title'] = $txt['permission_settings_title'];
995 1039
 	$context['sub_template'] = 'show_settings';
@@ -1040,8 +1084,9 @@  discard block
 block discarded – undo
1040 1084
 					'min_posts' => -1,
1041 1085
 				)
1042 1086
 			);
1043
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1044
-				$post_groups[] = $row['id_group'];
1087
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1088
+							$post_groups[] = $row['id_group'];
1089
+			}
1045 1090
 			$smcFunc['db_free_result']($request);
1046 1091
 
1047 1092
 			// Remove'em.
@@ -1250,16 +1295,19 @@  discard block
 block discarded – undo
1250 1295
 	// Make sure we're not granting someone too many permissions!
1251 1296
 	foreach ($groupLevels['global'][$level] as $k => $permission)
1252 1297
 	{
1253
-		if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions']))
1254
-			unset($groupLevels['global'][$level][$k]);
1298
+		if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions'])) {
1299
+					unset($groupLevels['global'][$level][$k]);
1300
+		}
1255 1301
 
1256
-		if ($group == -1 && in_array($permission, $context['non_guest_permissions']))
1257
-			unset($groupLevels['global'][$level][$k]);
1302
+		if ($group == -1 && in_array($permission, $context['non_guest_permissions'])) {
1303
+					unset($groupLevels['global'][$level][$k]);
1304
+		}
1258 1305
 	}
1259
-	if ($group == -1)
1260
-		foreach ($groupLevels['board'][$level] as $k => $permission)
1306
+	if ($group == -1) {
1307
+			foreach ($groupLevels['board'][$level] as $k => $permission)
1261 1308
 			if (in_array($permission, $context['non_guest_permissions']))
1262 1309
 				unset($groupLevels['board'][$level][$k]);
1310
+	}
1263 1311
 
1264 1312
 	// Reset all cached permissions.
1265 1313
 	updateSettings(array('settings_updated' => time()));
@@ -1269,8 +1317,9 @@  discard block
 block discarded – undo
1269 1317
 	{
1270 1318
 		$group = (int) $group;
1271 1319
 
1272
-		if (empty($groupLevels['global'][$level]))
1273
-			return;
1320
+		if (empty($groupLevels['global'][$level])) {
1321
+					return;
1322
+		}
1274 1323
 
1275 1324
 		$smcFunc['db_query']('', '
1276 1325
 			DELETE FROM {db_prefix}permissions
@@ -1292,8 +1341,9 @@  discard block
 block discarded – undo
1292 1341
 		);
1293 1342
 
1294 1343
 		$groupInserts = array();
1295
-		foreach ($groupLevels['global'][$level] as $permission)
1296
-			$groupInserts[] = array($group, $permission);
1344
+		foreach ($groupLevels['global'][$level] as $permission) {
1345
+					$groupInserts[] = array($group, $permission);
1346
+		}
1297 1347
 
1298 1348
 		$smcFunc['db_insert']('insert',
1299 1349
 			'{db_prefix}permissions',
@@ -1303,8 +1353,9 @@  discard block
 block discarded – undo
1303 1353
 		);
1304 1354
 
1305 1355
 		$boardInserts = array();
1306
-		foreach ($groupLevels['board'][$level] as $permission)
1307
-			$boardInserts[] = array(1, $group, $permission);
1356
+		foreach ($groupLevels['board'][$level] as $permission) {
1357
+					$boardInserts[] = array(1, $group, $permission);
1358
+		}
1308 1359
 
1309 1360
 		$smcFunc['db_insert']('insert',
1310 1361
 			'{db_prefix}board_permissions',
@@ -1335,8 +1386,9 @@  discard block
 block discarded – undo
1335 1386
 		if (!empty($groupLevels['board'][$level]))
1336 1387
 		{
1337 1388
 			$boardInserts = array();
1338
-			foreach ($groupLevels['board'][$level] as $permission)
1339
-				$boardInserts[] = array($profile, $group, $permission);
1389
+			foreach ($groupLevels['board'][$level] as $permission) {
1390
+							$boardInserts[] = array($profile, $group, $permission);
1391
+			}
1340 1392
 
1341 1393
 			$smcFunc['db_insert']('insert',
1342 1394
 				'{db_prefix}board_permissions',
@@ -1359,8 +1411,9 @@  discard block
 block discarded – undo
1359 1411
 			)
1360 1412
 		);
1361 1413
 
1362
-		if (empty($boardLevels[$level]))
1363
-			return;
1414
+		if (empty($boardLevels[$level])) {
1415
+					return;
1416
+		}
1364 1417
 
1365 1418
 		// Get all the groups...
1366 1419
 		$query = $smcFunc['db_query']('', '
@@ -1378,8 +1431,9 @@  discard block
 block discarded – undo
1378 1431
 			$group = $row[0];
1379 1432
 
1380 1433
 			$boardInserts = array();
1381
-			foreach ($boardLevels[$level] as $permission)
1382
-				$boardInserts[] = array($profile, $group, $permission);
1434
+			foreach ($boardLevels[$level] as $permission) {
1435
+							$boardInserts[] = array($profile, $group, $permission);
1436
+			}
1383 1437
 
1384 1438
 			$smcFunc['db_insert']('insert',
1385 1439
 				'{db_prefix}board_permissions',
@@ -1392,8 +1446,9 @@  discard block
 block discarded – undo
1392 1446
 
1393 1447
 		// Add permissions for ungrouped members.
1394 1448
 		$boardInserts = array();
1395
-		foreach ($boardLevels[$level] as $permission)
1396
-			$boardInserts[] = array($profile, 0, $permission);
1449
+		foreach ($boardLevels[$level] as $permission) {
1450
+					$boardInserts[] = array($profile, 0, $permission);
1451
+		}
1397 1452
 
1398 1453
 		$smcFunc['db_insert']('insert',
1399 1454
 				'{db_prefix}board_permissions',
@@ -1403,9 +1458,10 @@  discard block
 block discarded – undo
1403 1458
 			);
1404 1459
 	}
1405 1460
 	// $profile and $group are both null!
1406
-	else
1407
-		fatal_lang_error('no_access', false);
1408
-}
1461
+	else {
1462
+			fatal_lang_error('no_access', false);
1463
+	}
1464
+	}
1409 1465
 
1410 1466
 /**
1411 1467
  * Load permissions into $context['permissions'].
@@ -1606,15 +1662,17 @@  discard block
 block discarded – undo
1606 1662
 		foreach ($permissionList as $permission => $permissionArray)
1607 1663
 		{
1608 1664
 			// If this is a guest permission we don't do it if it's the guest group.
1609
-			if (isset($context['group']['id']) && $context['group']['id'] == -1 && in_array($permission, $context['non_guest_permissions']))
1610
-				continue;
1665
+			if (isset($context['group']['id']) && $context['group']['id'] == -1 && in_array($permission, $context['non_guest_permissions'])) {
1666
+							continue;
1667
+			}
1611 1668
 
1612 1669
 			// What groups will this permission be in?
1613 1670
 			$own_group = $permissionArray[1];
1614 1671
 
1615 1672
 			// First, Do these groups actually exist - if not add them.
1616
-			if (!isset($permissionGroups[$permissionType][$own_group]))
1617
-				$permissionGroups[$permissionType][$own_group] = true;
1673
+			if (!isset($permissionGroups[$permissionType][$own_group])) {
1674
+							$permissionGroups[$permissionType][$own_group] = true;
1675
+			}
1618 1676
 
1619 1677
 			// What column should this be located into?
1620 1678
 			$position = !in_array($own_group, $leftPermissionGroups) ? 1 : 0;
@@ -1622,8 +1680,8 @@  discard block
 block discarded – undo
1622 1680
 			// If the groups have not yet been created be sure to create them.
1623 1681
 			$bothGroups = array('own' => $own_group);
1624 1682
 
1625
-			foreach ($bothGroups as $group)
1626
-				if (!isset($context['permissions'][$permissionType]['columns'][$position][$group]))
1683
+			foreach ($bothGroups as $group) {
1684
+							if (!isset($context['permissions'][$permissionType]['columns'][$position][$group]))
1627 1685
 					$context['permissions'][$permissionType]['columns'][$position][$group] = array(
1628 1686
 						'type' => $permissionType,
1629 1687
 						'id' => $group,
@@ -1633,6 +1691,7 @@  discard block
 block discarded – undo
1633 1691
 						'hidden' => false,
1634 1692
 						'permissions' => array()
1635 1693
 					);
1694
+			}
1636 1695
 
1637 1696
 			$context['permissions'][$permissionType]['columns'][$position][$own_group]['permissions'][$permission] = array(
1638 1697
 				'id' => $permission,
@@ -1657,27 +1716,30 @@  discard block
 block discarded – undo
1657 1716
 				{
1658 1717
 					$context['hidden_permissions'][] = $permission . '_own';
1659 1718
 					$context['hidden_permissions'][] = $permission . '_any';
1719
+				} else {
1720
+									$context['hidden_permissions'][] = $permission;
1660 1721
 				}
1661
-				else
1662
-					$context['hidden_permissions'][] = $permission;
1663 1722
 			}
1664 1723
 		}
1665 1724
 		ksort($context['permissions'][$permissionType]['columns']);
1666 1725
 
1667 1726
 		// Check we don't leave any empty groups - and mark hidden ones as such.
1668
-		foreach ($context['permissions'][$permissionType]['columns'] as $column => $groups)
1669
-			foreach ($groups as $id => $group)
1727
+		foreach ($context['permissions'][$permissionType]['columns'] as $column => $groups) {
1728
+					foreach ($groups as $id => $group)
1670 1729
 			{
1671 1730
 				if (empty($group['permissions']))
1672 1731
 					unset($context['permissions'][$permissionType]['columns'][$column][$id]);
1732
+		}
1673 1733
 				else
1674 1734
 				{
1675 1735
 					$foundNonHidden = false;
1676
-					foreach ($group['permissions'] as $permission)
1677
-						if (empty($permission['hidden']))
1736
+					foreach ($group['permissions'] as $permission) {
1737
+											if (empty($permission['hidden']))
1678 1738
 							$foundNonHidden = true;
1679
-					if (!$foundNonHidden)
1680
-						$context['permissions'][$permissionType]['columns'][$column][$id]['hidden'] = true;
1739
+					}
1740
+					if (!$foundNonHidden) {
1741
+											$context['permissions'][$permissionType]['columns'][$column][$id]['hidden'] = true;
1742
+					}
1681 1743
 				}
1682 1744
 			}
1683 1745
 	}
@@ -1704,12 +1766,13 @@  discard block
 block discarded – undo
1704 1766
 	$context['can_change_permissions'] = allowedTo('manage_permissions');
1705 1767
 
1706 1768
 	// Nothing to initialize here.
1707
-	if (!$context['can_change_permissions'])
1708
-		return;
1769
+	if (!$context['can_change_permissions']) {
1770
+			return;
1771
+	}
1709 1772
 
1710 1773
 	// Load the permission settings for guests
1711
-	foreach ($permissions as $permission)
1712
-		$context[$permission] = array(
1774
+	foreach ($permissions as $permission) {
1775
+			$context[$permission] = array(
1713 1776
 			-1 => array(
1714 1777
 				'id' => -1,
1715 1778
 				'name' => $txt['membergroups_guests'],
@@ -1723,6 +1786,7 @@  discard block
 block discarded – undo
1723 1786
 				'status' => 'off',
1724 1787
 			),
1725 1788
 		);
1789
+	}
1726 1790
 
1727 1791
 	$request = $smcFunc['db_query']('', '
1728 1792
 		SELECT id_group, CASE WHEN add_deny = {int:denied} THEN {string:deny} ELSE {string:on} END AS status, permission
@@ -1736,8 +1800,9 @@  discard block
 block discarded – undo
1736 1800
 			'on' => 'on',
1737 1801
 		)
1738 1802
 	);
1739
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1740
-		$context[$row['permission']][$row['id_group']]['status'] = $row['status'];
1803
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1804
+			$context[$row['permission']][$row['id_group']]['status'] = $row['status'];
1805
+	}
1741 1806
 	$smcFunc['db_free_result']($request);
1742 1807
 
1743 1808
 	$request = $smcFunc['db_query']('', '
@@ -1758,14 +1823,15 @@  discard block
 block discarded – undo
1758 1823
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1759 1824
 	{
1760 1825
 		// Initialize each permission as being 'off' until proven otherwise.
1761
-		foreach ($permissions as $permission)
1762
-			if (!isset($context[$permission][$row['id_group']]))
1826
+		foreach ($permissions as $permission) {
1827
+					if (!isset($context[$permission][$row['id_group']]))
1763 1828
 				$context[$permission][$row['id_group']] = array(
1764 1829
 					'id' => $row['id_group'],
1765 1830
 					'name' => $row['group_name'],
1766 1831
 					'is_postgroup' => $row['min_posts'] != -1,
1767 1832
 					'status' => 'off',
1768 1833
 				);
1834
+		}
1769 1835
 
1770 1836
 		$context[$row['permission']][$row['id_group']]['status'] = empty($row['status']) ? 'deny' : ($row['status'] == 1 ? 'on' : 'off');
1771 1837
 	}
@@ -1779,8 +1845,9 @@  discard block
 block discarded – undo
1779 1845
 	{
1780 1846
 		foreach ($permissions as $permission)
1781 1847
 		{
1782
-			if (isset($context[$permission][$group]))
1783
-				unset($context[$permission][$group]);
1848
+			if (isset($context[$permission][$group])) {
1849
+							unset($context[$permission][$group]);
1850
+			}
1784 1851
 		}
1785 1852
 	}
1786 1853
 
@@ -1788,8 +1855,9 @@  discard block
 block discarded – undo
1788 1855
 	$non_guest_perms = array_intersect(str_replace(array('_any', '_own'), '', $permissions), $context['non_guest_permissions']);
1789 1856
 	foreach ($non_guest_perms as $permission)
1790 1857
 	{
1791
-		if (isset($context[$permission][-1]))
1792
-			unset($context[$permission][-1]);
1858
+		if (isset($context[$permission][-1])) {
1859
+					unset($context[$permission][-1]);
1860
+		}
1793 1861
 	}
1794 1862
 
1795 1863
 	// Create the token for the separate inline permission verification.
@@ -1824,8 +1892,9 @@  discard block
 block discarded – undo
1824 1892
 	global $context, $smcFunc;
1825 1893
 
1826 1894
 	// No permissions? Not a great deal to do here.
1827
-	if (!allowedTo('manage_permissions'))
1828
-		return;
1895
+	if (!allowedTo('manage_permissions')) {
1896
+			return;
1897
+	}
1829 1898
 
1830 1899
 	// Almighty session check, verify our ways.
1831 1900
 	checkSession();
@@ -1837,13 +1906,15 @@  discard block
 block discarded – undo
1837 1906
 	$insertRows = array();
1838 1907
 	foreach ($permissions as $permission)
1839 1908
 	{
1840
-		if (!isset($_POST[$permission]))
1841
-			continue;
1909
+		if (!isset($_POST[$permission])) {
1910
+					continue;
1911
+		}
1842 1912
 
1843 1913
 		foreach ($_POST[$permission] as $id_group => $value)
1844 1914
 		{
1845
-			if (in_array($value, array('on', 'deny')) && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions'])))
1846
-				$insertRows[] = array((int) $id_group, $permission, $value == 'on' ? 1 : 0);
1915
+			if (in_array($value, array('on', 'deny')) && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions']))) {
1916
+							$insertRows[] = array((int) $id_group, $permission, $value == 'on' ? 1 : 0);
1917
+			}
1847 1918
 		}
1848 1919
 	}
1849 1920
 
@@ -1859,13 +1930,14 @@  discard block
 block discarded – undo
1859 1930
 	);
1860 1931
 
1861 1932
 	// ...and replace them with new ones.
1862
-	if (!empty($insertRows))
1863
-		$smcFunc['db_insert']('insert',
1933
+	if (!empty($insertRows)) {
1934
+			$smcFunc['db_insert']('insert',
1864 1935
 			'{db_prefix}permissions',
1865 1936
 			array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
1866 1937
 			$insertRows,
1867 1938
 			array('id_group', 'permission')
1868 1939
 		);
1940
+	}
1869 1941
 
1870 1942
 	// Do a full child update.
1871 1943
 	updateChildPermissions(array(), -1);
@@ -1892,10 +1964,11 @@  discard block
 block discarded – undo
1892 1964
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1893 1965
 	{
1894 1966
 		// Format the label nicely.
1895
-		if (isset($txt['permissions_profile_' . $row['profile_name']]))
1896
-			$name = $txt['permissions_profile_' . $row['profile_name']];
1897
-		else
1898
-			$name = $row['profile_name'];
1967
+		if (isset($txt['permissions_profile_' . $row['profile_name']])) {
1968
+					$name = $txt['permissions_profile_' . $row['profile_name']];
1969
+		} else {
1970
+					$name = $row['profile_name'];
1971
+		}
1899 1972
 
1900 1973
 		$context['profiles'][$row['id_profile']] = array(
1901 1974
 			'id' => $row['id_profile'],
@@ -1950,17 +2023,19 @@  discard block
 block discarded – undo
1950 2023
 			)
1951 2024
 		);
1952 2025
 		$inserts = array();
1953
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1954
-			$inserts[] = array($profile_id, $row['id_group'], $row['permission'], $row['add_deny']);
2026
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2027
+					$inserts[] = array($profile_id, $row['id_group'], $row['permission'], $row['add_deny']);
2028
+		}
1955 2029
 		$smcFunc['db_free_result']($request);
1956 2030
 
1957
-		if (!empty($inserts))
1958
-			$smcFunc['db_insert']('insert',
2031
+		if (!empty($inserts)) {
2032
+					$smcFunc['db_insert']('insert',
1959 2033
 				'{db_prefix}board_permissions',
1960 2034
 				array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
1961 2035
 				$inserts,
1962 2036
 				array('id_profile', 'id_group', 'permission')
1963 2037
 			);
2038
+		}
1964 2039
 	}
1965 2040
 	// Renaming?
1966 2041
 	elseif (isset($_POST['rename']))
@@ -1969,16 +2044,16 @@  discard block
 block discarded – undo
1969 2044
 		validateToken('admin-mpp');
1970 2045
 
1971 2046
 		// Just showing the boxes?
1972
-		if (!isset($_POST['rename_profile']))
1973
-			$context['show_rename_boxes'] = true;
1974
-		else
2047
+		if (!isset($_POST['rename_profile'])) {
2048
+					$context['show_rename_boxes'] = true;
2049
+		} else
1975 2050
 		{
1976 2051
 			foreach ($_POST['rename_profile'] as $id => $value)
1977 2052
 			{
1978 2053
 				$value = $smcFunc['htmlspecialchars']($value);
1979 2054
 
1980
-				if (trim($value) != '' && $id > 4)
1981
-					$smcFunc['db_query']('', '
2055
+				if (trim($value) != '' && $id > 4) {
2056
+									$smcFunc['db_query']('', '
1982 2057
 						UPDATE {db_prefix}permission_profiles
1983 2058
 						SET profile_name = {string:profile_name}
1984 2059
 						WHERE id_profile = {int:current_profile}',
@@ -1987,6 +2062,7 @@  discard block
 block discarded – undo
1987 2062
 							'profile_name' => $value,
1988 2063
 						)
1989 2064
 					);
2065
+				}
1990 2066
 			}
1991 2067
 		}
1992 2068
 	}
@@ -1997,9 +2073,10 @@  discard block
 block discarded – undo
1997 2073
 		validateToken('admin-mpp');
1998 2074
 
1999 2075
 		$profiles = array();
2000
-		foreach ($_POST['delete_profile'] as $profile)
2001
-			if ($profile > 4)
2076
+		foreach ($_POST['delete_profile'] as $profile) {
2077
+					if ($profile > 4)
2002 2078
 				$profiles[] = (int) $profile;
2079
+		}
2003 2080
 
2004 2081
 		// Verify it's not in use...
2005 2082
 		$request = $smcFunc['db_query']('', '
@@ -2011,8 +2088,9 @@  discard block
 block discarded – undo
2011 2088
 				'profile_list' => $profiles,
2012 2089
 			)
2013 2090
 		);
2014
-		if ($smcFunc['db_num_rows']($request) != 0)
2015
-			fatal_lang_error('no_access', false);
2091
+		if ($smcFunc['db_num_rows']($request) != 0) {
2092
+					fatal_lang_error('no_access', false);
2093
+		}
2016 2094
 		$smcFunc['db_free_result']($request);
2017 2095
 
2018 2096
 		// Oh well, delete.
@@ -2036,10 +2114,11 @@  discard block
 block discarded – undo
2036 2114
 		array(
2037 2115
 		)
2038 2116
 	);
2039
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2040
-		if (isset($context['profiles'][$row['id_profile']]))
2117
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2118
+			if (isset($context['profiles'][$row['id_profile']]))
2041 2119
 		{
2042 2120
 			$context['profiles'][$row['id_profile']]['in_use'] = true;
2121
+	}
2043 2122
 			$context['profiles'][$row['id_profile']]['boards'] = $row['board_count'];
2044 2123
 			$context['profiles'][$row['id_profile']]['boards_text'] = $row['board_count'] > 1 ? sprintf($txt['permissions_profile_used_by_many'], $row['board_count']) : $txt['permissions_profile_used_by_' . ($row['board_count'] ? 'one' : 'none')];
2045 2124
 		}
@@ -2051,8 +2130,9 @@  discard block
 block discarded – undo
2051 2130
 	{
2052 2131
 		// Can't delete special ones.
2053 2132
 		$context['profiles'][$id]['can_edit'] = isset($txt['permissions_profile_' . $profile['unformatted_name']]) ? false : true;
2054
-		if ($context['profiles'][$id]['can_edit'])
2055
-			$context['can_edit_something'] = true;
2133
+		if ($context['profiles'][$id]['can_edit']) {
2134
+					$context['can_edit_something'] = true;
2135
+		}
2056 2136
 
2057 2137
 		// You can only delete it if you can edit it AND it's not in use.
2058 2138
 		$context['profiles'][$id]['can_delete'] = $context['profiles'][$id]['can_edit'] && empty($profile['in_use']) ? true : false;
@@ -2073,8 +2153,9 @@  discard block
 block discarded – undo
2073 2153
 	global $smcFunc;
2074 2154
 
2075 2155
 	// All the parent groups to sort out.
2076
-	if (!is_array($parents))
2077
-		$parents = array($parents);
2156
+	if (!is_array($parents)) {
2157
+			$parents = array($parents);
2158
+	}
2078 2159
 
2079 2160
 	// Find all the children of this group.
2080 2161
 	$request = $smcFunc['db_query']('', '
@@ -2101,8 +2182,9 @@  discard block
 block discarded – undo
2101 2182
 	$parents = array_unique($parents);
2102 2183
 
2103 2184
 	// Not a sausage, or a child?
2104
-	if (empty($children))
2105
-		return false;
2185
+	if (empty($children)) {
2186
+			return false;
2187
+	}
2106 2188
 
2107 2189
 	// First off, are we doing general permissions?
2108 2190
 	if ($profile < 1 || $profile === null)
@@ -2117,9 +2199,10 @@  discard block
 block discarded – undo
2117 2199
 			)
2118 2200
 		);
2119 2201
 		$permissions = array();
2120
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2121
-			foreach ($children[$row['id_group']] as $child)
2202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2203
+					foreach ($children[$row['id_group']] as $child)
2122 2204
 				$permissions[] = array($child, $row['permission'], $row['add_deny']);
2205
+		}
2123 2206
 		$smcFunc['db_free_result']($request);
2124 2207
 
2125 2208
 		$smcFunc['db_query']('', '
@@ -2159,9 +2242,10 @@  discard block
 block discarded – undo
2159 2242
 			)
2160 2243
 		);
2161 2244
 		$permissions = array();
2162
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2163
-			foreach ($children[$row['id_group']] as $child)
2245
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2246
+					foreach ($children[$row['id_group']] as $child)
2164 2247
 				$permissions[] = array($child, $row['id_profile'], $row['permission'], $row['add_deny']);
2248
+		}
2165 2249
 		$smcFunc['db_free_result']($request);
2166 2250
 
2167 2251
 		$smcFunc['db_query']('', '
@@ -2195,12 +2279,15 @@  discard block
 block discarded – undo
2195 2279
 	global $context;
2196 2280
 
2197 2281
 	$context['illegal_permissions'] = array();
2198
-	if (!allowedTo('admin_forum'))
2199
-		$context['illegal_permissions'][] = 'admin_forum';
2200
-	if (!allowedTo('manage_membergroups'))
2201
-		$context['illegal_permissions'][] = 'manage_membergroups';
2202
-	if (!allowedTo('manage_permissions'))
2203
-		$context['illegal_permissions'][] = 'manage_permissions';
2282
+	if (!allowedTo('admin_forum')) {
2283
+			$context['illegal_permissions'][] = 'admin_forum';
2284
+	}
2285
+	if (!allowedTo('manage_membergroups')) {
2286
+			$context['illegal_permissions'][] = 'manage_membergroups';
2287
+	}
2288
+	if (!allowedTo('manage_permissions')) {
2289
+			$context['illegal_permissions'][] = 'manage_permissions';
2290
+	}
2204 2291
 
2205 2292
 	call_integration_hook('integrate_load_illegal_permissions');
2206 2293
 }
@@ -2349,16 +2436,17 @@  discard block
 block discarded – undo
2349 2436
 				'attachment' => 'disallow',
2350 2437
 				'children' => array(),
2351 2438
 			);
2439
+		} elseif (isset($context['profile_groups'][$row['id_parent']])) {
2440
+					$context['profile_groups'][$row['id_parent']]['children'][] = $row['group_name'];
2352 2441
 		}
2353
-		elseif (isset($context['profile_groups'][$row['id_parent']]))
2354
-			$context['profile_groups'][$row['id_parent']]['children'][] = $row['group_name'];
2355 2442
 	}
2356 2443
 	$smcFunc['db_free_result']($request);
2357 2444
 
2358 2445
 	// What are the permissions we are querying?
2359 2446
 	$all_permissions = array();
2360
-	foreach ($mappings as $perm_set)
2361
-		$all_permissions = array_merge($all_permissions, $perm_set);
2447
+	foreach ($mappings as $perm_set) {
2448
+			$all_permissions = array_merge($all_permissions, $perm_set);
2449
+	}
2362 2450
 
2363 2451
 	// If we're saving the changes then do just that - save them.
2364 2452
 	if (!empty($_POST['save_changes']) && ($context['current_profile'] == 1 || $context['current_profile'] > 4))
@@ -2373,8 +2461,7 @@  discard block
 block discarded – undo
2373 2461
 			{
2374 2462
 				// Turning it on. This seems easy enough.
2375 2463
 				updateSettings(array('postmod_active' => 1));
2376
-			}
2377
-			else
2464
+			} else
2378 2465
 			{
2379 2466
 				// Turning it off. Not so straightforward. We have to turn off warnings to moderation level, and make everything approved.
2380 2467
 				updateSettings(array(
@@ -2385,8 +2472,7 @@  discard block
 block discarded – undo
2385 2472
 				require_once($sourcedir . '/PostModeration.php');
2386 2473
 				approveAllData();
2387 2474
 			}
2388
-		}
2389
-		elseif ($modSettings['postmod_active'])
2475
+		} elseif ($modSettings['postmod_active'])
2390 2476
 		{
2391 2477
 			// We're not saving a new setting - and if it's still enabled we have more work to do.
2392 2478
 
@@ -2416,21 +2502,22 @@  discard block
 block discarded – undo
2416 2502
 							// Give them both sets for fun.
2417 2503
 							$new_permissions[] = array($context['current_profile'], $group['id'], $data[0], 1);
2418 2504
 							$new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1);
2505
+						} elseif ($_POST[$index][$group['id']] == 'moderate') {
2506
+													$new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1);
2419 2507
 						}
2420
-						elseif ($_POST[$index][$group['id']] == 'moderate')
2421
-							$new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1);
2422 2508
 					}
2423 2509
 				}
2424 2510
 			}
2425 2511
 
2426 2512
 			// Insert new permissions.
2427
-			if (!empty($new_permissions))
2428
-				$smcFunc['db_insert']('',
2513
+			if (!empty($new_permissions)) {
2514
+							$smcFunc['db_insert']('',
2429 2515
 					'{db_prefix}board_permissions',
2430 2516
 					array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'),
2431 2517
 					$new_permissions,
2432 2518
 					array('id_profile', 'id_group', 'permission')
2433 2519
 				);
2520
+			}
2434 2521
 		}
2435 2522
 	}
2436 2523
 
@@ -2459,11 +2546,13 @@  discard block
 block discarded – undo
2459 2546
 					if ($row['add_deny'])
2460 2547
 					{
2461 2548
 						// Full allowance?
2462
-						if ($index == 0)
2463
-							$context['profile_groups'][$row['id_group']][$key] = 'allow';
2549
+						if ($index == 0) {
2550
+													$context['profile_groups'][$row['id_group']][$key] = 'allow';
2551
+						}
2464 2552
 						// Otherwise only bother with moderate if not on allow.
2465
-						elseif ($context['profile_groups'][$row['id_group']][$key] != 'allow')
2466
-							$context['profile_groups'][$row['id_group']][$key] = 'moderate';
2553
+						elseif ($context['profile_groups'][$row['id_group']][$key] != 'allow') {
2554
+													$context['profile_groups'][$row['id_group']][$key] = 'moderate';
2555
+						}
2467 2556
 					}
2468 2557
 				}
2469 2558
 			}
Please login to merge, or discard this patch.
Sources/Subs-Recent.php 1 patch
Braces   +5 added lines, -3 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 the latest posts of a forum.
@@ -59,8 +60,9 @@  discard block
 block discarded – undo
59 60
 		censorText($row['body']);
60 61
 
61 62
 		$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => '&#10;')));
62
-		if ($smcFunc['strlen']($row['body']) > 128)
63
-			$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
63
+		if ($smcFunc['strlen']($row['body']) > 128) {
64
+					$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
65
+		}
64 66
 
65 67
 		// Build the array.
66 68
 		$posts[] = array(
Please login to merge, or discard this patch.
Sources/ManagePaid.php 1 patch
Braces   +202 added lines, -148 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * The main entrance point for the 'Paid Subscription' screen, calling
@@ -32,18 +33,19 @@  discard block
 block discarded – undo
32 33
 	loadLanguage('ManagePaid');
33 34
 	loadTemplate('ManagePaid');
34 35
 
35
-	if (!empty($modSettings['paid_enabled']))
36
-		$subActions = array(
36
+	if (!empty($modSettings['paid_enabled'])) {
37
+			$subActions = array(
37 38
 			'modify' => array('ModifySubscription', 'admin_forum'),
38 39
 			'modifyuser' => array('ModifyUserSubscription', 'admin_forum'),
39 40
 			'settings' => array('ModifySubscriptionSettings', 'admin_forum'),
40 41
 			'view' => array('ViewSubscriptions', 'admin_forum'),
41 42
 			'viewsub' => array('ViewSubscribedUsers', 'admin_forum'),
42 43
 		);
43
-	else
44
-		$subActions = array(
44
+	} else {
45
+			$subActions = array(
45 46
 			'settings' => array('ModifySubscriptionSettings', 'admin_forum'),
46 47
 		);
48
+	}
47 49
 
48 50
 	// Default the sub-action to 'view subscriptions', but only if they have already set things up..
49 51
 	$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($modSettings['paid_currency_symbol']) && !empty($modSettings['paid_enabled']) ? 'view' : 'settings');
@@ -59,8 +61,8 @@  discard block
 block discarded – undo
59 61
 		'help' => '',
60 62
 		'description' => $txt['paid_subscriptions_desc'],
61 63
 	);
62
-	if (!empty($modSettings['paid_enabled']))
63
-		$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
64
+	if (!empty($modSettings['paid_enabled'])) {
65
+			$context[$context['admin_menu_name']]['tab_data']['tabs'] = array(
64 66
 			'view' => array(
65 67
 				'description' => $txt['paid_subs_view_desc'],
66 68
 			),
@@ -68,6 +70,7 @@  discard block
 block discarded – undo
68 70
 				'description' => $txt['paid_subs_settings_desc'],
69 71
 			),
70 72
 		);
73
+	}
71 74
 
72 75
 	call_integration_hook('integrate_manage_subscriptions', array(&$subActions));
73 76
 
@@ -92,8 +95,9 @@  discard block
 block discarded – undo
92 95
 	{
93 96
 		// If the currency is set to something different then we need to set it to other for this to work and set it back shortly.
94 97
 		$modSettings['paid_currency'] = !empty($modSettings['paid_currency_code']) ? $modSettings['paid_currency_code'] : '';
95
-		if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud')))
96
-			$modSettings['paid_currency'] = 'other';
98
+		if (!empty($modSettings['paid_currency_code']) && !in_array($modSettings['paid_currency_code'], array('usd', 'eur', 'gbp', 'cad', 'aud'))) {
99
+					$modSettings['paid_currency'] = 'other';
100
+		}
97 101
 
98 102
 		// These are all the default settings.
99 103
 		$config_vars = array(
@@ -156,8 +160,7 @@  discard block
 block discarded – undo
156 160
 			}
157 161
 		}
158 162
 		toggleOther();', true);
159
-	}
160
-	else
163
+	} else
161 164
 	{
162 165
 		$config_vars = array(
163 166
 			array('check', 'paid_enabled'),
@@ -166,8 +169,9 @@  discard block
 block discarded – undo
166 169
 	}
167 170
 
168 171
 	// Just searching?
169
-	if ($return_config)
170
-		return $config_vars;
172
+	if ($return_config) {
173
+			return $config_vars;
174
+	}
171 175
 
172 176
 	// Get the settings template fired up.
173 177
 	require_once($sourcedir . '/ManageServer.php');
@@ -211,8 +215,9 @@  discard block
 block discarded – undo
211 215
 			foreach (explode(',', $_POST['paid_email_to']) as $email)
212 216
 			{
213 217
 				$email = trim($email);
214
-				if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL))
215
-					$email_addresses[] = $email;
218
+				if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
219
+									$email_addresses[] = $email;
220
+				}
216 221
 				$_POST['paid_email_to'] = implode(',', $email_addresses);
217 222
 			}
218 223
 		}
@@ -249,8 +254,9 @@  discard block
 block discarded – undo
249 254
 	global $context, $txt, $modSettings, $sourcedir, $scripturl;
250 255
 
251 256
 	// Not made the settings yet?
252
-	if (empty($modSettings['paid_currency_symbol']))
253
-		fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings');
257
+	if (empty($modSettings['paid_currency_symbol'])) {
258
+			fatal_lang_error('paid_not_set_currency', false, $scripturl . '?action=admin;area=paidsubscribe;sa=settings');
259
+	}
254 260
 
255 261
 	// Some basic stuff.
256 262
 	$context['page_title'] = $txt['paid_subs_view'];
@@ -270,10 +276,11 @@  discard block
 block discarded – undo
270 276
 
271 277
 				foreach ($context['subscriptions'] as $data)
272 278
 				{
273
-					if (++$counter < $start)
274
-						continue;
275
-					elseif ($counter == $start + $items_per_page)
276
-						break;
279
+					if (++$counter < $start) {
280
+											continue;
281
+					} elseif ($counter == $start + $items_per_page) {
282
+											break;
283
+					}
277 284
 
278 285
 					$subscriptions[] = $data;
279 286
 				}
@@ -450,8 +457,9 @@  discard block
 block discarded – undo
450 457
 			);
451 458
 			$id_group = 0;
452 459
 			$add_groups = '';
453
-			if ($smcFunc['db_num_rows']($request))
454
-				list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);
460
+			if ($smcFunc['db_num_rows']($request)) {
461
+							list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);
462
+			}
455 463
 			$smcFunc['db_free_result']($request);
456 464
 
457 465
 			$changes = array();
@@ -463,8 +471,9 @@  discard block
 block discarded – undo
463 471
 				{
464 472
 					// If their current primary group isn't what they had before the subscription, and their current group was
465 473
 					// granted by the sub, remove it.
466
-					if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group)
467
-						$changes[$id_member]['id_group'] = $member_data['old_id_group'];
474
+					if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group) {
475
+											$changes[$id_member]['id_group'] = $member_data['old_id_group'];
476
+					}
468 477
 				}
469 478
 			}
470 479
 
@@ -477,15 +486,17 @@  discard block
 block discarded – undo
477 486
 					// First let's get their groups sorted.
478 487
 					$current_groups = explode(',', $member_data['additional_groups']);
479 488
 					$new_groups = implode(',', array_diff($current_groups, $add_groups));
480
-					if ($new_groups != $member_data['additional_groups'])
481
-						$changes[$id_member]['additional_groups'] = $new_groups;
489
+					if ($new_groups != $member_data['additional_groups']) {
490
+											$changes[$id_member]['additional_groups'] = $new_groups;
491
+					}
482 492
 				}
483 493
 			}
484 494
 
485 495
 			// We're going through changes...
486
-			if (!empty($changes))
487
-				foreach ($changes as $id_member => $new_values)
496
+			if (!empty($changes)) {
497
+							foreach ($changes as $id_member => $new_values)
488 498
 					updateMemberData($id_member, $new_values);
499
+			}
489 500
 		}
490 501
 
491 502
 		// Delete the subscription
@@ -533,11 +544,13 @@  discard block
 block discarded – undo
533 544
 				'M' => 24,
534 545
 				'Y' => 5,
535 546
 			);
536
-			if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1)
537
-				fatal_lang_error('paid_invalid_duration', false);
547
+			if (empty($_POST['span_unit']) || empty($limits[$_POST['span_unit']]) || empty($_POST['span_value']) || $_POST['span_value'] < 1) {
548
+							fatal_lang_error('paid_invalid_duration', false);
549
+			}
538 550
 
539
-			if ($_POST['span_value'] > $limits[$_POST['span_unit']])
540
-				fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false);
551
+			if ($_POST['span_value'] > $limits[$_POST['span_unit']]) {
552
+							fatal_lang_error('paid_invalid_duration_' . $_POST['span_unit'], false);
553
+			}
541 554
 
542 555
 			// Clean the span.
543 556
 			$span = $_POST['span_value'] . $_POST['span_unit'];
@@ -546,8 +559,9 @@  discard block
 block discarded – undo
546 559
 			$cost = array('fixed' => sprintf('%01.2f', strtr($_POST['cost'], ',', '.')));
547 560
 
548 561
 			// There needs to be something.
549
-			if (empty($_POST['span_value']) || empty($_POST['cost']))
550
-				fatal_lang_error('paid_no_cost_value');
562
+			if (empty($_POST['span_value']) || empty($_POST['cost'])) {
563
+							fatal_lang_error('paid_no_cost_value');
564
+			}
551 565
 		}
552 566
 		// Flexible is harder but more fun ;)
553 567
 		else
@@ -561,8 +575,9 @@  discard block
 block discarded – undo
561 575
 				'year' => sprintf('%01.2f', strtr($_POST['cost_year'], ',', '.')),
562 576
 			);
563 577
 
564
-			if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year']))
565
-				fatal_lang_error('paid_all_freq_blank');
578
+			if (empty($_POST['cost_day']) && empty($_POST['cost_week']) && empty($_POST['cost_month']) && empty($_POST['cost_year'])) {
579
+							fatal_lang_error('paid_all_freq_blank');
580
+			}
566 581
 		}
567 582
 		$cost = json_encode($cost);
568 583
 
@@ -571,9 +586,10 @@  discard block
 block discarded – undo
571 586
 
572 587
 		// Yep, time to do additional groups.
573 588
 		$addgroups = array();
574
-		if (!empty($_POST['addgroup']))
575
-			foreach ($_POST['addgroup'] as $id => $dummy)
589
+		if (!empty($_POST['addgroup'])) {
590
+					foreach ($_POST['addgroup'] as $id => $dummy)
576 591
 				$addgroups[] = (int) $id;
592
+		}
577 593
 		$addgroups = implode(',', $addgroups);
578 594
 
579 595
 		// Is it new?!
@@ -683,18 +699,18 @@  discard block
 block discarded – undo
683 699
 			{
684 700
 				$span_value = $match[1];
685 701
 				$span_unit = $match[2];
686
-			}
687
-			else
702
+			} else
688 703
 			{
689 704
 				$span_value = 0;
690 705
 				$span_unit = 'D';
691 706
 			}
692 707
 
693 708
 			// Is this a flexible one?
694
-			if ($row['length'] == 'F')
695
-				$isFlexible = true;
696
-			else
697
-				$isFlexible = false;
709
+			if ($row['length'] == 'F') {
710
+							$isFlexible = true;
711
+			} else {
712
+							$isFlexible = false;
713
+			}
698 714
 
699 715
 			$context['sub'] = array(
700 716
 				'name' => $row['name'],
@@ -743,8 +759,9 @@  discard block
 block discarded – undo
743 759
 		)
744 760
 	);
745 761
 	$context['groups'] = array();
746
-	while ($row = $smcFunc['db_fetch_assoc']($request))
747
-		$context['groups'][$row['id_group']] = $row['group_name'];
762
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
763
+			$context['groups'][$row['id_group']] = $row['group_name'];
764
+	}
748 765
 	$smcFunc['db_free_result']($request);
749 766
 
750 767
 	// This always happens.
@@ -778,8 +795,9 @@  discard block
 block discarded – undo
778 795
 		)
779 796
 	);
780 797
 	// Something wrong?
781
-	if ($smcFunc['db_num_rows']($request) == 0)
782
-		fatal_lang_error('no_access', false);
798
+	if ($smcFunc['db_num_rows']($request) == 0) {
799
+			fatal_lang_error('no_access', false);
800
+	}
783 801
 	// Do the subscription context.
784 802
 	$row = $smcFunc['db_fetch_assoc']($request);
785 803
 	$context['subscription'] = array(
@@ -1014,8 +1032,8 @@  discard block
 block discarded – undo
1014 1032
 		))
1015 1033
 	);
1016 1034
 	$subscribers = array();
1017
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1018
-		$subscribers[] = array(
1035
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1036
+			$subscribers[] = array(
1019 1037
 			'id' => $row['id_sublog'],
1020 1038
 			'id_member' => $row['id_member'],
1021 1039
 			'name' => $row['name'],
@@ -1025,6 +1043,7 @@  discard block
 block discarded – undo
1025 1043
 			'status' => $row['status'],
1026 1044
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] == 0 ? $txt['paid_finished'] : $txt['paid_pending']) : $txt['paid_active'],
1027 1045
 		);
1046
+	}
1028 1047
 	$smcFunc['db_free_result']($request);
1029 1048
 
1030 1049
 	return $subscribers;
@@ -1059,14 +1078,16 @@  discard block
 block discarded – undo
1059 1078
 				'current_log_item' => $context['log_id'],
1060 1079
 			)
1061 1080
 		);
1062
-		if ($smcFunc['db_num_rows']($request) == 0)
1063
-			fatal_lang_error('no_access', false);
1081
+		if ($smcFunc['db_num_rows']($request) == 0) {
1082
+					fatal_lang_error('no_access', false);
1083
+		}
1064 1084
 		list ($context['sub_id']) = $smcFunc['db_fetch_row']($request);
1065 1085
 		$smcFunc['db_free_result']($request);
1066 1086
 	}
1067 1087
 
1068
-	if (!isset($context['subscriptions'][$context['sub_id']]))
1069
-		fatal_lang_error('no_access', false);
1088
+	if (!isset($context['subscriptions'][$context['sub_id']])) {
1089
+			fatal_lang_error('no_access', false);
1090
+	}
1070 1091
 	$context['current_subscription'] = $context['subscriptions'][$context['sub_id']];
1071 1092
 
1072 1093
 	// Searching?
@@ -1099,8 +1120,9 @@  discard block
 block discarded – undo
1099 1120
 					'name' => $_POST['name'],
1100 1121
 				)
1101 1122
 			);
1102
-			if ($smcFunc['db_num_rows']($request) == 0)
1103
-				fatal_lang_error('error_member_not_found');
1123
+			if ($smcFunc['db_num_rows']($request) == 0) {
1124
+							fatal_lang_error('error_member_not_found');
1125
+			}
1104 1126
 
1105 1127
 			list ($id_member, $id_group) = $smcFunc['db_fetch_row']($request);
1106 1128
 			$smcFunc['db_free_result']($request);
@@ -1116,14 +1138,15 @@  discard block
 block discarded – undo
1116 1138
 					'current_member' => $id_member,
1117 1139
 				)
1118 1140
 			);
1119
-			if ($smcFunc['db_num_rows']($request) != 0)
1120
-				fatal_lang_error('member_already_subscribed');
1141
+			if ($smcFunc['db_num_rows']($request) != 0) {
1142
+							fatal_lang_error('member_already_subscribed');
1143
+			}
1121 1144
 			$smcFunc['db_free_result']($request);
1122 1145
 
1123 1146
 			// Actually put the subscription in place.
1124
-			if ($status == 1)
1125
-				addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1126
-			else
1147
+			if ($status == 1) {
1148
+							addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1149
+			} else
1127 1150
 			{
1128 1151
 				$smcFunc['db_insert']('',
1129 1152
 					'{db_prefix}log_subscribed',
@@ -1150,20 +1173,20 @@  discard block
 block discarded – undo
1150 1173
 					'current_log_item' => $context['log_id'],
1151 1174
 				)
1152 1175
 			);
1153
-			if ($smcFunc['db_num_rows']($request) == 0)
1154
-				fatal_lang_error('no_access', false);
1176
+			if ($smcFunc['db_num_rows']($request) == 0) {
1177
+							fatal_lang_error('no_access', false);
1178
+			}
1155 1179
 
1156 1180
 			list ($id_member, $old_status) = $smcFunc['db_fetch_row']($request);
1157 1181
 			$smcFunc['db_free_result']($request);
1158 1182
 
1159 1183
 			// Pick the right permission stuff depending on what the status is changing from/to.
1160
-			if ($old_status == 1 && $status != 1)
1161
-				removeSubscription($context['sub_id'], $id_member);
1162
-			elseif ($status == 1 && $old_status != 1)
1184
+			if ($old_status == 1 && $status != 1) {
1185
+							removeSubscription($context['sub_id'], $id_member);
1186
+			} elseif ($status == 1 && $old_status != 1)
1163 1187
 			{
1164 1188
 				addSubscription($context['sub_id'], $id_member, 0, $starttime, $endtime);
1165
-			}
1166
-			else
1189
+			} else
1167 1190
 			{
1168 1191
 				$smcFunc['db_query']('', '
1169 1192
 					UPDATE {db_prefix}log_subscribed
@@ -1191,8 +1214,9 @@  discard block
 block discarded – undo
1191 1214
 		if (!empty($_REQUEST['delsub']))
1192 1215
 		{
1193 1216
 			$toDelete = array();
1194
-			foreach ($_REQUEST['delsub'] as $id => $dummy)
1195
-				$toDelete[] = (int) $id;
1217
+			foreach ($_REQUEST['delsub'] as $id => $dummy) {
1218
+							$toDelete[] = (int) $id;
1219
+			}
1196 1220
 
1197 1221
 			$request = $smcFunc['db_query']('', '
1198 1222
 				SELECT id_subscribe, id_member
@@ -1202,8 +1226,9 @@  discard block
 block discarded – undo
1202 1226
 					'subscription_list' => $toDelete,
1203 1227
 				)
1204 1228
 			);
1205
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1206
-				removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete']));
1229
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1230
+							removeSubscription($row['id_subscribe'], $row['id_member'], isset($_REQUEST['delete']));
1231
+			}
1207 1232
 			$smcFunc['db_free_result']($request);
1208 1233
 		}
1209 1234
 		redirectexit('action=admin;area=paidsubscribe;sa=viewsub;sid=' . $context['sub_id']);
@@ -1247,9 +1272,9 @@  discard block
 block discarded – undo
1247 1272
 			);
1248 1273
 			list ($context['sub']['username']) = $smcFunc['db_fetch_row']($request);
1249 1274
 			$smcFunc['db_free_result']($request);
1275
+		} else {
1276
+					$context['sub']['username'] = '';
1250 1277
 		}
1251
-		else
1252
-			$context['sub']['username'] = '';
1253 1278
 	}
1254 1279
 	// Otherwise load the existing info.
1255 1280
 	else
@@ -1266,8 +1291,9 @@  discard block
 block discarded – undo
1266 1291
 				'blank_string' => '',
1267 1292
 			)
1268 1293
 		);
1269
-		if ($smcFunc['db_num_rows']($request) == 0)
1270
-			fatal_lang_error('no_access', false);
1294
+		if ($smcFunc['db_num_rows']($request) == 0) {
1295
+					fatal_lang_error('no_access', false);
1296
+		}
1271 1297
 		$row = $smcFunc['db_fetch_assoc']($request);
1272 1298
 		$smcFunc['db_free_result']($request);
1273 1299
 
@@ -1288,13 +1314,13 @@  discard block
 block discarded – undo
1288 1314
 					{
1289 1315
 						foreach ($costs as $duration => $cost)
1290 1316
 						{
1291
-							if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2])
1292
-								$context['pending_payments'][$id] = array(
1317
+							if ($cost != 0 && $cost == $pending[1] && $duration == $pending[2]) {
1318
+															$context['pending_payments'][$id] = array(
1293 1319
 									'desc' => sprintf($modSettings['paid_currency_symbol'], $cost . '/' . $txt[$duration]),
1294 1320
 								);
1321
+							}
1295 1322
 						}
1296
-					}
1297
-					elseif ($costs['fixed'] == $pending[1])
1323
+					} elseif ($costs['fixed'] == $pending[1])
1298 1324
 					{
1299 1325
 						$context['pending_payments'][$id] = array(
1300 1326
 							'desc' => sprintf($modSettings['paid_currency_symbol'], $costs['fixed']),
@@ -1312,8 +1338,9 @@  discard block
 block discarded – undo
1312 1338
 					if ($_GET['pending'] == $id && $pending[3] == 'payback' && isset($context['pending_payments'][$id]))
1313 1339
 					{
1314 1340
 						// Flexible?
1315
-						if (isset($_GET['accept']))
1316
-							addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);
1341
+						if (isset($_GET['accept'])) {
1342
+													addSubscription($context['current_subscription']['id'], $row['id_member'], $context['current_subscription']['real_length'] == 'F' ? strtoupper(substr($pending[2], 0, 1)) : 0);
1343
+						}
1317 1344
 						unset($pending_details[$id]);
1318 1345
 
1319 1346
 						$new_details = json_encode($pending_details);
@@ -1375,8 +1402,9 @@  discard block
 block discarded – undo
1375 1402
 	global $smcFunc;
1376 1403
 
1377 1404
 	// Make it an array.
1378
-	if (!is_array($users))
1379
-		$users = array($users);
1405
+	if (!is_array($users)) {
1406
+			$users = array($users);
1407
+	}
1380 1408
 
1381 1409
 	// Get all the members current groups.
1382 1410
 	$groups = array();
@@ -1414,14 +1442,16 @@  discard block
 block discarded – undo
1414 1442
 		if ($row['id_group'] != 0)
1415 1443
 		{
1416 1444
 			// If this is changing - add the old one to the additional groups so it's not lost.
1417
-			if ($row['id_group'] != $groups[$row['id_member']]['primary'])
1418
-				$groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary'];
1445
+			if ($row['id_group'] != $groups[$row['id_member']]['primary']) {
1446
+							$groups[$row['id_member']]['additional'][] = $groups[$row['id_member']]['primary'];
1447
+			}
1419 1448
 			$groups[$row['id_member']]['primary'] = $row['id_group'];
1420 1449
 		}
1421 1450
 
1422 1451
 		// Additional groups.
1423
-		if (!empty($row['add_groups']))
1424
-			$groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups']));
1452
+		if (!empty($row['add_groups'])) {
1453
+					$groups[$row['id_member']]['additional'] = array_merge($groups[$row['id_member']]['additional'], explode(',', $row['add_groups']));
1454
+		}
1425 1455
 	}
1426 1456
 	$smcFunc['db_free_result']($request);
1427 1457
 
@@ -1429,9 +1459,10 @@  discard block
 block discarded – undo
1429 1459
 	foreach ($groups as $id => $group)
1430 1460
 	{
1431 1461
 		$group['additional'] = array_unique($group['additional']);
1432
-		foreach ($group['additional'] as $key => $value)
1433
-			if (empty($value))
1462
+		foreach ($group['additional'] as $key => $value) {
1463
+					if (empty($value))
1434 1464
 				unset($group['additional'][$key]);
1465
+		}
1435 1466
 		$addgroups = implode(',', $group['additional']);
1436 1467
 
1437 1468
 		$smcFunc['db_query']('', '
@@ -1465,8 +1496,9 @@  discard block
 block discarded – undo
1465 1496
 	loadSubscriptions();
1466 1497
 
1467 1498
 	// Exists, yes?
1468
-	if (!isset($context['subscriptions'][$id_subscribe]))
1469
-		return;
1499
+	if (!isset($context['subscriptions'][$id_subscribe])) {
1500
+			return;
1501
+	}
1470 1502
 
1471 1503
 	$curSub = $context['subscriptions'][$id_subscribe];
1472 1504
 
@@ -1514,16 +1546,19 @@  discard block
 block discarded – undo
1514 1546
 		list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request);
1515 1547
 
1516 1548
 		// If this has already expired but is active, extension means the period from now.
1517
-		if ($endtime < time())
1518
-			$endtime = time();
1519
-		if ($starttime == 0)
1520
-			$starttime = time();
1549
+		if ($endtime < time()) {
1550
+					$endtime = time();
1551
+		}
1552
+		if ($starttime == 0) {
1553
+					$starttime = time();
1554
+		}
1521 1555
 
1522 1556
 		// Work out the new expiry date.
1523 1557
 		$endtime += $duration;
1524 1558
 
1525
-		if ($forceEndTime != 0)
1526
-			$endtime = $forceEndTime;
1559
+		if ($forceEndTime != 0) {
1560
+					$endtime = $forceEndTime;
1561
+		}
1527 1562
 
1528 1563
 		// As everything else should be good, just update!
1529 1564
 		$smcFunc['db_query']('', '
@@ -1553,8 +1588,9 @@  discard block
 block discarded – undo
1553 1588
 	);
1554 1589
 
1555 1590
 	// Just in case the member doesn't exist.
1556
-	if ($smcFunc['db_num_rows']($request) == 0)
1557
-		return;
1591
+	if ($smcFunc['db_num_rows']($request) == 0) {
1592
+			return;
1593
+	}
1558 1594
 
1559 1595
 	list ($old_id_group, $additional_groups) = $smcFunc['db_fetch_row']($request);
1560 1596
 	$smcFunc['db_free_result']($request);
@@ -1571,16 +1607,18 @@  discard block
 block discarded – undo
1571 1607
 		$id_group = $curSub['prim_group'];
1572 1608
 
1573 1609
 		// Ensure their old privileges are maintained.
1574
-		if ($old_id_group != 0)
1575
-			$newAddGroups[] = $old_id_group;
1610
+		if ($old_id_group != 0) {
1611
+					$newAddGroups[] = $old_id_group;
1612
+		}
1613
+	} else {
1614
+			$id_group = $old_id_group;
1576 1615
 	}
1577
-	else
1578
-		$id_group = $old_id_group;
1579 1616
 
1580 1617
 	// Yep, make sure it's unique, and no empties.
1581
-	foreach ($newAddGroups as $k => $v)
1582
-		if (empty($v))
1618
+	foreach ($newAddGroups as $k => $v) {
1619
+			if (empty($v))
1583 1620
 			unset($newAddGroups[$k]);
1621
+	}
1584 1622
 	$newAddGroups = array_unique($newAddGroups);
1585 1623
 	$newAddGroups = implode(',', $newAddGroups);
1586 1624
 
@@ -1616,16 +1654,19 @@  discard block
 block discarded – undo
1616 1654
 		list ($id_sublog, $endtime, $starttime) = $smcFunc['db_fetch_row']($request);
1617 1655
 
1618 1656
 		// If this has already expired but is active, extension means the period from now.
1619
-		if ($endtime < time())
1620
-			$endtime = time();
1621
-		if ($starttime == 0)
1622
-			$starttime = time();
1657
+		if ($endtime < time()) {
1658
+					$endtime = time();
1659
+		}
1660
+		if ($starttime == 0) {
1661
+					$starttime = time();
1662
+		}
1623 1663
 
1624 1664
 		// Work out the new expiry date.
1625 1665
 		$endtime += $duration;
1626 1666
 
1627
-		if ($forceEndTime != 0)
1628
-			$endtime = $forceEndTime;
1667
+		if ($forceEndTime != 0) {
1668
+					$endtime = $forceEndTime;
1669
+		}
1629 1670
 
1630 1671
 		// As everything else should be good, just update!
1631 1672
 		$smcFunc['db_query']('', '
@@ -1648,13 +1689,15 @@  discard block
 block discarded – undo
1648 1689
 
1649 1690
 	// Otherwise a very simple insert.
1650 1691
 	$endtime = time() + $duration;
1651
-	if ($forceEndTime != 0)
1652
-		$endtime = $forceEndTime;
1692
+	if ($forceEndTime != 0) {
1693
+			$endtime = $forceEndTime;
1694
+	}
1653 1695
 
1654
-	if ($forceStartTime == 0)
1655
-		$starttime = time();
1656
-	else
1657
-		$starttime = $forceStartTime;
1696
+	if ($forceStartTime == 0) {
1697
+			$starttime = time();
1698
+	} else {
1699
+			$starttime = $forceStartTime;
1700
+	}
1658 1701
 
1659 1702
 	$smcFunc['db_insert']('',
1660 1703
 		'{db_prefix}log_subscribed',
@@ -1727,15 +1770,17 @@  discard block
 block discarded – undo
1727 1770
 	$new_id_group = -1;
1728 1771
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1729 1772
 	{
1730
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
1731
-			continue;
1773
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
1774
+					continue;
1775
+		}
1732 1776
 
1733 1777
 		// The one we're removing?
1734 1778
 		if ($row['id_subscribe'] == $id_subscribe)
1735 1779
 		{
1736 1780
 			$removals = explode(',', $context['subscriptions'][$row['id_subscribe']]['add_groups']);
1737
-			if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0)
1738
-				$removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
1781
+			if ($context['subscriptions'][$row['id_subscribe']]['prim_group'] != 0) {
1782
+							$removals[] = $context['subscriptions'][$row['id_subscribe']]['prim_group'];
1783
+			}
1739 1784
 			$old_id_group = $row['old_id_group'];
1740 1785
 		}
1741 1786
 		// Otherwise things we allow.
@@ -1753,30 +1798,33 @@  discard block
 block discarded – undo
1753 1798
 
1754 1799
 	// Now, for everything we are removing check they definitely are not allowed it.
1755 1800
 	$existingGroups = explode(',', $additional_groups);
1756
-	foreach ($existingGroups as $key => $group)
1757
-		if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed)))
1801
+	foreach ($existingGroups as $key => $group) {
1802
+			if (empty($group) || (in_array($group, $removals) && !in_array($group, $allowed)))
1758 1803
 			unset($existingGroups[$key]);
1804
+	}
1759 1805
 
1760 1806
 	// Finally, do something with the current primary group.
1761 1807
 	if (in_array($id_group, $removals))
1762 1808
 	{
1763 1809
 		// If this primary group is actually allowed keep it.
1764
-		if (in_array($id_group, $allowed))
1765
-			$existingGroups[] = $id_group;
1810
+		if (in_array($id_group, $allowed)) {
1811
+					$existingGroups[] = $id_group;
1812
+		}
1766 1813
 
1767 1814
 		// Either way, change the id_group back.
1768 1815
 		if ($new_id_group < 1)
1769 1816
 		{
1770 1817
 			// If we revert to the old id-group we need to ensure it wasn't from a subscription.
1771
-			foreach ($context['subscriptions'] as $id => $group)
1772
-				// It was? Make them a regular member then!
1818
+			foreach ($context['subscriptions'] as $id => $group) {
1819
+							// It was? Make them a regular member then!
1773 1820
 				if ($group['prim_group'] == $old_id_group)
1774 1821
 					$old_id_group = 0;
1822
+			}
1775 1823
 
1776 1824
 			$id_group = $old_id_group;
1825
+		} else {
1826
+					$id_group = $new_id_group;
1777 1827
 		}
1778
-		else
1779
-			$id_group = $new_id_group;
1780 1828
 	}
1781 1829
 
1782 1830
 	// Crazy stuff, we seem to have our groups fixed, just make them unique
@@ -1796,8 +1844,8 @@  discard block
 block discarded – undo
1796 1844
 	);
1797 1845
 
1798 1846
 	// Disable the subscription.
1799
-	if (!$delete)
1800
-		$smcFunc['db_query']('', '
1847
+	if (!$delete) {
1848
+			$smcFunc['db_query']('', '
1801 1849
 			UPDATE {db_prefix}log_subscribed
1802 1850
 			SET status = {int:not_active}
1803 1851
 			WHERE id_member = {int:current_member}
@@ -1808,9 +1856,10 @@  discard block
 block discarded – undo
1808 1856
 				'current_subscription' => $id_subscribe,
1809 1857
 			)
1810 1858
 		);
1859
+	}
1811 1860
 	// Otherwise delete it!
1812
-	else
1813
-		$smcFunc['db_query']('', '
1861
+	else {
1862
+			$smcFunc['db_query']('', '
1814 1863
 			DELETE FROM {db_prefix}log_subscribed
1815 1864
 			WHERE id_member = {int:current_member}
1816 1865
 				AND id_subscribe = {int:current_subscription}',
@@ -1819,7 +1868,8 @@  discard block
 block discarded – undo
1819 1868
 				'current_subscription' => $id_subscribe,
1820 1869
 			)
1821 1870
 		);
1822
-}
1871
+	}
1872
+	}
1823 1873
 
1824 1874
 /**
1825 1875
  * This just kind of caches all the subscription data.
@@ -1828,8 +1878,9 @@  discard block
 block discarded – undo
1828 1878
 {
1829 1879
 	global $context, $txt, $modSettings, $smcFunc;
1830 1880
 
1831
-	if (!empty($context['subscriptions']))
1832
-		return;
1881
+	if (!empty($context['subscriptions'])) {
1882
+			return;
1883
+	}
1833 1884
 
1834 1885
 	// Make sure this is loaded, just in case.
1835 1886
 	loadLanguage('ManagePaid');
@@ -1846,10 +1897,11 @@  discard block
 block discarded – undo
1846 1897
 		// Pick a cost.
1847 1898
 		$costs = smf_json_decode($row['cost'], true);
1848 1899
 
1849
-		if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed']))
1850
-			$cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']);
1851
-		else
1852
-			$cost = '???';
1900
+		if ($row['length'] != 'F' && !empty($modSettings['paid_currency_symbol']) && !empty($costs['fixed'])) {
1901
+					$cost = sprintf($modSettings['paid_currency_symbol'], $costs['fixed']);
1902
+		} else {
1903
+					$cost = '???';
1904
+		}
1853 1905
 
1854 1906
 		// Do the span.
1855 1907
 		preg_match('~(\d*)(\w)~', $row['length'], $match);
@@ -1876,9 +1928,9 @@  discard block
 block discarded – undo
1876 1928
 					$num_length *= 31556926;
1877 1929
 					break;
1878 1930
 			}
1931
+		} else {
1932
+					$length = '??';
1879 1933
 		}
1880
-		else
1881
-			$length = '??';
1882 1934
 
1883 1935
 		$context['subscriptions'][$row['id_subscribe']] = array(
1884 1936
 			'id' => $row['id_subscribe'],
@@ -1913,8 +1965,9 @@  discard block
 block discarded – undo
1913 1965
 	{
1914 1966
 		$ind = $row['status'] == 0 ? 'finished' : 'total';
1915 1967
 
1916
-		if (isset($context['subscriptions'][$row['id_subscribe']]))
1917
-			$context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count'];
1968
+		if (isset($context['subscriptions'][$row['id_subscribe']])) {
1969
+					$context['subscriptions'][$row['id_subscribe']][$ind] = $row['member_count'];
1970
+		}
1918 1971
 	}
1919 1972
 	$smcFunc['db_free_result']($request);
1920 1973
 
@@ -1928,8 +1981,9 @@  discard block
 block discarded – undo
1928 1981
 	);
1929 1982
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1930 1983
 	{
1931
-		if (isset($context['subscriptions'][$row['id_subscribe']]))
1932
-			$context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending'];
1984
+		if (isset($context['subscriptions'][$row['id_subscribe']])) {
1985
+					$context['subscriptions'][$row['id_subscribe']]['pending'] = $row['total_pending'];
1986
+		}
1933 1987
 	}
1934 1988
 	$smcFunc['db_free_result']($request);
1935 1989
 }
Please login to merge, or discard this patch.
Sources/Help.php 1 patch
Braces   +29 added lines, -22 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
  * Redirect to the user help ;).
@@ -95,12 +96,13 @@  discard block
 block discarded – undo
95 96
 	);
96 97
 
97 98
 	// Have we got a localized one?
98
-	if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt'))
99
-		$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
100
-	elseif (file_exists($boarddir . '/agreement.txt'))
101
-		$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
102
-	else
103
-		$context['agreement'] = '';
99
+	if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) {
100
+			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
101
+	} elseif (file_exists($boarddir . '/agreement.txt')) {
102
+			$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
103
+	} else {
104
+			$context['agreement'] = '';
105
+	}
104 106
 
105 107
 	// Nothing to show, so let's get out of here
106 108
 	if (empty($context['agreement']))
@@ -128,18 +130,21 @@  discard block
 block discarded – undo
128 130
 {
129 131
 	global $txt, $helptxt, $context, $scripturl;
130 132
 
131
-	if (!isset($_GET['help']) || !is_string($_GET['help']))
132
-		fatal_lang_error('no_access', false);
133
+	if (!isset($_GET['help']) || !is_string($_GET['help'])) {
134
+			fatal_lang_error('no_access', false);
135
+	}
133 136
 
134
-	if (!isset($helptxt))
135
-		$helptxt = array();
137
+	if (!isset($helptxt)) {
138
+			$helptxt = array();
139
+	}
136 140
 
137 141
 	// Load the admin help language file and template.
138 142
 	loadLanguage('Help');
139 143
 
140 144
 	// Permission specific help?
141
-	if (isset($_GET['help']) && substr($_GET['help'], 0, 14) == 'permissionhelp')
142
-		loadLanguage('ManagePermissions');
145
+	if (isset($_GET['help']) && substr($_GET['help'], 0, 14) == 'permissionhelp') {
146
+			loadLanguage('ManagePermissions');
147
+	}
143 148
 
144 149
 	loadTemplate('Help');
145 150
 
@@ -154,16 +159,18 @@  discard block
 block discarded – undo
154 159
 	$context['sub_template'] = 'popup';
155 160
 
156 161
 	// What help string should be used?
157
-	if (isset($helptxt[$_GET['help']]))
158
-		$context['help_text'] = $helptxt[$_GET['help']];
159
-	elseif (isset($txt[$_GET['help']]))
160
-		$context['help_text'] = $txt[$_GET['help']];
161
-	else
162
-		$context['help_text'] = $_GET['help'];
162
+	if (isset($helptxt[$_GET['help']])) {
163
+			$context['help_text'] = $helptxt[$_GET['help']];
164
+	} elseif (isset($txt[$_GET['help']])) {
165
+			$context['help_text'] = $txt[$_GET['help']];
166
+	} else {
167
+			$context['help_text'] = $_GET['help'];
168
+	}
163 169
 
164 170
 	// Does this text contain a link that we should fill in?
165
-	if (preg_match('~%([0-9]+\$)?s\?~', $context['help_text'], $match))
166
-		$context['help_text'] = sprintf($context['help_text'], $scripturl, $context['session_id'], $context['session_var']);
167
-}
171
+	if (preg_match('~%([0-9]+\$)?s\?~', $context['help_text'], $match)) {
172
+			$context['help_text'] = sprintf($context['help_text'], $scripturl, $context['session_id'], $context['session_var']);
173
+	}
174
+	}
168 175
 
169 176
 ?>
170 177
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Db-mysql.php 1 patch
Braces   +251 added lines, -185 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
  *  Maps the implementations in this file (smf_db_function_name)
@@ -33,8 +34,8 @@  discard block
 block discarded – undo
33 34
 	global $smcFunc;
34 35
 
35 36
 	// Map some database specific functions, only do this once.
36
-	if (!isset($smcFunc['db_fetch_assoc']))
37
-		$smcFunc += array(
37
+	if (!isset($smcFunc['db_fetch_assoc'])) {
38
+			$smcFunc += array(
38 39
 			'db_query'                  => 'smf_db_query',
39 40
 			'db_quote'                  => 'smf_db_quote',
40 41
 			'db_fetch_assoc'            => 'mysqli_fetch_assoc',
@@ -60,9 +61,11 @@  discard block
 block discarded – undo
60 61
 			'db_mb4'                    => false,
61 62
 			'db_ping'                   => 'mysqli_ping',
62 63
 		);
64
+	}
63 65
 
64
-	if (!empty($db_options['persist']))
65
-		$db_server = 'p:' . $db_server;
66
+	if (!empty($db_options['persist'])) {
67
+			$db_server = 'p:' . $db_server;
68
+	}
66 69
 
67 70
 	$connection = mysqli_init();
68 71
 
@@ -71,24 +74,27 @@  discard block
 block discarded – undo
71 74
 	$success = false;
72 75
 
73 76
 	if ($connection) {
74
-		if (!empty($db_options['port']))
75
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
76
-		else
77
-			$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
77
+		if (!empty($db_options['port'])) {
78
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags);
79
+		} else {
80
+					$success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags);
81
+		}
78 82
 	}
79 83
 
80 84
 	// Something's wrong, show an error if its fatal (which we assume it is)
81 85
 	if ($success === false)
82 86
 	{
83
-		if (!empty($db_options['non_fatal']))
84
-			return null;
85
-		else
86
-			display_db_error();
87
+		if (!empty($db_options['non_fatal'])) {
88
+					return null;
89
+		} else {
90
+					display_db_error();
91
+		}
87 92
 	}
88 93
 
89 94
 	// Select the database, unless told not to
90
-	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal']))
91
-		display_db_error();
95
+	if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) {
96
+			display_db_error();
97
+	}
92 98
 
93 99
 	$smcFunc['db_query']('', 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'',
94 100
 		array(),
@@ -164,38 +170,46 @@  discard block
 block discarded – undo
164 170
 	global $db_callback, $user_info, $db_prefix, $smcFunc;
165 171
 
166 172
 	list ($values, $connection) = $db_callback;
167
-	if (!is_object($connection))
168
-		display_db_error();
173
+	if (!is_object($connection)) {
174
+			display_db_error();
175
+	}
169 176
 
170
-	if ($matches[1] === 'db_prefix')
171
-		return $db_prefix;
177
+	if ($matches[1] === 'db_prefix') {
178
+			return $db_prefix;
179
+	}
172 180
 
173 181
 	if (!empty($user_info))
174 182
 	{
175
-		foreach (array_keys($user_info) as $key)
176
-			if (strpos($key, 'query_') !== false && $key === $matches[1])
183
+		foreach (array_keys($user_info) as $key) {
184
+					if (strpos($key, 'query_') !== false && $key === $matches[1])
177 185
 				return $user_info[$matches[1]];
186
+		}
178 187
 	}
179 188
 
180
-	if ($matches[1] === 'empty')
181
-		return '\'\'';
189
+	if ($matches[1] === 'empty') {
190
+			return '\'\'';
191
+	}
182 192
 
183
-	if (!isset($matches[2]))
184
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
193
+	if (!isset($matches[2])) {
194
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
195
+	}
185 196
 
186
-	if ($matches[1] === 'literal')
187
-		return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
197
+	if ($matches[1] === 'literal') {
198
+			return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\'';
199
+	}
188 200
 
189
-	if (!isset($values[$matches[2]]))
190
-		smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
201
+	if (!isset($values[$matches[2]])) {
202
+			smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__);
203
+	}
191 204
 
192 205
 	$replacement = $values[$matches[2]];
193 206
 
194 207
 	switch ($matches[1])
195 208
 	{
196 209
 		case 'int':
197
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
198
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
210
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
211
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
212
+			}
199 213
 			return (string) (int) $replacement;
200 214
 		break;
201 215
 
@@ -207,65 +221,73 @@  discard block
 block discarded – undo
207 221
 		case 'array_int':
208 222
 			if (is_array($replacement))
209 223
 			{
210
-				if (empty($replacement))
211
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
224
+				if (empty($replacement)) {
225
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
226
+				}
212 227
 
213 228
 				foreach ($replacement as $key => $value)
214 229
 				{
215
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
216
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
230
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
231
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
232
+					}
217 233
 
218 234
 					$replacement[$key] = (string) (int) $value;
219 235
 				}
220 236
 
221 237
 				return implode(', ', $replacement);
238
+			} else {
239
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
222 240
 			}
223
-			else
224
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
225 241
 
226 242
 		break;
227 243
 
228 244
 		case 'array_string':
229 245
 			if (is_array($replacement))
230 246
 			{
231
-				if (empty($replacement))
232
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
247
+				if (empty($replacement)) {
248
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+				}
233 250
 
234
-				foreach ($replacement as $key => $value)
235
-					$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
251
+				foreach ($replacement as $key => $value) {
252
+									$replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value));
253
+				}
236 254
 
237 255
 				return implode(', ', $replacement);
256
+			} else {
257
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
238 258
 			}
239
-			else
240
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241 259
 		break;
242 260
 
243 261
 		case 'date':
244
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
245
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
246
-			else
247
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
262
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
263
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
264
+			} else {
265
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
266
+			}
248 267
 		break;
249 268
 
250 269
 		case 'time':
251
-			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1)
252
-				return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
253
-			else
254
-				smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
270
+			if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) {
271
+							return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]);
272
+			} else {
273
+							smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
274
+			}
255 275
 		break;
256 276
 
257 277
 		case 'datetime':
258
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1)
259
-				return 'str_to_date('.
278
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) {
279
+							return 'str_to_date('.
260 280
 					sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]).
261 281
 					',\'%Y-%m-%d %h:%i:%s\')';
262
-			else
263
-				smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
282
+			} else {
283
+							smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
284
+			}
264 285
 		break;
265 286
 
266 287
 		case 'float':
267
-			if (!is_numeric($replacement))
268
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
288
+			if (!is_numeric($replacement)) {
289
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
290
+			}
269 291
 			return (string) (float) $replacement;
270 292
 		break;
271 293
 
@@ -279,32 +301,37 @@  discard block
 block discarded – undo
279 301
 		break;
280 302
 
281 303
 		case 'inet':
282
-			if ($replacement == 'null' || $replacement == '')
283
-				return 'null';
284
-			if (!isValidIP($replacement))
285
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
304
+			if ($replacement == 'null' || $replacement == '') {
305
+							return 'null';
306
+			}
307
+			if (!isValidIP($replacement)) {
308
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
309
+			}
286 310
 			//we don't use the native support of mysql > 5.6.2
287 311
 			return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement)));
288 312
 
289 313
 		case 'array_inet':
290 314
 			if (is_array($replacement))
291 315
 			{
292
-				if (empty($replacement))
293
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
316
+				if (empty($replacement)) {
317
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
318
+				}
294 319
 
295 320
 				foreach ($replacement as $key => $value)
296 321
 				{
297
-					if ($replacement == 'null' || $replacement == '')
298
-						$replacement[$key] = 'null';
299
-					if (!isValidIP($value))
300
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
322
+					if ($replacement == 'null' || $replacement == '') {
323
+											$replacement[$key] = 'null';
324
+					}
325
+					if (!isValidIP($value)) {
326
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
327
+					}
301 328
 					$replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value)));
302 329
 				}
303 330
 
304 331
 				return implode(', ', $replacement);
332
+			} else {
333
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
305 334
 			}
306
-			else
307
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
308 335
 		break;
309 336
 
310 337
 		default:
@@ -380,22 +407,25 @@  discard block
 block discarded – undo
380 407
 		// Are we in SSI mode?  If so try that username and password first
381 408
 		if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
382 409
 		{
383
-			if (empty($db_persist))
384
-				$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
385
-			else
386
-				$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
410
+			if (empty($db_persist)) {
411
+							$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
412
+			} else {
413
+							$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
414
+			}
387 415
 		}
388 416
 		// Fall back to the regular username and password if need be
389 417
 		if (!$db_connection)
390 418
 		{
391
-			if (empty($db_persist))
392
-				$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
393
-			else
394
-				$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
419
+			if (empty($db_persist)) {
420
+							$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
421
+			} else {
422
+							$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
423
+			}
395 424
 		}
396 425
 
397
-		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
398
-			$db_connection = false;
426
+		if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
427
+					$db_connection = false;
428
+		}
399 429
 
400 430
 		$connection = $db_connection;
401 431
 	}
@@ -403,18 +433,20 @@  discard block
 block discarded – undo
403 433
 	// One more query....
404 434
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
405 435
 
406
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
407
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
436
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
437
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
438
+	}
408 439
 
409 440
 	// Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By
410 441
 	if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string))
411 442
 	{
412 443
 		// Add before LIMIT
413
-		if ($pos = strpos($db_string, 'LIMIT '))
414
-			$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
415
-		else
416
-			// Append it.
444
+		if ($pos = strpos($db_string, 'LIMIT ')) {
445
+					$db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string));
446
+		} else {
447
+					// Append it.
417 448
 			$db_string .= "\n\t\t\tORDER BY null";
449
+		}
418 450
 	}
419 451
 
420 452
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
@@ -436,8 +468,9 @@  discard block
 block discarded – undo
436 468
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
437 469
 
438 470
 		// Initialize $db_cache if not already initialized.
439
-		if (!isset($db_cache))
440
-			$db_cache = array();
471
+		if (!isset($db_cache)) {
472
+					$db_cache = array();
473
+		}
441 474
 
442 475
 		if (!empty($_SESSION['debug_redirect']))
443 476
 		{
@@ -463,17 +496,18 @@  discard block
 block discarded – undo
463 496
 		while (true)
464 497
 		{
465 498
 			$pos = strpos($db_string, '\'', $pos + 1);
466
-			if ($pos === false)
467
-				break;
499
+			if ($pos === false) {
500
+							break;
501
+			}
468 502
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
469 503
 
470 504
 			while (true)
471 505
 			{
472 506
 				$pos1 = strpos($db_string, '\'', $pos + 1);
473 507
 				$pos2 = strpos($db_string, '\\', $pos + 1);
474
-				if ($pos1 === false)
475
-					break;
476
-				elseif ($pos2 === false || $pos2 > $pos1)
508
+				if ($pos1 === false) {
509
+									break;
510
+				} elseif ($pos2 === false || $pos2 > $pos1)
477 511
 				{
478 512
 					$pos = $pos1;
479 513
 					break;
@@ -489,29 +523,35 @@  discard block
 block discarded – undo
489 523
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
490 524
 
491 525
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
492
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
493
-			$fail = true;
526
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
527
+					$fail = true;
528
+		}
494 529
 		// Trying to change passwords, slow us down, or something?
495
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
496
-			$fail = true;
497
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
498
-			$fail = true;
530
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
531
+					$fail = true;
532
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
533
+					$fail = true;
534
+		}
499 535
 
500
-		if (!empty($fail) && function_exists('log_error'))
501
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
536
+		if (!empty($fail) && function_exists('log_error')) {
537
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
538
+		}
502 539
 	}
503 540
 
504
-	if (empty($db_unbuffered))
505
-		$ret = @mysqli_query($connection, $db_string);
506
-	else
507
-		$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
541
+	if (empty($db_unbuffered)) {
542
+			$ret = @mysqli_query($connection, $db_string);
543
+	} else {
544
+			$ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT);
545
+	}
508 546
 
509
-	if ($ret === false && empty($db_values['db_error_skip']))
510
-		$ret = smf_db_error($db_string, $connection);
547
+	if ($ret === false && empty($db_values['db_error_skip'])) {
548
+			$ret = smf_db_error($db_string, $connection);
549
+	}
511 550
 
512 551
 	// Debugging.
513
-	if (isset($db_show_debug) && $db_show_debug === true)
514
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
552
+	if (isset($db_show_debug) && $db_show_debug === true) {
553
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
554
+	}
515 555
 
516 556
 	return $ret;
517 557
 }
@@ -558,12 +598,13 @@  discard block
 block discarded – undo
558 598
 	// Decide which connection to use
559 599
 	$connection = $connection === null ? $db_connection : $connection;
560 600
 
561
-	if ($type == 'begin')
562
-		return @mysqli_query($connection, 'BEGIN');
563
-	elseif ($type == 'rollback')
564
-		return @mysqli_query($connection, 'ROLLBACK');
565
-	elseif ($type == 'commit')
566
-		return @mysqli_query($connection, 'COMMIT');
601
+	if ($type == 'begin') {
602
+			return @mysqli_query($connection, 'BEGIN');
603
+	} elseif ($type == 'rollback') {
604
+			return @mysqli_query($connection, 'ROLLBACK');
605
+	} elseif ($type == 'commit') {
606
+			return @mysqli_query($connection, 'COMMIT');
607
+	}
567 608
 
568 609
 	return false;
569 610
 }
@@ -603,8 +644,9 @@  discard block
 block discarded – undo
603 644
 	//    2013: Lost connection to server during query.
604 645
 
605 646
 	// Log the error.
606
-	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error'))
607
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
647
+	if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) {
648
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line);
649
+	}
608 650
 
609 651
 	// Database error auto fixing ;).
610 652
 	if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1'))
@@ -613,8 +655,9 @@  discard block
 block discarded – undo
613 655
 		$old_cache = @$modSettings['cache_enable'];
614 656
 		$modSettings['cache_enable'] = '1';
615 657
 
616
-		if (($temp = cache_get_data('db_last_error', 600)) !== null)
617
-			$db_last_error = max(@$db_last_error, $temp);
658
+		if (($temp = cache_get_data('db_last_error', 600)) !== null) {
659
+					$db_last_error = max(@$db_last_error, $temp);
660
+		}
618 661
 
619 662
 		if (@$db_last_error < time() - 3600 * 24 * 3)
620 663
 		{
@@ -630,8 +673,9 @@  discard block
 block discarded – undo
630 673
 					foreach ($tables as $table)
631 674
 					{
632 675
 						// Now, it's still theoretically possible this could be an injection.  So backtick it!
633
-						if (trim($table) != '')
634
-							$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
676
+						if (trim($table) != '') {
677
+													$fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`';
678
+						}
635 679
 					}
636 680
 				}
637 681
 
@@ -640,8 +684,9 @@  discard block
 block discarded – undo
640 684
 			// Table crashed.  Let's try to fix it.
641 685
 			elseif ($query_errno == 1016)
642 686
 			{
643
-				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0)
644
-					$fix_tables = array('`' . $match[1] . '`');
687
+				if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) {
688
+									$fix_tables = array('`' . $match[1] . '`');
689
+				}
645 690
 			}
646 691
 			// Indexes crashed.  Should be easy to fix!
647 692
 			elseif ($query_errno == 1034 || $query_errno == 1035)
@@ -660,13 +705,15 @@  discard block
 block discarded – undo
660 705
 
661 706
 			// Make a note of the REPAIR...
662 707
 			cache_put_data('db_last_error', time(), 600);
663
-			if (($temp = cache_get_data('db_last_error', 600)) === null)
664
-				updateSettingsFile(array('db_last_error' => time()));
708
+			if (($temp = cache_get_data('db_last_error', 600)) === null) {
709
+							updateSettingsFile(array('db_last_error' => time()));
710
+			}
665 711
 
666 712
 			// Attempt to find and repair the broken table.
667
-			foreach ($fix_tables as $table)
668
-				$smcFunc['db_query']('', "
713
+			foreach ($fix_tables as $table) {
714
+							$smcFunc['db_query']('', "
669 715
 					REPAIR TABLE $table", false, false);
716
+			}
670 717
 
671 718
 			// And send off an email!
672 719
 			sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror');
@@ -675,11 +722,12 @@  discard block
 block discarded – undo
675 722
 
676 723
 			// Try the query again...?
677 724
 			$ret = $smcFunc['db_query']('', $db_string, false, false);
678
-			if ($ret !== false)
679
-				return $ret;
725
+			if ($ret !== false) {
726
+							return $ret;
727
+			}
728
+		} else {
729
+					$modSettings['cache_enable'] = $old_cache;
680 730
 		}
681
-		else
682
-			$modSettings['cache_enable'] = $old_cache;
683 731
 
684 732
 		// Check for the "lost connection" or "deadlock found" errors - and try it just one more time.
685 733
 		if (in_array($query_errno, array(1205, 1213, 2006, 2013)))
@@ -689,22 +737,25 @@  discard block
 block discarded – undo
689 737
 				// Are we in SSI mode?  If so try that username and password first
690 738
 				if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
691 739
 				{
692
-					if (empty($db_persist))
693
-						$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
694
-					else
695
-						$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
740
+					if (empty($db_persist)) {
741
+											$db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd);
742
+					} else {
743
+											$db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd);
744
+					}
696 745
 				}
697 746
 				// Fall back to the regular username and password if need be
698 747
 				if (!$db_connection)
699 748
 				{
700
-					if (empty($db_persist))
701
-						$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
702
-					else
703
-						$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
749
+					if (empty($db_persist)) {
750
+											$db_connection = @mysqli_connect($db_server, $db_user, $db_passwd);
751
+					} else {
752
+											$db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd);
753
+					}
704 754
 				}
705 755
 
706
-				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name))
707
-					$db_connection = false;
756
+				if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) {
757
+									$db_connection = false;
758
+				}
708 759
 			}
709 760
 
710 761
 			if ($db_connection)
@@ -715,24 +766,27 @@  discard block
 block discarded – undo
715 766
 					$ret = $smcFunc['db_query']('', $db_string, false, false);
716 767
 
717 768
 					$new_errno = mysqli_errno($db_connection);
718
-					if ($ret !== false || in_array($new_errno, array(1205, 1213)))
719
-						break;
769
+					if ($ret !== false || in_array($new_errno, array(1205, 1213))) {
770
+											break;
771
+					}
720 772
 				}
721 773
 
722 774
 				// If it failed again, shucks to be you... we're not trying it over and over.
723
-				if ($ret !== false)
724
-					return $ret;
775
+				if ($ret !== false) {
776
+									return $ret;
777
+				}
725 778
 			}
726 779
 		}
727 780
 		// Are they out of space, perhaps?
728 781
 		elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false))
729 782
 		{
730
-			if (!isset($txt))
731
-				$query_error .= ' - check database storage space.';
732
-			else
783
+			if (!isset($txt)) {
784
+							$query_error .= ' - check database storage space.';
785
+			} else
733 786
 			{
734
-				if (!isset($txt['mysql_error_space']))
735
-					loadLanguage('Errors');
787
+				if (!isset($txt['mysql_error_space'])) {
788
+									loadLanguage('Errors');
789
+				}
736 790
 
737 791
 				$query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space'];
738 792
 			}
@@ -740,15 +794,17 @@  discard block
 block discarded – undo
740 794
 	}
741 795
 
742 796
 	// Nothing's defined yet... just die with it.
743
-	if (empty($context) || empty($txt))
744
-		die($query_error);
797
+	if (empty($context) || empty($txt)) {
798
+			die($query_error);
799
+	}
745 800
 
746 801
 	// Show an error message, if possible.
747 802
 	$context['error_title'] = $txt['database_error'];
748
-	if (allowedTo('admin_forum'))
749
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
750
-	else
751
-		$context['error_message'] = $txt['try_again'];
803
+	if (allowedTo('admin_forum')) {
804
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
805
+	} else {
806
+			$context['error_message'] = $txt['try_again'];
807
+	}
752 808
 
753 809
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
754 810
 	{
@@ -778,25 +834,28 @@  discard block
 block discarded – undo
778 834
 	$connection = $connection === null ? $db_connection : $connection;
779 835
 
780 836
 	// With nothing to insert, simply return.
781
-	if (empty($data))
782
-		return;
837
+	if (empty($data)) {
838
+			return;
839
+	}
783 840
 
784 841
 	// Replace the prefix holder with the actual prefix.
785 842
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
786 843
 
787 844
 	// Inserting data as a single row can be done as a single array.
788
-	if (!is_array($data[array_rand($data)]))
789
-		$data = array($data);
845
+	if (!is_array($data[array_rand($data)])) {
846
+			$data = array($data);
847
+	}
790 848
 
791 849
 	// Create the mold for a single row insert.
792 850
 	$insertData = '(';
793 851
 	foreach ($columns as $columnName => $type)
794 852
 	{
795 853
 		// Are we restricting the length?
796
-		if (strpos($type, 'string-') !== false)
797
-			$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
798
-		else
799
-			$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
854
+		if (strpos($type, 'string-') !== false) {
855
+					$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
856
+		} else {
857
+					$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
858
+		}
800 859
 	}
801 860
 	$insertData = substr($insertData, 0, -2) . ')';
802 861
 
@@ -805,8 +864,9 @@  discard block
 block discarded – undo
805 864
 
806 865
 	// Here's where the variables are injected to the query.
807 866
 	$insertRows = array();
808
-	foreach ($data as $dataRow)
809
-		$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
867
+	foreach ($data as $dataRow) {
868
+			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
869
+	}
810 870
 
811 871
 	// Determine the method of insertion.
812 872
 	$queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT');
@@ -826,15 +886,16 @@  discard block
 block discarded – undo
826 886
 
827 887
 	if(!empty($keys) && (count($keys) > 0) && ($method === '' || $method === 'insert') && $returnmode > 0)
828 888
 	{
829
-		if ($returnmode == 1)
830
-			$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
831
-		else if ($returnmode == 2)
889
+		if ($returnmode == 1) {
890
+					$return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1;
891
+		} else if ($returnmode == 2)
832 892
 		{
833 893
 			$return_var = array();
834 894
 			$count = count($insertRows);
835 895
 			$start = smf_db_insert_id($table, $keys[0]);
836
-			for ($i = 0; $i < $count; $i++ )
837
-				$return_var[] = $start + $i;
896
+			for ($i = 0; $i < $count; $i++ ) {
897
+							$return_var[] = $start + $i;
898
+			}
838 899
 		}
839 900
 		return $return_var;
840 901
 	}
@@ -852,8 +913,9 @@  discard block
 block discarded – undo
852 913
  */
853 914
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
854 915
 {
855
-	if (empty($log_message))
856
-		$log_message = $error_message;
916
+	if (empty($log_message)) {
917
+			$log_message = $error_message;
918
+	}
857 919
 
858 920
 	foreach (debug_backtrace() as $step)
859 921
 	{
@@ -872,12 +934,14 @@  discard block
 block discarded – undo
872 934
 	}
873 935
 
874 936
 	// A special case - we want the file and line numbers for debugging.
875
-	if ($error_type == 'return')
876
-		return array($file, $line);
937
+	if ($error_type == 'return') {
938
+			return array($file, $line);
939
+	}
877 940
 
878 941
 	// Is always a critical error.
879
-	if (function_exists('log_error'))
880
-		log_error($log_message, 'critical', $file, $line);
942
+	if (function_exists('log_error')) {
943
+			log_error($log_message, 'critical', $file, $line);
944
+	}
881 945
 
882 946
 	if (function_exists('fatal_error'))
883 947
 	{
@@ -885,12 +949,12 @@  discard block
 block discarded – undo
885 949
 
886 950
 		// Cannot continue...
887 951
 		exit;
952
+	} elseif ($error_type) {
953
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
954
+	} else {
955
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
956
+	}
888 957
 	}
889
-	elseif ($error_type)
890
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
891
-	else
892
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
893
-}
894 958
 
895 959
 /**
896 960
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -907,10 +971,11 @@  discard block
 block discarded – undo
907 971
 		'\\' => '\\\\',
908 972
 	);
909 973
 
910
-	if ($translate_human_wildcards)
911
-		$replacements += array(
974
+	if ($translate_human_wildcards) {
975
+			$replacements += array(
912 976
 			'*' => '%',
913 977
 		);
978
+	}
914 979
 
915 980
 	return strtr($string, $replacements);
916 981
 }
@@ -924,8 +989,9 @@  discard block
 block discarded – undo
924 989
  */
925 990
 function smf_is_resource($result)
926 991
 {
927
-	if ($result instanceof mysqli_result)
928
-		return true;
992
+	if ($result instanceof mysqli_result) {
993
+			return true;
994
+	}
929 995
 
930 996
 	return false;
931 997
 }
Please login to merge, or discard this patch.
Sources/ManageRegistration.php 1 patch
Braces   +27 added lines, -19 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
  * Entrance point for the registration center, it checks permissions and forwards
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 	global $context, $txt;
32 33
 
33 34
 	// Old templates might still request this.
34
-	if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'browse')
35
-		redirectexit('action=admin;area=viewmembers;sa=browse' . (isset($_REQUEST['type']) ? ';type=' . $_REQUEST['type'] : ''));
35
+	if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'browse') {
36
+			redirectexit('action=admin;area=viewmembers;sa=browse' . (isset($_REQUEST['type']) ? ';type=' . $_REQUEST['type'] : ''));
37
+	}
36 38
 
37 39
 	$subActions = array(
38 40
 		'register' => array('AdminRegister', 'moderate_forum'),
@@ -99,9 +101,10 @@  discard block
 block discarded – undo
99 101
 		checkSession();
100 102
 		validateToken('admin-regc');
101 103
 
102
-		foreach ($_POST as $key => $value)
103
-			if (!is_array($_POST[$key]))
104
+		foreach ($_POST as $key => $value) {
105
+					if (!is_array($_POST[$key]))
104 106
 				$_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key]));
107
+		}
105 108
 
106 109
 		$regOptions = array(
107 110
 			'interface' => 'admin',
@@ -161,12 +164,13 @@  discard block
 block discarded – undo
161 164
 			)
162 165
 		);
163 166
 		$context['member_groups'] = array(0 => $txt['admin_register_group_none']);
164
-		while ($row = $smcFunc['db_fetch_assoc']($request))
165
-			$context['member_groups'][$row['id_group']] = $row['group_name'];
167
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
168
+					$context['member_groups'][$row['id_group']] = $row['group_name'];
169
+		}
166 170
 		$smcFunc['db_free_result']($request);
171
+	} else {
172
+			$context['member_groups'] = array();
167 173
 	}
168
-	else
169
-		$context['member_groups'] = array();
170 174
 
171 175
 	// Basic stuff.
172 176
 	$context['sub_template'] = 'admin_register';
@@ -207,8 +211,9 @@  discard block
 block discarded – undo
207 211
 		{
208 212
 			$context['editable_agreements']['.' . $lang['filename']] = $lang['name'];
209 213
 			// Are we editing this?
210
-			if (isset($_POST['agree_lang']) && $_POST['agree_lang'] == '.' . $lang['filename'])
211
-				$context['current_agreement'] = '.' . $lang['filename'];
214
+			if (isset($_POST['agree_lang']) && $_POST['agree_lang'] == '.' . $lang['filename']) {
215
+							$context['current_agreement'] = '.' . $lang['filename'];
216
+			}
212 217
 		}
213 218
 	}
214 219
 
@@ -223,10 +228,11 @@  discard block
 block discarded – undo
223 228
 
224 229
 		updateSettings(array('requireAgreement' => !empty($_POST['requireAgreement'])));
225 230
 
226
-		if ($bytes == strlen($to_write))
227
-			$context['saved_successful'] = true;
228
-		else
229
-			$context['could_not_save'] = true;
231
+		if ($bytes == strlen($to_write)) {
232
+					$context['saved_successful'] = true;
233
+		} else {
234
+					$context['could_not_save'] = true;
235
+		}
230 236
 	}
231 237
 
232 238
 	$context['agreement'] = file_exists($boarddir . '/agreement' . $context['current_agreement'] . '.txt') ? $smcFunc['htmlspecialchars'](file_get_contents($boarddir . '/agreement' . $context['current_agreement'] . '.txt')) : '';
@@ -310,8 +316,9 @@  discard block
 block discarded – undo
310 316
 
311 317
 	call_integration_hook('integrate_modify_registration_settings', array(&$config_vars));
312 318
 
313
-	if ($return_config)
314
-		return $config_vars;
319
+	if ($return_config) {
320
+			return $config_vars;
321
+	}
315 322
 
316 323
 	// Setup the template
317 324
 	$context['sub_template'] = 'show_settings';
@@ -322,8 +329,9 @@  discard block
 block discarded – undo
322 329
 		checkSession();
323 330
 
324 331
 		// Are there some contacts missing?
325
-		if (!empty($_POST['coppaAge']) && !empty($_POST['coppaType']) && empty($_POST['coppaPost']) && empty($_POST['coppaFax']))
326
-			fatal_lang_error('admin_setting_coppa_require_contact');
332
+		if (!empty($_POST['coppaAge']) && !empty($_POST['coppaType']) && empty($_POST['coppaPost']) && empty($_POST['coppaFax'])) {
333
+					fatal_lang_error('admin_setting_coppa_require_contact');
334
+		}
327 335
 
328 336
 		// Post needs to take into account line breaks.
329 337
 		$_POST['coppaPost'] = str_replace("\n", '<br>', empty($_POST['coppaPost']) ? '' : $_POST['coppaPost']);
Please login to merge, or discard this patch.
Sources/Logging.php 1 patch
Braces   +140 added lines, -101 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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
  * Truncate the GET array to a specified length
@@ -26,14 +27,15 @@  discard block
 block discarded – undo
26 27
 function truncateArray($arr, $max_length=1900)
27 28
 {
28 29
 	$curr_length = array_sum(array_map("strlen", $arr));
29
-	if ($curr_length <= $max_length)
30
-		return $arr;
31
-	else
30
+	if ($curr_length <= $max_length) {
31
+			return $arr;
32
+	} else
32 33
 	{
33 34
 		// Truncate each element's value to a reasonable length
34 35
 		$param_max = floor($max_length/count($arr));
35
-		foreach ($arr as $key => &$value)
36
-			$value = substr($value, 0, $param_max - strlen($key) - 5);
36
+		foreach ($arr as $key => &$value) {
37
+					$value = substr($value, 0, $param_max - strlen($key) - 5);
38
+		}
37 39
 		return $arr;
38 40
 	}
39 41
 }
@@ -55,8 +57,9 @@  discard block
 block discarded – undo
55 57
 		// Don't update for every page - this isn't wholly accurate but who cares.
56 58
 		if ($topic)
57 59
 		{
58
-			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic)
59
-				$force = false;
60
+			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) {
61
+							$force = false;
62
+			}
60 63
 			$_SESSION['last_topic_id'] = $topic;
61 64
 		}
62 65
 	}
@@ -69,22 +72,24 @@  discard block
 block discarded – undo
69 72
 	}
70 73
 
71 74
 	// Don't mark them as online more than every so often.
72
-	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force)
73
-		return;
75
+	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) {
76
+			return;
77
+	}
74 78
 
75 79
 	if (!empty($modSettings['who_enabled']))
76 80
 	{
77 81
 		$serialized = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
78 82
 
79 83
 		// In the case of a dlattach action, session_var may not be set.
80
-		if (!isset($context['session_var']))
81
-			$context['session_var'] = $_SESSION['session_var'];
84
+		if (!isset($context['session_var'])) {
85
+					$context['session_var'] = $_SESSION['session_var'];
86
+		}
82 87
 
83 88
 		unset($serialized['sesc'], $serialized[$context['session_var']]);
84 89
 		$serialized = json_encode($serialized);
90
+	} else {
91
+			$serialized = '';
85 92
 	}
86
-	else
87
-		$serialized = '';
88 93
 
89 94
 	// Guests use 0, members use their session ID.
90 95
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
@@ -124,17 +129,18 @@  discard block
 block discarded – undo
124 129
 		);
125 130
 
126 131
 		// Guess it got deleted.
127
-		if ($smcFunc['db_affected_rows']() == 0)
132
+		if ($smcFunc['db_affected_rows']() == 0) {
133
+					$_SESSION['log_time'] = 0;
134
+		}
135
+	} else {
128 136
 			$_SESSION['log_time'] = 0;
129 137
 	}
130
-	else
131
-		$_SESSION['log_time'] = 0;
132 138
 
133 139
 	// Otherwise, we have to delete and insert.
134 140
 	if (empty($_SESSION['log_time']))
135 141
 	{
136
-		if ($do_delete || !empty($user_info['id']))
137
-			$smcFunc['db_query']('', '
142
+		if ($do_delete || !empty($user_info['id'])) {
143
+					$smcFunc['db_query']('', '
138 144
 				DELETE FROM {db_prefix}log_online
139 145
 				WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'),
140 146
 				array(
@@ -142,6 +148,7 @@  discard block
 block discarded – undo
142 148
 					'log_time' => time() - $modSettings['lastActive'] * 60,
143 149
 				)
144 150
 			);
151
+		}
145 152
 
146 153
 		$smcFunc['db_insert']($do_delete ? 'ignore' : 'replace',
147 154
 			'{db_prefix}log_online',
@@ -155,21 +162,24 @@  discard block
 block discarded – undo
155 162
 	$_SESSION['log_time'] = time();
156 163
 
157 164
 	// Well, they are online now.
158
-	if (empty($_SESSION['timeOnlineUpdated']))
159
-		$_SESSION['timeOnlineUpdated'] = time();
165
+	if (empty($_SESSION['timeOnlineUpdated'])) {
166
+			$_SESSION['timeOnlineUpdated'] = time();
167
+	}
160 168
 
161 169
 	// Set their login time, if not already done within the last minute.
162 170
 	if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa'))))
163 171
 	{
164 172
 		// Don't count longer than 15 minutes.
165
-		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
166
-			$_SESSION['timeOnlineUpdated'] = time();
173
+		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) {
174
+					$_SESSION['timeOnlineUpdated'] = time();
175
+		}
167 176
 
168 177
 		$user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
169 178
 		updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in']));
170 179
 
171
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
172
-			cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
180
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
181
+					cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
182
+		}
173 183
 
174 184
 		$user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
175 185
 		$_SESSION['timeOnlineUpdated'] = time();
@@ -206,8 +216,7 @@  discard block
 block discarded – undo
206 216
 			// Oops. maybe we have no more disk space left, or some other troubles, troubles...
207 217
 			// Copy the file back and run for your life!
208 218
 			@copy($boarddir . '/db_last_error_bak.php', $boarddir . '/db_last_error.php');
209
-		}
210
-		else
219
+		} else
211 220
 		{
212 221
 			@touch($boarddir . '/' . 'Settings.php');
213 222
 			return true;
@@ -227,22 +236,27 @@  discard block
 block discarded – undo
227 236
 	global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt;
228 237
 
229 238
 	// Add to Settings.php if you want to show the debugging information.
230
-	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery'))
231
-		return;
239
+	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) {
240
+			return;
241
+	}
232 242
 
233
-	if (empty($_SESSION['view_queries']))
234
-		$_SESSION['view_queries'] = 0;
235
-	if (empty($context['debug']['language_files']))
236
-		$context['debug']['language_files'] = array();
237
-	if (empty($context['debug']['sheets']))
238
-		$context['debug']['sheets'] = array();
243
+	if (empty($_SESSION['view_queries'])) {
244
+			$_SESSION['view_queries'] = 0;
245
+	}
246
+	if (empty($context['debug']['language_files'])) {
247
+			$context['debug']['language_files'] = array();
248
+	}
249
+	if (empty($context['debug']['sheets'])) {
250
+			$context['debug']['sheets'] = array();
251
+	}
239 252
 
240 253
 	$files = get_included_files();
241 254
 	$total_size = 0;
242 255
 	for ($i = 0, $n = count($files); $i < $n; $i++)
243 256
 	{
244
-		if (file_exists($files[$i]))
245
-			$total_size += filesize($files[$i]);
257
+		if (file_exists($files[$i])) {
258
+					$total_size += filesize($files[$i]);
259
+		}
246 260
 		$files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)'));
247 261
 	}
248 262
 
@@ -251,8 +265,9 @@  discard block
 block discarded – undo
251 265
 	{
252 266
 		foreach ($db_cache as $q => $qq)
253 267
 		{
254
-			if (!empty($qq['w']))
255
-				$warnings += count($qq['w']);
268
+			if (!empty($qq['w'])) {
269
+							$warnings += count($qq['w']);
270
+			}
256 271
 		}
257 272
 
258 273
 		$_SESSION['debug'] = &$db_cache;
@@ -273,12 +288,14 @@  discard block
 block discarded – undo
273 288
 	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
274 289
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
275 290
 
276
-	if (function_exists('memory_get_peak_usage'))
277
-		echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
291
+	if (function_exists('memory_get_peak_usage')) {
292
+			echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
293
+	}
278 294
 
279 295
 	// What tokens are active?
280
-	if (isset($_SESSION['token']))
281
-		echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
296
+	if (isset($_SESSION['token'])) {
297
+			echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
298
+	}
282 299
 
283 300
 	if (!empty($modSettings['cache_enable']) && !empty($cache_hits))
284 301
 	{
@@ -292,10 +309,12 @@  discard block
 block discarded – undo
292 309
 			$total_t += $cache_hit['t'];
293 310
 			$total_s += $cache_hit['s'];
294 311
 		}
295
-		if (!isset($cache_misses))
296
-			$cache_misses = array();
297
-		foreach ($cache_misses as $missed)
298
-			$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
312
+		if (!isset($cache_misses)) {
313
+					$cache_misses = array();
314
+		}
315
+		foreach ($cache_misses as $missed) {
316
+					$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
317
+		}
299 318
 
300 319
 		echo '
301 320
 	', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br>
@@ -306,38 +325,44 @@  discard block
 block discarded – undo
306 325
 	<a href="', $scripturl, '?action=viewquery" target="_blank" class="new_win">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br>
307 326
 	<br>';
308 327
 
309
-	if ($_SESSION['view_queries'] == 1 && !empty($db_cache))
310
-		foreach ($db_cache as $q => $qq)
328
+	if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) {
329
+			foreach ($db_cache as $q => $qq)
311 330
 		{
312 331
 			$is_select = strpos(trim($qq['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0;
332
+	}
313 333
 			// Temporary tables created in earlier queries are not explainable.
314 334
 			if ($is_select)
315 335
 			{
316
-				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp)
317
-					if (strpos(trim($qq['q']), $tmp) !== false)
336
+				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
337
+									if (strpos(trim($qq['q']), $tmp) !== false)
318 338
 					{
319 339
 						$is_select = false;
340
+				}
320 341
 						break;
321 342
 					}
322 343
 			}
323 344
 			// But actual creation of the temporary tables are.
324
-			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0)
325
-				$is_select = true;
345
+			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) {
346
+							$is_select = true;
347
+			}
326 348
 
327 349
 			// Make the filenames look a bit better.
328
-			if (isset($qq['f']))
329
-				$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
350
+			if (isset($qq['f'])) {
351
+							$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
352
+			}
330 353
 
331 354
 			echo '
332 355
 	<strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" class="new_win" style="text-decoration: none;">' : '', nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', $smcFunc['htmlspecialchars'](ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br>
333 356
 	&nbsp;&nbsp;&nbsp;';
334
-			if (!empty($qq['f']) && !empty($qq['l']))
335
-				echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
357
+			if (!empty($qq['f']) && !empty($qq['l'])) {
358
+							echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
359
+			}
336 360
 
337
-			if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at']))
338
-				echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>';
339
-			elseif (isset($qq['t']))
340
-				echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>';
361
+			if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) {
362
+							echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>';
363
+			} elseif (isset($qq['t'])) {
364
+							echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>';
365
+			}
341 366
 			echo '
342 367
 	<br>';
343 368
 		}
@@ -362,12 +387,14 @@  discard block
 block discarded – undo
362 387
 	global $modSettings, $smcFunc;
363 388
 	static $cache_stats = array();
364 389
 
365
-	if (empty($modSettings['trackStats']))
366
-		return false;
367
-	if (!empty($stats))
368
-		return $cache_stats = array_merge($cache_stats, $stats);
369
-	elseif (empty($cache_stats))
370
-		return false;
390
+	if (empty($modSettings['trackStats'])) {
391
+			return false;
392
+	}
393
+	if (!empty($stats)) {
394
+			return $cache_stats = array_merge($cache_stats, $stats);
395
+	} elseif (empty($cache_stats)) {
396
+			return false;
397
+	}
371 398
 
372 399
 	$setStringUpdate = '';
373 400
 	$insert_keys = array();
@@ -380,10 +407,11 @@  discard block
 block discarded – undo
380 407
 		$setStringUpdate .= '
381 408
 			' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ',';
382 409
 
383
-		if ($change === '+')
384
-			$cache_stats[$field] = 1;
385
-		else
386
-			$update_parameters[$field] = $change;
410
+		if ($change === '+') {
411
+					$cache_stats[$field] = 1;
412
+		} else {
413
+					$update_parameters[$field] = $change;
414
+		}
387 415
 		$insert_keys[$field] = 'int';
388 416
 	}
389 417
 
@@ -447,43 +475,50 @@  discard block
 block discarded – undo
447 475
 	);
448 476
 
449 477
 	// Make sure this particular log is enabled first...
450
-	if (empty($modSettings['modlog_enabled']))
451
-		unset ($log_types['moderate']);
452
-	if (empty($modSettings['userlog_enabled']))
453
-		unset ($log_types['user']);
454
-	if (empty($modSettings['adminlog_enabled']))
455
-		unset ($log_types['admin']);
478
+	if (empty($modSettings['modlog_enabled'])) {
479
+			unset ($log_types['moderate']);
480
+	}
481
+	if (empty($modSettings['userlog_enabled'])) {
482
+			unset ($log_types['user']);
483
+	}
484
+	if (empty($modSettings['adminlog_enabled'])) {
485
+			unset ($log_types['admin']);
486
+	}
456 487
 
457 488
 	call_integration_hook('integrate_log_types', array(&$log_types));
458 489
 
459 490
 	foreach ($logs as $log)
460 491
 	{
461
-		if (!isset($log_types[$log['log_type']]))
462
-			return false;
492
+		if (!isset($log_types[$log['log_type']])) {
493
+					return false;
494
+		}
463 495
 
464
-		if (!is_array($log['extra']))
465
-			trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
496
+		if (!is_array($log['extra'])) {
497
+					trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
498
+		}
466 499
 
467 500
 		// Pull out the parts we want to store separately, but also make sure that the data is proper
468 501
 		if (isset($log['extra']['topic']))
469 502
 		{
470
-			if (!is_numeric($log['extra']['topic']))
471
-				trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
503
+			if (!is_numeric($log['extra']['topic'])) {
504
+							trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
505
+			}
472 506
 			$topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic'];
473 507
 			unset($log['extra']['topic']);
508
+		} else {
509
+					$topic_id = 0;
474 510
 		}
475
-		else
476
-			$topic_id = 0;
477 511
 
478 512
 		if (isset($log['extra']['message']))
479 513
 		{
480
-			if (!is_numeric($log['extra']['message']))
481
-				trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
514
+			if (!is_numeric($log['extra']['message'])) {
515
+							trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
516
+			}
482 517
 			$msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message'];
483 518
 			unset($log['extra']['message']);
519
+		} else {
520
+					$msg_id = 0;
484 521
 		}
485
-		else
486
-			$msg_id = 0;
487 522
 
488 523
 		// @todo cache this?
489 524
 		// Is there an associated report on this?
@@ -510,23 +545,26 @@  discard block
 block discarded – undo
510 545
 			$smcFunc['db_free_result']($request);
511 546
 		}
512 547
 
513
-		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member']))
514
-			trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
548
+		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) {
549
+					trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
550
+		}
515 551
 
516 552
 		if (isset($log['extra']['board']))
517 553
 		{
518
-			if (!is_numeric($log['extra']['board']))
519
-				trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
554
+			if (!is_numeric($log['extra']['board'])) {
555
+							trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
556
+			}
520 557
 			$board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board'];
521 558
 			unset($log['extra']['board']);
559
+		} else {
560
+					$board_id = 0;
522 561
 		}
523
-		else
524
-			$board_id = 0;
525 562
 
526 563
 		if (isset($log['extra']['board_to']))
527 564
 		{
528
-			if (!is_numeric($log['extra']['board_to']))
529
-				trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
565
+			if (!is_numeric($log['extra']['board_to'])) {
566
+							trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
567
+			}
530 568
 			if (empty($board_id))
531 569
 			{
532 570
 				$board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to'];
@@ -534,10 +572,11 @@  discard block
 block discarded – undo
534 572
 			}
535 573
 		}
536 574
 
537
-		if (isset($log['extra']['member_affected']))
538
-			$memID = $log['extra']['member_affected'];
539
-		else
540
-			$memID = $user_info['id'];
575
+		if (isset($log['extra']['member_affected'])) {
576
+					$memID = $log['extra']['member_affected'];
577
+		} else {
578
+					$memID = $user_info['id'];
579
+		}
541 580
 
542 581
 		$inserts[] = array(
543 582
 			time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'],
Please login to merge, or discard this patch.
Sources/ReportedContent.php 1 patch
Braces   +61 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 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
  * Sets and call a function based on the given subaction. Acts as a dispatcher function.
@@ -54,8 +55,9 @@  discard block
 block discarded – undo
54 55
 	);
55 56
 
56 57
 	// This comes under the umbrella of moderating posts.
57
-	if ($context['report_type'] == 'members' || $user_info['mod_cache']['bq'] == '0=1')
58
-		isAllowedTo('moderate_forum');
58
+	if ($context['report_type'] == 'members' || $user_info['mod_cache']['bq'] == '0=1') {
59
+			isAllowedTo('moderate_forum');
60
+	}
59 61
 
60 62
 	$subActions = array(
61 63
 		'show' => 'ShowReports',
@@ -70,11 +72,11 @@  discard block
 block discarded – undo
70 72
 	call_integration_hook('integrate_reported_' . $context['report_type'], array(&$subActions));
71 73
 
72 74
 	// By default we call the open sub-action.
73
-	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]))
74
-		$context['sub_action'] = $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_REQUEST['sa']), ENT_QUOTES);
75
-
76
-	else
77
-		$context['sub_action'] = 'show';
75
+	if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) {
76
+			$context['sub_action'] = $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_REQUEST['sa']), ENT_QUOTES);
77
+	} else {
78
+			$context['sub_action'] = 'show';
79
+	}
78 80
 
79 81
 	// Hi Ho Silver Away!
80 82
 	call_helper($subActions[$context['sub_action']]);
@@ -116,11 +118,13 @@  discard block
 block discarded – undo
116 118
 
117 119
 		// All the ones to update...
118 120
 		$toClose = array();
119
-		foreach ($_POST['close'] as $rid)
120
-			$toClose[] = (int) $rid;
121
+		foreach ($_POST['close'] as $rid) {
122
+					$toClose[] = (int) $rid;
123
+		}
121 124
 
122
-		if (!empty($toClose))
123
-			updateReport('closed', 1, $toClose);
125
+		if (!empty($toClose)) {
126
+					updateReport('closed', 1, $toClose);
127
+		}
124 128
 
125 129
 		// Set the confirmation message.
126 130
 		$_SESSION['rc_confirmation'] = 'close_all';
@@ -175,8 +179,9 @@  discard block
 block discarded – undo
175 179
 	global $context, $sourcedir, $scripturl, $txt;
176 180
 
177 181
 	// Have to at least give us something to work with.
178
-	if (empty($_REQUEST['rid']))
179
-		fatal_lang_error('mc_reportedp_none_found');
182
+	if (empty($_REQUEST['rid'])) {
183
+			fatal_lang_error('mc_reportedp_none_found');
184
+	}
180 185
 
181 186
 	// Integers only please
182 187
 	$report_id = (int) $_REQUEST['rid'];
@@ -184,8 +189,9 @@  discard block
 block discarded – undo
184 189
 	// Get the report details.
185 190
 	$report = getReportDetails($report_id);
186 191
 
187
-	if (!$report)
188
-		fatal_lang_error('mc_no_modreport_found');
192
+	if (!$report) {
193
+			fatal_lang_error('mc_no_modreport_found');
194
+	}
189 195
 
190 196
 	// Build the report data - basic details first, then extra stuff based on the type
191 197
 	$context['report'] = array(
@@ -211,8 +217,7 @@  discard block
 block discarded – undo
211 217
 				'href' => $scripturl . '?action=profile;u=' . $report['id_user'],
212 218
 			),
213 219
 		);
214
-	}
215
-	else
220
+	} else
216 221
 	{
217 222
 		$extraDetails = array(
218 223
 			'topic_id' => $report['id_topic'],
@@ -235,8 +240,9 @@  discard block
 block discarded – undo
235 240
 
236 241
 	$reportComments = getReportComments($report_id);
237 242
 
238
-	if (!empty($reportComments))
239
-		$context['report'] = array_merge($context['report'], $reportComments);
243
+	if (!empty($reportComments)) {
244
+			$context['report'] = array_merge($context['report'], $reportComments);
245
+	}
240 246
 
241 247
 	// What have the other moderators done to this message?
242 248
 	require_once($sourcedir . '/Modlog.php');
@@ -257,8 +263,7 @@  discard block
 block discarded – undo
257 263
 			1,
258 264
 			true,
259 265
 		);
260
-	}
261
-	else
266
+	} else
262 267
 	{
263 268
 		$params = array(
264 269
 			'lm.id_topic = {int:id_topic}
@@ -358,16 +363,16 @@  discard block
 block discarded – undo
358 363
 	createList($listOptions);
359 364
 
360 365
 	// Make sure to get the correct tab selected.
361
-	if ($context['report']['closed'])
362
-		$context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
366
+	if ($context['report']['closed']) {
367
+			$context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
368
+	}
363 369
 
364 370
 	// Finally we are done :P
365 371
 	if ($context['report_type'] == 'members')
366 372
 	{
367 373
 		$context['page_title'] = sprintf($txt['mc_viewmemberreport'], $context['report']['user']['name']);
368 374
 		$context['sub_template'] = 'viewmemberreport';
369
-	}
370
-	else
375
+	} else
371 376
 	{
372 377
 		$context['page_title'] = sprintf($txt['mc_viewmodreport'], $context['report']['subject'], $context['report']['author']['name']);
373 378
 		$context['sub_template'] = 'viewmodreport';
@@ -390,8 +395,9 @@  discard block
 block discarded – undo
390 395
 	global $smcFunc, $scripturl, $user_info, $context;
391 396
 
392 397
 	// The report ID is a must.
393
-	if (empty($_REQUEST['rid']))
394
-		fatal_lang_error('mc_reportedp_none_found');
398
+	if (empty($_REQUEST['rid'])) {
399
+			fatal_lang_error('mc_reportedp_none_found');
400
+	}
395 401
 
396 402
 	// Integers only please.
397 403
 	$report_id = (int) $_REQUEST['rid'];
@@ -416,8 +422,9 @@  discard block
 block discarded – undo
416 422
 		checkSession('get');
417 423
 		validateToken('mod-reportC-delete', 'get');
418 424
 
419
-		if (empty($_REQUEST['mid']))
420
-			fatal_lang_error('mc_reportedp_comment_none_found');
425
+		if (empty($_REQUEST['mid'])) {
426
+					fatal_lang_error('mc_reportedp_comment_none_found');
427
+		}
421 428
 
422 429
 		$comment_id = (int) $_REQUEST['mid'];
423 430
 
@@ -425,15 +432,17 @@  discard block
 block discarded – undo
425 432
 		$comment = getCommentModDetails($comment_id);
426 433
 
427 434
 		// Perhaps somebody else already deleted this fine gem...
428
-		if (empty($comment))
429
-			fatal_lang_error('report_action_message_delete_issue');
435
+		if (empty($comment)) {
436
+					fatal_lang_error('report_action_message_delete_issue');
437
+		}
430 438
 
431 439
 		// Can you actually do this?
432 440
 		$comment_owner = $user_info['id'] == $comment['id_member'];
433 441
 
434 442
 		// Nope! sorry.
435
-		if (!allowedTo('admin_forum') && !$comment_owner)
436
-			fatal_lang_error('report_action_message_delete_cannot');
443
+		if (!allowedTo('admin_forum') && !$comment_owner) {
444
+					fatal_lang_error('report_action_message_delete_cannot');
445
+		}
437 446
 
438 447
 		// All good!
439 448
 		deleteModComment($comment_id);
@@ -458,11 +467,13 @@  discard block
 block discarded – undo
458 467
 	checkSession(isset($_REQUEST['save']) ? 'post' : 'get');
459 468
 
460 469
 	// The report ID is a must.
461
-	if (empty($_REQUEST['rid']))
462
-		fatal_lang_error('mc_reportedp_none_found');
470
+	if (empty($_REQUEST['rid'])) {
471
+			fatal_lang_error('mc_reportedp_none_found');
472
+	}
463 473
 
464
-	if (empty($_REQUEST['mid']))
465
-		fatal_lang_error('mc_reportedp_comment_none_found');
474
+	if (empty($_REQUEST['mid'])) {
475
+			fatal_lang_error('mc_reportedp_comment_none_found');
476
+	}
466 477
 
467 478
 	// Integers only please.
468 479
 	$context['report_id'] = (int) $_REQUEST['rid'];
@@ -470,8 +481,9 @@  discard block
 block discarded – undo
470 481
 
471 482
 	$context['comment'] = getCommentModDetails($context['comment_id']);
472 483
 
473
-	if (empty($context['comment']))
474
-		fatal_lang_error('mc_reportedp_comment_none_found');
484
+	if (empty($context['comment'])) {
485
+			fatal_lang_error('mc_reportedp_comment_none_found');
486
+	}
475 487
 
476 488
 	// Set up the comforting bits...
477 489
 	$context['page_title'] = $txt['mc_reported_posts'];
@@ -482,15 +494,17 @@  discard block
 block discarded – undo
482 494
 		validateToken('mod-reportC-edit');
483 495
 
484 496
 		// Make sure there is some data to edit on the DB.
485
-		if (empty($context['comment']))
486
-			fatal_lang_error('report_action_message_edit_issue');
497
+		if (empty($context['comment'])) {
498
+					fatal_lang_error('report_action_message_edit_issue');
499
+		}
487 500
 
488 501
 		// Still there, good, now lets see if you can actually edit it...
489 502
 		$comment_owner = $user_info['id'] == $context['comment']['id_member'];
490 503
 
491 504
 		// So, you aren't neither an admin or the comment owner huh? that's too bad.
492
-		if (!allowedTo('admin_forum') && !$comment_owner)
493
-			fatal_lang_error('report_action_message_edit_cannot');
505
+		if (!allowedTo('admin_forum') && !$comment_owner) {
506
+					fatal_lang_error('report_action_message_edit_cannot');
507
+		}
494 508
 
495 509
 		// All good!
496 510
 		$edited_comment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment']));
@@ -516,8 +530,9 @@  discard block
 block discarded – undo
516 530
 	checkSession('get');
517 531
 
518 532
 	// We need to do something!
519
-	if (empty($_GET['rid']) && (!isset($_GET['ignore']) || !isset($_GET['closed'])))
520
-		fatal_lang_error('mc_reportedp_none_found');
533
+	if (empty($_GET['rid']) && (!isset($_GET['ignore']) || !isset($_GET['closed']))) {
534
+			fatal_lang_error('mc_reportedp_none_found');
535
+	}
521 536
 
522 537
 	// What are we gonna do?
523 538
 	$action = isset($_GET['ignore']) ? 'ignore' : 'closed';
Please login to merge, or discard this patch.
Sources/PersonalMessage.php 1 patch
Braces   +633 added lines, -471 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This helps organize things...
@@ -37,13 +38,14 @@  discard block
 block discarded – undo
37 38
 
38 39
 	loadLanguage('PersonalMessage+Drafts');
39 40
 
40
-	if (!isset($_REQUEST['xml']))
41
-		loadTemplate('PersonalMessage');
41
+	if (!isset($_REQUEST['xml'])) {
42
+			loadTemplate('PersonalMessage');
43
+	}
42 44
 
43 45
 	// Load up the members maximum message capacity.
44
-	if ($user_info['is_admin'])
45
-		$context['message_limit'] = 0;
46
-	elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
46
+	if ($user_info['is_admin']) {
47
+			$context['message_limit'] = 0;
48
+	} elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
47 49
 	{
48 50
 		// @todo Why do we do this?  It seems like if they have any limit we should use it.
49 51
 		$request = $smcFunc['db_query']('', '
@@ -78,8 +80,9 @@  discard block
 block discarded – undo
78 80
 	}
79 81
 
80 82
 	// a previous message was sent successfully? show a small indication.
81
-	if (isset($_GET['done']) && ($_GET['done'] == 'sent'))
82
-		$context['pm_sent'] = true;
83
+	if (isset($_GET['done']) && ($_GET['done'] == 'sent')) {
84
+			$context['pm_sent'] = true;
85
+	}
83 86
 
84 87
 	$context['labels'] = array();
85 88
 
@@ -210,11 +213,11 @@  discard block
 block discarded – undo
210 213
 	{
211 214
 		$_REQUEST['sa'] = '';
212 215
 		MessageFolder();
213
-	}
214
-	else
216
+	} else
215 217
 	{
216
-		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup')
217
-			messageIndexBar($_REQUEST['sa']);
218
+		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') {
219
+					messageIndexBar($_REQUEST['sa']);
220
+		}
218 221
 
219 222
 		call_helper($subActions[$_REQUEST['sa']]);
220 223
 	}
@@ -291,16 +294,17 @@  discard block
 block discarded – undo
291 294
 	);
292 295
 
293 296
 	// Handle labels.
294
-	if (empty($context['currently_using_labels']))
295
-		unset($pm_areas['labels']);
296
-	else
297
+	if (empty($context['currently_using_labels'])) {
298
+			unset($pm_areas['labels']);
299
+	} else
297 300
 	{
298 301
 		// Note we send labels by id as it will have less problems in the querystring.
299 302
 		$unread_in_labels = 0;
300 303
 		foreach ($context['labels'] as $label)
301 304
 		{
302
-			if ($label['id'] == -1)
303
-				continue;
305
+			if ($label['id'] == -1) {
306
+							continue;
307
+			}
304 308
 
305 309
 			// Count the amount of unread items in labels.
306 310
 			$unread_in_labels += $label['unread_messages'];
@@ -314,8 +318,9 @@  discard block
 block discarded – undo
314 318
 			);
315 319
 		}
316 320
 
317
-		if (!empty($unread_in_labels))
318
-			$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
321
+		if (!empty($unread_in_labels)) {
322
+					$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
323
+		}
319 324
 	}
320 325
 
321 326
 	$pm_areas['folders']['areas']['inbox']['unread_messages'] = &$context['labels'][-1]['unread_messages'];
@@ -353,8 +358,9 @@  discard block
 block discarded – undo
353 358
 	unset($pm_areas);
354 359
 
355 360
 	// No menu means no access.
356
-	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession()))
357
-		fatal_lang_error('no_access', false);
361
+	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) {
362
+			fatal_lang_error('no_access', false);
363
+	}
358 364
 
359 365
 	// Make a note of the Unique ID for this menu.
360 366
 	$context['pm_menu_id'] = $context['max_menu_id'];
@@ -365,9 +371,10 @@  discard block
 block discarded – undo
365 371
 	$context['menu_item_selected'] = $current_area;
366 372
 
367 373
 	// Set the template for this area and add the profile layer.
368
-	if (!isset($_REQUEST['xml']))
369
-		$context['template_layers'][] = 'pm';
370
-}
374
+	if (!isset($_REQUEST['xml'])) {
375
+			$context['template_layers'][] = 'pm';
376
+	}
377
+	}
371 378
 
372 379
 /**
373 380
  * The popup for when we ask for the popup from the user.
@@ -399,8 +406,9 @@  discard block
 block discarded – undo
399 406
 		)
400 407
 	);
401 408
 	$pms = array();
402
-	while ($row = $smcFunc['db_fetch_row']($request))
403
-		$pms[] = $row[0];
409
+	while ($row = $smcFunc['db_fetch_row']($request)) {
410
+			$pms[] = $row[0];
411
+	}
404 412
 	$smcFunc['db_free_result']($request);
405 413
 
406 414
 	if (!empty($pms))
@@ -428,8 +436,9 @@  discard block
 block discarded – undo
428 436
 		);
429 437
 		while ($row = $smcFunc['db_fetch_assoc']($request))
430 438
 		{
431
-			if (!empty($row['id_member_from']))
432
-				$senders[] = $row['id_member_from'];
439
+			if (!empty($row['id_member_from'])) {
440
+							$senders[] = $row['id_member_from'];
441
+			}
433 442
 
434 443
 			$row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head'];
435 444
 			$row['time'] = timeformat($row['timestamp']);
@@ -439,13 +448,15 @@  discard block
 block discarded – undo
439 448
 		$smcFunc['db_free_result']($request);
440 449
 
441 450
 		$senders = loadMemberData($senders);
442
-		foreach ($senders as $member)
443
-			loadMemberContext($member);
451
+		foreach ($senders as $member) {
452
+					loadMemberContext($member);
453
+		}
444 454
 
445 455
 		// Having loaded everyone, attach them to the PMs.
446
-		foreach ($context['unread_pms'] as $id_pm => $details)
447
-			if (!empty($memberContext[$details['id_member_from']]))
456
+		foreach ($context['unread_pms'] as $id_pm => $details) {
457
+					if (!empty($memberContext[$details['id_member_from']]))
448 458
 				$context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']];
459
+		}
449 460
 	}
450 461
 }
451 462
 
@@ -465,12 +476,13 @@  discard block
 block discarded – undo
465 476
 	}
466 477
 
467 478
 	// Make sure the starting location is valid.
468
-	if (isset($_GET['start']) && $_GET['start'] != 'new')
469
-		$_GET['start'] = (int) $_GET['start'];
470
-	elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first']))
471
-		$_GET['start'] = 0;
472
-	else
473
-		$_GET['start'] = 'new';
479
+	if (isset($_GET['start']) && $_GET['start'] != 'new') {
480
+			$_GET['start'] = (int) $_GET['start'];
481
+	} elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) {
482
+			$_GET['start'] = 0;
483
+	} else {
484
+			$_GET['start'] = 'new';
485
+	}
474 486
 
475 487
 	// Set up some basic theme stuff.
476 488
 	$context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to';
@@ -487,8 +499,7 @@  discard block
 block discarded – undo
487 499
 	{
488 500
 		$labelQuery = '
489 501
 			AND pmr.in_inbox = 1';
490
-	}
491
-	elseif ($context['folder'] != 'sent')
502
+	} elseif ($context['folder'] != 'sent')
492 503
 	{
493 504
 		$labelJoin = '
494 505
 			INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)';
@@ -530,22 +541,24 @@  discard block
 block discarded – undo
530 541
 	$txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']);
531 542
 
532 543
 	// Now, build the link tree!
533
-	if ($context['current_label_id'] == -1)
534
-		$context['linktree'][] = array(
544
+	if ($context['current_label_id'] == -1) {
545
+			$context['linktree'][] = array(
535 546
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'],
536 547
 			'name' => $pmbox
537 548
 		);
549
+	}
538 550
 
539 551
 	// Build it further for a label.
540
-	if ($context['current_label_id'] != -1)
541
-		$context['linktree'][] = array(
552
+	if ($context['current_label_id'] != -1) {
553
+			$context['linktree'][] = array(
542 554
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'],
543 555
 			'name' => $txt['pm_current_label'] . ': ' . $context['current_label']
544 556
 		);
557
+	}
545 558
 
546 559
 	// Figure out how many messages there are.
547
-	if ($context['folder'] == 'sent')
548
-		$request = $smcFunc['db_query']('', '
560
+	if ($context['folder'] == 'sent') {
561
+			$request = $smcFunc['db_query']('', '
549 562
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
550 563
 			FROM {db_prefix}personal_messages AS pm
551 564
 			WHERE pm.id_member_from = {int:current_member}
@@ -555,8 +568,8 @@  discard block
 block discarded – undo
555 568
 				'not_deleted' => 0,
556 569
 			)
557 570
 		);
558
-	else
559
-		$request = $smcFunc['db_query']('', '
571
+	} else {
572
+			$request = $smcFunc['db_query']('', '
560 573
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
561 574
 			FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
562 575
 				INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -567,6 +580,7 @@  discard block
 block discarded – undo
567 580
 				'not_deleted' => 0,
568 581
 			)
569 582
 		);
583
+	}
570 584
 	list ($max_messages) = $smcFunc['db_fetch_row']($request);
571 585
 	$smcFunc['db_free_result']($request);
572 586
 
@@ -575,10 +589,11 @@  discard block
 block discarded – undo
575 589
 	$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
576 590
 
577 591
 	// Start on the last page.
578
-	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages)
579
-		$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
580
-	elseif ($_GET['start'] < 0)
581
-		$_GET['start'] = 0;
592
+	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) {
593
+			$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
594
+	} elseif ($_GET['start'] < 0) {
595
+			$_GET['start'] = 0;
596
+	}
582 597
 
583 598
 	// ... but wait - what if we want to start from a specific message?
584 599
 	if (isset($_GET['pmid']))
@@ -586,19 +601,21 @@  discard block
 block discarded – undo
586 601
 		$pmID = (int) $_GET['pmid'];
587 602
 
588 603
 		// Make sure you have access to this PM.
589
-		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
590
-			fatal_lang_error('no_access', false);
604
+		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
605
+					fatal_lang_error('no_access', false);
606
+		}
591 607
 
592 608
 		$context['current_pm'] = $pmID;
593 609
 
594 610
 		// With only one page of PM's we're gonna want page 1.
595
-		if ($max_messages <= $maxPerPage)
596
-			$_GET['start'] = 0;
611
+		if ($max_messages <= $maxPerPage) {
612
+					$_GET['start'] = 0;
613
+		}
597 614
 		// If we pass kstart we assume we're in the right place.
598 615
 		elseif (!isset($_GET['kstart']))
599 616
 		{
600
-			if ($context['folder'] == 'sent')
601
-				$request = $smcFunc['db_query']('', '
617
+			if ($context['folder'] == 'sent') {
618
+							$request = $smcFunc['db_query']('', '
602 619
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
603 620
 					FROM {db_prefix}personal_messages
604 621
 					WHERE id_member_from = {int:current_member}
@@ -610,8 +627,8 @@  discard block
 block discarded – undo
610 627
 						'id_pm' => $pmID,
611 628
 					)
612 629
 				);
613
-			else
614
-				$request = $smcFunc['db_query']('', '
630
+			} else {
631
+							$request = $smcFunc['db_query']('', '
615 632
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
616 633
 					FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
617 634
 						INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -624,6 +641,7 @@  discard block
 block discarded – undo
624 641
 						'id_pm' => $pmID,
625 642
 					)
626 643
 				);
644
+			}
627 645
 
628 646
 			list ($_GET['start']) = $smcFunc['db_fetch_row']($request);
629 647
 			$smcFunc['db_free_result']($request);
@@ -638,8 +656,9 @@  discard block
 block discarded – undo
638 656
 	{
639 657
 		$pmsg = (int) $_GET['pmsg'];
640 658
 
641
-		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
642
-			fatal_lang_error('no_access', false);
659
+		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
660
+					fatal_lang_error('no_access', false);
661
+		}
643 662
 	}
644 663
 
645 664
 	// Set up the page index.
@@ -734,8 +753,9 @@  discard block
 block discarded – undo
734 753
 	{
735 754
 		if (!isset($recipients[$row['id_pm']]))
736 755
 		{
737
-			if (isset($row['id_member_from']))
738
-				$posters[$row['id_pm']] = $row['id_member_from'];
756
+			if (isset($row['id_member_from'])) {
757
+							$posters[$row['id_pm']] = $row['id_member_from'];
758
+			}
739 759
 			$pms[$row['id_pm']] = $row['id_pm'];
740 760
 			$recipients[$row['id_pm']] = array(
741 761
 				'to' => array(),
@@ -744,29 +764,33 @@  discard block
 block discarded – undo
744 764
 		}
745 765
 
746 766
 		// Keep track of the last message so we know what the head is without another query!
747
-		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm']))
748
-			$lastData = array(
767
+		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) {
768
+					$lastData = array(
749 769
 				'id' => $row['id_pm'],
750 770
 				'head' => $row['id_pm_head'],
751 771
 			);
772
+		}
752 773
 	}
753 774
 	$smcFunc['db_free_result']($request);
754 775
 
755 776
 	// Make sure that we have been given a correct head pm id!
756
-	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id'])
757
-		fatal_lang_error('no_access', false);
777
+	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) {
778
+			fatal_lang_error('no_access', false);
779
+	}
758 780
 
759 781
 	if (!empty($pms))
760 782
 	{
761 783
 		// Select the correct current message.
762
-		if (empty($pmID))
763
-			$context['current_pm'] = $lastData['id'];
784
+		if (empty($pmID)) {
785
+					$context['current_pm'] = $lastData['id'];
786
+		}
764 787
 
765 788
 		// This is a list of the pm's that are used for "full" display.
766
-		if ($context['display_mode'] == 0)
767
-			$display_pms = $pms;
768
-		else
769
-			$display_pms = array($context['current_pm']);
789
+		if ($context['display_mode'] == 0) {
790
+					$display_pms = $pms;
791
+		} else {
792
+					$display_pms = array($context['current_pm']);
793
+		}
770 794
 
771 795
 		// At this point we know the main id_pm's. But - if we are looking at conversations we need the others!
772 796
 		if ($context['display_mode'] == 2)
@@ -788,16 +812,18 @@  discard block
 block discarded – undo
788 812
 			while ($row = $smcFunc['db_fetch_assoc']($request))
789 813
 			{
790 814
 				// This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn!
791
-				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1)
792
-					continue;
793
-				elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1)
794
-					continue;
815
+				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) {
816
+									continue;
817
+				} elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) {
818
+									continue;
819
+				}
795 820
 
796
-				if (!isset($recipients[$row['id_pm']]))
797
-					$recipients[$row['id_pm']] = array(
821
+				if (!isset($recipients[$row['id_pm']])) {
822
+									$recipients[$row['id_pm']] = array(
798 823
 						'to' => array(),
799 824
 						'bcc' => array()
800 825
 					);
826
+				}
801 827
 				$display_pms[] = $row['id_pm'];
802 828
 				$posters[$row['id_pm']] = $row['id_member_from'];
803 829
 			}
@@ -848,8 +874,9 @@  discard block
 block discarded – undo
848 874
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
849 875
 				{
850 876
 					$l_id = $row2['id_label'];
851
-					if (isset($context['labels'][$l_id]))
852
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
877
+					if (isset($context['labels'][$l_id])) {
878
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
879
+					}
853 880
 				}
854 881
 
855 882
 				$smcFunc['db_free_result']($request2);
@@ -866,9 +893,10 @@  discard block
 block discarded – undo
866 893
 		// Make sure we don't load unnecessary data.
867 894
 		if ($context['display_mode'] == 1)
868 895
 		{
869
-			foreach ($posters as $k => $v)
870
-				if (!in_array($k, $display_pms))
896
+			foreach ($posters as $k => $v) {
897
+							if (!in_array($k, $display_pms))
871 898
 					unset($posters[$k]);
899
+			}
872 900
 		}
873 901
 
874 902
 		// Load any users....
@@ -879,8 +907,9 @@  discard block
 block discarded – undo
879 907
 		{
880 908
 			// Get the order right.
881 909
 			$orderBy = array();
882
-			foreach (array_reverse($pms) as $pm)
883
-				$orderBy[] = 'pm.id_pm = ' . $pm;
910
+			foreach (array_reverse($pms) as $pm) {
911
+							$orderBy[] = 'pm.id_pm = ' . $pm;
912
+			}
884 913
 
885 914
 			// Seperate query for these bits!
886 915
 			$subjects_request = $smcFunc['db_query']('', '
@@ -926,9 +955,9 @@  discard block
 block discarded – undo
926 955
 			// Allow mods to add additional buttons here
927 956
 			call_integration_hook('integrate_conversation_buttons');
928 957
 		}
958
+	} else {
959
+			$messages_request = false;
929 960
 	}
930
-	else
931
-		$messages_request = false;
932 961
 
933 962
 	$context['can_send_pm'] = allowedTo('pm_send');
934 963
 	$context['can_send_email'] = allowedTo('moderate_forum');
@@ -939,11 +968,13 @@  discard block
 block discarded – undo
939 968
 	if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages']))
940 969
 	{
941 970
 		// If the display mode is "old sk00l" do them all...
942
-		if ($context['display_mode'] == 0)
943
-			markMessages(null, $context['current_label_id']);
971
+		if ($context['display_mode'] == 0) {
972
+					markMessages(null, $context['current_label_id']);
973
+		}
944 974
 		// Otherwise do just the current one!
945
-		elseif (!empty($context['current_pm']))
946
-			markMessages($display_pms, $context['current_label_id']);
975
+		elseif (!empty($context['current_pm'])) {
976
+					markMessages($display_pms, $context['current_label_id']);
977
+		}
947 978
 	}
948 979
 }
949 980
 
@@ -961,8 +992,9 @@  discard block
 block discarded – undo
961 992
 
962 993
 	// Count the current message number....
963 994
 	static $counter = null;
964
-	if ($counter === null || $reset)
965
-		$counter = $context['start'];
995
+	if ($counter === null || $reset) {
996
+			$counter = $context['start'];
997
+	}
966 998
 
967 999
 	static $temp_pm_selected = null;
968 1000
 	if ($temp_pm_selected === null)
@@ -1007,19 +1039,22 @@  discard block
 block discarded – undo
1007 1039
 	}
1008 1040
 
1009 1041
 	// Bail if it's false, ie. no messages.
1010
-	if ($messages_request == false)
1011
-		return false;
1042
+	if ($messages_request == false) {
1043
+			return false;
1044
+	}
1012 1045
 
1013 1046
 	// Reset the data?
1014
-	if ($reset == true)
1015
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1047
+	if ($reset == true) {
1048
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1049
+	}
1016 1050
 
1017 1051
 	// Get the next one... bail if anything goes wrong.
1018 1052
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1019 1053
 	if (!$message)
1020 1054
 	{
1021
-		if ($type != 'subject')
1022
-			$smcFunc['db_free_result']($messages_request);
1055
+		if ($type != 'subject') {
1056
+					$smcFunc['db_free_result']($messages_request);
1057
+		}
1023 1058
 
1024 1059
 		return false;
1025 1060
 	}
@@ -1039,8 +1074,7 @@  discard block
 block discarded – undo
1039 1074
 		$memberContext[$message['id_member_from']]['email'] = '';
1040 1075
 		$memberContext[$message['id_member_from']]['show_email'] = false;
1041 1076
 		$memberContext[$message['id_member_from']]['is_guest'] = true;
1042
-	}
1043
-	else
1077
+	} else
1044 1078
 	{
1045 1079
 		$memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']);
1046 1080
 		$memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id'])));
@@ -1081,12 +1115,13 @@  discard block
 block discarded – undo
1081 1115
 	$counter++;
1082 1116
 
1083 1117
 	// Any custom profile fields?
1084
-	if (!empty($memberContext[$message['id_member_from']]['custom_fields']))
1085
-		foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1118
+	if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) {
1119
+			foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1086 1120
 			switch ($custom['placement'])
1087 1121
 			{
1088 1122
 				case 1:
1089 1123
 					$output['custom_fields']['icons'][] = $custom;
1124
+	}
1090 1125
 					break;
1091 1126
 				case 2:
1092 1127
 					$output['custom_fields']['above_signature'][] = $custom;
@@ -1129,22 +1164,28 @@  discard block
 block discarded – undo
1129 1164
 			$context['search_params'][$k] = $v;
1130 1165
 		}
1131 1166
 	}
1132
-	if (isset($_REQUEST['search']))
1133
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1167
+	if (isset($_REQUEST['search'])) {
1168
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1169
+	}
1134 1170
 
1135
-	if (isset($context['search_params']['search']))
1136
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1137
-	if (isset($context['search_params']['userspec']))
1138
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1171
+	if (isset($context['search_params']['search'])) {
1172
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1173
+	}
1174
+	if (isset($context['search_params']['userspec'])) {
1175
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1176
+	}
1139 1177
 
1140
-	if (!empty($context['search_params']['searchtype']))
1141
-		$context['search_params']['searchtype'] = 2;
1178
+	if (!empty($context['search_params']['searchtype'])) {
1179
+			$context['search_params']['searchtype'] = 2;
1180
+	}
1142 1181
 
1143
-	if (!empty($context['search_params']['minage']))
1144
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1182
+	if (!empty($context['search_params']['minage'])) {
1183
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1184
+	}
1145 1185
 
1146
-	if (!empty($context['search_params']['maxage']))
1147
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1186
+	if (!empty($context['search_params']['maxage'])) {
1187
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1188
+	}
1148 1189
 
1149 1190
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
1150 1191
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
@@ -1171,8 +1212,9 @@  discard block
 block discarded – undo
1171 1212
 		$context['search_errors']['messages'] = array();
1172 1213
 		foreach ($context['search_errors'] as $search_error => $dummy)
1173 1214
 		{
1174
-			if ($search_error == 'messages')
1175
-				continue;
1215
+			if ($search_error == 'messages') {
1216
+							continue;
1217
+			}
1176 1218
 
1177 1219
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
1178 1220
 		}
@@ -1194,8 +1236,9 @@  discard block
 block discarded – undo
1194 1236
 	global $scripturl, $modSettings, $user_info, $context, $txt;
1195 1237
 	global $memberContext, $smcFunc;
1196 1238
 
1197
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
1198
-		fatal_lang_error('loadavg_search_disabled', false);
1239
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
1240
+			fatal_lang_error('loadavg_search_disabled', false);
1241
+	}
1199 1242
 
1200 1243
 	/**
1201 1244
 	 * @todo For the moment force the folder to the inbox.
@@ -1224,35 +1267,40 @@  discard block
 block discarded – undo
1224 1267
 	$context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1225 1268
 
1226 1269
 	// Store whether simple search was used (needed if the user wants to do another query).
1227
-	if (!isset($search_params['advanced']))
1228
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1270
+	if (!isset($search_params['advanced'])) {
1271
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1272
+	}
1229 1273
 
1230 1274
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
1231
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
1232
-		$search_params['searchtype'] = 2;
1275
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
1276
+			$search_params['searchtype'] = 2;
1277
+	}
1233 1278
 
1234 1279
 	// Minimum age of messages. Default to zero (don't set param in that case).
1235
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
1236
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1280
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
1281
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1282
+	}
1237 1283
 
1238 1284
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
1239
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999))
1240
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1285
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) {
1286
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1287
+	}
1241 1288
 
1242 1289
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
1243 1290
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
1244 1291
 
1245 1292
 	// Default the user name to a wildcard matching every user (*).
1246
-	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
1247
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1293
+	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
1294
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1295
+	}
1248 1296
 
1249 1297
 	// This will be full of all kinds of parameters!
1250 1298
 	$searchq_parameters = array();
1251 1299
 
1252 1300
 	// If there's no specific user, then don't mention it in the main query.
1253
-	if (empty($search_params['userspec']))
1254
-		$userQuery = '';
1255
-	else
1301
+	if (empty($search_params['userspec'])) {
1302
+			$userQuery = '';
1303
+	} else
1256 1304
 	{
1257 1305
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
1258 1306
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -1264,8 +1312,9 @@  discard block
 block discarded – undo
1264 1312
 		{
1265 1313
 			$possible_users[$k] = trim($possible_users[$k]);
1266 1314
 
1267
-			if (strlen($possible_users[$k]) == 0)
1268
-				unset($possible_users[$k]);
1315
+			if (strlen($possible_users[$k]) == 0) {
1316
+							unset($possible_users[$k]);
1317
+			}
1269 1318
 		}
1270 1319
 
1271 1320
 		if (!empty($possible_users))
@@ -1277,8 +1326,9 @@  discard block
 block discarded – undo
1277 1326
 			{
1278 1327
 				$where_params['name_' . $k] = $v;
1279 1328
 				$where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}';
1280
-				if (!isset($where_params['real_name']))
1281
-					$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1329
+				if (!isset($where_params['real_name'])) {
1330
+									$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1331
+				}
1282 1332
 			}
1283 1333
 
1284 1334
 			// Who matches those criteria?
@@ -1291,28 +1341,28 @@  discard block
 block discarded – undo
1291 1341
 			);
1292 1342
 
1293 1343
 			// Simply do nothing if there're too many members matching the criteria.
1294
-			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
1295
-				$userQuery = '';
1296
-			elseif ($smcFunc['db_num_rows']($request) == 0)
1344
+			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
1345
+							$userQuery = '';
1346
+			} elseif ($smcFunc['db_num_rows']($request) == 0)
1297 1347
 			{
1298 1348
 				$userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})';
1299 1349
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1300 1350
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1301
-			}
1302
-			else
1351
+			} else
1303 1352
 			{
1304 1353
 				$memberlist = array();
1305
-				while ($row = $smcFunc['db_fetch_assoc']($request))
1306
-					$memberlist[] = $row['id_member'];
1354
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
1355
+									$memberlist[] = $row['id_member'];
1356
+				}
1307 1357
 				$userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))';
1308 1358
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1309 1359
 				$searchq_parameters['member_list'] = $memberlist;
1310 1360
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1311 1361
 			}
1312 1362
 			$smcFunc['db_free_result']($request);
1363
+		} else {
1364
+					$userQuery = '';
1313 1365
 		}
1314
-		else
1315
-			$userQuery = '';
1316 1366
 	}
1317 1367
 
1318 1368
 	// Setup the sorting variables...
@@ -1320,8 +1370,9 @@  discard block
 block discarded – undo
1320 1370
 	$sort_columns = array(
1321 1371
 		'pm.id_pm',
1322 1372
 	);
1323
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
1324
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1373
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
1374
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1375
+	}
1325 1376
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';
1326 1377
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
1327 1378
 
@@ -1331,24 +1382,27 @@  discard block
 block discarded – undo
1331 1382
 	if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels'])
1332 1383
 	{
1333 1384
 		// Came here from pagination?  Put them back into $_REQUEST for sanitization.
1334
-		if (isset($search_params['labels']))
1335
-			$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1385
+		if (isset($search_params['labels'])) {
1386
+					$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1387
+		}
1336 1388
 
1337 1389
 		// Assuming we have some labels - make them all integers.
1338 1390
 		if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel']))
1339 1391
 		{
1340
-			foreach ($_REQUEST['searchlabel'] as $key => $id)
1341
-				$_REQUEST['searchlabel'][$key] = (int) $id;
1392
+			foreach ($_REQUEST['searchlabel'] as $key => $id) {
1393
+							$_REQUEST['searchlabel'][$key] = (int) $id;
1394
+			}
1395
+		} else {
1396
+					$_REQUEST['searchlabel'] = array();
1342 1397
 		}
1343
-		else
1344
-			$_REQUEST['searchlabel'] = array();
1345 1398
 
1346 1399
 		// Now that everything is cleaned up a bit, make the labels a param.
1347 1400
 		$search_params['labels'] = implode(',', $_REQUEST['searchlabel']);
1348 1401
 
1349 1402
 		// No labels selected? That must be an error!
1350
-		if (empty($_REQUEST['searchlabel']))
1351
-			$context['search_errors']['no_labels_selected'] = true;
1403
+		if (empty($_REQUEST['searchlabel'])) {
1404
+					$context['search_errors']['no_labels_selected'] = true;
1405
+		}
1352 1406
 		// Otherwise prepare the query!
1353 1407
 		elseif (count($_REQUEST['searchlabel']) != count($context['labels']))
1354 1408
 		{
@@ -1371,8 +1425,7 @@  discard block
 block discarded – undo
1371 1425
 					// Not searching the inbox - PM must be labeled
1372 1426
 					$labelQuery = ' AND pml.id_label IN ({array_int:labels})';
1373 1427
 					$labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)';
1374
-				}
1375
-				else
1428
+				} else
1376 1429
 				{
1377 1430
 					// Searching the inbox - PM doesn't have to be labeled
1378 1431
 					$labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))';
@@ -1387,8 +1440,9 @@  discard block
 block discarded – undo
1387 1440
 	// What are we actually searching for?
1388 1441
 	$search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');
1389 1442
 	// If we ain't got nothing - we should error!
1390
-	if (!isset($search_params['search']) || $search_params['search'] == '')
1391
-		$context['search_errors']['invalid_search_string'] = true;
1443
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
1444
+			$context['search_errors']['invalid_search_string'] = true;
1445
+	}
1392 1446
 
1393 1447
 	// Extract phrase parts first (e.g. some words "this is a phrase" some more words.)
1394 1448
 	preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER);
@@ -1401,12 +1455,14 @@  discard block
 block discarded – undo
1401 1455
 	$excludedWords = array();
1402 1456
 
1403 1457
 	// .. first, we check for things like -"some words", but not "-some words".
1404
-	foreach ($matches[1] as $index => $word)
1405
-		if ($word == '-')
1458
+	foreach ($matches[1] as $index => $word) {
1459
+			if ($word == '-')
1406 1460
 		{
1407 1461
 			$word = $smcFunc['strtolower'](trim($searchArray[$index]));
1408
-			if (strlen($word) > 0)
1409
-				$excludedWords[] = $word;
1462
+	}
1463
+			if (strlen($word) > 0) {
1464
+							$excludedWords[] = $word;
1465
+			}
1410 1466
 			unset($searchArray[$index]);
1411 1467
 		}
1412 1468
 
@@ -1416,8 +1472,9 @@  discard block
 block discarded – undo
1416 1472
 		if (strpos(trim($word), '-') === 0)
1417 1473
 		{
1418 1474
 			$word = substr($smcFunc['strtolower']($word), 1);
1419
-			if (strlen($word) > 0)
1420
-				$excludedWords[] = $word;
1475
+			if (strlen($word) > 0) {
1476
+							$excludedWords[] = $word;
1477
+			}
1421 1478
 			unset($tempSearch[$index]);
1422 1479
 		}
1423 1480
 	}
@@ -1428,9 +1485,9 @@  discard block
 block discarded – undo
1428 1485
 	foreach ($searchArray as $index => $value)
1429 1486
 	{
1430 1487
 		$searchArray[$index] = $smcFunc['strtolower'](trim($value));
1431
-		if ($searchArray[$index] == '')
1432
-			unset($searchArray[$index]);
1433
-		else
1488
+		if ($searchArray[$index] == '') {
1489
+					unset($searchArray[$index]);
1490
+		} else
1434 1491
 		{
1435 1492
 			// Sort out entities first.
1436 1493
 			$searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]);
@@ -1440,27 +1497,32 @@  discard block
 block discarded – undo
1440 1497
 
1441 1498
 	// Create an array of replacements for highlighting.
1442 1499
 	$context['mark'] = array();
1443
-	foreach ($searchArray as $word)
1444
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1500
+	foreach ($searchArray as $word) {
1501
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1502
+	}
1445 1503
 
1446 1504
 	// This contains *everything*
1447 1505
 	$searchWords = array_merge($searchArray, $excludedWords);
1448 1506
 
1449 1507
 	// Make sure at least one word is being searched for.
1450
-	if (empty($searchArray))
1451
-		$context['search_errors']['invalid_search_string'] = true;
1508
+	if (empty($searchArray)) {
1509
+			$context['search_errors']['invalid_search_string'] = true;
1510
+	}
1452 1511
 
1453 1512
 	// Sort out the search query so the user can edit it - if they want.
1454 1513
 	$context['search_params'] = $search_params;
1455
-	if (isset($context['search_params']['search']))
1456
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1457
-	if (isset($context['search_params']['userspec']))
1458
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1514
+	if (isset($context['search_params']['search'])) {
1515
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1516
+	}
1517
+	if (isset($context['search_params']['userspec'])) {
1518
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1519
+	}
1459 1520
 
1460 1521
 	// Now we have all the parameters, combine them together for pagination and the like...
1461 1522
 	$context['params'] = array();
1462
-	foreach ($search_params as $k => $v)
1463
-		$context['params'][] = $k . '|\'|' . $v;
1523
+	foreach ($search_params as $k => $v) {
1524
+			$context['params'][] = $k . '|\'|' . $v;
1525
+	}
1464 1526
 	$context['params'] = base64_encode(implode('|"|', $context['params']));
1465 1527
 
1466 1528
 	// Compile the subject query part.
@@ -1468,26 +1530,31 @@  discard block
 block discarded – undo
1468 1530
 
1469 1531
 	foreach ($searchWords as $index => $word)
1470 1532
 	{
1471
-		if ($word == '')
1472
-			continue;
1533
+		if ($word == '') {
1534
+					continue;
1535
+		}
1473 1536
 
1474
-		if ($search_params['subject_only'])
1475
-			$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1476
-		else
1477
-			$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1537
+		if ($search_params['subject_only']) {
1538
+					$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1539
+		} else {
1540
+					$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1541
+		}
1478 1542
 		$searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%';
1479 1543
 	}
1480 1544
 
1481 1545
 	$searchQuery = ' 1=1';
1482
-	if (!empty($andQueryParts))
1483
-		$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1546
+	if (!empty($andQueryParts)) {
1547
+			$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1548
+	}
1484 1549
 
1485 1550
 	// Age limits?
1486 1551
 	$timeQuery = '';
1487
-	if (!empty($search_params['minage']))
1488
-		$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1489
-	if (!empty($search_params['maxage']))
1490
-		$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1552
+	if (!empty($search_params['minage'])) {
1553
+			$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1554
+	}
1555
+	if (!empty($search_params['maxage'])) {
1556
+			$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1557
+	}
1491 1558
 
1492 1559
 	// If we have errors - return back to the first screen...
1493 1560
 	if (!empty($context['search_errors']))
@@ -1573,8 +1640,9 @@  discard block
 block discarded – undo
1573 1640
 			)
1574 1641
 		);
1575 1642
 		$real_pm_ids = array();
1576
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1577
-			$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1643
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1644
+					$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1645
+		}
1578 1646
 		$smcFunc['db_free_result']($request);
1579 1647
 	}
1580 1648
 
@@ -1604,8 +1672,9 @@  discard block
 block discarded – undo
1604 1672
 		);
1605 1673
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1606 1674
 		{
1607
-			if ($context['folder'] == 'sent' || empty($row['bcc']))
1608
-				$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1675
+			if ($context['folder'] == 'sent' || empty($row['bcc'])) {
1676
+							$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1677
+			}
1609 1678
 
1610 1679
 			if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
1611 1680
 			{
@@ -1626,12 +1695,14 @@  discard block
 block discarded – undo
1626 1695
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
1627 1696
 				{
1628 1697
 					$l_id = $row2['id_label'];
1629
-					if (isset($context['labels'][$l_id]))
1630
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1698
+					if (isset($context['labels'][$l_id])) {
1699
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1700
+					}
1631 1701
 
1632 1702
 					// Here we find the first label on a message - for linking to posts in results
1633
-					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1)
1634
-						$context['first_label'][$row['id_pm']] = $l_id;
1703
+					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) {
1704
+											$context['first_label'][$row['id_pm']] = $l_id;
1705
+					}
1635 1706
 				}
1636 1707
 
1637 1708
 				$smcFunc['db_free_result']($request2);
@@ -1758,8 +1829,9 @@  discard block
 block discarded – undo
1758 1829
 		list ($postCount) = $smcFunc['db_fetch_row']($request);
1759 1830
 		$smcFunc['db_free_result']($request);
1760 1831
 
1761
-		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
1762
-			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1832
+		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) {
1833
+					fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1834
+		}
1763 1835
 	}
1764 1836
 
1765 1837
 	// Quoting/Replying to a message?
@@ -1768,8 +1840,9 @@  discard block
 block discarded – undo
1768 1840
 		$pmsg = (int) $_REQUEST['pmsg'];
1769 1841
 
1770 1842
 		// Make sure this is yours.
1771
-		if (!isAccessiblePM($pmsg))
1772
-			fatal_lang_error('no_access', false);
1843
+		if (!isAccessiblePM($pmsg)) {
1844
+					fatal_lang_error('no_access', false);
1845
+		}
1773 1846
 
1774 1847
 		// Work out whether this is one you've received?
1775 1848
 		$request = $smcFunc['db_query']('', '
@@ -1806,8 +1879,9 @@  discard block
 block discarded – undo
1806 1879
 				'id_pm' => $pmsg,
1807 1880
 			)
1808 1881
 		);
1809
-		if ($smcFunc['db_num_rows']($request) == 0)
1810
-			fatal_lang_error('pm_not_yours', false);
1882
+		if ($smcFunc['db_num_rows']($request) == 0) {
1883
+					fatal_lang_error('pm_not_yours', false);
1884
+		}
1811 1885
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
1812 1886
 		$smcFunc['db_free_result']($request);
1813 1887
 
@@ -1818,9 +1892,9 @@  discard block
 block discarded – undo
1818 1892
 		// Add 'Re: ' to it....
1819 1893
 		if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
1820 1894
 		{
1821
-			if ($language === $user_info['language'])
1822
-				$context['response_prefix'] = $txt['response_prefix'];
1823
-			else
1895
+			if ($language === $user_info['language']) {
1896
+							$context['response_prefix'] = $txt['response_prefix'];
1897
+			} else
1824 1898
 			{
1825 1899
 				loadLanguage('index', $language, false);
1826 1900
 				$context['response_prefix'] = $txt['response_prefix'];
@@ -1829,22 +1903,25 @@  discard block
 block discarded – undo
1829 1903
 			cache_put_data('response_prefix', $context['response_prefix'], 600);
1830 1904
 		}
1831 1905
 		$form_subject = $row_quoted['subject'];
1832
-		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
1833
-			$form_subject = $context['response_prefix'] . $form_subject;
1906
+		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
1907
+					$form_subject = $context['response_prefix'] . $form_subject;
1908
+		}
1834 1909
 
1835 1910
 		if (isset($_REQUEST['quote']))
1836 1911
 		{
1837 1912
 			// Remove any nested quotes and <br>...
1838 1913
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']);
1839
-			if (!empty($modSettings['removeNestedQuotes']))
1840
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1841
-			if (empty($row_quoted['id_member']))
1842
-				$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1843
-			else
1844
-				$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1914
+			if (!empty($modSettings['removeNestedQuotes'])) {
1915
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1916
+			}
1917
+			if (empty($row_quoted['id_member'])) {
1918
+							$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1919
+			} else {
1920
+							$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1921
+			}
1922
+		} else {
1923
+					$form_message = '';
1845 1924
 		}
1846
-		else
1847
-			$form_message = '';
1848 1925
 
1849 1926
 		// Do the BBC thang on the message.
1850 1927
 		$row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);
@@ -1865,8 +1942,7 @@  discard block
 block discarded – undo
1865 1942
 			'timestamp' => forum_time(true, $row_quoted['msgtime']),
1866 1943
 			'body' => $row_quoted['body']
1867 1944
 		);
1868
-	}
1869
-	else
1945
+	} else
1870 1946
 	{
1871 1947
 		$context['quoted_message'] = false;
1872 1948
 		$form_subject = '';
@@ -1885,11 +1961,12 @@  discard block
 block discarded – undo
1885 1961
 		if ($_REQUEST['u'] == 'all' && isset($row_quoted))
1886 1962
 		{
1887 1963
 			// Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.
1888
-			if ($row_quoted['id_member'] != $user_info['id'])
1889
-				$context['recipients']['to'][] = array(
1964
+			if ($row_quoted['id_member'] != $user_info['id']) {
1965
+							$context['recipients']['to'][] = array(
1890 1966
 					'id' => $row_quoted['id_member'],
1891 1967
 					'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']),
1892 1968
 				);
1969
+			}
1893 1970
 
1894 1971
 			// Now to get the others.
1895 1972
 			$request = $smcFunc['db_query']('', '
@@ -1905,18 +1982,19 @@  discard block
 block discarded – undo
1905 1982
 					'not_bcc' => 0,
1906 1983
 				)
1907 1984
 			);
1908
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1909
-				$context['recipients']['to'][] = array(
1985
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1986
+							$context['recipients']['to'][] = array(
1910 1987
 					'id' => $row['id_member'],
1911 1988
 					'name' => $row['real_name'],
1912 1989
 				);
1990
+			}
1913 1991
 			$smcFunc['db_free_result']($request);
1914
-		}
1915
-		else
1992
+		} else
1916 1993
 		{
1917 1994
 			$_REQUEST['u'] = explode(',', $_REQUEST['u']);
1918
-			foreach ($_REQUEST['u'] as $key => $uID)
1919
-				$_REQUEST['u'][$key] = (int) $uID;
1995
+			foreach ($_REQUEST['u'] as $key => $uID) {
1996
+							$_REQUEST['u'][$key] = (int) $uID;
1997
+			}
1920 1998
 
1921 1999
 			$_REQUEST['u'] = array_unique($_REQUEST['u']);
1922 2000
 
@@ -1930,22 +2008,24 @@  discard block
 block discarded – undo
1930 2008
 					'limit' => count($_REQUEST['u']),
1931 2009
 				)
1932 2010
 			);
1933
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1934
-				$context['recipients']['to'][] = array(
2011
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2012
+							$context['recipients']['to'][] = array(
1935 2013
 					'id' => $row['id_member'],
1936 2014
 					'name' => $row['real_name'],
1937 2015
 				);
2016
+			}
1938 2017
 			$smcFunc['db_free_result']($request);
1939 2018
 		}
1940 2019
 
1941 2020
 		// Get a literal name list in case the user has JavaScript disabled.
1942 2021
 		$names = array();
1943
-		foreach ($context['recipients']['to'] as $to)
1944
-			$names[] = $to['name'];
2022
+		foreach ($context['recipients']['to'] as $to) {
2023
+					$names[] = $to['name'];
2024
+		}
1945 2025
 		$context['to_value'] = empty($names) ? '' : '&quot;' . implode('&quot;, &quot;', $names) . '&quot;';
2026
+	} else {
2027
+			$context['to_value'] = '';
1946 2028
 	}
1947
-	else
1948
-		$context['to_value'] = '';
1949 2029
 
1950 2030
 	// Set the defaults...
1951 2031
 	$context['subject'] = $form_subject;
@@ -2015,8 +2095,9 @@  discard block
 block discarded – undo
2015 2095
 
2016 2096
 	// validate with loadMemberData()
2017 2097
 	$memberResult = loadMemberData($user_info['id'], false);
2018
-	if (!$memberResult)
2019
-		fatal_lang_error('not_a_user', false);
2098
+	if (!$memberResult) {
2099
+			fatal_lang_error('not_a_user', false);
2100
+	}
2020 2101
 	list ($memID) = $memberResult;
2021 2102
 
2022 2103
 	// drafts is where the functions reside
@@ -2042,9 +2123,9 @@  discard block
 block discarded – undo
2042 2123
 		$context['sub_template'] = 'send';
2043 2124
 		loadJavaScriptFile('PersonalMessage.js', array('defer' => false), 'smf_pms');
2044 2125
 		loadJavaScriptFile('suggest.js', array('defer' => false), 'smf_suggest');
2126
+	} else {
2127
+			$context['sub_template'] = 'pm';
2045 2128
 	}
2046
-	else
2047
-		$context['sub_template'] = 'pm';
2048 2129
 
2049 2130
 	$context['page_title'] = $txt['send_message'];
2050 2131
 
@@ -2105,10 +2186,11 @@  discard block
 block discarded – undo
2105 2186
 		);
2106 2187
 		if ($smcFunc['db_num_rows']($request) == 0)
2107 2188
 		{
2108
-			if (!isset($_REQUEST['xml']))
2109
-				fatal_lang_error('pm_not_yours', false);
2110
-			else
2111
-				$error_types[] = 'pm_not_yours';
2189
+			if (!isset($_REQUEST['xml'])) {
2190
+							fatal_lang_error('pm_not_yours', false);
2191
+			} else {
2192
+							$error_types[] = 'pm_not_yours';
2193
+			}
2112 2194
 		}
2113 2195
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
2114 2196
 		$smcFunc['db_free_result']($request);
@@ -2155,14 +2237,16 @@  discard block
 block discarded – undo
2155 2237
 		$context['post_error'][$error_type] = true;
2156 2238
 		if (isset($txt['error_' . $error_type]))
2157 2239
 		{
2158
-			if ($error_type == 'long_message')
2159
-				$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2240
+			if ($error_type == 'long_message') {
2241
+							$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2242
+			}
2160 2243
 			$context['post_error']['messages'][] = $txt['error_' . $error_type];
2161 2244
 		}
2162 2245
 
2163 2246
 		// If it's not a minor error flag it as such.
2164
-		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject')))
2165
-			$context['error_type'] = 'serious';
2247
+		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) {
2248
+					$context['error_type'] = 'serious';
2249
+		}
2166 2250
 	}
2167 2251
 
2168 2252
 	// We need to load the editor once more.
@@ -2220,8 +2304,9 @@  discard block
 block discarded – undo
2220 2304
 	require_once($sourcedir . '/Subs-Auth.php');
2221 2305
 
2222 2306
 	// PM Drafts enabled and needed?
2223
-	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft'])))
2224
-		require_once($sourcedir . '/Drafts.php');
2307
+	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) {
2308
+			require_once($sourcedir . '/Drafts.php');
2309
+	}
2225 2310
 
2226 2311
 	loadLanguage('PersonalMessage', '', false);
2227 2312
 
@@ -2251,24 +2336,27 @@  discard block
 block discarded – undo
2251 2336
 
2252 2337
 		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
2253 2338
 		{
2254
-			if (!isset($_REQUEST['xml']))
2255
-				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2256
-			else
2257
-				$post_errors[] = 'pm_too_many_per_hour';
2339
+			if (!isset($_REQUEST['xml'])) {
2340
+							fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2341
+			} else {
2342
+							$post_errors[] = 'pm_too_many_per_hour';
2343
+			}
2258 2344
 		}
2259 2345
 	}
2260 2346
 
2261 2347
 	// If your session timed out, show an error, but do allow to re-submit.
2262
-	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '')
2263
-		$post_errors[] = 'session_timeout';
2348
+	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') {
2349
+			$post_errors[] = 'session_timeout';
2350
+	}
2264 2351
 
2265 2352
 	$_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
2266 2353
 	$_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];
2267 2354
 	$_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];
2268 2355
 
2269 2356
 	// Route the input from the 'u' parameter to the 'to'-list.
2270
-	if (!empty($_POST['u']))
2271
-		$_POST['recipient_to'] = explode(',', $_POST['u']);
2357
+	if (!empty($_POST['u'])) {
2358
+			$_POST['recipient_to'] = explode(',', $_POST['u']);
2359
+	}
2272 2360
 
2273 2361
 	// Construct the list of recipients.
2274 2362
 	$recipientList = array();
@@ -2280,8 +2368,9 @@  discard block
 block discarded – undo
2280 2368
 		$recipientList[$recipientType] = array();
2281 2369
 		if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))
2282 2370
 		{
2283
-			foreach ($_POST['recipient_' . $recipientType] as $recipient)
2284
-				$recipientList[$recipientType][] = (int) $recipient;
2371
+			foreach ($_POST['recipient_' . $recipientType] as $recipient) {
2372
+							$recipientList[$recipientType][] = (int) $recipient;
2373
+			}
2285 2374
 		}
2286 2375
 
2287 2376
 		// Are there also literal names set?
@@ -2295,10 +2384,11 @@  discard block
 block discarded – undo
2295 2384
 
2296 2385
 			foreach ($namedRecipientList[$recipientType] as $index => $recipient)
2297 2386
 			{
2298
-				if (strlen(trim($recipient)) > 0)
2299
-					$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2300
-				else
2301
-					unset($namedRecipientList[$recipientType][$index]);
2387
+				if (strlen(trim($recipient)) > 0) {
2388
+									$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2389
+				} else {
2390
+									unset($namedRecipientList[$recipientType][$index]);
2391
+				}
2302 2392
 			}
2303 2393
 
2304 2394
 			if (!empty($namedRecipientList[$recipientType]))
@@ -2328,8 +2418,9 @@  discard block
 block discarded – undo
2328 2418
 		}
2329 2419
 
2330 2420
 		// Selected a recipient to be deleted? Remove them now.
2331
-		if (!empty($_POST['delete_recipient']))
2332
-			$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2421
+		if (!empty($_POST['delete_recipient'])) {
2422
+					$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2423
+		}
2333 2424
 
2334 2425
 		// Make sure we don't include the same name twice
2335 2426
 		$recipientList[$recipientType] = array_unique($recipientList[$recipientType]);
@@ -2339,8 +2430,9 @@  discard block
 block discarded – undo
2339 2430
 	$is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']);
2340 2431
 
2341 2432
 	// Check if there's at least one recipient.
2342
-	if (empty($recipientList['to']) && empty($recipientList['bcc']))
2343
-		$post_errors[] = 'no_to';
2433
+	if (empty($recipientList['to']) && empty($recipientList['bcc'])) {
2434
+			$post_errors[] = 'no_to';
2435
+	}
2344 2436
 
2345 2437
 	// Make sure that we remove the members who did get it from the screen.
2346 2438
 	if (!$is_recipient_change)
@@ -2354,28 +2446,31 @@  discard block
 block discarded – undo
2354 2446
 				// Since we already have a post error, remove the previous one.
2355 2447
 				$post_errors = array_diff($post_errors, array('no_to'));
2356 2448
 
2357
-				foreach ($namesNotFound[$recipientType] as $name)
2358
-					$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2449
+				foreach ($namesNotFound[$recipientType] as $name) {
2450
+									$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2451
+				}
2359 2452
 			}
2360 2453
 		}
2361 2454
 	}
2362 2455
 
2363 2456
 	// Did they make any mistakes?
2364
-	if ($_REQUEST['subject'] == '')
2365
-		$post_errors[] = 'no_subject';
2366
-	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '')
2367
-		$post_errors[] = 'no_message';
2368
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength'])
2369
-		$post_errors[] = 'long_message';
2370
-	else
2457
+	if ($_REQUEST['subject'] == '') {
2458
+			$post_errors[] = 'no_subject';
2459
+	}
2460
+	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
2461
+			$post_errors[] = 'no_message';
2462
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) {
2463
+			$post_errors[] = 'long_message';
2464
+	} else
2371 2465
 	{
2372 2466
 		// Preparse the message.
2373 2467
 		$message = $_REQUEST['message'];
2374 2468
 		preparsecode($message);
2375 2469
 
2376 2470
 		// Make sure there's still some content left without the tags.
2377
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false))
2378
-			$post_errors[] = 'no_message';
2471
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) {
2472
+					$post_errors[] = 'no_message';
2473
+		}
2379 2474
 	}
2380 2475
 
2381 2476
 	// Wrong verification code?
@@ -2387,13 +2482,15 @@  discard block
 block discarded – undo
2387 2482
 		);
2388 2483
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
2389 2484
 
2390
-		if (is_array($context['require_verification']))
2391
-			$post_errors = array_merge($post_errors, $context['require_verification']);
2485
+		if (is_array($context['require_verification'])) {
2486
+					$post_errors = array_merge($post_errors, $context['require_verification']);
2487
+		}
2392 2488
 	}
2393 2489
 
2394 2490
 	// If they did, give a chance to make ammends.
2395
-	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml']))
2396
-		return messagePostError($post_errors, $namedRecipientList, $recipientList);
2491
+	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) {
2492
+			return messagePostError($post_errors, $namedRecipientList, $recipientList);
2493
+	}
2397 2494
 
2398 2495
 	// Want to take a second glance before you send?
2399 2496
 	if (isset($_REQUEST['preview']))
@@ -2424,8 +2521,9 @@  discard block
 block discarded – undo
2424 2521
 		foreach ($namesNotFound as $recipientType => $names)
2425 2522
 		{
2426 2523
 			$post_errors[] = 'bad_' . $recipientType;
2427
-			foreach ($names as $name)
2428
-				$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2524
+			foreach ($names as $name) {
2525
+							$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2526
+			}
2429 2527
 		}
2430 2528
 
2431 2529
 		return messagePostError(array(), $namedRecipientList, $recipientList);
@@ -2455,13 +2553,14 @@  discard block
 block discarded – undo
2455 2553
 	checkSubmitOnce('check');
2456 2554
 
2457 2555
 	// Do the actual sending of the PM.
2458
-	if (!empty($recipientList['to']) || !empty($recipientList['bcc']))
2459
-		$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2460
-	else
2461
-		$context['send_log'] = array(
2556
+	if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) {
2557
+			$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2558
+	} else {
2559
+			$context['send_log'] = array(
2462 2560
 			'sent' => array(),
2463 2561
 			'failed' => array()
2464 2562
 		);
2563
+	}
2465 2564
 
2466 2565
 	// Mark the message as "replied to".
2467 2566
 	if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox')
@@ -2479,11 +2578,12 @@  discard block
 block discarded – undo
2479 2578
 	}
2480 2579
 
2481 2580
 	// If one or more of the recipient were invalid, go back to the post screen with the failed usernames.
2482
-	if (!empty($context['send_log']['failed']))
2483
-		return messagePostError($post_errors, $namesNotFound, array(
2581
+	if (!empty($context['send_log']['failed'])) {
2582
+			return messagePostError($post_errors, $namesNotFound, array(
2484 2583
 			'to' => array_intersect($recipientList['to'], $context['send_log']['failed']),
2485 2584
 			'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed'])
2486 2585
 		));
2586
+	}
2487 2587
 
2488 2588
 	// Message sent successfully?
2489 2589
 	if (!empty($context['send_log']) && empty($context['send_log']['failed']))
@@ -2491,8 +2591,9 @@  discard block
 block discarded – undo
2491 2591
 		$context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent';
2492 2592
 
2493 2593
 		// If we had a PM draft for this one, then its time to remove it since it was just sent
2494
-		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft']))
2495
-			DeleteDraft($_POST['id_pm_draft']);
2594
+		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) {
2595
+					DeleteDraft($_POST['id_pm_draft']);
2596
+		}
2496 2597
 	}
2497 2598
 
2498 2599
 	// Go back to the where they sent from, if possible...
@@ -2507,24 +2608,28 @@  discard block
 block discarded – undo
2507 2608
 
2508 2609
 	checkSession('request');
2509 2610
 
2510
-	if (isset($_REQUEST['del_selected']))
2511
-		$_REQUEST['pm_action'] = 'delete';
2611
+	if (isset($_REQUEST['del_selected'])) {
2612
+			$_REQUEST['pm_action'] = 'delete';
2613
+	}
2512 2614
 
2513 2615
 	if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms']))
2514 2616
 	{
2515
-		foreach ($_REQUEST['pms'] as $pm)
2516
-			$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2617
+		foreach ($_REQUEST['pms'] as $pm) {
2618
+					$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2619
+		}
2517 2620
 	}
2518 2621
 
2519
-	if (empty($_REQUEST['pm_actions']))
2520
-		redirectexit($context['current_label_redirect']);
2622
+	if (empty($_REQUEST['pm_actions'])) {
2623
+			redirectexit($context['current_label_redirect']);
2624
+	}
2521 2625
 
2522 2626
 	// If we are in conversation, we may need to apply this to every message in the conversation.
2523 2627
 	if ($context['display_mode'] == 2 && isset($_REQUEST['conversation']))
2524 2628
 	{
2525 2629
 		$id_pms = array();
2526
-		foreach ($_REQUEST['pm_actions'] as $pm => $dummy)
2527
-			$id_pms[] = (int) $pm;
2630
+		foreach ($_REQUEST['pm_actions'] as $pm => $dummy) {
2631
+					$id_pms[] = (int) $pm;
2632
+		}
2528 2633
 
2529 2634
 		$request = $smcFunc['db_query']('', '
2530 2635
 			SELECT id_pm_head, id_pm
@@ -2535,8 +2640,9 @@  discard block
 block discarded – undo
2535 2640
 			)
2536 2641
 		);
2537 2642
 		$pm_heads = array();
2538
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2539
-			$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2643
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2644
+					$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2645
+		}
2540 2646
 		$smcFunc['db_free_result']($request);
2541 2647
 
2542 2648
 		$request = $smcFunc['db_query']('', '
@@ -2550,8 +2656,9 @@  discard block
 block discarded – undo
2550 2656
 		// Copy the action from the single to PM to the others.
2551 2657
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2552 2658
 		{
2553
-			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]))
2554
-				$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2659
+			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) {
2660
+							$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2661
+			}
2555 2662
 		}
2556 2663
 		$smcFunc['db_free_result']($request);
2557 2664
 	}
@@ -2562,22 +2669,21 @@  discard block
 block discarded – undo
2562 2669
 	$labels = array();
2563 2670
 	foreach ($_REQUEST['pm_actions'] as $pm => $action)
2564 2671
 	{
2565
-		if ($action === 'delete')
2566
-			$to_delete[] = (int) $pm;
2567
-		else
2672
+		if ($action === 'delete') {
2673
+					$to_delete[] = (int) $pm;
2674
+		} else
2568 2675
 		{
2569 2676
 			if (substr($action, 0, 4) == 'add_')
2570 2677
 			{
2571 2678
 				$type = 'add';
2572 2679
 				$action = substr($action, 4);
2573
-			}
2574
-			elseif (substr($action, 0, 4) == 'rem_')
2680
+			} elseif (substr($action, 0, 4) == 'rem_')
2575 2681
 			{
2576 2682
 				$type = 'rem';
2577 2683
 				$action = substr($action, 4);
2684
+			} else {
2685
+							$type = 'unk';
2578 2686
 			}
2579
-			else
2580
-				$type = 'unk';
2581 2687
 
2582 2688
 			if ($action == '-1' || (int) $action > 0)
2583 2689
 			{
@@ -2588,8 +2694,9 @@  discard block
 block discarded – undo
2588 2694
 	}
2589 2695
 
2590 2696
 	// Deleting, it looks like?
2591
-	if (!empty($to_delete))
2592
-		deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2697
+	if (!empty($to_delete)) {
2698
+			deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2699
+	}
2593 2700
 
2594 2701
 	// Are we labeling anything?
2595 2702
 	if (!empty($to_label) && $context['folder'] == 'inbox')
@@ -2655,8 +2762,7 @@  discard block
 block discarded – undo
2655 2762
 				}
2656 2763
 
2657 2764
 				$smcFunc['db_free_result']($request2);
2658
-			}
2659
-			elseif ($type == 'rem')
2765
+			} elseif ($type == 'rem')
2660 2766
 			{
2661 2767
 				// If we're removing from the inbox, see if we have at least one other label.
2662 2768
 				// This query is faster than the one above
@@ -2688,21 +2794,25 @@  discard block
 block discarded – undo
2688 2794
 			if ($to_label[$row['id_pm']] != '-1')
2689 2795
 			{
2690 2796
 				// If this label is in the list and we're not adding it, remove it
2691
-				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add')
2692
-					unset($labels[$to_label[$row['id_pm']]]);
2693
-				else if ($type !== 'rem')
2694
-					$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2797
+				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') {
2798
+									unset($labels[$to_label[$row['id_pm']]]);
2799
+				} else if ($type !== 'rem') {
2800
+									$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2801
+				}
2695 2802
 			}
2696 2803
 
2697 2804
 			// Removing all labels or just removing the inbox label
2698
-			if ($type == 'rem' && empty($labels))
2699
-				$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2805
+			if ($type == 'rem' && empty($labels)) {
2806
+							$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2807
+			}
2700 2808
 			// Adding new labels, but removing inbox and applying new ones
2701
-			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels))
2702
-				$in_inbox = 0;
2809
+			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) {
2810
+							$in_inbox = 0;
2811
+			}
2703 2812
 			// Just adding it to the inbox
2704
-			else
2705
-				$in_inbox = 1;
2813
+			else {
2814
+							$in_inbox = 1;
2815
+			}
2706 2816
 
2707 2817
 			// Are we adding it to or removing it from the inbox?
2708 2818
 			if ($in_inbox != $row['in_inbox'])
@@ -2744,8 +2854,9 @@  discard block
 block discarded – undo
2744 2854
 			if (!empty($labels_to_apply))
2745 2855
 			{
2746 2856
 				$inserts = array();
2747
-				foreach ($labels_to_apply as $label)
2748
-					$inserts[] = array($row['id_pm'], $label);
2857
+				foreach ($labels_to_apply as $label) {
2858
+									$inserts[] = array($row['id_pm'], $label);
2859
+				}
2749 2860
 
2750 2861
 				$smcFunc['db_insert']('',
2751 2862
 					'{db_prefix}pm_labeled_messages',
@@ -2789,11 +2900,13 @@  discard block
 block discarded – undo
2789 2900
 	checkSession('get');
2790 2901
 
2791 2902
 	// If all then delete all messages the user has.
2792
-	if ($_REQUEST['f'] == 'all')
2793
-		deleteMessages(null, null);
2903
+	if ($_REQUEST['f'] == 'all') {
2904
+			deleteMessages(null, null);
2905
+	}
2794 2906
 	// Otherwise just the selected folder.
2795
-	else
2796
-		deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2907
+	else {
2908
+			deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2909
+	}
2797 2910
 
2798 2911
 	// Done... all gone.
2799 2912
 	redirectexit($context['current_label_redirect']);
@@ -2830,8 +2943,9 @@  discard block
 block discarded – undo
2830 2943
 				'msgtime' => $deleteTime,
2831 2944
 			)
2832 2945
 		);
2833
-		while ($row = $smcFunc['db_fetch_row']($request))
2834
-			$toDelete[] = $row[0];
2946
+		while ($row = $smcFunc['db_fetch_row']($request)) {
2947
+					$toDelete[] = $row[0];
2948
+		}
2835 2949
 		$smcFunc['db_free_result']($request);
2836 2950
 
2837 2951
 		// Select all messages in their inbox older than $deleteTime.
@@ -2848,8 +2962,9 @@  discard block
 block discarded – undo
2848 2962
 				'msgtime' => $deleteTime,
2849 2963
 			)
2850 2964
 		);
2851
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2852
-			$toDelete[] = $row['id_pm'];
2965
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2966
+					$toDelete[] = $row['id_pm'];
2967
+		}
2853 2968
 		$smcFunc['db_free_result']($request);
2854 2969
 
2855 2970
 		// Delete the actual messages.
@@ -2880,26 +2995,29 @@  discard block
 block discarded – undo
2880 2995
 {
2881 2996
 	global $user_info, $smcFunc;
2882 2997
 
2883
-	if ($owner === null)
2884
-		$owner = array($user_info['id']);
2885
-	elseif (empty($owner))
2886
-		return;
2887
-	elseif (!is_array($owner))
2888
-		$owner = array($owner);
2998
+	if ($owner === null) {
2999
+			$owner = array($user_info['id']);
3000
+	} elseif (empty($owner)) {
3001
+			return;
3002
+	} elseif (!is_array($owner)) {
3003
+			$owner = array($owner);
3004
+	}
2889 3005
 
2890 3006
 	if ($personal_messages !== null)
2891 3007
 	{
2892
-		if (empty($personal_messages) || !is_array($personal_messages))
2893
-			return;
3008
+		if (empty($personal_messages) || !is_array($personal_messages)) {
3009
+					return;
3010
+		}
2894 3011
 
2895
-		foreach ($personal_messages as $index => $delete_id)
2896
-			$personal_messages[$index] = (int) $delete_id;
3012
+		foreach ($personal_messages as $index => $delete_id) {
3013
+					$personal_messages[$index] = (int) $delete_id;
3014
+		}
2897 3015
 
2898 3016
 		$where = '
2899 3017
 				AND id_pm IN ({array_int:pm_list})';
3018
+	} else {
3019
+			$where = '';
2900 3020
 	}
2901
-	else
2902
-		$where = '';
2903 3021
 
2904 3022
 	if ($folder == 'sent' || $folder === null)
2905 3023
 	{
@@ -2934,17 +3052,19 @@  discard block
 block discarded – undo
2934 3052
 		// ...And update the statistics accordingly - now including unread messages!.
2935 3053
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2936 3054
 		{
2937
-			if ($row['is_read'])
2938
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
2939
-			else
2940
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3055
+			if ($row['is_read']) {
3056
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
3057
+			} else {
3058
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3059
+			}
2941 3060
 
2942 3061
 			// If this is the current member we need to make their message count correct.
2943 3062
 			if ($user_info['id'] == $row['id_member'])
2944 3063
 			{
2945 3064
 				$user_info['messages'] -= $row['num_deleted_messages'];
2946
-				if (!($row['is_read']))
2947
-					$user_info['unread_messages'] -= $row['num_deleted_messages'];
3065
+				if (!($row['is_read'])) {
3066
+									$user_info['unread_messages'] -= $row['num_deleted_messages'];
3067
+				}
2948 3068
 			}
2949 3069
 		}
2950 3070
 		$smcFunc['db_free_result']($request);
@@ -3012,8 +3132,9 @@  discard block
 block discarded – undo
3012 3132
 		)
3013 3133
 	);
3014 3134
 	$remove_pms = array();
3015
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3016
-		$remove_pms[] = $row['sender'];
3135
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3136
+			$remove_pms[] = $row['sender'];
3137
+	}
3017 3138
 	$smcFunc['db_free_result']($request);
3018 3139
 
3019 3140
 	if (!empty($remove_pms))
@@ -3058,8 +3179,9 @@  discard block
 block discarded – undo
3058 3179
 {
3059 3180
 	global $user_info, $context, $smcFunc;
3060 3181
 
3061
-	if ($owner === null)
3062
-		$owner = $user_info['id'];
3182
+	if ($owner === null) {
3183
+			$owner = $user_info['id'];
3184
+	}
3063 3185
 
3064 3186
 	$in_inbox = '';
3065 3187
 
@@ -3083,8 +3205,7 @@  discard block
 block discarded – undo
3083 3205
 		}
3084 3206
 
3085 3207
 		$smcFunc['db_free_result']($get_messages);
3086
-	}
3087
-	elseif ($label = '-1')
3208
+	} elseif ($label = '-1')
3088 3209
 	{
3089 3210
 		// Marking all PMs in your inbox read
3090 3211
 		$in_inbox = '
@@ -3109,8 +3230,9 @@  discard block
 block discarded – undo
3109 3230
 	{
3110 3231
 		if ($owner == $user_info['id'])
3111 3232
 		{
3112
-			foreach ($context['labels'] as $label)
3113
-				$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3233
+			foreach ($context['labels'] as $label) {
3234
+							$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3235
+			}
3114 3236
 		}
3115 3237
 
3116 3238
 		$result = $smcFunc['db_query']('', '
@@ -3130,8 +3252,9 @@  discard block
 block discarded – undo
3130 3252
 		{
3131 3253
 			$total_unread += $row['num'];
3132 3254
 
3133
-			if ($owner != $user_info['id'] || empty($row['id_pm']))
3134
-				continue;
3255
+			if ($owner != $user_info['id'] || empty($row['id_pm'])) {
3256
+							continue;
3257
+			}
3135 3258
 
3136 3259
 			$this_labels = array();
3137 3260
 
@@ -3155,11 +3278,13 @@  discard block
 block discarded – undo
3155 3278
 
3156 3279
 			$smcFunc['db_free_result']($result2);
3157 3280
 
3158
-			foreach ($this_labels as $this_label)
3159
-				$context['labels'][$this_label]['unread_messages'] += $row['num'];
3281
+			foreach ($this_labels as $this_label) {
3282
+							$context['labels'][$this_label]['unread_messages'] += $row['num'];
3283
+			}
3160 3284
 
3161
-			if ($row['in_inbox'] == 1)
3162
-				$context['labels'][-1]['unread_messages'] += $row['num'];
3285
+			if ($row['in_inbox'] == 1) {
3286
+							$context['labels'][-1]['unread_messages'] += $row['num'];
3287
+			}
3163 3288
 		}
3164 3289
 		$smcFunc['db_free_result']($result);
3165 3290
 
@@ -3168,8 +3293,9 @@  discard block
 block discarded – undo
3168 3293
 		updateMemberData($owner, array('unread_messages' => $total_unread));
3169 3294
 
3170 3295
 		// If it was for the current member, reflect this in the $user_info array too.
3171
-		if ($owner == $user_info['id'])
3172
-			$user_info['unread_messages'] = $total_unread;
3296
+		if ($owner == $user_info['id']) {
3297
+					$user_info['unread_messages'] = $total_unread;
3298
+		}
3173 3299
 	}
3174 3300
 }
3175 3301
 
@@ -3197,8 +3323,9 @@  discard block
 block discarded – undo
3197 3323
 	// Add all existing labels to the array to save, slashing them as necessary...
3198 3324
 	foreach ($context['labels'] as $label)
3199 3325
 	{
3200
-		if ($label['id'] != -1)
3201
-			$the_labels[$label['id']] = $label['name'];
3326
+		if ($label['id'] != -1) {
3327
+					$the_labels[$label['id']] = $label['name'];
3328
+		}
3202 3329
 	}
3203 3330
 
3204 3331
 	if (isset($_POST[$context['session_var']]))
@@ -3217,8 +3344,9 @@  discard block
 block discarded – undo
3217 3344
 		{
3218 3345
 			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => '&#044;'));
3219 3346
 
3220
-			if ($smcFunc['strlen']($_POST['label']) > 30)
3221
-				$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3347
+			if ($smcFunc['strlen']($_POST['label']) > 30) {
3348
+							$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3349
+			}
3222 3350
 			if ($_POST['label'] != '')
3223 3351
 			{
3224 3352
 				$the_labels[] = $_POST['label'];
@@ -3239,24 +3367,25 @@  discard block
 block discarded – undo
3239 3367
 		{
3240 3368
 			foreach ($the_labels as $id => $name)
3241 3369
 			{
3242
-				if ($id == -1)
3243
-					continue;
3244
-				elseif (isset($_POST['label_name'][$id]))
3370
+				if ($id == -1) {
3371
+									continue;
3372
+				} elseif (isset($_POST['label_name'][$id]))
3245 3373
 				{
3246 3374
 					$_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => '&#044;')));
3247 3375
 
3248
-					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30)
3249
-						$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3376
+					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) {
3377
+											$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3378
+					}
3250 3379
 					if ($_POST['label_name'][$id] != '')
3251 3380
 					{
3252 3381
 						// Changing the name of this label?
3253
-						if ($the_labels[$id] != $_POST['label_name'][$id])
3254
-							$label_updates[$id] = $_POST['label_name'][$id];
3382
+						if ($the_labels[$id] != $_POST['label_name'][$id]) {
3383
+													$label_updates[$id] = $_POST['label_name'][$id];
3384
+						}
3255 3385
 
3256 3386
 						$the_labels[(int) $id] = $_POST['label_name'][$id];
3257 3387
 
3258
-					}
3259
-					else
3388
+					} else
3260 3389
 					{
3261 3390
 						unset($the_labels[(int) $id]);
3262 3391
 						$labels_to_remove[] = $id;
@@ -3270,8 +3399,9 @@  discard block
 block discarded – undo
3270 3399
 		if (!empty($labels_to_add))
3271 3400
 		{
3272 3401
 			$inserts = array();
3273
-			foreach ($labels_to_add AS $label)
3274
-				$inserts[] = array($user_info['id'], $label);
3402
+			foreach ($labels_to_add AS $label) {
3403
+							$inserts[] = array($user_info['id'], $label);
3404
+			}
3275 3405
 
3276 3406
 			$smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
3277 3407
 		}
@@ -3361,8 +3491,9 @@  discard block
 block discarded – undo
3361 3491
 				// Each action...
3362 3492
 				foreach ($rule['actions'] as $k2 => $action)
3363 3493
 				{
3364
-					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove))
3365
-						continue;
3494
+					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) {
3495
+											continue;
3496
+					}
3366 3497
 
3367 3498
 					$rule_changes[] = $rule['id'];
3368 3499
 
@@ -3377,8 +3508,8 @@  discard block
 block discarded – undo
3377 3508
 		{
3378 3509
 			$rule_changes = array_unique($rule_changes);
3379 3510
 			// Update/delete as appropriate.
3380
-			foreach ($rule_changes as $k => $id)
3381
-				if (!empty($context['rules'][$id]['actions']))
3511
+			foreach ($rule_changes as $k => $id) {
3512
+							if (!empty($context['rules'][$id]['actions']))
3382 3513
 				{
3383 3514
 					$smcFunc['db_query']('', '
3384 3515
 						UPDATE {db_prefix}pm_rules
@@ -3391,12 +3522,13 @@  discard block
 block discarded – undo
3391 3522
 							'actions' => json_encode($context['rules'][$id]['actions']),
3392 3523
 						)
3393 3524
 					);
3525
+			}
3394 3526
 					unset($rule_changes[$k]);
3395 3527
 				}
3396 3528
 
3397 3529
 			// Anything left here means it's lost all actions...
3398
-			if (!empty($rule_changes))
3399
-				$smcFunc['db_query']('', '
3530
+			if (!empty($rule_changes)) {
3531
+							$smcFunc['db_query']('', '
3400 3532
 					DELETE FROM {db_prefix}pm_rules
3401 3533
 					WHERE id_rule IN ({array_int:rule_list})
3402 3534
 							AND id_member = {int:current_member}',
@@ -3405,6 +3537,7 @@  discard block
 block discarded – undo
3405 3537
 						'rule_list' => $rule_changes,
3406 3538
 					)
3407 3539
 				);
3540
+			}
3408 3541
 		}
3409 3542
 
3410 3543
 		// Make sure we're not caching this!
@@ -3474,8 +3607,9 @@  discard block
 block discarded – undo
3474 3607
 		// Save the fields.
3475 3608
 		saveProfileFields();
3476 3609
 
3477
-		if (!empty($profile_vars))
3478
-			updateMemberData($user_info['id'], $profile_vars);
3610
+		if (!empty($profile_vars)) {
3611
+					updateMemberData($user_info['id'], $profile_vars);
3612
+		}
3479 3613
 	}
3480 3614
 
3481 3615
 	setupProfileContext(
@@ -3500,13 +3634,15 @@  discard block
 block discarded – undo
3500 3634
 	global $user_info, $language, $modSettings, $smcFunc;
3501 3635
 
3502 3636
 	// Check that this feature is even enabled!
3503
-	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg']))
3504
-		fatal_lang_error('no_access', false);
3637
+	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) {
3638
+			fatal_lang_error('no_access', false);
3639
+	}
3505 3640
 
3506 3641
 	$pmsg = (int) $_REQUEST['pmsg'];
3507 3642
 
3508
-	if (!isAccessiblePM($pmsg, 'inbox'))
3509
-		fatal_lang_error('no_access', false);
3643
+	if (!isAccessiblePM($pmsg, 'inbox')) {
3644
+			fatal_lang_error('no_access', false);
3645
+	}
3510 3646
 
3511 3647
 	$context['pm_id'] = $pmsg;
3512 3648
 	$context['page_title'] = $txt['pm_report_title'];
@@ -3528,8 +3664,9 @@  discard block
 block discarded – undo
3528 3664
 			)
3529 3665
 		);
3530 3666
 		$context['admins'] = array();
3531
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3532
-			$context['admins'][$row['id_member']] = $row['real_name'];
3667
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3668
+					$context['admins'][$row['id_member']] = $row['real_name'];
3669
+		}
3533 3670
 		$smcFunc['db_free_result']($request);
3534 3671
 
3535 3672
 		// How many admins in total?
@@ -3558,8 +3695,9 @@  discard block
 block discarded – undo
3558 3695
 			)
3559 3696
 		);
3560 3697
 		// Can only be a hacker here!
3561
-		if ($smcFunc['db_num_rows']($request) == 0)
3562
-			fatal_lang_error('no_access', false);
3698
+		if ($smcFunc['db_num_rows']($request) == 0) {
3699
+					fatal_lang_error('no_access', false);
3700
+		}
3563 3701
 		list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);
3564 3702
 		$smcFunc['db_free_result']($request);
3565 3703
 
@@ -3583,15 +3721,17 @@  discard block
 block discarded – undo
3583 3721
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3584 3722
 		{
3585 3723
 			// If it's hidden still don't reveal their names - privacy after all ;)
3586
-			if ($row['bcc'])
3587
-				$hidden_recipients++;
3588
-			else
3589
-				$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3724
+			if ($row['bcc']) {
3725
+							$hidden_recipients++;
3726
+			} else {
3727
+							$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3728
+			}
3590 3729
 		}
3591 3730
 		$smcFunc['db_free_result']($request);
3592 3731
 
3593
-		if ($hidden_recipients)
3594
-			$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3732
+		if ($hidden_recipients) {
3733
+					$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3734
+		}
3595 3735
 
3596 3736
 		// Now let's get out and loop through the admins.
3597 3737
 		$request = $smcFunc['db_query']('', '
@@ -3607,8 +3747,9 @@  discard block
 block discarded – undo
3607 3747
 		);
3608 3748
 
3609 3749
 		// Maybe we shouldn't advertise this?
3610
-		if ($smcFunc['db_num_rows']($request) == 0)
3611
-			fatal_lang_error('no_access', false);
3750
+		if ($smcFunc['db_num_rows']($request) == 0) {
3751
+					fatal_lang_error('no_access', false);
3752
+		}
3612 3753
 
3613 3754
 		$memberFromName = un_htmlspecialchars($memberFromName);
3614 3755
 
@@ -3627,8 +3768,9 @@  discard block
 block discarded – undo
3627 3768
 				// Make the body.
3628 3769
 				$report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']);
3629 3770
 				$report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n";
3630
-				if (!empty($recipients))
3631
-					$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3771
+				if (!empty($recipients)) {
3772
+									$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3773
+				}
3632 3774
 				$report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '&quot;' . $memberFromName . '&quot;' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]';
3633 3775
 
3634 3776
 				// Plonk it in the array ;)
@@ -3648,12 +3790,14 @@  discard block
 block discarded – undo
3648 3790
 		$smcFunc['db_free_result']($request);
3649 3791
 
3650 3792
 		// Send a different email for each language.
3651
-		foreach ($messagesToSend as $lang => $message)
3652
-			sendpm($message['recipients'], $message['subject'], $message['body']);
3793
+		foreach ($messagesToSend as $lang => $message) {
3794
+					sendpm($message['recipients'], $message['subject'], $message['body']);
3795
+		}
3653 3796
 
3654 3797
 		// Give the user their own language back!
3655
-		if (!empty($modSettings['userLanguage']))
3656
-			loadLanguage('PersonalMessage', '', false);
3798
+		if (!empty($modSettings['userLanguage'])) {
3799
+					loadLanguage('PersonalMessage', '', false);
3800
+		}
3657 3801
 
3658 3802
 		// Leave them with a template.
3659 3803
 		$context['sub_template'] = 'report_message_complete';
@@ -3699,8 +3843,9 @@  discard block
 block discarded – undo
3699 3843
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3700 3844
 	{
3701 3845
 		// Hide hidden groups!
3702
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
3703
-			continue;
3846
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
3847
+					continue;
3848
+		}
3704 3849
 
3705 3850
 		$context['groups'][$row['id_group']] = $row['group_name'];
3706 3851
 	}
@@ -3726,9 +3871,10 @@  discard block
 block discarded – undo
3726 3871
 			$context['rule'] = $context['rules'][$context['rid']];
3727 3872
 			$members = array();
3728 3873
 			// Need to get member names!
3729
-			foreach ($context['rule']['criteria'] as $k => $criteria)
3730
-				if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3874
+			foreach ($context['rule']['criteria'] as $k => $criteria) {
3875
+							if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3731 3876
 					$members[(int) $criteria['v']] = $k;
3877
+			}
3732 3878
 
3733 3879
 			if (!empty($members))
3734 3880
 			{
@@ -3740,19 +3886,20 @@  discard block
 block discarded – undo
3740 3886
 						'member_list' => array_keys($members),
3741 3887
 					)
3742 3888
 				);
3743
-				while ($row = $smcFunc['db_fetch_assoc']($request))
3744
-					$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3889
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
3890
+									$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3891
+				}
3745 3892
 				$smcFunc['db_free_result']($request);
3746 3893
 			}
3747
-		}
3748
-		else
3749
-			$context['rule'] = array(
3894
+		} else {
3895
+					$context['rule'] = array(
3750 3896
 				'id' => '',
3751 3897
 				'name' => '',
3752 3898
 				'criteria' => array(),
3753 3899
 				'actions' => array(),
3754 3900
 				'logic' => 'and',
3755 3901
 			);
3902
+		}
3756 3903
 	}
3757 3904
 	// Saving?
3758 3905
 	elseif (isset($_GET['save']))
@@ -3762,22 +3909,25 @@  discard block
 block discarded – undo
3762 3909
 
3763 3910
 		// Name is easy!
3764 3911
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
3765
-		if (empty($ruleName))
3766
-			fatal_lang_error('pm_rule_no_name', false);
3912
+		if (empty($ruleName)) {
3913
+					fatal_lang_error('pm_rule_no_name', false);
3914
+		}
3767 3915
 
3768 3916
 		// Sanity check...
3769
-		if (empty($_POST['ruletype']) || empty($_POST['acttype']))
3770
-			fatal_lang_error('pm_rule_no_criteria', false);
3917
+		if (empty($_POST['ruletype']) || empty($_POST['acttype'])) {
3918
+					fatal_lang_error('pm_rule_no_criteria', false);
3919
+		}
3771 3920
 
3772 3921
 		// Let's do the criteria first - it's also hardest!
3773 3922
 		$criteria = array();
3774 3923
 		foreach ($_POST['ruletype'] as $ind => $type)
3775 3924
 		{
3776 3925
 			// Check everything is here...
3777
-			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]])))
3778
-				continue;
3779
-			elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind]))
3780
-				continue;
3926
+			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) {
3927
+							continue;
3928
+			} elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) {
3929
+							continue;
3930
+			}
3781 3931
 
3782 3932
 			// Members need to be found.
3783 3933
 			if ($type == 'mid')
@@ -3801,13 +3951,13 @@  discard block
 block discarded – undo
3801 3951
 				$smcFunc['db_free_result']($request);
3802 3952
 
3803 3953
 				$criteria[] = array('t' => 'mid', 'v' => $memID);
3954
+			} elseif ($type == 'bud') {
3955
+							$criteria[] = array('t' => 'bud', 'v' => 1);
3956
+			} elseif ($type == 'gid') {
3957
+							$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3958
+			} elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') {
3959
+							$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3804 3960
 			}
3805
-			elseif ($type == 'bud')
3806
-				$criteria[] = array('t' => 'bud', 'v' => 1);
3807
-			elseif ($type == 'gid')
3808
-				$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3809
-			elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '')
3810
-				$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3811 3961
 		}
3812 3962
 
3813 3963
 		// Also do the actions!
@@ -3817,26 +3967,29 @@  discard block
 block discarded – undo
3817 3967
 		foreach ($_POST['acttype'] as $ind => $type)
3818 3968
 		{
3819 3969
 			// Picking a valid label?
3820
-			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]])))
3821
-				continue;
3970
+			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) {
3971
+							continue;
3972
+			}
3822 3973
 
3823 3974
 			// Record what we're doing.
3824
-			if ($type == 'del')
3825
-				$doDelete = 1;
3826
-			elseif ($type == 'lab')
3827
-				$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3975
+			if ($type == 'del') {
3976
+							$doDelete = 1;
3977
+			} elseif ($type == 'lab') {
3978
+							$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3979
+			}
3828 3980
 		}
3829 3981
 
3830
-		if (empty($criteria) || (empty($actions) && !$doDelete))
3831
-			fatal_lang_error('pm_rule_no_criteria', false);
3982
+		if (empty($criteria) || (empty($actions) && !$doDelete)) {
3983
+					fatal_lang_error('pm_rule_no_criteria', false);
3984
+		}
3832 3985
 
3833 3986
 		// What are we storing?
3834 3987
 		$criteria = json_encode($criteria);
3835 3988
 		$actions = json_encode($actions);
3836 3989
 
3837 3990
 		// Create the rule?
3838
-		if (empty($context['rid']))
3839
-			$smcFunc['db_insert']('',
3991
+		if (empty($context['rid'])) {
3992
+					$smcFunc['db_insert']('',
3840 3993
 				'{db_prefix}pm_rules',
3841 3994
 				array(
3842 3995
 					'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string',
@@ -3847,8 +4000,8 @@  discard block
 block discarded – undo
3847 4000
 				),
3848 4001
 				array('id_rule')
3849 4002
 			);
3850
-		else
3851
-			$smcFunc['db_query']('', '
4003
+		} else {
4004
+					$smcFunc['db_query']('', '
3852 4005
 				UPDATE {db_prefix}pm_rules
3853 4006
 				SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions},
3854 4007
 					delete_pm = {int:delete_pm}, is_or = {int:is_or}
@@ -3864,6 +4017,7 @@  discard block
 block discarded – undo
3864 4017
 					'actions' => $actions,
3865 4018
 				)
3866 4019
 			);
4020
+		}
3867 4021
 
3868 4022
 		redirectexit('action=pm;sa=manrules');
3869 4023
 	}
@@ -3872,11 +4026,12 @@  discard block
 block discarded – undo
3872 4026
 	{
3873 4027
 		checkSession();
3874 4028
 		$toDelete = array();
3875
-		foreach ($_POST['delrule'] as $k => $v)
3876
-			$toDelete[] = (int) $k;
4029
+		foreach ($_POST['delrule'] as $k => $v) {
4030
+					$toDelete[] = (int) $k;
4031
+		}
3877 4032
 
3878
-		if (!empty($toDelete))
3879
-			$smcFunc['db_query']('', '
4033
+		if (!empty($toDelete)) {
4034
+					$smcFunc['db_query']('', '
3880 4035
 				DELETE FROM {db_prefix}pm_rules
3881 4036
 				WHERE id_rule IN ({array_int:delete_list})
3882 4037
 					AND id_member = {int:current_member}',
@@ -3885,6 +4040,7 @@  discard block
 block discarded – undo
3885 4040
 					'delete_list' => $toDelete,
3886 4041
 				)
3887 4042
 			);
4043
+		}
3888 4044
 
3889 4045
 		redirectexit('action=pm;sa=manrules');
3890 4046
 	}
@@ -3903,8 +4059,9 @@  discard block
 block discarded – undo
3903 4059
 	loadRules();
3904 4060
 
3905 4061
 	// No rules?
3906
-	if (empty($context['rules']))
3907
-		return;
4062
+	if (empty($context['rules'])) {
4063
+			return;
4064
+	}
3908 4065
 
3909 4066
 	// Just unread ones?
3910 4067
 	$ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1';
@@ -3934,8 +4091,9 @@  discard block
 block discarded – undo
3934 4091
 			// Loop through all the criteria hoping to make a match.
3935 4092
 			foreach ($rule['criteria'] as $criterium)
3936 4093
 			{
3937
-				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false))
3938
-					$match = true;
4094
+				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) {
4095
+									$match = true;
4096
+				}
3939 4097
 				// If we're adding and one criteria don't match then we stop!
3940 4098
 				elseif ($rule['logic'] == 'and')
3941 4099
 				{
@@ -3947,17 +4105,18 @@  discard block
 block discarded – undo
3947 4105
 			// If we have a match the rule must be true - act!
3948 4106
 			if ($match)
3949 4107
 			{
3950
-				if ($rule['delete'])
3951
-					$actions['deletes'][] = $row['id_pm'];
3952
-				else
4108
+				if ($rule['delete']) {
4109
+									$actions['deletes'][] = $row['id_pm'];
4110
+				} else
3953 4111
 				{
3954 4112
 					foreach ($rule['actions'] as $ruleAction)
3955 4113
 					{
3956 4114
 						if ($ruleAction['t'] == 'lab')
3957 4115
 						{
3958 4116
 							// Get a basic pot started!
3959
-							if (!isset($actions['labels'][$row['id_pm']]))
3960
-								$actions['labels'][$row['id_pm']] = array();
4117
+							if (!isset($actions['labels'][$row['id_pm']])) {
4118
+															$actions['labels'][$row['id_pm']] = array();
4119
+							}
3961 4120
 							$actions['labels'][$row['id_pm']][] = $ruleAction['v'];
3962 4121
 						}
3963 4122
 					}
@@ -3968,8 +4127,9 @@  discard block
 block discarded – undo
3968 4127
 	$smcFunc['db_free_result']($request);
3969 4128
 
3970 4129
 	// Deletes are easy!
3971
-	if (!empty($actions['deletes']))
3972
-		deleteMessages($actions['deletes']);
4130
+	if (!empty($actions['deletes'])) {
4131
+			deleteMessages($actions['deletes']);
4132
+	}
3973 4133
 
3974 4134
 	// Relabel?
3975 4135
 	if (!empty($actions['labels']))
@@ -3996,8 +4156,7 @@  discard block
 block discarded – undo
3996 4156
 								'current_member' => $user_info['id'],
3997 4157
 							)
3998 4158
 						);
3999
-					}
4000
-					else
4159
+					} else
4001 4160
 					{
4002 4161
 						$realLabels[] = $label['id'];
4003 4162
 					}
@@ -4006,8 +4165,9 @@  discard block
 block discarded – undo
4006 4165
 
4007 4166
 			$inserts = array();
4008 4167
 			// Now we insert the label info
4009
-			foreach ($realLabels as $a_label)
4010
-				$inserts[] = array($pm, $a_label);
4168
+			foreach ($realLabels as $a_label) {
4169
+							$inserts[] = array($pm, $a_label);
4170
+			}
4011 4171
 
4012 4172
 			$smcFunc['db_insert']('ignore',
4013 4173
 				'{db_prefix}pm_labeled_messages',
@@ -4028,8 +4188,9 @@  discard block
 block discarded – undo
4028 4188
 {
4029 4189
 	global $user_info, $context, $smcFunc;
4030 4190
 
4031
-	if (isset($context['rules']) && !$reload)
4032
-		return;
4191
+	if (isset($context['rules']) && !$reload) {
4192
+			return;
4193
+	}
4033 4194
 
4034 4195
 	$request = $smcFunc['db_query']('', '
4035 4196
 		SELECT
@@ -4053,8 +4214,9 @@  discard block
 block discarded – undo
4053 4214
 			'logic' => $row['is_or'] ? 'or' : 'and',
4054 4215
 		);
4055 4216
 
4056
-		if ($row['delete_pm'])
4057
-			$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4217
+		if ($row['delete_pm']) {
4218
+					$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4219
+		}
4058 4220
 	}
4059 4221
 	$smcFunc['db_free_result']($request);
4060 4222
 }
Please login to merge, or discard this patch.