Completed
Branch release-2.1 (e49a83)
by Michael
08:59
created
Sources/Reports.php 1 patch
Braces   +199 added lines, -148 removed lines patch added patch discarded remove patch
@@ -21,8 +21,9 @@  discard block
 block discarded – undo
21 21
  * @version 2.1 Beta 3
22 22
  */
23 23
 
24
-if (!defined('SMF'))
24
+if (!defined('SMF')) {
25 25
 	die('No direct access...');
26
+}
26 27
 
27 28
 /**
28 29
  * Handling function for generating reports.
@@ -69,14 +70,15 @@  discard block
 block discarded – undo
69 70
 	);
70 71
 
71 72
 	$is_first = 0;
72
-	foreach ($context['report_types'] as $k => $temp)
73
-		$context['report_types'][$k] = array(
73
+	foreach ($context['report_types'] as $k => $temp) {
74
+			$context['report_types'][$k] = array(
74 75
 			'id' => $k,
75 76
 			'title' => isset($txt['gr_type_' . $k]) ? $txt['gr_type_' . $k] : $k,
76 77
 			'description' => isset($txt['gr_type_desc_' . $k]) ? $txt['gr_type_desc_' . $k] : null,
77 78
 			'function' => $temp,
78 79
 			'is_first' => $is_first++ == 0,
79 80
 		);
81
+	}
80 82
 
81 83
 	// If they haven't chosen a report type which is valid, send them off to the report type chooser!
82 84
 	if (empty($_REQUEST['rt']) || !isset($context['report_types'][$_REQUEST['rt']]))
@@ -102,8 +104,9 @@  discard block
 block discarded – undo
102 104
 		$context['sub_template'] = $_REQUEST['st'];
103 105
 
104 106
 		// Are we disabling the other layers - print friendly for example?
105
-		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null)
106
-			$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
107
+		if ($reportTemplates[$_REQUEST['st']]['layers'] !== null) {
108
+					$context['template_layers'] = $reportTemplates[$_REQUEST['st']]['layers'];
109
+		}
107 110
 	}
108 111
 
109 112
 	// Make the page title more descriptive.
@@ -151,8 +154,9 @@  discard block
 block discarded – undo
151 154
 		)
152 155
 	);
153 156
 	$moderators = array();
154
-	while ($row = $smcFunc['db_fetch_assoc']($request))
155
-		$moderators[$row['id_board']][] = $row['real_name'];
157
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
158
+			$moderators[$row['id_board']][] = $row['real_name'];
159
+	}
156 160
 	$smcFunc['db_free_result']($request);
157 161
 
158 162
 	// Get every moderator gruop.
@@ -164,8 +168,9 @@  discard block
 block discarded – undo
164 168
 		)
165 169
 	);
166 170
 	$moderator_groups = array();
167
-	while ($row = $smcFunc['db_fetch_assoc']($request))
168
-		$moderator_groups[$row['id_board']][] = $row['group_name'];
171
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
172
+			$moderator_groups[$row['id_board']][] = $row['group_name'];
173
+	}
169 174
 	$smcFunc['db_free_result']($request);
170 175
 
171 176
 	// Get all the possible membergroups!
@@ -176,8 +181,9 @@  discard block
 block discarded – undo
176 181
 		)
177 182
 	);
178 183
 	$groups = array(-1 => $txt['guest_title'], 0 => $txt['full_member']);
179
-	while ($row = $smcFunc['db_fetch_assoc']($request))
180
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
184
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
185
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
186
+	}
181 187
 	$smcFunc['db_free_result']($request);
182 188
 
183 189
 	// All the fields we'll show.
@@ -195,8 +201,9 @@  discard block
 block discarded – undo
195 201
 		'moderator_groups' => $txt['board_moderator_groups'],
196 202
 		'groups' => $txt['board_groups'],
197 203
 	);
198
-	if (!empty($modSettings['deny_boards_access']))
199
-		$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
204
+	if (!empty($modSettings['deny_boards_access'])) {
205
+			$boardSettings['disallowed_groups'] = $txt['board_disallowed_groups'];
206
+	}
200 207
 
201 208
 	// Do it in columns, it's just easier.
202 209
 	setKeys('cols');
@@ -222,8 +229,9 @@  discard block
 block discarded – undo
222 229
 		newTable($row['name'], '', 'left', 'auto', 'left', 200, 'left');
223 230
 
224 231
 		$this_boardSettings = $boardSettings;
225
-		if (empty($row['redirect']))
226
-			unset($this_boardSettings['redirect']);
232
+		if (empty($row['redirect'])) {
233
+					unset($this_boardSettings['redirect']);
234
+		}
227 235
 
228 236
 		// First off, add in the side key.
229 237
 		addData($this_boardSettings);
@@ -250,10 +258,11 @@  discard block
 block discarded – undo
250 258
 		$allowedGroups = explode(',', $row['member_groups']);
251 259
 		foreach ($allowedGroups as $key => $group)
252 260
 		{
253
-			if (isset($groups[$group]))
254
-				$allowedGroups[$key] = $groups[$group];
255
-			else
256
-				unset($allowedGroups[$key]);
261
+			if (isset($groups[$group])) {
262
+							$allowedGroups[$key] = $groups[$group];
263
+			} else {
264
+							unset($allowedGroups[$key]);
265
+			}
257 266
 		}
258 267
 		$boardData['groups'] = implode(', ', $allowedGroups);
259 268
 		if (!empty($modSettings['deny_boards_access']))
@@ -261,16 +270,18 @@  discard block
 block discarded – undo
261 270
 			$disallowedGroups = explode(',', $row['deny_member_groups']);
262 271
 			foreach ($disallowedGroups as $key => $group)
263 272
 			{
264
-				if (isset($groups[$group]))
265
-					$disallowedGroups[$key] = $groups[$group];
266
-				else
267
-					unset($disallowedGroups[$key]);
273
+				if (isset($groups[$group])) {
274
+									$disallowedGroups[$key] = $groups[$group];
275
+				} else {
276
+									unset($disallowedGroups[$key]);
277
+				}
268 278
 			}
269 279
 			$boardData['disallowed_groups'] = implode(', ', $disallowedGroups);
270 280
 		}
271 281
 
272
-		if (empty($row['redirect']))
273
-			unset ($boardData['redirect']);
282
+		if (empty($row['redirect'])) {
283
+					unset ($boardData['redirect']);
284
+		}
274 285
 
275 286
 		// Next add the main data.
276 287
 		addData($boardData);
@@ -295,27 +306,31 @@  discard block
 block discarded – undo
295 306
 
296 307
 	if (isset($_REQUEST['boards']))
297 308
 	{
298
-		if (!is_array($_REQUEST['boards']))
299
-			$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
300
-		foreach ($_REQUEST['boards'] as $k => $dummy)
301
-			$_REQUEST['boards'][$k] = (int) $dummy;
309
+		if (!is_array($_REQUEST['boards'])) {
310
+					$_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
311
+		}
312
+		foreach ($_REQUEST['boards'] as $k => $dummy) {
313
+					$_REQUEST['boards'][$k] = (int) $dummy;
314
+		}
302 315
 
303 316
 		$board_clause = 'id_board IN ({array_int:boards})';
317
+	} else {
318
+			$board_clause = '1=1';
304 319
 	}
305
-	else
306
-		$board_clause = '1=1';
307 320
 
308 321
 	if (isset($_REQUEST['groups']))
309 322
 	{
310
-		if (!is_array($_REQUEST['groups']))
311
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
312
-		foreach ($_REQUEST['groups'] as $k => $dummy)
313
-			$_REQUEST['groups'][$k] = (int) $dummy;
323
+		if (!is_array($_REQUEST['groups'])) {
324
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
325
+		}
326
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
327
+					$_REQUEST['groups'][$k] = (int) $dummy;
328
+		}
314 329
 
315 330
 		$group_clause = 'id_group IN ({array_int:groups})';
331
+	} else {
332
+			$group_clause = '1=1';
316 333
 	}
317
-	else
318
-		$group_clause = '1=1';
319 334
 
320 335
 	// Fetch all the board names.
321 336
 	$request = $smcFunc['db_query']('', '
@@ -369,12 +384,14 @@  discard block
 block discarded – undo
369 384
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
370 385
 		)
371 386
 	);
372
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
373
-		$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
374
-	else
375
-		$member_groups = array('col' => '');
376
-	while ($row = $smcFunc['db_fetch_assoc']($request))
377
-		$member_groups[$row['id_group']] = $row['group_name'];
387
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
388
+			$member_groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
389
+	} else {
390
+			$member_groups = array('col' => '');
391
+	}
392
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
393
+			$member_groups[$row['id_group']] = $row['group_name'];
394
+	}
378 395
 	$smcFunc['db_free_result']($request);
379 396
 
380 397
 	// Make sure that every group is represented - plus in rows!
@@ -411,12 +428,14 @@  discard block
 block discarded – undo
411 428
 	);
412 429
 	while ($row = $smcFunc['db_fetch_assoc']($request))
413 430
 	{
414
-		if (in_array($row['permission'], $disabled_permissions))
415
-			continue;
431
+		if (in_array($row['permission'], $disabled_permissions)) {
432
+					continue;
433
+		}
416 434
 
417
-		foreach ($boards as $id => $board)
418
-			if ($board['profile'] == $row['id_profile'])
435
+		foreach ($boards as $id => $board) {
436
+					if ($board['profile'] == $row['id_profile'])
419 437
 				$board_permissions[$id][$row['id_group']][$row['permission']] = $row['add_deny'];
438
+		}
420 439
 
421 440
 		// Make sure we get every permission.
422 441
 		if (!isset($permissions[$row['permission']]))
@@ -454,8 +473,9 @@  discard block
 block discarded – undo
454 473
 			foreach ($member_groups as $id_group => $name)
455 474
 			{
456 475
 				// Don't overwrite the key column!
457
-				if ($id_group === 'col')
458
-					continue;
476
+				if ($id_group === 'col') {
477
+									continue;
478
+				}
459 479
 
460 480
 				$group_permissions = isset($groups[$id_group]) ? $groups[$id_group] : array();
461 481
 
@@ -477,16 +497,18 @@  discard block
 block discarded – undo
477 497
 				}
478 498
 
479 499
 				// Now actually make the data for the group look right.
480
-				if (empty($curData[$id_group]))
481
-					$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
482
-				elseif ($curData[$id_group] == 1)
483
-					$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
484
-				else
485
-					$curData[$id_group] = 'x';
500
+				if (empty($curData[$id_group])) {
501
+									$curData[$id_group] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
502
+				} elseif ($curData[$id_group] == 1) {
503
+									$curData[$id_group] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
504
+				} else {
505
+									$curData[$id_group] = 'x';
506
+				}
486 507
 
487 508
 				// Embolden those permissions different from global (makes it a lot easier!)
488
-				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM])
489
-					$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
509
+				if (@$board_permissions[0][$id_group][$ID_PERM] != @$group_permissions[$ID_PERM]) {
510
+									$curData[$id_group] = '<strong>' . $curData[$id_group] . '</strong>';
511
+				}
490 512
 			}
491 513
 
492 514
 			// Now add the data for this permission.
@@ -516,15 +538,17 @@  discard block
 block discarded – undo
516 538
 	);
517 539
 	while ($row = $smcFunc['db_fetch_assoc']($request))
518 540
 	{
519
-		if (trim($row['member_groups']) == '')
520
-			$groups = array(1);
521
-		else
522
-			$groups = array_merge(array(1), explode(',', $row['member_groups']));
541
+		if (trim($row['member_groups']) == '') {
542
+					$groups = array(1);
543
+		} else {
544
+					$groups = array_merge(array(1), explode(',', $row['member_groups']));
545
+		}
523 546
 
524
-		if (trim($row['deny_member_groups']) == '')
525
-			$denyGroups = array();
526
-		else
527
-			$denyGroups = explode(',', $row['deny_member_groups']);
547
+		if (trim($row['deny_member_groups']) == '') {
548
+					$denyGroups = array();
549
+		} else {
550
+					$denyGroups = explode(',', $row['deny_member_groups']);
551
+		}
528 552
 
529 553
 		$boards[$row['id_board']] = array(
530 554
 			'id' => $row['id_board'],
@@ -548,8 +572,9 @@  discard block
 block discarded – undo
548 572
 	);
549 573
 
550 574
 	// Add on the boards!
551
-	foreach ($boards as $board)
552
-		$mgSettings['board_' . $board['id']] = $board['name'];
575
+	foreach ($boards as $board) {
576
+			$mgSettings['board_' . $board['id']] = $board['name'];
577
+	}
553 578
 
554 579
 	// Add all the membergroup settings, plus we'll be adding in columns!
555 580
 	setKeys('cols', $mgSettings);
@@ -594,8 +619,9 @@  discard block
 block discarded – undo
594 619
 			'icons' => ''
595 620
 		),
596 621
 	);
597
-	while ($row = $smcFunc['db_fetch_assoc']($request))
598
-		$rows[] = $row;
622
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
623
+			$rows[] = $row;
624
+	}
599 625
 	$smcFunc['db_free_result']($request);
600 626
 
601 627
 	foreach ($rows as $row)
@@ -611,8 +637,9 @@  discard block
 block discarded – undo
611 637
 		);
612 638
 
613 639
 		// Board permissions.
614
-		foreach ($boards as $board)
615
-			$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
640
+		foreach ($boards as $board) {
641
+					$group['board_' . $board['id']] = in_array($row['id_group'], $board['groups']) ? '<span class="success">' . $txt['board_perms_allow'] . '</span>' : (!empty($modSettings['deny_boards_access']) && in_array($row['id_group'], $board['deny_groups']) ? '<span class="alert">' . $txt['board_perms_deny'] . '</span>' : 'x');
642
+		}
616 643
 
617 644
 		addData($group);
618 645
 	}
@@ -632,16 +659,18 @@  discard block
 block discarded – undo
632 659
 
633 660
 	if (isset($_REQUEST['groups']))
634 661
 	{
635
-		if (!is_array($_REQUEST['groups']))
636
-			$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
637
-		foreach ($_REQUEST['groups'] as $k => $dummy)
638
-			$_REQUEST['groups'][$k] = (int) $dummy;
662
+		if (!is_array($_REQUEST['groups'])) {
663
+					$_REQUEST['groups'] = explode(',', $_REQUEST['groups']);
664
+		}
665
+		foreach ($_REQUEST['groups'] as $k => $dummy) {
666
+					$_REQUEST['groups'][$k] = (int) $dummy;
667
+		}
639 668
 		$_REQUEST['groups'] = array_diff($_REQUEST['groups'], array(3));
640 669
 
641 670
 		$clause = 'id_group IN ({array_int:groups})';
671
+	} else {
672
+			$clause = 'id_group != {int:moderator_group}';
642 673
 	}
643
-	else
644
-		$clause = 'id_group != {int:moderator_group}';
645 674
 
646 675
 	// Get all the possible membergroups, except admin!
647 676
 	$request = $smcFunc['db_query']('', '
@@ -659,12 +688,14 @@  discard block
 block discarded – undo
659 688
 			'groups' => isset($_REQUEST['groups']) ? $_REQUEST['groups'] : array(),
660 689
 		)
661 690
 	);
662
-	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups']))
663
-		$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
664
-	else
665
-		$groups = array('col' => '');
666
-	while ($row = $smcFunc['db_fetch_assoc']($request))
667
-		$groups[$row['id_group']] = $row['group_name'];
691
+	if (!isset($_REQUEST['groups']) || in_array(-1, $_REQUEST['groups']) || in_array(0, $_REQUEST['groups'])) {
692
+			$groups = array('col' => '', -1 => $txt['membergroups_guests'], 0 => $txt['membergroups_members']);
693
+	} else {
694
+			$groups = array('col' => '');
695
+	}
696
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
697
+			$groups[$row['id_group']] = $row['group_name'];
698
+	}
668 699
 	$smcFunc['db_free_result']($request);
669 700
 
670 701
 	// Make sure that every group is represented!
@@ -688,8 +719,9 @@  discard block
 block discarded – undo
688 719
 		$disabled_permissions[] = 'calendar_edit_own';
689 720
 		$disabled_permissions[] = 'calendar_edit_any';
690 721
 	}
691
-	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0)
692
-		$disabled_permissions[] = 'issue_warning';
722
+	if (empty($modSettings['warning_settings']) || $modSettings['warning_settings'][0] == 0) {
723
+			$disabled_permissions[] = 'issue_warning';
724
+	}
693 725
 
694 726
 	call_integration_hook('integrate_reports_groupperm', array(&$disabled_permissions));
695 727
 
@@ -710,15 +742,17 @@  discard block
 block discarded – undo
710 742
 	$curData = array();
711 743
 	while ($row = $smcFunc['db_fetch_assoc']($request))
712 744
 	{
713
-		if (in_array($row['permission'], $disabled_permissions))
714
-			continue;
745
+		if (in_array($row['permission'], $disabled_permissions)) {
746
+					continue;
747
+		}
715 748
 
716 749
 		// If this is a new permission flush the last row.
717 750
 		if ($row['permission'] != $lastPermission)
718 751
 		{
719 752
 			// Send the data!
720
-			if ($lastPermission !== null)
721
-				addData($curData);
753
+			if ($lastPermission !== null) {
754
+							addData($curData);
755
+			}
722 756
 
723 757
 			// Add the permission name in the left column.
724 758
 			$curData = array('col' => isset($txt['group_perms_name_' . $row['permission']]) ? $txt['group_perms_name_' . $row['permission']] : $row['permission']);
@@ -727,10 +761,11 @@  discard block
 block discarded – undo
727 761
 		}
728 762
 
729 763
 		// Good stuff - add the permission to the list!
730
-		if ($row['add_deny'])
731
-			$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
732
-		else
733
-			$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
764
+		if ($row['add_deny']) {
765
+					$curData[$row['id_group']] = '<span style="color: darkgreen;">' . $txt['board_perms_allow'] . '</span>';
766
+		} else {
767
+					$curData[$row['id_group']] = '<span class="red">' . $txt['board_perms_deny'] . '</span>';
768
+		}
734 769
 	}
735 770
 	$smcFunc['db_free_result']($request);
736 771
 
@@ -760,8 +795,9 @@  discard block
 block discarded – undo
760 795
 		)
761 796
 	);
762 797
 	$boards = array();
763
-	while ($row = $smcFunc['db_fetch_assoc']($request))
764
-		$boards[$row['id_board']] = $row['name'];
798
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
799
+			$boards[$row['id_board']] = $row['name'];
800
+	}
765 801
 	$smcFunc['db_free_result']($request);
766 802
 
767 803
 	// Get every moderator.
@@ -793,12 +829,14 @@  discard block
 block discarded – undo
793 829
 	while ($row = $smcFunc['db_fetch_assoc']($request))
794 830
 	{
795 831
 		// Either we don't have them as a moderator at all or at least not as a moderator of this board
796
-		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']]))
797
-			$moderators[$row['id_member']][] = $row['id_board'];
832
+		if (!array_key_exists($row['id_member'], $moderators) || !in_array($row['id_board'], $moderators[$row['id_member']])) {
833
+					$moderators[$row['id_member']][] = $row['id_board'];
834
+		}
798 835
 
799 836
 		// We don't have them listed as a moderator yet
800
-		if (!array_key_exists($row['id_member'], $local_mods))
801
-			$local_mods[$row['id_member']] = $row['id_member'];
837
+		if (!array_key_exists($row['id_member'], $local_mods)) {
838
+					$local_mods[$row['id_member']] = $row['id_member'];
839
+		}
802 840
 	}
803 841
 
804 842
 	// Get a list of global moderators (i.e. members with moderation powers).
@@ -811,8 +849,9 @@  discard block
 block discarded – undo
811 849
 	$allStaff = array_unique($allStaff);
812 850
 
813 851
 	// This is a bit of a cop out - but we're protecting their forum, really!
814
-	if (count($allStaff) > 300)
815
-		fatal_lang_error('report_error_too_many_staff');
852
+	if (count($allStaff) > 300) {
853
+			fatal_lang_error('report_error_too_many_staff');
854
+	}
816 855
 
817 856
 	// Get all the possible membergroups!
818 857
 	$request = $smcFunc['db_query']('', '
@@ -822,8 +861,9 @@  discard block
 block discarded – undo
822 861
 		)
823 862
 	);
824 863
 	$groups = array(0 => $txt['full_member']);
825
-	while ($row = $smcFunc['db_fetch_assoc']($request))
826
-		$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
864
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
865
+			$groups[$row['id_group']] = empty($row['online_color']) ? $row['group_name'] : '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>';
866
+	}
827 867
 	$smcFunc['db_free_result']($request);
828 868
 
829 869
 	// All the fields we'll show.
@@ -864,19 +904,20 @@  discard block
 block discarded – undo
864 904
 		);
865 905
 
866 906
 		// What do they moderate?
867
-		if (in_array($row['id_member'], $global_mods))
868
-			$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
869
-		elseif (isset($moderators[$row['id_member']]))
907
+		if (in_array($row['id_member'], $global_mods)) {
908
+					$staffData['moderates'] = '<em>' . $txt['report_staff_all_boards'] . '</em>';
909
+		} elseif (isset($moderators[$row['id_member']]))
870 910
 		{
871 911
 			// Get the names
872
-			foreach ($moderators[$row['id_member']] as $board)
873
-				if (isset($boards[$board]))
912
+			foreach ($moderators[$row['id_member']] as $board) {
913
+							if (isset($boards[$board]))
874 914
 					$staffData['moderates'][] = $boards[$board];
915
+			}
875 916
 
876 917
 			$staffData['moderates'] = implode(', ', $staffData['moderates']);
918
+		} else {
919
+					$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
877 920
 		}
878
-		else
879
-			$staffData['moderates'] = '<em>' . $txt['report_staff_no_boards'] . '</em>';
880 921
 
881 922
 		// Next add the main data.
882 923
 		addData($staffData);
@@ -904,8 +945,9 @@  discard block
 block discarded – undo
904 945
 	global $context;
905 946
 
906 947
 	// Set the table count if needed.
907
-	if (empty($context['table_count']))
908
-		$context['table_count'] = 0;
948
+	if (empty($context['table_count'])) {
949
+			$context['table_count'] = 0;
950
+	}
909 951
 
910 952
 	// Create the table!
911 953
 	$context['tables'][$context['table_count']] = array(
@@ -955,16 +997,18 @@  discard block
 block discarded – undo
955 997
 	global $context;
956 998
 
957 999
 	// No tables? Create one even though we are probably already in a bad state!
958
-	if (empty($context['table_count']))
959
-		newTable();
1000
+	if (empty($context['table_count'])) {
1001
+			newTable();
1002
+	}
960 1003
 
961 1004
 	// Specific table?
962
-	if ($custom_table !== null && !isset($context['tables'][$custom_table]))
963
-		return false;
964
-	elseif ($custom_table !== null)
965
-		$table = $custom_table;
966
-	else
967
-		$table = $context['current_table'];
1005
+	if ($custom_table !== null && !isset($context['tables'][$custom_table])) {
1006
+			return false;
1007
+	} elseif ($custom_table !== null) {
1008
+			$table = $custom_table;
1009
+	} else {
1010
+			$table = $context['current_table'];
1011
+	}
968 1012
 
969 1013
 	// If we have keys, sanitise the data...
970 1014
 	if (!empty($context['keys']))
@@ -976,11 +1020,11 @@  discard block
 block discarded – undo
976 1020
 				'v' => empty($inc_data[$key]) ? $context['tables'][$table]['default_value'] : $inc_data[$key],
977 1021
 			);
978 1022
 			// Special "hack" the adding separators when doing data by column.
979
-			if (substr($key, 0, 5) == '#sep#')
980
-				$data[$key]['separator'] = true;
1023
+			if (substr($key, 0, 5) == '#sep#') {
1024
+							$data[$key]['separator'] = true;
1025
+			}
981 1026
 		}
982
-	}
983
-	else
1027
+	} else
984 1028
 	{
985 1029
 		$data = $inc_data;
986 1030
 		foreach ($data as $key => $value)
@@ -988,8 +1032,9 @@  discard block
 block discarded – undo
988 1032
 			$data[$key] = array(
989 1033
 				'v' => $value,
990 1034
 			);
991
-			if (substr($key, 0, 5) == '#sep#')
992
-				$data[$key]['separator'] = true;
1035
+			if (substr($key, 0, 5) == '#sep#') {
1036
+							$data[$key]['separator'] = true;
1037
+			}
993 1038
 		}
994 1039
 	}
995 1040
 
@@ -1002,8 +1047,9 @@  discard block
 block discarded – undo
1002 1047
 	// Otherwise, tricky!
1003 1048
 	else
1004 1049
 	{
1005
-		foreach ($data as $key => $item)
1006
-			$context['tables'][$table]['data'][$key][] = $item;
1050
+		foreach ($data as $key => $item) {
1051
+					$context['tables'][$table]['data'][$key][] = $item;
1052
+		}
1007 1053
 	}
1008 1054
 }
1009 1055
 
@@ -1020,16 +1066,18 @@  discard block
 block discarded – undo
1020 1066
 	global $context;
1021 1067
 
1022 1068
 	// No tables - return?
1023
-	if (empty($context['table_count']))
1024
-		return;
1069
+	if (empty($context['table_count'])) {
1070
+			return;
1071
+	}
1025 1072
 
1026 1073
 	// Specific table?
1027
-	if ($custom_table !== null && !isset($context['tables'][$table]))
1028
-		return false;
1029
-	elseif ($custom_table !== null)
1030
-		$table = $custom_table;
1031
-	else
1032
-		$table = $context['current_table'];
1074
+	if ($custom_table !== null && !isset($context['tables'][$table])) {
1075
+			return false;
1076
+	} elseif ($custom_table !== null) {
1077
+			$table = $custom_table;
1078
+	} else {
1079
+			$table = $context['current_table'];
1080
+	}
1033 1081
 
1034 1082
 	// Plumb in the separator
1035 1083
 	$context['tables'][$table]['data'][] = array(0 => array(
@@ -1050,8 +1098,9 @@  discard block
 block discarded – undo
1050 1098
 {
1051 1099
 	global $context;
1052 1100
 
1053
-	if (empty($context['tables']))
1054
-		return;
1101
+	if (empty($context['tables'])) {
1102
+			return;
1103
+	}
1055 1104
 
1056 1105
 	// Loop through each table counting up some basic values, to help with the templating.
1057 1106
 	foreach ($context['tables'] as $id => $table)
@@ -1062,12 +1111,13 @@  discard block
 block discarded – undo
1062 1111
 		$context['tables'][$id]['column_count'] = count($curElement);
1063 1112
 
1064 1113
 		// Work out the rough width - for templates like the print template. Without this we might get funny tables.
1065
-		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto')
1066
-			$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1067
-		elseif ($table['width']['normal'] != 'auto')
1068
-			$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1069
-		else
1070
-			$context['tables'][$id]['max_width'] = 'auto';
1114
+		if ($table['shading']['left'] && $table['width']['shaded'] != 'auto' && $table['width']['normal'] != 'auto') {
1115
+					$context['tables'][$id]['max_width'] = $table['width']['shaded'] + ($context['tables'][$id]['column_count'] - 1) * $table['width']['normal'];
1116
+		} elseif ($table['width']['normal'] != 'auto') {
1117
+					$context['tables'][$id]['max_width'] = $context['tables'][$id]['column_count'] * $table['width']['normal'];
1118
+		} else {
1119
+					$context['tables'][$id]['max_width'] = 'auto';
1120
+		}
1071 1121
 	}
1072 1122
 }
1073 1123
 
@@ -1092,10 +1142,11 @@  discard block
 block discarded – undo
1092 1142
 	global $context;
1093 1143
 
1094 1144
 	// Do we want to use the keys of the keys as the keys? :P
1095
-	if ($reverse)
1096
-		$context['keys'] = array_flip($keys);
1097
-	else
1098
-		$context['keys'] = $keys;
1145
+	if ($reverse) {
1146
+			$context['keys'] = array_flip($keys);
1147
+	} else {
1148
+			$context['keys'] = $keys;
1149
+	}
1099 1150
 
1100 1151
 	// Rows or columns?
1101 1152
 	$context['key_method'] = $method == 'rows' ? 'rows' : 'cols';
Please login to merge, or discard this patch.
Sources/SearchAPI-Standard.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * Standard non full index, non custom index search
Please login to merge, or discard this patch.
Sources/ManageMembers.php 1 patch
Braces   +158 added lines, -116 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main entrance point for the Manage Members screen.
@@ -62,16 +63,18 @@  discard block
 block discarded – undo
62 63
 	$context['activation_numbers'] = array();
63 64
 	$context['awaiting_activation'] = 0;
64 65
 	$context['awaiting_approval'] = 0;
65
-	while ($row = $smcFunc['db_fetch_assoc']($request))
66
-		$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
66
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
67
+			$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
68
+	}
67 69
 	$smcFunc['db_free_result']($request);
68 70
 
69 71
 	foreach ($context['activation_numbers'] as $activation_type => $total_members)
70 72
 	{
71
-		if (in_array($activation_type, array(0, 2)))
72
-			$context['awaiting_activation'] += $total_members;
73
-		elseif (in_array($activation_type, array(3, 4, 5)))
74
-			$context['awaiting_approval'] += $total_members;
73
+		if (in_array($activation_type, array(0, 2))) {
74
+					$context['awaiting_activation'] += $total_members;
75
+		} elseif (in_array($activation_type, array(3, 4, 5))) {
76
+					$context['awaiting_approval'] += $total_members;
77
+		}
75 78
 	}
76 79
 
77 80
 	// For the page header... do we show activation?
@@ -124,8 +127,9 @@  discard block
 block discarded – undo
124 127
 	}
125 128
 	if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve'))
126 129
 	{
127
-		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate'))
128
-			$context['tabs']['search']['is_last'] = true;
130
+		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) {
131
+					$context['tabs']['search']['is_last'] = true;
132
+		}
129 133
 		unset($context['tabs']['approve']);
130 134
 	}
131 135
 
@@ -157,8 +161,9 @@  discard block
 block discarded – undo
157 161
 		foreach ($_POST['delete'] as $key => $value)
158 162
 		{
159 163
 			// Don't delete yourself, idiot.
160
-			if ($value != $user_info['id'])
161
-				$delete[$key] = (int) $value;
164
+			if ($value != $user_info['id']) {
165
+							$delete[$key] = (int) $value;
166
+			}
162 167
 		}
163 168
 
164 169
 		if (!empty($delete))
@@ -194,17 +199,18 @@  discard block
 block discarded – undo
194 199
 		);
195 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
196 201
 		{
197
-			if ($row['min_posts'] == -1)
198
-				$context['membergroups'][] = array(
202
+			if ($row['min_posts'] == -1) {
203
+							$context['membergroups'][] = array(
199 204
 					'id' => $row['id_group'],
200 205
 					'name' => $row['group_name'],
201 206
 					'can_be_additional' => true
202 207
 				);
203
-			else
204
-				$context['postgroups'][] = array(
208
+			} else {
209
+							$context['postgroups'][] = array(
205 210
 					'id' => $row['id_group'],
206 211
 					'name' => $row['group_name']
207 212
 				);
213
+			}
208 214
 		}
209 215
 		$smcFunc['db_free_result']($request);
210 216
 
@@ -268,14 +274,15 @@  discard block
 block discarded – undo
268 274
 		call_integration_hook('integrate_view_members_params', array(&$params));
269 275
 
270 276
 		$search_params = array();
271
-		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types']))
272
-			$search_params = smf_json_decode(base64_decode($_REQUEST['params']), true);
273
-		elseif (!empty($_POST))
277
+		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) {
278
+					$search_params = smf_json_decode(base64_decode($_REQUEST['params']), true);
279
+		} elseif (!empty($_POST))
274 280
 		{
275 281
 			$search_params['types'] = $_POST['types'];
276
-			foreach ($params as $param_name => $param_info)
277
-				if (isset($_POST[$param_name]))
282
+			foreach ($params as $param_name => $param_info) {
283
+							if (isset($_POST[$param_name]))
278 284
 					$search_params[$param_name] = $_POST[$param_name];
285
+			}
279 286
 		}
280 287
 
281 288
 		$search_url_params = isset($search_params) ? base64_encode(json_encode($search_params)) : null;
@@ -288,18 +295,21 @@  discard block
 block discarded – undo
288 295
 		foreach ($params as $param_name => $param_info)
289 296
 		{
290 297
 			// Not filled in?
291
-			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '')
292
-				continue;
298
+			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') {
299
+							continue;
300
+			}
293 301
 
294 302
 			// Make sure numeric values are really numeric.
295
-			if (in_array($param_info['type'], array('int', 'age')))
296
-				$search_params[$param_name] = (int) $search_params[$param_name];
303
+			if (in_array($param_info['type'], array('int', 'age'))) {
304
+							$search_params[$param_name] = (int) $search_params[$param_name];
305
+			}
297 306
 			// Date values have to match the specified format.
298 307
 			elseif ($param_info['type'] == 'date')
299 308
 			{
300 309
 				// Check if this date format is valid.
301
-				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
302
-					continue;
310
+				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) {
311
+									continue;
312
+				}
303 313
 
304 314
 				$search_params[$param_name] = strtotime($search_params[$param_name]);
305 315
 			}
@@ -308,8 +318,9 @@  discard block
 block discarded – undo
308 318
 			if (!empty($param_info['range']))
309 319
 			{
310 320
 				// Default to '=', just in case...
311
-				if (empty($range_trans[$search_params['types'][$param_name]]))
312
-					$search_params['types'][$param_name] = '=';
321
+				if (empty($range_trans[$search_params['types'][$param_name]])) {
322
+									$search_params['types'][$param_name] = '=';
323
+				}
313 324
 
314 325
 				// Handle special case 'age'.
315 326
 				if ($param_info['type'] == 'age')
@@ -337,29 +348,30 @@  discard block
 block discarded – undo
337 348
 				elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=')
338 349
 				{
339 350
 					$query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400);
351
+				} else {
352
+									$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
340 353
 				}
341
-				else
342
-					$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
343 354
 			}
344 355
 			// Checkboxes.
345 356
 			elseif ($param_info['type'] == 'checkbox')
346 357
 			{
347 358
 				// Each checkbox or no checkbox at all is checked -> ignore.
348
-				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values']))
349
-					continue;
359
+				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) {
360
+									continue;
361
+				}
350 362
 
351 363
 				$query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})';
352 364
 				$where_params[$param_name . '_check'] = $search_params[$param_name];
353
-			}
354
-			else
365
+			} else
355 366
 			{
356 367
 				// Replace the wildcard characters ('*' and '?') into MySQL ones.
357 368
 				$parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')));
358 369
 
359
-				if ($smcFunc['db_case_sensitive'])
360
-					$query_parts[] = '(LOWER(' . implode( ') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
361
-				else
362
-					$query_parts[] = '(' . implode( ' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
370
+				if ($smcFunc['db_case_sensitive']) {
371
+									$query_parts[] = '(LOWER(' . implode( ') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
372
+				} else {
373
+									$query_parts[] = '(' . implode( ' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
374
+				}
363 375
 				$where_params[$param_name . '_normal'] = '%' . $parameter . '%';
364 376
 			}
365 377
 		}
@@ -375,16 +387,18 @@  discard block
 block discarded – undo
375 387
 		}
376 388
 
377 389
 		// Additional membergroups (these are only relevant if not all primary groups where selected!).
378
-		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1])))
379
-			foreach ($search_params['membergroups'][2] as $mg)
390
+		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) {
391
+					foreach ($search_params['membergroups'][2] as $mg)
380 392
 			{
381 393
 				$mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0';
394
+		}
382 395
 				$where_params['add_group_' . $mg] = $mg;
383 396
 			}
384 397
 
385 398
 		// Combine the one or two membergroup parts into one query part linked with an OR.
386
-		if (!empty($mg_query_parts))
387
-			$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
399
+		if (!empty($mg_query_parts)) {
400
+					$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
401
+		}
388 402
 
389 403
 		// Get all selected post count related membergroups.
390 404
 		if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups']))
@@ -396,9 +410,9 @@  discard block
 block discarded – undo
396 410
 		// Construct the where part of the query.
397 411
 		$where = empty($query_parts) ? '1=1' : implode('
398 412
 			AND ', $query_parts);
413
+	} else {
414
+			$search_url_params = null;
399 415
 	}
400
-	else
401
-		$search_url_params = null;
402 416
 
403 417
 	// Construct the additional URL part with the query info in it.
404 418
 	$context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : '';
@@ -521,28 +535,32 @@  discard block
 block discarded – undo
521 535
 					'function' => function ($rowData) use ($txt)
522 536
 					{
523 537
 						// Calculate number of days since last online.
524
-						if (empty($rowData['last_login']))
525
-							$difference = $txt['never'];
526
-						else
538
+						if (empty($rowData['last_login'])) {
539
+													$difference = $txt['never'];
540
+						} else
527 541
 						{
528 542
 							$num_days_difference = jeffsdatediff($rowData['last_login']);
529 543
 
530 544
 							// Today.
531
-							if (empty($num_days_difference))
532
-								$difference = $txt['viewmembers_today'];
545
+							if (empty($num_days_difference)) {
546
+															$difference = $txt['viewmembers_today'];
547
+							}
533 548
 
534 549
 							// Yesterday.
535
-							elseif ($num_days_difference == 1)
536
-								$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
550
+							elseif ($num_days_difference == 1) {
551
+															$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
552
+							}
537 553
 
538 554
 							// X days ago.
539
-							else
540
-								$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
555
+							else {
556
+															$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
557
+							}
541 558
 						}
542 559
 
543 560
 						// Show it in italics if they're not activated...
544
-						if ($rowData['is_activated'] % 10 != 1)
545
-							$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
561
+						if ($rowData['is_activated'] % 10 != 1) {
562
+													$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
563
+						}
546 564
 
547 565
 						return $difference;
548 566
 					},
@@ -594,8 +612,9 @@  discard block
 block discarded – undo
594 612
 	);
595 613
 
596 614
 	// Without enough permissions, don't show 'delete members' checkboxes.
597
-	if (!allowedTo('profile_remove_any'))
598
-		unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
615
+	if (!allowedTo('profile_remove_any')) {
616
+			unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
617
+	}
599 618
 
600 619
 	require_once($sourcedir . '/Subs-List.php');
601 620
 	createList($listOptions);
@@ -638,17 +657,18 @@  discard block
 block discarded – undo
638 657
 	);
639 658
 	while ($row = $smcFunc['db_fetch_assoc']($request))
640 659
 	{
641
-		if ($row['min_posts'] == -1)
642
-			$context['membergroups'][] = array(
660
+		if ($row['min_posts'] == -1) {
661
+					$context['membergroups'][] = array(
643 662
 				'id' => $row['id_group'],
644 663
 				'name' => $row['group_name'],
645 664
 				'can_be_additional' => true
646 665
 			);
647
-		else
648
-			$context['postgroups'][] = array(
666
+		} else {
667
+					$context['postgroups'][] = array(
649 668
 				'id' => $row['id_group'],
650 669
 				'name' => $row['group_name']
651 670
 			);
671
+		}
652 672
 	}
653 673
 	$smcFunc['db_free_result']($request);
654 674
 
@@ -675,8 +695,9 @@  discard block
 block discarded – undo
675 695
 	$context['page_title'] = $txt['admin_members'];
676 696
 	$context['sub_template'] = 'admin_browse';
677 697
 	$context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
678
-	if (isset($context['tabs'][$context['browse_type']]))
679
-		$context['tabs'][$context['browse_type']]['is_selected'] = true;
698
+	if (isset($context['tabs'][$context['browse_type']])) {
699
+			$context['tabs'][$context['browse_type']]['is_selected'] = true;
700
+	}
680 701
 
681 702
 	// Allowed filters are those we can have, in theory.
682 703
 	$context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
@@ -687,18 +708,20 @@  discard block
 block discarded – undo
687 708
 	foreach ($context['activation_numbers'] as $type => $amount)
688 709
 	{
689 710
 		// We have some of these...
690
-		if (in_array($type, $context['allowed_filters']) && $amount > 0)
691
-			$context['available_filters'][] = array(
711
+		if (in_array($type, $context['allowed_filters']) && $amount > 0) {
712
+					$context['available_filters'][] = array(
692 713
 				'type' => $type,
693 714
 				'amount' => $amount,
694 715
 				'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
695 716
 				'selected' => $type == $context['current_filter']
696 717
 			);
718
+		}
697 719
 	}
698 720
 
699 721
 	// If the filter was not sent, set it to whatever has people in it!
700
-	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
701
-		$context['current_filter'] = $context['available_filters'][0]['type'];
722
+	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) {
723
+			$context['current_filter'] = $context['available_filters'][0]['type'];
724
+	}
702 725
 
703 726
 	// This little variable is used to determine if we should flag where we are looking.
704 727
 	$context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
@@ -713,44 +736,47 @@  discard block
 block discarded – undo
713 736
 	);
714 737
 
715 738
 	// Are we showing duplicate information?
716
-	if (isset($_GET['showdupes']))
717
-		$_SESSION['showdupes'] = (int) $_GET['showdupes'];
739
+	if (isset($_GET['showdupes'])) {
740
+			$_SESSION['showdupes'] = (int) $_GET['showdupes'];
741
+	}
718 742
 	$context['show_duplicates'] = !empty($_SESSION['showdupes']);
719 743
 
720 744
 	// Determine which actions we should allow on this page.
721 745
 	if ($context['browse_type'] == 'approve')
722 746
 	{
723 747
 		// If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
724
-		if ($context['current_filter'] == 4)
725
-			$context['allowed_actions'] = array(
748
+		if ($context['current_filter'] == 4) {
749
+					$context['allowed_actions'] = array(
726 750
 				'reject' => $txt['admin_browse_w_approve_deletion'],
727 751
 				'ok' => $txt['admin_browse_w_reject'],
728 752
 			);
729
-		else
730
-			$context['allowed_actions'] = array(
753
+		} else {
754
+					$context['allowed_actions'] = array(
731 755
 				'ok' => $txt['admin_browse_w_approve'],
732 756
 				'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
733 757
 				'require_activation' => $txt['admin_browse_w_approve_require_activate'],
734 758
 				'reject' => $txt['admin_browse_w_reject'],
735 759
 				'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
736 760
 			);
737
-	}
738
-	elseif ($context['browse_type'] == 'activate')
739
-		$context['allowed_actions'] = array(
761
+		}
762
+	} elseif ($context['browse_type'] == 'activate') {
763
+			$context['allowed_actions'] = array(
740 764
 			'ok' => $txt['admin_browse_w_activate'],
741 765
 			'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
742 766
 			'delete' => $txt['admin_browse_w_delete'],
743 767
 			'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
744 768
 			'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
745 769
 		);
770
+	}
746 771
 
747 772
 	// Create an option list for actions allowed to be done with selected members.
748 773
 	$allowed_actions = '
749 774
 			<option selected value="">' . $txt['admin_browse_with_selected'] . ':</option>
750 775
 			<option value="" disabled>-----------------------------</option>';
751
-	foreach ($context['allowed_actions'] as $key => $desc)
752
-		$allowed_actions .= '
776
+	foreach ($context['allowed_actions'] as $key => $desc) {
777
+			$allowed_actions .= '
753 778
 			<option value="' . $key . '">' . $desc . '</option>';
779
+	}
754 780
 
755 781
 	// Setup the Javascript function for selecting an action for the list.
756 782
 	$javascript = '
@@ -762,15 +788,16 @@  discard block
 block discarded – undo
762 788
 			var message = "";';
763 789
 
764 790
 	// We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
765
-	if ($context['current_filter'] == 4)
766
-		$javascript .= '
791
+	if ($context['current_filter'] == 4) {
792
+			$javascript .= '
767 793
 			if (document.forms.postForm.todo.value.indexOf("reject") != -1)
768 794
 				message = "' . $txt['admin_browse_w_delete'] . '";
769 795
 			else
770 796
 				message = "' . $txt['admin_browse_w_reject'] . '";';
797
+	}
771 798
 	// Otherwise a nice standard message.
772
-	else
773
-		$javascript .= '
799
+	else {
800
+			$javascript .= '
774 801
 			if (document.forms.postForm.todo.value.indexOf("delete") != -1)
775 802
 				message = "' . $txt['admin_browse_w_delete'] . '";
776 803
 			else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
@@ -779,6 +806,7 @@  discard block
 block discarded – undo
779 806
 				message = "' . $txt['admin_browse_w_remind'] . '";
780 807
 			else
781 808
 				message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
809
+	}
782 810
 	$javascript .= '
783 811
 			if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
784 812
 				document.forms.postForm.submit();
@@ -911,10 +939,11 @@  discard block
 block discarded – undo
911 939
 						$member_links = array();
912 940
 						foreach ($rowData['duplicate_members'] as $member)
913 941
 						{
914
-							if ($member['id'])
915
-								$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
916
-							else
917
-								$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
942
+							if ($member['id']) {
943
+															$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
944
+							} else {
945
+															$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
946
+							}
918 947
 						}
919 948
 						return implode (', ', $member_links);
920 949
 					},
@@ -963,14 +992,16 @@  discard block
 block discarded – undo
963 992
 	);
964 993
 
965 994
 	// Pick what column to actually include if we're showing duplicates.
966
-	if ($context['show_duplicates'])
967
-		unset($listOptions['columns']['email']);
968
-	else
969
-		unset($listOptions['columns']['duplicates']);
995
+	if ($context['show_duplicates']) {
996
+			unset($listOptions['columns']['email']);
997
+	} else {
998
+			unset($listOptions['columns']['duplicates']);
999
+	}
970 1000
 
971 1001
 	// Only show hostname on duplicates as it takes a lot of time.
972
-	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
973
-		unset($listOptions['columns']['hostname']);
1002
+	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) {
1003
+			unset($listOptions['columns']['hostname']);
1004
+	}
974 1005
 
975 1006
 	// Is there any need to show filters?
976 1007
 	if (isset($context['available_filters']) && count($context['available_filters']) > 1)
@@ -978,9 +1009,10 @@  discard block
 block discarded – undo
978 1009
 		$filterOptions = '
979 1010
 			<strong>' . $txt['admin_browse_filter_by'] . ':</strong>
980 1011
 			<select name="filter" onchange="this.form.submit();">';
981
-		foreach ($context['available_filters'] as $filter)
982
-			$filterOptions .= '
1012
+		foreach ($context['available_filters'] as $filter) {
1013
+					$filterOptions .= '
983 1014
 				<option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
1015
+		}
984 1016
 		$filterOptions .= '
985 1017
 			</select>
986 1018
 			<noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button_submit"></noscript>';
@@ -992,12 +1024,13 @@  discard block
 block discarded – undo
992 1024
 	}
993 1025
 
994 1026
 	// What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
995
-	if (!empty($context['show_filter']) && !empty($context['available_filters']))
996
-		$listOptions['additional_rows'][] = array(
1027
+	if (!empty($context['show_filter']) && !empty($context['available_filters'])) {
1028
+			$listOptions['additional_rows'][] = array(
997 1029
 			'position' => 'above_column_headers',
998 1030
 			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'],
999 1031
 			'class' => 'smalltext floatright',
1000 1032
 		);
1033
+	}
1001 1034
 
1002 1035
 	// Now that we have all the options, create the list.
1003 1036
 	require_once($sourcedir . '/Subs-List.php');
@@ -1028,12 +1061,14 @@  discard block
 block discarded – undo
1028 1061
 	$current_filter = (int) $_REQUEST['orig_filter'];
1029 1062
 
1030 1063
 	// If we are applying a filter do just that - then redirect.
1031
-	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
1032
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1064
+	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) {
1065
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1066
+	}
1033 1067
 
1034 1068
 	// Nothing to do?
1035
-	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
1036
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1069
+	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) {
1070
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1071
+	}
1037 1072
 
1038 1073
 	// Are we dealing with members who have been waiting for > set amount of time?
1039 1074
 	if (isset($_POST['time_passed']))
@@ -1046,8 +1081,9 @@  discard block
 block discarded – undo
1046 1081
 	else
1047 1082
 	{
1048 1083
 		$members = array();
1049
-		foreach ($_POST['todoAction'] as $id)
1050
-			$members[] = (int) $id;
1084
+		foreach ($_POST['todoAction'] as $id) {
1085
+					$members[] = (int) $id;
1086
+		}
1051 1087
 		$condition = '
1052 1088
 			AND id_member IN ({array_int:members})';
1053 1089
 	}
@@ -1068,8 +1104,9 @@  discard block
 block discarded – undo
1068 1104
 	$member_count = $smcFunc['db_num_rows']($request);
1069 1105
 
1070 1106
 	// If no results then just return!
1071
-	if ($member_count == 0)
1072
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1107
+	if ($member_count == 0) {
1108
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1109
+	}
1073 1110
 
1074 1111
 	$member_info = array();
1075 1112
 	$members = array();
@@ -1108,8 +1145,9 @@  discard block
 block discarded – undo
1108 1145
 		// Do we have to let the integration code know about the activations?
1109 1146
 		if (!empty($modSettings['integrate_activate']))
1110 1147
 		{
1111
-			foreach ($member_info as $member)
1112
-				call_integration_hook('integrate_activate', array($member['username']));
1148
+			foreach ($member_info as $member) {
1149
+							call_integration_hook('integrate_activate', array($member['username']));
1150
+			}
1113 1151
 		}
1114 1152
 
1115 1153
 		// Check for email.
@@ -1240,20 +1278,23 @@  discard block
 block discarded – undo
1240 1278
 		$log_inserts = array();
1241 1279
 
1242 1280
 		require_once($sourcedir . '/Logging.php');
1243
-		foreach ($member_info as $member)
1244
-			logAction($log_action, array('member' => $member['id']), 'admin');
1281
+		foreach ($member_info as $member) {
1282
+					logAction($log_action, array('member' => $member['id']), 'admin');
1283
+		}
1245 1284
 	}
1246 1285
 
1247 1286
 	// Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
1248
-	if (in_array($current_filter, array(3, 4, 5)))
1249
-		updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1287
+	if (in_array($current_filter, array(3, 4, 5))) {
1288
+			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1289
+	}
1250 1290
 
1251 1291
 	// Update the member's stats. (but, we know the member didn't change their name.)
1252 1292
 	updateStats('member', false);
1253 1293
 
1254 1294
 	// If they haven't been deleted, update the post group statistics on them...
1255
-	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
1256
-		updateStats('postgroups', $members);
1295
+	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) {
1296
+			updateStats('postgroups', $members);
1297
+	}
1257 1298
 
1258 1299
 	redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1259 1300
 }
@@ -1278,10 +1319,11 @@  discard block
 block discarded – undo
1278 1319
 	$dis = time() - $old;
1279 1320
 
1280 1321
 	// Before midnight?
1281
-	if ($dis < $sinceMidnight)
1282
-		return 0;
1283
-	else
1284
-		$dis -= $sinceMidnight;
1322
+	if ($dis < $sinceMidnight) {
1323
+			return 0;
1324
+	} else {
1325
+			$dis -= $sinceMidnight;
1326
+	}
1285 1327
 
1286 1328
 	// Divide out the seconds in a day to get the number of days.
1287 1329
 	return ceil($dis / (24 * 60 * 60));
Please login to merge, or discard this patch.
Sources/DbPackages-postgresql.php 1 patch
Braces   +110 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * Add the file functions to the $smcFunc array.
@@ -52,8 +53,9 @@  discard block
 block discarded – undo
52 53
 		'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages',
53 54
 		'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys',
54 55
 		'themes', 'topics');
55
-	foreach ($reservedTables as $k => $table_name)
56
-		$reservedTables[$k] = strtolower($db_prefix . $table_name);
56
+	foreach ($reservedTables as $k => $table_name) {
57
+			$reservedTables[$k] = strtolower($db_prefix . $table_name);
58
+	}
57 59
 
58 60
 	// We in turn may need the extra stuff.
59 61
 	db_extend('extra');
@@ -102,8 +104,9 @@  discard block
 block discarded – undo
102 104
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
103 105
 
104 106
 	// First - no way do we touch SMF tables.
105
-	if (in_array(strtolower($table_name), $reservedTables))
106
-		return false;
107
+	if (in_array(strtolower($table_name), $reservedTables)) {
108
+			return false;
109
+	}
107 110
 
108 111
 	// Log that we'll want to remove this on uninstall.
109 112
 	$db_package_log[] = array('remove_table', $table_name);
@@ -113,10 +116,11 @@  discard block
 block discarded – undo
113 116
 	if (in_array($full_table_name, $tables))
114 117
 	{
115 118
 		// This is a sad day... drop the table? If not, return false (error) by default.
116
-		if ($if_exists == 'overwrite')
117
-			$smcFunc['db_drop_table']($table_name);
118
-		else
119
-			return $if_exists == 'ignore';
119
+		if ($if_exists == 'overwrite') {
120
+					$smcFunc['db_drop_table']($table_name);
121
+		} else {
122
+					return $if_exists == 'ignore';
123
+		}
120 124
 	}
121 125
 
122 126
 	// If we've got this far - good news - no table exists. We can build our own!
@@ -134,17 +138,18 @@  discard block
 block discarded – undo
134 138
 				)
135 139
 			);
136 140
 			$default = 'default nextval(\'' . $table_name . '_seq\')';
141
+		} elseif (isset($column['default']) && $column['default'] !== null) {
142
+					$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
143
+		} else {
144
+					$default = '';
137 145
 		}
138
-		elseif (isset($column['default']) && $column['default'] !== null)
139
-			$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
140
-		else
141
-			$default = '';
142 146
 
143 147
 		// Sort out the size...
144 148
 		$column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
145 149
 		list ($type, $size) = $smcFunc['db_calculate_type']($column['type'], $column['size']);
146
-		if ($size !== null)
147
-			$type = $type . '(' . $size . ')';
150
+		if ($size !== null) {
151
+					$type = $type . '(' . $size . ')';
152
+		}
148 153
 
149 154
 		// Now just put it together!
150 155
 		$table_query .= "\n\t\"" . $column['name'] . '" ' . $type . ' ' . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default . ',';
@@ -157,19 +162,21 @@  discard block
 block discarded – undo
157 162
 		$columns = implode(',', $index['columns']);
158 163
 
159 164
 		// Primary goes in the table...
160
-		if (isset($index['type']) && $index['type'] == 'primary')
161
-			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
162
-		else
165
+		if (isset($index['type']) && $index['type'] == 'primary') {
166
+					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
167
+		} else
163 168
 		{
164
-			if (empty($index['name']))
165
-				$index['name'] = implode('_', $index['columns']);
169
+			if (empty($index['name'])) {
170
+							$index['name'] = implode('_', $index['columns']);
171
+			}
166 172
 			$index_queries[] = 'CREATE ' . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $table_name . '_' . $index['name'] . ' ON ' . $table_name . ' (' . $columns . ')';
167 173
 		}
168 174
 	}
169 175
 
170 176
 	// No trailing commas!
171
-	if (substr($table_query, -1) == ',')
172
-		$table_query = substr($table_query, 0, -1);
177
+	if (substr($table_query, -1) == ',') {
178
+			$table_query = substr($table_query, 0, -1);
179
+	}
173 180
 
174 181
 	$table_query .= ')';
175 182
 
@@ -180,12 +187,13 @@  discard block
 block discarded – undo
180 187
 		)
181 188
 	);
182 189
 	// And the indexes...
183
-	foreach ($index_queries as $query)
184
-		$smcFunc['db_query']('', $query,
190
+	foreach ($index_queries as $query) {
191
+			$smcFunc['db_query']('', $query,
185 192
 		array(
186 193
 			'security_override' => true,
187 194
 		)
188 195
 	);
196
+	}
189 197
 
190 198
 	// Go, go power rangers!
191 199
 	$smcFunc['db_transaction']('commit');
@@ -213,8 +221,9 @@  discard block
 block discarded – undo
213 221
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
214 222
 
215 223
 	// God no - dropping one of these = bad.
216
-	if (in_array(strtolower($table_name), $reservedTables))
217
-		return false;
224
+	if (in_array(strtolower($table_name), $reservedTables)) {
225
+			return false;
226
+	}
218 227
 
219 228
 	// Does it exist?
220 229
 	if (in_array($full_table_name, $smcFunc['db_list_tables']()))
@@ -272,21 +281,24 @@  discard block
 block discarded – undo
272 281
 
273 282
 	// Does it exist - if so don't add it again!
274 283
 	$columns = $smcFunc['db_list_columns']($table_name, false);
275
-	foreach ($columns as $column)
276
-		if ($column == $column_info['name'])
284
+	foreach ($columns as $column) {
285
+			if ($column == $column_info['name'])
277 286
 		{
278 287
 			// If we're going to overwrite then use change column.
279 288
 			if ($if_exists == 'update')
280 289
 				return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
281
-			else
282
-				return false;
290
+	}
291
+			else {
292
+							return false;
293
+			}
283 294
 		}
284 295
 
285 296
 	// Get the specifics...
286 297
 	$column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null;
287 298
 	list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
288
-	if ($size !== null)
289
-		$type = $type . '(' . $size . ')';
299
+	if ($size !== null) {
300
+			$type = $type . '(' . $size . ')';
301
+	}
290 302
 
291 303
 	// Now add the thing!
292 304
 	$query = '
@@ -301,11 +313,12 @@  discard block
 block discarded – undo
301 313
 	// If there's more attributes they need to be done via a change on PostgreSQL.
302 314
 	unset($column_info['type'], $column_info['size']);
303 315
 
304
-	if (count($column_info) != 1)
305
-		return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
306
-	else
307
-		return true;
308
-}
316
+	if (count($column_info) != 1) {
317
+			return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
318
+	} else {
319
+			return true;
320
+	}
321
+	}
309 322
 
310 323
 /**
311 324
  * Removes a column.
@@ -324,8 +337,8 @@  discard block
 block discarded – undo
324 337
 
325 338
 	// Does it exist?
326 339
 	$columns = $smcFunc['db_list_columns']($table_name, true);
327
-	foreach ($columns as $column)
328
-		if ($column['name'] == $column_name)
340
+	foreach ($columns as $column) {
341
+			if ($column['name'] == $column_name)
329 342
 		{
330 343
 			// If there is an auto we need remove it!
331 344
 			if ($column['auto'])
@@ -335,6 +348,7 @@  discard block
 block discarded – undo
335 348
 						'security_override' => true,
336 349
 					)
337 350
 				);
351
+	}
338 352
 
339 353
 			$smcFunc['db_query']('', '
340 354
 				ALTER TABLE ' . $table_name . '
@@ -369,13 +383,15 @@  discard block
 block discarded – undo
369 383
 	// Check it does exist!
370 384
 	$columns = $smcFunc['db_list_columns']($table_name, true);
371 385
 	$old_info = null;
372
-	foreach ($columns as $column)
373
-		if ($column['name'] == $old_column)
386
+	foreach ($columns as $column) {
387
+			if ($column['name'] == $old_column)
374 388
 			$old_info = $column;
389
+	}
375 390
 
376 391
 	// Nothing?
377
-	if ($old_info == null)
378
-		return false;
392
+	if ($old_info == null) {
393
+			return false;
394
+	}
379 395
 
380 396
 	// Now we check each bit individually and ALTER as required.
381 397
 	if (isset($column_info['name']) && $column_info['name'] != $old_column)
@@ -432,8 +448,9 @@  discard block
 block discarded – undo
432 448
 	{
433 449
 		$column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null;
434 450
 		list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
435
-		if ($size !== null)
436
-			$type = $type . '(' . $size . ')';
451
+		if ($size !== null) {
452
+					$type = $type . '(' . $size . ')';
453
+		}
437 454
 
438 455
 		// The alter is a pain.
439 456
 		$smcFunc['db_transaction']('begin');
@@ -527,21 +544,23 @@  discard block
 block discarded – undo
527 544
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
528 545
 
529 546
 	// No columns = no index.
530
-	if (empty($index_info['columns']))
531
-		return false;
547
+	if (empty($index_info['columns'])) {
548
+			return false;
549
+	}
532 550
 	$columns = implode(',', $index_info['columns']);
533 551
 
534 552
 	// No name - make it up!
535 553
 	if (empty($index_info['name']))
536 554
 	{
537 555
 		// No need for primary.
538
-		if (isset($index_info['type']) && $index_info['type'] == 'primary')
539
-			$index_info['name'] = '';
540
-		else
541
-			$index_info['name'] = $table_name . implode('_', $index_info['columns']);
556
+		if (isset($index_info['type']) && $index_info['type'] == 'primary') {
557
+					$index_info['name'] = '';
558
+		} else {
559
+					$index_info['name'] = $table_name . implode('_', $index_info['columns']);
560
+		}
561
+	} else {
562
+			$index_info['name'] = $table_name . $index_info['name'];
542 563
 	}
543
-	else
544
-		$index_info['name'] = $table_name . $index_info['name'];
545 564
 
546 565
 	// Log that we are going to want to remove this!
547 566
 	$db_package_log[] = array('remove_index', $table_name, $index_info['name']);
@@ -554,10 +573,11 @@  discard block
 block discarded – undo
554 573
 		if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary'))
555 574
 		{
556 575
 			// If we want to overwrite simply remove the current one then continue.
557
-			if ($if_exists != 'update' || $index['type'] == 'primary')
558
-				return false;
559
-			else
560
-				$smcFunc['db_remove_index']($table_name, $index_info['name']);
576
+			if ($if_exists != 'update' || $index['type'] == 'primary') {
577
+							return false;
578
+			} else {
579
+							$smcFunc['db_remove_index']($table_name, $index_info['name']);
580
+			}
561 581
 		}
562 582
 	}
563 583
 
@@ -571,8 +591,7 @@  discard block
 block discarded – undo
571 591
 				'security_override' => true,
572 592
 			)
573 593
 		);
574
-	}
575
-	else
594
+	} else
576 595
 	{
577 596
 		$smcFunc['db_query']('', '
578 597
 			CREATE ' . (isset($index_info['type']) && $index_info['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $index_info['name'] . ' ON ' . $table_name . ' (' . $columns . ')',
@@ -600,8 +619,9 @@  discard block
 block discarded – undo
600 619
 
601 620
 	// Better exist!
602 621
 	$indexes = $smcFunc['db_list_indexes']($table_name, true);
603
-	if ($index_name != 'primary')
604
-		$index_name = $table_name . '_' . $index_name;
622
+	if ($index_name != 'primary') {
623
+			$index_name = $table_name . '_' . $index_name;
624
+	}
605 625
 
606 626
 	foreach ($indexes as $index)
607 627
 	{
@@ -665,8 +685,7 @@  discard block
 block discarded – undo
665 685
 			'datetime' => 'timestamp without time zone',
666 686
 			'timestamp' => 'timestamp without time zone',
667 687
 		);
668
-	}
669
-	else
688
+	} else
670 689
 	{
671 690
 		$types = array(
672 691
 			'character varying' => 'varchar',
@@ -682,14 +701,16 @@  discard block
 block discarded – undo
682 701
 	// Got it? Change it!
683 702
 	if (isset($types[$type_name]))
684 703
 	{
685
-		if ($type_name == 'tinytext')
686
-			$type_size = 255;
704
+		if ($type_name == 'tinytext') {
705
+					$type_size = 255;
706
+		}
687 707
 		$type_name = $types[$type_name];
688 708
 	}
689 709
 
690 710
 	// Only char fields got size
691
-	if (strpos($type_name, 'char') === false)
692
-			$type_size = null;
711
+	if (strpos($type_name, 'char') === false) {
712
+				$type_size = null;
713
+	}
693 714
 
694 715
 
695 716
 	return array($type_name, $type_size);
@@ -744,8 +765,7 @@  discard block
 block discarded – undo
744 765
 		if (!$detail)
745 766
 		{
746 767
 			$columns[] = $row['column_name'];
747
-		}
748
-		else
768
+		} else
749 769
 		{
750 770
 			$auto = false;
751 771
 			// What is the default?
@@ -753,11 +773,11 @@  discard block
 block discarded – undo
753 773
 			{
754 774
 				$default = null;
755 775
 				$auto = true;
776
+			} elseif (trim($row['column_default']) != '') {
777
+							$default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::'));
778
+			} else {
779
+							$default = null;
756 780
 			}
757
-			elseif (trim($row['column_default']) != '')
758
-				$default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::'));
759
-			else
760
-				$default = null;
761 781
 
762 782
 			// Make the type generic.
763 783
 			list ($type, $size) = $smcFunc['db_calculate_type']($row['data_type'], $row['character_maximum_length'], true);
@@ -808,26 +828,30 @@  discard block
 block discarded – undo
808 828
 	while ($row = $smcFunc['db_fetch_assoc']($result))
809 829
 	{
810 830
 		// Try get the columns that make it up.
811
-		if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0)
812
-			continue;
831
+		if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) {
832
+					continue;
833
+		}
813 834
 
814 835
 		$columns = explode(',', $matches[1]);
815 836
 
816
-		if (empty($columns))
817
-			continue;
837
+		if (empty($columns)) {
838
+					continue;
839
+		}
818 840
 
819
-		foreach ($columns as $k => $v)
820
-			$columns[$k] = trim($v);
841
+		foreach ($columns as $k => $v) {
842
+					$columns[$k] = trim($v);
843
+		}
821 844
 
822 845
 		// Fix up the name to be consistent cross databases
823
-		if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1)
824
-			$row['name'] = 'PRIMARY';
825
-		else
826
-			$row['name'] = str_replace($table_name . '_', '', $row['name']);
846
+		if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) {
847
+					$row['name'] = 'PRIMARY';
848
+		} else {
849
+					$row['name'] = str_replace($table_name . '_', '', $row['name']);
850
+		}
827 851
 
828
-		if (!$detail)
829
-			$indexes[] = $row['name'];
830
-		else
852
+		if (!$detail) {
853
+					$indexes[] = $row['name'];
854
+		} else
831 855
 		{
832 856
 			$indexes[$row['name']] = array(
833 857
 				'name' => $row['name'],
Please login to merge, or discard this patch.
Sources/Profile-Modify.php 1 patch
Braces   +693 added lines, -519 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 3
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 defines every profile field known to man.
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $sourcedir, $profile_vars;
30 31
 
31 32
 	// Don't load this twice!
32
-	if (!empty($profile_fields) && !$force_reload)
33
-		return;
33
+	if (!empty($profile_fields) && !$force_reload) {
34
+			return;
35
+	}
34 36
 
35 37
 	/* This horrific array defines all the profile fields in the whole world!
36 38
 		In general each "field" has one array - the key of which is the database column name associated with said field. Each item
@@ -103,13 +105,14 @@  discard block
 block discarded – undo
103 105
 				if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
104 106
 				{
105 107
 					// Set to blank?
106
-					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
107
-						$value = '0001-01-01';
108
-					else
109
-						$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
108
+					if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) {
109
+											$value = '0001-01-01';
110
+					} else {
111
+											$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01';
112
+					}
113
+				} else {
114
+									$value = '0001-01-01';
110 115
 				}
111
-				else
112
-					$value = '0001-01-01';
113 116
 
114 117
 				$profile_vars['birthdate'] = $value;
115 118
 				$cur_profile['birthdate'] = $value;
@@ -127,8 +130,7 @@  discard block
 block discarded – undo
127 130
 				{
128 131
 					$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '0001-01-01';
129 132
 					return true;
130
-				}
131
-				else
133
+				} else
132 134
 				{
133 135
 					$value = empty($cur_profile['birthdate']) ? '0001-01-01' : $cur_profile['birthdate'];
134 136
 					return false;
@@ -150,10 +152,11 @@  discard block
 block discarded – undo
150 152
 					return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
151 153
 				}
152 154
 				// As long as it doesn't equal "N/A"...
153
-				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
154
-					$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
155
-				else
156
-					$value = $cur_profile['date_registered'];
155
+				elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) {
156
+									$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
157
+				} else {
158
+									$value = $cur_profile['date_registered'];
159
+				}
157 160
 
158 161
 				return true;
159 162
 			},
@@ -177,8 +180,9 @@  discard block
 block discarded – undo
177 180
 			{
178 181
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
179 182
 
180
-				if (strtolower($value) == strtolower($old_profile['email_address']))
181
-					return false;
183
+				if (strtolower($value) == strtolower($old_profile['email_address'])) {
184
+									return false;
185
+				}
182 186
 
183 187
 				$isValid = profileValidateEmail($value, $context['id_member']);
184 188
 
@@ -254,11 +258,11 @@  discard block
 block discarded – undo
254 258
 
255 259
 				if (isset($context['profile_languages'][$value]))
256 260
 				{
257
-					if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
258
-						$_SESSION['language'] = $value;
261
+					if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) {
262
+											$_SESSION['language'] = $value;
263
+					}
259 264
 					return true;
260
-				}
261
-				else
265
+				} else
262 266
 				{
263 267
 					$value = $cur_profile['lngfile'];
264 268
 					return false;
@@ -282,13 +286,14 @@  discard block
 block discarded – undo
282 286
 
283 287
 					// Maybe they are trying to change their password as well?
284 288
 					$resetPassword = true;
285
-					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
286
-						$resetPassword = false;
289
+					if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) {
290
+											$resetPassword = false;
291
+					}
287 292
 
288 293
 					// Do the reset... this will send them an email too.
289
-					if ($resetPassword)
290
-						resetPassword($context['id_member'], $value);
291
-					elseif ($value !== null)
294
+					if ($resetPassword) {
295
+											resetPassword($context['id_member'], $value);
296
+					} elseif ($value !== null)
292 297
 					{
293 298
 						validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
294 299
 						updateMemberData($context['id_member'], array('member_name' => $value));
@@ -312,20 +317,23 @@  discard block
 block discarded – undo
312 317
 			'input_validate' => function (&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
313 318
 			{
314 319
 				// If we didn't try it then ignore it!
315
-				if ($value == '')
316
-					return false;
320
+				if ($value == '') {
321
+									return false;
322
+				}
317 323
 
318 324
 				// Do the two entries for the password even match?
319
-				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
320
-					return 'bad_new_password';
325
+				if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) {
326
+									return 'bad_new_password';
327
+				}
321 328
 
322 329
 				// Let's get the validation function into play...
323 330
 				require_once($sourcedir . '/Subs-Auth.php');
324 331
 				$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
325 332
 
326 333
 				// Were there errors?
327
-				if ($passwordErrors != null)
328
-					return 'password_' . $passwordErrors;
334
+				if ($passwordErrors != null) {
335
+									return 'password_' . $passwordErrors;
336
+				}
329 337
 
330 338
 				// Set up the new password variable... ready for storage.
331 339
 				$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
@@ -350,8 +358,9 @@  discard block
 block discarded – undo
350 358
 			'permission' => 'profile_blurb',
351 359
 			'input_validate' => function (&$value) use ($smcFunc)
352 360
 			{
353
-				if ($smcFunc['strlen']($value) > 50)
354
-					return 'personal_text_too_long';
361
+				if ($smcFunc['strlen']($value) > 50) {
362
+									return 'personal_text_too_long';
363
+				}
355 364
 
356 365
 				return true;
357 366
 			},
@@ -386,10 +395,11 @@  discard block
 block discarded – undo
386 395
 			'permission' => 'moderate_forum',
387 396
 			'input_validate' => function (&$value)
388 397
 			{
389
-				if (!is_numeric($value))
390
-					return 'digits_only';
391
-				else
392
-					$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
398
+				if (!is_numeric($value)) {
399
+									return 'digits_only';
400
+				} else {
401
+									$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
402
+				}
393 403
 				return true;
394 404
 			},
395 405
 		),
@@ -405,15 +415,16 @@  discard block
 block discarded – undo
405 415
 			{
406 416
 				$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
407 417
 
408
-				if (trim($value) == '')
409
-					return 'no_name';
410
-				elseif ($smcFunc['strlen']($value) > 60)
411
-					return 'name_too_long';
412
-				elseif ($cur_profile['real_name'] != $value)
418
+				if (trim($value) == '') {
419
+									return 'no_name';
420
+				} elseif ($smcFunc['strlen']($value) > 60) {
421
+									return 'name_too_long';
422
+				} elseif ($cur_profile['real_name'] != $value)
413 423
 				{
414 424
 					require_once($sourcedir . '/Subs-Members.php');
415
-					if (isReservedName($value, $context['id_member']))
416
-						return 'name_taken';
425
+					if (isReservedName($value, $context['id_member'])) {
426
+											return 'name_taken';
427
+					}
417 428
 				}
418 429
 				return true;
419 430
 			},
@@ -471,8 +482,9 @@  discard block
 block discarded – undo
471 482
 						'selected' => $set == $context['member']['smiley_set']['id']
472 483
 					);
473 484
 
474
-					if ($context['smiley_sets'][$i]['selected'])
475
-						$context['member']['smiley_set']['name'] = $set_names[$i];
485
+					if ($context['smiley_sets'][$i]['selected']) {
486
+											$context['member']['smiley_set']['name'] = $set_names[$i];
487
+					}
476 488
 				}
477 489
 				return true;
478 490
 			},
@@ -481,8 +493,9 @@  discard block
 block discarded – undo
481 493
 				global $modSettings;
482 494
 
483 495
 				$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
484
-				if (!in_array($value, $smiley_sets) && $value != 'none')
485
-					$value = '';
496
+				if (!in_array($value, $smiley_sets) && $value != 'none') {
497
+									$value = '';
498
+				}
486 499
 				return true;
487 500
 			},
488 501
 		),
@@ -497,8 +510,9 @@  discard block
 block discarded – undo
497 510
 				loadLanguage('Settings');
498 511
 
499 512
 				$context['allow_no_censored'] = false;
500
-				if ($user_info['is_admin'] || $context['user']['is_owner'])
501
-					$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
513
+				if ($user_info['is_admin'] || $context['user']['is_owner']) {
514
+									$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
515
+				}
502 516
 
503 517
 				return true;
504 518
 			},
@@ -545,8 +559,9 @@  discard block
 block discarded – undo
545 559
 			'input_validate' => function ($value)
546 560
 			{
547 561
 				$tz = smf_list_timezones();
548
-				if (!isset($tz[$value]))
549
-					return 'bad_timezone';
562
+				if (!isset($tz[$value])) {
563
+									return 'bad_timezone';
564
+				}
550 565
 
551 566
 				return true;
552 567
 			},
@@ -561,8 +576,9 @@  discard block
 block discarded – undo
561 576
 			'enabled' => !empty($modSettings['titlesEnable']),
562 577
 			'input_validate' => function (&$value) use ($smcFunc)
563 578
 			{
564
-				if ($smcFunc['strlen']($value) > 50)
565
-					return 'user_title_too_long';
579
+				if ($smcFunc['strlen']($value) > 50) {
580
+									return 'user_title_too_long';
581
+				}
566 582
 
567 583
 				return true;
568 584
 			},
@@ -584,10 +600,12 @@  discard block
 block discarded – undo
584 600
 			// Fix the URL...
585 601
 			'input_validate' => function (&$value)
586 602
 			{
587
-				if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
588
-					$value = 'http://' . $value;
589
-				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
590
-					$value = '';
603
+				if (strlen(trim($value)) > 0 && strpos($value, '://') === false) {
604
+									$value = 'http://' . $value;
605
+				}
606
+				if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) {
607
+									$value = '';
608
+				}
591 609
 				return true;
592 610
 			},
593 611
 			'link_with' => 'website',
@@ -601,16 +619,19 @@  discard block
 block discarded – undo
601 619
 	foreach ($profile_fields as $key => $field)
602 620
 	{
603 621
 		// Do we have permission to do this?
604
-		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
605
-			unset($profile_fields[$key]);
622
+		if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) {
623
+					unset($profile_fields[$key]);
624
+		}
606 625
 
607 626
 		// Is it enabled?
608
-		if (isset($field['enabled']) && !$field['enabled'])
609
-			unset($profile_fields[$key]);
627
+		if (isset($field['enabled']) && !$field['enabled']) {
628
+					unset($profile_fields[$key]);
629
+		}
610 630
 
611 631
 		// Is it specifically disabled?
612
-		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
613
-			unset($profile_fields[$key]);
632
+		if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) {
633
+					unset($profile_fields[$key]);
634
+		}
614 635
 	}
615 636
 }
616 637
 
@@ -635,9 +656,10 @@  discard block
 block discarded – undo
635 656
 	loadProfileFields(true);
636 657
 
637 658
 	// First check for any linked sets.
638
-	foreach ($profile_fields as $key => $field)
639
-		if (isset($field['link_with']) && in_array($field['link_with'], $fields))
659
+	foreach ($profile_fields as $key => $field) {
660
+			if (isset($field['link_with']) && in_array($field['link_with'], $fields))
640 661
 			$fields[] = $key;
662
+	}
641 663
 
642 664
 	$i = 0;
643 665
 	$last_type = '';
@@ -649,38 +671,46 @@  discard block
 block discarded – undo
649 671
 			$cur_field = &$profile_fields[$field];
650 672
 
651 673
 			// Does it have a preload and does that preload succeed?
652
-			if (isset($cur_field['preload']) && !$cur_field['preload']())
653
-				continue;
674
+			if (isset($cur_field['preload']) && !$cur_field['preload']()) {
675
+							continue;
676
+			}
654 677
 
655 678
 			// If this is anything but complex we need to do more cleaning!
656 679
 			if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
657 680
 			{
658
-				if (!isset($cur_field['label']))
659
-					$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
681
+				if (!isset($cur_field['label'])) {
682
+									$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
683
+				}
660 684
 
661 685
 				// Everything has a value!
662
-				if (!isset($cur_field['value']))
663
-					$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
686
+				if (!isset($cur_field['value'])) {
687
+									$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
688
+				}
664 689
 
665 690
 				// Any input attributes?
666 691
 				$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
667 692
 			}
668 693
 
669 694
 			// Was there an error with this field on posting?
670
-			if (isset($context['profile_errors'][$field]))
671
-				$cur_field['is_error'] = true;
695
+			if (isset($context['profile_errors'][$field])) {
696
+							$cur_field['is_error'] = true;
697
+			}
672 698
 
673 699
 			// Any javascript stuff?
674
-			if (!empty($cur_field['js_submit']))
675
-				$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
676
-			if (!empty($cur_field['js']))
677
-				$context['profile_javascript'] .= $cur_field['js'];
700
+			if (!empty($cur_field['js_submit'])) {
701
+							$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
702
+			}
703
+			if (!empty($cur_field['js'])) {
704
+							$context['profile_javascript'] .= $cur_field['js'];
705
+			}
678 706
 
679 707
 			// Any template stuff?
680
-			if (!empty($cur_field['prehtml']))
681
-				$context['profile_prehtml'] .= $cur_field['prehtml'];
682
-			if (!empty($cur_field['posthtml']))
683
-				$context['profile_posthtml'] .= $cur_field['posthtml'];
708
+			if (!empty($cur_field['prehtml'])) {
709
+							$context['profile_prehtml'] .= $cur_field['prehtml'];
710
+			}
711
+			if (!empty($cur_field['posthtml'])) {
712
+							$context['profile_posthtml'] .= $cur_field['posthtml'];
713
+			}
684 714
 
685 715
 			// Finally put it into context?
686 716
 			if ($cur_field['type'] != 'hidden')
@@ -713,12 +743,14 @@  discard block
 block discarded – undo
713 743
 	}, false);' : ''), true);
714 744
 
715 745
 	// Any onsubmit javascript?
716
-	if (!empty($context['profile_onsubmit_javascript']))
717
-		addInlineJavaScript($context['profile_onsubmit_javascript'], true);
746
+	if (!empty($context['profile_onsubmit_javascript'])) {
747
+			addInlineJavaScript($context['profile_onsubmit_javascript'], true);
748
+	}
718 749
 
719 750
 	// Any totally custom stuff?
720
-	if (!empty($context['profile_javascript']))
721
-		addInlineJavaScript($context['profile_javascript'], true);
751
+	if (!empty($context['profile_javascript'])) {
752
+			addInlineJavaScript($context['profile_javascript'], true);
753
+	}
722 754
 
723 755
 	// Free up some memory.
724 756
 	unset($profile_fields);
@@ -739,8 +771,9 @@  discard block
 block discarded – undo
739 771
 
740 772
 	// This allows variables to call activities when they save - by default just to reload their settings
741 773
 	$context['profile_execute_on_save'] = array();
742
-	if ($context['user']['is_owner'])
743
-		$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
774
+	if ($context['user']['is_owner']) {
775
+			$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
776
+	}
744 777
 
745 778
 	// Assume we log nothing.
746 779
 	$context['log_changes'] = array();
@@ -748,8 +781,9 @@  discard block
 block discarded – undo
748 781
 	// Cycle through the profile fields working out what to do!
749 782
 	foreach ($profile_fields as $key => $field)
750 783
 	{
751
-		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
752
-			continue;
784
+		if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) {
785
+					continue;
786
+		}
753 787
 
754 788
 		// What gets updated?
755 789
 		$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
@@ -777,12 +811,13 @@  discard block
 block discarded – undo
777 811
 		$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
778 812
 
779 813
 		// Finally, clean up certain types.
780
-		if ($field['cast_type'] == 'int')
781
-			$_POST[$key] = (int) $_POST[$key];
782
-		elseif ($field['cast_type'] == 'float')
783
-			$_POST[$key] = (float) $_POST[$key];
784
-		elseif ($field['cast_type'] == 'check')
785
-			$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
814
+		if ($field['cast_type'] == 'int') {
815
+					$_POST[$key] = (int) $_POST[$key];
816
+		} elseif ($field['cast_type'] == 'float') {
817
+					$_POST[$key] = (float) $_POST[$key];
818
+		} elseif ($field['cast_type'] == 'check') {
819
+					$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
820
+		}
786 821
 
787 822
 		// If we got here we're doing OK.
788 823
 		if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
@@ -793,11 +828,12 @@  discard block
 block discarded – undo
793 828
 			$cur_profile[$key] = $_POST[$key];
794 829
 
795 830
 			// Are we logging it?
796
-			if (!empty($field['log_change']) && isset($old_profile[$key]))
797
-				$context['log_changes'][$key] = array(
831
+			if (!empty($field['log_change']) && isset($old_profile[$key])) {
832
+							$context['log_changes'][$key] = array(
798 833
 					'previous' => $old_profile[$key],
799 834
 					'new' => $_POST[$key],
800 835
 				);
836
+			}
801 837
 		}
802 838
 
803 839
 		// Logging group changes are a bit different...
@@ -830,10 +866,11 @@  discard block
 block discarded – undo
830 866
 				{
831 867
 					foreach ($groups as $id => $group)
832 868
 					{
833
-						if (isset($context['member_groups'][$group]))
834
-							$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
835
-						else
836
-							unset($additional_groups[$type][$id]);
869
+						if (isset($context['member_groups'][$group])) {
870
+													$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
871
+						} else {
872
+													unset($additional_groups[$type][$id]);
873
+						}
837 874
 					}
838 875
 					$additional_groups[$type] = implode(', ', $additional_groups[$type]);
839 876
 				}
@@ -844,10 +881,11 @@  discard block
 block discarded – undo
844 881
 	}
845 882
 
846 883
 	// @todo Temporary
847
-	if ($context['user']['is_owner'])
848
-		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
849
-	else
850
-		$changeOther = allowedTo('profile_extra_any');
884
+	if ($context['user']['is_owner']) {
885
+			$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
886
+	} else {
887
+			$changeOther = allowedTo('profile_extra_any');
888
+	}
851 889
 	if ($changeOther && empty($post_errors))
852 890
 	{
853 891
 		makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
@@ -855,8 +893,9 @@  discard block
 block discarded – undo
855 893
 		{
856 894
 			$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
857 895
 
858
-			if (!empty($custom_fields_errors))
859
-				$post_errors = array_merge($post_errors, $custom_fields_errors);
896
+			if (!empty($custom_fields_errors)) {
897
+							$post_errors = array_merge($post_errors, $custom_fields_errors);
898
+			}
860 899
 		}
861 900
 	}
862 901
 
@@ -883,8 +922,7 @@  discard block
 block discarded – undo
883 922
 	{
884 923
 		$changeIdentity = allowedTo(array('profile_identity_any', 'profile_identity_own', 'profile_password_any', 'profile_password_own'));
885 924
 		$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
886
-	}
887
-	else
925
+	} else
888 926
 	{
889 927
 		$changeIdentity = allowedTo('profile_identity_any', 'profile_signature_any');
890 928
 		$changeOther = allowedTo('profile_extra_any', 'profile_website_any', 'profile_signature_any');
@@ -899,22 +937,25 @@  discard block
 block discarded – undo
899 937
 		'ignore_boards',
900 938
 	);
901 939
 
902
-	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
903
-		$_POST['ignore_brd'] = array();
940
+	if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) {
941
+			$_POST['ignore_brd'] = array();
942
+	}
904 943
 
905 944
 	unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing.  Kinda like our minds.
906 945
 	if (isset($_POST['ignore_brd']))
907 946
 	{
908
-		if (!is_array($_POST['ignore_brd']))
909
-			$_POST['ignore_brd'] = array ($_POST['ignore_brd']);
947
+		if (!is_array($_POST['ignore_brd'])) {
948
+					$_POST['ignore_brd'] = array ($_POST['ignore_brd']);
949
+		}
910 950
 
911 951
 		foreach ($_POST['ignore_brd'] as $k => $d)
912 952
 		{
913 953
 			$d = (int) $d;
914
-			if ($d != 0)
915
-				$_POST['ignore_brd'][$k] = $d;
916
-			else
917
-				unset($_POST['ignore_brd'][$k]);
954
+			if ($d != 0) {
955
+							$_POST['ignore_brd'][$k] = $d;
956
+			} else {
957
+							unset($_POST['ignore_brd'][$k]);
958
+			}
918 959
 		}
919 960
 		$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
920 961
 		unset($_POST['ignore_brd']);
@@ -927,21 +968,26 @@  discard block
 block discarded – undo
927 968
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
928 969
 		//makeAvatarChanges($memID, $post_errors);
929 970
 
930
-		if (!empty($_REQUEST['sa']))
931
-			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
971
+		if (!empty($_REQUEST['sa'])) {
972
+					makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
973
+		}
932 974
 
933
-		foreach ($profile_bools as $var)
934
-			if (isset($_POST[$var]))
975
+		foreach ($profile_bools as $var) {
976
+					if (isset($_POST[$var]))
935 977
 				$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
936
-		foreach ($profile_ints as $var)
937
-			if (isset($_POST[$var]))
978
+		}
979
+		foreach ($profile_ints as $var) {
980
+					if (isset($_POST[$var]))
938 981
 				$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
939
-		foreach ($profile_floats as $var)
940
-			if (isset($_POST[$var]))
982
+		}
983
+		foreach ($profile_floats as $var) {
984
+					if (isset($_POST[$var]))
941 985
 				$profile_vars[$var] = (float) $_POST[$var];
942
-		foreach ($profile_strings as $var)
943
-			if (isset($_POST[$var]))
986
+		}
987
+		foreach ($profile_strings as $var) {
988
+					if (isset($_POST[$var]))
944 989
 				$profile_vars[$var] = $_POST[$var];
990
+		}
945 991
 	}
946 992
 }
947 993
 
@@ -975,8 +1021,9 @@  discard block
 block discarded – undo
975 1021
 	);
976 1022
 
977 1023
 	// Can't change reserved vars.
978
-	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
979
-		fatal_lang_error('no_access', false);
1024
+	if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) {
1025
+			fatal_lang_error('no_access', false);
1026
+	}
980 1027
 
981 1028
 	// Don't allow any overriding of custom fields with default or non-default options.
982 1029
 	$request = $smcFunc['db_query']('', '
@@ -988,8 +1035,9 @@  discard block
 block discarded – undo
988 1035
 		)
989 1036
 	);
990 1037
 	$custom_fields = array();
991
-	while ($row = $smcFunc['db_fetch_assoc']($request))
992
-		$custom_fields[] = $row['col_name'];
1038
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1039
+			$custom_fields[] = $row['col_name'];
1040
+	}
993 1041
 	$smcFunc['db_free_result']($request);
994 1042
 
995 1043
 	// These are the theme changes...
@@ -998,33 +1046,39 @@  discard block
 block discarded – undo
998 1046
 	{
999 1047
 		foreach ($_POST['options'] as $opt => $val)
1000 1048
 		{
1001
-			if (in_array($opt, $custom_fields))
1002
-				continue;
1049
+			if (in_array($opt, $custom_fields)) {
1050
+							continue;
1051
+			}
1003 1052
 
1004 1053
 			// These need to be controlled.
1005
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1006
-				$val = max(0, min($val, 50));
1054
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1055
+							$val = max(0, min($val, 50));
1056
+			}
1007 1057
 			// We don't set this per theme anymore.
1008
-			elseif ($opt == 'allow_no_censored')
1009
-				continue;
1058
+			elseif ($opt == 'allow_no_censored') {
1059
+							continue;
1060
+			}
1010 1061
 
1011 1062
 			$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
1012 1063
 		}
1013 1064
 	}
1014 1065
 
1015 1066
 	$erase_options = array();
1016
-	if (isset($_POST['default_options']) && is_array($_POST['default_options']))
1017
-		foreach ($_POST['default_options'] as $opt => $val)
1067
+	if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
1068
+			foreach ($_POST['default_options'] as $opt => $val)
1018 1069
 		{
1019 1070
 			if (in_array($opt, $custom_fields))
1020 1071
 				continue;
1072
+	}
1021 1073
 
1022 1074
 			// These need to be controlled.
1023
-			if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
1024
-				$val = max(0, min($val, 50));
1075
+			if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
1076
+							$val = max(0, min($val, 50));
1077
+			}
1025 1078
 			// Only let admins and owners change the censor.
1026
-			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
1027
-					continue;
1079
+			elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
1080
+								continue;
1081
+			}
1028 1082
 
1029 1083
 			$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
1030 1084
 			$erase_options[] = $opt;
@@ -1060,8 +1114,9 @@  discard block
 block discarded – undo
1060 1114
 
1061 1115
 		// Admins can choose any theme, even if it's not enabled...
1062 1116
 		$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
1063
-		foreach ($themes as $t)
1064
-			cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1117
+		foreach ($themes as $t) {
1118
+					cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
1119
+		}
1065 1120
 	}
1066 1121
 }
1067 1122
 
@@ -1080,8 +1135,9 @@  discard block
 block discarded – undo
1080 1135
 	if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
1081 1136
 	{
1082 1137
 		// Make sure only integers are deleted.
1083
-		foreach ($_POST['notify_boards'] as $index => $id)
1084
-			$_POST['notify_boards'][$index] = (int) $id;
1138
+		foreach ($_POST['notify_boards'] as $index => $id) {
1139
+					$_POST['notify_boards'][$index] = (int) $id;
1140
+		}
1085 1141
 
1086 1142
 		// id_board = 0 is reserved for topic notifications.
1087 1143
 		$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
@@ -1100,8 +1156,9 @@  discard block
 block discarded – undo
1100 1156
 	// We are editing topic notifications......
1101 1157
 	elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
1102 1158
 	{
1103
-		foreach ($_POST['notify_topics'] as $index => $id)
1104
-			$_POST['notify_topics'][$index] = (int) $id;
1159
+		foreach ($_POST['notify_topics'] as $index => $id) {
1160
+					$_POST['notify_topics'][$index] = (int) $id;
1161
+		}
1105 1162
 
1106 1163
 		// Make sure there are no zeros left.
1107 1164
 		$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
@@ -1115,16 +1172,18 @@  discard block
 block discarded – undo
1115 1172
 				'selected_member' => $memID,
1116 1173
 			)
1117 1174
 		);
1118
-		foreach ($_POST['notify_topics'] as $topic)
1119
-			setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1175
+		foreach ($_POST['notify_topics'] as $topic) {
1176
+					setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
1177
+		}
1120 1178
 	}
1121 1179
 
1122 1180
 	// We are removing topic preferences
1123 1181
 	elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
1124 1182
 	{
1125 1183
 		$prefs = array();
1126
-		foreach ($_POST['notify_topics'] as $topic)
1127
-			$prefs[] = 'topic_notify_' . $topic;
1184
+		foreach ($_POST['notify_topics'] as $topic) {
1185
+					$prefs[] = 'topic_notify_' . $topic;
1186
+		}
1128 1187
 		deleteNotifyPrefs($memID, $prefs);
1129 1188
 	}
1130 1189
 
@@ -1132,8 +1191,9 @@  discard block
 block discarded – undo
1132 1191
 	elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
1133 1192
 	{
1134 1193
 		$prefs = array();
1135
-		foreach ($_POST['notify_boards'] as $board)
1136
-			$prefs[] = 'board_notify_' . $board;
1194
+		foreach ($_POST['notify_boards'] as $board) {
1195
+					$prefs[] = 'board_notify_' . $board;
1196
+		}
1137 1197
 		deleteNotifyPrefs($memID, $prefs);
1138 1198
 	}
1139 1199
 }
@@ -1154,8 +1214,9 @@  discard block
 block discarded – undo
1154 1214
 
1155 1215
 	$errors = array();
1156 1216
 
1157
-	if ($sanitize && isset($_POST['customfield']))
1158
-		$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1217
+	if ($sanitize && isset($_POST['customfield'])) {
1218
+			$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
1219
+	}
1159 1220
 
1160 1221
 	$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
1161 1222
 
@@ -1180,48 +1241,49 @@  discard block
 block discarded – undo
1180 1241
 			- The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
1181 1242
 			- The area isn't registration, and if it is that the field is not supposed to be shown there.
1182 1243
 		*/
1183
-		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
1184
-			continue;
1244
+		if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) {
1245
+					continue;
1246
+		}
1185 1247
 
1186 1248
 		// Validate the user data.
1187
-		if ($row['field_type'] == 'check')
1188
-			$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1189
-		elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1249
+		if ($row['field_type'] == 'check') {
1250
+					$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
1251
+		} elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
1190 1252
 		{
1191 1253
 			$value = $row['default_value'];
1192
-			foreach (explode(',', $row['field_options']) as $k => $v)
1193
-				if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1254
+			foreach (explode(',', $row['field_options']) as $k => $v) {
1255
+							if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
1194 1256
 					$value = $v;
1257
+			}
1195 1258
 		}
1196 1259
 		// Otherwise some form of text!
1197 1260
 		else
1198 1261
 		{
1199 1262
 			$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
1200
-			if ($row['field_length'])
1201
-				$value = $smcFunc['substr']($value, 0, $row['field_length']);
1263
+			if ($row['field_length']) {
1264
+							$value = $smcFunc['substr']($value, 0, $row['field_length']);
1265
+			}
1202 1266
 
1203 1267
 			// Any masks?
1204 1268
 			if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
1205 1269
 			{
1206 1270
 				if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
1207 1271
 				{
1208
-					if ($returnErrors)
1209
-						$errors[] = 'custom_field_mail_fail';
1210
-
1211
-					else
1212
-						$value = '';
1213
-				}
1214
-				elseif ($row['mask'] == 'number')
1272
+					if ($returnErrors) {
1273
+											$errors[] = 'custom_field_mail_fail';
1274
+					} else {
1275
+											$value = '';
1276
+					}
1277
+				} elseif ($row['mask'] == 'number')
1215 1278
 				{
1216 1279
 					$value = (int) $value;
1217
-				}
1218
-				elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1280
+				} elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
1219 1281
 				{
1220
-					if ($returnErrors)
1221
-						$errors[] = 'custom_field_regex_fail';
1222
-
1223
-					else
1224
-						$value = '';
1282
+					if ($returnErrors) {
1283
+											$errors[] = 'custom_field_regex_fail';
1284
+					} else {
1285
+											$value = '';
1286
+					}
1225 1287
 				}
1226 1288
 			}
1227 1289
 		}
@@ -1248,8 +1310,9 @@  discard block
 block discarded – undo
1248 1310
 	$hook_errors = array();
1249 1311
 	$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize));
1250 1312
 
1251
-	if (!empty($hook_errors) && is_array($hook_errors))
1252
-		$errors = array_merge($errors, $hook_errors);
1313
+	if (!empty($hook_errors) && is_array($hook_errors)) {
1314
+			$errors = array_merge($errors, $hook_errors);
1315
+	}
1253 1316
 
1254 1317
 	// Make those changes!
1255 1318
 	if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors))
@@ -1267,9 +1330,10 @@  discard block
 block discarded – undo
1267 1330
 		}
1268 1331
 	}
1269 1332
 
1270
-	if ($returnErrors)
1271
-		return $errors;
1272
-}
1333
+	if ($returnErrors) {
1334
+			return $errors;
1335
+	}
1336
+	}
1273 1337
 
1274 1338
 /**
1275 1339
  * Show all the users buddies, as well as a add/delete interface.
@@ -1281,8 +1345,9 @@  discard block
 block discarded – undo
1281 1345
 	global $context, $txt, $modSettings;
1282 1346
 
1283 1347
 	// Do a quick check to ensure people aren't getting here illegally!
1284
-	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
1285
-		fatal_lang_error('no_access', false);
1348
+	if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) {
1349
+			fatal_lang_error('no_access', false);
1350
+	}
1286 1351
 
1287 1352
 	// Can we email the user direct?
1288 1353
 	$context['can_moderate_forum'] = allowedTo('moderate_forum');
@@ -1312,9 +1377,10 @@  discard block
 block discarded – undo
1312 1377
 	$context['sub_template'] = $subActions[$context['list_area']][0];
1313 1378
 	$call = call_helper($subActions[$context['list_area']][0], true);
1314 1379
 
1315
-	if (!empty($call))
1316
-		call_user_func($call, $memID);
1317
-}
1380
+	if (!empty($call)) {
1381
+			call_user_func($call, $memID);
1382
+	}
1383
+	}
1318 1384
 
1319 1385
 /**
1320 1386
  * Show all the users buddies, as well as a add/delete interface.
@@ -1328,9 +1394,10 @@  discard block
 block discarded – undo
1328 1394
 
1329 1395
 	// For making changes!
1330 1396
 	$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
1331
-	foreach ($buddiesArray as $k => $dummy)
1332
-		if ($dummy == '')
1397
+	foreach ($buddiesArray as $k => $dummy) {
1398
+			if ($dummy == '')
1333 1399
 			unset($buddiesArray[$k]);
1400
+	}
1334 1401
 
1335 1402
 	// Removing a buddy?
1336 1403
 	if (isset($_GET['remove']))
@@ -1342,10 +1409,11 @@  discard block
 block discarded – undo
1342 1409
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1343 1410
 
1344 1411
 		// Heh, I'm lazy, do it the easy way...
1345
-		foreach ($buddiesArray as $key => $buddy)
1346
-			if ($buddy == (int) $_GET['remove'])
1412
+		foreach ($buddiesArray as $key => $buddy) {
1413
+					if ($buddy == (int) $_GET['remove'])
1347 1414
 			{
1348 1415
 				unset($buddiesArray[$key]);
1416
+		}
1349 1417
 				$_SESSION['prf-save'] = true;
1350 1418
 			}
1351 1419
 
@@ -1355,8 +1423,7 @@  discard block
 block discarded – undo
1355 1423
 
1356 1424
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1357 1425
 		redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
1358
-	}
1359
-	elseif (isset($_POST['new_buddy']))
1426
+	} elseif (isset($_POST['new_buddy']))
1360 1427
 	{
1361 1428
 		checkSession();
1362 1429
 
@@ -1369,8 +1436,9 @@  discard block
 block discarded – undo
1369 1436
 		{
1370 1437
 			$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
1371 1438
 
1372
-			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1373
-				unset($new_buddies[$k]);
1439
+			if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1440
+							unset($new_buddies[$k]);
1441
+			}
1374 1442
 		}
1375 1443
 
1376 1444
 		call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
@@ -1390,16 +1458,18 @@  discard block
 block discarded – undo
1390 1458
 				)
1391 1459
 			);
1392 1460
 
1393
-			if ($smcFunc['db_num_rows']($request) != 0)
1394
-				$_SESSION['prf-save'] = true;
1461
+			if ($smcFunc['db_num_rows']($request) != 0) {
1462
+							$_SESSION['prf-save'] = true;
1463
+			}
1395 1464
 
1396 1465
 			// Add the new member to the buddies array.
1397 1466
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1398 1467
 			{
1399
-				if (in_array($row['id_member'], $buddiesArray))
1400
-					continue;
1401
-				else
1402
-					$buddiesArray[] = (int) $row['id_member'];
1468
+				if (in_array($row['id_member'], $buddiesArray)) {
1469
+									continue;
1470
+				} else {
1471
+									$buddiesArray[] = (int) $row['id_member'];
1472
+				}
1403 1473
 			}
1404 1474
 			$smcFunc['db_free_result']($request);
1405 1475
 
@@ -1429,18 +1499,20 @@  discard block
 block discarded – undo
1429 1499
 
1430 1500
 	$context['custom_pf'] = array();
1431 1501
 	$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
1432
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1433
-		if (!isset($disabled_fields[$row['col_name']]))
1502
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1503
+			if (!isset($disabled_fields[$row['col_name']]))
1434 1504
 			$context['custom_pf'][$row['col_name']] = array(
1435 1505
 				'label' => $row['field_name'],
1436 1506
 				'type' => $row['field_type'],
1437 1507
 				'bbc' => !empty($row['bbc']),
1438 1508
 				'enclose' => $row['enclose'],
1439 1509
 			);
1510
+	}
1440 1511
 
1441 1512
 	// Gotta disable the gender option.
1442
-	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled')
1443
-		unset($context['custom_pf']['cust_gender']);
1513
+	if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') {
1514
+			unset($context['custom_pf']['cust_gender']);
1515
+	}
1444 1516
 
1445 1517
 	$smcFunc['db_free_result']($request);
1446 1518
 
@@ -1457,8 +1529,9 @@  discard block
 block discarded – undo
1457 1529
 				'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
1458 1530
 			)
1459 1531
 		);
1460
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1461
-			$buddies[] = $row['id_member'];
1532
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1533
+					$buddies[] = $row['id_member'];
1534
+		}
1462 1535
 		$smcFunc['db_free_result']($result);
1463 1536
 	}
1464 1537
 
@@ -1486,30 +1559,32 @@  discard block
 block discarded – undo
1486 1559
 					continue;
1487 1560
 				}
1488 1561
 
1489
-				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
1490
-					$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1491
-
1492
-				elseif ($column['type'] == 'check')
1493
-					$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1562
+				if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) {
1563
+									$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
1564
+				} elseif ($column['type'] == 'check') {
1565
+									$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
1566
+				}
1494 1567
 
1495 1568
 				// Enclosing the user input within some other text?
1496
-				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
1497
-					$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1569
+				if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) {
1570
+									$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
1498 1571
 						'{SCRIPTURL}' => $scripturl,
1499 1572
 						'{IMAGES_URL}' => $settings['images_url'],
1500 1573
 						'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1501 1574
 						'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
1502 1575
 					));
1576
+				}
1503 1577
 			}
1504 1578
 		}
1505 1579
 	}
1506 1580
 
1507 1581
 	if (isset($_SESSION['prf-save']))
1508 1582
 	{
1509
-		if ($_SESSION['prf-save'] === true)
1510
-			$context['saved_successful'] = true;
1511
-		else
1512
-			$context['saved_failed'] = $_SESSION['prf-save'];
1583
+		if ($_SESSION['prf-save'] === true) {
1584
+					$context['saved_successful'] = true;
1585
+		} else {
1586
+					$context['saved_failed'] = $_SESSION['prf-save'];
1587
+		}
1513 1588
 
1514 1589
 		unset($_SESSION['prf-save']);
1515 1590
 	}
@@ -1529,9 +1604,10 @@  discard block
 block discarded – undo
1529 1604
 
1530 1605
 	// For making changes!
1531 1606
 	$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
1532
-	foreach ($ignoreArray as $k => $dummy)
1533
-		if ($dummy == '')
1607
+	foreach ($ignoreArray as $k => $dummy) {
1608
+			if ($dummy == '')
1534 1609
 			unset($ignoreArray[$k]);
1610
+	}
1535 1611
 
1536 1612
 	// Removing a member from the ignore list?
1537 1613
 	if (isset($_GET['remove']))
@@ -1541,10 +1617,11 @@  discard block
 block discarded – undo
1541 1617
 		$_SESSION['prf-save'] = $txt['could_not_remove_person'];
1542 1618
 
1543 1619
 		// Heh, I'm lazy, do it the easy way...
1544
-		foreach ($ignoreArray as $key => $id_remove)
1545
-			if ($id_remove == (int) $_GET['remove'])
1620
+		foreach ($ignoreArray as $key => $id_remove) {
1621
+					if ($id_remove == (int) $_GET['remove'])
1546 1622
 			{
1547 1623
 				unset($ignoreArray[$key]);
1624
+		}
1548 1625
 				$_SESSION['prf-save'] = true;
1549 1626
 			}
1550 1627
 
@@ -1554,8 +1631,7 @@  discard block
 block discarded – undo
1554 1631
 
1555 1632
 		// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
1556 1633
 		redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
1557
-	}
1558
-	elseif (isset($_POST['new_ignore']))
1634
+	} elseif (isset($_POST['new_ignore']))
1559 1635
 	{
1560 1636
 		checkSession();
1561 1637
 		// Prepare the string for extraction...
@@ -1567,8 +1643,9 @@  discard block
 block discarded – undo
1567 1643
 		{
1568 1644
 			$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
1569 1645
 
1570
-			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
1571
-				unset($new_entries[$k]);
1646
+			if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) {
1647
+							unset($new_entries[$k]);
1648
+			}
1572 1649
 		}
1573 1650
 
1574 1651
 		$_SESSION['prf-save'] = $txt['could_not_add_person'];
@@ -1586,16 +1663,18 @@  discard block
 block discarded – undo
1586 1663
 				)
1587 1664
 			);
1588 1665
 
1589
-			if ($smcFunc['db_num_rows']($request) != 0)
1590
-				$_SESSION['prf-save'] = true;
1666
+			if ($smcFunc['db_num_rows']($request) != 0) {
1667
+							$_SESSION['prf-save'] = true;
1668
+			}
1591 1669
 
1592 1670
 			// Add the new member to the buddies array.
1593 1671
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1594 1672
 			{
1595
-				if (in_array($row['id_member'], $ignoreArray))
1596
-					continue;
1597
-				else
1598
-					$ignoreArray[] = (int) $row['id_member'];
1673
+				if (in_array($row['id_member'], $ignoreArray)) {
1674
+									continue;
1675
+				} else {
1676
+									$ignoreArray[] = (int) $row['id_member'];
1677
+				}
1599 1678
 			}
1600 1679
 			$smcFunc['db_free_result']($request);
1601 1680
 
@@ -1624,8 +1703,9 @@  discard block
 block discarded – undo
1624 1703
 				'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
1625 1704
 			)
1626 1705
 		);
1627
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1628
-			$ignored[] = $row['id_member'];
1706
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1707
+					$ignored[] = $row['id_member'];
1708
+		}
1629 1709
 		$smcFunc['db_free_result']($result);
1630 1710
 	}
1631 1711
 
@@ -1644,10 +1724,11 @@  discard block
 block discarded – undo
1644 1724
 
1645 1725
 	if (isset($_SESSION['prf-save']))
1646 1726
 	{
1647
-		if ($_SESSION['prf-save'] === true)
1648
-			$context['saved_successful'] = true;
1649
-		else
1650
-			$context['saved_failed'] = $_SESSION['prf-save'];
1727
+		if ($_SESSION['prf-save'] === true) {
1728
+					$context['saved_successful'] = true;
1729
+		} else {
1730
+					$context['saved_failed'] = $_SESSION['prf-save'];
1731
+		}
1651 1732
 
1652 1733
 		unset($_SESSION['prf-save']);
1653 1734
 	}
@@ -1663,8 +1744,9 @@  discard block
 block discarded – undo
1663 1744
 	global $context, $txt;
1664 1745
 
1665 1746
 	loadThemeOptions($memID);
1666
-	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
1667
-		loadCustomFields($memID, 'account');
1747
+	if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) {
1748
+			loadCustomFields($memID, 'account');
1749
+	}
1668 1750
 
1669 1751
 	$context['sub_template'] = 'edit_options';
1670 1752
 	$context['page_desc'] = $txt['account_info'];
@@ -1691,8 +1773,9 @@  discard block
 block discarded – undo
1691 1773
 	global $context, $txt;
1692 1774
 
1693 1775
 	loadThemeOptions($memID);
1694
-	if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
1695
-		loadCustomFields($memID, 'forumprofile');
1776
+	if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) {
1777
+			loadCustomFields($memID, 'forumprofile');
1778
+	}
1696 1779
 
1697 1780
 	$context['sub_template'] = 'edit_options';
1698 1781
 	$context['page_desc'] = $txt['forumProfile_info'];
@@ -1725,18 +1808,21 @@  discard block
 block discarded – undo
1725 1808
 	$dirs = array();
1726 1809
 	$files = array();
1727 1810
 
1728
-	if (!$dir)
1729
-		return array();
1811
+	if (!$dir) {
1812
+			return array();
1813
+	}
1730 1814
 
1731 1815
 	while ($line = $dir->read())
1732 1816
 	{
1733
-		if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
1734
-			continue;
1817
+		if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) {
1818
+					continue;
1819
+		}
1735 1820
 
1736
-		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
1737
-			$dirs[] = $line;
1738
-		else
1739
-			$files[] = $line;
1821
+		if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
1822
+					$dirs[] = $line;
1823
+		} else {
1824
+					$files[] = $line;
1825
+		}
1740 1826
 	}
1741 1827
 	$dir->close();
1742 1828
 
@@ -1757,14 +1843,15 @@  discard block
 block discarded – undo
1757 1843
 	foreach ($dirs as $line)
1758 1844
 	{
1759 1845
 		$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
1760
-		if (!empty($tmp))
1761
-			$result[] = array(
1846
+		if (!empty($tmp)) {
1847
+					$result[] = array(
1762 1848
 				'filename' => $smcFunc['htmlspecialchars']($line),
1763 1849
 				'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
1764 1850
 				'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
1765 1851
 				'is_dir' => true,
1766 1852
 				'files' => $tmp
1767 1853
 		);
1854
+		}
1768 1855
 		unset($tmp);
1769 1856
 	}
1770 1857
 
@@ -1774,8 +1861,9 @@  discard block
 block discarded – undo
1774 1861
 		$extension = substr(strrchr($line, '.'), 1);
1775 1862
 
1776 1863
 		// Make sure it is an image.
1777
-		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
1778
-			continue;
1864
+		if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
1865
+					continue;
1866
+		}
1779 1867
 
1780 1868
 		$result[] = array(
1781 1869
 			'filename' => $smcFunc['htmlspecialchars']($line),
@@ -1783,8 +1871,9 @@  discard block
 block discarded – undo
1783 1871
 			'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
1784 1872
 			'is_dir' => false
1785 1873
 		);
1786
-		if ($level == 1)
1787
-			$context['avatar_list'][] = $directory . '/' . $line;
1874
+		if ($level == 1) {
1875
+					$context['avatar_list'][] = $directory . '/' . $line;
1876
+		}
1788 1877
 	}
1789 1878
 
1790 1879
 	return $result;
@@ -1800,8 +1889,9 @@  discard block
 block discarded – undo
1800 1889
 	global $txt, $context;
1801 1890
 
1802 1891
 	loadThemeOptions($memID);
1803
-	if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
1804
-		loadCustomFields($memID, 'theme');
1892
+	if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) {
1893
+			loadCustomFields($memID, 'theme');
1894
+	}
1805 1895
 
1806 1896
 	$context['sub_template'] = 'edit_options';
1807 1897
 	$context['page_desc'] = $txt['theme_info'];
@@ -1855,16 +1945,19 @@  discard block
 block discarded – undo
1855 1945
 {
1856 1946
 	global $txt, $user_profile, $context, $modSettings, $smcFunc, $sourcedir;
1857 1947
 
1858
-	if (!isset($context['token_check']))
1859
-		$context['token_check'] = 'profile-nt' . $memID;
1948
+	if (!isset($context['token_check'])) {
1949
+			$context['token_check'] = 'profile-nt' . $memID;
1950
+	}
1860 1951
 
1861 1952
 	is_not_guest();
1862
-	if (!$context['user']['is_owner'])
1863
-		isAllowedTo('profile_extra_any');
1953
+	if (!$context['user']['is_owner']) {
1954
+			isAllowedTo('profile_extra_any');
1955
+	}
1864 1956
 
1865 1957
 	// Set the post action if we're coming from the profile...
1866
-	if (!isset($context['action']))
1867
-		$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1958
+	if (!isset($context['action'])) {
1959
+			$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
1960
+	}
1868 1961
 
1869 1962
 	// What options are set
1870 1963
 	loadThemeOptions($memID);
@@ -1951,28 +2044,34 @@  discard block
 block discarded – undo
1951 2044
 	);
1952 2045
 
1953 2046
 	// There are certain things that are disabled at the group level.
1954
-	if (empty($modSettings['cal_enabled']))
1955
-		unset($alert_types['calendar']);
2047
+	if (empty($modSettings['cal_enabled'])) {
2048
+			unset($alert_types['calendar']);
2049
+	}
1956 2050
 
1957 2051
 	// Disable paid subscriptions at group level if they're disabled
1958
-	if (empty($modSettings['paid_enabled']))
1959
-		unset($alert_types['paidsubs']);
2052
+	if (empty($modSettings['paid_enabled'])) {
2053
+			unset($alert_types['paidsubs']);
2054
+	}
1960 2055
 
1961 2056
 	// Disable membergroup requests at group level if they're disabled
1962
-	if (empty($modSettings['show_group_membership']))
1963
-		unset($alert_types['groupr'], $alert_types['members']['request_group']);
2057
+	if (empty($modSettings['show_group_membership'])) {
2058
+			unset($alert_types['groupr'], $alert_types['members']['request_group']);
2059
+	}
1964 2060
 
1965 2061
 	// Disable mentions if they're disabled
1966
-	if (empty($modSettings['enable_mentions']))
1967
-		unset($alert_types['msg']['msg_mention']);
2062
+	if (empty($modSettings['enable_mentions'])) {
2063
+			unset($alert_types['msg']['msg_mention']);
2064
+	}
1968 2065
 
1969 2066
 	// Disable likes if they're disabled
1970
-	if (empty($modSettings['enable_likes']))
1971
-		unset($alert_types['msg']['msg_like']);
2067
+	if (empty($modSettings['enable_likes'])) {
2068
+			unset($alert_types['msg']['msg_like']);
2069
+	}
1972 2070
 
1973 2071
 	// Disable buddy requests if they're disabled
1974
-	if (empty($modSettings['enable_buddylist']))
1975
-		unset($alert_types['members']['buddy_request']);
2072
+	if (empty($modSettings['enable_buddylist'])) {
2073
+			unset($alert_types['members']['buddy_request']);
2074
+	}
1976 2075
 
1977 2076
 	// Now, now, we could pass this through global but we should really get into the habit of
1978 2077
 	// passing content to hooks, not expecting hooks to splatter everything everywhere.
@@ -2000,15 +2099,17 @@  discard block
 block discarded – undo
2000 2099
 			$perms_cache['manage_membergroups'] = in_array($memID, $members);
2001 2100
 		}
2002 2101
 
2003
-		if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
2004
-			unset($alert_types['members']['request_group']);
2102
+		if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) {
2103
+					unset($alert_types['members']['request_group']);
2104
+		}
2005 2105
 
2006 2106
 		foreach ($alert_types as $group => $items)
2007 2107
 		{
2008 2108
 			foreach ($items as $alert_key => $alert_value)
2009 2109
 			{
2010
-				if (!isset($alert_value['permission']))
2011
-					continue;
2110
+				if (!isset($alert_value['permission'])) {
2111
+									continue;
2112
+				}
2012 2113
 				if (!isset($perms_cache[$alert_value['permission']['name']]))
2013 2114
 				{
2014 2115
 					$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
@@ -2016,12 +2117,14 @@  discard block
 block discarded – undo
2016 2117
 					$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
2017 2118
 				}
2018 2119
 
2019
-				if (!$perms_cache[$alert_value['permission']['name']])
2020
-					unset ($alert_types[$group][$alert_key]);
2120
+				if (!$perms_cache[$alert_value['permission']['name']]) {
2121
+									unset ($alert_types[$group][$alert_key]);
2122
+				}
2021 2123
 			}
2022 2124
 
2023
-			if (empty($alert_types[$group]))
2024
-				unset ($alert_types[$group]);
2125
+			if (empty($alert_types[$group])) {
2126
+							unset ($alert_types[$group]);
2127
+			}
2025 2128
 		}
2026 2129
 	}
2027 2130
 
@@ -2053,9 +2156,9 @@  discard block
 block discarded – undo
2053 2156
 						$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
2054 2157
 						break;
2055 2158
 					case 'select':
2056
-						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
2057
-							$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2058
-						else
2159
+						if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) {
2160
+													$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
2161
+						} else
2059 2162
 						{
2060 2163
 							// We didn't have a sane value. Let's grab the first item from the possibles.
2061 2164
 							$keys = array_keys($this_option['opts']);
@@ -2075,23 +2178,28 @@  discard block
 block discarded – undo
2075 2178
 				$this_value = 0;
2076 2179
 				foreach ($context['alert_bits'] as $type => $bitvalue)
2077 2180
 				{
2078
-					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
2079
-						$this_value |= $bitvalue;
2181
+					if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') {
2182
+											$this_value |= $bitvalue;
2183
+					}
2184
+				}
2185
+				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) {
2186
+									$update_prefs[$item_key] = $this_value;
2080 2187
 				}
2081
-				if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value)
2082
-					$update_prefs[$item_key] = $this_value;
2083 2188
 			}
2084 2189
 		}
2085 2190
 
2086
-		if (!empty($_POST['opt_alert_timeout']))
2087
-			$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2191
+		if (!empty($_POST['opt_alert_timeout'])) {
2192
+					$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
2193
+		}
2088 2194
 
2089
-		if (!empty($_POST['notify_announcements']))
2090
-			$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2195
+		if (!empty($_POST['notify_announcements'])) {
2196
+					$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
2197
+		}
2091 2198
 
2092 2199
 		setNotifyPrefs((int) $memID, $update_prefs);
2093
-		foreach ($update_prefs as $pref => $value)
2094
-			$context['alert_prefs'][$pref] = $value;
2200
+		foreach ($update_prefs as $pref => $value) {
2201
+					$context['alert_prefs'][$pref] = $value;
2202
+		}
2095 2203
 
2096 2204
 		makeNotificationChanges($memID);
2097 2205
 
@@ -2121,8 +2229,9 @@  discard block
 block discarded – undo
2121 2229
 
2122 2230
 	// Now we're all set up.
2123 2231
 	is_not_guest();
2124
-	if (!$context['user']['is_owner'])
2125
-		fatal_error('no_access');
2232
+	if (!$context['user']['is_owner']) {
2233
+			fatal_error('no_access');
2234
+	}
2126 2235
 
2127 2236
 	checkSession('get');
2128 2237
 
@@ -2154,8 +2263,9 @@  discard block
 block discarded – undo
2154 2263
 {
2155 2264
 	global $smcFunc;
2156 2265
 
2157
-	if (empty($toMark) || empty($memID))
2158
-		return false;
2266
+	if (empty($toMark) || empty($memID)) {
2267
+			return false;
2268
+	}
2159 2269
 
2160 2270
 	$toMark = (array) $toMark;
2161 2271
 	$count = 0;
@@ -2190,8 +2300,9 @@  discard block
 block discarded – undo
2190 2300
 {
2191 2301
 	global $smcFunc;
2192 2302
 
2193
-	if (empty($toDelete))
2194
-		return false;
2303
+	if (empty($toDelete)) {
2304
+			return false;
2305
+	}
2195 2306
 
2196 2307
 	$toDelete = (array) $toDelete;
2197 2308
 
@@ -2226,8 +2337,9 @@  discard block
 block discarded – undo
2226 2337
 {
2227 2338
 	global $smcFunc;
2228 2339
 
2229
-	if (empty($memID))
2230
-		return false;
2340
+	if (empty($memID)) {
2341
+			return false;
2342
+	}
2231 2343
 
2232 2344
 	$count = 0;
2233 2345
 
@@ -2306,8 +2418,9 @@  discard block
 block discarded – undo
2306 2418
 					{
2307 2419
 						$link = $topic['link'];
2308 2420
 
2309
-						if ($topic['new'])
2310
-							$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2421
+						if ($topic['new']) {
2422
+													$link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2423
+						}
2311 2424
 
2312 2425
 						$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
2313 2426
 
@@ -2458,8 +2571,9 @@  discard block
 block discarded – undo
2458 2571
 					{
2459 2572
 						$link = $board['link'];
2460 2573
 
2461
-						if ($board['new'])
2462
-							$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2574
+						if ($board['new']) {
2575
+													$link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>';
2576
+						}
2463 2577
 
2464 2578
 						return $link;
2465 2579
 					},
@@ -2659,8 +2773,8 @@  discard block
 block discarded – undo
2659 2773
 		)
2660 2774
 	);
2661 2775
 	$notification_boards = array();
2662
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2663
-		$notification_boards[] = array(
2776
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2777
+			$notification_boards[] = array(
2664 2778
 			'id' => $row['id_board'],
2665 2779
 			'name' => $row['name'],
2666 2780
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
@@ -2668,6 +2782,7 @@  discard block
 block discarded – undo
2668 2782
 			'new' => $row['board_read'] < $row['id_msg_updated'],
2669 2783
 			'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
2670 2784
 		);
2785
+	}
2671 2786
 	$smcFunc['db_free_result']($request);
2672 2787
 
2673 2788
 	return $notification_boards;
@@ -2682,17 +2797,18 @@  discard block
 block discarded – undo
2682 2797
 {
2683 2798
 	global $context, $options, $cur_profile, $smcFunc;
2684 2799
 
2685
-	if (isset($_POST['default_options']))
2686
-		$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2800
+	if (isset($_POST['default_options'])) {
2801
+			$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
2802
+	}
2687 2803
 
2688 2804
 	if ($context['user']['is_owner'])
2689 2805
 	{
2690 2806
 		$context['member']['options'] = $options;
2691
-		if (isset($_POST['options']) && is_array($_POST['options']))
2692
-			foreach ($_POST['options'] as $k => $v)
2807
+		if (isset($_POST['options']) && is_array($_POST['options'])) {
2808
+					foreach ($_POST['options'] as $k => $v)
2693 2809
 				$context['member']['options'][$k] = $v;
2694
-	}
2695
-	else
2810
+		}
2811
+	} else
2696 2812
 	{
2697 2813
 		$request = $smcFunc['db_query']('', '
2698 2814
 			SELECT id_member, variable, value
@@ -2713,8 +2829,9 @@  discard block
 block discarded – undo
2713 2829
 				continue;
2714 2830
 			}
2715 2831
 
2716
-			if (isset($_POST['options'][$row['variable']]))
2717
-				$row['value'] = $_POST['options'][$row['variable']];
2832
+			if (isset($_POST['options'][$row['variable']])) {
2833
+							$row['value'] = $_POST['options'][$row['variable']];
2834
+			}
2718 2835
 			$context['member']['options'][$row['variable']] = $row['value'];
2719 2836
 		}
2720 2837
 		$smcFunc['db_free_result']($request);
@@ -2722,8 +2839,9 @@  discard block
 block discarded – undo
2722 2839
 		// Load up the default theme options for any missing.
2723 2840
 		foreach ($temp as $k => $v)
2724 2841
 		{
2725
-			if (!isset($context['member']['options'][$k]))
2726
-				$context['member']['options'][$k] = $v;
2842
+			if (!isset($context['member']['options'][$k])) {
2843
+							$context['member']['options'][$k] = $v;
2844
+			}
2727 2845
 		}
2728 2846
 	}
2729 2847
 }
@@ -2738,8 +2856,9 @@  discard block
 block discarded – undo
2738 2856
 	global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
2739 2857
 
2740 2858
 	// Have the admins enabled this option?
2741
-	if (empty($modSettings['allow_ignore_boards']))
2742
-		fatal_lang_error('ignoreboards_disallowed', 'user');
2859
+	if (empty($modSettings['allow_ignore_boards'])) {
2860
+			fatal_lang_error('ignoreboards_disallowed', 'user');
2861
+	}
2743 2862
 
2744 2863
 	// Find all the boards this user is allowed to see.
2745 2864
 	$request = $smcFunc['db_query']('order_by_board_order', '
@@ -2759,12 +2878,13 @@  discard block
 block discarded – undo
2759 2878
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2760 2879
 	{
2761 2880
 		// This category hasn't been set up yet..
2762
-		if (!isset($context['categories'][$row['id_cat']]))
2763
-			$context['categories'][$row['id_cat']] = array(
2881
+		if (!isset($context['categories'][$row['id_cat']])) {
2882
+					$context['categories'][$row['id_cat']] = array(
2764 2883
 				'id' => $row['id_cat'],
2765 2884
 				'name' => $row['cat_name'],
2766 2885
 				'boards' => array()
2767 2886
 			);
2887
+		}
2768 2888
 
2769 2889
 		// Set this board up, and let the template know when it's a child.  (indent them..)
2770 2890
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -2794,18 +2914,20 @@  discard block
 block discarded – undo
2794 2914
 	}
2795 2915
 
2796 2916
 	$max_boards = ceil(count($temp_boards) / 2);
2797
-	if ($max_boards == 1)
2798
-		$max_boards = 2;
2917
+	if ($max_boards == 1) {
2918
+			$max_boards = 2;
2919
+	}
2799 2920
 
2800 2921
 	// Now, alternate them so they can be shown left and right ;).
2801 2922
 	$context['board_columns'] = array();
2802 2923
 	for ($i = 0; $i < $max_boards; $i++)
2803 2924
 	{
2804 2925
 		$context['board_columns'][] = $temp_boards[$i];
2805
-		if (isset($temp_boards[$i + $max_boards]))
2806
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
2807
-		else
2808
-			$context['board_columns'][] = array();
2926
+		if (isset($temp_boards[$i + $max_boards])) {
2927
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
2928
+		} else {
2929
+					$context['board_columns'][] = array();
2930
+		}
2809 2931
 	}
2810 2932
 
2811 2933
 	loadThemeOptions($memID);
@@ -2874,8 +2996,9 @@  discard block
 block discarded – undo
2874 2996
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2875 2997
 	{
2876 2998
 		// We should skip the administrator group if they don't have the admin_forum permission!
2877
-		if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
2878
-			continue;
2999
+		if ($row['id_group'] == 1 && !allowedTo('admin_forum')) {
3000
+					continue;
3001
+		}
2879 3002
 
2880 3003
 		$context['member_groups'][$row['id_group']] = array(
2881 3004
 			'id' => $row['id_group'],
@@ -2921,16 +3044,17 @@  discard block
 block discarded – undo
2921 3044
 	$context['max_signature_length'] = $context['signature_limits']['max_length'];
2922 3045
 	// Warning message for signature image limits?
2923 3046
 	$context['signature_warning'] = '';
2924
-	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
2925
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
2926
-	elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
2927
-		$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3047
+	if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) {
3048
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
3049
+	} elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) {
3050
+			$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
3051
+	}
2928 3052
 
2929 3053
 	$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv'))));
2930 3054
 
2931
-	if (empty($context['do_preview']))
2932
-		$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
2933
-	else
3055
+	if (empty($context['do_preview'])) {
3056
+			$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
3057
+	} else
2934 3058
 	{
2935 3059
 		$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
2936 3060
 		$validation = profileValidateSignature($signature);
@@ -2940,8 +3064,9 @@  discard block
 block discarded – undo
2940 3064
 			$context['post_errors'] = array();
2941 3065
 		}
2942 3066
 		$context['post_errors'][] = 'signature_not_yet_saved';
2943
-		if ($validation !== true && $validation !== false)
2944
-			$context['post_errors'][] = $validation;
3067
+		if ($validation !== true && $validation !== false) {
3068
+					$context['post_errors'][] = $validation;
3069
+		}
2945 3070
 
2946 3071
 		censorText($context['member']['signature']);
2947 3072
 		$context['member']['current_signature'] = $context['member']['signature'];
@@ -2951,8 +3076,9 @@  discard block
 block discarded – undo
2951 3076
 	}
2952 3077
 
2953 3078
 	// Load the spell checker?
2954
-	if ($context['show_spellchecking'])
2955
-		loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3079
+	if ($context['show_spellchecking']) {
3080
+			loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck');
3081
+	}
2956 3082
 
2957 3083
 	return true;
2958 3084
 }
@@ -2986,8 +3112,7 @@  discard block
 block discarded – undo
2986 3112
 			'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
2987 3113
 		);
2988 3114
 		$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
2989
-	}
2990
-	elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
3115
+	} elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
2991 3116
 	{
2992 3117
 		$context['member']['avatar'] += array(
2993 3118
 			'choice' => 'upload',
@@ -2995,34 +3120,34 @@  discard block
 block discarded – undo
2995 3120
 			'external' => 'http://'
2996 3121
 		);
2997 3122
 		$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
2998
-	}
2999
-	elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
3000
-		$context['member']['avatar'] += array(
3123
+	} elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) {
3124
+			$context['member']['avatar'] += array(
3001 3125
 			'choice' => 'external',
3002 3126
 			'server_pic' => 'blank.png',
3003 3127
 			'external' => $cur_profile['avatar']
3004 3128
 		);
3005
-	elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
3006
-		$context['member']['avatar'] += array(
3129
+	} elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
3130
+			$context['member']['avatar'] += array(
3007 3131
 			'choice' => 'server_stored',
3008 3132
 			'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
3009 3133
 			'external' => 'http://'
3010 3134
 		);
3011
-	else
3012
-		$context['member']['avatar'] += array(
3135
+	} else {
3136
+			$context['member']['avatar'] += array(
3013 3137
 			'choice' => 'none',
3014 3138
 			'server_pic' => 'blank.png',
3015 3139
 			'external' => 'http://'
3016 3140
 		);
3141
+	}
3017 3142
 
3018 3143
 	// Get a list of all the avatars.
3019 3144
 	if ($context['member']['avatar']['allow_server_stored'])
3020 3145
 	{
3021 3146
 		$context['avatar_list'] = array();
3022 3147
 		$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
3148
+	} else {
3149
+			$context['avatars'] = array();
3023 3150
 	}
3024
-	else
3025
-		$context['avatars'] = array();
3026 3151
 
3027 3152
 	// Second level selected avatar...
3028 3153
 	$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
@@ -3051,19 +3176,22 @@  discard block
 block discarded – undo
3051 3176
 			)
3052 3177
 		);
3053 3178
 		$protected_groups = array(1);
3054
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3055
-			$protected_groups[] = $row['id_group'];
3179
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3180
+					$protected_groups[] = $row['id_group'];
3181
+		}
3056 3182
 		$smcFunc['db_free_result']($request);
3057 3183
 
3058 3184
 		$protected_groups = array_unique($protected_groups);
3059 3185
 	}
3060 3186
 
3061 3187
 	// The account page allows the change of your id_group - but not to a protected group!
3062
-	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
3063
-		$value = (int) $value;
3188
+	if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) {
3189
+			$value = (int) $value;
3190
+	}
3064 3191
 	// ... otherwise it's the old group sir.
3065
-	else
3066
-		$value = $old_profile['id_group'];
3192
+	else {
3193
+			$value = $old_profile['id_group'];
3194
+	}
3067 3195
 
3068 3196
 	// Find the additional membergroups (if any)
3069 3197
 	if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
@@ -3072,16 +3200,18 @@  discard block
 block discarded – undo
3072 3200
 		foreach ($_POST['additional_groups'] as $group_id)
3073 3201
 		{
3074 3202
 			$group_id = (int) $group_id;
3075
-			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
3076
-				$additional_groups[] = $group_id;
3203
+			if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) {
3204
+							$additional_groups[] = $group_id;
3205
+			}
3077 3206
 		}
3078 3207
 
3079 3208
 		// Put the protected groups back in there if you don't have permission to take them away.
3080 3209
 		$old_additional_groups = explode(',', $old_profile['additional_groups']);
3081 3210
 		foreach ($old_additional_groups as $group_id)
3082 3211
 		{
3083
-			if (!empty($protected_groups) && in_array($group_id, $protected_groups))
3084
-				$additional_groups[] = $group_id;
3212
+			if (!empty($protected_groups) && in_array($group_id, $protected_groups)) {
3213
+							$additional_groups[] = $group_id;
3214
+			}
3085 3215
 		}
3086 3216
 
3087 3217
 		if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
@@ -3113,18 +3243,20 @@  discard block
 block discarded – undo
3113 3243
 			list ($another) = $smcFunc['db_fetch_row']($request);
3114 3244
 			$smcFunc['db_free_result']($request);
3115 3245
 
3116
-			if (empty($another))
3117
-				fatal_lang_error('at_least_one_admin', 'critical');
3246
+			if (empty($another)) {
3247
+							fatal_lang_error('at_least_one_admin', 'critical');
3248
+			}
3118 3249
 		}
3119 3250
 	}
3120 3251
 
3121 3252
 	// If we are changing group status, update permission cache as necessary.
3122 3253
 	if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
3123 3254
 	{
3124
-		if ($context['user']['is_owner'])
3125
-			$_SESSION['mc']['time'] = 0;
3126
-		else
3127
-			updateSettings(array('settings_updated' => time()));
3255
+		if ($context['user']['is_owner']) {
3256
+					$_SESSION['mc']['time'] = 0;
3257
+		} else {
3258
+					updateSettings(array('settings_updated' => time()));
3259
+		}
3128 3260
 	}
3129 3261
 
3130 3262
 	// Announce to any hooks that we have changed groups, but don't allow them to change it.
@@ -3145,8 +3277,9 @@  discard block
 block discarded – undo
3145 3277
 	global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
3146 3278
 
3147 3279
 	$memID = $context['id_member'];
3148
-	if (empty($memID) && !empty($context['password_auth_failed']))
3149
-		return false;
3280
+	if (empty($memID) && !empty($context['password_auth_failed'])) {
3281
+			return false;
3282
+	}
3150 3283
 
3151 3284
 	require_once($sourcedir . '/ManageAttachments.php');
3152 3285
 
@@ -3157,8 +3290,9 @@  discard block
 block discarded – undo
3157 3290
 	$downloadedExternalAvatar = false;
3158 3291
 	if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
3159 3292
 	{
3160
-		if (!is_writable($uploadDir))
3161
-			fatal_lang_error('attachments_no_write', 'critical');
3293
+		if (!is_writable($uploadDir)) {
3294
+					fatal_lang_error('attachments_no_write', 'critical');
3295
+		}
3162 3296
 
3163 3297
 		require_once($sourcedir . '/Subs-Package.php');
3164 3298
 
@@ -3202,19 +3336,18 @@  discard block
 block discarded – undo
3202 3336
 
3203 3337
 		// Get rid of their old avatar. (if uploaded.)
3204 3338
 		removeAttachments(array('id_member' => $memID));
3205
-	}
3206
-	elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3339
+	} elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
3207 3340
 	{
3208 3341
 		// One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar.
3209
-		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
3210
-			$profile_vars['avatar'] = 'gravatar://';
3211
-		else
3212
-			$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3342
+		if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) {
3343
+					$profile_vars['avatar'] = 'gravatar://';
3344
+		} else {
3345
+					$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
3346
+		}
3213 3347
 
3214 3348
 		// Get rid of their old avatar. (if uploaded.)
3215 3349
 		removeAttachments(array('id_member' => $memID));
3216
-	}
3217
-	elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3350
+	} elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
3218 3351
 	{
3219 3352
 		// We need these clean...
3220 3353
 		$cur_profile['id_attach'] = 0;
@@ -3226,11 +3359,13 @@  discard block
 block discarded – undo
3226 3359
 
3227 3360
 		$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
3228 3361
 
3229
-		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
3230
-			$profile_vars['avatar'] = '';
3362
+		if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') {
3363
+					$profile_vars['avatar'] = '';
3364
+		}
3231 3365
 		// Trying to make us do something we'll regret?
3232
-		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
3233
-			return 'bad_avatar_invalid_url';
3366
+		elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') {
3367
+					return 'bad_avatar_invalid_url';
3368
+		}
3234 3369
 		// Should we check dimensions?
3235 3370
 		elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
3236 3371
 		{
@@ -3240,9 +3375,9 @@  discard block
 block discarded – undo
3240 3375
 			if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
3241 3376
 			{
3242 3377
 				// Houston, we have a problem. The avatar is too large!!
3243
-				if ($modSettings['avatar_action_too_large'] == 'option_refuse')
3244
-					return 'bad_avatar_too_large';
3245
-				elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3378
+				if ($modSettings['avatar_action_too_large'] == 'option_refuse') {
3379
+									return 'bad_avatar_too_large';
3380
+				} elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
3246 3381
 				{
3247 3382
 					// @todo remove this if appropriate
3248 3383
 					require_once($sourcedir . '/Subs-Graphics.php');
@@ -3252,26 +3387,27 @@  discard block
 block discarded – undo
3252 3387
 						$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
3253 3388
 						$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
3254 3389
 						$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
3390
+					} else {
3391
+											return 'bad_avatar';
3255 3392
 					}
3256
-					else
3257
-						return 'bad_avatar';
3258 3393
 				}
3259 3394
 			}
3260 3395
 		}
3261
-	}
3262
-	elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3396
+	} elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
3263 3397
 	{
3264 3398
 		if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
3265 3399
 		{
3266 3400
 			// Get the dimensions of the image.
3267 3401
 			if (!$downloadedExternalAvatar)
3268 3402
 			{
3269
-				if (!is_writable($uploadDir))
3270
-					fatal_lang_error('attachments_no_write', 'critical');
3403
+				if (!is_writable($uploadDir)) {
3404
+									fatal_lang_error('attachments_no_write', 'critical');
3405
+				}
3271 3406
 
3272 3407
 				$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
3273
-				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
3274
-					fatal_lang_error('attach_timeout', 'critical');
3408
+				if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) {
3409
+									fatal_lang_error('attach_timeout', 'critical');
3410
+				}
3275 3411
 
3276 3412
 				$_FILES['attachment']['tmp_name'] = $new_filename;
3277 3413
 			}
@@ -3384,17 +3520,19 @@  discard block
 block discarded – undo
3384 3520
 			$profile_vars['avatar'] = '';
3385 3521
 
3386 3522
 			// Delete any temporary file.
3387
-			if (file_exists($_FILES['attachment']['tmp_name']))
3388
-				@unlink($_FILES['attachment']['tmp_name']);
3523
+			if (file_exists($_FILES['attachment']['tmp_name'])) {
3524
+							@unlink($_FILES['attachment']['tmp_name']);
3525
+			}
3389 3526
 		}
3390 3527
 		// Selected the upload avatar option and had one already uploaded before or didn't upload one.
3391
-		else
3528
+		else {
3529
+					$profile_vars['avatar'] = '';
3530
+		}
3531
+	} elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) {
3532
+			$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3533
+	} else {
3392 3534
 			$profile_vars['avatar'] = '';
3393 3535
 	}
3394
-	elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
3395
-		$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
3396
-	else
3397
-		$profile_vars['avatar'] = '';
3398 3536
 
3399 3537
 	// Setup the profile variables so it shows things right on display!
3400 3538
 	$cur_profile['avatar'] = $profile_vars['avatar'];
@@ -3442,9 +3580,9 @@  discard block
 block discarded – undo
3442 3580
 		$smiley_parsed = $unparsed_signature;
3443 3581
 		parsesmileys($smiley_parsed);
3444 3582
 		$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
3445
-		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
3446
-			return 'signature_allow_smileys';
3447
-		elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3583
+		if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) {
3584
+					return 'signature_allow_smileys';
3585
+		} elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
3448 3586
 		{
3449 3587
 			$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
3450 3588
 			return 'signature_max_smileys';
@@ -3457,14 +3595,15 @@  discard block
 block discarded – undo
3457 3595
 			{
3458 3596
 				$limit_broke = 0;
3459 3597
 				// Attempt to allow all sizes of abuse, so to speak.
3460
-				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
3461
-					$limit_broke = $sig_limits[7] . 'px';
3462
-				elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
3463
-					$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3464
-				elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
3465
-					$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3466
-				elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
3467
-					$limit_broke = 'large';
3598
+				if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) {
3599
+									$limit_broke = $sig_limits[7] . 'px';
3600
+				} elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) {
3601
+									$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
3602
+				} elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) {
3603
+									$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
3604
+				} elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) {
3605
+									$limit_broke = 'large';
3606
+				}
3468 3607
 
3469 3608
 				if ($limit_broke)
3470 3609
 				{
@@ -3506,24 +3645,26 @@  discard block
 block discarded – undo
3506 3645
 					$width = -1; $height = -1;
3507 3646
 
3508 3647
 					// Does it have predefined restraints? Width first.
3509
-					if ($matches[6][$key])
3510
-						$matches[2][$key] = $matches[6][$key];
3648
+					if ($matches[6][$key]) {
3649
+											$matches[2][$key] = $matches[6][$key];
3650
+					}
3511 3651
 					if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
3512 3652
 					{
3513 3653
 						$width = $sig_limits[5];
3514 3654
 						$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
3655
+					} elseif ($matches[2][$key]) {
3656
+											$width = $matches[2][$key];
3515 3657
 					}
3516
-					elseif ($matches[2][$key])
3517
-						$width = $matches[2][$key];
3518 3658
 					// ... and height.
3519 3659
 					if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
3520 3660
 					{
3521 3661
 						$height = $sig_limits[6];
3522
-						if ($width != -1)
3523
-							$width = $width * ($height / $matches[4][$key]);
3662
+						if ($width != -1) {
3663
+													$width = $width * ($height / $matches[4][$key]);
3664
+						}
3665
+					} elseif ($matches[4][$key]) {
3666
+											$height = $matches[4][$key];
3524 3667
 					}
3525
-					elseif ($matches[4][$key])
3526
-						$height = $matches[4][$key];
3527 3668
 
3528 3669
 					// If the dimensions are still not fixed - we need to check the actual image.
3529 3670
 					if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
@@ -3541,21 +3682,24 @@  discard block
 block discarded – undo
3541 3682
 							if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
3542 3683
 							{
3543 3684
 								$height = $sig_limits[6];
3544
-								if ($width == -1)
3545
-									$width = $sizes[0];
3685
+								if ($width == -1) {
3686
+																	$width = $sizes[0];
3687
+								}
3546 3688
 								$width = $width * ($height / $sizes[1]);
3689
+							} elseif ($width != -1) {
3690
+															$height = $sizes[1];
3547 3691
 							}
3548
-							elseif ($width != -1)
3549
-								$height = $sizes[1];
3550 3692
 						}
3551 3693
 					}
3552 3694
 
3553 3695
 					// Did we come up with some changes? If so remake the string.
3554
-					if ($width != -1 || $height != -1)
3555
-						$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3696
+					if ($width != -1 || $height != -1) {
3697
+											$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
3698
+					}
3699
+				}
3700
+				if (!empty($replaces)) {
3701
+									$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3556 3702
 				}
3557
-				if (!empty($replaces))
3558
-					$value = str_replace(array_keys($replaces), array_values($replaces), $value);
3559 3703
 			}
3560 3704
 		}
3561 3705
 
@@ -3599,10 +3743,12 @@  discard block
 block discarded – undo
3599 3743
 	$email = strtr($email, array('&#039;' => '\''));
3600 3744
 
3601 3745
 	// Check the name and email for validity.
3602
-	if (trim($email) == '')
3603
-		return 'no_email';
3604
-	if (!filter_var($email, FILTER_VALIDATE_EMAIL))
3605
-		return 'bad_email';
3746
+	if (trim($email) == '') {
3747
+			return 'no_email';
3748
+	}
3749
+	if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
3750
+			return 'bad_email';
3751
+	}
3606 3752
 
3607 3753
 	// Email addresses should be and stay unique.
3608 3754
 	$request = $smcFunc['db_query']('', '
@@ -3617,8 +3763,9 @@  discard block
 block discarded – undo
3617 3763
 		)
3618 3764
 	);
3619 3765
 
3620
-	if ($smcFunc['db_num_rows']($request) > 0)
3621
-		return 'email_taken';
3766
+	if ($smcFunc['db_num_rows']($request) > 0) {
3767
+			return 'email_taken';
3768
+	}
3622 3769
 	$smcFunc['db_free_result']($request);
3623 3770
 
3624 3771
 	return true;
@@ -3631,8 +3778,9 @@  discard block
 block discarded – undo
3631 3778
 {
3632 3779
 	global $modSettings, $context, $cur_profile;
3633 3780
 
3634
-	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
3635
-		setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3781
+	if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') {
3782
+			setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
3783
+	}
3636 3784
 
3637 3785
 	loadUserSettings();
3638 3786
 	writeLog();
@@ -3648,8 +3796,9 @@  discard block
 block discarded – undo
3648 3796
 	require_once($sourcedir . '/Subs-Post.php');
3649 3797
 
3650 3798
 	// Shouldn't happen but just in case.
3651
-	if (empty($profile_vars['email_address']))
3652
-		return;
3799
+	if (empty($profile_vars['email_address'])) {
3800
+			return;
3801
+	}
3653 3802
 
3654 3803
 	$replacements = array(
3655 3804
 		'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
@@ -3672,8 +3821,9 @@  discard block
 block discarded – undo
3672 3821
 	$_SESSION['log_time'] = 0;
3673 3822
 	$_SESSION['login_' . $cookiename] = json_encode(array(0, '', 0));
3674 3823
 
3675
-	if (isset($_COOKIE[$cookiename]))
3676
-		$_COOKIE[$cookiename] = '';
3824
+	if (isset($_COOKIE[$cookiename])) {
3825
+			$_COOKIE[$cookiename] = '';
3826
+	}
3677 3827
 
3678 3828
 	loadUserSettings();
3679 3829
 
@@ -3706,11 +3856,13 @@  discard block
 block discarded – undo
3706 3856
 	$groups[] = $curMember['id_group'];
3707 3857
 
3708 3858
 	// Ensure the query doesn't croak!
3709
-	if (empty($groups))
3710
-		$groups = array(0);
3859
+	if (empty($groups)) {
3860
+			$groups = array(0);
3861
+	}
3711 3862
 	// Just to be sure...
3712
-	foreach ($groups as $k => $v)
3713
-		$groups[$k] = (int) $v;
3863
+	foreach ($groups as $k => $v) {
3864
+			$groups[$k] = (int) $v;
3865
+	}
3714 3866
 
3715 3867
 	// Get all the membergroups they can join.
3716 3868
 	$request = $smcFunc['db_query']('', '
@@ -3740,12 +3892,14 @@  discard block
 block discarded – undo
3740 3892
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3741 3893
 	{
3742 3894
 		// Can they edit their primary group?
3743
-		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
3744
-			$context['can_edit_primary'] = true;
3895
+		if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) {
3896
+					$context['can_edit_primary'] = true;
3897
+		}
3745 3898
 
3746 3899
 		// If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
3747
-		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
3748
-			continue;
3900
+		if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) {
3901
+					continue;
3902
+		}
3749 3903
 
3750 3904
 		$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
3751 3905
 			'id' => $row['id_group'],
@@ -3774,13 +3928,15 @@  discard block
 block discarded – undo
3774 3928
 	);
3775 3929
 
3776 3930
 	// No changing primary one unless you have enough groups!
3777
-	if (count($context['groups']['member']) < 2)
3778
-		$context['can_edit_primary'] = false;
3931
+	if (count($context['groups']['member']) < 2) {
3932
+			$context['can_edit_primary'] = false;
3933
+	}
3779 3934
 
3780 3935
 	// In the special case that someone is requesting membership of a group, setup some special context vars.
3781
-	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
3782
-		$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3783
-}
3936
+	if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) {
3937
+			$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
3938
+	}
3939
+	}
3784 3940
 
3785 3941
 /**
3786 3942
  * This function actually makes all the group changes
@@ -3795,10 +3951,12 @@  discard block
 block discarded – undo
3795 3951
 	global $user_info, $context, $user_profile, $modSettings, $smcFunc;
3796 3952
 
3797 3953
 	// Let's be extra cautious...
3798
-	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
3799
-		isAllowedTo('manage_membergroups');
3800
-	if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
3801
-		fatal_lang_error('no_access', false);
3954
+	if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) {
3955
+			isAllowedTo('manage_membergroups');
3956
+	}
3957
+	if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) {
3958
+			fatal_lang_error('no_access', false);
3959
+	}
3802 3960
 
3803 3961
 	checkSession(isset($_GET['gid']) ? 'get' : 'post');
3804 3962
 
@@ -3817,8 +3975,9 @@  discard block
 block discarded – undo
3817 3975
 	$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
3818 3976
 
3819 3977
 	// Sanity check!!
3820
-	if ($group_id == 1)
3821
-		isAllowedTo('admin_forum');
3978
+	if ($group_id == 1) {
3979
+			isAllowedTo('admin_forum');
3980
+	}
3822 3981
 	// Protected groups too!
3823 3982
 	else
3824 3983
 	{
@@ -3835,8 +3994,9 @@  discard block
 block discarded – undo
3835 3994
 		list ($is_protected) = $smcFunc['db_fetch_row']($request);
3836 3995
 		$smcFunc['db_free_result']($request);
3837 3996
 
3838
-		if ($is_protected == 1)
3839
-			isAllowedTo('admin_forum');
3997
+		if ($is_protected == 1) {
3998
+					isAllowedTo('admin_forum');
3999
+		}
3840 4000
 	}
3841 4001
 
3842 4002
 	// What ever we are doing, we need to determine if changing primary is possible!
@@ -3858,36 +4018,43 @@  discard block
 block discarded – undo
3858 4018
 			$group_name = $row['group_name'];
3859 4019
 
3860 4020
 			// Does the group type match what we're doing - are we trying to request a non-requestable group?
3861
-			if ($changeType == 'request' && $row['group_type'] != 2)
3862
-				fatal_lang_error('no_access', false);
4021
+			if ($changeType == 'request' && $row['group_type'] != 2) {
4022
+							fatal_lang_error('no_access', false);
4023
+			}
3863 4024
 			// What about leaving a requestable group we are not a member of?
3864
-			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
3865
-				fatal_lang_error('no_access', false);
3866
-			elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
3867
-				fatal_lang_error('no_access', false);
4025
+			elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) {
4026
+							fatal_lang_error('no_access', false);
4027
+			} elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) {
4028
+							fatal_lang_error('no_access', false);
4029
+			}
3868 4030
 
3869 4031
 			// We can't change the primary group if this is hidden!
3870
-			if ($row['hidden'] == 2)
3871
-				$canChangePrimary = false;
4032
+			if ($row['hidden'] == 2) {
4033
+							$canChangePrimary = false;
4034
+			}
3872 4035
 		}
3873 4036
 
3874 4037
 		// If this is their old primary, can we change it?
3875
-		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
3876
-			$canChangePrimary = 1;
4038
+		if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) {
4039
+					$canChangePrimary = 1;
4040
+		}
3877 4041
 
3878 4042
 		// If we are not doing a force primary move, don't do it automatically if current primary is not 0.
3879
-		if ($changeType != 'primary' && $old_profile['id_group'] != 0)
3880
-			$canChangePrimary = false;
4043
+		if ($changeType != 'primary' && $old_profile['id_group'] != 0) {
4044
+					$canChangePrimary = false;
4045
+		}
3881 4046
 
3882 4047
 		// If this is the one we are acting on, can we even act?
3883
-		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
3884
-			$canChangePrimary = false;
4048
+		if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) {
4049
+					$canChangePrimary = false;
4050
+		}
3885 4051
 	}
3886 4052
 	$smcFunc['db_free_result']($request);
3887 4053
 
3888 4054
 	// Didn't find the target?
3889
-	if (!$foundTarget)
3890
-		fatal_lang_error('no_access', false);
4055
+	if (!$foundTarget) {
4056
+			fatal_lang_error('no_access', false);
4057
+	}
3891 4058
 
3892 4059
 	// Final security check, don't allow users to promote themselves to admin.
3893 4060
 	if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
@@ -3907,8 +4074,9 @@  discard block
 block discarded – undo
3907 4074
 		list ($disallow) = $smcFunc['db_fetch_row']($request);
3908 4075
 		$smcFunc['db_free_result']($request);
3909 4076
 
3910
-		if ($disallow)
3911
-			isAllowedTo('admin_forum');
4077
+		if ($disallow) {
4078
+					isAllowedTo('admin_forum');
4079
+		}
3912 4080
 	}
3913 4081
 
3914 4082
 	// If we're requesting, add the note then return.
@@ -3926,8 +4094,9 @@  discard block
 block discarded – undo
3926 4094
 				'status_open' => 0,
3927 4095
 			)
3928 4096
 		);
3929
-		if ($smcFunc['db_num_rows']($request) != 0)
3930
-			fatal_lang_error('profile_error_already_requested_group');
4097
+		if ($smcFunc['db_num_rows']($request) != 0) {
4098
+					fatal_lang_error('profile_error_already_requested_group');
4099
+		}
3931 4100
 		$smcFunc['db_free_result']($request);
3932 4101
 
3933 4102
 		// Log the request.
@@ -3961,10 +4130,11 @@  discard block
 block discarded – undo
3961 4130
 		// Are we leaving?
3962 4131
 		if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
3963 4132
 		{
3964
-			if ($old_profile['id_group'] == $group_id)
3965
-				$newPrimary = 0;
3966
-			else
3967
-				unset($addGroups[$group_id]);
4133
+			if ($old_profile['id_group'] == $group_id) {
4134
+							$newPrimary = 0;
4135
+			} else {
4136
+							unset($addGroups[$group_id]);
4137
+			}
3968 4138
 		}
3969 4139
 		// ... if not, must be joining.
3970 4140
 		else
@@ -3972,36 +4142,42 @@  discard block
 block discarded – undo
3972 4142
 			// Can we change the primary, and do we want to?
3973 4143
 			if ($canChangePrimary)
3974 4144
 			{
3975
-				if ($old_profile['id_group'] != 0)
3976
-					$addGroups[$old_profile['id_group']] = -1;
4145
+				if ($old_profile['id_group'] != 0) {
4146
+									$addGroups[$old_profile['id_group']] = -1;
4147
+				}
3977 4148
 				$newPrimary = $group_id;
3978 4149
 			}
3979 4150
 			// Otherwise it's an additional group...
3980
-			else
3981
-				$addGroups[$group_id] = -1;
4151
+			else {
4152
+							$addGroups[$group_id] = -1;
4153
+			}
3982 4154
 		}
3983 4155
 	}
3984 4156
 	// Finally, we must be setting the primary.
3985 4157
 	elseif ($canChangePrimary)
3986 4158
 	{
3987
-		if ($old_profile['id_group'] != 0)
3988
-			$addGroups[$old_profile['id_group']] = -1;
3989
-		if (isset($addGroups[$group_id]))
3990
-			unset($addGroups[$group_id]);
4159
+		if ($old_profile['id_group'] != 0) {
4160
+					$addGroups[$old_profile['id_group']] = -1;
4161
+		}
4162
+		if (isset($addGroups[$group_id])) {
4163
+					unset($addGroups[$group_id]);
4164
+		}
3991 4165
 		$newPrimary = $group_id;
3992 4166
 	}
3993 4167
 
3994 4168
 	// Finally, we can make the changes!
3995
-	foreach ($addGroups as $id => $dummy)
3996
-		if (empty($id))
4169
+	foreach ($addGroups as $id => $dummy) {
4170
+			if (empty($id))
3997 4171
 			unset($addGroups[$id]);
4172
+	}
3998 4173
 	$addGroups = implode(',', array_flip($addGroups));
3999 4174
 
4000 4175
 	// Ensure that we don't cache permissions if the group is changing.
4001
-	if ($context['user']['is_owner'])
4002
-		$_SESSION['mc']['time'] = 0;
4003
-	else
4004
-		updateSettings(array('settings_updated' => time()));
4176
+	if ($context['user']['is_owner']) {
4177
+			$_SESSION['mc']['time'] = 0;
4178
+	} else {
4179
+			updateSettings(array('settings_updated' => time()));
4180
+	}
4005 4181
 
4006 4182
 	updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
4007 4183
 
@@ -4024,8 +4200,9 @@  discard block
 block discarded – undo
4024 4200
 	if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
4025 4201
 	{
4026 4202
 		// Check to ensure we're forcing SSL for authentication
4027
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
4028
-			fatal_lang_error('login_ssl_required');
4203
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
4204
+					fatal_lang_error('login_ssl_required');
4205
+		}
4029 4206
 
4030 4207
 		// In some cases (forced 2FA or backup code) they would be forced to be redirected here,
4031 4208
 		// we do not want too much AJAX to confuse them.
@@ -4062,8 +4239,7 @@  discard block
 block discarded – undo
4062 4239
 				$context['sub_template'] = 'tfasetup_backup';
4063 4240
 
4064 4241
 				return;
4065
-			}
4066
-			else
4242
+			} else
4067 4243
 			{
4068 4244
 				$context['tfa_secret'] = $_SESSION['tfa_secret'];
4069 4245
 				$context['tfa_error'] = !$valid_code;
@@ -4071,8 +4247,7 @@  discard block
 block discarded – undo
4071 4247
 				$context['tfa_pass_value'] = $_POST['passwd'];
4072 4248
 				$context['tfa_value'] = $_POST['tfa_code'];
4073 4249
 			}
4074
-		}
4075
-		else
4250
+		} else
4076 4251
 		{
4077 4252
 			$totp = new \TOTP\Auth();
4078 4253
 			$secret = $totp->generateCode();
@@ -4082,17 +4257,16 @@  discard block
 block discarded – undo
4082 4257
 		}
4083 4258
 
4084 4259
 		$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
4085
-	}
4086
-	elseif (isset($_REQUEST['disable']))
4260
+	} elseif (isset($_REQUEST['disable']))
4087 4261
 	{
4088 4262
 		updateMemberData($memID, array(
4089 4263
 			'tfa_secret' => '',
4090 4264
 			'tfa_backup' => '',
4091 4265
 		));
4092 4266
 		redirectexit('action=profile;area=account;u=' . $memID);
4267
+	} else {
4268
+			redirectexit('action=profile;area=account;u=' . $memID);
4269
+	}
4093 4270
 	}
4094
-	else
4095
-		redirectexit('action=profile;area=account;u=' . $memID);
4096
-}
4097 4271
 
4098 4272
 ?>
4099 4273
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Profile-View.php 1 patch
Braces   +297 added lines, -216 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@  discard block
 block discarded – undo
11 11
  * @version 2.1 Beta 3
12 12
  */
13 13
 
14
-if (!defined('SMF'))
14
+if (!defined('SMF')) {
15 15
 	die('No direct access...');
16
+}
16 17
 
17 18
 /**
18 19
  * View a summary.
@@ -23,8 +24,9 @@  discard block
 block discarded – undo
23 24
 	global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
24 25
 
25 26
 	// Attempt to load the member's profile data.
26
-	if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
27
-		fatal_lang_error('not_a_user', false, 404);
27
+	if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
28
+			fatal_lang_error('not_a_user', false, 404);
29
+	}
28 30
 
29 31
 	// Set up the stuff and load the user.
30 32
 	$context += array(
@@ -49,19 +51,21 @@  discard block
 block discarded – undo
49 51
 
50 52
 	// See if they have broken any warning levels...
51 53
 	list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
52
-	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
53
-		$context['warning_status'] = $txt['profile_warning_is_muted'];
54
-	elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
55
-		$context['warning_status'] = $txt['profile_warning_is_moderation'];
56
-	elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
57
-		$context['warning_status'] = $txt['profile_warning_is_watch'];
54
+	if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
55
+			$context['warning_status'] = $txt['profile_warning_is_muted'];
56
+	} elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
57
+			$context['warning_status'] = $txt['profile_warning_is_moderation'];
58
+	} elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
59
+			$context['warning_status'] = $txt['profile_warning_is_watch'];
60
+	}
58 61
 
59 62
 	// They haven't even been registered for a full day!?
60 63
 	$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
61
-	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
62
-		$context['member']['posts_per_day'] = $txt['not_applicable'];
63
-	else
64
-		$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
64
+	if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
65
+			$context['member']['posts_per_day'] = $txt['not_applicable'];
66
+	} else {
67
+			$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
68
+	}
65 69
 
66 70
 	// Set the age...
67 71
 	if (empty($context['member']['birth_date']))
@@ -70,8 +74,7 @@  discard block
 block discarded – undo
70 74
 			'age' => $txt['not_applicable'],
71 75
 			'today_is_birthday' => false
72 76
 		);
73
-	}
74
-	else
77
+	} else
75 78
 	{
76 79
 		list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
77 80
 		$datearray = getdate(forum_time());
@@ -84,15 +87,16 @@  discard block
 block discarded – undo
84 87
 	if (allowedTo('moderate_forum'))
85 88
 	{
86 89
 		// Make sure it's a valid ip address; otherwise, don't bother...
87
-		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
88
-			$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
89
-		else
90
-			$context['member']['hostname'] = '';
90
+		if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
91
+					$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
92
+		} else {
93
+					$context['member']['hostname'] = '';
94
+		}
91 95
 
92 96
 		$context['can_see_ip'] = true;
97
+	} else {
98
+			$context['can_see_ip'] = false;
93 99
 	}
94
-	else
95
-		$context['can_see_ip'] = false;
96 100
 
97 101
 	// Are they hidden?
98 102
 	$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
@@ -103,8 +107,9 @@  discard block
 block discarded – undo
103 107
 		include_once($sourcedir . '/Who.php');
104 108
 		$action = determineActions($user_profile[$memID]['url']);
105 109
 
106
-		if ($action !== false)
107
-			$context['member']['action'] = $action;
110
+		if ($action !== false) {
111
+					$context['member']['action'] = $action;
112
+		}
108 113
 	}
109 114
 
110 115
 	// If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
@@ -167,13 +172,15 @@  discard block
 block discarded – undo
167 172
 		{
168 173
 			// Work out what restrictions we actually have.
169 174
 			$ban_restrictions = array();
170
-			foreach (array('access', 'register', 'login', 'post') as $type)
171
-				if ($row['cannot_' . $type])
175
+			foreach (array('access', 'register', 'login', 'post') as $type) {
176
+							if ($row['cannot_' . $type])
172 177
 					$ban_restrictions[] = $txt['ban_type_' . $type];
178
+			}
173 179
 
174 180
 			// No actual ban in place?
175
-			if (empty($ban_restrictions))
176
-				continue;
181
+			if (empty($ban_restrictions)) {
182
+							continue;
183
+			}
177 184
 
178 185
 			// Prepare the link for context.
179 186
 			$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
@@ -196,9 +203,10 @@  discard block
 block discarded – undo
196 203
 	$context['print_custom_fields'] = array();
197 204
 
198 205
 	// Any custom profile fields?
199
-	if (!empty($context['custom_fields']))
200
-		foreach ($context['custom_fields'] as $custom)
206
+	if (!empty($context['custom_fields'])) {
207
+			foreach ($context['custom_fields'] as $custom)
201 208
 			$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
209
+	}
202 210
 
203 211
 }
204 212
 
@@ -242,14 +250,16 @@  discard block
 block discarded – undo
242 250
 		$row['extra'] = !empty($row['extra']) ? smf_json_decode($row['extra'], true) : array();
243 251
 		$alerts[$id_alert] = $row;
244 252
 
245
-		if (!empty($row['sender_id']))
246
-			$senders[] = $row['sender_id'];
253
+		if (!empty($row['sender_id'])) {
254
+					$senders[] = $row['sender_id'];
255
+		}
247 256
 	}
248 257
 	$smcFunc['db_free_result']($request);
249 258
 
250 259
 	$senders = loadMemberData($senders);
251
-	foreach ($senders as $member)
252
-		loadMemberContext($member);
260
+	foreach ($senders as $member) {
261
+			loadMemberContext($member);
262
+	}
253 263
 
254 264
 	// Now go through and actually make with the text.
255 265
 	loadLanguage('Alerts');
@@ -263,12 +273,15 @@  discard block
 block discarded – undo
263 273
 	$msgs = array();
264 274
 	foreach ($alerts as $id_alert => $alert)
265 275
 	{
266
-		if (isset($alert['extra']['board']))
267
-			$boards[$alert['extra']['board']] = $txt['board_na'];
268
-		if (isset($alert['extra']['topic']))
269
-			$topics[$alert['extra']['topic']] = $txt['topic_na'];
270
-		if ($alert['content_type'] == 'msg')
271
-			$msgs[$alert['content_id']] = $txt['topic_na'];
276
+		if (isset($alert['extra']['board'])) {
277
+					$boards[$alert['extra']['board']] = $txt['board_na'];
278
+		}
279
+		if (isset($alert['extra']['topic'])) {
280
+					$topics[$alert['extra']['topic']] = $txt['topic_na'];
281
+		}
282
+		if ($alert['content_type'] == 'msg') {
283
+					$msgs[$alert['content_id']] = $txt['topic_na'];
284
+		}
272 285
 	}
273 286
 
274 287
 	// Having figured out what boards etc. there are, let's now get the names of them if we can see them. If not, there's already a fallback set up.
@@ -283,8 +296,9 @@  discard block
 block discarded – undo
283 296
 				'boards' => array_keys($boards),
284 297
 			)
285 298
 		);
286
-		while ($row = $smcFunc['db_fetch_assoc']($request))
287
-			$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
299
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
300
+					$boards[$row['id_board']] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
301
+		}
288 302
 	}
289 303
 	if (!empty($topics))
290 304
 	{
@@ -299,8 +313,9 @@  discard block
 block discarded – undo
299 313
 				'topics' => array_keys($topics),
300 314
 			)
301 315
 		);
302
-		while ($row = $smcFunc['db_fetch_assoc']($request))
303
-			$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
316
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
317
+					$topics[$row['id_topic']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>';
318
+		}
304 319
 	}
305 320
 	if (!empty($msgs))
306 321
 	{
@@ -315,26 +330,33 @@  discard block
 block discarded – undo
315 330
 				'msgs' => array_keys($msgs),
316 331
 			)
317 332
 		);
318
-		while ($row = $smcFunc['db_fetch_assoc']($request))
319
-			$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
333
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
334
+					$msgs[$row['id_msg']] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
335
+		}
320 336
 	}
321 337
 
322 338
 	// Now to go back through the alerts, reattach this extra information and then try to build the string out of it (if a hook didn't already)
323 339
 	foreach ($alerts as $id_alert => $alert)
324 340
 	{
325
-		if (!empty($alert['text']))
326
-			continue;
327
-		if (isset($alert['extra']['board']))
328
-			$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
329
-		if (isset($alert['extra']['topic']))
330
-			$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
331
-		if ($alert['content_type'] == 'msg')
332
-			$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
333
-		if ($alert['content_type'] == 'profile')
334
-			$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
335
-
336
-		if (!empty($memberContext[$alert['sender_id']]))
337
-			$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
341
+		if (!empty($alert['text'])) {
342
+					continue;
343
+		}
344
+		if (isset($alert['extra']['board'])) {
345
+					$alerts[$id_alert]['extra']['board_msg'] = $boards[$alert['extra']['board']];
346
+		}
347
+		if (isset($alert['extra']['topic'])) {
348
+					$alerts[$id_alert]['extra']['topic_msg'] = $topics[$alert['extra']['topic']];
349
+		}
350
+		if ($alert['content_type'] == 'msg') {
351
+					$alerts[$id_alert]['extra']['msg_msg'] = $msgs[$alert['content_id']];
352
+		}
353
+		if ($alert['content_type'] == 'profile') {
354
+					$alerts[$id_alert]['extra']['profile_msg'] = '<a href="' . $scripturl . '?action=profile;u=' . $alerts[$id_alert]['content_id'] . '">' . $alerts[$id_alert]['extra']['user_name'] . '</a>';
355
+		}
356
+
357
+		if (!empty($memberContext[$alert['sender_id']])) {
358
+					$alerts[$id_alert]['sender'] = &$memberContext[$alert['sender_id']];
359
+		}
338 360
 
339 361
 		$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
340 362
 		if (isset($txt[$string]))
@@ -422,11 +444,11 @@  discard block
 block discarded – undo
422 444
 		checkSession('request');
423 445
 
424 446
 		// Call it!
425
-		if ($action == 'remove')
426
-			alert_delete($toMark, $memID);
427
-
428
-		else
429
-			alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
447
+		if ($action == 'remove') {
448
+					alert_delete($toMark, $memID);
449
+		} else {
450
+					alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
451
+		}
430 452
 
431 453
 		// Set a nice update message.
432 454
 		$_SESSION['update_message'] = true;
@@ -476,23 +498,27 @@  discard block
 block discarded – undo
476 498
 	);
477 499
 
478 500
 	// Set the page title
479
-	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
480
-		$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
481
-	else
482
-		$context['page_title'] = $txt['showPosts'];
501
+	if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title)) {
502
+			$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
503
+	} else {
504
+			$context['page_title'] = $txt['showPosts'];
505
+	}
483 506
 
484 507
 	$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
485 508
 
486 509
 	// Is the load average too high to allow searching just now?
487
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
488
-		fatal_lang_error('loadavg_show_posts_disabled', false);
510
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts']) {
511
+			fatal_lang_error('loadavg_show_posts_disabled', false);
512
+	}
489 513
 
490 514
 	// If we're specifically dealing with attachments use that function!
491
-	if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
492
-		return showAttachments($memID);
515
+	if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
516
+			return showAttachments($memID);
517
+	}
493 518
 	// Instead, if we're dealing with unwatched topics (and the feature is enabled) use that other function.
494
-	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
495
-		return showUnwatched($memID);
519
+	elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics') {
520
+			return showUnwatched($memID);
521
+	}
496 522
 
497 523
 	// Are we just viewing topics?
498 524
 	$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
@@ -515,27 +541,30 @@  discard block
 block discarded – undo
515 541
 		$smcFunc['db_free_result']($request);
516 542
 
517 543
 		// Trying to remove a message that doesn't exist.
518
-		if (empty($info))
519
-			redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
544
+		if (empty($info)) {
545
+					redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
546
+		}
520 547
 
521 548
 		// We can be lazy, since removeMessage() will check the permissions for us.
522 549
 		require_once($sourcedir . '/RemoveTopic.php');
523 550
 		removeMessage((int) $_GET['delete']);
524 551
 
525 552
 		// Add it to the mod log.
526
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
527
-			logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
553
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
554
+					logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
555
+		}
528 556
 
529 557
 		// Back to... where we are now ;).
530 558
 		redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
531 559
 	}
532 560
 
533 561
 	// Default to 10.
534
-	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
535
-		$_REQUEST['viewscount'] = '10';
562
+	if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
563
+			$_REQUEST['viewscount'] = '10';
564
+	}
536 565
 
537
-	if ($context['is_topics'])
538
-		$request = $smcFunc['db_query']('', '
566
+	if ($context['is_topics']) {
567
+			$request = $smcFunc['db_query']('', '
539 568
 			SELECT COUNT(*)
540 569
 			FROM {db_prefix}topics AS t' . ($user_info['query_see_board'] == '1=1' ? '' : '
541 570
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})') . '
@@ -548,8 +577,8 @@  discard block
 block discarded – undo
548 577
 				'board' => $board,
549 578
 			)
550 579
 		);
551
-	else
552
-		$request = $smcFunc['db_query']('', '
580
+	} else {
581
+			$request = $smcFunc['db_query']('', '
553 582
 			SELECT COUNT(*)
554 583
 			FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
555 584
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
@@ -562,6 +591,7 @@  discard block
 block discarded – undo
562 591
 				'board' => $board,
563 592
 			)
564 593
 		);
594
+	}
565 595
 	list ($msgCount) = $smcFunc['db_fetch_row']($request);
566 596
 	$smcFunc['db_free_result']($request);
567 597
 
@@ -583,10 +613,11 @@  discard block
 block discarded – undo
583 613
 	$reverse = false;
584 614
 	$range_limit = '';
585 615
 
586
-	if ($context['is_topics'])
587
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
588
-	else
589
-		$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
616
+	if ($context['is_topics']) {
617
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
618
+	} else {
619
+			$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
620
+	}
590 621
 
591 622
 	$maxIndex = $maxPerPage;
592 623
 
@@ -612,9 +643,9 @@  discard block
 block discarded – undo
612 643
 		{
613 644
 			$margin *= 5;
614 645
 			$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
646
+		} else {
647
+					$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
615 648
 		}
616
-		else
617
-			$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
618 649
 	}
619 650
 
620 651
 	// Find this user's posts.  The left join on categories somehow makes this faster, weird as it looks.
@@ -646,8 +677,7 @@  discard block
 block discarded – undo
646 677
 					'max' => $maxIndex,
647 678
 				)
648 679
 			);
649
-		}
650
-		else
680
+		} else
651 681
 		{
652 682
 			$request = $smcFunc['db_query']('', '
653 683
 				SELECT
@@ -676,8 +706,9 @@  discard block
 block discarded – undo
676 706
 		}
677 707
 
678 708
 		// Make sure we quit this loop.
679
-		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped)
680
-			break;
709
+		if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped) {
710
+					break;
711
+		}
681 712
 		$looped = true;
682 713
 		$range_limit = '';
683 714
 	}
@@ -721,19 +752,21 @@  discard block
 block discarded – undo
721 752
 			'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
722 753
 		);
723 754
 
724
-		if ($user_info['id'] == $row['id_member_started'])
725
-			$board_ids['own'][$row['id_board']][] = $counter;
755
+		if ($user_info['id'] == $row['id_member_started']) {
756
+					$board_ids['own'][$row['id_board']][] = $counter;
757
+		}
726 758
 		$board_ids['any'][$row['id_board']][] = $counter;
727 759
 	}
728 760
 	$smcFunc['db_free_result']($request);
729 761
 
730 762
 	// All posts were retrieved in reverse order, get them right again.
731
-	if ($reverse)
732
-		$context['posts'] = array_reverse($context['posts'], true);
763
+	if ($reverse) {
764
+			$context['posts'] = array_reverse($context['posts'], true);
765
+	}
733 766
 
734 767
 	// These are all the permissions that are different from board to board..
735
-	if ($context['is_topics'])
736
-		$permissions = array(
768
+	if ($context['is_topics']) {
769
+			$permissions = array(
737 770
 			'own' => array(
738 771
 				'post_reply_own' => 'can_reply',
739 772
 			),
@@ -741,8 +774,8 @@  discard block
 block discarded – undo
741 774
 				'post_reply_any' => 'can_reply',
742 775
 			)
743 776
 		);
744
-	else
745
-		$permissions = array(
777
+	} else {
778
+			$permissions = array(
746 779
 			'own' => array(
747 780
 				'post_reply_own' => 'can_reply',
748 781
 				'delete_own' => 'can_delete',
@@ -752,6 +785,7 @@  discard block
 block discarded – undo
752 785
 				'delete_any' => 'can_delete',
753 786
 			)
754 787
 		);
788
+	}
755 789
 
756 790
 	// For every permission in the own/any lists...
757 791
 	foreach ($permissions as $type => $list)
@@ -762,19 +796,22 @@  discard block
 block discarded – undo
762 796
 			$boards = boardsAllowedTo($permission);
763 797
 
764 798
 			// Hmm, they can do it on all boards, can they?
765
-			if (!empty($boards) && $boards[0] == 0)
766
-				$boards = array_keys($board_ids[$type]);
799
+			if (!empty($boards) && $boards[0] == 0) {
800
+							$boards = array_keys($board_ids[$type]);
801
+			}
767 802
 
768 803
 			// Now go through each board they can do the permission on.
769 804
 			foreach ($boards as $board_id)
770 805
 			{
771 806
 				// There aren't any posts displayed from this board.
772
-				if (!isset($board_ids[$type][$board_id]))
773
-					continue;
807
+				if (!isset($board_ids[$type][$board_id])) {
808
+									continue;
809
+				}
774 810
 
775 811
 				// Set the permission to true ;).
776
-				foreach ($board_ids[$type][$board_id] as $counter)
777
-					$context['posts'][$counter][$allowed] = true;
812
+				foreach ($board_ids[$type][$board_id] as $counter) {
813
+									$context['posts'][$counter][$allowed] = true;
814
+				}
778 815
 			}
779 816
 		}
780 817
 	}
@@ -805,8 +842,9 @@  discard block
 block discarded – undo
805 842
 	$boardsAllowed = boardsAllowedTo('view_attachments');
806 843
 
807 844
 	// Make sure we can't actually see anything...
808
-	if (empty($boardsAllowed))
809
-		$boardsAllowed = array(-1);
845
+	if (empty($boardsAllowed)) {
846
+			$boardsAllowed = array(-1);
847
+	}
810 848
 
811 849
 	require_once($sourcedir . '/Subs-List.php');
812 850
 
@@ -957,8 +995,8 @@  discard block
 block discarded – undo
957 995
 		)
958 996
 	);
959 997
 	$attachments = array();
960
-	while ($row = $smcFunc['db_fetch_assoc']($request))
961
-		$attachments[] = array(
998
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
999
+			$attachments[] = array(
962 1000
 			'id' => $row['id_attach'],
963 1001
 			'filename' => $row['filename'],
964 1002
 			'downloads' => $row['downloads'],
@@ -970,6 +1008,7 @@  discard block
 block discarded – undo
970 1008
 			'board_name' => $row['name'],
971 1009
 			'approved' => $row['approved'],
972 1010
 		);
1011
+	}
973 1012
 
974 1013
 	$smcFunc['db_free_result']($request);
975 1014
 
@@ -1024,8 +1063,9 @@  discard block
 block discarded – undo
1024 1063
 	global $txt, $user_info, $scripturl, $modSettings, $context, $sourcedir;
1025 1064
 
1026 1065
 	// Only the owner can see the list (if the function is enabled of course)
1027
-	if ($user_info['id'] != $memID)
1028
-		return;
1066
+	if ($user_info['id'] != $memID) {
1067
+			return;
1068
+	}
1029 1069
 
1030 1070
 	require_once($sourcedir . '/Subs-List.php');
1031 1071
 
@@ -1171,8 +1211,9 @@  discard block
 block discarded – undo
1171 1211
 	);
1172 1212
 
1173 1213
 	$topics = array();
1174
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1175
-		$topics[] = $row['id_topic'];
1214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1215
+			$topics[] = $row['id_topic'];
1216
+	}
1176 1217
 
1177 1218
 	$smcFunc['db_free_result']($request);
1178 1219
 
@@ -1192,8 +1233,9 @@  discard block
 block discarded – undo
1192 1233
 				'topics' => $topics,
1193 1234
 			)
1194 1235
 		);
1195
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1196
-			$topicsInfo[] = $row;
1236
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1237
+					$topicsInfo[] = $row;
1238
+		}
1197 1239
 		$smcFunc['db_free_result']($request);
1198 1240
 	}
1199 1241
 
@@ -1241,8 +1283,9 @@  discard block
 block discarded – undo
1241 1283
 	$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
1242 1284
 
1243 1285
 	// Is the load average too high to allow searching just now?
1244
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
1245
-		fatal_lang_error('loadavg_userstats_disabled', false);
1286
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats']) {
1287
+			fatal_lang_error('loadavg_userstats_disabled', false);
1288
+	}
1246 1289
 
1247 1290
 	// General user statistics.
1248 1291
 	$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
@@ -1400,11 +1443,13 @@  discard block
 block discarded – undo
1400 1443
 	}
1401 1444
 	$smcFunc['db_free_result']($result);
1402 1445
 
1403
-	if ($maxPosts > 0)
1404
-		for ($hour = 0; $hour < 24; $hour++)
1446
+	if ($maxPosts > 0) {
1447
+			for ($hour = 0;
1448
+	}
1449
+	$hour < 24; $hour++)
1405 1450
 		{
1406
-			if (!isset($context['posts_by_time'][$hour]))
1407
-				$context['posts_by_time'][$hour] = array(
1451
+			if (!isset($context['posts_by_time'][$hour])) {
1452
+							$context['posts_by_time'][$hour] = array(
1408 1453
 					'hour' => $hour,
1409 1454
 					'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
1410 1455
 					'posts' => 0,
@@ -1412,7 +1457,7 @@  discard block
 block discarded – undo
1412 1457
 					'relative_percent' => 0,
1413 1458
 					'is_last' => $hour == 23,
1414 1459
 				);
1415
-			else
1460
+			} else
1416 1461
 			{
1417 1462
 				$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
1418 1463
 				$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
@@ -1445,8 +1490,9 @@  discard block
 block discarded – undo
1445 1490
 
1446 1491
 	foreach ($subActions as $sa => $action)
1447 1492
 	{
1448
-		if (!allowedTo($action[2]))
1449
-			unset($subActions[$sa]);
1493
+		if (!allowedTo($action[2])) {
1494
+					unset($subActions[$sa]);
1495
+		}
1450 1496
 	}
1451 1497
 
1452 1498
 	// Create the tabs for the template.
@@ -1464,15 +1510,18 @@  discard block
 block discarded – undo
1464 1510
 	);
1465 1511
 
1466 1512
 	// Moderation must be on to track edits.
1467
-	if (empty($modSettings['userlog_enabled']))
1468
-		unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1513
+	if (empty($modSettings['userlog_enabled'])) {
1514
+			unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
1515
+	}
1469 1516
 
1470 1517
 	// Group requests must be active to show it...
1471
-	if (empty($modSettings['show_group_membership']))
1472
-		unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1518
+	if (empty($modSettings['show_group_membership'])) {
1519
+			unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
1520
+	}
1473 1521
 
1474
-	if (empty($subActions))
1475
-		fatal_lang_error('no_access', false);
1522
+	if (empty($subActions)) {
1523
+			fatal_lang_error('no_access', false);
1524
+	}
1476 1525
 
1477 1526
 	$keys = array_keys($subActions);
1478 1527
 	$default = array_shift($keys);
@@ -1485,9 +1534,10 @@  discard block
 block discarded – undo
1485 1534
 	$context['sub_template'] = $subActions[$context['tracking_area']][0];
1486 1535
 	$call = call_helper($subActions[$context['tracking_area']][0], true);
1487 1536
 
1488
-	if (!empty($call))
1489
-		call_user_func($call, $memID);
1490
-}
1537
+	if (!empty($call)) {
1538
+			call_user_func($call, $memID);
1539
+	}
1540
+	}
1491 1541
 
1492 1542
 /**
1493 1543
  * Handles tracking a user's activity
@@ -1503,8 +1553,9 @@  discard block
 block discarded – undo
1503 1553
 	isAllowedTo('moderate_forum');
1504 1554
 
1505 1555
 	$context['last_ip'] = $user_profile[$memID]['member_ip'];
1506
-	if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
1507
-		$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1556
+	if ($context['last_ip'] != $user_profile[$memID]['member_ip2']) {
1557
+			$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
1558
+	}
1508 1559
 	$context['member']['name'] = $user_profile[$memID]['real_name'];
1509 1560
 
1510 1561
 	// Set the options for the list component.
@@ -1670,8 +1721,9 @@  discard block
 block discarded – undo
1670 1721
 			)
1671 1722
 		);
1672 1723
 		$message_members = array();
1673
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1674
-			$message_members[] = $row['id_member'];
1724
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1725
+					$message_members[] = $row['id_member'];
1726
+		}
1675 1727
 		$smcFunc['db_free_result']($request);
1676 1728
 
1677 1729
 		// Fetch their names, cause of the GROUP BY doesn't like giving us that normally.
@@ -1686,8 +1738,9 @@  discard block
 block discarded – undo
1686 1738
 					'ip_list' => $ips,
1687 1739
 				)
1688 1740
 			);
1689
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1690
-				$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1741
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1742
+							$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1743
+			}
1691 1744
 			$smcFunc['db_free_result']($request);
1692 1745
 		}
1693 1746
 
@@ -1701,8 +1754,9 @@  discard block
 block discarded – undo
1701 1754
 				'ip_list' => $ips,
1702 1755
 			)
1703 1756
 		);
1704
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1705
-			$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1757
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1758
+					$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
1759
+		}
1706 1760
 		$smcFunc['db_free_result']($request);
1707 1761
 	}
1708 1762
 }
@@ -1762,8 +1816,8 @@  discard block
 block discarded – undo
1762 1816
 		))
1763 1817
 	);
1764 1818
 	$error_messages = array();
1765
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1766
-		$error_messages[] = array(
1819
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1820
+			$error_messages[] = array(
1767 1821
 			'ip' => inet_dtop($row['ip']),
1768 1822
 			'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
1769 1823
 			'message' => strtr($row['message'], array('&lt;span class=&quot;remove&quot;&gt;' => '', '&lt;/span&gt;' => '')),
@@ -1771,6 +1825,7 @@  discard block
 block discarded – undo
1771 1825
 			'time' => timeformat($row['log_time']),
1772 1826
 			'timestamp' => forum_time(true, $row['log_time']),
1773 1827
 		);
1828
+	}
1774 1829
 	$smcFunc['db_free_result']($request);
1775 1830
 
1776 1831
 	return $error_messages;
@@ -1833,8 +1888,8 @@  discard block
 block discarded – undo
1833 1888
 		))
1834 1889
 	);
1835 1890
 	$messages = array();
1836
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1837
-		$messages[] = array(
1891
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1892
+			$messages[] = array(
1838 1893
 			'ip' => inet_dtop($row['poster_ip']),
1839 1894
 			'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
1840 1895
 			'board' => array(
@@ -1847,6 +1902,7 @@  discard block
 block discarded – undo
1847 1902
 			'time' => timeformat($row['poster_time']),
1848 1903
 			'timestamp' => forum_time(true, $row['poster_time'])
1849 1904
 		);
1905
+	}
1850 1906
 	$smcFunc['db_free_result']($request);
1851 1907
 
1852 1908
 	return $messages;
@@ -1873,19 +1929,20 @@  discard block
 block discarded – undo
1873 1929
 		$context['sub_template'] = 'trackIP';
1874 1930
 		$context['page_title'] = $txt['profile'];
1875 1931
 		$context['base_url'] = $scripturl . '?action=trackip';
1876
-	}
1877
-	else
1932
+	} else
1878 1933
 	{
1879 1934
 		$context['ip'] = $user_profile[$memID]['member_ip'];
1880 1935
 		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
1881 1936
 	}
1882 1937
 
1883 1938
 	// Searching?
1884
-	if (isset($_REQUEST['searchip']))
1885
-		$context['ip'] = trim($_REQUEST['searchip']);
1939
+	if (isset($_REQUEST['searchip'])) {
1940
+			$context['ip'] = trim($_REQUEST['searchip']);
1941
+	}
1886 1942
 
1887
-	if (isValidIP($context['ip']) === false)
1888
-		fatal_lang_error('invalid_tracking_ip', false);
1943
+	if (isValidIP($context['ip']) === false) {
1944
+			fatal_lang_error('invalid_tracking_ip', false);
1945
+	}
1889 1946
 
1890 1947
 	//mysql didn't support like search with varbinary
1891 1948
 	//$ip_var = str_replace('*', '%', $context['ip']);
@@ -1893,8 +1950,9 @@  discard block
 block discarded – undo
1893 1950
 	$ip_var = $context['ip'];
1894 1951
 	$ip_string = '= {inet:ip_address}';
1895 1952
 
1896
-	if (empty($context['tracking_area']))
1897
-		$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1953
+	if (empty($context['tracking_area'])) {
1954
+			$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
1955
+	}
1898 1956
 
1899 1957
 	$request = $smcFunc['db_query']('', '
1900 1958
 		SELECT id_member, real_name AS display_name, member_ip
@@ -1905,8 +1963,9 @@  discard block
 block discarded – undo
1905 1963
 		)
1906 1964
 	);
1907 1965
 	$context['ips'] = array();
1908
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1909
-		$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1966
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1967
+			$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
1968
+	}
1910 1969
 	$smcFunc['db_free_result']($request);
1911 1970
 
1912 1971
 	ksort($context['ips']);
@@ -2135,8 +2194,9 @@  discard block
 block discarded – undo
2135 2194
 		foreach ($context['whois_servers'] as $whois)
2136 2195
 		{
2137 2196
 			// Strip off the "decimal point" and anything following...
2138
-			if (in_array((int) $context['ip'], $whois['range']))
2139
-				$context['auto_whois_server'] = $whois;
2197
+			if (in_array((int) $context['ip'], $whois['range'])) {
2198
+							$context['auto_whois_server'] = $whois;
2199
+			}
2140 2200
 		}
2141 2201
 	}
2142 2202
 }
@@ -2153,10 +2213,11 @@  discard block
 block discarded – undo
2153 2213
 	// Gonna want this for the list.
2154 2214
 	require_once($sourcedir . '/Subs-List.php');
2155 2215
 
2156
-	if ($memID == 0)
2157
-		$context['base_url'] = $scripturl . '?action=trackip';
2158
-	else
2159
-		$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2216
+	if ($memID == 0) {
2217
+			$context['base_url'] = $scripturl . '?action=trackip';
2218
+	} else {
2219
+			$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
2220
+	}
2160 2221
 
2161 2222
 	// Start with the user messages.
2162 2223
 	$listOptions = array(
@@ -2266,12 +2327,13 @@  discard block
 block discarded – undo
2266 2327
 		)
2267 2328
 	);
2268 2329
 	$logins = array();
2269
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2270
-		$logins[] = array(
2330
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2331
+			$logins[] = array(
2271 2332
 			'time' => timeformat($row['time']),
2272 2333
 			'ip' => inet_dtop($row['ip']),
2273 2334
 			'ip2' => inet_dtop($row['ip2']),
2274 2335
 		);
2336
+	}
2275 2337
 	$smcFunc['db_free_result']($request);
2276 2338
 
2277 2339
 	return $logins;
@@ -2296,11 +2358,12 @@  discard block
 block discarded – undo
2296 2358
 		)
2297 2359
 	);
2298 2360
 	$context['custom_field_titles'] = array();
2299
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2300
-		$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2361
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2362
+			$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
2301 2363
 			'title' => $row['field_name'],
2302 2364
 			'parse_bbc' => $row['bbc'],
2303 2365
 		);
2366
+	}
2304 2367
 	$smcFunc['db_free_result']($request);
2305 2368
 
2306 2369
 	// Set the options for the error lists.
@@ -2439,19 +2502,22 @@  discard block
 block discarded – undo
2439 2502
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2440 2503
 	{
2441 2504
 		$extra = smf_json_decode($row['extra'], true);
2442
-		if (!empty($extra['applicator']))
2443
-			$members[] = $extra['applicator'];
2505
+		if (!empty($extra['applicator'])) {
2506
+					$members[] = $extra['applicator'];
2507
+		}
2444 2508
 
2445 2509
 		// Work out what the name of the action is.
2446
-		if (isset($txt['trackEdit_action_' . $row['action']]))
2447
-			$action_text = $txt['trackEdit_action_' . $row['action']];
2448
-		elseif (isset($txt[$row['action']]))
2449
-			$action_text = $txt[$row['action']];
2510
+		if (isset($txt['trackEdit_action_' . $row['action']])) {
2511
+					$action_text = $txt['trackEdit_action_' . $row['action']];
2512
+		} elseif (isset($txt[$row['action']])) {
2513
+					$action_text = $txt[$row['action']];
2514
+		}
2450 2515
 		// Custom field?
2451
-		elseif (isset($context['custom_field_titles'][$row['action']]))
2452
-			$action_text = $context['custom_field_titles'][$row['action']]['title'];
2453
-		else
2454
-			$action_text = $row['action'];
2516
+		elseif (isset($context['custom_field_titles'][$row['action']])) {
2517
+					$action_text = $context['custom_field_titles'][$row['action']]['title'];
2518
+		} else {
2519
+					$action_text = $row['action'];
2520
+		}
2455 2521
 
2456 2522
 		// Parse BBC?
2457 2523
 		$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
@@ -2483,13 +2549,15 @@  discard block
 block discarded – undo
2483 2549
 			)
2484 2550
 		);
2485 2551
 		$members = array();
2486
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2487
-			$members[$row['id_member']] = $row['real_name'];
2552
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2553
+					$members[$row['id_member']] = $row['real_name'];
2554
+		}
2488 2555
 		$smcFunc['db_free_result']($request);
2489 2556
 
2490
-		foreach ($edits as $key => $value)
2491
-			if (isset($members[$value['id_member']]))
2557
+		foreach ($edits as $key => $value) {
2558
+					if (isset($members[$value['id_member']]))
2492 2559
 				$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
2560
+		}
2493 2561
 	}
2494 2562
 
2495 2563
 	return $edits;
@@ -2690,10 +2758,11 @@  discard block
 block discarded – undo
2690 2758
 	$context['board'] = $board;
2691 2759
 
2692 2760
 	// Determine which groups this user is in.
2693
-	if (empty($user_profile[$memID]['additional_groups']))
2694
-		$curGroups = array();
2695
-	else
2696
-		$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2761
+	if (empty($user_profile[$memID]['additional_groups'])) {
2762
+			$curGroups = array();
2763
+	} else {
2764
+			$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
2765
+	}
2697 2766
 	$curGroups[] = $user_profile[$memID]['id_group'];
2698 2767
 	$curGroups[] = $user_profile[$memID]['id_post_group'];
2699 2768
 
@@ -2713,28 +2782,30 @@  discard block
 block discarded – undo
2713 2782
 	$context['no_access_boards'] = array();
2714 2783
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2715 2784
 	{
2716
-		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
2717
-			$context['no_access_boards'][] = array(
2785
+		if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod']) {
2786
+					$context['no_access_boards'][] = array(
2718 2787
 				'id' => $row['id_board'],
2719 2788
 				'name' => $row['name'],
2720 2789
 				'is_last' => false,
2721 2790
 			);
2722
-		elseif ($row['id_profile'] != 1 || $row['is_mod'])
2723
-			$context['boards'][$row['id_board']] = array(
2791
+		} elseif ($row['id_profile'] != 1 || $row['is_mod']) {
2792
+					$context['boards'][$row['id_board']] = array(
2724 2793
 				'id' => $row['id_board'],
2725 2794
 				'name' => $row['name'],
2726 2795
 				'selected' => $board == $row['id_board'],
2727 2796
 				'profile' => $row['id_profile'],
2728 2797
 				'profile_name' => $context['profiles'][$row['id_profile']]['name'],
2729 2798
 			);
2799
+		}
2730 2800
 	}
2731 2801
 	$smcFunc['db_free_result']($request);
2732 2802
 
2733 2803
 	require_once($sourcedir . '/Subs-Boards.php');
2734 2804
 	sortBoards($context['boards']);
2735 2805
 
2736
-	if (!empty($context['no_access_boards']))
2737
-		$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2806
+	if (!empty($context['no_access_boards'])) {
2807
+			$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
2808
+	}
2738 2809
 
2739 2810
 	$context['member']['permissions'] = array(
2740 2811
 		'general' => array(),
@@ -2743,8 +2814,9 @@  discard block
 block discarded – undo
2743 2814
 
2744 2815
 	// If you're an admin we know you can do everything, we might as well leave.
2745 2816
 	$context['member']['has_all_permissions'] = in_array(1, $curGroups);
2746
-	if ($context['member']['has_all_permissions'])
2747
-		return;
2817
+	if ($context['member']['has_all_permissions']) {
2818
+			return;
2819
+	}
2748 2820
 
2749 2821
 	$denied = array();
2750 2822
 
@@ -2763,21 +2835,24 @@  discard block
 block discarded – undo
2763 2835
 	while ($row = $smcFunc['db_fetch_assoc']($result))
2764 2836
 	{
2765 2837
 		// We don't know about this permission, it doesn't exist :P.
2766
-		if (!isset($txt['permissionname_' . $row['permission']]))
2767
-			continue;
2838
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2839
+					continue;
2840
+		}
2768 2841
 
2769
-		if (empty($row['add_deny']))
2770
-			$denied[] = $row['permission'];
2842
+		if (empty($row['add_deny'])) {
2843
+					$denied[] = $row['permission'];
2844
+		}
2771 2845
 
2772 2846
 		// Permissions that end with _own or _any consist of two parts.
2773
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2774
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2775
-		else
2776
-			$name = $txt['permissionname_' . $row['permission']];
2847
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2848
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2849
+		} else {
2850
+					$name = $txt['permissionname_' . $row['permission']];
2851
+		}
2777 2852
 
2778 2853
 		// Add this permission if it doesn't exist yet.
2779
-		if (!isset($context['member']['permissions']['general'][$row['permission']]))
2780
-			$context['member']['permissions']['general'][$row['permission']] = array(
2854
+		if (!isset($context['member']['permissions']['general'][$row['permission']])) {
2855
+					$context['member']['permissions']['general'][$row['permission']] = array(
2781 2856
 				'id' => $row['permission'],
2782 2857
 				'groups' => array(
2783 2858
 					'allowed' => array(),
@@ -2787,6 +2862,7 @@  discard block
 block discarded – undo
2787 2862
 				'is_denied' => false,
2788 2863
 				'is_global' => true,
2789 2864
 			);
2865
+		}
2790 2866
 
2791 2867
 		// Add the membergroup to either the denied or the allowed groups.
2792 2868
 		$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
@@ -2820,18 +2896,20 @@  discard block
 block discarded – undo
2820 2896
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2821 2897
 	{
2822 2898
 		// We don't know about this permission, it doesn't exist :P.
2823
-		if (!isset($txt['permissionname_' . $row['permission']]))
2824
-			continue;
2899
+		if (!isset($txt['permissionname_' . $row['permission']])) {
2900
+					continue;
2901
+		}
2825 2902
 
2826 2903
 		// The name of the permission using the format 'permission name' - 'own/any topic/event/etc.'.
2827
-		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
2828
-			$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2829
-		else
2830
-			$name = $txt['permissionname_' . $row['permission']];
2904
+		if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)])) {
2905
+					$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
2906
+		} else {
2907
+					$name = $txt['permissionname_' . $row['permission']];
2908
+		}
2831 2909
 
2832 2910
 		// Create the structure for this permission.
2833
-		if (!isset($context['member']['permissions']['board'][$row['permission']]))
2834
-			$context['member']['permissions']['board'][$row['permission']] = array(
2911
+		if (!isset($context['member']['permissions']['board'][$row['permission']])) {
2912
+					$context['member']['permissions']['board'][$row['permission']] = array(
2835 2913
 				'id' => $row['permission'],
2836 2914
 				'groups' => array(
2837 2915
 					'allowed' => array(),
@@ -2841,6 +2919,7 @@  discard block
 block discarded – undo
2841 2919
 				'is_denied' => false,
2842 2920
 				'is_global' => empty($board),
2843 2921
 			);
2922
+		}
2844 2923
 
2845 2924
 		$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
2846 2925
 
@@ -2859,8 +2938,9 @@  discard block
 block discarded – undo
2859 2938
 	global $modSettings, $context, $sourcedir, $txt, $scripturl;
2860 2939
 
2861 2940
 	// Firstly, can we actually even be here?
2862
-	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
2863
-		fatal_lang_error('no_access', false);
2941
+	if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum')) {
2942
+			fatal_lang_error('no_access', false);
2943
+	}
2864 2944
 
2865 2945
 	// Make sure things which are disabled stay disabled.
2866 2946
 	$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
@@ -2947,9 +3027,10 @@  discard block
 block discarded – undo
2947 3027
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
2948 3028
 	);
2949 3029
 	$context['current_level'] = 0;
2950
-	foreach ($context['level_effects'] as $limit => $dummy)
2951
-		if ($context['member']['warning'] >= $limit)
3030
+	foreach ($context['level_effects'] as $limit => $dummy) {
3031
+			if ($context['member']['warning'] >= $limit)
2952 3032
 			$context['current_level'] = $limit;
2953
-}
3033
+	}
3034
+	}
2954 3035
 
2955 3036
 ?>
2956 3037
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Xml.php 1 patch
Braces   +55 added lines, -42 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main handler and designator for AJAX stuff - jumpto, message icons and previews
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 	// Easy adding of sub actions.
33 34
 	call_integration_hook('integrate_XMLhttpMain_subActions', array(&$subActions));
34 35
 
35
-	if (!isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']]))
36
-		fatal_lang_error('no_access', false);
36
+	if (!isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']])) {
37
+			fatal_lang_error('no_access', false);
38
+	}
37 39
 
38 40
 	call_helper($subActions[$_REQUEST['sa']]);
39 41
 }
@@ -57,8 +59,9 @@  discard block
 block discarded – undo
57 59
 	foreach ($context['jump_to'] as $id_cat => $cat)
58 60
 	{
59 61
 		$context['jump_to'][$id_cat]['name'] = un_htmlspecialchars(strip_tags($cat['name']));
60
-		foreach ($cat['boards'] as $id_board => $board)
61
-			$context['jump_to'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name']));
62
+		foreach ($cat['boards'] as $id_board => $board) {
63
+					$context['jump_to'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name']));
64
+		}
62 65
 	}
63 66
 
64 67
 	$context['sub_template'] = 'jump_to';
@@ -95,8 +98,9 @@  discard block
 block discarded – undo
95 98
 
96 99
 	$context['sub_template'] = 'generic_xml';
97 100
 
98
-	if (!isset($_POST['item']) || !in_array($_POST['item'], $items))
99
-		return false;
101
+	if (!isset($_POST['item']) || !in_array($_POST['item'], $items)) {
102
+			return false;
103
+	}
100 104
 
101 105
 	$_POST['item']();
102 106
 }
@@ -112,10 +116,11 @@  discard block
 block discarded – undo
112 116
 
113 117
 	$errors = array();
114 118
 	$news = !isset($_POST['news'])? '' : $smcFunc['htmlspecialchars']($_POST['news'], ENT_QUOTES);
115
-	if (empty($news))
116
-		$errors[] = array('value' => 'no_news');
117
-	else
118
-		preparsecode($news);
119
+	if (empty($news)) {
120
+			$errors[] = array('value' => 'no_news');
121
+	} else {
122
+			preparsecode($news);
123
+	}
119 124
 
120 125
 	$context['xml_data'] = array(
121 126
 		'news' => array(
@@ -148,10 +153,12 @@  discard block
 block discarded – undo
148 153
 	$context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0;
149 154
 	$context['send_html'] = !empty($_POST['send_html']) ? 1 : 0;
150 155
 
151
-	if (empty($_POST['subject']))
152
-		$context['post_error']['messages'][] = $txt['error_no_subject'];
153
-	if (empty($_POST['message']))
154
-		$context['post_error']['messages'][] = $txt['error_no_message'];
156
+	if (empty($_POST['subject'])) {
157
+			$context['post_error']['messages'][] = $txt['error_no_subject'];
158
+	}
159
+	if (empty($_POST['message'])) {
160
+			$context['post_error']['messages'][] = $txt['error_no_message'];
161
+	}
155 162
 
156 163
 	prepareMailingForPreview();
157 164
 
@@ -196,38 +203,41 @@  discard block
 block discarded – undo
196 203
 		$preview_signature = !empty($_POST['signature']) ? $_POST['signature'] : $txt['no_signature_preview'];
197 204
 		$validation = profileValidateSignature($preview_signature);
198 205
 
199
-		if ($validation !== true && $validation !== false)
200
-			$errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error'));
206
+		if ($validation !== true && $validation !== false) {
207
+					$errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error'));
208
+		}
201 209
 
202 210
 		censorText($preview_signature);
203 211
 		$preview_signature = parse_bbc($preview_signature, true, 'sig' . $user);
204
-	}
205
-	elseif (!$can_change)
212
+	} elseif (!$can_change)
206 213
 	{
207
-		if ($is_owner)
208
-			$errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error'));
209
-		else
210
-			$errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error'));
214
+		if ($is_owner) {
215
+					$errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error'));
216
+		} else {
217
+					$errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error'));
218
+		}
219
+	} else {
220
+			$errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error'));
211 221
 	}
212
-	else
213
-		$errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error'));
214 222
 
215 223
 	$context['xml_data']['signatures'] = array(
216 224
 			'identifier' => 'signature',
217 225
 			'children' => array()
218 226
 		);
219
-	if (isset($current_signature))
220
-		$context['xml_data']['signatures']['children'][] = array(
227
+	if (isset($current_signature)) {
228
+			$context['xml_data']['signatures']['children'][] = array(
221 229
 					'value' => $current_signature,
222 230
 					'attributes' => array('type' => 'current'),
223 231
 				);
224
-	if (isset($preview_signature))
225
-		$context['xml_data']['signatures']['children'][] = array(
232
+	}
233
+	if (isset($preview_signature)) {
234
+			$context['xml_data']['signatures']['children'][] = array(
226 235
 					'value' => $preview_signature,
227 236
 					'attributes' => array('type' => 'preview'),
228 237
 				);
229
-	if (!empty($errors))
230
-		$context['xml_data']['errors'] = array(
238
+	}
239
+	if (!empty($errors)) {
240
+			$context['xml_data']['errors'] = array(
231 241
 			'identifier' => 'error',
232 242
 			'children' => array_merge(
233 243
 				array(
@@ -239,7 +249,8 @@  discard block
 block discarded – undo
239 249
 				$errors
240 250
 			),
241 251
 		);
242
-}
252
+	}
253
+	}
243 254
 
244 255
 /**
245 256
  * Handles previewing user warnings
@@ -261,15 +272,17 @@  discard block
 block discarded – undo
261 272
 		$context['preview_subject'] = !empty($_POST['title']) ? trim($smcFunc['htmlspecialchars']($_POST['title'])) : '';
262 273
 		if (isset($_POST['issuing']))
263 274
 		{
264
-			if (empty($_POST['title']) || empty($_POST['body']))
265
-				$context['post_error']['messages'][] = $txt['warning_notify_blank'];
266
-		}
267
-		else
275
+			if (empty($_POST['title']) || empty($_POST['body'])) {
276
+							$context['post_error']['messages'][] = $txt['warning_notify_blank'];
277
+			}
278
+		} else
268 279
 		{
269
-			if (empty($_POST['title']))
270
-				$context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title'];
271
-			if (empty($_POST['body']))
272
-				$context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body'];
280
+			if (empty($_POST['title'])) {
281
+							$context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title'];
282
+			}
283
+			if (empty($_POST['body'])) {
284
+							$context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body'];
285
+			}
273 286
 			// Add in few replacements.
274 287
 			/**
275 288
 			* These are the defaults:
@@ -300,9 +313,9 @@  discard block
 block discarded – undo
300 313
 			$warning_body = parse_bbc($warning_body, true);
301 314
 		}
302 315
 		$context['preview_message'] = $warning_body;
316
+	} else {
317
+			$context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error'));
303 318
 	}
304
-	else
305
-		$context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error'));
306 319
 
307 320
 	$context['sub_template'] = 'warning';
308 321
 }
Please login to merge, or discard this patch.
Sources/Logging.php 1 patch
Braces   +134 added lines, -96 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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
  * Put this user in the online log.
@@ -33,8 +34,9 @@  discard block
 block discarded – undo
33 34
 		// Don't update for every page - this isn't wholly accurate but who cares.
34 35
 		if ($topic)
35 36
 		{
36
-			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic)
37
-				$force = false;
37
+			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) {
38
+							$force = false;
39
+			}
38 40
 			$_SESSION['last_topic_id'] = $topic;
39 41
 		}
40 42
 	}
@@ -47,22 +49,24 @@  discard block
 block discarded – undo
47 49
 	}
48 50
 
49 51
 	// Don't mark them as online more than every so often.
50
-	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force)
51
-		return;
52
+	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) {
53
+			return;
54
+	}
52 55
 
53 56
 	if (!empty($modSettings['who_enabled']))
54 57
 	{
55 58
 		$serialized = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
56 59
 
57 60
 		// In the case of a dlattach action, session_var may not be set.
58
-		if (!isset($context['session_var']))
59
-			$context['session_var'] = $_SESSION['session_var'];
61
+		if (!isset($context['session_var'])) {
62
+					$context['session_var'] = $_SESSION['session_var'];
63
+		}
60 64
 
61 65
 		unset($serialized['sesc'], $serialized[$context['session_var']]);
62 66
 		$serialized = json_encode($serialized);
67
+	} else {
68
+			$serialized = '';
63 69
 	}
64
-	else
65
-		$serialized = '';
66 70
 
67 71
 	// Guests use 0, members use their session ID.
68 72
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
@@ -102,17 +106,18 @@  discard block
 block discarded – undo
102 106
 		);
103 107
 
104 108
 		// Guess it got deleted.
105
-		if ($smcFunc['db_affected_rows']() == 0)
109
+		if ($smcFunc['db_affected_rows']() == 0) {
110
+					$_SESSION['log_time'] = 0;
111
+		}
112
+	} else {
106 113
 			$_SESSION['log_time'] = 0;
107 114
 	}
108
-	else
109
-		$_SESSION['log_time'] = 0;
110 115
 
111 116
 	// Otherwise, we have to delete and insert.
112 117
 	if (empty($_SESSION['log_time']))
113 118
 	{
114
-		if ($do_delete || !empty($user_info['id']))
115
-			$smcFunc['db_query']('', '
119
+		if ($do_delete || !empty($user_info['id'])) {
120
+					$smcFunc['db_query']('', '
116 121
 				DELETE FROM {db_prefix}log_online
117 122
 				WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'),
118 123
 				array(
@@ -120,6 +125,7 @@  discard block
 block discarded – undo
120 125
 					'log_time' => time() - $modSettings['lastActive'] * 60,
121 126
 				)
122 127
 			);
128
+		}
123 129
 
124 130
 		$smcFunc['db_insert']($do_delete ? 'ignore' : 'replace',
125 131
 			'{db_prefix}log_online',
@@ -133,21 +139,24 @@  discard block
 block discarded – undo
133 139
 	$_SESSION['log_time'] = time();
134 140
 
135 141
 	// Well, they are online now.
136
-	if (empty($_SESSION['timeOnlineUpdated']))
137
-		$_SESSION['timeOnlineUpdated'] = time();
142
+	if (empty($_SESSION['timeOnlineUpdated'])) {
143
+			$_SESSION['timeOnlineUpdated'] = time();
144
+	}
138 145
 
139 146
 	// Set their login time, if not already done within the last minute.
140 147
 	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'))))
141 148
 	{
142 149
 		// Don't count longer than 15 minutes.
143
-		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
144
-			$_SESSION['timeOnlineUpdated'] = time();
150
+		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) {
151
+					$_SESSION['timeOnlineUpdated'] = time();
152
+		}
145 153
 
146 154
 		$user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
147 155
 		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']));
148 156
 
149
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
150
-			cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
157
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
158
+					cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
159
+		}
151 160
 
152 161
 		$user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
153 162
 		$_SESSION['timeOnlineUpdated'] = time();
@@ -184,8 +193,7 @@  discard block
 block discarded – undo
184 193
 			// Oops. maybe we have no more disk space left, or some other troubles, troubles...
185 194
 			// Copy the file back and run for your life!
186 195
 			@copy($boarddir . '/db_last_error_bak.php', $boarddir . '/db_last_error.php');
187
-		}
188
-		else
196
+		} else
189 197
 		{
190 198
 			@touch($boarddir . '/' . 'Settings.php');
191 199
 			return true;
@@ -205,22 +213,27 @@  discard block
 block discarded – undo
205 213
 	global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt;
206 214
 
207 215
 	// Add to Settings.php if you want to show the debugging information.
208
-	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery'))
209
-		return;
216
+	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) {
217
+			return;
218
+	}
210 219
 
211
-	if (empty($_SESSION['view_queries']))
212
-		$_SESSION['view_queries'] = 0;
213
-	if (empty($context['debug']['language_files']))
214
-		$context['debug']['language_files'] = array();
215
-	if (empty($context['debug']['sheets']))
216
-		$context['debug']['sheets'] = array();
220
+	if (empty($_SESSION['view_queries'])) {
221
+			$_SESSION['view_queries'] = 0;
222
+	}
223
+	if (empty($context['debug']['language_files'])) {
224
+			$context['debug']['language_files'] = array();
225
+	}
226
+	if (empty($context['debug']['sheets'])) {
227
+			$context['debug']['sheets'] = array();
228
+	}
217 229
 
218 230
 	$files = get_included_files();
219 231
 	$total_size = 0;
220 232
 	for ($i = 0, $n = count($files); $i < $n; $i++)
221 233
 	{
222
-		if (file_exists($files[$i]))
223
-			$total_size += filesize($files[$i]);
234
+		if (file_exists($files[$i])) {
235
+					$total_size += filesize($files[$i]);
236
+		}
224 237
 		$files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)'));
225 238
 	}
226 239
 
@@ -229,8 +242,9 @@  discard block
 block discarded – undo
229 242
 	{
230 243
 		foreach ($db_cache as $q => $qq)
231 244
 		{
232
-			if (!empty($qq['w']))
233
-				$warnings += count($qq['w']);
245
+			if (!empty($qq['w'])) {
246
+							$warnings += count($qq['w']);
247
+			}
234 248
 		}
235 249
 
236 250
 		$_SESSION['debug'] = &$db_cache;
@@ -251,12 +265,14 @@  discard block
 block discarded – undo
251 265
 	',(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>') : ''),'
252 266
 	', $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>';
253 267
 
254
-	if (function_exists('memory_get_peak_usage'))
255
-		echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
268
+	if (function_exists('memory_get_peak_usage')) {
269
+			echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
270
+	}
256 271
 
257 272
 	// What tokens are active?
258
-	if (isset($_SESSION['token']))
259
-		echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
273
+	if (isset($_SESSION['token'])) {
274
+			echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
275
+	}
260 276
 
261 277
 	if (!empty($modSettings['cache_enable']) && !empty($cache_hits))
262 278
 	{
@@ -269,10 +285,12 @@  discard block
 block discarded – undo
269 285
 			$total_t += $cache_hit['t'];
270 286
 			$total_s += $cache_hit['s'];
271 287
 		}
272
-		if (!isset($cache_misses))
273
-			$cache_misses = array();
274
-		foreach ($cache_misses as $missed)
275
-			$missed_entires[] = $missed['d'] . ' ' . $missed['k'];
288
+		if (!isset($cache_misses)) {
289
+					$cache_misses = array();
290
+		}
291
+		foreach ($cache_misses as $missed) {
292
+					$missed_entires[] = $missed['d'] . ' ' . $missed['k'];
293
+		}
276 294
 
277 295
 		echo '
278 296
 	', $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>
@@ -283,38 +301,44 @@  discard block
 block discarded – undo
283 301
 	<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>
284 302
 	<br>';
285 303
 
286
-	if ($_SESSION['view_queries'] == 1 && !empty($db_cache))
287
-		foreach ($db_cache as $q => $qq)
304
+	if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) {
305
+			foreach ($db_cache as $q => $qq)
288 306
 		{
289 307
 			$is_select = strpos(trim($qq['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0;
308
+	}
290 309
 			// Temporary tables created in earlier queries are not explainable.
291 310
 			if ($is_select)
292 311
 			{
293
-				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp)
294
-					if (strpos(trim($qq['q']), $tmp) !== false)
312
+				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
313
+									if (strpos(trim($qq['q']), $tmp) !== false)
295 314
 					{
296 315
 						$is_select = false;
316
+				}
297 317
 						break;
298 318
 					}
299 319
 			}
300 320
 			// But actual creation of the temporary tables are.
301
-			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0)
302
-				$is_select = true;
321
+			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) {
322
+							$is_select = true;
323
+			}
303 324
 
304 325
 			// Make the filenames look a bit better.
305
-			if (isset($qq['f']))
306
-				$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
326
+			if (isset($qq['f'])) {
327
+							$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
328
+			}
307 329
 
308 330
 			echo '
309 331
 	<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>
310 332
 	&nbsp;&nbsp;&nbsp;';
311
-			if (!empty($qq['f']) && !empty($qq['l']))
312
-				echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
333
+			if (!empty($qq['f']) && !empty($qq['l'])) {
334
+							echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
335
+			}
313 336
 
314
-			if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at']))
315
-				echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>';
316
-			elseif (isset($qq['t']))
317
-				echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>';
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>';
341
+			}
318 342
 			echo '
319 343
 	<br>';
320 344
 		}
@@ -339,12 +363,14 @@  discard block
 block discarded – undo
339 363
 	global $modSettings, $smcFunc;
340 364
 	static $cache_stats = array();
341 365
 
342
-	if (empty($modSettings['trackStats']))
343
-		return false;
344
-	if (!empty($stats))
345
-		return $cache_stats = array_merge($cache_stats, $stats);
346
-	elseif (empty($cache_stats))
347
-		return false;
366
+	if (empty($modSettings['trackStats'])) {
367
+			return false;
368
+	}
369
+	if (!empty($stats)) {
370
+			return $cache_stats = array_merge($cache_stats, $stats);
371
+	} elseif (empty($cache_stats)) {
372
+			return false;
373
+	}
348 374
 
349 375
 	$setStringUpdate = '';
350 376
 	$insert_keys = array();
@@ -357,10 +383,11 @@  discard block
 block discarded – undo
357 383
 		$setStringUpdate .= '
358 384
 			' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ',';
359 385
 
360
-		if ($change === '+')
361
-			$cache_stats[$field] = 1;
362
-		else
363
-			$update_parameters[$field] = $change;
386
+		if ($change === '+') {
387
+					$cache_stats[$field] = 1;
388
+		} else {
389
+					$update_parameters[$field] = $change;
390
+		}
364 391
 		$insert_keys[$field] = 'int';
365 392
 	}
366 393
 
@@ -424,43 +451,50 @@  discard block
 block discarded – undo
424 451
 	);
425 452
 
426 453
 	// Make sure this particular log is enabled first...
427
-	if (empty($modSettings['modlog_enabled']))
428
-		unset ($log_types['moderate']);
429
-	if (empty($modSettings['userlog_enabled']))
430
-		unset ($log_types['user']);
431
-	if (empty($modSettings['adminlog_enabled']))
432
-		unset ($log_types['admin']);
454
+	if (empty($modSettings['modlog_enabled'])) {
455
+			unset ($log_types['moderate']);
456
+	}
457
+	if (empty($modSettings['userlog_enabled'])) {
458
+			unset ($log_types['user']);
459
+	}
460
+	if (empty($modSettings['adminlog_enabled'])) {
461
+			unset ($log_types['admin']);
462
+	}
433 463
 
434 464
 	call_integration_hook('integrate_log_types', array(&$log_types));
435 465
 
436 466
 	foreach ($logs as $log)
437 467
 	{
438
-		if (!isset($log_types[$log['log_type']]))
439
-			return false;
468
+		if (!isset($log_types[$log['log_type']])) {
469
+					return false;
470
+		}
440 471
 
441
-		if (!is_array($log['extra']))
442
-			trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
472
+		if (!is_array($log['extra'])) {
473
+					trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
474
+		}
443 475
 
444 476
 		// Pull out the parts we want to store separately, but also make sure that the data is proper
445 477
 		if (isset($log['extra']['topic']))
446 478
 		{
447
-			if (!is_numeric($log['extra']['topic']))
448
-				trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
479
+			if (!is_numeric($log['extra']['topic'])) {
480
+							trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
481
+			}
449 482
 			$topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic'];
450 483
 			unset($log['extra']['topic']);
484
+		} else {
485
+					$topic_id = 0;
451 486
 		}
452
-		else
453
-			$topic_id = 0;
454 487
 
455 488
 		if (isset($log['extra']['message']))
456 489
 		{
457
-			if (!is_numeric($log['extra']['message']))
458
-				trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
490
+			if (!is_numeric($log['extra']['message'])) {
491
+							trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
492
+			}
459 493
 			$msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message'];
460 494
 			unset($log['extra']['message']);
495
+		} else {
496
+					$msg_id = 0;
461 497
 		}
462
-		else
463
-			$msg_id = 0;
464 498
 
465 499
 		// @todo cache this?
466 500
 		// Is there an associated report on this?
@@ -487,23 +521,26 @@  discard block
 block discarded – undo
487 521
 			$smcFunc['db_free_result']($request);
488 522
 		}
489 523
 
490
-		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member']))
491
-			trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
524
+		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) {
525
+					trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
526
+		}
492 527
 
493 528
 		if (isset($log['extra']['board']))
494 529
 		{
495
-			if (!is_numeric($log['extra']['board']))
496
-				trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
530
+			if (!is_numeric($log['extra']['board'])) {
531
+							trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
532
+			}
497 533
 			$board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board'];
498 534
 			unset($log['extra']['board']);
535
+		} else {
536
+					$board_id = 0;
499 537
 		}
500
-		else
501
-			$board_id = 0;
502 538
 
503 539
 		if (isset($log['extra']['board_to']))
504 540
 		{
505
-			if (!is_numeric($log['extra']['board_to']))
506
-				trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
541
+			if (!is_numeric($log['extra']['board_to'])) {
542
+							trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
543
+			}
507 544
 			if (empty($board_id))
508 545
 			{
509 546
 				$board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to'];
@@ -511,10 +548,11 @@  discard block
 block discarded – undo
511 548
 			}
512 549
 		}
513 550
 
514
-		if (isset($log['extra']['member_affected']))
515
-			$memID = $log['extra']['member_affected'];
516
-		else
517
-			$memID = $user_info['id'];
551
+		if (isset($log['extra']['member_affected'])) {
552
+					$memID = $log['extra']['member_affected'];
553
+		} else {
554
+					$memID = $user_info['id'];
555
+		}
518 556
 
519 557
 		$inserts[] = array(
520 558
 			time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'],
Please login to merge, or discard this patch.
Sources/Subs-Db-postgresql.php 1 patch
Braces   +206 added lines, -152 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 3
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)
@@ -34,8 +35,8 @@  discard block
 block discarded – undo
34 35
 	global $smcFunc;
35 36
 
36 37
 	// Map some database specific functions, only do this once.
37
-	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc')
38
-		$smcFunc += array(
38
+	if (!isset($smcFunc['db_fetch_assoc']) || $smcFunc['db_fetch_assoc'] != 'postg_fetch_assoc') {
39
+			$smcFunc += array(
39 40
 			'db_query' => 'smf_db_query',
40 41
 			'db_quote' => 'smf_db_quote',
41 42
 			'db_insert' => 'smf_db_insert',
@@ -59,11 +60,13 @@  discard block
 block discarded – undo
59 60
 			'db_escape_wildcard_string' => 'smf_db_escape_wildcard_string',
60 61
 			'db_is_resource' => 'is_resource',
61 62
 		);
63
+	}
62 64
 
63
-	if (!empty($db_options['persist']))
64
-		$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
65
-	else
66
-		$connection = @pg_connect( 'host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
65
+	if (!empty($db_options['persist'])) {
66
+			$connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
67
+	} else {
68
+			$connection = @pg_connect( 'host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\''));
69
+	}
67 70
 
68 71
 	// Something's wrong, show an error if its fatal (which we assume it is)
69 72
 	if (!$connection)
@@ -71,8 +74,7 @@  discard block
 block discarded – undo
71 74
 		if (!empty($db_options['non_fatal']))
72 75
 		{
73 76
 			return null;
74
-		}
75
-		else
77
+		} else
76 78
 		{
77 79
 			display_db_error();
78 80
 		}
@@ -123,34 +125,42 @@  discard block
 block discarded – undo
123 125
 
124 126
 	list ($values, $connection) = $db_callback;
125 127
 
126
-	if ($matches[1] === 'db_prefix')
127
-		return $db_prefix;
128
+	if ($matches[1] === 'db_prefix') {
129
+			return $db_prefix;
130
+	}
128 131
 
129
-	if ($matches[1] === 'query_see_board')
130
-		return $user_info['query_see_board'];
132
+	if ($matches[1] === 'query_see_board') {
133
+			return $user_info['query_see_board'];
134
+	}
131 135
 
132
-	if ($matches[1] === 'query_wanna_see_board')
133
-		return $user_info['query_wanna_see_board'];
136
+	if ($matches[1] === 'query_wanna_see_board') {
137
+			return $user_info['query_wanna_see_board'];
138
+	}
134 139
 
135
-	if ($matches[1] === 'empty')
136
-		return '\'\'';
140
+	if ($matches[1] === 'empty') {
141
+			return '\'\'';
142
+	}
137 143
 
138
-	if (!isset($matches[2]))
139
-		smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
144
+	if (!isset($matches[2])) {
145
+			smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__);
146
+	}
140 147
 
141
-	if ($matches[1] === 'literal')
142
-		return '\'' . pg_escape_string($matches[2]) . '\'';
148
+	if ($matches[1] === 'literal') {
149
+			return '\'' . pg_escape_string($matches[2]) . '\'';
150
+	}
143 151
 
144
-	if (!isset($values[$matches[2]]))
145
-		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__);
152
+	if (!isset($values[$matches[2]])) {
153
+			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__);
154
+	}
146 155
 
147 156
 	$replacement = $values[$matches[2]];
148 157
 
149 158
 	switch ($matches[1])
150 159
 	{
151 160
 		case 'int':
152
-			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement)
153
-				smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
161
+			if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) {
162
+							smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
163
+			}
154 164
 			return (string) (int) $replacement;
155 165
 		break;
156 166
 
@@ -162,49 +172,55 @@  discard block
 block discarded – undo
162 172
 		case 'array_int':
163 173
 			if (is_array($replacement))
164 174
 			{
165
-				if (empty($replacement))
166
-					smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
175
+				if (empty($replacement)) {
176
+									smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177
+				}
167 178
 
168 179
 				foreach ($replacement as $key => $value)
169 180
 				{
170
-					if (!is_numeric($value) || (string) $value !== (string) (int) $value)
171
-						smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
181
+					if (!is_numeric($value) || (string) $value !== (string) (int) $value) {
182
+											smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
183
+					}
172 184
 
173 185
 					$replacement[$key] = (string) (int) $value;
174 186
 				}
175 187
 
176 188
 				return implode(', ', $replacement);
189
+			} else {
190
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
177 191
 			}
178
-			else
179
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
180 192
 
181 193
 		break;
182 194
 
183 195
 		case 'array_string':
184 196
 			if (is_array($replacement))
185 197
 			{
186
-				if (empty($replacement))
187
-					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
198
+				if (empty($replacement)) {
199
+									smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
200
+				}
188 201
 
189
-				foreach ($replacement as $key => $value)
190
-					$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
202
+				foreach ($replacement as $key => $value) {
203
+									$replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value));
204
+				}
191 205
 
192 206
 				return implode(', ', $replacement);
207
+			} else {
208
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
193 209
 			}
194
-			else
195
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
196 210
 		break;
197 211
 
198 212
 		case 'date':
199
-			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1)
200
-				return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
201
-			else
202
-				smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
213
+			if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) {
214
+							return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]);
215
+			} else {
216
+							smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
217
+			}
203 218
 		break;
204 219
 
205 220
 		case 'float':
206
-			if (!is_numeric($replacement))
207
-				smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
221
+			if (!is_numeric($replacement)) {
222
+							smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
223
+			}
208 224
 			return (string) (float) $replacement;
209 225
 		break;
210 226
 
@@ -217,31 +233,36 @@  discard block
 block discarded – undo
217 233
 		break;
218 234
 
219 235
 		case 'inet':
220
-			if ($replacement == 'null' || $replacement == '')
221
-				return 'null';
222
-			if (inet_pton($replacement) === false)
223
-				smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
236
+			if ($replacement == 'null' || $replacement == '') {
237
+							return 'null';
238
+			}
239
+			if (inet_pton($replacement) === false) {
240
+							smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
241
+			}
224 242
 			return sprintf('\'%1$s\'::inet', pg_escape_string($replacement));
225 243
 
226 244
 		case 'array_inet':
227 245
 			if (is_array($replacement))
228 246
 			{
229
-				if (empty($replacement))
230
-					smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
247
+				if (empty($replacement)) {
248
+									smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
249
+				}
231 250
 
232 251
 				foreach ($replacement as $key => $value)
233 252
 				{
234
-					if ($replacement == 'null' || $replacement == '')
235
-						$replacement[$key] = 'null';
236
-					if (!isValidIP($value))
237
-						smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
253
+					if ($replacement == 'null' || $replacement == '') {
254
+											$replacement[$key] = 'null';
255
+					}
256
+					if (!isValidIP($value)) {
257
+											smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
258
+					}
238 259
 					$replacement[$key] =  sprintf('\'%1$s\'::inet', pg_escape_string($value));
239 260
 				}
240 261
 
241 262
 				return implode(', ', $replacement);
263
+			} else {
264
+							smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
242 265
 			}
243
-			else
244
-				smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
245 266
 		break;
246 267
 
247 268
 		default:
@@ -328,14 +349,16 @@  discard block
 block discarded – undo
328 349
 		),
329 350
 	);
330 351
 
331
-	if (isset($replacements[$identifier]))
332
-		$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
352
+	if (isset($replacements[$identifier])) {
353
+			$db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string);
354
+	}
333 355
 
334 356
 	// Limits need to be a little different.
335 357
 	$db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string);
336 358
 
337
-	if (trim($db_string) == '')
338
-		return false;
359
+	if (trim($db_string) == '') {
360
+			return false;
361
+	}
339 362
 
340 363
 	// Comments that are allowed in a query are preg_removed.
341 364
 	static $allowed_comments_from = array(
@@ -355,8 +378,9 @@  discard block
 block discarded – undo
355 378
 	$db_count = !isset($db_count) ? 1 : $db_count + 1;
356 379
 	$db_replace_result = 0;
357 380
 
358
-	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override']))
359
-		smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
381
+	if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) {
382
+			smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__);
383
+	}
360 384
 
361 385
 	if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false))
362 386
 	{
@@ -377,8 +401,9 @@  discard block
 block discarded – undo
377 401
 		list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__);
378 402
 
379 403
 		// Initialize $db_cache if not already initialized.
380
-		if (!isset($db_cache))
381
-			$db_cache = array();
404
+		if (!isset($db_cache)) {
405
+					$db_cache = array();
406
+		}
382 407
 
383 408
 		if (!empty($_SESSION['debug_redirect']))
384 409
 		{
@@ -404,17 +429,18 @@  discard block
 block discarded – undo
404 429
 		while (true)
405 430
 		{
406 431
 			$pos = strpos($db_string, '\'', $pos + 1);
407
-			if ($pos === false)
408
-				break;
432
+			if ($pos === false) {
433
+							break;
434
+			}
409 435
 			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
410 436
 
411 437
 			while (true)
412 438
 			{
413 439
 				$pos1 = strpos($db_string, '\'', $pos + 1);
414 440
 				$pos2 = strpos($db_string, '\\', $pos + 1);
415
-				if ($pos1 === false)
416
-					break;
417
-				elseif ($pos2 === false || $pos2 > $pos1)
441
+				if ($pos1 === false) {
442
+									break;
443
+				} elseif ($pos2 === false || $pos2 > $pos1)
418 444
 				{
419 445
 					$pos = $pos1;
420 446
 					break;
@@ -430,26 +456,31 @@  discard block
 block discarded – undo
430 456
 		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
431 457
 
432 458
 		// Comments?  We don't use comments in our queries, we leave 'em outside!
433
-		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
434
-			$fail = true;
459
+		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) {
460
+					$fail = true;
461
+		}
435 462
 		// Trying to change passwords, slow us down, or something?
436
-		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
437
-			$fail = true;
438
-		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
439
-			$fail = true;
463
+		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) {
464
+					$fail = true;
465
+		} elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) {
466
+					$fail = true;
467
+		}
440 468
 
441
-		if (!empty($fail) && function_exists('log_error'))
442
-			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
469
+		if (!empty($fail) && function_exists('log_error')) {
470
+					smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
471
+		}
443 472
 	}
444 473
 
445 474
 	$db_last_result = @pg_query($connection, $db_string);
446 475
 
447
-	if ($db_last_result === false && empty($db_values['db_error_skip']))
448
-		$db_last_result = smf_db_error($db_string, $connection);
476
+	if ($db_last_result === false && empty($db_values['db_error_skip'])) {
477
+			$db_last_result = smf_db_error($db_string, $connection);
478
+	}
449 479
 
450 480
 	// Debugging.
451
-	if (isset($db_show_debug) && $db_show_debug === true)
452
-		$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
481
+	if (isset($db_show_debug) && $db_show_debug === true) {
482
+			$db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
483
+	}
453 484
 
454 485
 	return $db_last_result;
455 486
 }
@@ -462,10 +493,11 @@  discard block
 block discarded – undo
462 493
 {
463 494
 	global $db_last_result, $db_replace_result;
464 495
 
465
-	if ($db_replace_result)
466
-		return $db_replace_result;
467
-	elseif ($result === null && !$db_last_result)
468
-		return 0;
496
+	if ($db_replace_result) {
497
+			return $db_replace_result;
498
+	} elseif ($result === null && !$db_last_result) {
499
+			return 0;
500
+	}
469 501
 
470 502
 	return pg_affected_rows($result === null ? $db_last_result : $result);
471 503
 }
@@ -484,16 +516,18 @@  discard block
 block discarded – undo
484 516
 
485 517
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
486 518
 
487
-	if ($connection === false)
488
-		$connection = $db_connection;
519
+	if ($connection === false) {
520
+			$connection = $db_connection;
521
+	}
489 522
 
490 523
 	// Try get the last ID for the auto increment field.
491 524
 	$request = $smcFunc['db_query']('', 'SELECT CURRVAL(\'' . $table . '_seq\') AS insertID',
492 525
 		array(
493 526
 		)
494 527
 	);
495
-	if (!$request)
496
-		return false;
528
+	if (!$request) {
529
+			return false;
530
+	}
497 531
 	list ($lastID) = $smcFunc['db_fetch_row']($request);
498 532
 	$smcFunc['db_free_result']($request);
499 533
 
@@ -514,12 +548,13 @@  discard block
 block discarded – undo
514 548
 	// Decide which connection to use
515 549
 	$connection = $connection === null ? $db_connection : $connection;
516 550
 
517
-	if ($type == 'begin')
518
-		return @pg_query($connection, 'BEGIN');
519
-	elseif ($type == 'rollback')
520
-		return @pg_query($connection, 'ROLLBACK');
521
-	elseif ($type == 'commit')
522
-		return @pg_query($connection, 'COMMIT');
551
+	if ($type == 'begin') {
552
+			return @pg_query($connection, 'BEGIN');
553
+	} elseif ($type == 'rollback') {
554
+			return @pg_query($connection, 'ROLLBACK');
555
+	} elseif ($type == 'commit') {
556
+			return @pg_query($connection, 'COMMIT');
557
+	}
523 558
 
524 559
 	return false;
525 560
 }
@@ -547,19 +582,22 @@  discard block
 block discarded – undo
547 582
 	$query_error = @pg_last_error($connection);
548 583
 
549 584
 	// Log the error.
550
-	if (function_exists('log_error'))
551
-		log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line);
585
+	if (function_exists('log_error')) {
586
+			log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" .$db_string : ''), 'database', $file, $line);
587
+	}
552 588
 
553 589
 	// Nothing's defined yet... just die with it.
554
-	if (empty($context) || empty($txt))
555
-		die($query_error);
590
+	if (empty($context) || empty($txt)) {
591
+			die($query_error);
592
+	}
556 593
 
557 594
 	// Show an error message, if possible.
558 595
 	$context['error_title'] = $txt['database_error'];
559
-	if (allowedTo('admin_forum'))
560
-		$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
561
-	else
562
-		$context['error_message'] = $txt['try_again'];
596
+	if (allowedTo('admin_forum')) {
597
+			$context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line;
598
+	} else {
599
+			$context['error_message'] = $txt['try_again'];
600
+	}
563 601
 
564 602
 	if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true)
565 603
 	{
@@ -581,12 +619,14 @@  discard block
 block discarded – undo
581 619
 {
582 620
 	global $db_row_count;
583 621
 
584
-	if ($counter !== false)
585
-		return pg_fetch_row($request, $counter);
622
+	if ($counter !== false) {
623
+			return pg_fetch_row($request, $counter);
624
+	}
586 625
 
587 626
 	// Reset the row counter...
588
-	if (!isset($db_row_count[(int) $request]))
589
-		$db_row_count[(int) $request] = 0;
627
+	if (!isset($db_row_count[(int) $request])) {
628
+			$db_row_count[(int) $request] = 0;
629
+	}
590 630
 
591 631
 	// Return the right row.
592 632
 	return @pg_fetch_row($request, $db_row_count[(int) $request]++);
@@ -603,12 +643,14 @@  discard block
 block discarded – undo
603 643
 {
604 644
 	global $db_row_count;
605 645
 
606
-	if ($counter !== false)
607
-		return pg_fetch_assoc($request, $counter);
646
+	if ($counter !== false) {
647
+			return pg_fetch_assoc($request, $counter);
648
+	}
608 649
 
609 650
 	// Reset the row counter...
610
-	if (!isset($db_row_count[(int) $request]))
611
-		$db_row_count[(int) $request] = 0;
651
+	if (!isset($db_row_count[(int) $request])) {
652
+			$db_row_count[(int) $request] = 0;
653
+	}
612 654
 
613 655
 	// Return the right row.
614 656
 	return @pg_fetch_assoc($request, $db_row_count[(int) $request]++);
@@ -660,11 +702,13 @@  discard block
 block discarded – undo
660 702
 
661 703
 	$replace = '';
662 704
 
663
-	if (empty($data))
664
-		return;
705
+	if (empty($data)) {
706
+			return;
707
+	}
665 708
 
666
-	if (!is_array($data[array_rand($data)]))
667
-		$data = array($data);
709
+	if (!is_array($data[array_rand($data)])) {
710
+			$data = array($data);
711
+	}
668 712
 
669 713
 	// Replace the prefix holder with the actual prefix.
670 714
 	$table = str_replace('{db_prefix}', $db_prefix, $table);
@@ -690,11 +734,13 @@  discard block
 block discarded – undo
690 734
 			//pg 9.5 got replace support
691 735
 			$pg_version = $smcFunc['db_get_version']();
692 736
 			// if we got a Beta Version
693
-			if (stripos($pg_version, 'beta') !== false)
694
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0';
737
+			if (stripos($pg_version, 'beta') !== false) {
738
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')).'.0';
739
+			}
695 740
 			// or RC
696
-			if (stripos($pg_version, 'rc') !== false)
697
-				$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0';
741
+			if (stripos($pg_version, 'rc') !== false) {
742
+							$pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')).'.0';
743
+			}
698 744
 
699 745
 			$replace_support = (version_compare($pg_version,'9.5.0','>=') ? true : false);
700 746
 		}
@@ -713,8 +759,7 @@  discard block
 block discarded – undo
713 759
 					$key_str .= ($count_pk > 0 ? ',' : '');
714 760
 					$key_str .= $columnName;
715 761
 					$count_pk++;
716
-				}
717
-				else //normal field
762
+				} else //normal field
718 763
 				{
719 764
 					$col_str .= ($count > 0 ? ',' : '');
720 765
 					$col_str .= $columnName.' = EXCLUDED.'.$columnName;
@@ -722,20 +767,21 @@  discard block
 block discarded – undo
722 767
 				}
723 768
 			}
724 769
 			$replace = ' ON CONFLICT ('.$key_str.') DO UPDATE SET '.$col_str;
725
-		}
726
-		else
770
+		} else
727 771
 		{
728 772
 			foreach ($columns as $columnName => $type)
729 773
 			{
730 774
 				// Are we restricting the length?
731
-				if (strpos($type, 'string-') !== false)
732
-					$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
733
-				else
734
-					$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
775
+				if (strpos($type, 'string-') !== false) {
776
+									$actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count);
777
+				} else {
778
+									$actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count);
779
+				}
735 780
 
736 781
 				// A key? That's what we were looking for.
737
-				if (in_array($columnName, $keys))
738
-					$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
782
+				if (in_array($columnName, $keys)) {
783
+									$where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2);
784
+				}
739 785
 				$count++;
740 786
 			}
741 787
 
@@ -761,10 +807,11 @@  discard block
 block discarded – undo
761 807
 		foreach ($columns as $columnName => $type)
762 808
 		{
763 809
 			// Are we restricting the length?
764
-			if (strpos($type, 'string-') !== false)
765
-				$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
766
-			else
767
-				$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
810
+			if (strpos($type, 'string-') !== false) {
811
+							$insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName);
812
+			} else {
813
+							$insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName);
814
+			}
768 815
 		}
769 816
 		$insertData = substr($insertData, 0, -2) . ')';
770 817
 
@@ -773,11 +820,12 @@  discard block
 block discarded – undo
773 820
 
774 821
 		// Here's where the variables are injected to the query.
775 822
 		$insertRows = array();
776
-		foreach ($data as $dataRow)
777
-			$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
823
+		foreach ($data as $dataRow) {
824
+					$insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection);
825
+		}
778 826
 
779
-		foreach ($insertRows as $entry)
780
-			// Do the insert.
827
+		foreach ($insertRows as $entry) {
828
+					// Do the insert.
781 829
 			$smcFunc['db_query']('', '
782 830
 				INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '")
783 831
 				VALUES
@@ -788,11 +836,13 @@  discard block
 block discarded – undo
788 836
 				),
789 837
 				$connection
790 838
 			);
839
+		}
791 840
 	}
792 841
 
793
-	if ($priv_trans)
794
-		$smcFunc['db_transaction']('commit', $connection);
795
-}
842
+	if ($priv_trans) {
843
+			$smcFunc['db_transaction']('commit', $connection);
844
+	}
845
+	}
796 846
 
797 847
 /**
798 848
  * Dummy function really. Doesn't do anything on PostgreSQL.
@@ -829,8 +879,9 @@  discard block
 block discarded – undo
829 879
  */
830 880
 function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
831 881
 {
832
-	if (empty($log_message))
833
-		$log_message = $error_message;
882
+	if (empty($log_message)) {
883
+			$log_message = $error_message;
884
+	}
834 885
 
835 886
 	foreach (debug_backtrace() as $step)
836 887
 	{
@@ -849,12 +900,14 @@  discard block
 block discarded – undo
849 900
 	}
850 901
 
851 902
 	// A special case - we want the file and line numbers for debugging.
852
-	if ($error_type == 'return')
853
-		return array($file, $line);
903
+	if ($error_type == 'return') {
904
+			return array($file, $line);
905
+	}
854 906
 
855 907
 	// Is always a critical error.
856
-	if (function_exists('log_error'))
857
-		log_error($log_message, 'critical', $file, $line);
908
+	if (function_exists('log_error')) {
909
+			log_error($log_message, 'critical', $file, $line);
910
+	}
858 911
 
859 912
 	if (function_exists('fatal_error'))
860 913
 	{
@@ -862,12 +915,12 @@  discard block
 block discarded – undo
862 915
 
863 916
 		// Cannot continue...
864 917
 		exit;
918
+	} elseif ($error_type) {
919
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
920
+	} else {
921
+			trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
922
+	}
865 923
 	}
866
-	elseif ($error_type)
867
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
868
-	else
869
-		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
870
-}
871 924
 
872 925
 /**
873 926
  * Escape the LIKE wildcards so that they match the character and not the wildcard.
@@ -884,10 +937,11 @@  discard block
 block discarded – undo
884 937
 		'\\' => '\\\\',
885 938
 	);
886 939
 
887
-	if ($translate_human_wildcards)
888
-		$replacements += array(
940
+	if ($translate_human_wildcards) {
941
+			$replacements += array(
889 942
 			'*' => '%',
890 943
 		);
944
+	}
891 945
 
892 946
 	return strtr($string, $replacements);
893 947
 }
Please login to merge, or discard this patch.